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