// Result is the Node-Element!
public Element addNodeIntoLine(Point p, Line line)
{
Draht draht=line.getDraht();
Element node=addNode();
if (line.getDirection()==Line.HORIZONTAL)
{
Polygon[] lrDrahts=getLRDrahts(draht,line, p);
Polygon leftPoly=lrDrahts[0];
Polygon rightPoly=lrDrahts[1];
node.setLocation(p.x-(node.getWidth()/2),line.myStart.y-(node.getHeight()/2));
// 1. Delete old Draht
// 2. verbinde LDraht mit Source und Node
// 3. verbinde RDraht mit Node und Dest
vmobject.deleteDraht(draht);
Draht leftDraht;
Draht rightDraht;
if (line.myStart.x<line.myEnd.x)
{
leftDraht=vmobject.addDrahtIntoCanvas(draht.getSourceElementID(),draht.getSourcePin(), node.getID(),3);
rightDraht=vmobject.addDrahtIntoCanvas(node.getID(),1, draht.getDestElementID(),draht.getDestPin());
node.getPin(1).draht=rightDraht;
node.getPin(3).draht=leftDraht;
}else
{
leftDraht=vmobject.addDrahtIntoCanvas(draht.getSourceElementID(),draht.getSourcePin(), node.getID(),1);
rightDraht=vmobject.addDrahtIntoCanvas(node.getID(),3, draht.getDestElementID(),draht.getDestPin());
node.getPin(3).draht=rightDraht;
node.getPin(1).draht=leftDraht;
}
copyPoints(leftPoly,leftDraht);
copyPoints(rightPoly,rightDraht);
}else
{
Polygon[] lrDrahts=getTBDrahts(draht,line, p);
Polygon poly1=lrDrahts[0];
Polygon poly2=lrDrahts[1];
node.setLocation(line.myStart.x-(node.getWidth()/2), p.y-(node.getHeight()/2));
// 1. Delete old Draht
// 2. verbinde LDraht mit Source und Node
// 3. verbinde RDraht mit Node und Dest
vmobject.deleteDraht(draht);
Draht draht1;
Draht draht2;
if (line.myStart.y>line.myEnd.y)
{
draht1=vmobject.addDrahtIntoCanvas(draht.getSourceElementID(),draht.getSourcePin(), node.getID(),2);
draht2=vmobject.addDrahtIntoCanvas(node.getID(),0, draht.getDestElementID(),draht.getDestPin());
node.getPin(0).draht=draht1;
node.getPin(2).draht=draht2;
}else
{
draht1=vmobject.addDrahtIntoCanvas(draht.getSourceElementID(),draht.getSourcePin(), node.getID(),0);
draht2=vmobject.addDrahtIntoCanvas(node.getID(),2, draht.getDestElementID(),draht.getDestPin());
node.getPin(0).draht=draht2;
node.getPin(2).draht=draht1;
}
copyPoints(poly1,draht1);
copyPoints(poly2,draht2);