2 // C++ : Gestion des soous-shapes
4 // Copyright (C) 2009-2013 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/
21 // or email : webmaster.salome@opencascade.com
24 #include "HexVertexShape.hxx"
25 #include "HexNewShape.hxx"
26 #include "HexXmlWriter.hxx"
29 #include <TopoDS_Vertex.hxx>
30 #include <BRepTools.hxx>
31 #include <BRep_Builder.hxx>
32 #include <BRepBuilderAPI_MakeVertex.hxx>
37 // static bool db = on_debug (); // == getenv ("HEXA_DB") > 0
39 // ====================================================== Constructeur
40 VertexShape::VertexShape (NewShape* dad, int id)
41 : SubShape (dad, id, 0)
45 ss_coord[dir_x] = ss_coord[dir_y] = ss_coord[dir_z] = 0;
50 // ====================================================== Constructeur bis*
51 VertexShape::VertexShape (NewShape* dad, int id, double* point)
52 : SubShape (dad, id, 0)
57 for (int nc=dir_x ; nc<=dir_z ; ++nc)
58 ss_coord[nc] = point[nc];
60 // ====================================================== updateCoords
61 void VertexShape::updateCoords ()
69 TopoDS_Vertex gver = TopoDS::Vertex (geo_shape);
70 gp_Pnt gpoint = BRep_Tool::Pnt (gver);
72 ss_coord [dir_x] = gpoint.X();
73 ss_coord [dir_y] = gpoint.Y();
74 ss_coord [dir_z] = gpoint.Z();
76 // ====================================================== getCoords
77 void VertexShape::getCoords (double& px, double& py, double& pz)
87 // ====================================================== getShape
88 const TopoDS_Shape& VertexShape::getShape()
90 if (geo_shape.IsNull() && ss_parent != NULL &&
91 ss_parent->getOrigin() == SH_CLOUD)
96 geo_shape = BRepBuilderAPI_MakeVertex(pnt);
99 return SubShape::getShape ();
102 // ====================================================== addAssociation
103 void VertexShape::addAssociation (Vertex* elt)
105 tab_assoc.push_back (elt);
106 is_associated = true ;
108 // ====================================================== getAssociation
109 Vertex* VertexShape::getAssociation (int nro)
111 if (nro>0 && nro < (int)tab_assoc.size())
112 return tab_assoc[nro];
116 // ====================================================== definedBy
117 bool VertexShape::definedBy (double point[])
122 const double Epsilon2 = 1e-4;
123 bool rep = same_coords (point, ss_coord, Epsilon2);
126 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127 // ====================================================== saveXml
128 void VertexShape::saveXml (XmlWriter* xml)
131 sprintf (coord, "%g %g %g", ss_coord[dir_x], ss_coord[dir_y],
134 xml->openMark ("Vertex");
135 xml->addAttribute ("subid", sub_ident);
136 xml->addAttribute ("coord", coord);