Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-6607 - Input/Output Node - part 1 #14987

Merged
merged 12 commits into from
Mar 15, 2024
130 changes: 130 additions & 0 deletions src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,136 @@
</Setter>
<Style.Triggers />
</Style>


<!-- NodeView c ustomization styles -->
<ControlTemplate x:Key="NodeViewComboBoxToggleButton" TargetType="ToggleButton">
<Grid>
<Border x:Name="Border"
Background="#2a2a2a"
BorderThickness="0"/>
<Path x:Name="Arrow"
Margin="0 0 5 0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Data="M 0 0 L 4 4 L 8 0 Z"
Fill="#999" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ToggleButton.IsMouseOver"
Value="true">
<Setter TargetName="Arrow"
Property="Fill"
Value="#fff" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

<Style x:Key="NodeViewComboBox" TargetType="{x:Type ComboBox}">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.CanContentScroll" Value="true" />
<Setter Property="MinWidth" Value="40" />
<Setter Property="Padding" Value="5 0" />
<Setter Property="MinHeight" Value="20" />
<Setter Property="MaxHeight" Value="30" />
<Setter Property="FontSize" Value="10" />
<Setter Property="Foreground" Value="#C7C7C7" />
<Setter Property="ItemContainerStyle" Value="{DynamicResource PackageManagerComboBoxItemStyle}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton Name="ToggleButton"
Grid.Column="2"
ClickMode="Press"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Template="{DynamicResource NodeViewComboBoxToggleButton}" />
<ContentPresenter Name="ContentSite"
Margin="5,3,12,3"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="False" />
<TextBox x:Name="PART_EditableTextBox"
Margin="3,3,23,3"
Padding="10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Background="#2a2a2a"
CaretBrush="#bbbbbb"
Focusable="True"
Foreground="#bbbbbb"
IsReadOnly="{TemplateBinding IsReadOnly}"
Style="{x:Null}"
Template="{StaticResource ComboBoxTextBox}"
Visibility="Hidden" />
<Popup Name="Popup"
AllowsTransparency="True"
Focusable="False"
IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom"
PopupAnimation="Slide">
<Grid Name="DropDown"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
SnapsToDevicePixels="True">
<Border x:Name="DropDownBorder"
Background="#2a2a2a"
BorderBrush="Transparent"
BorderThickness="0" />
<ScrollViewer Margin="0,6,0,6"
SnapsToDevicePixels="True">
<StackPanel IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasItems"
Value="false">
<Setter TargetName="DropDownBorder"
Property="MinHeight"
Value="95" />
</Trigger>
<Trigger Property="IsGrouping"
Value="true">
<Setter Property="ScrollViewer.CanContentScroll"
Value="false" />
</Trigger>
<Trigger SourceName="Popup"
Property="Popup.AllowsTransparency"
Value="true">
<Setter TargetName="DropDownBorder"
Property="CornerRadius"
Value="0" />
<Setter TargetName="DropDownBorder"
Property="Margin"
Value="0,0,0,0" />
</Trigger>
<Trigger Property="IsEditable"
Value="true">
<Setter Property="IsTabStop"
Value="false" />
<Setter TargetName="PART_EditableTextBox"
Property="Visibility"
Value="Visible" />
<Setter TargetName="ContentSite"
Property="Visibility"
Value="Hidden" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers />
</Style>
<!-- End Package Manager Styles -->
<Style x:Key="SComboBox_Update" TargetType="{x:Type ComboBox}">
<Setter Property="SnapsToDevicePixels" Value="true" />
Expand Down
161 changes: 161 additions & 0 deletions src/Libraries/CoreNodeModels/DefineData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using DSCore;
using Dynamo.Graph.Nodes;
using Newtonsoft.Json;
using ProtoCore.AST.AssociativeAST;
using VMDataBridge;


