Salome HOME
e6583a3d88b2f48335081e530c46b8c3592d1c74
[modules/hexablock.git] / src / HEXABLOCK / HexEdge.cxx
1
2 // C++ : Gestion des aretes
3
4 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "HexEdge.hxx"
23 #include "HexVertex.hxx"
24 #include "HexQuad.hxx"
25
26 #include "HexPropagation.hxx"
27 #include "HexXmlWriter.hxx"
28 #include "HexNewShape.hxx"
29 #include "HexAssoEdge.hxx"
30
31 static int niveau = 0;
32
33 BEGIN_NAMESPACE_HEXA
34
35 static bool db = on_debug();
36
37 void geom_dump_asso (Edge* edge);
38
39 // ======================================================== Constructeur
40 Edge::Edge (Vertex* va, Vertex* vb)
41     : EltBase (va->dad(), EL_EDGE)
42 {
43    e_vertex [V_AMONT] = va;
44    e_vertex [V_AVAL ] = vb;
45
46    e_propag = NOTHING;
47    e_way    = true;
48    e_law    = NULL;
49    e_clone  = NULL;
50
51    if (isBad())
52       return;
53    else if (BadElement (va) || BadElement (vb))
54       {
55       setError ();
56       return;
57       }
58    else if (va == vb)
59       {
60       setError ();
61       return;
62       }
63
64    majReferences ();
65 }
66 // ======================================================== Constructeur 2
67 Edge::Edge (Edge* other)
68     : EltBase (other->dad(), EL_EDGE)
69 {
70    e_vertex [V_AMONT] = e_vertex [V_AVAL ] = NULL;
71    if (BadElement (other))
72       setError ();
73
74    e_propag = NOTHING;
75    e_way    = true;
76    e_law    = NULL;
77    e_clone  = NULL;
78 }
79 // ======================================================== majReferences
80 void Edge::majReferences ()
81 {
82    e_vertex [V_AMONT]->addParent (this);
83    e_vertex [V_AVAL ]->addParent (this);
84 }
85 // ======================================================== anaMerge
86 int Edge::anaMerge (Vertex* orig, Vertex* tv1[])
87 {
88    tv1 [0] = orig;
89
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];
94    else
95       return HERR;
96
97    return HOK;
98 }
99 // ========================================================= propager
100 void Edge::propager (Propagation* prop, int groupe, int sens)
101 {
102    setPropag (groupe, sens>0);
103    prop->addEdge (this);
104
105    niveau ++;
106    int nbquads = getNbrParents ();
107    for (int nq=0 ; nq<nbquads ; nq++)
108        {
109        Quad* quad = getParent (nq);
110        if (quad!=NULL && quad->hasParents())
111           {
112           if (debug (6))
113              {
114              printf ("Prop : niv=%d edge=", niveau);
115              printName ();
116              printf ("parent=%d quad=", nq);
117              quad->printName ("\n");
118              fflush(stdout);
119              }
120
121           int meme = 1;
122           Edge* arete = quad->getOpposEdge (this, meme);
123           if (arete != NULL && arete->getPropag () < 0)
124               arete->propager (prop, groupe, meme*sens);
125           }
126        }
127    niveau --;
128 }
129 // ========================================================= getParent
130 Quad* Edge::getParent  (int nro)
131 {
132    return static_cast <Quad*> (getFather (nro));
133 }
134 // ========================================================= saveXml
135 void Edge::saveXml (XmlWriter* xml)
136 {
137    char buffer[12];
138    string vertices = e_vertex [V_AMONT]->getName(buffer);
139    vertices += " ";
140    vertices       += e_vertex [V_AVAL ]->getName(buffer);
141
142    xml->openMark     ("Edge");
143    xml->addAttribute ("id",       getName (buffer));
144    xml->addAttribute ("vertices", vertices);
145    if (el_name!=buffer)
146        xml->addAttribute ("name", el_name);
147    xml->closeMark ();
148
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);
153 }
154 // ======================================================== replaceVertex
155 void Edge::replaceVertex (Vertex* old, Vertex* par)
156 {
157    for (int nro=0 ; nro<QUAD4 ; nro++)
158        {
159        if (e_vertex[nro]==old)
160            {
161            e_vertex[nro] = par;
162            if (debug())
163               {
164               printf (" Dans ");
165               printName ();
166               printf (" [%d], ", nro);
167               old->printName (" est remplace par ");
168               par->printName ("\n");
169               }
170            }
171        }
172 }
173 // ======================================================== dump
174 void Edge::dump ()
175 {
176    printName(" = (");
177    if (NOT isHere ())
178       {
179       printf ("*** deleted ***)\n");
180       return;
181       }
182
183    e_vertex[V_AMONT]->printName(", ");
184    e_vertex[V_AVAL] ->printName(")");
185    if (e_propag>=0)
186       {
187       char signe = e_way ? '+' : '-';
188       printf (", Prop= %c%d", signe, e_propag);
189       }
190
191    dumpRef ();
192 }
193 // ======================================================== dumpAsso
194 void Edge::dumpAsso ()
195 {
196    if (NOT isHere ())
197       {
198       printName(" = *** deleted **\n");
199       return;
200       }
201
202    geom_dump_asso (this);
203 }
204 // ======================================================== dumpPlus
205 void Edge::dumpPlus ()
206 {
207    dump ();
208    for (int nro=0 ; nro < V_TWO ; nro++)
209        {
210        Vertex* pv = e_vertex[nro];
211        printf ( "    ");
212        if (pv!=NULL)
213           {
214           pv->printName ();
215           printf (" (%g, %g, %g)\n", pv->getX(),  pv->getY(),  pv->getZ());
216           }
217        else
218           {
219           printf (" NULL\n");
220           }
221        }
222 }
223 // ======================================================== makeDefinition
224 string Edge::makeDefinition ()
225 {
226    string definition = el_name;
227
228    definition += " = (";
229    definition += e_vertex [V_AMONT]->getName();
230    definition += ",";
231    definition += e_vertex [V_AVAL]->getName();
232    definition += ")";
233
234    return definition;
235 }
236 // ========================================================== addAssociation
237 int Edge::addAssociation (EdgeShape* gline, double deb, double fin)
238 {
239    if (gline == NULL)
240       return HERR;
241
242    gline->addAssociation (this);
243    AssoEdge*  asso  = new AssoEdge (gline, deb, fin);
244    tab_assoc.push_back (asso);
245
246    if (db)
247       {
248       cout << " Edge " << el_name
249            << " = (" << e_vertex[V_AMONT]->getName()
250            << " , "  << e_vertex[V_AVAL ]->getName()
251            << ") addAssociation " << gline->getName ()
252            << " (" << deb << ", " << fin << ")"
253            << endl;
254       PutCoord (asso->getOrigin ());
255       PutCoord (asso->getExtrem ());
256       }
257    is_associated = true;
258    return HOK;
259 }
260 // ========================================================== addAssociation
261 int Edge::addAssociation (NewShape* geom, int subid, double deb, double fin)
262 {
263    if (geom == NULL)
264       {
265       if (el_root->debug ())
266           cout << "  Edge " << el_name << " addAssociation of NULL ignored"
267                << endl;
268       return HERR;
269       }
270
271    EdgeShape* gline = geom->findEdge (subid);
272    int ier = addAssociation (gline, deb, fin);
273    return ier;
274 }
275 // ========================================================== clearAssociation
276 void Edge::clearAssociation ()
277 {
278    int nombre = tab_assoc.size ();
279    for (int nro=0 ; nro<nombre ; nro++)
280        {
281        delete tab_assoc [nro];
282        }
283
284    tab_assoc .clear ();
285    is_associated = false;
286 }
287 // ========================================================== getAssociation
288 AssoEdge* Edge::getAssociation (int nro)
289 {
290    if (nro<0 || nro >= tab_assoc.size())
291       return NULL;
292
293    return tab_assoc [nro];
294 }
295 // ========================================================== checkAssociation
296 int Edge::checkAssociation ()
297 {
298    int nombre = tab_assoc.size();
299    if (nombre==0)
300       return HOK;
301
302    Real3 ver_assoc [V_TWO];
303    int arc [V_TWO], sens [V_TWO];
304    for (int nro=0 ; nro<V_TWO ; ++nro)
305        {
306        arc [nro] = sens [nro] = NOTHING;
307        e_vertex[nro]->getAssoCoord (ver_assoc[nro]);
308        }
309
310    int ier    = HOK;
311    for (int nass=0 ; nass<nombre ; ++nass)
312        {
313        AssoEdge*  asso = tab_assoc[nass];
314        for (int nro = V_AMONT ; nro<=V_AVAL ; ++nro)
315            {
316            int rep = asso->onExtremity (ver_assoc[nro]);
317            if (rep != NOTHING)
318               {
319               if (arc[nro] != NOTHING)
320                  {
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;
327                  ier   = 112;
328                  }
329               arc  [nro] = nass;
330               sens [nro] = rep;
331               }
332           }
333        }
334
335    for (int nro=0 ; nro<V_TWO ; ++nro)
336        {
337        if (arc [nro] == NOTHING)
338           {
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]);
345           ier = 111;
346           }
347        }
348    if (ier==HOK)
349        return ier;
350
351    cout << " ** Controle associations (" << nombre << ") edge " << el_name
352         << " = (" << e_vertex[V_AMONT]->getName()
353         << " , "  << e_vertex[V_AVAL ]->getName()
354         << ")" << endl;
355
356    for (int nv=0 ; nv<2 ; ++nv)
357        {
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;
363        }
364
365    for (int nass=0 ; nass<nombre ; ++nass)
366        {
367        AssoEdge*  asso = tab_assoc[nass];
368        cout << " " << nass << " :";
369        asso->dump ();
370        }
371
372    return ier;
373 }
374 END_NAMESPACE_HEXA