Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / HEXABLOCK / HexElements_check.cxx
index 4fe03edd4c494b8696e3b0ae2957586c86e6d565..d73fd11822e251b51b72d011cfa06b85f759a1dd 100644 (file)
@@ -1,28 +1,28 @@
 
 // C++ : Controle arguments
 
-//  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.
+// 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, 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
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// 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 "HexDocument.hxx"
 
 #include "HexElements.hxx"
+
+#include "HexDocument.hxx"
 #include "HexVector.hxx"
 #include "HexHexa.hxx"
 #include "HexQuad.hxx"
@@ -304,7 +304,7 @@ void Elements::checkSense (int nro, Vertex* v1, Vertex* v2, Quad* quad)
    cpchar where = nro < 4 ? "start" : "target";
    setError (HERR);
    Mess << "Arguments nr " << nro << " and " << nro+2 
-        << " : these vertices doenst define an edge of the "
+        << " : these vertices do not define an edge of the "
         << where << " quad";
 }
 // ======================================================== checkPhi
@@ -545,6 +545,172 @@ void Elements::checkDisco (Hexas& thexas, Edges& tedges)
           }
        }
 }
+// ====================================================== checkContour 
+void Elements::checkContour (Quads& tquad, Vertex* v1, Vertex* v2, bool target,
+                             Edges& tedge)
+{
+   tedge.clear ();
+   cpchar who    = target ? "Target" : "Pattern";
+   std::string nmedge = target ? "Vertices of target (args 5 and 6)" 
+                          : "Vertices of pattern (args 3 and 4)" ;
+   nmedge += "don't define an edge" ;
+
+   Edge*  edge1 = el_root->findEdge (v1, v2);
+   if (BadElement (edge1))
+      {
+      setError (HERR);
+      Mess << nmedge;
+      return;
+      }
+
+   std::map <Edge*, int> edge_count;
+   std::map <Edge*, int> :: iterator iter;
+   int nbre = tquad.size();
+   for (int nq=0 ; nq<nbre ; ++nq)
+        {
+        Quad* quad = tquad [nq];
+        if (BadElement (quad)) 
+           {
+           setError (HERR);
+           Mess << who << " quad nr " << nq+1 << " is not valid";
+           return;
+           }
+         else if (target && quad->getNbrParents() != 1)
+           {
+           setError (HERR);
+           Mess << " Target quad nr " << nq+1 
+                << " must be an external face";
+           return;
+           }
+       
+        for (int ned=0 ; ned<QUAD4 ; ++ned)
+            {
+            Edge* edge = quad->getEdge (ned);
+            edge_count [edge] += 1;
+            }
+        }
+   
+   int pos1 = edge_count [edge1];
+   if (pos1==0)
+       {
+       setError (HERR);
+       Mess << nmedge << " of the " << who << " quads";
+       return;
+       }
+   else if (pos1==2)
+       {
+       setError (HERR);
+       Mess << nmedge << " of the " << who << " contour";
+       return;
+       }
+
+   tedge.push_back (edge1);
+   Vertex* vlast = v2;
+   Edge*   elast = edge1;
+   while (vlast != v1)
+         {
+         int   nbre  = vlast->getNbrParents(); 
+         Edge* enext = NULL;
+         for (int ned=0 ; ned<nbre && enext == NULL; ++ned)
+             {
+             Edge* edge = vlast->getParent(ned);
+             if (edge != elast && edge_count [edge]==1)
+                 enext = edge;
+             }
+         if (enext==NULL)
+            {
+            setError (HERR);
+            Mess << who << " as an unclosed contour";
+            return;
+            }
+         tedge.push_back (enext);
+         vlast = enext->opposedVertex (vlast);
+         elast = enext;
+         }
+}
+// ====================================================== checkContour 
+void Elements::checkContour (Quads& tquad, Vertex* v1, Vertex* v2, bool target,
+                             Vertices& tvertex)
+{
+   tvertex.clear ();
+   cpchar who    = target ? "Target" : "Pattern";
+   std::string nmedge = target ? "Vertices of target (args 4 and 6)" 
+                          : "Vertices of pattern (args 3 and 5)" ;
+   nmedge += "don't define an edge" ;
+
+   Edge*  edge1 = el_root->findEdge (v1, v2);
+   if (BadElement (edge1))
+      {
+      setError (HERR);
+      Mess << nmedge;
+      return;
+      }
+
+   std::map <Edge*, int> edge_count;
+   std::map <Edge*, int> :: iterator iter;
+   int nbre = tquad.size();
+   for (int nq=0 ; nq<nbre ; ++nq)
+        {
+        Quad* quad = tquad [nq];
+        if (BadElement (quad)) 
+           {
+           setError (HERR);
+           Mess << who << " quad nr " << nq+1 << " is not valid";
+           return;
+           }
+         else if (target && quad->getNbrParents() != 1)
+           {
+           setError (HERR);
+           Mess << " Target quad nr " << nq+1 
+                << " must be an external face";
+           return;
+           }
+       
+        for (int ned=0 ; ned<QUAD4 ; ++ned)
+            {
+            Edge* edge = quad->getEdge (ned);
+            edge_count [edge] += 1;
+            }
+        }
+   
+   int pos1 = edge_count [edge1];
+   if (pos1==0)
+       {
+       setError (HERR);
+       Mess << nmedge << " of the " << who << " quads";
+       return;
+       }
+   else if (pos1==2)
+       {
+       setError (HERR);
+       Mess << nmedge << " of the " << who << " contour";
+       return;
+       }
+
+   tvertex.push_back (v1);
+   Vertex* vlast = v2;
+   Edge*   elast = edge1;
+   while (vlast != v1)
+         {
+         tvertex.push_back (vlast);
+         int   nbre  = vlast->getNbrParents(); 
+         Edge* enext = NULL;
+         for (int ned=0 ; ned<nbre && enext == NULL; ++ned)
+             {
+             Edge* edge = vlast->getParent(ned);
+             if (edge != elast && edge_count [edge]==1)
+                 enext = edge;
+             }
+         if (enext==NULL)
+            {
+            setError (HERR);
+            Mess << who << " as an unclosed contour";
+            return;
+            }
+         vlast = enext->opposedVertex (vlast);
+         elast = enext;
+         }
+}
 // ======================================================== calcul_phimax
 double calcul_phimax (double radhole, double radext, bool sphere)
 {