Author Topic: Controlling whether parts are visible in a diagram  (Read 10372 times)

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Controlling whether parts are visible in a diagram
« on: August 25, 2021, 05:49:32 pm »
Hi all,

I try to control automatically whether parts are shown in different diagrams:
  • For example I have a constraintBlock with a part "A" inside. In the Parts/Properties tab of the Features of the constraintBlock, this part appears with a checkbox in front of its name, setting the value in the "Visible" column to True/False, and having an effect in the related diagram: the part appears/disappears as a blue rectangle.
  • I also have a constraintLink referring to this constraintBlock. If this constraintLink is shown in a parametric diagram, visibility of part "A" inside the rounded blue rectangle can also be controlled with the checkbox in the feature list, but obviously this is independent of the visibility in the constraint diagram.
I conclude that the "Visible" flag is not a property of the Part "A", but something related to the context in which the Part is used.

Until now I did not find a way to programmatically show/hide my Part in the parametric diagram. Do I have to set some parameter? Do I have to create a DiagramObject inside the DiagramObject of the constraintLink, because maybe the "Visible" flag is not a real variable but just reflecting the existence of the Part in the diagram? Any other way?

Not sure where to start. Do you have any hints?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #1 on: August 25, 2021, 07:08:47 pm »
Well, it's simply removed from the diagram objects. That's all.

q.

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #2 on: August 25, 2021, 07:55:25 pm »
Well, it's simply removed from the diagram objects. That's all.
Thanks for confirming that!
If I understand correctly, I have to study more deeply how to create/delete the appropriate DiagramObjects in case I want to show/hide my elements.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #3 on: August 25, 2021, 08:13:08 pm »
Yes, that's all about it. Placing embedded elements is a bit tricky since you need a bit of geometry (only very basics, though). They must be placed inside the borders of the embedding element (which must be visible). IIRC the API allows even placing embedded elements without parent which the GUI does not allow.

q.

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #4 on: August 26, 2021, 01:20:30 am »
Good to hear about the trick for embedded elements, trying that out now.

The problem I have with this is that the coordinates I specify are not taken.
For each element I add in the diagram I do something like:
Code: [Select]
diagramObject = myDiagram.DiagramObjects.AddNew(position, "")
diagramObject.ElementID = someElement.ElementID
diagramObject.Update()

During my last test I added 4 elements with different positions like:
"l=50;r=170;t=-50;b=-156;"
"l=220;r=340;t=-50;b=-156;'"
"l=50;r=550;t=-256;b=-756;"
"l=50;r=150;t=-276;b=-376;"

When inspecting DiagramObjects, I find not 4 but 5 objects (I suspect that the 5th object is referring to the parent block of the parametric diagram), with left / right / top / bottom coordinates like:
"15 / 206 / -15 / -113" (parent block, did not add it myself, invisible in the GUI)
"50 / 170 / -50 / -82"
"84 / 204 / -50 / -82"
"50 / 120 / -79 / -111"
"50 / 150 / -276 / -376" (only correct one)

So some of the coordinates are correct, some are not.
What could be the way to set them as desired?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #5 on: August 26, 2021, 03:30:20 am »
Embedded elements are a bit touchy (EA-wise). I know it for port where (in a certain EA version) the coordinates where ignored completely. I haven't use it since a while, so no idea about the current state. From the coordinates it looks like you calculated the lower position as too low and EA moved them up. I have not the faintest idea what you mean by "invisible parent".

q.

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #6 on: August 26, 2021, 07:34:39 pm »
From the coordinates it looks like you calculated the lower position as too low and EA moved them up.
I think for my test I specify more space than needed for the contents it should show, but the top/left is not always on the desired location, and the width/height is adapted (shrunk), even such that it isn't sufficient for covering the complete contents.

Would I have to switch to direct database access in order to achieve what I want? Would that be possible?

I have not the faintest idea what you mean by "invisible parent".
To clarify this: For verifying the coordinates, I'm iterating through the DiagramObjects and print the ElementID of the associated elements. The extra DiagramObject I find has an ElementID of the block to which my Diagram is belonging, so I call that the parent.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Controlling whether parts are visible in a diagram
« Reply #7 on: August 26, 2021, 07:55:54 pm »
"15 / 206 / -15 / -113" (parent block, did not add it myself, invisible in the GUI)
<snip>
During my last test I added 4 elements with different positions like:
"l=50;r=170;t=-50;b=-156;"
"l=220;r=340;t=-50;b=-156;'"
"l=50;r=550;t=-256;b=-756;"
"l=50;r=150;t=-276;b=-376;"

The problem is that you are asking EA to set the edges of your embedded diagramObject outside of the boundaries of the "parent" element.
EA doesn't want to do that, and thus adjusts the coordinates to fit within the boundaries.

For example for your second diagramObject you specify

"l=220;r=340;t=-50;b=-156;'"

But the parent's right side is on 206. 220 > 206, so that would be completely outside (to the right) of the parent object.
EA doesn't like that and adjusts your x axis to fall within the bounds of the parent object.

So you probably need to figure the coordinates of the parent object before setting the coordinates of the embedded objects.

Geert

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #8 on: August 27, 2021, 12:29:15 am »
Getting again one step further in understanding how the things work. It is about understanding what objects are created under the hood when clicking in EA GUI.

