#include <NCollection_IndexedDataMap.hxx>
#include <BOPAlgo_BOP.hxx>
#include <BOPAlgo_Section.hxx>
+#include <TopTools_MapOfShape.hxx>
#include <Basics_OCCTVersion.hxx>
return IsInter;
}
+bool HYDROData_BoundaryPolygonTools::CutTool( const TopTools_SequenceOfShape& CutTools,
+ NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
+ NCollection_IndexedDataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher>& 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<TopoDS_Shape, TopoDS_Shape>& ObjToRes )
{
}
return true;
-}
+}*/
bool HYDROData_BoundaryPolygonTools::IncludeTool( const TopTools_SequenceOfShape& IncludeTools,
#include "HYDROData.h"
#include <TopTools_SequenceOfShape.hxx>
#include <NCollection_IndexedDataMap.hxx>
-
+#include <TopTools_ShapeMapHasher.hxx>
+#include <TopTools_MapOfShape.hxx>
class TopoDS_Shape;
-class HYDRODATA_EXPORT HYDROData_BoundaryPolygonTools {
+class HYDRODATA_EXPORT HYDROData_BoundaryPolygonTools
+{
public:
- static bool CutTool( const TopTools_SequenceOfShape& CutTools,
- NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes );
+ static bool CutTool( const TopTools_SequenceOfShape& CutTools, NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
+ NCollection_IndexedDataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher>& BPFaceToCutEdges );
static bool IncludeTool( const TopTools_SequenceOfShape& IncludeTools,
TopoDS_Shape Obj);
#include <HYDROData_Tool.h>
#include <HYDROData_BCPolygon.h>
#include <HYDROData_BoundaryPolygonTools.h>
+#include <HYDROData_SplitToZonesTool.h>
#ifdef WIN32
#pragma warning ( disable: 4251 )
static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
const HYDROData_SequenceOfObjects& aBoundaryPolygons,
- NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes)
+ NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
+ HYDROData_SplitToZonesTool::SplitDataList& outBoundaryPolygonEdgesList)
{
//perform boundary condition polygons on EdgesList
TopTools_SequenceOfShape CutTools;
+ NCollection_DataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> BPolyToName;
+
ObjToRes.Clear();
HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
for (int i=1; i<=aBoundaryPolygons.Size();i++)
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() )
ObjToRes.Add(aSplitData.Shape, TopoDS_Shape());
}
- HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes);
+ NCollection_IndexedDataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher> 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<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
+ const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
HYDROData_SplitToZonesTool::SplitDataList& outZoneList)
{
HYDROData_SplitToZonesTool::SplitDataListIterator it( ZoneList );
}
static void CreateNewEdgeList( const HYDROData_SplitToZonesTool::SplitDataList& theEdges,
- const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
+ const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
HYDROData_SplitToZonesTool::SplitDataList& newEdges)
{
HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
//split edges by boundary polygons
HYDROData_SequenceOfObjects aBoundaryPolygons = GetBoundaryPolygons();
//edge to splitted edge (compound of edges or original edge)
- NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape> ObjToRes;
+ NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> 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);
//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);
#include <BRepGProp.hxx>
#include <HYDROData_ShapesGroup.h>
#include <HYDROData_BCPolygon.h>
+#include <TopExp_Explorer.hxx>
extern QString REF_DATA_PATH;
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;