aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs23
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs155
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineCreationDialog.xaml16
3 files changed, 30 insertions, 164 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs
index 4584d3508..340f92edd 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs
@@ -10,9 +10,9 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
{
public class MachineCreationDialogVM : DialogViewVM
{
- public List<MachineVersion> MachineVersions { get; set; }
+ public List<MachinePrototype> Prototypes { get; set; }
- public MachineVersion SelectedMachineVersion { get; set; }
+ public MachinePrototype SelectedPrototype { get; set; }
private bool _isNewMachine;
public bool IsNewMachine
@@ -35,25 +35,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
set { _name = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
- private bool _generateDispensers;
- public bool GenerateDispensers
- {
- get { return _generateDispensers; }
- set { _generateDispensers = value; RaisePropertyChangedAuto(); }
- }
-
- private double _dispenserFactor;
- public double DispenserFactor
- {
- get { return _dispenserFactor; }
- set { _dispenserFactor = value; RaisePropertyChangedAuto(); }
- }
-
- public MachineCreationDialogVM() : base()
- {
- DispenserFactor = 2.34;
- }
-
protected override bool CanOK()
{
return base.CanOK() && !String.IsNullOrWhiteSpace(SerialNumber) && !String.IsNullOrWhiteSpace(Name);
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 dc29515c8..6ddf86ddb 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
@@ -287,7 +287,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
public override async void OnApplicationReady()
{
MachinesAdapter.MachineVersions = (await MachinesAdapter.Context.MachineVersions.ToListAsync()).ToObservableCollection();
-
+ MachinesAdapter.MachinePrototypes = (await MachinesAdapter.Context.MachinePrototypes.ToListAsync()).ToObservableCollection();
}
#endregion
@@ -513,7 +513,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
{
IsNewMachine = true;
- if (machineCreationDialogVM.SelectedMachineVersion == null)
+ if (machineCreationDialogVM.SelectedPrototype == null)
{
ActiveMachine = new Machine();
ActiveMachine.Configuration = new Configuration();
@@ -526,9 +526,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
try
{
initHwConfig = false;
- ActiveMachine = await machineCreationDialogVM.SelectedMachineVersion.CreatePrototypeMachine(ActiveMachineAdapter.Context);
- ActiveMachine.SerialNumber = machineCreationDialogVM.SerialNumber;
- ActiveMachine.Name = machineCreationDialogVM.Name;
+ ActiveMachine = machineCreationDialogVM.SelectedPrototype.CreateMachine(machineCreationDialogVM.SerialNumber, machineCreationDialogVM.Name);
+ ActiveMachine.MachineVersion = ActiveMachineAdapter.MachineVersions.FirstOrDefault(x => x.Guid == ActiveMachine.MachineVersionGuid);
ActiveMachineAdapter.Context.Machines.Add(ActiveMachine);
HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification);
@@ -537,105 +536,13 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
}
catch (Exception ex)
{
- _notification.ShowError($"Invalid machine version prototype.\n{ex.FlattenMessage()}");
+ _notification.ShowError($"Invalid machine prototype.\n{ex.FlattenMessage()}");
View.NavigateTo(MachineDesignerNavigationView.MachinesView);
return;
}
}
}
- if ((newMachine || clone) && machineCreationDialogVM.GenerateDispensers)
- {
- for (int i = 0; i < 10; i++)
- {
- var serial = machineCreationDialogVM.SerialNumber + "-" + (i + 1);
-
- var existingDispenser = await ActiveMachineAdapter.Context.Dispensers.Include(x => x.IdsPacks).SingleOrDefaultAsync(x => x.SerialNumber == serial);
-
- if (existingDispenser != null)
- {
- if (existingDispenser.IsInstalled)
- {
- _notification.ShowError($"Dispenser '{serial}' already exists. Cannot create machine.");
- return;
- }
- else
- {
- if (!_notification.ShowErrorQuestion($"Dispenser '{serial}' already exists and is not installed. Do you wish to assign the existing dispenser to this machine?"))
- {
- return;
- }
- }
- }
-
- Dispenser dispenser = new Dispenser();
-
- if (existingDispenser == null)
- {
- dispenser.SerialNumber = serial;
-
- if (newMachine)
- {
- dispenser.NlPerPulse = machineCreationDialogVM.DispenserFactor;
-
- if (i == 8)
- {
- dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.LubricantDispenser.ToInt32()).Guid;
- }
- else if (i == 9)
- {
- dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.CleanerDispenser.ToInt32()).Guid;
- }
- else
- {
- dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.StandardDispenser.ToInt32()).Guid;
- }
- }
- else
- {
- var packBefore = machineConfigBeforeClone.NoneEmptyIdsPacks.SingleOrDefault(x => x.PackIndex == i);
-
- if (packBefore != null)
- {
- dispenser.NlPerPulse = packBefore.Dispenser.NlPerPulse;
-
- if (i == 8)
- {
- dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.LubricantDispenser.ToInt32()).Guid;
- }
- else if (i == 9)
- {
- dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.CleanerDispenser.ToInt32()).Guid;
- }
- else
- {
- dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.StandardDispenser.ToInt32()).Guid;
- }
- }
- else
- {
- continue;
- }
- }
-
- dispenser.ProductionDate = DateTime.UtcNow;
-
- ActiveMachineAdapter.Context.Dispensers.Add(dispenser);
- }
- else
- {
- dispenser = existingDispenser;
- }
-
- var idsPack = ActiveMachine.Configuration.NoneEmptyIdsPacks.SingleOrDefault(x => x.PackIndex == i);
-
- if (idsPack != null)
- {
- idsPack.Dispenser = dispenser;
- idsPack.DispenserGuid = dispenser.Guid;
- }
- }
- }
ActiveMachine.OrganizationChanged -= ActiveMachine_OrganizationChanged;
ActiveMachine.OrganizationChanged += ActiveMachine_OrganizationChanged;
@@ -888,7 +795,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
{
MachineCreationDialogVM vm = new MachineCreationDialogVM();
vm.IsNewMachine = true;
- vm.MachineVersions = MachinesAdapter.MachineVersions.ToList();
+ vm.Prototypes = MachinesAdapter.MachinePrototypes.ToList();
_notification.ShowModalDialog<MachineCreationDialogVM, Views.MachineCreationDialog>(vm, (x) =>
{
if (MachinesAdapter.Context.Machines.Any(y => y.SerialNumber == vm.SerialNumber || y.Name.ToLower() == vm.Name.ToLower()))
@@ -897,12 +804,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
return;
}
- if (vm.SelectedMachineVersion != null && String.IsNullOrWhiteSpace(vm.SelectedMachineVersion.PrototypeMachineData))
- {
- _notification.ShowError("The selected version does not contain any prototype machine data.");
- return;
- }
-
LoadSelectedMachine(true, false, vm);
}, () => { });
}
@@ -946,36 +847,32 @@ 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;
- }
+ String protoName = _notification.ShowTextInput("Enter prototype name", "name");
+
+ if (!protoName.IsNotNullOrWhiteSpace()) 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($"Saving machine prototype '{protoName}'..."))
{
- using (_notification.PushTaskItem($"Making prototype machine for '{ActiveMachine.MachineVersion.Name}'..."))
+ try
{
- try
- {
- IsFree = false;
+ 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)
+ using (var db = ObservablesContext.CreateDefault())
{
- _notification.ShowError($"Error making machine version prototype\n{ex.FlattenMessage()}");
- }
- finally
- {
- IsFree = true;
+ MachinePrototype prototype = MachinePrototype.CreateNew(ActiveMachine, protoName, protoName);
+ db.MachinePrototypes.Add(prototype);
+ await db.SaveChangesAsync();
+ MachinesAdapter.MachinePrototypes = (await MachinesAdapter.Context.MachinePrototypes.ToListAsync()).ToObservableCollection();
}
}
+ catch (Exception ex)
+ {
+ _notification.ShowError($"Error creating machine prototype\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ IsFree = true;
+ }
}
}
@@ -985,7 +882,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
{
MachineCreationDialogVM vm = new MachineCreationDialogVM();
vm.IsNewMachine = false;
- vm.MachineVersions = MachinesAdapter.MachineVersions.ToList();
+ vm.Prototypes = MachinesAdapter.MachinePrototypes.ToList();
_notification.ShowModalDialog<MachineCreationDialogVM, Views.MachineCreationDialog>(vm, (x) =>
{
if (MachinesAdapter.Context.Machines.Any(y => y.SerialNumber == vm.SerialNumber || y.Name.ToLower() == vm.Name.ToLower()))
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineCreationDialog.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineCreationDialog.xaml
index 41e0fa685..f69606e29 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineCreationDialog.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineCreationDialog.xaml
@@ -52,28 +52,16 @@
<Grid>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20 20 0 0" Width="400">
<TextBlock TextWrapping="Wrap" Visibility="{Binding IsNewMachine,Converter={StaticResource BooleanToVisibilityConverter}}">
- <Run>Please specify the machine version in order to prototype the new machine with default machine settings and configuration.</Run>
+ <Run>Specify a machine prototype to create the new machine with default settings and configuration.</Run>
</TextBlock>
- <ComboBox Visibility="{Binding IsNewMachine,Converter={StaticResource BooleanToVisibilityConverter}}" ItemsSource="{Binding MachineVersions}" SelectedItem="{Binding SelectedMachineVersion}" DisplayMemberPath="Name" Margin="0 10 0 0" FontSize="16" materialDesign:HintAssist.Hint="NONE"></ComboBox>
+ <ComboBox Visibility="{Binding IsNewMachine,Converter={StaticResource BooleanToVisibilityConverter}}" ItemsSource="{Binding Prototypes}" SelectedItem="{Binding SelectedPrototype}" DisplayMemberPath="Name" Margin="0 10 0 0" FontSize="16" materialDesign:HintAssist.Hint="NONE"></ComboBox>
<TextBlock Margin="0 20 0 0" FontSize="10">Serial Number</TextBlock>
<TextBox Margin="0 2 0 0" Text="{Binding SerialNumber,UpdateSourceTrigger=PropertyChanged}"></TextBox>
<TextBlock Margin="0 20 0 0" FontSize="10">Name</TextBlock>
<TextBox Margin="0 2 0 0" Text="{Binding Name,UpdateSourceTrigger=PropertyChanged}"></TextBox>
-
- <CheckBox Margin="0 30 -200 0" IsChecked="{Binding GenerateDispensers}">
- <TextBlock>
- <Run>Automatically generate 10 dispensers for this machine</Run>
- <Run>(</Run><Run Foreground="{StaticResource GrayBrush}" FontSize="10" Text="{Binding SerialNumber}"></Run><Run Foreground="{StaticResource GrayBrush}" FontSize="10">-1-10</Run><Run>)</Run>
- </TextBlock>
- </CheckBox>
-
- <StackPanel Margin="20 10 0 0" Visibility="{Binding IsNewMachine,Converter={StaticResource BooleanToVisibilityConverter}}">
- <TextBlock FontSize="10">Dispenser max nl/cm</TextBlock>
- <mahapps:NumericUpDown Minimum="0" StringFormat="0.00" Maximum="10" InterceptMouseWheel="True" Value="{Binding DispenserFactor,Mode=TwoWay}" HorizontalContentAlignment="Left" Width="95" HorizontalAlignment="Left" BorderThickness="0 0 0 1" Margin="0 2 0 0" HideUpDownButtons="True" HasDecimals="True" Background="Transparent"></mahapps:NumericUpDown>
- </StackPanel>
</StackPanel>
</Grid>
</DockPanel>