Book a Demo

Author Topic: Drawing a square on a diagram  (Read 31143 times)

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Drawing a square on a diagram
« on: August 28, 2016, 03:57:50 pm »
Hi,

I want to draw a square around an element on a diagram.
I have its left, right, top and button positions.

Does anybody know if there is any graphic API that i can use to do this?

Tzafrir

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Drawing a square on a diagram
« Reply #1 on: August 28, 2016, 07:11:20 pm »
Create a Boundary element and place it at the right position.

q.

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: Drawing a square on a diagram
« Reply #2 on: August 28, 2016, 10:09:20 pm »
How do you create boundary element?
Regular element with boundaries? how do you create those boundaries

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Drawing a square on a diagram
« Reply #3 on: August 28, 2016, 11:34:08 pm »
Package.Elements.AddNew("", "Boundary")

q.

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: Drawing a square on a diagram
« Reply #4 on: September 01, 2016, 01:19:59 am »
I used what you suggested with diagramobject AddNew API.
I see that a new entry is added in t_diagramobjects table, but this new boundary element does not appear in the diagram itself
This it the code I am using:

Can you let me know what should be added to it?

leftPos = 100;
rightPos = 100;
topPos = 100;
bottomPos= 100;

EA.DiagramObject addedNewElement = (EA.DiagramObject)MyDiagram.DiagramObjects.AddNew("l=" + leftPos + ";r=" + rightPos + ";t=" + topPos + ";b=" + bottomPos + ";", "Boundary");

addedNewElement.Update();
MyDiagram.Update();
repository.ReloadDiagram(MyDiagram.DiagramID);

Thanks

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Drawing a square on a diagram
« Reply #5 on: September 01, 2016, 02:47:23 am »
y-position goes to negative, not positive.

q.

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Drawing a square on a diagram
« Reply #6 on: September 01, 2016, 09:47:15 am »
y-position goes to negative, not positive.
Top and Bottom when stored in the database will be negative values, but when you are passing them to DiagramObjects.AddNew you specify them as positive values.  You will need to change the values you are passing though - at the moment you have the left, right, top and bottom all on the same x/y position.

The actual problem in the code sample you provided is that you are only creating a DiagramObject.  You haven't created the actual Element for the boundary.

Try something like this instead:

Code: [Select]
EA.Package ParentPackage = repository.GetPackageByID( MyDiagram.PackageID );
EA.Element NewElement = (EA.Element)ParentPackage.Elements.AddNew("", "Boundary");
NewElement.Update();

leftPos = 100;
rightPos = 300;
topPos = 100;
bottomPos= 200;

EA.DiagramObject NewDiagramObject = (EA.DiagramObject)MyDiagram.DiagramObjects.AddNew("l=" + leftPos + ";r=" + rightPos + ";t=" + topPos + ";b=" + bottomPos + ";", "");
NewDiagramObject.ElementID = NewElement.ElementID;
NewDiagramObject.Update();
repository.ReloadDiagram(MyDiagram.DiagramID);