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

Private GIT Repository
start modifying read/write blocks and project to take into account control ifaces
[blast.git] / Dispatcher.cpp
index b6495bb4b536cb03706dc9acdb108b1f27958506..ac0862ca64a60e8508b411643a8c3b08f3e0b49a 100644 (file)
@@ -224,28 +224,40 @@ void Dispatcher::renameInterface(InterfaceItem *item) {
   cout << "call to " << qPrintable(fctName) << endl;
 #endif
 
   cout << "call to " << qPrintable(fctName) << endl;
 #endif
 
-  bool ok;
-  QString text = QInputDialog::getText(NULL, "Rename an interface",
+  bool ok = false;
+  QString text = "";
+  while (!ok) {
+    text = QInputDialog::getText(NULL, "Rename an interface",
                                        "New name:", QLineEdit::Normal,
                                        item->refInter->getName(), &ok);
                                        "New name:", QLineEdit::Normal,
                                        item->refInter->getName(), &ok);
-
-  /* CAUTION: when renaming an interface item, there are two cases :
-     - it refers to a functional block interface (fbi): the fbi keeps its name
-     and the new name is given to item
-     - it refers to a group block interface (gbi) : both gbi and item store the new name
-
-   */
-  if(ok && !text.isEmpty() && text.length() < 30) {
-    if (item->refInter->getOwner()->isGroupBlock()) {
-      item->refInter->setName(text);
+   
+    if (!ok) return;
+    
+    if (text == item->refInter->getName()) return;
+    
+    if( (text.isEmpty()) || (text.length() > 30)) {
+      QMessageBox::warning(NULL,"Error in given name",
+                           "the interface name must be shorter than 30 characters, cannot be empty",
+                           QMessageBox::Ok);
+      ok = false;
+    }
+    else {
+      AbstractInterface* iface = item->refInter->getOwner()->getIfaceFromName(text);
+      if (iface != NULL) {
+        QMessageBox::warning(NULL,"Error in given name",
+                             "the name provided is similar to that of another interface",
+                             QMessageBox::Ok);
+        ok = false;
+      }
     }
   }
     }
   }
-  else {
-    QMessageBox::warning(NULL,"Error in given name",
-                         "the interface name must be shorter than 30 characters and can't be empty!",
-                         QMessageBox::Ok);
-    renameInterface(item);
+  item->refInter->setName(text);
+  AbstractInterface* assoIface = item->refInter->getAssociatedIface();
+  if (assoIface != NULL) {
+    assoIface->setName(text+"_ctl");
   }
   }
+  item->updateName(text);
+  item->getOwner()->interfaceRenamed();  
 }
 
 void Dispatcher::duplicateBlock(BoxItem *item){
 }
 
 void Dispatcher::duplicateBlock(BoxItem *item){
@@ -284,16 +296,26 @@ void Dispatcher::duplicateInterface(InterfaceItem *item) {
   if(! refB->isFunctionalBlock()) return;
 
   FunctionalInterface* iface = (FunctionalInterface*)refI;
   if(! refB->isFunctionalBlock()) return;
 
   FunctionalInterface* iface = (FunctionalInterface*)refI;
-  AbstractInterface *otherRef = iface->clone();
-  if (otherRef == NULL) {
+  AbstractInterface *cloneIface = iface->clone();
+  if (cloneIface == NULL) {
     QMessageBox::warning(NULL,"Error while cloning an interface","the interface cannot be cloned because its maximum multiplicity is reached", QMessageBox::Ok);
     return;
   }
 
     QMessageBox::warning(NULL,"Error while cloning an interface","the interface cannot be cloned because its maximum multiplicity is reached", QMessageBox::Ok);
     return;
   }
 
-  refB->addInterface(otherRef);
+  refB->addInterface(cloneIface);
 
 
-  InterfaceItem *otherIface = new InterfaceItem(item->getPosition(),item->getOrientation(),(ConnectedInterface*)otherRef,item->getOwner(),params);
-  item->getOwner()->addInterface(otherIface,true);
+  InterfaceItem *cloneIfaceItem = new InterfaceItem(item->getPosition(),item->getOrientation(),(ConnectedInterface*)cloneIface,item->getOwner(),params);
+  item->getOwner()->addInterface(cloneIfaceItem,true);
+  
+  // creating control interface if needed
+  if (refI->getAssociatedIface() != NULL) {
+    QString ctlName = cloneIface->getName()+"_ctl";
+    ReferenceInterface* ctlIface = new ReferenceInterface(refB,ctlName,"boolean","1",cloneIface->getDirection(), AbstractInterface::Control, 1);
+    refB->addInterface(ctlIface);
+    if (! ctlIface->setAssociatedIface(cloneIface)) {
+      cerr << "Abnormal case while cloning an interface and creating its associated control interface" << endl;
+    }
+  }
 }
 
 
 }
 
 
@@ -814,7 +836,7 @@ void Dispatcher::connectInterToGroup(InterfaceItem *item){
   GroupItem *parentItem = item->getOwner()->getScene()->getGroupItem();
 
   // creating/adding the group interface in the graph model
   GroupItem *parentItem = item->getOwner()->getScene()->getGroupItem();
 
   // creating/adding the group interface in the graph model
-  GroupInterface *groupInter = new GroupInterface(parentBlock,refInter->getName()+"_group",refInter->getDirection());
+  GroupInterface *groupInter = new GroupInterface(parentBlock,refInter->getName()+"_group",refInter->getDirection(),refInter->getPurpose());
   groupInter->setType(refInter->getType());
   groupInter->setWidth(refInter->getWidth());
   groupInter->setPurpose(refInter->getPurpose());
   groupInter->setType(refInter->getType());
   groupInter->setWidth(refInter->getWidth());
   groupInter->setPurpose(refInter->getPurpose());
@@ -956,7 +978,7 @@ void Dispatcher::disconnectInterFromGroup(InterfaceItem *item) {
 #endif
 
 }
 #endif
 
 }
-void Dispatcher::removeBlockInterface(InterfaceItem *item) {
+void Dispatcher::removeFunctionalInterface(InterfaceItem *item) {
   static QString fctName = "Dispatcher::removeBlockInterface()";
 #ifdef DEBUG_FCTNAME
   cout << "call to " << qPrintable(fctName) << endl;
   static QString fctName = "Dispatcher::removeBlockInterface()";
 #ifdef DEBUG_FCTNAME
   cout << "call to " << qPrintable(fctName) << endl;