1
Suggestions and Requests / Re: arranging ports in a diagram via script
« on: September 25, 2018, 09:41:01 pm »
Still does not fix my problem.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
I was less interested in the way you calculated the position rather than how you update the data in the DB.
q.
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;
}
"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
Geert
I have just tried with 1309 and it appears to work. Can you post your code so we can eventually spot the bug?
q.
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
}