-
Notifications
You must be signed in to change notification settings - Fork 11
/
UISlider.cs
158 lines (130 loc) · 4.04 KB
/
UISlider.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
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 System.Linq;
using Newtonsoft.Json;
namespace NodeModelsEssentials
{
[NodeName("UI.Slider")]
[NodeDescription("A sample Node Model with custom Wpf UI.")]
[NodeCategory("NodeModelsEssentials")]
[OutPortNames(">")]
[OutPortTypes("double")]
[OutPortDescriptions("Double")]
[IsDesignScriptCompatible]
public class CustomUIWpfNodeModel : NodeModel
{
#region private members
private double number;
private double maximumValue;
private double minimumValue;
private double step;
#endregion
#region properties
[IsVisibleInDynamoLibrary(false)]
public DelegateCommand IncreaseCommand { get; set; }
[IsVisibleInDynamoLibrary(false)]
public DelegateCommand DecreaseCommand { get; set; }
public double MinimumValue
{
get { return minimumValue; }
set
{
minimumValue = value;
RaisePropertyChanged("MinimumValue");
}
}
public double MaximumValue
{
get { return maximumValue; }
set
{
maximumValue = value;
RaisePropertyChanged("MaximumValue");
}
}
public double Number
{
get { return number; }
set
{
number = Math.Round(value, 2); ;
RaisePropertyChanged("Number");
OnNodeModified();
}
}
#endregion
#region constructor
[JsonConstructor]
private CustomUIWpfNodeModel(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
{
}
public CustomUIWpfNodeModel()
{
RegisterAllPorts();
IncreaseCommand = new DelegateCommand(IncreaseNumber);
DecreaseCommand = new DelegateCommand(DecreaseNumber);
MinimumValue = 0.0;
MaximumValue = 100.0;
step = 10.0;
}
#endregion
#region public methods
[IsVisibleInDynamoLibrary(false)]
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAsNodes)
{
var doubleNode = AstFactory.BuildDoubleNode(number);
//var funcNode = AstFactory.BuildFunctionCall(
// new Func<double, double, double>(NodeModelsEssentialsFunctions.Multiply),
// new List<AssociativeNode>() { doubleNode, doubleNode }
// );
return new[]
{
AstFactory.BuildAssignment(
GetAstIdentifierForOutputIndex(0), doubleNode)
};
}
#endregion
#region command methods
private void IncreaseNumber(object obj)
{
if (Number + step >= MaximumValue)
{
Number = MaximumValue;
} else
{
Number += step;
}
}
private void DecreaseNumber(object obj)
{
if (Number - step <= MinimumValue)
{
Number = MinimumValue;
} else
{
Number += -step;
}
}
#endregion
}
/// <summary>
/// View customizer for CustomUINodeModel Node Model.
/// </summary>
public class CustomUIWpfNodeModelViewCustomization : INodeViewCustomization<CustomUIWpfNodeModel>
{
public void CustomizeView(CustomUIWpfNodeModel model, NodeView nodeView)
{
var myFirstDynamoControl = new MyFirstDynamoControl();
nodeView.inputGrid.Children.Add(myFirstDynamoControl);
myFirstDynamoControl.DataContext = model;
}
public void Dispose() { }
}
}