Sparx Systems Forum
Enterprise Architect => Suggestions and Requests => Topic started by: cristian.ignat on September 24, 2018, 04:08:23 pm
-
Hello!
I am trying to automatically generate some diagrams with components that have ports. I've tried a lot of arranging systems for the ports but none seem to work. The ports seem to all go to one spot or randomly place themselves on a margin from the component they belong to even tough the coordinates set for the ports are exactly on the margin of the component (i used the system explained in the scripting book of EA: the port is 15 pixels wide and 15 pixel high, and the center sport is on the margin of the component).
I have tried offsetting them by a set amount of pixels but is still would not work.
If anyone can help, I would be grateful!
-
Positioning of embedded element broke in one version (can't remember exactly when, but quite a while ago). I don't know if it has been fixed in some recent version. Try an update.
q.
-
I work on version 13.0.1309. Do you know if this version in specially is affected ? Unfortunately I cannot update
-
I have just tried with 1309 and it appears to work. Can you post your code so we can eventually spot the bug?
q.
-
I have just tried with 1309 and it appears to work. Can you post your code so we can eventually spot the bug?
q.
This is the class responsible for the position of the ports. At the constructor it gets a point in the top middle margin and from there it starts to go around the component.
private class portPosition{
Side side;
double l,r,t,b;
int portSpacing = 50;
Point M;
componentPosition cp;
public portPosition(Point Middle, componentPosition cp) {
side = Side.top;
this.cp = cp;
this.M = Middle;
l=M.getX()-7;
r=M.getX()+7;
t=M.getY()+7;
b=M.getY()-7;
new Point(l,t);
new Point(r,b);
}
public String getFormatedPosition() {
StringBuilder sb = new StringBuilder();
sb.append("l=").append(l).append(";r=").append(r).append(";t=").append(t).append(";b=").append(b);
//"l="+l+";r="+r+";t="+t+";b="+b;
return sb.toString();
}
public void nextPosition() {
switch(side) {
case top:
if(cp.getRight()>M.getX()+portSpacing) {
M.setX(M.getX()+portSpacing);
l=M.getX()-7;
r=M.getX()+7;
System.out.println("top "+getFormatedPosition());
}else {
M.setX(cp.getRight());
M.setY(cp.getTop());
this.side = Side.right;
l=M.getX()-7;
r=M.getX()+7;
t=M.getY()+7;
b=M.getY()-7;
System.out.println("top next"+getFormatedPosition());
//this.nextPosition();
}
break;
case right:
if(cp.getBottom()<M.getY()-portSpacing) {
M.setY(M.getY()-portSpacing);
t=M.getY()+7;
b=M.getY()-7;
System.out.println("right "+getFormatedPosition());
}else {
M.setY(cp.getBottom());
M.setX(cp.getRight());
this.side = Side.bottom;
l=M.getX()-7;
r=M.getX()+7;
t=M.getY()+7;
b=M.getY()-7;
System.out.println("right next "+getFormatedPosition());
//this.nextPosition();
}
break;
case bottom:
if(cp.getLeft()<M.getX()-portSpacing) {
M.setX(M.getX()-portSpacing);
l=M.getX()-7;
r=M.getX()+7;
///System.out.println("bottom "+getFormatedPosition());
}else {
M.setX(cp.getLeft());
M.setY(cp.getBottom());
this.side = Side.left;
l=M.getX()-7;
r=M.getX()+7;
t=M.getY()+7;
b=M.getY()-7;
System.out.println("bottmon next "+getFormatedPosition());
//this.nextPosition();
}
break;
case left:
if(cp.getTop()>M.getY()+portSpacing) {
M.setY(M.getY()+portSpacing);
l=M.getX()-7;
r=M.getX()+7;
System.out.println("left "+getFormatedPosition());
}
else {
M.setX(cp.getLeft());
M.setY(cp.getTop());
this.side = Side.top;
l=M.getX()-7;
r=M.getX()+7;
t=M.getY()+7;
b=M.getY()-7;
System.out.println("left next "+getFormatedPosition());
//this.nextPosition();
}
break;
default: System.out.println("Default case");
break;
}
}
@SuppressWarnings("unused")
public int getLeft() {
return (int)l;
}
@SuppressWarnings("unused")
public int getRight() {
return (int) r;
}
@SuppressWarnings("unused")
public int getTop() {
return (int)t;
}
@SuppressWarnings("unused")
public int getBottom() {
return (int)b;
}
}
private enum Side{
top,
right,
bottom,
left
}
-
"7" seems to be an important magical number ;)
Geert
-
"7" seems to be an important magical number ;)
I used 7 because from what I read from the scripting manual a port is 15 by 15 pixels. One pixel in the middle that is on the margin plus 7 in all direction gives a 15 by 15 square... If I am not wrong :D
Geert
-
I was less interested in the way you calculated the position rather than how you update the data in the DB.
q.
-
I was less interested in the way you calculated the position rather than how you update the data in the DB.
q.
This is how I add an element to a diagram.The ports are already part of the component and they seem to automatically snap to the component they belong to.
private DiagramObject addElement(Diagram d, Element e,String position) {
//Adds a diagram object (port or component) to the diagram given
DiagramObject newDiagramObject;
newDiagramObject = d.GetDiagramObjects().AddNew(position, "");
newDiagramObject.SetElementID(e.GetElementID());
if(!newDiagramObject.Update()) {
System.out.println(newDiagramObject.GetLastError());
}
repository.SaveDiagram(d.GetDiagramID());
repository.ReloadDiagram(d.GetPackageID());
newDiagramObject.Update();
d.Update();
d.GetDiagramObjects().Refresh();
return newDiagramObject;
}
-
That's a bit messy what you're doing. You should be done without the save/reload of the diagram. Just put a repository.ReloadDiagram at the very end of it all to show the update.
q.
-
Still does not fix my problem.
-
It's a bit hard to debug this way. What you should do it to write a small test program to add an embedded element. Basically you
- create a diagram object with .AddNew("<position string>", "")
- add the according embedded element's ID and
- update() the diagram object.
- Finally you need a repos.reloadDiagram(id) to actually show the newly added element.
Compare the <position string> to what a manually added object has stored in the database (use an almost empty EAP) by looking into t_diagramobjects.
q.
P.S: I used this Perl snippet:
my $rep = $ENV{'REP'}; # get repository pointer "by magic"
my $dia = $rep->GetCurrentDiagram();
my $e = $rep->GetTreeSelectedObject();
my $do = $dia->DiagramObjects->AddNew ("t=-369;l=156;r=171;b=-384", "");
$do->{ElementID} = $e->ElementID;
$do->Update ();
$rep->ReloadDiagram($dia->DiagramID);