0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / IMeshTools / IMeshTools_ShapeExplorer.cxx
CommitLineData
7bd071ed 1// Created on: 2016-04-07
2// Copyright (c) 2016 OPEN CASCADE SAS
3// Created by: Oleg AGASHIN
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <IMeshTools_ShapeExplorer.hxx>
17#include <TopExp.hxx>
18#include <TopExp_Explorer.hxx>
19#include <TopoDS.hxx>
20#include <TopoDS_Face.hxx>
21#include <TopoDS_Edge.hxx>
22#include <TopTools_ListOfShape.hxx>
23#include <BRepLib.hxx>
24#include <BRep_Tool.hxx>
25#include <TopTools_MapOfShape.hxx>
26#include <Geom_Surface.hxx>
27
967d2f4f 28namespace
29{
30 //=======================================================================
31 // Function: visitEdges
32 // Purpose : Explodes the given shape on edges according to the specified
33 // criteria and visits each one in order to add it to data model.
34 //=======================================================================
35 void visitEdges (const Handle (IMeshTools_ShapeVisitor)& theVisitor,
36 const TopoDS_Shape& theShape,
e9d05765 37 const Standard_Boolean isResetLocation,
967d2f4f 38 const TopAbs_ShapeEnum theToFind,
39 const TopAbs_ShapeEnum theToAvoid = TopAbs_SHAPE)
40 {
41 TopExp_Explorer aEdgesIt (theShape, theToFind, theToAvoid);
42 for (; aEdgesIt.More (); aEdgesIt.Next ())
43 {
44 const TopoDS_Edge& aEdge = TopoDS::Edge (aEdgesIt.Current ());
45 if (!BRep_Tool::IsGeometric (aEdge))
46 {
47 continue;
48 }
49
e9d05765 50 theVisitor->Visit (isResetLocation ?
51 TopoDS::Edge (aEdge.Located (TopLoc_Location ())) :
52 aEdge);
967d2f4f 53 }
54 }
55}
56
7bd071ed 57//=======================================================================
58// Function: Constructor
59// Purpose :
60//=======================================================================
61IMeshTools_ShapeExplorer::IMeshTools_ShapeExplorer (
62 const TopoDS_Shape& theShape)
63 : IMeshData_Shape (theShape)
64{
65}
66
67//=======================================================================
68// Function: Destructor
69// Purpose :
70//=======================================================================
71IMeshTools_ShapeExplorer::~IMeshTools_ShapeExplorer ()
72{
73}
74
75//=======================================================================
76// Function: Accept
77// Purpose :
78//=======================================================================
79void IMeshTools_ShapeExplorer::Accept (
80 const Handle (IMeshTools_ShapeVisitor)& theVisitor)
81{
967d2f4f 82 // Explore all free edges in shape.
e9d05765 83 visitEdges (theVisitor, GetShape (), Standard_True, TopAbs_EDGE, TopAbs_FACE);
7bd071ed 84
967d2f4f 85 // Explore all related to some face edges in shape.
86 // make array of faces suitable for processing (excluding faces without surface)
7bd071ed 87 TopTools_ListOfShape aFaceList;
88 BRepLib::ReverseSortFaces (GetShape (), aFaceList);
89 TopTools_MapOfShape aFaceMap;
90
7bd071ed 91 const TopLoc_Location aEmptyLoc;
92 TopTools_ListIteratorOfListOfShape aFaceIter (aFaceList);
93 for (; aFaceIter.More (); aFaceIter.Next ())
94 {
95 TopoDS_Shape aFaceNoLoc = aFaceIter.Value ();
96 aFaceNoLoc.Location (aEmptyLoc);
97 if (!aFaceMap.Add(aFaceNoLoc))
98 {
99 continue; // already processed
100 }
101
967d2f4f 102 const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Value ());
128654b6 103 if (!BRep_Tool::IsGeometric (aFace))
7bd071ed 104 {
105 continue;
106 }
107
967d2f4f 108 // Explore all edges in face.
e9d05765 109 visitEdges (theVisitor, aFace, Standard_False, TopAbs_EDGE);
967d2f4f 110
7bd071ed 111 // Store only forward faces in order to prevent inverse issue.
112 theVisitor->Visit (TopoDS::Face (aFace.Oriented (TopAbs_FORWARD)));
113 }
114}