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

BHoM_Engine: Add and Query Fragments #1185

Merged
merged 5 commits into from
Sep 14, 2019

Conversation

michaldengusiak
Copy link
Member

@michaldengusiak michaldengusiak commented Sep 11, 2019

NOTE: Depends on

Issues addressed by this PR

Closes #1184

Add Modify AddFragments

Test files

N/A

Changelog

  • Add node to Modify AddFragments
  • Add node Query FindFragment

Additional comments

Copy link
Contributor

@FraserGreenroyd FraserGreenroyd left a comment

Choose a reason for hiding this comment

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

This is not the right place for a method which will be needed by so many disciplines. This will result in duplicated code in every engine.

@michaldengusiak
Copy link
Member Author

ok, I implemented comments and moved to the correct place as advice

Copy link
Contributor

@FraserGreenroyd FraserGreenroyd left a comment

Choose a reason for hiding this comment

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

PR

  • Change PR title to reflect the actual engine being modified and to correctly identify the change
  • Bullet point the change log as there are 2 changes here

Code

  • See comments on the code

[Input("iBHoMObject", "Any object implementing the IBHoMObject interface that can have fragment properties appended to it")]
[Input("fragment", "Any fragment object implementing the IBHoMFragment interface to append to the object")]
[Output("iBHoMObject", "The BHoM object with the added fragment")]
public static IBHoMObject AddFragment(this IBHoMObject iBHoMObject, IBHoMFragment fragment)
Copy link
Contributor

Choose a reason for hiding this comment

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

As per the discussion on #1184 I would like to see an optional bool (set to false initially) that allows users to replace fragments if they already exist.
Similarly, if the input is false, we should check if the fragment exists and return an error if it does. See discussion on #1184 for more info.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another thing on this method, You will need to clone the object to be changed as well as its list before modifying it. Either use the DeepClone method in the BHoMEngine, or shallow clone the object, and copy the fragment list. Right now, the incoming objects will be changed, changing things upstream in an visual programming workflow.

Copy link
Contributor

@IsakNaslundBh IsakNaslundBh left a comment

Choose a reason for hiding this comment

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

added comment

[Input("iBHoMObject", "Any object implementing the IBHoMObject interface that can have fragment properties appended to it")]
[Input("fragment", "Any fragment object implementing the IBHoMFragment interface to append to the object")]
[Output("iBHoMObject", "The BHoM object with the added fragment")]
public static IBHoMObject AddFragment(this IBHoMObject iBHoMObject, IBHoMFragment fragment)
Copy link
Contributor

Choose a reason for hiding this comment

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

Another thing on this method, You will need to clone the object to be changed as well as its list before modifying it. Either use the DeepClone method in the BHoMEngine, or shallow clone the object, and copy the fragment list. Right now, the incoming objects will be changed, changing things upstream in an visual programming workflow.

Copy link
Contributor

@FraserGreenroyd FraserGreenroyd left a comment

Choose a reason for hiding this comment

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

My previous comments have not yet been addressed. Requesting changes to ensure they are addressed before this is merged.

Copy link
Contributor

@FraserGreenroyd FraserGreenroyd left a comment

Choose a reason for hiding this comment

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

This is a good improvement, some minor comments relating to style and documentation in the code (functionality is good). See below.

PR

  • Change PR title to reflect the actual engine being modified and to correctly identify the change
  • Bullet point the change log as there are 2 changes here

Code

  • See comments on the code

if(o.Fragments.Contains(fragment))
{
if(replace)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Use single line if statements given these are single line operations

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}
else
{
Reflection.Compute.RecordError("Fragment already exists");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we expand this error message to tell the user something like "That fragment already exists on this object. If you would like to replace the existing fragment set the 'replace' input to 'true'"

Copy link
Member Author

Choose a reason for hiding this comment

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

done

[Description("Appends a Fragment Property to a given BHoM Object")]
[Input("iBHoMObject", "Any object implementing the IBHoMObject interface that can have fragment properties appended to it")]
[Input("fragment", "Any fragment object implementing the IBHoMFragment interface to append to the object")]
[Input("replace", "If true will replace exisiting fragments ")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Expand the description to be more informative for the user, Something like "If set to true and the object already contains a fragment of the type being added, the fragment will be replaced by this instance"

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@michaldengusiak michaldengusiak changed the title Physical_Engine: Add Modify AddFragments BHoM_Engine: Add Modify AddFragments Sep 14, 2019
@FraserGreenroyd FraserGreenroyd changed the title BHoM_Engine: Add Modify AddFragments BHoM_Engine: Add and Query Fragments Sep 14, 2019
Copy link
Contributor

@FraserGreenroyd FraserGreenroyd left a comment

Choose a reason for hiding this comment

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

Finally LGTM

@FraserGreenroyd
Copy link
Contributor

While this LGTM now and will be merged in to unblock on the workflows, @michaldengusiak please can you raise issues to deprecate the existing methods within the Environment Engine which do similar functionality. Please assign to me and put on the 2.4RC milestone. Cheers!

@FraserGreenroyd FraserGreenroyd merged commit d5cc6a6 into master Sep 14, 2019
@FraserGreenroyd FraserGreenroyd deleted the Physical_Engine-Issue1184-AddFragments branch September 14, 2019 20:54
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.

Physical_Engine: Modify AddFragments
3 participants