-
Notifications
You must be signed in to change notification settings - Fork 7
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
CreateObject component to include default constructor for each BHoM object type #147
Conversation
Hi @adecler ! I added the |
Thanks @epignatelli , we are starting to have a bit too many labels for it not to be at least a bit confusing :-P. This PR can already be reviewed within the context of what it already promises (i.e. a new component that merges CreateObject and CreateCustom). |
This is now ready for review and merging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments in the code. Generally I love it!
@@ -35,15 +35,23 @@ public static partial class Convert | |||
|
|||
[Input("property", "The system property to convert to bhom")] | |||
[Output("parameter", "The bhom parameter used in the bhom abstract syntax")] | |||
public static oM.UI.ParamInfo ToBHoM(this PropertyInfo property) | |||
public static oM.UI.ParamInfo ToBHoM(this PropertyInfo property, object instance = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have had this problem as well some times.
A Convert
method should accept only one argument, correct?
Not saying that we need to change this, just trying to understand for the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is for sure a rare case. I couldn't really find a better way of doing this (if we actually end up needing it as it is currently placeholder code for further development). I guess there could be an argument for having an additional 'config' parameter required in some conversion although I am not super keen on the idea. This one is purely for performance reason though. I am not a big fan of it so happy for any suggestion to go around it in a different way.
/**** Private Methods ****/ | ||
/*************************************/ | ||
|
||
protected Func<object[], object> CreateConstructor(Type type, List<ParamInfo> parameters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the light of the migration of all the methods to construct delegates (https://github.com/BHoM/BHoM_Engine/blob/master/Reflection_Engine/Convert/ToFunc.cs) maybe BH.Engine.Reflection.Create
is a better place for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
Description = type.Description(); | ||
|
||
//object instance = Activator.CreateInstance(type); // Potentially for later | ||
string[] excluded = new string[] { "BHoM_Guid" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to use this component to avoid continuously coding Create
methods, I think it is scary for people to have the properties of the base BHoMObject
as inputs.
LeakyRelu
is an example but I am sure there are a lot of others.
It just wants you to set NegativeSlope
, the rest is useless (but the user doesn't know that).
Although, I would still like to have a way to include them.
My suggesting is an Additional Inputs
entry in the context menu, with a checklist where you can check/uncheck the additional properties you need (might extend it to all properties).
You can test it on speckle:
To be clear, the additional properties I am referring to are Name
, Fragments
, Tags
and CustomData
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that.
As a final comment, I think that we can address the comments in a separate pr, especially to unblock the adapter refactoring. Thus, I am approving, but not merging to have a coordination chat before that @adecler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving as per comment above.
Do not merge this, please.
This is looking good - massively going to improve both user and coding experience I think. One specific comment I have which I think will be good to include in this PR if possible is the way in which the default constructor is represented in the menu. Is currently showing up as Suggest we try and explicitly list out the defining properties as possible inputs. (Knowing that they can actually be removed or left as default).
For bar example will look not too dissimilar to current Engine.Create exposing and mapping directly across many of the object initialiser syntax. a method which we will remove. See screen shot below. Also as these can get long - I do really like the and "x" more inputs added to the end where needed. |
@adecler @epignatelli @alelom - what do you think of the above? |
I generally agree we should find a better representation for the
Problem with this is if you end up having a Create constructor and the In this cases, I would simply go for the clearest, most explicit description, like using a sentence: |
In agree with all the above as well. I also agree with @alelom about potentially confusing the custom constructor with the Maybe we can exploit curly braces? |
Don't forget we will be removing any and all Create methods that are simply exposing defining properties only - so there will be, by definition, no conflicts or generating the same string. |
hmmm ... right. Thanks @epignatelli. So there are alternate options above - but personally I do like the idea of not labouring the distinction between creating an object through selecting a Create method or reflected public properties through syntax. Is not important to user here - and may confuse. Interested in thoughts though? |
Eduardo is right that gathering the properties would be an overhead. But more importantly to me the distinction between the two type of constructors is actually quite important as they behave differently. One can have some of its input removed, the other cannot. Something you will only see when zooming on the component. Having a clear visual indicator of this difference in the menu is therefore important to avoid guessing work in my opinion. Alessio's point of the final method string looking the same due to the cutting of long parameter chain is also very relevant. @epignatelli , I like you suggestion on using the context menu to allow adding the base properties instead of providing them by default. Agreed that it would be better to do this on a separate PR though so we can merge this and unblock the PR from @alelom . Let's catch up in your morning before merging this. |
I think that #147 (comment) is a bigger obstacle, because it can scary people - they don't know what to do when they are overwhelmed by all the properties. For this other issue, I agree that the initialiser provides a different experience compared to the other methods. Despite that, the user does not yet know that when he/she's choosing the entry from the list for the first time. |
Agreed @epignatelli - good summary above. on this:
Thinking your idea of curly braces could be a subtle but distinct way of clarifying |
To be honest I don't really see the point of listing all the properties explicitly while the idea is always the same: all properties are used as input. |
When you are creating an object through the UI you do not necessarily know what the defining properties are. |
It does. So you're saying this helps when people don't know what properties an object is made of and there are multiple ways of building an object. My concern was that it would not be as obvious that we are dealing with a variable input component anymore (hence the |
I like your identification of “one time learning aspect versus a full time practical issue“. One idea I just had - is around icons. We obviously only want one component!! (that was this whole task!!) but the wee icons in the search list could subtly reference the difference between variable input component or not. Maybe? An option in addition to the written syntax anyway. |
Hmmm, the issue I have with that idea is that the icons in the search are an indicator of the component from the task bar used in each case. This might be confusing if the search shows an icon that is not actually in the task bar. I guess we could make a small change but 1) it might be missed by some people 2) others will consider as a different icon altogether. |
Yep fair point - if subtle, then may well defeat the point. Icon are small in the menu here too. |
NOTE: Depends on
BHoM/BHoM_Engine#1276
Issues addressed by this PR
Closes #124
Test files
Just pop the new component on the canvas and play with it.
Additional comments
CreateObject
and theCreateCustom
components so bear that in mind when testing.