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;
507 QAction* showPatterns = NULL;
509 InterfaceItem* ifaceItem = getInterfaceItemFromCursor(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;
525 if ((iface->getDirection() == AbstractInterface::Input) && (iface->getConnectedFrom() == NULL)) {
526 connectToGroup = menu.addAction("Connect to group input");
528 else if ((iface->getDirection() == AbstractInterface::Output) && (iface->getConnectionToParentGroup() == NULL)) {
529 connectToGroup = menu.addAction("Connect to group output");
531 else if (iface->getConnectionFromParentGroup() != NULL) {
532 ifaceGroup = iface->getConnectionFromParentGroup();
533 if (ifaceGroup->isConnectedFrom()) {
537 else if (iface->getConnectionToParentGroup() != NULL) {
538 ifaceGroup = iface->getConnectionToParentGroup();
539 if (ifaceGroup->isConnectedTo()) {
544 if (iface->isFunctionalInterface()) {
545 FunctionalInterface* fi = AI_TO_FUN(ifaceItem->refInter);
546 ReferenceInterface* ri = (ReferenceInterface*)(fi->getReference());
547 if(ri->getMultiplicity() == -1 || ri->getMultiplicity() > 1){
548 cloneInterface = menu.addAction("Duplicate");
549 if ((canRemove) && (fi->getInterfaceMultiplicity() > 1)) {
550 removeAction = menu.addAction("Remove");
554 if ((iface->getAssociatedIface() != NULL) && (iface->getDirection() == AbstractInterface::Output)) {
555 showPatterns = menu.addAction("Show patterns");
558 // menu for blocks (group or func)
560 titleAction = menu.addAction("Block operations");
561 titleAction->setEnabled(false);
564 if (refBlock->nbParameters() > 0) {
565 showParameters = menu.addAction("Show parameters");
567 renameAction = menu.addAction("Rename");
569 if(refBlock->isGroupBlock()){
570 openWindow = menu.addAction("Open/show group window");
573 duplicateAction = menu.addAction("Duplicate");
574 showRstClkIface = menu.addAction("Show reset/clock interfaces");
575 showRstClkIface->setCheckable(true);
576 showRstClkIface->setChecked(rstClkVisible);
577 showWishboneIface = menu.addAction("Show wishbone interfaces");
578 showWishboneIface->setCheckable(true);
579 showWishboneIface->setChecked(wishboneVisible);
581 removeAction = menu.addAction("Remove");
584 QAction* selectedAction = NULL;
585 selectedAction = menu.exec(event->screenPos());
587 if(selectedAction == NULL) return ;
589 if (selectedAction == removeAction) {
590 if(ifaceItem != NULL) {
591 dispatcher->removeFunctionalInterface(ifaceItem);
594 dispatcher->removeBoxItem(this);
597 else if (selectedAction == duplicateAction) {
598 dispatcher->duplicateBoxItem(this);
600 else if(selectedAction == renameAction){
601 if(ifaceItem != NULL) {
602 dispatcher->renameInterface(ifaceItem);
605 if (refBlock->isFunctionalBlock()) {
606 dispatcher->renameFunctionalBlock(this);
608 else if (refBlock->isGroupBlock()) {
609 dispatcher->renameGroupBlock(childGroupItem);
613 else if(selectedAction == showProperties){
614 dispatcher->showProperties(ifaceItem);
616 else if (selectedAction == connectToGroup){
617 dispatcher->connectInterToGroup(ifaceItem);
619 else if (selectedAction == cloneInterface){
620 dispatcher->duplicateInterfaceItem(ifaceItem);
622 else if (selectedAction == openWindow){
623 dispatcher->showRaiseWindow(this);
625 else if(selectedAction == showRstClkIface) {
626 dispatcher->showRstClkIface(this);
628 else if(selectedAction == showWishboneIface) {
629 dispatcher->showWishboneIface(this);
631 else if(selectedAction == showParameters) {
632 new ParametersWindow(refBlock, params, NULL);
634 else if(selectedAction == showPatterns) {
635 dispatcher->showPatterns(ifaceItem);
639 void BoxItem::loadFunctional(QDomElement funcElement) throw(Exception) {
643 int id = funcElement.attribute("id","none").toInt(&ok);
644 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
646 QString refXml = funcElement.attribute("ref_xml","none");
647 if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));
649 QString refMd5 = funcElement.attribute("ref_md5","none");
650 if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));
652 cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;
654 QString name = funcElement.attribute("name","none");
655 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
657 QStringList positionStr = funcElement.attribute("position","none").split(",");
658 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
659 int posX = positionStr.at(0).toInt(&ok);
660 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
661 int posY = positionStr.at(1).toInt(&ok);
662 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
664 QStringList dimensionStr = funcElement.attribute("dimension","none").split(",");
665 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
666 int dimX = dimensionStr.at(0).toInt(&ok);
667 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
668 int dimY = dimensionStr.at(1).toInt(&ok);
669 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
671 ReferenceBlock *referenceMd5 = NULL;
672 ReferenceBlock *referenceXml = NULL;
673 ReferenceBlock *reference = NULL;
674 if(refMd5 != "none") {
675 referenceMd5 = params->searchBlockByMd5(refMd5);
677 if(refXml != "none"){
678 referenceXml = params->searchBlockByXml(refXml);
680 if ((referenceMd5 == NULL) && (referenceXml == NULL)) {
681 throw(Exception(PROJECTFILE_CORRUPTED));
683 if (referenceMd5 != referenceXml) {
684 throw(Exception(PROJECTFILE_CORRUPTED));
687 reference = referenceMd5;
690 GroupBlock* parentGroupBlock = AB_TO_GRP(((GroupItem *)parentItem())->getRefBlock());
691 FunctionalBlock* functionalBlock = params->getGraph()->createFunctionalBlock(parentGroupBlock, reference);
692 /* NB: addFunctionalBlock creates all interfaces from the reference, which is annoying when
693 reading bif_iface tags. Thus interface are all removed.
695 functionalBlock->setName(name);
696 setRefBlock(functionalBlock);
699 setDimension(dimX,dimY);
703 QDomNodeList blockParamNodes = funcElement.elementsByTagName("bif_parameter");
704 // setting parameters value
705 for(int i=0; i<blockParamNodes.length(); i++){
706 QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();
708 QString name = currentBlockParamNode.attribute("name","none");
709 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
711 QString value = currentBlockParamNode.attribute("value","none");
712 if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));
714 BlockParameter *blockParam = NULL;
715 blockParam = functionalBlock->getParameterFromName(name);
716 if (blockParam == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
717 blockParam->setValue(value);
720 // recreate all (non-control) interfaces because of some may have a multiplicity>1 with several examplars
721 functionalBlock->removeAllInterfaces();
722 QDomNodeList interfaceNodes = funcElement.elementsByTagName("bif_iface");
723 // setting interfaces (user name, and for multiplicity>1 may be create some new ones)
724 for(int i=0; i<interfaceNodes.length(); i++) {
726 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
728 QString name = currentInterfaceNode.attribute("name","none");
729 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
731 QString refName = currentInterfaceNode.attribute("ref_name","none");
732 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
734 ReferenceInterface* refInter = AI_TO_REF(reference->getIfaceFromName(refName));
735 cout << "creating iface from reference named " << qPrintable(refName) << endl;
736 FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);
737 functionalInterface->setName(name);
738 functionalBlock->addInterface(functionalInterface);
740 // searching for control interface
741 QString ctlRefName = refName+"_enb";
742 ReferenceInterface* ctlRefIface = AI_TO_REF(reference->getIfaceFromName(ctlRefName));
744 if (ctlRefIface != NULL) {
745 cout << "found a control iface:" << qPrintable(ctlRefName) << endl;
746 FunctionalInterface *ctlIface = new FunctionalInterface(functionalBlock,ctlRefIface);
747 if (! ctlIface->setAssociatedIface(functionalInterface)) {
748 throw(Exception(PROJECTFILE_CORRUPTED));
750 ctlIface->setName(name+"_enb");
751 functionalBlock->addInterface(ctlIface);
755 // creating InterfaceItem
756 initInterfaceItems();
757 // setting them with saved values
758 for(int i=0; i<interfaceNodes.length(); i++){
760 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
762 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
763 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
765 QString name = currentInterfaceNode.attribute("name","none");
766 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
768 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
769 int orientation = InterfaceItem::getIntOrientation(orientationStr);
770 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
772 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
773 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
775 InterfaceItem *interfaceItem = searchInterfaceItemByName(name);
776 interfaceItem->setId(id);
777 interfaceItem->setOrientation(orientation);
778 interfaceItem->setPositionRatio(position);
780 updateGeometry(Resize);
783 void BoxItem::save(QXmlStreamWriter &writer) {
784 if (refBlock->isFunctionalBlock()) {
785 writer.writeStartElement("bi_functional");
787 writer.writeAttribute("id",QString::number(id));
788 writer.writeAttribute("ref_xml", ((FunctionalBlock*)refBlock)->getReferenceXmlFile());
789 writer.writeAttribute("ref_md5", ((FunctionalBlock*)refBlock)->getReferenceHashMd5());
790 writer.writeAttribute("name",refBlock->getName());
791 QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y())));
792 writer.writeAttribute("position",attrPos);
793 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
794 writer.writeAttribute("dimension",attrDim);
796 writer.writeStartElement("bif_parameters");
797 foreach(BlockParameter *param,refBlock->getParameters()){
798 writer.writeStartElement("bif_parameter");
800 writer.writeAttribute("name",param->getName());
801 writer.writeAttribute("value",param->getValue().toString());
803 writer.writeAttribute("context",param->getStrContext());
804 writer.writeAttribute("type",param->getTypeString());
806 writer.writeEndElement(); //</bif_parameter>
808 writer.writeEndElement(); //</bif_parameters>
810 writer.writeStartElement("bif_ifaces");
811 writer.writeAttribute("count",QString::number(interfaces.length()));
812 foreach(InterfaceItem* inter, interfaces){
813 writer.writeStartElement("bif_iface");
815 writer.writeAttribute("id",QString::number(inter->getId()));
816 writer.writeAttribute("name",inter->getName());
817 writer.writeAttribute("ref_name",inter->refInter->getName());
818 writer.writeAttribute("orientation",inter->getStrOrientation());
819 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
821 writer.writeEndElement(); //</bif_iface>
823 writer.writeEndElement(); //</bif_ifaces>
825 writer.writeEndElement(); //</bi_functional>
828 writer.writeStartElement("bi_group");
830 writer.writeAttribute("id",QString::number(id));
831 writer.writeAttribute("inside_group",QString::number(childGroupItem->getId()));
832 QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y())));
833 writer.writeAttribute("position",attrPos);
834 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
835 writer.writeAttribute("dimension",attrDim);
837 writer.writeStartElement("big_ifaces");
838 writer.writeAttribute("count",QString::number(interfaces.length()));
839 foreach(InterfaceItem* inter, interfaces){
840 writer.writeStartElement("big_iface");
842 writer.writeAttribute("id",QString::number(inter->getId()));
843 writer.writeAttribute("ref_name",inter->refInter->getName());
844 writer.writeAttribute("orientation",inter->getStrOrientation());
845 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
847 writer.writeEndElement(); //</big_iface>
850 writer.writeEndElement(); //</big_ifaces>
851 writer.writeEndElement(); //</bi_group>
855 QDataStream &operator <<(QDataStream &out, BoxItem &b) {
856 out.setVersion(QDataStream::Qt_4_8);
858 QByteArray blockData;
859 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
861 QString refXml = ((FunctionalBlock*)b.refBlock)->getReferenceXmlFile();
862 QByteArray xmlFile = QByteArray(refXml.toStdString().c_str());
866 toWrite << (int)b.x();
867 toWrite << (int)b.y();
868 toWrite << b.boxWidth;
869 toWrite << b.boxHeight;
870 toWrite << b.getInterfaces().length();
872 for(int i=0; i<b.getInterfaces().length(); i++){
873 InterfaceItem *inter = b.getInterfaces().at(i);
874 toWrite << inter->getId();
875 //toWrite << inter->getName();
876 toWrite << inter->getPositionRatio();
877 toWrite << inter->getOrientation();
885 QDataStream &operator >>(QDataStream &in, BoxItem &b) {
887 in.setVersion(QDataStream::Qt_4_8);
902 cout << "nbInter:" << nbInter << endl;
903 for(int i=0; i<nbInter; i++){
906 double positionRatio;
909 InterfaceItem *inter = b.getInterfaces().at(i);
916 inter->setPositionRatio(positionRatio);
917 inter->setOrientation(orientation);
918 inter->updatePosition();