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

Private GIT Repository
adding xsd files to master
[blast.git] / GroupItem.cpp
index fa341b268d166c1de4bee34a0a2b90f3d9b3e061..679cc5e7498310cf06767cc0e9469dc4462a1ae5 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,72 @@ 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 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);
+
+    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");
@@ -597,8 +687,7 @@ void GroupItem::save(QXmlStreamWriter &writer) {
     writer.writeStartElement("group_iface");
 
     writer.writeAttribute("id",QString::number(item->getId()));
-    writer.writeAttribute("name",item->getName());
-    writer.writeAttribute("level",QString(item->refInter->getLevelString()));
+    writer.writeAttribute("name",item->getName());    
     writer.writeAttribute("direction",QString(item->refInter->getDirectionString()));
     writer.writeAttribute("orientation",item->getStrOrientation());
     writer.writeAttribute("position",QString::number(item->getPositionRatio()));