1 // Created on: 2010-11-15
2 // Created by: Sergey SLYADNEV
3 // Copyright (c) 2010-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <StepToTopoDS_NMTool.hxx>
17 #include <TopTools_ListIteratorOfListOfShape.hxx>
18 #include <TopExp_Explorer.hxx>
19 #include <TopoDS_Shape.hxx>
21 // ============================================================================
22 // Method : StepToTopoDS_NMTool
23 // Purpose : Default constructor
24 // ============================================================================
26 StepToTopoDS_NMTool::StepToTopoDS_NMTool() {
27 myIDEASCase = Standard_False;
28 myActiveFlag = Standard_False;
31 // ============================================================================
32 // Method : StepToTopoDS_NMTool
33 // Purpose : Constructor with a Map for Representation Items and their names
34 // ============================================================================
36 StepToTopoDS_NMTool::StepToTopoDS_NMTool(const StepToTopoDS_DataMapOfRI& MapOfRI,
37 const StepToTopoDS_DataMapOfRINames& MapOfRINames) {
38 myIDEASCase = Standard_False;
39 myActiveFlag = Standard_False;
40 Init(MapOfRI, MapOfRINames);
43 // ============================================================================
45 // Purpose : Initializes internal maps of the tool with the passed ones
46 // ============================================================================
48 void StepToTopoDS_NMTool::Init(const StepToTopoDS_DataMapOfRI& MapOfRI,
49 const StepToTopoDS_DataMapOfRINames& MapOfRINames) {
51 myRINamesMap = MapOfRINames;
54 // ============================================================================
56 // Purpose : Turns the tool ON/OFF (OFF by default)
57 // ============================================================================
59 void StepToTopoDS_NMTool::SetActive(const Standard_Boolean isActive) {
60 myActiveFlag = isActive;
63 // ============================================================================
65 // Purpose : TRUE if active, FALSE - otherwise
66 // ============================================================================
68 Standard_Boolean StepToTopoDS_NMTool::IsActive() {
72 // ============================================================================
74 // Purpose : Clears all internal containers
75 // ============================================================================
77 void StepToTopoDS_NMTool::CleanUp() {
82 // ============================================================================
84 // Purpose : Indicates weither a RI is bound or not in the Map
85 // ============================================================================
87 Standard_Boolean StepToTopoDS_NMTool::IsBound(const Handle(StepRepr_RepresentationItem)& RI) {
88 return myRIMap.IsBound(RI);
91 // ============================================================================
93 // Purpose : Indicates weither a RI is bound or not in the Map by name
94 // ============================================================================
96 Standard_Boolean StepToTopoDS_NMTool::IsBound(const TCollection_AsciiString& RIName) {
97 return myRINamesMap.IsBound(RIName);
100 // ============================================================================
102 // Purpose : Binds a RI with a Shape in the Map
103 // ============================================================================
105 void StepToTopoDS_NMTool::Bind(const Handle(StepRepr_RepresentationItem)& RI, const TopoDS_Shape& S) {
109 // ============================================================================
111 // Purpose : Binds a RI's name with a Shape in the Map
112 // ============================================================================
114 void StepToTopoDS_NMTool::Bind(const TCollection_AsciiString& RIName, const TopoDS_Shape& S) {
115 myRINamesMap.Bind(RIName, S);
118 // ============================================================================
120 // Purpose : Returns the Shape corresponding to the bounded RI
121 // ============================================================================
123 const TopoDS_Shape& StepToTopoDS_NMTool::Find(const Handle(StepRepr_RepresentationItem)& RI) {
124 return myRIMap.Find(RI);
127 // ============================================================================
129 // Purpose : Returns the Shape corresponding to the bounded RI's name
130 // ============================================================================
132 const TopoDS_Shape& StepToTopoDS_NMTool::Find(const TCollection_AsciiString& RIName) {
133 return myRINamesMap.Find(RIName);
136 // ============================================================================
137 // Method : RegisterNMEdge
138 // Purpose : Register non-manifold Edge in the internal storage if it wasn't
140 // ============================================================================
142 void StepToTopoDS_NMTool::RegisterNMEdge(const TopoDS_Shape& Edge) {
143 if ( !this->isEdgeRegisteredAsNM(Edge) )
144 myNMEdges.Append(Edge);
147 // ============================================================================
148 // Method : IsSuspectedAsClosing
149 // Purpose : Checks whether SuspectedShell is pure non-manifold and adjacent
151 // ============================================================================
153 Standard_Boolean StepToTopoDS_NMTool::IsSuspectedAsClosing(const TopoDS_Shape& BaseShell,
154 const TopoDS_Shape& SuspectedShell) {
155 return this->IsPureNMShell(SuspectedShell) &&
156 this->isAdjacentShell(BaseShell, SuspectedShell);
160 // ============================================================================
161 // Method : SetIDEASCase
162 // Purpose : Sets myIDEASCase flag (I-DEAS-like STP is processed)
163 // ============================================================================
165 void StepToTopoDS_NMTool::SetIDEASCase(const Standard_Boolean IDEASCase) {
166 myIDEASCase = IDEASCase;
169 // ============================================================================
170 // Method : GetIDEASCase
171 // Purpose : Gets myIDEASCase flag (I-DEAS-like STP is processed)
172 // ============================================================================
174 Standard_Boolean StepToTopoDS_NMTool::IsIDEASCase() {
178 // ============================================================================
179 // Method : IsPureNMShell
180 // Purpose : Checks if the Shell passed contains only non-manifold Edges
181 // ============================================================================
183 Standard_Boolean StepToTopoDS_NMTool::IsPureNMShell(const TopoDS_Shape& Shell) {
184 Standard_Boolean result = Standard_True;
185 TopExp_Explorer edgeExp(Shell, TopAbs_EDGE);
186 for ( ; edgeExp.More(); edgeExp.Next() ) {
187 TopoDS_Shape currentEdge = edgeExp.Current();
188 if ( !this->isEdgeRegisteredAsNM(currentEdge) ) {
189 result = Standard_False;
196 // ============================================================================
197 // Method : isEdgeRegisteredAsNM
198 // Purpose : Checks if the Edge passed is registered as non-manifold one
199 // ============================================================================
201 Standard_Boolean StepToTopoDS_NMTool::isEdgeRegisteredAsNM(const TopoDS_Shape& Edge) {
202 Standard_Boolean result = Standard_False;
203 TopTools_ListIteratorOfListOfShape it(myNMEdges);
204 for ( ; it.More(); it.Next() ) {
205 TopoDS_Shape currentShape = it.Value();
206 if ( currentShape.IsSame(Edge) ) {
207 result = Standard_True;
214 // ============================================================================
215 // Method : isAdjacentShell
216 // Purpose : Checks if the ShellA is adjacent to the ShellB
217 // ============================================================================
219 Standard_Boolean StepToTopoDS_NMTool::isAdjacentShell(const TopoDS_Shape& ShellA,
220 const TopoDS_Shape& ShellB) {
221 if ( ShellA.IsSame(ShellB) )
222 return Standard_False;
224 TopExp_Explorer edgeExpA(ShellA, TopAbs_EDGE);
225 for ( ; edgeExpA.More(); edgeExpA.Next() ) {
226 TopoDS_Shape currentEdgeA = edgeExpA.Current();
227 TopExp_Explorer edgeExpB(ShellB, TopAbs_EDGE);
228 for ( ; edgeExpB.More(); edgeExpB.Next() ) {
229 TopoDS_Shape currentEdgeB = edgeExpB.Current();
230 if ( currentEdgeA.IsSame(currentEdgeB) )
231 return Standard_True;
235 return Standard_False;