0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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>
7bd071ed 19#include <TopoDS_Face.hxx>
7bd071ed 20#include <TopTools_ListOfShape.hxx>
21#include <BRepLib.hxx>
22#include <BRep_Tool.hxx>
23#include <TopTools_MapOfShape.hxx>
7bd071ed 24
4945e8be 25IMPLEMENT_STANDARD_RTTIEXT(IMeshTools_ShapeExplorer, IMeshData_Shape)
26
967d2f4f 27namespace
28{
29 //=======================================================================
30 // Function: visitEdges
31 // Purpose : Explodes the given shape on edges according to the specified
32 // criteria and visits each one in order to add it to data model.
33 //=======================================================================
34 void visitEdges (const Handle (IMeshTools_ShapeVisitor)& theVisitor,
35 const TopoDS_Shape& theShape,
e9d05765 36 const Standard_Boolean isResetLocation,
967d2f4f 37 const TopAbs_ShapeEnum theToFind,
38 const TopAbs_ShapeEnum theToAvoid = TopAbs_SHAPE)
39 {
40 TopExp_Explorer aEdgesIt (theShape, theToFind, theToAvoid);
41 for (; aEdgesIt.More (); aEdgesIt.Next ())
42 {
43 const TopoDS_Edge& aEdge = TopoDS::Edge (aEdgesIt.Current ());
44 if (!BRep_Tool::IsGeometric (aEdge))
45 {
46 continue;
47 }
48
e9d05765 49 theVisitor->Visit (isResetLocation ?
50 TopoDS::Edge (aEdge.Located (TopLoc_Location ())) :
51 aEdge);
967d2f4f 52 }
53 }
54}
55
7bd071ed 56//=======================================================================
57// Function: Constructor
58// Purpose :
59//=======================================================================
60IMeshTools_ShapeExplorer::IMeshTools_ShapeExplorer (
61 const TopoDS_Shape& theShape)
62 : IMeshData_Shape (theShape)
63{
64}
65
66//=======================================================================
67// Function: Destructor
68// Purpose :
69//=======================================================================
70IMeshTools_ShapeExplorer::~IMeshTools_ShapeExplorer ()
71{
72}
73
74//=======================================================================
75// Function: Accept
76// Purpose :
77//=======================================================================
78void IMeshTools_ShapeExplorer::Accept (
79 const Handle (IMeshTools_ShapeVisitor)& theVisitor)
80{
967d2f4f 81 // Explore all free edges in shape.
e9d05765 82 visitEdges (theVisitor, GetShape (), Standard_True, TopAbs_EDGE, TopAbs_FACE);
7bd071ed 83
967d2f4f 84 // Explore all related to some face edges in shape.
85 // make array of faces suitable for processing (excluding faces without surface)
7bd071ed 86 TopTools_ListOfShape aFaceList;
87 BRepLib::ReverseSortFaces (GetShape (), aFaceList);
88 TopTools_MapOfShape aFaceMap;
89
7bd071ed 90 const TopLoc_Location aEmptyLoc;
91 TopTools_ListIteratorOfListOfShape aFaceIter (aFaceList);
92 for (; aFaceIter.More (); aFaceIter.Next ())
93 {
94 TopoDS_Shape aFaceNoLoc = aFaceIter.Value ();
95 aFaceNoLoc.Location (aEmptyLoc);
96 if (!aFaceMap.Add(aFaceNoLoc))
97 {
98 continue; // already processed
99 }
100
967d2f4f 101 const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Value ());
128654b6 102 if (!BRep_Tool::IsGeometric (aFace))
7bd071ed 103 {
104 continue;
105 }
106
967d2f4f 107 // Explore all edges in face.
e9d05765 108 visitEdges (theVisitor, aFace, Standard_False, TopAbs_EDGE);
967d2f4f 109
7bd071ed 110 // Store only forward faces in order to prevent inverse issue.
111 theVisitor->Visit (TopoDS::Face (aFace.Oriented (TopAbs_FORWARD)));
112 }
113}