-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathUISliderBound.cs
175 lines (142 loc) · 4.46 KB
/
UISliderBound.cs
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.Collections.Generic;
using Dynamo.Controls;
using Dynamo.Graph.Nodes;
using Dynamo.UI.Commands;
using Dynamo.Wpf;
using ProtoCore.AST.AssociativeAST;
using Autodesk.DesignScript.Runtime;
using NodeModelsEssentials.Controls;
using NodeModelsEssentials.Functions;
using System.Linq;
using Newtonsoft.Json;
namespace NodeModelsEssentials
{
[NodeName("UI.SliderBound")]
[NodeDescription("A sample Node Model with custom Wpf UI.")]
[NodeCategory("NodeModelsEssentials")]
[InPortNames("list")]
[InPortTypes("List<object>")]
[InPortDescriptions("A list of items.")]
[OutPortNames(">")]
[OutPortTypes("object")]
[OutPortDescriptions("Item")]
[IsDesignScriptCompatible]
public class CustomUINodeModelWpfSliderBound : NodeModel
{
#region private members
private int index;
private int maximumValue;
private int minimumValue;
private int step;
#endregion
#region properties
[IsVisibleInDynamoLibrary(false)]
public DelegateCommand IncreaseCommand { get; set; }
[IsVisibleInDynamoLibrary(false)]
public DelegateCommand DecreaseCommand { get; set; }
public int MinimumValue
{
get { return minimumValue; }
set
{
minimumValue = value;
RaisePropertyChanged("MinimumValue");
}
}
public int MaximumValue
{
get { return maximumValue; }
set
{
maximumValue = value;
RaisePropertyChanged("MaximumValue");
}
}
public int Index
{
get { return index; }
set
{
index = value;
//index = Math.Round(value, 2); ;
RaisePropertyChanged("Index");
OnNodeModified();
}
}
#endregion
#region constructor
[JsonConstructor]
private CustomUINodeModelWpfSliderBound(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
{
}
public CustomUINodeModelWpfSliderBound()
{
RegisterAllPorts();
IncreaseCommand = new DelegateCommand(IncreaseNumber);
DecreaseCommand = new DelegateCommand(DecreaseNumber);
MinimumValue = 0;
MaximumValue = 100;
step = 10;
index = 5;
}
#endregion
#region public methods
[IsVisibleInDynamoLibrary(false)]
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAsNodes)
{
if (!InPorts[0].Connectors.Any())
{
return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
}
var indexNode = AstFactory.BuildIntNode(index);
var funcNode = AstFactory.BuildFunctionCall(
new Func<List<object>, int, object>(NodeModelsEssentialsFunctions.GetItem),
new List<AssociativeNode>() { inputAsNodes[0], indexNode }
);
return new[]
{
AstFactory.BuildAssignment(
GetAstIdentifierForOutputIndex(0), funcNode)
};
}
#endregion
#region command methods
private void IncreaseNumber(object obj)
{
if (Index + step >= MaximumValue)
{
Index = MaximumValue;
}
else
{
Index += step;
}
}
private void DecreaseNumber(object obj)
{
if (Index - step <= MinimumValue)
{
Index = MinimumValue;
}
else
{
Index += -step;
}
}
#endregion
}
/// <summary>
/// View customizer for CustomUINodeModel Node Model.
/// </summary>
public class CustomUINodeModelWpfSliderBoundViewCustomization : INodeViewCustomization<CustomUINodeModelWpfSliderBound>
{
public void CustomizeView(CustomUINodeModelWpfSliderBound model, NodeView nodeView)
{
var mySliderBound = new SliderBound();
nodeView.inputGrid.Children.Add(mySliderBound);
mySliderBound.DataContext = model;
}
public void Dispose() { }
}
}