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/ or email : webmaster.salome@opencascade.com
26 #include "HexEltBase.hxx"
32 class Document : public EltBase
34 // Fonctions utilisateur
37 bool isSaved () { return doc_saved ; }
38 int setName (const char* name);
40 int save (const char* ficxml); // Genere le xml dans un seul fichier
41 int appendXml (pfile fstudy); // Genere le xml dans un fichier ouvert
42 cpchar getXml (); // Genere le xml et rend un flux
44 int getLevel () { return doc_db ; }
45 void setLevel (int niv);
47 Hexa* getHexa (int nro);
48 Quad* getQuad (int nro);
49 Edge* getEdge (int nro);
50 Vertex* getVertex (int nro);
52 int countHexa () { return countElement (EL_HEXA); }
53 int countQuad () { return countElement (EL_QUAD); }
54 int countEdge () { return countElement (EL_EDGE); }
55 int countVertex () { return countElement (EL_VERTEX); }
57 // Creation d'elements
58 Vertex* addVertex (double x=0.0, double y=0.0, double z=0.0);
59 Edge* addEdge (Vertex* va, Vertex* vb);
60 Edge* addEdgeVector (Vertex* va, Vector* vec);
62 Edge* addEdge (Vertex* va, Vector* vec) // A supprimer
63 { return addEdgeVector (va, vec) ; } // (comptibilite)
65 Quad* addQuadVertices (Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4);
66 Quad* addQuad (Edge* v1, Edge* v2, Edge* v3, Edge* v4);
68 Hexa* addHexaVertices (Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4,
69 Vertex* v5, Vertex* v6, Vertex* v7, Vertex* v8);
70 Hexa* addHexa (Quad* qa, Quad* qb, Quad* qc, Quad* qd, Quad* qe, Quad* qf);
72 Vector* addVector (double dx=0.0, double dy=0.0, double dz=0.0);
73 Vector* addVectorVertices (Vertex* va, Vertex* vb);
75 Elements* makeCartesian (Vertex* v, Vector* v1,
76 int px, int py, int pz, int mx=0, int my=0, int mz=0);
77 Elements* makeCartesian (Vertex* v, Vector* v1, Vector* v2, Vector* v3,
78 int px, int py, int pz);
79 Elements* makeCartesian1 (Vertex* v, Vector* v1, Vector* v2, Vector* v3,
80 int px, int py, int pz, int mx, int my, int mz);
82 Elements* makeCylindrical (Vertex* c, Vector* b, Vector* h, double dr,
83 double da, double dl, int nr, int na, int nl, bool fill=false);
86 Elements* makeSpherical (Vertex* v, Vector* dv, int nb, double k=1) {return NULL;}
87 Elements* makeSpherical (Vertex* center, double rayon, int nb, double k=1);
89 Elements* prismQuad (Quad* start, Vector* dv, int nb);
90 Elements* prismQuads (Quads& start, Vector* dv, int nb);
91 Elements* prismQuadsVec (Quads& start, Vector* dv, RealVector& th, int k=0);
93 Elements* joinQuad (Quad* start, Quad* dest, Vertex* v1, Vertex* v2,
94 Vertex* v3, Vertex* v4, int nb);
95 Elements* joinQuads (Quads& start, Quad* dest, Vertex* v1, Vertex* v2,
96 Vertex* v3, Vertex* v4, int nb);
98 Cylinder* addCylinder (Vertex* b, Vector* d, double r, double h);
99 Elements* makeCylinder (Cylinder* cyl, Vector* vx, int nr, int na, int nl);
100 CrossElements* makeCylinders (Cylinder* cyl1, Cylinder* cyl2);
102 Pipe* addPipe (Vertex* b, Vector* d, double ri, double re, double h);
103 Elements* makePipe (Pipe* pip, Vector* vx, int nr, int na, int nl);
104 CrossElements* makePipes (Pipe* pipe1, Pipe* pipe2);
106 BiCylinder* makeBiCylinder (Cylinder* cyl1, Cylinder* cyl2);
107 BiCylinder* makeBiPipe (Pipe* pipe1, Pipe* pipe2);
109 int removeHexa (Hexa* maille);
110 int removeQuad (Quad* maille);
111 int removeConnectedHexa (Hexa* maille);
112 int removeElements (Elements* bloc);
114 Vertex* findVertex (double vx, double vy, double vz);
115 Edge* findEdge (Vertex* va, Vertex* vb);
116 Quad* findQuad (Vertex* va, Vertex* vb);
117 Hexa* findHexa (Vertex* va, Vertex* vb);
119 Vertex* findVertex (int id);
121 int mergeVertices (Vertex* v1, Vertex* v2);
122 int mergeEdges (Edge* e1, Edge* e2, Vertex* v1, Vertex* v2);
123 int mergeQuads (Quad* q1, Quad* q2, Vertex* v1, Vertex* v2,
124 Vertex* v3, Vertex* v4);
125 int closeQuads (Quad* q1, Quad* q2);
127 Elements* makeTranslation (Elements* elts, Vector* trans);
128 Elements* makeScale (Elements* elts, Vertex* ver, double k);
129 Elements* makeRotation (Elements* elts, Vertex* ver, Vector* vec,
131 Elements* makeSymmetryPoint (Elements* elts, Vertex* ver);
132 Elements* makeSymmetryLine (Elements* elts, Vertex* ver, Vector* vec);
133 Elements* makeSymmetryPlane (Elements* elts, Vertex* ver, Vector* vec);
135 int performTranslation (Elements* elts, Vector* trans);
136 int performScale (Elements* elts, Vertex* ver, double k);
137 int performRotation (Elements* elts, Vertex* ver, Vector* vec, double angle);
138 int performSymmetryPoint (Elements* elts, Vertex* ver);
139 int performSymmetryLine (Elements* elts, Vertex* ver, Vector* vec);
140 int performSymmetryPlane (Elements* elts, Vertex* ver, Vector* vec);
142 void setTolerance (double tol) { doc_tolerance = std::max (tol, 0.0); }
143 double getTolerance () { return doc_tolerance; }
145 Elements* disconnectQuad (Hexa* maille, Quad* face);
146 Elements* disconnectEdge (Hexa* maille, Edge* arete);
147 Elements* disconnectVertex (Hexa* maille, Vertex* noeud);
148 Elements* disconnectEdges (Hexas& thexas, Edges& edges);
150 Elements* cut (Edge* edge, int nbcuts);
152 Group* addGroup (cpchar name, EnumGroup kind);
153 Group* getGroup (int nro);
154 Group* findGroup (cpchar name);
155 int removeGroup (Group* grp);
156 int countGroup () { return (int) doc_group.size(); }
158 // ---------------------------------------------------
160 Law* addLaw (const char* name, int nbnodes);
161 Law* addLaw (Law* law); // lo-add-lololo
162 int countLaw () { return nbr_laws ; }
163 Law* getLaw (int nro);
164 Law* findLaw (const char* name);
165 int removeLaw (Law* loi);
167 // ---------------------------------------------------
168 int countPropagation ();
169 Propagation* getPropagation (int nro);
170 Propagation* findPropagation (Edge* arete);
171 void dumpPropagation ();
173 int countVector () { return doc_vector.size(); }
174 int countCylinder () { return doc_cylinder.size(); }
175 int countPipe () { return doc_pipe.size(); }
177 Vector* getVector (int nro);
178 Cylinder* getCylinder (int nro);
179 Pipe* getPipe (int nro);
183 // --------------------------------------------------- Evols Hexa3
185 Document* copyDocument ();
187 int countUsedHexa ();
188 int countUsedQuad ();
189 int countUsedEdge ();
190 int countUsedVertex ();
192 Hexa* getUsedHexa (int nro);
193 Quad* getUsedQuad (int nro);
194 Edge* getUsedEdge (int nro);
195 Vertex* getUsedVertex (int nro);
197 Hexa* addHexa2Quads (Quad* q1, Quad* q2);
198 Hexa* addHexa3Quads (Quad* q1, Quad* q2, Quad* q3);
199 Hexa* addHexa4Quads (Quad* q1, Quad* q2, Quad* q3, Quad* q4);
200 Hexa* addHexa5Quads (Quad* q1, Quad* q2, Quad* q3, Quad* q4, Quad* q5);
202 Elements* revolutionQuads (Quads& start, Vertex* center, Vector* axis,
205 Elements* makeSphere (Vertex* center, Vector* vx, Vector* vz,
206 double radius, double radhole,
208 int nrad, int nang, int nhaut);
210 Elements* makePartSphere (Vertex* center, Vector* vx, Vector* vz,
211 double radius, double radhole,
212 Vertex* plorig, double angle,
213 int nrad, int nang, int nhaut);
215 Elements* makeRind (Vertex* center, Vector* vx, Vector* vz,
216 double radext, double radint, double radhole,
218 int nrad, int nang, int nhaut);
220 Elements* makePartRind (Vertex* center, Vector* vx, Vector* vz,
221 double radext, double radint, double radhole,
222 Vertex* plorig, double angle,
223 int nrad, int nang, int nhaut);
225 Elements* replace (Quads& pattern, Vertex* p1, Vertex* c1,
226 Vertex* p2, Vertex* c2, Vertex* p3, Vertex* c3);
228 Elements* makeCylindricals (Vertex* c, Vector* b, Vector* h,
229 RealVector& tdr, RealVector& tda, RealVector& tdh,
232 // --------------------------------------------------- Evols Hexa4'
234 void clearAssociation ();
236 typedef std::vector <Vertex*> Vertices;
237 void getAssoEdges (Edges& tabelt);
238 void getAssoVertices (Vertices& tabelt);
240 // --------------------------------------------------- Evols Hexa5
242 NewShape* getCloud () { return doc_cloud ; }
243 NewShape* addShape (TopoDS_Shape& forme, const char* name);
244 NewShape* addShape (const char* name, EnumShape type);
245 NewShape* getShape (int nro);
246 NewShape* findShape (rcstring name);
247 int countShape () { return doc_tab_shape.size() ; }
249 int associateOpenedLine (Edges& mline, NewShapes& gline, IntVector& tabid,
250 double pstart, double pend);
252 int associateClosedLine (Vertex* mfirst, Edges& mline,
253 NewShapes& gline, IntVector& tabid,
254 double pstart, bool inv);
256 int associateLine (Vertex* mfirst, Edges& mline,
257 NewShapes& gline, IntVector& tabid,
258 double pstart, double pend, bool inv);
260 int clearAssociation (EnumElt type);
261 void clearAssoVertices ();
262 void clearAssoEdges ();
263 void clearAssoQuads ();
265 int checkAssociations ();
268 Document (cpchar name, Hex* dad=NULL);
271 int loadXml (cpchar name);
272 int setXml (cpchar flux);
273 int setXml (cpchar flux, int& position);
275 EltBase* getFirstEltBase (EnumElt type) { return doc_first_elt [type]; }
276 EltBase* getLastEltBase (EnumElt type) { return doc_last_elt [type]; }
277 int getNbrElt (EnumElt type) { return doc_nbr_elt [type]; }
278 void setDeprecated (int level=1);
281 void markAll (int marque, int type=-1);
282 int saveVtk0 (cpchar nomfic);
283 int saveVtk (cpchar nomfic);
284 int saveVtk (cpchar radical, int &nro);
286 void putError (cpchar mess, cpchar info1=NULL, cpchar info2=NULL);
287 void nputError (cpchar mess, int info1, cpchar info2=NULL);
288 void hputError (cpchar mess, EltBase* e1, EltBase* e2=NULL);
290 void majReferences (); // M.A.J relation "utilise par"
291 void update () { if (maj_connection) majReferences (); }
292 bool debug (int niv=0) { return doc_db > niv ; }
294 void reorderFaces ();
295 void reorderQuads ();
297 // --------------------------------------------------- Evols Hexa5
298 cpchar getNextName (EnumElt type, string& name);
299 string getNextName (EnumElt type);
301 virtual char* makeVarName (char* name);
311 int parseXml (XmlTree& xml);
313 void replaceVertex (Vertex* v1, Vertex* v2);
314 void replaceEdge (Edge* e1, Edge* e2);
315 void replaceQuad (Quad* q1, Quad* q2);
317 int countElement (EnumElt type);
318 EltBase* getElement (EnumElt type, int nro);
320 void majPropagation ();
323 Elements* clonerElements (Elements* table, Matrix* matrice);
325 // --------------------------------------------------- Evols Hexa3
326 Hexa* addHexaQuadsAB (AnaQuads& strquads);
327 Hexa* addHexaQuadsAC (AnaQuads& strquads);
328 Hexa* addHexaQuadsACE (AnaQuads& strquads);
329 Hexa* addHexaQuadsACD (AnaQuads& strquads);
330 Hexa* addHexaQuadsABCD (AnaQuads& strquads);
331 Hexa* addHexaQuadsACDE (AnaQuads& strquads);
333 EltBase* findElement (EnumElt type, int ident);
334 // --------------------------------------------------- Evols Hexa5
336 int sortShapes (NewShapes& tshapes, IntVector& subid,
337 bool closed, bool inv, double pstart, double pend,
338 EdgeShapes& glines, IntVector& sens, double& lgtotale);
339 int sortEdges (Vertex* vfirst, Edges& mline, Edges& edges, IntVector& sens);
341 void parseShapes (XmlTree& root);
342 void parseAssociation (XmlTree* root, Quad* elt);
343 void parseAssociation (XmlTree* root, Edge* elt);
344 void parseAssociation (XmlTree* root, Vertex* elt);
345 SubShape* parseSubShape (XmlTree* root);
348 friend class EltBase;
358 EltBase* doc_first_elt [EL_MAXI];
359 EltBase* doc_last_elt [EL_MAXI];
360 int doc_nbr_elt [EL_MAXI];
361 double doc_tolerance;
363 std::vector <Law*> doc_laws;
367 int nbr_propagations;
368 bool maj_propagation;
370 std::vector <Propagation*> doc_propagation;
371 std::vector <Group*> doc_group;
373 std::vector <Vector*> doc_vector;
374 std::vector <Cylinder*> doc_cylinder;
375 std::vector <Pipe*> doc_pipe;
378 // --------------------------------------------------- HexaBlock v3
380 std::vector <Hexa*> doc_used_hexas;
381 std::vector <Quad*> doc_used_quads;
382 std::vector <Edge*> doc_used_edges;
383 std::vector <Vertex*> doc_used_vertex;
390 // --------------------------------------------------- HexaBlock v5
392 static int doc_number;
396 NewShape* doc_cloud; // Nuage de points du doc;
397 std::vector <NewShape*> doc_tab_shape;
399 // ========================================================= saveVtk (avec nro)
400 inline int Document::saveVtk (cpchar radical, int &nro)
403 sprintf (num, "%d", nro);
406 string filename = radical;
409 int ier = saveVtk (filename.c_str());
412 // ========================================================= setDeprecated
413 inline void Document::setDeprecated (int level)
417 // En cas de destruction : parents invalides
418 case 2 : maj_connection = true;
419 purge_elements = true;
420 // creation + destruction : propagations a revoir
421 case 1 : maj_propagation = true;
423 default: doc_modified = true;
424 count_modified = true;