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>
40 #include <TopTools_MapOfShape.hxx>
43 #include <Basics_OCCTVersion.hxx>
45 static bool FindInterBySection(const TopoDS_Face& IncF, TopoDS_Shape poly)
49 //make cmp from edges of Inc_sh
50 TopTools_IndexedMapOfShape IncToolsE;
51 TopExp::MapShapes(IncF, TopAbs_EDGE, IncToolsE);
53 TopoDS_Compound aToolCmp;
54 BB.MakeCompound(aToolCmp);
55 for (int i=1; i<= IncToolsE.Extent();i++)
56 BB.Add(aToolCmp, IncToolsE(i));
58 //perform bsection - poly vs aToolCmp
60 aBOP.AddArgument(poly);
61 aBOP.AddArgument(aToolCmp);
62 aBOP.SetRunParallel(true);
67 //#if OCC_VERSION_LARGE > 0x07020000
68 // if (aBOP.HasErrors())
72 const TopoDS_Shape& aRes=aBOP.Shape();
77 TopTools_IndexedMapOfShape aShVE;
78 TopExp::MapShapes(aRes, TopAbs_VERTEX, aShVE);
81 TopExp::MapShapes(aRes, TopAbs_EDGE, aShVE);
90 bool HYDROData_BoundaryPolygonTools::CutTool( const TopTools_SequenceOfShape& CutTools,
91 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
92 NCollection_IndexedDataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher>& BPFaceToCutEdges)
94 BOPAlgo_Builder anAlgo;
95 TopTools_MapOfShape cuttedEdges; //all new edges (Obj) after cut
97 for (int i=1; i<= CutTools.Length();i++)
98 anAlgo.AddArgument(CutTools(i));
100 for (int i = 1; i <= ObjToRes.Extent(); i++ )
102 const TopoDS_Shape& Obj = ObjToRes.FindKey(i);
104 anAlgo.AddArgument(Obj);
108 #if OCC_VERSION_LARGE > 0x07020000
109 if (anAlgo.HasErrors())
112 TopoDS_Shape aRes = anAlgo.Shape();
115 for (int i = 1; i <= ObjToRes.Extent(); i++ )
117 const TopoDS_Shape& Obj = ObjToRes.FindKey(i);
121 TopTools_ListOfShape ls = anAlgo.Modified(Obj);
125 aRes = Obj; //no changes
126 cuttedEdges.Add(aRes);
128 else if (ls.Extent() == 1)
131 cuttedEdges.Add(aRes);
136 BB.MakeCompound(cmp);
137 TopTools_ListIteratorOfListOfShape aItLS(ls);
138 for (; aItLS.More(); aItLS.Next())
140 const TopoDS_Shape& val = aItLS.Value();
142 cuttedEdges.Add(val);
146 ObjToRes.ChangeFromKey(Obj) = aRes;
150 //determine the source face
151 for (int i = 1; i <= CutTools.Length(); i++ )
153 TopoDS_Shape F = CutTools(i);
154 TopTools_ListOfShape lsF = anAlgo.Modified(F);
157 TopoDS_Compound cmpF;
158 BB.MakeCompound(cmpF);
159 TopTools_ListIteratorOfListOfShape aItLS(lsF);
160 for (; aItLS.More(); aItLS.Next())
161 BB.Add(cmpF, aItLS.Value());
162 //cmpF is a compound if connected faces => modified of boudnary polygon F
163 TopExp_Explorer expE(cmpF, TopAbs_EDGE);
164 TopTools_MapOfShape cmpFEdges;
165 for (;expE.More();expE.Next())
166 cmpFEdges.Add(expE.Current());
167 cmpFEdges.Intersect(cuttedEdges);
168 BPFaceToCutEdges.Add(F, cmpFEdges);
175 bool HYDROData_BoundaryPolygonTools::CutTool( const TopTools_SequenceOfShape& CutTools,
176 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes )
178 TopTools_IndexedMapOfShape EdgesTools;
179 for (int i =1; i<=CutTools.Length();i++)
181 const TopoDS_Shape& CSH = CutTools(i);
182 TopExp::MapShapes(CSH, TopAbs_EDGE, EdgesTools);
186 TopoDS_Compound aToolCmp;
187 BB.MakeCompound(aToolCmp);
188 for (int i=1; i<= EdgesTools.Extent();i++)
189 BB.Add(aToolCmp, EdgesTools(i));
191 TopoDS_Compound aObjCmp;
192 BB.MakeCompound(aObjCmp);
193 for (int i = 1; i <= ObjToRes.Extent(); i++ )
195 const TopoDS_Shape& Obj = ObjToRes.FindKey(i);
197 BB.Add(aObjCmp, Obj);
202 aTol = Precision::Confusion();
205 aBOP.AddArgument(aObjCmp);
206 aBOP.AddTool(aToolCmp);
207 aBOP.SetOperation(BOPAlgo_FUSE);
208 aBOP.SetRunParallel(true);
212 #if OCC_VERSION_LARGE > 0x07020000
213 if (aBOP.HasErrors())
217 for (int i = 1; i <= ObjToRes.Extent(); i++ )
219 const TopoDS_Shape& Obj = ObjToRes.FindKey(i);
223 TopTools_ListOfShape ls = aBOP.Modified(Obj);
226 aRes = Obj; //no fusing of toolcmp with Obj
227 else if (ls.Extent() == 1)
233 BB.MakeCompound(cmp);
234 TopTools_ListIteratorOfListOfShape aItLS(ls);
235 for (; aItLS.More(); aItLS.Next())
236 BB.Add(cmp, aItLS.Value());
239 //const TopoDS_Shape& aRes=aBOP.Shape();
240 ObjToRes.ChangeFromKey(Obj) = aRes;
248 bool HYDROData_BoundaryPolygonTools::IncludeTool( const TopTools_SequenceOfShape& IncludeTools,
251 TopExp_Explorer exp(Obj, TopAbs_VERTEX);
254 TopoDS_Vertex aV = TopoDS::Vertex(exp.Current());
255 gp_Pnt aP = BRep_Tool::Pnt(aV);
256 for (int i=1; i<=IncludeTools.Size(); i++)
258 TopoDS_Face IncF = TopoDS::Face(IncludeTools(i));
259 bool IsInter = FindInterBySection(IncF, Obj);
263 gp_XY aP2d(aP.X(), aP.Y());
264 TopAbs_State aState = HYDROData_Tool::ComputePointState(aP2d, IncF);
265 if (aState != TopAbs_IN)
271 bool HYDROData_BoundaryPolygonTools::SelectionTool( const TopTools_SequenceOfShape& SelectionTool,
274 for (int i=1; i<=SelectionTool.Size(); i++)
276 TopoDS_Face IncF = TopoDS::Face(SelectionTool(i));
277 bool IsInter = FindInterBySection(IncF, Obj);