aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
blob: 0da894aba6a575cd77bae47d3805a5969c9d7cc1 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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(); }
        }

        private ObservableCollection<MotorType> _currentVersionMotorTypes;
        public ObservableCollection<MotorType> CurrentVersionMotorTypes
        {
            get { return _currentVersionMotorTypes; }
            set { _currentVersionMotorTypes = value; RaisePropertyChangedAuto(); }
        }

        private ObservableCollection<DancerType> _currentVersionDancerTypes;
        public ObservableCollection<DancerType> CurrentVersionDancerTypes
        {
            get { return _currentVersionDancerTypes; }
            set { _currentVersionDancerTypes = value; RaisePropertyChangedAuto(); }
        }

        private ObservableCollection<PidControl> _currentVersionPidControls;
        public ObservableCollection<PidControl> CurrentVersionPidControls
        {
            get { return _currentVersionPidControls; }
            set { _currentVersionPidControls = value; RaisePropertyChangedAuto(); }
        }

        public RelayCommand SaveCommand { get; set; }

        public MainViewVM()
        {
            Adapter = ObservablesEntitiesAdapter.Instance;

            SaveCommand = new RelayCommand(Save);
        }

        private void OnSelectedVersionChanged()
        {
            CurrentVersion = SelectedVersion.Clone();
            CurrentVersionDancerTypes = CurrentVersion.HardwareVersionsDancerTypes.Select(x => x.DancerType).ToObservableCollection();
            CurrentVersionMotorTypes = CurrentVersion.HardwareVersionsMotorTypes.Select(x => x.MotorType).ToObservableCollection();
            CurrentVersionPidControls = CurrentVersion.HardwareVersionsPidControls.Select(x => x.PidControl).ToObservableCollection();
        }

        public void OnRemoveDancer(DancerType dancerType)
        {
            CurrentVersionDancerTypes.Remove(dancerType);
        }

        public void OnRemoveMotor(MotorType motorType)
        {
            CurrentVersionMotorTypes.Remove(motorType);
        }

        public void OnRemovePidControl(PidControl pidControl)
        {
            CurrentVersionPidControls.Remove(pidControl);
        }

        public void OnMotorDrop(MotorType motorType)
        {
            if (!CurrentVersionMotorTypes.Contains(motorType))
            {
                CurrentVersionMotorTypes.Add(motorType);
            }
        }

        public void OnDropDancer(DancerType dancerType)
        {
            if (!CurrentVersionDancerTypes.Contains(dancerType))
            {
                CurrentVersionDancerTypes.Add(dancerType);
            }
        }

        public void OnDropPidControl(PidControl pidControl)
        {
            if (!CurrentVersionPidControls.Contains(pidControl))
            {
                CurrentVersionPidControls.Add(pidControl);
            }
        }

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

            }
        }
    }
}