aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-02-27 17:25:26 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-02-27 17:25:26 +0200
commitf1a77b05c2e56cd073180803947aa991a09f9b40 (patch)
treee199c2bd9298fab848bdfd71eb09e993e8c535cb /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner
parent47c117490f9f9fed42329ebd1374709528693d6b (diff)
downloadTango-f1a77b05c2e56cd073180803947aa991a09f9b40.tar.gz
Tango-f1a77b05c2e56cd073180803947aa991a09f9b40.zip
Implemented hardware designer new, save, delete.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Tango.MachineStudio.HardwareDesigner.csproj7
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs110
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml30
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/app.config10
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/packages.config1
5 files changed, 137 insertions, 21 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Tango.MachineStudio.HardwareDesigner.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Tango.MachineStudio.HardwareDesigner.csproj
index 12c32df08..6ca84be11 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Tango.MachineStudio.HardwareDesigner.csproj
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Tango.MachineStudio.HardwareDesigner.csproj
@@ -31,6 +31,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+ <HintPath>..\..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll</HintPath>
+ </Reference>
+ <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+ <HintPath>..\..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
+ </Reference>
<Reference Include="GalaSoft.MvvmLight, Version=5.3.0.19026, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
</Reference>
@@ -53,6 +59,7 @@
<HintPath>..\..\..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
index 06a3c9ba4..6d605ed1c 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
@@ -6,12 +6,16 @@ using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
using Tango.Integration.Observables;
+using Tango.MachineStudio.Common.Notifications;
using Tango.SharedUI;
namespace Tango.MachineStudio.HardwareDesigner.ViewModels
{
public class MainViewVM : ViewModel
{
+ private INotificationProvider _notification;
+ private bool _isNew;
+
private ObservablesEntitiesAdapter _adapter;
public ObservablesEntitiesAdapter Adapter
{
@@ -30,21 +34,34 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
public HardwareVersion CurrentVersion
{
get { return _currentVersion; }
- set { _currentVersion = value; RaisePropertyChangedAuto(); }
+ set { _currentVersion = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
public RelayCommand SaveCommand { get; set; }
- public MainViewVM()
+ public RelayCommand DeleteCommand { get; set; }
+
+ public RelayCommand NewCommand { get; set; }
+
+ public MainViewVM(INotificationProvider notification)
{
- Adapter = ObservablesEntitiesAdapter.Instance;
+ _notification = notification;
- SaveCommand = new RelayCommand(Save);
+ Adapter = ObservablesEntitiesAdapter.Instance;
+ SaveCommand = new RelayCommand(Save, () => CurrentVersion != null);
+ NewCommand = new RelayCommand(New);
+ DeleteCommand = new RelayCommand(Delete, () => !_isNew && CurrentVersion != null);
}
private void OnSelectedVersionChanged()
{
- CurrentVersion = SelectedVersion.Clone();
+ if (SelectedVersion != null)
+ {
+ _isNew = false;
+ CurrentVersion = SelectedVersion.Clone();
+ }
+
+ InvalidateRelayCommands();
}
public void OnRemoveDancer(HardwareDancer dancer)
@@ -86,11 +103,92 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
}
}
- private void Save()
+ private void New()
+ {
+ String name = _notification.ShowTextInput("Enter hardware version name", "Name");
+
+ if (!String.IsNullOrWhiteSpace(name))
+ {
+ SelectedVersion = null;
+ CurrentVersion = new HardwareVersion();
+ CurrentVersion.Version = Adapter.HardwareVersions.Max(x => x.Version) + 1;
+ CurrentVersion.Name = name;
+
+ _isNew = true;
+ InvalidateRelayCommands();
+ }
+ }
+
+ private async void Save()
{
if (CurrentVersion != null)
{
+ using (_notification.PushTaskItem("Saving hardware version..."))
+ {
+ HardwareVersion realVersion = null;
+
+ if (_isNew)
+ {
+ realVersion = CurrentVersion;
+ }
+ else
+ {
+ realVersion = Adapter.HardwareVersions.SingleOrDefault(x => x.Guid == SelectedVersion.Guid);
+ realVersion.Version = CurrentVersion.Version;
+ realVersion.Name = CurrentVersion.Name;
+ realVersion.HardwareDancers.ToList().ForEach(x => x.DefferedDelete(Adapter.Context));
+ realVersion.HardwareMotors.ToList().ForEach(x => x.DefferedDelete(Adapter.Context));
+ realVersion.HardwarePidControls.ToList().ForEach(x => x.DefferedDelete(Adapter.Context));
+
+ realVersion.HardwareDancers.Clear();
+ realVersion.HardwareMotors.Clear();
+ realVersion.HardwarePidControls.Clear();
+
+
+ foreach (var item in CurrentVersion.HardwareDancers.ToList().Select(x => x.Clone()))
+ {
+ item.HardwareVersionGuid = realVersion.Guid;
+ realVersion.HardwareDancers.Add(item);
+ }
+
+ foreach (var item in CurrentVersion.HardwareMotors.ToList().Select(x => x.Clone()))
+ {
+ item.HardwareVersionGuid = realVersion.Guid;
+ realVersion.HardwareMotors.Add(item);
+ }
+
+ foreach (var item in CurrentVersion.HardwarePidControls.ToList().Select(x => x.Clone()))
+ {
+ item.HardwareVersionGuid = realVersion.Guid;
+ realVersion.HardwarePidControls.Add(item);
+ }
+ }
+
+
+
+ if (_isNew)
+ {
+ Adapter.Context.HardwareVersions.Add(realVersion);
+ }
+
+ await realVersion.SaveAsync(Adapter.Context);
+
+ SelectedVersion = Adapter.HardwareVersions.SingleOrDefault(x => x.Guid == realVersion.Guid);
+ }
+ }
+ }
+
+ private void Delete()
+ {
+ if (_notification.ShowQuestion("Are you sure you want to delete this hardware version?"))
+ {
+ using (_notification.PushTaskItem("Deleting hardware version..."))
+ {
+ SelectedVersion.DeleteAsync(Adapter.Context);
+ SelectedVersion = null;
+ CurrentVersion = null;
+ }
}
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml
index 3e840467f..f8de83966 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml
@@ -250,8 +250,8 @@
<materialDesign:Card Margin="5,10,5,0" Background="{DynamicResource MaterialDesignBackground}">
<StackPanel>
- <Expander HorizontalAlignment="Stretch" Header="Motors">
- <ListBox ItemsSource="{Binding Adapter.HardwareMotorTypes}" HorizontalContentAlignment="Stretch">
+ <Expander HorizontalAlignment="Stretch" Header="PID Controls">
+ <ListBox ItemsSource="{Binding Adapter.HardwarePidControlTypes}" HorizontalContentAlignment="Stretch">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
@@ -263,7 +263,7 @@
<DataTemplate>
<Grid Background="Transparent" IsHitTestVisible="True" dragAndDrop:DragAndDropService.DraggableBorderBrush="{StaticResource AccentColorBrush}" dragAndDrop:DragAndDropService.Draggable="True" dragAndDrop:DragAndDropService.DraggingSurface="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DraggingSurface}">
<StackPanel Orientation="Horizontal" Margin="2 8">
- <Image IsHitTestVisible="False" Width="24" Height="24" Source="../Images/engine.png" Stretch="Fill" RenderOptions.BitmapScalingMode="Fant"></Image>
+ <Image IsHitTestVisible="False" Width="24" Height="24" Source="../Images/balance.png" Stretch="Fill" RenderOptions.BitmapScalingMode="Fant"></Image>
<StackPanel Margin="5 0 0 0" IsHitTestVisible="False" VerticalAlignment="Center">
<TextBlock IsHitTestVisible="False" FontSize="10" Foreground="DimGray"><Run Text="{Binding Name}"></Run></TextBlock>
</StackPanel>
@@ -280,8 +280,8 @@
<materialDesign:Card Margin="5,10,5,0" Background="{DynamicResource MaterialDesignBackground}">
<StackPanel>
- <Expander HorizontalAlignment="Stretch" Header="Dancers">
- <ListBox ItemsSource="{Binding Adapter.HardwareDancerTypes}" HorizontalContentAlignment="Stretch">
+ <Expander HorizontalAlignment="Stretch" Header="Motors">
+ <ListBox ItemsSource="{Binding Adapter.HardwareMotorTypes}" HorizontalContentAlignment="Stretch">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
@@ -293,7 +293,7 @@
<DataTemplate>
<Grid Background="Transparent" IsHitTestVisible="True" dragAndDrop:DragAndDropService.DraggableBorderBrush="{StaticResource AccentColorBrush}" dragAndDrop:DragAndDropService.Draggable="True" dragAndDrop:DragAndDropService.DraggingSurface="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DraggingSurface}">
<StackPanel Orientation="Horizontal" Margin="2 8">
- <Image IsHitTestVisible="False" Width="24" Height="24" Source="../Images/compass.png" Stretch="Fill" RenderOptions.BitmapScalingMode="Fant"></Image>
+ <Image IsHitTestVisible="False" Width="24" Height="24" Source="../Images/engine.png" Stretch="Fill" RenderOptions.BitmapScalingMode="Fant"></Image>
<StackPanel Margin="5 0 0 0" IsHitTestVisible="False" VerticalAlignment="Center">
<TextBlock IsHitTestVisible="False" FontSize="10" Foreground="DimGray"><Run Text="{Binding Name}"></Run></TextBlock>
</StackPanel>
@@ -310,8 +310,8 @@
<materialDesign:Card Margin="5,10,5,0" Background="{DynamicResource MaterialDesignBackground}">
<StackPanel>
- <Expander HorizontalAlignment="Stretch" Header="PID Controls">
- <ListBox ItemsSource="{Binding Adapter.HardwarePidControlTypes}" HorizontalContentAlignment="Stretch">
+ <Expander HorizontalAlignment="Stretch" Header="Dancers">
+ <ListBox ItemsSource="{Binding Adapter.HardwareDancerTypes}" HorizontalContentAlignment="Stretch">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
@@ -323,7 +323,7 @@
<DataTemplate>
<Grid Background="Transparent" IsHitTestVisible="True" dragAndDrop:DragAndDropService.DraggableBorderBrush="{StaticResource AccentColorBrush}" dragAndDrop:DragAndDropService.Draggable="True" dragAndDrop:DragAndDropService.DraggingSurface="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DraggingSurface}">
<StackPanel Orientation="Horizontal" Margin="2 8">
- <Image IsHitTestVisible="False" Width="24" Height="24" Source="../Images/balance.png" Stretch="Fill" RenderOptions.BitmapScalingMode="Fant"></Image>
+ <Image IsHitTestVisible="False" Width="24" Height="24" Source="../Images/compass.png" Stretch="Fill" RenderOptions.BitmapScalingMode="Fant"></Image>
<StackPanel Margin="5 0 0 0" IsHitTestVisible="False" VerticalAlignment="Center">
<TextBlock IsHitTestVisible="False" FontSize="10" Foreground="DimGray"><Run Text="{Binding Name}"></Run></TextBlock>
</StackPanel>
@@ -341,8 +341,8 @@
<materialDesign:Card Margin="5,10,5,0" Background="{DynamicResource MaterialDesignBackground}">
<StackPanel>
<Grid>
- <Expander HorizontalAlignment="Stretch" Header="Motor Properties">
- <editors:ParameterizedEditor ParameterizedObject="{Binding ElementName=listMotors,Path=SelectedItem}" Padding="10">
+ <Expander HorizontalAlignment="Stretch" Header="PID Control Properties">
+ <editors:ParameterizedEditor ParameterizedObject="{Binding ElementName=listPid,Path=SelectedItem}" Padding="10">
<editors:ParameterizedEditor.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
@@ -381,8 +381,8 @@
<materialDesign:Card Margin="5,10,5,0" Background="{DynamicResource MaterialDesignBackground}">
<StackPanel>
<Grid>
- <Expander HorizontalAlignment="Stretch" Header="Dancer Properties">
- <editors:ParameterizedEditor ParameterizedObject="{Binding ElementName=listDancers,Path=SelectedItem}" Padding="10">
+ <Expander HorizontalAlignment="Stretch" Header="Motor Properties">
+ <editors:ParameterizedEditor ParameterizedObject="{Binding ElementName=listMotors,Path=SelectedItem}" Padding="10">
<editors:ParameterizedEditor.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
@@ -421,8 +421,8 @@
<materialDesign:Card Margin="5,10,5,0" Background="{DynamicResource MaterialDesignBackground}">
<StackPanel>
<Grid>
- <Expander HorizontalAlignment="Stretch" Header="PID Control Properties">
- <editors:ParameterizedEditor ParameterizedObject="{Binding ElementName=listPid,Path=SelectedItem}" Padding="10">
+ <Expander HorizontalAlignment="Stretch" Header="Dancer Properties">
+ <editors:ParameterizedEditor ParameterizedObject="{Binding ElementName=listDancers,Path=SelectedItem}" Padding="10">
<editors:ParameterizedEditor.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/app.config
index cacd4cd77..4a6cb0526 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/app.config
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/app.config
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
+ <configSections>
+ <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+ <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+ </configSections>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
@@ -8,4 +12,10 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
+ <entityFramework>
+ <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
+ <providers>
+ <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
+ </providers>
+ </entityFramework>
</configuration> \ No newline at end of file
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/packages.config
index 4fd672b32..cf0df03c8 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/packages.config
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/packages.config
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonServiceLocator" version="1.3" targetFramework="net46" />
+ <package id="EntityFramework" version="6.0.0" targetFramework="net46" />
<package id="MahApps.Metro" version="1.5.0" targetFramework="net46" />
<package id="MaterialDesignColors" version="1.1.2" targetFramework="net46" />
<package id="MaterialDesignThemes" version="2.3.1.953" targetFramework="net46" />