2 // C++ : Gestion des aretes
4 // Copyright (C) 2009-2013 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.
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"
31 static int niveau = 0;
35 static bool db = on_debug();
37 void geom_dump_asso (Edge* edge);
39 // ======================================================== Constructeur
40 Edge::Edge (Vertex* va, Vertex* vb)
41 : EltBase (va->dad(), EL_EDGE)
43 e_vertex [V_AMONT] = va;
44 e_vertex [V_AVAL ] = vb;
53 else if (BadElement (va) || BadElement (vb))
66 // ======================================================== Constructeur 2
67 Edge::Edge (Edge* other)
68 : EltBase (other->dad(), EL_EDGE)
70 e_vertex [V_AMONT] = e_vertex [V_AVAL ] = NULL;
71 if (BadElement (other))
79 // ======================================================== majReferences
80 void Edge::majReferences ()
82 e_vertex [V_AMONT]->addParent (this);
83 e_vertex [V_AVAL ]->addParent (this);
85 // ======================================================== anaMerge
86 int Edge::anaMerge (Vertex* orig, Vertex* tv1[])
90 if (orig == e_vertex [V_AMONT])
91 tv1 [1] = e_vertex[V_AVAL];
92 else if (orig == e_vertex [V_AVAL])
93 tv1 [1] = e_vertex[V_AMONT];
99 // ========================================================= propager
100 void Edge::propager (Propagation* prop, int groupe, int sens)
102 setPropag (groupe, sens>0);
103 prop->addEdge (this);
106 int nbquads = getNbrParents ();
107 for (int nq=0 ; nq<nbquads ; nq++)
109 Quad* quad = getParent (nq);
110 if (quad!=NULL && quad->hasParents())
114 printf ("Prop : niv=%d edge=", niveau);
116 printf ("parent=%d quad=", nq);
117 quad->printName ("\n");
122 Edge* arete = quad->getOpposEdge (this, meme);
123 if (arete != NULL && arete->getPropag () < 0)
124 arete->propager (prop, groupe, meme*sens);
129 // ========================================================= getParent
130 Quad* Edge::getParent (int nro)
132 return static_cast <Quad*> (getFather (nro));
134 // ========================================================= saveXml
135 void Edge::saveXml (XmlWriter* xml)
138 string vertices = e_vertex [V_AMONT]->getName(buffer);
140 vertices += e_vertex [V_AVAL ]->getName(buffer);
142 xml->openMark ("Edge");
143 xml->addAttribute ("id", getName (buffer));
144 xml->addAttribute ("vertices", vertices);
146 xml->addAttribute ("name", el_name);
149 int nbass = tab_assoc.size();
150 for (int nro=0 ; nro<nbass ; nro++)
151 if (tab_assoc[nro] != NULL)
152 tab_assoc[nro]->saveXml (xml);
154 // ======================================================== replaceVertex
155 void Edge::replaceVertex (Vertex* old, Vertex* par)
157 for (int nro=0 ; nro<QUAD4 ; nro++)
159 if (e_vertex[nro]==old)
166 printf (" [%d], ", nro);
167 old->printName (" est remplace par ");
168 par->printName ("\n");
173 // ======================================================== dump
179 printf ("*** deleted ***)\n");
183 e_vertex[V_AMONT]->printName(", ");
184 e_vertex[V_AVAL] ->printName(")");
187 char signe = e_way ? '+' : '-';
188 printf (", Prop= %c%d", signe, e_propag);
193 // ======================================================== dumpAsso
194 void Edge::dumpAsso ()
198 printName(" = *** deleted **\n");
202 geom_dump_asso (this);
204 // ======================================================== dumpPlus
205 void Edge::dumpPlus ()
208 for (int nro=0 ; nro < V_TWO ; nro++)
210 Vertex* pv = e_vertex[nro];
215 printf (" (%g, %g, %g)\n", pv->getX(), pv->getY(), pv->getZ());
223 // ======================================================== makeDefinition
224 string Edge::makeDefinition ()
226 string definition = el_name;
228 definition += " = (";
229 definition += e_vertex [V_AMONT]->getName();
231 definition += e_vertex [V_AVAL]->getName();
236 // ========================================================== addAssociation
237 int Edge::addAssociation (EdgeShape* gline, double deb, double fin)
242 gline->addAssociation (this);
243 AssoEdge* asso = new AssoEdge (gline, deb, fin);
244 tab_assoc.push_back (asso);
248 cout << " Edge " << el_name
249 << " = (" << e_vertex[V_AMONT]->getName()
250 << " , " << e_vertex[V_AVAL ]->getName()
251 << ") addAssociation " << gline->getName ()
252 << " (" << deb << ", " << fin << ")"
254 PutCoord (asso->getOrigin ());
255 PutCoord (asso->getExtrem ());
257 is_associated = true;
260 // ========================================================== addAssociation
261 int Edge::addAssociation (NewShape* geom, int subid, double deb, double fin)
265 if (el_root->debug ())
266 cout << " Edge " << el_name << " addAssociation of NULL ignored"
271 EdgeShape* gline = geom->findEdge (subid);
272 int ier = addAssociation (gline, deb, fin);
275 // ========================================================== clearAssociation
276 void Edge::clearAssociation ()
278 int nombre = tab_assoc.size ();
279 for (int nro=0 ; nro<nombre ; nro++)
281 delete tab_assoc [nro];
285 is_associated = false;
287 // ========================================================== getAssociation
288 AssoEdge* Edge::getAssociation (int nro)
290 if (nro<0 || nro >= tab_assoc.size())
293 return tab_assoc [nro];
295 // ========================================================== checkAssociation
296 int Edge::checkAssociation ()
298 int nombre = tab_assoc.size();
302 Real3 ver_assoc [V_TWO];
303 int arc [V_TWO], sens [V_TWO];
304 for (int nro=0 ; nro<V_TWO ; ++nro)
306 arc [nro] = sens [nro] = NOTHING;
307 e_vertex[nro]->getAssoCoord (ver_assoc[nro]);
311 for (int nass=0 ; nass<nombre ; ++nass)
313 AssoEdge* asso = tab_assoc[nass];
314 for (int nro = V_AMONT ; nro<=V_AVAL ; ++nro)
316 int rep = asso->onExtremity (ver_assoc[nro]);
319 if (arc[nro] != NOTHING)
321 if (ier==HOK) cout << endl;
322 cout << " Association Edge " << el_name
323 << " : Le vertex " << e_vertex[nro]->getName()
324 << " : Le vertex " << e_vertex[nro]->getName()
325 << " Touche les lignes " << arc [nro]
326 << " et " << nass << endl;
335 for (int nro=0 ; nro<V_TWO ; ++nro)
337 if (arc [nro] == NOTHING)
339 if (ier==HOK) cout << endl;
340 cout << " Association Edge " << el_name
341 << " : Le vertex nro " << nro
342 << " = " << e_vertex[nro]->getName()
343 << " est isole" << endl;
344 PutCoord (ver_assoc[nro]);
351 cout << " ** Controle associations (" << nombre << ") edge " << el_name
352 << " = (" << e_vertex[V_AMONT]->getName()
353 << " , " << e_vertex[V_AVAL ]->getName()
356 for (int nv=0 ; nv<2 ; ++nv)
358 Vertex* node = e_vertex[nv];
359 cout << node->getName() << " = (" << node->getX()
360 << ", " << node->getY() << ", " << node->getZ()
361 << ") -> "<< ver_assoc [nv][0] << ", " << ver_assoc [nv][1]
362 << ", " << ver_assoc [nv][2] << ")" << endl;
365 for (int nass=0 ; nass<nombre ; ++nass)
367 AssoEdge* asso = tab_assoc[nass];
368 cout << " " << nass << " :";