From a61ec27f03c7d6216c60f9dd3692df0a45c43c24 Mon Sep 17 00:00:00 2001 From: isn Date: Wed, 25 Nov 2015 17:17:05 +0300 Subject: [PATCH] refs #744 [another fix] --- src/HYDROData/HYDROData_LandCoverMap.cxx | 120 ++++++++++++++++++----- src/HYDROData/HYDROData_LandCoverMap.h | 7 +- 2 files changed, 100 insertions(+), 27 deletions(-) diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 367f6048..be2f26ad 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -59,6 +59,8 @@ #include #include #include +#include +#include #include @@ -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 aVerticesMap; NCollection_IndexedDataMap< TopoDS_Edge, QList > 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 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 ) diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index c6535eec..736a8d7e 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -27,6 +27,7 @@ #include class Handle_HYDROData_StricklerTable; +#include typedef NCollection_IndexedDataMap 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 ); -- 2.39.2