Skip to content

Commit

Permalink
DYN-6365 Promote Gate node from GD Extension to Dynamo Core. (#14528)
Browse files Browse the repository at this point in the history
* Gate node

* Add Tests

* Bad format

* Remame file

* Update graphic

---------

Co-authored-by: Craig Long <[email protected]>
  • Loading branch information
saintentropy and saintentropy authored Nov 13, 2023
1 parent ec16645 commit 4971e9d
Show file tree
Hide file tree
Showing 15 changed files with 656 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/Libraries/CoreNodeModels/CoreNodeModelsImages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,50 @@
f66KxdT5Mc9gSmp03qAW9gD5lfwobNUbvjVjAU0UNacLobgfWBUOJrhkXnc2pc08O3uXcsnTdV1Kw+dw
IPQxh9M1WA0uyLqE0AAGIW/Key8ihlALTQmXWtgG1VZGV7BDhxVyKQowQnFEcOlzsDI4jR14HIzwmO9p
2zaJFT8arCiKovwdxnwAzk7Zcq1S2RAAAAAASUVORK5CYII=
</value>
</data>
<data name="CoreNodeModels.Logic.Gate.Large" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
wgAADsIBFShKgAAABiBJREFUeF7tnF1oHUUUx9Na6zdo/SraItZPREFJUaNtMrtJc2kVpErwQQX1wSdR
VLC0fnAL9qFok+zMvYaoDyIKNdU+iA1iC6WKQmuV1qTZnb2poQa1KklQUz+q7fXM5tzbTeghH72ZTMr5
wWE39+zO/s/8d2c2D7NVDMMwDMMwDMMwDMMwDMMwDMMwDMMws4CBgYGXBgcHi2OiDdOzlllTFyXUk3ob
xAYv0GsbZOFOPHzWcDoYUPRlfAS2wxA/ekH0NWzX+UqvbMz3LsbTneU0MCA6BJ1eNEbAPm5TEehdvoof
y2aLc6tMFItzsEknmDUGGFFjRBaNeF9FTakO/wVMiGH7M8Tfqd+TGHlS4neFCh/wZ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MnoRDP78RIcn8SfEPk9FH4hW/ZzXeuAOPHVKUHVh2h0ooZUyIPNW/wIvp1dBOxtEsv4rWQX5
X6ltuNt/Muu/wJBn/Vxca5apNjVNfKynoOrCtDtQQk/FgLs3RhckC7dV1AYduwOigKsgk/ZgYv3NC+JP
zMc+hCoIIfcvqm7feyaeXhGoujDtDpTQqRhQu6lrsSfjp+BO/wzO6093ugn4/TvYvtwgC7eJfPdCkS3O
w1MrDlUXpt2BEjoZAxpUmBFBvBNfGUet80UT3vDz4V0j34ew8wUVqi5MuwMl9KQGFItzzMp3s+pdqINL
YfwOkjG81NkyPgbDjVnt3g+x20y4jW29lyXnWoaqC9PuQAlNGyBk9JCf67kKJskV8Pc66PSvII6W8uYf
Jtj2Chl/BBPq8/DefqN568FLzAhUXZh2B0roqCcgF20xr4ewbz7YlPyWRADv70pvhsn0BdhfZZ4ObHbG
oerCtDtQQuFu7hrV2eWIh+CJ6IRYA/v3mMkUm3IKqi5MuwMlFIaYP1Idf9yX+gAE/IMUZuqb9ZKmbPd8
bMJJqLow7Q6U0KTjzWdlAv22UNFSv7Xr8pWycNZ0f+mqUlB1YdodKKEi33ttdXuxov8c2YSqC9MMwzAM
wzAMwzAMwzAMwzAMwzAMwzDuUlX1P0yI3rYMerjIAAAAAElFTkSuQmCC
</value>
</data>
<data name="CoreNodeModels.Logic.Gate.Small" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
wgAADsIBFShKgAAAAXpJREFUWEftlTFLw0AYhiO66CKORV10qKCbm0ObxCJWXATFQZ39Aa4iKIibkMRS
EBER/AWCjuKkYLeC3qVaFwen+hd8Gr6AlVpTjB00Dzyk35e768sl5IyEhISvqNVqRTyyXD2ecyvd0m6b
cB0po8MkhRUCvOEzXtiuv2J6OpU5qPbIsG8J15EyOkyq4j1/XDIdnbFcf4rf23iFZTzGJdPVQzKlKeE6
UkbnQ4Cy5egJaRszp69dlqP66U/jDpZQYRHz2YJqeFyxB2gG91PsxAJj73Be2gEdCRDC2C0e1ZqUAZ0O
sIvLUgZ0OIDa4/1YlDLgTwSov+FpabfktwI8Wp4elXZLkgD/OwBfwjRjzwkxJ62AOAI8EWBE2g3Ynh7m
/jpe4y1u2EUd+1nwYntqUNoGJ+MArtK/xBvctDw1lt1vPIRC4grA9qo8nrHVmt4h10kZ2pI4AtSwfj3B
nOn4fTIkEj8JUEDOeH/Wch96pd024TpSJiQkfMIw3gFrUwF9tuj5yAAAAABJRU5ErkJggg==
</value>
</data>
</root>
72 changes: 72 additions & 0 deletions src/Libraries/CoreNodeModels/Logic/Gate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using CoreNodeModels.Properties;
using Dynamo.Graph.Nodes;
using Newtonsoft.Json;
using ProtoCore.AST.AssociativeAST;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoreNodeModels.Logic
{
[NodeName("Gate")]
[NodeDescription(nameof(Resources.GateDescription), typeof(Resources))]
[NodeCategory(BuiltinNodeCategories.LOGIC)]
[NodeSearchTags(nameof(Resources.GateSearchTags), typeof(Resources))]
[InPortNames(">")]
[InPortTypes("object")]
[InPortDescriptions(nameof(Resources.GateInPortToolTip), nameof(Resources))]
[OutPortNames(">")]
[OutPortTypes("object")]
[OutPortDescriptions(nameof(Resources.GateOutPortToolTip), nameof(Resources))]
[IsDesignScriptCompatible]
public class Gate : NodeModel
{
private bool value;

[JsonProperty("InputValue")]
public virtual bool Value
{
get
{
return value;
}
set
{
if (!this.value.Equals(value))
{
this.value = value;
ClearDirtyFlag();
OnNodeModified();
RaisePropertyChanged(nameof(Value));
}
}
}

[JsonConstructor]
private Gate(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
{
ShouldDisplayPreviewCore = false;
}

public Gate()
{
Value = false;
RegisterAllPorts();
ShouldDisplayPreviewCore = false;
}

public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
// Check that node can run
if (!Value)
{
return new[]
{AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode())};
}

return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), inputAstNodes[0]) };
}
}
}
38 changes: 38 additions & 0 deletions src/Libraries/CoreNodeModels/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/Libraries/CoreNodeModels/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,18 @@ Default value: {0}</value>
<data name="TooltipTextQuery" xml:space="preserve">
<value>Nodes that query data</value>
</data>
<data name="GateDescription" xml:space="preserve">
<value>Block data passing through this node to downstream nodes. Node returns the input data only if the node value is set to Open.

