Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / HEXABLOCK / HexEdge.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 7fc3dc5..ceb87eb
@@ -1,12 +1,12 @@
 
 // C++ : Gestion des aretes
 
-// Copyright (C) 2009-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2009-2024  CEA, EDF
 //
 // 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;
 
@@ -144,13 +144,13 @@ void Edge::setPropag  (int nro, bool sens)
    Vertex* v1 = getVertex (  prems);
    Vertex* v2 = getVertex (1-prems);
 
-   cout << " setPropag " << el_name
-           << " = "   << nro 
-           <<  " = (" << v1->getName() << ", "    << v2->getName()
-           << ") = (" << v2->getX() - v1->getX() 
-           << ", "    << v2->getY() - v1->getY() 
-           << ", "    << v2->getZ() - v1->getZ() 
-           << ")"     << endl;
+   std::cout << " setPropag " << el_name
+            << " = "   << nro 
+            <<  " = (" << v1->getName() << ", "    << v2->getName()
+            << ") = (" << v2->getX() - v1->getX() 
+            << ", "    << v2->getY() - v1->getY() 
+            << ", "    << v2->getZ() - v1->getZ() 
+            << ")"     << std::endl;
 }
 // ========================================================= getParent
 Quad* Edge::getParent  (int nro)
@@ -161,7 +161,7 @@ Quad* Edge::getParent  (int nro)
 void Edge::saveXml (XmlWriter* xml)
 {
    char buffer[12];
-   string vertices = e_vertex [V_AMONT]->getName(buffer);
+   std::string vertices = e_vertex [V_AMONT]->getName(buffer);
    vertices += " ";
    vertices       += e_vertex [V_AVAL ]->getName(buffer);
 
@@ -247,9 +247,9 @@ void Edge::dumpPlus ()
        }
 }
 // ======================================================== makeDefinition
