4 // Copyright (C) 2009-2015 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"
35 static bool db = on_debug (); // == getenv ("HEXA_DB") > 0
37 // ====================================================== Constructeur
38 Vertex::Vertex (Document* doc, double x, double y, double z)
39 : EltBase (doc, EL_VERTEX)
50 el_root->addVertex (this);
52 // ========================================================= Constructeur bis
53 Vertex::Vertex (Vertex* other)
54 : EltBase (other->dad(), EL_VERTEX)
61 v_scalar = other->v_scalar;
66 v_shape = other->v_shape;
71 gc_x = gc_y = gc_z = 0;
77 // ========================================================= getParent
78 Edge* Vertex::getParent (int nro)
80 return static_cast <Edge*> (getFather (nro));
82 // ========================================================= saveXml
83 void Vertex::saveXml (XmlWriter* xml)
85 char buffer[12], coord[80];
87 sprintf (coord, "%g %g %g", v_x, v_y, v_z);
89 xml->openMark ("Vertex");
90 xml->addAttribute ("id", getName (buffer));
91 xml->addAttribute ("coord", coord);
93 xml->addAttribute ("name", el_name);
98 sprintf (coord, "%g %g %g", gc_x, gc_y, gc_z);
99 v_shape->callXml (xml);
100 xml->addAttribute ("coord", coord);
104 // if (el_assoc!=NULL) xml->addAttribute ("shape", el_assoc->getBrep().c_str());
106 // ========================================================= translate
107 void Vertex::translate (Vector* vecteur, double fact)
109 v_x += fact*vecteur->getDx ();
110 v_y += fact*vecteur->getDy ();
111 v_z += fact*vecteur->getDz ();
113 // ========================================================= createMiddle
114 Vertex* Vertex::createMiddle (Vertex* left, Vertex* right)
116 Vertex* milieu = new Vertex (left);
118 milieu->v_x = (left->v_x + right->v_x) / 2;
119 milieu->v_y = (left->v_y + right->v_y) / 2;
120 milieu->v_z = (left->v_z + right->v_z) / 2;
124 // ========================================================= setAssociation
125 int Vertex::setAssociation (VertexShape* forme)
130 forme->addAssociation (this);
131 forme->getCoords (gc_x, gc_y, gc_z);
134 if (db) cout << " Vertex " << el_name
135 << " setAssociation-> " << forme->getName ()
136 << " = (" << gc_x << ", " << gc_y << ", " << gc_z << ") \n" ;
138 is_associated = true;
141 // ========================================================= setAssociation
142 int Vertex::setAssociation (NewShape* geom, int subid)
147 VertexShape* shape = geom->findVertex (subid);
151 int ier = setAssociation (shape);
154 // ========================================================= setAssociation
155 int Vertex::setAssociation (double* point)
157 NewShape* cloud = el_root->getCloud();
159 int subid = cloud->addPoint (point);
160 int ier = setAssociation (cloud, subid);
163 // ========================================================= setAssociation
164 int Vertex::setAssociation (double px, double py, double pz)
166 Real3 point = { px, py, pz };
167 int ier = setAssociation (point);
170 // ========================================================= clearAssociation
171 void Vertex::clearAssociation ()
174 is_associated = false;
176 // ========================================================= getAssoCoord
177 void Vertex::getAssoCoord (double &px, double &py, double &pz)
192 // ========================================================= getAssoCoord
193 void Vertex::getAssoCoord (double* point)
195 getAssoCoord (point[dir_x], point[dir_y], point[dir_z]);
197 // ===================================================== getCoord
198 double Vertex::getCoord (int dir)
203 case dir_x : val = v_x;
205 case dir_y : val = v_y;
207 case dir_z : val = v_z;
212 // ========================================================= dump
218 printf ("(*** deleted ***)\n");
222 printf ("(%g, %g, %g)", v_x,v_y,v_z);
225 // ========================================================= setCoord
226 void Vertex::setCoord (double x, double y, double z)
232 // ========================================================= isin
233 bool Vertex::isin (double xmin, double xmax, double ymin, double ymax,
234 double zmin, double zmax)
236 bool rep = v_x >= xmin && v_x <= xmax
237 && v_y >= ymin && v_y <= ymax
238 && v_z >= zmin && v_z <= zmax;
241 // ========================================================= getPoint
242 double* Vertex::getPoint (double point[])
249 // ========================================================= duplicate
250 void Vertex::duplicate (Document* cible)
252 v_clone = new Vertex (cible, v_x, v_y, v_z);
253 v_clone->v_scalar = v_scalar;
255 // ========================================================= definedBy
256 bool Vertex::definedBy (double px, double py, double pz, double eps2)
258 double dist2 = carre (v_x-px) + carre (v_y-py) + carre (v_z-pz);
261 // ========================================================= dist2
262 double Vertex::dist2 (Vertex* other)
264 if (BadElement (other))
267 double dist = carre (v_x-other->v_x) + carre (v_y-other->v_y)
268 + carre (v_z-other->v_z);
271 // ========================================================= anaVertices
272 void Vertex::anaVertices (Vertices& cont, double pmin[], double pmax[],
276 int nbre = cont.size();
279 for (int nc=0 ; nc<DIM3 ; nc++)
280 pmin [nc] = pmax[nc] = center[nc] = 0;
284 cont[0]->getPoint (pmin);
285 cont[0]->getPoint (pmax);
286 for (int nro=1 ; nro<nbre ; ++nro)
288 cont[nro]->getPoint (point);
289 for (int nc=0 ; nc<DIM3 ; nc++)
291 pmin [nc] = std::min (pmin[nc], point[nc]);
292 pmax [nc] = std::max (pmax[nc], point[nc]);
296 for (int nc=0 ; nc<DIM3 ; nc++)
297 center [nc] = (pmin[nc] + pmax[nc])/2;