Hi,
I rewrote the code according to my needs, but it does not make any changes when I call the method.
I created
angle and
radius as global variables in order to avoid using reference
Here is how it looks like. If you will have a time, please look at it.
void diagram_LinkCreated(DiagramLink link1)
{
List<DiagramLink> commonLinks = new ArrayList<DiagramLink>();
commonLinks = GetCommonLinks(link1.getOrigin(), link1.getDestination());
Float pt1 = link1.getControlPoints().get(0);
Float pt2 = link1.getControlPoints().get(link1.getControlPoints().size() - 1);
if (commonLinks.size() > 1)
{
for (int c = 0; c < commonLinks.size(); ++c)
{
DiagramLink link = commonLinks.get(c);
link.setStyle(LinkStyle.Bezier);
link.setSegmentCount(1);
cp1 = new Float(pt1.x + 1 * (pt2.x - pt1.x) / 3, pt1.y + 1 * (pt2.y - pt1.y) / 3);
cp2 = new Float(pt1.x + 2 * (pt2.x - pt1.x) / 3, pt1.y + 2 * (pt2.y - pt1.y) / 3);
angle = 0;
radius = 0;
CartesianToPolar(pt1, pt2, angle, radius);
int pairOffset = (c / 2 + 1) * 5;
if (commonLinks.size() % 2 == 0)
{
PolarToCartesian(cp1, c % 2 == 0 ? angle - 90 : angle + 90, pairOffset, cp1);
PolarToCartesian(cp2, c % 2 == 0 ? angle - 90 : angle + 90, pairOffset, cp2);
if (link1.getControlPoints().get(0) == pt1)
{
link.getControlPoints().set(1, cp1);
link.getControlPoints().set(2, cp2);
}
else
{
link.getControlPoints().set(1, cp2);
link.getControlPoints().set(2, cp1);
}
link.updateFromPoints();
}
}
}
}
List<DiagramLink> GetCommonLinks(DiagramNode node1, DiagramNode node2)
{
List<DiagramLink> commonLinks = new ArrayList<DiagramLink>();
for (DiagramLink link : node1.getOutgoingLinks())
if (link.getDestination() == node2)
commonLinks.add(link);
for (DiagramLink link : node1.getIncomingLinks())
if (link.getDestination() == node2)
commonLinks.add(link);
return commonLinks;
}
void PolarToCartesian(Float coordCenter, float a, float r, Float cartesian)
{
if (r == 0)
{
cartesian = coordCenter;
return;
}
cartesian.x = (float) (coordCenter.x + Math.cos(a * Math.PI / 180) * r);
cartesian.y = (float) (coordCenter.y - Math.sin(a * Math.PI / 180) * r);
}
void CartesianToPolar(Float coordCenter, Float cartesian, float a, float r)
{
if (coordCenter == cartesian)
{
a = 0;
r = 0;
return;
}
float dx = cartesian.x - coordCenter.x;
float dy = cartesian.y - coordCenter.y;
double x = Math.pow(dx, 2);
double y = Math.pow(dy, a);
double sqrt = Math.sqrt(x + y);
r = (float) sqrt;
a = (float) (Math.atan(-dy / dx) * 180 / Math.PI);
if (dx < 0)
a = a + 180;
this.radius = r;
this.angle = a;
}
Thanks very much
Michal