]> AND Private Git Repository - blast.git/commitdiff
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
loading project corrected
authorstephane Domas <stephane.domas@univ-fcomte.fr>
Wed, 3 May 2017 06:26:43 +0000 (08:26 +0200)
committerstephane Domas <stephane.domas@univ-fcomte.fr>
Wed, 3 May 2017 06:26:43 +0000 (08:26 +0200)
20 files changed:
AbstractBlock.cpp
AbstractBlock.h
AbstractBoxItem.cpp
AbstractBoxItem.h
BoxItem.cpp
BoxItem.h
Dispatcher.cpp
Dispatcher.h
GroupItem.cpp
GroupItem.h
GroupScene.cpp
GroupScene.h
InterfaceItem.cpp
InterfaceItem.h
MainWindow.cpp
MainWindow.h
Parameters.cpp
Parameters.h
blast.creator.user
projectfile.xsd

index 6e9cc86a9c764f014aa3695b023e6111f5e515b8..d316800e91e43534ed43d2d6ef5bbd3b7bca723f 100644 (file)
@@ -16,18 +16,8 @@ AbstractBlock::AbstractBlock(const QString& _name) {
 \r
 AbstractBlock::~AbstractBlock() {\r
 \r
-  foreach(AbstractInterface* iface, inputs) {\r
-    delete iface;\r
-  }\r
-  foreach(AbstractInterface* iface, outputs) {\r
-    delete iface;\r
-  }\r
-  foreach(AbstractInterface* iface, bidirs) {\r
-    delete iface;\r
-  }\r
-  inputs.clear();\r
-  outputs.clear();\r
-  bidirs.clear();\r
+  removeAllInterfaces();\r
+\r
   foreach(BlockParameter* p, params) {\r
     delete p;\r
   }\r
@@ -90,6 +80,23 @@ void AbstractBlock::removeInterface(AbstractInterface *inter) {
   delete inter;\r
 }\r
 \r
+void AbstractBlock::removeAllInterfaces() {\r
+\r
+  foreach(AbstractInterface* iface, inputs) {\r
+    delete iface;\r
+  }\r
+  foreach(AbstractInterface* iface, outputs) {\r
+    delete iface;\r
+  }\r
+  foreach(AbstractInterface* iface, bidirs) {\r
+    delete iface;\r
+  }\r
+  inputs.clear();\r
+  outputs.clear();\r
+  bidirs.clear();\r
+\r
+}\r
+\r
 void AbstractBlock::defineBlockParam(BlockParameter *param)\r
 {\r
   cout << "definition of param : " << param->getName().toStdString() << endl;\r
index 19209b773bad2081e10be79bbd64aadfb16769f2..acdc1c8ab8771953a7c180b1d72656ed299b8a76 100644 (file)
@@ -51,6 +51,7 @@ public:
   void addParameter(BlockParameter *param);\r
   void addInterface(AbstractInterface *inter);\r
   void removeInterface(AbstractInterface *inter);\r
+  void removeAllInterfaces();\r
   void defineBlockParam(BlockParameter *param);\r
 \r
   QList<AbstractInterface *> getInterfaces();\r
index ec791fb9587cfe062ab7e77fe48ce17130a6ed3e..c4cdae9272ab244d220ef0f27d3d5de8a4f3f73f 100644 (file)
@@ -15,9 +15,8 @@
 AbstractBoxItem::  AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem *parent) : QGraphicsItem(parent) {
   dispatcher = _dispatcher;
   params = _params;
-  refBlock = _refBlock;
-  QFont fontId("Arial",10);
-  QFontMetrics fmId(fontId);
+  refBlock = _refBlock;  
+  QFontMetrics fmId(params->defaultBlockFont);
   nameWidth = fmId.width(refBlock->getName());
   nameHeight = fmId.height();
   nameMargin = 10;
@@ -42,6 +41,34 @@ AbstractBoxItem::  AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispat
   // NOTE : initInterfaces() is only called in subclasses
 }
 
+AbstractBoxItem::AbstractBoxItem(Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem* parent) : QGraphicsItem(parent) {
+  dispatcher = _dispatcher;
+  params = _params;
+  refBlock = NULL;
+  nameWidth = 0;
+  nameHeight = 0;
+  nameMargin = 10;
+  ifaceMargin = 10;
+
+  // the six following values will be override in subclass constructors
+  minimumBoxWidth = 0;
+  minimumBoxHeight = 0;
+  boxWidth = 0;
+  boxHeight = 0;
+  totalWidth = 0;
+  totalHeight = 0;
+
+  originPoint = QPointF(0.0,0.0);
+
+  selected = false;
+  currentInterface = NULL;
+  rstClkVisible = false;
+
+  setAcceptHoverEvents(true);
+
+  // NOTE : initInterfaces() is only called in subclasses
+}
+
 AbstractBoxItem::~AbstractBoxItem() {
   foreach(InterfaceItem* inter, interfaces) {
     delete inter;
@@ -57,8 +84,14 @@ bool AbstractBoxItem::isGroupItem() {
   return false;
 }
 
-void AbstractBoxItem::initInterfaces()
-{
+void AbstractBoxItem::setRefBlock(AbstractBlock* _refBlock) {
+  refBlock = _refBlock;
+  QFontMetrics fmId(params->defaultBlockFont);
+  nameWidth = fmId.width(refBlock->getName());
+  nameHeight = fmId.height();
+}
+
+void AbstractBoxItem::initInterfaces() {
   /* TO DO : creating all needed InterfaceItem, with by default, input at west and output at east */
   int orientation = Parameters::West;
 
index 375e9dcabad9706b433285199d31816e30da8ba1..98cec586cb3f35e73dd0777200f72f988e95736b 100644 (file)
@@ -22,6 +22,7 @@ public:
   enum ChangeType { Resize = 0, InterfaceMove };
 
   AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem* parent = Q_NULLPTR);
+  AbstractBoxItem(Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem* parent = Q_NULLPTR);
 
   virtual ~AbstractBoxItem();
 
@@ -40,7 +41,8 @@ public:
   inline QPointF getOriginPoint() { return originPoint; }
 
   // setters
-  inline void setId(int id){ this->id = id; }
+  void setRefBlock(AbstractBlock* _refBlock);
+  inline void setId(int _id){ id = _id; }
   inline void setSelected(bool _selected) { selected = _selected; }  
   inline void setRstClkVisible(bool b){ rstClkVisible = b;}
   void setDimension(int x, int y);
index 237c7ee0f843b8f1dd05322791e69cadb3c4f6a6..a654718ed91877e2fdc3b509e47c3d74293cdc39 100644 (file)
@@ -12,6 +12,7 @@
 #include "ReferenceBlock.h"
 #include "ParametersWindow.h"
 #include "BlockParameter.h"
+#include "Graph.h"
 
 
 BoxItem::BoxItem(AbstractBlock *_refBlock,
@@ -41,6 +42,26 @@ BoxItem::BoxItem(AbstractBlock *_refBlock,
   //cout << "pos in group: " << x() << "," << y() << endl;
 }
 
+BoxItem::BoxItem(Dispatcher *_dispatcher, Parameters *_params, GroupItem *parent) throw(Exception) : AbstractBoxItem(_dispatcher, _params, parent) {
+
+  refBlock = NULL;
+  childGroupItem = NULL;
+  currentBorder = NoBorder;
+  selected = false;
+
+  setZValue(100);
+  setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
+
+  boxWidth = params->defaultBlockWidth;
+  boxHeight = params->defaultBlockHeight;
+  //initInterfaces();
+  //updateGeometry(InterfaceMove);
+  //resetInterfacesPosition();
+  //QPointF initPos = QPointF(0.0,0.0) - originPoint;
+  //setPos(initPos);
+  //cout << "total size of block: " << totalWidth << "," << totalHeight << endl;
+  //cout << "pos in group: " << x() << "," << y() << endl;
+}
 
 BoxItem::~BoxItem() {
 }
@@ -133,7 +154,7 @@ bool BoxItem::updateGeometry(ChangeType type) {
 
   bool boxSizeChanged = false;
 
-  // whatever the change, the minimum size may ahve changed
+  // whatever the change, the minimum size may have changed
   updateMinimumSize();
 
   if (type == Resize) {
@@ -589,6 +610,132 @@ void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
     new ParametersWindow(refBlock, params, NULL);
   }
 }
+void BoxItem::loadFunctional(QDomElement funcElement) throw(Exception) {
+
+  bool ok = false;
+
+  int id = funcElement.attribute("id","none").toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+  QString refXml = funcElement.attribute("ref_xml","none");
+  if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+  QString refMd5 = funcElement.attribute("ref_md5","none");
+  if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+  cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;
+
+  QString name = funcElement.attribute("name","none");
+  if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+  QStringList positionStr = funcElement.attribute("position","none").split(",");
+  if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
+  int posX = positionStr.at(0).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+  int posY = positionStr.at(1).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+  QStringList dimensionStr = funcElement.attribute("dimension","none").split(",");
+  if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
+  int dimX = dimensionStr.at(0).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+  int dimY = dimensionStr.at(1).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+  ReferenceBlock *referenceMd5 = NULL;
+  ReferenceBlock *referenceXml = NULL;
+  ReferenceBlock *reference = NULL;
+  if(refMd5 != "none") {
+    referenceMd5 = params->searchBlockByMd5(refMd5);
+  }
+  if(refXml != "none"){
+    referenceXml = params->searchBlockByXml(refXml);
+  }
+  if ((referenceMd5 == NULL) && (referenceXml == NULL)) {
+    throw(Exception(PROJECTFILE_CORRUPTED));
+  }
+  if (referenceMd5 != referenceXml) {
+    throw(Exception(PROJECTFILE_CORRUPTED));
+  }
+  else {
+    reference = referenceMd5;
+  }
+  GroupBlock* parentGroupBlock = AB_TO_GRP(((GroupItem *)parentItem())->getRefBlock());
+  FunctionalBlock* functionalBlock = params->getGraph()->addFunctionalBlock(parentGroupBlock, reference);
+  /* NB: addFunctionalBlock creates all interfaces from the reference, which is annoying when
+    reading bif_iface tags. Thus interface are all removed.
+  */
+  functionalBlock->setName(name);
+  setRefBlock(functionalBlock);
+
+  setPos(posX,posY);
+  setDimension(dimX,dimY);
+  setId(id);
+
+
+  QDomNodeList blockParamNodes = funcElement.elementsByTagName("bif_parameter");
+  // setting parameters value
+  for(int i=0; i<blockParamNodes.length(); i++){
+    QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();
+
+    QString name = currentBlockParamNode.attribute("name","none");
+    if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString value = currentBlockParamNode.attribute("value","none");
+    if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+    BlockParameter *blockParam = NULL;
+    blockParam = functionalBlock->getParameterFromName(name);
+    if (blockParam == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
+    blockParam->setValue(value);
+  }
+
+  // recreate all interface because of some may have a multiplicity>1 with several examplars
+  functionalBlock->removeAllInterfaces();
+  QDomNodeList interfaceNodes = funcElement.elementsByTagName("bif_iface");
+  // setting interfaces (user name, and for multiplicity>1 may be create some new ones)
+  for(int i=0; i<interfaceNodes.length(); i++) {
+
+    QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
+
+    QString name = currentInterfaceNode.attribute("name","none");
+    if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString refName = currentInterfaceNode.attribute("ref_name","none");
+    if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+    ReferenceInterface* refInter = AI_TO_REF(reference->getIfaceFromName(refName));
+    FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);
+    functionalInterface->setName(name);
+    functionalBlock->addInterface(functionalInterface);
+  }
+  // creating InterfaceItem
+  initInterfaces();
+  // setting them with saved values
+  for(int i=0; i<interfaceNodes.length(); i++){
+
+    QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
+
+    int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
+    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString name = currentInterfaceNode.attribute("name","none");
+    if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString orientationStr = currentInterfaceNode.attribute("orientation","none");
+    int orientation = InterfaceItem::getIntOrientation(orientationStr);
+    if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
+    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    InterfaceItem *interfaceItem = searchInterfaceByName(name);
+    interfaceItem->setId(id);
+    interfaceItem->setOrientation(orientation);
+    interfaceItem->setPositionRatio(position);
+  }
+  updateGeometry(Resize);
+}
 
 void BoxItem::save(QXmlStreamWriter &writer) {
   if (refBlock->isFunctionalBlock()) {
@@ -682,7 +829,7 @@ QDataStream &operator <<(QDataStream &out, BoxItem &b) {
   for(int i=0; i<b.getInterfaces().length(); i++){
     InterfaceItem *inter = b.getInterfaces().at(i);
     toWrite << inter->getId();
-    toWrite << inter->getName();
+    //toWrite << inter->getName();
     toWrite << inter->getPositionRatio();
     toWrite << inter->getOrientation();
   }
@@ -692,8 +839,7 @@ QDataStream &operator <<(QDataStream &out, BoxItem &b) {
   return out;
 }
 
-QDataStream &operator >>(QDataStream &in, BoxItem &b)
-{
+QDataStream &operator >>(QDataStream &in, BoxItem &b) {
 
   in.setVersion(QDataStream::Qt_4_8);
 
@@ -723,8 +869,7 @@ QDataStream &operator >>(QDataStream &in, BoxItem &b)
     in >> positionRatio;
     in >> orientation;
 
-    inter->setId(id);
-    inter->setName(name);
+    inter->setId(id);    
     inter->setPositionRatio(positionRatio);
     inter->setOrientation(orientation);
     inter->updatePosition();
index 74eb36afbf1c8db2d3eeca8cb1d15fdd92ee37e6..35a12a84cf71900a6dc58c85e66684748656b0e7 100644 (file)
--- a/BoxItem.h
+++ b/BoxItem.h
@@ -5,6 +5,8 @@
 
 #include <QtCore>
 #include <QtGui>
+#include <QtXml>
+#include <QtXmlPatterns>
 
 
 #include "AbstractBoxItem.h"
@@ -29,6 +31,7 @@ class BoxItem : public AbstractBoxItem {
 
 public:
   BoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, GroupItem* parent) throw(Exception);
+  BoxItem(Dispatcher *_dispatcher, Parameters *_params, GroupItem* parent) throw(Exception);
   ~BoxItem();
 
   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);  
@@ -44,6 +47,7 @@ public:
 
   // others
   void moveTo(QPointF dest);
+  void loadFunctional(QDomElement funcElement) throw(Exception);
   void save(QXmlStreamWriter& writer);
 
 protected:
index b191651df14951e2d3a1b3a6bbb7d692163338e6..bbeb84142b6347aea12f14742f400cd24570e0a7 100644 (file)
@@ -44,6 +44,7 @@ GroupWidget *Dispatcher::loadProject(const QString& filename) {
     return NULL;
   }
 
+  /*
   // creating the top widget/scene
   topGroup = new GroupWidget(NULL,this,params);
   currentGroup = topGroup;
@@ -52,9 +53,9 @@ GroupWidget *Dispatcher::loadProject(const QString& filename) {
 
   params->setTopScene(scene);
   params->setCurrentScene(scene);
-
+*/
   try {   
-    params->loadProject(root);
+    topGroup = params->loadProject(root);
   }
   catch(Exception e){
     cerr << qPrintable(e.getDefaultMessage()) << endl;
@@ -72,7 +73,11 @@ void Dispatcher::closeCurrentProject() {
   foreach(GroupWidget* win, groupList) {
     win->deleteLater();
   }
+  groupList.clear();
   params->destroyGraph();
+  topGroup = NULL;
+  currentGroup = NULL;
+  sceneCounter = 0;
 }
 
 bool Dispatcher::connect(InterfaceItem *iface1, InterfaceItem *iface2) {
@@ -234,8 +239,6 @@ void Dispatcher::renameInterface(InterfaceItem *item) {
     if (item->refInter->getOwner()->isGroupBlock()) {
       item->refInter->setName(text);
     }
-    item->setName(text);
-
   }
   else {
     QMessageBox::warning(NULL,"Error in given name",
@@ -343,7 +346,7 @@ GroupWidget *Dispatcher::createTopScene(){
   return topGroup;
 }
 
-void Dispatcher::addNewEmptyGroup(GroupScene* scene) {
+GroupWidget* Dispatcher::addNewEmptyGroup(GroupScene* scene, bool show) {
   static QString fctName = "Dispatcher::addNewEmptyGroup();";
 #ifdef DEBUG_FCTNAME
   cout << "call to " << qPrintable(fctName) << endl;
@@ -360,7 +363,8 @@ void Dispatcher::addNewEmptyGroup(GroupScene* scene) {
   params->unsaveModif = true;
 
   GroupWidget* child = createChildScene(scene->getGroupWidget(),newItem);
-  child->show();
+  if (show) child->show();
+  return child;
 
 }
 
@@ -370,24 +374,38 @@ GroupWidget *Dispatcher::createChildScene(GroupWidget* parentWidget, BoxItem *up
   cout << "call to " << qPrintable(fctName) << endl;
 #endif
 
-  // getting back the goup block already created
-  GroupBlock* groupBlock = NULL;
-  if (upperItemOfGroupItem != NULL) {
-    groupBlock = AB_TO_GRP(upperItemOfGroupItem->getRefBlock());
-  }  
-  // creating the view part of the group
-  GroupItem *groupItem = new GroupItem(upperItemOfGroupItem,groupBlock,this,params);
-  // creating the group widget
-  GroupWidget* group = new GroupWidget(parentWidget, this, params);
-  // getting the newly created scene
-  GroupScene *scene = group->getScene();
-  scene->setId(sceneCounter++);
-  // affecting group item to the scene
-  scene->setGroupItem(groupItem);
-  groupList.append(group);
-
-  mainWindow->getLibrary()->updateComboScene();
+  GroupWidget* group = NULL;
+  /* NB: this method may be called during design process or when loading
+     a project. In this case, upperItemOfGroupItem is NULL, thus a lot of things
+     cannot be initialized yet. This is why there are 2 cases below
+   */
 
+  if (upperItemOfGroupItem != NULL) {
+    // getting back the goup block already created
+    GroupBlock* groupBlock = AB_TO_GRP(upperItemOfGroupItem->getRefBlock());
+    // creating the view part of the group
+    GroupItem *groupItem = new GroupItem(upperItemOfGroupItem,groupBlock,this,params);
+    // creating the group widget
+    group = new GroupWidget(parentWidget, this, params);
+    // getting the newly created scene
+    GroupScene *scene = group->getScene();
+    scene->setId(sceneCounter++);
+    // affecting group item to the scene
+    scene->setGroupItem(groupItem);
+    groupList.append(group);
+
+    mainWindow->getLibrary()->updateComboScene();
+  }
+  else {
+    GroupItem *groupItem = new GroupItem(this,params);
+    // creating the group widget
+    group = new GroupWidget(parentWidget, this, params);
+    // getting the newly created scene
+    GroupScene *scene = group->getScene();
+    // affecting group item to the scene
+    scene->setGroupItem(groupItem);
+    groupList.append(group);
+  }
   return group;
 }
 
index fd61087b3e0f053624eb540e1ca48e39761d0410..e79ad60c30dcd52093f398f0d0cc26dda6563750 100644 (file)
@@ -44,11 +44,13 @@ public:
   void destroyScene(GroupScene* scene);
   void showRaiseWindow(BoxItem *item);
   void showRstClkInter(AbstractBoxItem *item);
-  void addNewEmptyGroup(GroupScene *scene);
+  GroupWidget *addNewEmptyGroup(GroupScene *scene, bool show = true);
   void addNewFullGroup();  
 
   inline GroupWidget* getCurrentGroup() { return currentGroup; }
 
+  inline void setSceneCounter(int value) { sceneCounter = value;}
+
   bool isCurrentProject;
 
 public slots:
index fa341b268d166c1de4bee34a0a2b90f3d9b3e061..69b5e0473dc19ca5a5a622883bc49613f4750b1f 100644 (file)
@@ -10,6 +10,8 @@
 #include "ConnectedInterface.h"
 #include "GroupScene.h"
 #include "ParametersWindow.h"
+#include "GroupBlock.h"
+#include "GroupInterface.h"
 
 
 GroupItem::GroupItem(BoxItem *_parentItem,
@@ -48,6 +50,21 @@ GroupItem::GroupItem(BoxItem *_parentItem,
   cout << "pos in scene: " << x() << "," << y() << endl;
 }
 
+GroupItem::GroupItem(Dispatcher *_dispatcher,Parameters *_params) throw(Exception) :AbstractBoxItem(_dispatcher, _params) {
+
+  parentItem = NULL;
+  rectTitle = QRectF(0,-(nameHeight+2*nameMargin),nameWidth+2*nameMargin,nameHeight+2*nameMargin);
+  selected = false;
+  setZValue(-100);
+  setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
+
+  updateGeometry(InterfaceMove);
+  QPointF initPos = QPointF(0.0,0.0) - originPoint;
+  setPos(initPos);
+  cout << "total size of group: " << totalWidth << "," << totalHeight << endl;
+  cout << "pos in scene: " << x() << "," << y() << endl;
+}
+
 GroupItem::~GroupItem() {
   // since the reference block is nowhere referenced except in this class, it must be deleted here
   delete refBlock;
@@ -61,6 +78,13 @@ BoxItem* GroupItem::getParentItem() {
   return parentItem;
 }
 
+void GroupItem::setParentItem(BoxItem *_parentItem) {
+  parentItem = _parentItem;
+  if (parentItem != NULL) {
+    parentItem->setChildGroupItem(this);
+  }
+}
+
 void GroupItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
   if(boxWidth > 0 && boxHeight > 0){
     if(selected)
@@ -569,6 +593,76 @@ InterfaceItem* GroupItem::isHoverInterface(QPointF point) {
   return NULL;
 }
 
+void GroupItem::load(QDomElement groupElement) throw(Exception) {
+
+  GroupBlock* groupBlock = AB_TO_GRP(refBlock);
+
+  bool ok = false;
+
+  int id = groupElement.attribute("id","none").toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+  QString nameStr = groupElement.attribute("name","none");
+  if(nameStr == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+  QStringList positionStr = groupElement.attribute("position","none").split(",");
+  if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
+  int posX = positionStr.at(0).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+  int posY = positionStr.at(1).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+  QStringList dimensionStr = groupElement.attribute("dimension","none").split(",");
+  if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
+  int dimX = dimensionStr.at(0).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+  int dimY = dimensionStr.at(1).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+  setId(id);
+  setPos(posX,posY);
+  setDimension(dimX,dimY);
+  groupBlock->setName(nameStr);
+
+  cout << "group info : \n-id : " << id << "\n-pos : " << posX << ", " << posY << "\n-dim : " << dimX << ", " << dimY << "\n-name : " << nameStr.toStdString() << endl;
+
+  QDomNodeList interfaces = groupElement.elementsByTagName("group_iface");
+  for(int j=0; j<interfaces.length(); j++){
+    QDomElement currentInterfaceNode = interfaces.at(j).toElement();
+
+    int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
+    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString name = currentInterfaceNode.attribute("name","none");
+    if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString levelStr = currentInterfaceNode.attribute("level","none");
+    int level = AbstractInterface::getIntLevel(levelStr);
+    if(level == -1) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString directionStr = currentInterfaceNode.attribute("direction","none");
+    int direction = AbstractInterface::getIntDirection(directionStr);
+    if(direction == -1) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString orientationStr = currentInterfaceNode.attribute("orientation","none");
+    int orientation = InterfaceItem::getIntOrientation(orientationStr);
+    if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
+    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,level);
+
+    InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupInterface,this,params);
+    interfaceItem->setId(id);
+
+    groupBlock->addInterface(groupInterface);
+    addInterface(interfaceItem, false);
+    cout << "interface add to " << groupBlock->getName().toStdString() << endl;
+  }
+
+}
+
 void GroupItem::save(QXmlStreamWriter &writer) {
 
   writer.writeStartElement("group_item");
index 3882a6021a726dff6fdeab4dbc091db60ee6f33a..137ff03f4723c5b07d1ec6816c270f363da5b288 100644 (file)
@@ -5,6 +5,9 @@
 
 #include <QtCore>
 #include <QtGui>
+#include <QtXml>
+#include <QtXmlPatterns>
+
 
 #include "AbstractBoxItem.h"
 class AbstractBoxItem;
@@ -31,12 +34,14 @@ public:
 
    */
   GroupItem(BoxItem* _parentItem, AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params) throw(Exception);
+  GroupItem(Dispatcher *_dispatcher, Parameters *_params) throw(Exception); //! uses only when loading a project file
   ~GroupItem();
 
   // getters
   BoxItem* getParentItem();
 
   // setters
+  void setParentItem(BoxItem* _parentItem);
 
   // testers
   bool isGroupItem();
@@ -44,6 +49,7 @@ public:
   // others  
   void updateShape();
   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);  
+  void load(QDomElement groupElement) throw(Exception);
   void save(QXmlStreamWriter& writer);
 
 protected:
index daf6bf1e2102d782f883655dd708b8b899786169..e8c9e842ecb9454925fef709f5d6b6d199cfffd7 100644 (file)
@@ -86,15 +86,8 @@ QList<AbstractBoxItem*> GroupScene::getGroupAndBlocks() {
 
 BoxItem *GroupScene::createBlockItem(AbstractBlock *block) {
 
-  BoxItem* blockItem = new BoxItem(block,dispatcher,params,groupItem);
-  blockItem->setZValue(1);
-  addBlockItem(blockItem);
-  return blockItem;
-}
-
-void GroupScene::addBlockItem(BoxItem* item) {
-  // add item from the viewport
-  //addItem(item);
+  BoxItem* item = new BoxItem(block,dispatcher,params,groupItem);
+  item->setZValue(1);
   // add item from the QList
   blockItems.append(item);
   // repainting the group
@@ -102,7 +95,16 @@ void GroupScene::addBlockItem(BoxItem* item) {
   // center the new block
   QPointF newPos((groupItem->getWidth()-item->getTotalWidth())/2.0, (groupItem->getHeight()-item->getTotalHeight())/2.0);
   newPos = newPos-item->getOriginPoint();
-  item->moveTo(newPos);  
+  item->moveTo(newPos);
+
+  return item;
+}
+
+void GroupScene::addBlockItem(BoxItem* item) {  
+  // add item from the QList
+  blockItems.append(item);
+  // repainting the group
+  groupItem->updateShape();  
 }
 
 void GroupScene::removeBlockItem(BoxItem* item) {
@@ -187,6 +189,12 @@ void GroupScene::updateConnectionItemsShape() {
 void GroupScene::save(QXmlStreamWriter &writer) {
   writer.writeStartElement("scene");
   writer.writeAttribute("id",QString::number(id));
+  if (parentScene == NULL) {
+    writer.writeAttribute("upper_scene",QString::number(-1));
+  }
+  else {
+    writer.writeAttribute("upper_scene",QString::number(parentScene->getId()));
+  }
   groupItem->save(writer);
 
   writer.writeStartElement("block_items");
index e7b42ecb1c008c792920891b3ed8e1b25223ed15..a14ef0b873cc0f3f92db7bf73dc0a4bcc7900e71 100644 (file)
@@ -69,8 +69,8 @@ public:
 
 
   // others  
-  BoxItem* createBlockItem(AbstractBlock* block);
-  void addBlockItem(BoxItem* item);
+  BoxItem* createBlockItem(AbstractBlock* block); //! create a new BoxItem and place it at the center of the scene
+  void addBlockItem(BoxItem* item); //! add an already configured BoxItem in the scene.
   void removeBlockItem(BoxItem* item);
   void createConnectionItem(InterfaceItem* iface1, InterfaceItem* iface2);
   ConnectionItem* searchConnectionItem(InterfaceItem* iface1, InterfaceItem* iface2);
index 552e15989b990aa9257d362333c66ccfe4cefc9e..0e87a1934d67e8fc30b604466cad3ca2fe7cf4f5 100644 (file)
@@ -19,10 +19,9 @@ InterfaceItem::InterfaceItem(double _position,
   // CAUTION : the owner must add explicitely this item to its interface, calling addInterface()
   owner = _owner;
   params = _params;
-  selected = false;
-  name = refInter->getName();
+  selected = false;  
   QFontMetrics fmName(params->defaultIfaceFont);
-  nameWidth = fmName.width(name);
+  nameWidth = fmName.width(refInter->getName());
   nameHeight = fmName.height();
   // by default, only data interface are visible
   if (refInter->getPurpose() == AbstractInterface::Data) {
@@ -42,6 +41,10 @@ InterfaceItem::InterfaceItem(){
   this->id = counter++;
 }
 
+QString InterfaceItem::getName() {
+  return refInter->getName();
+}
+
 /* boundingRect() : give the bounding rect in the blockitem coord. system */
 QRectF InterfaceItem::boundingRect() const {
 
@@ -364,11 +367,11 @@ void InterfaceItem::unconnectTo(InterfaceItem *iface)
     iface->refInter->connectFrom(NULL);
   }
   if(iface->refInter->getConnectedTo().contains(refInter)){
-    cout << "abnormal case while removing iface conn from " << qPrintable(name) << " to " << qPrintable(iface->name) << endl;
+    cout << "abnormal case while removing iface conn from " << qPrintable(refInter->getName()) << " to " << qPrintable(iface->refInter->getName()) << endl;
     iface->refInter->removeConnectedTo(refInter);
   }
   if(refInter->getConnectedFrom() == iface->refInter) {
-    cout << "abnormal case while removing iface conn from " << qPrintable(name) << " to " << qPrintable(iface->name) << endl;
+    cout << "abnormal case while removing iface conn from " << qPrintable(refInter->getName()) << " to " << qPrintable(iface->refInter->getName()) << endl;
     refInter->connectFrom(NULL);
   }
   if(refInter->getConnectedTo().contains(iface->refInter)){
index ce65b9e04605aa58229abb5cfa198d2260e1230b..ef3b58d4c6ab4e41193fcff04bca65900a7b58ef 100644 (file)
@@ -30,7 +30,7 @@ public:
 
   // getters
   inline int getId() { return id; }
-  inline QString getName() { return name; }
+  QString getName();
   inline double getPositionRatio() { return positionRatio; }
   inline double getPosition() { return position; }
   inline int getOrientation() { return orientation; }
@@ -43,8 +43,7 @@ public:
 
   // setters
   void setOriginPoint();
-  inline void setId(int id){ this->id = id; }
-  inline void setName(QString name){ this->name = name; }
+  inline void setId(int id){ this->id = id; }  
   inline void setPositionRatio(double ratio) { positionRatio = ratio; }
   inline void setOrientation(int _orientation){ orientation = _orientation; }
 
@@ -68,8 +67,7 @@ public:
 
 
 private:
-  int id;
-  QString name;
+  int id;  
   double positionRatio;
   int position; // position in pixels on the "orientation side" of the owner
   int orientation; // north, south, east, west
index e9f841475ce352d735c9b879b8b83a81571bbeb4..6afabcdcf21aabdb040159e13bec859acf1e6567 100644 (file)
@@ -271,11 +271,12 @@ void MainWindow::slotLoadProject(){
     if (topGroup != NULL) {
       addTopGroup(topGroup);
       library->updateComboScene();
+      params->isCurrentProject = true;
+      enableProjectActions(true, PROJECT_CLOSE | PROJECT_SAVE | PROJECT_SAVEAS | PROJECT_LIB, OP_RAZ);
     }
     else {
       QMessageBox msgBox;
-      msgBox.setText("Cannot open the project.");
-      msgBox.setInformativeText("Do you want to save your changes?");
+      msgBox.setText("Cannot open the project.");      
       msgBox.setStandardButtons(QMessageBox::Cancel);
       msgBox.setDefaultButton(QMessageBox::Cancel);
 
@@ -294,21 +295,46 @@ void MainWindow::slotNewProject(){
   params->isCurrentProject = true;
 }
 
-void MainWindow::slotCloseProject(){
+bool MainWindow::slotCloseProject(){
 
-  // removing the GroupWidget from stack
-  QWidget *widget = stackedWidget->widget(1);
-  stackedWidget->removeWidget(widget);
-  stackedWidget->setCurrentIndex(0);
+  bool doClose = false;
 
-  dispatcher->closeCurrentProject();
+  if(params->isCurrentProject) {
+    if (params->unsaveModif) {
+      QMessageBox msgBox;
+      msgBox.setText("The project has been modified.");
+      msgBox.setInformativeText("Do you want to save your changes?");
+      msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+      msgBox.setDefaultButton(QMessageBox::Save);
 
+      int ret = msgBox.exec();
 
-  params->isCurrentProject = false;
-  params->unsaveModif = false;
-  absoluteFilename = QString();
+      switch(ret) {
+      case QMessageBox::Save :
+        slotSaveProject();
+        doClose = true;
+        break;
+      case QMessageBox::Discard :
+        doClose = true;
+        break;
+      }
+    }
+    if (doClose) {
+      // removing the GroupWidget from stack
+      QWidget *widget = stackedWidget->widget(1);
+      stackedWidget->removeWidget(widget);
+      stackedWidget->setCurrentIndex(0);
 
-  initialize();
+      dispatcher->closeCurrentProject();
+
+      params->isCurrentProject = false;
+      params->unsaveModif = false;
+      absoluteFilename = QString();
+
+      initialize();
+    }
+  }
+  return doClose;
 }
 
 
@@ -358,29 +384,13 @@ void MainWindow::removeTopGroup() {
   stackedWidget->setCurrentIndex(0);
 }
 
-void MainWindow::closeEvent(QCloseEvent *event){
-  if(params->isCurrentProject){
-    QMessageBox msgBox;
-    msgBox.setText("The project has been modified.");
-    msgBox.setInformativeText("Do you want to save your changes?");
-    msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
-    msgBox.setDefaultButton(QMessageBox::Save);
-
-    int ret = msgBox.exec();
-
-    switch(ret) {
-    case QMessageBox::Save :
-      slotSaveProject();
-      slotCloseProject();
-      break;
-    case QMessageBox::Discard :
-      slotCloseProject();
-      break;
-    }
+void MainWindow::closeEvent(QCloseEvent *event) {
+
+  if (params->isCurrentProject) {
+    slotCloseProject();
     event->ignore();
-  } else {
-    exit(0);
   }
+
 }
 
 void MainWindow::mousePressEvent(QMouseEvent *e) {
index 28feaffdbb9f4a8e614b3509896999ba9d91854b..2dee56c9a236b48cde3343c7698343dece5bc474 100644 (file)
@@ -115,7 +115,7 @@ private slots:
   void slotLoadProject();
   void slotSaveProject();
   void slotSaveAsProject();
-  void slotCloseProject();
+  bool slotCloseProject();
   void slotOpenBlockLibrary();
 
   void slotNewBlockWidget();  
index fce043506b96dce7c4a8ccb6962ceb386345dd11..4fd583d614d70201cb92fff7132b4c06c7fb381c 100644 (file)
@@ -189,115 +189,64 @@ QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Ex
   return root;\r
 }\r
 \r
-void Parameters::loadProject(QDomElement root) {\r
-\r
-#ifdef DEBUG_INCLFUN\r
+GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {\r
 \r
   bool ok = false;\r
   GroupWidget* groupWidget = NULL;\r
   GroupItem *groupItem = NULL;\r
   GroupBlock *groupBlock = NULL;\r
 \r
+  GroupWidget* topGroup = NULL;\r
   /**********************************************************\r
    1 : getting scene and creating associated group widgets\r
   ***********************************************************/\r
   QDomNodeList scenesNodes = root.elementsByTagName("scene");\r
 \r
+  int maxIdScene = -1;\r
   for(int i=0; i<scenesNodes.length(); i++) {\r
     QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
     int idScene = currentSceneNode.attribute("id","none").toInt(&ok);\r
     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+    if (idScene > maxIdScene) maxIdScene = idScene;\r
     int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);\r
     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
 \r
     if (idUpperScene == -1) {\r
-      dispatcher->createTopScene();\r
+      topGroup = dispatcher->createTopScene();\r
       topScene->setId(idScene);\r
-      groupItem = topScene->getGroupItem();\r
-      groupBlock = AB_TO_GRP(groupItem->getRefBlock());\r
+      groupItem = topScene->getGroupItem();      \r
       cout << "top group added to scene n°" << idScene << endl;\r
     }\r
     else {\r
-      GroupScene* scene = searchSceneById(idUpperScene, topScene);\r
-      GroupWidget* parent = scene->getGroupWindow();\r
-      groupWidget = dispatcher->createChildScene(parent);\r
-      groupItem = groupWidget->getScene()->getGroupItem();\r
-      groupBlock = AB_TO_GRP(groupItem->getRefBlock());\r
+      cout << "trying to create scene n°" << idScene << " with upper scene n°" <<idUpperScene << endl;\r
+      GroupScene* upperScene = searchSceneById(idUpperScene, topScene);\r
+      groupWidget = dispatcher->addNewEmptyGroup(upperScene,false);\r
+      groupWidget->getScene()->setId(idScene);\r
+      groupItem = groupWidget->getScene()->getGroupItem();      \r
     }\r
+    groupBlock = AB_TO_GRP(groupItem->getRefBlock());\r
     /**********************************************************\r
-     1.1 : getting the group item\r
+     1.1 : getting the group item of each scene\r
     ***********************************************************/\r
     QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");\r
-\r
-    int id = groupItemNode.attribute("id","none").toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-    QString name = groupItemNode.attribute("name","none");\r
-    if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-    QStringList positionStr = groupItemNode.attribute("position","none").split(",");\r
-    if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
-    int posX = positionStr.at(0).toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-    int posY = positionStr.at(1).toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-    QStringList dimensionStr = groupItemNode.attribute("dimension","none").split(",");\r
-    if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
-    int dimX = dimensionStr.at(0).toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-    int dimY = dimensionStr.at(1).toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-    groupItem->setId(id);\r
-    groupItem->setPos(posX,posY);\r
-    groupItem->setDimension(dimX,dimY);\r
-    groupBlock->setName(name);\r
+    try {\r
+      groupItem->load(groupItemNode);\r
+    }\r
+    catch(Exception err) {\r
+      throw(err);\r
+    }\r
 \r
     if (idUpperScene != -1) {\r
       groupWidget->setWindowTitle(groupBlock->getName());\r
       groupWidget->show();\r
-    }\r
-    cout << "group info : \n-id : " << id << "\n-pos : " << posX << ", " << posY << "\n-dim : " << dimX << ", " << dimY << "\n-name : " << name.toStdString() << endl;\r
-\r
-    QDomNodeList interfaces = groupItemNode.elementsByTagName("group_iface");\r
-    for(int j=0; j<interfaces.length(); j++){\r
-      QDomElement currentInterfaceNode = interfaces.at(j).toElement();\r
-\r
-      int id = currentInterfaceNode.attribute("id","none").toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString name = currentInterfaceNode.attribute("name","none");\r
-      if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString levelStr = currentInterfaceNode.attribute("level","none");\r
-      int level = AbstractInterface::getIntLevel(levelStr);\r
-      if(level == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString directionStr = currentInterfaceNode.attribute("direction","none");\r
-      int direction = AbstractInterface::getIntDirection(directionStr);\r
-      if(direction == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString orientationStr = currentInterfaceNode.attribute("orientation","none");\r
-      int orientation = InterfaceItem::getIntOrientation(orientationStr);\r
-      if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,level);\r
-\r
-      InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupInterface,groupItem,this);\r
-      interfaceItem->setId(id);\r
-\r
-      groupBlock->addInterface(groupInterface);\r
-      groupItem->addInterface(interfaceItem);\r
-      cout << "interface add to " << groupBlock->getName().toStdString() << endl;\r
-    }\r
+    }    \r
   }\r
-\r
+  dispatcher->setSceneCounter(maxIdScene+1);\r
   cout << "groupItems loaded and windows created succefully!" << endl;\r
 \r
+  /**********************************************************\r
+   2 : getting the functional blocks of each scene\r
+  ***********************************************************/\r
 \r
   for(int i=0; i<scenesNodes.length(); i++){\r
     QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
@@ -310,134 +259,24 @@ void Parameters::loadProject(QDomElement root) {
 \r
     QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");\r
 \r
-    for(int j=0; j<functionalBlockNodes.length(); j++){\r
-      QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();\r
-\r
-      int id = currentFBNode.attribute("id","none").toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString refXml = currentFBNode.attribute("ref_xml","none");\r
-      if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString refMd5 = currentFBNode.attribute("ref_md5","none");\r
-      if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;\r
-\r
-      QString name = currentFBNode.attribute("name","none");\r
-      if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QStringList positionStr = currentFBNode.attribute("position","none").split(",");\r
-      if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
-      int posX = positionStr.at(0).toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-      int posY = positionStr.at(1).toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QStringList dimensionStr = currentFBNode.attribute("dimension","none").split(",");\r
-      if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
-      int dimX = dimensionStr.at(0).toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-      int dimY = dimensionStr.at(1).toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      AbstractBlock *reference;\r
-      /*if(refMd5 != "none"){\r
-        cout << "md5" << endl;\r
-        reference = searchBlockByMd5(refMd5);\r
-      }\r
-      else */if(refXml != "none"){\r
-        cout << "xml" << endl;\r
-        reference = searchBlockByXml(refXml);\r
-      }\r
-      else {\r
-        throw(Exception(PROJECTFILE_CORRUPTED));\r
-      }\r
-\r
-      FunctionalBlock *functionalBlock = new FunctionalBlock(currentScene->getGroupItem()->getRefBlock(),reference);\r
-      functionalBlock->setName(name);\r
-\r
-      ((GroupBlock*)currentScene->getGroupItem()->getRefBlock())->addBlock(functionalBlock);\r
-\r
-\r
-      BlockItem *blockItem = new BlockItem(currentScene->getGroupItem(),functionalBlock,dispatcher,this);\r
-      blockItem->setPos(posX,posY);\r
-      blockItem->setDimension(dimX,dimY);\r
-      blockItem->setId(id);\r
-      ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);\r
-      currentScene->addItem(blockItem);\r
-      currentScene->addBlockItem(blockItem);\r
-\r
-      QDomNodeList blockParamNodes = currentFBNode.elementsByTagName("bif_parameter");\r
-\r
-      for(int i=0; i<blockParamNodes.length(); i++){\r
-        QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();\r
-\r
-        QString name = currentBlockParamNode.attribute("name","none");\r
-        if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString value = currentBlockParamNode.attribute("value","none");\r
-        if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString context = currentBlockParamNode.attribute("context","none");\r
-        if(context == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString type = currentBlockParamNode.attribute("type","none");\r
-        if(type == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-\r
-        BlockParameter *blockParam = new BlockParameter;\r
-        blockParam->setName(name);\r
-        blockParam->setValue(value);\r
-        blockParam->setType(type);\r
-        if(context == "constant") blockParam->setContext(BlockParameter::Constant);\r
-        if(context == "user") blockParam->setContext(BlockParameter::User);\r
-        if(context == "generic") blockParam->setContext(BlockParameter::Generic);\r
-        if(context == "wb") blockParam->setContext(BlockParameter::Wishbone);\r
-        if(context == "port") blockParam->setContext(BlockParameter::Port);\r
-\r
-        functionalBlock->addParameter(blockParam);\r
+    for(int j=0; j<functionalBlockNodes.length(); j++) {\r
+      QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();      \r
+      BoxItem* funcItem = new BoxItem(dispatcher,this, currentScene->getGroupItem());\r
+      try {\r
+        funcItem->loadFunctional(currentFBNode);\r
       }\r
-\r
-\r
-      QDomNodeList interfaceNodes = currentFBNode.elementsByTagName("bif_iface");\r
-\r
-      for(int i=0; i<interfaceNodes.length(); i++){\r
-\r
-        QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();\r
-\r
-        int id = currentInterfaceNode.attribute("id","none").toInt(&ok);\r
-        if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString name = currentInterfaceNode.attribute("name","none");\r
-        if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString refName = currentInterfaceNode.attribute("ref_name","none");\r
-        if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString orientationStr = currentInterfaceNode.attribute("orientation","none");\r
-        int orientation = InterfaceItem::getIntOrientation(orientationStr);\r
-        if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
-        if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        ReferenceInterface *refInter = (ReferenceInterface*)reference->getIfaceFromName(refName);\r
-        FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);\r
-        functionalBlock->addInterface(functionalInterface);\r
-        functionalInterface->setName(refName);\r
-\r
-        InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,functionalInterface,blockItem,this);\r
-        interfaceItem->setId(id);\r
-        interfaceItem->setName(name);\r
-\r
-        blockItem->addInterface(interfaceItem);\r
-\r
+      catch(Exception err) {\r
+        throw(err);\r
       }\r
+      // add the block to the GroupScene\r
+      currentScene->addBlockItem(funcItem);\r
     }\r
   }\r
-  cout << "functionalBlocks loaded and created succefully!" << endl;\r
+  cout << "functional blocks loaded and created succefully!" << endl;\r
 \r
+  /**********************************************************\r
+   3 : set the BoxItem that represents a GroupItem in a child scene\r
+  ***********************************************************/\r
 \r
   for(int i=0; i<scenesNodes.length(); i++){\r
     QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
@@ -471,19 +310,27 @@ void Parameters::loadProject(QDomElement root) {
       int dimY = dimensionStr.at(1).toInt(&ok);\r
       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
 \r
-\r
+      // get the GroupItem already created and set at phase 1\r
       GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);\r
+      BoxItem* upperItem = NULL;\r
       if(insideGroup == NULL) cout << "group null" << endl;\r
-      BlockItem *blockItem = new BlockItem(insideGroup->getRefBlock(), dispatcher, this);\r
-      blockItem->setChildGroupItem(insideGroup);\r
-      blockItem->setId(id);\r
-      blockItem->setPos(posX,posY);\r
-      blockItem->setDimension(dimX,dimY);\r
+      // now search within the scene which BoxItem has a childItem that is = to insideGroup\r
+      QList<BoxItem *> lst = currentScene->getBlockItems();\r
+      foreach(BoxItem* item, lst) {\r
+        if (item->getChildGroupItem() == insideGroup) {\r
+          upperItem = item;\r
+          break;\r
+        }\r
+      }\r
+      if (upperItem == NULL) {\r
+        throw(Exception(PROJECTFILE_CORRUPTED));\r
+      }\r
 \r
-      ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);\r
-      currentScene->addItem(blockItem);\r
-      currentScene->addBlockItem(blockItem);\r
+      upperItem->setId(id);\r
+      upperItem->setPos(posX,posY);\r
+      upperItem->setDimension(dimX,dimY);\r
 \r
+      // set interfaces of this BoxItem\r
       QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");\r
 \r
       for(int k=0; k<interfaceNodes.length(); k++){\r
@@ -502,34 +349,15 @@ void Parameters::loadProject(QDomElement root) {
         double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
         if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
 \r
-        GroupInterface *refInter = (GroupInterface*)insideGroup->searchInterfaceByName(refName)->refInter;\r
-        InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, blockItem, this);\r
+        ConnectedInterface *refInter = insideGroup->searchInterfaceByName(refName)->refInter;\r
+        InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this);\r
         ifaceItem->setId(id);\r
-        blockItem->addInterface(ifaceItem);\r
+        upperItem->addInterface(ifaceItem);\r
       }\r
     }\r
   }\r
   cout << "blockItems \"group\" loaded and created succefully!" << endl;\r
 \r
-\r
-  for(int i=0; i<scenesNodes.length(); i++){\r
-    QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
-\r
-    QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");\r
-\r
-    int id = groupItemNode.attribute("id","none").toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-    int idUpperItem = groupItemNode.attribute("upper_item","none").toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-    BlockItem *currentItem = searchBlockItemById(id,topScene);\r
-    GroupItem *upperItem = searchGroupItemById(idUpperItem, topScene);\r
-\r
-    if(currentItem != NULL && upperItem != NULL){\r
-      currentItem->setUpperItem(upperItem);\r
-    }\r
-  }\r
-\r
   QDomNodeList connectionNodes = root.elementsByTagName("connection");\r
 \r
   for(int i=0; i<connectionNodes.length(); i++){\r
@@ -551,8 +379,9 @@ void Parameters::loadProject(QDomElement root) {
       cout << "interfaces not found, connect canceled!" << endl;\r
     }\r
   }\r
+  cout << "connections loaded and created succefully!" << endl;\r
 \r
-#endif\r
+  return topGroup;\r
 }\r
 \r
 void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {\r
index 7f14814a7ff904ca663423de50f5515e5b0d44aa..a152f1cca2c41549113c9f63ddf0d9f34454ce37 100644 (file)
@@ -20,6 +20,7 @@ class GroupItem;
 class BoxItem;\r
 class InterfaceItem;\r
 class Graph;\r
+class GroupWidget;\r
 \r
 #include "BlockImplementation.h"\r
 \r
@@ -128,7 +129,7 @@ public :
   void clear();\r
 \r
   QDomElement openProjectFile(const QString& projectFileName) throw(Exception);\r
-  void loadProject(QDomElement root);\r
+  GroupWidget *loadProject(QDomElement root) throw(Exception);\r
 \r
   void loadBlastConfiguration(QString confFile) throw(Exception);\r
   void loadReferencesFromXml() throw(Exception);\r
index 9930e199a3471549367574c3c58802a07811595c..b7f7e1d9bc01fac06a04454c131f7b3ba3f71696 100755 (executable)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 3.2.1, 2017-04-27T20:11:44. -->
+<!-- Written by QtCreator 3.2.1, 2017-05-03T08:26:25. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
index 8a35bc97f28d73e4c446eb0746620651ae4745ff..e5693dc66ebb444a2016c2981b3ea54a09ee1cac 100644 (file)
        </xs:simpleType>
     </xs:attribute>
 
+    <xs:attribute name="upper_scene">
+       <xs:simpleType>
+           <xs:restriction base="xs:integer">
+               <xs:minInclusive value="-1"/>
+           </xs:restriction>
+       </xs:simpleType>
+    </xs:attribute>
+
     <xs:attribute name="upper_group">
        <xs:simpleType>
            <xs:restriction base="xs:integer">
        <xs:complexType>
            <xs:group ref="sceneElmtGroup"/>
            <xs:attribute ref="id"/>
+           <xs:attribute ref="upper_scene"/>
        </xs:complexType>
     </xs:element>