2 #include "GroupScene.h"
3 #include "ConnectionItem.h"
4 #include "InterfaceItem.h"
6 #include "Parameters.h"
8 #include "Dispatcher.h"
9 #include "FunctionalBlock.h"
10 #include "FunctionalInterface.h"
11 #include "ReferenceInterface.h"
12 #include "ReferenceBlock.h"
13 #include "ParametersWindow.h"
14 #include "BlockParameter.h"
18 BoxItem::BoxItem(AbstractBlock *_refBlock,
19 Dispatcher *_dispatcher,
20 Parameters *_params, GroupItem *parent) throw(Exception) : AbstractBoxItem( _refBlock, _dispatcher, _params, parent) {
23 _refBlock : mandatory a FunctionalBlock or a GroupBlock
25 if (_refBlock->isReferenceBlock()) throw(Exception(BLOCK_INVALID_TYPE));
27 childGroupItem = NULL;
28 //boxWidth = params->defaultBlockWidth;
29 //boxHeight = params->defaultBlockHeight;
30 currentBorder = NoBorder;
34 setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
37 updateGeometry(InterfaceMove);
38 resetInterfaceItemsPosition();
39 QPointF initPos = QPointF(0.0,0.0) - originPoint;
41 //cout << "total size of block: " << totalWidth << "," << totalHeight << endl;
42 //cout << "pos in group: " << x() << "," << y() << endl;
45 BoxItem::BoxItem(Dispatcher *_dispatcher, Parameters *_params, GroupItem *parent) throw(Exception) : AbstractBoxItem(_dispatcher, _params, parent) {
48 childGroupItem = NULL;
49 currentBorder = NoBorder;
53 setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
55 boxWidth = params->defaultBlockWidth;
56 boxHeight = params->defaultBlockHeight;
58 //updateGeometry(InterfaceMove);
59 //resetInterfacesPosition();
60 //QPointF initPos = QPointF(0.0,0.0) - originPoint;
62 //cout << "total size of block: " << totalWidth << "," << totalHeight << endl;
63 //cout << "pos in group: " << x() << "," << y() << endl;
69 void BoxItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
70 QPen pen(Qt::black, 3);
72 pen.setColor(Qt::red);
75 painter->setBrush(Qt::yellow);
77 painter->drawRect(0,0,boxWidth, boxHeight);
78 painter->drawText(0,0,boxWidth, boxHeight,Qt::AlignCenter | Qt::TextWordWrap,QString(refBlock->getName()));
79 foreach(InterfaceItem *inter, interfaces) {
80 inter->paint(painter);
84 void BoxItem::moveTo(QPointF dest) {
86 currentPosition = dest;
89 bool BoxItem::isBoxItem() {
93 void BoxItem::updateMinimumSize() {
99 int nbSouth = nbInterfacesByOrientation(Parameters::South);
100 int nbNorth = nbInterfacesByOrientation(Parameters::North);
101 int nbMaxSN = nbNorth;
102 if (nbSouth > nbNorth) nbMaxSN = nbSouth;
103 int nbEast = nbInterfacesByOrientation(Parameters::East);
104 int nbWest = nbInterfacesByOrientation(Parameters::West);
105 int nbMaxEW = nbEast;
106 if (nbWest > nbEast) {
113 foreach(InterfaceItem* iface, interfaces) {
114 ifaceWidth = iface->getNameWidth();
115 ifaceHeight = iface->getNameHeight();
116 if (iface->getOrientation() == Parameters::South) {
117 if (ifaceWidth > maxSouth) maxSouth = ifaceWidth;
119 else if (iface->getOrientation() == Parameters::North) {
120 if (ifaceWidth > maxNorth) maxNorth = ifaceWidth;
122 else if (iface->getOrientation() == Parameters::East) {
123 if (ifaceWidth > maxEast) maxEast = ifaceWidth;
125 else if (iface->getOrientation() == Parameters::West) {
126 if (ifaceWidth > maxWest) maxWest = ifaceWidth;
130 /* NB: the width layout is the following
131 ifaceMargin | maxWest | nameMargin | name | nameMargin | maxEast | ifaceMargin
133 minimumBoxWidth = maxWest+maxEast+nameWidth+2*(ifaceMargin+nameMargin);
134 // if the minimum is not sufficent taking into account N/S interfaces
135 if (minimumBoxWidth < (nbMaxSN*ifaceHeight+ifaceMargin*(nbMaxSN+1))) {
136 minimumBoxWidth = (nbMaxSN*ifaceHeight+ifaceMargin*(nbMaxSN+1));
138 minimumBoxHeight = maxNorth+maxSouth+3*ifaceMargin;
139 if (minimumBoxHeight < (nbMaxEW*ifaceHeight+ifaceMargin*(nbMaxEW+1))) {
140 minimumBoxHeight = (nbMaxEW*ifaceHeight+ifaceMargin*(nbMaxEW+1));
145 /* updateGeometry() :
148 bool BoxItem::updateGeometry(ChangeType type) {
150 currentPosition = pos();
151 //cout << "current pos of block: " << currentPosition.x() << "," << currentPosition.y() << endl;
152 QPointF oldOrigin = originPoint;
153 QSize oldSize(totalWidth,totalHeight);
155 bool boxSizeChanged = false;
157 // whatever the change, the minimum size may have changed
160 if (type == Resize) {
161 // resize implies to move interfaces and to update connections
162 boxSizeChanged = true;
164 else if (type == InterfaceMove) {
165 // if an interface moves, it may change the box size
166 if (boxWidth < minimumBoxWidth) {
167 boxWidth = minimumBoxWidth;
168 boxSizeChanged = true;
170 if (boxHeight < minimumBoxHeight) {
171 boxHeight = minimumBoxHeight;
172 boxSizeChanged = true;
175 if (boxSizeChanged) {
176 updateInterfaceAndConnectionItems();
182 totalWidth = boxWidth;
183 totalHeight = boxHeight;
185 if(isInterfaces(Parameters::East)){
186 totalWidth += params->arrowWidth+params->arrowLineLength;
188 if(isInterfaces(Parameters::West)){
189 totalWidth += params->arrowWidth+params->arrowLineLength;
190 x -= params->arrowWidth+params->arrowLineLength;
192 if(isInterfaces(Parameters::South)){
193 totalHeight += params->arrowWidth+params->arrowLineLength;
195 if(isInterfaces(Parameters::North)){
196 totalHeight += params->arrowWidth+params->arrowLineLength;
197 y -= params->arrowWidth+params->arrowLineLength;
199 QSizeF newSize(totalWidth,totalHeight);
203 if ((boxSizeChanged) || (newSize != oldSize) || (originPoint != oldOrigin)) {
204 prepareGeometryChange();
210 void BoxItem::nameChanged() {
212 QFontMetrics fmId(params->defaultBlockFont);
213 nameWidth = fmId.width(refBlock->getName());
214 nameHeight = fmId.height();
216 if (updateGeometry(InterfaceMove)) {
217 //cout << "must recompute group item geometry" << endl;
218 (getScene()->getGroupItem())->updateShape();
220 // force the update in case of size has not changed
224 void BoxItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
226 if(params->editState == Parameters::EditBlockMove) {
227 QPointF absPos = currentPosition + originPoint;
228 int marginConn = 2*(params->arrowWidth+params->arrowLineLength);
229 int gapX = event->scenePos().x() - cursorPosition.x();
230 int gapY = event->scenePos().y() - cursorPosition.y();
232 //cout << "block abs. pos: " << absPos.x() << "," << absPos.y() << " | ";
233 //cout << "block current. pos: " << currentPosition.x() << "," << currentPosition.y() << " | ";
235 if (absPos.x()+gapX < marginConn) {
236 gapX = marginConn-absPos.x();
238 if (absPos.y()+gapY < marginConn) {
239 gapY = marginConn-absPos.y();
241 //cout << "gap: " << gapX << "," << gapY << endl;
242 QPointF gap(gapX,gapY);
243 currentPosition = currentPosition+gap;
244 setPos(currentPosition);
245 // update all connections from/to this block
246 foreach(ConnectionItem *item, getScene()->getConnectionItems()){
247 if ((item->getFromInterfaceItem()->getOwner() == this) || (item->getToInterfaceItem()->getOwner() == this)) {
251 cursorPosition = event->scenePos();
253 // udpate the groupitem
254 (getScene()->getGroupItem())->updateShape();
256 else if(params->editState == Parameters::EditBlockResize) {
258 int gapX = event->scenePos().x() - cursorPosition.x();
259 int gapY = event->scenePos().y() - cursorPosition.y();
260 //cout << "gap: " << gapX << "," << gapY << endl;
261 switch(currentBorder){
263 if(boxWidth+gapX > minimumBoxWidth){
269 if(boxHeight+gapY > minimumBoxHeight){
274 case CornerSouthEast: {
275 if(boxWidth+gapX > minimumBoxWidth){
278 if(boxHeight+gapY > minimumBoxHeight){
284 cout << "abnormal case while resizing block" << endl;
287 // recompute the geometry of the block and possibly the group item
288 if (updateGeometry(Resize)) {
289 (getScene()->getGroupItem())->updateShape();
292 cursorPosition = event->scenePos();
294 else if(params->editState == Parameters::EditInterfaceMove) {
295 prepareGeometryChange();
296 moveInterfaceItemTo(event->pos());
297 // recompute the geometry of the block
298 if (updateGeometry(InterfaceMove)) {
299 //cout << "must recompute group item geometry" << endl;
300 (getScene()->getGroupItem())->updateShape();
302 // update connection from/to the selected interface
303 foreach(ConnectionItem *item, getScene()->getConnectionItems()){
304 if ((item->getFromInterfaceItem() == currentInterface) || (item->getToInterfaceItem() == currentInterface)) {
311 void BoxItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
313 QPointF pos = event->pos();
317 //QGraphicsItem::mousePressEvent(event);
319 if(event->button() == Qt::RightButton) return;
321 int mode = getScene()->getEditionMode();
323 dispatcher->setCurrentGroupWidget(getScene()->getGroupWidget());
325 if ((mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) {
326 InterfaceItem *inter = getInterfaceItemFromCursor(x,y);
329 if (params->editState == Parameters::EditNoOperation) {
330 getScene()->setSelectedInterface(1,inter);
331 params->setEditState(Parameters::EditStartConnection);
333 else if (params->editState == Parameters::EditStartConnection) {
334 if (inter == getScene()->getSelectedInterface(1)) {
335 params->setEditState(Parameters::EditAbortConnection);
338 getScene()->setSelectedInterface(2,inter);
339 params->setEditState(Parameters::EditCloseConnection);
344 else if (mode == GroupScene::ItemEdition) {
345 //setZValue(zValue()+100);
346 if (params->cursorState == Parameters::CursorOnInterface) {
347 InterfaceItem *inter = getInterfaceItemFromCursor(x,y);
349 if (inter == currentInterface) {
350 params->setEditState(Parameters::EditInterfaceDeselect);
353 setFlag(ItemIsMovable, false);
354 currentInterface = inter;
355 params->setEditState(Parameters::EditInterfaceMove);
359 else if (params->cursorState == Parameters::CursorInBlock) {
360 selected = !selected;
361 params->setEditState(Parameters::EditBlockMove);
362 cursorPosition = event->scenePos();
363 //cout << "cursor current pos. in scene " << cursorPosition.x() << "," << cursorPosition.y() << endl;
366 else if (params->cursorState == Parameters::CursorOnBorder) {
367 setFlag(ItemIsMovable, false);
368 cursorPosition = event->scenePos();
369 params->setEditState(Parameters::EditBlockResize);
374 void BoxItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
376 //setZValue(zValue()-100);
378 int mode = getScene()->getEditionMode();
380 if (mode == GroupScene::AddConnection) {
382 if (params->editState == Parameters::EditStartConnection) {
383 InterfaceItem* iface = getScene()->getSelectedInterface(1);
384 iface->selected = true;
385 update(iface->boundingRect());
387 else if (params->editState == Parameters::EditAbortConnection) {
388 InterfaceItem* iface = getScene()->getSelectedInterface(1);
389 iface->selected = false;
390 update(iface->boundingRect());
391 getScene()->setSelectedInterface(1,NULL);
392 params->setEditState(Parameters::EditNoOperation);
394 else if (params->editState == Parameters::EditCloseConnection) {
395 InterfaceItem* iface1 = getScene()->getSelectedInterface(1);
396 InterfaceItem* iface2 = getScene()->getSelectedInterface(2);
397 bool ok = dispatcher->createConnection(iface1,iface2);
399 iface1->selected = false;
400 update(iface1->boundingRect());
401 iface2->selected = false;
402 update(iface2->boundingRect());
403 getScene()->setSelectedInterface(1,NULL);
404 getScene()->setSelectedInterface(2,NULL);
405 params->setEditState(Parameters::EditNoOperation);
408 //QMessageBox::warning(NULL,"Error","Cannot connect selected interfaces", QMessageBox::Ok);
409 getScene()->setSelectedInterface(2,NULL);
410 params->setEditState(Parameters::EditStartConnection);
414 else if (mode == GroupScene::ItemEdition) {
415 currentInterface = NULL;
416 params->editState = Parameters::EditNoOperation;
417 setFlag(ItemIsMovable);
420 QGraphicsItem::mouseReleaseEvent(event);
423 void BoxItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event) {
425 QPointF pos = event->pos();
428 currentBorder = NoBorder;
429 int mode = getScene()->getEditionMode();
431 if (mode == GroupScene::AddConnection) {
432 InterfaceItem* iface = getInterfaceItemFromCursor(x,y);
434 params->cursorState = Parameters::CursorOnInterface;
435 setCursor(Qt::PointingHandCursor);
438 params->cursorState = Parameters::CursorNowhere;
439 setCursor(Qt::ArrowCursor);
442 else if (mode == GroupScene::ItemEdition) {
446 InterfaceItem* iface = getInterfaceItemFromCursor(x,y);
448 params->cursorState = Parameters::CursorOnInterface;
449 setCursor(Qt::PointingHandCursor);
451 else if ((x>boxWidth-marginE)&&(x<boxWidth)) {
453 params->cursorState = Parameters::CursorOnBorder;
455 if ((y>boxHeight-2*marginS)&&(y<boxHeight)) {
456 currentBorder = CornerSouthEast;
457 setCursor(Qt::SizeFDiagCursor);
460 currentBorder = BorderEast;
461 setCursor(Qt::SizeHorCursor);
464 else if ((y>boxHeight-marginS)&&(y<boxHeight)) {
466 params->cursorState = Parameters::CursorOnBorder;
468 if ((x>boxWidth-2*marginE)&&(x<boxWidth)) {
469 currentBorder = CornerSouthEast;
470 setCursor(Qt::SizeFDiagCursor);
473 currentBorder = BorderSouth;
474 setCursor(Qt::SizeVerCursor);
478 if ((x>0) && (x<boxWidth-marginE) && (y>0) && (y<boxHeight-marginS)) {
479 params->cursorState = Parameters::CursorInBlock;
480 setCursor(Qt::OpenHandCursor);
483 params->cursorState = Parameters::CursorNowhere;
484 setCursor(Qt::ArrowCursor);
488 //QGraphicsItem::hoverMoveEvent(event);
493 void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
496 QAction* titleAction = NULL;
497 QAction* removeAction = NULL;
498 QAction* duplicateAction = NULL;
499 QAction* renameAction = NULL;
500 QAction* connectToGroup = NULL;
501 QAction* showProperties = NULL;
502 QAction* cloneInterface = NULL;
503 QAction* openWindow = NULL;
504 QAction* showRstClkIface = NULL;
505 QAction* showWishboneIface = NULL;
506 QAction* showParameters = NULL;
508 InterfaceItem* ifaceItem = getInterfaceItemFromCursor(event->pos().x(), event->pos().y());
509 // menu for interface
510 if( ifaceItem != NULL){
512 titleAction = menu.addAction("Interface operations");
513 titleAction->setEnabled(false);
517 showProperties = menu.addAction("Show properties");
518 renameAction = menu.addAction("Rename");
520 ConnectedInterface* iface = ifaceItem->refInter;
521 ConnectedInterface* ifaceGroup = NULL;
522 bool canRemove = true;
524 if ((iface->getDirection() == AbstractInterface::Input) && (iface->getConnectedFrom() == NULL)) {
525 connectToGroup = menu.addAction("Connect to group input");
527 else if ((iface->getDirection() == AbstractInterface::Output) && (iface->getConnectionToParentGroup() == NULL)) {
528 connectToGroup = menu.addAction("Connect to group output");
530 else if (iface->getConnectionFromParentGroup() != NULL) {
531 ifaceGroup = iface->getConnectionFromParentGroup();
532 if (ifaceGroup->isConnectedFrom()) {
536 else if (iface->getConnectionToParentGroup() != NULL) {
537 ifaceGroup = iface->getConnectionToParentGroup();
538 if (ifaceGroup->isConnectedTo()) {
543 if (iface->isFunctionalInterface()) {
544 FunctionalInterface* fi = AI_TO_FUN(ifaceItem->refInter);
545 ReferenceInterface* ri = (ReferenceInterface*)(fi->getReference());
546 if(ri->getMultiplicity() == -1 || ri->getMultiplicity() > 1){
547 cloneInterface = menu.addAction("Duplicate");
548 if ((canRemove) && (fi->getInterfaceMultiplicity() > 1)) {
549 removeAction = menu.addAction("Remove");
554 // menu for blocks (group or func)
556 titleAction = menu.addAction("Block operations");
557 titleAction->setEnabled(false);
560 if (refBlock->nbParameters() > 0) {
561 showParameters = menu.addAction("Show parameters");
563 renameAction = menu.addAction("Rename");
565 if(refBlock->isGroupBlock()){
566 openWindow = menu.addAction("Open/show group window");
569 duplicateAction = menu.addAction("Duplicate");
570 showRstClkIface = menu.addAction("Show reset/clock interfaces");
571 showRstClkIface->setCheckable(true);
572 showRstClkIface->setChecked(rstClkVisible);
573 showWishboneIface = menu.addAction("Show wishbone interfaces");
574 showWishboneIface->setCheckable(true);
575 showWishboneIface->setChecked(wishboneVisible);
577 removeAction = menu.addAction("Remove");
580 QAction* selectedAction = NULL;
581 selectedAction = menu.exec(event->screenPos());
583 if(selectedAction == NULL) return ;
585 if (selectedAction == removeAction) {
586 if(ifaceItem != NULL) {
587 dispatcher->removeFunctionalInterface(ifaceItem);
590 dispatcher->removeBoxItem(this);
593 else if (selectedAction == duplicateAction) {
594 dispatcher->duplicateBoxItem(this);
596 else if(selectedAction == renameAction){
597 if(ifaceItem != NULL) {
598 dispatcher->renameInterface(ifaceItem);
601 if (refBlock->isFunctionalBlock()) {
602 dispatcher->renameFunctionalBlock(this);
604 else if (refBlock->isGroupBlock()) {
605 dispatcher->renameGroupBlock(childGroupItem);
609 else if(selectedAction == showProperties){
610 dispatcher->showProperties(ifaceItem);
612 else if (selectedAction == connectToGroup){
613 dispatcher->connectInterToGroup(ifaceItem);
615 else if (selectedAction == cloneInterface){
616 dispatcher->duplicateInterfaceItem(ifaceItem);
618 else if (selectedAction == openWindow){
619 dispatcher->showRaiseWindow(this);
621 else if(selectedAction == showRstClkIface) {
622 dispatcher->showRstClkIface(this);
624 else if(selectedAction == showWishboneIface) {
625 dispatcher->showWishboneIface(this);
627 else if(selectedAction == showParameters) {
628 if (refBlock->isFunctionalBlock()) {
629 FunctionalBlock* fun = AB_TO_FUN(refBlock);
632 new ParametersWindow(refBlock, params, NULL);
636 void BoxItem::loadFunctional(QDomElement funcElement) throw(Exception) {
640 int id = funcElement.attribute("id","none").toInt(&ok);
641 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
643 QString refXml = funcElement.attribute("ref_xml","none");
644 if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));
646 QString refMd5 = funcElement.attribute("ref_md5","none");
647 if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));
649 cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;
651 QString name = funcElement.attribute("name","none");
652 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
654 QStringList positionStr = funcElement.attribute("position","none").split(",");
655 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
656 int posX = positionStr.at(0).toInt(&ok);
657 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
658 int posY = positionStr.at(1).toInt(&ok);
659 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
661 QStringList dimensionStr = funcElement.attribute("dimension","none").split(",");
662 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
663 int dimX = dimensionStr.at(0).toInt(&ok);
664 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
665 int dimY = dimensionStr.at(1).toInt(&ok);
666 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
668 ReferenceBlock *referenceMd5 = NULL;
669 ReferenceBlock *referenceXml = NULL;
670 ReferenceBlock *reference = NULL;
671 if(refMd5 != "none") {
672 referenceMd5 = params->searchBlockByMd5(refMd5);
674 if(refXml != "none"){
675 referenceXml = params->searchBlockByXml(refXml);
677 if ((referenceMd5 == NULL) && (referenceXml == NULL)) {
678 throw(Exception(PROJECTFILE_CORRUPTED));
680 if (referenceMd5 != referenceXml) {
681 throw(Exception(PROJECTFILE_CORRUPTED));
684 reference = referenceMd5;
687 GroupBlock* parentGroupBlock = AB_TO_GRP(((GroupItem *)parentItem())->getRefBlock());
688 FunctionalBlock* functionalBlock = params->getGraph()->createFunctionalBlock(parentGroupBlock, reference);
689 /* NB: addFunctionalBlock creates all interfaces from the reference, which is annoying when
690 reading bif_iface tags. Thus interface are all removed.
692 functionalBlock->setName(name);
693 setRefBlock(functionalBlock);
696 setDimension(dimX,dimY);
700 QDomNodeList blockParamNodes = funcElement.elementsByTagName("bif_parameter");
701 // setting parameters value
702 for(int i=0; i<blockParamNodes.length(); i++){
703 QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();
705 QString name = currentBlockParamNode.attribute("name","none");
706 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
708 QString value = currentBlockParamNode.attribute("value","none");
709 if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));
711 BlockParameter *blockParam = NULL;
712 blockParam = functionalBlock->getParameterFromName(name);
713 if (blockParam == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
714 blockParam->setValue(value);
717 // recreate all (non-control) interfaces because of some may have a multiplicity>1 with several examplars
718 functionalBlock->removeAllInterfaces();
719 QDomNodeList interfaceNodes = funcElement.elementsByTagName("bif_iface");
720 // setting interfaces (user name, and for multiplicity>1 may be create some new ones)
721 for(int i=0; i<interfaceNodes.length(); i++) {
723 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
725 QString name = currentInterfaceNode.attribute("name","none");
726 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
728 QString refName = currentInterfaceNode.attribute("ref_name","none");
729 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
731 ReferenceInterface* refInter = AI_TO_REF(reference->getIfaceFromName(refName));
732 cout << "creating iface from reference named " << qPrintable(refName) << endl;
733 FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);
734 functionalInterface->setName(name);
735 functionalBlock->addInterface(functionalInterface);
737 // searching for control interface
738 QString ctlRefName = refName+"_enb";
739 ReferenceInterface* ctlRefIface = AI_TO_REF(reference->getIfaceFromName(ctlRefName));
741 if (ctlRefIface != NULL) {
742 cout << "found a control iface:" << qPrintable(ctlRefName) << endl;
743 FunctionalInterface *ctlIface = new FunctionalInterface(functionalBlock,ctlRefIface);
744 if (! ctlIface->setAssociatedIface(functionalInterface)) {
745 throw(Exception(PROJECTFILE_CORRUPTED));
747 ctlIface->setName(name+"_enb");
748 functionalBlock->addInterface(ctlIface);
752 // creating InterfaceItem
753 initInterfaceItems();
754 // setting them with saved values
755 for(int i=0; i<interfaceNodes.length(); i++){
757 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
759 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
760 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
762 QString name = currentInterfaceNode.attribute("name","none");
763 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
765 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
766 int orientation = InterfaceItem::getIntOrientation(orientationStr);
767 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
769 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
770 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
772 InterfaceItem *interfaceItem = searchInterfaceItemByName(name);
773 interfaceItem->setId(id);
774 interfaceItem->setOrientation(orientation);
775 interfaceItem->setPositionRatio(position);
777 updateGeometry(Resize);
780 void BoxItem::save(QXmlStreamWriter &writer) {
781 if (refBlock->isFunctionalBlock()) {
782 writer.writeStartElement("bi_functional");
784 writer.writeAttribute("id",QString::number(id));
785 writer.writeAttribute("ref_xml", ((FunctionalBlock*)refBlock)->getReferenceXmlFile());
786 writer.writeAttribute("ref_md5", ((FunctionalBlock*)refBlock)->getReferenceHashMd5());
787 writer.writeAttribute("name",refBlock->getName());
788 QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y())));
789 writer.writeAttribute("position",attrPos);
790 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
791 writer.writeAttribute("dimension",attrDim);
793 writer.writeStartElement("bif_parameters");
794 foreach(BlockParameter *param,refBlock->getParameters()){
795 writer.writeStartElement("bif_parameter");
797 writer.writeAttribute("name",param->getName());
798 writer.writeAttribute("value",param->getValue().toString());
800 writer.writeAttribute("context",param->getStrContext());
801 writer.writeAttribute("type",param->getTypeString());
803 writer.writeEndElement(); //</bif_parameter>
805 writer.writeEndElement(); //</bif_parameters>
807 writer.writeStartElement("bif_ifaces");
808 writer.writeAttribute("count",QString::number(interfaces.length()));
809 foreach(InterfaceItem* inter, interfaces){
810 writer.writeStartElement("bif_iface");
812 writer.writeAttribute("id",QString::number(inter->getId()));
813 writer.writeAttribute("name",inter->getName());
814 writer.writeAttribute("ref_name",inter->refInter->getName());
815 writer.writeAttribute("orientation",inter->getStrOrientation());
816 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
818 writer.writeEndElement(); //</bif_iface>
820 writer.writeEndElement(); //</bif_ifaces>
822 writer.writeEndElement(); //</bi_functional>
825 writer.writeStartElement("bi_group");
827 writer.writeAttribute("id",QString::number(id));
828 writer.writeAttribute("inside_group",QString::number(childGroupItem->getId()));
829 QString attrPos = QString::number(pos().x()).append(",").append(QString::number(pos().y()));
830 writer.writeAttribute("position",attrPos);
831 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
832 writer.writeAttribute("dimension",attrDim);
834 writer.writeStartElement("big_ifaces");
835 writer.writeAttribute("count",QString::number(interfaces.length()));
836 foreach(InterfaceItem* inter, interfaces){
837 writer.writeStartElement("big_iface");
839 writer.writeAttribute("id",QString::number(inter->getId()));
840 writer.writeAttribute("ref_name",inter->refInter->getName());
841 writer.writeAttribute("orientation",inter->getStrOrientation());
842 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
844 writer.writeEndElement(); //</big_iface>
847 writer.writeEndElement(); //</big_ifaces>
848 writer.writeEndElement(); //</bi_group>
852 QDataStream &operator <<(QDataStream &out, BoxItem &b) {
853 out.setVersion(QDataStream::Qt_4_8);
855 QByteArray blockData;
856 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
858 QString refXml = ((FunctionalBlock*)b.refBlock)->getReferenceXmlFile();
859 QByteArray xmlFile = QByteArray(refXml.toStdString().c_str());
863 toWrite << (int)b.x();
864 toWrite << (int)b.y();
865 toWrite << b.boxWidth;
866 toWrite << b.boxHeight;
867 toWrite << b.getInterfaces().length();
869 for(int i=0; i<b.getInterfaces().length(); i++){
870 InterfaceItem *inter = b.getInterfaces().at(i);
871 toWrite << inter->getId();
872 //toWrite << inter->getName();
873 toWrite << inter->getPositionRatio();
874 toWrite << inter->getOrientation();
882 QDataStream &operator >>(QDataStream &in, BoxItem &b) {
884 in.setVersion(QDataStream::Qt_4_8);
899 cout << "nbInter:" << nbInter << endl;
900 for(int i=0; i<nbInter; i++){
903 double positionRatio;
906 InterfaceItem *inter = b.getInterfaces().at(i);
913 inter->setPositionRatio(positionRatio);
914 inter->setOrientation(orientation);
915 inter->updatePosition();