When I manually
  • create the ParametricDiagram
  • add a constraintLink for a specific ConstraintBlock
  • select the ConstraintLink and check on the visibility of an underlying Part "A" in the feature list
Then I end up with 3 DiagramObjects:
  • one object for the ConstraintLink
  • one extra locked and invisible object related to the parent block
  • one extra Part also called "A", but with different ElementID than the one of the original "A" Part under ConstraintBlock
This locked object is around the other objects, and it will constrain the positions of any new DiagramObject as Geert explained.

Now I have to replicate the creation of these objects in my program, especially the creation of this embedded object for Part "A" seems still a challenge, that's what I will try now. I think I need the following steps to achieve this:
  • Create a ConstraintLink referring to my ConstraintBlock (containing a Part "A")
  • Create a new Part "A" under this ConstraintLink
  • Create the ParametricDiagram
  • Add the parent block to the Diagram
  • Fiddle with it (maybe with SQL queries) to set a large enough size and make sure it is locked (NSL=1)
  • Add the ConstraintLink to the Diagram
  • Fiddle with it to set its size
  • Add the new Part "A" inside the borders of the ConstraintLink in the hope it becomes an embedded element
Thank you for advice if you see mistakes in this recipe!

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #9 on: August 27, 2021, 08:12:24 am »
one extra locked and invisible object related to the parent block

This will be the diagram frame. I haven't ever created a SysML diagram using automation, but I would expect to get the diagram frame for free.
The Sparx Team
[email protected]

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #10 on: August 27, 2021, 07:22:32 pm »
This will be the diagram frame. I haven't ever created a SysML diagram using automation, but I would expect to get the diagram frame for free.
The diagram frame is not created directly after creating the new Parametric diagram.
Only for example if I open the project in the GUI, double click the diagram and close it again, then EA asks to save it. At that time it is added.
It was also added when I call the function LayoutDiagramEx().

Wondering if there is an alternative to LayoutDiagramEx for getting the diagram frame for free...

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Controlling whether parts are visible in a diagram
« Reply #11 on: August 27, 2021, 09:03:44 pm »
You can try to open the diagram, save it and close it using the API functions.
Maybe that works the same way as doing it manually?

Geert

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #12 on: August 27, 2021, 10:54:37 pm »
You can try to open the diagram, save it and close it using the API functions.
Maybe that works the same way as doing it manually?
Indeed, this is a much easier way to get the diagram frame for free, thank you Geert for that!

I'm getting closer and closer to my end-goal, layout of the diagram is more and more under control.

One of the last difficulties I need to solve is the fact that EA is not completely happy with the sub-elements that I create in my constraintLink. These are my findings:
  • The good thing is that they show as embedded DiagramObjects in the constraintLink (with the little square for a connector).
  • On the other hand, EA generates a new set of sub-elements when I select manually the constraintLink in my ParametricDiagram. It must be that he is not happy with my sub-elements. The automatically created sub-elements show as owner the ConstraintBlock that was set as PropertyType for the ConstraintLink, which makes sense of course.
When I try to set the ownership (parentID) myself on my own sub-elements, then unfortunately the sub-elements do not become embedded elements of the ConstraintLink in the ParametricDiagram.

I do not see the difference between my own sub-elements and the ones created automatically by EA. Any hint?

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Controlling whether parts are visible in a diagram
« Reply #13 on: August 30, 2021, 08:26:19 pm »
I started investigating more in depth the differences between elements created in the GUI and elements created in my program. This has revealed that I have to set properly p_object.PDATA3 of my element to make everything work.

This is now what I do (I have already a ConstraintBlock with Part "A"):
  • Create a ConstraintLink referring to my ConstraintBlock
  • Create a new Part "A" under this ConstraintLink
  • Set PDATA3 for this new Part to the GUID of Part "A" in the ConstraintBlock
  • Create the ParametricDiagram
  • Add the parent block to the Diagram
  • Add the ConstraintLink to the Diagram
  • Add the new Part "A" inside the borders of the ConstraintLink
"A" is nicely becoming an embedded element in the ConstraintLink.
No more extra Elements are created in the ConstraintLink when selecting it in the Diagram, my own elements are accepted.
All seems to be fine...

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Controlling whether parts are visible in a diagram
« Reply #14 on: August 30, 2021, 08:59:02 pm »
I started investigating more in depth the differences between elements created in the GUI and elements created in my program. This has revealed that I have to set properly p_object.PDATA3 of my element to make everything work.

This is now what I do (I have already a ConstraintBlock with Part "A"):
  • Create a ConstraintLink referring to my ConstraintBlock
  • Create a new Part "A" under this ConstraintLink
  • Set PDATA3 for this new Part to the GUID of Part "A" in the ConstraintBlock
  • Create the ParametricDiagram
  • Add the parent block to the Diagram
  • Add the ConstraintLink to the Diagram
  • Add the new Part "A" inside the borders of the ConstraintLink
"A" is nicely becoming an embedded element in the ConstraintLink.
No more extra Elements are created in the ConstraintLink when selecting it in the Diagram, my own elements are accepted.
All seems to be fine...
Yep, that sounds like exactly the same scenario I went through a couple of times.
- try to replicate some kind of behavior in EA using the API
- notice small differences between manual behavior and automated behavior
- find the difference in the database by painstakingly comparing each field
- adjust the code to replicate the (often undocumented) difference
- ???
- Profit  ;)

I'm happy you got it working.

Geert