2 // CC++ : Interface Cascade de la classe Elements
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
23 #include "HexElements.hxx"
24 #include "HexEdge.hxx"
25 #include "HexDocument.hxx"
27 #include "HexKasBiCylinder.hxx"
28 #include "HexKasPoint.hxx"
29 #include "HexKasLine.hxx"
31 #include <BRepTools.hxx>
32 #include <BRep_Builder.hxx>
33 #include <BRepAdaptor_Curve.hxx>
34 #include <BRepBuilderAPI_Transform.hxx>
35 #include <BRepBuilderAPI_MakeVertex.hxx>
37 #include <GCPnts_AbscissaPoint.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TopoDS_Compound.hxx>
43 #include <TopoDS_Vertex.hxx>
51 #include "HexVertex.hxx"
52 #include "HexOldShape.hxx"
53 #include "HexDiagnostics.hxx"
55 #include <GEOMImpl_CircleDriver.hxx>
56 #include <GEOMImpl_ICircle.hxx>
58 #include <BRepBuilderAPI_MakeEdge.hxx>
59 #include <BRep_Tool.hxx>
61 #include <GC_MakeCircle.hxx>
62 #include <Geom_Circle.hxx>
64 #include <gp_Circ.hxx>
66 #include <BRepPrimAPI_MakeSphere.hxx>
68 #include <GEOMImpl_CylinderDriver.hxx>
69 #include <GEOMImpl_ICylinder.hxx>
70 #include <BRepPrimAPI_MakeCylinder.hxx>
71 #include <BRepAlgoAPI_Section.hxx>
75 static bool db = false;
77 void clear_associations (Edge* edge);
79 // ---------------------------------------------------------------------
81 static KasLine current_line;
82 static Shape current_shape ("");
84 // ========================================================= cutAssociation
85 void Elements::cutAssociation (Shapes& tshapes, Edges& tedges, bool exist)
89 int nbedges = tedges.size();
90 int nbshapes = tshapes.size ();
94 std::vector <KasLine> tab_gline (nbshapes);
96 Vertex* prems = tedges [0] -> getVertex (V_AMONT);
97 Vertex* derns = tedges [nbedges-1] -> getVertex (V_AVAL);
99 KasPoint pnt_first, pnt_last;
100 pnt_first.definePoint (prems);
101 pnt_last .definePoint (derns);
105 if (pnt_first.isBad())
107 el_root->putError (W_ASSO_CUT1, prems->getName (foo));
110 else if (pnt_last.isBad ())
112 el_root->putError (W_ASSO_CUT2, derns->getName (foo));
116 // ----------- Define + longueur totale
118 for (int ns = 0 ; ns<nbshapes ; ns++)
120 tab_gline[ns].defineLine (tshapes[ns]);
121 longueur += tab_gline[ns].getLength ();
124 // ----------- Ordonnancement des shapes
127 double* coord = pnt_first.getCoord ();
130 tab_gline [0].setRank (0, 0, abscisse);
135 for (int rg = 0 ; rg<nbshapes ; rg++)
138 for (int ns = 0 ; ns<nbshapes && more ; ns++)
140 if (tab_gline[ns].getRank()==NOTHING)
142 int pos = tab_gline[ns].findBound (coord);
147 tab_gline [ns].setRank (rg, pos, abscisse);
148 coord = tab_gline [ns].getEnd ();
155 el_root->putError (W_ASSO_CUT3, derns->getName (foo));
160 // ----------- Dernier
163 coord = pnt_last.getCoord ();
164 int pos = tab_gline[nslast].findBound (coord);
167 el_root->putError (W_ASSO_CUT4, derns->getName (foo));
171 // ----------- Associations
172 double delta = longueur / nbedges;
173 for (int ned = 0 ; ned<nbedges ; ned++)
175 if (db) cout << " ++ Association Edge nro "
176 << ned << "/" <<nbedges << endl;
177 Edge* edge = tedges[ned];
178 double sm1 = ned*delta;
179 double sm2 = sm1 + delta;
180 for (int ns = 0 ; ns<nbshapes ; ns++)
182 tab_gline[ns].associate (edge, sm1, sm2);
186 if (db) cout << " +++ End of Elements::cutAssociation" << endl;
188 // ====================================================== geom_define_line
189 void geom_define_line (string& brep)
191 current_shape.setBrep (brep);
192 current_shape.setBounds (0, 1);
193 current_line.defineLine (¤t_shape);
195 // ====================================================== geom_asso_point
196 void geom_asso_point (double angle, Vertex* node)
198 if (node!=NULL && node->getAssociation() == NULL)
199 current_line.assoPoint (angle, node);
201 // ====================================================== geom_asso_point
202 void geom_asso_point (Vertex* node)
204 if (node==NULL || node->getAssociation() != NULL)
207 Real3 koord = { node->getX(), node->getY(), node->getZ() };
208 KasPoint asso_point ;
209 asso_point.definePoint (koord);
210 asso_point.associate (node);
212 // ====================================================== geom_create_circle
213 void geom_create_circle (double* milieu, double rayon, double* normale,
214 double* base, string& brep)
217 if (db) printf ("geom_create_circle c=(%g,%g,%g), r=%g\n",
218 milieu[0], milieu[1], milieu[2], rayon);
219 if (db) printf (" -------- base=(%g,%g,%g)\n", base[0], base[1], base[2]);
220 if (db) printf (" -------- norm=(%g,%g,%g)\n", normale[0], normale[1],
223 gp_Pnt gp_center (milieu [dir_x], milieu [dir_y], milieu [dir_z]);
224 gp_Vec gp_vx (base [dir_x], base [dir_y], base [dir_z]);
225 gp_Vec gp_norm (normale[dir_x], normale[dir_y], normale[dir_z]);
227 gp_Ax2 gp_axes (gp_center, gp_norm, gp_vx);
228 gp_Circ gp_circ (gp_axes, rayon);
230 TopoDS_Edge geom_circ = BRepBuilderAPI_MakeEdge(gp_circ).Edge();
231 ostringstream stream_shape;
232 BRepTools::Write(geom_circ, stream_shape);
233 brep = stream_shape.str();
235 // geom_make_brep (geom_circ, brep);
238 // Impressions de mise au point
239 double umin = 0, umax = 0;
241 Handle(Geom_Curve) handle = BRep_Tool::Curve (geom_circ, loc, umin, umax);
242 GeomAdaptor_Curve AdaptCurve (handle);
243 double length = GCPnts_AbscissaPoint::Length(AdaptCurve, umin, umax);
245 BRepAdaptor_Curve geom_curve (geom_circ);
247 for (int pk=0; pk<=4; pk++)
249 GCPnts_AbscissaPoint s1 (geom_curve, pk*length/4,
250 geom_curve.FirstParameter());
251 double u1 = s1.Parameter ();
252 gp_Pnt point = geom_curve.Value (u1);
254 printf ( " ..... pnt%d = (%g, %g, %g)\n", pk, point.X(),
255 point.Y(), point.Z());
258 // ====================================================== geom_create_sphere
259 void geom_create_sphere (double* milieu, double radius, string& brep)
261 gp_Pnt gp_center (milieu [dir_x], milieu [dir_y], milieu [dir_z]);
262 gp_Ax2 gp_axis = gp_Ax2 (gp_center, gp_Dir(0,0,1), gp_Dir(1,0,0));
264 BRepPrimAPI_MakeSphere make_sphere (gp_axis, radius);
268 ostringstream stream_shape;
269 TopoDS_Shape geom_sphere = make_sphere.Face();
270 BRepTools::Write (geom_sphere, stream_shape);
271 brep = stream_shape.str();
273 // ====================================================== geom_dump_asso
274 void geom_dump_asso (Edge* edge)
276 printf (" %s dump_edge :\n",
277 "_______________________________________________________________");
278 if (edge==NULL || NOT edge->isHere ())
280 printf ("*** deleted ***)\n");
286 edge->printName(" = (");
287 edge->getVertex (V_AMONT)-> printName (", ");
288 edge->getVertex (V_AVAL) -> printName (")\n");
291 for (int nro=0 ; nro<V_TWO ; nro++)
293 Vertex* vertex = edge->getVertex (nro);
294 vertex->printName ("");
295 printf (" = (%g, %g, %g)", vertex->getX(), vertex->getY(),
298 int ier = asso_point.definePoint (vertex);
301 double* coord = asso_point.getCoord();
302 printf (", pnt_asso = (%g, %g, %g)", coord[dir_x], coord[dir_y],
309 const Shapes& tshapes = edge->getAssociations ();
310 for (int nro=0 ; nro<tshapes.size() ; nro++)
312 printf ( " ------------------- Edge.tab_shape[%d] :\n", nro);
313 Shape* shape = tshapes[nro];
316 printf ( " = NULL\n");
320 asso_line.defineLine (shape);
321 double* deb = asso_line.getStart ();
322 double* fin = asso_line.getEnd ();
323 double lg = asso_line.getLength ();
324 printf (" Longueur = %g\n", lg);
325 printf (" Debut = %g = (%g, %g, %g)\n", shape->getStart(),
326 deb[0], deb[1], deb[2]);
327 printf (" Fin = %g = (%g, %g, %g)\n", shape->getEnd(),
328 fin[0], fin[1], fin[2]);
333 // ====================================================== translate_brep
334 void translate_brep (string& brep, double dir[], string& trep)
337 BRep_Builder builder;
340 gp_Vec vecteur (dir [dir_x], dir [dir_y], dir [dir_z]);
341 transfo.SetTranslation (vecteur);
342 istringstream stream_brep (brep);
343 BRepTools::Read (orig, stream_brep, builder);
345 TopLoc_Location loc_orig = orig.Location();
346 gp_Trsf trans_orig = loc_orig.Transformation();
347 TopLoc_Location loc_result (transfo * trans_orig);
348 TopoDS_Shape result = orig.Located (loc_result);
350 ostringstream stream_shape;
351 BRepTools::Write (result, stream_shape);
352 trep = stream_shape.str();
354 // ====================================================== transfo_brep
355 void transfo_brep (string& brep, Matrix* matrice, string& trep)
357 BRep_Builder builder;
358 TopoDS_Shape shape_orig;
361 double a11,a12,a13,a14, a21,a22,a23,a24, a31,a32,a33,a34;
362 matrice->getCoeff (a11,a12,a13,a14, a21,a22,a23,a24, a31,a32,a33,a34);
363 transfo.SetValues (a11,a12,a13,a14, a21,a22,a23,a24, a31,a32,a33,a34,
366 istringstream stream_brep (brep);
367 BRepTools::Read (shape_orig, stream_brep, builder);
369 BRepBuilderAPI_Transform brep_transfo (shape_orig, transfo, Standard_True);
370 TopoDS_Shape result = brep_transfo.Shape();
372 ostringstream stream_shape;
373 BRepTools::Write (result, stream_shape);
374 trep = stream_shape.str();
376 // ====================================================== clear_associations
377 void clear_associations (Edge* edge)
379 edge->clearAssociation();
380 edge->getVertex(V_AMONT)->clearAssociation();
381 edge->getVertex(V_AVAL )->clearAssociation();
383 // ====================================================== set_debug_asso
384 void set_debug_asso (bool boule)
388 printf (" ... Traces actives dans HexAssoElements_asso.cxx\n");
390 // ====================================================== clean_brep
391 void clean_brep (string& brep)
394 BRep_Builder builder;
395 istringstream stream_brep (brep);
397 BRepTools::Read (shape, stream_brep, builder);
398 BRepTools::Clean (shape);
400 ostringstream stream_shape;
401 BRepTools::Write (shape, stream_shape);
402 brep = stream_shape.str();