bool CThemeProvider::ThemeHasSize(const wxString& themePath, const wxString& size) { wxFileName fn(wxGetApp().GetResourceDir() + themePath, _T("theme.xml")); TiXmlElement* pDocument = GetXmlFile(fn.GetFullPath(), false); if (!pDocument) return false; TiXmlElement* pTheme = pDocument->FirstChildElement("Theme"); if (!pTheme) { delete pDocument->GetDocument(); return false; } for (TiXmlElement* pSize = pTheme->FirstChildElement("size"); pSize; pSize = pSize->NextSiblingElement("size")) { const char* txt = pSize->GetText(); if (!txt) continue; if (size == ConvLocal(txt)) { delete pDocument->GetDocument(); return true; } } delete pDocument->GetDocument(); return false; }
void CWrapEngine::SetWidthToCache(const char* name, int width) { if (!m_use_cache) return; if (!name || !*name) return; // We have to synchronize access to layout.xml so that multiple processed don't write // to the same file or one is reading while the other one writes. CInterProcessMutex mutex(MUTEX_LAYOUT); wxFileName file(COptions::Get()->GetOption(OPTION_DEFAULT_SETTINGSDIR), _T("layout.xml")); TiXmlElement* pDocument = GetXmlFile(file); if (!pDocument) return; TiXmlElement* pElement = pDocument->FirstChildElement("Layout"); if (!pElement) { delete pDocument->GetDocument(); return; } wxString language = wxGetApp().GetCurrentLanguageCode(); if (language.empty()) language = _T("default"); TiXmlElement* pLanguage = FindElementWithAttribute(pElement, "Language", "id", language.mb_str()); if (!pLanguage) { delete pDocument->GetDocument(); return; } TiXmlElement* pDialog = FindElementWithAttribute(pLanguage, "Dialog", "name", name); if (!pDialog) { pDialog = pLanguage->LinkEndChild(new TiXmlElement("Dialog"))->ToElement(); pDialog->SetAttribute("name", name); } pDialog->SetAttribute("width", width); wxString error; SaveXmlFile(file, pDocument, &error); delete pDocument->GetDocument(); }
int ExportAnyData(CString filename, vector<string> &orders) { Book* book = xlCreateBook(); if(!book) return 0; for(vector<string>::iterator it = orders.begin(); it != orders.end(); it++) { CString Filename = it->c_str(); Filename += ".xml"; TiXmlElement *Root = getXMLRoot(Filename); Sheet* sheet = book->addSheet(it->c_str()); if(!sheet) return 0; addOneSheet(sheet, Root); delete Root->GetDocument(); } if(book->save(_T(filename.GetBuffer(0)) )) { return 1; } else { return 0; } book->release(); }
bool StoryDataCenter::LoadDataFromXML() { if (mIsLoadAllData) { return true; } mIsLoadAllData = true; std::string filePath = std::string("Data/") + std::string("cutscene.xml"); TiXmlElement *RootElement = initXML(filePath.c_str()); if (0 != RootElement) { TiXmlElement *childElement = RootElement->FirstChildElement(); while (0 != childElement) { ReadOneXmlItem(childElement); childElement = childElement->NextSiblingElement(); } TiXmlDocument *doc = RootElement->GetDocument(); doc->Clear(); CC_SAFE_DELETE(doc); GetMainLandStoryData(); } else { return false; } return true; }
TiXmlElement* CXmlFile::Load(const wxFileName& fileName) { if (fileName.IsOk()) SetFileName(fileName); wxCHECK(m_fileName.IsOk(), 0); delete m_pDocument; m_pDocument = 0; TiXmlElement* pElement = GetXmlFile(m_fileName); if (!pElement) { m_modificationTime = wxDateTime(); return 0; } { wxLogNull log; m_modificationTime = m_fileName.GetModificationTime(); } m_pDocument = pElement->GetDocument(); return pElement; }
TiXmlElement* CXmlFile::Load(const wxFileName& fileName) { if (fileName.IsOk()) SetFileName(fileName); wxCHECK(m_fileName.IsOk(), 0); delete m_pDocument; m_pDocument = 0; wxString error; TiXmlElement* pElement = GetXmlFile(m_fileName, &error); if (!pElement) { if (!error.empty()) { m_error.Printf(_("The file '%s' could not be loaded."), m_fileName.GetFullPath().c_str()); if (!error.empty()) m_error += _T("\n") + error; else m_error += wxString(_T("\n")) + _("Make sure the file can be accessed and is a well-formed XML document."); m_modificationTime = wxDateTime(); } return 0; } { wxLogNull log; m_modificationTime = m_fileName.GetModificationTime(); } m_pDocument = pElement->GetDocument(); return pElement; }
std::list<wxString> CThemeProvider::GetThemeSizes(const wxString& themePath) { std::list<wxString> sizes; wxFileName fn(wxGetApp().GetResourceDir() + themePath, _T("theme.xml")); TiXmlElement* pDocument = GetXmlFile(fn.GetFullPath(), false); if (!pDocument) return sizes; TiXmlElement* pTheme = pDocument->FirstChildElement("Theme"); if (pTheme) { for (TiXmlElement* pSize = pTheme->FirstChildElement("size"); pSize; pSize = pSize->NextSiblingElement("size")) { const char* txt = pSize->GetText(); if (!txt) continue; wxString size = ConvLocal(txt); if (size == _T("")) continue; sizes.push_back(size); } } delete pDocument->GetDocument(); return sizes; }
bool XMLSceneVisitor::VisitExit( const TiXmlElement& element) { if(element.ValueStr() == "scene") { return (element.Parent() == element.GetDocument()); } else if (element.ValueStr() == "materials") { return true; } else if (element.ValueStr() == "primitives") { return true; } else if (element.ValueStr() == "plane") { m_scene->insert_primitive(m_current); m_current = NULL; return true; } else if (element.ValueStr() == "sphere") { m_scene->insert_primitive(m_current); m_current = NULL; return true; } else return false; }
void csTinyXmlNode::SetAttributeAsFloat (const char* name, float value) { TiXmlElement* el = node->ToElement (); if (el) { csString v; v.Format ("%g", value); el->SetAttribute (el->GetDocument (), name, v); } }
bool XMLSceneVisitor::VisitEnter(const TiXmlElement& element, const TiXmlAttribute* attribute) { if(element.ValueStr() == "scene") { return (element.Parent() == element.GetDocument()); } else if (element.ValueStr() == "materials") { return true; } else if (element.ValueStr() == "primitives") { return (element.Parent()->ValueStr() == "scene"); } else if (element.ValueStr() == "plane") { if(element.Parent()->ValueStr() != "primitives") return false; assert(m_current == NULL); double nx(0.0f), ny(1.0f), nz(0.0f), value(0.0f); element.Attribute("nx", &nx); element.Attribute("ny", &ny); element.Attribute("nz", &nz); element.Attribute("value", &value); glm::vec3 normal(nx, ny, nz); normal = glm::normalize(normal); m_current = new Scene::Plane(normal, value); return true; } else if (element.ValueStr() == "sphere") { if(element.Parent()->ValueStr() != "primitives") return false; assert(m_current == NULL); double cx(0.0f), cy(1.0f), cz(0.0f), radius(0.0f); element.Attribute("cx", &cx); element.Attribute("cy", &cy); element.Attribute("cz", &cz); element.Attribute("radius", &radius); glm::vec3 center(cx, cy, cz); m_current = new Scene::Sphere(center, radius); return true; } else return false; }
void ParticleFactory::InitXML() { std::string pPath = GameResourceManager::sharedManager()->storedFullPathFromRelativePath("Data/particles.xml"); unsigned long _size; char *_pFileContent = (char*)CCFileUtils::sharedFileUtils()->getFileData(pPath.c_str() , "r", &_size); TiXmlDocument *_document = new TiXmlDocument(); _document->Parse(_pFileContent, 0, TIXML_ENCODING_UTF8); CC_SAFE_DELETE_ARRAY(_pFileContent); TiXmlElement *RootElement = _document->RootElement(); if (RootElement) { TiXmlElement *childElement = RootElement->FirstChildElement(); while (0 != childElement) { OneParticleInfo oneParticleInfo; TiXmlAttribute* pAttribute = childElement->FirstAttribute(); while(pAttribute) { std::string strName(pAttribute->Name()); std::string content = childElement->Attribute(strName.c_str()); if (strName == "ID") { unsigned int id = atoi(content.c_str()); oneParticleInfo.id = id; } else if (strName == "fileName") { oneParticleInfo.fileName = content; } pAttribute = pAttribute->Next(); } m_particleListInfo.insert(std::make_pair(oneParticleInfo.id,oneParticleInfo)); childElement = childElement->NextSiblingElement(); } TiXmlDocument *doc = RootElement->GetDocument(); doc->Clear(); CC_SAFE_DELETE(doc); } }
bool CThemeProvider::GetThemeData(const wxString& themePath, wxString& name, wxString& author, wxString& email) { wxFileName fn(wxGetApp().GetResourceDir() + themePath, _T("theme.xml")); TiXmlElement* pDocument = GetXmlFile(fn.GetFullPath(), false); if (!pDocument) return false; TiXmlElement* pTheme = pDocument->FirstChildElement("Theme"); if (pTheme) { name = GetTextElement(pTheme, "Name"); author = GetTextElement(pTheme, "Author"); email = GetTextElement(pTheme, "Mail"); } delete pDocument->GetDocument(); return pTheme != 0; }
void CFilterManager::LoadFilters() { if (m_loaded) return; m_loaded = true; CInterProcessMutex mutex(MUTEX_FILTERS); wxFileName file(wxGetApp().GetSettingsDir(), _T("filters.xml")); if (!file.FileExists()) { wxFileName defaults(wxGetApp().GetResourceDir(), _T("defaultfilters.xml")); if (defaults.FileExists()) { TiXmlElement* pDocument = GetXmlFile(defaults); if (pDocument) { SaveXmlFile(file, pDocument); delete pDocument->GetDocument(); } } } CXmlFile xml(file); TiXmlElement* pDocument = xml.Load(); if (!pDocument) { wxString msg = xml.GetError() + _T("\n\n") + _("Any changes made to the filters will not be saved."); wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR); return; } TiXmlElement *pFilters = pDocument->FirstChildElement("Filters"); if (!pFilters) return; TiXmlElement *pFilter = pFilters->FirstChildElement("Filter"); while (pFilter) { CFilter filter; filter.name = GetTextElement(pFilter, "Name"); if (filter.name == _T("")) { pFilter = pFilter->NextSiblingElement("Filter"); continue; } filter.filterFiles = GetTextElement(pFilter, "ApplyToFiles") == _T("1"); filter.filterDirs = GetTextElement(pFilter, "ApplyToDirs") == _T("1"); wxString type = GetTextElement(pFilter, "MatchType"); if (type == _T("Any")) filter.matchType = CFilter::any; else if (type == _T("None")) filter.matchType = CFilter::none; else filter.matchType = CFilter::all; filter.matchCase = GetTextElement(pFilter, "MatchCase") == _T("1"); TiXmlElement *pConditions = pFilter->FirstChildElement("Conditions"); if (!pConditions) { pFilter = pFilter->NextSiblingElement("Filter"); continue; } TiXmlElement *pCondition = pConditions->FirstChildElement("Condition"); while (pCondition) { CFilterCondition condition; int type = GetTextElementInt(pCondition, "Type", 0); switch (type) { case 0: condition.type = filter_name; break; case 1: condition.type = filter_size; break; case 2: condition.type = filter_attributes; break; case 3: condition.type = filter_permissions; break; case 4: condition.type = filter_path; break; default: pCondition = pCondition->NextSiblingElement("Condition"); continue; } condition.condition = GetTextElementInt(pCondition, "Condition", 0); condition.strValue = GetTextElement(pCondition, "Value"); condition.matchCase = filter.matchCase; if (condition.strValue == _T("")) { pCondition = pCondition->NextSiblingElement("Condition"); continue; } // TODO: 64bit filesize if (condition.type == filter_size) { unsigned long tmp; condition.strValue.ToULong(&tmp); condition.value = tmp; } else if (condition.type == filter_attributes || condition.type == filter_permissions) { if (condition.strValue == _T("0")) condition.value = 0; else condition.value = 1; } filter.filters.push_back(condition); pCondition = pCondition->NextSiblingElement("Condition"); } if (!filter.filters.empty()) m_globalFilters.push_back(filter); pFilter = pFilter->NextSiblingElement("Filter"); } CompileRegexes(); TiXmlElement* pSets = pDocument->FirstChildElement("Sets"); if (!pSets) return; for (TiXmlElement* pSet = pSets->FirstChildElement("Set"); pSet; pSet = pSet->NextSiblingElement("Set")) { CFilterSet set; TiXmlElement* pItem = pSet->FirstChildElement("Item"); while (pItem) { wxString local = GetTextElement(pItem, "Local"); wxString remote = GetTextElement(pItem, "Remote"); set.local.push_back(local == _T("1") ? true : false); set.remote.push_back(remote == _T("1") ? true : false); pItem = pItem->NextSiblingElement("Item"); } if (!m_globalFilterSets.empty()) { set.name = GetTextElement(pSet, "Name"); if (set.name == _T("")) continue; } if (set.local.size() == m_globalFilters.size()) m_globalFilterSets.push_back(set); } wxString attribute = GetTextAttribute(pSets, "Current"); unsigned long value; if (attribute.ToULong(&value)) { if (value < m_globalFilterSets.size()) m_globalCurrentFilterSet = value; } }
/// Visit an element. virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* attribute) { if(element.ValueStr() == "world") { if(element.Parent() != element.GetDocument()) return false; return true; } else if(element.ValueStr() == "materials") { if(element.Parent()->ValueStr() != "world") return false; return true; } else if(element.ValueStr() == "material") { if(element.Parent()->ValueStr() != "materials") return false; char const* name; double density = 1; double friction = 0; double restitution = 0; double cr = 0; double cg = 0; double cb = 0; name = element.Attribute("name"); if(!name) { return false; } element.Attribute("density", &density); element.Attribute("friction", &friction); element.Attribute("restitution", &restitution); element.Attribute("cr", &cr); element.Attribute("cg", &cg); element.Attribute("cb", &cb); // populate sound parameters double thickness; double youngsModulus; double fluidDamping; double viscoelasticDamping; element.Attribute("thickness", &thickness); element.Attribute("youngsModulus", &youngsModulus); element.Attribute("fluidDamping", &fluidDamping); element.Attribute("viscoelasticDamping", &viscoelasticDamping); // if any values are NULL then set them to the default thickness = thickness == NULL ? 0.1 : thickness; youngsModulus = youngsModulus == NULL ? 900 : youngsModulus; fluidDamping = fluidDamping == NULL ? 0.00001 : fluidDamping; viscoelasticDamping = viscoelasticDamping == NULL ? 0.1 : viscoelasticDamping; m_curMaterial = new Material(float(density), float(friction), float(restitution), Vector3(float(cr), float(cg), float(cb)), float(thickness), float(youngsModulus), float(fluidDamping), float(viscoelasticDamping)); m_materials[name] = m_curMaterial; return true; } else if(element.ValueStr() == "bodies") { if(element.Parent()->ValueStr() != "world") return false; return true; } else if(element.ValueStr() == "ground") { if(element.Parent()->ValueStr() != "bodies") return false; assert(m_curBody == NULL); m_curBody = new Ground(); return true; } else if(element.ValueStr() == "box") { if(element.Parent()->ValueStr() != "bodies") return false; assert(m_curBody == NULL); double hx = 1; double hy = 1; double hz = 1; element.Attribute("hx", &hx); element.Attribute("hy", &hy); element.Attribute("hz", &hz); m_curBody = new Box(Vector3(float(hx), float(hy), float(hz))); return true; } else if(element.ValueStr() == "sphere") { if(element.Parent()->ValueStr() != "bodies") return false; assert(m_curBody == NULL); double r = 1; element.Attribute("r", &r); m_curBody = new Sphere(float(r)); return true; } else if(element.ValueStr() == "id") { if(!IsBody(element.Parent())) return false; assert(m_curBody != NULL); int id = 0; element.Attribute("id", &id); m_curBody->SetID(id); return true; } else if(element.ValueStr() == "pos") { if(!IsBody(element.Parent())) return false; assert(m_curBody != NULL); double x = 0; double y = 0; double z = 0; element.Attribute("x", &x); element.Attribute("y", &y); element.Attribute("z", &z); m_curBody->SetPosition(Vector3(float(x), float(y), float(z))); return true; } else if(element.ValueStr() == "vel") { if(!IsBody(element.Parent())) return false; assert(m_curBody != NULL); double x = 0; double y = 0; double z = 0; element.Attribute("x", &x); element.Attribute("y", &y); element.Attribute("z", &z); m_curBody->SetVelocity(Vector3(float(x), float(y), float(z))); return true; } else if(element.ValueStr() == "ori") { if(!IsBody(element.Parent())) return false; assert(m_curBody != NULL); double theta = 0; double x = 0; double y = 0; double z = 0; element.Attribute("theta", &theta); element.Attribute("x", &x); element.Attribute("y", &y); element.Attribute("z", &z); m_curBody->SetOrientation(Quaternion(float(theta), Vector3(float(x), float(y), float(z)))); return true; } else if(element.ValueStr() == "avel") { if(!IsBody(element.Parent())) return false; assert(m_curBody != NULL); double x = 0; double y = 0; double z = 0; element.Attribute("x", &x); element.Attribute("y", &y); element.Attribute("z", &z); m_curBody->SetAngularVelocity(Vector3(float(x), float(y), float(z))); return true; } else if(element.ValueStr() == "bodymaterial") { if(!IsBody(element.Parent())) return false; assert(m_curBody != NULL); const char* name = element.Attribute("name"); Material* material = m_materials[name]; if(material != NULL) { m_curBody->SetMaterial(material); } return true; } else { return false; } assert(false); // we should never get here return false; }
void CFilterDialog::SaveFilters() { CInterProcessMutex mutex(MUTEX_FILTERS); wxFileName file(wxGetApp().GetSettingsDir(), _T("filters.xml")); TiXmlElement* pDocument = GetXmlFile(file); if (!pDocument) { wxString msg = wxString::Format(_("Could not load \"%s\", please make sure the file is valid and can be accessed.\nAny changes made in the Site Manager could not be saved."), file.GetFullPath().c_str()); wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR); return; } TiXmlElement *pFilters = pDocument->FirstChildElement("Filters"); while (pFilters) { pDocument->RemoveChild(pFilters); pFilters = pDocument->FirstChildElement("Filters"); } pFilters = pDocument->InsertEndChild(TiXmlElement("Filters"))->ToElement(); for (std::vector<CFilter>::const_iterator iter = m_globalFilters.begin(); iter != m_globalFilters.end(); iter++) { const CFilter& filter = *iter; TiXmlElement* pFilter = pFilters->InsertEndChild(TiXmlElement("Filter"))->ToElement(); AddTextElement(pFilter, "Name", filter.name); AddTextElement(pFilter, "ApplyToFiles", filter.filterFiles ? _T("1") : _T("0")); AddTextElement(pFilter, "ApplyToDirs", filter.filterDirs ? _T("1") : _T("0")); AddTextElement(pFilter, "MatchType", (filter.matchType == CFilter::any) ? _T("Any") : ((filter.matchType == CFilter::none) ? _T("None") : _T("All"))); AddTextElement(pFilter, "MatchCase", filter.matchCase ? _T("1") : _T("0")); TiXmlElement* pConditions = pFilter->InsertEndChild(TiXmlElement("Conditions"))->ToElement(); for (std::vector<CFilterCondition>::const_iterator conditionIter = filter.filters.begin(); conditionIter != filter.filters.end(); conditionIter++) { const CFilterCondition& condition = *conditionIter; TiXmlElement* pCondition = pConditions->InsertEndChild(TiXmlElement("Condition"))->ToElement(); AddTextElement(pCondition, "Type", condition.type); AddTextElement(pCondition, "Condition", condition.condition); AddTextElement(pCondition, "Value", condition.strValue); } } TiXmlElement *pSets = pDocument->FirstChildElement("Sets"); while (pSets) { pDocument->RemoveChild(pSets); pSets = pDocument->FirstChildElement("Sets"); } pSets = pDocument->InsertEndChild(TiXmlElement("Sets"))->ToElement(); SetTextAttribute(pSets, "Current", wxString::Format(_T("%d"), m_currentFilterSet)); for (std::vector<CFilterSet>::const_iterator iter = m_globalFilterSets.begin(); iter != m_globalFilterSets.end(); iter++) { const CFilterSet& set = *iter; TiXmlElement* pSet = pSets->InsertEndChild(TiXmlElement("Set"))->ToElement(); if (iter != m_globalFilterSets.begin()) AddTextElement(pSet, "Name", set.name); for (unsigned int i = 0; i < set.local.size(); i++) { TiXmlElement* pItem = pSet->InsertEndChild(TiXmlElement("Item"))->ToElement(); AddTextElement(pItem, "Local", set.local[i] ? _T("1") : _T("0")); AddTextElement(pItem, "Remote", set.remote[i] ? _T("1") : _T("0")); } } SaveXmlFile(file, pDocument); delete pDocument->GetDocument(); }
bool XMLSceneVisitor::VisitEnter(const TiXmlElement& element, const TiXmlAttribute* attribute) { if(element.ValueStr() == "scene") { return (element.Parent() == element.GetDocument()); } else if (element.ValueStr() == "materials") { return true; } else if (element.ValueStr() == "primitives") { return (element.Parent()->ValueStr() == "scene"); } else if (element.ValueStr() == "plane") { if(element.Parent()->ValueStr() != "primitives") return false; assert(m_current == NULL); double nx(0.0), ny(1.0), nz(0.0), value(0.0); element.Attribute("nx", &nx); element.Attribute("ny", &ny); element.Attribute("nz", &nz); element.Attribute("value", &value); glm::vec3 normal(nx, ny, nz); normal = glm::normalize(normal); m_current = new Plane(normal, value); m_current->m_ini_pos=m_current->m_pos; return true; } else if (element.ValueStr() == "sphere") { if(element.Parent()->ValueStr() != "primitives") return false; assert(m_current == NULL); double cx(0.0), cy(1.0), cz(0.0), radius(0.0); double vx,vy,vz; element.Attribute("cx", &cx); element.Attribute("cy", &cy); element.Attribute("cz", &cz); element.Attribute("vx", &vx); element.Attribute("vy", &vy); element.Attribute("vz", &vz); element.Attribute("radius", &radius); glm::vec3 center(cx, cy, cz); m_current = new Sphere(center, glm::vec3(vx,vy,vz),radius); m_current->m_ini_pos=m_current->m_pos; return true; } else if (element.ValueStr() == "cube") { if(element.Parent()->ValueStr() != "primitives") return false; assert(m_current == NULL); double cx(0.0), cy(1.0), cz(0.0), hx(0.0), hy(0.0), hz(0.0); element.Attribute("cx", &cx); element.Attribute("cy", &cy); element.Attribute("cz", &cz); element.Attribute("hx", &hx); element.Attribute("hy", &hy); element.Attribute("hz", &hz); glm::vec3 center(cx, cy, cz); glm::vec3 hf_dims(hx, hy, hz); m_current = new Cube(center, hf_dims); m_current->m_ini_pos=m_current->m_pos; return true; } else if (element.ValueStr() == "obj") { if(element.Parent()->ValueStr() != "primitives") return false; assert(m_current == NULL); double cx(0.0), cy(1.0), cz(0.0), scale(0.0); element.Attribute("cx", &cx); element.Attribute("cy", &cy); element.Attribute("cz", &cz); element.Attribute("scale", &scale); glm::vec3 center(cx, cy, cz); m_current = new ObjMesh(DEFAULT_OBJ_MODEL, center, scale); m_current->m_ini_pos=m_current->m_pos; return true; } else return false; }
void CFilterManager::LoadFilters() { if (m_loaded) return; m_loaded = true; CInterProcessMutex mutex(MUTEX_FILTERS); wxFileName file(COptions::Get()->GetOption(OPTION_DEFAULT_SETTINGSDIR), _T("filters.xml")); if (!file.FileExists()) { wxFileName defaults(wxGetApp().GetResourceDir(), _T("defaultfilters.xml")); if (defaults.FileExists()) { TiXmlElement* pDocument = GetXmlFile(defaults); if (pDocument) { SaveXmlFile(file, pDocument); delete pDocument->GetDocument(); } } } CXmlFile xml(file); TiXmlElement* pDocument = xml.Load(); if (!pDocument) { wxString msg = xml.GetError() + _T("\n\n") + _("Any changes made to the filters will not be saved."); wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR); return; } TiXmlElement *pFilters = pDocument->FirstChildElement("Filters"); if (!pFilters) return; TiXmlElement *pFilter = pFilters->FirstChildElement("Filter"); while (pFilter) { CFilter filter; bool loaded = LoadFilter(pFilter, filter); if (loaded && filter.name != _T("") && !filter.filters.empty()) m_globalFilters.push_back(filter); pFilter = pFilter->NextSiblingElement("Filter"); } CompileRegexes(); TiXmlElement* pSets = pDocument->FirstChildElement("Sets"); if (!pSets) return; for (TiXmlElement* pSet = pSets->FirstChildElement("Set"); pSet; pSet = pSet->NextSiblingElement("Set")) { CFilterSet set; TiXmlElement* pItem = pSet->FirstChildElement("Item"); while (pItem) { wxString local = GetTextElement(pItem, "Local"); wxString remote = GetTextElement(pItem, "Remote"); set.local.push_back(local == _T("1") ? true : false); set.remote.push_back(remote == _T("1") ? true : false); pItem = pItem->NextSiblingElement("Item"); } if (!m_globalFilterSets.empty()) { set.name = GetTextElement(pSet, "Name"); if (set.name == _T("")) continue; } if (set.local.size() == m_globalFilters.size()) m_globalFilterSets.push_back(set); } wxString attribute = GetTextAttribute(pSets, "Current"); unsigned long value; if (attribute.ToULong(&value)) { if (value < m_globalFilterSets.size()) m_globalCurrentFilterSet = value; } }
void CFilterManager::LoadFilters() { if (m_loaded) { m_filters = m_globalFilters; m_filterSets = m_globalFilterSets; m_currentFilterSet = m_globalCurrentFilterSet; return; } m_loaded = true; CInterProcessMutex mutex(MUTEX_FILTERS); wxFileName file(wxGetApp().GetSettingsDir(), _T("filters.xml")); if (!file.FileExists()) { wxFileName defaults(wxGetApp().GetResourceDir(), _T("defaultfilters.xml")); if (defaults.FileExists()) { TiXmlElement* pDocument = GetXmlFile(defaults); if (pDocument) SaveXmlFile(file, pDocument); } } TiXmlElement* pDocument = GetXmlFile(file); if (!pDocument) { wxString msg = wxString::Format(_("Could not load \"%s\", please make sure the file is valid and can be accessed.\nAny changes made in the Site Manager could not be saved."), file.GetFullPath().c_str()); wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR); return; } TiXmlElement *pFilters = pDocument->FirstChildElement("Filters"); if (!pFilters) { delete pDocument->GetDocument(); return; } TiXmlElement *pFilter = pFilters->FirstChildElement("Filter"); while (pFilter) { CFilter filter; filter.name = GetTextElement(pFilter, "Name"); if (filter.name == _T("")) { pFilter = pFilter->NextSiblingElement("Filter"); continue; } filter.filterFiles = GetTextElement(pFilter, "ApplyToFiles") == _T("1"); filter.filterDirs = GetTextElement(pFilter, "ApplyToDirs") == _T("1"); wxString type = GetTextElement(pFilter, "MatchType"); if (type == _T("Any")) filter.matchType = CFilter::any; else if (type == _T("None")) filter.matchType = CFilter::none; else filter.matchType = CFilter::all; filter.matchCase = GetTextElement(pFilter, "MatchCase") == _T("1"); TiXmlElement *pConditions = pFilter->FirstChildElement("Conditions"); if (!pConditions) { pFilter = pFilter->NextSiblingElement("Filter"); continue; } TiXmlElement *pCondition = pConditions->FirstChildElement("Condition"); while (pCondition) { CFilterCondition condition; int type = GetTextElementInt(pCondition, "Type", 0); if (type < 0 || type >= filterType_size) { pCondition = pCondition->NextSiblingElement("Condition"); continue; } condition.type = (enum t_filterType)type; condition.condition = GetTextElementInt(pCondition, "Condition", 0); condition.strValue = GetTextElement(pCondition, "Value"); condition.matchCase = filter.matchCase; if (condition.strValue == _T("")) { pCondition = pCondition->NextSiblingElement("Condition"); continue; } // TODO: 64bit filesize if (condition.type == size) { unsigned long tmp; condition.strValue.ToULong(&tmp); condition.value = tmp; } else if (condition.type == attributes || condition.type == permissions) { if (condition.strValue == _T("0")) condition.value = 0; else condition.value = 1; } filter.filters.push_back(condition); pCondition = pCondition->NextSiblingElement("Condition"); } if (!filter.filters.empty()) m_globalFilters.push_back(filter); pFilter = pFilter->NextSiblingElement("Filter"); } m_filters = m_globalFilters; TiXmlElement* pSets = pDocument->FirstChildElement("Sets"); if (!pSets) { delete pDocument->GetDocument(); return; } for (TiXmlElement* pSet = pSets->FirstChildElement("Set"); pSet; pSet = pSet->NextSiblingElement("Set")) { CFilterSet set; TiXmlElement* pItem = pSet->FirstChildElement("Item"); while (pItem) { wxString local = GetTextElement(pItem, "Local"); wxString remote = GetTextElement(pItem, "Remote"); set.local.push_back(local == _T("1") ? true : false); set.remote.push_back(remote == _T("1") ? true : false); pItem = pItem->NextSiblingElement("Item"); } if (!m_globalFilterSets.empty()) { set.name = GetTextElement(pSet, "Name"); if (set.name == _T("")) continue; } if (set.local.size() == m_filters.size()) m_globalFilterSets.push_back(set); } m_filterSets = m_globalFilterSets; wxString attribute = GetTextAttribute(pSets, "Current"); unsigned long value; if (attribute.ToULong(&value)) { if (value < m_globalFilterSets.size()) m_globalCurrentFilterSet = value; } m_currentFilterSet = m_globalCurrentFilterSet; delete pDocument->GetDocument(); }
void ParticleAnimation::init() { std::string tmpPath = "particles/" + m_rcsFileName + ".xml"; std::string pPath = GameResourceManager::sharedManager()->storedFullPathFromRelativePath(tmpPath.c_str()); unsigned long _size; char *_pFileContent = (char*)CCFileUtils::sharedFileUtils()->getFileData(pPath.c_str() , "r", &_size); TiXmlDocument *_document = new TiXmlDocument(); _document->Parse(_pFileContent, 0, TIXML_ENCODING_UTF8); CC_SAFE_DELETE_ARRAY(_pFileContent); TiXmlElement *RootElement = _document->RootElement(); if (RootElement) { TiXmlElement *childElement = RootElement->FirstChildElement(); while (0 != childElement) { const char* elementName = childElement->Value(); if (strcmp(elementName,"TotalFrames") == 0) { unsigned int totalFrames = atoi(childElement->Attribute("value")); m_nTotalFrames = totalFrames; } else if(strcmp(elementName,"Frames") == 0) { TiXmlElement *subChildElement = childElement->FirstChildElement(); while (subChildElement) { OneParticleSpritesInfo oneParticleSpriteInfo; TiXmlAttribute* pAttribute = subChildElement->FirstAttribute(); while(pAttribute) { std::string strName(pAttribute->Name()); std::string content = subChildElement->Attribute(strName.c_str()); if (strName == "fileName") { oneParticleSpriteInfo.spriteName = content; } else if (strName == "offsetX") { float pos = atof(content.c_str()); oneParticleSpriteInfo.offsetPoint.x = pos; } else if (strName == "offsetY") { float pos = atof(content.c_str()); oneParticleSpriteInfo.offsetPoint.y = pos; } pAttribute = pAttribute->Next(); } m_vecParticleSpritesInfo.push_back(oneParticleSpriteInfo); subChildElement = subChildElement->NextSiblingElement(); } } childElement = childElement->NextSiblingElement(); } TiXmlDocument *doc = RootElement->GetDocument(); doc->Clear(); CC_SAFE_DELETE(doc); } }
/// Visit an element. virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* attribute) { if(element.ValueStr() == "world") { if(element.Parent() != element.GetDocument()) return false; return true; } else if(element.ValueStr() == "materials") { return true; } else if(element.ValueStr() == "material") { return true; } else if(element.ValueStr() == "bodies") { if(element.Parent()->ValueStr() != "world") return false; return true; } else if(element.ValueStr() == "ground") { if(element.Parent()->ValueStr() != "bodies") return false; assert(m_curBody == NULL); m_curBody = new World::Ground(); return true; } else if(element.ValueStr() == "box") { if(element.Parent()->ValueStr() != "bodies") return false; assert(m_curBody == NULL); double hx = 0.5; double hy = 0.5; double hz = 0.5; element.Attribute("hx", &hx); element.Attribute("hy", &hy); element.Attribute("hz", &hz); World::Cube* cube = new World::Cube(); cube->hx = hx; cube->hy = hy; cube->hz = hz; m_curBody = cube; return true; } else if(element.ValueStr() == "sphere") { if(element.Parent()->ValueStr() != "bodies") return false; assert(m_curBody == NULL); double r = 1; element.Attribute("r", &r); World::Sphere* sphere = new World::Sphere(); sphere->r = r; m_curBody = sphere; return true; } else if(element.ValueStr() == "cylinder") { if(element.Parent()->ValueStr() != "bodies") return false; assert(m_curBody == NULL); double r = 1; double startx, starty, startz; double endx, endy, endz; element.Attribute("r", &r); element.Attribute("sx", &startx); element.Attribute("sy", &starty); element.Attribute("sz", &startz); element.Attribute("ex", &endx); element.Attribute("ey", &endy); element.Attribute("ez", &endz); World::Cylinder* cylinder = new World::Cylinder(); cylinder->start = vec3(startx, starty, startz); cylinder->end = vec3(endx, endy, endz); cylinder->r = r; m_curBody = cylinder; return true; } else if(element.ValueStr() == "pos") { if(!IsBody(element.Parent())) return false; assert(m_curBody != NULL); double x = 0; double y = 0; double z = 0; element.Attribute("x", &x); element.Attribute("y", &y); element.Attribute("z", &z); m_curBody->pos = vec3(float(x), float(y), float(z)); return true; } else if(element.ValueStr() == "vel") { return false; } else if(element.ValueStr() == "ori") { return false; } else if(element.ValueStr() == "avel") { return false; } else if(element.ValueStr() == "bodymaterial") { return false; } else { return false; } assert(false); // we should never get here return false; }
void csTinyXmlNode::SetAttributeAsInt (const char* name, int value) { TiXmlElement* el = node->ToElement (); if (el) el->SetAttribute (el->GetDocument (), name, value); }