Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / HEXABLOCK / HexCloner.cxx
1
2 // C++ : Copiteur d'hexaedres
3
4 // Copyright (C) 2009-2024  CEA, EDF
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, or (at your option) any later version.
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 #include "HexCloner.hxx"
23 #include "HexMatrix.hxx"
24
25 #include "HexHexa.hxx"
26 #include "HexQuad.hxx"
27 #include "HexEdge.hxx"
28 #include "HexVertex.hxx"
29
30 #include "HexElements.hxx"
31 #include "HexVertexShape.hxx"
32 #include "HexEdgeShape.hxx"
33 #include "HexFaceShape.hxx"
34
35 BEGIN_NAMESPACE_HEXA
36
37 void transfo_brep (std::string& brep, Matrix* matrice, std::string& trep);
38 static bool db = false;
39
40 // ============================================================= Constructeur
41 Cloner::Cloner  (Matrix* mat)
42 {
43    matrice = mat;
44 }
45 // ============================================================== clonerVertex
46 Vertex* Cloner::clonerVertex (Vertex* orig)
47 {
48    if (orig == NULL)
49        return orig;
50
51    Vertex* copie = clone_vertex [orig];
52    if (copie != NULL)
53        return copie;
54
55    copie = new Vertex (orig);
56    matrice -> perform (copie);
57    clone_vertex [orig] = copie;
58
59    if (db)
60       {
61       printf ( " --- Cloner::Asso (%s) -> asso (%s)\n", orig ->getName  (),
62                                                         copie->getName ());
63       }
64    return copie;
65 }
66 // ============================================================== clonerEdge
67 Edge* Cloner::clonerEdge (Edge* orig)
68 {
69    if (orig == NULL)
70         return orig;
71
72    Edge* copie = clone_edge [orig];
73    if (copie != NULL)
74        return copie;
75
76    copie = new Edge (orig);
77
78    copie->e_vertex [V_AMONT] = clonerVertex (orig->e_vertex [V_AMONT]);
79    copie->e_vertex [V_AVAL]  = clonerVertex (orig->e_vertex [V_AVAL]);
80
81    copie->majReferences ();
82    clone_edge [orig] = copie;
83
84    if (orig->debug())
85       {
86       copie->printName (" est la copie de ");
87       orig ->printName ("\n");
88       }
89
90 /***********************
91    // const  Shapes & new_asso = copie->getAssociations ();  TODO  New Shape
92    // int    nbass             = new_asso.size();
93    // if (nbass!=0)
94       // return copie;
95
96    const Shapes & tab_asso = orig->getAssociations ();
97    nbass             = tab_asso.size();
98    for (int nro=0 ; nro < nbass ; nro++)
99        {
100        Shape* shape = tab_asso [nro];
101        std::string brep  = shape->getBrep();
102        std::string trep;
103        transfo_brep (brep, matrice, trep);
104        Shape* tshape = new Shape (trep);
105        tshape->setBounds (shape->getStart(), shape->getEnd());
106        copie ->addAssociation (tshape);
107        if (db)
108           {
109           printf ( " --- Cloner::Asso (%s) -> asso (%s)\n", orig ->getName (),
110                                                             copie->getName ());
111           // geom_dump_asso (orig );
112           // geom_dump_asso (copie);
113           }
114        }
115 ***************************************************/
116    return copie;
117 }
118 // ============================================================== clonerQuad
119 Quad* Cloner::clonerQuad (Quad* orig)
120 {
121    if (orig == NULL)
122        return orig;
123
124    Quad* copie = clone_quad [orig];
125    if (copie != NULL)
126        return copie;
127
128    copie = new Quad (orig);
129
130    for (int nro=0 ; nro<QUAD4 ; nro++)
131        copie->q_edge [nro] = clonerEdge (orig->q_edge [nro]);
132
133    for (int nro=0 ; nro<QUAD4 ; nro++)
134        copie->q_vertex [nro] = clonerVertex (orig->q_vertex [nro]);
135
136    copie->majReferences ();
137    clone_quad [orig] = copie;
138 /*******************************************************************
139    const  Shapes & new_asso = copie->getAssociations ();
140    int    nbass             = new_asso.size();
141    if (nbass!=0)
142       return copie;
143
144    const Shapes & tab_asso = orig->getAssociations ();
145    nbass             = tab_asso.size();
146    for (int nro=0 ; nro < nbass ; nro++)
147        {
148        Shape* shape = tab_asso [nro];
149        std::string brep  = shape->getBrep();
150        std::string trep;
151        transfo_brep (brep, matrice, trep);
152        Shape* tshape = new Shape (trep);
153        copie ->addAssociation (tshape);
154        if (db)
155           printf ( " --- Asso (%s) -> asso (%s)\n", orig ->getName (),
156                                                     copie->getName ());
157        }
158
159 ***************************************************/
160    return copie;
161 }
162 // ============================================================== clonerHexa
163 Hexa* Cloner::clonerHexa (Hexa* orig)
164 {
165    if (orig == NULL)
166        return orig;
167
168    Hexa* copie = clone_hexa [orig];
169    if (copie != NULL)
170        return copie;
171
172    copie = new Hexa (orig);
173    for (int nro=0 ; nro<HQ_MAXI ; nro++)
174        copie->h_quad [nro] = clonerQuad (orig->h_quad [nro]);
175
176    for (int nro=0 ; nro<HE_MAXI ; nro++)
177        copie->h_edge [nro] = clonerEdge (orig->h_edge [nro]);
178
179    for (int nro=0 ; nro<HV_MAXI ; nro++)
180        copie->h_vertex [nro] = clonerVertex (orig->h_vertex [nro]);
181
182    copie->majReferences ();
183    clone_hexa [orig] = copie;
184    return copie;
185 }
186 // ============================================================== clonerElements
187 Elements* Cloner::clonerElements (Elements* orig)
188 {
189    Elements* copie = new Elements (orig);
190    if (db)
191       {
192       double             a11,a12,a13,a14, a21,a22,a23,a24, a31,a32,a33,a34;
193       matrice->getCoeff (a11,a12,a13,a14, a21,a22,a23,a24, a31,a32,a33,a34);
194       printf ( "\n");
195       printf ( " --- Matrice = (%g, %g, %g) (%g) \n", a11,a12,a13,a14 );
196       printf ( "               (%g, %g, %g) (%g) \n", a21,a22,a23,a24 );
197       printf ( "               (%g, %g, %g) (%g) \n", a31,a32,a33,a34 );
198       }
199
200    int nombre = orig->countHexa ();
201    for (int nro=0 ; nro<nombre ; nro++)
202        {
203        Hexa* elt  = orig->getHexa (nro);
204        Hexa* elt2 = clonerHexa (elt);
205        copie->setHexa (elt2, nro);
206        }
207
208    nombre = orig->countQuad ();
209    for (int nro=0 ; nro<nombre ; nro++)
210        {
211        Quad* elt  = orig->getQuad (nro);
212        Quad* elt2 = clonerQuad (elt);
213        copie->setQuad (elt2, nro);
214        }
215
216    nombre = orig->countEdge ();
217    for (int nro=0 ; nro<nombre ; nro++)
218        {
219        Edge* elt  = orig->getEdge (nro);
220        Edge* elt2 = clonerEdge (elt);
221        copie->setEdge (elt2, nro);
222        }
223
224    nombre = orig->countVertex ();
225    for (int nro=0 ; nro<nombre ; nro++)
226        {
227        Vertex* elt  = orig->getVertex (nro);
228        Vertex* elt2 = clonerVertex (elt);
229        copie->setVertex (elt2, nro);
230        }
231
232
233    return copie;
234 }
235 END_NAMESPACE_HEXA