Salome HOME
caabd5943ef316527a632199133661239c85107e
[modules/hexablock.git] / src / HEXABLOCK / HexVertexShape.cxx
1
2 // C++ : Gestion des soous-shapes
3
4 // Copyright (C) 2009-2023  CEA, EDF
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, or (at your option) any later version.
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 "HexVertexShape.hxx"
24 #include "HexNewShape.hxx"
25 #include "HexXmlWriter.hxx"
26
27 #include <TopoDS.hxx>
28 #include <TopoDS_Vertex.hxx>
29 #include <BRepTools.hxx>
30 #include <BRep_Builder.hxx>
31 #include <BRepBuilderAPI_MakeVertex.hxx>
32 #include <gp_Pnt.hxx>
33
34 BEGIN_NAMESPACE_HEXA
35
36 // static bool db = on_debug ();  // == getenv ("HEXA_DB") > 0
37
38 // ====================================================== Constructeur
39 VertexShape::VertexShape (NewShape* dad, int id)
40          : SubShape  (dad, id, 0)
41 {
42    free_point      = false;
43    maj_coords      = true;
44    ss_coord[dir_x] = ss_coord[dir_y]  = ss_coord[dir_z] = 0;
45
46                                // Les coordonnées
47    updateCoords ();
48 }
49 // ====================================================== Constructeur bis*
50 VertexShape::VertexShape (NewShape* dad, int id, double* point)
51          : SubShape  (dad, id, 0)
52 {
53    free_point      = true;
54    maj_coords      = false;
55    maj_shape       = false;
56    for (int nc=dir_x ; nc<=dir_z ; ++nc)
57         ss_coord[nc] = point[nc];
58 }
59 // ====================================================== updateCoords
60 void VertexShape::updateCoords ()
61 {
62    if (free_point)
63       return;
64    if (maj_shape)
65        updateShape ();
66
67    maj_coords = false;
68    TopoDS_Vertex gver = TopoDS::Vertex (geo_shape);
69    gp_Pnt      gpoint = BRep_Tool::Pnt (gver);
70
71    ss_coord [dir_x]   = gpoint.X();
72    ss_coord [dir_y]   = gpoint.Y();
73    ss_coord [dir_z]   = gpoint.Z();
74 }
75 // ====================================================== getCoords
76 void VertexShape::getCoords (double& px, double& py, double& pz)
77 {
78    if (maj_coords)
79        updateCoords ();
80
81    px = ss_coord[dir_x];
82    py = ss_coord[dir_y];
83    pz = ss_coord[dir_z];
84 }
85 #if 0
86 // ====================================================== getShape
87 const TopoDS_Shape& VertexShape::getShape()
88 {
89     if (geo_shape.IsNull() && ss_parent != NULL &&
90             ss_parent->getOrigin() == SH_CLOUD)
91     {
92         double x, y, z;
93         getCoords(x, y, z);
94         gp_Pnt pnt(x, y, z);
95         geo_shape = BRepBuilderAPI_MakeVertex(pnt);
96     }
97
98     return SubShape::getShape ();
99 }
100 #endif
101 // ====================================================== addAssociation
102 void VertexShape::addAssociation (Vertex* elt)
103 {
104    tab_assoc.push_back (elt);
105    is_associated = true ;
106 }
107 // ====================================================== getAssociation
108 Vertex* VertexShape::getAssociation (int nro)
109 {
110    if (nro>0 && nro < (int)tab_assoc.size())
111       return tab_assoc[nro];
112    else
113       return NULL;
114 }
115 // ====================================================== definedBy 
116 bool VertexShape::definedBy (double point[])
117 {
118    if (maj_coords)
119        updateCoords ();
120
121    const double Epsilon2 = 1e-4;
122    bool   rep = same_coords (point, ss_coord, Epsilon2);
123    return rep; 
124 }
125 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126 // ====================================================== saveXml
127 void VertexShape::saveXml (XmlWriter* xml)
128 {
129    char coord[80];
130    sprintf (coord, "%g %g %g", ss_coord[dir_x], ss_coord[dir_y],
131                                                 ss_coord[dir_z]);
132
133    xml->openMark     ("Vertex");
134    xml->addAttribute ("subid", sub_ident);
135    xml->addAttribute ("coord", coord);
136    xml->closeMark ();
137 }
138 END_NAMESPACE_HEXA