Salome HOME
0c6bee6cc286d6cb6bcf3ff91d51ab97f4b0c958
[modules/hexablock.git] / src / HEXABLOCK / HexVertex.cxx
1
2 //  C++ Les noeuds
3
4 // Copyright (C) 2009-2012  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 "HexVertex.hxx"
24 #include "HexEdge.hxx"
25 #include "HexVector.hxx"
26
27 #include "HexXmlWriter.hxx"
28 #include "HexShape.hxx"
29
30 BEGIN_NAMESPACE_HEXA
31
32 // ====================================================== Constructeur
33 Vertex::Vertex  (Document* doc, double x, double y, double z)
34       : EltBase (doc, EL_VERTEX)
35 {
36    gc_x = v_x = x;
37    gc_y = v_y = y;
38    gc_z = v_z = z;
39
40    v_scalar = 0;
41    v_clone  = NULL;
42 }
43 // ========================================================= getParent 
44 Edge* Vertex::getParent  (int nro)
45 {
46    return static_cast <Edge*> (getFather (nro));
47 }
48 // ========================================================= saveXml 
49 void Vertex::saveXml  (XmlWriter* xml)
50 {
51    char buffer[12], coord[80];
52
53    sprintf (coord, "%g %g %g", v_x,v_y,v_z);
54
55    xml->openMark     ("Vertex");
56    xml->addAttribute ("id",    getName (buffer));
57    xml->addAttribute ("coord", coord);
58    if (el_name!=buffer) 
59        xml->addAttribute ("name", el_name);
60    if (el_assoc!=NULL)
61       xml->addAttribute ("shape", el_assoc->getBrep().c_str());
62    xml->closeMark ();
63 }
64 // ========================================================= translate 
65 void  Vertex::translate  (Vector* vecteur, double fact)
66 {
67     v_x += fact*vecteur->getDx ();
68     v_y += fact*vecteur->getDy ();
69     v_z += fact*vecteur->getDz ();
70 }
71 // ========================================================= createMiddle 
72 Vertex* Vertex::createMiddle  (Vertex* left, Vertex* right)
73 {
74     Vertex* milieu = new Vertex (left);
75
76     milieu->v_x = (left->v_x + right->v_x) / 2;
77     milieu->v_y = (left->v_y + right->v_y) / 2;
78     milieu->v_z = (left->v_z + right->v_z) / 2;
79
80     return milieu;
81 }
82 END_NAMESPACE_HEXA