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