aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
blob: 06a3c9ba4b3739ea1c64d2b0a2f9e7c93d977fec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
using Tango.Integration.Observables;
using Tango.SharedUI;

namespace Tango.MachineStudio.HardwareDesigner.ViewModels
{
    public class MainViewVM : ViewModel
    {
        private ObservablesEntitiesAdapter _adapter;
        public ObservablesEntitiesAdapter Adapter
        {
            get { return _adapter; }
            set { _adapter = value; RaisePropertyChangedAuto(); }
        }

        private HardwareVersion _selectedVersion;
        public HardwareVersion SelectedVersion
        {
            get { return _selectedVersion; }
            set { _selectedVersion = value; RaisePropertyChangedAuto(); OnSelectedVersionChanged(); }
        }

        private HardwareVersion _currentVersion;
        public HardwareVersion CurrentVersion
        {
            get { return _currentVersion; }
            set { _currentVersion = value; RaisePropertyChangedAuto(); }
        }

        public RelayCommand SaveCommand { get; set; }

        public MainViewVM()
        {
            Adapter = ObservablesEntitiesAdapter.Instance;

            SaveCommand = new RelayCommand(Save);
        }

        private void OnSelectedVersionChanged()
        {
            CurrentVersion = SelectedVersion.Clone();
        }

        public void OnRemoveDancer(HardwareDancer dancer)
        {
            CurrentVersion.HardwareDancers.Remove(dancer);
        }

        public void OnRemoveMotor(HardwareMotor motor)
        {
            CurrentVersion.HardwareMotors.Remove(motor);
        }

        public void OnRemovePidControl(HardwarePidControl pidControl)
        {
            CurrentVersion.HardwarePidControls.Remove(pidControl);
        }

        public void OnMotorDrop(HardwareMotorType motorType)
        {
            if (!CurrentVersion.HardwareMotors.ToList().Exists(x => x.HardwareMotorType == motorType))
            {
                CurrentVersion.HardwareMotors.Add(new HardwareMotor() { HardwareMotorType = motorType });
            }
        }

        public void OnDropDancer(HardwareDancerType dancerType)
        {
            if (!CurrentVersion.HardwareDancers.ToList().Exists(x => x.HardwareDancerType == dancerType))
            {
                CurrentVersion.HardwareDancers.Add(new HardwareDancer() { HardwareDancerType = dancerType });
            }
        }

        public void OnDropPidControl(HardwarePidControlType pidControlType)
        {
            if (!CurrentVersion.HardwarePidControls.ToList().Exists(x => x.HardwarePidControlType == pidControlType))
            {
                CurrentVersion.HardwarePidControls.Add(new HardwarePidControl() { HardwarePidControlType = pidControlType });
            }
        }

        private void Save()
        {
            if (CurrentVersion != null)
            {

            }
        }
    }
}