-
Notifications
You must be signed in to change notification settings - Fork 11
/
UICopyableWatch.cs
205 lines (171 loc) · 5.85 KB
/
UICopyableWatch.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.DesignScript.Geometry;
using Autodesk.DesignScript.Runtime;
using Dynamo.Controls;
using Dynamo.Events;
using Dynamo.Graph.Nodes;
using Dynamo.Session;
using Dynamo.Wpf;
using Newtonsoft.Json;
using NodeModelsEssentials.Controls;
using ProtoCore.AST.AssociativeAST;
using VMDataBridge;
namespace NodeModelsEssentials
{
// This component uses the data bridging strategy
// of the original Watch Dynamo node.
[NodeName("UI.CopyableWatch")]
[NodeDescription("A watch node from which you can copy text =).")]
[NodeCategory("NodeModelsEssentials")]
[InPortNames(">")]
[InPortTypes("object")]
[InPortDescriptions("An object.")]
[OutPortNames(">")]
[OutPortTypes("object")]
[OutPortDescriptions("Item")]
[IsDesignScriptCompatible]
public class UICopyableWatch : NodeModel
{
#region private members
string text;
int index;
#endregion
#region properties
public Action Executed;
public string Text
{
get => text;
set
{
text = value;
RaisePropertyChanged("Text");
OnNodeModified();
}
}
#endregion
#region constructor
[JsonConstructor]
UICopyableWatch(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
{
}
public UICopyableWatch()
{
Executed = () =>
{
//MessageBox.Show("Executed!");
};
RegisterAllPorts();
Text = "MyTextChanged";
//IncreaseCommand = new DelegateCommand(IncreaseNumber);
//DecreaseCommand = new DelegateCommand(DecreaseNumber);
ExecutionEvents.GraphPostExecution += ExecutionEvents_GraphPostExecution;
ExecutionEvents.GraphPreExecution += ExecutionEvents_GraphPreExecution;
}
void ExecutionEvents_GraphPreExecution(IExecutionSession session)
{
//session.
if (InPorts[0].Connectors.Any())
{
// this.GetValue()
// get parent
// MessageBox.Show("There is an input! " + InPorts[0].Owner.GetValue(;
//return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
}
}
void ExecutionEvents_GraphPostExecution(IExecutionSession session)
{
//index++;
//text += index.ToString();
}
#endregion
#region public methods
public override void Dispose()
{
base.Dispose();
DataBridge.Instance.UnregisterCallback(GUID.ToString());
}
protected override void OnBuilt()
{
base.OnBuilt();
DataBridge.Instance.RegisterCallback(GUID.ToString(), DataBridgeCallback);
}
void DataBridgeCallback(object data)
{
string str = data as string;
if (str != null)
Text = str;
else
Text = "";
if (data is Point && data as Point != null) Text = (data as Point).ToString();
Executed();
}
[IsVisibleInDynamoLibrary(false)]
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAsNodes)
{
//if (!InPorts[0].Connectors.Any())
//{
// return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
//}
StringNode textNode = AstFactory.BuildStringNode(text);
//var funcNode = AstFactory.BuildFunctionCall(
// new Func<List<object>, int, object>(NodeModelsEssentialsFunctions.SetTextValue),
// new List<AssociativeNode>() { inputAsNodes[0], textNode }
// );
return new[]
{
AstFactory.BuildAssignment(
GetAstIdentifierForOutputIndex(0),
textNode),
AstFactory.BuildAssignment(
AstFactory.BuildIdentifier(AstIdentifierBase + "_dummy"),
DataBridge.GenerateBridgeDataAst(GUID.ToString(), inputAsNodes[0]))
};
}
#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 CustomUINodeModelCopyableWatchViewCustomization : INodeViewCustomization<UICopyableWatch>
{
public void CustomizeView(UICopyableWatch model, NodeView nodeView)
{
CopyableWatch copyableWatch = new CopyableWatch();
nodeView.inputGrid.Children.Add(copyableWatch);
nodeView.inputGrid.ClipToBounds = true;
//nodeView.MouseLeave += (sender, args) => { MessageBox.Show("MouseLeave"); };
copyableWatch.DataContext = model;
// add an event to watch properties of the workspace and set model.runtype
//(nodeView.ViewModel.DynamoViewModel.Model.CurrentWorkspace as HomeWorkspaceModel).RunSettings.RunType
}
public void Dispose()
{
}
}
}