Book a Demo

Author Topic: How to create DiagramObjects correctly?  (Read 5931 times)

André Ribeiro

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
How to create DiagramObjects correctly?
« on: November 06, 2013, 11:33:00 pm »
Hi everyone,

I've been trying to create some diagramObjects, but I'm facing some problems namely because I need some classes with inner classes. Thus, I need to use the sequence property that defines the z-order of each diagramObject in order to correctly depict the inner classes.

Firstly, I tried the following way that worked:
Code: [Select]
EA.DiagramObject diagObj = diagram.DiagramObjects.AddNew(Element.Name, "Class");
diagObj.left = left.Value;
diagObj.right = right.Value;
diagObj.top = -top.Value;
diagObj.bottom = -bottom.Value;
diagObj.Sequence = Sequence;
diagObj.Update();
diagram.Update();
Repository.ReloadDiagram(diagram.DiagramID);
string query = "update t_diagramobjects set Object_ID = " + Element.ElementID + " where Diagram_ID = "
+ diagram.DiagramID + " and Object_ID = 0";
Repository.Execute(query);

Then, I've discovered the ElemenId property and set it, but when I use this way, the sequence value doesn't change:
Code: [Select]
EA.DiagramObject diagObj = diagram.DiagramObjects.AddNew(Element.Name, "Class");
diagObj.left = left.Value;
diagObj.right = right.Value;
diagObj.top = -top.Value;
diagObj.bottom = -bottom.Value;
diagObj.Sequence = Sequence;
diagObj.ElementID = Element.ElementID;
diagObj.Update();
diagram.Update();
Repository.ReloadDiagram(diagram.DiagramID);

My question is what is the correct way of creating a diagram object and setting its properties?

Many thanks!

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: How to create DiagramObjects correctly?
« Reply #1 on: November 07, 2013, 07:14:03 pm »
Hi André

I had problems with the same thing and not even sure I fully understood, however what appears to work for me is having created the diagram object dobj, set the ElementID and perform an update on the diagram object before doing other stuff as below:

 dobj.ElementID = myElement.ElementID
 dobj.Update()
 dobj.top = top
 dobj.bottom = bottom
 dobj.left = left
 dobj.right = right
 dobj.Sequence = order
 dobj.Update()

Not really happy and the fact that there appears to be crosstalk that affects the setting of properties is a little alarming, in particular as there is no documentation to highlight any dependencies; it does make one feel like building on sand at times!

BR


EXploringEA - information, utilities and addins

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to create DiagramObjects correctly?
« Reply #2 on: November 07, 2013, 09:58:20 pm »
Setting diaObj.ElementID is inevitable since a diagram object needs a real object to represent it. There's no need to hack that with an UPDATE statement. Setting the Sequence for the z-order is optional. What MrWappy posted is the right way to do it.

q.

André Ribeiro

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: How to create DiagramObjects correctly?
« Reply #3 on: November 08, 2013, 02:14:27 am »
Thank you for answering!
I've tried your solution, but it's still not working.
I've one classe that contains another class that contains another class:
MyLIST
->MyITEM
-->MyTEXTBOX

The problem is that the sequence (z-order) applied to the parent is inherited by its children and when I try to set it, nothing happens.
This is some test code I've done:

package - is the package that contains the diagram and the elements;
d - is my diagram.

Code: [Select]
EA.Element lst = package.Elements.AddNew("MyLIST", "Class");
lst.Update();
EA.Element item = lst.Elements.AddNew("MyITEM", "Class");
item.Update();
EA.Element tx = item.Elements.AddNew("MyTEXTBOX", "Class");
tx.Update();

