Salome HOME
Porting on OCCT 7.0 and Qt 5. Make compilable version.
[modules/hydro.git] / src / HYDROData / HYDROData_LandCoverMap.cxx
index 1226dbc5a865cdabcbe737ef1ad5e429193a8dea..fe76bd40afe3f04cca64422d76ab8a5ca070dc0a 100644 (file)
 #include <BRepCheck_Shell.hxx>
 #include <BRepCheck_ListOfStatus.hxx>
 #include <TopTools_SequenceOfShape.hxx>
-#include <Handle_Geom_Curve.hxx>
-#include <Handle_Geom_Line.hxx>
-#include <Handle_Geom_TrimmedCurve.hxx>
+#include <Geom_Curve.hxx>
+#include <Geom_Line.hxx>
+#include <Geom_TrimmedCurve.hxx>
 #include <Geom_TrimmedCurve.hxx>
 #include <TopTools_DataMapOfShapeListOfShape.hxx>
 #include <NCollection_DoubleMap.hxx>
 
+#include <stdexcept>
 
 #include <QFile>
 #include <QString>
 #include <QTextStream>
 #include <QFileInfo>
 
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 const char TELEMAC_FORMAT = 'f';
 const int TELEMAC_PRECISION = 3;
 
 
-IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
 
 /**
@@ -642,6 +645,7 @@ TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& the
                                                  TopTools_IndexedDataMapOfShapeListOfShape* theShHistory, 
                                                  double theTolerance)
 {
+  //DEBTRACE("MergeFaces");
   int anError;
   TopTools_ListIteratorOfListOfShape anIt;
   BOPCol_ListOfShape aLC;
@@ -826,6 +830,7 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co
     aShapesList.Append( anIt.Face() );
   aShapesList.Append( theNewShape );
 
+  //DEBTRACE("theNewType " << theNewType);
   if( aShapesList.Size()==1 && theNewShape.ShapeType()==TopAbs_FACE )
   {
     aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
@@ -863,6 +868,7 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co
   for( ; aMIt.More(); aMIt.Next() )
   {
     //std::cout << "   " << aMIt.Value() << std::endl;
+    //DEBTRACE(aMIt.Value());
     int aKey = (int)(uintptr_t)aMIt.Value().TShape().operator->();
     aShapesFromNewFace.Add( aKey );
   }
@@ -872,11 +878,13 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co
   for( ; anIt.More(); anIt.Next() )
   {
     QString aSType = anIt.StricklerType();
+    //DEBTRACE(anIt.StricklerType() << " " << anIt.Face());
     //std::cout << "from " << anIt.Face() << ": " << anIt.StricklerType() << std::endl;
     TopTools_ListOfShape aModified = aBuilder.Modified( anIt.Face() );
     //
     if( aModified.Extent() == 0 )
       aModified.Append( anIt.Face() );
+    //DEBTRACE(anIt.StricklerType() << " " << anIt.Face());
 
     TopTools_ListIteratorOfListOfShape aMIt( aModified );
     for( ; aMIt.More(); aMIt.Next() )
@@ -889,14 +897,21 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co
       if( isFace && !isAlsoFromNew )
         aNewFaces.Add( TopoDS::Face( aShape ), aSType );
     }
+    //DEBTRACE(anIt.StricklerType() << " " << anIt.Face());
   }
-
   //     c. add the new shape if it is face with its type
   if( theNewShape.ShapeType()==TopAbs_FACE )
     aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
+  //DEBTRACE(theNewShape << " " << theNewType);
   
   // convert map of shape to type to compound and list of types
   StoreLandCovers( aNewFaces );
+
+//  anIt.Init( *this );
+//  for( ; anIt.More(); anIt.Next() )
+//  {
+//     DEBTRACE(anIt.StricklerType() << " " << anIt.Face());
+//  }
   return true;
 }
 
@@ -908,6 +923,7 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl
 {
   TopTools_ListOfShape aListOfFaces;
 
+  //DEBTRACE("theMap.Extent() " << theMap.Extent());
   for( int i = 1; i <= theMap.Extent(); i++ )
   {
     TopoDS_Face aFace = theMap.FindKey(i);
@@ -917,6 +933,7 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl
   }
 
   TopTools_IndexedDataMapOfShapeListOfShape ShHistory;
+  ShHistory.Clear();
 
   TopoDS_Shape aResult;
   if( aListOfFaces.Extent() == 1 )
@@ -941,28 +958,57 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl
   for( int i = 1; i <= theMap.Extent(); i++ )
   {
     TopoDS_Face aFF = theMap.FindKey(i);
+    //DEBTRACE("  --- " << aFF);
     if( aFF.IsNull() )
       continue;
-    TopTools_ListOfShape aLS = ShHistory.FindFromKey(aFF);
+    //DEBTRACE(ShHistory.IsEmpty());
+    //DEBTRACE(aFF.Checked());
+    TopTools_ListOfShape aLS;
+    try
+    {
+      aLS = ShHistory.FindFromKey(aFF); //TODO: bug to fix. Observed on an incomplete split of a face
+    }
+    catch (...)
+    {
+      DEBTRACE("TODO: bug to fix. Observed on an incomplete split of a face");
+      //continue; // No, keep aLS empty and propagate the type of the original face
+    }
     if (aLS.IsEmpty())
     {
+      //DEBTRACE("--- aLS.IsEmpty()");
       QString aSType = theMap.FindFromKey(aFF);
+      //DEBTRACE("  --- " << aSType.toStdString());
       if (ShF2FHistory.Contains(aFF))
-        aChF2ST.Add(ShF2FHistory.FindFromKey(aFF), aSType);
+        {
+          //DEBTRACE("ShF2FHistory.FindFromKey(aFF) " << ShF2FHistory.FindFromKey(aFF));
+          aChF2ST.Add(ShF2FHistory.FindFromKey(aFF), aSType);
+        }
       else
-        aChF2ST.Add(aFF, aSType);
+        {
+          //DEBTRACE("aFF " << aFF);
+          aChF2ST.Add(aFF, aSType);
+        }
     }
     else
     {
+      //DEBTRACE("--- !aLS.IsEmpty()");
       TopTools_ListIteratorOfListOfShape anIt(aLS);
       for (; anIt.More(); anIt.Next())
       {
         QString aSType = theMap.FindFromKey(aFF);
+        //DEBTRACE("  --- " << aSType.toStdString());
         const TopoDS_Face& aMF = TopoDS::Face(anIt.Value()); 
-        if (ShF2FHistory.Contains(aFF))
-          aChF2ST.Add(ShF2FHistory.FindFromKey(aFF), aSType);
+        //if (ShF2FHistory.Contains(aFF))
+        if (ShF2FHistory.Contains(aMF))
+          {
+            //DEBTRACE("ShF2FHistory.FindFromKey(aMF) " << ShF2FHistory.FindFromKey(aFF));
+            aChF2ST.Add(ShF2FHistory.FindFromKey(aMF), aSType);
+          }
         else
-          aChF2ST.Add(aFF, aSType);
+          {
+            //DEBTRACE("aMF " << aMF);
+            aChF2ST.Add(aMF, aSType);
+          }
       }
     }
   }
@@ -977,6 +1023,7 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl
     QString aST = ""; 
     if (aChF2ST.Contains(aFace))
       aST = aChF2ST.FindFromKey(aFace);
+    //DEBTRACE("aFace "  << aFace << " aST " << aST.toStdString());
     aSTypes << aST;
   }
   
@@ -984,6 +1031,7 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl
   int k = 0;
   foreach (QString aST, aSTypes)
   {
+    //DEBTRACE("aST " << aST.toStdString());
     aTypes->SetValue( k, HYDROData_Tool::toExtString( aST ) );
     k++;
   }
@@ -1061,6 +1109,7 @@ QStringList HYDROData_LandCoverMap::DumpToPython( const QString&       thePyScri
 
 void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollection_IndexedDataMap<TopoDS_Face, TopoDS_Face>* aF2FReplace)
 {
+  //DEBTRACE("RemoveInternal");
   //Shape must be topologically correct
   TopExp_Explorer anExpF(ShToRebuild, TopAbs_FACE);
   //
@@ -1080,7 +1129,7 @@ void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollecti
     //
     if (!anEdgesToRemove.IsEmpty())
     {
-      Handle_ShapeBuild_ReShape aReshape = new ShapeBuild_ReShape();
+      Handle(ShapeBuild_ReShape) aReshape = new ShapeBuild_ReShape();
       TopoDS_Shape OutF = aReshape->Apply(CurFace);
       TopTools_ListIteratorOfListOfShape aIt(anEdgesToRemove);
       for (; aIt.More(); aIt.Next()) 
@@ -1095,7 +1144,7 @@ void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollecti
     }
   }
   //
-  Handle_ShapeBuild_ReShape anExtReshape = new ShapeBuild_ReShape();
+  Handle(ShapeBuild_ReShape) anExtReshape = new ShapeBuild_ReShape();
   for (int i = 1; i <= aF2FReplace->Extent(); i++)
   {
     TopoDS_Face aFK = aF2FReplace->FindKey(i);
@@ -1103,6 +1152,10 @@ void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollecti
     anExtReshape->Replace(aFK, aFV);
     ShToRebuild = anExtReshape->Apply(ShToRebuild);
   }
+//  for (int i = 1; i <= aF2FReplace->Extent(); i++)
+//    {
+//      DEBTRACE("aF2FReplace key,value " << aF2FReplace->FindKey(i) << " " << aF2FReplace->FindFromIndex(i));
+//    }
 
 }
 
@@ -1123,7 +1176,7 @@ bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName,
   QStringList aPolyList; 
   TopTools_SequenceOfShape aFaces;
   int aSHapeType = -1;
-  int Stat = anImporter.ImportPolygons(theSHPFileName, aPolyList, aFaces, aSHapeType);
+  int Stat = anImporter.ImportPolygons(HYDROData_Document::Document(1), theSHPFileName, aPolyList, aFaces, aSHapeType);
   //
   if (Stat != 1)
     return false;
@@ -1164,7 +1217,7 @@ bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName, bool bUse
 {
   HYDROData_ShapeFile anExporter;
   QStringList aList;
-  anExporter.Export(theSHPFileName, this, aList, bUseDiscr, theDefl );
+  anExporter.Export(HYDROData_Document::Document(1), theSHPFileName, this, aList, bUseDiscr, theDefl );
   if (aList.empty())
     return true;
   else 
@@ -1179,7 +1232,7 @@ bool HYDROData_LandCoverMap::CheckLinear()
   {
     TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
     double aFP, aLP;
-    Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
+    Handle(Geom_Curve) aCur = BRep_Tool::Curve(E, aFP, aLP);
     Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
     if (aLine.IsNull())
     {