Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / HEXABLOCK / HexDocument_asso.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 197c61b..262b42b
@@ -1,12 +1,12 @@
 
 // C++ : Associations dans le document
 
-// Copyright (C) 2009-2012  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 "HexDocument.hxx"
 #include "HexEdge.hxx"
 #include "HexDiagnostics.hxx"
 #include "HexNewShape.hxx"
 #include "HexEdgeShape.hxx"
+#include "HexPropagation.hxx"
+
+#include <map>
 
 BEGIN_NAMESPACE_HEXA
 
 static bool db = on_debug ();  // == getenv ("HEXA_DB") > 0
 
 
-int vertexInLine (Vertex* vfirst, Edges& mline, vector<int> &tsens);
+int vertexInLine (Vertex* vfirst, Edges& mline, std::vector<int> &tsens);
 // ====================================================== vertexInLine
-int vertexInLine (Vertex* vfirst, Edges& mline, vector<int> &tsens)
+int vertexInLine (Vertex* vfirst, Edges& mline, std::vector<int> &tsens)
 {
    int nbseg = mline.size ();
 
@@ -104,7 +106,7 @@ void Document::clearAssoEdges ()
 // ====================================================== clearAssoQuads
 void Document::clearAssoQuads ()
 {
-   for (EltBase* elt = doc_first_elt[EL_VERTEX]->next (); elt!=NULL;
+   for (EltBase* elt = doc_first_elt[EL_QUAD]->next (); elt!=NULL;
                  elt = elt->next())
        {
        Quad* elem = static_cast <Quad*> (elt);
@@ -148,6 +150,19 @@ NewShape* Document::getShape (int nro)
 
    return doc_tab_shape [nro];
 }
+// ====================================================== getFirstExplicitShape
+cpchar Document::getFirstExplicitShape()
+{
+   int nbre = doc_tab_shape.size ();
+   for (int nro=0 ; nro < nbre ; ++nro)
+       {
+       NewShape* shape = doc_tab_shape [nro];
+       if (shape!= NULL && shape->getOrigin()==SH_IMPORT)
+          return shape->getBrep ();
+       }
+
+   return NULL;
+}
 // ====================================================== findShape
 NewShape* Document::findShape (rcstring nom)
 {
@@ -155,6 +170,8 @@ NewShape* Document::findShape (rcstring nom)
    for (int nro=0 ; nro<nbre ; ++nro)
        if (nom == doc_tab_shape [nro]->getName())
           return  doc_tab_shape [nro];
+
+   return NULL;
 }
 // ====================================================== find_line
 EdgeShape* find_line (EdgeShapes& gline, double* point, int& sens)
@@ -197,20 +214,20 @@ Edge* find_edge (Edges& mline, Vertex* vfirst, int& sens)
    return NULL;
 }
 // ====================================================== associateOpenedLine
-int Document::associateOpenedLine (Edges&  mline, NewShapes& gline,
-                                   IntVector& tabid,
+int Document::associateOpenedLine (Edges  mline, NewShapes gline,
+                                   IntVector tabid,
                                    double pstart, double pend)
 {
-   cout << "_________________________________ Asso Open Line"
-        << " ed=" << mline.size()
-        << " sh=" << tabid.size()
-        << endl;
+  std::cout << "_________________________________ Asso Open Line"
+           << " ed=" << mline.size()
+           << " sh=" << tabid.size()
+           << std::endl;
    int ier = associateLine (NULL, mline, gline, tabid, pstart, pend, false);
    return ier;
 }
 // ====================================================== associateClosedLine
-int Document::associateClosedLine (Vertex* vfirst,   Edges&  mline,
-                                   NewShapes& gline, IntVector& tabid,
+int Document::associateClosedLine (Vertex* vfirst,   Edges  mline,
+                                   NewShapes gline, IntVector tabid,
                                    double pstart, bool inv)
 {
    if (vfirst == NULL)
@@ -219,12 +236,12 @@ int Document::associateClosedLine (Vertex* vfirst,   Edges&  mline,
       return HERR;
       }
 
-   cout << "_________________________________ Asso Closed Line"
-        << " first=" << vfirst->getName()
-        << " ed=" << mline.size()
-        << " sh=" << tabid.size()
-        << " inv=" << inv
-        << endl;
+   std::cout << "_________________________________ Asso Closed Line"
+            << " first=" << vfirst->getName()
+            << " ed=" << mline.size()
+            << " sh=" << tabid.size()
+            << " inv=" << inv
+            << std::endl;
    int ier = associateLine (vfirst, mline, gline, tabid, pstart, 1.0, inv);
    PutData (ier);
    return ier;
@@ -272,7 +289,6 @@ int Document::associateLine (Vertex* vfirst, Edges& mline,
    node->setAssociation (doc_cloud, vsid);
 
    double lgedge = lgtotale/nbedges;
-   double smin   = 0;
    double smax   = gstart->getLength()*(1-abstart);
    double emax   = lgedge;
    double pdeb   = pstart;
@@ -328,18 +344,12 @@ int Document::associateLine (Vertex* vfirst, Edges& mline,
           {
           pdeb = 0;
           if (boucle)
-             {
-             smin = smax;
              smax = shape->getLength ();
-             }
           else
              {
              nsh ++;
              if (nsh<nblines)
-                {
-                 smin = smax;
                  smax += glines[nsh]->getLength();
-                 }
              }
           }
        }
@@ -510,13 +520,64 @@ int Document::sortEdges (Vertex* vfirst, Edges& mline, Edges& tab_edge,
 int Document::checkAssociations ()
 {
    int nombre = countUsedEdge();
+   int nberrors = 0;
    for (int ned=0 ; ned<nombre ; ++ned)
        {
        Edge* edge = getUsedEdge (ned);
        int ier = edge->checkAssociation ();
-       // if (ier != HOK) return ier;
+       if (ier != HOK) nberrors ++;
        }
 
+   std::cout << " ... Check edges assotiations : " << nberrors
+            << " error(s)." << std::endl;
+
+   if (nberrors>0) return HERR;
+      else         return HOK;
+}
+// ====================================================== addLaws
+int Document::addLaws (double lgmoy, bool usemax)
+{
+   const double Epsilon   = 1e-6;
+   const double Precision = 1e-2;
+   const double BigNumber = 1e+36;
+
+   std::map <int, Law*>    existing_law;
+   std::map <int, Law*> :: iterator iter;
+
+   if (lgmoy<=Epsilon)
+      return HERR;
+
+   int nbprop = countPropagation();
+   for (int np=0 ; np<nbprop ; ++np)
+       {
+       Propagation* prop      = getPropagation (np);
+       const Edges& tab_edges = prop->getEdges ();
+       double lgref = usemax ? 0 : BigNumber;
+       int  nbedges = tab_edges.size();
+       for (int ned=0 ; ned<nbedges ; ++ned)
+           {
+           Edge*  edge = tab_edges [ned];
+           double lg   = edge->getAssoLen ();
+           if (usemax)
+              lgref = std::max (lgref, lg);
+           else
+              lgref = std::min (lgref, lg);
+           }
+        lgref        = lgref / lgmoy;
+        int    nbcut = (int) lgref; 
+        double delta =  lgref - (double) nbcut; 
+        if (NOT usemax || (delta < Precision))
+            nbcut --;
+
+        iter = existing_law.find (nbcut);
+        if (iter == existing_law.end())
+           {
+           char name [2];
+           sprintf (name, "u_%02d", nbcut);
+           existing_law [nbcut] = addLaw (name, nbcut);
+           }
+       prop->setLaw (existing_law [nbcut]);
+       }
    return HOK;
 }
 END_NAMESPACE_HEXA