2 // C++ : Gestion des soous-shapes
4 // Copyright (C) 2009-2019 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, or (at your option) any later version.
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 "HexVertexShape.hxx"
24 #include "HexNewShape.hxx"
25 #include "HexXmlWriter.hxx"
28 #include <TopoDS_Vertex.hxx>
29 #include <BRepTools.hxx>
30 #include <BRep_Builder.hxx>
31 #include <BRepBuilderAPI_MakeVertex.hxx>
36 // static bool db = on_debug (); // == getenv ("HEXA_DB") > 0
38 // ====================================================== Constructeur
39 VertexShape::VertexShape (NewShape* dad, int id)
40 : SubShape (dad, id, 0)
44 ss_coord[dir_x] = ss_coord[dir_y] = ss_coord[dir_z] = 0;
49 // ====================================================== Constructeur bis*
50 VertexShape::VertexShape (NewShape* dad, int id, double* point)
51 : SubShape (dad, id, 0)
56 for (int nc=dir_x ; nc<=dir_z ; ++nc)
57 ss_coord[nc] = point[nc];
59 // ====================================================== updateCoords
60 void VertexShape::updateCoords ()
68 TopoDS_Vertex gver = TopoDS::Vertex (geo_shape);
69 gp_Pnt gpoint = BRep_Tool::Pnt (gver);
71 ss_coord [dir_x] = gpoint.X();
72 ss_coord [dir_y] = gpoint.Y();
73 ss_coord [dir_z] = gpoint.Z();
75 // ====================================================== getCoords
76 void VertexShape::getCoords (double& px, double& py, double& pz)
86 // ====================================================== getShape
87 const TopoDS_Shape& VertexShape::getShape()
89 if (geo_shape.IsNull() && ss_parent != NULL &&
90 ss_parent->getOrigin() == SH_CLOUD)
95 geo_shape = BRepBuilderAPI_MakeVertex(pnt);
98 return SubShape::getShape ();
101 // ====================================================== addAssociation
102 void VertexShape::addAssociation (Vertex* elt)
104 tab_assoc.push_back (elt);
105 is_associated = true ;
107 // ====================================================== getAssociation
108 Vertex* VertexShape::getAssociation (int nro)
110 if (nro>0 && nro < (int)tab_assoc.size())
111 return tab_assoc[nro];
115 // ====================================================== definedBy
116 bool VertexShape::definedBy (double point[])
121 const double Epsilon2 = 1e-4;
122 bool rep = same_coords (point, ss_coord, Epsilon2);
125 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126 // ====================================================== saveXml
127 void VertexShape::saveXml (XmlWriter* xml)
130 sprintf (coord, "%g %g %g", ss_coord[dir_x], ss_coord[dir_y],
133 xml->openMark ("Vertex");
134 xml->addAttribute ("subid", sub_ident);
135 xml->addAttribute ("coord", coord);