aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
blob: 4becc0b0427d7c42667a1ca8815db9a314a225f9 (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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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(); }
        }


        public MainViewVM()
        {
            Adapter = ObservablesEntitiesAdapter.Instance;
        }

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

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

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

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

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