X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/f311fbc3e1436bf248c54225f0743cfa671c4bd7..e5af659f87bcb199d6a5f10f09b311138351d0f3:/Dispatcher.cpp diff --git a/Dispatcher.cpp b/Dispatcher.cpp index b191651..ac0862c 100644 --- a/Dispatcher.cpp +++ b/Dispatcher.cpp @@ -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) { @@ -219,30 +224,40 @@ void Dispatcher::renameInterface(InterfaceItem *item) { 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); - - /* 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; + } } - item->setName(text); - } - 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){ @@ -281,16 +296,26 @@ void Dispatcher::duplicateInterface(InterfaceItem *item) { 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; } - refB->addInterface(otherRef); - - InterfaceItem *otherIface = new InterfaceItem(item->getPosition(),item->getOrientation(),(ConnectedInterface*)otherRef,item->getOwner(),params); - item->getOwner()->addInterface(otherIface,true); + refB->addInterface(cloneIface); + + 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; + } + } } @@ -343,7 +368,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 +385,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 +396,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; } @@ -431,16 +471,23 @@ void Dispatcher::showRaiseWindow(BoxItem *item) { params->setCurrentScene(currentGroup->getScene()); } -void Dispatcher::showRstClkInter(AbstractBoxItem *item) { - static QString fctName = "Dispatcher::showRstClkInter()"; +void Dispatcher::showRstClkIface(AbstractBoxItem *item) { + static QString fctName = "Dispatcher::showRstClkIface()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif item->setRstClkVisible(!item->isRstClkVisible()); - item->resetInterfacesPosition(); + +} + +void Dispatcher::showWishboneIface(AbstractBoxItem *item) { + static QString fctName = "Dispatcher::showWishboneIface()"; +#ifdef DEBUG_FCTNAME + cout << "call to " << qPrintable(fctName) << endl; +#endif - item->getScene()->updateConnectionItemsShape(); + item->setWishboneVisible(!item->isWishboneVisible()); } void Dispatcher::addNewFullGroup() { @@ -789,7 +836,7 @@ void Dispatcher::connectInterToGroup(InterfaceItem *item){ 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(),refInter->getLevel()); + GroupInterface *groupInter = new GroupInterface(parentBlock,refInter->getName()+"_group",refInter->getDirection(),refInter->getPurpose()); groupInter->setType(refInter->getType()); groupInter->setWidth(refInter->getWidth()); groupInter->setPurpose(refInter->getPurpose()); @@ -931,7 +978,7 @@ void Dispatcher::disconnectInterFromGroup(InterfaceItem *item) { #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;