-
Notifications
You must be signed in to change notification settings - Fork 635
/
NodeViewModel.cs
1765 lines (1522 loc) · 58 KB
/
NodeViewModel.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using Dynamo.Configuration;
using Dynamo.Engine.CodeGeneration;
using Dynamo.Graph;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.Selection;
using Dynamo.UI;
using Dynamo.Wpf.ViewModels.Core;
using Newtonsoft.Json;
using Point = System.Windows.Point;
using Size = System.Windows.Size;
namespace Dynamo.ViewModels
{
/// <summary>
/// Interaction logic for dynControl.xaml
/// </summary>
public partial class NodeViewModel : ViewModelBase
{
#region delegates
public delegate void SetToolTipDelegate(string message);
public delegate void NodeDialogEventHandler(object sender, NodeDialogEventArgs e);
public delegate void SnapInputEventHandler(PortViewModel portViewModel);
public delegate void PreviewPinStatusHandler(bool pinned);
internal delegate void NodeAutoCompletePopupEventHandler(Popup popup);
internal delegate void PortContextMenuPopupEventHandler(Popup popup);
#endregion
#region events
public event SnapInputEventHandler SnapInputEvent;
#endregion
[JsonIgnore]
public Action OnMouseLeave;
#region private members
ObservableCollection<PortViewModel> inPorts = new ObservableCollection<PortViewModel>();
ObservableCollection<PortViewModel> outPorts = new ObservableCollection<PortViewModel>();
NodeModel nodeLogic;
private int zIndex = Configurations.NodeStartZIndex;
private string astText = string.Empty;
private bool isexplictFrozen;
private bool canToggleFrozen = true;
private bool isRenamed = false;
private bool isNodeInCollapsedGroup = false;
#endregion
#region public members
/// <summary>
/// Returns NodeModel ID
/// </summary>
[JsonConverter(typeof(IdToGuidConverter))]
public Guid Id
{
get { return NodeModel.GUID; }
}
[JsonIgnore]
public readonly DynamoViewModel DynamoViewModel;
[JsonIgnore]
public readonly WorkspaceViewModel WorkspaceViewModel;
[JsonIgnore]
public readonly Size? PreferredSize;
private bool previewPinned;
[JsonIgnore]
public bool PreviewPinned
{
get { return previewPinned; }
set
{
if (previewPinned == value) return;
previewPinned = value;
DynamoViewModel.ExecuteCommand(
new DynamoModel.UpdateModelValueCommand(
System.Guid.Empty, NodeModel.GUID, "PreviewPinned", previewPinned.ToString()));
}
}
[JsonIgnore]
public NodeModel NodeModel { get { return nodeLogic; } private set { nodeLogic = value; } }
[JsonIgnore]
public LacingStrategy ArgumentLacing
{
get { return nodeLogic.ArgumentLacing; }
}
[JsonIgnore]
public NodeModel NodeLogic
{
get { return nodeLogic; }
}
[JsonIgnore]
public InfoBubbleViewModel ErrorBubble { get; set; }
[JsonIgnore]
public string ToolTipText
{
get { return nodeLogic.ToolTipText; }
}
[JsonIgnore]
public ObservableCollection<PortViewModel> InPorts
{
get { return inPorts; }
set
{
inPorts = value;
RaisePropertyChanged("InPorts");
}
}
[JsonIgnore]
public ObservableCollection<PortViewModel> OutPorts
{
get { return outPorts; }
set
{
outPorts = value;
RaisePropertyChanged("OutPorts");
}
}
[JsonIgnore]
public bool IsSelected
{
get
{
return nodeLogic.IsSelected;
}
}
[JsonIgnore]
public bool IsInput
{
get
{
return nodeLogic.IsInputNode;
}
}
public bool IsSetAsInput
{
get
{
return nodeLogic.IsSetAsInput;
}
set
{
if (nodeLogic.IsSetAsInput != value)
{
DynamoViewModel.ExecuteCommand(new DynamoModel.UpdateModelValueCommand(
Guid.Empty, NodeModel.GUID, nameof(IsSetAsInput), value.ToString()));
RaisePropertyChanged(nameof(IsSetAsInput));
Analytics.TrackEvent(Actions.Set, Categories.NodeContextMenuOperations, "AsInput");
}
}
}
[JsonIgnore]
public bool IsOutput
{
get
{
return nodeLogic.IsOutputNode;
}
}
public bool IsSetAsOutput
{
get
{
return nodeLogic.IsSetAsOutput;
}
set
{
if (nodeLogic.IsSetAsOutput != value)
{
DynamoViewModel.ExecuteCommand(new DynamoModel.UpdateModelValueCommand(
Guid.Empty, NodeModel.GUID, nameof(IsSetAsOutput), value.ToString()));
RaisePropertyChanged(nameof(IsSetAsOutput));
Analytics.TrackEvent(Actions.Set, Categories.NodeContextMenuOperations, "AsOutput");
}
}
}
/// <summary>
/// The Name of the nodemodel this view points to
/// this is the name of the node as it is displayed in the UI.
/// </summary>
public string Name
{
get
{
IsRenamed = OriginalName != nodeLogic.Name;
return nodeLogic.Name;
}
set { nodeLogic.Name = value; }
}
/// <summary>
/// The original name of the node. Notice this property will return
/// current node name if the node is dummy node or unloaded custom node.
/// </summary>
[JsonIgnore]
public string OriginalName
{
get { return nodeLogic.GetOriginalName(); }
}
/// <summary>
/// If a node has been renamed. Notice this boolean will be disabled
/// (always false) if the node is dummy node or unloaded custom node.
/// </summary>
[JsonIgnore]
public bool IsRenamed
{
get { return isRenamed; }
set
{
if (isRenamed != value)
{
isRenamed = value;
RaisePropertyChanged(nameof(IsRenamed));
}
}
}
[JsonIgnore]
public ElementState State
{
get { return nodeLogic.State; }
}
/// <summary>
/// The total number of info/warnings/errors dismissed by the user on this node.
/// This is displayed on the node by a little icon beside the Context Menu button.
/// </summary>
[JsonIgnore]
public int NumberOfDismissedAlerts
{
get => DismissedAlerts.Count;
}
[JsonIgnore]
public string Description
{
get { return nodeLogic.Description; }
}
[JsonIgnore]
public bool IsCustomFunction
{
get { return nodeLogic.IsCustomFunction ? true : false; }
}
/// <summary>
/// Element's left position is two-way bound to this value
/// </summary>
[JsonIgnore]
public double Left
{
get { return nodeLogic.X; }
set
{
nodeLogic.X = value;
RaisePropertyChanged("Left");
}
}
/// <summary>
/// Element's top position is two-way bound to this value
/// </summary>
[JsonIgnore]
public double Top
{
get { return nodeLogic.Y; }
set
{
nodeLogic.Y = value;
RaisePropertyChanged("Top");
}
}
/// <summary>
/// ZIndex is used to order nodes, when some node is clicked.
/// This selected node should be moved above others.
/// Start value of zIndex is 3, because 1 is for groups and 2 is for connectors.
/// Nodes should be always at the top.
///
/// Static is used because every node should know what is the highest z-index right now.
/// </summary>
internal static int StaticZIndex = Configurations.NodeStartZIndex;
/// <summary>
/// ZIndex represents the order on the z-plane in which nodes appear.
/// </summary>
[JsonIgnore]
public int ZIndex
{
get { return zIndex; }
set
{
zIndex = value;
RaisePropertyChanged("ZIndex");
if (ErrorBubble == null) return;
ErrorBubble.ZIndex = zIndex + 1;
}
}
/// <summary>
/// Input grid's enabled state is now bound to this property
/// which tracks the node model's InteractionEnabled property
/// </summary>
[JsonIgnore]
public bool IsInteractionEnabled
{
get { return true; }
}
[JsonProperty("ShowGeometry")]
public bool IsVisible
{
get
{
return nodeLogic.IsVisible;
}
}
/// <summary>
/// Determines whether or not the semi-transparent overlay is displaying on the node.
/// This reflects whether the node is in a info/warning/error/frozen state
/// </summary>
[JsonIgnore]
public bool NodeOverlayVisible => IsFrozen;
/// <summary>
/// Determines whether the node is showing a bar at its base, indicating that the
/// node has undismissed info/warning/error messages.
/// </summary>
[JsonIgnore]
public bool NodeWarningBarVisible => (ErrorBubble != null && ErrorBubble.DoesNodeDisplayMessages) || IsVisible == false;
/// <summary>
/// The color of the warning bar: blue for info, orange for warnings, red for errors.
/// </summary>
[JsonIgnore]
public SolidColorBrush WarningBarColor
{
get => warningBarColor;
internal set
{
if (warningBarColor != value)
{
warningBarColor = value;
RaisePropertyChanged(nameof(WarningBarColor));
}
}
}
/// <summary>
/// Determines the color of the node's visual overlay, which displays
/// if the node is in a Frozen, Info, Error or Warning state.
/// </summary>
[JsonIgnore]
public SolidColorBrush NodeOverlayColor => IsFrozen ?
(SolidColorBrush)SharedDictionaryManager.DynamoColorsAndBrushesDictionary["NodeFrozenOverlayColor"] : null;
[JsonIgnore]
public Visibility PeriodicUpdateVisibility
{
get
{
return nodeLogic.CanUpdatePeriodically
? Visibility.Visible
: Visibility.Collapsed;
}
}
[JsonIgnore]
public bool EnablePeriodicUpdate
{
get { return nodeLogic.CanUpdatePeriodically; }
set { nodeLogic.CanUpdatePeriodically = value; }
}
[JsonIgnore]
public bool ShowsVisibilityToggles
{
get { return true; }
}
[JsonIgnore]
public bool IsPreviewInsetVisible
{
get { return WorkspaceViewModel.Model is HomeWorkspaceModel && nodeLogic.ShouldDisplayPreview; }
}
[JsonIgnore]
public bool ShouldShowGlyphBar
{
get { return IsPreviewInsetVisible || ArgumentLacing != LacingStrategy.Disabled; }
}
/// <summary>
/// Enable or disable text labels on nodes.
/// </summary>
[JsonIgnore]
public bool IsDisplayingLabels
{
get { return nodeLogic.DisplayLabels; }
set
{
if (nodeLogic.DisplayLabels != value)
{
DynamoViewModel.ExecuteCommand(new DynamoModel.UpdateModelValueCommand(
Guid.Empty, NodeModel.GUID, nameof(nodeLogic.DisplayLabels), value.ToString()));
RaisePropertyChanged(nameof(IsDisplayingLabels));
Analytics.TrackEvent(Actions.Show, Categories.NodeContextMenuOperations, "Labels");
}
}
}
[JsonIgnore]
public bool CanDisplayLabels
{
get
{
//lock (nodeLogic.RenderPackagesMutex)
//{
// return nodeLogic.RenderPackages.Any(y => ((RenderPackage)y).IsNotEmpty());
//}
return true;
}
}
[JsonIgnore]
public string ASTText
{
get { return astText; }
set
{
astText = value;
RaisePropertyChanged("ASTText");
}
}
[JsonIgnore]
public bool ShowDebugASTs
{
get { return DynamoViewModel.Model.DebugSettings.ShowDebugASTs; }
set
{
DynamoViewModel.Model.DebugSettings.ShowDebugASTs = value;
}
}
[JsonIgnore]
public bool WillForceReExecuteOfNode
{
get
{
return NodeModel.NeedsForceExecution;
}
}
private bool showExectionPreview;
[JsonIgnore]
public bool ShowExecutionPreview
{
get
{
return showExectionPreview;
}
set
{
showExectionPreview = value;
RaisePropertyChanged("ShowExecutionPreview");
RaisePropertyChanged("PreviewState");
}
}
[JsonIgnore]
public PreviewState PreviewState
{
get
{
if (ShowExecutionPreview)
{
return PreviewState.ExecutionPreview;
}
if (NodeModel.IsSelected)
{
return PreviewState.Selection;
}
return PreviewState.None;
}
}
private bool isNodeNewlyAdded;
private ImageSource imageSource;
private SolidColorBrush warningBarColor;
[JsonIgnore]
public bool IsNodeAddedRecently
{
get
{
return isNodeNewlyAdded;
}
set
{
isNodeNewlyAdded = value;
}
}
/// <summary>
/// Returns a value indicating whether this model is frozen.
/// </summary>
/// <value>
/// <c>true</c> if this instance is frozen; otherwise, <c>false</c>.
/// </value>
[JsonIgnore]
public bool IsFrozen
{
get
{
RaisePropertyChanged("IsFrozenExplicitly");
RaisePropertyChanged("CanToggleFrozen");
return NodeModel.IsFrozen;
}
set
{
NodeModel.IsFrozen = value;
}
}
/// <summary>
/// A flag indicating whether the node is set to freeze by the user.
/// </summary>
/// <value>
/// Returns true if the node has been frozen explicitly by the user, otherwise false.
/// </value>
[JsonProperty("Excluded")]
public bool IsFrozenExplicitly
{
get
{
//if the node is freeze by the user, then always
//check the Freeze property
if (this.NodeLogic.isFrozenExplicitly)
{
return true;
}
return false;
}
}
/// <summary>
/// A flag indicating whether the underlying NodeModel's IsFrozen property can be toggled.
/// </summary>
/// <value>
/// This will return false if this node is not the root of the freeze operation, otherwise it will return
/// true.
/// </value>
[JsonIgnore]
public bool CanToggleFrozen
{
get
{
return !NodeModel.IsAnyUpstreamFrozen();
}
}
/// <summary>
/// Returns or set the X position of the Node.
/// </summary>
public double X
{
get { return NodeModel.X; }
set
{
NodeModel.X = value;
}
}
/// <summary>
/// Returns or set the Y position of the Node.
/// </summary>
public double Y
{
get { return NodeModel.Y; }
set
{
NodeModel.Y = value;
}
}
[JsonIgnore]
public ImageSource ImageSource
{
get => imageSource;
set
{
imageSource = value;
RaisePropertyChanged(nameof(ImageSource));
}
}
internal double ActualHeight { get; set; }
internal double ActualWidth { get; set; }
/// <summary>
/// Node description defined by the user.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string UserDescription
{
get { return NodeModel.UserDescription; }
set { NodeModel.UserDescription = value; }
}
public override bool IsCollapsed
{
get => base.IsCollapsed;
set
{
base.IsCollapsed = value;
if (ErrorBubble == null) return;
ErrorBubble.IsCollapsed = value;
RaisePropertyChanged(nameof(NodeWarningBarVisible));
}
}
/// <summary>
/// Used as a flag to indicate to associated connectors what ZIndex to be drawn at.
/// </summary>
[JsonIgnore]
public bool IsNodeInCollapsedGroup
{
get => isNodeInCollapsedGroup;
set
{
isNodeInCollapsedGroup = value;
RaisePropertyChanged(nameof(IsNodeInCollapsedGroup));
}
}
/// <summary>
/// A collection of error/warning/info messages, dismissed via a sub-menu in the node Context Menu.
/// </summary>
[JsonIgnore]
public ObservableCollection<string> DismissedAlerts => nodeLogic.DismissedAlerts;
#endregion
#region events
internal event NodeAutoCompletePopupEventHandler RequestAutoCompletePopupPlacementTarget;
internal event PortContextMenuPopupEventHandler RequestPortContextMenuPopupPlacementTarget;
internal void OnRequestAutoCompletePopupPlacementTarget(Popup popup)
{
RequestAutoCompletePopupPlacementTarget?.Invoke(popup);
}
public void OnRequestPortContextMenuPlacementTarget(Popup popup)
{
RequestPortContextMenuPopupPlacementTarget?.Invoke(popup);
}
public event NodeDialogEventHandler RequestShowNodeHelp;
public virtual void OnRequestShowNodeHelp(Object sender, NodeDialogEventArgs e)
{
if (RequestShowNodeHelp != null)
{
RequestShowNodeHelp(this, e);
}
}
public event NodeDialogEventHandler RequestShowNodeRename;
public virtual void OnRequestShowNodeRename(Object sender, NodeDialogEventArgs e)
{
if (RequestShowNodeRename != null)
{
RequestShowNodeRename(this, e);
}
}
public event EventHandler RequestsSelection;
public virtual void OnRequestsSelection(Object sender, EventArgs e)
{
if (RequestsSelection != null)
{
RequestsSelection(this, e);
}
}
/// <summary>
/// Event to determine when Node is selected
/// </summary>
internal event EventHandler Selected;
internal void OnSelected(object sender, EventArgs e)
{
Selected?.Invoke(this, e);
}
/// <summary>
/// Event to determine when Node is removed
/// </summary>
internal event EventHandler Removed;
internal void OnRemoved(object sender, EventArgs e)
{
Removed?.Invoke(this, e);
}
#endregion
#region constructors
/// <summary>
/// Constructor
/// </summary>
/// <param name="workspaceViewModel"></param>
/// <param name="logic"></param>
public NodeViewModel(WorkspaceViewModel workspaceViewModel, NodeModel logic)
{
WorkspaceViewModel = workspaceViewModel;
DynamoViewModel = workspaceViewModel.DynamoViewModel;
nodeLogic = logic;
previewPinned = logic.PreviewPinned;
//respond to collection changed events to add
//and remove port model views
logic.InPorts.CollectionChanged += inports_collectionChanged;
logic.OutPorts.CollectionChanged += outports_collectionChanged;
logic.PropertyChanged += logic_PropertyChanged;
DynamoViewModel.Model.PropertyChanged += Model_PropertyChanged;
DynamoViewModel.Model.DebugSettings.PropertyChanged += DebugSettings_PropertyChanged;
//Do a one time setup of the initial ports on the node
//we can not do this automatically because this constructor
//is called after the node's constructor where the ports
//are initially registered
SetupInitialPortViewModels();
if (IsDebugBuild)
{
DynamoViewModel.EngineController.AstBuilt += EngineController_AstBuilt;
}
ShowExecutionPreview = workspaceViewModel.DynamoViewModel.ShowRunPreview;
IsNodeAddedRecently = true;
DynamoSelection.Instance.Selection.CollectionChanged += SelectionOnCollectionChanged;
ZIndex = ++StaticZIndex;
++NoteViewModel.StaticZIndex;
if (workspaceViewModel.InCanvasSearchViewModel.TryGetNodeIcon(this, out ImageSource imgSource))
{
ImageSource = imgSource;
}
if(nodeLogic.State == ElementState.Error)
{
BuildErrorBubble();
UpdateBubbleContent();
}
logic.NodeMessagesClearing += Logic_NodeMessagesClearing;
logic_PropertyChanged(this, new PropertyChangedEventArgs(nameof(IsVisible)));
}
/// <summary>
/// Updates whether the Warning Bar is visible or not and whether the node's
/// Frozen/Info/Warning/Error overlay is displaying.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UpdateOverlays(object sender, EventArgs e)
{
RaisePropertyChanged(nameof(NodeWarningBarVisible));
RaisePropertyChanged(nameof(NodeOverlayVisible));
RaisePropertyChanged(nameof(NodeOverlayColor));
}
/// <summary>
/// Clears the existing messages on a node before it executes and re-evalutes its warnings/errors.
/// </summary>
/// <param name="obj"></param>
private void Logic_NodeMessagesClearing(NodeModel obj)
{
// Because errors are evaluated before the graph/node executes, we need to ensure
// errors aren't being dismissed when the graph runs.
if (nodeLogic.State == ElementState.Error || ErrorBubble == null) return;
if (DynamoViewModel.UIDispatcher != null)
{
DynamoViewModel.UIDispatcher.Invoke(() =>
{
ErrorBubble.NodeMessages.Clear();
});
}
else
{
ErrorBubble.NodeMessages.Clear();
}
}
private void DismissedNodeMessages_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (!(sender is ObservableCollection<InfoBubbleDataPacket> observableCollection)) return;
DismissedAlerts.Clear();
foreach (InfoBubbleDataPacket infoBubbleDataPacket in observableCollection)
{
DismissedAlerts.Add(infoBubbleDataPacket.Message);
}
RaisePropertyChanged(nameof(DismissedAlerts));
RaisePropertyChanged(nameof(NumberOfDismissedAlerts));
}
/// <summary>
/// Dispose function
/// </summary>
public override void Dispose()
{
NodeModel.PropertyChanged -= logic_PropertyChanged;
NodeModel.InPorts.CollectionChanged -= inports_collectionChanged;
NodeModel.OutPorts.CollectionChanged -= outports_collectionChanged;
DynamoViewModel.Model.PropertyChanged -= Model_PropertyChanged;
DynamoViewModel.Model.DebugSettings.PropertyChanged -= DebugSettings_PropertyChanged;
if (IsDebugBuild)
{
DynamoViewModel.EngineController.AstBuilt -= EngineController_AstBuilt;
}
foreach (var p in InPorts)
{
p.Dispose();
}
foreach (var p in OutPorts)
{
p.Dispose();
}
NodeModel.NodeMessagesClearing -= Logic_NodeMessagesClearing;
if (ErrorBubble != null) DisposeErrorBubble();
DynamoSelection.Instance.Selection.CollectionChanged -= SelectionOnCollectionChanged;
base.Dispose();
}
public NodeViewModel(WorkspaceViewModel workspaceViewModel, NodeModel logic, Size preferredSize)
: this(workspaceViewModel, logic)
{
// preferredSize is set when a node needs to have a fixed size
PreferredSize = preferredSize;
}
private void SelectionOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
CreateGroupCommand.RaiseCanExecuteChanged();
AddToGroupCommand.RaiseCanExecuteChanged();
UngroupCommand.RaiseCanExecuteChanged();
ToggleIsFrozenCommand.RaiseCanExecuteChanged();
RaisePropertyChanged("IsFrozenExplicitly");
RaisePropertyChanged("CanToggleFrozen");
}
void DebugSettings_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "ShowDebugASTs")
{
RaisePropertyChanged("ShowDebugASTs");
}
}
/// <summary>
/// Handler for the EngineController's AstBuilt event.
/// Formats a string of AST for preview on the node.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void EngineController_AstBuilt(object sender, CompiledEventArgs e)
{
if (e.Node == nodeLogic.GUID)
{
var sb = new StringBuilder();
sb.AppendLine(string.Format("{0} AST:", e.Node));
foreach (var assocNode in e.AstNodes)
{
var pretty = assocNode.ToString();
//shorten the guids
var strRegex = @"([0-9a-f-]{32}).*?";
var myRegex = new Regex(strRegex, RegexOptions.None);
string strTargetString = assocNode.ToString();
foreach (Match myMatch in myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
pretty = pretty.Replace(myMatch.Value, "..." + myMatch.Value.Substring(myMatch.Value.Length - 7));
}
}
sb.AppendLine(pretty);
}
ASTText = sb.ToString();
}
}
#endregion
/// <summary>
/// Do a one setup of the ports
/// </summary>
private void SetupInitialPortViewModels()
{
foreach (var item in nodeLogic.InPorts)
{
PortViewModel inportViewModel = SubscribeInPortEvents(item);
InPorts.Add(inportViewModel);
}
foreach (var item in nodeLogic.OutPorts)
{
PortViewModel outportViewModel = SubscribeOutPortEvents(item);
OutPorts.Add(outportViewModel);
}
}
/// <summary>
/// Respond to property changes on the Dynamo model
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "CurrentWorkspace":
RaisePropertyChanged("NodeVisibility");
break;
}
}
/// <summary>
/// Respond to property changes on the node model.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void logic_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{