Salome HOME
Merge from V6_main 01/04/2013
[modules/hexablock.git] / src / HEXABLOCK / HexVertexShape.cxx
1
2 // C++ : Gestion des soous-shapes
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 "HexVertexShape.hxx"
24 #include "HexXmlWriter.hxx"
25
26 #ifndef NO_CASCADE
27
28 #include <TopoDS.hxx>
29 #include <TopoDS_Vertex.hxx>
30 #include <BRepTools.hxx>
31 #include <BRep_Builder.hxx>
32 #include <BRepBuilderAPI_MakeVertex.hxx>
33 #include <gp_Pnt.hxx>
34
35 BEGIN_NAMESPACE_HEXA
36
37 // static bool db = on_debug ();  // == getenv ("HEXA_DB") > 0
38
39 // ====================================================== Constructeur
40 VertexShape::VertexShape (NewShape* dad, int id)
41          : SubShape  (dad, id, 0)
42 {
43    free_point      = false;
44    maj_coords      = true;
45    ss_coord[dir_x] = ss_coord[dir_y]  = ss_coord[dir_z] = 0;
46
47                                // Les coordonnées
48    updateCoords ();
49 }
50 // ====================================================== Constructeur bis*
51 VertexShape::VertexShape (NewShape* dad, int id, double* point)
52          : SubShape  (dad, id, 0)
53 {
54    free_point      = true;
55    maj_coords      = false;
56    maj_shape       = false;
57    for (int nc=dir_x ; nc<=dir_z ; ++nc)
58         ss_coord[nc] = point[nc];
59 }
60 // ====================================================== updateCoords
61 void VertexShape::updateCoords ()
62 {
63    if (free_point)
64       return;
65    if (maj_shape)
66        updateShape ();
67
68    maj_coords = false;
69    TopoDS_Vertex gver = TopoDS::Vertex (geo_shape);
70    gp_Pnt      gpoint = BRep_Tool::Pnt (gver);
71
72    ss_coord [dir_x]   = gpoint.X();
73    ss_coord [dir_y]   = gpoint.Y();
74    ss_coord [dir_z]   = gpoint.Z();
75 }
76 // ====================================================== getCoords
77 void VertexShape::getCoords (double& px, double& py, double& pz)
78 {
79    if (maj_coords)
80        updateCoords ();
81
82    px = ss_coord[dir_x];
83    py = ss_coord[dir_y];
84    pz = ss_coord[dir_z];
85 }
86 // ====================================================== addAssociation
87 void VertexShape::addAssociation (Vertex* elt)
88 {
89    tab_assoc.push_back (elt);
90    is_associated = true ;
91 }
92 // ====================================================== getAssociation
93 Vertex* VertexShape::getAssociation (int nro)
94 {
95    if (nro>0 && nro<tab_assoc.size())
96       return tab_assoc[nro];
97    else
98       return NULL;
99 }
100 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101 // ====================================================== saveXml
102 void VertexShape::saveXml (XmlWriter* xml)
103 {
104    char coord[80];
105    sprintf (coord, "%g %g %g", ss_coord[dir_x], ss_coord[dir_y],
106                                                 ss_coord[dir_z]);
107
108    xml->openMark     ("Vertex");
109    xml->addAttribute ("subid", sub_ident);
110    xml->addAttribute ("coord", coord);
111    xml->closeMark ();
112 }
113 END_NAMESPACE_HEXA
114 #endif