1 // Created on: 1995-08-07
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #define OCC215 //SAV: 01/04/02 vertex exploring is done for all types of shape.
23 #define OCC598 //SAV: 22/10/02 searching for internal vertices.
25 #include <Prs3d_ShapeTool.ixx>
27 #include <BRepTools.hxx>
30 #include <TopTools_ListOfShape.hxx>
31 #include <TopTools_MapOfShape.hxx>
32 #include <TopTools_ListIteratorOfListOfShape.hxx>
34 #include <BRepBndLib.hxx>
35 #include <BRepAdaptor_Surface.hxx>
36 #include <BRepAdaptor_Curve.hxx>
37 #include <Bnd_Box.hxx>
38 #include <BRep_Tool.hxx>
39 #include <Geom_Surface.hxx>
40 #include <Geom_RectangularTrimmedSurface.hxx>
41 #include <Geom_Plane.hxx>
44 //=======================================================================
45 //function : Prs3d_ShapeTool
47 //=======================================================================
49 Prs3d_ShapeTool::Prs3d_ShapeTool(const TopoDS_Shape& TheShape):
54 TopExp::MapShapesAndAncestors(TheShape,TopAbs_EDGE,TopAbs_FACE,myEdgeMap);
57 // find vertices not under ancestors.
58 TopAbs_ShapeEnum E = TheShape.ShapeType();
61 // this check were done to reduce the number of selectable objects
62 // in a local context. By now, there's no noticeable performance improvement.
63 if (E != TopAbs_SOLID && E != TopAbs_SHELL)
66 TopExp_Explorer ex(TheShape,TopAbs_VERTEX, TopAbs_EDGE);
68 const TopoDS_Shape& aV=ex.Current();
74 TopExp_Explorer edges( TheShape, TopAbs_EDGE );
75 while( edges.More() ) {
77 const TopoDS_Shape& aE= edges.Current();
78 TopoDS_Iterator aIt(aE, Standard_False, Standard_True);
80 const TopoDS_Shape& aV=aIt.Value();
81 if (aV.Orientation()==TopAbs_INTERNAL) {
87 TopExp_Explorer vertices( edges.Current(), TopAbs_VERTEX );
88 while( vertices.More() ) {
89 TopoDS_Vertex current = TopoDS::Vertex( vertices.Current() );
90 if ( current.Orientation() == TopAbs_INTERNAL )
91 myVertexMap.Add( current );
101 //=======================================================================
102 //function : InitFace
104 //=======================================================================
106 void Prs3d_ShapeTool::InitFace()
108 myFaceExplorer.Init(myShape,TopAbs_FACE);
111 //=======================================================================
112 //function : MoreFace
114 //=======================================================================
116 Standard_Boolean Prs3d_ShapeTool::MoreFace() const
118 return myFaceExplorer.More();
121 //=======================================================================
122 //function : NextFace
124 //=======================================================================
126 void Prs3d_ShapeTool::NextFace()
128 myFaceExplorer.Next();
131 //=======================================================================
134 //=======================================================================
136 const TopoDS_Face& Prs3d_ShapeTool::GetFace () const
138 return TopoDS::Face(myFaceExplorer.Current());
142 //=======================================================================
143 //function : FaceBound
145 //=======================================================================
147 Bnd_Box Prs3d_ShapeTool::FaceBound() const
149 const TopoDS_Face& F = TopoDS::Face(myFaceExplorer.Current());
151 BRepBndLib::Add(F, B);
155 //=======================================================================
156 //function : IsPlanarFace
158 //=======================================================================
160 Standard_Boolean Prs3d_ShapeTool::IsPlanarFace() const
163 const TopoDS_Face& F = TopoDS::Face(myFaceExplorer.Current());
164 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F, l);
165 Handle(Standard_Type) TheType = S->DynamicType();
167 if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
168 Handle(Geom_RectangularTrimmedSurface)
169 RTS = *((Handle(Geom_RectangularTrimmedSurface)*)&S);
170 TheType = RTS->BasisSurface()->DynamicType();
172 return (TheType == STANDARD_TYPE(Geom_Plane));
177 //=======================================================================
178 //function : InitCurve
180 //=======================================================================
182 void Prs3d_ShapeTool::InitCurve()
187 //=======================================================================
188 //function : MoreCurve
190 //=======================================================================
192 Standard_Boolean Prs3d_ShapeTool::MoreCurve() const
194 return myEdge <= myEdgeMap.Extent();
197 //=======================================================================
198 //function : NextCurve
200 //=======================================================================
202 void Prs3d_ShapeTool::NextCurve()
207 //=======================================================================
208 //function : GetCurve
210 //=======================================================================
212 const TopoDS_Edge& Prs3d_ShapeTool::GetCurve () const
214 return TopoDS::Edge(myEdgeMap.FindKey(myEdge));
217 //=======================================================================
218 //function : CurveBound
220 //=======================================================================
222 Bnd_Box Prs3d_ShapeTool::CurveBound () const
224 const TopoDS_Edge& E = TopoDS::Edge(myEdgeMap.FindKey(myEdge));
226 BRepBndLib::Add(E, B);
230 //=======================================================================
231 //function : Neighbours
233 //=======================================================================
235 Standard_Integer Prs3d_ShapeTool::Neighbours () const
237 const TopTools_ListOfShape& L = myEdgeMap.FindFromIndex(myEdge);
241 //=======================================================================
242 //function : FacesOfEdge
244 //=======================================================================
246 Handle(TopTools_HSequenceOfShape) Prs3d_ShapeTool::FacesOfEdge () const
248 Handle(TopTools_HSequenceOfShape) H = new TopTools_HSequenceOfShape;
250 const TopTools_ListOfShape& L = myEdgeMap.FindFromIndex(myEdge);
251 TopTools_ListIteratorOfListOfShape LI;
253 for (LI.Initialize(L); LI.More(); LI.Next()) H->Append(LI.Value());
258 //=======================================================================
259 //function : InitVertex
261 //=======================================================================
263 void Prs3d_ShapeTool::InitVertex()
268 //=======================================================================
269 //function : MoreVertex
271 //=======================================================================
273 Standard_Boolean Prs3d_ShapeTool::MoreVertex() const
275 return myVertex <= myVertexMap.Extent();
278 //=======================================================================
279 //function : NextVertex
281 //=======================================================================
283 void Prs3d_ShapeTool::NextVertex()
288 //=======================================================================
289 //function : GetVertex
291 //=======================================================================
293 const TopoDS_Vertex& Prs3d_ShapeTool::GetVertex () const
295 return TopoDS::Vertex(myVertexMap.FindKey(myVertex));
299 //=======================================================================
300 //function : HasSurface
302 //=======================================================================
304 Standard_Boolean Prs3d_ShapeTool::HasSurface() const
307 const Handle(Geom_Surface)& S = BRep_Tool::Surface(GetFace(), l);
308 return (!S.IsNull());
313 //=======================================================================
314 //function : CurrentTriangulation
316 //=======================================================================
318 Handle(Poly_Triangulation) Prs3d_ShapeTool::CurrentTriangulation(TopLoc_Location& l) const
320 return BRep_Tool::Triangulation(GetFace(), l);
324 //=======================================================================
325 //function : HasCurve
327 //=======================================================================
329 Standard_Boolean Prs3d_ShapeTool::HasCurve() const
331 return (BRep_Tool::IsGeometric(GetCurve()));
337 //=======================================================================
338 //function : PolygonOnTriangulation
340 //=======================================================================
342 void Prs3d_ShapeTool::PolygonOnTriangulation
343 (Handle(Poly_PolygonOnTriangulation)& Indices,
344 Handle(Poly_Triangulation)& T,
345 TopLoc_Location& l) const
347 BRep_Tool::PolygonOnTriangulation(GetCurve(), Indices, T, l);
352 //=======================================================================
353 //function : Polygon3D
355 //=======================================================================
357 Handle(Poly_Polygon3D) Prs3d_ShapeTool::Polygon3D(TopLoc_Location& l) const
359 return BRep_Tool::Polygon3D(GetCurve(), l);