X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/f311fbc3e1436bf248c54225f0743cfa671c4bd7..18fecf25efe710631fabecbb9f689c2997fdfe18:/BoxItem.cpp diff --git a/BoxItem.cpp b/BoxItem.cpp index 237c7ee..4471c86 100644 --- a/BoxItem.cpp +++ b/BoxItem.cpp @@ -12,6 +12,7 @@ #include "ReferenceBlock.h" #include "ParametersWindow.h" #include "BlockParameter.h" +#include "Graph.h" BoxItem::BoxItem(AbstractBlock *_refBlock, @@ -32,15 +33,35 @@ BoxItem::BoxItem(AbstractBlock *_refBlock, setZValue(100); setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges); - initInterfaces(); + initInterfaceItems(); updateGeometry(InterfaceMove); - resetInterfacesPosition(); + resetInterfaceItemsPosition(); QPointF initPos = QPointF(0.0,0.0) - originPoint; setPos(initPos); //cout << "total size of block: " << totalWidth << "," << totalHeight << endl; //cout << "pos in group: " << x() << "," << y() << endl; } +BoxItem::BoxItem(Dispatcher *_dispatcher, Parameters *_params, GroupItem *parent) throw(Exception) : AbstractBoxItem(_dispatcher, _params, parent) { + + refBlock = NULL; + childGroupItem = NULL; + currentBorder = NoBorder; + selected = false; + + setZValue(100); + setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges); + + boxWidth = params->defaultBlockWidth; + boxHeight = params->defaultBlockHeight; + //initInterfaces(); + //updateGeometry(InterfaceMove); + //resetInterfacesPosition(); + //QPointF initPos = QPointF(0.0,0.0) - originPoint; + //setPos(initPos); + //cout << "total size of block: " << totalWidth << "," << totalHeight << endl; + //cout << "pos in group: " << x() << "," << y() << endl; +} BoxItem::~BoxItem() { } @@ -133,7 +154,7 @@ bool BoxItem::updateGeometry(ChangeType type) { bool boxSizeChanged = false; - // whatever the change, the minimum size may ahve changed + // whatever the change, the minimum size may have changed updateMinimumSize(); if (type == Resize) { @@ -152,7 +173,7 @@ bool BoxItem::updateGeometry(ChangeType type) { } } if (boxSizeChanged) { - updateInterfacesAndConnections(); + updateInterfaceAndConnectionItems(); } @@ -186,6 +207,20 @@ bool BoxItem::updateGeometry(ChangeType type) { return false; } +void BoxItem::nameChanged() { + + QFontMetrics fmId(params->defaultBlockFont); + nameWidth = fmId.width(refBlock->getName()); + nameHeight = fmId.height(); + + if (updateGeometry(InterfaceMove)) { + //cout << "must recompute group item geometry" << endl; + (getScene()->getGroupItem())->updateShape(); + } + // force the update in case of size has not changed + update(); +} + void BoxItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if(params->editState == Parameters::EditBlockMove) { @@ -245,6 +280,15 @@ void BoxItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { } break; } + case Title: + cout << "abnormal case while resizing block" << endl; + break; + case BorderWest: + cout << "abnormal case while resizing block" << endl; + break; + case BorderNorth: + cout << "abnormal case while resizing block" << endl; + break; case NoBorder: cout << "abnormal case while resizing block" << endl; break; @@ -258,10 +302,10 @@ void BoxItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { } else if(params->editState == Parameters::EditInterfaceMove) { prepareGeometryChange(); - moveInterfaceTo(event->pos()); + moveInterfaceItemTo(event->pos()); // recompute the geometry of the block if (updateGeometry(InterfaceMove)) { - cout << "must recompute group item geometry" << endl; + //cout << "must recompute group item geometry" << endl; (getScene()->getGroupItem())->updateShape(); } // update connection from/to the selected interface @@ -288,7 +332,7 @@ void BoxItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { dispatcher->setCurrentGroupWidget(getScene()->getGroupWidget()); if ((mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) { - InterfaceItem *inter = getInterfaceFromCursor(x,y); + InterfaceItem *inter = getInterfaceItemFromCursor(x,y); if (inter != NULL) { if (params->editState == Parameters::EditNoOperation) { @@ -307,9 +351,9 @@ void BoxItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { } } else if (mode == GroupScene::ItemEdition) { - setZValue(zValue()+100); + //setZValue(zValue()+100); if (params->cursorState == Parameters::CursorOnInterface) { - InterfaceItem *inter = getInterfaceFromCursor(x,y); + InterfaceItem *inter = getInterfaceItemFromCursor(x,y); if (inter != NULL) { if (inter == currentInterface) { params->setEditState(Parameters::EditInterfaceDeselect); @@ -338,7 +382,7 @@ void BoxItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { void BoxItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - setZValue(zValue()-100); + //setZValue(zValue()-100); int mode = getScene()->getEditionMode(); @@ -359,10 +403,12 @@ void BoxItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { else if (params->editState == Parameters::EditCloseConnection) { InterfaceItem* iface1 = getScene()->getSelectedInterface(1); InterfaceItem* iface2 = getScene()->getSelectedInterface(2); - bool ok = dispatcher->connect(iface1,iface2); + bool ok = dispatcher->createConnection(iface1,iface2); if (ok) { iface1->selected = false; - // no update needed since the whole scene will be repainted + update(iface1->boundingRect()); + iface2->selected = false; + update(iface2->boundingRect()); getScene()->setSelectedInterface(1,NULL); getScene()->setSelectedInterface(2,NULL); params->setEditState(Parameters::EditNoOperation); @@ -392,7 +438,7 @@ void BoxItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event) { int mode = getScene()->getEditionMode(); if (mode == GroupScene::AddConnection) { - InterfaceItem* iface = getInterfaceFromCursor(x,y); + InterfaceItem* iface = getInterfaceItemFromCursor(x,y); if (iface != NULL) { params->cursorState = Parameters::CursorOnInterface; setCursor(Qt::PointingHandCursor); @@ -406,7 +452,7 @@ void BoxItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event) { int marginE = 5; int marginS = 5; - InterfaceItem* iface = getInterfaceFromCursor(x,y); + InterfaceItem* iface = getInterfaceItemFromCursor(x,y); if (iface != NULL) { params->cursorState = Parameters::CursorOnInterface; setCursor(Qt::PointingHandCursor); @@ -448,26 +494,31 @@ void BoxItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event) { } } } - QGraphicsItem::hoverMoveEvent(event); + //QGraphicsItem::hoverMoveEvent(event); + event->ignore(); } -void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { - +void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { + QMenu menu; QAction* titleAction = NULL; QAction* removeAction = NULL; QAction* duplicateAction = NULL; QAction* renameAction = NULL; - QAction* connectToGroup = NULL; - QAction* disconnectFromGroup = NULL; + QAction* connectToGroup = NULL; QAction* showProperties = NULL; QAction* cloneInterface = NULL; QAction* openWindow = NULL; - QAction* showRstClkInter = NULL; + QAction* showRstClkIface = NULL; + QAction* showWishboneIface = NULL; QAction* showParameters = NULL; + QAction* showPatterns = NULL; + QAction* showModifier = NULL; + QAction* removeModifier = NULL; + QAction* generateVHDL = NULL; - InterfaceItem* ifaceItem = getInterfaceFromCursor(event->pos().x(), event->pos().y()); + InterfaceItem* ifaceItem = getInterfaceItemFromCursor(event->pos().x(), event->pos().y()); // menu for interface if( ifaceItem != NULL){ @@ -483,7 +534,6 @@ void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { ConnectedInterface* ifaceGroup = NULL; bool canRemove = true; - if ((iface->getDirection() == AbstractInterface::Input) && (iface->getConnectedFrom() == NULL)) { connectToGroup = menu.addAction("Connect to group input"); } @@ -491,22 +541,14 @@ void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { connectToGroup = menu.addAction("Connect to group output"); } else if (iface->getConnectionFromParentGroup() != NULL) { - ifaceGroup = iface->getConnectionFromParentGroup(); - //if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) { - if (!ifaceGroup->isConnectedFrom()) { - disconnectFromGroup = menu.addAction("Disconnect from group"); - } - else { + ifaceGroup = iface->getConnectionFromParentGroup(); + if (ifaceGroup->isConnectedFrom()) { canRemove = false; } } else if (iface->getConnectionToParentGroup() != NULL) { - ifaceGroup = iface->getConnectionToParentGroup(); - //if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) { - if (!ifaceGroup->isConnectedTo()) { - disconnectFromGroup = menu.addAction("Disconnect from group"); - } - else { + ifaceGroup = iface->getConnectionToParentGroup(); + if (ifaceGroup->isConnectedTo()) { canRemove = false; } } @@ -521,6 +563,25 @@ void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { } } } + if (iface->getAssociatedIface() != NULL) { + if (iface->getDirection() == AbstractInterface::Output) { + showPatterns = menu.addAction("Show output pattern"); + } + else if (iface->getDirection() == AbstractInterface::Input) { + showPatterns = menu.addAction("Show input pattern"); + } + } + + if (iface->getAssociatedIface() != NULL) { + ConnectedInterface* assoIface = AI_TO_CON(iface->getAssociatedIface()); + if (assoIface->getInputModifier() != NULL) { + removeModifier = menu.addAction("Remove input modifier"); + } + if (assoIface->getInputModifier() != NULL) { + showModifier = menu.addAction("Show input modifier parameters"); + } + } + } // menu for blocks (group or func) else { @@ -538,11 +599,15 @@ void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { } else { duplicateAction = menu.addAction("Duplicate"); - showRstClkInter = menu.addAction("Show reset/clock interfaces"); - showRstClkInter->setCheckable(true); - showRstClkInter->setChecked(rstClkVisible); + showRstClkIface = menu.addAction("Show reset/clock interfaces"); + showRstClkIface->setCheckable(true); + showRstClkIface->setChecked(rstClkVisible); + showWishboneIface = menu.addAction("Show wishbone interfaces"); + showWishboneIface->setCheckable(true); + showWishboneIface->setChecked(wishboneVisible); } removeAction = menu.addAction("Remove"); + generateVHDL = menu.addAction("Generate VHDL"); } QAction* selectedAction = NULL; @@ -552,20 +617,27 @@ void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { if (selectedAction == removeAction) { if(ifaceItem != NULL) { - dispatcher->removeBlockInterface(ifaceItem); + dispatcher->removeFunctionalInterface(ifaceItem); } else { - dispatcher->removeBlock(this); + dispatcher->removeBoxItem(this); } } else if (selectedAction == duplicateAction) { - dispatcher->duplicateBlock(this); + dispatcher->duplicateBoxItem(this); } else if(selectedAction == renameAction){ - if(ifaceItem != NULL) + if(ifaceItem != NULL) { dispatcher->renameInterface(ifaceItem); - else - dispatcher->renameBlockOrGroup(this); + } + else { + if (refBlock->isFunctionalBlock()) { + dispatcher->renameFunctionalBlock(this); + } + else if (refBlock->isGroupBlock()) { + dispatcher->renameGroupBlock(childGroupItem); + } + } } else if(selectedAction == showProperties){ dispatcher->showProperties(ifaceItem); @@ -573,21 +645,179 @@ void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { else if (selectedAction == connectToGroup){ dispatcher->connectInterToGroup(ifaceItem); } - else if (selectedAction == disconnectFromGroup) { - dispatcher->disconnectInterFromGroup(ifaceItem); - } else if (selectedAction == cloneInterface){ - dispatcher->duplicateInterface(ifaceItem); + dispatcher->duplicateInterfaceItem(ifaceItem); } else if (selectedAction == openWindow){ dispatcher->showRaiseWindow(this); } - else if(selectedAction == showRstClkInter){ - dispatcher->showRstClkInter(this); + else if(selectedAction == showRstClkIface) { + dispatcher->showRstClkIface(this); + } + else if(selectedAction == showWishboneIface) { + dispatcher->showWishboneIface(this); } - else if(selectedAction == showParameters){ + else if(selectedAction == showParameters) { new ParametersWindow(refBlock, params, NULL); } + else if(selectedAction == showPatterns) { + dispatcher->showPatterns(ifaceItem); + } + else if(selectedAction == removeModifier) { + dispatcher->removeModifier(ifaceItem); + } + else if(selectedAction == showModifier) { + dispatcher->showModifier(ifaceItem); + } + else if(selectedAction == generateVHDL) { + dispatcher->generateBlockVHDL(this); + } + +} + +void BoxItem::loadFunctional(QDomElement funcElement) throw(Exception) { + + bool ok = false; + + int id = funcElement.attribute("id","none").toInt(&ok); + if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); + + QString refXml = funcElement.attribute("ref_xml","none"); + if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED)); + + QString refMd5 = funcElement.attribute("ref_md5","none"); + if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED)); + + cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl; + + QString name = funcElement.attribute("name","none"); + if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED)); + + QStringList positionStr = funcElement.attribute("position","none").split(","); + if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED)); + int posX = positionStr.at(0).toInt(&ok); + if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); + int posY = positionStr.at(1).toInt(&ok); + if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); + + QStringList dimensionStr = funcElement.attribute("dimension","none").split(","); + if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED)); + int dimX = dimensionStr.at(0).toInt(&ok); + if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); + int dimY = dimensionStr.at(1).toInt(&ok); + if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); + + ReferenceBlock *referenceMd5 = NULL; + ReferenceBlock *referenceXml = NULL; + ReferenceBlock *reference = NULL; + if(refMd5 != "none") { + referenceMd5 = params->searchBlockByMd5(refMd5); + } + if(refXml != "none"){ + referenceXml = params->searchBlockByXml(refXml); + } + if ((referenceMd5 == NULL) && (referenceXml == NULL)) { + throw(Exception(PROJECTFILE_CORRUPTED)); + } + if (referenceMd5 != referenceXml) { + throw(Exception(PROJECTFILE_CORRUPTED)); + } + else { + reference = referenceMd5; + } + + GroupBlock* parentGroupBlock = AB_TO_GRP(((GroupItem *)parentItem())->getRefBlock()); + FunctionalBlock* functionalBlock = params->getGraph()->createFunctionalBlock(parentGroupBlock, reference); + /* NB: addFunctionalBlock creates all interfaces from the reference, which is annoying when + reading bif_iface tags. Thus interface are all removed. + */ + functionalBlock->setName(name); + setRefBlock(functionalBlock); + params->blockToItem.insert(functionalBlock,this); + + setPos(posX,posY); + setDimension(dimX,dimY); + setId(id); + + + QDomNodeList blockParamNodes = funcElement.elementsByTagName("bif_parameter"); + // setting parameters value + for(int i=0; igetParameterFromName(name); + if (blockParam == NULL) throw(Exception(PROJECTFILE_CORRUPTED)); + blockParam->setValue(value); + } + + // recreate all (non-control) interfaces because of some may have a multiplicity>1 with several examplars + functionalBlock->removeAllInterfaces(); + QDomNodeList interfaceNodes = funcElement.elementsByTagName("bif_iface"); + // setting interfaces (user name, and for multiplicity>1 may be create some new ones) + for(int i=0; igetIfaceFromName(refName)); + cout << "creating iface from reference named " << qPrintable(refName) << endl; + FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter); + functionalInterface->setName(name); + functionalBlock->addInterface(functionalInterface); + + // searching for control interface + QString ctlRefName = refName+"_enb"; + ReferenceInterface* ctlRefIface = AI_TO_REF(reference->getIfaceFromName(ctlRefName)); + + if (ctlRefIface != NULL) { + cout << "found a control iface:" << qPrintable(ctlRefName) << endl; + FunctionalInterface *ctlIface = new FunctionalInterface(functionalBlock,ctlRefIface); + if (! ctlIface->setAssociatedIface(functionalInterface)) { + throw(Exception(PROJECTFILE_CORRUPTED)); + } + ctlIface->setName(name+"_enb"); + functionalBlock->addInterface(ctlIface); + } + } + + // creating InterfaceItem + initInterfaceItems(); + // setting them with saved values + for(int i=0; isetId(id); + interfaceItem->setOrientation(orientation); + interfaceItem->setPositionRatio(position); + } + updateGeometry(Resize); } void BoxItem::save(QXmlStreamWriter &writer) { @@ -598,7 +828,7 @@ void BoxItem::save(QXmlStreamWriter &writer) { writer.writeAttribute("ref_xml", ((FunctionalBlock*)refBlock)->getReferenceXmlFile()); writer.writeAttribute("ref_md5", ((FunctionalBlock*)refBlock)->getReferenceHashMd5()); writer.writeAttribute("name",refBlock->getName()); - QString attrPos = QString::number(pos().x()).append(",").append(QString::number(pos().y())); + QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y()))); writer.writeAttribute("position",attrPos); QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight())); writer.writeAttribute("dimension",attrDim); @@ -639,7 +869,7 @@ void BoxItem::save(QXmlStreamWriter &writer) { writer.writeAttribute("id",QString::number(id)); writer.writeAttribute("inside_group",QString::number(childGroupItem->getId())); - QString attrPos = QString::number(pos().x()).append(",").append(QString::number(pos().y())); + QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y()))); writer.writeAttribute("position",attrPos); QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight())); writer.writeAttribute("dimension",attrDim); @@ -682,7 +912,7 @@ QDataStream &operator <<(QDataStream &out, BoxItem &b) { for(int i=0; igetId(); - toWrite << inter->getName(); + //toWrite << inter->getName(); toWrite << inter->getPositionRatio(); toWrite << inter->getOrientation(); } @@ -692,8 +922,7 @@ QDataStream &operator <<(QDataStream &out, BoxItem &b) { return out; } -QDataStream &operator >>(QDataStream &in, BoxItem &b) -{ +QDataStream &operator >>(QDataStream &in, BoxItem &b) { in.setVersion(QDataStream::Qt_4_8); @@ -723,8 +952,7 @@ QDataStream &operator >>(QDataStream &in, BoxItem &b) in >> positionRatio; in >> orientation; - inter->setId(id); - inter->setName(name); + inter->setId(id); inter->setPositionRatio(positionRatio); inter->setOrientation(orientation); inter->updatePosition();