]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCK/HexKas_functions.cxx
Salome HOME
Merge from V6_main 01/04/2013
[modules/hexablock.git] / src / HEXABLOCK / HexKas_functions.cxx
1 //
2 // CC++ : Fonctions Interface Cascade
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 #include "HexKas_functions.hxx"
24
25 #ifndef NO_CASCADE
26
27 #include <TopoDS.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopoDS_Vertex.hxx>
30
31 #include <BRep_Builder.hxx>
32 #include <BRepTools.hxx>
33
34 #include <gp_Pnt.hxx>
35
36 BEGIN_NAMESPACE_HEXA
37
38 // ====================================================== same_coords
39 bool same_coords (gp_Pnt& pa, gp_Pnt& pb, double epsilon)
40 {
41    double d2 = carre (pb.X()-pa.X()) + carre (pb.Y()-pa.Y())
42                                      + carre (pb.Z()-pa.Z()) ;
43    return d2 < epsilon;
44 }
45 // ====================================================== save_brep
46 void save_brep (cpchar nom, string brep, int& compteur)
47 {
48     char buff[8];
49     compteur ++;
50     sprintf (buff ,"%d", compteur);
51
52     string name (nom);
53     name += buff;
54     name += ".brep";
55     FILE*    fic = fopen (name.c_str(), "w");
56     fprintf (fic, "%s\n", brep.c_str());
57     fclose  (fic);
58 }
59 // ====================================================== geom_make_brep
60 void geom_make_brep (TopoDS_Shape& shape, string& brep)
61 {
62    ostringstream  stream_shape;
63    BRepTools::Write (shape, stream_shape);
64    brep = stream_shape.str();
65 }
66 // ====================================================== geom_brep2shape (F)
67 TopoDS_Shape geom_brep2shape (rcstring brep)
68 {
69    TopoDS_Shape topo;
70    istringstream streamBrep(brep);
71    BRep_Builder aBuilder;
72    BRepTools::Read (topo, streamBrep, aBuilder);
73    return topo;
74 }
75 // ====================================================== geom_brep2shape
76 int geom_brep2shape (rcstring brep, TopoDS_Shape& shape)
77 {
78    istringstream streamBrep(brep);
79    BRep_Builder  aBuilder;
80    BRepTools::Read (shape, streamBrep, aBuilder);
81    return HOK;
82 }
83 // ====================================================== geom_brep2point
84 int geom_brep2point (rcstring brep, double& px, double& py, double& pz)
85 {
86    TopoDS_Shape topo;
87    geom_brep2shape (brep, topo);
88
89    if (topo.ShapeType() != TopAbs_VERTEX)
90       return HERR;
91
92    TopoDS_Vertex g_vertex = TopoDS::Vertex (topo);
93    gp_Pnt        g_point  = BRep_Tool::Pnt( g_vertex );
94
95    px = g_point.X();
96    py = g_point.Y();
97    pz = g_point.Z();
98    return HOK;
99 }
100 END_NAMESPACE_HEXA
101
102 #else // *************************************************** NO_CASCADE
103
104 BEGIN_NAMESPACE_HEXA
105 int geom_brep2point (rcstring b, double& x, double& y, double& z) {return HOK;}
106 int geom_brep2shape (rcstring brep, TopoDS_Shape& shape) {return HOK ; }
107 TopoDS_Shape geom_brep2shape (rcstring brep)             {return O ; }
108 END_NAMESPACE_HEXA
109 #endif