void Fenetre::ouvrir() { QString fileName = QFileDialog::getOpenFileName(this, tr("Séléctionner un fichier"), QDir::currentPath(), tr("Fichiers XML (*.xml)")); if (fileName.isEmpty()) return; QFile fileXML(fileName); if (!fileXML.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this, tr("Erreur lecture"), tr("Impossible de lire le fichier %1:\n%2.") .arg(fileName) .arg(fileXML.errorString())); return; } QFile fileSchema("schemaGraph.xsd"); fileSchema.open(QIODevice::ReadOnly); QXmlSchema schema; MessageHandler messageHandler; schema.setMessageHandler(&messageHandler); schema.load(&fileSchema, QUrl::fromLocalFile(fileSchema.fileName())); if (schema.isValid()) { QFile fileXML2(fileName); fileXML2.open(QIODevice::ReadOnly); QXmlSchemaValidator validator(schema); if (!validator.validate(&fileXML2, QUrl::fromLocalFile(fileXML2.fileName()))){ QMessageBox::warning(this, tr("Fichier malformé"), tr("Impossible d'ouvrir le fichier' %1'.\n Le document ne correspond pas au schéma. \n%2") .arg(fileName) .arg(messageHandler.statusMessage())); return; } } ImportExport import=ImportExport(&graphe,xmltree, affichageSVG); if (import.ouvrir(&fileXML, &domDocument)) ui->statusBar->showMessage(tr("Fichier chargé"), 2000); affichageSVG->drawGraph(); ui->afficheGraphe->adjustSize(); //On pense à remettre la liste des sommets pour créer les arcs redessinerComboArc(); }
DialogValidator::DialogValidator(QWidget *parent) : QDialog(parent), ui(new Ui::DialogValidator) { ui->setupUi(this); Qt::WindowFlags flags=Qt::Dialog; flags |=Qt::WindowMinimizeButtonHint; flags |=Qt::WindowMaximizeButtonHint; setWindowFlags(flags); new XmlSyntaxHighlighter(ui->textEditXML->document()); new XmlSyntaxHighlighter(ui->textEditXSD->document()); QFile fileXSD(":/contact.xsd"); fileXSD.open(QFile::ReadOnly); ui->textEditXSD->setText(QString::fromUtf8(fileXSD.readAll())); fileXSD.close(); QFile fileXML(":/valid_contact.xml"); fileXML.open(QFile::ReadOnly); ui->textEditXML->setText(QString::fromUtf8(fileXML.readAll())); fileXML.close(); }
Mesh* Charger_Collada(std::string __nom_du_fichier){ Mesh *objet_charge = NULL; std::cout <<"Chargement de mesh, fichier: "<< __nom_du_fichier << ".xml\n"; // Chargement du fichier avec TinyXML string name=__nom_du_fichier; TiXmlDocument fileXML(name.c_str()); if (!fileXML.LoadFile()){ std::cerr << "Le fichier "<<__nom_du_fichier<<" n'existe pas"<<std::endl; return NULL; } // Elements de TinyXML TiXmlHandle docHandle( &fileXML ); TiXmlElement* elem; TiXmlElement* elem2; TiXmlElement* elem3; // Chargement de la racine TiXmlHandle root=TiXmlHandle(docHandle.FirstChildElement().Element()); // Parcours de <COLLADA> <library_geometries> elem=root.FirstChild("library_geometries").Element(); if (!elem) { std::cerr << "Probleme de lecture"<<std::endl; return NULL; } root=TiXmlHandle(elem); Debug::_trace(7,"<library_geometries>"); // Parcours de <geometry> elem=root.FirstChild("geometry").Element(); if (!elem) { std::cerr << "Probleme de lecture"<<std::endl; return NULL; } Debug::_trace(7,"<geometry>"); root=TiXmlHandle(elem); //std::cout << "Geometry name : " <<elem->Attribute("name")<<" id : "<< elem->Attribute("id")<< std::endl; // Parcours de <mesh> // Un seul mesh sera chargé ! elem2=root.FirstChild("mesh").Element(); if (!elem2) { std::cerr << "Probleme de lecture"<<std::endl; return NULL; } Debug::_trace(7,"<mesh>"); root=TiXmlHandle(elem2); //------------------------------------- // ----- Chargement des vertex //------------------------------------- // <source> <float_array> elem3=root.FirstChild("source").FirstChild("float_array").Element(); Debug::_trace(7,"<source> <float_array>"); // Definition du mesh objet_charge = new Mesh(); objet_charge->_nb_vertex = (atoi(elem3->Attribute("count")) / 3 ); const char *parcour = elem3->GetText(); objet_charge->_tab_vertex = new Vertex[objet_charge->_nb_vertex]; //Chargement des vertex for (int i = 0; i < objet_charge->_nb_vertex; i ++) { //printf("%f \n",atof(parcour)); objet_charge->_tab_vertex[i]._position[0] = atof(parcour); while (*parcour != ' '){ parcour ++; } parcour ++; objet_charge->_tab_vertex[i]._position[1] = atof(parcour); while (*parcour != ' '){ parcour ++; } parcour ++; objet_charge->_tab_vertex[i]._position[2] = atof(parcour); while (*parcour != ' '){ parcour ++; } parcour ++; } Debug::_trace(7,"</float_array> </source> "); // </source> </float_array> //------------------------------------- // ----- Chargement des faces //------------------------------------- // <triangles> <p> elem3=root.FirstChild("triangles").Element(); Debug::_trace(7,"<triangles> "); objet_charge->_nb_triangles = atoi(elem3->Attribute("count")); objet_charge->_tab_triangles = new Triangles[objet_charge->_nb_triangles]; bool normal = false; bool coord = false; bool color = false; int vertex_offset; int coord_offset; int color_offset; int total_offset; // On recupere les infos des offsets root=TiXmlHandle(elem3); // <geometry> elem3=root.FirstChild("input").Element(); if (!elem3) return 0; total_offset = 0; for( ; elem3 ; elem3=elem3->NextSiblingElement("input")){ total_offset++; std::string att = elem3->Attribute("semantic"); if ( att == "VERTEX"){ vertex_offset = atoi(elem3->Attribute("offset")); std::cout<<"Vertex\n"; } att = elem3->Attribute("semantic"); if ( att == "NORMAL"){ normal = true; std::cout<<"Normal\n"; } att = elem3->Attribute("semantic"); if ( att == "TEXCOORD"){ coord = true; coord_offset = atoi(elem3->Attribute("offset")); std::cout<<"Text\n"; } att = elem3->Attribute("semantic"); if ( att == "COLOR"){ color = true; color_offset = atoi(elem3->Attribute("offset")); std::cout<<"Color\n"; } } elem3=root.FirstChild("p").Element(); Debug::_trace(7,"<p> "); parcour = elem3->GetText(); for (int i = 0; i < (objet_charge->_nb_triangles) * total_offset -1 ; i++) { std::cout << "boucle i " << i << std::endl; objet_charge->_tab_triangles[i]._vertexIndices[0] = atoi(&parcour[vertex_offset]); // trouve le prochain chiffre while (*parcour != ' '){ parcour ++; } // ignore la normale if(normal){ parcour ++; while (*parcour != ' '){ parcour ++; } } // textcoord if(coord){ parcour ++; while (*parcour != ' '){ parcour ++; } } parcour ++; objet_charge->_tab_triangles[i]._vertexIndices[1] = atoi(&parcour[vertex_offset]); // trouve le prochain chiffre while (*parcour != ' '){ parcour ++; } // ignore la normale if(normal){ parcour ++; while (*parcour != ' '){ parcour ++; } } // textcoord if(coord){ parcour ++; while (*parcour != ' '){ parcour ++; } } parcour ++; objet_charge->_tab_triangles[i]._vertexIndices[2] = atoi(&parcour[vertex_offset]); // trouve le prochain chiffre while (*parcour != ' '){ parcour ++; } // ignore la normale if(normal){ parcour ++; while (*parcour != ' '){ parcour ++; } } // textcoord if(coord){ parcour ++; while (*parcour != ' '){ parcour ++; } } parcour ++; } Debug::_trace(7,"</triangles> </p> "); // --------- Debug::_trace(7,"</mesh>"); Debug::_trace(7,"</geometry>"); Debug::_trace(7,"</library_geometries> </COLLADA> "); std::cout <<"Loaded: "<< name << ".xml" << std::endl; return objet_charge; }
void Area::saveEdit(int del){ //temporary file for the text edition QFile newph("temp.ph"); newph.open(QIODevice::WriteOnly | QIODevice::Truncate); QTextStream flux(&newph); flux.setCodec("UTF-8"); QString *file = new QString("temp.ph"); QString fileXML("tempXML.xml"); std::string phFile = file->toStdString(); try{ //Save new text into new file if(this->textArea->toPlainText().isEmpty()){ throw textAreaEmpty_exception(); } flux << this->textArea->toPlainText() << endl; newph.close(); if(del == 0){ emit makeTempXML(); } // render graph PHPtr myPHPtr = PHIO::parseFile(phFile); this->myArea->setPHPtr(myPHPtr); myPHPtr->render(); PHScenePtr scene = myPHPtr->getGraphicsScene(); this->myArea->setScene(&*scene); // delete the current sortsTree and groupsTree this->treeArea->sortsTree->clear(); //this->treeArea->groupsTree->clear(); // set the pointer of the treeArea this->treeArea->myPHPtr = myPHPtr; //set the pointer of the treeArea this->treeArea->myArea = this->myArea; // build the tree in the treeArea this->treeArea->build(); this->indicatorEdit->setVisible(false); this->saveTextEdit->setDefault(false); this->textArea->incrementeNberTextChange(); this->typeOfCancel = 0; this->saveTextEdit->setEnabled(false); this->textArea->setNberEdit(0); this->cancelTextEdit->setShortcut(QKeySequence()); this->setOldText(); newph.remove(); this->mainWindow->importXMLMetadata(fileXML); } catch(textAreaEmpty_exception & e){ QMessageBox::critical(this, "Error !", "You cannot update from an empty text area !"); } catch(ph_parse_error & argh){ //Catch a parsing error ! //Put the exception into a QMessageBox critical QString phc = "phc"; QStringList args; args << "-l" << "dump" << "-i" << QString::fromUtf8(phFile.c_str()) << "--no-debug"; QProcess *phcProcess = new QProcess(); phcProcess->start(phc, args); if (!phcProcess->waitForStarted()) throw pint_program_not_found() << file_info("phc"); phcProcess->readChannel(); // read result QByteArray stderr; QByteArray stdout; while (!phcProcess->waitForFinished()) { stderr += phcProcess->readAllStandardError(); stdout += phcProcess->readAllStandardOutput(); } stderr += phcProcess->readAllStandardError(); stdout += phcProcess->readAllStandardOutput(); delete phcProcess; //Use split function to only keep the line number QStringList list = QString(stderr).split('"'); QStringList list2 = list[1].split(":"); QStringList list3 = list2[0].split(" "); //One or more of your expressions are wrong ! newph.remove(); QMessageBox::critical(this, "Syntax error !", "One or more of your expressions are wrong !\nNear "+list3[0]+" "+list3[1]+" of dump"); //return NULL; } catch(sort_not_found& sort){ //Catch a error if the user delete a sort before associated actions ! QMessageBox::critical(this, "Error !", "Delete the associated actions before the process !"); } }