namespace CoreNodeModels
{
[NodeName("DefineData")]
[NodeDescription(nameof(Properties.Resources.RememberDescription), typeof(Properties.Resources))]
[NodeCategory("Core.Data")]
[InPortNames(">")]
[InPortTypes("var[]..[]")]
[InPortDescriptions(typeof(Properties.Resources),
nameof(Properties.Resources.RememberInputToolTip))]
[OutPortNames(">")]
[OutPortTypes("var[]..[]")]
[OutPortDescriptions(typeof(Properties.Resources), nameof(Properties.Resources.RememberOuputToolTip))]
[IsDesignScriptCompatible]
public class DefineData : DSDropDownBase
{
private bool context;
private List<DynamoDropDownItem> serializedItems;

[JsonProperty]
public bool IsList { get; set; }

/// <summary>
/// Copy of <see cref="DSDropDownBase.Items"/> to be serialized./>
/// </summary>
[JsonProperty]
protected List<DynamoDropDownItem> SerializedItems
{
get => serializedItems;
set
{
serializedItems = value;

Items.Clear();

foreach (DynamoDropDownItem item in serializedItems)
{
Items.Add(item);
}
}
}

/// <summary>
/// Construct a new DefineData Dropdown Menu node
/// </summary>
public DefineData() : base(">")
{
RegisterAllPorts();
PropertyChanged += OnPropertyChanged;

foreach (var dataType in Data.GetDataNodeDynamoTypeList())
{
var displayName = dataType.Name;
var value = dataType;

Items.Add(new DynamoDropDownItem(displayName, value));
}

SelectedIndex = 0;
}

[JsonConstructor]
private DefineData(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(">", inPorts, outPorts)
{
PropertyChanged += OnPropertyChanged;
}

private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{

}

protected override void OnBuilt()
{
base.OnBuilt();
DataBridge.Instance.RegisterCallback(GUID.ToString(), DataBridgeCallback);
}

public override void Dispose()
{
PropertyChanged -= OnPropertyChanged;
base.Dispose();
DataBridge.Instance.UnregisterCallback(GUID.ToString());
}

public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
var resultAst = new List<AssociativeNode>();

// function call inputs - reference to the function, and the function arguments coming from the inputs
// the object to be (type) evaluated
// the expected datatype
// if the input is an ArrayList or not
var function = new Func<object, string, bool, bool>(DSCore.Data.IsSupportedDataNodeDynamoType);
var funtionInputs = new List<AssociativeNode> {
inputAstNodes[0],
AstFactory.BuildStringNode((Items[SelectedIndex].Item as Data.DataNodeDynamoType).Type.ToString()),
AstFactory.BuildBooleanNode(IsList) };


var functionCall = AstFactory.BuildFunctionCall(function, funtionInputs);
var functionCallIdentifier = AstFactory.BuildIdentifier(GUID + "_func");

// build the function call
resultAst.Add(AstFactory.BuildAssignment(functionCallIdentifier, functionCall));

// build the output call
resultAst.Add(AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall));

// build the call for the DataBridge
resultAst.Add(AstFactory.BuildAssignment(functionCallIdentifier,
DataBridge.GenerateBridgeDataAst(GUID.ToString(),
AstFactory.BuildExprList(inputAstNodes))));


return resultAst;
}


/// <summary>
/// Not sure at the moment how relevant is the databridge for this node type
/// </summary>
/// <param name="data"></param>
private void DataBridgeCallback(object data)
{
var inputs = data as ArrayList;

var inputObject = inputs[0];

if (!InPorts[0].IsConnected)
{
return;
}

}


protected override SelectionState PopulateItemsCore(string currentSelection)
{
return SelectionState.Restore;
}

[OnSerializing]
private void OnSerializing(StreamingContext context)
{
serializedItems = Items.ToList();
}
}
}
81 changes: 81 additions & 0 deletions src/Libraries/CoreNodeModelsWpf/Controls/DefineDataControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<UserControl x:Class="CoreNodeModelsWpf.Controls.DefineDataControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:p="clr-namespace:Dynamo.Wpf.Properties"
xmlns:core="clr-namespace:Dynamo.Nodes;assembly=DynamoCoreWpf"
xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf"
mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="350">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoModernDictionaryUri}" />
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoConvertersDictionaryUri}" />
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoColorsAndBrushesDictionaryUri}" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="StrokeBrush" Color="#999999 " />

