X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/d30c9cf675ad7141d1c8e31d2e72315267d45cf2..2019e5afdaf7fd0ad21607848710348bbc3be256:/AbstractBoxItem.cpp?ds=sidebyside diff --git a/AbstractBoxItem.cpp b/AbstractBoxItem.cpp index ec791fb..925cd6f 100644 --- a/AbstractBoxItem.cpp +++ b/AbstractBoxItem.cpp @@ -8,6 +8,7 @@ #include "AbstractBlock.h" #include "GroupScene.h" +#include "GroupItem.h" #include "AbstractInterface.h" #include "ConnectedInterface.h" @@ -15,12 +16,11 @@ AbstractBoxItem:: AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem *parent) : QGraphicsItem(parent) { dispatcher = _dispatcher; params = _params; - refBlock = _refBlock; - QFont fontId("Arial",10); - QFontMetrics fmId(fontId); + refBlock = _refBlock; + QFontMetrics fmId(params->defaultBlockFont); nameWidth = fmId.width(refBlock->getName()); nameHeight = fmId.height(); - nameMargin = 10; + nameMargin = 5; ifaceMargin = 10; // the six following values will be override in subclass constructors @@ -36,7 +36,37 @@ AbstractBoxItem:: AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispat selected = false; currentInterface = NULL; rstClkVisible = false; + wishboneVisible = false; + + setAcceptHoverEvents(true); + + // NOTE : initInterfaces() is only called in subclasses +} + +AbstractBoxItem::AbstractBoxItem(Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem* parent) : QGraphicsItem(parent) { + dispatcher = _dispatcher; + params = _params; + refBlock = NULL; + nameWidth = 0; + nameHeight = 0; + nameMargin = 10; + ifaceMargin = 10; + // the six following values will be override in subclass constructors + minimumBoxWidth = 0; + minimumBoxHeight = 0; + boxWidth = 0; + boxHeight = 0; + totalWidth = 0; + totalHeight = 0; + + originPoint = QPointF(0.0,0.0); + + selected = false; + currentInterface = NULL; + rstClkVisible = false; + wishboneVisible = false; + setAcceptHoverEvents(true); // NOTE : initInterfaces() is only called in subclasses @@ -57,13 +87,56 @@ bool AbstractBoxItem::isGroupItem() { return false; } -void AbstractBoxItem::initInterfaces() -{ +bool AbstractBoxItem::isSourceItem() { + return false; +} + +void AbstractBoxItem::setRstClkVisible(bool b) { + rstClkVisible = b; + foreach(InterfaceItem* ifaceItem, interfaces) { + if ((ifaceItem->refInter->getPurpose() == AbstractInterface::Clock) || + (ifaceItem->refInter->getPurpose() == AbstractInterface::Reset) ) { + ifaceItem->visible = b; + } + } + resetInterfaceItemsPosition(); + updateGeometry(InterfaceMove); + update(); + getScene()->updateConnectionItemsShape(); + (getScene()->getGroupItem())->updateShape(); + +} + +void AbstractBoxItem::setWishboneVisible(bool b) { + wishboneVisible = b; + foreach(InterfaceItem* ifaceItem, interfaces) { + if (ifaceItem->refInter->getPurpose() == AbstractInterface::Wishbone) { + ifaceItem->visible = b; + } + } + resetInterfaceItemsPosition(); + updateGeometry(InterfaceMove); + update(); + getScene()->updateConnectionItemsShape(); + (getScene()->getGroupItem())->updateShape(); +} + +void AbstractBoxItem::setRefBlock(AbstractBlock* _refBlock) { + refBlock = _refBlock; + QFontMetrics fmId(params->defaultBlockFont); + nameWidth = fmId.width(refBlock->getName()); + nameHeight = fmId.height(); +} + +void AbstractBoxItem::initInterfaceItems() { /* TO DO : creating all needed InterfaceItem, with by default, input at west and output at east */ int orientation = Parameters::West; foreach(AbstractInterface *inter, refBlock->getInterfaces()){ - if(inter->getPurpose() != AbstractInterface::Wishbone){ + + /* NB: does not create InterfaceItem for control interfaces. + */ + if (inter->getPurpose() != AbstractInterface::Control) { InterfaceItem *item; if(inter->getDirection() == AbstractInterface::Input){ orientation = Parameters::West; @@ -73,12 +146,12 @@ void AbstractBoxItem::initInterfaces() orientation = Parameters::North; } item = new InterfaceItem(0.0 , orientation, (ConnectedInterface *)inter, this, params); - interfaces.append(item); + interfaces.append(item); } - } + } } -InterfaceItem* AbstractBoxItem::searchInterfaceByName(QString name) { +InterfaceItem* AbstractBoxItem::searchInterfaceItemByName(QString name) { foreach(InterfaceItem *inter, interfaces){ if(inter->getName() == name) return inter; @@ -86,7 +159,7 @@ InterfaceItem* AbstractBoxItem::searchInterfaceByName(QString name) { return NULL; } -InterfaceItem* AbstractBoxItem::searchInterfaceByRef(ConnectedInterface *ref) { +InterfaceItem* AbstractBoxItem::searchInterfaceItemByRef(ConnectedInterface *ref) { foreach(InterfaceItem *inter, interfaces){ if(inter->refInter == ref) { return inter; @@ -95,16 +168,16 @@ InterfaceItem* AbstractBoxItem::searchInterfaceByRef(ConnectedInterface *ref) { return NULL; } -void AbstractBoxItem::addInterface(InterfaceItem *i, bool resetPosition) { +void AbstractBoxItem::addInterfaceItem(InterfaceItem *i, bool resetPosition) { interfaces.append(i); - if (resetPosition) resetInterfacesPosition(); + if (resetPosition) resetInterfaceItemsPosition(); updateGeometry(InterfaceMove); update(); } -void AbstractBoxItem::removeInterface(InterfaceItem *i) { +void AbstractBoxItem::removeInterfaceItem(InterfaceItem *i) { // NB : removing from model is done in dispatcher - interfaces.removeOne(i); + interfaces.removeAll(i); delete i; //resetInterfacesPosition(); @@ -113,7 +186,7 @@ void AbstractBoxItem::removeInterface(InterfaceItem *i) { } -void AbstractBoxItem::resetInterfacesPosition() { +void AbstractBoxItem::resetInterfaceItemsPosition() { int nbNorth=0, nbSouth=0, nbEast=0, nbWest=0; double cntNorth=1.0,cntSouth=1.0,cntEast=1.0,cntWest=1.0; @@ -122,7 +195,7 @@ void AbstractBoxItem::resetInterfacesPosition() { foreach(InterfaceItem* inter, interfaces) { // only data interfaces and if needed time and reset - if(inter->refInter->getPurpose() == AbstractInterface::Data || inter->getOwner()->isRstClkVisible()){ + if(inter->visible) { if(inter->getOrientation() == Parameters::North){ nbNorth++; } else if(inter->getOrientation() == Parameters::South){ @@ -137,7 +210,7 @@ void AbstractBoxItem::resetInterfacesPosition() { foreach(InterfaceItem* inter, interfaces) { - if(inter->refInter->getPurpose() == AbstractInterface::Data || inter->getOwner()->isRstClkVisible()){ + if(inter->visible){ if(inter->getOrientation() == Parameters::North){ positionRatio = cntNorth/(double)(nbNorth+1); @@ -158,7 +231,7 @@ void AbstractBoxItem::resetInterfacesPosition() { } } -void AbstractBoxItem::moveInterfaceTo(QPointF pos) { +void AbstractBoxItem::moveInterfaceItemTo(QPointF pos) { double positionRatio; if(currentInterface->getOrientation() == Parameters::North || currentInterface->getOrientation() == Parameters::South){ if(pos.x() < 0){ @@ -196,11 +269,26 @@ void AbstractBoxItem::moveInterfaceTo(QPointF pos) { QRectF AbstractBoxItem::boundingRect() const { // returns a QRectF that contains the block (i.e the main rectangle, interfaces, title, ...) - QPointF p = originPoint - QPointF(nameHeight,nameHeight); - QSizeF s(totalWidth+2*nameHeight,totalHeight+2*nameHeight); + QPointF p = originPoint; + QSizeF s(totalWidth,totalHeight); return QRectF(p,s); } +QRectF AbstractBoxItem::boundingRectInScene() { + /* returns a QRectF in scene coordinates, that contains the block plus + a margin of size arrowWidth+arrowLineLength + */ + int marginConn = params->arrowLineLength+params->arrowWidth; + + QPointF posBox = scenePos(); + posBox.setX(posBox.x()+originPoint.x()-marginConn); + posBox.setY(posBox.y()+originPoint.y()-marginConn); + + QSizeF sizeBox(totalWidth+2*marginConn,totalHeight+2*marginConn); + + return QRectF(posBox,sizeBox); +} + /* isInterface() : return true if there are some interfaces with the given orientation (N,S,E,O) @@ -220,7 +308,7 @@ int AbstractBoxItem::nbInterfacesByOrientation(int orientation) { return nb; } -void AbstractBoxItem::updateInterfacesAndConnections() { +void AbstractBoxItem::updateInterfaceAndConnectionItems() { // update all interfaces positions foreach(InterfaceItem *item, interfaces){ @@ -242,7 +330,7 @@ void AbstractBoxItem::setDimension(int x, int y) { boxHeight = y; } -InterfaceItem* AbstractBoxItem::getInterfaceFromCursor(qreal x, qreal y) { +InterfaceItem* AbstractBoxItem::getInterfaceItemFromCursor(qreal x, qreal y) { foreach(InterfaceItem* inter, interfaces) { if(x > inter->boundingRect().x() && x < (inter->boundingRect().x() + inter->boundingRect().width())){