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 // no update needed since the whole scene will be repainted
401 getScene()->setSelectedInterface(1,NULL);
402 getScene()->setSelectedInterface(2,NULL);
403 params->setEditState(Parameters::EditNoOperation);
406 //QMessageBox::warning(NULL,"Error","Cannot connect selected interfaces", QMessageBox::Ok);
407 getScene()->setSelectedInterface(2,NULL);
408 params->setEditState(Parameters::EditStartConnection);
412 else if (mode == GroupScene::ItemEdition) {
413 currentInterface = NULL;
414 params->editState = Parameters::EditNoOperation;
415 setFlag(ItemIsMovable);
418 QGraphicsItem::mouseReleaseEvent(event);
421 void BoxItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event) {
423 QPointF pos = event->pos();
426 currentBorder = NoBorder;
427 int mode = getScene()->getEditionMode();
429 if (mode == GroupScene::AddConnection) {
430 InterfaceItem* iface = getInterfaceFromCursor(x,y);
432 params->cursorState = Parameters::CursorOnInterface;
433 setCursor(Qt::PointingHandCursor);
436 params->cursorState = Parameters::CursorNowhere;
437 setCursor(Qt::ArrowCursor);
440 else if (mode == GroupScene::ItemEdition) {
444 InterfaceItem* iface = getInterfaceFromCursor(x,y);
446 params->cursorState = Parameters::CursorOnInterface;
447 setCursor(Qt::PointingHandCursor);
449 else if ((x>boxWidth-marginE)&&(x<boxWidth)) {
451 params->cursorState = Parameters::CursorOnBorder;
453 if ((y>boxHeight-2*marginS)&&(y<boxHeight)) {
454 currentBorder = CornerSouthEast;
455 setCursor(Qt::SizeFDiagCursor);
458 currentBorder = BorderEast;
459 setCursor(Qt::SizeHorCursor);
462 else if ((y>boxHeight-marginS)&&(y<boxHeight)) {
464 params->cursorState = Parameters::CursorOnBorder;
466 if ((x>boxWidth-2*marginE)&&(x<boxWidth)) {
467 currentBorder = CornerSouthEast;
468 setCursor(Qt::SizeFDiagCursor);
471 currentBorder = BorderSouth;
472 setCursor(Qt::SizeVerCursor);
476 if ((x>0) && (x<boxWidth-marginE) && (y>0) && (y<boxHeight-marginS)) {
477 params->cursorState = Parameters::CursorInBlock;
478 setCursor(Qt::OpenHandCursor);
481 params->cursorState = Parameters::CursorNowhere;
482 setCursor(Qt::ArrowCursor);
486 QGraphicsItem::hoverMoveEvent(event);
490 void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
495 QAction* titleAction = NULL;
496 QAction* removeAction = NULL;
497 QAction* duplicateAction = NULL;
498 QAction* renameAction = NULL;
499 QAction* connectToGroup = NULL;
500 QAction* disconnectFromGroup = 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 = getInterfaceFromCursor(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;
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()) || (!ifaceGroup->isConnectedTo())) {
534 if (!ifaceGroup->isConnectedFrom()) {
535 disconnectFromGroup = menu.addAction("Disconnect from group");
541 else if (iface->getConnectionToParentGroup() != NULL) {
542 ifaceGroup = iface->getConnectionToParentGroup();
543 //if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
544 if (!ifaceGroup->isConnectedTo()) {
545 disconnectFromGroup = menu.addAction("Disconnect from group");
552 if (iface->isFunctionalInterface()) {
553 FunctionalInterface* fi = AI_TO_FUN(ifaceItem->refInter);
554 ReferenceInterface* ri = (ReferenceInterface*)(fi->getReference());
555 if(ri->getMultiplicity() == -1 || ri->getMultiplicity() > 1){
556 cloneInterface = menu.addAction("Duplicate");
557 if ((canRemove) && (fi->getInterfaceMultiplicity() > 1)) {
558 removeAction = menu.addAction("Remove");
563 // menu for blocks (group or func)
565 titleAction = menu.addAction("Block operations");
566 titleAction->setEnabled(false);
569 if (refBlock->nbParameters() > 0) {
570 showParameters = menu.addAction("Show parameters");
572 renameAction = menu.addAction("Rename");
574 if(refBlock->isGroupBlock()){
575 openWindow = menu.addAction("Open/show group window");
578 duplicateAction = menu.addAction("Duplicate");
579 showRstClkIface = menu.addAction("Show reset/clock interfaces");
580 showRstClkIface->setCheckable(true);
581 showRstClkIface->setChecked(rstClkVisible);
582 showWishboneIface = menu.addAction("Show wishbone interfaces");
583 showWishboneIface->setCheckable(true);
584 showWishboneIface->setChecked(wishboneVisible);
586 removeAction = menu.addAction("Remove");
589 QAction* selectedAction = NULL;
590 selectedAction = menu.exec(event->screenPos());
592 if(selectedAction == NULL) return ;
594 if (selectedAction == removeAction) {
595 if(ifaceItem != NULL) {
596 dispatcher->removeFunctionalInterface(ifaceItem);
599 dispatcher->removeBoxItem(this);
602 else if (selectedAction == duplicateAction) {
603 dispatcher->duplicateBoxItem(this);
605 else if(selectedAction == renameAction){
606 if(ifaceItem != NULL) {
607 dispatcher->renameInterface(ifaceItem);
610 if (refBlock->isFunctionalBlock()) {
611 dispatcher->renameFunctionalBlock(this);
613 else if (refBlock->isGroupBlock()) {
614 dispatcher->renameGroupBlock(childGroupItem);
618 else if(selectedAction == showProperties){
619 dispatcher->showProperties(ifaceItem);
621 else if (selectedAction == connectToGroup){
622 dispatcher->connectInterToGroup(ifaceItem);
624 else if (selectedAction == disconnectFromGroup) {
625 dispatcher->disconnectInterFromGroup(ifaceItem);
627 else if (selectedAction == cloneInterface){
628 dispatcher->duplicateInterfaceItem(ifaceItem);
630 else if (selectedAction == openWindow){
631 dispatcher->showRaiseWindow(this);
633 else if(selectedAction == showRstClkIface) {
634 dispatcher->showRstClkIface(this);
636 else if(selectedAction == showWishboneIface) {
637 dispatcher->showWishboneIface(this);
639 else if(selectedAction == showParameters){
640 new ParametersWindow(refBlock, params, NULL);
644 void BoxItem::loadFunctional(QDomElement funcElement) throw(Exception) {
648 int id = funcElement.attribute("id","none").toInt(&ok);
649 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
651 QString refXml = funcElement.attribute("ref_xml","none");
652 if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));
654 QString refMd5 = funcElement.attribute("ref_md5","none");
655 if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));
657 cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;
659 QString name = funcElement.attribute("name","none");
660 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
662 QStringList positionStr = funcElement.attribute("position","none").split(",");
663 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
664 int posX = positionStr.at(0).toInt(&ok);
665 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
666 int posY = positionStr.at(1).toInt(&ok);
667 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
669 QStringList dimensionStr = funcElement.attribute("dimension","none").split(",");
670 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
671 int dimX = dimensionStr.at(0).toInt(&ok);
672 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
673 int dimY = dimensionStr.at(1).toInt(&ok);
674 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
676 ReferenceBlock *referenceMd5 = NULL;
677 ReferenceBlock *referenceXml = NULL;
678 ReferenceBlock *reference = NULL;
679 if(refMd5 != "none") {
680 referenceMd5 = params->searchBlockByMd5(refMd5);
682 if(refXml != "none"){
683 referenceXml = params->searchBlockByXml(refXml);
685 if ((referenceMd5 == NULL) && (referenceXml == NULL)) {
686 throw(Exception(PROJECTFILE_CORRUPTED));
688 if (referenceMd5 != referenceXml) {
689 throw(Exception(PROJECTFILE_CORRUPTED));
692 reference = referenceMd5;
695 GroupBlock* parentGroupBlock = AB_TO_GRP(((GroupItem *)parentItem())->getRefBlock());
696 FunctionalBlock* functionalBlock = params->getGraph()->createFunctionalBlock(parentGroupBlock, reference);
697 /* NB: addFunctionalBlock creates all interfaces from the reference, which is annoying when
698 reading bif_iface tags. Thus interface are all removed.
700 functionalBlock->setName(name);
701 setRefBlock(functionalBlock);
704 setDimension(dimX,dimY);
708 QDomNodeList blockParamNodes = funcElement.elementsByTagName("bif_parameter");
709 // setting parameters value
710 for(int i=0; i<blockParamNodes.length(); i++){
711 QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();
713 QString name = currentBlockParamNode.attribute("name","none");
714 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
716 QString value = currentBlockParamNode.attribute("value","none");
717 if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));
719 BlockParameter *blockParam = NULL;
720 blockParam = functionalBlock->getParameterFromName(name);
721 if (blockParam == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
722 blockParam->setValue(value);
725 // recreate all (non-control) interfaces because of some may have a multiplicity>1 with several examplars
726 functionalBlock->removeAllInterfaces();
727 QDomNodeList interfaceNodes = funcElement.elementsByTagName("bif_iface");
728 // setting interfaces (user name, and for multiplicity>1 may be create some new ones)
729 for(int i=0; i<interfaceNodes.length(); i++) {
731 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
733 QString name = currentInterfaceNode.attribute("name","none");
734 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
736 QString refName = currentInterfaceNode.attribute("ref_name","none");
737 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
739 ReferenceInterface* refInter = AI_TO_REF(reference->getIfaceFromName(refName));
740 cout << "creating iface from reference named " << qPrintable(refName) << endl;
741 FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);
742 functionalInterface->setName(name);
743 functionalBlock->addInterface(functionalInterface);
745 // searching for control interface
746 QString ctlRefName = refName+"_ctl";
747 ReferenceInterface* ctlRefIface = AI_TO_REF(reference->getIfaceFromName(ctlRefName));
749 if (ctlRefIface != NULL) {
750 cout << "found a control iface:" << qPrintable(ctlRefName) << endl;
751 FunctionalInterface *ctlIface = new FunctionalInterface(functionalBlock,ctlRefIface);
752 if (! ctlIface->setAssociatedIface(functionalInterface)) {
753 throw(Exception(PROJECTFILE_CORRUPTED));
755 ctlIface->setName(name+"_ctl");
756 functionalBlock->addInterface(ctlIface);
760 // creating InterfaceItem
762 // setting them with saved values
763 for(int i=0; i<interfaceNodes.length(); i++){
765 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
767 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
768 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
770 QString name = currentInterfaceNode.attribute("name","none");
771 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
773 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
774 int orientation = InterfaceItem::getIntOrientation(orientationStr);
775 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
777 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
778 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
780 InterfaceItem *interfaceItem = searchInterfaceByName(name);
781 interfaceItem->setId(id);
782 interfaceItem->setOrientation(orientation);
783 interfaceItem->setPositionRatio(position);
785 updateGeometry(Resize);
788 void BoxItem::save(QXmlStreamWriter &writer) {
789 if (refBlock->isFunctionalBlock()) {
790 writer.writeStartElement("bi_functional");
792 writer.writeAttribute("id",QString::number(id));
793 writer.writeAttribute("ref_xml", ((FunctionalBlock*)refBlock)->getReferenceXmlFile());
794 writer.writeAttribute("ref_md5", ((FunctionalBlock*)refBlock)->getReferenceHashMd5());
795 writer.writeAttribute("name",refBlock->getName());
796 QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y())));
797 writer.writeAttribute("position",attrPos);
798 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
799 writer.writeAttribute("dimension",attrDim);
801 writer.writeStartElement("bif_parameters");
802 foreach(BlockParameter *param,refBlock->getParameters()){
803 writer.writeStartElement("bif_parameter");
805 writer.writeAttribute("name",param->getName());
806 writer.writeAttribute("value",param->getValue().toString());
808 writer.writeAttribute("context",param->getStrContext());
809 writer.writeAttribute("type",param->getTypeString());
811 writer.writeEndElement(); //</bif_parameter>
813 writer.writeEndElement(); //</bif_parameters>
815 writer.writeStartElement("bif_ifaces");
816 writer.writeAttribute("count",QString::number(interfaces.length()));
817 foreach(InterfaceItem* inter, interfaces){
818 writer.writeStartElement("bif_iface");
820 writer.writeAttribute("id",QString::number(inter->getId()));
821 writer.writeAttribute("name",inter->getName());
822 writer.writeAttribute("ref_name",inter->refInter->getName());
823 writer.writeAttribute("orientation",inter->getStrOrientation());
824 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
826 writer.writeEndElement(); //</bif_iface>
828 writer.writeEndElement(); //</bif_ifaces>
830 writer.writeEndElement(); //</bi_functional>
833 writer.writeStartElement("bi_group");
835 writer.writeAttribute("id",QString::number(id));
836 writer.writeAttribute("inside_group",QString::number(childGroupItem->getId()));
837 QString attrPos = QString::number(pos().x()).append(",").append(QString::number(pos().y()));
838 writer.writeAttribute("position",attrPos);
839 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
840 writer.writeAttribute("dimension",attrDim);
842 writer.writeStartElement("big_ifaces");
843 writer.writeAttribute("count",QString::number(interfaces.length()));
844 foreach(InterfaceItem* inter, interfaces){
845 writer.writeStartElement("big_iface");
847 writer.writeAttribute("id",QString::number(inter->getId()));
848 writer.writeAttribute("ref_name",inter->refInter->getName());
849 writer.writeAttribute("orientation",inter->getStrOrientation());
850 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
852 writer.writeEndElement(); //</big_iface>
855 writer.writeEndElement(); //</big_ifaces>
856 writer.writeEndElement(); //</bi_group>
860 QDataStream &operator <<(QDataStream &out, BoxItem &b) {
861 out.setVersion(QDataStream::Qt_4_8);
863 QByteArray blockData;
864 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
866 QString refXml = ((FunctionalBlock*)b.refBlock)->getReferenceXmlFile();
867 QByteArray xmlFile = QByteArray(refXml.toStdString().c_str());
871 toWrite << (int)b.x();
872 toWrite << (int)b.y();
873 toWrite << b.boxWidth;
874 toWrite << b.boxHeight;
875 toWrite << b.getInterfaces().length();
877 for(int i=0; i<b.getInterfaces().length(); i++){
878 InterfaceItem *inter = b.getInterfaces().at(i);
879 toWrite << inter->getId();
880 //toWrite << inter->getName();
881 toWrite << inter->getPositionRatio();
882 toWrite << inter->getOrientation();
890 QDataStream &operator >>(QDataStream &in, BoxItem &b) {
892 in.setVersion(QDataStream::Qt_4_8);
907 cout << "nbInter:" << nbInter << endl;
908 for(int i=0; i<nbInter; i++){
911 double positionRatio;
914 InterfaceItem *inter = b.getInterfaces().at(i);
921 inter->setPositionRatio(positionRatio);
922 inter->setOrientation(orientation);
923 inter->updatePosition();