<PathGeometry x:Key="QuestionIcon" Figures="M8 0C3.58172 0 0 3.58172 0 8C0 12.4183 3.58172 16 8 16C12.4183 16 16 12.4183 16 8C16 5.87827 15.1571 3.84344 13.6569 2.34315C12.1566 0.842855 10.1217 0 8 0ZM9 14H7V12H9V14ZM10 8.45C9.38 8.74 9 8.95 9 9.45V11H7V8.92C6.97651 8.37388 7.19188 7.84457 7.59 7.47C8.05 7.06 9.75 6.56 9.75 5.59C9.75 5 9.45 4.33 8.23 4.33C6.75 4.33 6.23 6.66 6.23 6.66L4.45 6.25C4.45 6.25 4.86 2.39 8.25 2.39C9.13189 2.33809 9.99827 2.63874 10.6584 3.22576C11.3186 3.81279 11.7185 4.63809 11.77 5.52C11.8034 6.75866 11.1119 7.90321 10 8.45Z"/>
<PathGeometry x:Key="PadlockIcon" Figures="M 35 7 C 30.038 7 26 11.038 26 16 L 26 20 L 9 20 C 7.343 20 6 21.343 6 23 L 6 38 C 6 39.657 7.343 41 9 41 L 27 41 C 28.657 41 30 39.657 30 38 L 30 23 C 30 21.343 28.657 20 27 20 L 27 16 C 27 11.589 30.589 8 35 8 C 39.411 8 43 11.589 43 16 L 43 20.5 C 43 20.776 43.224 21 43.5 21 C 43.776 21 44 20.776 44 20.5 L 44 16 C 44 11.038 39.962 7 35 7 z M 9 21 L 27 21 C 28.105 21 29 21.895 29 23 L 29 38 C 29 39.105 28.105 40 27 40 L 9 40 C 7.895 40 7 39.105 7 38 L 7 23 C 7 21.895 7.895 21 9 21 z"/>
</ResourceDictionary>
</UserControl.Resources>
<DockPanel VerticalAlignment="Bottom">
<ToggleButton VerticalAlignment="Center"
Width="30"
Height="15"
Margin="2,0,0,0"
IsEnabled="True"
IsChecked="{Binding Path=StaticSplashScreenEnabled}"
Style="{StaticResource EllipseToggleButton1}"/>
<Label Content="List"
Margin="4 0"
Foreground="{StaticResource PreferencesWindowFontColor}"/>
<Canvas VerticalAlignment="Center" Width="14" Height="14">
<Viewbox Width="14" Height="14">
<Path x:Name="ExpandPath" Data="{StaticResource QuestionIcon}"
Fill="{StaticResource StrokeBrush}"
Stroke="{StaticResource StrokeBrush}">
</Path>
</Viewbox>
<Canvas.ToolTip>
<ToolTip Content="Fill in later"
Style="{StaticResource GenericToolTipLight}"/>
</Canvas.ToolTip>
</Canvas>

<Button Margin="0 0 10 3"
x:Name="LockButton"
BorderThickness="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Cursor="Hand">
<Button.ToolTip>
<ToolTip Content="Lock tooltup"
Style="{StaticResource GenericToolTipLight}" />
</Button.ToolTip>
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="Transparent">
<Viewbox Width="16"
Height="16"
VerticalAlignment="Center">
<Path x:Name="Folder"
Fill="#999999"
Data="{StaticResource PadlockIcon}"
StrokeThickness="1"
Stroke="{StaticResource StrokeBrush}">
</Path>
</Viewbox>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Folder" Property="Fill" Value="#6AC0E7" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</DockPanel>
</UserControl>
Loading
Loading