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

void CNItem::updateConnectorPoints ( bool  add  )  [virtual, inherited]

ICNDocument needs to know what 'cells' a CNItem is present in, so that connection mapping can be done to avoid CNItems. This function will add the hit penalty to the cells pointed to by ICNDocument::cells()

Reimplemented in FlowContainer.

Definition at line 468 of file cnitem.cpp.

References Cells::height(), and Cells::width().

Referenced by ICNDocument::addAllItemConnectorPoints(), ICNDocument::createCellMap(), CNItem::moveBy(), CNItem::removeItem(), Component::setAngleDegrees(), and Component::setFlipped().

{
      if ( b_deleted || !isVisible() )
            add = false;

      if ( b_pointsAdded == add )
            return;

      b_pointsAdded = add;

      Cells *cells = p_icnDocument->cells();
      if (!cells) return;
      
      const int cx = cells->width();
      const int cy = cells->height();
      
      if ( cx < 1 || cy < 1 ) {
            return;
      }
      
      // Get translation matrix
      // Hackish...
      QWMatrix m;
      if ( Component *c = dynamic_cast<Component*>(this) )
            m = c->transMatrix( c->angleDegrees(), c->flipped(), int(x()), int(y()), false );
      
      // Convention used here: _UM = unmapped by both matrix and cell reference, _M = mapped

      const QPoint start_UM = QPoint( int(x()+offsetX())-cellSize, int(y()+offsetY())-cellSize );
      const QPoint end_UM = start_UM + QPoint( width()+2*cellSize, height()+2*cellSize );
      
      const QPoint start_M = m.map(start_UM)/cellSize;
      const QPoint end_M = m.map(end_UM)/cellSize;
      
      
      int sx_M = start_M.x();
      int ex_M = end_M.x();
      
      int sy_M = start_M.y();
      int ey_M = end_M.y();
      
      
      // Normalise start and end points
      if ( sx_M > ex_M )
      {
            const int temp = sx_M;
            sx_M = ex_M;
            ex_M = temp;
      }
      if ( sy_M > ey_M )
      {
            const int temp = sy_M;
            sy_M = ey_M;
            ey_M = temp;
      }
      
      ex_M++;
      ey_M++;
      
      const int mult = add ? 1 : -1;
      
      for ( int x = sx_M; x < ex_M; x++ )
      {
            for ( int y = sy_M; y < ey_M; y++ )
            {
                  if ( p_icnDocument->isValidCellReference( x, y ) )
                  {
                        if ( x != sx_M && y != sy_M && x != (ex_M-1) && y != (ey_M-1) )
                        {
                              (*cells)[x][y].CIpenalty += mult*ICNDocument::hs_item;
                        }
                        else 
                        {
//                            (*cells)[x][y].CIpenalty += mult*ICNDocument::hs_item/2;
                              (*cells)[x][y].CIpenalty += mult*ICNDocument::hs_connector*5;
                        }
                  }
            }
      }
      
#if 0
      // And subtract the positions of the node on the border
      NodeMap::iterator end = m_nodeMap.end();
      for ( NodeMap::iterator it = m_nodeMap.begin(); it != end; ++it )
      {
            const int x = (int)((it->second.node->x()-4)/cellSize);
            const int y = (int)((it->second.node->y()-4)/cellSize);
            if ( p_icnDocument->isValidCellReference(x,y) ) {
                  (*cells)[x][y].CIpenalty -= mult*ICNDocument::hs_connector*5;
            }
      }
#endif
      
      const TextMap::iterator textMapEnd = m_textMap.end();
      for ( TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it )
      {
            it.data()->updateConnectorPoints(add);
      }
      const WidgetMap::iterator widgetMapEnd = m_widgetMap.end();
      for ( WidgetMap::iterator it = m_widgetMap.begin(); it != widgetMapEnd; ++it )
      {
            it.data()->updateConnectorPoints(add);
      }
}


Generated by  Doxygen 1.6.0   Back to index