2 // C++ : La clase principale de Hexa
4 // Copyright (C) 2009-2012 CEA/DEN, EDF R&D
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/
21 // or email : webmaster.salome@opencascade.com
23 #include "HexDocument.hxx"
25 #include "HexEltBase.hxx"
26 #include "HexVertex.hxx"
27 #include "HexEdge.hxx"
28 #include "HexQuad.hxx"
29 #include "HexHexa.hxx"
31 #include "HexElements.hxx"
32 #include "HexCrossElements.hxx"
33 #include "HexBiCylinder.hxx"
35 #include "HexVector.hxx"
36 #include "HexCylinder.hxx"
37 #include "HexPipe.hxx"
38 #include "HexMatrix.hxx"
39 #include "HexCloner.hxx"
40 #include "HexPropagation.hxx"
43 #include "HexXmlWriter.hxx"
44 #include "HexXmlTree.hxx"
45 #include "HexGlobale.hxx"
46 #include "HexGroup.hxx"
48 #include "HexNewShape.hxx"
52 int Document::doc_number = 0;
54 // ======================================================== Constructeur
55 Document::Document (cpchar name, Hex* dad)
59 glob = Globale::getInstance ();
69 maj_propagation = true;
72 nbr_used_hexas = nbr_used_quads = nbr_used_edges = nbr_used_vertex = 0;
74 for (EnumElt type = EL_NONE ; type < EL_MAXI ; type=(EnumElt) (type+1))
76 doc_first_elt [type] = doc_last_elt [type] = new EltBase ();
77 doc_nbr_elt [type] = 0;
81 strcpy (doc_ident, "doc");
83 sprintf (doc_ident, "doc%02d", doc_number);
87 defaultLaw = addLaw ("DefaultLaw", 0);
92 // ======================================================== Destructeur
93 Document::~Document ()
97 for (EnumElt type = EL_NONE ; type < EL_MAXI ; type=(EnumElt) (type+1))
99 // printf ("____________________________ Type=%d\n", type);
100 EltBase* next = NULL;
101 for (EltBase* elt=doc_first_elt [type] ; elt != NULL ; elt=next)
108 // ======================================================== addVector
109 Vector* Document::addVector (double dx, double dy, double dz)
111 DumpStart ("addVector", dx << dy << dz);
112 Vector* pv = new Vector (this, dx, dy, dz);
113 doc_vector.push_back (pv);
118 // ======================================================== addVectorVertices
119 Vector* Document::addVectorVertices (Vertex* va, Vertex* vb)
121 DumpStart ("addVectorVertices", va << vb);
123 Vector* pv = addVector (vb->getX () - va->getX (),
124 vb->getY () - va->getY (),
125 vb->getZ () - va->getZ ());
130 // ======================================================== addVertex
131 Vertex* Document::addVertex (double x, double y, double z)
133 DumpStart ("addVertex", x << y << z);
135 Vertex* pv = new Vertex (this, x, y, z);
139 // ======================================================== addEdge
140 Edge* Document::addEdge (Vertex* va, Vertex* vb)
142 DumpStart ("addEdge", va << vb );
144 if (va==NULL || vb==NULL)
147 Edge* arete = new Edge (va, vb);
151 // ======================================================== addEdgeVector
152 Edge* Document::addEdgeVector (Vertex* va, Vector* vec)
154 DumpStart ("addEdgeVector", va << vec );
156 Vertex* vb = addVertex (va->getX () + vec->getDx(),
157 va->getY () + vec->getDy(),
158 va->getZ () + vec->getDz());
160 Edge* arete = addEdge (va, vb);
164 // ======================================================== addQuadVertices
165 Quad* Document::addQuadVertices (Vertex* va, Vertex* vb, Vertex* vc, Vertex* vd)
167 DumpStart ("addQuadVertices", va << vb << vc << vd );
169 Quad* face = new Quad (va, vb, vc, vd);
173 // ======================================================== addQuad
174 Quad* Document::addQuad (Edge* ea, Edge* eb, Edge* ec, Edge* ed)
176 DumpStart ("addQuad", ea << eb << ec << ed );
178 Quad* face = new Quad (ea, eb, ec, ed);
182 // ======================================================== addHexaVertices
183 Hexa* Document::addHexaVertices (Vertex* va, Vertex* vb, Vertex* vc, Vertex* vd,
184 Vertex* ve, Vertex* vf, Vertex* vg, Vertex* vh)
186 DumpStart ("addHexaVertices", va << vb << vc << vd << ve << vf << vg << vh);
188 Hexa* pave = new Hexa (va, vb, vc, vd, ve, vf, vg, vh);
192 // ======================================================== addHexa
193 Hexa* Document::addHexa (Quad* qa, Quad* qb, Quad* qc, Quad* qd, Quad* qe,
196 DumpStart ("addHexa", qa << qb << qc << qd << qe << qf );
198 Hexa* pave = new Hexa (qa, qb, qc, qd, qe, qf);
202 // ======================================================== addCylinder
203 Cylinder* Document::addCylinder (Vertex* b, Vector* d, double r, double h)
205 DumpStart ("addCylinder", b << d << r << h);
207 Cylinder* cyl = new Cylinder (b, d, r, h);
208 doc_cylinder.push_back (cyl);
213 // ======================================================== addPipe
214 Pipe* Document::addPipe (Vertex* b, Vector* d, double ri, double re, double h)
216 DumpStart ("addPipe", b << d << ri << re << h);
218 Pipe* tuyau = new Pipe (b, d, ri, re, h);
219 doc_pipe.push_back (tuyau);
224 // ======================================================== makeCartesian
225 Elements* Document::makeCartesian (Vertex* v, Vector* dir,
226 int px, int py, int pz, int mx, int my, int mz)
228 DumpStart ("makeCartesianDiag", v << dir << px << py << pz << mx << my << mz);
230 Vector* v1 = new Vector (this, dir->getDx(), 0, 0);
231 Vector* v2 = new Vector (this, 0, dir->getDy(), 0);
232 Vector* v3 = new Vector (this, 0,0, dir->getDz());
233 Elements* grille = new Elements (this);
234 grille->makeCartesianGrid (v, v1, v2, v3, px, py, pz, mx, my, mz);
239 // ======================================================== makeCartesian
240 Elements* Document::makeCartesian (Vertex* v, Vector* v1, Vector* v2,
241 Vector* v3, int px, int py, int pz)
243 DumpStart ("makeCartesian", v << v1 << v2 << v3 << px << py << pz);
245 Elements* grille = new Elements (this);
246 grille->makeCartesianGrid (v, v1, v2, v3, px, py, pz);
251 // ======================================================== makeCartesian1
252 Elements* Document::makeCartesian1 (Vertex* v, Vector* v1, Vector* v2,
253 Vector* v3, int px, int py, int pz, int mx, int my, int mz)
255 DumpStart ("makeCartesian1", v << v1 << v2 << v3 << px << py << pz
258 Elements* grille = new Elements (this);
259 grille->makeCartesianGrid (v, v1, v2, v3, px, py, pz, mx, my, mz);
264 // ======================================================== makeSpherical
265 Elements* Document::makeSpherical (Vertex* c, double rayon, int nb, double k)
267 DumpStart ("makeSpherical", c << rayon << nb << k );
269 Elements* grille = new Elements (this);
270 grille->makeSphericalGrid (c, rayon, nb, k);
275 // ======================================================== makeCylindrical
276 Elements* Document::makeCylindrical (Vertex* c, Vector* b, Vector* h,
277 double dr, double da, double dl, int nr, int na, int nl, bool fill)
279 DumpStart ("makeCylindrical", c << b << h << dr << da << dl << nr << na
282 Elements* grille = new Elements (this);
283 grille->makeCylindricalGrid (c, b, h, dr, da, dl, nr, na, nl, fill);
288 // ======================================================== makeSphere
289 Elements* Document::makeSphere (Vertex* center, Vector* vx, Vector* vz,
290 double radius, double radhole, Vertex* plorig,
291 int nrad, int nang, int nhaut)
293 DumpStart ("makeSphere", center << vx << vz << radius << radhole << plorig
294 << nrad << nang << nhaut);
296 Elements* grille = new Elements (this);
297 double radint = (radhole + radius)*DEMI;
298 grille->makeRind (GR_HEMISPHERIC, center, vx, vz, radius, radint, radhole,
299 plorig, 360.0, nrad, nang, nhaut);
304 // ======================================================== makePartSphere
305 Elements* Document::makePartSphere (Vertex* center, Vector* vx, Vector* vz,
306 double radius, double radhole,
307 Vertex* plorig, double angle,
308 int nrad, int nang, int nhaut)
310 DumpStart ("makePartSphere", center << vx << vz
313 << nrad << nang << nhaut);
315 Elements* grille = new Elements (this);
316 double radint = (radhole + radius)*DEMI;
317 grille->makeRind (GR_PART_SPHERIC, center, vx, vz, radius, radint, radhole,
318 plorig, angle, nrad, nang, nhaut);
323 // ======================================================== makeRind
324 Elements* Document::makeRind (Vertex* center, Vector* vx, Vector* vz,
325 double radext, double radint, double radhole,
326 Vertex* plorig, int nrad, int nang, int nhaut)
328 DumpStart ("makeRind", center << vx << vz
329 << radext << radint << radhole
330 << plorig << nrad << nang << nhaut);
332 Elements* grille = new Elements (this);
333 grille->makeRind (GR_RIND, center, vx, vz, radext, radint, radhole,
334 plorig, 360.0, nrad, nang, nhaut);
339 // ======================================================== makePartRind
340 Elements* Document::makePartRind (Vertex* center, Vector* vx, Vector* vz,
341 double radext, double radint, double radhole,
342 Vertex* plorig, double angle,
343 int nrad, int nang, int nhaut)
345 DumpStart ("makePartRind", center << vx << vz
346 << radext << radint << radhole
347 << plorig << angle << nrad << nang << nhaut);
349 Elements* grille = new Elements (this);
350 grille->makeRind (GR_PART_RIND, center, vx, vz, radext, radint, radhole,
351 plorig, angle, nrad, nang, nhaut);
356 // ======================================================== findVertex
357 Vertex* Document::findVertex (double vx, double vy, double vz)
359 double xmin = vx - doc_tolerance;
360 double xmax = vx + doc_tolerance;
361 double ymin = vy - doc_tolerance;
362 double ymax = vy + doc_tolerance;
363 double zmin = vz - doc_tolerance;
364 double zmax = vz + doc_tolerance;
366 for (EltBase* elt = doc_first_elt[EL_VERTEX]->next (); elt!=NULL;
371 Vertex* node = static_cast <Vertex*> (elt);
372 if (node->isin (xmin, xmax, ymin, ymax, zmin, zmax))
378 // ======================================================== findEdge
379 Edge* Document::findEdge (Vertex* v1, Vertex* v2)
381 for (EltBase* elt = doc_first_elt[EL_EDGE]->next (); elt!=NULL;
384 Edge* candidat = static_cast <Edge*> (elt);
385 if (candidat->definedBy (v1, v2))
390 // ======================================================== findQuad
391 Quad* Document::findQuad (Vertex* v1, Vertex* v2)
393 for (EltBase* elt = doc_first_elt[EL_QUAD]->next (); elt!=NULL;
396 Quad* candidat = static_cast <Quad*> (elt);
397 if (candidat->definedBy (v1, v2))
402 // ======================================================== findHexa
403 Hexa* Document::findHexa (Vertex* v1, Vertex* v2)
405 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
408 Hexa* candidat = static_cast <Hexa*> (elt);
409 if (candidat->definedBy (v1, v2))
414 // ======================================================== findElement
415 EltBase* Document::findElement (EnumElt type, int ident)
417 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
420 if (elt->isHere() && elt->getId()==ident)
425 // ======================================================== findVertex
426 Vertex* Document::findVertex (int ident)
428 Vertex* node = static_cast <Vertex*> (findElement (EL_VERTEX, ident));
432 // ======================================================== index_tv
433 int index_tv (Vertex* table[], Vertex* elt)
435 for (int nro=0; nro<QUAD4; nro++)
436 if (elt == table[nro])
441 // ======================================================== mergeQuads
442 int Document::mergeQuads (Quad* dest, Quad* orig, Vertex* v1, Vertex* v2,
443 Vertex* v3, Vertex* v4)
445 DumpStart ("mergeQuads", dest << orig << v1 << v2 << v3 << v4);
451 printf (" *** Quads identiques dans mergeQuads\n");
455 else if (dest==NULL || dest->isDeleted())
457 printf (" *** Quad nro 1 incorrect dans mergeQuads \n");
461 else if (orig==NULL || orig->isDeleted() )
463 printf (" *** Quad nro 2 incorrect dans mergeQuads \n");
469 for (int nro=0 ; nro<QUAD4 ; nro++)
471 int norig = orig->indexVertex (dest->getVertex(nro));
472 if (norig != NOTHING)
474 Vertex* uv = dest->getVertex(nro);
479 printf (" +++ Sommets communs dans mergeQuads");
480 printf (" (%s,", dest->getName (nom));
481 printf (" %s)\n", orig->getName (nom));
483 printf (" +++ quad1[%d] = quad2[%d] = %s\n", nro, norig,
490 printf (" +++ Les vertex passes en arguments sont ignores\n");
491 int ier = closeQuads (dest, orig);
495 else if (nbcomm != 0)
497 printf (" *** _____________________ mergeQuads refuse: \n");
498 printf (" il y a %d sommet(s) sont commun(s)\n", nbcomm);
503 if ( v1 ==NULL || v1 ->isDeleted() || v2 ==NULL || v2 ->isDeleted()
504 || v3 ==NULL || v3 ->isDeleted() || v4 ==NULL || v4 ->isDeleted())
506 printf (" *** _____________________ mergeQuads refuse: \n");
507 printf (" un sommet est incorrect\n");
515 printf (" ----------------- mergeQuads : \n");
524 Vertex *tv1 [QUAD4], *tv2 [QUAD4];
525 Edge *te1 [QUAD4], *te2 [QUAD4];
527 int ier1 = dest->ordoVertex (v1, v3, tv1);
528 int ier2 = orig->ordoVertex (v2, v4, tv2);
534 else if (ier2 != HOK)
540 for (int nro=0 ; nro<QUAD4 ; nro++)
542 te1 [nro] = dest->getEdge(nro);
543 Vertex* va1 = te1[nro]->getVertex(V_AMONT);
544 Vertex* vb1 = te1[nro]->getVertex(V_AVAL);
545 int na = index_tv (tv1, va1);
546 int nb = index_tv (tv1, vb1);
547 if (na==NOTHING || nb==NOTHING)
553 te2 [nro] = orig->findEdge (tv2[na], tv2[nb]);
563 printf (" ----------------- Correspondances mergeQuads : \n");
564 for (int nro=0 ; nro<QUAD4 ; nro++)
566 printf (" %d : ", nro);
567 tv2 [nro]->printName(" -> ");
568 tv1 [nro]->printName("\n");
570 for (int nro=0 ; nro<QUAD4 ; nro++)
572 printf (" %d : ", nro);
573 te2 [nro]->printName(" (");
574 te2 [nro]->getVertex(0)->printName(", ");
575 te2 [nro]->getVertex(1)->printName(") -> ");
576 te1 [nro]->printName(" (");
577 te1 [nro]->getVertex(0)->printName(", ");
578 te1 [nro]->getVertex(1)->printName(")\n");
582 replaceQuad (orig, dest);
583 for (int nro=0 ; nro<QUAD4 ; nro++)
584 replaceEdge (te2[nro], te1[nro]);
585 for (int nro=0 ; nro<QUAD4 ; nro++)
586 replaceVertex (tv2[nro], tv1[nro]);
588 maj_connection = false;
589 purge_elements = false;
594 // ======================================================== closeQuads
595 int Document::closeQuads (Quad* dest, Quad* orig)
597 DumpStart ("closeQuads", dest << orig);
604 printf (" *** Quads identiques dans closeQuads : %s\n",
609 else if (dest==NULL || dest->isDeleted())
611 printf (" *** Quad nro 1 incorrect dans closeQuads \n");
615 else if (orig==NULL || orig->isDeleted() )
617 printf (" *** Quad nro 2 incorrect dans closeQuads \n");
623 for (int nro=0 ; nro<QUAD4 ; nro++)
625 int norig = orig->indexEdge (dest->getEdge(nro));
626 if (norig != NOTHING)
630 printf (" *** Plus d'une arete commune dans closeQuads");
631 printf (" (%s,", dest->getName (nom));
632 printf (" %s)\n", orig->getName (nom));
636 edc = dest->getEdge (nro);
637 printf (" +++ quad1[%d] = quad2[%d] = %s\n", nro, norig,
642 Vertex* va = edc->getVertex (V_AMONT);
643 Vertex* vb = edc->getVertex (V_AVAL);
644 Vertex *tv1 [QUAD4], *tv2 [QUAD4];
645 Edge *te1 [QUAD4], *te2 [QUAD4];
647 int ier1 = dest->ordoVertex (va, vb, tv1);
648 int ier2 = orig->ordoVertex (va, vb, tv2);
655 else if (ier2 != HOK)
661 for (int nro=0 ; nro<QUAD4 ; nro++)
663 te1 [nro] = dest->getEdge(nro);
664 Vertex* va1 = te1[nro]->getVertex(V_AMONT);
665 Vertex* vb1 = te1[nro]->getVertex(V_AVAL);
666 int na = index_tv (tv1, va1);
667 int nb = index_tv (tv1, vb1);
668 if (na==NOTHING || nb==NOTHING)
674 te2 [nro] = orig->findEdge (tv2[na], tv2[nb]);
684 printf (" ----------------- Correspondances mergeQuads : \n");
685 for (int nro=0 ; nro<QUAD4 ; nro++)
687 printf (" %d : ", nro);
688 tv2 [nro]->printName(" -> ");
689 tv1 [nro]->printName("\n");
691 for (int nro=0 ; nro<QUAD4 ; nro++)
693 printf (" %d : ", nro);
694 te2 [nro]->printName(" (");
695 te2 [nro]->getVertex(0)->printName(", ");
696 te2 [nro]->getVertex(1)->printName(") -> ");
697 te1 [nro]->printName(" (");
698 te1 [nro]->getVertex(0)->printName(", ");
699 te1 [nro]->getVertex(1)->printName(")\n");
703 replaceQuad (orig, dest);
704 for (int nro=0 ; nro<QUAD4 ; nro++)
705 replaceEdge (te2[nro], te1[nro]);
706 for (int nro=0 ; nro<QUAD4 ; nro++)
707 replaceVertex (tv2[nro], tv1[nro]);
709 maj_connection = false;
710 purge_elements = false;
715 // ======================================================== mergeEdges
716 int Document::mergeEdges (Edge* e1, Edge* e2, Vertex* v1, Vertex* v2)
718 DumpStart ("mergeEdges", e1 << e2 << v1 << v2);
720 if (e1==NULL || e1->isDeleted() || e2==NULL || e2->isDeleted())
726 for (int nro=0 ; nro<V_TWO ; nro++)
727 if (e1->index (e2->getVertex(nro))!= NOTHING)
733 Vertex *tv1 [V_TWO], *tv2 [V_TWO];
735 int ier1 = e1->anaMerge (v1, tv1);
736 int ier2 = e2->anaMerge (v2, tv2);
743 else if (ier2 != HOK)
749 replaceEdge (e2, e1);
750 for (int nro=0 ; nro<V_TWO ; nro++)
751 replaceVertex (tv2[nro], tv1[nro]);
753 maj_connection = false;
757 // ======================================================== mergeVertices
758 int Document::mergeVertices (Vertex* v1, Vertex* v2)
760 DumpStart ("mergeVertices", v1 << v2);
762 if (v1==v2 || v1==NULL || v1->isDeleted()
763 || v2==NULL || v2->isDeleted())
769 replaceVertex (v2, v1);
771 maj_connection = false;
775 // ======================================================== replaceVertex
776 void Document::replaceVertex (Vertex* old, Vertex* par)
778 DumpStart ("replaceVertex", old << par);
779 if (BadElement(old) || BadElement(par) || old==par)
785 // par->replaceAssociation (old); TODO
787 for (int type=EL_EDGE ; type <= EL_HEXA ; type++)
789 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
792 elt->replaceVertex (old, par);
797 // ======================================================== replaceEdge
798 void Document::replaceEdge (Edge* old, Edge* par)
800 DumpStart ("replaceEdge", old << par);
801 if (BadElement(old) || BadElement(par) || old==par)
807 // par->replaceAssociation (old); TODO
809 for (int type=EL_QUAD ; type <= EL_HEXA ; type++)
811 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
814 elt->replaceEdge (old, par);
820 // ======================================================== replaceQuad
821 void Document::replaceQuad (Quad* old, Quad* par)
823 DumpStart ("replaceQuad", old << par);
824 if (BadElement(old) || BadElement(par) || old==par)
830 // par->replaceAssociation (old); TODO
832 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
836 Hexa* cell = static_cast <Hexa*> (elt);
837 cell->replaceQuad (old, par);
841 // ======================================================== prismQuad
842 Elements* Document::prismQuad (Quad* qstart, Vector* dir, int nb)
844 DumpStart ("prismQuad", qstart << dir << nb);
847 tstart.push_back (qstart);
850 Elements* prisme = prismQuads (tstart, dir, nb);
855 // ======================================================== prismQuads
856 Elements* Document::prismQuads (Quads& tstart, Vector* dir, int nb)
858 DumpStart ("prismQuads", tstart << dir << nb);
860 Elements* prisme = new Elements (this);
862 prisme->prismQuads (tstart, dir, nb);
867 // ======================================================== prismQuadsVec
868 Elements* Document::prismQuadsVec (Quads& tstart, Vector* dir, RealVector& tlen,
871 DumpStart ("prismQuadVec", tstart << dir << tlen << crit);
872 Elements* prisme = new Elements (this);
873 if (tlen.size()<=0) return prisme;
875 prisme->prismQuadsVec (tstart, dir, tlen, crit);
880 // ======================================================== joinQuads
881 Elements* Document::joinQuads (Quads& tstart, Quad* dest, Vertex* v1,
882 Vertex* v2, Vertex* v3, Vertex* v4, int nb)
884 DumpStart ("joinQuads", tstart << dest << v1 << v2 << v3 << v4 << nb);
886 Elements* joint = new Elements (this);
887 if (nb<=0) return joint;
889 int ier = joint->joinQuads (tstart, nb, v1, v2, v3, v4, dest);
891 printf ("\n ****\n **** Error in joinQuad(s)\n ****\n");
896 // ======================================================== joinQuad
897 Elements* Document::joinQuad (Quad* qstart, Quad* dest, Vertex* v1,
898 Vertex* v2, Vertex* v3, Vertex* v4, int nb)
900 DumpStart ("joinQuad", qstart << dest << v1 << v2 << v3 << v4 << nb);
903 tstart.push_back (qstart);
905 Elements* joint = joinQuads (tstart, dest, v1, v2, v3, v4, nb);
910 // ========================================================== getHexa
911 Hexa* Document::getHexa (int nro)
913 return static_cast <Hexa*> (getElement (EL_HEXA, nro));
915 // ========================================================== getQuad
916 Quad* Document::getQuad (int nro)
918 return static_cast <Quad*> (getElement (EL_QUAD, nro));
920 // ========================================================== getEdge
921 Edge* Document::getEdge (int nro)
923 return static_cast <Edge*> (getElement (EL_EDGE, nro));
925 // ========================================================== getVertex
926 Vertex* Document::getVertex (int nro)
928 return static_cast <Vertex*> (getElement (EL_VERTEX, nro));
930 // ========================================================== countElement
931 int Document::countElement (EnumElt type)
934 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
941 // ========================================================== getElement
942 EltBase* Document::getElement (EnumElt type, int nro)
945 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
957 // ========================================================= addLaw
958 Law* Document::addLaw (const char* name, int nbnodes)
960 DumpStart ("addLaw", name << nbnodes);
961 Law* loi = new Law (this, name, nbnodes);
966 // ========================================================= addLaw
967 Law* Document::addLaw (Law* loi)
969 doc_laws.push_back (loi);
973 // ========================================================= GetLaw
974 Law* Document::getLaw (int nro)
976 if (nro <0 || nro>= nbr_laws)
979 return doc_laws [nro];
981 // ========================================================= FindLaw
982 Law* Document::findLaw (const char* name)
985 for (int nro=0 ; nro<nbr_laws; nro++)
986 if (doc_laws [nro]->getName() == nom)
987 return doc_laws [nro];
991 // ========================================================= removeLaw
992 int Document::removeLaw (Law* loi)
994 for (int nro=1 ; nro<nbr_laws; nro++)
995 if (doc_laws [nro] == loi)
997 //All propagations having this law should now have the default law.
998 for (int nl=0 ; nl<nbr_propagations ; nl++)
1000 if ( doc_propagation [nl]->getLaw() == loi )
1001 doc_propagation [nl]->setLaw(defaultLaw);
1004 delete doc_laws [nro];
1005 doc_laws.erase (doc_laws.begin()+nro);
1006 nbr_laws = doc_laws.size();
1012 // ========================================================= majPropagation
1013 void Document::majPropagation ()
1018 // if (purge_elements)
1021 for (int nro=0 ; nro<nbr_propagations ; nro++)
1023 delete doc_propagation [nro];
1026 doc_propagation.clear ();
1027 nbr_propagations = 0;
1028 maj_propagation = false;
1030 for (EltBase* elt = doc_first_elt[EL_EDGE]->next (); elt!=NULL;
1033 Edge* arete = static_cast <Edge*> (elt);
1035 arete->setPropag (NOTHING, true);
1038 // markAll (NO_COUNTED, EL_EDGE);
1040 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
1043 Hexa* cell = static_cast <Hexa*> (elt);
1044 if (cell!=NULL && cell->isHere())
1046 for (int ne=0 ; ne<HE_MAXI ; ne++)
1048 Edge* arete = cell->getEdge(ne);
1049 if (arete->getPropag()<0)
1051 Propagation* prop = new Propagation ();
1052 doc_propagation.push_back (prop);
1053 arete->propager (prop, nbr_propagations);
1054 nbr_propagations ++;
1062 // ======================================================== countPropagation
1063 int Document::countPropagation ()
1065 if (maj_propagation)
1068 return nbr_propagations;
1070 // ======================================================== getPropagation
1071 Propagation* Document::getPropagation (int nro)
1073 if (maj_propagation)
1076 if (nro < 0 || nro >= nbr_propagations)
1079 return doc_propagation [nro];
1081 // ======================================================== findPropagation
1082 Propagation* Document::findPropagation (Edge* arete)
1087 if (maj_propagation)
1090 return getPropagation (arete->getPropag ());
1092 // ======================================================== disconnectQuad
1093 Elements* Document::disconnectQuad (Hexa* cell, Quad* element)
1095 if (cell==NULL || element==NULL)
1099 Elements* crees = cell->disconnectQuad (element);
1106 // ======================================================== disconnectEdge
1107 Elements* Document::disconnectEdge (Hexa* cell, Edge* element)
1109 if (cell==NULL || element==NULL)
1113 Elements* crees = cell->disconnectEdge (element);
1119 // ======================================================== disconnectVertex
1120 Elements* Document::disconnectVertex (Hexa* cell, Vertex* element)
1122 if (cell==NULL || element==NULL)
1126 Elements* crees = cell->disconnectVertex (element);
1132 // ======================================================== cut
1133 Elements* Document::cut (Edge* edge, int nbcuts)
1135 Elements* t_hexas = new Elements (this);
1137 if (edge==NULL || nbcuts<=0)
1140 Propagation* prop = findPropagation (edge);
1141 const Edges& t_edges = prop->getEdges ();
1143 t_hexas->cutHexas (t_edges, nbcuts);
1148 // ======================================================== addGroup
1149 Group* Document::addGroup (cpchar name, EnumGroup kind)
1151 Group* grp = new Group (name, kind);
1152 doc_group.push_back (grp);
1155 // ======================================================== findGroup
1156 Group* Document::findGroup (cpchar name)
1158 int nbre = doc_group.size();
1160 for (int ng=0 ; ng<nbre ; ng++)
1161 if (Cestegal (doc_group [ng]->getName(), name))
1162 return doc_group [ng];
1166 // ======================================================== removeGroup
1167 int Document::removeGroup (Group* grp)
1169 int nbre = doc_group.size();
1170 for (int ng=0 ; ng<nbre ; ng++)
1172 if (grp == doc_group [ng])
1174 doc_group.erase (doc_group.begin() + ng);
1179 // Pas trouve dans la liste. On detruit quand meme
1183 // ======================================================== makeCylinder
1184 Elements* Document::makeCylinder (Cylinder* cyl, Vector* base, int nr, int na,
1187 DumpStart ("makeCylinder", cyl << base << nr << na << nl);
1189 Elements* grille = new Elements (this);
1190 grille->makeCylinder (cyl, base, nr, na, nl);
1192 DumpReturn (grille);
1195 // ======================================================== makeCylinders
1196 CrossElements* Document::makeCylinders (Cylinder* cyl1, Cylinder* cyl2)
1198 DumpStart ("makeCylinders", cyl1 << cyl2 );
1200 CrossElements* grille = new CrossElements (this, GR_BICYL);
1201 grille->crossCylinders (cyl1, cyl2, true);
1203 DumpReturn (grille);
1207 // ======================================================== makePipe
1208 Elements* Document::makePipe (Pipe* pipe, Vector* bx, int nr, int na, int nl)
1210 DumpStart ("makePipe",
1211 pipe << bx << nr << na << nl);
1213 Elements* grille = new Elements (this);
1214 grille->makePipe (pipe, bx, nr, na, nr);
1216 DumpReturn (grille);
1219 // ======================================================== makePipes
1220 CrossElements* Document::makePipes (Pipe* pipe1, Pipe* pipe2)
1222 DumpStart ("makePipes",
1225 CrossElements* grille = new CrossElements (this, GR_BIPIPE);
1226 grille->crossCylinders (pipe1, pipe2, false);
1228 DumpReturn (grille);
1231 // ======================================================== setName
1232 int Document::setName (cpchar prefix)
1234 if (Cestvide (prefix) || el_name==prefix)
1237 string name = prefix;
1238 if (hex_parent != NULL)
1239 hex_parent->makeName (prefix, name);
1244 // ======================================================== setLevel
1252 BiCylinder* test_bicylinder (Document* docu, int option);
1253 void set_debug_asso (bool boule);
1255 void Document::setLevel (int niv)
1258 checkAssociations ();
1259 else if (niv == 748)
1261 int nbshapes = countShape ();
1262 for (int nsh=0 ; nsh < nbshapes ; nsh++)
1264 doc_tab_shape[nsh]->saveBrep();
1267 else if (niv == 777)
1268 set_special_option (true);
1269 else if (niv == 778)
1270 set_special_option (false);
1272 else if (niv >=90 && niv <=99)
1273 test_bicylinder (this, niv-90);
1278 set_debug_asso (niv>0);
1282 // ======================================================== getAssoVertices
1283 void Document::getAssoVertices (Vertices& tabelt)
1286 for (EltBase* elt = doc_first_elt[EL_VERTEX]->next (); elt!=NULL;
1288 if (elt->isHere() && elt->getAssociation()!=NULL)
1289 tabelt.push_back (static_cast <Vertex*> (elt));
1291 // ======================================================== getAssoEdges
1292 void Document::getAssoEdges (Edges& tabelt)
1295 for (EltBase* elt = doc_first_elt[EL_EDGE]->next (); elt!=NULL;
1299 Edge* edge = static_cast <Edge*> (elt);
1300 int nbass = edge->getAssociations().size();
1302 tabelt.push_back (edge);
1306 // ======================================================== makeVarName
1307 char* Document::makeVarName (char* name)
1309 strcpy (name, doc_ident);
1312 // ======================================================== isEmpty
1313 bool Document::isEmpty ()
1315 int nombre = countVertex () + countVector ()
1316 + countCylinder() + countPipe();
1317 return nombre <= 0 && countLaw () <= 1;
1319 // ======================================================== getNextName
1320 cpchar Document::getNextName (EnumElt type, string& buff)
1323 EltBase::makeName (type, doc_nbr_elt [type], name);
1326 return buff.c_str();
1329 // ======================================================== getNextName
1330 string Document::getNextName (EnumElt type)
1333 EltBase::makeName (type, doc_nbr_elt [type], name);
1335 return string(name);
1338 // ======================================================== lockDump
1339 void Document::lockDump ()
1343 // ======================================================== restoreDump
1344 void Document::restoreDump ()
1346 glob->dump.restore (DumpActif);
1348 // ======================================================== getGroup
1349 Group* Document::getGroup (int nro)
1351 int size = doc_group.size();
1352 if (nro>=0 && nro<size)
1353 return doc_group [nro];
1357 // ======================================================== getVector
1358 Vector* Document::getVector (int nro)
1360 int size = doc_vector.size();
1361 if (nro>=0 && nro<size)
1362 return doc_vector [nro];
1366 // ======================================================== getCylinder
1367 Cylinder* Document::getCylinder (int nro)
1369 int size = doc_cylinder.size();
1370 if (nro>=0 && nro<size)
1371 return doc_cylinder [nro];
1375 // ======================================================== getPipe
1376 Pipe* Document::getPipe (int nro)
1378 int size = doc_pipe.size();
1379 if (nro>=0 && nro<size)
1380 return doc_pipe [nro];
1385 // ======================================================== makeBiCylinder
1386 BiCylinder* Document::makeBiCylinder (Cylinder* cyl1, Cylinder* cyl2)
1388 DumpStart ("makeBiCylinder", cyl1 << cyl2 );
1390 BiCylinder* grille = new BiCylinder (this);
1391 grille->crossCylinders (cyl1, cyl2);
1393 DumpReturn (grille);
1396 // ======================================================== makeBiPipe
1397 BiCylinder* Document::makeBiPipe (Pipe* pipe1, Pipe* pipe2)
1399 DumpStart ("makeBiPipe", pipe1 << pipe2);
1401 BiCylinder* grille = new BiCylinder (this);
1402 grille->crossCylinders (pipe1, pipe2);
1404 DumpReturn (grille);