Salome HOME
8226f8bee0c8829b91f72487912f6ac6b672f379
[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 "HexDocument.hxx"
29 #include "HexOldShape.hxx"
30 #include "HexNewShape.hxx"
31 #include "HexVertexShape.hxx"
32 #include "HexKas_functions.hxx"
33
34 BEGIN_NAMESPACE_HEXA
35
36 static bool db =  on_debug ();  // == getenv ("HEXA_DB") > 0
37
38 // ====================================================== Constructeur
39 Vertex::Vertex  (Document* doc, double x, double y, double z)
40       : EltBase (doc, EL_VERTEX)
41 {
42    gc_x = v_x = x;
43    gc_y = v_y = y;
44    gc_z = v_z = z;
45
46    v_shape  = NULL;
47    v_scalar = 0;
48    v_clone  = NULL;
49 }
50 // ========================================================= getParent
51 Edge* Vertex::getParent  (int nro)
52 {
53    return static_cast <Edge*> (getFather (nro));
54 }
55 // ========================================================= saveXml
56 void Vertex::saveXml  (XmlWriter* xml)
57 {
58    char buffer[12], coord[80];
59
60    sprintf (coord, "%g %g %g", v_x, v_y, v_z);
61
62    xml->openMark     ("Vertex");
63    xml->addAttribute ("id",    getName (buffer));
64    xml->addAttribute ("coord", coord);
65    if (el_name!=buffer)
66        xml->addAttribute ("name", el_name);
67    xml->closeMark ();
68
69    if (v_shape != NULL)
70       {
71       sprintf (coord, "%g %g %g", gc_x, gc_y, gc_z);
72       v_shape->callXml (xml);
73       xml->addAttribute ("coord", coord);
74       xml->closeMark ();
75       }
76
77 // if (el_assoc!=NULL) xml->addAttribute ("shape", el_assoc->getBrep().c_str());
78 }
79 // ========================================================= translate
80 void  Vertex::translate  (Vector* vecteur, double fact)
81 {
82     v_x += fact*vecteur->getDx ();
83     v_y += fact*vecteur->getDy ();
84     v_z += fact*vecteur->getDz ();
85 }
86 // ========================================================= createMiddle
87 Vertex* Vertex::createMiddle  (Vertex* left, Vertex* right)
88 {
89     Vertex* milieu = new Vertex (left);
90
91     milieu->v_x = (left->v_x + right->v_x) / 2;
92     milieu->v_y = (left->v_y + right->v_y) / 2;
93     milieu->v_z = (left->v_z + right->v_z) / 2;
94
95     return milieu;
96 }
97 // ========================================================= setAssociation
98 int Vertex::setAssociation (VertexShape* forme)
99 {
100    if (forme==NULL)
101       return HERR;
102
103    forme->addAssociation (this);
104    forme->getCoords (gc_x, gc_y, gc_z);
105    v_shape = forme;
106
107    if (db) cout << " Vertex "           << el_name
108                 << " setAssociation-> " << forme->getName ()
109                 << " = (" << gc_x << ", " << gc_y << ", " << gc_z << ") \n" ;
110
111    is_associated = true;
112    return HOK;
113 }
114 // ========================================================= setAssociation
115 int Vertex::setAssociation (NewShape* geom, int subid)
116 {
117    if (geom==NULL)
118       return HERR;
119
120    VertexShape* shape = geom->findVertex (subid);
121    if (shape==NULL)
122       return HERR;
123
124    int ier = setAssociation (shape);
125    return ier;
126 }
127 // ========================================================= setAssociation
128 int Vertex::setAssociation (double* point)
129 {
130    NewShape* cloud = el_root->getCloud();
131
132    int subid = cloud->addPoint (point);
133    int ier   = setAssociation  (cloud, subid);
134    return ier;
135 }
136 // ========================================================= setAssociation
137 int Vertex::setAssociation (double px, double py, double pz)
138 {
139    Real3 point = { px, py, pz };
140    int   ier   = setAssociation (point);
141    return ier;
142 }
143 // ========================================================= clearAssociation
144 void Vertex::clearAssociation ()
145 {
146    v_shape = NULL;
147    is_associated = false;
148 }
149 // ========================================================= getAssoCoord
150 void Vertex::getAssoCoord (double &px, double &py, double &pz)
151 {
152    if (is_associated)
153       {
154       px = gc_x;
155       py = gc_y;
156       pz = gc_z;
157       }
158    else
159       {
160       px = v_x;
161       py = v_y;
162       pz = v_z;
163       }
164 }
165 // ========================================================= getAssoCoord
166 void Vertex::getAssoCoord (double* point)
167 {
168    getAssoCoord (point[dir_x], point[dir_y], point[dir_z]);
169 }
170 END_NAMESPACE_HEXA