Skip to content

[DYN-8997] CBN output port to show the name of the variable #16300

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ivaylo-matov
Copy link
Contributor

Purpose

This PR aims to address DYN-8997.

Changes:

  • CBN outports now display the left-hand variable/identifier of each code statement (previously just “>”)
  • For single-statement code blocks:
    • The outport is rendered in standard size (34px) and always positioned at the very top, aligned with the inport, regardless of any comments or empty lines above the statement
    • The outport tooltip always displays the left side of the statement
    • Adding or removing comments or empty lines above does not affect the outport’s vertical position
  • For multiple-statement code blocks:
    • Outports are displayed in condensed size and each shows the left side of its statement.
    • Each outport is vertically aligned with its respective statement line.
    • Tooltips also reflect the left side of each statement.
  • Fixed an issue where inports and outports sharing the same name could cause connector restoration to fail after code edits. Logic now ensures unique identification for each port and prevents connector loss or duplication.
  • The above behaviors are also applied to proxy ports in collapsed groups.

DYN-8997-CodeBlockNode outputs

Declarations

Check these if you believe they are true

  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB
  • This PR introduces new feature code involve network connecting and is tested with no-network mode.

Release Notes

The output port of code block node now displays the left side of the statement.

Reviewers

@DynamoDS/eidos
@jasonstratton.

FYIs

@dnenov
@achintyabhat

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

See the ticket for this pull request: https://jira.autodesk.com/browse/DYN-8997

@zeusongit zeusongit requested review from a team and Copilot June 18, 2025 01:59
Copilot

This comment was marked as outdated.

@aparajit-pratap
Copy link
Contributor

aparajit-pratap commented Jun 18, 2025

This looks weird and is a deviation from current output port alignment:
image

The output port should always be placed against the identifier.

@@ -1007,19 +1025,23 @@ private void SetOutputPorts()
// Clear out all the output port models
OutPorts.RemoveAll((p) => true);

// Add an output port for each definition. If there is only one port, force it to the top (LineIndex = 0)
// regardless of code line, so it is not shifted by comments or empty lines.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aparajit-pratap , this design was suggested during last week's canthup - the idea was to keep the single output port aligned with the input port. I’ll bring up your concern with the team in today’s meeting, and I’ll make adjustments if agreed.

foreach (var def in allDefs)
{
var tooltip = IsTempIdentifier(def.Key) ? string.Format(Resources.CodeBlockTempIdentifierOutputLabel, def.Value) : def.Key;
string portLabel = outputPortNames.TryGetValue(def.Key, out var label) ? label : string.Empty;
int lineIndex = (totalPorts == 1) ? 0 : def.Value - 1;
Copy link
Contributor

@aparajit-pratap aparajit-pratap Jun 18, 2025

Choose a reason for hiding this comment

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

I would strongly suggest lineIndex to always be set to def.Value - 1.

// Special case: When a code block node has multiple outputs, its output ports are smaller than regular node outputs.
// Adding +9 here ensures the first code block output aligns visually with the first input port of any node.
// For a single output port, we skip this offset so the port and its connector are centered at the very top,
// regardless of any empty lines or comments in the code block.
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, I disagree with this design.

Copy link
Contributor

@aparajit-pratap aparajit-pratap left a comment

Choose a reason for hiding this comment

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

I suggest removing the special condition for a single statement CBN to have the output port always placed at the topmost line. I don't see why it's needed. I agree with the idea of showing the single output port be bigger than when there are multiple ports but I strongly feel that the output port should always align with the code statement, even when there are whitespaces or comments.

In other words, the placement of the output port should be like it is currently:
image

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the CBN output port behavior so that it displays the variable name used on the left-hand side of code statements, ensuring proper alignment and tooltip display for both single and multiple statement code blocks. It also fixes a connector restoration issue by enforcing unique port identification.

  • Outport controls are updated to adjust styling and margins based on the number of code block outputs.
  • A new property (IsOnlyOutputPortInCodeBlock) has been introduced to differentiate single from multiple output ports.
  • Layout adjustments and API documentation updates have been applied across several files to support these changes.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs Adjusted outport margins and styling for CodeBlockNodes based on port count.
src/DynamoCoreWpf/ViewModels/Core/PortViewModel.cs Added property to check for a single output port in code blocks.
src/DynamoCoreWpf/ViewModels/Core/OutPortViewModel.cs Updated condensed port condition to incorporate single port logic.
src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs Revised port positioning and introduced a constant for collapsed port height.
src/DynamoCoreWpf/PublicAPI.Unshipped.txt Exposed the new IsOnlyOutputPortInCodeBlock property.
src/DynamoCoreWpf/Controls/OutPorts.xaml.cs Modified UI element margins and sizes based on the port type.
src/DynamoCore/Graph/Nodes/PortModel.cs Adjusted center position calculation to correctly offset code block outputs.
src/DynamoCore/Graph/Nodes/CodeBlockNode.cs Cleared and built output port labels with adjusted line indexing for single vs. multiple ports.

@@ -805,6 +806,7 @@ private void ProcessCode(out string errorMessage, out string warningMessage,
OutPorts.Clear();
InPorts.Clear();
inputPortNames.Clear();
outputPortNames.Clear();
Copy link
Preview

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

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

[nitpick] There are multiple calls to outputPortNames.Clear() in the ProcessCode method. Consolidating these calls may prevent potential redundancy and clarify the port name collection process.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@jasonstratton jasonstratton left a comment

Choose a reason for hiding this comment

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

This change appears pretty straightforward. I do understand Aparajit's objection and barring a change in the requirements there, I think this looks good to go.

@@ -32,6 +32,9 @@ public class AnnotationViewModel : ViewModelBase
private ObservableCollection<Dynamo.Configuration.StyleItem> groupStyleList;
private IEnumerable<Configuration.StyleItem> preferencesStyleItemsList;
private PreferenceSettings preferenceSettings;
// TODO: Investigate why collapsed group ports appear 0.655px taller than actual port height.
// This constant is currently used to visually align collapsed ports for CBNs with multiple outputs.
private const double CodeBlockCollapsedPortVisualHeight = 17;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good to document this one and use a const as it is even more magical due to the unknown nature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants