Skip to content

Commit

Permalink
Started to work on "real" inverting
Browse files Browse the repository at this point in the history
  • Loading branch information
JensKrumsieck committed Jun 20, 2023
1 parent 1891753 commit a726fd7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions PorphyStruct.Core/Analysis/MacrocycleAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ protected virtual IEnumerable<AtomDataPoint> CalculateDataPoints()
}
}

public void InvertDataPoints()
{
_dataPoints = _dataPoints!.Invert();
Properties!.Rebuild();
}

/// <summary>
/// checks whether it's an alpha atom or not
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public MacrocycleProperties(MacrocycleAnalysis analysis)
/// <summary>
/// Fills all Lists
/// </summary>
private void Rebuild()
public void Rebuild()
{
Simulation ??= new Simulation(Analysis.GetAnalysisType());
if (Analysis.DataPoints.Any())
Expand Down
2 changes: 2 additions & 0 deletions PorphyStruct.Core/Extension/MathUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public static double Heron(Atom a1, Atom a2, Atom a3)
var sqrt = (a + b + c) * (-a + b + c) * (a - b + c) * (a + b - c);
return 1f / 4f * MathF.Sqrt(sqrt);
}

public static IEnumerable<AtomDataPoint> Invert(this IEnumerable<AtomDataPoint> dataPoints) => dataPoints.Select(datapoint => new AtomDataPoint(datapoint.X, -datapoint.Y, datapoint.Atom, datapoint.Size, datapoint.Value, datapoint.Tag));
}
2 changes: 2 additions & 0 deletions PorphyStruct.ViewModel/AnalysisViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public bool Inverted
{
ExperimentalSeries.Inverted = value;
SimulationSeries.Inverted = value;
Analysis.InvertDataPoints();
OnPropertyChanged(nameof(Analysis));
Invalidate();
});
}
Expand Down
15 changes: 14 additions & 1 deletion PorphyStruct.ViewModel/MacrocycleViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PorphyStruct.Core;
using System.ComponentModel;
using PorphyStruct.Core;
using PorphyStruct.Core.Analysis.Properties;
using TinyMVVM;

Expand Down Expand Up @@ -41,11 +42,23 @@ public async Task Analyze()
foreach (var part in Macrocycle.DetectedParts)
{
var analysis = new AnalysisViewModel(this, part);
analysis.PropertyChanged += Child_Changed;
part.Properties ??= new MacrocycleProperties(part);
Items.Add(analysis);
SelectedIndex = Items.IndexOf(analysis);
}
}

private void Child_Changed(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != nameof(SelectedItem.Analysis)) return;
var tmp = new List<AnalysisViewModel>(Items);
var tmpIndex = SelectedIndex;
Items.Clear();
for(var i = 0; i < tmp.Count; i++) Items.Add(tmp[i]);
SelectedIndex = -1;
SelectedIndex = tmpIndex;
}

protected virtual void Validate() { }
}
2 changes: 1 addition & 1 deletion PorphyStruct.WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
</h:HelixViewport3D>
<TabControl Grid.Row="1" Grid.Column="1" Background="Transparent" TabStripPlacement="Left" ItemContainerStyle="{DynamicResource SideTabHeaderStyle}"
Padding="0" BorderThickness="0" ContentTemplateSelector="{DynamicResource TemplateByTypeSelector}">
<TabItem Header="Analysis" extension:ControlExtension.AttachedIcon="Flask" DataContext="{Binding SelectedItem.Analysis}" Content="{Binding}"/>
<TabItem Header="Analysis" extension:ControlExtension.AttachedIcon="Flask" DataContext="{Binding SelectedItem.Analysis}" Content="{Binding .}"/>
<TabItem Header="Coordinates" extension:ControlExtension.AttachedIcon="Navigation" DataContext="{Binding}" Content="{Binding}"/>
<TabItem DataContext="{Binding SelectedItem}" Content="{Binding}" Header="Quick Settings" extension:ControlExtension.AttachedIcon="Cog" VerticalAlignment="Top"/>
</TabControl>
Expand Down

1 comment on commit a726fd7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for porphystruct ready!

✅ Preview
https://porphystruct-qfv15d53x-jenskrumsieck.vercel.app

Built with commit a726fd7.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.