Salome HOME
8950e5c565524c4bc5be349e908b7717ead7fd40
[modules/hexablock.git] / src / HEXABLOCK / HexDocument.hxx
1
2 // class : Document
3
4 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef __DOCUMENT_H_
24 #define __DOCUMENT_H_
25
26 #include "HexEltBase.hxx"
27
28 BEGIN_NAMESPACE_HEXA
29
30 class NewShape;
31
32 class Document : public EltBase
33 {
34                                    // Fonctions utilisateur
35 public :
36                                    // Fonctions globales
37    bool        isSaved ()              { return doc_saved ; }
38    int setName (const char* name);
39
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
43
44    int  getLevel ()                    { return doc_db ; }
45    void setLevel (int niv);
46
47    Hexa*   getHexa   (int nro);
48    Quad*   getQuad   (int nro);
49    Edge*   getEdge   (int nro);
50    Vertex* getVertex (int nro);
51
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); }
56
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);
61
62    Edge*   addEdge   (Vertex* va, Vector* vec)             // A supprimer
63                      { return addEdgeVector (va, vec) ; }  // (comptibilite)
64
65    Quad*   addQuadVertices   (Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4);
66    Quad*   addQuad   (Edge* v1, Edge* v2, Edge* v3, Edge* v4);
67
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);
71
72    Vector* addVector (double dx=0.0, double dy=0.0, double dz=0.0);
73    Vector* addVectorVertices (Vertex* va, Vertex* vb);
74
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);
81
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);
84
85                                                       // Obsolete
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);
88
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);
92
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);
97
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);
101
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);
105
106    BiCylinder* makeBiCylinder (Cylinder* cyl1, Cylinder* cyl2);
107    BiCylinder* makeBiPipe     (Pipe* pipe1, Pipe* pipe2);
108
109    int     removeHexa (Hexa* maille);
110    int     removeQuad (Quad* maille);
111    int     removeConnectedHexa (Hexa* maille);
112    int     removeElements  (Elements* bloc);
113
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);
118
119    Vertex* findVertex (int id);
120
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);
126
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,
130                                 double angle);
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);
134
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);
141
142    void   setTolerance (double tol) { doc_tolerance = std::max (tol, 0.0); }
143    double getTolerance ()           { return doc_tolerance; }
144
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);
149
150    Elements* cut (Edge* edge, int nbcuts);
151
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(); }
157
158    // ---------------------------------------------------
159
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);
166
167    // ---------------------------------------------------
168    int          countPropagation ();
169    Propagation* getPropagation   (int nro);
170    Propagation* findPropagation  (Edge* arete);
171    void         dumpPropagation  ();
172
173    int countVector ()              { return doc_vector.size(); }
174    int countCylinder ()            { return doc_cylinder.size(); }
175    int countPipe ()                { return doc_pipe.size(); }
176
177    Vector*   getVector   (int nro);
178    Cylinder* getCylinder (int nro);
179    Pipe*     getPipe     (int nro);
180
181    void purge ();
182
183    // --------------------------------------------------- Evols Hexa3
184
185    Document* copyDocument ();
186
187    int countUsedHexa   ();
188    int countUsedQuad   ();
189    int countUsedEdge   ();
190    int countUsedVertex ();
191
192    Hexa*   getUsedHexa   (int nro);
193    Quad*   getUsedQuad   (int nro);
194    Edge*   getUsedEdge   (int nro);
195    Vertex* getUsedVertex (int nro);
196
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);
201
202    Elements* revolutionQuads (Quads& start, Vertex* center, Vector* axis,
203                               RealVector &angles);
204
205    Elements* makeSphere (Vertex* center, Vector* vx, Vector* vz,
206                          double radius, double radhole,
207                          Vertex* plorig,
208                          int nrad, int nang, int nhaut);
209
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);
214
215    Elements* makeRind (Vertex* center, Vector* vx, Vector* vz,
216                        double  radext, double radint, double radhole,
217                        Vertex* plorig,
218                        int nrad, int nang, int nhaut);
219
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);
224
225    Elements* replace (Quads& pattern, Vertex* p1, Vertex* c1,
226                       Vertex* p2, Vertex* c2,  Vertex* p3, Vertex* c3);
227
228    Elements* makeCylindricals (Vertex* c, Vector* b, Vector* h,
229              RealVector& tdr, RealVector& tda, RealVector& tdh,
230              bool fill=false);
231
232    // --------------------------------------------------- Evols Hexa4'
233
234    void clearAssociation ();
235
236    typedef std::vector <Vertex*> Vertices;
237    void getAssoEdges    (Edges&    tabelt);
238    void getAssoVertices (Vertices& tabelt);
239
240    // --------------------------------------------------- Evols Hexa5
241
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() ; }
248
249    int associateOpenedLine (Edges&  mline, NewShapes& gline, IntVector& tabid,
250                             double pstart, double pend);
251
252    int associateClosedLine (Vertex* mfirst,   Edges&  mline,
253                             NewShapes& gline, IntVector& tabid,
254                             double pstart, bool inv);
255
256    int associateLine (Vertex* mfirst, Edges& mline,
257                       NewShapes& gline, IntVector& tabid,
258                       double pstart, double pend, bool inv);
259
260    int  clearAssociation  (EnumElt type);
261    void clearAssoVertices ();
262    void clearAssoEdges   ();
263    void clearAssoQuads   ();
264
265    int  checkAssociations ();
266
267 public:
268     Document (cpchar name, Hex* dad=NULL);
269    ~Document ();
270
271     int    loadXml (cpchar name);
272     int    setXml  (cpchar flux);
273     int    setXml  (cpchar flux, int& position);
274
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);
279
280     void dump ();
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);
285
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);
289
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 ; }
293
294     void  reorderFaces ();
295     void  reorderQuads ();
296
297    // --------------------------------------------------- Evols Hexa5
298    cpchar getNextName (EnumElt type, string& name);
299    string getNextName (EnumElt type);
300
301    virtual char* makeVarName (char* name);
302    void    lockDump();
303    void    restoreDump();
304    bool    isEmpty ();
305
306 public:
307    Globale* glob;
308
309 private :
310    int   genXml   ();
311    int   parseXml (XmlTree& xml);
312
313    void  replaceVertex (Vertex* v1, Vertex* v2);
314    void  replaceEdge   (Edge*   e1, Edge* e2);
315    void  replaceQuad   (Quad*   q1, Quad* q2);
316
317    int   countElement  (EnumElt type);
318    EltBase* getElement (EnumElt type, int nro);
319
320    void  majPropagation ();
321    void  renumeroter ();
322
323    Elements* clonerElements (Elements* table, Matrix* matrice);
324
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);
332
333    EltBase* findElement (EnumElt type, int ident);
334    // --------------------------------------------------- Evols Hexa5
335    void addCloud ();
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);
340
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);
346
347 private :
348    friend class EltBase;
349
350    bool doc_modified;
351    bool count_modified;
352    bool doc_saved;
353    bool maj_connection;
354    bool purge_elements;
355    int  doc_db;
356    int  nbr_errors;
357
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;
362
363    std::vector <Law*> doc_laws;
364    int                nbr_laws;
365    Law* defaultLaw;
366
367    int  nbr_propagations;
368    bool maj_propagation;
369
370    std::vector <Propagation*> doc_propagation;
371    std::vector <Group*>       doc_group;
372
373    std::vector <Vector*>      doc_vector;
374    std::vector <Cylinder*>    doc_cylinder;
375    std::vector <Pipe*>        doc_pipe;
376    XmlWriter*                 doc_xml;
377
378    // --------------------------------------------------- HexaBlock v3
379
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;
384
385    int nbr_used_hexas;
386    int nbr_used_quads;
387    int nbr_used_edges;
388    int nbr_used_vertex;
389
390    // --------------------------------------------------- HexaBlock v5
391
392    static int doc_number;
393    char      doc_ident [8];
394    Hex*      hex_parent;
395
396    NewShape*   doc_cloud;                     // Nuage de points du doc;
397    std::vector <NewShape*> doc_tab_shape;
398 };
399 // ========================================================= saveVtk (avec nro)
400 inline int Document::saveVtk  (cpchar radical, int &nro)
401 {
402    char num[8];
403    sprintf (num, "%d", nro);
404    nro ++;
405
406    string filename = radical;
407    filename += num;
408    filename += ".vtk";
409    int ier = saveVtk (filename.c_str());
410    return ier;
411 }
412 // ========================================================= setDeprecated
413 inline void Document::setDeprecated (int level)
414 {
415    switch (level)
416           {
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;
422                          // Par defaut :
423           default: doc_modified    = true;
424                    count_modified  = true;
425           }
426 }
427
428 END_NAMESPACE_HEXA
429 #endif