Skip to content

Commit

Permalink
Select Atom from Plot
Browse files Browse the repository at this point in the history
  • Loading branch information
JensKrumsieck committed Jun 23, 2023
1 parent ffd5f41 commit 5295706
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 36 deletions.
2 changes: 1 addition & 1 deletion PorphyStruct.Core/PorphyStruct.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


<ItemGroup>
<PackageReference Include="ChemSharp.Molecules" Version="2.0.0" />
<PackageReference Include="ChemSharp.Molecules" Version="2.0.1" />
<PackageReference Include="JensKrumsieck.TinyMVVM" Version="1.0.0" />
<PackageReference Include="OxyPlot.Core" Version="2.1.2" />
<PackageReference Include="OxyPlot.SkiaSharp" Version="2.1.2" />
Expand Down
35 changes: 7 additions & 28 deletions PorphyStruct.ViewModel.Windows/MacrocycleViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,6 @@ namespace PorphyStruct.ViewModel.Windows;

public class MacrocycleViewModel : ViewModel.MacrocycleViewModel
{
private Atom _selectedAtom;
/// <summary>
/// Gets or Sets the selected Atom
/// </summary>
public Atom SelectedAtom
{
get => _selectedAtom;
set => Set(ref _selectedAtom, value, () =>
{
foreach (var atom in Atoms3D)
atom.IsSelected = atom.Atom.Equals(_selectedAtom);
var found = false;
foreach (var viewModel in Items)
{
if (!viewModel.Analysis.Atoms.Contains(_selectedAtom))
{
viewModel.ExperimentalSeries.ClearSelection();
viewModel.Model.InvalidatePlot(true);
continue;
}
SelectedIndex = Items.IndexOf(viewModel);
var index = viewModel.Analysis.GetMappingIndex(_selectedAtom);
viewModel.ExperimentalSeries.SelectItem(index);
viewModel.Model.InvalidatePlot(true);
break;
}
});
}
/// <summary>
/// 3D Representation of Atoms
/// </summary>
Expand Down Expand Up @@ -102,4 +74,11 @@ protected override void Validate()
}
}
}

public override void HandleAtomSelect(Atom selectedAtom)
{
base.HandleAtomSelect(selectedAtom);
foreach (var atom in Atoms3D)
atom.IsSelected = atom.Atom.Equals(selectedAtom);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ChemSharp.Molecules.HelixToolkit" Version="2.0.0" />
<PackageReference Include="ChemSharp.Molecules.HelixToolkit" Version="2.0.1" />
<ProjectReference Include="..\PorphyStruct.ViewModel\PorphyStruct.ViewModel.csproj" />
</ItemGroup>

Expand Down
12 changes: 12 additions & 0 deletions PorphyStruct.ViewModel/AnalysisViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class AnalysisViewModel : ListItemViewModel<MacrocycleViewModel, Analysis
public MacrocycleAnalysis Analysis { get; }

public DefaultPlotModel Model { get; }

public PlotController Controller { get; set; }

public DefaultScatterSeries ExperimentalSeries { get; } = new();

Expand Down Expand Up @@ -99,6 +101,16 @@ public AnalysisViewModel(MacrocycleViewModel parent, MacrocycleAnalysis analysis
//Init Object
Analysis = analysis;
Model = new DefaultPlotModel();
Controller = new PlotController();
Controller.BindMouseEnter(PlotCommands.HoverSnapTrack);
var handleSelect = new DelegatePlotCommand<OxyMouseDownEventArgs>((v, c, e) =>
{
var args = new HitTestArguments(e.Position, 10);
var result = ExperimentalSeries.HitTest(args);
if (result?.Item is not AtomDataPoint point) return;
Parent.SelectedAtom = point.Atom;
});
Controller.Bind(new OxyMouseDownGesture(OxyMouseButton.Left), handleSelect);
Model.Init();
Model.Series.Add(ExperimentalSeries);
Model.Series.Add(SimulationSeries);
Expand Down
31 changes: 31 additions & 0 deletions PorphyStruct.ViewModel/MacrocycleViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using ChemSharp.Molecules;
using PorphyStruct.Core;
using PorphyStruct.Core.Analysis.Properties;
using TinyMVVM;
Expand All @@ -12,6 +13,16 @@ public class MacrocycleViewModel : ListingViewModel<AnalysisViewModel>
/// </summary>
public string Filename { get; }

private Atom? _selectedAtom;
/// <summary>
/// Gets or Sets the selected Atom
/// </summary>
public Atom? SelectedAtom
{
get => _selectedAtom;
set => Set(ref _selectedAtom, value, () => HandleAtomSelect(_selectedAtom));
}

/// <summary>
/// The opened Macrocycle
/// </summary>
Expand Down Expand Up @@ -47,6 +58,8 @@ public async Task Analyze()
SelectedIndex = Items.IndexOf(analysis);
analysis.PropertyChanged += Child_Changed;
}

SelectedIndexChanged += (sender, args) => SelectedAtom = null;
}

