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

Node auto layout for node autocomplete #11177

Merged
merged 18 commits into from
Oct 15, 2020

Conversation

aparajit-pratap
Copy link
Contributor

@aparajit-pratap aparajit-pratap commented Oct 13, 2020

Purpose

https://jira.autodesk.com/browse/DYN-2978

This builds on top of PR #11164.

The node chosen from node autocomplete suggestions is created, connected, and then placed relative to the initial node using the graph auto layout. A single undo-recorder group is initialized for this entire operation so that it can be undone in a single step. The following are the sequence of steps:

  1. A new undo-redo recorder group is first initialized
  2. A new option is added to the CreateAndConnectCommand to make it use an existing undo-redo recorder group instead of creating a new one
  3. The NodeViewReady event on DynamoViewModel is subscribed to. Only when this event is raised does the size of the new node created get set. Only once the size is set, can graph layout work correctly.
  4. In the NodeViewReady event handler the graph auto layout is performed using only the input nodes to the initial node. This is to ensure that the initial node does not jump to a new location on graph layout.
  5. The undo-redo group is finally disposed and the event unsubscribed.

Please hide whitespace to review this PR.

place_and_connect_nodes_final

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • 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
  • All tests pass using the self-service CI.
  • 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

FYIs

@Amoursol

@aparajit-pratap aparajit-pratap changed the title Node auto layout Node auto layout for node autocomplete Oct 13, 2020

// Clear current selections and select all input nodes
DynamoSelection.Instance.ClearSelection();
var inputNodes = portModel.Owner.InputNodes.Values.Where(x => x != null).Select(y => y.Item2);
Copy link
Contributor

@QilongTang QilongTang Oct 14, 2020

Choose a reason for hiding this comment

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

Can you explain the Item2 part? I think I tried this one before by just calling Select and did not work.. Maybe i missed something. You are doing some smart thing for sure 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, nothing smart here. InputNodes property on NodeModel is of type IDictionary<int, Tuple<int, NodeModel>>. I'm just getting the NodeModel part of the tuple.

Copy link
Contributor

@QilongTang QilongTang left a comment

Choose a reason for hiding this comment

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

LGTM

@QilongTang
Copy link
Contributor

If there is a chance, I would like to get some knowledge share around undo/redo recorder and what it means to reuse it. That is the only piece I am not sure if the way in this PR will be something we want to promote in the feature.

@aparajit-pratap
Copy link
Contributor Author

aparajit-pratap commented Oct 15, 2020

@QilongTang I have done some final refactor - I have moved the commands from SearchViewModel to NodeSearchElementViewModel. It's a little cleaner this way as there is less event redirection. It would be great if you could review one last time.

var adjustedX = initialNodeVm.X;

var createAsDownStreamNode = portModel.PortType == PortType.Output;
// Placing the new node based on which input port it is connecting to.
Copy link
Contributor

Choose a reason for hiding this comment

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

Which port?

Model.CreationName, 0, portModel.Index, adjustedX, 0, createAsDownStreamNode, false, true));

// Clear current selections and select all input nodes as we need to perform Auto layout on only the input nodes.
DynamoSelection.Instance.ClearSelection();
Copy link
Contributor

Choose a reason for hiding this comment

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

@aparajit-pratap Do you know if selection is part of undo/redo sequence? I have been thinking about if there could be any side effects to this but in general feels OK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not part of the undo/redo sequence. I think you'll need to use one of the selection related commands to add it to undo/redo queue.

@aparajit-pratap aparajit-pratap merged commit 17f1104 into DynamoDS:master Oct 15, 2020
@aparajit-pratap aparajit-pratap deleted the NodeAutoLayout branch October 15, 2020 13:31
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.

2 participants