From: isn Date: Thu, 20 Dec 2018 13:21:06 +0000 (+0300) Subject: lot 14 -> add edges (which are inside boundary polygon of type 1) as a separate group... X-Git-Tag: SH_V2_2_0~99^2~42^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c56d697565a24f5eef5aeeac75ec8b75d717e173;p=modules%2Fhydro.git lot 14 -> add edges (which are inside boundary polygon of type 1) as a separate group +test Signed-off-by: isn --- diff --git a/src/HYDROData/HYDROData_BoundaryPolygonTools.cxx b/src/HYDROData/HYDROData_BoundaryPolygonTools.cxx index e9f44e44..6a98011f 100644 --- a/src/HYDROData/HYDROData_BoundaryPolygonTools.cxx +++ b/src/HYDROData/HYDROData_BoundaryPolygonTools.cxx @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -86,6 +87,91 @@ static bool FindInterBySection(const TopoDS_Face& IncF, TopoDS_Shape poly) return IsInter; } +bool HYDROData_BoundaryPolygonTools::CutTool( const TopTools_SequenceOfShape& CutTools, + NCollection_IndexedDataMap& ObjToRes, + NCollection_IndexedDataMap& BPFaceToCutEdges) +{ + BOPAlgo_Builder anAlgo; + TopTools_MapOfShape cuttedEdges; //all new edges (Obj) after cut + + for (int i=1; i<= CutTools.Length();i++) + anAlgo.AddArgument(CutTools(i)); + + for (int i = 1; i <= ObjToRes.Extent(); i++ ) + { + const TopoDS_Shape& Obj = ObjToRes.FindKey(i); + if (!Obj.IsNull()) + anAlgo.AddArgument(Obj); + } + + anAlgo.Perform(); +#if OCC_VERSION_LARGE > 0x07020000 + if (anAlgo.HasErrors()) + return false; +#endif + TopoDS_Shape aRes = anAlgo.Shape(); + + BRep_Builder BB; + for (int i = 1; i <= ObjToRes.Extent(); i++ ) + { + const TopoDS_Shape& Obj = ObjToRes.FindKey(i); + Standard_Real aTol; + if (!Obj.IsNull()) + { + TopTools_ListOfShape ls = anAlgo.Modified(Obj); + TopoDS_Shape aRes; + if (ls.IsEmpty()) + { + aRes = Obj; //no changes + cuttedEdges.Add(aRes); + } + else if (ls.Extent() == 1) + { + aRes = ls.First(); + cuttedEdges.Add(aRes); + } + else + { + TopoDS_Compound cmp; + BB.MakeCompound(cmp); + TopTools_ListIteratorOfListOfShape aItLS(ls); + for (; aItLS.More(); aItLS.Next()) + { + const TopoDS_Shape& val = aItLS.Value(); + BB.Add(cmp, val); + cuttedEdges.Add(val); + } + aRes = cmp; + } + ObjToRes.ChangeFromKey(Obj) = aRes; + } + } + + //determine the source face + for (int i = 1; i <= CutTools.Length(); i++ ) + { + TopoDS_Shape F = CutTools(i); + TopTools_ListOfShape lsF = anAlgo.Modified(F); + if (lsF.IsEmpty()) + lsF.Append(F); + TopoDS_Compound cmpF; + BB.MakeCompound(cmpF); + TopTools_ListIteratorOfListOfShape aItLS(lsF); + for (; aItLS.More(); aItLS.Next()) + BB.Add(cmpF, aItLS.Value()); + //cmpF is a compound if connected faces => modified of boudnary polygon F + TopExp_Explorer expE(cmpF, TopAbs_EDGE); + TopTools_MapOfShape cmpFEdges; + for (;expE.More();expE.Next()) + cmpFEdges.Add(expE.Current()); + cmpFEdges.Intersect(cuttedEdges); + BPFaceToCutEdges.Add(F, cmpFEdges); + } + + return true; +} + +/* OLD WAY bool HYDROData_BoundaryPolygonTools::CutTool( const TopTools_SequenceOfShape& CutTools, NCollection_IndexedDataMap& ObjToRes ) { @@ -156,7 +242,7 @@ bool HYDROData_BoundaryPolygonTools::CutTool( const TopTools_SequenceOfShape& Cu } return true; -} +}*/ bool HYDROData_BoundaryPolygonTools::IncludeTool( const TopTools_SequenceOfShape& IncludeTools, diff --git a/src/HYDROData/HYDROData_BoundaryPolygonTools.h b/src/HYDROData/HYDROData_BoundaryPolygonTools.h index 70f4d60c..c18802c0 100644 --- a/src/HYDROData/HYDROData_BoundaryPolygonTools.h +++ b/src/HYDROData/HYDROData_BoundaryPolygonTools.h @@ -22,16 +22,18 @@ #include "HYDROData.h" #include #include - +#include +#include class TopoDS_Shape; -class HYDRODATA_EXPORT HYDROData_BoundaryPolygonTools { +class HYDRODATA_EXPORT HYDROData_BoundaryPolygonTools +{ public: - static bool CutTool( const TopTools_SequenceOfShape& CutTools, - NCollection_IndexedDataMap& ObjToRes ); + static bool CutTool( const TopTools_SequenceOfShape& CutTools, NCollection_IndexedDataMap& ObjToRes, + NCollection_IndexedDataMap& BPFaceToCutEdges ); static bool IncludeTool( const TopTools_SequenceOfShape& IncludeTools, TopoDS_Shape Obj); diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 0328afdc..9fb52a8f 100755 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef WIN32 #pragma warning ( disable: 4251 ) @@ -321,10 +322,13 @@ static void FilterEdgesByIncludeSelectionBoundaryPolygons( const HYDROData_Split static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList, const HYDROData_SequenceOfObjects& aBoundaryPolygons, - NCollection_IndexedDataMap& ObjToRes) + NCollection_IndexedDataMap& ObjToRes, + HYDROData_SplitToZonesTool::SplitDataList& outBoundaryPolygonEdgesList) { //perform boundary condition polygons on EdgesList TopTools_SequenceOfShape CutTools; + NCollection_DataMap BPolyToName; + ObjToRes.Clear(); HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList); for (int i=1; i<=aBoundaryPolygons.Size();i++) @@ -333,7 +337,11 @@ static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::Spli TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape(); int bType = aBCPoly->GetBoundaryType(); if (bType == 1) + { CutTools.Append(aPolyTopShape); + QString bp_name = aBCPoly->GetName(); + BPolyToName.Bind(aPolyTopShape, bp_name); + } } while( anIter.hasNext() ) @@ -346,12 +354,33 @@ static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::Spli ObjToRes.Add(aSplitData.Shape, TopoDS_Shape()); } - HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes); + NCollection_IndexedDataMap BPFaceToCutEdges; + HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes, BPFaceToCutEdges); + // + for (int i = 1; i <= CutTools.Length(); i++ ) + { + TopoDS_Shape F = CutTools(i); + const QString* name = BPolyToName.Seek(F); + const TopTools_MapOfShape* EdgesIn = BPFaceToCutEdges.Seek(F); // EdgesIn : edges inside boudnary polygon F + if (name && EdgesIn) + { + TopTools_MapIteratorOfMapOfShape it(*EdgesIn); + for (;it.More();it.Next()) + { + TopoDS_Edge E = TopoDS::Edge(it.Value()); + if (!E.IsNull()) + { + HYDROData_SplitToZonesTool::SplitData SD(HYDROData_SplitToZonesTool::SplitData::Data_Edge, E, *name); + outBoundaryPolygonEdgesList.append(SD); + } + } + } + } } static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataList& ZoneList, - const NCollection_IndexedDataMap& ObjToRes, + const NCollection_IndexedDataMap& ObjToRes, HYDROData_SplitToZonesTool::SplitDataList& outZoneList) { HYDROData_SplitToZonesTool::SplitDataListIterator it( ZoneList ); @@ -398,7 +427,7 @@ static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataLi } static void CreateNewEdgeList( const HYDROData_SplitToZonesTool::SplitDataList& theEdges, - const NCollection_IndexedDataMap& ObjToRes, + const NCollection_IndexedDataMap& ObjToRes, HYDROData_SplitToZonesTool::SplitDataList& newEdges) { HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges ); @@ -467,9 +496,10 @@ void HYDROData_CalculationCase::Update() //split edges by boundary polygons HYDROData_SequenceOfObjects aBoundaryPolygons = GetBoundaryPolygons(); //edge to splitted edge (compound of edges or original edge) - NCollection_IndexedDataMap ObjToRes; + NCollection_IndexedDataMap ObjToRes; //split edge list by BP - SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes); + HYDROData_SplitToZonesTool::SplitDataList outBoundaryPolygonEdgesList; //new groups - for each BP of type 1 (cut) create a group of edges which are inside of this BP + SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes, outBoundaryPolygonEdgesList); HYDROData_SplitToZonesTool::SplitDataList aNewZonesList; //replace splitted edges in zone list (faces) PerformEdgeReplInZones(aZonesList, ObjToRes, aNewZonesList); @@ -477,6 +507,8 @@ void HYDROData_CalculationCase::Update() //create new edges list based on splitting info from ObjToRes HYDROData_SplitToZonesTool::SplitDataList newEdgesList1,newEdgesList2; CreateNewEdgeList(anEdgesList, ObjToRes, newEdgesList1); + // + newEdgesList1.append(outBoundaryPolygonEdgesList); //append new list of groups //filter out edges list by include&selection tools FilterEdgesByIncludeSelectionBoundaryPolygons(newEdgesList1,aBoundaryPolygons,newEdgesList2); diff --git a/src/HYDRO_tests/test_HYDROData_BoundaryPolygons.cxx b/src/HYDRO_tests/test_HYDROData_BoundaryPolygons.cxx index 18675aee..1877e1a3 100644 --- a/src/HYDRO_tests/test_HYDROData_BoundaryPolygons.cxx +++ b/src/HYDRO_tests/test_HYDROData_BoundaryPolygons.cxx @@ -26,6 +26,7 @@ #include #include #include +#include extern QString REF_DATA_PATH; @@ -44,15 +45,47 @@ void test_HYDROData_BoundaryPolygons::test_bp_1() aCase->Update(); CPPUNIT_ASSERT_EQUAL(4, aCase->GetBoundaryPolygons().Size()); HYDROData_SequenceOfObjects aSplitGroups = aCase->GetSplitGroups(); - CPPUNIT_ASSERT_EQUAL(1, aSplitGroups.Size()); + CPPUNIT_ASSERT_EQUAL(4, aSplitGroups.Size()); - Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aSplitGroups.First() ); - std::string name = aGroup->GetName().toStdString(); - CPPUNIT_ASSERT_EQUAL( name, std::string("Case_1_Immersible zone_1_Outer") ); + Handle(HYDROData_ShapesGroup) aGroup1; + TopTools_MapOfShape EdgesFromBPGroups; + for (int i=1; i<=4;i++) + { + Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aSplitGroups(i) ); + if (aGroup->GetName() == "Case_1_Immersible zone_1_Outer") + { + aGroup1 = aGroup; + } + else + { + TopTools_SequenceOfShape aSeqShapes1; + aGroup->GetShapes( aSeqShapes1 ); + for (int j=1; j<=aSeqShapes1.Size();j++) + { + TopExp_Explorer exp(aSeqShapes1(j), TopAbs_EDGE); + for (;exp.More();exp.Next()) + EdgesFromBPGroups.Add(exp.Current()); + } + } + } + CPPUNIT_ASSERT( !aGroup1.IsNull() ); TopTools_SequenceOfShape aSeqShapes; - aGroup->GetShapes( aSeqShapes ); + aGroup1->GetShapes( aSeqShapes ); CPPUNIT_ASSERT_EQUAL( 78, aSeqShapes.Size()); + // + TopTools_MapOfShape EdgesFromOuter; + + for (int i=1;i<=aSeqShapes.Size();i++) + EdgesFromOuter.Add(aSeqShapes(i)); + + //check that EdgesFromBPGroups is a PART of Case_1_Immersible zone_1_Outer group + int ext1 = EdgesFromBPGroups.Extent(); + EdgesFromOuter.Intersect(EdgesFromBPGroups); + int ext2 = EdgesFromOuter.Extent(); + CPPUNIT_ASSERT_EQUAL(35, ext1); + CPPUNIT_ASSERT_EQUAL(ext1, ext2); + // BRep_Builder BB; TopTools_IndexedMapOfShape ME, MV; GProp_GProps G;