aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs275
1 files changed, 250 insertions, 25 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
index 9e108d0a8..b7e7859ac 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
@@ -1,18 +1,23 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows.Data;
using Tango.BL;
using Tango.BL.Builders;
using Tango.BL.Entities;
+using Tango.Core.Commands;
+using Tango.MachineStudio.ColorLab.ViewModels;
using Tango.MachineStudio.Common;
using Tango.MachineStudio.Common.Notifications;
+using Tango.MachineStudio.RML.Contracts;
namespace Tango.MachineStudio.RML.ViewModels
{
- public class MainViewVM : StudioViewModel
+ public class MainViewVM : StudioViewModel<IMainView>
{
private INotificationProvider _notification;
@@ -26,11 +31,60 @@ namespace Tango.MachineStudio.RML.ViewModels
set { _rmls = value; RaisePropertyChangedAuto(); }
}
+ private ObservableCollection<MediaMaterial> _materials;
+ public ObservableCollection<MediaMaterial> Materials
+ {
+ get { return _materials; }
+ set { _materials = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ObservableCollection<MediaColor> _colors;
+ public ObservableCollection<MediaColor> Colors
+ {
+ get { return _colors; }
+ set { _colors = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ObservableCollection<MediaPurpos> _purposes;
+ public ObservableCollection<MediaPurpos> Purposes
+ {
+ get { return _purposes; }
+ set { _purposes = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ObservableCollection<MediaCondition> _conditions;
+ public ObservableCollection<MediaCondition> Conditions
+ {
+ get { return _conditions; }
+ set { _conditions = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ObservableCollection<LinearMassDensityUnit> _linearMassDensityUnits;
+ public ObservableCollection<LinearMassDensityUnit> LinearMassDensityUnits
+ {
+ get { return _linearMassDensityUnits; }
+ set { _linearMassDensityUnits = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ObservableCollection<FiberShape> _fiberShapes;
+ public ObservableCollection<FiberShape> FiberShapes
+ {
+ get { return _fiberShapes; }
+ set { _fiberShapes = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ObservableCollection<FiberSynth> _fiberSynths;
+ public ObservableCollection<FiberSynth> FiberSynths
+ {
+ get { return _fiberSynths; }
+ set { _fiberSynths = value; RaisePropertyChangedAuto(); }
+ }
+
private Rml _selectedRML;
public Rml SelectedRML
{
get { return _selectedRML; }
- set { _selectedRML = value; RaisePropertyChangedAuto(); OnSelectedRmlChanged(); }
+ set { _selectedRML = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
private Rml _activeRML;
@@ -40,9 +94,65 @@ namespace Tango.MachineStudio.RML.ViewModels
set { _activeRML = value; RaisePropertyChangedAuto(); }
}
+ private CalibrationDataViewVM _calibrationDataViewVM;
+ public CalibrationDataViewVM CalibrationDataViewVM
+ {
+ get { return _calibrationDataViewVM; }
+ set { _calibrationDataViewVM = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ObservableCollection<LiquidTypesRml> _liquidTypesRmls;
+ public ObservableCollection<LiquidTypesRml> LiquidTypesRmls
+ {
+ get { return _liquidTypesRmls; }
+ set { _liquidTypesRmls = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ProcessParametersTablesGroup _activeProcessParametersGroup;
+ public ProcessParametersTablesGroup ActiveProcessParametersGroup
+ {
+ get { return _activeProcessParametersGroup; }
+ set { _activeProcessParametersGroup = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ICollectionView _activeProcessParametersTableView;
+ public ICollectionView ActiveProcessParametersTableView
+ {
+ get { return _activeProcessParametersTableView; }
+ set { _activeProcessParametersTableView = value; RaisePropertyChangedAuto(); }
+ }
+
+
+ /// <summary>
+ /// Gets or sets the manage RML command.
+ /// </summary>
+ public RelayCommand ManageRmlCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the add RML command.
+ /// </summary>
+ public RelayCommand AddRmlCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the remove RML command.
+ /// </summary>
+ public RelayCommand RemoveRmlCommand { get; set; }
+
+ public RelayCommand AddProcessParametersTableCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the back to RMLS command.
+ /// </summary>
+ public RelayCommand BackToRmlsCommand { get; set; }
+
public MainViewVM(INotificationProvider notificationProvider)
{
_notification = notificationProvider;
+ ManageRmlCommand = new RelayCommand(() => LoadActiveRML(SelectedRML.Guid), () => SelectedRML != null);
+ RemoveRmlCommand = new RelayCommand(RemoveSelectedRml);
+ AddRmlCommand = new RelayCommand(AddNewRml);
+ BackToRmlsCommand = new RelayCommand(BackToRmls);
+ AddProcessParametersTableCommand = new RelayCommand(AddProcessParametersTable);
}
public override void OnApplicationReady()
@@ -52,36 +162,21 @@ namespace Tango.MachineStudio.RML.ViewModels
private async void LoadRmls()
{
- //using (_rmls_context = ObservablesContext.CreateDefault())
- //{
- // await Task.Factory.StartNew(() =>
- // {
- // Rmls = _rmls.ToList().ToObservableCollection();
- // });
- //}
- }
-
- private void OnSelectedRmlChanged()
- {
- if (SelectedRML != null)
- {
- LoadActiveRML(SelectedRML.Guid);
- }
- else
+ using (_rmls_context = ObservablesContext.CreateDefault())
{
- UnloadActiveRML();
+ await Task.Factory.StartNew(() =>
+ {
+ Rmls = _rmls_context.Rmls.ToList().ToObservableCollection();
+ });
}
}
- private void UnloadActiveRML()
- {
- ActiveRML = null;
- }
-
private async void LoadActiveRML(String guid)
{
using (_notification.PushTaskItem("Loading RML..."))
{
+ IsFree = false;
+
if (_active_context != null)
{
_active_context.Dispose();
@@ -89,12 +184,142 @@ namespace Tango.MachineStudio.RML.ViewModels
_active_context = ObservablesContext.CreateDefault();
+ LoadRmlProperties();
+
ActiveRML = await new RmlBuilder(_active_context)
.Set(guid)
- .WithAllParametersGroup()
+ .WithActiveParametersGroup()
.WithLiquidFactors()
+ .WithMediaProperties()
.BuildAsync();
+
+ ActiveProcessParametersGroup = ActiveRML.ProcessParametersTablesGroups.ToList().FirstOrDefault();
+ ActiveProcessParametersTableView = CollectionViewSource.GetDefaultView(ActiveProcessParametersGroup.ProcessParametersTables);
+ ActiveProcessParametersTableView.SortDescriptions.Add(new SortDescription(nameof(ProcessParametersTable.TableIndex), ListSortDirection.Ascending));
+
+ CalibrationDataViewVM = new CalibrationDataViewVM();
+ LiquidTypesRmls = ActiveRML.LiquidTypesRmls;
+
+ foreach (var liquidTypeRml in LiquidTypesRmls)
+ {
+ CalibrationDataVM catVM = new CalibrationDataVM();
+ catVM.Name = liquidTypeRml.LiquidType.Name;
+ catVM.Color = liquidTypeRml.LiquidType.Color;
+
+ if (liquidTypeRml.DefaultCatData != null)
+ {
+ catVM.CalibrationPoints = liquidTypeRml.GetCalibrationData().CalibrationPoints.Select(x => new CalibrationDataPointVM(x.X, x.Y)).ToObservableCollection();
+ }
+
+ CalibrationDataViewVM.LiquidsCalibrationData.Add(catVM);
+ }
+
+
+ View.NavigateTo(RmlNavigationView.RmlView);
+
+ IsFree = true;
}
}
+
+ private void LoadRmlProperties()
+ {
+ Materials = _active_context.MediaMaterials.ToObservableCollection();
+ Colors = _active_context.MediaColors.ToObservableCollection();
+ Purposes = _active_context.MediaPurposes.ToObservableCollection();
+ Conditions = _active_context.MediaConditions.ToObservableCollection();
+ LinearMassDensityUnits = _active_context.LinearMassDensityUnits.ToObservableCollection();
+ FiberShapes = _active_context.FiberShapes.ToObservableCollection();
+ FiberSynths = _active_context.FiberSynths.ToObservableCollection();
+ }
+
+ private async void AddNewRml()
+ {
+ var name = _notification.ShowTextInput("Please enter RML name", "Name");
+
+ if (!String.IsNullOrWhiteSpace(name))
+ {
+ if (Rmls.ToList().Exists(x => x.Name == name))
+ {
+ _notification.ShowError("The specified RML name already exists. Please select a different name.");
+ return;
+ }
+
+ using (_notification.PushTaskItem("Creating new RML..."))
+ {
+ IsFree = false;
+
+ if (_active_context != null)
+ {
+ _active_context.Dispose();
+ }
+
+ LoadRmlProperties();
+
+ Rml rml = new Rml();
+ rml.Name = name;
+ rml.Manufacturer = "Twine";
+ rml.Code = Rmls.Max(x => x.Code) + 1;
+ rml.MediaMaterial = Materials.FirstOrDefault();
+ rml.MediaColor = Colors.FirstOrDefault();
+ rml.MediaPurpose = Purposes.FirstOrDefault();
+ rml.MediaCondition = Conditions.FirstOrDefault();
+ rml.LinearMassDensityUnit = LinearMassDensityUnits.FirstOrDefault();
+ rml.FiberShape = FiberShapes.FirstOrDefault();
+ rml.FiberSynth = FiberSynths.FirstOrDefault();
+ _active_context.Rmls.Add(rml);
+ await _active_context.SaveChangesAsync();
+ LoadActiveRML(rml.Guid);
+
+ IsFree = true;
+ }
+ }
+ }
+
+ private void RemoveSelectedRml()
+ {
+
+ }
+
+ private void AddProcessParametersTable()
+ {
+ var name = _notification.ShowTextInput("Enter table name", "Name");
+
+ if (!String.IsNullOrWhiteSpace(name))
+ {
+ _active_context.ProcessParametersTables.Add(new ProcessParametersTable()
+ {
+ ProcessParametersTablesGroup = ActiveProcessParametersGroup,
+ Name = name,
+ TableIndex = ActiveProcessParametersGroup.ProcessParametersTables.Max(x => x.TableIndex) + 1,
+ });
+ }
+ }
+
+ public void OnProcessParametersTableDropped(ProcessParametersTable dragged, ProcessParametersTable dropped)
+ {
+ if (dragged.TableIndex > dropped.TableIndex)
+ {
+ dragged.TableIndex = dropped.TableIndex - 1;
+ }
+ else
+ {
+ dragged.TableIndex = dropped.TableIndex + 1;
+ }
+
+ int index = 0;
+
+ foreach (var table in ActiveProcessParametersGroup.ProcessParametersTables.OrderBy(x => x.TableIndex))
+ {
+ table.TableIndex = index++;
+ }
+
+ ActiveProcessParametersTableView.Refresh();
+ }
+
+ private void BackToRmls()
+ {
+ View.NavigateTo(RmlNavigationView.RmlsView);
+ LoadRmls();
+ }
}
}