X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/abbc64cf04a35ab3549d5c516f44c7c5921baa63..107509468a60f3e9e698d82a2575b700d9dde07e:/Parameters.cpp diff --git a/Parameters.cpp b/Parameters.cpp index c991e5f..af8eb22 100644 --- a/Parameters.cpp +++ b/Parameters.cpp @@ -69,37 +69,23 @@ void Parameters::destroyGraph() { delete graph; } -GroupBlock* Parameters::addGroupBlock() { - GroupBlock* parent = AB_TO_GRP(currentScene->getGroupItem()->getRefBlock()); - GroupBlock* newOne = graph->createChildBlock(parent); - return newOne; -} - -FunctionalBlock* Parameters::addFunctionalBlock(int idCategory, int idBlock) { +ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) { BlockCategory* blockCat = categoryTree->searchCategory(idCategory); if (blockCat == NULL) return NULL; - GroupBlock* group = AB_TO_GRP(currentScene->getGroupItem()->getRefBlock()); ReferenceBlock* ref = blockCat->getBlock(idBlock); - if (ref == NULL) return NULL; - - FunctionalBlock* newOne = graph->addFunctionalBlock(group, ref); - unsaveModif = true; - - return newOne; + return ref; } + FunctionalBlock* Parameters::duplicateFunctionalBlock(FunctionalBlock *block) { ReferenceBlock* ref = block->getReference(); GroupBlock* group = AB_TO_GRP(block->getParent()); - // adding to the group - FunctionalBlock* newBlock = new FunctionalBlock(group,ref); - newBlock->populate(); - group->addBlock(newBlock); - + // adding to the graph + FunctionalBlock* newBlock = graph->addFunctionalBlock(group,ref); return newBlock; } @@ -203,115 +189,64 @@ QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Ex return root; } -void Parameters::loadProject(QDomElement root) { - -#ifdef DEBUG_INCLFUN +GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { bool ok = false; GroupWidget* groupWidget = NULL; GroupItem *groupItem = NULL; GroupBlock *groupBlock = NULL; + GroupWidget* topGroup = NULL; /********************************************************** 1 : getting scene and creating associated group widgets ***********************************************************/ QDomNodeList scenesNodes = root.elementsByTagName("scene"); + int maxIdScene = -1; for(int i=0; i maxIdScene) maxIdScene = idScene; int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok); if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); if (idUpperScene == -1) { - dispatcher->createTopScene(); + topGroup = dispatcher->createTopScene(); topScene->setId(idScene); - groupItem = topScene->getGroupItem(); - groupBlock = AB_TO_GRP(groupItem->getRefBlock()); + groupItem = topScene->getGroupItem(); cout << "top group added to scene n°" << idScene << endl; } else { - GroupScene* scene = searchSceneById(idUpperScene, topScene); - GroupWidget* parent = scene->getGroupWindow(); - groupWidget = dispatcher->createChildScene(parent); - groupItem = groupWidget->getScene()->getGroupItem(); - groupBlock = AB_TO_GRP(groupItem->getRefBlock()); + cout << "trying to create scene n°" << idScene << " with upper scene n°" <addNewEmptyGroup(upperScene,false); + groupWidget->getScene()->setId(idScene); + groupItem = groupWidget->getScene()->getGroupItem(); } + groupBlock = AB_TO_GRP(groupItem->getRefBlock()); /********************************************************** - 1.1 : getting the group item + 1.1 : getting the group item of each scene ***********************************************************/ QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item"); - - int id = groupItemNode.attribute("id","none").toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - QString name = groupItemNode.attribute("name","none"); - if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - QStringList positionStr = groupItemNode.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 = groupItemNode.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)); - - groupItem->setId(id); - groupItem->setPos(posX,posY); - groupItem->setDimension(dimX,dimY); - groupBlock->setName(name); + try { + groupItem->load(groupItemNode); + } + catch(Exception err) { + throw(err); + } if (idUpperScene != -1) { groupWidget->setWindowTitle(groupBlock->getName()); groupWidget->show(); - } - cout << "group info : \n-id : " << id << "\n-pos : " << posX << ", " << posY << "\n-dim : " << dimX << ", " << dimY << "\n-name : " << name.toStdString() << endl; - - QDomNodeList interfaces = groupItemNode.elementsByTagName("group_iface"); - for(int j=0; jsetId(id); - - groupBlock->addInterface(groupInterface); - groupItem->addInterface(interfaceItem); - cout << "interface add to " << groupBlock->getName().toStdString() << endl; - } + } } - + dispatcher->setSceneCounter(maxIdScene+1); cout << "groupItems loaded and windows created succefully!" << endl; + /********************************************************** + 2 : getting the functional blocks of each scene + ***********************************************************/ for(int i=0; igetGroupItem()->getRefBlock(),reference); - functionalBlock->setName(name); - - ((GroupBlock*)currentScene->getGroupItem()->getRefBlock())->addBlock(functionalBlock); - - - BlockItem *blockItem = new BlockItem(currentScene->getGroupItem(),functionalBlock,dispatcher,this); - blockItem->setPos(posX,posY); - blockItem->setDimension(dimX,dimY); - blockItem->setId(id); - ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem); - currentScene->addItem(blockItem); - currentScene->addBlockItem(blockItem); - - QDomNodeList blockParamNodes = currentFBNode.elementsByTagName("bif_parameter"); - - for(int i=0; isetName(name); - blockParam->setValue(value); - blockParam->setType(type); - if(context == "constant") blockParam->setContext(BlockParameter::Constant); - if(context == "user") blockParam->setContext(BlockParameter::User); - if(context == "generic") blockParam->setContext(BlockParameter::Generic); - if(context == "wb") blockParam->setContext(BlockParameter::Wishbone); - if(context == "port") blockParam->setContext(BlockParameter::Port); - - functionalBlock->addParameter(blockParam); + for(int j=0; jgetGroupItem()); + try { + funcItem->loadFunctional(currentFBNode); } - - - QDomNodeList interfaceNodes = currentFBNode.elementsByTagName("bif_iface"); - - for(int i=0; igetIfaceFromName(refName); - FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter); - functionalBlock->addInterface(functionalInterface); - functionalInterface->setName(refName); - - InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,functionalInterface,blockItem,this); - interfaceItem->setId(id); - interfaceItem->setName(name); - - blockItem->addInterface(interfaceItem); - + catch(Exception err) { + throw(err); } + // add the block to the GroupScene + currentScene->addBlockItem(funcItem); } } - cout << "functionalBlocks loaded and created succefully!" << endl; + cout << "functional blocks loaded and created succefully!" << endl; + /********************************************************** + 3 : set the BoxItem that represents a GroupItem in a child scene + ***********************************************************/ for(int i=0; igetRefBlock(), dispatcher, this); - blockItem->setChildGroupItem(insideGroup); - blockItem->setId(id); - blockItem->setPos(posX,posY); - blockItem->setDimension(dimX,dimY); + // now search within the scene which BoxItem has a childItem that is = to insideGroup + QList lst = currentScene->getBlockItems(); + foreach(BoxItem* item, lst) { + if (item->getChildGroupItem() == insideGroup) { + upperItem = item; + break; + } + } + if (upperItem == NULL) { + throw(Exception(PROJECTFILE_CORRUPTED)); + } - ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem); - currentScene->addItem(blockItem); - currentScene->addBlockItem(blockItem); + upperItem->setId(id); + upperItem->setPos(posX,posY); + upperItem->setDimension(dimX,dimY); + // set interfaces of this BoxItem QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface"); for(int k=0; ksearchInterfaceByName(refName)->refInter; - InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, blockItem, this); + ConnectedInterface *refInter = insideGroup->searchInterfaceByName(refName)->refInter; + InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this); ifaceItem->setId(id); - blockItem->addInterface(ifaceItem); + upperItem->addInterface(ifaceItem); } } } cout << "blockItems \"group\" loaded and created succefully!" << endl; - - for(int i=0; isetUpperItem(upperItem); - } - } - QDomNodeList connectionNodes = root.elementsByTagName("connection"); for(int i=0; igetBlockItems().length(); for(int i = 0; igetBlockItems().at(i)->isSelected()){ - currentScene->getGroupWindow()->enableGroupButton(true); + currentScene->getGroupWidget()->enableGroupButton(true); return; } } - currentScene->getGroupWindow()->enableGroupButton(false); + currentScene->getGroupWidget()->enableGroupButton(false); } @@ -1098,9 +913,6 @@ void Parameters::save(QString confFile) { // cross the scene level by level using a FIFO QList fifoScene; fifoScene.append(topScene); - foreach(ConnectionItem* item, topScene->getConnectionItems()) { - allConnections.append(item); - } GroupScene *scene; while (!fifoScene.isEmpty()) { @@ -1109,11 +921,12 @@ void Parameters::save(QString confFile) { foreach(GroupScene* s, scene->getChildrenScene()) { fifoScene.append(s); } - foreach(ConnectionItem* item, topScene->getConnectionItems()) { + + foreach(ConnectionItem* item, scene->getConnectionItems()) { allConnections.append(item); } } - + writer.writeEndElement(); // writer.writeStartElement("connections"); foreach(ConnectionItem* item, allConnections) {