In Generative Design workflows, this node should be used to control and block the behavior of nodes that will place elements in Revit</value>
</data>
<data name="GateInPortToolTip" xml:space="preserve">
<value>Data to pass to a downstream node with gated controls.</value>
</data>
<data name="GateOutPortToolTip" xml:space="preserve">
<value>Data</value>
</data>
<data name="GateSearchTags" xml:space="preserve">
<value>gate;stop;data</value>
</data>
</root>
14 changes: 14 additions & 0 deletions src/Libraries/CoreNodeModels/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,18 @@ Default value: {0}</value>
<data name="TooltipTextQuery" xml:space="preserve">
<value>Nodes that query data</value>
</data>
<data name="GateDescription" xml:space="preserve">
<value>Block data passing through this node to downstream nodes. Node returns the input data only if the node value is set to Open.

In Generative Design workflows, this node should be used to control and block the behavior of nodes that will place elements in Revit</value>
</data>
<data name="GateInPortToolTip" xml:space="preserve">
<value>Data to pass to a downstream node with gated controls.</value>
</data>
<data name="GateOutPortToolTip" xml:space="preserve">
<value>Data</value>
</data>
<data name="GateSearchTags" xml:space="preserve">
<value>gate;stop;data</value>
</data>
</root>
70 changes: 70 additions & 0 deletions src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/Gate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using CoreNodeModels;
using CoreNodeModels.Logic;
using CoreNodeModels.Properties;
using Dynamo.Controls;
using Dynamo.UI;
using Dynamo.Wpf;
using Dynamo.Wpf.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;

