Logo Search packages:      
Sourcecode: ktechlab version File versions  Download package

Connector * ICNDocument::createConnector ( Connector con1,
Connector con2,
const QPoint &  pos1,
const QPoint &  pos2,
QPointList *  pointList = 0L 
) [inherited]

Splits con1 and con2 into two new connectors each at points pos1 and pos2, and creates a new connector between the two points of intersection given by pos1 and pos2. If pointList is non-null, then the new connector between the two points will be assigned those points

Definition at line 434 of file icndocument.cpp.

References ICNDocument::addAllItemConnectorPoints(), NodeGroup::addNode(), Node::addOutputConnector(), ICNDocument::canConnect(), Node::createInputConnector(), ICNDocument::createNodeGroup(), ICNDocument::deleteNodeGroup(), Connector::endNode(), ICNDocument::flushDeleteList(), NodeGroup::init(), ConRouter::mapRoute(), ConRouter::pointList(), Connector::removeConnector(), Node::removeNode(), Connector::setRoutePoints(), Connector::splitConnectorPoints(), Connector::startNode(), Document::type(), Connector::updateConnectorPoints(), Connector::updateDrawList(), and Connector::usesManualPoints().

{
      if ( !canConnect( con1, con2 ) )
            return 0l;
      
      const bool con1UsedManual = con1->usesManualPoints();
      const bool con2UsedManual = con2->usesManualPoints();
      
      QValueList<QPointList> oldCon1Points = con1->splitConnectorPoints(pos1);
      QValueList<QPointList> oldCon2Points = con2->splitConnectorPoints(pos2);
      
      Node *node1a = con1->startNode();
      Node *node1b = con1->endNode();
      
      Node *node2a = con2->startNode();
      Node *node2b = con2->endNode();
      
      if ( !node1a || !node1b || !node2a || !node2b )
            return 0l;
      
      con1->hide();     
      con2->hide();
      
      if ( type() != Document::dt_circuit )
            return 0l;
      
      ECNode * newNode1 = new ECNode( this, Node::ec_junction, Node::dir_right, pos1 );
      ECNode * newNode2 = new ECNode( this, Node::ec_junction, Node::dir_right, pos2 );
      
      Connector *con1a = newNode1->createInputConnector(node1a);
      node1a->addOutputConnector(con1a);
      Connector *con1b = newNode1->createInputConnector(node1b);
      node1b->addOutputConnector(con1b);
      
      Connector *newCon = newNode1->createInputConnector(newNode2);
      newNode2->addOutputConnector(newCon);
      
      Connector *con2a = node2a->createInputConnector(newNode2);
      newNode2->addOutputConnector(con2a);
      Connector *con2b = node2b->createInputConnector(newNode2);
      newNode2->addOutputConnector(con2b);
      
      if ( !con1a || !con1b || !con2a || !con2b )
      {
            // This should never happen, as the canConnect function should strictly
            // determine whether the connectors could be created before hand.
            kdWarning() << k_funcinfo << "Not all the connectors were created, this should never happen" << endl;
            
            if (con1a)
                  con1a->removeConnector();
            
            if (con1b)
                  con1b->removeConnector();
            
            if (con2a)
                  con2a->removeConnector();
            
            if (con2b)
                  con2b->removeConnector();
            
            newNode1->removeNode();
            newNode2->removeNode();
            
            flushDeleteList();
            return 0l;
      }
      
      con1a->setRoutePoints( *oldCon1Points.at(0), con1UsedManual );
      con1b->setRoutePoints( *oldCon1Points.at(1), con1UsedManual );
      
      con2a->setRoutePoints( *oldCon2Points.at(0), con2UsedManual );
      con2b->setRoutePoints( *oldCon2Points.at(1), con2UsedManual );
      
      QPointList autoPoints;
      if (!pointList)
      {
            addAllItemConnectorPoints();
            ConRouter cr(this);
            cr.mapRoute( pos1.x(), pos1.y(), pos2.x(), pos2.y() );
            autoPoints = cr.pointList(false);
            pointList = &autoPoints;
      }
      newCon->setRoutePoints(*pointList,true);
      
      
      // Avoid flicker: tell them to update their draw lists now
      con1->updateConnectorPoints(false);
      con2->updateConnectorPoints(false);
      newCon->updateDrawList();
      con1a->updateDrawList();
      con1b->updateDrawList();
      con2a->updateDrawList();
      con2b->updateDrawList();
      
      
      // Now it's safe to remove the connectors
      con1->removeConnector();
      con2->removeConnector();
      
      flushDeleteList();

      deleteNodeGroup(node1a);
      deleteNodeGroup(node1b);
      deleteNodeGroup(node2a);
      deleteNodeGroup(node2b);
      NodeGroup *ng = createNodeGroup(newNode1);
      ng->addNode( newNode2, true );
      ng->init();
      
      return newCon;
}


Generated by  Doxygen 1.6.0   Back to index