2 // C++ : La clase principale de Hexa
4 #include "HexDocument.hxx"
6 #include "HexEltBase.hxx"
7 #include "HexVertex.hxx"
10 #include "HexHexa.hxx"
12 #include "HexElements.hxx"
13 #include "HexCrossElements.hxx"
15 #include "HexVector.hxx"
16 #include "HexCylinder.hxx"
17 #include "HexPipe.hxx"
18 #include "HexMatrix.hxx"
19 #include "HexCloner.hxx"
20 #include "HexPropagation.hxx"
23 #include "HexXmlWriter.hxx"
24 #include "HexXmlTree.hxx"
25 #include "HexGlobale.hxx"
26 #include "HexGroups.hxx"
30 // ======================================================== Constructeur
31 Document::Document (cpchar filename)
33 glob = Globale::getInstance ();
42 maj_propagation = true;
44 addLaw ("DefaultLaw", 0);
46 for (EnumElt type = EL_NONE ; type < EL_MAXI ; type=(EnumElt) (type+1))
48 doc_first_elt [type] = doc_last_elt [type] = new EltBase ();
49 doc_nbr_elt [type] = 0;
52 // ======================================================== Destructeur
53 Document::~Document ()
55 for (EnumElt type = EL_NONE ; type < EL_MAXI ; type=(EnumElt) (type+1))
57 // printf ("____________________________ Type=%d\n", type);
59 for (EltBase* elt=doc_first_elt [type] ; elt != NULL ; elt=next)
69 // ======================================================== addVector
70 Vector* Document::addVector (double dx, double dy, double dz)
72 Vector* pv = new Vector (this, dx, dy, dz);
73 doc_vector.push_back (pv);
76 // ======================================================== addVectorVertices
77 Vector* Document::addVectorVertices (Vertex* va, Vertex* vb)
79 Vector* pv = addVector (vb->getX () - va->getX (),
80 vb->getY () - va->getY (),
81 vb->getZ () - va->getZ ());
84 // ======================================================== addVertex
85 Vertex* Document::addVertex (double x, double y, double z)
87 Vertex* pv = new Vertex (this, x, y, z);
91 // ======================================================== addEdge
92 Edge* Document::addEdge (Vertex* va, Vertex* vb)
94 if (va==NULL || vb==NULL)
97 Edge* arete = new Edge (va, vb);
101 // ======================================================== addEdge (bis)
102 Edge* Document::addEdge (Vertex* va, Vector* vec)
105 Vertex* vb = addVertex (va->getX () + vec->getDx(),
106 va->getY () + vec->getDy(),
107 va->getZ () + vec->getDz());
109 Edge* arete = addEdge (va, vb);
112 // ======================================================== addQuadVertices
113 Quad* Document::addQuadVertices (Vertex* va, Vertex* vb, Vertex* vc, Vertex* vd)
115 Quad* face = new Quad (va, vb, vc, vd);
119 // ======================================================== addQuad
120 Quad* Document::addQuad (Edge* ea, Edge* eb, Edge* ec, Edge* ed)
122 Quad* face = new Quad (ea, eb, ec, ed);
126 // ======================================================== addHexaVertices
127 Hexa* Document::addHexaVertices (Vertex* va, Vertex* vb, Vertex* vc, Vertex* vd,
128 Vertex* ve, Vertex* vf, Vertex* vg, Vertex* vh)
130 Hexa* pave = new Hexa (va, vb, vc, vd, ve, vf, vg, vh);
134 // ======================================================== addHexa
135 Hexa* Document::addHexa (Quad* qa, Quad* qb, Quad* qc, Quad* qd, Quad* qe,
138 Hexa* pave = new Hexa (qa, qb, qc, qd, qe, qf);
142 // ======================================================== addCylinder
143 Cylinder* Document::addCylinder (Vertex* b, Vector* d, double r, double h)
146 Cylinder* cyl = new Cylinder (b, d, r, h);
147 doc_cylinder.push_back (cyl);
150 // ======================================================== addPipe
151 Pipe* Document::addPipe (Vertex* b, Vector* d, double ri, double re, double h)
154 Pipe* tuyau = new Pipe (b, d, ri, re, h);
155 doc_pipe.push_back (tuyau);
158 // ======================================================== makeCartesian
159 Elements* Document::makeCartesian (Vertex* v, Vector* dir,
160 int px, int py, int pz, int mx, int my, int mz)
162 Vector* v1 = new Vector (this, dir->getDx(), 0, 0);
163 Vector* v2 = new Vector (this, 0, dir->getDy(), 0);
164 Vector* v3 = new Vector (this, 0,0, dir->getDz());
165 Elements* grille = new Elements (this);
166 grille->makeCartesianGrid (v, v1, v2, v3, px, py, pz, mx, my, mz);
169 // ======================================================== makeCartesian
170 Elements* Document::makeCartesian (Vertex* v, Vector* v1, Vector* v2,
171 Vector* v3, int px, int py, int pz, int mx, int my, int mz)
173 Elements* grille = new Elements (this);
174 grille->makeCartesianGrid (v, v1, v2, v3, px, py, pz, mx, my, mz);
177 // ======================================================== makeSpherical
178 Elements* Document::makeSpherical (Vertex* c, Vector* dv, int nb, double k)
180 Elements* grille = new Elements (this);
181 grille->makeSphericalGrid (c, dv, nb, k);
184 // ======================================================== makeCylindrical
185 Elements* Document::makeCylindrical (Vertex* c, Vector* b, Vector* h,
186 double dr, double da, double dl, int nr, int na, int nl, bool fill)
188 Elements* grille = new Elements (this);
189 grille->makeCylindricalGrid (c, b, h, dr, da, dl, nr, na, nl, fill);
192 // ======================================================== findVertex
193 Vertex* Document::findVertex (double vx, double vy, double vz)
195 double xmin = vx - doc_tolerance;
196 double xmax = vx + doc_tolerance;
197 double ymin = vy - doc_tolerance;
198 double ymax = vy + doc_tolerance;
199 double zmin = vz - doc_tolerance;
200 double zmax = vz + doc_tolerance;
202 for (EltBase* elt = doc_first_elt[EL_VERTEX]->next (); elt!=NULL;
207 Vertex* node = static_cast <Vertex*> (elt);
208 if (node->isin (xmin, xmax, ymin, ymax, zmin, zmax))
214 // ======================================================== findEdge
215 Edge* Document::findEdge (Vertex* v1, Vertex* v2)
217 for (EltBase* elt = doc_first_elt[EL_EDGE]->next (); elt!=NULL;
220 Edge* candidat = static_cast <Edge*> (elt);
221 if (candidat->definedBy (v1, v2))
226 // ======================================================== findQuad
227 Quad* Document::findQuad (Vertex* v1, Vertex* v2)
229 for (EltBase* elt = doc_first_elt[EL_QUAD]->next (); elt!=NULL;
232 Quad* candidat = static_cast <Quad*> (elt);
233 if (candidat->definedBy (v1, v2))
238 // ======================================================== findHexa
239 Hexa* Document::findHexa (Vertex* v1, Vertex* v2)
241 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
244 Hexa* candidat = static_cast <Hexa*> (elt);
245 if (candidat->definedBy (v1, v2))
250 // ======================================================== makeCylinder
251 int index_tv (Vertex* table[], Vertex* elt)
253 for (int nro=0; nro<QUAD4; nro++)
254 if (elt == table[nro])
259 // ======================================================== mergeQuads
260 int Document::mergeQuads (Quad* par, Quad* old, Vertex* v1, Vertex* v2,
261 Vertex* v3, Vertex* v4)
265 if ( par==NULL || par->isDeleted() || old==NULL || old->isDeleted()
266 || v1 ==NULL || v1 ->isDeleted() || v2 ==NULL || v2 ->isDeleted()
267 || v3 ==NULL || v3 ->isDeleted() || v4 ==NULL || v4 ->isDeleted())
270 for (int nro=0 ; nro<QUAD4 ; nro++)
271 if (old->indexVertex (par->getVertex(nro))!= NOTHING)
276 printf (" ----------------- mergeQuads : \n");
285 Vertex *tv1 [QUAD4], *tv2 [QUAD4];
286 Edge *te1 [QUAD4], *te2 [QUAD4];
288 int ier1 = par->ordoVertex (v1, v3, tv1);
289 int ier2 = old->ordoVertex (v2, v4, tv2);
290 if (ier1 != HOK) return ier1;
291 else if (ier2 != HOK) return ier2;
293 for (int nro=0 ; nro<QUAD4 ; nro++)
295 te1 [nro] = par->getEdge(nro);
296 Vertex* va1 = te1[nro]->getVertex(V_AMONT);
297 Vertex* vb1 = te1[nro]->getVertex(V_AVAL);
298 int na = index_tv (tv1, va1);
299 int nb = index_tv (tv1, vb1);
300 if (na==NOTHING || nb==NOTHING)
303 te2 [nro] = old->findEdge (tv2[na], tv2[nb]);
310 printf (" ----------------- Correspondances mergeQuads : \n");
311 for (int nro=0 ; nro<QUAD4 ; nro++)
313 printf (" %d : ", nro);
314 tv2 [nro]->printName(" -> ");
315 tv1 [nro]->printName("\n");
317 for (int nro=0 ; nro<QUAD4 ; nro++)
319 printf (" %d : ", nro);
320 te2 [nro]->printName(" (");
321 te2 [nro]->getVertex(0)->printName(", ");
322 te2 [nro]->getVertex(1)->printName(") -> ");
323 te1 [nro]->printName(" (");
324 te1 [nro]->getVertex(0)->printName(", ");
325 te1 [nro]->getVertex(1)->printName(")\n");
329 replaceQuad (old, par);
330 for (int nro=0 ; nro<QUAD4 ; nro++)
331 replaceEdge (te2[nro], te1[nro]);
332 for (int nro=0 ; nro<QUAD4 ; nro++)
333 replaceVertex (tv2[nro], tv1[nro]);
335 maj_connection = false;
336 purge_elements = false;
339 // ======================================================== mergeEdges
340 int Document::mergeEdges (Edge* e1, Edge* e2, Vertex* v1, Vertex* v2)
342 if (e1==NULL || e1->isDeleted() || e2==NULL || e2->isDeleted())
345 for (int nro=0 ; nro<V_TWO ; nro++)
346 if (e1->index (e2->getVertex(nro))!= NOTHING)
349 Vertex *tv1 [V_TWO], *tv2 [V_TWO];
351 int ier1 = e1->anaMerge (v1, tv1);
352 int ier2 = e2->anaMerge (v2, tv2);
354 if (ier1 != HOK) return ier1;
355 else if (ier2 != HOK) return ier2;
357 replaceEdge (e2, e1);
358 for (int nro=0 ; nro<V_TWO ; nro++)
359 replaceVertex (tv2[nro], tv1[nro]);
361 maj_connection = false;
364 // ======================================================== mergeVertices
365 int Document::mergeVertices (Vertex* v1, Vertex* v2)
367 if (v1==v2 || v1==NULL || v1->isDeleted()
368 || v2==NULL || v2->isDeleted())
371 replaceVertex (v2, v1);
373 maj_connection = false;
376 // ======================================================== replaceVertex
377 void Document::replaceVertex (Vertex* old, Vertex* par)
382 for (int type=EL_EDGE ; type <= EL_HEXA ; type++)
384 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
387 elt->replaceVertex (old, par);
391 // ======================================================== replaceEdge
392 void Document::replaceEdge (Edge* old, Edge* par)
397 for (int type=EL_QUAD ; type <= EL_HEXA ; type++)
399 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
402 elt->replaceEdge (old, par);
406 // ======================================================== replaceQuad
407 void Document::replaceQuad (Quad* old, Quad* par)
412 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
416 Hexa* cell = static_cast <Hexa*> (elt);
417 cell->replaceQuad (old, par);
421 // ======================================================== prismQuad
422 Elements* Document::prismQuad (Quad* start, Vector* dir, int nb)
425 tstart.push_back (start);
428 Elements* prisme = prismQuads (tstart, dir, nb);
431 // ======================================================== prismQuads
432 Elements* Document::prismQuads (Quads& tstart, Vector* dir, int nb)
434 if (nb<=0) return NULL;
436 Elements* prisme = new Elements (this);
437 prisme->prismQuads (tstart, dir, nb);
440 // ======================================================== joinQuads
441 Elements* Document::joinQuads (Quads& start, Quad* dest, Vertex* v1,
442 Vertex* v2, Vertex* v3, Vertex* v4, int nb)
444 if (nb<=0) return NULL;
447 Elements* joint = new Elements (this);
448 joint->joinQuads (start, nb, v1, v2, v3, v4, dest);
451 // ======================================================== joinQuad
452 Elements* Document::joinQuad (Quad* start, Quad* dest, Vertex* v1,
453 Vertex* v2, Vertex* v3, Vertex* v4, int nb)
456 tstart.push_back (start);
458 Elements* joint = joinQuads (tstart, dest, v1, v2, v3, v4, nb);
461 // ========================================================== getHexa
462 Hexa* Document::getHexa (int nro)
464 return static_cast <Hexa*> (getElement (EL_HEXA, nro));
466 // ========================================================== getQuad
467 Quad* Document::getQuad (int nro)
469 return static_cast <Quad*> (getElement (EL_QUAD, nro));
471 // ========================================================== getEdge
472 Edge* Document::getEdge (int nro)
474 return static_cast <Edge*> (getElement (EL_EDGE, nro));
476 // ========================================================== getVertex
477 Vertex* Document::getVertex (int nro)
479 return static_cast <Vertex*> (getElement (EL_VERTEX, nro));
481 // ========================================================== countElement
482 int Document::countElement (EnumElt type)
485 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
492 // ========================================================== getElement
493 EltBase* Document::getElement (EnumElt type, int nro)
496 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
508 // ========================================================= addLaw
509 Law* Document::addLaw (const char* name, int nbnodes)
511 Law* loi = new Law (name, nbnodes);
512 doc_laws.push_back (loi);
516 // ========================================================= GetLaw
517 Law* Document::getLaw (int nro)
519 if (nro <0 || nro>= nbr_laws)
522 return doc_laws [nro];
524 // ========================================================= FindLaw
525 Law* Document::findLaw (const char* name)
527 std::string nom = name;
528 for (int nro=0 ; nro<nbr_laws; nro++)
529 if (doc_laws [nro]->getName() == nom)
530 return doc_laws [nro];
534 // ========================================================= removeLaw
535 int Document::removeLaw (Law* loi)
537 for (int nro=1 ; nro<nbr_laws; nro++)
538 if (doc_laws [nro] == loi)
540 delete doc_laws [nro];
541 doc_laws.erase (doc_laws.begin()+nro);
542 nbr_laws= doc_laws.size();
548 // ========================================================= majPropagation
549 void Document::majPropagation ()
555 for (int nro=0 ; nro<nbr_propagations ; nro++)
557 delete doc_propagation [nro];
560 doc_propagation.clear ();
561 nbr_propagations = 0;
562 maj_propagation = false;
564 for (EltBase* elt = doc_first_elt[EL_EDGE]->next (); elt!=NULL;
567 Edge* arete = static_cast <Edge*> (elt);
569 arete->setPropag (NOTHING, true);
572 // markAll (NO_COUNTED, EL_EDGE);
574 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
577 Hexa* cell = static_cast <Hexa*> (elt);
578 if (cell!=NULL && cell->isHere())
580 for (int ne=0 ; ne<HE_MAXI ; ne++)
582 Edge* arete = cell->getEdge(ne);
583 if (arete->getPropag()<0)
585 Propagation* prop = new Propagation ();
586 doc_propagation.push_back (prop);
587 arete->propager (prop, nbr_propagations);
595 // ======================================================== countPropagation
596 int Document::countPropagation ()
601 return nbr_propagations;
603 // ======================================================== getPropagation
604 Propagation* Document::getPropagation (int nro)
609 if (nro < 0 || nro >= nbr_propagations)
612 return doc_propagation [nro];
614 // ======================================================== findPropagation
615 Propagation* Document::findPropagation (Edge* arete)
623 return getPropagation (arete->getPropag ());
625 // ======================================================== disconnectQuad
626 Elements* Document::disconnectQuad (Hexa* cell, Quad* element)
628 if (cell==NULL || element==NULL)
632 Elements* crees = cell->disconnectQuad (element);
639 // ======================================================== disconnectEdge
640 Elements* Document::disconnectEdge (Hexa* cell, Edge* element)
642 if (cell==NULL || element==NULL)
646 Elements* crees = cell->disconnectEdge (element);
652 // ======================================================== disconnectVertex
653 Elements* Document::disconnectVertex (Hexa* cell, Vertex* element)
655 if (cell==NULL || element==NULL)
659 Elements* crees = cell->disconnectVertex (element);
665 // ======================================================== cut
666 Elements* Document::cut (Edge* edge, int nbcuts)
668 Elements* t_hexas = new Elements (this);
670 if (edge==NULL || nbcuts<=0)
673 Propagation* prop = findPropagation (edge);
674 const Edges& t_edges = prop->getEdges ();
676 t_hexas->cutHexas (t_edges, nbcuts);
681 // ======================================================== addGroup
682 Group* Document::addGroup (cpchar name, EnumGroup kind)
684 Group* grp = new Group (name, kind);
685 doc_group.push_back (grp);
688 // ======================================================== findGroup
689 Group* Document::findGroup (cpchar name)
691 int nbre = doc_group.size();
693 for (int ng=0 ; ng<nbre ; ng++)
694 if (Cestegal (doc_group [ng]->getName(), name))
695 return doc_group [ng];
699 // ======================================================== removeGroup
700 int Document::removeGroup (Group* grp)
702 int nbre = doc_group.size();
703 for (int ng=0 ; ng<nbre ; ng++)
705 if (grp == doc_group [ng])
707 doc_group.erase (doc_group.begin() + ng);
712 // Pas trouve dans la liste. On detruit quand meme
715 }// ======================================================== makeCylinder
716 Elements* Document::makeCylinder (Cylinder* cyl, Vector* base, int nr, int na,
719 Elements* grille = new Elements (this);
720 grille->makeCylinder (cyl, base, nr, na, nr);
723 // ======================================================== makeCylinders
724 CrossElements* Document::makeCylinders (Cylinder* cyl1, Cylinder* cyl2)
726 CrossElements* grille = new CrossElements (this);
727 grille->crossCylinders (cyl1, cyl2, true);
731 // ======================================================== makePipe
732 Elements* Document::makePipe (Pipe* pipe, Vector* bx, int nr, int na, int nl)
734 Elements* grille = new Elements (this);
735 grille->makePipe (pipe, bx, nr, na, nr);
738 // ======================================================== makePipes
739 CrossElements* Document::makePipes (Pipe* pipe1, Pipe* pipe2)
741 CrossElements* grille = new CrossElements (this);
742 grille->crossCylinders (pipe1, pipe2, false);