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

void Connector::updateDrawList (  ) 

Update the list of lines and connetion-points that the connector uses for drawing.

Definition at line 224 of file connector.cpp.

References ConRouter::cellPointList(), ICNDocument::cells(), and ICNDocument::isValidCellReference().

Referenced by ICNDocument::createConnector(), ICNDocument::joinConnectors(), restoreFromConnectorData(), and translateRoute().

{
      if ( !m_startNode || !m_endNode || !canvas() ) {
            return;
      }
      
      QPointList drawLineList;
      
      int prevX = (*m_conRouter->cellPointList()->begin()).x();
      int prevY = (*m_conRouter->cellPointList()->begin()).y();
      
      int prevX_canvas = toCanvas(prevX);
      int prevY_canvas = toCanvas(prevY);
      
      Cells *cells = p_icnDocument->cells();
      
      bool bumpNow = false;
      const QPointList::const_iterator cplEnd = m_conRouter->cellPointList()->end();
      for ( QPointList::const_iterator it = m_conRouter->cellPointList()->begin(); it != cplEnd; ++it )
      {
            const int x = (*it).x();
            const int y = (*it).y();
            const int numCon = p_icnDocument->isValidCellReference(x,y) ? (*cells)[x][y].numCon : 0;
            
            const int y_canvas = toCanvas(y);
            const int x_canvas = toCanvas(x);
            
            const bool bumpNext = ( prevX == x &&
                                                numCon > 1 &&
                                                std::abs(y_canvas-m_startNode->y())>8 &&
                                                std::abs(y_canvas-m_endNode->y())>8 );
            
            int x0 = prevX_canvas;
            int x2 = x_canvas;
            int x1 = (x0+x2)/2;
            
            int y0 = prevY_canvas;
            int y3 = y_canvas;
            int y1 = ( y0 == y3 ) ? y0 : ((y0<y3) ? y0+3 : y0-3);
            int y2 = ( y0 == y3 ) ? y3 : ((y0<y3) ? y3-3 : y3+3);
            
            if (bumpNow) x0 += 3;
            if (bumpNext) x2 += 3;
            
            if ( !bumpNow && !bumpNext )
            {
                  drawLineList += QPoint( x0, y0 );
                  drawLineList += QPoint( x2, y3 );
            }
            else if (bumpNow)
            {
                  drawLineList += QPoint( x0, y0 );
                  drawLineList += QPoint( x1, y1 );
                  drawLineList += QPoint( x2, y3 );
            }
            else if (bumpNext)
            {
                  drawLineList += QPoint( x0, y0 );
                  drawLineList += QPoint( x1, y2 );
                  drawLineList += QPoint( x2, y3 );
            }
            else
            {
                  drawLineList += QPoint( x0, y0 );
                  drawLineList += QPoint( x1, y1 );
                  drawLineList += QPoint( x1, y2 );
                  drawLineList += QPoint( x2, y3 );
            }
            
            prevX = x;
            prevY = y;
            prevY_canvas = y_canvas;
            prevX_canvas = x_canvas;
            bumpNow = bumpNext;
      }
      
      // Now, remove redundant points (i.e. those that are either repeated or are
      // in the same direction as the previous points)
      
      if ( drawLineList.size() < 3 ) {
            return;
      }
      
      const QPointList::iterator dllEnd = drawLineList.end();
      
      QPointList::iterator previous = drawLineList.begin();
      
      QPointList::iterator current = previous;
      current++;
      
      QPointList::const_iterator next = current;
      next++;
      
      while ( previous != dllEnd && current != dllEnd && next != dllEnd )
      {
            const int slope1 = getSlope( (*previous).x(), (*previous).y(), (*current).x(), (*current).y() );
            const int slope2  = getSlope( (*current).x(), (*current).y(), (*next).x(), (*next).y() );
            
            if ( slope1 == slope2 || slope1 == 0 || slope2 == 0 ) 
            {
                  *current = QPoint( -1, -1 );
            }
            else
            {
                  previous = current;
            }
            
            current++;
            next++;
      }
      
      drawLineList.remove( QPoint( -1, -1 ) );
      
      // Find the bounding rect
      {
            int x1=-1, y1=-1, x2=-1, y2=-1;
            const QPointList::iterator end = drawLineList.end();
            for ( QPointList::iterator it = drawLineList.begin(); it != end; ++it )
            {
                  const QPoint p = *it;
                  if ( p.x() < x1 || x1 == -1 ) {
                        x1 = p.x();
                  }
                  if ( p.x() > x2 || x2 == -1 ) {
                        x2 = p.x();
                  }
                  if ( p.y() < y1 || y1 == -1 ) {
                        y1 = p.y();
                  }
                  if ( p.y() > y2 || y2 == -1 ) {
                        y2 = p.y();
                  }
            }
            
            QRect boundRect( x1, y1, x2-x1, y2-y1 );
            if ( boundRect != m_oldBoundRect )
            {
                  canvas()->setChanged( boundRect | m_oldBoundRect );
                  m_oldBoundRect = boundRect;
            }
      }
      
      //BEGIN build up ConnectorLine list
      const ConnectorLineList::iterator ConnectorLineEnd = m_connectorLineList.end();
      for ( ConnectorLineList::iterator it = m_connectorLineList.begin(); it != ConnectorLineEnd; ++it )
            delete *it;
      m_connectorLineList.clear();
      
      if ( drawLineList.size() > 1 )
      {
            QPoint prev = drawLineList.first();
            const QPointList::iterator end = drawLineList.end();
            for ( QPointList::iterator it = ++drawLineList.begin(); it != end; ++it )
            {
                  const QPoint next = *it;
                  ConnectorLine *line = new ConnectorLine(this);
                  line->setPoints( prev.x(), prev.y(), next.x(), next.y() );
                  m_connectorLineList.append(line);
                  prev = next;
            }
      }
      updateConnectorLines();
      //END build up ConnectorPoint list
}


Generated by  Doxygen 1.6.0   Back to index