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

void NodeGroup::updateRoutes (  ) 

Reroute the NodeGroup. This function should only ever be called by ICNDocument::rerouteInvalidatedConnectors(), as it is important that there is only ever one entity controlling the routing of connectors.

Definition at line 114 of file nodegroup.cpp.

References ConRouter::dividePoints(), findBestPair(), findCommonConnector(), findRoute(), ConRouter::mapRoute(), Node::moveBy(), removeRoutedNodes(), Connector::setRoutePoints(), and Connector::updateConnectorPoints().

{
      resetRoutedMap();
      
      // Basic algorithm used here: starting with the external nodes, find the
      // pair with the shortest distance between them. Route the connectors
      // between the two nodes appropriately. Remove that pair of nodes from the
      // list, and add the nodes along the connector route (which have been spaced
      // equally along the route). Repeat until all the nodes are connected.
      
      
      const ConnectorList::iterator conEnd = m_conList.end();
      for ( ConnectorList::iterator it = m_conList.begin(); it != conEnd; ++it )
      {
            if (*it) 
                  (*it)->updateConnectorPoints(false);
      }
      
      Node *n1, *n2;
      NodeList currentList = m_extNodeList;
      while ( !currentList.isEmpty() )
      {
            findBestPair( &currentList, &n1, &n2 );
            if ( n1 == 0l || n2 == 0l ) {
                  return;
            }
            NodeList route = findRoute( n1, n2 );
            currentList += route;
            
            ConRouter cr(p_icnDocument);
            cr.mapRoute( (int)n1->x(), (int)n1->y(), (int)n2->x(), (int)n2->y() );
            QPointListList pl = cr.dividePoints( route.size()+1 );
            
            const NodeList::iterator routeEnd = route.end();
            const QPointListList::iterator plEnd = pl.end();
            Node *prev = n1;
            NodeList::iterator routeIt = route.begin();
            for ( QPointListList::iterator it = pl.begin(); it != plEnd; ++it )
            {
                  Node *next = (routeIt == routeEnd) ? n2 : (Node*)*(routeIt++);
                  removeRoutedNodes( &currentList, prev, next );
                  QPointList pointList = *it;
                  if ( prev != n1 )
                  {
                        QPoint first = pointList.first();
                        prev->moveBy( first.x() - prev->x(), first.y() - prev->y() );
                  }
                  Connector *con = findCommonConnector( prev, next );
                  if (con)
                  {
                        con->updateConnectorPoints(false);
                        con->setRoutePoints( pointList, false, false );
                        con->updateConnectorPoints(true);
//                      con->conRouter()->setPoints( &pointList, con->startNode() != prev );
//                      con->conRouter()->setPoints( &pointList, con->pointsAreReverse( &pointList ) );
//                      con->calcBoundingPoints();
                  }
                  prev = next;
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index