private void Child_Changed(object? sender, PropertyChangedEventArgs e)
Expand All @@ -59,4 +72,22 @@ private void Child_Changed(object? sender, PropertyChangedEventArgs e)
OnSelectedIndexChanged();
}
protected virtual void Validate() { }

public virtual void HandleAtomSelect(Atom? selectedAtom)
{
foreach (var viewModel in Items)
{
if (!viewModel.Analysis.Atoms.Contains(selectedAtom))
{
viewModel.ExperimentalSeries.ClearSelection();
viewModel.Model.InvalidatePlot(true);
continue;
}
SelectedIndex = Items.IndexOf(viewModel);
var index = viewModel.Analysis.GetMappingIndex(selectedAtom);
viewModel.ExperimentalSeries.SelectItem(index);
viewModel.Model.InvalidatePlot(true);
break;
}
}
}
2 changes: 1 addition & 1 deletion PorphyStruct.ViewModel/PorphyStruct.ViewModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ChemSharp.Molecules" Version="2.0.0" />
<PackageReference Include="ChemSharp.Molecules" Version="2.0.1" />
<PackageReference Include="JensKrumsieck.TinyMVVM" Version="1.0.0" />
<PackageReference Include="OxyPlot.Core" Version="2.1.2" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions PorphyStruct.WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<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}}"/>
<Button extension:ControlExtension.AttachedIcon="RotateClockwise" Content="Shift" Click="Rotate_OnClick" IsEnabled="{Binding SelectedItem, Converter={converterlocal:SufficientSymmetryConverter}}"/>
</ToolBar>
<ToolBar>
<Button extension:ControlExtension.AttachedIcon="Console" Content="Batch" Click="Batch_OnClick" />
Expand Down Expand Up @@ -203,11 +203,11 @@
</TabControl.Background>
<TabControl.ContentTemplate>
<DataTemplate DataType="viewModel:AnalysisViewModel">
<wpf:PlotView x:Name="PlotView" Model="{Binding Model}"/>
<wpf:PlotView x:Name="PlotView" Model="{Binding Model}" Controller="{Binding Controller}"/>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
<h:HelixViewport3D Grid.Column="1" Grid.Row="0" x:Name="Viewport3D"
<h:HelixViewport3D Grid.Column="1" Grid.Row="0" x:Name="Viewport3D" Drop="OnFileDrop"
MouseLeftButtonDown="Viewport3D_OnMouseLeftButtonDown"
ShowViewCube="False" ShowCoordinateSystem="True"
ZoomExtentsWhenLoaded="True" IsHeadLightEnabled="True" >
Expand Down
2 changes: 2 additions & 0 deletions PorphyStruct.WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
using ChemSharp.Mathematics;
using ChemSharp.Molecules.HelixToolkit;
Expand Down Expand Up @@ -31,6 +32,7 @@ public partial class MainWindow : DefaultWindow
public MainWindow()
{
Settings.Instance.Load();
Atom3D.SelectionColor = Brushes.Fuchsia;
InitializeComponent();
CheckUpdate();
}
Expand Down
2 changes: 1 addition & 1 deletion PorphyStruct.WPF/PorphyStruct.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ChemSharp.Molecules.HelixToolkit" Version="2.0.0" />
<PackageReference Include="ChemSharp.Molecules.HelixToolkit" Version="2.0.1" />
<PackageReference Include="JensKrumsieck.ThemeCommons.MaterialDesign" Version="1.0.0" />
<PackageReference Include="OxyPlot.SkiaSharp.Wpf" Version="2.1.2" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion PorphyStruct.Web/PorphyStruct.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ChemSharp.Molecules.Blazor" Version="2.0.0" />
<PackageReference Include="ChemSharp.Molecules.Blazor" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.ClientAssets" Version="0.1.0-alpha.21528.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.3" PrivateAssets="all" />
Expand Down

1 comment on commit 5295706

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

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

Please sign in to comment.