X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/624231601a0f5daea9b8809993ad3503beafce4f..8f0bedf735fe2b306c11c3f4a168245a05e37ccd:/ConnectionItem.cpp diff --git a/ConnectionItem.cpp b/ConnectionItem.cpp index c99d489..4de86cb 100644 --- a/ConnectionItem.cpp +++ b/ConnectionItem.cpp @@ -92,7 +92,7 @@ ConnectionItem::ConnectionItem(InterfaceItem* _iface1, setAcceptHoverEvents(true); setFlag(ItemSendsGeometryChanges); setCursor(Qt::PointingHandCursor); - setZValue(0); + setZValue(200); if (fromInterfaceItem->refInter->getPurpose() == AbstractInterface::Data) { visible = true; @@ -397,8 +397,8 @@ void ConnectionItem::setPath() { } } - pps.setWidth(5); - pathShape = pps.createStroke(pathPaint); + //pps.setWidth(5); + //pathShape = pps.createStroke(pathPaint); } @@ -406,86 +406,123 @@ void ConnectionItem::computeEsse(int orientationFrom) { //cout << "drawing an esse" << endl; pathPaint = QPainterPath(pointFrom); + QPainterPath s; interPoints.clear(); - double gap = marginConn; + double gap = marginConn; + if ((orientationFrom == Parameters::North)||(orientationFrom == Parameters::West)) gap = -gap; QPointF p(0.0,0.0); if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) { + // must draw a complete esse - p = QPointF(pointFrom.x()+gap,pointFrom.y()); + p = QPointF(pointFrom.x()+gap,pointFrom.y()); + s.moveTo(p); pathPaint.lineTo(p); interPoints.append(p); p = QPointF(pointFrom.x()+gap,(pointFrom.y()+pointTo.y())/2.0); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); p = QPointF(pointTo.x()-gap,(pointFrom.y()+pointTo.y())/2.0); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); p = QPointF(pointTo.x()-gap,pointTo.y()); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); } else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) { // must draw a complete esse - p = QPointF(pointFrom.x(),pointFrom.y()+gap); + p = QPointF(pointFrom.x(),pointFrom.y()+gap); pathPaint.lineTo(p); + s.moveTo(p); interPoints.append(p); p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointFrom.y()+gap); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointTo.y()-gap); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); p = QPointF(pointTo.x(), pointTo.y()-gap); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); } + pps.setWidth(5); + pathShape = pps.createStroke(s); } void ConnectionItem::computeStaircase(int orientationFrom) { pathPaint = QPainterPath(pointFrom); - interPoints.clear(); + QPainterPath s; + double gap = marginConn; + interPoints.clear(); QPointF p(0.0,0.0); if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) { + + if (orientationFrom == Parameters::West) gap = -gap; + p = QPointF(pointFrom.x()+gap,pointFrom.y()); + s.moveTo(p); + if (pointFrom.y() == pointTo.y()) { //cout << "drawing straight line" << endl; pathPaint.lineTo(pointTo); + } else { //cout << "drawing a staircase" << endl; // sufficient place to draw a simple staircase p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointFrom.y()); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointTo.y()); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); } + p = QPointF(pointTo.x()-gap,pointTo.y()); + s.lineTo(p); } else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) { + + if (orientationFrom == Parameters::North) gap = -gap; + + p = QPointF(pointFrom.x(),pointFrom.y()+gap); + s.moveTo(p); + if (pointFrom.x() == pointTo.x()) { //cout << "drawing straight line" << endl; - pathPaint.lineTo(pointTo); + pathPaint.lineTo(pointTo); } else { //cout << "drawing a staircase" << endl; // sufficient place to draw a simple staircase p = QPointF(pointFrom.x(),(pointFrom.y()+pointTo.y())/2.0); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); p = QPointF(pointTo.x(),(pointFrom.y()+pointTo.y())/2.0); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); } + p = QPointF(pointTo.x(),pointTo.y()-gap); + s.lineTo(p); } + pps.setWidth(5); + pathShape = pps.createStroke(s); } /* drawCorner(): @@ -500,20 +537,37 @@ void ConnectionItem::computeCorner(int orientationFrom) { pathPaint = QPainterPath(pointFrom); interPoints.clear(); QPointF p(0.0,0.0); + QPainterPath s; + double gap = marginConn; + //cout << "drawing a corner" << endl; if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) { + if (orientationFrom == Parameters::West) gap = -gap; + p = QPointF(pointFrom.x()+gap,pointFrom.y()); + s.moveTo(p); p = QPointF(pointTo.x(),pointFrom.y()); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); + p = QPointF(pointTo.x(),pointTo.y()-gap); + s.lineTo(p); } else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) { + if (orientationFrom == Parameters::North) gap = -gap; + p = QPointF(pointFrom.x(),pointFrom.y()+gap); + s.moveTo(p); p = QPointF(pointFrom.x(),pointTo.y()); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); + p = QPointF(pointTo.x()-gap,pointTo.y()); + s.lineTo(p); } + pps.setWidth(5); + pathShape = pps.createStroke(s); } /* drawOpenRect(): @@ -522,6 +576,8 @@ void ConnectionItem::computeCorner(int orientationFrom) { __ | |_| + + Its beginning and end have always a size of marginConn */ void ConnectionItem::computeOpenRect(int orientationFrom, int orientationTo) { pathPaint = QPainterPath(pointFrom); @@ -529,6 +585,7 @@ void ConnectionItem::computeOpenRect(int orientationFrom, int orientationTo) { QPointF p(0.0,0.0); double gap1 = marginConn; double gap2 = marginConn; + QPainterPath s; //cout << "drawing an OpenRect" << endl; if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) { @@ -540,12 +597,15 @@ void ConnectionItem::computeOpenRect(int orientationFrom, int orientationTo) { } p = QPointF(pointFrom.x()+gap1,pointFrom.y()); pathPaint.lineTo(p); + s.moveTo(p); interPoints.append(p); p = QPointF(pointFrom.x()+gap1,pointTo.y()+gap2); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); p = QPointF(pointTo.x(),pointTo.y()+gap2); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); @@ -559,17 +619,23 @@ void ConnectionItem::computeOpenRect(int orientationFrom, int orientationTo) { } p = QPointF(pointFrom.x(),pointFrom.y()+gap1); pathPaint.lineTo(p); + s.moveTo(p); interPoints.append(p); p = QPointF(pointTo.x()+gap2,pointFrom.y()+gap1); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); p = QPointF(pointTo.x()+gap2,pointTo.y()); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); } + pps.setWidth(5); + pathShape = pps.createStroke(s); } + /* drawHookSmallEnd(): A Hook has the following shape : @@ -581,41 +647,57 @@ void ConnectionItem::computeOpenRect(int orientationFrom, int orientationTo) { void ConnectionItem::computeHookSmallEnd(int orientationFrom, int orientationTo) { pathPaint = QPainterPath(pointFrom); interPoints.clear(); - QPointF p(0.0,0.0); - double gap = marginConn; + QPointF p(0.0,0.0); + QPainterPath s; + double gap2 = marginConn; + double gap1 = marginConn; //cout << "drawing a Hook with small end" << endl; if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) { - if (orientationTo == Parameters::North) gap = -gap; + if (orientationFrom == Parameters::West) gap1 = -gap1; + if (orientationTo == Parameters::North) gap2 = -gap2; + p = QPointF(pointFrom.x()+gap1,pointFrom.y()); + s.moveTo(p); p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointFrom.y()); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); - p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointTo.y()+gap); + p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointTo.y()+gap2); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); - p = QPointF(pointTo.x(),pointTo.y()+gap); + p = QPointF(pointTo.x(),pointTo.y()+gap2); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); } else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) { - if (orientationTo == Parameters::West) gap = -gap; - + if (orientationFrom == Parameters::North) gap1 = -gap1; + if (orientationTo == Parameters::West) gap2 = -gap2; + + p = QPointF(pointFrom.x(),pointFrom.y()+gap1); + s.moveTo(p); p = QPointF(pointFrom.x(),(pointFrom.y()+pointTo.y())/2.0); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); - p = QPointF(pointTo.x()+gap,(pointFrom.y()+pointTo.y())/2.0); + p = QPointF(pointTo.x()+gap2,(pointFrom.y()+pointTo.y())/2.0); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); - p = QPointF(pointTo.x()+gap,pointTo.y()); + p = QPointF(pointTo.x()+gap2,pointTo.y()); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); } + pps.setWidth(5); + pathShape = pps.createStroke(s); } /* drawHookSmallStart(): @@ -630,39 +712,55 @@ void ConnectionItem::computeHookSmallStart(int orientationFrom, int orientationT pathPaint = QPainterPath(pointFrom); interPoints.clear(); QPointF p(0.0,0.0); - double gap = marginConn; + QPainterPath s; + double gap1 = marginConn; + double gap2 = marginConn; //cout << "drawing a Hook with small start" << endl; if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) { - if (orientationFrom == Parameters::West) gap = -gap; + if (orientationFrom == Parameters::West) gap1 = -gap1; + if (orientationTo == Parameters::North) gap2 = -gap2; - p = QPointF(pointFrom.x()+gap,pointFrom.y()); + p = QPointF(pointFrom.x()+gap1,pointFrom.y()); + s.moveTo(p); pathPaint.lineTo(p); interPoints.append(p); - p = QPointF(pointFrom.x()+gap,(pointFrom.y()+pointTo.y())/2.0); + p = QPointF(pointFrom.x()+gap1,(pointFrom.y()+pointTo.y())/2.0); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); p = QPointF(pointTo.x(),(pointFrom.y()+pointTo.y())/2.0); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); + p = QPointF(pointTo.x(),pointFrom.y()+gap2); + s.lineTo(p); } else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) { - if (orientationFrom == Parameters::North) gap = -gap; + if (orientationFrom == Parameters::North) gap1 = -gap1; + if (orientationTo == Parameters::West) gap2 = -gap2; - p = QPointF(pointFrom.x(),pointFrom.y()+gap); + p = QPointF(pointFrom.x(),pointFrom.y()+gap1); + s.moveTo(p); pathPaint.lineTo(p); interPoints.append(p); - p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointFrom.y()+gap); + p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointFrom.y()+gap1); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointTo.y()); pathPaint.lineTo(p); + s.lineTo(p); interPoints.append(p); pathPaint.lineTo(pointTo); + p = QPointF(pointTo.x()+gap2,pointFrom.y()); + s.lineTo(p); } + pps.setWidth(5); + pathShape = pps.createStroke(s); } /* drawElle(): @@ -677,78 +775,84 @@ void ConnectionItem::computeElle(int orientationFrom) { pathPaint = QPainterPath(pointFrom); interPoints.clear(); QPointF p(0.0,0.0); + QPainterPath s; + double gap = marginConn; + double x; double y; - switch(orientationFrom){ - case Parameters::North : - if(pointFrom.y() < pointTo.y()) { - y = pointFrom.y()-marginConn; - } - else { - y = pointTo.y()-marginConn; - } - p = QPointF(pointFrom.x(),y); - pathPaint.lineTo(p); - interPoints.append(p); - p = QPointF(pointTo.x(),y); - pathPaint.lineTo(p); - interPoints.append(p); - pathPaint.lineTo(pointTo); - break; - case Parameters::South : - if(pointFrom.y() > pointTo.y()) { - y = pointFrom.y()+marginConn; - } - else { - y = pointTo.y()+marginConn; + if ((orientationFrom == Parameters::North) || (orientationFrom == Parameters::South)) { + double diffPos = pointFrom.y() - pointTo.y(); + if (orientationFrom == Parameters::North) { + gap = -gap; + diffPos = -diffPos; } - p = QPointF(pointFrom.x(),y); - pathPaint.lineTo(p); - interPoints.append(p); - p = QPointF(pointTo.x(),y); - pathPaint.lineTo(p); - interPoints.append(p); - pathPaint.lineTo(pointTo); - break; - case Parameters::West : - if(pointFrom.x() < pointTo.x()) { - x = pointFrom.x()-marginConn; + p = QPointF(pointFrom.x(),pointFrom.y()+gap); + s.moveTo(p); + if (diffPos >= 0.0) { + pathPaint.lineTo(p); + interPoints.append(p); + p = QPointF(pointTo.x(),pointFrom.y()+gap); + pathPaint.lineTo(p); + s.lineTo(p); + interPoints.append(p); + pathPaint.lineTo(pointTo); + p = QPointF(pointTo.x(),pointTo.y()+gap); + s.lineTo(p); } else { - x = pointTo.x()-marginConn; + p = QPointF(pointFrom.x(),pointTo.y()+gap); + pathPaint.lineTo(p); + s.lineTo(p); + interPoints.append(p); + p = QPointF(pointTo.x(),pointTo.y()+gap); + pathPaint.lineTo(p); + s.lineTo(p); + interPoints.append(p); + pathPaint.lineTo(pointTo); + } + } + else if ((orientationFrom == Parameters::West) || (orientationFrom == Parameters::East)) { + double diffPos = pointFrom.x() - pointTo.x(); + if (orientationFrom == Parameters::West) { + gap = -gap; + diffPos = -diffPos; } - p = QPointF(x, pointFrom.y()); - pathPaint.lineTo(p); - interPoints.append(p); - p = QPointF(x, pointTo.y()); - pathPaint.lineTo(p); - interPoints.append(p); - pathPaint.lineTo(pointTo); - break; - case Parameters::East : - if(pointFrom.x() > pointTo.x()) { - x = pointFrom.x()+marginConn; + p = QPointF(pointFrom.x()+gap,pointFrom.y()); + s.moveTo(p); + if (diffPos >= 0.0) { + pathPaint.lineTo(p); + interPoints.append(p); + p = QPointF(pointTo.x()+gap,pointFrom.y()); + pathPaint.lineTo(p); + s.lineTo(p); + interPoints.append(p); + pathPaint.lineTo(pointTo); + p = QPointF(pointTo.x()+gap,pointTo.y()); + s.lineTo(p); } else { - x = pointTo.x()+marginConn; + p = QPointF(pointFrom.x()+gap,pointTo.y()); + pathPaint.lineTo(p); + s.lineTo(p); + interPoints.append(p); + p = QPointF(pointTo.x()+gap,pointTo.y()); + pathPaint.lineTo(p); + s.lineTo(p); + interPoints.append(p); + pathPaint.lineTo(pointTo); } - p = QPointF(x, pointFrom.y()); - pathPaint.lineTo(p); - interPoints.append(p); - p = QPointF(x, pointTo.y()); - pathPaint.lineTo(p); - interPoints.append(p); - pathPaint.lineTo(pointTo); - break; } + + pps.setWidth(5); + pathShape = pps.createStroke(s); } void ConnectionItem::setSelected(bool selected) { this->selected = selected; if(selected){ - setZValue(50); + setZValue(201); } else { - setZValue(0); + setZValue(200); } } @@ -772,18 +876,22 @@ void ConnectionItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { /* have to check if the connection can be removed. If the from or to InterfaceItem is owned by a group item, and this item is both connected to and from, thus it is impossible to remove this connection + because there would be a group interface alone and not connected and this situation is not allowed. + + Nevertheless, there are 2 exceptions : + - a from group interface is connected to more than one input interface + - the connection is between a source block outside the top group and the top group */ bool canRemove = true; - InterfaceItem* groupIfaceItem = NULL; + if (fromInterfaceItem->getOwner()->isGroupItem()) { - groupIfaceItem = fromInterfaceItem; - } - else if (toInterfaceItem->getOwner()->isGroupItem()) { - groupIfaceItem = toInterfaceItem; + ConnectedInterface* ref = fromInterfaceItem->refInter; + if ((ref->isConnectedFrom()) && (ref->getConnectedTo().length() == 1)) { + canRemove = false; + } } - - if (groupIfaceItem != NULL) { - ConnectedInterface* ref = groupIfaceItem->refInter; + else if ((toInterfaceItem->getOwner()->isGroupItem()) && (! toInterfaceItem->getOwner()->getRefBlock()->isTopGroupBlock())) { + ConnectedInterface* ref = toInterfaceItem->refInter; if ((ref->isConnectedFrom()) && (ref->isConnectedTo())) { canRemove = false; }