Skip to content

Commit

Permalink
add ability to flip X Axis (CW vs CCW)
Browse files Browse the repository at this point in the history
  • Loading branch information
JensKrumsieck committed Jun 20, 2023
1 parent ea06f9b commit 43e8cd4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
19 changes: 18 additions & 1 deletion PorphyStruct.Core/Analysis/MacrocycleAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,29 @@ protected virtual IEnumerable<AtomDataPoint> CalculateDataPoints()
}
}

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

//flips the x axis positions by remapping
public void InvertXDataPoints()
{
Dictionary<string, Atom> newMapping = new();
var orderedMap = _mapping.OrderBy(s => RingAtoms.IndexOf(s.Key)).ToList();
for (var i = 0; i < orderedMap.Count; i++)
{
if(Type == MacrocycleType.Porphyrin && orderedMap[i].Key != "C20")
newMapping[orderedMap[i].Key] = orderedMap[_mapping.Count - (i+2)].Value;
else newMapping[orderedMap[i].Key] = orderedMap[_mapping.Count - (i+1)].Value;
}
if(Type == MacrocycleType.Porphyrin)
newMapping["C20"] = _mapping["C20"];
_mapping = newMapping;
Properties!.Rebuild();
}

/// <summary>
/// Rotates Datapoints for Porphyrin: 90 deg, for Norcorrole and Porphycene 180 deg
/// </summary>
Expand Down
41 changes: 29 additions & 12 deletions PorphyStruct.ViewModel/AnalysisViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,22 @@ public bool Inverted
get => _inverted;
set => Set(ref _inverted, value, () =>
{
ExperimentalSeries.Inverted = value;
Analysis.InvertDataPoints();
OnPropertyChanged(nameof(Analysis));
if(SimulationVisible) SimulationChanged();
Invalidate();
Analysis.InvertYDataPoints();
DataChanged(true);
});
}

private bool _invertedX;
/// <summary>
/// Indicates whether the series are x flipped
/// </summary>
public bool InvertedX
{
get => _invertedX;
set => Set(ref _invertedX, value, () =>
{
Analysis.InvertXDataPoints();
DataChanged(true);
});
}

Expand All @@ -65,19 +76,14 @@ public void Rotate()
break;
case MacrocycleType.Norcorrole:
case MacrocycleType.Porphycene:
Analysis.RotateDataPoints(10, false);
Analysis.RotateDataPoints(10, true);
break;
case MacrocycleType.Corrole:
case MacrocycleType.Corrphycene:
default:
break;
}
ExperimentalBonds.ClearAndNotify();
foreach (var (a1, a2) in Analysis.BondDataPoints())
ExperimentalBonds.Add(new BondAnnotation(a1, a2, ExperimentalSeries));
OnPropertyChanged(nameof(Analysis));
if(SimulationVisible) SimulationChanged();
Invalidate();
DataChanged();
}

private void Invalidate()
Expand Down Expand Up @@ -145,6 +151,17 @@ public void SimulationChanged()
Invalidate();
}

public void DataChanged(bool resetData = false)
{
if (resetData)
ExperimentalSeries.ItemsSource = Analysis.DataPoints;
ExperimentalBonds.ClearAndNotify();
foreach (var (a1, a2) in Analysis.BondDataPoints())
ExperimentalBonds.Add(new BondAnnotation(a1, a2, ExperimentalSeries));
OnPropertyChanged(nameof(Analysis));
if(SimulationVisible) SimulationChanged();
Invalidate();
}
/// <summary>
/// Calculates Conformation
/// </summary>
Expand Down
7 changes: 4 additions & 3 deletions PorphyStruct.WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
Title="PorphyStruct"
Background="{DynamicResource Background}"
Icon="Resources/porphystruct.ico"
MinWidth="1250" MinHeight="650"
MinWidth="1400" MinHeight="650"
x:Name="Main"
TitlebarBackground="{DynamicResource TitleBar}" Height="750" Width="1440">
TitlebarBackground="{DynamicResource TitleBar}" Height="750" Width="1400">
<commons:DefaultWindow.TitlebarContent>
<Grid VerticalAlignment="Center" x:Name="TitleGrid">
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -64,7 +64,8 @@
<Separator/>
<ListBox SelectionMode="Multiple">
<ListBoxItem Style="{DynamicResource ToolbarListItem}" IsSelected="{Binding SelectedItem.SimulationVisible}" extension:ControlExtension.AttachedIcon="Wand" Content="Simulation" IsEnabled="{Binding SelectedItem, Converter={converter:NotNullConverter}}"/>
<ListBoxItem Style="{DynamicResource ToolbarListItem}" IsSelected="{Binding SelectedItem.Inverted}" extension:ControlExtension.AttachedIcon="PlusMinusBox" Content="Invert" IsEnabled="{Binding SelectedItem, Converter={converter:NotNullConverter}}"/>
<ListBoxItem Style="{DynamicResource ToolbarListItem}" IsSelected="{Binding SelectedItem.Inverted}" extension:ControlExtension.AttachedIcon="PlusMinusBox" Content="InvertY" IsEnabled="{Binding SelectedItem, Converter={converter:NotNullConverter}}"/>
<ListBoxItem Style="{DynamicResource ToolbarListItem}" IsSelected="{Binding SelectedItem.InvertedX}" extension:ControlExtension.AttachedIcon="FlipHorizontal" Content="InvertX" IsEnabled="{Binding SelectedItem, Converter={converter:NotNullConverter}}"/>
</ListBox>
<Button extension:ControlExtension.AttachedIcon="RotateClockwise" Content="Rotate" Click="Rotate_OnClick" IsEnabled="{Binding SelectedItem, Converter={converterlocal:SufficientSymmetryConverter}}"/>
</ToolBar>
Expand Down

1 comment on commit 43e8cd4

@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-e6fpi0eif-jenskrumsieck.vercel.app

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

Please sign in to comment.