X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/abbc64cf04a35ab3549d5c516f44c7c5921baa63..e5af659f87bcb199d6a5f10f09b311138351d0f3:/AbstractBoxItem.cpp diff --git a/AbstractBoxItem.cpp b/AbstractBoxItem.cpp index 0afbe29..b76bf66 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,9 +16,8 @@ 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; @@ -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 @@ -56,26 +86,64 @@ bool AbstractBoxItem::isBoxItem() { bool AbstractBoxItem::isGroupItem() { 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; + } + } + resetInterfacesPosition(); + 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; + } + } + resetInterfacesPosition(); + 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::initInterfaces() -{ +void AbstractBoxItem::initInterfaces() { /* 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){ - InterfaceItem *item; - if(inter->getDirection() == AbstractInterface::Input){ - orientation = Parameters::West; - } else if(inter->getDirection() == AbstractInterface::Output){ - orientation = Parameters::East; - } else if(inter->getDirection() == AbstractInterface::InOut){ - orientation = Parameters::North; - } - item = new InterfaceItem(0.0 , orientation, (ConnectedInterface *)inter, this, params); - interfaces.append(item); + + /* NB: create InterfaceItem for every interfaces, even if they do not have a graphical representation + It will allow to save them in the XML project file and thus to create their equivalent + in the graph while the file is loaded. + */ + InterfaceItem *item; + if(inter->getDirection() == AbstractInterface::Input){ + orientation = Parameters::West; + } else if(inter->getDirection() == AbstractInterface::Output){ + orientation = Parameters::East; + } else if(inter->getDirection() == AbstractInterface::InOut){ + orientation = Parameters::North; } - } + item = new InterfaceItem(0.0 , orientation, (ConnectedInterface *)inter, this, params); + interfaces.append(item); + } } InterfaceItem* AbstractBoxItem::searchInterfaceByName(QString name) { @@ -98,7 +166,7 @@ InterfaceItem* AbstractBoxItem::searchInterfaceByRef(ConnectedInterface *ref) { void AbstractBoxItem::addInterface(InterfaceItem *i, bool resetPosition) { interfaces.append(i); if (resetPosition) resetInterfacesPosition(); - updateGeometry(); + updateGeometry(InterfaceMove); update(); } @@ -108,7 +176,7 @@ void AbstractBoxItem::removeInterface(InterfaceItem *i) { delete i; //resetInterfacesPosition(); - updateGeometry(); + updateGeometry(InterfaceMove); update(); } @@ -122,7 +190,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 +205,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 +226,7 @@ void AbstractBoxItem::resetInterfacesPosition() { } } -void AbstractBoxItem::deplaceInterface(QPointF pos) { +void AbstractBoxItem::moveInterfaceTo(QPointF pos) { double positionRatio; if(currentInterface->getOrientation() == Parameters::North || currentInterface->getOrientation() == Parameters::South){ if(pos.x() < 0){ @@ -226,11 +294,12 @@ void AbstractBoxItem::updateInterfacesAndConnections() { foreach(InterfaceItem *item, interfaces){ item->updatePosition(); } + // NB: dunno the utility of this test !! if (getScene() != NULL) { // update all connections from/to this block foreach(ConnectionItem *item, getScene()->getConnectionItems()){ if ((item->getFromInterfaceItem()->getOwner() == this) || (item->getToInterfaceItem()->getOwner() == this)) { - item->setPathes(); + item->setPath(); } } }