Inserts a port into the schematic and connects it to another node if the coordinates are identical. The node is returned.
| 32 | // Inserts a port into the schematic and connects it to another node if |
| 33 | // the coordinates are identical. The node is returned. |
| 34 | Node* Schematic::insertNode(int x, int y, Element *e) |
| 35 | { |
| 36 | Node *pn; |
| 37 | // check if new node lies upon existing node |
| 38 | for(pn = Nodes->first(); pn != 0; pn = Nodes->next()) // check every node |
| 39 | if(pn->cx == x) if(pn->cy == y) |
| 40 | { |
| 41 | pn->Connections.append(e); |
| 42 | break; |
| 43 | } |
| 44 | |
| 45 | if(pn == 0) // create new node, if no existing one lies at this position |
| 46 | { |
| 47 | pn = new Node(x, y); |
| 48 | Nodes->append(pn); |
| 49 | pn->Connections.append(e); // connect schematic node to component node |
| 50 | } |
| 51 | else return pn; // return, if node is not new |
| 52 | |
| 53 | // check if the new node lies upon an existing wire |
| 54 | for(Wire *pw = Wires->first(); pw != 0; pw = Wires->next()) |
| 55 | { |
| 56 | if(pw->x1 == x) |
| 57 | { |
| 58 | if(pw->y1 > y) continue; |
| 59 | if(pw->y2 < y) continue; |
| 60 | } |
| 61 | else if(pw->y1 == y) |
| 62 | { |
| 63 | if(pw->x1 > x) continue; |
| 64 | if(pw->x2 < x) continue; |
| 65 | } |
| 66 | else continue; |
| 67 | |
| 68 | // split the wire into two wires |
| 69 | splitWire(pw, pn); |
| 70 | return pn; |
| 71 | } |
| 72 | |
| 73 | return pn; |
| 74 | } |
| 75 | |
| 76 | // --------------------------------------------------- |
| 77 | Node* Schematic::selectedNode(int x, int y) |