-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DYN-6365 Promote Gate node from GD Extension to Dynamo Core. (#14528)
* Gate node * Add Tests * Bad format * Remame file * Update graphic --------- Co-authored-by: Craig Long <[email protected]>
- Loading branch information
1 parent
ec16645
commit 4971e9d
Showing
15 changed files
with
656 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
src/Libraries/CoreNodeModels/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/Gate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Libraries/CoreNodeModelsWpf/Properties/CoreNodeModelWpfResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.