-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathDoubleSlider.cs
More file actions
206 lines (183 loc) · 6.6 KB
/
DoubleSlider.cs
File metadata and controls
206 lines (183 loc) · 6.6 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml;
using Autodesk.DesignScript.Runtime;
using Dynamo.Graph;
using Dynamo.Graph.Nodes;
using Dynamo.Migration;
using Newtonsoft.Json;
using ProtoCore.AST.AssociativeAST;
namespace CoreNodeModels.Input
{
[NodeName("Number Slider")]
[NodeCategory(BuiltinNodeCategories.CORE_INPUT)]
[NodeDescription("DoubleSliderNodeDescription", typeof(Properties.Resources))]
[NodeSearchTags("DoubleSliderSearchTags", typeof(Properties.Resources))]
[OutPortTypes("number")]
[SupressImportIntoVM]
[IsDesignScriptCompatible]
[AlsoKnownAs("DSCoreNodesUI.Input.DoubleSlider")]
public class DoubleSlider : SliderBase<double>
{
/// <summary>
/// The NodeType property provides a name which maps to the
/// server type for the node. This property should only be
/// used for serialization.
/// </summary>
public override string NodeType
{
get
{
return "NumberInputNode";
}
}
public string NumberType
{
get
{
return "Double";
}
}
public override NodeInputData InputData
{
get
{
return new NodeInputData()
{
Id = this.GUID,
Name = this.Name,
Type = NodeInputTypes.numberInput,
Type2 = NodeInputTypes.numberInput,
Description = this.Description,
Value = Value.ToString(CultureInfo.InvariantCulture),
MinimumValue = this.Min,
MaximumValue = this.Max,
StepValue = this.Step,
NumberType = this.NumberType,
};
}
}
[JsonConstructor]
private DoubleSlider(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
{
Min = 0;
Max = 100;
Step = 0.1;
Value = 1;
ShouldDisplayPreviewCore = false;
}
public DoubleSlider()
{
Min = 0;
Max = 100;
Step = 0.1;
Value = 1;
ShouldDisplayPreviewCore = false;
}
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
var rhs = AstFactory.BuildDoubleNode(Value);
var assignment = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), rhs);
return new[] {assignment};
}
protected override double DeserializeValue(string val)
{
try
{
return Convert.ToDouble(val, CultureInfo.InvariantCulture);
}
catch
{
return 0;
}
}
protected override string SerializeValue()
{
return Value.ToString(CultureInfo.InvariantCulture);
}
protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
{
string name = updateValueParams.PropertyName;
string value = updateValueParams.PropertyValue;
switch (name)
{
case "Min":
case "MinText":
Min = ConvertStringToDouble(value);
return true; // UpdateValueCore handled.
case "Max":
case "MaxText":
Max = ConvertStringToDouble(value);
return true; // UpdateValueCore handled.
case "Value":
case "ValueText":
Value = ConvertStringToDouble(value);
return true; // UpdateValueCore handled.
case "Step":
case "StepText":
Step = ConvertStringToDouble(value);
return true;
}
return base.UpdateValueCore(updateValueParams);
}
#region Serialization/Deserialization Methods
protected override void SerializeCore(XmlElement element, SaveContext context)
{
base.SerializeCore(element, context); // Base implementation must be called.
var xmlDocument = element.OwnerDocument;
var subNode = xmlDocument.CreateElement("Range");
subNode.SetAttribute("min", Min.ToString(CultureInfo.InvariantCulture));
subNode.SetAttribute("max", Max.ToString(CultureInfo.InvariantCulture));
subNode.SetAttribute("step", Step.ToString(CultureInfo.InvariantCulture));
element.AppendChild(subNode);
}
protected override void DeserializeCore(XmlElement element, SaveContext context)
{
base.DeserializeCore(element, context); //Base implementation must be called.
foreach (XmlNode subNode in element.ChildNodes)
{
if (!subNode.Name.Equals("Range"))
continue;
if (subNode.Attributes == null || (subNode.Attributes.Count <= 0))
continue;
foreach (XmlAttribute attr in subNode.Attributes)
{
switch (attr.Name)
{
case "min":
Min = ConvertStringToDouble(attr.Value);
break;
case "max":
Max = ConvertStringToDouble(attr.Value);
break;
case "step":
Step = ConvertStringToDouble(attr.Value);
break;
default:
Log(string.Format("{0} attribute could not be deserialized for {1}", attr.Name, GetType()));
break;
}
}
break;
}
}
#endregion
}
}
namespace Dynamo.Nodes
{
public class DoubleSlider
{
[NodeMigration(version: "0.7.5.0")]
public static NodeMigrationData Migrate_0750(NodeMigrationData data)
{
var migrationData = new NodeMigrationData(data.Document);
XmlElement oldNode = data.MigratedNodes.ElementAt(0);
XmlElement newNode = MigrationManager.CloneAndChangeName(oldNode, "CoreNodeModels.Input.DoubleSlider", "Number Slider", true);
migrationData.AppendNode(newNode);
return migrationData;
}
}
}