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

Python engine property should copy/paste and undo correctly. #11006

Merged
merged 8 commits into from
Aug 17, 2020

Conversation

mjkkirschner
Copy link
Member

@mjkkirschner mjkkirschner commented Aug 14, 2020

Purpose

https://jira.autodesk.com/browse/DYN-3022
Some properties of nodeModel cannot be undone using undo/redo and do not copy/paste correctly. This includes the new Engine property on Python nodes.

This PR does the following:

  • adds xml serialization and deserialization of the missing properties to NodeModel and PythonNodeModel classes, as the undo redo recorder and copy/paste rely on legacy xml model serialization.

  • adds cases for the updateModelValue command handler on NodeModel to handle the properties we want to be undoable.

  • in the viewModel layer - anywhere we wish to have undoable property settings, we use a UpdateModelValueCommand to set the property, these are automatically serialized into the undo/redo recorder.

  • tests are added for the nodeModel properties, and for the Python engine properties.

  • Fix a small issue with the PythonNodeViewCustmizationTests and when the python engines were being scanned for to update the available engines.

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

@mjkkirschner mjkkirschner changed the title Pythonundo Python engine property should copy/paste and undo correctly. Aug 14, 2020
{
libraries.Add("DSCPython.dll");
libraries.Add("DSIronPython.dll");
base.Start();
Copy link
Contributor

@QilongTang QilongTang Aug 14, 2020

Choose a reason for hiding this comment

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

Can you remind me what does base.Start() do?

Copy link
Member Author

@mjkkirschner mjkkirschner Aug 14, 2020

Choose a reason for hiding this comment

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

a bunch of stuff, it basically starts the DynamoModel, and in this case the View as well.

Assert.AreEqual(new List<string> { "2.7.9", "3.8.3" }, pynode2.CachedValue.GetElements().Select(x => x.Data));
DispatcherUtil.DoEvents();
Model.CurrentWorkspace.Undo();
Assert.AreEqual(new List<string> { "3.8.3", "3.8.3" }, pynode2.CachedValue.GetElements().Select(x => x.Data));
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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.

Thank you for adding tests for the other newly supported commands within this PR. Looks good to me

@@ -251,6 +269,10 @@ protected override void SerializeCore(XmlElement element, SaveContext context)
XmlElement script = element.OwnerDocument.CreateElement("Script");
script.InnerText = this.script;
element.AppendChild(script);
XmlElement engine = element.OwnerDocument.CreateElement(nameof(Engine));
engine.InnerText = Enum.GetName(typeof(PythonEngineVersion), Engine);
element.AppendChild(engine);
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems these can still be easily converted to use Json in the future

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. The fact that there are things in Dynamo depending on XML serialization, when we have obsoleted it, is scary.

Copy link
Member Author

@mjkkirschner mjkkirschner Aug 17, 2020

Choose a reason for hiding this comment

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

I will file a task to do a spike on this, I believe we did one way back when we looked at JSON originally, maybe I can dig up some notes.

Copy link
Collaborator

@mmisol mmisol left a comment

Choose a reason for hiding this comment

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

Added some minor comments. Looks good overall

nodeLogic.IsSetAsInput = value;
RaisePropertyChanged("IsSetAsInput");
DynamoViewModel.ExecuteCommand(
new DynamoModel.UpdateModelValueCommand(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you check formatting here? If this was Python the statement would be outside the if :)

nodeLogic.IsSetAsOutput = value;
RaisePropertyChanged("IsSetAsOutput");
DynamoViewModel.ExecuteCommand(
new DynamoModel.UpdateModelValueCommand(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

RaisePropertyChanged("IsDisplayingLabels");

DynamoViewModel.ExecuteCommand(
new DynamoModel.UpdateModelValueCommand(
Copy link
Collaborator

Choose a reason for hiding this comment

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

No if for this property?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I'm not sure why that is, I didn't touch it because it didn't exist before and was present for those other properties - I can make the change and see if there are any test failures if you would like.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess it would be more consistent but not really required. Your call

@@ -251,6 +269,10 @@ protected override void SerializeCore(XmlElement element, SaveContext context)
XmlElement script = element.OwnerDocument.CreateElement("Script");
script.InnerText = this.script;
element.AppendChild(script);
XmlElement engine = element.OwnerDocument.CreateElement(nameof(Engine));
engine.InnerText = Enum.GetName(typeof(PythonEngineVersion), Engine);
element.AppendChild(engine);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. The fact that there are things in Dynamo depending on XML serialization, when we have obsoleted it, is scary.

@@ -386,6 +386,111 @@ public void CanAdd100NodesToClipboardAndPaste()
Assert.AreEqual(numNodes * 2, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
}

[Test]
[Category("UnitTests")]
public void CanCopydAndPasteAndUndoShowLabels()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo Copyd => Copy. I see this is consistently copied over to other tests.

@mjkkirschner mjkkirschner added this to the 2.8 milestone Aug 17, 2020
@mjkkirschner mjkkirschner merged commit 3a35539 into DynamoDS:master Aug 17, 2020
mjkkirschner added a commit to mjkkirschner/Dynamo that referenced this pull request Aug 17, 2020
mjkkirschner added a commit that referenced this pull request Aug 18, 2020
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