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

void ICNDocument::rerouteInvalidatedConnectors (  )  [inherited]

Reroutes invalidated directors. You shouldn't call this function directly - instead use ItemDocument::requestEvent.

Definition at line 1143 of file icndocument.cpp.

References ICNDocument::addAllItemConnectorPoints(), Connector::connectorPoints(), NodeGroup::contains(), Connector::endNode(), Connector::nodeGroup(), Connector::startNode(), and Connector::usesManualPoints().

Referenced by ItemDocument::processItemDocumentEvents().

{
      qApp->processEvents(300);
      
      // We only ever need to add the connector points for CNItem's when we're about to reroute...
      addAllItemConnectorPoints();
      
      // List of connectors which are to be determined to need rerouting (and whose routes aren't controlled by NodeGroups)
      ConnectorList connectorRerouteList;
      
      // For those connectors that are controlled by node groups
      NodeGroupList nodeGroupRerouteList;
      
      const ConnectorList::iterator connectorListEnd = m_connectorList.end();
      for ( ConnectorList::iterator it = m_connectorList.begin(); it != connectorListEnd; ++it )
      {
            Connector *connector = *it;
            if ( connector && connector->isVisible() && connector->startNode() && connector->endNode() )
            {
                  // Perform a series of tests to see if the connector needs rerouting
                  bool needsRerouting = false;
                  
                  // Test to see if we actually have any points
                  const QPointList pointList = connector->connectorPoints();
                  if ( pointList.isEmpty() )
                        needsRerouting = true;
                  
                  // Test to see if the route doesn't match up with the node positions at either end
                  if (!needsRerouting)
                  {
                        const QPoint listStart = pointList.first();
                        const QPoint listEnd = pointList.last();
                        const QPoint nodeStart = QPoint( int(connector->startNode()->x()), int(connector->startNode()->y()) );
                        const QPoint nodeEnd = QPoint( int(connector->endNode()->x()), int(connector->endNode()->y()) );
                        
                        if ( ((listStart != nodeStart) || (listEnd != nodeEnd)) &&
                                                   ((listStart != nodeEnd) || (listEnd != nodeStart)) )
                        {
                              needsRerouting = true;
//                            kdDebug() << "listStart=("<<listStart.x()<<","<<listStart.y()<<") nodeStart=("<<nodeStart.x()<<","<<nodeStart.y()<<") listEnd=("<<listEnd.x()<<","<<listEnd.y()<<") nodeEnd=("<<nodeEnd.x()<<","<<nodeEnd.y()<<")"<<endl;
                        }
                  }
                  
                  // Test to see if the route intersects any Items (we ignore if it is a manual route)
                  if ( !needsRerouting && !connector->usesManualPoints() )
                  {
                        const QCanvasItemList collisions = connector->collisions(true);
                        const QCanvasItemList::const_iterator collisionsEnd = collisions.end();
                        for ( QCanvasItemList::const_iterator collisionsIt = collisions.begin(); (collisionsIt != collisionsEnd) && !needsRerouting; ++collisionsIt )
                        {
                              if ( dynamic_cast<Item*>(*collisionsIt) )
                                    needsRerouting = true;
                        }
                  }
                  
                  if (needsRerouting)
                  {
                        NodeGroup *nodeGroup = connector->nodeGroup();
                        
                        if ( !nodeGroup && !connectorRerouteList.contains(connector) )
                              connectorRerouteList.append(connector);
                        
                        else if ( nodeGroup && !nodeGroupRerouteList.contains(nodeGroup) )
                              nodeGroupRerouteList.append(nodeGroup);
                  }
            }
      }
      
      // To allow proper rerouting, we want to start with clean routes for all of the invalidated connectors
      const NodeGroupList::iterator nodeGroupRerouteEnd = nodeGroupRerouteList.end();
      for ( NodeGroupList::iterator it = nodeGroupRerouteList.begin(); it != nodeGroupRerouteEnd; ++it )
      {
            const ConnectorList contained = (*it)->connectorList();
            const ConnectorList::const_iterator end = contained.end();
            for ( ConnectorList::const_iterator it = contained.begin(); it != end; ++it )
                  (*it)->updateConnectorPoints(false);
      }
      
      const ConnectorList::iterator connectorRerouteEnd = connectorRerouteList.end();
      for ( ConnectorList::iterator it = connectorRerouteList.begin(); it != connectorRerouteEnd; ++it )
            (*it)->updateConnectorPoints(false);
      
      // And finally, reroute the connectors
      for ( NodeGroupList::iterator it = nodeGroupRerouteList.begin(); it != nodeGroupRerouteEnd; ++it )
            (*it)->updateRoutes();
      
      for ( ConnectorList::iterator it = connectorRerouteList.begin(); it != connectorRerouteEnd; ++it )
            (*it)->rerouteConnector();
      
      for ( ConnectorList::iterator it = m_connectorList.begin(); it != connectorListEnd; ++it )
      {
            if (*it)
                  (*it)->updateDrawList();
      }
}


Generated by  Doxygen 1.6.0   Back to index