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 resetInterfacesPosition();
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 updateInterfacesAndConnections();
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 moveInterfaceTo(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 = getInterfaceFromCursor(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 = getInterfaceFromCursor(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->createConnectionItem(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 = getInterfaceFromCursor(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 = getInterfaceFromCursor(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* disconnectFromGroup = NULL;
502 QAction* showProperties = NULL;
503 QAction* cloneInterface = NULL;
504 QAction* openWindow = NULL;
505 QAction* showRstClkIface = NULL;
506 QAction* showWishboneIface = NULL;
507 QAction* showParameters = NULL;
509 InterfaceItem* ifaceItem = getInterfaceFromCursor(event->pos().x(), event->pos().y());
510 // menu for interface
511 if( ifaceItem != NULL){
513 titleAction = menu.addAction("Interface operations");
514 titleAction->setEnabled(false);
518 showProperties = menu.addAction("Show properties");
519 renameAction = menu.addAction("Rename");
521 ConnectedInterface* iface = ifaceItem->refInter;
522 ConnectedInterface* ifaceGroup = NULL;
523 bool canRemove = true;
526 if ((iface->getDirection() == AbstractInterface::Input) && (iface->getConnectedFrom() == NULL)) {
527 connectToGroup = menu.addAction("Connect to group input");
529 else if ((iface->getDirection() == AbstractInterface::Output) && (iface->getConnectionToParentGroup() == NULL)) {
530 connectToGroup = menu.addAction("Connect to group output");
532 else if (iface->getConnectionFromParentGroup() != NULL) {
533 ifaceGroup = iface->getConnectionFromParentGroup();
534 //if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
535 if (!ifaceGroup->isConnectedFrom()) {
536 disconnectFromGroup = menu.addAction("Disconnect from group");
542 else if (iface->getConnectionToParentGroup() != NULL) {
543 ifaceGroup = iface->getConnectionToParentGroup();
544 //if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
545 if (!ifaceGroup->isConnectedTo()) {
546 disconnectFromGroup = menu.addAction("Disconnect from group");
553 if (iface->isFunctionalInterface()) {
554 FunctionalInterface* fi = AI_TO_FUN(ifaceItem->refInter);
555 ReferenceInterface* ri = (ReferenceInterface*)(fi->getReference());
556 if(ri->getMultiplicity() == -1 || ri->getMultiplicity() > 1){
557 cloneInterface = menu.addAction("Duplicate");
558 if ((canRemove) && (fi->getInterfaceMultiplicity() > 1)) {
559 removeAction = menu.addAction("Remove");
564 // menu for blocks (group or func)
566 titleAction = menu.addAction("Block operations");
567 titleAction->setEnabled(false);
570 if (refBlock->nbParameters() > 0) {
571 showParameters = menu.addAction("Show parameters");
573 renameAction = menu.addAction("Rename");
575 if(refBlock->isGroupBlock()){
576 openWindow = menu.addAction("Open/show group window");
579 duplicateAction = menu.addAction("Duplicate");
580 showRstClkIface = menu.addAction("Show reset/clock interfaces");
581 showRstClkIface->setCheckable(true);
582 showRstClkIface->setChecked(rstClkVisible);
583 showWishboneIface = menu.addAction("Show wishbone interfaces");
584 showWishboneIface->setCheckable(true);
585 showWishboneIface->setChecked(wishboneVisible);
587 removeAction = menu.addAction("Remove");
590 QAction* selectedAction = NULL;
591 selectedAction = menu.exec(event->screenPos());
593 if(selectedAction == NULL) return ;
595 if (selectedAction == removeAction) {
596 if(ifaceItem != NULL) {
597 dispatcher->removeFunctionalInterface(ifaceItem);
600 dispatcher->removeBoxItem(this);
603 else if (selectedAction == duplicateAction) {
604 dispatcher->duplicateBoxItem(this);
606 else if(selectedAction == renameAction){
607 if(ifaceItem != NULL) {
608 dispatcher->renameInterface(ifaceItem);
611 if (refBlock->isFunctionalBlock()) {
612 dispatcher->renameFunctionalBlock(this);
614 else if (refBlock->isGroupBlock()) {
615 dispatcher->renameGroupBlock(childGroupItem);
619 else if(selectedAction == showProperties){
620 dispatcher->showProperties(ifaceItem);
622 else if (selectedAction == connectToGroup){
623 dispatcher->connectInterToGroup(ifaceItem);
625 else if (selectedAction == disconnectFromGroup) {
626 dispatcher->disconnectInterFromGroup(ifaceItem);
628 else if (selectedAction == cloneInterface){
629 dispatcher->duplicateInterfaceItem(ifaceItem);
631 else if (selectedAction == openWindow){
632 dispatcher->showRaiseWindow(this);
634 else if(selectedAction == showRstClkIface) {
635 dispatcher->showRstClkIface(this);
637 else if(selectedAction == showWishboneIface) {
638 dispatcher->showWishboneIface(this);
640 else if(selectedAction == showParameters){
641 new ParametersWindow(refBlock, params, NULL);
645 void BoxItem::loadFunctional(QDomElement funcElement) throw(Exception) {
649 int id = funcElement.attribute("id","none").toInt(&ok);
650 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
652 QString refXml = funcElement.attribute("ref_xml","none");
653 if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));
655 QString refMd5 = funcElement.attribute("ref_md5","none");
656 if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));
658 cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;
660 QString name = funcElement.attribute("name","none");
661 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
663 QStringList positionStr = funcElement.attribute("position","none").split(",");
664 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
665 int posX = positionStr.at(0).toInt(&ok);
666 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
667 int posY = positionStr.at(1).toInt(&ok);
668 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
670 QStringList dimensionStr = funcElement.attribute("dimension","none").split(",");
671 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
672 int dimX = dimensionStr.at(0).toInt(&ok);
673 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
674 int dimY = dimensionStr.at(1).toInt(&ok);
675 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
677 ReferenceBlock *referenceMd5 = NULL;
678 ReferenceBlock *referenceXml = NULL;
679 ReferenceBlock *reference = NULL;
680 if(refMd5 != "none") {
681 referenceMd5 = params->searchBlockByMd5(refMd5);
683 if(refXml != "none"){
684 referenceXml = params->searchBlockByXml(refXml);
686 if ((referenceMd5 == NULL) && (referenceXml == NULL)) {
687 throw(Exception(PROJECTFILE_CORRUPTED));
689 if (referenceMd5 != referenceXml) {
690 throw(Exception(PROJECTFILE_CORRUPTED));
693 reference = referenceMd5;
696 GroupBlock* parentGroupBlock = AB_TO_GRP(((GroupItem *)parentItem())->getRefBlock());
697 FunctionalBlock* functionalBlock = params->getGraph()->createFunctionalBlock(parentGroupBlock, reference);
698 /* NB: addFunctionalBlock creates all interfaces from the reference, which is annoying when
699 reading bif_iface tags. Thus interface are all removed.
701 functionalBlock->setName(name);
702 setRefBlock(functionalBlock);
705 setDimension(dimX,dimY);
709 QDomNodeList blockParamNodes = funcElement.elementsByTagName("bif_parameter");
710 // setting parameters value
711 for(int i=0; i<blockParamNodes.length(); i++){
712 QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();
714 QString name = currentBlockParamNode.attribute("name","none");
715 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
717 QString value = currentBlockParamNode.attribute("value","none");
718 if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));
720 BlockParameter *blockParam = NULL;
721 blockParam = functionalBlock->getParameterFromName(name);
722 if (blockParam == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
723 blockParam->setValue(value);
726 // recreate all (non-control) interfaces because of some may have a multiplicity>1 with several examplars
727 functionalBlock->removeAllInterfaces();
728 QDomNodeList interfaceNodes = funcElement.elementsByTagName("bif_iface");
729 // setting interfaces (user name, and for multiplicity>1 may be create some new ones)
730 for(int i=0; i<interfaceNodes.length(); i++) {
732 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
734 QString name = currentInterfaceNode.attribute("name","none");
735 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
737 QString refName = currentInterfaceNode.attribute("ref_name","none");
738 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
740 ReferenceInterface* refInter = AI_TO_REF(reference->getIfaceFromName(refName));
741 cout << "creating iface from reference named " << qPrintable(refName) << endl;
742 FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);
743 functionalInterface->setName(name);
744 functionalBlock->addInterface(functionalInterface);
746 // searching for control interface
747 QString ctlRefName = refName+"_enb";
748 ReferenceInterface* ctlRefIface = AI_TO_REF(reference->getIfaceFromName(ctlRefName));
750 if (ctlRefIface != NULL) {
751 cout << "found a control iface:" << qPrintable(ctlRefName) << endl;
752 FunctionalInterface *ctlIface = new FunctionalInterface(functionalBlock,ctlRefIface);
753 if (! ctlIface->setAssociatedIface(functionalInterface)) {
754 throw(Exception(PROJECTFILE_CORRUPTED));
756 ctlIface->setName(name+"_enb");
757 functionalBlock->addInterface(ctlIface);
761 // creating InterfaceItem
763 // setting them with saved values
764 for(int i=0; i<interfaceNodes.length(); i++){
766 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
768 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
769 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
771 QString name = currentInterfaceNode.attribute("name","none");
772 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
774 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
775 int orientation = InterfaceItem::getIntOrientation(orientationStr);
776 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
778 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
779 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
781 InterfaceItem *interfaceItem = searchInterfaceByName(name);
782 interfaceItem->setId(id);
783 interfaceItem->setOrientation(orientation);
784 interfaceItem->setPositionRatio(position);
786 updateGeometry(Resize);
789 void BoxItem::save(QXmlStreamWriter &writer) {
790 if (refBlock->isFunctionalBlock()) {
791 writer.writeStartElement("bi_functional");
793 writer.writeAttribute("id",QString::number(id));
794 writer.writeAttribute("ref_xml", ((FunctionalBlock*)refBlock)->getReferenceXmlFile());
795 writer.writeAttribute("ref_md5", ((FunctionalBlock*)refBlock)->getReferenceHashMd5());
796 writer.writeAttribute("name",refBlock->getName());
797 QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y())));
798 writer.writeAttribute("position",attrPos);
799 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
800 writer.writeAttribute("dimension",attrDim);
802 writer.writeStartElement("bif_parameters");
803 foreach(BlockParameter *param,refBlock->getParameters()){
804 writer.writeStartElement("bif_parameter");
806 writer.writeAttribute("name",param->getName());
807 writer.writeAttribute("value",param->getValue().toString());
809 writer.writeAttribute("context",param->getStrContext());
810 writer.writeAttribute("type",param->getTypeString());
812 writer.writeEndElement(); //</bif_parameter>
814 writer.writeEndElement(); //</bif_parameters>
816 writer.writeStartElement("bif_ifaces");
817 writer.writeAttribute("count",QString::number(interfaces.length()));
818 foreach(InterfaceItem* inter, interfaces){
819 writer.writeStartElement("bif_iface");
821 writer.writeAttribute("id",QString::number(inter->getId()));
822 writer.writeAttribute("name",inter->getName());
823 writer.writeAttribute("ref_name",inter->refInter->getName());
824 writer.writeAttribute("orientation",inter->getStrOrientation());
825 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
827 writer.writeEndElement(); //</bif_iface>
829 writer.writeEndElement(); //</bif_ifaces>
831 writer.writeEndElement(); //</bi_functional>
834 writer.writeStartElement("bi_group");
836 writer.writeAttribute("id",QString::number(id));
837 writer.writeAttribute("inside_group",QString::number(childGroupItem->getId()));
838 QString attrPos = QString::number(pos().x()).append(",").append(QString::number(pos().y()));
839 writer.writeAttribute("position",attrPos);
840 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
841 writer.writeAttribute("dimension",attrDim);
843 writer.writeStartElement("big_ifaces");
844 writer.writeAttribute("count",QString::number(interfaces.length()));
845 foreach(InterfaceItem* inter, interfaces){
846 writer.writeStartElement("big_iface");
848 writer.writeAttribute("id",QString::number(inter->getId()));
849 writer.writeAttribute("ref_name",inter->refInter->getName());
850 writer.writeAttribute("orientation",inter->getStrOrientation());
851 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
853 writer.writeEndElement(); //</big_iface>
856 writer.writeEndElement(); //</big_ifaces>
857 writer.writeEndElement(); //</bi_group>
861 QDataStream &operator <<(QDataStream &out, BoxItem &b) {
862 out.setVersion(QDataStream::Qt_4_8);
864 QByteArray blockData;
865 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
867 QString refXml = ((FunctionalBlock*)b.refBlock)->getReferenceXmlFile();
868 QByteArray xmlFile = QByteArray(refXml.toStdString().c_str());
872 toWrite << (int)b.x();
873 toWrite << (int)b.y();
874 toWrite << b.boxWidth;
875 toWrite << b.boxHeight;
876 toWrite << b.getInterfaces().length();
878 for(int i=0; i<b.getInterfaces().length(); i++){
879 InterfaceItem *inter = b.getInterfaces().at(i);
880 toWrite << inter->getId();
881 //toWrite << inter->getName();
882 toWrite << inter->getPositionRatio();
883 toWrite << inter->getOrientation();
891 QDataStream &operator >>(QDataStream &in, BoxItem &b) {
893 in.setVersion(QDataStream::Qt_4_8);
908 cout << "nbInter:" << nbInter << endl;
909 for(int i=0; i<nbInter; i++){
912 double positionRatio;
915 InterfaceItem *inter = b.getInterfaces().at(i);
922 inter->setPositionRatio(positionRatio);
923 inter->setOrientation(orientation);
924 inter->updatePosition();