EA.DiagramObject lstObj = d.DiagramObjects.AddNew("MyLIST", "Class");
lstObj.ElementID = lst.ElementID;
MessageBox.Show(lst.Name + " " + lstObj.Sequence);
lstObj.Update();
lstObj.left = 217;
lstObj.right = 642;
lstObj.top = -10;
lstObj.bottom = -540;
lstObj.Sequence = 10;
MessageBox.Show(lst.Name + " " + lstObj.Sequence);
lstObj.Update();
d.DiagramObjects.Refresh();
MessageBox.Show(lst.Name + " " + lstObj.Sequence);

EA.DiagramObject itemObj = d.DiagramObjects.AddNew("MyLIST", "Class");
itemObj.ElementID = item.ElementID;
itemObj.Update();
MessageBox.Show(item.Name + " " + itemObj.Sequence);
itemObj.left = lstObj.left + 10;
itemObj.right = lstObj.right - 10;
itemObj.top = lstObj.top - 10;
itemObj.bottom = lstObj.bottom + 10;
itemObj.Sequence = lstObj.Sequence - 1;
MessageBox.Show(item.Name + " " + itemObj.Sequence);
itemObj.Update();
d.DiagramObjects.Refresh();
MessageBox.Show(item.Name + " " + itemObj.Sequence);

EA.DiagramObject txObj = d.DiagramObjects.AddNew("MyTEXTBOX", "Class");
txObj.ElementID = tx.ElementID;
txObj.Update();
MessageBox.Show(tx.Name + " " + txObj.Sequence);
txObj.left = itemObj.left + 10;
txObj.right = itemObj.right - 10;
txObj.top = itemObj.top - 10;
txObj.bottom = itemObj.bottom + 10;
txObj.Sequence = itemObj.Sequence - 1;
MessageBox.Show(tx.Name + " " + txObj.Sequence);
txObj.Update();
d.DiagramObjects.Refresh();
MessageBox.Show(tx.Name + " " + txObj.Sequence);

Repository.ReloadDiagram(d.DiagramID);

I don't understand why this happens.
Thanks in advance!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to create DiagramObjects correctly?
« Reply #4 on: November 08, 2013, 02:54:20 am »
It seems that EA sets sequence for all objects to that of the first one. Very strange and smells like a bug. I'll test a bit more...

q.

[edit] I just tried with 9.3 and there it worked. So it's clear: this is a bug introduced with 10.0. Work around: you know how to handle Repository.Execute... And would you please report the bug?
« Last Edit: November 08, 2013, 03:06:20 am by qwerty »

André Ribeiro

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: How to create DiagramObjects correctly?
« Reply #5 on: November 08, 2013, 04:27:28 am »
Thanks for helping me @qwerty.
I solved this problem by performing the following query to update the sequence value:
Code: [Select]
string query = "update t_diagramobjects set Sequence = " + sequence + " where Object_ID = " + diagObj.ElementID;
Repository.Execute(query);

Bug reported. Just for the record I'm using EA version 10.0.1005 (Build 1005).
« Last Edit: November 08, 2013, 05:09:29 am by krypton »

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: How to create DiagramObjects correctly?
« Reply #6 on: November 08, 2013, 07:19:07 pm »
@André

You are correct about the issue of inheriting and that was solve for me in the single case by setting the ElementID doing the update and then setting the Sequence.

But your case is more complicated than mine and clearly highlights the crosstalk issue.  There is clearly something that they are doing such as setting the sequence when they establish the link to the ElementID which overwrites any values set. I wonder if you reversed the order of creating you objects (i.e. going from the leaf upwards) whether the behaviour changed.  Or possibly create the objects with ElementID's and then set the sequencing after diagram objects / elements all established.  A bit of a mess and clearly not ideal, however if its a bug and you need a solution may be worth a quick test.  

Be interested to know - sorry I've not got the time to try myself ... one of those days ahead!
EXploringEA - information, utilities and addins

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to create DiagramObjects correctly?
« Reply #7 on: November 08, 2013, 10:32:13 pm »
I've tried that. Reversing works. However, EA does not respect the Sequence and that is simply a bug.

q.