1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| #include "AReVi/arSystem.h"
using namespace AReVi;
#include "AReVi/Contrib/xmlParser.h"
struct point
{int x;
int y;int z;};
ArRef<Scheduler>
simulationInit(void)
{
///POUR ECRIRE
//cerr << "Crée un nouveau document" << endl;
ArRef<XmlFlowOut> flow=new_XmlFlowOut("nouveau.xml");//crée nouveau ou supprime l'existant
ArRef<XmlNode> root1=flow->getRoot();
//cerr << "Creé noeud Configuration" << endl;
ArRef<XmlNode> node=root1->addChild("Parking");
ArRef<XmlNode> Attribute=node->addChild("Attribute");
Attribute->setPropertyString("name","typeVehicule");
Attribute->setPropertyString("value","Rafale");
for(int i=0;i<5;i++)//5=nombre places
{
ArRef<XmlNode> Relation=node->addChild("Relation");
Relation->setPropertyString("name","place");
Relation->setPropertyString("value","Place1");//nom de la place
}
point _vectPlacesParkAv[5];
_vectPlacesParkAv[0].x=1;
_vectPlacesParkAv[0].y=10;
_vectPlacesParkAv[1].x=15;
_vectPlacesParkAv[1].y=1;
_vectPlacesParkAv[2].x=17;
_vectPlacesParkAv[2].y=15;
_vectPlacesParkAv[3].x=19;
_vectPlacesParkAv[3].y=16;
_vectPlacesParkAv[4].x=1;
_vectPlacesParkAv[4].y=18;
for (int i=0; i<5;i++)
{
ArRef<XmlNode> Entity=node->addChild("Entity");
Entity->setPropertyString("class","yuyu");
Entity->setPropertyString("name","yaya");//nom place
ArRef<XmlNode> Location=Entity->addChild("Location");
Location->setPropertyInteger("x",_vectPlacesParkAv[i].x);
Location->setPropertyInteger("y",_vectPlacesParkAv[i].y);
Location->setPropertyInteger("z",_vectPlacesParkAv[i].z);
ArRef<XmlNode> Orientation=Entity->addChild("Orientation");
Orientation->setPropertyInteger("roll",0);
Orientation->setPropertyInteger("pitch",0);
Orientation->setPropertyInteger("yaw",3);//mettre yaw!
}
//Ne as oublier (pour jetter dans le flux)!!!!!!!
flow->addXmlNode(node,0,"");
/POUR LIRE
string _nom="nom";int _x,_y,_yaw;
//creer un parseur et un noeud
ArRef<XmlParser> parser=new_XmlParser();
ArRef<XmlNode> root;
//charge le fichier XML et fixe le parseur au début
if (!parser->parseFile("nouveau.xml",true))
{
cerr << "erreur en chargeant .xml" << endl;
return Scheduler::nullRef();
}
//place le noeud a la premiere balise
root=parser->getRoot();
for (int i=1; i<=5;i++)//!!attention
{
ArRef<XmlNode> EntityPlace=root->getChild("Entity",i);
ArRef<XmlNode> locationPlace=EntityPlace->getChild("Location",1);
ArRef<XmlNode> orientationPlace=EntityPlace->getChild("Orientation",1);
EntityPlace->getPropertyString("name",_nom);
locationPlace->getPropertyInteger("x",_x);
locationPlace->getPropertyInteger("y",_y);
orientationPlace->getPropertyInteger("yaw",_yaw);
cout<<"nom "<<_nom<<" x "<<_x<<" y "<<_y<<" yaw "<<_yaw<<endl;
}
return(Scheduler::nullRef());
}
int
main(int argc,
char ** argv)
{
ArSystem arevi(argc,argv,false);
ArSystem::loadPlugin("XmlParser");
ArSystem::simulationLoop(&simulationInit);
return(0);
} |
Partager