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-5018 wires disappear when moving group #12997

Merged

Conversation

filipeotero
Copy link
Contributor

@filipeotero filipeotero commented Jun 14, 2022

Purpose

In this PR, the position of the wires is calculated based on the height of the port that is created after the group is collapsed.
Previously, we were assuming that all the ports have the same height, causing a mispositioning of the wires.

image

image

Positionwires

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

Reviewers

@QilongTang @pinzart @reddyashish

@@ -260,6 +262,15 @@ public bool IsExpanded
AddGroupToGroupCommand.RaiseCanExecuteChanged();
RaisePropertyChanged(nameof(IsExpanded));
RedrawConnectors();
ReportNodesPosition();
Copy link
Contributor

Choose a reason for hiding this comment

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

node.ReportPosition is an expensive operation when dealing with a lot of nodes under the same group.
Please check the performance with (there should be a .dyn you can use in this jira taks

Also take a look at what code paths might be calling the IsExpanded setter (to get a better idea what to test) - could be direct function calls or RaisePropertyChanges...

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not call UpdateProxyPortsPosition directly...instead of having to go through the nodeModel's position ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is for when the group is uncollapsed and the annotation inside it needs to report the position. Otherwise, that's what happens:
annotationNode

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is no performance penalty in doing "node.ReportPosition" then it is fine.
The fix would be to make the Connectors redraw when the corresponding NodeModels(start or end) change their IsProxyPort flag
https://github.com/DynamoDS/Dynamo/blob/master/src/DynamoCoreWpf/ViewModels/Core/ConnectorViewModel.cs#L1209


// calculate new position for the proxy inports.
model.Center = CalculatePortPosition(model, i);
var originalPort = originalPortViewModels.FirstOrDefault(x => x.PortModel.GUID == group.GUID);
Copy link
Member

@mjkkirschner mjkkirschner Jun 14, 2022

Choose a reason for hiding this comment

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

I'm, confused by this, but not super familiar with this code, when would the guid of a group equal the guid of a port model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the group's port. I will change the variable to groupPort to avoid confusion. Thanks.

@@ -245,9 +245,11 @@ public bool IsExpanded
set
{
annotationModel.IsExpanded = value;
Copy link
Contributor

@pinzart90 pinzart90 Jun 14, 2022

Choose a reason for hiding this comment

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

As a possible improvement:
If the IsExpanded flag can be changed from other places in Dynamo ....I think would be better to listen to the model.IsExpanded OnPropertyChanged...and only keep the annotationModel.IsExpanded = value; in the setter.

annotationModel.PropertyChanged += OnModelPropertyChanged;
OnModelPropertyChanged(sender, e) {
if (e.PropertyName == "IsExpanded") {
InPorts.Clear();
OutPorts.Clear();
if (value)
{
this.ShowGroupContents();
}
else
{
this.SetGroupInputPorts();
this.SetGroupOutPorts();
this.CollapseGroupContents(true);
RaisePropertyChanged(nameof(NodeContentCount));
}
WorkspaceViewModel.HasUnsavedChanges = true;
.............the whole setter content............
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, let's do that on another PR

@@ -1081,10 +1097,12 @@ private void model_PropertyChanged(object sender, System.ComponentModel.Property
RaisePropertyChanged("Width");
RaisePropertyChanged(nameof(ModelAreaRect));
UpdateAllGroupedGroups();
UpdateProxyPortsPosition();
Copy link
Contributor

Choose a reason for hiding this comment

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

check performance here...
When moving a group (drag with mouse) ...these properties can get changed a lot of times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will check an alternative for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

check if performance is an issue first...then check alternatives
No use in doing premature optimization

@filipeotero
Copy link
Contributor Author

Instead of calling the UpdateProxyPortsPosition method every time the width changes, the method is being called on GroupTextBox_OnTextChanged which was updating of the width of the group, but not the center of its ports.

@@ -536,11 +547,15 @@ private bool CanChangeFontSize(object obj)
public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationModel model)
{
annotationModel = model;
var modelBase = (ModelBase)model;
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you need to cast it to ModelBase ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

this.WorkspaceViewModel = workspaceViewModel;
this.preferenceSettings = WorkspaceViewModel.DynamoViewModel.PreferenceSettings;
model.PropertyChanged += model_PropertyChanged;
model.RemovedFromGroup += OnModelRemovedFromGroup;
model.AddedToGroup += OnModelAddedToGroup;
modelBase.PropertyChanged += ModelBase_PropertyChanged;
Copy link
Contributor

Choose a reason for hiding this comment

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

there already is a handler for the model PropertyChange event

model.PropertyChanged += model_PropertyChanged;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

switch (e.PropertyName)
{
case nameof(annotationModel.Position):
UpdateProxyPortsPosition();
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to move this to model_PropertyChanged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@@ -625,7 +649,6 @@ internal void SetGroupInputPorts()
/// </summary>
internal void SetGroupOutPorts()
{
OutPorts.Clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you remove OutPorts.Clear(); ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because now it is called at the beginning of the isExpanded property.

Copy link
Contributor

Choose a reason for hiding this comment

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

so now SetGroupInputPorts and SetGroupOutPorts will always append ports to OutPorts and InPorts. I hope nobody uses these functions expecting the port arrays to be re-set ...as the func names suggest. Can you make these functions private and maybe add to the description that they always append to the respective port arrays ?

Copy link
Contributor Author

@filipeotero filipeotero Jun 23, 2022

Choose a reason for hiding this comment

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

Sure, they were edited.

internal void SetGroupInputPorts()
{
InPorts.Clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you remove InPorts.Clear(); ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here

/// Creates input ports for the group based on its Nodes.
/// Input ports that either is connected to a Node outside of the
/// group, or has a port that is not connected will be used for the group.
/// </summary>
Copy link
Contributor

@pinzart90 pinzart90 Jun 23, 2022

Choose a reason for hiding this comment

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

looks like the formatting got messed up

@QilongTang QilongTang merged commit 0174e38 into DynamoDS:master Jun 25, 2022
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.

4 participants