Connector * CircuitICNDocument::createConnector( Node *node, Connector *con, const QPoint &pos2, QPointList *pointList ) { if(!canConnect( node, con ) ) return 0; // FIXME dynamic_cast used, fix it in Connector class ECNode *conStartNode = dynamic_cast<ECNode *> (con->startNode() ); ECNode *conEndNode = dynamic_cast<ECNode *> (con->endNode() ); ECNode *ecNode = dynamic_cast<ECNode *> (node ); const bool usedManual = con->usesManualPoints(); ECNode *newNode = new JunctionNode(this, 0, pos2); QPointList autoPoints; if (!pointList) { addAllItemConnectorPoints(); ConRouter cr(this); cr.mapRoute( int(node->x()), int(node->y()), pos2.x(), pos2.y() ); autoPoints = cr.pointList(false); pointList = &autoPoints; } QList<QPointList> oldConPoints = con->splitConnectorPoints(pos2); con->hide(); // The actual new connector Connector *new1 = newNode->createConnector(node); ecNode->addConnector(new1); new1->setRoutePoints(*pointList,usedManual); // The two connectors formed from the original one when split Connector *new2 = newNode->createConnector(conStartNode); conStartNode->addConnector(new2); new2->setRoutePoints( oldConPoints.at(0), usedManual ); Connector *new3 = conEndNode->createConnector(newNode); newNode->addConnector(new3); new3->setRoutePoints( oldConPoints.at(1), usedManual ); // Avoid flicker: tell them to update their draw lists now con->updateConnectorPoints(false); new1->updateDrawList(); new2->updateDrawList(); new3->updateDrawList(); // Now it's safe to remove the connector... con->removeConnector(); flushDeleteList(); deleteNodeGroup(conStartNode); deleteNodeGroup(conEndNode); createNodeGroup(newNode)->init(); return new1; }
Connector *CircuitICNDocument::createConnector( const QString &startNodeId, const QString &endNodeId, QPointList *pointList ) { ECNode *startNode = getEcNodeWithID(startNodeId); ECNode *endNode = getEcNodeWithID(endNodeId); if ( !startNode || !endNode ) { kDebug() << "Either/both the connector start node and end node could not be found" << endl; return 0L; } if ( !canConnect( startNode, endNode ) ) return 0l; Connector *connector = endNode->createConnector(startNode); if (!connector) { kError() << k_funcinfo << "End node did not create the connector" << endl; return 0l; } startNode->addConnector(connector); flushDeleteList(); // Delete any connectors that might have been removed by the nodes // Set the route to the manual created one if the user created such a route if(pointList) connector->setRoutePoints(*pointList,true); // FIXME WTF is going on here? Redundant/meaningless code? // ConnectorList connectorList; // connectorList.append(connector); setModified(true); requestRerouteInvalidatedConnectors(); return connector; }
bool CircuitICNDocument::joinConnectors( ECNode *node ) { // We don't want to destroy the node if it has a parent if ( node->parentItem() ) return false; node->removeNullConnectors(); // an electronic node can be removed if it has exactly 2 connectors connected to it int conCount = node->getAllConnectors().count(); if ( conCount != 2 ) return false; Connector *con1, *con2; ECNode *startNode = NULL; ECNode *endNode = NULL; QPointList conPoints; con1 = node->connectorList().at(0).data(); con2 = node->connectorList().at(1).data(); if ( con1 == con2 ) return false; // we don't know on which end of the connectors is our node, so we must check both ends // HACK // TODO // dynamic_cast used, because Connector doesn't know about ECNode, only Node if( con1->startNode() == node ) startNode = dynamic_cast<ECNode*> ( con1->endNode() ); else startNode = dynamic_cast<ECNode*> ( con1->startNode() ); if( con2->startNode() == node ) endNode = dynamic_cast<ECNode*> ( con2->endNode() ); else endNode = dynamic_cast<ECNode*> ( con2->startNode() ); conPoints = con1->connectorPoints(false) + con2->connectorPoints(false); if( !startNode || !endNode ) return false; Connector *newCon = endNode->createConnector(startNode); if(!newCon) return false; startNode->addConnector(newCon); newCon->setRoutePoints( conPoints, con1->usesManualPoints() || con2->usesManualPoints() ); // Avoid flicker: update draw lists now con1->updateConnectorPoints(false); con2->updateConnectorPoints(false); newCon->updateDrawList(); node->removeNode(); con1->removeConnector(); con2->removeConnector(); return true; }