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