diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner')
4 files changed, 110 insertions, 31 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/HardwareConfigurationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/HardwareConfigurationViewVM.cs index 51d88c3f9..e29ba3b6f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/HardwareConfigurationViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/HardwareConfigurationViewVM.cs @@ -92,16 +92,19 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { HardwareVersion hardwareVersion = configuration.HardwareVersion; - _hwConfig = configuration.GetHardwareConfiguration(); + if (hardwareVersion != null) + { + _hwConfig = configuration.GetHardwareConfiguration(); - Collections.Clear(); - Collections.Add(CreateMotorsCollection(hardwareVersion)); - Collections.Add(CreateDancerCollection(hardwareVersion)); - Collections.Add(CreatePidCollection(hardwareVersion)); - Collections.Add(CreateWindersCollection(hardwareVersion)); - Collections.Add(CreateSpeedSensorsCollection(hardwareVersion)); - Collections.Add(CreateBlowersCollection(hardwareVersion)); - Collections.Add(CreateBreakSensorCollection(hardwareVersion)); + Collections.Clear(); + Collections.Add(CreateMotorsCollection(hardwareVersion)); + Collections.Add(CreateDancerCollection(hardwareVersion)); + Collections.Add(CreatePidCollection(hardwareVersion)); + Collections.Add(CreateWindersCollection(hardwareVersion)); + Collections.Add(CreateSpeedSensorsCollection(hardwareVersion)); + Collections.Add(CreateBlowersCollection(hardwareVersion)); + Collections.Add(CreateBreakSensorCollection(hardwareVersion)); + } } private HardwareCollection CreateMotorsCollection(HardwareVersion hardwareVersion) diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index 7b6ae7ef0..8b0401dc7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -228,6 +228,11 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// </summary> public RelayCommand ResetDeviceRegistrationCommand { get; set; } + /// <summary> + /// Gets or sets the make prototype command. + /// </summary> + public RelayCommand MakePrototypeCommand { get; set; } + #endregion #region Constructors @@ -261,6 +266,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels RemoveSpoolCommand = new RelayCommand(RemoveSpool, () => SelectedSpool != null); CloneMachineCommand = new RelayCommand(CloneMachine, () => SelectedMachine != null); ResetDeviceRegistrationCommand = new RelayCommand(ResetDeviceRegistration); + MakePrototypeCommand = new RelayCommand(MakePrototype); MachineUpdatesViewVM = new MachineUpdatesViewVM(_notification); TupViewVM = new TupViewVM(_notification); @@ -470,6 +476,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels ActiveMachineAdapter.MachineVersions = (await ActiveMachineAdapter.Context.MachineVersions.ToListAsync()).ToObservableCollection(); ActiveMachineAdapter.Organizations = (await ActiveMachineAdapter.Context.Organizations.ToListAsync()).ToObservableCollection(); + bool initHwConfig = true; + if (!newMachine) { ActiveMachine = (await new MachineBuilder(ActiveMachineAdapter.Context).Set(SelectedMachine.Guid).WithOrganization().WithConfiguration().WithSpools().BuildAsync()); @@ -500,8 +508,22 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels } else { - ActiveMachine = selectedVersion.CreatePrototypeMachine(ActiveMachineAdapter.Context); - ActiveMachineAdapter.Context.Machines.Add(ActiveMachine); + try + { + initHwConfig = false; + ActiveMachine = selectedVersion.CreatePrototypeMachine(ActiveMachineAdapter.Context); + ActiveMachineAdapter.Context.Machines.Add(ActiveMachine); + + HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification); + var version = await new HardwareVersionBuilder(ActiveMachineAdapter.Context).Set(ActiveMachine.Configuration.HardwareVersionGuid).WithHardwareComponents().BuildAsync(); + HardwareConfigurationViewVM.Init(ActiveMachine.Configuration); + } + catch (Exception ex) + { + _notification.ShowError($"Invalid machine version prototype.\n{ex.FlattenMessage()}"); + View.NavigateTo(MachineDesignerNavigationView.MachinesView); + return; + } } } @@ -516,8 +538,11 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels SelectedRML = ActiveMachineAdapter.Rmls.FirstOrDefault(), }; - HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification); - HardwareConfigurationViewVM.Init(ActiveMachine.Configuration); + if (initHwConfig) + { + HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification); + HardwareConfigurationViewVM.Init(ActiveMachine.Configuration); + } await MachineUpdatesViewVM.Init(ActiveMachine, ActiveMachineAdapter.Context); TupViewVM.Init(ActiveMachine); @@ -549,6 +574,11 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { try { + if (HardwareConfigurationViewVM == null) + { + HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification); + } + version = await new HardwareVersionBuilder(ActiveMachineAdapter.Context).Set(version.Guid).WithHardwareComponents().BuildAsync(); HardwareConfigurationViewVM.Init(ActiveMachine.Configuration); } @@ -775,6 +805,41 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels } } + private async void MakePrototype() + { + if (ActiveMachine.MachineVersion == null) + { + _notification.ShowError("Machine version must be selected in order to make a prototype."); + return; + } + + if (_notification.ShowQuestion($"Are you sure you wish to make this machine configuration as a prototype for version '{ActiveMachine.MachineVersion.Name}' ?")) + { + using (_notification.PushTaskItem($"Making prototype machine for '{ActiveMachine.MachineVersion.Name}'...")) + { + try + { + IsFree = false; + + using (var db = ObservablesContext.CreateDefault()) + { + var machineVersion = await db.MachineVersions.SingleOrDefaultAsync(x => x.Guid == ActiveMachine.MachineVersionGuid); + await machineVersion.ApplyPrototypeMachine(ActiveMachine, db); + await db.SaveChangesAsync(); + } + } + catch (Exception ex) + { + _notification.ShowError($"Error making machine version prototype\n{ex.FlattenMessage()}"); + } + finally + { + IsFree = true; + } + } + } + } + #endregion private void CloneMachine() diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineDetailsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineDetailsView.xaml index bcca83ca5..b3cef3083 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineDetailsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineDetailsView.xaml @@ -23,7 +23,7 @@ </StackPanel> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0 0 20 0"> - <Button Width="170" Height="45" VerticalAlignment="Center" Command="{Binding SaveCommand}"> + <Button Width="170" Height="45" VerticalAlignment="Center" Command="{Binding SaveCommand}"> <StackPanel Orientation="Horizontal"> <materialDesign:PackIcon Kind="ContentSaveAll" Width="24" Height="24" /> <TextBlock VerticalAlignment="Center" Margin="10 0 0 0">SAVE</TextBlock> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml index 4631ac068..499d6dc89 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml @@ -35,28 +35,39 @@ <ColumnDefinition Width="Auto" /> <ColumnDefinition/> </Grid.ColumnDefinitions> - <controls:TableGrid RowHeight="50" Margin="10"> - <TextBlock FontWeight="SemiBold">Serial Number</TextBlock> - <TextBox Text="{Binding ActiveMachine.SerialNumber}"></TextBox> - <TextBlock FontWeight="SemiBold">Name</TextBlock> - <TextBox Text="{Binding ActiveMachine.Name}"></TextBox> + <StackPanel> + <controls:TableGrid RowHeight="50" Margin="10"> + <TextBlock FontWeight="SemiBold">Serial Number</TextBlock> + <TextBox Text="{Binding ActiveMachine.SerialNumber}"></TextBox> - <TextBlock FontWeight="SemiBold">Machine Version</TextBlock> - <ComboBox Background="Transparent" ItemsSource="{Binding ActiveMachineAdapter.MachineVersions}" SelectedItem="{Binding ActiveMachine.MachineVersion}" DisplayMemberPath="Name" Style="{StaticResource TransparentComboBoxStyle}"></ComboBox> + <TextBlock FontWeight="SemiBold">Name</TextBlock> + <TextBox Text="{Binding ActiveMachine.Name}"></TextBox> - <TextBlock FontWeight="SemiBold">Organization</TextBlock> - <ComboBox Background="Transparent" ItemsSource="{Binding ActiveMachineAdapter.Organizations}" SelectedItem="{Binding ActiveMachine.Organization}" DisplayMemberPath="Name" Style="{StaticResource TransparentComboBoxStyle}"></ComboBox> + <TextBlock FontWeight="SemiBold">Machine Version</TextBlock> + <ComboBox Background="Transparent" ItemsSource="{Binding ActiveMachineAdapter.MachineVersions}" SelectedItem="{Binding ActiveMachine.MachineVersion}" DisplayMemberPath="Name" Style="{StaticResource TransparentComboBoxStyle}"></ComboBox> - <TextBlock FontWeight="SemiBold">Site</TextBlock> - <ComboBox Background="Transparent" ItemsSource="{Binding Sites}" SelectedItem="{Binding SelectedSite}" DisplayMemberPath="Name" Style="{StaticResource TransparentComboBoxStyle}"></ComboBox> + <TextBlock FontWeight="SemiBold">Organization</TextBlock> + <ComboBox Background="Transparent" ItemsSource="{Binding ActiveMachineAdapter.Organizations}" SelectedItem="{Binding ActiveMachine.Organization}" DisplayMemberPath="Name" Style="{StaticResource TransparentComboBoxStyle}"></ComboBox> - <TextBlock FontWeight="SemiBold">OS Key</TextBlock> - <TextBox Text="{Binding ActiveMachine.OsKey}"></TextBox> + <TextBlock FontWeight="SemiBold">Site</TextBlock> + <ComboBox Background="Transparent" ItemsSource="{Binding Sites}" SelectedItem="{Binding SelectedSite}" DisplayMemberPath="Name" Style="{StaticResource TransparentComboBoxStyle}"></ComboBox> + + <TextBlock FontWeight="SemiBold">OS Key</TextBlock> + <TextBox Text="{Binding ActiveMachine.OsKey}"></TextBox> + + <TextBlock FontWeight="SemiBold">Device COM Port</TextBlock> + <TextBox Text="{Binding ActiveMachine.DeviceComPort}"></TextBox> + </controls:TableGrid> + + <Button Margin="0 20 0 0" Background="{StaticResource RedBrush300}" ToolTip="Make this machine configuration as a prototype for the selected machine version" BorderBrush="{StaticResource RedBrush300}" Width="200" Height="45" VerticalAlignment="Bottom" Command="{Binding MakePrototypeCommand}"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Kind="Copyright" Width="24" Height="24" /> + <TextBlock VerticalAlignment="Center" Margin="10 0 0 0">MAKE PROTOTYPE</TextBlock> + </StackPanel> + </Button> + </StackPanel> - <TextBlock FontWeight="SemiBold">Device COM Port</TextBlock> - <TextBox Text="{Binding ActiveMachine.DeviceComPort}"></TextBox> - </controls:TableGrid> <Rectangle Grid.Column="1" StrokeThickness="1" Stroke="{StaticResource borderBrush}" HorizontalAlignment="Center" Margin="50 50" /> <controls:TableGrid RowHeight="50" Margin="10" Grid.Column="2"> <TextBlock FontWeight="SemiBold">Auto Login</TextBlock> @@ -109,7 +120,7 @@ </TextBlock> </StackPanel> - <Button Command="{Binding ResetDeviceRegistrationCommand}" HorizontalAlignment="Center" VerticalAlignment="Center" Background="{StaticResource RedBrush300}" BorderBrush="{StaticResource RedBrush300}" Padding="10" Height="Auto">RESET DEVICE REGISTRATION</Button> + <Button Command="{Binding ResetDeviceRegistrationCommand}" HorizontalAlignment="Center" VerticalAlignment="Center" Background="{StaticResource RedBrush300}" BorderBrush="{StaticResource RedBrush300}" Padding="10" Height="45" Width="240">RESET DEVICE REGISTRATION</Button> </DockPanel> </Border> </StackPanel> |
