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 cout << "abnormal case while resizing block" << endl;
290 cout << "abnormal case while resizing block" << endl;
293 cout << "abnormal case while resizing block" << endl;
296 // recompute the geometry of the block and possibly the group item
297 if (updateGeometry(Resize)) {
298 (getScene()->getGroupItem())->updateShape();
301 cursorPosition = event->scenePos();
303 else if(params->editState == Parameters::EditInterfaceMove) {
304 prepareGeometryChange();
305 moveInterfaceItemTo(event->pos());
306 // recompute the geometry of the block
307 if (updateGeometry(InterfaceMove)) {
308 //cout << "must recompute group item geometry" << endl;
309 (getScene()->getGroupItem())->updateShape();
311 // update connection from/to the selected interface
312 foreach(ConnectionItem *item, getScene()->getConnectionItems()){
313 if ((item->getFromInterfaceItem() == currentInterface) || (item->getToInterfaceItem() == currentInterface)) {
320 void BoxItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
322 QPointF pos = event->pos();
326 //QGraphicsItem::mousePressEvent(event);
328 if(event->button() == Qt::RightButton) return;
330 int mode = getScene()->getEditionMode();
332 dispatcher->setCurrentGroupWidget(getScene()->getGroupWidget());
334 if ((mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) {
335 InterfaceItem *inter = getInterfaceItemFromCursor(x,y);
338 if (params->editState == Parameters::EditNoOperation) {
339 getScene()->setSelectedInterface(1,inter);
340 params->setEditState(Parameters::EditStartConnection);
342 else if (params->editState == Parameters::EditStartConnection) {
343 if (inter == getScene()->getSelectedInterface(1)) {
344 params->setEditState(Parameters::EditAbortConnection);
347 getScene()->setSelectedInterface(2,inter);
348 params->setEditState(Parameters::EditCloseConnection);
353 else if (mode == GroupScene::ItemEdition) {
354 //setZValue(zValue()+100);
355 if (params->cursorState == Parameters::CursorOnInterface) {
356 InterfaceItem *inter = getInterfaceItemFromCursor(x,y);
358 if (inter == currentInterface) {
359 params->setEditState(Parameters::EditInterfaceDeselect);
362 setFlag(ItemIsMovable, false);
363 currentInterface = inter;
364 params->setEditState(Parameters::EditInterfaceMove);
368 else if (params->cursorState == Parameters::CursorInBlock) {
369 selected = !selected;
370 params->setEditState(Parameters::EditBlockMove);
371 cursorPosition = event->scenePos();
372 //cout << "cursor current pos. in scene " << cursorPosition.x() << "," << cursorPosition.y() << endl;
375 else if (params->cursorState == Parameters::CursorOnBorder) {
376 setFlag(ItemIsMovable, false);
377 cursorPosition = event->scenePos();
378 params->setEditState(Parameters::EditBlockResize);
383 void BoxItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
385 //setZValue(zValue()-100);
387 int mode = getScene()->getEditionMode();
389 if (mode == GroupScene::AddConnection) {
391 if (params->editState == Parameters::EditStartConnection) {
392 InterfaceItem* iface = getScene()->getSelectedInterface(1);
393 iface->selected = true;
394 update(iface->boundingRect());
396 else if (params->editState == Parameters::EditAbortConnection) {
397 InterfaceItem* iface = getScene()->getSelectedInterface(1);
398 iface->selected = false;
399 update(iface->boundingRect());
400 getScene()->setSelectedInterface(1,NULL);
401 params->setEditState(Parameters::EditNoOperation);
403 else if (params->editState == Parameters::EditCloseConnection) {
404 InterfaceItem* iface1 = getScene()->getSelectedInterface(1);
405 InterfaceItem* iface2 = getScene()->getSelectedInterface(2);
406 bool ok = dispatcher->createConnection(iface1,iface2);
408 iface1->selected = false;
409 update(iface1->boundingRect());
410 iface2->selected = false;
411 update(iface2->boundingRect());
412 getScene()->setSelectedInterface(1,NULL);
413 getScene()->setSelectedInterface(2,NULL);
414 params->setEditState(Parameters::EditNoOperation);
417 //QMessageBox::warning(NULL,"Error","Cannot connect selected interfaces", QMessageBox::Ok);
418 getScene()->setSelectedInterface(2,NULL);
419 params->setEditState(Parameters::EditStartConnection);
423 else if (mode == GroupScene::ItemEdition) {
424 currentInterface = NULL;
425 params->editState = Parameters::EditNoOperation;
426 setFlag(ItemIsMovable);
429 QGraphicsItem::mouseReleaseEvent(event);
432 void BoxItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event) {
434 QPointF pos = event->pos();
437 currentBorder = NoBorder;
438 int mode = getScene()->getEditionMode();
440 if (mode == GroupScene::AddConnection) {
441 InterfaceItem* iface = getInterfaceItemFromCursor(x,y);
443 params->cursorState = Parameters::CursorOnInterface;
444 setCursor(Qt::PointingHandCursor);
447 params->cursorState = Parameters::CursorNowhere;
448 setCursor(Qt::ArrowCursor);
451 else if (mode == GroupScene::ItemEdition) {
455 InterfaceItem* iface = getInterfaceItemFromCursor(x,y);
457 params->cursorState = Parameters::CursorOnInterface;
458 setCursor(Qt::PointingHandCursor);
460 else if ((x>boxWidth-marginE)&&(x<boxWidth)) {
462 params->cursorState = Parameters::CursorOnBorder;
464 if ((y>boxHeight-2*marginS)&&(y<boxHeight)) {
465 currentBorder = CornerSouthEast;
466 setCursor(Qt::SizeFDiagCursor);
469 currentBorder = BorderEast;
470 setCursor(Qt::SizeHorCursor);
473 else if ((y>boxHeight-marginS)&&(y<boxHeight)) {
475 params->cursorState = Parameters::CursorOnBorder;
477 if ((x>boxWidth-2*marginE)&&(x<boxWidth)) {
478 currentBorder = CornerSouthEast;
479 setCursor(Qt::SizeFDiagCursor);
482 currentBorder = BorderSouth;
483 setCursor(Qt::SizeVerCursor);
487 if ((x>0) && (x<boxWidth-marginE) && (y>0) && (y<boxHeight-marginS)) {
488 params->cursorState = Parameters::CursorInBlock;
489 setCursor(Qt::OpenHandCursor);
492 params->cursorState = Parameters::CursorNowhere;
493 setCursor(Qt::ArrowCursor);
497 //QGraphicsItem::hoverMoveEvent(event);
502 void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
505 QAction* titleAction = NULL;
506 QAction* removeAction = NULL;
507 QAction* duplicateAction = NULL;
508 QAction* renameAction = NULL;
509 QAction* connectToGroup = NULL;
510 QAction* showProperties = NULL;
511 QAction* cloneInterface = NULL;
512 QAction* openWindow = NULL;
513 QAction* showRstClkIface = NULL;
514 QAction* showWishboneIface = NULL;
515 QAction* showParameters = NULL;
516 QAction* showPatterns = NULL;
517 QAction* showModifier = NULL;
518 QAction* removeModifier = NULL;
519 QAction* generateVHDL = NULL;
521 InterfaceItem* ifaceItem = getInterfaceItemFromCursor(event->pos().x(), event->pos().y());
522 // menu for interface
523 if( ifaceItem != NULL){
525 titleAction = menu.addAction("Interface operations");
526 titleAction->setEnabled(false);
530 showProperties = menu.addAction("Show properties");
531 renameAction = menu.addAction("Rename");
533 ConnectedInterface* iface = ifaceItem->refInter;
534 ConnectedInterface* ifaceGroup = NULL;
535 bool canRemove = true;
537 if ((iface->getDirection() == AbstractInterface::Input) && (iface->getConnectedFrom() == NULL)) {
538 connectToGroup = menu.addAction("Connect to group input");
540 else if ((iface->getDirection() == AbstractInterface::Output) && (iface->getConnectionToParentGroup() == NULL)) {
541 connectToGroup = menu.addAction("Connect to group output");
543 else if (iface->getConnectionFromParentGroup() != NULL) {
544 ifaceGroup = iface->getConnectionFromParentGroup();
545 if (ifaceGroup->isConnectedFrom()) {
549 else if (iface->getConnectionToParentGroup() != NULL) {
550 ifaceGroup = iface->getConnectionToParentGroup();
551 if (ifaceGroup->isConnectedTo()) {
556 if (iface->isFunctionalInterface()) {
557 FunctionalInterface* fi = AI_TO_FUN(ifaceItem->refInter);
558 ReferenceInterface* ri = (ReferenceInterface*)(fi->getReference());
559 if(ri->getMultiplicity() == -1 || ri->getMultiplicity() > 1){
560 cloneInterface = menu.addAction("Duplicate");
561 if ((canRemove) && (fi->getInterfaceMultiplicity() > 1)) {
562 removeAction = menu.addAction("Remove");
566 if (iface->getAssociatedIface() != NULL) {
567 if (iface->getDirection() == AbstractInterface::Output) {
568 showPatterns = menu.addAction("Show output pattern");
570 else if (iface->getDirection() == AbstractInterface::Input) {
571 showPatterns = menu.addAction("Show input pattern");
575 if (iface->getInputModifier() != NULL) {
576 removeModifier = menu.addAction("Remove input modifier");
578 if (iface->getInputModifier() != NULL) {
579 showModifier = menu.addAction("Show input modifier parameters");
583 // menu for blocks (group or func)
585 titleAction = menu.addAction("Block operations");
586 titleAction->setEnabled(false);
589 if (refBlock->nbParameters() > 0) {
590 showParameters = menu.addAction("Show parameters");
592 renameAction = menu.addAction("Rename");
594 if(refBlock->isGroupBlock()){
595 openWindow = menu.addAction("Open/show group window");
598 duplicateAction = menu.addAction("Duplicate");
599 showRstClkIface = menu.addAction("Show reset/clock interfaces");
600 showRstClkIface->setCheckable(true);
601 showRstClkIface->setChecked(rstClkVisible);
602 showWishboneIface = menu.addAction("Show wishbone interfaces");
603 showWishboneIface->setCheckable(true);
604 showWishboneIface->setChecked(wishboneVisible);
606 removeAction = menu.addAction("Remove");
607 generateVHDL = menu.addAction("Generate VHDL");
610 QAction* selectedAction = NULL;
611 selectedAction = menu.exec(event->screenPos());
613 if(selectedAction == NULL) return ;
615 if (selectedAction == removeAction) {
616 if(ifaceItem != NULL) {
617 dispatcher->removeFunctionalInterface(ifaceItem);
620 dispatcher->removeBoxItem(this);
623 else if (selectedAction == duplicateAction) {
624 dispatcher->duplicateBoxItem(this);
626 else if(selectedAction == renameAction){
627 if(ifaceItem != NULL) {
628 dispatcher->renameInterface(ifaceItem);
631 if (refBlock->isFunctionalBlock()) {
632 dispatcher->renameFunctionalBlock(this);
634 else if (refBlock->isGroupBlock()) {
635 dispatcher->renameGroupBlock(childGroupItem);
639 else if(selectedAction == showProperties){
640 dispatcher->showProperties(ifaceItem);
642 else if (selectedAction == connectToGroup){
643 dispatcher->connectInterToGroup(ifaceItem);
645 else if (selectedAction == cloneInterface){
646 dispatcher->duplicateInterfaceItem(ifaceItem);
648 else if (selectedAction == openWindow){
649 dispatcher->showRaiseWindow(this);
651 else if(selectedAction == showRstClkIface) {
652 dispatcher->showRstClkIface(this);
654 else if(selectedAction == showWishboneIface) {
655 dispatcher->showWishboneIface(this);
657 else if(selectedAction == showParameters) {
658 new ParametersWindow(refBlock, params, NULL);
660 else if(selectedAction == showPatterns) {
661 dispatcher->showPatterns(ifaceItem);
663 else if(selectedAction == removeModifier) {
664 dispatcher->removeModifier(ifaceItem);
666 else if(selectedAction == showModifier) {
667 dispatcher->showModifier(ifaceItem);
669 else if(selectedAction == generateVHDL) {
670 dispatcher->generateBlockVHDL(this);
675 void BoxItem::loadFunctional(QDomElement funcElement) throw(Exception) {
679 int id = funcElement.attribute("id","none").toInt(&ok);
680 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
682 QString refXml = funcElement.attribute("ref_xml","none");
683 if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));
685 QString refMd5 = funcElement.attribute("ref_md5","none");
686 if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));
688 cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;
690 QString name = funcElement.attribute("name","none");
691 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
693 QStringList positionStr = funcElement.attribute("position","none").split(",");
694 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
695 int posX = positionStr.at(0).toInt(&ok);
696 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
697 int posY = positionStr.at(1).toInt(&ok);
698 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
700 QStringList dimensionStr = funcElement.attribute("dimension","none").split(",");
701 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
702 int dimX = dimensionStr.at(0).toInt(&ok);
703 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
704 int dimY = dimensionStr.at(1).toInt(&ok);
705 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
707 ReferenceBlock *referenceMd5 = NULL;
708 ReferenceBlock *referenceXml = NULL;
709 ReferenceBlock *reference = NULL;
710 if(refMd5 != "none") {
711 referenceMd5 = params->searchBlockByMd5(refMd5);
713 if(refXml != "none"){
714 referenceXml = params->searchBlockByXml(refXml);
716 if ((referenceMd5 == NULL) && (referenceXml == NULL)) {
717 throw(Exception(PROJECTFILE_CORRUPTED));
719 if (referenceMd5 != referenceXml) {
720 throw(Exception(PROJECTFILE_CORRUPTED));
723 reference = referenceMd5;
726 GroupBlock* parentGroupBlock = AB_TO_GRP(((GroupItem *)parentItem())->getRefBlock());
727 FunctionalBlock* functionalBlock = params->getGraph()->createFunctionalBlock(parentGroupBlock, reference);
728 /* NB: addFunctionalBlock creates all interfaces from the reference, which is annoying when
729 reading bif_iface tags. Thus interface are all removed.
731 functionalBlock->setName(name);
732 setRefBlock(functionalBlock);
733 params->blockToItem.insert(functionalBlock,this);
736 setDimension(dimX,dimY);
740 QDomNodeList blockParamNodes = funcElement.elementsByTagName("bif_parameter");
741 // setting parameters value
742 for(int i=0; i<blockParamNodes.length(); i++){
743 QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();
745 QString name = currentBlockParamNode.attribute("name","none");
746 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
748 QString value = currentBlockParamNode.attribute("value","none");
749 if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));
751 BlockParameter *blockParam = NULL;
752 blockParam = functionalBlock->getParameterFromName(name);
753 if (blockParam == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
754 blockParam->setValue(value);
757 // recreate all (non-control) interfaces because of some may have a multiplicity>1 with several examplars
758 functionalBlock->removeAllInterfaces();
759 QDomNodeList interfaceNodes = funcElement.elementsByTagName("bif_iface");
760 // setting interfaces (user name, and for multiplicity>1 may be create some new ones)
761 for(int i=0; i<interfaceNodes.length(); i++) {
763 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
765 QString name = currentInterfaceNode.attribute("name","none");
766 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
768 QString refName = currentInterfaceNode.attribute("ref_name","none");
769 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
771 ReferenceInterface* refInter = AI_TO_REF(reference->getIfaceFromName(refName));
772 cout << "creating iface from reference named " << qPrintable(refName) << endl;
773 FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);
774 functionalInterface->setName(name);
775 functionalBlock->addInterface(functionalInterface);
777 // searching for control interface
778 QString ctlRefName = refName+"_enb";
779 ReferenceInterface* ctlRefIface = AI_TO_REF(reference->getIfaceFromName(ctlRefName));
781 if (ctlRefIface != NULL) {
782 cout << "found a control iface:" << qPrintable(ctlRefName) << endl;
783 FunctionalInterface *ctlIface = new FunctionalInterface(functionalBlock,ctlRefIface);
784 if (! ctlIface->setAssociatedIface(functionalInterface)) {
785 throw(Exception(PROJECTFILE_CORRUPTED));
787 ctlIface->setName(name+"_enb");
788 functionalBlock->addInterface(ctlIface);
792 // creating InterfaceItem
793 initInterfaceItems();
794 // setting them with saved values
795 for(int i=0; i<interfaceNodes.length(); i++){
797 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
799 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
800 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
802 QString name = currentInterfaceNode.attribute("name","none");
803 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
805 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
806 int orientation = InterfaceItem::getIntOrientation(orientationStr);
807 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
809 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
810 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
812 InterfaceItem *interfaceItem = searchInterfaceItemByName(name);
813 interfaceItem->setId(id);
814 interfaceItem->setOrientation(orientation);
815 interfaceItem->setPositionRatio(position);
817 updateGeometry(Resize);
820 void BoxItem::save(QXmlStreamWriter &writer) {
821 if (refBlock->isFunctionalBlock()) {
822 writer.writeStartElement("bi_functional");
824 writer.writeAttribute("id",QString::number(id));
825 writer.writeAttribute("ref_xml", ((FunctionalBlock*)refBlock)->getReferenceXmlFile());
826 writer.writeAttribute("ref_md5", ((FunctionalBlock*)refBlock)->getReferenceHashMd5());
827 writer.writeAttribute("name",refBlock->getName());
828 QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y())));
829 writer.writeAttribute("position",attrPos);
830 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
831 writer.writeAttribute("dimension",attrDim);
833 writer.writeStartElement("bif_parameters");
834 foreach(BlockParameter *param,refBlock->getParameters()){
835 writer.writeStartElement("bif_parameter");
837 writer.writeAttribute("name",param->getName());
838 writer.writeAttribute("value",param->getValue().toString());
840 writer.writeAttribute("context",param->getStrContext());
841 writer.writeAttribute("type",param->getTypeString());
843 writer.writeEndElement(); //</bif_parameter>
845 writer.writeEndElement(); //</bif_parameters>
847 writer.writeStartElement("bif_ifaces");
848 writer.writeAttribute("count",QString::number(interfaces.length()));
849 foreach(InterfaceItem* inter, interfaces){
850 writer.writeStartElement("bif_iface");
852 writer.writeAttribute("id",QString::number(inter->getId()));
853 writer.writeAttribute("name",inter->getName());
854 writer.writeAttribute("ref_name",inter->refInter->getName());
855 writer.writeAttribute("orientation",inter->getStrOrientation());
856 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
858 writer.writeEndElement(); //</bif_iface>
860 writer.writeEndElement(); //</bif_ifaces>
862 writer.writeEndElement(); //</bi_functional>
865 writer.writeStartElement("bi_group");
867 writer.writeAttribute("id",QString::number(id));
868 writer.writeAttribute("inside_group",QString::number(childGroupItem->getId()));
869 QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y())));
870 writer.writeAttribute("position",attrPos);
871 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
872 writer.writeAttribute("dimension",attrDim);
874 writer.writeStartElement("big_ifaces");
875 writer.writeAttribute("count",QString::number(interfaces.length()));
876 foreach(InterfaceItem* inter, interfaces){
877 writer.writeStartElement("big_iface");
879 writer.writeAttribute("id",QString::number(inter->getId()));
880 writer.writeAttribute("ref_name",inter->refInter->getName());
881 writer.writeAttribute("orientation",inter->getStrOrientation());
882 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
884 writer.writeEndElement(); //</big_iface>
887 writer.writeEndElement(); //</big_ifaces>
888 writer.writeEndElement(); //</bi_group>
892 QDataStream &operator <<(QDataStream &out, BoxItem &b) {
893 out.setVersion(QDataStream::Qt_4_8);
895 QByteArray blockData;
896 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
898 QString refXml = ((FunctionalBlock*)b.refBlock)->getReferenceXmlFile();
899 QByteArray xmlFile = QByteArray(refXml.toStdString().c_str());
903 toWrite << (int)b.x();
904 toWrite << (int)b.y();
905 toWrite << b.boxWidth;
906 toWrite << b.boxHeight;
907 toWrite << b.getInterfaces().length();
909 for(int i=0; i<b.getInterfaces().length(); i++){
910 InterfaceItem *inter = b.getInterfaces().at(i);
911 toWrite << inter->getId();
912 //toWrite << inter->getName();
913 toWrite << inter->getPositionRatio();
914 toWrite << inter->getOrientation();
922 QDataStream &operator >>(QDataStream &in, BoxItem &b) {
924 in.setVersion(QDataStream::Qt_4_8);
939 cout << "nbInter:" << nbInter << endl;
940 for(int i=0; i<nbInter; i++){
943 double positionRatio;
946 InterfaceItem *inter = b.getInterfaces().at(i);
953 inter->setPositionRatio(positionRatio);
954 inter->setOrientation(orientation);
955 inter->updatePosition();