1 // Created on: 2010-11-15
2 // Created by: Sergey SLYADNEV
3 // Copyright (c) 2010-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <StepToTopoDS_NMTool.hxx>
22 #include <TopTools_ListIteratorOfListOfShape.hxx>
23 #include <TopExp_Explorer.hxx>
24 #include <TopoDS_Shape.hxx>
26 // ============================================================================
27 // Method : StepToTopoDS_NMTool
28 // Purpose : Default constructor
29 // ============================================================================
31 StepToTopoDS_NMTool::StepToTopoDS_NMTool() {
32 myIDEASCase = Standard_False;
33 myActiveFlag = Standard_False;
36 // ============================================================================
37 // Method : StepToTopoDS_NMTool
38 // Purpose : Constructor with a Map for Representation Items and their names
39 // ============================================================================
41 StepToTopoDS_NMTool::StepToTopoDS_NMTool(const StepToTopoDS_DataMapOfRI& MapOfRI,
42 const StepToTopoDS_DataMapOfRINames& MapOfRINames) {
43 myIDEASCase = Standard_False;
44 myActiveFlag = Standard_False;
45 Init(MapOfRI, MapOfRINames);
48 // ============================================================================
50 // Purpose : Initializes internal maps of the tool with the passed ones
51 // ============================================================================
53 void StepToTopoDS_NMTool::Init(const StepToTopoDS_DataMapOfRI& MapOfRI,
54 const StepToTopoDS_DataMapOfRINames& MapOfRINames) {
56 myRINamesMap = MapOfRINames;
59 // ============================================================================
61 // Purpose : Turns the tool ON/OFF (OFF by default)
62 // ============================================================================
64 void StepToTopoDS_NMTool::SetActive(const Standard_Boolean isActive) {
65 myActiveFlag = isActive;
68 // ============================================================================
70 // Purpose : TRUE if active, FALSE - otherwise
71 // ============================================================================
73 Standard_Boolean StepToTopoDS_NMTool::IsActive() {
77 // ============================================================================
79 // Purpose : Clears all internal containers
80 // ============================================================================
82 void StepToTopoDS_NMTool::CleanUp() {
87 // ============================================================================
89 // Purpose : Indicates weither a RI is bound or not in the Map
90 // ============================================================================
92 Standard_Boolean StepToTopoDS_NMTool::IsBound(const Handle(StepRepr_RepresentationItem)& RI) {
93 return myRIMap.IsBound(RI);
96 // ============================================================================
98 // Purpose : Indicates weither a RI is bound or not in the Map by name
99 // ============================================================================
101 Standard_Boolean StepToTopoDS_NMTool::IsBound(const TCollection_AsciiString& RIName) {
102 return myRINamesMap.IsBound(RIName);
105 // ============================================================================
107 // Purpose : Binds a RI with a Shape in the Map
108 // ============================================================================
110 void StepToTopoDS_NMTool::Bind(const Handle(StepRepr_RepresentationItem)& RI, const TopoDS_Shape& S) {
114 // ============================================================================
116 // Purpose : Binds a RI's name with a Shape in the Map
117 // ============================================================================
119 void StepToTopoDS_NMTool::Bind(const TCollection_AsciiString& RIName, const TopoDS_Shape& S) {
120 myRINamesMap.Bind(RIName, S);
123 // ============================================================================
125 // Purpose : Returns the Shape corresponding to the bounded RI
126 // ============================================================================
128 const TopoDS_Shape& StepToTopoDS_NMTool::Find(const Handle(StepRepr_RepresentationItem)& RI) {
129 return myRIMap.Find(RI);
132 // ============================================================================
134 // Purpose : Returns the Shape corresponding to the bounded RI's name
135 // ============================================================================
137 const TopoDS_Shape& StepToTopoDS_NMTool::Find(const TCollection_AsciiString& RIName) {
138 return myRINamesMap.Find(RIName);
141 // ============================================================================
142 // Method : RegisterNMEdge
143 // Purpose : Register non-manifold Edge in the internal storage if it wasn't
145 // ============================================================================
147 void StepToTopoDS_NMTool::RegisterNMEdge(const TopoDS_Shape& Edge) {
148 if ( !this->isEdgeRegisteredAsNM(Edge) )
149 myNMEdges.Append(Edge);
152 // ============================================================================
153 // Method : IsSuspectedAsClosing
154 // Purpose : Checks whether SuspectedShell is pure non-manifold and adjacent
156 // ============================================================================
158 Standard_Boolean StepToTopoDS_NMTool::IsSuspectedAsClosing(const TopoDS_Shape& BaseShell,
159 const TopoDS_Shape& SuspectedShell) {
160 return this->IsPureNMShell(SuspectedShell) &&
161 this->isAdjacentShell(BaseShell, SuspectedShell);
165 // ============================================================================
166 // Method : SetIDEASCase
167 // Purpose : Sets myIDEASCase flag (I-DEAS-like STP is processed)
168 // ============================================================================
170 void StepToTopoDS_NMTool::SetIDEASCase(const Standard_Boolean IDEASCase) {
171 myIDEASCase = IDEASCase;
174 // ============================================================================
175 // Method : GetIDEASCase
176 // Purpose : Gets myIDEASCase flag (I-DEAS-like STP is processed)
177 // ============================================================================
179 Standard_Boolean StepToTopoDS_NMTool::IsIDEASCase() {
183 // ============================================================================
184 // Method : IsPureNMShell
185 // Purpose : Checks if the Shell passed contains only non-manifold Edges
186 // ============================================================================
188 Standard_Boolean StepToTopoDS_NMTool::IsPureNMShell(const TopoDS_Shape& Shell) {
189 Standard_Boolean result = Standard_True;
190 TopExp_Explorer edgeExp(Shell, TopAbs_EDGE);
191 for ( ; edgeExp.More(); edgeExp.Next() ) {
192 TopoDS_Shape currentEdge = edgeExp.Current();
193 if ( !this->isEdgeRegisteredAsNM(currentEdge) ) {
194 result = Standard_False;
201 // ============================================================================
202 // Method : isEdgeRegisteredAsNM
203 // Purpose : Checks if the Edge passed is registered as non-manifold one
204 // ============================================================================
206 Standard_Boolean StepToTopoDS_NMTool::isEdgeRegisteredAsNM(const TopoDS_Shape& Edge) {
207 Standard_Boolean result = Standard_False;
208 TopTools_ListIteratorOfListOfShape it(myNMEdges);
209 for ( ; it.More(); it.Next() ) {
210 TopoDS_Shape currentShape = it.Value();
211 if ( currentShape.IsSame(Edge) ) {
212 result = Standard_True;
219 // ============================================================================
220 // Method : isAdjacentShell
221 // Purpose : Checks if the ShellA is adjacent to the ShellB
222 // ============================================================================
224 Standard_Boolean StepToTopoDS_NMTool::isAdjacentShell(const TopoDS_Shape& ShellA,
225 const TopoDS_Shape& ShellB) {
226 if ( ShellA.IsSame(ShellB) )
227 return Standard_False;
229 TopExp_Explorer edgeExpA(ShellA, TopAbs_EDGE);
230 for ( ; edgeExpA.More(); edgeExpA.Next() ) {
231 TopoDS_Shape currentEdgeA = edgeExpA.Current();
232 TopExp_Explorer edgeExpB(ShellB, TopAbs_EDGE);
233 for ( ; edgeExpB.More(); edgeExpB.Next() ) {
234 TopoDS_Shape currentEdgeB = edgeExpB.Current();
235 if ( currentEdgeA.IsSame(currentEdgeB) )
236 return Standard_True;
240 return Standard_False;