-string Edge::makeDefinition ()
+std::string Edge::makeDefinition ()
 {
-   string definition = el_name;
+   std::string definition = el_name;
 
    definition += " = (";
    definition += e_vertex [V_AMONT]->getName();
@@ -271,12 +271,12 @@ int Edge::addAssociation (EdgeShape* gline, double deb, double fin)
 
    if (db)
       {
-      cout << " Edge " << el_name
-           << " = (" << e_vertex[V_AMONT]->getName()
-           << " , "  << e_vertex[V_AVAL ]->getName()
-           << ") addAssociation " << gline->getName ()
-           << " (" << deb << ", " << fin << ")"
-           << endl;
+       std::cout << " Edge " << el_name
+                 << " = (" << e_vertex[V_AMONT]->getName()
+                 << " , "  << e_vertex[V_AVAL ]->getName()
+                 << ") addAssociation " << gline->getName ()
+                 << " (" << deb << ", " << fin << ")"
+                 << std::endl;
       PutCoord (asso->getOrigin ());
       PutCoord (asso->getExtrem ());
       }
@@ -289,8 +289,8 @@ int Edge::addAssociation (NewShape* geom, int subid, double deb, double fin)
    if (geom == NULL)
       {
       if (el_root->debug ())
-          cout << "  Edge " << el_name << " addAssociation of NULL ignored"
-               << endl;
+       std::cout << "  Edge " << el_name << " addAssociation of NULL ignored"
+                 << std::endl;
       return HERR;
       }
 
@@ -444,12 +444,12 @@ int Edge::checkAssociation ()
               {
               if (arc[nro] != NOTHING)
                  {
-                 if (ier==HOK) cout << endl;
-                 cout << " Association Edge "  << el_name
-                      << " : Le vertex " << e_vertex[nro]->getName()
-                      << " : Le vertex " << e_vertex[nro]->getName()
-                      << " Touche les lignes " << arc [nro]
-                      << " et " << nass << endl;
+                if (ier==HOK) std::cout << std::endl;
+                 std::cout << " Association Edge "  << el_name
+                          << " : Le vertex " << e_vertex[nro]->getName()
+                          << " : Le vertex " << e_vertex[nro]->getName()
+                          << " Touche les lignes " << arc [nro]
+                          << " et " << nass << std::endl;
                  ier   = 112;
                  }
               arc  [nro] = nass;
@@ -462,11 +462,11 @@ int Edge::checkAssociation ()
        {
        if (arc [nro] == NOTHING)
           {
-          if (ier==HOK) cout << endl;
-          cout << " Association Edge " << el_name
-               << " : Le vertex nro " << nro
-               << " = " << e_vertex[nro]->getName()
-               << " est isole" << endl;
+         if (ier==HOK) std::cout << std::endl;
+          std::cout << " Association Edge " << el_name
+                   << " : Le vertex nro " << nro
+                   << " = " << e_vertex[nro]->getName()
+                   << " est isole" << std::endl;
           PutCoord (ver_assoc[nro]);
           ier = 111;
           }
@@ -474,24 +474,24 @@ int Edge::checkAssociation ()
    if (ier==HOK)
        return ier;
 
-   cout << " ** Controle associations (" << nombre << ") edge " << el_name
-        << " = (" << e_vertex[V_AMONT]->getName()
-        << " , "  << e_vertex[V_AVAL ]->getName()
-        << ")" << endl;
+   std::cout << " ** Controle associations (" << nombre << ") edge " << el_name
+            << " = (" << e_vertex[V_AMONT]->getName()
+            << " , "  << e_vertex[V_AVAL ]->getName()
+            << ")" << std::endl;
 
    for (int nv=0 ; nv<2 ; ++nv)
        {
        Vertex* node = e_vertex[nv];
-       cout << node->getName()         << " = (" << node->getX()
-             << ", "   << node->getY() << ", "   << node->getZ()
-             << ") -> "<< ver_assoc [nv][0] << ", " << ver_assoc [nv][1]
-             << ", "   << ver_assoc [nv][2] << ")"  << endl;
+       std::cout << node->getName()         << " = (" << node->getX()
+                << ", "   << node->getY() << ", "   << node->getZ()
+                << ") -> "<< ver_assoc [nv][0] << ", " << ver_assoc [nv][1]
+                << ", "   << ver_assoc [nv][2] << ")"  << std::endl;
        }
 
    for (int nass=0 ; nass<nombre ; ++nass)
        {
        AssoEdge*  asso = tab_assoc[nass];
-       cout << " " << nass << " :";
+       std::cout << " " << nass << " :";
        asso->dump ();
        }
 
@@ -517,4 +517,97 @@ double Edge::getAssoLen ()
 
    return longueur;
 }
+// ========================================================= getLength
+double Edge::getLength ()
+{
+   Real3 p1, p2;
+   e_vertex [V_AMONT]-> getAssoCoord (p1);
+   e_vertex [V_AVAL ]-> getAssoCoord (p2);
+   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)
+      { 
+      std::cout << " *** FindAssociation "  << el_name << std::endl;
+      for (int nv=0 ; nv < V_TWO ; ++nv)
+          {
+          e_vertex [nv]-> getAssoCoord (point);
+          VertexShape* shape = geom->findVertex (point);
+          std::cout << " *** Vertex nro "  << nv;
+          if (shape==NULL)
+             {
+            std::cout << " absent : ";
+             PutCoord (point);
+             }
+          else
+             {
+              std::cout << " : Subid = " << shape->getIdent() << std::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 ())
+       std::cout << "  Edge " << el_name << " addAssociation of NULL ignored"
+                 << std::endl;
+      return HERR;
+      }
+
+   EdgeShape* gline = geom->findEdge (subid);
+   if (gline == NULL)
+      {
+      if (el_root->debug ())
+       std::cout << "  Edge " << el_name << " addAssociation bad subid : "
+                 << subid << std::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);
+   
+   std::cout << "setAssociation " << el_name << " :" <<std::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