aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Models/HardwareParameter.cs
blob: 33dbcad7194c2bd3bed244c7251e7b75709d97c8 (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
122
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.Commands;

namespace Tango.MachineStudio.MachineDesigner.Models
{
    public class HardwareParameter : ExtendedObject
    {
        public event EventHandler Selected;

        public HardwareComponent Component { get; set; }

        public RelayCommand DeleteCommand { get; set; }

        public String PropertyName { get; set; }

        private Object _defaultValue;
        public Object DefaultValue
        {
            get { return _defaultValue; }
            set
            {
                _defaultValue = value;
            }
        }

        public Type Type
        {
            get { return DefaultValue.GetType(); }
        }
        // updated after editing
        private Object _actualValue = null;
        public Object ActualValue
        {
            get { return _actualValue; }
            set
            {
                _actualValue = value;
                RaisePropertyChangedAuto();
                RaisePropertyChanged(nameof(IsDifferent));
                RaisePropertyChanged(nameof(IsValuesMatched));
            }
        }

        // displayed during  editing
        private Object _editableValue = null;
        public Object EditableValue
        {
            get { return _editableValue; }
            set
            {
                _editableValue = value;
                RaisePropertyChangedAuto();
            }
        }

        private bool _isSelected;
        public bool IsSelected
        {
            get { return _isSelected; }
            set
            {
                _isSelected = value;

                OnIsSelectedChanged();

                RaisePropertyChangedAuto();
                if (_isSelected)
                {
                    Selected?.Invoke(this, new EventArgs());
                }
            }
        }


        private void OnIsSelectedChanged()
        {
            if (IsSelected)
            {
                EditableValue = ActualValue != null ? ActualValue : DefaultValue;
            }
            else
            {
                if (EditableValue != null)
                {
                    ActualValue = EditableValue;
                }
            }
        }

        public bool IsDifferent
        {
            get
            {
                return (ActualValue != null);
            }
        }

        public bool IsValuesMatched
        {
            get
            {
                return ActualValue != null && ActualValue.ToString() == DefaultValue.ToString();
            }
        }

        public void DeleteValue()
        {
            ActualValue = null;
            EditableValue = null;
        }

        public HardwareParameter()
        {
            DeleteCommand = new RelayCommand(DeleteValue);
        }
    }
}