2 // C++ : Gestion des aretes
4 // Copyright (C) 2009-2012 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/
21 // or email : webmaster.salome@opencascade.com
23 #include "HexEdge.hxx"
24 #include "HexVertex.hxx"
25 #include "HexQuad.hxx"
27 #include "HexPropagation.hxx"
28 #include "HexXmlWriter.hxx"
29 #include "HexNewShape.hxx"
30 #include "HexAssoEdge.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))
67 // ======================================================== Constructeur 2
68 Edge::Edge (Edge* other)
69 : EltBase (other->dad(), EL_EDGE)
71 e_vertex [V_AMONT] = e_vertex [V_AVAL ] = NULL;
72 if (BadElement (other))
80 // ======================================================== majReferences
81 void Edge::majReferences ()
83 e_vertex [V_AMONT]->addParent (this);
84 e_vertex [V_AVAL ]->addParent (this);
86 // ======================================================== anaMerge
87 int Edge::anaMerge (Vertex* orig, Vertex* tv1[])
91 if (orig == e_vertex [V_AMONT])
92 tv1 [1] = e_vertex[V_AVAL];
93 else if (orig == e_vertex [V_AVAL])
94 tv1 [1] = e_vertex[V_AMONT];
100 // ========================================================= propager
101 void Edge::propager (Propagation* prop, int groupe, int sens)
103 setPropag (groupe, sens>0);
104 prop->addEdge (this);
107 int nbquads = getNbrParents ();
108 for (int nq=0 ; nq<nbquads ; nq++)
110 Quad* quad = getParent (nq);
111 if (quad!=NULL && quad->hasParents())
115 printf ("Prop : niv=%d edge=", niveau);
117 printf ("parent=%d quad=", nq);
118 quad->printName ("\n");
123 Edge* arete = quad->getOpposEdge (this, meme);
124 if (arete != NULL && arete->getPropag () < 0)
125 arete->propager (prop, groupe, meme*sens);
130 // ========================================================= getParent
131 Quad* Edge::getParent (int nro)
133 return static_cast <Quad*> (getFather (nro));
135 // ========================================================= saveXml
136 void Edge::saveXml (XmlWriter* xml)
139 string vertices = e_vertex [V_AMONT]->getName(buffer);
141 vertices += e_vertex [V_AVAL ]->getName(buffer);
143 xml->openMark ("Edge");
144 xml->addAttribute ("id", getName (buffer));
145 xml->addAttribute ("vertices", vertices);
147 xml->addAttribute ("name", el_name);
150 int nbass = tab_assoc.size();
151 for (int nro=0 ; nro<nbass ; nro++)
152 if (tab_assoc[nro] != NULL)
153 tab_assoc[nro]->saveXml (xml);
155 // ======================================================== replaceVertex
156 void Edge::replaceVertex (Vertex* old, Vertex* par)
158 for (int nro=0 ; nro<QUAD4 ; nro++)
160 if (e_vertex[nro]==old)
167 printf (" [%d], ", nro);
168 old->printName (" est remplace par ");
169 par->printName ("\n");
174 // ======================================================== dump
180 printf ("*** deleted ***)\n");
184 e_vertex[V_AMONT]->printName(", ");
185 e_vertex[V_AVAL] ->printName(")");
188 char signe = e_way ? '+' : '-';
189 printf (", Prop= %c%d", signe, e_propag);
194 // ======================================================== dumpAsso
195 void Edge::dumpAsso ()
199 printName(" = *** deleted **\n");
203 geom_dump_asso (this);
205 // ======================================================== dumpPlus
206 void Edge::dumpPlus ()
209 for (int nro=0 ; nro < V_TWO ; nro++)
211 Vertex* pv = e_vertex[nro];
216 printf (" (%g, %g, %g)\n", pv->getX(), pv->getY(), pv->getZ());
224 // ======================================================== makeDefinition
225 string Edge::makeDefinition ()
227 string definition = el_name;
229 definition += " = (";
230 definition += e_vertex [V_AMONT]->getName();
232 definition += e_vertex [V_AVAL]->getName();
237 // ========================================================== addAssociation
238 int Edge::addAssociation (EdgeShape* gline, double deb, double fin)
243 gline->addAssociation (this);
244 AssoEdge* asso = new AssoEdge (gline, deb, fin);
245 tab_assoc.push_back (asso);
249 cout << " Edge " << el_name
250 << " = (" << e_vertex[V_AMONT]->getName()
251 << " , " << e_vertex[V_AVAL ]->getName()
252 << ") addAssociation " << gline->getName ()
253 << " (" << deb << ", " << fin << ")"
255 PutCoord (asso->getOrigin ());
256 PutCoord (asso->getExtrem ());
258 is_associated = true;
261 // ========================================================== addAssociation
262 int Edge::addAssociation (NewShape* geom, int subid, double deb, double fin)
266 if (el_root->debug ())
267 cout << " Edge " << el_name << " addAssociation of NULL ignored"
272 EdgeShape* gline = geom->findEdge (subid);
273 int ier = addAssociation (gline, deb, fin);
276 // ========================================================== clearAssociation
277 void Edge::clearAssociation ()
279 int nombre = tab_assoc.size ();
280 for (int nro=0 ; nro<nombre ; nro++)
282 delete tab_assoc [nro];
286 is_associated = false;
288 // ========================================================== getAssociation
289 AssoEdge* Edge::getAssociation (int nro)
291 if (nro<0 || nro >= tab_assoc.size())
294 return tab_assoc [nro];
296 // ========================================================== checkAssociation
297 int Edge::checkAssociation ()
299 int nombre = tab_assoc.size();
303 Real3 ver_assoc [V_TWO];
304 int arc [V_TWO], sens [V_TWO];
305 for (int nro=0 ; nro<V_TWO ; ++nro)
307 arc [nro] = sens [nro] = NOTHING;
308 e_vertex[nro]->getAssoCoord (ver_assoc[nro]);
312 for (int nass=0 ; nass<nombre ; ++nass)
314 AssoEdge* asso = tab_assoc[nass];
315 for (int nro = V_AMONT ; nro<=V_AVAL ; ++nro)
317 int rep = asso->onExtremity (ver_assoc[nro]);
320 if (arc[nro] != NOTHING)
322 if (ier==HOK) cout << endl;
323 cout << " Association Edge " << el_name
324 << " : Le vertex " << e_vertex[nro]->getName()
325 << " : Le vertex " << e_vertex[nro]->getName()
326 << " Touche les lignes " << arc [nro]
327 << " et " << nass << endl;
336 for (int nro=0 ; nro<V_TWO ; ++nro)
338 if (arc [nro] == NOTHING)
340 if (ier==HOK) cout << endl;
341 cout << " Association Edge " << el_name
342 << " : Le vertex nro " << nro
343 << " = " << e_vertex[nro]->getName()
344 << " est isole" << endl;
345 PutCoord (ver_assoc[nro]);
352 cout << " ** Controle associations (" << nombre << ") edge " << el_name
353 << " = (" << e_vertex[V_AMONT]->getName()
354 << " , " << e_vertex[V_AVAL ]->getName()
357 for (int nv=0 ; nv<2 ; ++nv)
359 Vertex* node = e_vertex[nv];
360 cout << node->getName() << " = (" << node->getX()
361 << ", " << node->getY() << ", " << node->getZ()
362 << ") -> "<< ver_assoc [nv][0] << ", " << ver_assoc [nv][1]
363 << ", " << ver_assoc [nv][2] << ")" << endl;
366 for (int nass=0 ; nass<nombre ; ++nass)
368 AssoEdge* asso = tab_assoc[nass];
369 cout << " " << nass << " :";