algorithmic modeling for Rhino
I wrote some logic for custom GH_ComponentAttributes to add a group RadioButtons (left) OR a group of Checkboxes (right).
I use them both with success...
But now I want to combine them, for example, add a second group of RadioButtons, or even mix them...
The Layout they use is (or should be) based on the current size of the component, so I guess, doing them in a series should work just fine.
I had a research on this topic but did not find out how the adding should work...
This (needed?) line of code in CreateAttribute(), I guess, I don't fully understand
m_attributes = instanceOf_MyCustomAttribute;
I found the AppendToAttributeTree(), as a call and as an override. But in both cases
I tried to set GH_ComponentAttributes.Parent in both directions.
So, somebody can enlight my on this topic?
I could imagine a workaround where a Wrapper redirects each (do make it fully compatible) override of GH_ComponentAttributes to each item in a collection of GH_ComponentAttributes.
But this would be a stupid work to do. And also timeconsuming in computing I guess...
You can only have one attribute instance per component. The Attribute Tree is a data structure which combines all the attributes of the various elements that make up a component (i.e. the component itself and all the input/output parameters). You should not mess with the tree or the parent fields, that'll just break things.
If you want to have re-usable UI on custom component attributes, you are going to have to design the class hierarchy yourself. For example you could create a single type of component attributes which has additional logic for a variable set of UI elements. That would mean you'd only have to write the logic once. It'll be a fairly complicated job, but then overriding component attributes always is.
Imagine you have a single interface called IComponentUiElement which covers all the individual controls you'd like to add to components. There'd be two classes that implement this interface, let's call them ComponentCheckBox and ComponentOptionBox (you may want to add more later, ComponentComboBox, ComponentTextBox, ComponentNumberBox, ComponentSlider, ...).
Each control must carry all the information it needs to function; what it's name is, how it knows what state it is in, what area represents the mouse-click-relevant-region, what should happen when the mouse is clicked etc.
Then, your custom attributes will need the smarts to collect and maintain these controls. So your class CustomComponentAttributes will have a method AddCustomControl(IComponentUiElement). Then, within the CreateAttributes() method of each of your Components, you'll have to create this custom attribute class and populate it with the relevant controls.
As you can see, even in English it adds up to quite a bit of text, expect to write several thousand lines of code...
Thanks for ur explanation to this topic. Its a pity we can not just stack them.
So, lets code it in a stacked way.
It wasn't so hard ;) maybe a thousand lines of code were needed, I did not count them ;)
So, as u said, I ended up by Implementing a Root-class which redirects the calls to a stack of same interfaced instances. An abstract class is given too, to give basic functionality to disable/enable the drawing...
Further more I added some basic Visual Elements: CheckboxGroup, RadioButtonGroup, ToggleButton, Seperator, ArrowButton.... And a class to collect them in a collection.
Its to much code to paste here, therefor a link to bitbucket
Further more, I tried to develop a base-Component which can switch between Input- and Radio-Mode. It means, by menu, the user can either choose the "mode" to use a classical way using inputs (maybe multiple items) OR in a UI-Mode using RadioButtons...
Its working quiet gooud, but I am stuck with UndoThings which would be extremly needed in this case (Parameter+Wire is added/removed).
For the other stuff it would be nice too to undo the changes done by clicking the controls...
But, ya, at this I m stuck. If u have any adivces or good links to start with GH-UndoStuff, let me know...
To test the existing stuff, just download the .gha from below.
There some other things in there. TAB => Extra => MOr...
To test, there is a file attached...
The link to the shown components...
This design of UI is more simple than mine.You can go my page to have a look!
:) unfamiliar looking components...
Are u doing the whole drawing of the component out of an Attribute or whats going on?
yeah,i have overwritten the attributes!
I'm successfully using custom attributes stacking them vertical.
At the moment I try to implement someting like 'minWidth' in this stack, so the visuals fit nicely into the boundaries of the component. Therefor the component's width may have to be changed.
Here comes the problem:
The drawing on the canvas just looks fine but the Output-Paramters are drawn and are wired at/from the position they had before the width has changed.
Someone has a tip?
If the cattributes changed,you should re layout params!
this does not work...
what u mean with reLayout?
protected override void Layout()
Great, Thanks a lot...
U may also know how to layout the Icon in the center?
Found no same-pattern method...
Just using Drawimage(...) method!