]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #744 [another fix]
authorisn <isn@opencascade.com>
Wed, 25 Nov 2015 14:17:05 +0000 (17:17 +0300)
committerisn <isn@opencascade.com>
Wed, 25 Nov 2015 15:32:44 +0000 (18:32 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h

index 367f60488338e8b37d2fa308fc4373b5a70119d2..be2f26ad9dd46a9ba3dc2af0c69c4465f6044578 100644 (file)
@@ -59,6 +59,8 @@
 #include <Handle_Geom_Line.hxx>
 #include <Handle_Geom_TrimmedCurve.hxx>
 #include <Geom_TrimmedCurve.hxx>
+#include <TopTools_DataMapOfShapeListOfShape.hxx>
+#include <NCollection_DoubleMap.hxx>
 
 
 #include <QFile>
@@ -372,7 +374,7 @@ bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName,
     aTypesMap.insert( anIt.Face().TShape(), anIt.StricklerType() );
   }
 
-  TopoDS_Shape aShape = MergeFaces( aListOfFaces, false );
+  TopoDS_Shape aShape = MergeFaces( aListOfFaces, false, NULL );
 
   NCollection_IndexedMap<gp_Pnt> aVerticesMap;
   NCollection_IndexedDataMap< TopoDS_Edge, QList<int> > anEdgesMap;
@@ -608,7 +610,7 @@ bool HYDROData_LandCoverMap::Split( const TopoDS_Shape& theShape )
 bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const QString& theType )
 {
   // 1. to fuse the faces into the new face
-  TopoDS_Shape aMergedFace = MergeFaces( theFaces, true );  
+  TopoDS_Shape aMergedFace = MergeFaces( theFaces, true, NULL );  
   bool aStat = true;
   if( !aMergedFace.IsNull() )
   { 
@@ -634,8 +636,11 @@ bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const
   @param theTolerance the operation's tolerance
   @return result shape (face or shell)
 */
 TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& theFaces,
-                                                 bool IsToUnify, double theTolerance )
+                                                 bool IsToUnify, 
+                                                 TopTools_IndexedDataMapOfShapeListOfShape* theShHistory, 
+                                                 double theTolerance)
 {
   int anError;
   TopTools_ListIteratorOfListOfShape anIt;
@@ -670,6 +675,19 @@ TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& the
 
   const TopoDS_Shape& aMergedShape = anAlgo.Shape();
 
+  // retrieve history of modifications
+  if (theShHistory)
+  {
+    theShHistory->Clear();
+    anIt.Initialize(theFaces);
+    for( ; anIt.More(); anIt.Next() )
+    {
+      const TopTools_ListOfShape aMLS = anAlgo.Modified( anIt.Value() );
+      theShHistory->Add(anIt.Value(), aMLS);
+    }
+  }
+  //
+
   BRep_Builder aBuilder;
   TopoDS_Shell aShell; 
   aBuilder.MakeShell( aShell ); 
@@ -891,31 +909,77 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl
 {
   TopTools_ListOfShape aListOfFaces;
 
-  int n = theMap.Size();
-
-  Handle( TDataStd_ExtStringArray ) aTypes = 
-    TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_Types ), 0, n-1, Standard_True );
-
-  HYDROData_MapOfFaceToStricklerType::Iterator aNFIt( theMap );
-  for( int i=0; aNFIt.More(); aNFIt.Next(), i++ )
+  for( int i = 1; i <= theMap.Extent(); i++ )
   {
-    TopoDS_Face aFace = aNFIt.Key();
+    TopoDS_Face aFace = theMap.FindKey(i);
     if( aFace.IsNull() )
       continue;
-    QString aType = aNFIt.Value();
     aListOfFaces.Append(aFace);
-    aTypes->SetValue( i, HYDROData_Tool::toExtString( aType ) );
   }
 
+  TopTools_IndexedDataMapOfShapeListOfShape ShHistory;
+
   TopoDS_Shape aResult;
   if( aListOfFaces.Extent() == 1 )
     aResult = aListOfFaces.First();
   else if( aListOfFaces.Extent() > 1 )
-    aResult = MergeFaces( aListOfFaces, false );
+    aResult = MergeFaces( aListOfFaces, false, &ShHistory );
 
   //remove internal edges
+  //if nothing changes => the result shape should be the same
+  //in any other case the history of modifications may be broken
   aResult = RemoveInternal(aResult);
