From 5eb8421e340e9dbf4660a66347943c0ec4ea2944 Mon Sep 17 00:00:00 2001 From: isn Date: Tue, 8 Dec 2015 18:30:42 +0300 Subject: [PATCH] refs #766 more complex way to store the history of shape modifications --- src/HYDROData/HYDROData_LandCoverMap.cxx | 81 ++++++++++++++++-------- src/HYDROData/HYDROData_LandCoverMap.h | 2 +- 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index e5dacdf5..8f257c79 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -925,8 +925,10 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl //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); + //hence the map will be empty + + NCollection_IndexedDataMap ShF2FHistory; + RemoveInternal(aResult, &ShF2FHistory); //one face => mark as unchanged if( aListOfFaces.Extent() == 1 ) @@ -943,8 +945,11 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl TopTools_ListOfShape aLS = ShHistory.FindFromKey(aFF); if (aLS.IsEmpty()) { - QString SType = theMap.FindFromKey(aFF); - aChF2ST.Add(aFF, SType); + QString aSType = theMap.FindFromKey(aFF); + if (ShF2FHistory.Contains(aFF)) + aChF2ST.Add(ShF2FHistory.FindFromKey(aFF), aSType); + else + aChF2ST.Add(aFF, aSType); } else { @@ -952,7 +957,11 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl for (; anIt.More(); anIt.Next()) { QString aSType = theMap.FindFromKey(aFF); - aChF2ST.Add(TopoDS::Face(anIt.Value()), aSType); + const TopoDS_Face& aMF = TopoDS::Face(anIt.Value()); + if (ShF2FHistory.Contains(aFF)) + aChF2ST.Add(ShF2FHistory.FindFromKey(aFF), aSType); + else + aChF2ST.Add(aFF, aSType); } } } @@ -1049,35 +1058,51 @@ QStringList HYDROData_LandCoverMap::DumpToPython( const QString& thePyScri return aResList; } -TopoDS_Shape HYDROData_LandCoverMap::RemoveInternal(const TopoDS_Shape& InSh) +void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollection_IndexedDataMap* aF2FReplace) { //Shape must be topologically correct - TopExp_Explorer anExp(InSh, TopAbs_EDGE); - TopTools_ListOfShape anEdgesToRemove; - - for(; anExp.More(); anExp.Next() ) + TopExp_Explorer anExpF(ShToRebuild, TopAbs_FACE); + // + for(; anExpF.More(); anExpF.Next() ) { - TopoDS_Edge CurEdge = TopoDS::Edge(anExp.Current()); - if (CurEdge.Orientation() == TopAbs_INTERNAL) - anEdgesToRemove.Append(CurEdge); + TopoDS_Face CurFace = TopoDS::Face(anExpF.Current()); + // + TopExp_Explorer anExp(CurFace, TopAbs_EDGE); + TopTools_ListOfShape anEdgesToRemove; + // + for(; anExp.More(); anExp.Next() ) + { + TopoDS_Edge CurEdge = TopoDS::Edge(anExp.Current()); + if (CurEdge.Orientation() == TopAbs_INTERNAL) + anEdgesToRemove.Append(CurEdge); + } + // + if (!anEdgesToRemove.IsEmpty()) + { + Handle_ShapeBuild_ReShape aReshape = new ShapeBuild_ReShape(); + TopoDS_Shape OutF = aReshape->Apply(CurFace); + TopTools_ListIteratorOfListOfShape aIt(anEdgesToRemove); + for (; aIt.More(); aIt.Next()) + aReshape->Remove(aIt.Value()); + OutF = aReshape->Apply(CurFace); + + Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape; + sfs->Init(OutF); + sfs->Perform(); + OutF = sfs->Shape(); + aF2FReplace->Add(CurFace, TopoDS::Face(OutF)); + } } - - if (!anEdgesToRemove.IsEmpty()) + // + Handle_ShapeBuild_ReShape anExtReshape = new ShapeBuild_ReShape(); + for (int i = 1; i <= aF2FReplace->Extent(); i++) { - 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(); + TopoDS_Face aFK = aF2FReplace->FindKey(i); + TopoDS_Face aFV = aF2FReplace->FindFromIndex(i); + anExtReshape->Replace(aFK, aFV); + ShToRebuild = anExtReshape->Apply(ShToRebuild); } - else - return InSh; + } void HYDROData_LandCoverMap::SetTransparency( double theTransparency ) diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index 736a8d7e..cf2fe76f 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -142,7 +142,7 @@ public: HYDRODATA_EXPORT void SetTransparency( double ); HYDRODATA_EXPORT double GetTransparency() const; - HYDRODATA_EXPORT TopoDS_Shape RemoveInternal(const TopoDS_Shape& InSh); + HYDRODATA_EXPORT void RemoveInternal(TopoDS_Shape& ShToRebuild, NCollection_IndexedDataMap* aF2FReplace); HYDRODATA_EXPORT bool CheckLinear(); -- 2.39.2