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::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
212 if(params->editState == Parameters::EditBlockMove) {
213 QPointF absPos = currentPosition + originPoint;
214 int marginConn = 2*(params->arrowWidth+params->arrowLineLength);
215 int gapX = event->scenePos().x() - cursorPosition.x();
216 int gapY = event->scenePos().y() - cursorPosition.y();
218 //cout << "block abs. pos: " << absPos.x() << "," << absPos.y() << " | ";
219 //cout << "block current. pos: " << currentPosition.x() << "," << currentPosition.y() << " | ";
221 if (absPos.x()+gapX < marginConn) {
222 gapX = marginConn-absPos.x();
224 if (absPos.y()+gapY < marginConn) {
225 gapY = marginConn-absPos.y();
227 //cout << "gap: " << gapX << "," << gapY << endl;
228 QPointF gap(gapX,gapY);
229 currentPosition = currentPosition+gap;
230 setPos(currentPosition);
231 // update all connections from/to this block
232 foreach(ConnectionItem *item, getScene()->getConnectionItems()){
233 if ((item->getFromInterfaceItem()->getOwner() == this) || (item->getToInterfaceItem()->getOwner() == this)) {
237 cursorPosition = event->scenePos();
239 // udpate the groupitem
240 (getScene()->getGroupItem())->updateShape();
242 else if(params->editState == Parameters::EditBlockResize) {
244 int gapX = event->scenePos().x() - cursorPosition.x();
245 int gapY = event->scenePos().y() - cursorPosition.y();
246 //cout << "gap: " << gapX << "," << gapY << endl;
247 switch(currentBorder){
249 if(boxWidth+gapX > minimumBoxWidth){
255 if(boxHeight+gapY > minimumBoxHeight){
260 case CornerSouthEast: {
261 if(boxWidth+gapX > minimumBoxWidth){
264 if(boxHeight+gapY > minimumBoxHeight){
270 cout << "abnormal case while resizing block" << endl;
273 // recompute the geometry of the block and possibly the group item
274 if (updateGeometry(Resize)) {
275 (getScene()->getGroupItem())->updateShape();
278 cursorPosition = event->scenePos();
280 else if(params->editState == Parameters::EditInterfaceMove) {
281 prepareGeometryChange();
282 moveInterfaceTo(event->pos());
283 // recompute the geometry of the block
284 if (updateGeometry(InterfaceMove)) {
285 cout << "must recompute group item geometry" << endl;
286 (getScene()->getGroupItem())->updateShape();
288 // update connection from/to the selected interface
289 foreach(ConnectionItem *item, getScene()->getConnectionItems()){
290 if ((item->getFromInterfaceItem() == currentInterface) || (item->getToInterfaceItem() == currentInterface)) {
297 void BoxItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
299 QPointF pos = event->pos();
303 //QGraphicsItem::mousePressEvent(event);
305 if(event->button() == Qt::RightButton) return;
307 int mode = getScene()->getEditionMode();
309 dispatcher->setCurrentGroupWidget(getScene()->getGroupWidget());
311 if ((mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) {
312 InterfaceItem *inter = getInterfaceFromCursor(x,y);
315 if (params->editState == Parameters::EditNoOperation) {
316 getScene()->setSelectedInterface(1,inter);
317 params->setEditState(Parameters::EditStartConnection);
319 else if (params->editState == Parameters::EditStartConnection) {
320 if (inter == getScene()->getSelectedInterface(1)) {
321 params->setEditState(Parameters::EditAbortConnection);
324 getScene()->setSelectedInterface(2,inter);
325 params->setEditState(Parameters::EditCloseConnection);
330 else if (mode == GroupScene::ItemEdition) {
331 setZValue(zValue()+100);
332 if (params->cursorState == Parameters::CursorOnInterface) {
333 InterfaceItem *inter = getInterfaceFromCursor(x,y);
335 if (inter == currentInterface) {
336 params->setEditState(Parameters::EditInterfaceDeselect);
339 setFlag(ItemIsMovable, false);
340 currentInterface = inter;
341 params->setEditState(Parameters::EditInterfaceMove);
345 else if (params->cursorState == Parameters::CursorInBlock) {
346 selected = !selected;
347 params->setEditState(Parameters::EditBlockMove);
348 cursorPosition = event->scenePos();
349 //cout << "cursor current pos. in scene " << cursorPosition.x() << "," << cursorPosition.y() << endl;
352 else if (params->cursorState == Parameters::CursorOnBorder) {
353 setFlag(ItemIsMovable, false);
354 cursorPosition = event->scenePos();
355 params->setEditState(Parameters::EditBlockResize);
360 void BoxItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
362 setZValue(zValue()-100);
364 int mode = getScene()->getEditionMode();
366 if (mode == GroupScene::AddConnection) {
368 if (params->editState == Parameters::EditStartConnection) {
369 InterfaceItem* iface = getScene()->getSelectedInterface(1);
370 iface->selected = true;
371 update(iface->boundingRect());
373 else if (params->editState == Parameters::EditAbortConnection) {
374 InterfaceItem* iface = getScene()->getSelectedInterface(1);
375 iface->selected = false;
376 update(iface->boundingRect());
377 getScene()->setSelectedInterface(1,NULL);
378 params->setEditState(Parameters::EditNoOperation);
380 else if (params->editState == Parameters::EditCloseConnection) {
381 InterfaceItem* iface1 = getScene()->getSelectedInterface(1);
382 InterfaceItem* iface2 = getScene()->getSelectedInterface(2);
383 bool ok = dispatcher->connect(iface1,iface2);
385 iface1->selected = false;
386 // no update needed since the whole scene will be repainted
387 getScene()->setSelectedInterface(1,NULL);
388 getScene()->setSelectedInterface(2,NULL);
389 params->setEditState(Parameters::EditNoOperation);
392 //QMessageBox::warning(NULL,"Error","Cannot connect selected interfaces", QMessageBox::Ok);
393 getScene()->setSelectedInterface(2,NULL);
394 params->setEditState(Parameters::EditStartConnection);
398 else if (mode == GroupScene::ItemEdition) {
399 currentInterface = NULL;
400 params->editState = Parameters::EditNoOperation;
401 setFlag(ItemIsMovable);
404 QGraphicsItem::mouseReleaseEvent(event);
407 void BoxItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event) {
409 QPointF pos = event->pos();
412 currentBorder = NoBorder;
413 int mode = getScene()->getEditionMode();
415 if (mode == GroupScene::AddConnection) {
416 InterfaceItem* iface = getInterfaceFromCursor(x,y);
418 params->cursorState = Parameters::CursorOnInterface;
419 setCursor(Qt::PointingHandCursor);
422 params->cursorState = Parameters::CursorNowhere;
423 setCursor(Qt::ArrowCursor);
426 else if (mode == GroupScene::ItemEdition) {
430 InterfaceItem* iface = getInterfaceFromCursor(x,y);
432 params->cursorState = Parameters::CursorOnInterface;
433 setCursor(Qt::PointingHandCursor);
435 else if ((x>boxWidth-marginE)&&(x<boxWidth)) {
437 params->cursorState = Parameters::CursorOnBorder;
439 if ((y>boxHeight-2*marginS)&&(y<boxHeight)) {
440 currentBorder = CornerSouthEast;
441 setCursor(Qt::SizeFDiagCursor);
444 currentBorder = BorderEast;
445 setCursor(Qt::SizeHorCursor);
448 else if ((y>boxHeight-marginS)&&(y<boxHeight)) {
450 params->cursorState = Parameters::CursorOnBorder;
452 if ((x>boxWidth-2*marginE)&&(x<boxWidth)) {
453 currentBorder = CornerSouthEast;
454 setCursor(Qt::SizeFDiagCursor);
457 currentBorder = BorderSouth;
458 setCursor(Qt::SizeVerCursor);
462 if ((x>0) && (x<boxWidth-marginE) && (y>0) && (y<boxHeight-marginS)) {
463 params->cursorState = Parameters::CursorInBlock;
464 setCursor(Qt::OpenHandCursor);
467 params->cursorState = Parameters::CursorNowhere;
468 setCursor(Qt::ArrowCursor);
472 QGraphicsItem::hoverMoveEvent(event);
476 void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
479 QAction* titleAction = NULL;
480 QAction* removeAction = NULL;
481 QAction* duplicateAction = NULL;
482 QAction* renameAction = NULL;
483 QAction* connectToGroup = NULL;
484 QAction* disconnectFromGroup = NULL;
485 QAction* showProperties = NULL;
486 QAction* cloneInterface = NULL;
487 QAction* openWindow = NULL;
488 QAction* showRstClkInter = NULL;
489 QAction* showParameters = NULL;
491 InterfaceItem* ifaceItem = getInterfaceFromCursor(event->pos().x(), event->pos().y());
492 // menu for interface
493 if( ifaceItem != NULL){
495 titleAction = menu.addAction("Interface operations");
496 titleAction->setEnabled(false);
500 showProperties = menu.addAction("Show properties");
501 renameAction = menu.addAction("Rename");
503 ConnectedInterface* iface = ifaceItem->refInter;
504 ConnectedInterface* ifaceGroup = NULL;
505 bool canRemove = true;
508 if ((iface->getDirection() == AbstractInterface::Input) && (iface->getConnectedFrom() == NULL)) {
509 connectToGroup = menu.addAction("Connect to group input");
511 else if ((iface->getDirection() == AbstractInterface::Output) && (iface->getConnectionToParentGroup() == NULL)) {
512 connectToGroup = menu.addAction("Connect to group output");
514 else if (iface->getConnectionFromParentGroup() != NULL) {
515 ifaceGroup = iface->getConnectionFromParentGroup();
516 //if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
517 if (!ifaceGroup->isConnectedFrom()) {
518 disconnectFromGroup = menu.addAction("Disconnect from group");
524 else if (iface->getConnectionToParentGroup() != NULL) {
525 ifaceGroup = iface->getConnectionToParentGroup();
526 //if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
527 if (!ifaceGroup->isConnectedTo()) {
528 disconnectFromGroup = menu.addAction("Disconnect from group");
535 if (iface->isFunctionalInterface()) {
536 FunctionalInterface* fi = AI_TO_FUN(ifaceItem->refInter);
537 ReferenceInterface* ri = (ReferenceInterface*)(fi->getReference());
538 if(ri->getMultiplicity() == -1 || ri->getMultiplicity() > 1){
539 cloneInterface = menu.addAction("Duplicate");
540 if ((canRemove) && (fi->getInterfaceMultiplicity() > 1)) {
541 removeAction = menu.addAction("Remove");
546 // menu for blocks (group or func)
548 titleAction = menu.addAction("Block operations");
549 titleAction->setEnabled(false);
552 if (refBlock->nbParameters() > 0) {
553 showParameters = menu.addAction("Show parameters");
555 renameAction = menu.addAction("Rename");
557 if(refBlock->isGroupBlock()){
558 openWindow = menu.addAction("Open/show group window");
561 duplicateAction = menu.addAction("Duplicate");
562 showRstClkInter = menu.addAction("Show reset/clock interfaces");
563 showRstClkInter->setCheckable(true);
564 showRstClkInter->setChecked(rstClkVisible);
566 removeAction = menu.addAction("Remove");
569 QAction* selectedAction = NULL;
570 selectedAction = menu.exec(event->screenPos());
572 if(selectedAction == NULL) return ;
574 if (selectedAction == removeAction) {
575 if(ifaceItem != NULL) {
576 dispatcher->removeBlockInterface(ifaceItem);
579 dispatcher->removeBlock(this);
582 else if (selectedAction == duplicateAction) {
583 dispatcher->duplicateBlock(this);
585 else if(selectedAction == renameAction){
586 if(ifaceItem != NULL)
587 dispatcher->renameInterface(ifaceItem);
589 dispatcher->renameBlockOrGroup(this);
591 else if(selectedAction == showProperties){
592 dispatcher->showProperties(ifaceItem);
594 else if (selectedAction == connectToGroup){
595 dispatcher->connectInterToGroup(ifaceItem);
597 else if (selectedAction == disconnectFromGroup) {
598 dispatcher->disconnectInterFromGroup(ifaceItem);
600 else if (selectedAction == cloneInterface){
601 dispatcher->duplicateInterface(ifaceItem);
603 else if (selectedAction == openWindow){
604 dispatcher->showRaiseWindow(this);
606 else if(selectedAction == showRstClkInter){
607 dispatcher->showRstClkInter(this);
609 else if(selectedAction == showParameters){
610 new ParametersWindow(refBlock, params, NULL);
613 void BoxItem::loadFunctional(QDomElement funcElement) throw(Exception) {
617 int id = funcElement.attribute("id","none").toInt(&ok);
618 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
620 QString refXml = funcElement.attribute("ref_xml","none");
621 if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));
623 QString refMd5 = funcElement.attribute("ref_md5","none");
624 if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));
626 cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;
628 QString name = funcElement.attribute("name","none");
629 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
631 QStringList positionStr = funcElement.attribute("position","none").split(",");
632 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
633 int posX = positionStr.at(0).toInt(&ok);
634 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
635 int posY = positionStr.at(1).toInt(&ok);
636 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
638 QStringList dimensionStr = funcElement.attribute("dimension","none").split(",");
639 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
640 int dimX = dimensionStr.at(0).toInt(&ok);
641 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
642 int dimY = dimensionStr.at(1).toInt(&ok);
643 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
645 ReferenceBlock *referenceMd5 = NULL;
646 ReferenceBlock *referenceXml = NULL;
647 ReferenceBlock *reference = NULL;
648 if(refMd5 != "none") {
649 referenceMd5 = params->searchBlockByMd5(refMd5);
651 if(refXml != "none"){
652 referenceXml = params->searchBlockByXml(refXml);
654 if ((referenceMd5 == NULL) && (referenceXml == NULL)) {
655 throw(Exception(PROJECTFILE_CORRUPTED));
657 if (referenceMd5 != referenceXml) {
658 throw(Exception(PROJECTFILE_CORRUPTED));
661 reference = referenceMd5;
663 GroupBlock* parentGroupBlock = AB_TO_GRP(((GroupItem *)parentItem())->getRefBlock());
664 FunctionalBlock* functionalBlock = params->getGraph()->addFunctionalBlock(parentGroupBlock, reference);
665 /* NB: addFunctionalBlock creates all interfaces from the reference, which is annoying when
666 reading bif_iface tags. Thus interface are all removed.
668 functionalBlock->setName(name);
669 setRefBlock(functionalBlock);
672 setDimension(dimX,dimY);
676 QDomNodeList blockParamNodes = funcElement.elementsByTagName("bif_parameter");
677 // setting parameters value
678 for(int i=0; i<blockParamNodes.length(); i++){
679 QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();
681 QString name = currentBlockParamNode.attribute("name","none");
682 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
684 QString value = currentBlockParamNode.attribute("value","none");
685 if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));
687 BlockParameter *blockParam = NULL;
688 blockParam = functionalBlock->getParameterFromName(name);
689 if (blockParam == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
690 blockParam->setValue(value);
693 // recreate all interface because of some may have a multiplicity>1 with several examplars
694 functionalBlock->removeAllInterfaces();
695 QDomNodeList interfaceNodes = funcElement.elementsByTagName("bif_iface");
696 // setting interfaces (user name, and for multiplicity>1 may be create some new ones)
697 for(int i=0; i<interfaceNodes.length(); i++) {
699 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
701 QString name = currentInterfaceNode.attribute("name","none");
702 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
704 QString refName = currentInterfaceNode.attribute("ref_name","none");
705 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
707 ReferenceInterface* refInter = AI_TO_REF(reference->getIfaceFromName(refName));
708 FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);
709 functionalInterface->setName(name);
710 functionalBlock->addInterface(functionalInterface);
712 // creating InterfaceItem
714 // setting them with saved values
715 for(int i=0; i<interfaceNodes.length(); i++){
717 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
719 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
720 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
722 QString name = currentInterfaceNode.attribute("name","none");
723 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
725 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
726 int orientation = InterfaceItem::getIntOrientation(orientationStr);
727 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
729 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
730 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
732 InterfaceItem *interfaceItem = searchInterfaceByName(name);
733 interfaceItem->setId(id);
734 interfaceItem->setOrientation(orientation);
735 interfaceItem->setPositionRatio(position);
737 updateGeometry(Resize);
740 void BoxItem::save(QXmlStreamWriter &writer) {
741 if (refBlock->isFunctionalBlock()) {
742 writer.writeStartElement("bi_functional");
744 writer.writeAttribute("id",QString::number(id));
745 writer.writeAttribute("ref_xml", ((FunctionalBlock*)refBlock)->getReferenceXmlFile());
746 writer.writeAttribute("ref_md5", ((FunctionalBlock*)refBlock)->getReferenceHashMd5());
747 writer.writeAttribute("name",refBlock->getName());
748 QString attrPos = QString::number(pos().x()).append(",").append(QString::number(pos().y()));
749 writer.writeAttribute("position",attrPos);
750 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
751 writer.writeAttribute("dimension",attrDim);
753 writer.writeStartElement("bif_parameters");
754 foreach(BlockParameter *param,refBlock->getParameters()){
755 writer.writeStartElement("bif_parameter");
757 writer.writeAttribute("name",param->getName());
758 writer.writeAttribute("value",param->getValue().toString());
760 writer.writeAttribute("context",param->getStrContext());
761 writer.writeAttribute("type",param->getTypeString());
763 writer.writeEndElement(); //</bif_parameter>
765 writer.writeEndElement(); //</bif_parameters>
767 writer.writeStartElement("bif_ifaces");
768 writer.writeAttribute("count",QString::number(interfaces.length()));
769 foreach(InterfaceItem* inter, interfaces){
770 writer.writeStartElement("bif_iface");
772 writer.writeAttribute("id",QString::number(inter->getId()));
773 writer.writeAttribute("name",inter->getName());
774 writer.writeAttribute("ref_name",inter->refInter->getName());
775 writer.writeAttribute("orientation",inter->getStrOrientation());
776 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
778 writer.writeEndElement(); //</bif_iface>
780 writer.writeEndElement(); //</bif_ifaces>
782 writer.writeEndElement(); //</bi_functional>
785 writer.writeStartElement("bi_group");
787 writer.writeAttribute("id",QString::number(id));
788 writer.writeAttribute("inside_group",QString::number(childGroupItem->getId()));
789 QString attrPos = QString::number(pos().x()).append(",").append(QString::number(pos().y()));
790 writer.writeAttribute("position",attrPos);
791 QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
792 writer.writeAttribute("dimension",attrDim);
794 writer.writeStartElement("big_ifaces");
795 writer.writeAttribute("count",QString::number(interfaces.length()));
796 foreach(InterfaceItem* inter, interfaces){
797 writer.writeStartElement("big_iface");
799 writer.writeAttribute("id",QString::number(inter->getId()));
800 writer.writeAttribute("ref_name",inter->refInter->getName());
801 writer.writeAttribute("orientation",inter->getStrOrientation());
802 writer.writeAttribute("position",QString::number(inter->getPositionRatio()));
804 writer.writeEndElement(); //</big_iface>
807 writer.writeEndElement(); //</big_ifaces>
808 writer.writeEndElement(); //</bi_group>
812 QDataStream &operator <<(QDataStream &out, BoxItem &b) {
813 out.setVersion(QDataStream::Qt_4_8);
815 QByteArray blockData;
816 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
818 QString refXml = ((FunctionalBlock*)b.refBlock)->getReferenceXmlFile();
819 QByteArray xmlFile = QByteArray(refXml.toStdString().c_str());
823 toWrite << (int)b.x();
824 toWrite << (int)b.y();
825 toWrite << b.boxWidth;
826 toWrite << b.boxHeight;
827 toWrite << b.getInterfaces().length();
829 for(int i=0; i<b.getInterfaces().length(); i++){
830 InterfaceItem *inter = b.getInterfaces().at(i);
831 toWrite << inter->getId();
832 //toWrite << inter->getName();
833 toWrite << inter->getPositionRatio();
834 toWrite << inter->getOrientation();
842 QDataStream &operator >>(QDataStream &in, BoxItem &b) {
844 in.setVersion(QDataStream::Qt_4_8);
859 cout << "nbInter:" << nbInter << endl;
860 for(int i=0; i<nbInter; i++){
863 double positionRatio;
866 InterfaceItem *inter = b.getInterfaces().at(i);
873 inter->setPositionRatio(positionRatio);
874 inter->setOrientation(orientation);
875 inter->updatePosition();