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
9 // under the terms of the GNU Lesser General Public 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.
17 #define OCC215 //SAV: 01/04/02 vertex exploring is done for all types of shape.
18 #define OCC598 //SAV: 22/10/02 searching for internal vertices.
20 #include <Prs3d_ShapeTool.ixx>
22 #include <BRepTools.hxx>
25 #include <TopTools_ListOfShape.hxx>
26 #include <TopTools_MapOfShape.hxx>
27 #include <TopTools_ListIteratorOfListOfShape.hxx>
29 #include <BRepBndLib.hxx>
30 #include <BRepAdaptor_Surface.hxx>
31 #include <BRepAdaptor_Curve.hxx>
32 #include <Bnd_Box.hxx>
33 #include <BRep_Tool.hxx>
34 #include <Geom_Surface.hxx>
35 #include <Geom_RectangularTrimmedSurface.hxx>
36 #include <Geom_Plane.hxx>
39 //=======================================================================
40 //function : Prs3d_ShapeTool
42 //=======================================================================
44 Prs3d_ShapeTool::Prs3d_ShapeTool(const TopoDS_Shape& TheShape):
49 TopExp::MapShapesAndAncestors(TheShape,TopAbs_EDGE,TopAbs_FACE,myEdgeMap);
52 // find vertices not under ancestors.
53 TopAbs_ShapeEnum E = TheShape.ShapeType();
56 // this check were done to reduce the number of selectable objects
57 // in a local context. By now, there's no noticeable performance improvement.
58 if (E != TopAbs_SOLID && E != TopAbs_SHELL)
61 TopExp_Explorer ex(TheShape,TopAbs_VERTEX, TopAbs_EDGE);
63 const TopoDS_Shape& aV=ex.Current();
69 TopExp_Explorer edges( TheShape, TopAbs_EDGE );
70 while( edges.More() ) {
72 const TopoDS_Shape& aE= edges.Current();
73 TopoDS_Iterator aIt(aE, Standard_False, Standard_True);
75 const TopoDS_Shape& aV=aIt.Value();
76 if (aV.Orientation()==TopAbs_INTERNAL) {
82 TopExp_Explorer vertices( edges.Current(), TopAbs_VERTEX );
83 while( vertices.More() ) {
84 TopoDS_Vertex current = TopoDS::Vertex( vertices.Current() );
85 if ( current.Orientation() == TopAbs_INTERNAL )
86 myVertexMap.Add( current );
96 //=======================================================================
99 //=======================================================================
101 void Prs3d_ShapeTool::InitFace()
103 myFaceExplorer.Init(myShape,TopAbs_FACE);
106 //=======================================================================
107 //function : MoreFace
109 //=======================================================================
111 Standard_Boolean Prs3d_ShapeTool::MoreFace() const
113 return myFaceExplorer.More();
116 //=======================================================================
117 //function : NextFace
119 //=======================================================================
121 void Prs3d_ShapeTool::NextFace()
123 myFaceExplorer.Next();
126 //=======================================================================
129 //=======================================================================
131 const TopoDS_Face& Prs3d_ShapeTool::GetFace () const
133 return TopoDS::Face(myFaceExplorer.Current());
137 //=======================================================================
138 //function : FaceBound
140 //=======================================================================
142 Bnd_Box Prs3d_ShapeTool::FaceBound() const
144 const TopoDS_Face& F = TopoDS::Face(myFaceExplorer.Current());
146 BRepBndLib::Add(F, B);
150 //=======================================================================
151 //function : IsPlanarFace
153 //=======================================================================
155 Standard_Boolean Prs3d_ShapeTool::IsPlanarFace() const
158 const TopoDS_Face& F = TopoDS::Face(myFaceExplorer.Current());
159 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F, l);
160 Handle(Standard_Type) TheType = S->DynamicType();
162 if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
163 Handle(Geom_RectangularTrimmedSurface)
164 RTS = *((Handle(Geom_RectangularTrimmedSurface)*)&S);
165 TheType = RTS->BasisSurface()->DynamicType();
167 return (TheType == STANDARD_TYPE(Geom_Plane));
172 //=======================================================================
173 //function : InitCurve
175 //=======================================================================
177 void Prs3d_ShapeTool::InitCurve()
182 //=======================================================================
183 //function : MoreCurve
185 //=======================================================================
187 Standard_Boolean Prs3d_ShapeTool::MoreCurve() const
189 return myEdge <= myEdgeMap.Extent();
192 //=======================================================================
193 //function : NextCurve
195 //=======================================================================
197 void Prs3d_ShapeTool::NextCurve()
202 //=======================================================================
203 //function : GetCurve
205 //=======================================================================
207 const TopoDS_Edge& Prs3d_ShapeTool::GetCurve () const
209 return TopoDS::Edge(myEdgeMap.FindKey(myEdge));
212 //=======================================================================
213 //function : CurveBound
215 //=======================================================================
217 Bnd_Box Prs3d_ShapeTool::CurveBound () const
219 const TopoDS_Edge& E = TopoDS::Edge(myEdgeMap.FindKey(myEdge));
221 BRepBndLib::Add(E, B);
225 //=======================================================================
226 //function : Neighbours
228 //=======================================================================
230 Standard_Integer Prs3d_ShapeTool::Neighbours () const
232 const TopTools_ListOfShape& L = myEdgeMap.FindFromIndex(myEdge);
236 //=======================================================================
237 //function : FacesOfEdge
239 //=======================================================================
241 Handle(TopTools_HSequenceOfShape) Prs3d_ShapeTool::FacesOfEdge () const
243 Handle(TopTools_HSequenceOfShape) H = new TopTools_HSequenceOfShape;
245 const TopTools_ListOfShape& L = myEdgeMap.FindFromIndex(myEdge);
246 TopTools_ListIteratorOfListOfShape LI;
248 for (LI.Initialize(L); LI.More(); LI.Next()) H->Append(LI.Value());
253 //=======================================================================
254 //function : InitVertex
256 //=======================================================================
258 void Prs3d_ShapeTool::InitVertex()
263 //=======================================================================
264 //function : MoreVertex
266 //=======================================================================
268 Standard_Boolean Prs3d_ShapeTool::MoreVertex() const
270 return myVertex <= myVertexMap.Extent();
273 //=======================================================================
274 //function : NextVertex
276 //=======================================================================
278 void Prs3d_ShapeTool::NextVertex()
283 //=======================================================================
284 //function : GetVertex
286 //=======================================================================
288 const TopoDS_Vertex& Prs3d_ShapeTool::GetVertex () const
290 return TopoDS::Vertex(myVertexMap.FindKey(myVertex));
294 //=======================================================================
295 //function : HasSurface
297 //=======================================================================
299 Standard_Boolean Prs3d_ShapeTool::HasSurface() const
302 const Handle(Geom_Surface)& S = BRep_Tool::Surface(GetFace(), l);
303 return (!S.IsNull());
308 //=======================================================================
309 //function : CurrentTriangulation
311 //=======================================================================
313 Handle(Poly_Triangulation) Prs3d_ShapeTool::CurrentTriangulation(TopLoc_Location& l) const
315 return BRep_Tool::Triangulation(GetFace(), l);
319 //=======================================================================
320 //function : HasCurve
322 //=======================================================================
324 Standard_Boolean Prs3d_ShapeTool::HasCurve() const
326 return (BRep_Tool::IsGeometric(GetCurve()));
332 //=======================================================================
333 //function : PolygonOnTriangulation
335 //=======================================================================
337 void Prs3d_ShapeTool::PolygonOnTriangulation
338 (Handle(Poly_PolygonOnTriangulation)& Indices,
339 Handle(Poly_Triangulation)& T,
340 TopLoc_Location& l) const
342 BRep_Tool::PolygonOnTriangulation(GetCurve(), Indices, T, l);
347 //=======================================================================
348 //function : Polygon3D
350 //=======================================================================
352 Handle(Poly_Polygon3D) Prs3d_ShapeTool::Polygon3D(TopLoc_Location& l) const
354 return BRep_Tool::Polygon3D(GetCurve(), l);