+
+  //one face => mark as unchanged
+  if( aListOfFaces.Extent() == 1 )
+    ShHistory.Add(aResult, TopTools_ListOfShape());
+
+  NCollection_IndexedDataMap<TopoDS_Face, QString> aChF2ST;
+  QStringList aSTypes;
+  //
+  for( int i = 1; i <= theMap.Extent(); i++ )
+  {
+    TopoDS_Face aFF = theMap.FindKey(i);
+    if( aFF.IsNull() )
+      continue;
+    TopTools_ListOfShape aLS = ShHistory.FindFromKey(aFF);
+    if (aLS.IsEmpty())
+    {
+      QString SType = theMap.FindFromKey(aFF);
+      aChF2ST.Add(aFF, SType);
+    }
+    else
+    {
+      TopTools_ListIteratorOfListOfShape anIt(aLS);
+      for (; anIt.More(); anIt.Next())
+      {
+        QString aSType = theMap.FindFromKey(aFF);
+        aChF2ST.Add(TopoDS::Face(anIt.Value()), aSType);
+      }
+    }
+  }
+  //
   SetShape( aResult );
+  //
+  //Explorer Exp(*this);
+  TopExp_Explorer FExp(aResult, TopAbs_FACE);
+  for( ; FExp.More(); FExp.Next() )
+  {
+    TopoDS_Face aFace = TopoDS::Face(FExp.Current());
+    QString aST = ""; 
+    if (aChF2ST.Contains(aFace))
+      aST = aChF2ST.FindFromKey(aFace);
+    aSTypes << aST;
+  }
+  
+  Handle( TDataStd_ExtStringArray ) aTypes = TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_Types ), 0, aSTypes.size() - 1, Standard_True );
+  int k = 0;
+  foreach (QString aST, aSTypes)
+  {
+    aTypes->SetValue( k, HYDROData_Tool::toExtString( aST ) );
+    k++;
+  }
+
 }
 
 /**
@@ -1000,18 +1064,22 @@ TopoDS_Shape HYDROData_LandCoverMap::RemoveInternal(const TopoDS_Shape& InSh)
       anEdgesToRemove.Append(CurEdge);
   }
  
-  Handle_ShapeBuild_ReShape aReshape = new ShapeBuild_ReShape();
-  TopoDS_Shape OutSh = aReshape->Apply(InSh);
-  TopTools_ListIteratorOfListOfShape aIt(anEdgesToRemove);
-  for (; aIt.More(); aIt.Next()) 
-    aReshape->Remove(aIt.Value());
-  OutSh = aReshape->Apply(InSh);
-
-  Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
-  sfs->Init(OutSh);
-  sfs->Perform();
-  return sfs->Shape();
-
+  if (!anEdgesToRemove.IsEmpty())
+  {
+    Handle_ShapeBuild_ReShape aReshape = new ShapeBuild_ReShape();
+    TopoDS_Shape OutSh = aReshape->Apply(InSh);
+    TopTools_ListIteratorOfListOfShape aIt(anEdgesToRemove);
+    for (; aIt.More(); aIt.Next()) 
+      aReshape->Remove(aIt.Value());
+    OutSh = aReshape->Apply(InSh);
+
+    Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
+    sfs->Init(OutSh);
+    sfs->Perform();
+    return sfs->Shape();
+  }
+  else
+    return InSh;
 }
 
 void HYDROData_LandCoverMap::SetTransparency( double theTransparency )
index c6535eecbc321c69a61b93e7b0c9ad4cd9774bf7..736a8d7e16a49be03a5bd26bc029a5d39f62fada 100644 (file)
@@ -27,6 +27,7 @@
 #include <TopExp_Explorer.hxx>
 
 class Handle_HYDROData_StricklerTable;
+#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
 
 typedef NCollection_IndexedDataMap<TopoDS_Face, QString> HYDROData_MapOfFaceToStricklerType;
 
@@ -149,9 +150,13 @@ protected:
   void SetShape( const TopoDS_Shape& );
 
   bool Add( const TopoDS_Wire&, const QString& );
+
   bool LocalPartition( const TopoDS_Shape&, const QString& theNewType );
+
   static TopoDS_Shape MergeFaces(const TopTools_ListOfShape& theFaces,
-                      bool IsToUnify, double theTolerance = 1E-5 );
+                                 bool IsToUnify,
+                                 TopTools_IndexedDataMapOfShapeListOfShape* theShHistory = NULL, 
+                                 double theTolerance = 1E-5 );
 
 public:
   DEFINE_STANDARD_RTTI( HYDROData_LandCoverMap );