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-7943] Custom node cannot be added to its own workspace. #15783

Merged
merged 8 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

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

5 changes: 4 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4102,7 +4102,10 @@ To make this file into a new template, save it to a different folder, then move
<data name="PackageVersionTooltip" xml:space="preserve">
<value>Versions marked with .x include all versions in the specified major or minor release</value>
</data>
<data name="CannotAddNodeToWorkspace" xml:space="preserve">
<value>You cannot place a custom node directly to its own workspace. You can use the scopeif node and correctly implement the recursive base case.</value>
</data>
<data name="PackageUnknownCompatibilityVersionDownloadMsg" xml:space="preserve">
<value>The compatibility of this version with your setup has not been verified. It may or may not work as expected.</value>
</data>
</root>
</root>
5 changes: 4 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4089,7 +4089,10 @@ To make this file into a new template, save it to a different folder, then move
<data name="PackageVersionTooltip" xml:space="preserve">
<value>Versions marked with .x include all versions in the specified major or minor release</value>
</data>
<data name="CannotAddNodeToWorkspace" xml:space="preserve">
<value>You cannot place a custom node directly to its own workspace. You can use the scopeif node and correctly implement the recursive base case.</value>
</data>
<data name="PackageUnknownCompatibilityVersionDownloadMsg" xml:space="preserve">
<value>The compatibility of this version with your setup has not been verified. It may or may not work as expected. </value>
</data>
</root>
</root>
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5592,6 +5592,7 @@ static Dynamo.Wpf.Properties.Resources.WorkspaceTabSavingUnnecessary.get -> stri
static Dynamo.Wpf.Properties.Resources.WorkspaceTabTooltipHeaderUnsaved.get -> string
static Dynamo.Wpf.Properties.Resources.ZeroTouchTypeShortString.get -> string
static Dynamo.Wpf.Properties.Resources.ZoomLevel.get -> string
static Dynamo.Wpf.Properties.Resources.CannotAddNodeToWorkspace.get -> string
static Dynamo.Wpf.Rendering.RenderPackageExtensions.AllLineStripVerticesHaveColor(this Autodesk.DesignScript.Interfaces.IRenderPackage package, System.Windows.Media.Color color) -> bool
static Dynamo.Wpf.UI.GuidedTour.GuideFlowEvents.GuidedTourExited -> Dynamo.Wpf.UI.GuidedTour.GuidedTourExitedEventHandler
static Dynamo.Wpf.UI.GuidedTour.GuideFlowEvents.GuidedTourFinish -> Dynamo.Wpf.UI.GuidedTour.GuidedTourFinishEventHandler
Expand Down
15 changes: 15 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,21 @@ protected virtual void OnClicked()
try
{
var nodeModel = Model.CreateNode();

// check to make sure a custom node cannot be added to its own workspace.
var dynamoViewModel = searchViewModel.dynamoViewModel;

if (dynamoViewModel.CurrentSpace is CustomNodeWorkspaceModel customNodeWorkspaceModel)
{
var nodeGuid = Guid.Parse(nodeModel.CreationName);

if (nodeGuid.Equals(customNodeWorkspaceModel.CustomNodeId))
{
dynamoViewModel.MainGuideManager.CreateRealTimeInfoWindow(Properties.Resources.CannotAddNodeToWorkspace);
return;
}
}

Clicked(nodeModel, Position);
}
catch (Exception ex)
Expand Down
14 changes: 14 additions & 0 deletions src/LibraryViewExtensionWebView2/LibraryViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Windows.Input;
using CoreNodeModels.Properties;
using Dynamo.Extensions;
using Dynamo.Graph.Workspaces;
using Dynamo.LibraryViewExtensionWebView2.Handlers;
using Dynamo.LibraryViewExtensionWebView2.ViewModels;
using Dynamo.LibraryViewExtensionWebView2.Views;
Expand Down Expand Up @@ -187,6 +188,19 @@ public void CreateNode(string nodeName)
{
this.disableObserver = true;
}

// check to make sure a custom node cannot be added to its own workspace.
if (dynamoViewModel.CurrentSpace is CustomNodeWorkspaceModel customNodeWorkspaceModel)
{
var nodeGuid = Guid.Parse(nodeName);

if (nodeGuid.Equals(customNodeWorkspaceModel.CustomNodeId))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @QilongTang was suggesting that in this check you iterate all the other nodes and make sure that one of them is scopeif OR you defer this check until they try to save the .dyf.

Copy link
Member

@mjkkirschner mjkkirschner Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you wanted to get really fancy you could try to determine if they have the scope if hooked up correctly or at least in a topology where it has even a remote chance of working...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, looking into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the changes to look for the scopeif node in the custom node workspace and only then allow users to place the custom node in its own workspace. Modified the notification message accordingly.
As this freeze/hang happens mainly when that particular custom node instance is also present in the home workspace and is executed automatically, doing this check during saving the dyf wouldn't fix this case.

Copy link
Member

@mjkkirschner mjkkirschner Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about also switching them into manual run mode when this occurs - I think we have a notification for this already under some circumstances? Maybe when using tuneup - or at least we did that previously.

Copy link
Contributor Author

@reddyashish reddyashish Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes made the change to also set the homeworkspace to manual mode, when this case arises.

{
dynamoViewModel.MainGuideManager.CreateRealTimeInfoWindow(Properties.Resources.CannotAddNodeToWorkspace);
return;
}
}

//Create the node of given item name
var cmd = new DynamoModel.CreateNodeCommand(Guid.NewGuid().ToString(), nodeName, -1, -1, true, false);
commandExecutive.ExecuteCommand(cmd, Guid.NewGuid().ToString(), LibraryViewExtensionWebView2.ExtensionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<!--This command updates the npm registry configuration if necessary-->
<Exec Command="&quot;$(PowerShellCommand)&quot; -ExecutionPolicy ByPass -Command &quot;&amp; '$(SolutionDir)setnpmreg.ps1'&quot;" Condition="$(ShouldInstall)" />
<!--This command gets a specific build of the notifcation center from npm-->
<Exec Command="npm pack @dynamods/librariejs@$(PackageVersion)" Condition="$(ShouldInstall)"/>
<Exec Command="npm pack @dynamods/librariejs@$(PackageVersion)" Condition="$(ShouldInstall)" />
</Target>

<Target Name="ExtractTGZFile" BeforeTargets="BeforeBuild" Condition="$(ShouldInstall)">
Expand Down Expand Up @@ -229,6 +229,28 @@
<ItemGroup>
<ProjectReference Include="..\DynamoCoreWpf\DynamoCoreWpf.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Resources.en-US.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.en-US.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.en-US.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.en-US.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="AfterBuildOps" AfterTargets="Build">
<ItemGroup>
<ExtensionDefinition Include="Library_ViewExtensionDefinition.xml" />
Expand Down
81 changes: 81 additions & 0 deletions src/LibraryViewExtensionWebView2/Properties/Resources.Designer.cs

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

123 changes: 123 additions & 0 deletions src/LibraryViewExtensionWebView2/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CannotAddNodeToWorkspace" xml:space="preserve">
<value>You cannot place a custom node directly to its own workspace. You can use the scopeif node and correctly implement the recursive base case.</value>
</data>
</root>
Loading
Loading