int XmlGspInterface::readFile(const QString &fileName) { if(XMLQtInterface::readFile(fileName) == 0) return 0; QFileInfo fi(fileName); QString path = (fi.path().length() > 3) ? QString(fi.path() + "/") : fi.path(); QDomDocument doc("OGS-PROJECT-DOM"); doc.setContent(_fileData); QDomElement docElement = doc.documentElement(); //OpenGeoSysProject if (docElement.nodeName().compare("OpenGeoSysProject")) { ERR("XmlGspInterface::readFile(): Unexpected XML root."); return 0; } QDomNodeList fileList = docElement.childNodes(); for(int i = 0; i < fileList.count(); i++) { const QString file_node(fileList.at(i).nodeName()); if (file_node.compare("geo") == 0) { XmlGmlInterface gml(*(_project.getGEOObjects())); const QDomNodeList childList = fileList.at(i).childNodes(); for(int j = 0; j < childList.count(); j++) { const QDomNode child_node (childList.at(j)); if (child_node.nodeName().compare("file") == 0) { DBUG("XmlGspInterface::readFile(): path: \"%s\".", path.data()); DBUG("XmlGspInterface::readFile(): file name: \"%s\".", (child_node.toElement().text()).data()); gml.readFile(QString(path + child_node.toElement().text())); } } } else if (file_node.compare("stn") == 0) { XmlStnInterface stn(*(_project.getGEOObjects())); const QDomNodeList childList = fileList.at(i).childNodes(); for(int j = 0; j < childList.count(); j++) if (childList.at(j).nodeName().compare("file") == 0) stn.readFile(QString(path + childList.at(j).toElement().text())); } else if (file_node.compare("msh") == 0) { const std::string msh_name = path.toStdString() + fileList.at(i).toElement().text().toStdString(); MeshLib::Mesh* msh = FileIO::readMeshFromFile(msh_name); if (msh) _project.addMesh(msh); } } return 1; }
Graph::Graph(Canvas *canvas, string gmlFile, Page page, COff canvasOffset) : canvas_(canvas), gmlFileName(gmlFile), page(page), canvasOffset(canvasOffset), GA(G), shapes(G), timeStamps(G), connectors(G), edgeLengths(G), gbounds(DBL_MAX,DBL_MAX,-DBL_MAX,-DBL_MAX), scale(2), canvasShapesLimit(30), time(0), UML(true), UseClusters(canvas->useGmlClusters()) { canvas->setOptIdealEdgeLengthModifier(scale); canvas->setOptShapeNonoverlapPadding(4); GA.initAttributes( ogdf::GraphAttributes::nodeGraphics | ogdf::GraphAttributes::nodeLabel | ogdf::GraphAttributes::nodeType | ogdf::GraphAttributes::edgeType | ogdf::GraphAttributes::nodeTemplate | ogdf::GraphAttributes::nodeCluster | ogdf::GraphAttributes::nodeImageUrl); ifstream is(gmlFile.c_str()); ogdf::GmlParser gml(is,true); if (gml.error()||!gml.read(G,GA)) { ogdf::String message = gml.errorString(); int line = gml.getLineNumber(); cerr << "ERROR READING GML FILE: " << gmlFile << endl; cerr << "Message: "<<message<<endl; cerr << "Line: "<<line<<endl; throw "FILE ERROR!"; } ogdf::node v; shapes.fill(NULL); connectors.fill(NULL); edgeLengths.fill(1); timeStamps.fill(time); startNode=G.firstNode(); forall_nodes(v,G) { shapes[v] = NULL; GA.x(v)*=scale; GA.y(v)*=scale; GA.width(v)*=scale; GA.height(v)*=scale; string t(GA.templateNode(v).cstr()); if(t.size()>=15 && t.substr(10,5)=="START") { startNode = v; } //printf("node %s is in cluster %s\n",GA.labelNode(v).cstr(),GA.clusterNode(v).cstr()); }
int main(int argc, char**argv) { if(argc<3) { printf("Usage: %s (gml|csv) <nodes> <outputfile>\n", argv[0]); exit(1); } srand((unsigned)time(NULL)); int nodes = atoi(argv[2]); if(strncmp(argv[1], "gml", 3)==0) //create gml file { gml(nodes, argv[3]); return 0; } if(strncmp(argv[1], "csv", 3)==0) //create gml file { csv(nodes, argv[3]); return 0; } }
bool XmlGspInterface::write() { GeoLib::GEOObjects* geoObjects = _project.getGEOObjects(); QFileInfo fi(QString::fromStdString(_filename)); std::string path((fi.absolutePath()).toStdString() + "/"); _out << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; // xml definition _out << "<?xml-stylesheet type=\"text/xsl\" href=\"OpenGeoSysProject.xsl\"?>\n\n"; // stylefile definition QDomDocument doc("OGS-PROJECT-DOM"); QDomElement root = doc.createElement("OpenGeoSysProject"); root.setAttribute( "xmlns:ogs", "http://www.opengeosys.org" ); root.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); root.setAttribute( "xsi:noNamespaceSchemaLocation", "http://www.opengeosys.org/images/xsd/OpenGeoSysProject.xsd" ); doc.appendChild(root); // GML std::vector<std::string> geoNames; geoObjects->getGeometryNames(geoNames); for (std::vector<std::string>::const_iterator it(geoNames.begin()); it != geoNames.end(); ++it) { // write GLI file XmlGmlInterface gml(*geoObjects); std::string name(*it); gml.setNameForExport(name); if (gml.writeToFile(std::string(path + name + ".gml"))) { // write entry in project file QDomElement geoTag = doc.createElement("geo"); root.appendChild(geoTag); QDomElement fileNameTag = doc.createElement("file"); geoTag.appendChild(fileNameTag); QDomText fileNameText = doc.createTextNode(QString::fromStdString(name + ".gml")); fileNameTag.appendChild(fileNameText); } } // MSH const std::vector<MeshLib::Mesh*> msh_vec = _project.getMeshObjects(); for (std::vector<MeshLib::Mesh*>::const_iterator it(msh_vec.begin()); it != msh_vec.end(); ++it) { // write mesh file Legacy::MeshIO meshIO; meshIO.setMesh(*it); std::string fileName(path + (*it)->getName()); meshIO.writeToFile(fileName); // write entry in project file QDomElement mshTag = doc.createElement("msh"); root.appendChild(mshTag); QDomElement fileNameTag = doc.createElement("file"); mshTag.appendChild(fileNameTag); QDomText fileNameText = doc.createTextNode(QString::fromStdString((*it)->getName())); fileNameTag.appendChild(fileNameText); } // STN std::vector<std::string> stnNames; geoObjects->getStationVectorNames(stnNames); for (std::vector<std::string>::const_iterator it(stnNames.begin()); it != stnNames.end(); ++it) { // write STN file XmlStnInterface stn(*geoObjects); std::string name(*it); stn.setNameForExport(name); if (stn.writeToFile(path + name + ".stn")) { // write entry in project file QDomElement geoTag = doc.createElement("stn"); root.appendChild(geoTag); QDomElement fileNameTag = doc.createElement("file"); geoTag.appendChild(fileNameTag); QDomText fileNameText = doc.createTextNode(QString::fromStdString(name + ".stn")); fileNameTag.appendChild(fileNameText); } else ERR("XmlGspInterface::writeFile(): Error writing stn-file \"%s\".", name.c_str()); } std::string xml = doc.toString().toStdString(); _out << xml; return true; }
int XmlGspInterface::readFile(const QString &fileName) { QFile* file = new QFile(fileName); QFileInfo fi(fileName); QString path = (fi.path().length() > 3) ? QString(fi.path() + "/") : fi.path(); QFileInfo si(QString::fromStdString(_schemaName)); QString schemaPath(si.absolutePath() + "/"); if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { std::cout << "XmlGspInterface::readFile() - Can't open xml-file " << fileName.toStdString() << "." << std::endl; delete file; return 0; } if (!checkHash(fileName)) { delete file; return 0; } QDomDocument doc("OGS-PROJECT-DOM"); doc.setContent(file); QDomElement docElement = doc.documentElement(); //OpenGeoSysProject if (docElement.nodeName().compare("OpenGeoSysProject")) { std::cout << "XmlGspInterface::readFile() - Unexpected XML root." << std::endl; delete file; return 0; } QDomNodeList fileList = docElement.childNodes(); for(int i = 0; i < fileList.count(); i++) { const QString file_node(fileList.at(i).nodeName()); if (file_node.compare("geo") == 0) { XmlGmlInterface gml(_project, schemaPath.toStdString() + "OpenGeoSysGLI.xsd"); const QDomNodeList childList = fileList.at(i).childNodes(); for(int j = 0; j < childList.count(); j++) { const QDomNode child_node (childList.at(j)); if (child_node.nodeName().compare("file") == 0) { std::cout << "path: " << path.toStdString() << "#" << std::endl; std::cout << "file name: " << (child_node.toElement().text()).toStdString() << "#" << std::endl; gml.readFile(QString(path + child_node.toElement().text())); } } } else if (file_node.compare("stn") == 0) { XmlStnInterface stn(_project, schemaPath.toStdString() + "OpenGeoSysSTN.xsd"); const QDomNodeList childList = fileList.at(i).childNodes(); for(int j = 0; j < childList.count(); j++) if (childList.at(j).nodeName().compare("file") == 0) stn.readFile(QString(path + childList.at(j).toElement().text())); } else if (file_node.compare("msh") == 0) { const std::string msh_name = path.toStdString() + fileList.at(i).toElement().text().toStdString(); FileIO::MeshIO meshIO; MeshLib::Mesh* msh = meshIO.loadMeshFromFile(msh_name); _project->addMesh(msh); } } return 1; }
void GuildShell::guildMemberList(const uint8_t* data, size_t len) { // clear out any existing member data emit cleared(); m_members.clear(); m_maxNameLength = 0; // construct a netstream object on the data NetStream gml(data, len); // read the player name from the front of the stream QString player = gml.readText(); // read the player count from the stream uint32_t count; count = gml.readUInt32(); #ifdef GUILDSHELL_DIAG seqDebug("Guild has %d members:", count); #endif GuildMember* member; #ifdef GUILDSHELL_DIAG QDateTime dt; #endif // GUILDSHELL_DIAG // iterate over the data until we reach the end of it while (!gml.end()) { // create a new guildmember initializing it from the NetStream member = new GuildMember(gml); // insert the new member into the dictionary m_members.insert(member->name(), member); // check for new longest member name if (member->name().length() > m_maxNameLength) m_maxNameLength = member->name().length(); emit added(member); #ifdef GUILDSHELL_DIAG dt.setTime_t(member->lastOn()); seqDebug("%-64s\t%d\t%s\t%d\t%s\t'%s'\t%s:%d", (const char*)member->name(), member->level(), (const char*)classString(member->classVal()), member->guildRank(), (const char*)dt.toString(), (const char*)member->publicNote(), (const char*)m_zoneMgr->zoneNameFromID(member->zoneId()), member->zoneInstance()); #endif } emit loaded(); #ifdef GUILDSHELL_DIAG seqDebug("Finished processing %d guildmates. %d chars in longest name.", m_members.count(), m_maxNameLength); #endif // }