aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-01-20 13:11:40 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-01-20 13:11:40 +0200
commita4761335999936b8e1bd0091861b3b08ad3f6343 (patch)
tree821921b5c00f49278c0f47e2826d2c41ec3821a4 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels
parentcec1b3dc168db7dd87e288f07ab403407692978b (diff)
downloadTango-a4761335999936b8e1bd0091861b3b08ad3f6343.tar.gz
Tango-a4761335999936b8e1bd0091861b3b08ad3f6343.zip
Fixed main menu style.
Fixed issues with machine prototype creation. Implemented "make prototype".
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/HardwareConfigurationViewVM.cs21
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs73
2 files changed, 81 insertions, 13 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()