4 // Copyright (C) 2009-2016 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 "HexVertex.hxx"
24 #include "HexEdge.hxx"
25 #include "HexVector.hxx"
27 #include "HexXmlWriter.hxx"
28 #include "HexDocument.hxx"
29 #include "HexNewShape.hxx"
30 #include "HexVertexShape.hxx"
31 #include "HexKas_functions.hxx"
37 static bool db = on_debug (); // == getenv ("HEXA_DB") > 0
39 // ====================================================== Constructeur
40 Vertex::Vertex (Document* doc, double x, double y, double z)
41 : EltBase (doc, EL_VERTEX)
52 el_root->addVertex (this);
54 // ========================================================= Constructeur bis
55 Vertex::Vertex (Vertex* other)
56 : EltBase (other->dad(), EL_VERTEX)
63 v_scalar = other->v_scalar;
68 v_shape = other->v_shape;
73 gc_x = gc_y = gc_z = 0;
79 // ========================================================= getParent
80 Edge* Vertex::getParent (int nro)
82 return static_cast <Edge*> (getFather (nro));
84 // ========================================================= saveXml
85 void Vertex::saveXml (XmlWriter* xml)
87 char buffer[12], coord[80];
89 sprintf (coord, "%g %g %g", v_x, v_y, v_z);
91 xml->openMark ("Vertex");
92 xml->addAttribute ("id", getName (buffer));
93 xml->addAttribute ("coord", coord);
95 xml->addAttribute ("name", el_name);
100 sprintf (coord, "%g %g %g", gc_x, gc_y, gc_z);
101 v_shape->callXml (xml);
102 xml->addAttribute ("coord", coord);
106 // if (el_assoc!=NULL) xml->addAttribute ("shape", el_assoc->getBrep().c_str());
108 // ========================================================= translate
109 void Vertex::translate (Vector* vecteur, double fact)
111 v_x += fact*vecteur->getDx ();
112 v_y += fact*vecteur->getDy ();
113 v_z += fact*vecteur->getDz ();
115 // ========================================================= createMiddle
116 Vertex* Vertex::createMiddle (Vertex* left, Vertex* right)
118 Vertex* milieu = new Vertex (left);
120 milieu->v_x = (left->v_x + right->v_x) / 2;
121 milieu->v_y = (left->v_y + right->v_y) / 2;
122 milieu->v_z = (left->v_z + right->v_z) / 2;
126 // ========================================================= setAssociation
127 int Vertex::setAssociation (VertexShape* forme)
132 forme->addAssociation (this);
133 forme->getCoords (gc_x, gc_y, gc_z);
136 if (db) cout << " Vertex " << el_name
137 << " setAssociation-> " << forme->getName ()
138 << " = (" << gc_x << ", " << gc_y << ", " << gc_z << ") \n" ;
140 is_associated = true;
143 // ========================================================= setAssociation
144 int Vertex::setAssociation (NewShape* geom, int subid)
149 VertexShape* shape = geom->findVertex (subid);
153 int ier = setAssociation (shape);
156 // ========================================================= setAssociation
157 int Vertex::setAssociation (double* point)
159 NewShape* cloud = el_root->getCloud();
161 int subid = cloud->addPoint (point);
162 int ier = setAssociation (cloud, subid);
165 // ========================================================= setAssociation
166 int Vertex::setAssociation (double px, double py, double pz)
168 Real3 point = { px, py, pz };
169 int ier = setAssociation (point);
172 // ========================================================= clearAssociation
173 void Vertex::clearAssociation ()
176 is_associated = false;
178 // ========================================================= getAssoCoord
179 void Vertex::getAssoCoord (double &px, double &py, double &pz)
194 // ========================================================= getAssoCoord
195 void Vertex::getAssoCoord (double* point)
197 getAssoCoord (point[dir_x], point[dir_y], point[dir_z]);
199 // ===================================================== getCoord
200 double Vertex::getCoord (int dir)
205 case dir_x : val = v_x;
207 case dir_y : val = v_y;
209 case dir_z : val = v_z;
214 // ========================================================= dump
220 printf ("(*** deleted ***)\n");
224 printf ("(%g, %g, %g)", v_x,v_y,v_z);
227 // ========================================================= setCoord
228 void Vertex::setCoord (double x, double y, double z)
234 // ========================================================= isin
235 bool Vertex::isin (double xmin, double xmax, double ymin, double ymax,
236 double zmin, double zmax)
238 bool rep = v_x >= xmin && v_x <= xmax
239 && v_y >= ymin && v_y <= ymax
240 && v_z >= zmin && v_z <= zmax;
243 // ========================================================= getPoint
244 double* Vertex::getPoint (double point[])
251 // ========================================================= duplicate
252 void Vertex::duplicate (Document* cible)
254 v_clone = new Vertex (cible, v_x, v_y, v_z);
255 v_clone->v_scalar = v_scalar;
257 // ========================================================= definedBy
258 bool Vertex::definedBy (double px, double py, double pz, double eps2)
260 double dist2 = carre (v_x-px) + carre (v_y-py) + carre (v_z-pz);
263 // ========================================================= dist2
264 double Vertex::dist2 (Vertex* other)
266 if (BadElement (other))
269 double dist = carre (v_x-other->v_x) + carre (v_y-other->v_y)
270 + carre (v_z-other->v_z);
273 // ========================================================= anaVertices
274 void Vertex::anaVertices (Vertices& cont, double pmin[], double pmax[],
278 int nbre = cont.size();
281 for (int nc=0 ; nc<DIM3 ; nc++)
282 pmin [nc] = pmax[nc] = center[nc] = 0;
286 cont[0]->getPoint (pmin);
287 cont[0]->getPoint (pmax);
288 for (int nro=1 ; nro<nbre ; ++nro)
290 cont[nro]->getPoint (point);
291 for (int nc=0 ; nc<DIM3 ; nc++)
293 pmin [nc] = std::min (pmin[nc], point[nc]);
294 pmax [nc] = std::max (pmax[nc], point[nc]);
298 for (int nc=0 ; nc<DIM3 ; nc++)
299 center [nc] = (pmin[nc] + pmax[nc])/2;