namespace CoreNodeModelsWpf.Nodes
{
public class GateNodeViewCustomization : INodeViewCustomization<Gate>
{
public void CustomizeView(Gate model, NodeView nodeView)
{
//add a text box to the input grid of the control
var rbTrue = new RadioButton();
var rbFalse = new RadioButton();
rbTrue.Style = rbFalse.Style = (Style)SharedDictionaryManager.DynamoModernDictionary["RadioButton"];

//use a unique name for the button group
//so other instances of this element don't get confused
string groupName = Guid.NewGuid().ToString();
rbTrue.GroupName = groupName;
rbFalse.GroupName = groupName;

rbTrue.Content = CoreNodeModelWpfResources.GateOpen;
rbTrue.Padding = new Thickness(0, 0, 12, 0);
rbFalse.Content = CoreNodeModelWpfResources.GateClose;
rbFalse.Padding = new Thickness(0);
var wp = new WrapPanel
{
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
Margin = new Thickness(10, 5, 10, 0),
Orientation = Orientation.Horizontal
};

wp.Children.Add(rbTrue);
wp.Children.Add(rbFalse);
nodeView.inputGrid.Children.Add(wp);

rbFalse.DataContext = model;
rbTrue.DataContext = model;

var rbTrueBinding = new Binding("Value") { Mode = BindingMode.TwoWay, };
rbTrue.SetBinding(ToggleButton.IsCheckedProperty, rbTrueBinding);

var rbFalseBinding = new Binding("Value")
{
Mode = BindingMode.TwoWay,
Converter = new InverseBoolDisplay()
};
rbFalse.SetBinding(ToggleButton.IsCheckedProperty, rbFalseBinding);
}

public void Dispose()
{
// Nothing to dispose
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,10 @@ Dictionary&lt;string, List&lt;List&lt;double&gt;&gt;&gt;</value>
<data name="ResizeThumbToolTip" xml:space="preserve">
<value>Drag to modify the size of the chart</value>
</data>
<data name="GateClose" xml:space="preserve">
<value>Close</value>
</data>
<data name="GateOpen" xml:space="preserve">
<value>Open</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,10 @@ Dictionary&lt;string, List&lt;List&lt;double&gt;&gt;&gt;</value>
<data name="ResizeThumbToolTip" xml:space="preserve">
<value>Drag to modify the size of the chart</value>
</data>
<data name="GateClose" xml:space="preserve">
<value>Close</value>
</data>
<data name="GateOpen" xml:space="preserve">
<value>Open</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/LibraryViewExtensionWebView2/web/library/layoutSpecs.json
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,9 @@
"iconUrl": "",
"elementType": "group",
"include": [
{
"path": "Core.Logic.Gate"
},
{
"path": "BuiltIn.LoopWhile"
},
Expand Down
Loading

0 comments on commit 4971e9d

Please sign in to comment.