void NetworkConverter11to12::convertVolumeContainer(TiXmlElement* workspaceNode) { if (!workspaceNode) { LERRORC("voreen.NetworkConverter11to12", "no workspace node"); return; } // construct map from Volume-refID to URL std::map<std::string, std::string> refToUrl; TiXmlElement* volumeContainerNode = workspaceNode->FirstChildElement("VolumeContainer"); if (!volumeContainerNode) return; LWARNINGC("voreen.NetworkConverter11to12", "converting volume container ..."); TiXmlElement* volumeHandlesNode = volumeContainerNode->FirstChildElement("VolumeHandles"); if (!volumeHandlesNode) return; for (TiXmlElement* handleNode = volumeHandlesNode->FirstChildElement("VolumeHandle"); handleNode != 0; handleNode = handleNode->NextSiblingElement("VolumeHandle")) { const std::string* refID = handleNode->Attribute(std::string("id")); if (!refID) continue; TiXmlElement* originNode = handleNode->FirstChildElement("Origin"); if (!originNode) continue; const std::string* url = originNode->Attribute(std::string("url")); if (!url) url = originNode->Attribute(std::string("filename")); if (!url) continue; tgtAssert(refID, "no refID"); tgtAssert(url, "no url"); refToUrl.insert(std::pair<std::string, std::string>(*refID, *url)); } // look for VolumeSource processors and replace their VolumeHandleProperty (with specific refID) // with a VolumeURLProperty with the corresponding volume URL TiXmlElement* networkNode = workspaceNode->FirstChildElement("ProcessorNetwork"); if (!networkNode) return; TiXmlElement* processorsNode = networkNode->FirstChildElement("Processors"); if (!processorsNode) return; for (TiXmlElement* procNode = processorsNode->FirstChildElement("Processor"); procNode != 0; procNode = procNode->NextSiblingElement("Processor")) { const std::string* type = procNode->Attribute(std::string("type")); if (!type || *type != "VolumeSource") continue; // it's a VolumeSource => extract VolumeHandleProperty node TiXmlElement* propertiesNode = procNode->FirstChildElement("Properties"); if (!propertiesNode) continue; TiXmlElement* handlePropNode = propertiesNode->FirstChildElement("Property"); if (!handlePropNode) continue; const std::string* propName = handlePropNode->Attribute(std::string("name")); if (!propName || *propName != "volumeHandle") continue; // convert VolumeHandleProperty to VolumeURLProperty handlePropNode->SetAttribute("name", "volumeURL"); // retrieve Volume reference TiXmlElement* valueNode = handlePropNode->FirstChildElement("value"); if (!valueNode) continue; const std::string* refID = valueNode->Attribute(std::string("ref")); if (!refID) continue; // insert referenced URL into converted VolumeHandleProperty if (refToUrl.find(*refID) == refToUrl.end()) LWARNINGC("voreen.NetworkConverter11to12", "convertVolumeContainer(): unknown refID: " << *refID); else handlePropNode->SetAttribute("url", refToUrl[*refID]); } }
/** * Create an Core object reading data from XML file * * @brief Core::loadFromFile * @param path * @return */ Core * Core::loadFromFile(std::string basePath, std::string file) { /* Create the core and run setup() */ Core *it = new Core(); if(!it->setup()) return NULL; /* Load XML file */ TiXmlDocument doc(basePath+file); std::cout << "Loading from file: "<< basePath+file << "... "; if(!doc.LoadFile()) { std::cout << "Failed" << std::endl;; return NULL; } std::cout << "Ok" << std::endl;; TiXmlElement *root = doc.RootElement(); // Terrain TiXmlElement *terrain = root->FirstChildElement("terrain"); if(terrain) { std::string ttype = terrain->Attribute("type"); std::string tpath = terrain->Attribute("path"); // Set terrain std::cout << "\tSetting terrain (" << tpath << ")... "; if(it->setTerrain(basePath+tpath, ttype)) std::cout << "Ok" << std::endl; else std::cout << "Failed" << std::endl; } // Layers TiXmlElement *layers = root->FirstChildElement("layers"); if(layers) { TiXmlElement *layer = layers->FirstChildElement(); while(layer) { std::string ltype = layer->Attribute("type"); std::string lpath = layer->Attribute("path"); std::string lname = layer->Attribute("name"); std::string lmat = layer->Attribute("materials"); // Add layer std::cout << "\tAdding layer (" << lpath << ")... "; if(it->addLayer(lname, basePath+lpath, lmat, ltype)) std::cout << "Ok" << std::endl; else std::cout << "Failed" << std::endl; layer = layer->NextSiblingElement(); } } return it; }
Module* XmlModLoader::parsXml(const char* szFile) { module.clear(); ErrorLogger* logger = ErrorLogger::Instance(); TiXmlDocument doc(szFile); if(!doc.LoadFile()) { OSTRINGSTREAM err; err<<"Syntax error while loading "<<szFile<<" at line "\ <<doc.ErrorRow()<<": "; err<<doc.ErrorDesc(); logger->addError(err); return NULL; } /* retrieving root module */ TiXmlElement *root = doc.RootElement(); if(!root) { OSTRINGSTREAM err; err<<"Syntax error while loading "<<szFile<<" . "; err<<"No root element."; logger->addError(err); return NULL; } if(!compareString(root->Value(), "module")) { /* OSTRINGSTREAM msg; msg<<szFile<<" is not a module descriptor file."; logger->addWarning(msg); */ return NULL; } /* retrieving name */ TiXmlElement* name = (TiXmlElement*) root->FirstChild("name"); if(!name || !name->GetText()) { OSTRINGSTREAM err; err<<"Module from "<<szFile<<" has no name."; logger->addError(err); //return NULL; } module.setXmlFile(szFile); if(name) module.setName(name->GetText()); /* retrieving description */ TiXmlElement* desc; if((desc = (TiXmlElement*) root->FirstChild("description"))) module.setDescription(desc->GetText()); /* retrieving version */ TiXmlElement* ver; if((ver = (TiXmlElement*) root->FirstChild("version"))) module.setVersion(ver->GetText()); /* retrieving parameter */ TiXmlElement* arguments; if((arguments = (TiXmlElement*) root->FirstChild("arguments"))) for(TiXmlElement* param = arguments->FirstChildElement(); param; param = param->NextSiblingElement()) { if(compareString(param->Value(), "param")) { if(param->GetText()) { bool brequired = false; if(compareString(param->Attribute("required"), "yes")) brequired = true; Argument arg(param->GetText(), brequired, param->Attribute("desc")); arg.setDefault(param->Attribute("default")); module.addArgument(arg); } } else if(compareString(param->Value(), "switch")) { if(param->GetText()) { bool brequired = false; if(compareString(param->Attribute("required"), "yes")) brequired = true; Argument arg(param->GetText(), brequired, param->Attribute("desc"), true); arg.setDefault(param->Attribute("default")); module.addArgument(arg); } } else { OSTRINGSTREAM war; war<<"Unrecognized tag from "<<szFile<<" at line "\ <<param->Row()<<"."; logger->addWarning(war); } } /* retrieving rank */ TiXmlElement* rank; if((rank = (TiXmlElement*) root->FirstChild("rank")) && rank->GetText()) module.setRank(atoi(rank->GetText())); /* retrieving authors information*/ TiXmlElement* authors; if((authors = (TiXmlElement*) root->FirstChild("authors"))) for(TiXmlElement* ath = authors->FirstChildElement(); ath; ath = ath->NextSiblingElement()) { if(compareString(ath->Value(), "author")) { Author author; if(ath->GetText()) author.setName(ath->GetText()); if(ath->Attribute("email")) author.setEmail(ath->Attribute("email")); module.addAuthor(author); } else { OSTRINGSTREAM war; war<<"Unrecognized tag from "<<szFile<<" at line "\ <<ath->Row()<<"."; logger->addWarning(war); } } /* retrieving data */ if(root->FirstChild("data")) for(TiXmlElement* data = root->FirstChild("data")->FirstChildElement(); data; data = data->NextSiblingElement()) { /* output data */ if(compareString(data->Value(), "output")) { OutputData output; TiXmlElement* element; if((element = (TiXmlElement*) data->FirstChild("type"))) output.setName(element->GetText()); else { OSTRINGSTREAM war; war<<"Output data from "<<szFile<<" at line "\ <<data->Row()<<" has no type."; logger->addWarning(war); } if((element = (TiXmlElement*) data->FirstChild("port"))) { output.setPort(element->GetText()); output.setCarrier(element->Attribute("carrier")); } else { OSTRINGSTREAM war; war<<"Output data from "<<szFile<<" at line "\ <<data->Row()<<" has no port."; logger->addWarning(war); } if((element = (TiXmlElement*) data->FirstChild("description"))) output.setDescription(element->GetText()); module.addOutput(output); } // end of output data /* input data */ if(compareString(data->Value(), "input")) { InputData input; TiXmlElement* element; if((element = (TiXmlElement*) data->FirstChild("type"))) input.setName(element->GetText()); else { OSTRINGSTREAM war; war<<"Input data from "<<szFile<<" at line "\ <<data->Row()<<" has no type."; logger->addWarning(war); } if((element = (TiXmlElement*) data->FirstChild("port"))) { input.setPort(element->GetText()); input.setCarrier(element->Attribute("carrier")); } else { OSTRINGSTREAM war; war<<"Input data from "<<szFile<<" at line "\ <<data->Row()<<" has no port."; logger->addWarning(war); } if((element = (TiXmlElement*) data->FirstChild("description"))) input.setDescription(element->GetText()); if((element = (TiXmlElement*) data->FirstChild("required"))) if(compareString(element->GetText(), "yes")) input.setRequired(true); if((element = (TiXmlElement*) data->FirstChild("priority"))) if(compareString(element->GetText(), "yes")) input.setPriority(true); module.addInput(input); } // end of input data } /* retrieving broker*/ TiXmlElement* element; if((element = (TiXmlElement*) root->FirstChild("deployer"))) { module.setBroker(element->GetText()); module.setNeedDeployer(true); } /* retrieving dependencies*/ if(root->FirstChild("dependencies")) for(TiXmlElement* restag = root->FirstChild("dependencies")->FirstChildElement(); restag; restag = restag->NextSiblingElement()) { Computer computer; if(compareString(restag->Value(), "computer")) { Computer computer; computer.setXmlFile(szFile); for(TiXmlElement* comptag = restag->FirstChildElement(); comptag; comptag = comptag->NextSiblingElement()) { /* retrieving name */ if(compareString(comptag->Value(), "name")) computer.setName(comptag->GetText()); /* retrieving description */ if(compareString(comptag->Value(), "description")) computer.setDescription(comptag->GetText()); // platform if(compareString(comptag->Value(), "platform")) { Platform os; TiXmlElement* element; if((element = (TiXmlElement*) comptag->FirstChild("name"))) os.setName(element->GetText()); if((element = (TiXmlElement*) comptag->FirstChild("distribution"))) os.setDistribution(element->GetText()); if((element = (TiXmlElement*) comptag->FirstChild("release"))) os.setRelease(element->GetText()); computer.setPlatform(os); } // end of platform tag /* //multiplatform if(compareString(comptag->Value(), "multiplatform")) { MultiPlatform mltPlatform; for(TiXmlElement* mptag = comptag->FirstChild("multiplatform")->FirstChildElement(); mptag; mptag = mptag->NextSiblingElement()) { // platform if(compareString(mptag->Value(), "platform")) { Platform os; TiXmlElement* element; if((element = (TiXmlElement*) mptag->FirstChild("name"))) os.setName(element->GetText()); if((element = (TiXmlElement*) mptag->FirstChild("distribution"))) os.setDistribution(element->GetText()); if((element = (TiXmlElement*) mptag->FirstChild("release"))) os.setDistribution(element->GetText()); mltPlatform.addPlatform(os); } } module.addResource(mltPlatform); } // end of multiplatform tag */ // memory if(compareString(comptag->Value(), "memory")) { Memory mem; TiXmlElement* element; if((element = (TiXmlElement*) comptag->FirstChild("total_space"))) mem.setTotalSpace((Capacity)atol(element->GetText())); if((element = (TiXmlElement*) comptag->FirstChild("free_space"))) mem.setFreeSpace((Capacity)atol(element->GetText())); computer.setMemory(mem); } // end of memory tag // storage if(compareString(comptag->Value(), "storage")) { Storage stg; TiXmlElement* element; if((element = (TiXmlElement*) comptag->FirstChild("total_space"))) stg.setTotalSpace((Capacity)atol(element->GetText())); if((element = (TiXmlElement*) comptag->FirstChild("free_space"))) stg.setFreeSpace((Capacity)atol(element->GetText())); computer.setStorage(stg); } // end of storage tag // processor if(compareString(comptag->Value(), "processor")) { Processor proc; TiXmlElement* element; if((element = (TiXmlElement*) comptag->FirstChild("architecture"))) proc.setArchitecture(element->GetText()); if((element = (TiXmlElement*) comptag->FirstChild("model"))) proc.setModel(element->GetText()); if((element = (TiXmlElement*) comptag->FirstChild("cores"))) proc.setCores((size_t)atoi(element->GetText())); if((element = (TiXmlElement*) comptag->FirstChild("siblings"))) proc.setSiblings((size_t)atoi(element->GetText())); if((element = (TiXmlElement*) comptag->FirstChild("frequency"))) proc.setFrequency(atof(element->GetText())); computer.setProcessor(proc); } // end of processor tag // network if(compareString(comptag->Value(), "network")) { Network net; TiXmlElement* element; if((element = (TiXmlElement*) comptag->FirstChild("ip4"))) net.setIP4(element->GetText()); if((element = (TiXmlElement*) comptag->FirstChild("ip6"))) net.setIP6(element->GetText()); if((element = (TiXmlElement*) comptag->FirstChild("mac"))) net.setMAC(element->GetText()); module.addResource(net); computer.setNetwork(net); } // end of network tag // yarp_port if(compareString(comptag->Value(), "yarp_port")) { ResYarpPort yport; TiXmlElement* element = (TiXmlElement*) comptag->FirstChild("name"); if(element && element->GetText()) { yport.setName(element->GetText()); yport.setPort(element->GetText()); computer.addPeripheral(yport); } else { OSTRINGSTREAM war; war<<"yarp_port from "<<szFile<<" at line " <<comptag->Row()<<" has no name."; logger->addWarning(war); } } // gpu if(compareString(comptag->Value(), "gpu")) { GPU gpu; TiXmlElement* element; if((element = (TiXmlElement*) comptag->FirstChild("name"))) gpu.setName(element->GetText()); if((element = (TiXmlElement*) comptag->FirstChild("capability"))) gpu.setCompCompatibility(element->GetText()); if((element = (TiXmlElement*) comptag->FirstChild("cores"))) gpu.setCores((size_t)atoi(element->GetText())); if((element = (TiXmlElement*) comptag->FirstChild("frequency"))) gpu.setFrequency(atof(element->GetText())); if((element = (TiXmlElement*) comptag->FirstChild("register_block"))) gpu.setResgisterPerBlock((size_t)atoi(element->GetText())); if((element = (TiXmlElement*) comptag->FirstChild("thread_block"))) gpu.setThreadPerBlock((size_t)atoi(element->GetText())); if((element = (TiXmlElement*) comptag->FirstChild("overlap"))) { if(compareString(element->GetText(), "yes")) gpu.setOverlap(true); else gpu.setOverlap(false); } // global memory if(comptag->FirstChild("global_memory")) { TiXmlElement* element; element = (TiXmlElement*) comptag->FirstChild("global_memory"); if((element = (TiXmlElement*) element->FirstChild("total_space"))) gpu.setGlobalMemory((Capacity)atol(element->GetText())); } // end of global memory tag // shared memory if(comptag->FirstChild("shared_memory")) { TiXmlElement* element; element = (TiXmlElement*) comptag->FirstChild("shared_memory"); if((element = (TiXmlElement*) element->FirstChild("total_space"))) gpu.setSharedMemory((Capacity)atol(element->GetText())); } // end of shared memory tag // constant memory if(comptag->FirstChild("constant_memory")) { TiXmlElement* element; element = (TiXmlElement*) comptag->FirstChild("constant_memory"); if((element = (TiXmlElement*) element->FirstChild("total_space"))) gpu.setConstantMemory((Capacity)atol(element->GetText())); } // end of shared memory tag computer.addPeripheral(gpu); } // end of gpu tag } // end of computer tag loop module.addResource(computer); } //end of if computer tag }// end of dependecnies tag return &module; }
int CIMDB::InternalFindMovie(const CStdString &strMovie, IMDB_MOVIELIST& movielist, bool& sortMovieList, const CStdString& strFunction, CScraperUrl* pUrl) { movielist.clear(); CScraperUrl scrURL; CStdString strName = strMovie; CStdString movieTitle, movieTitleAndYear, movieYear; CUtil::CleanString(strName, movieTitle, movieTitleAndYear, movieYear, true); movieTitle.ToLower(); CLog::Log(LOGDEBUG, "%s: Searching for '%s' using %s scraper (file: '%s', content: '%s', language: '%s', date: '%s', framework: '%s')", __FUNCTION__, movieTitle.c_str(), m_info.strTitle.c_str(), m_info.strPath.c_str(), m_info.strContent.c_str(), m_info.strLanguage.c_str(), m_info.strDate.c_str(), m_info.strFramework.c_str()); if (!pUrl) { if (m_parser.HasFunction("CreateSearchUrl")) { GetURL(strMovie, movieTitle, movieYear, scrURL); } else if (m_info.strContent.Equals("musicvideos")) { if (!m_parser.HasFunction("FileNameScrape")) return false; CScraperUrl scrURL("filenamescrape"); scrURL.strTitle = strMovie; movielist.push_back(scrURL); return 1; } if (scrURL.m_xml.IsEmpty()) return 0; } else scrURL = *pUrl; vector<CStdString> strHTML; for (unsigned int i=0;i<scrURL.m_url.size();++i) { CStdString strCurrHTML; if (!CScraperUrl::Get(scrURL.m_url[i],strCurrHTML,m_http) || strCurrHTML.size() == 0) return 0; strHTML.push_back(strCurrHTML); } // now grab our details using the scraper for (unsigned int i=0;i<strHTML.size();++i) m_parser.m_param[i] = strHTML[i]; m_parser.m_param[strHTML.size()] = scrURL.m_url[0].m_url; CStdString strXML = m_parser.Parse(strFunction,&m_info.settings); //CLog::Log(LOGDEBUG,"scraper: %s returned %s",strFunction.c_str(),strXML.c_str()); if (strXML.IsEmpty()) { CLog::Log(LOGERROR, "%s: Unable to parse web site",__FUNCTION__); return 0; } if (!XMLUtils::HasUTF8Declaration(strXML)) g_charsetConverter.unknownToUTF8(strXML); // ok, now parse the xml file TiXmlDocument doc; doc.Parse(strXML.c_str(),0,TIXML_ENCODING_UTF8); if (!doc.RootElement()) { CLog::Log(LOGERROR, "%s: Unable to parse xml",__FUNCTION__); return 0; } if (stricmp(doc.RootElement()->Value(),"error")==0) { TiXmlElement* title = doc.RootElement()->FirstChildElement("title"); CStdString strTitle; if (title && title->FirstChild() && title->FirstChild()->Value()) strTitle = title->FirstChild()->Value(); TiXmlElement* message = doc.RootElement()->FirstChildElement("message"); CStdString strMessage; if (message && message->FirstChild() && message->FirstChild()->Value()) strMessage = message->FirstChild()->Value(); CGUIDialogOK* dialog = (CGUIDialogOK*)g_windowManager.GetWindow(WINDOW_DIALOG_OK); dialog->SetHeading(strTitle); dialog->SetLine(0,strMessage); g_application.getApplicationMessenger().DoModal(dialog,WINDOW_DIALOG_OK); return -1; } TiXmlHandle docHandle( &doc ); TiXmlElement* xurl = doc.RootElement()->FirstChildElement("url"); while (xurl && xurl->FirstChild()) { const char* szFunction = xurl->Attribute("function"); if (szFunction) { CScraperUrl scrURL(xurl); InternalFindMovie(strMovie,movielist,sortMovieList,szFunction,&scrURL); } xurl = xurl->NextSiblingElement("url"); } TiXmlElement *movie = docHandle.FirstChild( "results" ).FirstChild( "entity" ).Element(); if (!movie) return 0; while (movie) { // is our result already sorted correctly when handed over from scraper? if so, do not let xbmc sort it if (sortMovieList) { TiXmlElement* results = docHandle.FirstChild("results").Element(); if (results) { CStdString szSorted = results->Attribute("sorted"); sortMovieList = (szSorted.CompareNoCase("yes") != 0); } } CScraperUrl url; TiXmlNode *title = movie->FirstChild("title"); TiXmlElement *link = movie->FirstChildElement("url"); TiXmlNode *year = movie->FirstChild("year"); TiXmlNode* id = movie->FirstChild("id"); TiXmlNode* language = movie->FirstChild("language"); if (title && title->FirstChild() && link && link->FirstChild()) { url.strTitle = title->FirstChild()->Value(); while (link && link->FirstChild()) { url.ParseElement(link); link = link->NextSiblingElement("url"); } if (id && id->FirstChild()) url.strId = id->FirstChild()->Value(); // calculate the relavance of this hit CStdString compareTitle = url.strTitle; compareTitle.ToLower(); CStdString matchTitle = movieTitle; matchTitle.ToLower(); // see if we need to add year information CStdString compareYear; if(year && year->FirstChild()) compareYear = year->FirstChild()->Value(); if (!movieYear.IsEmpty() && !compareYear.IsEmpty()) { matchTitle.AppendFormat(" (%s)", movieYear.c_str()); compareTitle.AppendFormat(" (%s)", compareYear.c_str()); } url.relevance = fstrcmp(matchTitle.c_str(), compareTitle.c_str(), 0); // reconstruct a title for the user CStdString title = url.strTitle; if (!compareYear.IsEmpty()) title.AppendFormat(" (%s)", compareYear.c_str()); if (language && language->FirstChild()) title.AppendFormat(" (%s)", language->FirstChild()->Value()); url.strTitle = title; movielist.push_back(url); } movie = movie->NextSiblingElement(); } return 1; }
bool wxsCustomWidget::OnXmlWrite(TiXmlElement* Element,bool IsXRC,bool IsExtra) { bool Ret = wxsItem::OnXmlWrite(Element,IsXRC,IsExtra); if ( IsXRC ) { if ( !(GetPropertiesFlags() & flSource) ) { Element->SetAttribute("class",cbU2C(GetUserClass())); Element->RemoveAttribute("subclass"); Element->InsertEndChild(TiXmlElement("style"))->InsertEndChild(TiXmlText(cbU2C(m_Style))); for ( TiXmlElement* Child = m_XmlDataDoc.FirstChildElement(); Child; Child = Child->NextSiblingElement() ) { // Skipping all standard elements wxString Name = cbC2U(Child->Value()); if ( Name != _T("pos") && Name != _T("size") && Name != _T("style") && Name != _T("enabled") && Name != _T("focused") && Name != _T("hidden") && Name != _T("fg") && Name != _T("bg") && Name != _T("font") && Name != _T("handler") ) { Element->InsertEndChild(*Child); } } } } return Ret; }
bool Scene::readXml(TiXmlElement* e) { string objName; TiXmlElement* child = e->FirstChildElement(); while(child != NULL) { if(child->ValueStr() == "pixel") { if((objName = Xml::getAttrString(child, "name")) != "") { Pixel* p = new Pixel(objName, getOscRootAddress()); p->loadXml(child); addObject(p); LOG_DEBUG << "Scene \"" << _name << "\": Loaded pixel \"" << objName << "\" \"" << p->getOscRootAddress() << "\"" << std::endl; } else { LOG_WARN << "Scene \"" << _name << "\": cannot load pixel without name, line " << child->Row() << endl; } } else if(child->ValueStr() == "line") { if((objName = Xml::getAttrString(child, "name")) != "") { Line* l = new Line(objName, getOscRootAddress()); l->loadXml(child); addObject(l); LOG_DEBUG << "Scene \"" << _name << "\": Loaded line \"" << objName << "\" \"" << l->getOscRootAddress() << "\"" << std::endl; } else { LOG_WARN << "Scene \"" << _name << "\": cannot load line without name, line " << child->Row() << endl; } } else if(child->ValueStr() == "rect") { if((objName = Xml::getAttrString(child, "name")) != "") { Rect* r = new Rect(objName, getOscRootAddress()); r->loadXml(child); addObject(r); LOG_DEBUG << "Scene \"" << _name << "\": Loaded rect \"" << objName << "\" \"" << r->getOscRootAddress() << "\"" << std::endl; } else { LOG_WARN << "Scene \"" << _name << "\": cannot load rect without name, line " << child->Row() << endl; } } else if(child->ValueStr() == "bitmap") { if((objName = Xml::getAttrString(child, "name")) != "") { Bitmap* b = new Bitmap(objName, getOscRootAddress()); b->loadXml(child); addObject(b); LOG_DEBUG << "Scene \"" << _name << "\": Loaded bitmap \"" << objName << "\" \"" << b->getOscRootAddress() << "\"" << std::endl; } else { LOG_WARN << "Scene \"" << _name << "\": cannot load bitmap without name, line " << child->Row() << endl; } } else if(child->ValueStr() == "sprite") { if((objName = Xml::getAttrString(child, "name")) != "") { Sprite* s = new Sprite(objName, getOscRootAddress()); s->loadXml(child); addObject(s); LOG_DEBUG << "Scene \"" << _name << "\": Loaded sprite \"" << objName << "\" \"" << s->getOscRootAddress() << "\"" << std::endl; } else { LOG_WARN << "Scene \"" << _name << "\": cannot load sprite without name, line " << child->Row() << endl; } } else if(child->ValueStr() == "image") { if((objName = Xml::getAttrString(child, "name")) != "") { Image* i = new Image(objName, getOscRootAddress()); i->loadXml(child); addObject(i); LOG_DEBUG << "Scene \"" << _name << "\": Loaded image \"" << objName << "\" \"" << i->getOscRootAddress() << "\"" << std::endl; } else { LOG_WARN << "Scene \"" << _name << "\": cannot load image without name, line " << child->Row() << endl; } } else if(child->ValueStr() == "text") { if((objName = Xml::getAttrString(child, "name")) != "") { Text* t = new Text(objName, getOscRootAddress()); t->loadXml(child); addObject(t); LOG_DEBUG << "Scene \"" << _name << "\": Loaded text \"" << objName << "\" \"" << t->getOscRootAddress() << "\"" << std::endl; } else { LOG_WARN << "Scene \"" << _name << "\": cannot load text without name, line " << child->Row() << endl; } } else if(child->ValueStr() != "background") { LOG_WARN << "Scene \"" << _name << "\": ignoring unknown element \"" << child->ValueStr() << "\"" << endl; } child = child->NextSiblingElement(); } return true; }
bool LoadPrefs() { if (prefLoaded) // already attempted loading return true; char filepath[MAXPATHLEN]; sprintf(filepath, "%s/%s", MPLAYER_DATADIR, PREF_FILE_NAME); TiXmlDocument doc; bool loadOkay = doc.LoadFile(filepath); if (loadOkay) { FixInvalidSettings(); TiXmlHandle docu(&doc); TiXmlElement* settings = docu.FirstChildElement().Element(); if (settings == NULL) { goto noheader; } TiXmlHandle handle(0); TiXmlElement* elem; handle = TiXmlHandle(settings); elem = handle.FirstChild("global").FirstChild().Element(); for (elem; elem; elem = elem->NextSiblingElement()) { const char* elemName = elem->Value(); if (strcmp(elemName, "exit") == 0) { XMPlayerCfg.exit_action = atoi(elem->Attribute("value")); } else if (strcmp(elemName, "language") == 0) { XMPlayerCfg.language = atoi(elem->Attribute("value")); } } elem = handle.FirstChild("filebrowser").FirstChild().Element(); for (elem; elem; elem = elem->NextSiblingElement()) { const char* elemName = elem->Value(); if (strcmp(elemName, "sort") == 0) { XMPlayerCfg.sort_order = atoi(elem->Attribute("value")); } } elem = handle.FirstChild("audio").FirstChild().Element(); for (elem; elem; elem = elem->NextSiblingElement()) { const char* elemName = elem->Value(); if (strcmp(elemName, "language") == 0) { sprintf(XMPlayerCfg.alang, elem->Attribute("value")); sprintf(XMPlayerCfg.alang_desc, elem->Attribute("desc")); } else if (strcmp(elemName, "volume") == 0) { XMPlayerCfg.volume = atoi(elem->Attribute("value")); } else if (strcmp(elemName, "softvol") == 0) { XMPlayerCfg.softvol = atoi(elem->Attribute("value")); } } elem = handle.FirstChild("video").FirstChild().Element(); for (elem; elem; elem = elem->NextSiblingElement()) { const char* elemName = elem->Value(); if (strcmp(elemName, "framedrop") == 0) { XMPlayerCfg.framedrop = atoi(elem->Attribute("value")); } else if (strcmp(elemName, "vsync") == 0) { XMPlayerCfg.vsync = atoi(elem->Attribute("value")); } } elem = handle.FirstChild("subtitles").FirstChild().Element(); for (elem; elem; elem = elem->NextSiblingElement()) { const char* elemName = elem->Value(); if (strcmp(elemName, "sub_color") == 0) { elem->Attribute("value", &XMPlayerCfg.subcolor); } else if (strcmp(elemName, "border_color") == 0) { elem->Attribute("value", &XMPlayerCfg.border_color); } else if (strcmp(elemName, "codepage") == 0) { sprintf(XMPlayerCfg.subcp, elem->Attribute("value")); sprintf(XMPlayerCfg.subcp_desc, elem->Attribute("desc")); } else if (strcmp(elemName, "language") == 0) { sprintf(XMPlayerCfg.sublang, elem->Attribute("value")); sprintf(XMPlayerCfg.sublang_desc, elem->Attribute("desc")); } } doc.Clear(); prefLoaded = true; printf("[Preferences] Sucessfully loaded xmplayer.xml \n"); return true; } else { noheader: DefaultSettings(); printf("[Preferences] Failed to load xmplayer.xml - Loading default settings \n"); return false; } }
void LevelParser::parseObjectLayer(TiXmlElement* pObjectElement, std::vector<Layer*> *pLayers, Level* pLevel) { // create an object layer ObjectLayer* pObjectLayer = new ObjectLayer(); for(TiXmlElement* e = pObjectElement->FirstChildElement(); e != NULL; e = e->NextSiblingElement()) { if(e->Value() == std::string("object")) { int x, y, width, height, numFrames, callbackID = 0, animSpeed = 0; std::string textureID; std::string type; // get the initial node values type, x and y e->Attribute("x", &x); e->Attribute("y", &y); type = e->Attribute("type"); GameObject* pGameObject = TheGameObjectFactory::Instance()->create(type); // get the property values for(TiXmlElement* properties = e->FirstChildElement(); properties != NULL; properties = properties->NextSiblingElement()) { if(properties->Value() == std::string("properties")) { for(TiXmlElement* property = properties->FirstChildElement(); property != NULL; property = property->NextSiblingElement()) { if(property->Value() == std::string("property")) { if(property->Attribute("name") == std::string("numFrames")) { property->Attribute("value", &numFrames); } else if(property->Attribute("name") == std::string("textureHeight")) { property->Attribute("value", &height); } else if(property->Attribute("name") == std::string("textureID")) { textureID = property->Attribute("value"); } else if(property->Attribute("name") == std::string("textureWidth")) { property->Attribute("value", &width); } else if(property->Attribute("name") == std::string("callbackID")) { property->Attribute("value", &callbackID); } else if(e->Attribute("name") == std::string("animSpeed")) { property->Attribute("value", &animSpeed); } } } } } // load the object pGameObject->load(std::unique_ptr<LoaderParams>(new LoaderParams(x, y, width, height, textureID, numFrames,callbackID, animSpeed))); // set the collision layers pGameObject->setCollisionLayers(pLevel->getCollisionLayers()); if(type == "Player") { pLevel->setPlayer(dynamic_cast<Player*>(pGameObject)); } pObjectLayer->getGameObjects()->push_back(pGameObject); } } pLayers->push_back(pObjectLayer); }
void LevelParser::parseTileLayer(TiXmlElement* pTileElement, std::vector<Layer*> *pLayers, const std::vector<Tileset>* pTilesets, std::vector<TileLayer*> *pCollisionLayers) { TileLayer* pTileLayer = new TileLayer(m_tileSize, m_width, m_height, *pTilesets); bool collidable = false; // tile data std::vector<std::vector<int>> data; std::string decodedIDs; TiXmlElement* pDataNode; for(TiXmlElement* e = pTileElement->FirstChildElement(); e != NULL; e = e->NextSiblingElement()) { if(e->Value() == std::string("properties")) { for(TiXmlElement* property = e->FirstChildElement(); property != NULL; property = property->NextSiblingElement()) { if(property->Value() == std::string("property")) { if(property->Attribute("name") == std::string("collidable")) { collidable = true; } } } } if(e->Value() == std::string("data")) { pDataNode = e; } } for(TiXmlNode* e = pDataNode->FirstChild(); e != NULL; e = e->NextSibling()) { TiXmlText* text = e->ToText(); std::string t = text->Value(); decodedIDs = base64_decode(t); } // uncompress zlib compression uLongf sizeofids = m_width * m_height * sizeof(int); std::vector<int> ids(m_width * m_height); uncompress((Bytef*)&ids[0], &sizeofids,(const Bytef*)decodedIDs.c_str(), decodedIDs.size()); std::vector<int> layerRow(m_width); for(int j = 0; j < m_height; j++) { data.push_back(layerRow); } for(int rows = 0; rows < m_height; rows++) { for(int cols = 0; cols < m_width; cols++) { data[rows][cols] = ids[rows * m_width + cols]; } } pTileLayer->setTileIDs(data); if(collidable) { pCollisionLayers->push_back(pTileLayer); } pLayers->push_back(pTileLayer); }
//--------------------------------------------------------------------------- bool BitmapFont::AddTexturesFromZip( TiXmlDocument& metaDataDocument, ZipFile* zipFile, const std::string& metaDataFilePath ) { TiXmlElement* rootElement = metaDataDocument.RootElement(); TiXmlElement* pageElement = rootElement->FirstChildElement( "pages" ); const size_t lastSlashLocation = metaDataFilePath.rfind( '/' ); for ( TiXmlElement* currentElement = pageElement->FirstChildElement( "page" ); currentElement != nullptr; currentElement = currentElement->NextSiblingElement( "page" ) ) { Texture* texture = Texture::CreateOrGetTexture( zipFile, metaDataFilePath.substr( 0, lastSlashLocation + 1 ) + std::string( currentElement->Attribute( "file" ) ) ); if ( !texture ) return false; m_glyphSheets.push_back( texture ); } return true; }
void IPXMLParser::parseXML() { if ( fileName.empty() ) throw std::runtime_error( "Exception: fileName.empty()" ); doc = TiXmlDocument( fileName ); if ( !doc.LoadFile() ) throw std::runtime_error( "Exception: XML file cannot be loaded!" ); std::cout << fileName << " opened successfully!\n"; TiXmlHandle hDoc( &doc ); TiXmlHandle hRoot( NULL ); el = hDoc.FirstChildElement( "Properties" ).ToElement(); if ( !el ) throw std::runtime_error( "Exception: XML file empty or 'Properties' missing!" ); hRoot = TiXmlHandle( el ); TiXmlElement * properties = hRoot.FirstChild( "Property" ).ToElement(); if ( !properties ) throw std::runtime_error( "Exception: 'Properties' is empty!" ); for ( ; properties; properties = properties->NextSiblingElement( "Property" ) ) { const char * elName = properties->Attribute( "name" ); if ( !properties ) throw std::runtime_error( "Exception: no element named Property!" ); if ( strcmp( elName, "hsvMin" ) != 0 && std::strcmp( elName, "hsvMax" ) != 0 ) throw std::runtime_error( "Exception: hsvMin and hsvMax not available!" ); if ( strcmp( elName, "hsvMin" ) == 0 ) { double hMin, sMin, vMin; properties->QueryDoubleAttribute( "hMin", &hMin ); properties->QueryDoubleAttribute( "sMin", &sMin ); properties->QueryDoubleAttribute( "vMin", &vMin ); hsvMin = cv::Scalar( hMin, sMin, vMin ); std::cout << "hsvMin: " << hsvMin( 0 ) << " " << hsvMin( 1 ) << " " << hsvMin( 2 ) << " " << hsvMin( 3 ) << std::endl; } if ( strcmp( elName, "hsvMax" ) == 0 ) { double hMax, sMax, vMax; properties->QueryDoubleAttribute( "hMax", &hMax ); properties->QueryDoubleAttribute( "sMax", &sMax ); properties->QueryDoubleAttribute( "vMax", &vMax ); hsvMax = cv::Scalar( hMax, sMax, vMax ); std::cout << "hsvMax: " << hsvMax( 0 ) << " " << hsvMax( 1 ) << " " << hsvMax( 2 ) << " " << hsvMax( 3 ) << std::endl; } } }
//--------------------------------------------------------------------------- void BitmapFont::ExtractMetaDataFromTinyXMLDocument( TiXmlDocument& metaDataDocument ) { Vec2f glyphPosition; Vec2f glyphDimensions; TiXmlElement* rootElement = metaDataDocument.RootElement(); TiXmlElement* charElement = rootElement->FirstChildElement( "chars" ); TiXmlElement* commonElement = rootElement->FirstChildElement( "common" ); Vec2f glyphSheetDimensions( ( float ) atof( commonElement->Attribute( "scaleW" ) ), ( float ) atof( commonElement->Attribute( "scaleH" ) ) ); Vec2f oneOverGlyphSheetDimensions( 1.f / glyphSheetDimensions.x, 1.f / glyphSheetDimensions.y ); float oneOverGlyphCellHeight = 1.f / ( float ) atof( commonElement->Attribute( "lineHeight" ) ); for ( TiXmlElement* currentElement = charElement->FirstChildElement( "char" ); currentElement != nullptr; currentElement = currentElement->NextSiblingElement( "char" ) ) { GlyphMetaData& dataHolder = m_glyphData[ atoi( currentElement->Attribute( "id" ) ) ]; // store page number dataHolder.m_glyphSheetIndex = ( char ) atoi( currentElement->Attribute( "page" ) ); // find mins glyphPosition.x = ( float ) atof( currentElement->Attribute( "x" ) ); glyphPosition.y = ( float ) atof( currentElement->Attribute( "y" ) ); dataHolder.m_minTexCoords = Vec2f( glyphPosition.x * oneOverGlyphSheetDimensions.x, glyphPosition.y * oneOverGlyphSheetDimensions.y ); // find maxes glyphDimensions.x = ( float ) atof( currentElement->Attribute( "width" ) ) * oneOverGlyphSheetDimensions.x; glyphDimensions.y = ( float ) atof( currentElement->Attribute( "height" ) ) * oneOverGlyphSheetDimensions.y; dataHolder.m_maxTexCoords = dataHolder.m_minTexCoords + glyphDimensions; // find a b c values dataHolder.m_ttfA = ( float ) atof( currentElement->Attribute( "xoffset" ) ) * oneOverGlyphCellHeight; dataHolder.m_ttfB = ( float ) atof( currentElement->Attribute( "width" ) ) * oneOverGlyphCellHeight; // width dataHolder.m_ttfC = ( float ) ( atoi( currentElement->Attribute( "xadvance" ) ) - ( atoi( currentElement->Attribute( "width" ) ) + atoi( currentElement->Attribute( "xoffset" ) ) ) ) * oneOverGlyphCellHeight; // xoffset - ( xadvance + width ) } }
void CRssReader::GetNewsItems(TiXmlElement* channelXmlNode, int iFeed) { HTML::CHTMLUtil html; TiXmlElement * itemNode = channelXmlNode->FirstChildElement("item"); std::map<std::string, std::wstring> mTagElements; typedef std::pair<std::string, std::wstring> StrPair; std::list<std::string>::iterator i; // Add the title tag in if we didn't pass any tags in at all // Represents default behaviour before configurability if (m_tagSet.empty()) AddTag("title"); while (itemNode != nullptr) { TiXmlNode* childNode = itemNode->FirstChild(); mTagElements.clear(); while (childNode != nullptr) { std::string strName = childNode->ValueStr(); for (i = m_tagSet.begin(); i != m_tagSet.end(); ++i) { if (!childNode->NoChildren() && *i == strName) { std::string htmlText = childNode->FirstChild()->ValueStr(); // This usually happens in right-to-left languages where they want to // specify in the RSS body that the text should be RTL. // <title> // <div dir="RTL">��� ����: ���� �� �����</div> // </title> if (htmlText == "div" || htmlText == "span") htmlText = childNode->FirstChild()->FirstChild()->ValueStr(); std::wstring unicodeText, unicodeText2; g_charsetConverter.utf8ToW(htmlText, unicodeText2, m_rtlText); html.ConvertHTMLToW(unicodeText2, unicodeText); mTagElements.insert(StrPair(*i, unicodeText)); } } childNode = childNode->NextSibling(); } int rsscolour = RSS_COLOR_HEADLINE; for (i = m_tagSet.begin(); i != m_tagSet.end(); ++i) { std::map<std::string, std::wstring>::iterator j = mTagElements.find(*i); if (j == mTagElements.end()) continue; std::wstring& text = j->second; AddString(text, rsscolour, iFeed); rsscolour = RSS_COLOR_BODY; text = L" - "; AddString(text, rsscolour, iFeed); } itemNode = itemNode->NextSiblingElement("item"); } }
void NetworkConverter::changeProcessorType(TiXmlElement* elem, const std::string& from, const std::string& to) { TiXmlElement* processorsNode = elem->FirstChildElement("Processors"); for (TiXmlElement* node = processorsNode->FirstChildElement("Processor"); node != 0; node = node->NextSiblingElement("Processor")) { const std::string* type = node->Attribute(std::string("type")); if (type && *type == from) { node->SetAttribute("type", to); const std::string* name = node->Attribute(std::string("name")); if (name && *name == from) node->SetAttribute("name", to); } } }
TextureMap* ReadTexture(TiXmlElement *element) { const char* texName = element->Attribute("texture"); if ( texName == NULL ) return NULL; Texture *tex = NULL; if ( COMPARE(texName,"checkerboard") ) { TextureChecker *ctex = new TextureChecker; tex = ctex; printf(" Texture: Checker Board\n"); for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "color1" ) ) { Color c(0,0,0); ReadColor( child, c ); ctex->SetColor1(c); printf(" color1 %f %f %f\n",c.r,c.g,c.b); } else if ( COMPARE( child->Value(), "color2" ) ) { Color c(0,0,0); ReadColor( child, c ); ctex->SetColor2(c); printf(" color2 %f %f %f\n",c.r,c.g,c.b); } } textureList.Append( tex, texName ); } else { printf(" Texture: File \"%s\"",texName); tex = textureList.Find( texName ); if ( tex == NULL ) { TextureFile *ftex = new TextureFile; tex = ftex; ftex->SetName(texName); if ( ! ftex->Load() ) { printf(" -- Error loading file!"); delete tex; tex = NULL; } else { textureList.Append( tex, texName ); } } printf("\n"); } TextureMap *map = new TextureMap(tex); LoadTransform(map,element,1); return map; }
Level* LevelParser::parseLevel(const char *levelFile) { // create a tinyXML document and load the map xml TiXmlDocument levelDocument; levelDocument.LoadFile(levelFile); // create the level object Level* pLevel = new Level(); // get the root node and display some values TiXmlElement* pRoot = levelDocument.RootElement(); std::cout << "Loading level:\n" << "Version: " << pRoot->Attribute("version") << "\n"; std::cout << "Width:" << pRoot->Attribute("width") << " - Height:" << pRoot->Attribute("height") << "\n"; std::cout << "Tile Width:" << pRoot->Attribute("tilewidth") << " - Tile Height:" << pRoot->Attribute("tileheight") << "\n"; pRoot->Attribute("tilewidth", &m_tileSize); pRoot->Attribute("width", &m_width); pRoot->Attribute("height", &m_height); //we know that properties is the first child of the root TiXmlElement* pProperties = pRoot->FirstChildElement(); // we must parse the textures needed for this level, which have been added to properties for(TiXmlElement* e = pProperties->FirstChildElement(); e != NULL; e = e->NextSiblingElement()) { if(e->Value() == std::string("property")) { parseTextures(e); } } // we must now parse the tilesets for(TiXmlElement* e = pRoot->FirstChildElement(); e != NULL; e = e->NextSiblingElement()) { if(e->Value() == std::string("tileset")) { parseTilesets(e, pLevel->getTilesets()); } } // parse any object layers for(TiXmlElement* e = pRoot->FirstChildElement(); e != NULL; e = e->NextSiblingElement()) { if(e->Value() == std::string("objectgroup") || e->Value() == std::string("layer")) { if(e->FirstChildElement()->Value() == std::string("object")) { parseObjectLayer(e, pLevel->getLayers(), pLevel); } else if(e->FirstChildElement()->Value() == std::string("data") || (e->FirstChildElement()->NextSiblingElement() != 0 && e->FirstChildElement()->NextSiblingElement()->Value() == std::string("data"))) { parseTileLayer(e, pLevel->getLayers(), pLevel->getTilesets(), pLevel->getCollisionLayers()); } } } // set the players collision layer // pLevel->getPlayer()->setCollisionLayers(pLevel->getCollisionLayers()); return pLevel; }
int LoadScene(const char *filename) { TiXmlDocument doc(filename); if ( ! doc.LoadFile() ) { printf("Failed to load the file \"%s\"\n", filename); return 0; } TiXmlElement *xml = doc.FirstChildElement("xml"); if ( ! xml ) { printf("No \"xml\" tag found.\n"); return 0; } TiXmlElement *scene = xml->FirstChildElement("scene"); if ( ! scene ) { printf("No \"scene\" tag found.\n"); return 0; } TiXmlElement *cam = xml->FirstChildElement("camera"); if ( ! cam ) { printf("No \"camera\" tag found.\n"); return 0; } nodeMtlList.clear(); rootNode.Init(); materials.DeleteAll(); lights.DeleteAll(); objList.Clear(); textureList.Clear(); LoadScene( scene ); rootNode.ComputeChildBoundBox(); // Assign materials int numNodes = nodeMtlList.size(); for ( int i=0; i<numNodes; i++ ) { Material *mtl = materials.Find( nodeMtlList[i].mtlName ); if ( mtl ) nodeMtlList[i].node->SetMaterial(mtl); } nodeMtlList.clear(); // Load Camera camera.Init(); camera.dir += camera.pos; TiXmlElement *camChild = cam->FirstChildElement(); while ( camChild ) { if ( COMPARE( camChild->Value(), "position" ) ) ReadVector(camChild,camera.pos); else if ( COMPARE( camChild->Value(), "target" ) ) ReadVector(camChild,camera.dir); else if ( COMPARE( camChild->Value(), "up" ) ) ReadVector(camChild,camera.up); else if ( COMPARE( camChild->Value(), "fov" ) ) ReadFloat (camChild,camera.fov); else if ( COMPARE( camChild->Value(), "width" ) ) camChild->QueryIntAttribute("value", &camera.imgWidth); else if ( COMPARE( camChild->Value(), "height" ) ) camChild->QueryIntAttribute("value", &camera.imgHeight); camChild = camChild->NextSiblingElement(); } camera.dir -= camera.pos; camera.dir.Normalize(); Point3 x = camera.dir ^ camera.up; camera.up = (x ^ camera.dir).GetNormalized(); renderImage.Init( camera.imgWidth, camera.imgHeight ); return 1; }
bool CPeripherals::LoadMappings() { CSingleLock lock(m_critSectionMappings); CXBMCTinyXML xmlDoc; if (!xmlDoc.LoadFile("special://xbmc/system/peripherals.xml")) { CLog::Log(LOGWARNING, "%s - peripherals.xml does not exist", __FUNCTION__); return true; } TiXmlElement *pRootElement = xmlDoc.RootElement(); if (!pRootElement || strcmpi(pRootElement->Value(), "peripherals") != 0) { CLog::Log(LOGERROR, "%s - peripherals.xml does not contain <peripherals>", __FUNCTION__); return false; } for (TiXmlElement *currentNode = pRootElement->FirstChildElement("peripheral"); currentNode; currentNode = currentNode->NextSiblingElement("peripheral")) { PeripheralID id; PeripheralDeviceMapping mapping; mapping.m_strDeviceName = XMLUtils::GetAttribute(currentNode, "name"); // If there is no vendor_product attribute ignore this entry if (currentNode->Attribute("vendor_product")) { // The vendor_product attribute is a list of comma separated vendor:product pairs std::vector<std::string> vpArray = StringUtils::Split(currentNode->Attribute("vendor_product"), ","); for (const auto& i : vpArray) { std::vector<std::string> idArray = StringUtils::Split(i, ":"); if (idArray.size() != 2) { CLog::Log(LOGERROR, "%s - ignoring node \"%s\" with invalid vendor_product attribute", __FUNCTION__, mapping.m_strDeviceName.c_str()); continue; } id.m_iVendorId = PeripheralTypeTranslator::HexStringToInt(idArray[0].c_str()); id.m_iProductId = PeripheralTypeTranslator::HexStringToInt(idArray[1].c_str()); mapping.m_PeripheralID.push_back(id); } } mapping.m_busType = PeripheralTypeTranslator::GetBusTypeFromString(XMLUtils::GetAttribute(currentNode, "bus")); mapping.m_class = PeripheralTypeTranslator::GetTypeFromString(XMLUtils::GetAttribute(currentNode, "class")); mapping.m_mappedTo = PeripheralTypeTranslator::GetTypeFromString(XMLUtils::GetAttribute(currentNode, "mapTo")); GetSettingsFromMappingsFile(currentNode, mapping.m_settings); m_mappings.push_back(mapping); CLog::Log(LOGDEBUG, "%s - loaded node \"%s\"", __FUNCTION__, mapping.m_strDeviceName.c_str()); } return true; }
void MemMapper::LateInit() { // Make connections for (TiXmlElement *el = xml_config.FirstChildElement("connect"); el != NULL; el = el->NextSiblingElement("connect")) { const char *type = el->Attribute("type"); const char *dest = el->Attribute("dest"); if (type == NULL || dest == NULL) throw ConfigError(el, "MemMapper <connect> missing type or dest attribute"); std::string type_str = std::string(type); if (type_str == "Z80CPU") z80 = mbee.GetDevice<Z80CPU>(dest); else if (type_str == "Bank0") bank0 = mbee.GetDevice<RAM>(dest); else if (type_str == "Bank1") bank1 = mbee.GetDevice<RAM>(dest); else if (type_str == "Bank2") bank2 = mbee.GetDevice<RAM>(dest); else if (type_str == "Bank3") bank3 = mbee.GetDevice<RAM>(dest); else if (type_str == "ROM1") rom1 = mbee.GetDevice<ROM>(dest); else if (type_str == "ROM2") rom2 = mbee.GetDevice<ROM>(dest); else if (type_str == "ROM3") rom3 = mbee.GetDevice<ROM>(dest); else if (type_str == "CRTCMemory") crtcmem = mbee.GetDevice<CRTCMemory>(dest); } if (z80 == NULL) throw ConfigError(&xml_config, "MemMapper missing Z80CPU connection"); if (bank0 == NULL) throw ConfigError(&xml_config, "MemMapper missing Bank0 connection"); if (bank1 == NULL) throw ConfigError(&xml_config, "MemMapper missing Bank1 connection"); if (bank2 == NULL) throw ConfigError(&xml_config, "MemMapper missing Bank2 connection"); if (bank3 == NULL) throw ConfigError(&xml_config, "MemMapper missing Bank3 connection"); if (rom1 == NULL) throw ConfigError(&xml_config, "MemMapper missing ROM1 connection"); if (rom2 == NULL) throw ConfigError(&xml_config, "MemMapper missing ROM2 connection"); if (rom3 == NULL) throw ConfigError(&xml_config, "MemMapper missing ROM3 connection"); if (crtcmem == NULL) throw ConfigError(&xml_config, "MemMapper missing CRTCMemory connection"); }
void CPeripherals::GetSettingsFromMappingsFile(TiXmlElement *xmlNode, std::map<std::string, PeripheralDeviceSetting> &settings) { TiXmlElement *currentNode = xmlNode->FirstChildElement("setting"); int iMaxOrder = 0; while (currentNode) { CSetting *setting = nullptr; std::string strKey = XMLUtils::GetAttribute(currentNode, "key"); if (strKey.empty()) continue; std::string strSettingsType = XMLUtils::GetAttribute(currentNode, "type"); int iLabelId = currentNode->Attribute("label") ? atoi(currentNode->Attribute("label")) : -1; const std::string config = XMLUtils::GetAttribute(currentNode, "configurable"); bool bConfigurable = (config.empty() || (config != "no" && config != "false" && config != "0")); if (strSettingsType == "bool") { const std::string value = XMLUtils::GetAttribute(currentNode, "value"); bool bValue = (value != "no" && value != "false" && value != "0"); setting = new CSettingBool(strKey, iLabelId, bValue); } else if (strSettingsType == "int") { int iValue = currentNode->Attribute("value") ? atoi(currentNode->Attribute("value")) : 0; int iMin = currentNode->Attribute("min") ? atoi(currentNode->Attribute("min")) : 0; int iStep = currentNode->Attribute("step") ? atoi(currentNode->Attribute("step")) : 1; int iMax = currentNode->Attribute("max") ? atoi(currentNode->Attribute("max")) : 255; setting = new CSettingInt(strKey, iLabelId, iValue, iMin, iStep, iMax); } else if (strSettingsType == "float") { float fValue = currentNode->Attribute("value") ? (float) atof(currentNode->Attribute("value")) : 0; float fMin = currentNode->Attribute("min") ? (float) atof(currentNode->Attribute("min")) : 0; float fStep = currentNode->Attribute("step") ? (float) atof(currentNode->Attribute("step")) : 0; float fMax = currentNode->Attribute("max") ? (float) atof(currentNode->Attribute("max")) : 0; setting = new CSettingNumber(strKey, iLabelId, fValue, fMin, fStep, fMax); } else if (StringUtils::EqualsNoCase(strSettingsType, "enum")) { std::string strEnums = XMLUtils::GetAttribute(currentNode, "lvalues"); if (!strEnums.empty()) { std::vector< std::pair<int,int> > enums; std::vector<std::string> valuesVec; StringUtils::Tokenize(strEnums, valuesVec, "|"); for (unsigned int i = 0; i < valuesVec.size(); i++) enums.push_back(std::make_pair(atoi(valuesVec[i].c_str()), atoi(valuesVec[i].c_str()))); int iValue = currentNode->Attribute("value") ? atoi(currentNode->Attribute("value")) : 0; setting = new CSettingInt(strKey, iLabelId, iValue, enums); } } else { std::string strValue = XMLUtils::GetAttribute(currentNode, "value"); setting = new CSettingString(strKey, iLabelId, strValue); } if (setting) { //! @todo add more types if needed /* set the visibility */ setting->SetVisible(bConfigurable); /* set the order */ int iOrder = 0; currentNode->Attribute("order", &iOrder); /* if the order attribute is invalid or 0, then the setting will be added at the end */ if (iOrder < 0) iOrder = 0; if (iOrder > iMaxOrder) iMaxOrder = iOrder; /* and add this new setting */ PeripheralDeviceSetting deviceSetting = { setting, iOrder }; settings[strKey] = deviceSetting; } currentNode = currentNode->NextSiblingElement("setting"); } /* add the settings without an order attribute or an invalid order attribute set at the end */ for (auto& it : settings) { if (it.second.m_order == 0) it.second.m_order = ++iMaxOrder; } }
bool CIMDB::InternalGetEpisodeList(const CScraperUrl& url, IMDB_EPISODELIST& details) { IMDB_EPISODELIST temp; for(unsigned int i=0; i < url.m_url.size(); i++) { CStdString strHTML; if (!CScraperUrl::Get(url.m_url[i],strHTML, m_http) || strHTML.size() == 0) { CLog::Log(LOGERROR, "%s: Unable to retrieve web site",__FUNCTION__); if (temp.size() > 0 || (i == 0 && url.m_url.size() > 1)) // use what was fetched continue; return false; } m_parser.m_param[0] = strHTML; m_parser.m_param[1] = url.m_url[i].m_url; CStdString strXML = m_parser.Parse("GetEpisodeList",&m_info.settings); //CLog::Log(LOGDEBUG,"scraper: GetEpisodeList returned %s",strXML.c_str()); if (strXML.IsEmpty()) { CLog::Log(LOGERROR, "%s: Unable to parse web site",__FUNCTION__); if (temp.size() > 0 || (i == 0 && url.m_url.size() > 1)) // use what was fetched continue; return false; } // ok, now parse the xml file TiXmlDocument doc; doc.Parse(strXML.c_str()); if (!doc.RootElement()) { CLog::Log(LOGERROR, "%s: Unable to parse xml",__FUNCTION__); return false; } if (!XMLUtils::HasUTF8Declaration(strXML)) g_charsetConverter.unknownToUTF8(strXML); TiXmlHandle docHandle( &doc ); TiXmlElement *movie = docHandle.FirstChild( "episodeguide" ).FirstChild( "episode" ).Element(); while (movie) { TiXmlNode *title = movie->FirstChild("title"); TiXmlElement *link = movie->FirstChildElement("url"); TiXmlNode *epnum = movie->FirstChild("epnum"); TiXmlNode *season = movie->FirstChild("season"); TiXmlNode* id = movie->FirstChild("id"); TiXmlNode *aired = movie->FirstChild("aired"); if (link && link->FirstChild() && epnum && epnum->FirstChild() && season && season->FirstChild()) { CScraperUrl url2; if (title && title->FirstChild()) url2.strTitle = title->FirstChild()->Value(); else url2.strTitle = g_localizeStrings.Get(416); while (link && link->FirstChild()) { url2.ParseElement(link); link = link->NextSiblingElement("url"); } if (id && id->FirstChild()) url2.strId = id->FirstChild()->Value(); pair<int,int> key(atoi(season->FirstChild()->Value()),atoi(epnum->FirstChild()->Value())); IMDB_EPISODE newEpisode; newEpisode.key = key; newEpisode.cDate.SetValid(FALSE); if (aired && aired->FirstChild()) { const char *dateStr = aired->FirstChild()->Value(); // date must be the format of yyyy-mm-dd if (strlen(dateStr)==10) { char year[5]; char month[3]; memcpy(year,dateStr,4); year[4] = '\0'; memcpy(month,dateStr+5,2); month[2] = '\0'; newEpisode.cDate.SetDate(atoi(year),atoi(month),atoi(dateStr+8)); } } newEpisode.cScraperUrl = url2; temp.push_back(newEpisode); } movie = movie->NextSiblingElement(); } } // find minimum in each season map<int,int> min; for (IMDB_EPISODELIST::iterator iter=temp.begin(); iter != temp.end(); ++iter ) { if ((signed int) min.size() == (iter->key.first -1)) min.insert(iter->key); else if (iter->key.second < min[iter->key.first]) min[iter->key.first] = iter->key.second; } // correct episode numbers for (IMDB_EPISODELIST::iterator iter=temp.begin(); iter != temp.end(); ++iter ) { int episode=iter->key.second - min[iter->key.first]; if (min[iter->key.first] > 0) episode++; pair<int,int> key(iter->key.first,episode); IMDB_EPISODE newEpisode; newEpisode.key = key; newEpisode.cDate = iter->cDate; newEpisode.cScraperUrl = iter->cScraperUrl; details.push_back(newEpisode); } return true; }
void DotSceneLoader::processNode(TiXmlElement *XMLNode, SceneNode *pParent) { // Construct the node's name String name = m_sPrependNode + getAttrib(XMLNode, "name"); // Create the scene node SceneNode *pNode; if(name.empty()) { // Let Ogre choose the name if(pParent) pNode = pParent->createChildSceneNode(); else pNode = mAttachNode->createChildSceneNode(); } else { // Provide the name if(pParent) pNode = pParent->createChildSceneNode(name); else pNode = mAttachNode->createChildSceneNode(name); } // Process other attributes String id = getAttrib(XMLNode, "id"); bool isTarget = getAttribBool(XMLNode, "isTarget"); TiXmlElement *pElement; // Process position (?) pElement = XMLNode->FirstChildElement("position"); if(pElement) { pNode->setPosition(parseVector3(pElement)); pNode->setInitialState(); } // Process rotation (?) pElement = XMLNode->FirstChildElement("rotation"); if(pElement) { pNode->setOrientation(parseQuaternion(pElement)); pNode->setInitialState(); } // Process scale (?) pElement = XMLNode->FirstChildElement("scale"); if(pElement) { pNode->setScale(parseVector3(pElement)); pNode->setInitialState(); } // Process lookTarget (?) pElement = XMLNode->FirstChildElement("lookTarget"); if(pElement) processLookTarget(pElement, pNode); // Process trackTarget (?) pElement = XMLNode->FirstChildElement("trackTarget"); if(pElement) processTrackTarget(pElement, pNode); // Process node (*) pElement = XMLNode->FirstChildElement("node"); while(pElement) { processNode(pElement, pNode); pElement = pElement->NextSiblingElement("node"); } // Process entity (*) pElement = XMLNode->FirstChildElement("entity"); while(pElement) { processEntity(pElement, pNode); pElement = pElement->NextSiblingElement("entity"); } // Process light (*) pElement = XMLNode->FirstChildElement("light"); while(pElement) { processLight(pElement, pNode); pElement = pElement->NextSiblingElement("light"); } // Process camera (*) pElement = XMLNode->FirstChildElement("camera"); while(pElement) { processCamera(pElement, pNode); pElement = pElement->NextSiblingElement("camera"); } // Process particleSystem (*) pElement = XMLNode->FirstChildElement("particleSystem"); while(pElement) { processParticleSystem(pElement, pNode); pElement = pElement->NextSiblingElement("particleSystem"); } // Process billboardSet (*) pElement = XMLNode->FirstChildElement("billboardSet"); while(pElement) { processBillboardSet(pElement, pNode); pElement = pElement->NextSiblingElement("billboardSet"); } // Process plane (*) pElement = XMLNode->FirstChildElement("plane"); while(pElement) { processPlane(pElement, pNode); pElement = pElement->NextSiblingElement("plane"); } // Process userDataReference (?) pElement = XMLNode->FirstChildElement("userDataReference"); if(pElement) processUserDataReference(pElement, pNode); }
void readSchoolXml() { using namespace std; const char *xmlFile = "conf/school.xml"; TiXmlDocument doc; if (!doc.LoadFile(xmlFile)) { cout << "Load xml file failed.\t" << xmlFile << endl; return; } cout << "Load xml file OK." << endl; TiXmlDeclaration *decl = doc.FirstChild()->ToDeclaration(); if (!decl) { cout << "decl is null.\n" << endl; return; } cout << decl->Encoding(); cout << decl->Version(); cout << decl->Standalone() << endl; TiXmlHandle docHandle(&doc); TiXmlElement *child = docHandle.FirstChild("School").FirstChild("Class").Child("Student", 0).ToElement(); for ( ; child != NULL; child = child->NextSiblingElement()) { TiXmlAttribute *attr = child->FirstAttribute(); for (; attr != NULL; attr = attr->Next()) { cout << attr->Name() << " : " << attr->Value() << endl; } TiXmlElement *ct = child->FirstChildElement(); for (; ct != NULL; ct = ct->NextSiblingElement()) { char buf[1024] = {0}; u2g(ct->GetText(), strlen(ct->GetText()), buf, sizeof(buf)); cout << ct->Value() << " : " << buf << endl; } cout << "=====================================" << endl; } TiXmlElement *schl = doc.RootElement(); const char *value_t =schl->Attribute("name"); char buf[1024] = {0}; if ( u2g(value_t, strlen(value_t), buf, sizeof(buf)) == -1) { return; } cout << "Root Element value: " << buf << endl; schl->RemoveAttribute("name"); schl->SetValue("NewSchool"); cout << "Save file: " << (doc.SaveFile("conf/new.xml") ? "Ok" : "Failed") << endl; return ; TiXmlElement *rootElement = doc.RootElement(); TiXmlElement *classElement = rootElement->FirstChildElement(); TiXmlElement *studentElement = classElement->FirstChildElement(); // N 个 Student 节点 for ( ; studentElement!= NULL; studentElement = studentElement->NextSiblingElement()) { // 获得student TiXmlAttribute *stuAttribute = studentElement->FirstAttribute(); for (; stuAttribute != NULL; stuAttribute = stuAttribute->Next()) { cout << stuAttribute->Name() << " : " << stuAttribute->Value() << endl; } // 获得student的第一个联系方式 TiXmlElement *contact = studentElement->FirstChildElement(); for (; contact != NULL; contact = contact->NextSiblingElement()) { const char *text = contact->GetText(); char buf[1024] = {0}; if ( u2g(text, strlen(text), buf, sizeof(buf)) == -1) { continue; } cout << contact->Value() << " : " << buf << endl; } } }
void LoadNode(Node *parent, TiXmlElement *element, int level) { Node *node = new Node; parent->AppendChild(node); // name const char* name = element->Attribute("name"); node->SetName(name); PrintIndent(level); printf("object ["); if ( name ) printf("%s",name); printf("]"); // type const char* type = element->Attribute("type"); if ( type ) { if ( COMPARE(type,"sphere") ) { node->SetObject( &theSphere ); printf(" - Sphere"); } else if ( COMPARE(type,"plane") ) { node->SetObject( &thePlane ); printf(" - Plane"); } else if ( COMPARE(type,"obj") ) { printf(" - OBJ"); Object *obj = objList.Find(name); if ( obj == NULL ) { // object is not on the list, so we should load it now TriObj *tobj = new TriObj; if ( ! tobj->Load( name ) ) { printf(" -- ERROR: Cannot load file \"%s.\"", name); delete tobj; } else { objList.Append(tobj,name); // add to the list obj = tobj; } } node->SetObject( obj ); } else { printf(" - UNKNOWN TYPE"); } } // type const char* mtlName = element->Attribute("material"); if ( mtlName ) { printf(" <%s>", mtlName); NodeMtl nm; nm.node = node; nm.mtlName = mtlName; nodeMtlList.push_back(nm); } printf("\n"); for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "object" ) ) { LoadNode(node,child,level+1); } } LoadTransform( node, element, level ); }
void StyleManager::Init( wxString fromPath ) { TiXmlDocument doc; if( !wxDir::Exists( fromPath ) ) { wxString msg = _T("No styles found at: "); msg << fromPath; wxLogMessage( msg ); return; } wxDir dir( fromPath ); if( !dir.IsOpened() ) return; wxString filename; // We allow any number of styles to load from files called style<something>.xml bool more = dir.GetFirst( &filename, _T("style*.xml"), wxDIR_FILES ); if( !more ) { wxString msg = _T("No styles found at: "); msg << fromPath; wxLogMessage( msg ); return; } bool firstFile = true; while( more ) { wxString name, extension; if( !firstFile ) more = dir.GetNext( &filename ); if( !more ) break; firstFile = false; wxString fullFilePath = fromPath + filename; if( !doc.LoadFile( (const char*) fullFilePath.mb_str() ) ) { wxString msg( _T("Attempt to load styles from this file failed: ") ); msg += fullFilePath; wxLogMessage( msg ); continue; } wxString msg( _T("Styles loading from ") ); msg += fullFilePath; wxLogMessage( msg ); TiXmlHandle hRoot( doc.RootElement() ); wxString root = wxString( doc.RootElement()->Value(), wxConvUTF8 ); if( root != _T("styles" ) ) { wxLogMessage( _T(" StyleManager: Expected XML Root <styles> not found.") ); continue; } TiXmlElement* styleElem = hRoot.FirstChild().Element(); for( ; styleElem; styleElem = styleElem->NextSiblingElement() ) { if( wxString( styleElem->Value(), wxConvUTF8 ) == _T("style") ) { Style* style = new Style(); styles.Add( style ); style->name = wxString( styleElem->Attribute( "name" ), wxConvUTF8 ); style->myConfigFileDir = fromPath; TiXmlElement* subNode = styleElem->FirstChild()->ToElement(); for( ; subNode; subNode = subNode->NextSiblingElement() ) { wxString nodeType( subNode->Value(), wxConvUTF8 ); if( nodeType == _T("description") ) { style->description = wxString( subNode->GetText(), wxConvUTF8 ); continue; } if( nodeType == _T("chart-status-icon") ) { int w = 0; subNode->QueryIntAttribute( "width", &w ); style->chartStatusIconWidth = w; continue; } if( nodeType == _T("chart-status-window") ) { style->chartStatusWindowTransparent = wxString( subNode->Attribute( "transparent" ), wxConvUTF8 ).Lower().IsSameAs( _T("true") ); continue; } if( nodeType == _T("embossed-indicators") ) { style->embossFont = wxString( subNode->Attribute( "font" ), wxConvUTF8 ); subNode->QueryIntAttribute( "size", &(style->embossHeight) ); continue; } if( nodeType == _T("graphics-file") ) { style->graphicsFile = wxString( subNode->Attribute( "name" ), wxConvUTF8 ); isOK = true; // If we got this far we are at least partially OK... continue; } if( nodeType == _T("active-route") ) { TiXmlHandle handle( subNode ); TiXmlElement* tag = handle.Child( "font-color", 0 ).ToElement(); if( tag ) { int r, g, b; tag->QueryIntAttribute( "r", &r ); tag->QueryIntAttribute( "g", &g ); tag->QueryIntAttribute( "b", &b ); style->consoleFontColor = wxColour( r, g, b ); } tag = handle.Child( "text-background-location", 0 ).ToElement(); if( tag ) { int x, y, w, h; tag->QueryIntAttribute( "x", &x ); tag->QueryIntAttribute( "y", &y ); tag->QueryIntAttribute( "width", &w ); tag->QueryIntAttribute( "height", &h ); style->consoleTextBackgroundLoc = wxPoint( x, y ); style->consoleTextBackgroundSize = wxSize( w, h ); } continue; } if( nodeType == _T("icons") ) { TiXmlElement* iconNode = subNode->FirstChild()->ToElement(); for( ; iconNode; iconNode = iconNode->NextSiblingElement() ) { wxString nodeType( iconNode->Value(), wxConvUTF8 ); if( nodeType == _T("icon") ) { Icon* icon = new Icon(); style->icons.Add( icon ); icon->name = wxString( iconNode->Attribute( "name" ), wxConvUTF8 ); style->iconIndex[icon->name] = style->icons.Count() - 1; TiXmlHandle handle( iconNode ); TiXmlElement* tag = handle.Child( "icon-location", 0 ).ToElement(); if( tag ) { int x, y; tag->QueryIntAttribute( "x", &x ); tag->QueryIntAttribute( "y", &y ); icon->iconLoc = wxPoint( x, y ); } tag = handle.Child( "size", 0 ).ToElement(); if( tag ) { int x, y; tag->QueryIntAttribute( "x", &x ); tag->QueryIntAttribute( "y", &y ); icon->size = wxSize( x, y ); } } } } if( nodeType == _T("tools") ) { TiXmlElement* toolNode = subNode->FirstChild()->ToElement(); for( ; toolNode; toolNode = toolNode->NextSiblingElement() ) { wxString nodeType( toolNode->Value(), wxConvUTF8 ); if( nodeType == _T("horizontal") || nodeType == _T("vertical") ) { int orientation = 0; if( nodeType == _T("vertical") ) orientation = 1; TiXmlElement* attrNode = toolNode->FirstChild()->ToElement(); for( ; attrNode; attrNode = attrNode->NextSiblingElement() ) { wxString nodeType( attrNode->Value(), wxConvUTF8 ); if( nodeType == _T("separation") ) { attrNode->QueryIntAttribute( "distance", &style->toolSeparation[orientation] ); continue; } if( nodeType == _T("margin") ) { attrNode->QueryIntAttribute( "top", &style->toolMarginTop[orientation] ); attrNode->QueryIntAttribute( "right", &style->toolMarginRight[orientation] ); attrNode->QueryIntAttribute( "bottom", &style->toolMarginBottom[orientation] ); attrNode->QueryIntAttribute( "left", &style->toolMarginLeft[orientation] ); wxString invis = wxString( attrNode->Attribute( "invisible" ), wxConvUTF8 ); style->marginsInvisible = ( invis.Lower() == _T("true") ); continue;; } if( nodeType == _T("toggled-location") ) { int x, y; attrNode->QueryIntAttribute( "x", &x ); attrNode->QueryIntAttribute( "y", &y ); style->toggledBGlocation[orientation] = wxPoint( x, y ); x = 0; y = 0; attrNode->QueryIntAttribute( "width", &x ); attrNode->QueryIntAttribute( "height", &y ); style->toggledBGSize[orientation] = wxSize( x, y ); continue; } if( nodeType == _T("toolbar-start") ) { int x, y; attrNode->QueryIntAttribute( "x", &x ); attrNode->QueryIntAttribute( "y", &y ); style->toolbarStartLoc[orientation] = wxPoint( x, y ); x = 0; y = 0; attrNode->QueryIntAttribute( "width", &x ); attrNode->QueryIntAttribute( "height", &y ); style->toolbarStartSize[orientation] = wxSize( x, y ); continue; } if( nodeType == _T("toolbar-end") ) { int x, y; attrNode->QueryIntAttribute( "x", &x ); attrNode->QueryIntAttribute( "y", &y ); style->toolbarEndLoc[orientation] = wxPoint( x, y ); x = 0; y = 0; attrNode->QueryIntAttribute( "width", &x ); attrNode->QueryIntAttribute( "height", &y ); style->toolbarEndSize[orientation] = wxSize( x, y ); continue; } if( nodeType == _T("toolbar-corners") ) { int r; attrNode->QueryIntAttribute( "radius", &r ); style->cornerRadius[orientation] = r; continue; } if( nodeType == _T("background-location") ) { int x, y; attrNode->QueryIntAttribute( "x", &x ); attrNode->QueryIntAttribute( "y", &y ); style->normalBGlocation[orientation] = wxPoint( x, y ); style->HasBackground( true ); continue; } if( nodeType == _T("active-location") ) { int x, y; attrNode->QueryIntAttribute( "x", &x ); attrNode->QueryIntAttribute( "y", &y ); style->activeBGlocation[orientation] = wxPoint( x, y ); continue; } if( nodeType == _T("size") ) { int x, y; attrNode->QueryIntAttribute( "x", &x ); attrNode->QueryIntAttribute( "y", &y ); style->toolSize[orientation] = wxSize( x, y ); continue; } if( nodeType == _T("icon-offset") ) { int x, y; attrNode->QueryIntAttribute( "x", &x ); attrNode->QueryIntAttribute( "y", &y ); style->verticalIconOffset = wxSize( x, y ); continue; } } continue; } if( nodeType == _T("compass") ) { TiXmlElement* attrNode = toolNode->FirstChild()->ToElement(); for( ; attrNode; attrNode = attrNode->NextSiblingElement() ) { wxString nodeType( attrNode->Value(), wxConvUTF8 ); if( nodeType == _T("margin") ) { attrNode->QueryIntAttribute( "top", &style->compassMarginTop ); attrNode->QueryIntAttribute( "right", &style->compassMarginRight ); attrNode->QueryIntAttribute( "bottom", &style->compassMarginBottom ); attrNode->QueryIntAttribute( "left", &style->compassMarginLeft ); continue; } if( nodeType == _T("compass-corners") ) { int r; attrNode->QueryIntAttribute( "radius", &r ); style->compasscornerRadius = r; continue; } if( nodeType == _T("offset") ) { attrNode->QueryIntAttribute( "x", &style->compassXoffset ); attrNode->QueryIntAttribute( "y", &style->compassYoffset ); continue; } } } if( nodeType == _T("tool") ) { Tool* tool = new Tool(); style->tools.Add( tool ); tool->name = wxString( toolNode->Attribute( "name" ), wxConvUTF8 ); style->toolIndex[tool->name] = style->tools.Count() - 1; TiXmlHandle toolHandle( toolNode ); TiXmlElement* toolTag = toolHandle.Child( "icon-location", 0 ).ToElement(); if( toolTag ) { int x, y; toolTag->QueryIntAttribute( "x", &x ); toolTag->QueryIntAttribute( "y", &y ); tool->iconLoc = wxPoint( x, y ); } toolTag = toolHandle.Child( "rollover-location", 0 ).ToElement(); if( toolTag ) { int x, y; toolTag->QueryIntAttribute( "x", &x ); toolTag->QueryIntAttribute( "y", &y ); tool->rolloverLoc = wxPoint( x, y ); } toolTag = toolHandle.Child( "disabled-location", 0 ).ToElement(); if( toolTag ) { int x, y; toolTag->QueryIntAttribute( "x", &x ); toolTag->QueryIntAttribute( "y", &y ); tool->disabledLoc = wxPoint( x, y ); } toolTag = toolHandle.Child( "size", 0 ).ToElement(); if( toolTag ) { int x, y; toolTag->QueryIntAttribute( "x", &x ); toolTag->QueryIntAttribute( "y", &y ); tool->customSize = wxSize( x, y ); } continue; } } continue; } } } } } }
void LoadMaterial(TiXmlElement *element) { Material *mtl = NULL; // name const char* name = element->Attribute("name"); printf("Material ["); if ( name ) printf("%s",name); printf("]"); // type const char* type = element->Attribute("type"); if ( type ) { if ( COMPARE(type,"blinn") ) { printf(" - Blinn\n"); MtlBlinn *m = new MtlBlinn(); mtl = m; for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { Color c(1,1,1); float f=1; if ( COMPARE( child->Value(), "diffuse" ) ) { ReadColor( child, c ); m->SetDiffuse(c); printf(" diffuse %f %f %f\n",c.r,c.g,c.b); m->SetDiffuseTexture( ReadTexture(child) ); } else if ( COMPARE( child->Value(), "specular" ) ) { ReadColor( child, c ); m->SetSpecular(c); printf(" specular %f %f %f\n",c.r,c.g,c.b); m->SetSpecularTexture( ReadTexture(child) ); } else if ( COMPARE( child->Value(), "glossiness" ) ) { ReadFloat( child, f ); m->SetGlossiness(f); printf(" glossiness %f\n",f); } else if ( COMPARE( child->Value(), "reflection" ) ) { ReadColor( child, c ); m->SetReflection(c); printf(" reflection %f %f %f\n",c.r,c.g,c.b); m->SetReflectionTexture( ReadTexture(child) ); } else if ( COMPARE( child->Value(), "refraction" ) ) { ReadColor( child, c ); m->SetRefraction(c); ReadFloat( child, f, "index" ); m->SetRefractionIndex(f); printf(" refraction %f %f %f (index %f)\n",c.r,c.g,c.b,f); m->SetRefractionTexture( ReadTexture(child) ); } else if ( COMPARE( child->Value(), "absorption" ) ) { ReadColor( child, c ); m->SetAbsorption(c); printf(" absorption %f %f %f\n",c.r,c.g,c.b); } } } else { printf(" - UNKNOWN\n"); } } if ( mtl ) { mtl->SetName(name); materials.push_back(mtl); } }
// ---------------------------------------------------------------------------- // Scene* VenueReader::read( TiXmlElement* self, Scene* scene ) { scene = new Scene(); readDObject( self, scene, "scene_number" ); scene->m_bpm_rating = (BPMRating)read_int_attribute( self, "bpm_rating", BPMRating::BPM_NO_RATING); std::vector<SceneActor *> actors = read_xml_list<SceneActor>( self->FirstChildElement( "actors" ), "actor" ); for ( std::vector<SceneActor *>::iterator it=actors.begin(); it != actors.end(); ++it ) { scene->addActor( *(*it) ); delete (*it); } TiXmlElement* acts = self->FirstChildElement( "acts" ); if ( acts ) { TiXmlElement* element = acts->FirstChildElement( "act" ); while ( element ) { scene->m_acts.insert( read_unsigned_attribute( element, "number" ) ) ; element = element->NextSiblingElement(); } } TiXmlElement* container = self->FirstChildElement( "animations" ); if ( container ) { TiXmlElement* element = container->FirstChildElement( "animation" ); while ( element ) { const char* class_name = read_text_attribute( element, "class" ); AbstractAnimation* animation = NULL; if ( !strcmp( class_name, SceneSequence::className ) ) animation = read( element, (SceneSequence*)NULL ); else if ( !strcmp( class_name, SceneSoundLevel::className ) ) animation = read( element, (SceneSoundLevel*)NULL ); else if ( !strcmp( class_name, SceneChannelAnimator::className ) ) animation = read( element, (SceneChannelAnimator*)NULL ); else if ( !strcmp( class_name, ScenePatternDimmer::className ) ) animation = read( element, (ScenePatternDimmer*)NULL ); else if ( !strcmp( class_name, SceneColorFader::className ) ) animation = read( element, (SceneColorFader*)NULL ); else if ( !strcmp( class_name, SceneMovementAnimator::className ) ) animation = read( element, (SceneMovementAnimator*)NULL ); else if ( !strcmp( class_name, SceneStrobeAnimator::className ) ) animation = read( element, (SceneStrobeAnimator*)NULL ); else if ( !strcmp( class_name, ScenePixelAnimator::className ) ) animation = read( element, (ScenePixelAnimator*)NULL ); else if ( !strcmp( class_name, SceneChannelFilter::className ) ) animation = read( element, (SceneChannelFilter*)NULL ); else STUDIO_ASSERT( false, "Unknown animation class '%s'", class_name ); scene->addAnimation( animation ); element = element->NextSiblingElement(); } } return scene; }
void LoadLight(TiXmlElement *element) { Light *light = NULL; // name const char* name = element->Attribute("name"); printf("Light ["); if ( name ) printf("%s",name); printf("]"); // type const char* type = element->Attribute("type"); if ( type ) { if ( COMPARE(type,"ambient") ) { printf(" - Ambient\n"); AmbientLight *l = new AmbientLight(); light = l; for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "intensity" ) ) { Color c(1,1,1); ReadColor( child, c ); l->SetIntensity(c); printf(" intensity %f %f %f\n",c.r,c.g,c.b); } } } else if ( COMPARE(type,"direct") ) { printf(" - Direct\n"); DirectLight *l = new DirectLight(); light = l; for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "intensity" ) ) { Color c(1,1,1); ReadColor( child, c ); l->SetIntensity(c); printf(" intensity %f %f %f\n",c.r,c.g,c.b); } else if ( COMPARE( child->Value(), "direction" ) ) { Point3 v(1,1,1); ReadVector( child, v ); l->SetDirection(v); printf(" direction %f %f %f\n",v.x,v.y,v.z); } } } else if ( COMPARE(type,"point") ) { printf(" - Point\n"); PointLight *l = new PointLight(); light = l; for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "intensity" ) ) { Color c(1,1,1); ReadColor( child, c ); l->SetIntensity(c); printf(" intensity %f %f %f\n",c.r,c.g,c.b); } else if ( COMPARE( child->Value(), "position" ) ) { Point3 v(0,0,0); ReadVector( child, v ); l->SetPosition(v); printf(" position %f %f %f\n",v.x,v.y,v.z); } } } else { printf(" - UNKNOWN\n"); } } if ( light ) { light->SetName(name); lights.push_back(light); } }
void DirectoryWriter::WriteNode(string nodeName, string directory,string editDate) { TiXmlDocument doc("Config.xml"); bool loadOkay = doc.LoadFile(); if (!loadOkay) { printf("Could not load test file 'Config.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc()); exit(1); } TiXmlNode *versionNode = 0; versionNode = doc.FirstChild("Version"); TiXmlElement *versionelement = versionNode->ToElement(); std::string version = versionelement->Attribute("Number"); int value = atoi(version.c_str()); value += 1; versionelement->SetAttribute("Number", value); ///// TiXmlNode *node = 0; node = doc.FirstChild("Filesystem"); TiXmlElement *element = node->FirstChildElement("File"); if (element == NULL) { TiXmlElement newFile("File"); newFile.SetAttribute("filename", nodeName.c_str()); newFile.SetAttribute("Originalname", nodeName.c_str()); newFile.SetAttribute("directory", directory.c_str()); newFile.SetAttribute("Editdate", editDate.c_str()); TiXmlNode *node = 0; node = doc.FirstChild("Filesystem"); TiXmlElement *rootElement = 0; rootElement = node->ToElement(); rootElement->InsertEndChild(newFile); } else { TiXmlElement *searchNode = 0; bool found = false; for (TiXmlElement* e = node->FirstChildElement("File"); e != NULL; e = e->NextSiblingElement("File")) { found = false; const char *attribute = e->Attribute("Originalname"); if (strcmp(attribute, nodeName.c_str()) == 0) { UpdateNode(nodeName,directory,editDate); found = true; } if (!found) { TiXmlElement newFile("File"); newFile.SetAttribute("filename", nodeName.c_str()); newFile.SetAttribute("Originalname", nodeName.c_str()); newFile.SetAttribute("directory", directory.c_str()); newFile.SetAttribute("Editdate", editDate.c_str()); TiXmlNode *node = 0; node = doc.FirstChild("Filesystem"); TiXmlElement *rootElement = 0; rootElement = node->ToElement(); rootElement->InsertEndChild(newFile); break; } } } doc.SaveFile(); }
FloatingRate::FloatingRate(TiXmlNode* xmlNode) : Rate(xmlNode) { #ifdef ConsolePrint std::string initialtap_ = FileManager::instance().tap_; FileManager::instance().tap_.append(" "); #endif //floatingRateIndexNode ---------------------------------------------------------------------------------------------------------------------- TiXmlElement* floatingRateIndexNode = xmlNode->FirstChildElement("floatingRateIndex"); if(floatingRateIndexNode){floatingRateIndexIsNull_ = false;} else{floatingRateIndexIsNull_ = true;} #ifdef ConsolePrint FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "- floatingRateIndexNode , address : " << floatingRateIndexNode << std::endl; #endif if(floatingRateIndexNode) { if(floatingRateIndexNode->Attribute("href") || floatingRateIndexNode->Attribute("id")) { if(floatingRateIndexNode->Attribute("id")) { floatingRateIndexIDRef_ = floatingRateIndexNode->Attribute("id"); floatingRateIndex_ = boost::shared_ptr<FloatingRateIndex>(new FloatingRateIndex(floatingRateIndexNode)); floatingRateIndex_->setID(floatingRateIndexIDRef_); IDManager::instance().setID(floatingRateIndexIDRef_,floatingRateIndex_); } else if(floatingRateIndexNode->Attribute("href")) { floatingRateIndexIDRef_ = floatingRateIndexNode->Attribute("href");} else { QL_FAIL("id or href error"); } } else { floatingRateIndex_ = boost::shared_ptr<FloatingRateIndex>(new FloatingRateIndex(floatingRateIndexNode));} } //indexTenorNode ---------------------------------------------------------------------------------------------------------------------- TiXmlElement* indexTenorNode = xmlNode->FirstChildElement("indexTenor"); if(indexTenorNode){indexTenorIsNull_ = false;} else{indexTenorIsNull_ = true;} #ifdef ConsolePrint FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "- indexTenorNode , address : " << indexTenorNode << std::endl; #endif if(indexTenorNode) { if(indexTenorNode->Attribute("href") || indexTenorNode->Attribute("id")) { if(indexTenorNode->Attribute("id")) { indexTenorIDRef_ = indexTenorNode->Attribute("id"); indexTenor_ = boost::shared_ptr<Period>(new Period(indexTenorNode)); indexTenor_->setID(indexTenorIDRef_); IDManager::instance().setID(indexTenorIDRef_,indexTenor_); } else if(indexTenorNode->Attribute("href")) { indexTenorIDRef_ = indexTenorNode->Attribute("href");} else { QL_FAIL("id or href error"); } } else { indexTenor_ = boost::shared_ptr<Period>(new Period(indexTenorNode));} } //floatingRateMultiplierScheduleNode ---------------------------------------------------------------------------------------------------------------------- TiXmlElement* floatingRateMultiplierScheduleNode = xmlNode->FirstChildElement("floatingRateMultiplierSchedule"); if(floatingRateMultiplierScheduleNode){floatingRateMultiplierScheduleIsNull_ = false;} else{floatingRateMultiplierScheduleIsNull_ = true;} #ifdef ConsolePrint FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "- floatingRateMultiplierScheduleNode , address : " << floatingRateMultiplierScheduleNode << std::endl; #endif if(floatingRateMultiplierScheduleNode) { if(floatingRateMultiplierScheduleNode->Attribute("href") || floatingRateMultiplierScheduleNode->Attribute("id")) { if(floatingRateMultiplierScheduleNode->Attribute("id")) { floatingRateMultiplierScheduleIDRef_ = floatingRateMultiplierScheduleNode->Attribute("id"); floatingRateMultiplierSchedule_ = boost::shared_ptr<Schedule>(new Schedule(floatingRateMultiplierScheduleNode)); floatingRateMultiplierSchedule_->setID(floatingRateMultiplierScheduleIDRef_); IDManager::instance().setID(floatingRateMultiplierScheduleIDRef_,floatingRateMultiplierSchedule_); } else if(floatingRateMultiplierScheduleNode->Attribute("href")) { floatingRateMultiplierScheduleIDRef_ = floatingRateMultiplierScheduleNode->Attribute("href");} else { QL_FAIL("id or href error"); } } else { floatingRateMultiplierSchedule_ = boost::shared_ptr<Schedule>(new Schedule(floatingRateMultiplierScheduleNode));} } //spreadScheduleNode ---------------------------------------------------------------------------------------------------------------------- TiXmlElement* spreadScheduleNode = xmlNode->FirstChildElement("spreadSchedule"); if(spreadScheduleNode){spreadScheduleIsNull_ = false;} else{spreadScheduleIsNull_ = true;} if(spreadScheduleNode) { for(spreadScheduleNode; spreadScheduleNode; spreadScheduleNode = spreadScheduleNode->NextSiblingElement("spreadSchedule")){ #ifdef ConsolePrint FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "- spreadScheduleNode , address : " << spreadScheduleNode << std::endl; #endif if(spreadScheduleNode->Attribute("href") || spreadScheduleNode->Attribute("id")) { if(spreadScheduleNode->Attribute("id")) { spreadScheduleIDRef_ = spreadScheduleNode->Attribute("id"); spreadSchedule_.push_back(boost::shared_ptr<SpreadSchedule>(new SpreadSchedule(spreadScheduleNode))); spreadSchedule_.back()->setID(spreadScheduleIDRef_); IDManager::instance().setID(spreadScheduleIDRef_, spreadSchedule_.back()); } else if(spreadScheduleNode->Attribute("href")) { spreadScheduleIDRef_ = spreadScheduleNode->Attribute("href");} else { QL_FAIL("id or href error"); } } else { spreadSchedule_.push_back(boost::shared_ptr<SpreadSchedule>(new SpreadSchedule(spreadScheduleNode)));} } } else { #ifdef ConsolePrint FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "- spreadScheduleNode , address : " << spreadScheduleNode << std::endl; #endif } //rateTreatmentNode ---------------------------------------------------------------------------------------------------------------------- TiXmlElement* rateTreatmentNode = xmlNode->FirstChildElement("rateTreatment"); if(rateTreatmentNode){rateTreatmentIsNull_ = false;} else{rateTreatmentIsNull_ = true;} #ifdef ConsolePrint FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "- rateTreatmentNode , address : " << rateTreatmentNode << std::endl; #endif if(rateTreatmentNode) { if(rateTreatmentNode->Attribute("href") || rateTreatmentNode->Attribute("id")) { if(rateTreatmentNode->Attribute("id")) { rateTreatmentIDRef_ = rateTreatmentNode->Attribute("id"); rateTreatment_ = boost::shared_ptr<RateTreatmentEnum>(new RateTreatmentEnum(rateTreatmentNode)); rateTreatment_->setID(rateTreatmentIDRef_); IDManager::instance().setID(rateTreatmentIDRef_,rateTreatment_); } else if(rateTreatmentNode->Attribute("href")) { rateTreatmentIDRef_ = rateTreatmentNode->Attribute("href");} else { QL_FAIL("id or href error"); } } else { rateTreatment_ = boost::shared_ptr<RateTreatmentEnum>(new RateTreatmentEnum(rateTreatmentNode));} } //capRateScheduleNode ---------------------------------------------------------------------------------------------------------------------- TiXmlElement* capRateScheduleNode = xmlNode->FirstChildElement("capRateSchedule"); if(capRateScheduleNode){capRateScheduleIsNull_ = false;} else{capRateScheduleIsNull_ = true;} if(capRateScheduleNode) { for(capRateScheduleNode; capRateScheduleNode; capRateScheduleNode = capRateScheduleNode->NextSiblingElement("capRateSchedule")){ #ifdef ConsolePrint FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "- capRateScheduleNode , address : " << capRateScheduleNode << std::endl; #endif if(capRateScheduleNode->Attribute("href") || capRateScheduleNode->Attribute("id")) { if(capRateScheduleNode->Attribute("id")) { capRateScheduleIDRef_ = capRateScheduleNode->Attribute("id"); capRateSchedule_.push_back(boost::shared_ptr<StrikeSchedule>(new StrikeSchedule(capRateScheduleNode))); capRateSchedule_.back()->setID(capRateScheduleIDRef_); IDManager::instance().setID(capRateScheduleIDRef_, capRateSchedule_.back()); } else if(capRateScheduleNode->Attribute("href")) { capRateScheduleIDRef_ = capRateScheduleNode->Attribute("href");} else { QL_FAIL("id or href error"); } } else { capRateSchedule_.push_back(boost::shared_ptr<StrikeSchedule>(new StrikeSchedule(capRateScheduleNode)));} } } else { #ifdef ConsolePrint FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "- capRateScheduleNode , address : " << capRateScheduleNode << std::endl; #endif } //floorRateScheduleNode ---------------------------------------------------------------------------------------------------------------------- TiXmlElement* floorRateScheduleNode = xmlNode->FirstChildElement("floorRateSchedule"); if(floorRateScheduleNode){floorRateScheduleIsNull_ = false;} else{floorRateScheduleIsNull_ = true;} if(floorRateScheduleNode) { for(floorRateScheduleNode; floorRateScheduleNode; floorRateScheduleNode = floorRateScheduleNode->NextSiblingElement("floorRateSchedule")){ #ifdef ConsolePrint FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "- floorRateScheduleNode , address : " << floorRateScheduleNode << std::endl; #endif if(floorRateScheduleNode->Attribute("href") || floorRateScheduleNode->Attribute("id")) { if(floorRateScheduleNode->Attribute("id")) { floorRateScheduleIDRef_ = floorRateScheduleNode->Attribute("id"); floorRateSchedule_.push_back(boost::shared_ptr<StrikeSchedule>(new StrikeSchedule(floorRateScheduleNode))); floorRateSchedule_.back()->setID(floorRateScheduleIDRef_); IDManager::instance().setID(floorRateScheduleIDRef_, floorRateSchedule_.back()); } else if(floorRateScheduleNode->Attribute("href")) { floorRateScheduleIDRef_ = floorRateScheduleNode->Attribute("href");} else { QL_FAIL("id or href error"); } } else { floorRateSchedule_.push_back(boost::shared_ptr<StrikeSchedule>(new StrikeSchedule(floorRateScheduleNode)));} } } else { #ifdef ConsolePrint FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "- floorRateScheduleNode , address : " << floorRateScheduleNode << std::endl; #endif } #ifdef ConsolePrint FileManager::instance().tap_ = initialtap_; #endif }