Salome HOME
Merge remote-tracking branch 'origin/master' into V9_dev
[modules/hexablock.git] / src / HEXABLOCK / HexEdge.cxx
index e0e34a300326671dafbc004fa391bfe42c8cfbf9..2f0160b41b8cf83bef67c7a36fa3cbea15f9f4ac 100755 (executable)
@@ -1,12 +1,12 @@
 
 // C++ : Gestion des aretes
 
-// Copyright (C) 2009-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2009-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,8 +17,7 @@
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/
-// or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 #include "HexEdge.hxx"
 #include "HexVertex.hxx"
@@ -28,6 +27,7 @@
 #include "HexXmlWriter.hxx"
 #include "HexNewShape.hxx"
 #include "HexAssoEdge.hxx"
+#include "HexVertexShape.hxx"
 
 static int niveau = 0;
 
@@ -526,4 +526,88 @@ double Edge::getLength ()
    double longueur = calc_distance (p1, p2);
    return longueur;
 }
+// ========================================================= findAssociation
+int Edge::findAssociation (NewShape* geom)
+{
+   Real3 point, p2;
+   if (geom==NULL)
+      return NOTHING;
+
+   e_vertex [V_AMONT]-> getAssoCoord (point);
+   e_vertex [V_AVAL ]-> getAssoCoord (p2);
+
+   EdgeShape*  gline = geom->findEdge (point, p2);
+   if (gline==NULL)
+      { 
+      cout << " *** FindAssociation "  << el_name << endl;
+      for (int nv=0 ; nv < V_TWO ; ++nv)
+          {
+          e_vertex [nv]-> getAssoCoord (point);
+          VertexShape* shape = geom->findVertex (point);
+          cout << " *** Vertex nro "  << nv;
+          if (shape==NULL)
+             {
+             cout << " absent : ";
+             PutCoord (point);
+             }
+          else
+             {
+             cout << " : Subid = " << shape->getIdent() << endl;
+             }
+          }
+      return NOTHING;
+      }
+   
+   clearAssociation ();
+   addAssociation   (gline, 0, 1); 
+   return gline->getIdent();
+}
+// ========================================================= setAssociation
+int Edge::setAssociation (NewShape* geom, int subid)
+{
+   if (geom == NULL)
+      {
+      if (el_root->debug ())
+          cout << "  Edge " << el_name << " addAssociation of NULL ignored"
+               << endl;
+      return HERR;
+      }
+
+   EdgeShape* gline = geom->findEdge (subid);
+   if (gline == NULL)
+      {
+      if (el_root->debug ())
+          cout << "  Edge " << el_name << " addAssociation bad subid : "
+               << subid << endl;
+      return HERR;
+      }
+
+   Real3 p1, p2, pa, pb;
+   gline->getCoords (p1, p2);
+   e_vertex [V_AMONT]-> getAssoCoord (pa);
+   e_vertex [V_AVAL ]-> getAssoCoord (pb);
+
+   double da1 = calc_d2 (pa, p1);
+   double da2 = calc_d2 (pa, p2);
+   double db1 = calc_d2 (pb, p1);
+   double db2 = calc_d2 (pb, p2);
+   
+   cout << "setAssociation " << el_name << " :" <<endl;
+
+   if (da2 < da1 && db1 < db2) 
+      {
+      e_vertex [V_AMONT]->setAssociation (p2);
+      e_vertex [V_AVAL ]->setAssociation (p1);
+      }
+   else
+      {
+      e_vertex [V_AMONT]->setAssociation (p1);
+      e_vertex [V_AVAL ]->setAssociation (p2);
+      }
+
+   
+   clearAssociation ();
+   int ier = addAssociation   (gline, 0, 1); 
+   return ier;
+}
 END_NAMESPACE_HEXA