Archi Forum

Archi Plug-ins => jArchi => Topic started by: LapizLazuli on March 08, 2023, 08:10:03 AM

Title: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: LapizLazuli on March 08, 2023, 08:10:03 AM
Hi,

Context:
- Visual object 'ComposedElement' in a view.
- Two other objects 'Component1' and 'Component2', are linked by a composition-relationship to ComposedElement: they are both components of the ComposedElement.
- Size of ComposedElement is large enough to accommodate its two components
- Initial state: the two components are located 'outside' the parent 'ComposedElement' object.
- When, from the UI, Component1 and Component2 are dragged into ComposedComponent:
    - The appear *on top*, not behind, ComposedElement
    - They become part of ComposedElement, so when moving ComposedElement, the ComponentsX objects move with it.

Attempt:
- In order to help organizing a view with hierarchical elements (eg. Business Processes level 1, 2, 3, 4, etc.), I wrote a jArchi script which, when selecting an element:
  - increases its size, so that it holds all its ComponentX elements
  - position ComponentsX *within* the boundaries of ComposedElement.

My expectation was that, then, they become 'part' of the parent component, so that they appear on top of it, and are moved when the parent component moves.

In reality:
- Some of them appear on top, some other behind, the parent ComposedComponent
- When moving ComposedComponent, they don't move with it.

Question:
- Is there a way, in jArchi, to actually nest ComposedElementX into the parent ComposedElement?

If not quite clear, and needed, I'll try to post a sample model, and attach the scripts.

Thank you for your help.
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: Jean-Baptiste Sarrodie on March 08, 2023, 09:42:11 AM
Hi,

For this to work you have to remove the elements from the view and add them again either directly inside 'ComposedElement' (using object.add(element) (https://github.com/archimatetool/archi-scripting-plugin/wiki/jArchi-Object#addelement2)), or to the view with autonest set to true (https://github.com/archimatetool/archi-scripting-plugin/wiki/jArchi-Object#addelement).

Regards,

JB
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: Phil Beauvoir on March 08, 2023, 09:53:40 AM
As JB says, remove and re-add. I was just looking at the jArchi code and there is no "move" command for view objects (remove from existing parent and add to target object). Perhaps this is something for the "to do" list.
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: Jean-Baptiste Sarrodie on March 08, 2023, 11:09:15 AM
Quote from: Phil Beauvoir on March 08, 2023, 09:53:40 AMAs JB says, remove and re-add. I was just looking at the jArchi code and there is no "move" command for view objects (remove from existing parent and add to target object). Perhaps this is something for the "to do" list.

Maybe we could extend object.add(element, x, y, width, height) so that it accepts also a visual object (and in such case, change its parent).
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: Phil Beauvoir on March 08, 2023, 11:18:17 AM
Quote from: Jean-Baptiste Sarrodie on March 08, 2023, 11:09:15 AM
Quote from: Phil Beauvoir on March 08, 2023, 09:53:40 AMAs JB says, remove and re-add. I was just looking at the jArchi code and there is no "move" command for view objects (remove from existing parent and add to target object). Perhaps this is something for the "to do" list.

Maybe we could extend object.add(element, x, y, width, height) so that it accepts also a visual object (and in such case, change its parent).

Yes, that makes more sense.
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: Phil Beauvoir on March 08, 2023, 11:21:11 AM
https://github.com/archimatetool/archi-scripting-plugin/issues/116
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: LapizLazuli on March 08, 2023, 20:14:21 PM
Awesome, thanks!
Excellent, merci! :)
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: LapizLazuli on March 09, 2023, 02:14:34 AM
Quote from: Jean-Baptiste Sarrodie on March 08, 2023, 09:42:11 AMFor this to work you have to remove the elements from the view and add them again  [...] to the view with autonest set to true (https://github.com/archimatetool/archi-scripting-plugin/wiki/jArchi-Object#addelement).

Hi,

I attempted the above, and it failed. What am I doing wrong?

- View name : TestView
- Elements name : BizFuncParent and BizFuncChild
- Composition relation (BizFuncChild > BizFuncParent)
- BizFuncParent in view
- BizFuncChild not in view
Please also see attached screenshot

// Get view object
var oView = $(".TestView").first()
console.log(oView.name)   // Got view name. Object ok.

// Get oChild object from model. Not displayed in View
var oChild = $(".Child").first()
console.log(oChild.name)  // Got child object name. Object ok.

// Now try to add object from model to view
oView.add(oChild, 30, 30,-1,-1, true)

// Fails:
// Script Error: javax.script.ScriptException: java.lang.Exception: java.lang.NoClassDefFoundError: com/archimatetool/editor/preferences/Preferences


Thanks for your help.

Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: Phil Beauvoir on March 09, 2023, 08:51:58 AM
Hi,

you need to delete oChild first.

Something like this:

// Store the undlerying concept from the child visual object
concept = oChild.concept;

// Store any features like fill color...
fillColor = oChild.fillColor;

// Delete the visual object
oChild.delete();

// Add the stored concept back to parent view
oChild = oView.add(concept, 30, 30,-1,-1, true);

// Restore any features in visual object
oChild.fillColor = fillColor;
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: Jean-Baptiste Sarrodie on March 09, 2023, 13:41:25 PM
Hi,

Quote from: LapizLazuli on March 09, 2023, 02:14:34 AMI attempted the above, and it failed. What am I doing wrong?
- View name : TestView
- Elements name : BizFuncParent and BizFuncChild
- Composition relation (BizFuncChild > BizFuncParent)
- BizFuncParent in view
- BizFuncChild not in view

Works ok on my side...

JB
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: LapizLazuli on March 09, 2023, 17:00:04 PM
Thanks @Phil for your reply.

Quote from: Phil Beauvoir on March 09, 2023, 08:51:58 AMyou need to delete oChild first.
There must be something I don't understand. How can I delete oChild [from view], since in the example, it is already not in view?

Quote from: Jean-Baptiste SarrodieWorks on my side...
Thanks too. So the code seems correct. I need now then to investigate why it's not working on my configuration...
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: Phil Beauvoir on March 09, 2023, 17:18:19 PM
> There must be something I don't understand. How can I delete oChild [from view], since in the example, it is already not in view?

I thought you were trying to "move" an object from one parent to another.
Title: Re: Attaching nested visual objects to 'parent', in a composition-relationship
Post by: LapizLazuli on March 09, 2023, 20:20:03 PM
@Phil - Thanks, fine then :)

@All - The cause was purely on my side: the scripts were in a OneDrive folder, which just got a sync issue. Moving the scripts in the Document/Archi folder sorted things out. Apologies.