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 TopoDS_Compound aObjCmp;
106 BB.MakeCompound(aObjCmp);
107 for (int i = 1; i <= ObjToRes.Extent(); i++ )
109 const TopoDS_Shape& Obj = ObjToRes.FindKey(i);
111 BB.Add(aObjCmp, Obj);
116 aTol = Precision::Confusion();
119 aBOP.AddArgument(aObjCmp);
120 aBOP.AddTool(aToolCmp);
121 aBOP.SetOperation(BOPAlgo_FUSE);
122 aBOP.SetRunParallel(true);
126 #if OCC_VERSION_LARGE > 0x07020000
127 if (aBOP.HasErrors())
131 for (int i = 1; i <= ObjToRes.Extent(); i++ )
133 const TopoDS_Shape& Obj = ObjToRes.FindKey(i);
137 TopTools_ListOfShape ls = aBOP.Modified(Obj);
140 aRes = Obj; //no fusing of toolcmp with Obj
141 else if (ls.Extent() == 1)
147 BB.MakeCompound(cmp);
148 TopTools_ListIteratorOfListOfShape aItLS(ls);
149 for (; aItLS.More(); aItLS.Next())
150 BB.Add(cmp, aItLS.Value());
153 //const TopoDS_Shape& aRes=aBOP.Shape();
154 ObjToRes.ChangeFromKey(Obj) = aRes;
162 bool HYDROData_BoundaryPolygonTools::IncludeTool( const TopTools_SequenceOfShape& IncludeTools,
165 TopExp_Explorer exp(Obj, TopAbs_VERTEX);
168 TopoDS_Vertex aV = TopoDS::Vertex(exp.Current());
169 gp_Pnt aP = BRep_Tool::Pnt(aV);
170 for (int i=1; i<=IncludeTools.Size(); i++)
172 TopoDS_Face IncF = TopoDS::Face(IncludeTools(i));
173 bool IsInter = FindInterBySection(IncF, Obj);
177 gp_XY aP2d(aP.X(), aP.Y());
178 TopAbs_State aState = HYDROData_Tool::ComputePointState(aP2d, IncF);
179 if (aState != TopAbs_IN)
185 bool HYDROData_BoundaryPolygonTools::SelectionTool( const TopTools_SequenceOfShape& SelectionTool,
188 for (int i=1; i<=SelectionTool.Size(); i++)
190 TopoDS_Face IncF = TopoDS::Face(SelectionTool(i));
191 bool IsInter = FindInterBySection(IncF, Obj);