1 // Created on: 1995-08-07
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Bnd_Box.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAdaptor_Curve.hxx>
21 #include <BRepAdaptor_Surface.hxx>
22 #include <BRepBndLib.hxx>
23 #include <BRepTools.hxx>
24 #include <Geom_Plane.hxx>
25 #include <Geom_RectangularTrimmedSurface.hxx>
26 #include <Geom_Surface.hxx>
27 #include <Poly_Polygon3D.hxx>
28 #include <Poly_PolygonOnTriangulation.hxx>
29 #include <Poly_Triangulation.hxx>
30 #include <Prs3d_ShapeTool.hxx>
32 #include <TopLoc_Location.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Vertex.hxx>
38 #include <TopTools_ListIteratorOfListOfShape.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_MapOfShape.hxx>
42 //=======================================================================
43 //function : Prs3d_ShapeTool
45 //=======================================================================
46 Prs3d_ShapeTool::Prs3d_ShapeTool (const TopoDS_Shape& theShape,
47 const Standard_Boolean theAllVertices)
52 TopExp::MapShapesAndAncestors (theShape,TopAbs_EDGE,TopAbs_FACE, myEdgeMap);
54 TopExp_Explorer anExpl;
57 for (anExpl.Init (theShape, TopAbs_VERTEX); anExpl.More(); anExpl.Next())
59 myVertexMap.Add (anExpl.Current());
64 // Extracting isolated vertices
65 for (anExpl.Init (theShape, TopAbs_VERTEX, TopAbs_EDGE); anExpl.More(); anExpl.Next())
67 myVertexMap.Add (anExpl.Current());
70 // Extracting internal vertices
71 for (anExpl.Init (theShape, TopAbs_EDGE); anExpl.More(); anExpl.Next())
73 TopoDS_Iterator aIt (anExpl.Current(), Standard_False, Standard_True);
74 for (; aIt.More(); aIt.Next())
76 const TopoDS_Shape& aV = aIt.Value();
77 if (aV.Orientation() == TopAbs_INTERNAL)
86 //=======================================================================
89 //=======================================================================
91 void Prs3d_ShapeTool::InitFace()
93 myFaceExplorer.Init(myShape,TopAbs_FACE);
96 //=======================================================================
99 //=======================================================================
101 Standard_Boolean Prs3d_ShapeTool::MoreFace() const
103 return myFaceExplorer.More();
106 //=======================================================================
107 //function : NextFace
109 //=======================================================================
111 void Prs3d_ShapeTool::NextFace()
113 myFaceExplorer.Next();
116 //=======================================================================
119 //=======================================================================
121 const TopoDS_Face& Prs3d_ShapeTool::GetFace () const
123 return TopoDS::Face(myFaceExplorer.Current());
127 //=======================================================================
128 //function : FaceBound
130 //=======================================================================
132 Bnd_Box Prs3d_ShapeTool::FaceBound() const
134 const TopoDS_Face& F = TopoDS::Face(myFaceExplorer.Current());
136 BRepBndLib::Add(F, B);
140 //=======================================================================
141 //function : IsPlanarFace
143 //=======================================================================
145 Standard_Boolean Prs3d_ShapeTool::IsPlanarFace (const TopoDS_Face& theFace)
148 const Handle(Geom_Surface)& S = BRep_Tool::Surface(theFace, l);
151 return Standard_False;
154 Handle(Standard_Type) TheType = S->DynamicType();
156 if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
157 Handle(Geom_RectangularTrimmedSurface)
158 RTS = Handle(Geom_RectangularTrimmedSurface)::DownCast (S);
159 TheType = RTS->BasisSurface()->DynamicType();
161 return (TheType == STANDARD_TYPE(Geom_Plane));
166 //=======================================================================
167 //function : InitCurve
169 //=======================================================================
171 void Prs3d_ShapeTool::InitCurve()
176 //=======================================================================
177 //function : MoreCurve
179 //=======================================================================
181 Standard_Boolean Prs3d_ShapeTool::MoreCurve() const
183 return myEdge <= myEdgeMap.Extent();
186 //=======================================================================
187 //function : NextCurve
189 //=======================================================================
191 void Prs3d_ShapeTool::NextCurve()
196 //=======================================================================
197 //function : GetCurve
199 //=======================================================================
201 const TopoDS_Edge& Prs3d_ShapeTool::GetCurve () const
203 return TopoDS::Edge(myEdgeMap.FindKey(myEdge));
206 //=======================================================================
207 //function : CurveBound
209 //=======================================================================
211 Bnd_Box Prs3d_ShapeTool::CurveBound () const
213 const TopoDS_Edge& E = TopoDS::Edge(myEdgeMap.FindKey(myEdge));
215 BRepBndLib::Add(E, B);
219 //=======================================================================
220 //function : Neighbours
222 //=======================================================================
224 Standard_Integer Prs3d_ShapeTool::Neighbours () const
226 const TopTools_ListOfShape& L = myEdgeMap.FindFromIndex(myEdge);
230 //=======================================================================
231 //function : FacesOfEdge
233 //=======================================================================
235 Handle(TopTools_HSequenceOfShape) Prs3d_ShapeTool::FacesOfEdge () const
237 Handle(TopTools_HSequenceOfShape) H = new TopTools_HSequenceOfShape;
239 const TopTools_ListOfShape& L = myEdgeMap.FindFromIndex(myEdge);
240 TopTools_ListIteratorOfListOfShape LI;
242 for (LI.Initialize(L); LI.More(); LI.Next()) H->Append(LI.Value());
247 //=======================================================================
248 //function : InitVertex
250 //=======================================================================
252 void Prs3d_ShapeTool::InitVertex()
257 //=======================================================================
258 //function : MoreVertex
260 //=======================================================================
262 Standard_Boolean Prs3d_ShapeTool::MoreVertex() const
264 return myVertex <= myVertexMap.Extent();
267 //=======================================================================
268 //function : NextVertex
270 //=======================================================================
272 void Prs3d_ShapeTool::NextVertex()
277 //=======================================================================
278 //function : GetVertex
280 //=======================================================================
282 const TopoDS_Vertex& Prs3d_ShapeTool::GetVertex () const
284 return TopoDS::Vertex(myVertexMap.FindKey(myVertex));
288 //=======================================================================
289 //function : HasSurface
291 //=======================================================================
293 Standard_Boolean Prs3d_ShapeTool::HasSurface() const
296 const Handle(Geom_Surface)& S = BRep_Tool::Surface(GetFace(), l);
297 return (!S.IsNull());
302 //=======================================================================
303 //function : CurrentTriangulation
305 //=======================================================================
307 Handle(Poly_Triangulation) Prs3d_ShapeTool::CurrentTriangulation(TopLoc_Location& l) const
309 return BRep_Tool::Triangulation(GetFace(), l);
313 //=======================================================================
314 //function : HasCurve
316 //=======================================================================
318 Standard_Boolean Prs3d_ShapeTool::HasCurve() const
320 return (BRep_Tool::IsGeometric(GetCurve()));
326 //=======================================================================
327 //function : PolygonOnTriangulation
329 //=======================================================================
331 void Prs3d_ShapeTool::PolygonOnTriangulation
332 (Handle(Poly_PolygonOnTriangulation)& Indices,
333 Handle(Poly_Triangulation)& T,
334 TopLoc_Location& l) const
336 BRep_Tool::PolygonOnTriangulation(GetCurve(), Indices, T, l);
341 //=======================================================================
342 //function : Polygon3D
344 //=======================================================================
346 Handle(Poly_Polygon3D) Prs3d_ShapeTool::Polygon3D(TopLoc_Location& l) const
348 return BRep_Tool::Polygon3D(GetCurve(), l);