1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROData_Tool.h>
20 #include <HYDROData_BoundaryPolygonTools.h>
22 #include <TopExp_Explorer.hxx>
24 #include <TopoDS_Face.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Wire.hxx>
29 #include <BRep_Builder.hxx>
30 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
32 #include <NCollection_List.hxx>
33 #include <TopTools_ListIteratorOfListOfShape.hxx>
35 #include <TopExp_Explorer.hxx>
37 #include <NCollection_IndexedDataMap.hxx>
38 #include <BOPAlgo_BOP.hxx>
39 #include <BOPAlgo_Section.hxx>
42 #include <Basics_OCCTVersion.hxx>
44 static bool FindInterBySection(const TopoDS_Face& IncF, TopoDS_Shape poly)
48 //make cmp from edges of Inc_sh
49 TopTools_IndexedMapOfShape IncToolsE;
50 TopExp::MapShapes(IncF, TopAbs_EDGE, IncToolsE);
52 TopoDS_Compound aToolCmp;
53 BB.MakeCompound(aToolCmp);
54 for (int i=1; i<= IncToolsE.Extent();i++)
55 BB.Add(aToolCmp, IncToolsE(i));
57 //perform bsection - poly vs aToolCmp
59 aBOP.AddArgument(poly);
60 aBOP.AddArgument(aToolCmp);
61 aBOP.SetRunParallel(true);
66 //#if OCC_VERSION_LARGE > 0x07020000
67 // if (aBOP.HasErrors())
71 const TopoDS_Shape& aRes=aBOP.Shape();
76 TopTools_IndexedMapOfShape aShVE;
77 TopExp::MapShapes(aRes, TopAbs_VERTEX, aShVE);
80 TopExp::MapShapes(aRes, TopAbs_EDGE, aShVE);
89 bool HYDROData_BoundaryPolygonTools::CutTool( const TopTools_SequenceOfShape& CutTools,
90 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes )
92 TopTools_IndexedMapOfShape EdgesTools;
93 for (int i =1; i<=CutTools.Length();i++)
95 const TopoDS_Shape& CSH = CutTools(i);
96 TopExp::MapShapes(CSH, TopAbs_EDGE, EdgesTools);
100 TopoDS_Compound aToolCmp;
101 BB.MakeCompound(aToolCmp);
102 for (int i=1; i<= EdgesTools.Extent();i++)
103 BB.Add(aToolCmp, EdgesTools(i));
105 for (int i = 1; i <= ObjToRes.Extent(); i++ )
107 const TopoDS_Shape& Obj = ObjToRes.FindKey(i);
111 aTol = Precision::Confusion();
114 aBOP.AddArgument(Obj);
115 aBOP.AddTool(aToolCmp);
116 aBOP.SetOperation(BOPAlgo_CUT);
117 aBOP.SetRunParallel(true);
121 #if OCC_VERSION_LARGE > 0x07020000
122 if (aBOP.HasErrors())
126 const TopoDS_Shape& aRes=aBOP.Shape();
127 ObjToRes.ChangeFromKey(Obj) = aRes;
134 bool HYDROData_BoundaryPolygonTools::IncludeTool( const TopTools_SequenceOfShape& IncludeTools,
137 TopExp_Explorer exp(Obj, TopAbs_VERTEX);
140 TopoDS_Vertex aV = TopoDS::Vertex(exp.Current());
141 gp_Pnt aP = BRep_Tool::Pnt(aV);
142 for (int i=1; i<=IncludeTools.Size(); i++)
144 TopoDS_Face IncF = TopoDS::Face(IncludeTools(i));
145 bool IsInter = FindInterBySection(IncF, Obj);
149 gp_XY aP2d(aP.X(), aP.Y());
150 TopAbs_State aState = HYDROData_Tool::ComputePointState(aP2d, IncF);
151 if (aState != TopAbs_IN)
157 bool HYDROData_BoundaryPolygonTools::SelectionTool( const TopTools_SequenceOfShape& SelectionTool,
160 for (int i=1; i<=SelectionTool.Size(); i++)
162 TopoDS_Face IncF = TopoDS::Face(SelectionTool(i));
163 bool IsInter = FindInterBySection(IncF, Obj);