Skip to content

Commit

Permalink
added input toggle node. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksobon committed Jan 2, 2018
1 parent f6d7aae commit 487587e
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 0 deletions.
22 changes: 22 additions & 0 deletions _dynamoSamples/inputToggle.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Workspace Version="1.3.0.875" X="58.8025412446486" Y="-33.626820427704" zoom="0.954042924882813" ScaleFactor="1" Name="Home" Description="" RunType="Automatic" RunPeriod="1000" HasRunWithoutCrash="True">
<NamespaceResolutionMap />
<Elements>
<archilabUI.InputToggle.InputToggle guid="82446402-46b0-4cf5-84ef-ae1f6c13ba3c" type="archilabUI.InputToggle.InputToggle" nickname="Input Toggle" x="97.0405537288289" y="178.452665427908" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false" />
<CoreNodeModels.Input.StringInput guid="336219d9-61fa-4ee6-a022-6d656973ce0c" type="CoreNodeModels.Input.StringInput" nickname="String" x="340.219599564724" y="171.351359303558" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false">
<System.String>some string</System.String>
<System.String value="some string" />
</CoreNodeModels.Input.StringInput>
<DSRevitNodesUI.Categories guid="2cef9e78-1d01-472b-a265-c95fb09d69c6" type="DSRevitNodesUI.Categories" nickname="Categories" x="338.181259017963" y="240.942755344061" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false" index="2:AdaptivePoints_Planes" />
<CoreNodeModels.Input.DoubleSlider guid="ad8bb3e0-5170-46fc-a2c0-68a6596586d6" type="CoreNodeModels.Input.DoubleSlider" nickname="Number Slider" x="337.042035444359" y="337.27909446896" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false">
<System.Double>1</System.Double>
<Range min="0" max="100" step="0.1" />
</CoreNodeModels.Input.DoubleSlider>
</Elements>
<Connectors />
<Notes />
<Annotations />
<Presets />
<Cameras>
<Camera Name="Background Preview" eyeX="-17" eyeY="24" eyeZ="50" lookX="12" lookY="-13" lookZ="-58" upX="0" upY="1" upZ="0" />
</Cameras>
</Workspace>
18 changes: 18 additions & 0 deletions archilabUI/InputToggle/BoolToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Windows.Data;

namespace archilabUI.InputToggle
{
public class BoolToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (bool) value ? "Toggle Off" : "Toggle On";
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
53 changes: 53 additions & 0 deletions archilabUI/InputToggle/InputToggle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using Autodesk.DesignScript.Runtime;
using Dynamo.Graph.Nodes;
using Dynamo.ViewModels;
using ProtoCore.AST.AssociativeAST;
using GalaSoft.MvvmLight.Command;

namespace archilabUI.InputToggle
{
[NodeName("Input Toggle")]
[NodeCategory("archilab.Core.Utilities")]
[NodeDescription("Use this node to toggle the IsInput for ALL nodes in the definition ON/OFF.")]
[IsDesignScriptCompatible]
public class InputToggle : NodeModel
{
public WorkspaceViewModel WorkspaceViewModel { get; set; }
public RelayCommand ToggleInput { get; set; }

private bool _toggleState = true;
public bool ToggleState {
get { return _toggleState; }
set { _toggleState = value; RaisePropertyChanged("ToggleState"); }
}

public InputToggle()
{
RegisterAllPorts();
ArgumentLacing = LacingStrategy.Disabled;

ToggleInput = new RelayCommand(OnToggleInput);
}

private void OnToggleInput()
{
ToggleState = !ToggleState;
foreach (var node in WorkspaceViewModel.Nodes)
{
if (!node.IsInput) continue;

node.IsSetAsInput = ToggleState;
}
}

[IsVisibleInDynamoLibrary(false)]
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
return new[]
{
AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode())
};
}
}
}
21 changes: 21 additions & 0 deletions archilabUI/InputToggle/InputToggleView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<UserControl x:Class="archilabUI.InputToggle.InputToggleView"
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:local="clr-namespace:archilabUI.InputToggle"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.Resources>
<local:BoolToStringConverter x:Key="BoolToString" />
</Grid.Resources>
<Button x:Name="ButtonToggle"
Content="{Binding ToggleState, Converter={StaticResource BoolToString}}"
Command="{Binding ToggleInput}"
HorizontalAlignment="Stretch"
Margin="0"
VerticalAlignment="Stretch"/>

</Grid>
</UserControl>
14 changes: 14 additions & 0 deletions archilabUI/InputToggle/InputToggleView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

namespace archilabUI.InputToggle
{
/// <summary>
/// Interaction logic for InputToggleView.xaml
/// </summary>
public partial class InputToggleView
{
public InputToggleView()
{
InitializeComponent();
}
}
}
28 changes: 28 additions & 0 deletions archilabUI/InputToggle/InputToggleViewCustomization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Dynamo.Controls;
using Dynamo.Wpf;

namespace archilabUI.InputToggle
{
internal class InputToggleViewCustomization : INodeViewCustomization<InputToggle>
{
private InputToggle _viewModel;
private InputToggleView _view;

public void CustomizeView(InputToggle model, NodeView nodeView)
{
_viewModel = model;
_viewModel.WorkspaceViewModel = nodeView.ViewModel.WorkspaceViewModel;
_view = new InputToggleView
{
DataContext = model,
MaxHeight = 300,
MaxWidth = 200
};
nodeView.inputGrid.Children.Add(_view);
}

public void Dispose()
{
}
}
}
10 changes: 10 additions & 0 deletions archilabUI/archilabUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@
<Compile Include="Dropdowns.cs" />
<Compile Include="DropdownToList.cs" />
<Compile Include="DSDropDownBase.cs" />
<Compile Include="InputToggle\BoolToStringConverter.cs" />
<Compile Include="InputToggle\InputToggle.cs" />
<Compile Include="InputToggle\InputToggleView.xaml.cs">
<DependentUpon>InputToggleView.xaml</DependentUpon>
</Compile>
<Compile Include="InputToggle\InputToggleViewCustomization.cs" />
<Compile Include="ListSelector\ListSelector.cs" />
<Compile Include="ListSelector\ListSelectorView.xaml.cs">
<DependentUpon>ListSelectorView.xaml</DependentUpon>
Expand Down Expand Up @@ -208,6 +214,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="InputToggle\InputToggleView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ListSelector\ListSelectorView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down

0 comments on commit 487587e

Please sign in to comment.