MetaGear* Schema::newMetaGear() { std::string name="MetaGear"; return addMetaGear(name, getUniqueGearName(name)); }
bool Schema::load(QDomElement& parent, bool pasting, int dx, int dy) { std::vector<Gear*> addedGears; QDomNode gearsNode = XMLHelper::findChildNode(parent, "Gears"); // when pasting, gears have to be renamed std::map<std::string,std::string> renameMap; if (gearsNode.isNull()) { std::cout << "Bad DroneSchema : <Gears> tag not found!" << std::endl; return false; } QDomNode gearNode = gearsNode.firstChild(); Gear *pgear=NULL; while (!gearNode.isNull()) { QDomElement gearElem = gearNode.toElement(); if (!gearElem.isNull()) { std::string type = gearElem.attribute("Type","").ascii(); if (type == MetaGear::TYPE) //we default the name to metagear, but the name will be overwrited in the load of the metagear itself pgear = addMetaGear("MetaGear", gearElem.attribute("Name","").ascii()); else pgear = addGear(type, gearElem.attribute("Name","").ascii()); if (pgear!=NULL) { pgear->load(gearElem); } addedGears.push_back(pgear); } gearNode = gearNode.nextSibling(); } if(pasting) for(unsigned int i=0;i<addedGears.size();++i) { addedGears[i]->getGearGui()->setSelected(true); std::string newname = getUniqueGearName(addedGears[i]->type()); renameMap[addedGears[i]->name()] = getUniqueGearName(addedGears[i]->type()); std::cerr<<"rename : "<<addedGears[i]->name()<<" to "<<renameMap[addedGears[i]->name()]<<" (newname:) "<<newname<<std::endl; addedGears[i]->name(renameMap[addedGears[i]->name()]); } //load connections QDomNode connectionsNode = XMLHelper::findChildNode(parent, "Connections"); if (connectionsNode.isNull()) { std::cout << "Bad DroneSchema : <Connections> tag not found!" << std::endl; return false; } //iteration on all connections QDomNode connectionNode = connectionsNode.firstChild(); Connection connection; while (!connectionNode.isNull()) { QDomElement connectionElem = connectionNode.toElement(); if (!connectionElem.isNull()) { connection.load(connectionElem); if(pasting) connection.updateWithRenameMapping(renameMap); connect(connection); } connectionNode = connectionNode.nextSibling(); } return true; }
void SchemaEditor::slotMenuMetaGearSelected(QFileInfo* metaGearFileInfo) { addMetaGear(metaGearFileInfo->filePath().ascii(), _contextMenuPos); }