2 // C++ : Gestion des aretes
4 // Copyright (C) 2009-2019 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
22 #include "HexEdge.hxx"
23 #include "HexVertex.hxx"
24 #include "HexQuad.hxx"
26 #include "HexPropagation.hxx"
27 #include "HexXmlWriter.hxx"
28 #include "HexNewShape.hxx"
29 #include "HexAssoEdge.hxx"
30 #include "HexVertexShape.hxx"
32 static int niveau = 0;
36 static bool db = on_debug();
38 void geom_dump_asso (Edge* edge);
40 // ======================================================== Constructeur
41 Edge::Edge (Vertex* va, Vertex* vb)
42 : EltBase (va->dad(), EL_EDGE)
44 e_vertex [V_AMONT] = va;
45 e_vertex [V_AVAL ] = vb;
54 else if (BadElement (va) || BadElement (vb))
66 el_root->addEdge (this);
69 // ======================================================== Constructeur 2
70 Edge::Edge (Edge* other)
71 : EltBase (other->dad(), EL_EDGE)
73 e_vertex [V_AMONT] = e_vertex [V_AVAL ] = NULL;
74 if (BadElement (other))
83 el_root->addEdge (this);
85 // ======================================================== majReferences
86 void Edge::majReferences ()
88 e_vertex [V_AMONT]->addParent (this);
89 e_vertex [V_AVAL ]->addParent (this);
91 // ======================================================== anaMerge
92 int Edge::anaMerge (Vertex* orig, Vertex* tv1[])
96 if (orig == e_vertex [V_AMONT])
97 tv1 [1] = e_vertex[V_AVAL];
98 else if (orig == e_vertex [V_AVAL])
99 tv1 [1] = e_vertex[V_AMONT];
105 // ========================================================= propager
106 void Edge::propager (Propagation* prop, int groupe, int sens)
108 setPropag (groupe, sens>0);
109 prop->addEdge (this);
112 int nbquads = getNbrParents ();
113 for (int nq=0 ; nq<nbquads ; nq++)
115 Quad* quad = getParent (nq);
116 if (quad!=NULL && quad->hasParents())
120 printf ("Prop : niv=%d edge=", niveau);
122 printf ("parent=%d quad=", nq);
123 quad->printName ("\n");
128 Edge* arete = quad->getOpposEdge (this, meme);
129 if (arete != NULL && arete->getPropag () < 0)
130 arete->propager (prop, groupe, meme*sens);
135 // ========================================================= setPropag
136 void Edge::setPropag (int nro, bool sens)
143 int prems = sens ? 0 : 1;
144 Vertex* v1 = getVertex ( prems);
145 Vertex* v2 = getVertex (1-prems);
147 std::cout << " setPropag " << el_name
149 << " = (" << v1->getName() << ", " << v2->getName()
150 << ") = (" << v2->getX() - v1->getX()
151 << ", " << v2->getY() - v1->getY()
152 << ", " << v2->getZ() - v1->getZ()
155 // ========================================================= getParent
156 Quad* Edge::getParent (int nro)
158 return static_cast <Quad*> (getFather (nro));
160 // ========================================================= saveXml
161 void Edge::saveXml (XmlWriter* xml)
164 std::string vertices = e_vertex [V_AMONT]->getName(buffer);
166 vertices += e_vertex [V_AVAL ]->getName(buffer);
168 xml->openMark ("Edge");
169 xml->addAttribute ("id", getName (buffer));
170 xml->addAttribute ("vertices", vertices);
172 xml->addAttribute ("name", el_name);
175 int nbass = tab_assoc.size();
176 for (int nro=0 ; nro<nbass ; nro++)
177 if (tab_assoc[nro] != NULL)
178 tab_assoc[nro]->saveXml (xml);
180 // ======================================================== replaceVertex
181 void Edge::replaceVertex (Vertex* old, Vertex* par)
183 for (int nro=0 ; nro<QUAD4 ; nro++)
185 if (e_vertex[nro]==old)
192 printf (" [%d], ", nro);
193 old->printName (" est remplace par ");
194 par->printName ("\n");
199 // ======================================================== dump
205 printf ("*** deleted ***)\n");
209 e_vertex[V_AMONT]->printName(", ");
210 e_vertex[V_AVAL] ->printName(")");
213 char signe = e_way ? '+' : '-';
214 printf (", Prop= %c%d", signe, e_propag);
219 // ======================================================== dumpAsso
220 void Edge::dumpAsso ()
224 printName(" = *** deleted **\n");
228 geom_dump_asso (this);
230 // ======================================================== dumpPlus
231 void Edge::dumpPlus ()
234 for (int nro=0 ; nro < V_TWO ; nro++)
236 Vertex* pv = e_vertex[nro];
241 printf (" (%g, %g, %g)\n", pv->getX(), pv->getY(), pv->getZ());
249 // ======================================================== makeDefinition
250 std::string Edge::makeDefinition ()
252 std::string definition = el_name;
254 definition += " = (";
255 definition += e_vertex [V_AMONT]->getName();
257 definition += e_vertex [V_AVAL]->getName();
262 // ===================================================== addAssociation
263 int Edge::addAssociation (EdgeShape* gline, double deb, double fin)
268 gline->addAssociation (this);
269 AssoEdge* asso = new AssoEdge (gline, deb, fin);
270 tab_assoc.push_back (asso);
274 std::cout << " Edge " << el_name
275 << " = (" << e_vertex[V_AMONT]->getName()
276 << " , " << e_vertex[V_AVAL ]->getName()
277 << ") addAssociation " << gline->getName ()
278 << " (" << deb << ", " << fin << ")"
280 PutCoord (asso->getOrigin ());
281 PutCoord (asso->getExtrem ());
283 is_associated = true;
286 // ========================================================== addAssociation
287 int Edge::addAssociation (NewShape* geom, int subid, double deb, double fin)
291 if (el_root->debug ())
292 std::cout << " Edge " << el_name << " addAssociation of NULL ignored"
297 EdgeShape* gline = geom->findEdge (subid);
298 int ier = addAssociation (gline, deb, fin);
301 // ================================================== clearAssociation
302 void Edge::clearAssociation ()
304 int nombre = tab_assoc.size ();
305 for (int nro=0 ; nro<nombre ; nro++)
307 delete tab_assoc [nro];
311 is_associated = false;
313 // ================================================== getAssociation
314 AssoEdge* Edge::getAssociation (int nro)
316 if (nro<0 || nro >= (int)tab_assoc.size())
319 return tab_assoc [nro];
321 // =============================================================== getVertex
322 Vertex* Edge::getVertex(int nro)
325 if (nro >=0 && nro < V_TWO && el_status == HOK
326 && e_vertex [nro]->isValid())
327 elt = e_vertex [nro];
331 // =============================================================== index
332 int Edge::index (Vertex* node)
334 return node == NULL ? NOTHING
335 : node == e_vertex[V_AMONT] ? V_AMONT
336 : node == e_vertex[V_AVAL ] ? V_AVAL : NOTHING;
338 // ============================================================= opposedVertex
339 Vertex* Edge::opposedVertex (Vertex* sommet)
341 int nro = index (sommet);
342 return nro<0 ? NULL : e_vertex[1-nro];
344 // ============================================================= commonVertex
345 Vertex* Edge::commonVertex (Edge* other)
347 int nro = inter (other);
348 return nro<0 ? NULL : e_vertex[nro];
350 // ============================================================= commonPoint
351 double* Edge::commonPoint (Edge* other, double point[])
353 Vertex* commun = commonVertex (other);
356 point[dir_x] = point[dir_y] = point[dir_z] = 0;
360 commun->getPoint (point);
363 // =============================================================== inter
364 int Edge::inter (Edge* other)
367 return inter (other, nro);
369 // =============================================================== inter
370 int Edge::inter (Edge* other, int& nother)
372 for (int ni=0 ; ni<V_TWO ; ni++)
373 for (int nj=0 ; nj<V_TWO ; nj++)
374 if (e_vertex[ni] == other->e_vertex[nj])
383 // =============================================================== definedBy
384 bool Edge::definedBy (Vertex* v1, Vertex* v2)
386 bool rep = (v1 == e_vertex[V_AMONT] && v2 == e_vertex[V_AVAL ])
387 || (v1 == e_vertex[V_AVAL ] && v2 == e_vertex[V_AMONT]);
390 // =============================================================== setColor
391 void Edge::setColor (double val)
393 e_vertex [V_AMONT]->setColor (val);
394 e_vertex [V_AVAL ]->setColor (val);
396 // =============================================================== duplicate
397 void Edge::duplicate ()
399 e_clone = new Edge (GetClone (e_vertex [V_AMONT]),
400 GetClone (e_vertex [V_AVAL ]));
402 // e_clone->tab_shapes = tab_shapes;
403 e_clone->tab_assoc = tab_assoc;
405 // =============================================================== getVector
406 double* Edge::getVector (double vecteur[])
409 if (e_vertex[V_AMONT]==NULL || e_vertex[V_AVAL]==NULL)
411 vecteur [dir_x] = vecteur [dir_y] = vecteur [dir_z] = 0;
415 vecteur[dir_x] = e_vertex[V_AVAL]->getX() - e_vertex[V_AMONT]->getX();
416 vecteur[dir_y] = e_vertex[V_AVAL]->getY() - e_vertex[V_AMONT]->getY();
417 vecteur[dir_z] = e_vertex[V_AVAL]->getZ() - e_vertex[V_AMONT]->getZ();
421 // ========================================================== checkAssociation
422 int Edge::checkAssociation ()
424 int nombre = tab_assoc.size();
428 Real3 ver_assoc [V_TWO];
429 int arc [V_TWO], sens [V_TWO];
430 for (int nro=0 ; nro<V_TWO ; ++nro)
432 arc [nro] = sens [nro] = NOTHING;
433 e_vertex[nro]->getAssoCoord (ver_assoc[nro]);
437 for (int nass=0 ; nass<nombre ; ++nass)
439 AssoEdge* asso = tab_assoc[nass];
440 for (int nro = V_AMONT ; nro<=V_AVAL ; ++nro)
442 int rep = asso->onExtremity (ver_assoc[nro]);
445 if (arc[nro] != NOTHING)
447 if (ier==HOK) std::cout << std::endl;
448 std::cout << " Association Edge " << el_name
449 << " : Le vertex " << e_vertex[nro]->getName()
450 << " : Le vertex " << e_vertex[nro]->getName()
451 << " Touche les lignes " << arc [nro]
452 << " et " << nass << std::endl;
461 for (int nro=0 ; nro<V_TWO ; ++nro)
463 if (arc [nro] == NOTHING)
465 if (ier==HOK) std::cout << std::endl;
466 std::cout << " Association Edge " << el_name
467 << " : Le vertex nro " << nro
468 << " = " << e_vertex[nro]->getName()
469 << " est isole" << std::endl;
470 PutCoord (ver_assoc[nro]);
477 std::cout << " ** Controle associations (" << nombre << ") edge " << el_name
478 << " = (" << e_vertex[V_AMONT]->getName()
479 << " , " << e_vertex[V_AVAL ]->getName()
482 for (int nv=0 ; nv<2 ; ++nv)
484 Vertex* node = e_vertex[nv];
485 std::cout << node->getName() << " = (" << node->getX()
486 << ", " << node->getY() << ", " << node->getZ()
487 << ") -> "<< ver_assoc [nv][0] << ", " << ver_assoc [nv][1]
488 << ", " << ver_assoc [nv][2] << ")" << std::endl;
491 for (int nass=0 ; nass<nombre ; ++nass)
493 AssoEdge* asso = tab_assoc[nass];
494 std::cout << " " << nass << " :";
500 // ========================================================== getAssoLen
501 double Edge::getAssoLen ()
503 int nombre = tab_assoc.size();
508 e_vertex [V_AMONT]-> getAssoCoord (p1);
509 e_vertex [V_AVAL ]-> getAssoCoord (p2);
510 longueur = calc_distance (p1, p2);
514 for (int nass=0 ; nass<nombre ; ++nass)
515 longueur += tab_assoc[nass]->length ();
520 // ========================================================= getLength
521 double Edge::getLength ()
524 e_vertex [V_AMONT]-> getAssoCoord (p1);
525 e_vertex [V_AVAL ]-> getAssoCoord (p2);
526 double longueur = calc_distance (p1, p2);
529 // ========================================================= findAssociation
530 int Edge::findAssociation (NewShape* geom)
536 e_vertex [V_AMONT]-> getAssoCoord (point);
537 e_vertex [V_AVAL ]-> getAssoCoord (p2);
539 EdgeShape* gline = geom->findEdge (point, p2);
542 std::cout << " *** FindAssociation " << el_name << std::endl;
543 for (int nv=0 ; nv < V_TWO ; ++nv)
545 e_vertex [nv]-> getAssoCoord (point);
546 VertexShape* shape = geom->findVertex (point);
547 std::cout << " *** Vertex nro " << nv;
550 std::cout << " absent : ";
555 std::cout << " : Subid = " << shape->getIdent() << std::endl;
562 addAssociation (gline, 0, 1);
563 return gline->getIdent();
565 // ========================================================= setAssociation
566 int Edge::setAssociation (NewShape* geom, int subid)
570 if (el_root->debug ())
571 std::cout << " Edge " << el_name << " addAssociation of NULL ignored"
576 EdgeShape* gline = geom->findEdge (subid);
579 if (el_root->debug ())
580 std::cout << " Edge " << el_name << " addAssociation bad subid : "
581 << subid << std::endl;
585 Real3 p1, p2, pa, pb;
586 gline->getCoords (p1, p2);
587 e_vertex [V_AMONT]-> getAssoCoord (pa);
588 e_vertex [V_AVAL ]-> getAssoCoord (pb);
590 double da1 = calc_d2 (pa, p1);
591 double da2 = calc_d2 (pa, p2);
592 double db1 = calc_d2 (pb, p1);
593 double db2 = calc_d2 (pb, p2);
595 std::cout << "setAssociation " << el_name << " :" <<std::endl;
597 if (da2 < da1 && db1 < db2)
599 e_vertex [V_AMONT]->setAssociation (p2);
600 e_vertex [V_AVAL ]->setAssociation (p1);
604 e_vertex [V_AMONT]->setAssociation (p1);
605 e_vertex [V_AVAL ]->setAssociation (p2);
610 int ier = addAssociation (gline, 0, 1);