0024157: Parallelization of assembly part of BO
[occt.git] / src / StepToTopoDS / StepToTopoDS_NMTool.cxx
1 // Created on: 2010-11-15
2 // Created by: Sergey SLYADNEV
3 // Copyright (c) 2010-2012 OPEN CASCADE SAS
4 //
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.
9 //
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.
12 //
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.
19
20
21 #include <StepToTopoDS_NMTool.hxx>
22 #include <TopTools_ListIteratorOfListOfShape.hxx>
23 #include <TopExp_Explorer.hxx>
24 #include <TopoDS_Shape.hxx>
25
26 // ============================================================================
27 // Method  : StepToTopoDS_NMTool
28 // Purpose : Default constructor
29 // ============================================================================
30
31 StepToTopoDS_NMTool::StepToTopoDS_NMTool() {
32   myIDEASCase = Standard_False;
33   myActiveFlag = Standard_False;
34 }
35
36 // ============================================================================
37 // Method  : StepToTopoDS_NMTool
38 // Purpose : Constructor with a Map for Representation Items and their names
39 // ============================================================================
40
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);
46 }
47
48 // ============================================================================
49 // Method  : Init
50 // Purpose : Initializes internal maps of the tool with the passed ones
51 // ============================================================================
52
53 void StepToTopoDS_NMTool::Init(const StepToTopoDS_DataMapOfRI& MapOfRI, 
54                                const StepToTopoDS_DataMapOfRINames& MapOfRINames) { 
55   myRIMap = MapOfRI;
56   myRINamesMap = MapOfRINames;
57 }
58
59 // ============================================================================
60 // Method  : SetActive
61 // Purpose : Turns the tool ON/OFF (OFF by default)
62 // ============================================================================
63
64 void StepToTopoDS_NMTool::SetActive(const Standard_Boolean isActive) {
65   myActiveFlag = isActive;
66 }
67
68 // ============================================================================
69 // Method  : IsActive
70 // Purpose : TRUE if active, FALSE - otherwise
71 // ============================================================================
72
73 Standard_Boolean StepToTopoDS_NMTool::IsActive() {
74   return myActiveFlag;
75 }
76
77 // ============================================================================
78 // Method  : CleanUp
79 // Purpose : Clears all internal containers
80 // ============================================================================
81
82 void StepToTopoDS_NMTool::CleanUp() { 
83   myRIMap.Clear();
84   myRINamesMap.Clear();
85 }
86
87 // ============================================================================
88 // Method  : IsBound
89 // Purpose : Indicates weither a RI is bound or not in the Map
90 // ============================================================================
91
92 Standard_Boolean StepToTopoDS_NMTool::IsBound(const Handle(StepRepr_RepresentationItem)& RI) {
93   return myRIMap.IsBound(RI);
94 }
95
96 // ============================================================================
97 // Method  : IsBound
98 // Purpose : Indicates weither a RI is bound or not in the Map by name
99 // ============================================================================
100
101 Standard_Boolean StepToTopoDS_NMTool::IsBound(const TCollection_AsciiString& RIName) {
102   return myRINamesMap.IsBound(RIName);
103 }
104
105 // ============================================================================
106 // Method  : Bind
107 // Purpose : Binds a RI with a Shape in the Map
108 // ============================================================================
109
110 void StepToTopoDS_NMTool::Bind(const Handle(StepRepr_RepresentationItem)& RI, const TopoDS_Shape& S) {
111   myRIMap.Bind(RI, S);
112 }
113
114 // ============================================================================
115 // Method  : Bind
116 // Purpose : Binds a RI's name with a Shape in the Map
117 // ============================================================================
118
119 void StepToTopoDS_NMTool::Bind(const TCollection_AsciiString& RIName, const TopoDS_Shape& S) {
120   myRINamesMap.Bind(RIName, S);
121 }
122
123 // ============================================================================
124 // Method  : Find
125 // Purpose : Returns the Shape corresponding to the bounded RI
126 // ============================================================================
127
128 const TopoDS_Shape& StepToTopoDS_NMTool::Find(const Handle(StepRepr_RepresentationItem)& RI) {
129   return myRIMap.Find(RI);
130 }
131
132 // ============================================================================
133 // Method  : Find
134 // Purpose : Returns the Shape corresponding to the bounded RI's name
135 // ============================================================================
136
137 const TopoDS_Shape& StepToTopoDS_NMTool::Find(const TCollection_AsciiString& RIName) {
138   return myRINamesMap.Find(RIName);
139 }
140
141 // ============================================================================
142 // Method  : RegisterNMEdge
143 // Purpose : Register non-manifold Edge in the internal storage if it wasn't
144 //           registered before
145 // ============================================================================
146
147 void StepToTopoDS_NMTool::RegisterNMEdge(const TopoDS_Shape& Edge) {
148   if ( !this->isEdgeRegisteredAsNM(Edge) )
149     myNMEdges.Append(Edge);
150 }
151
152 // ============================================================================
153 // Method  : IsSuspectedAsClosing
154 // Purpose : Checks whether SuspectedShell is pure non-manifold and adjacent
155 //           to BaseShell
156 // ============================================================================
157
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);
162
163 }
164
165 // ============================================================================
166 // Method  : SetIDEASCase
167 // Purpose : Sets myIDEASCase flag (I-DEAS-like STP is processed)
168 // ============================================================================
169
170 void StepToTopoDS_NMTool::SetIDEASCase(const Standard_Boolean IDEASCase) {
171   myIDEASCase = IDEASCase;
172 }
173
174 // ============================================================================
175 // Method  : GetIDEASCase
176 // Purpose : Gets myIDEASCase flag (I-DEAS-like STP is processed)
177 // ============================================================================
178
179 Standard_Boolean StepToTopoDS_NMTool::IsIDEASCase() {
180   return myIDEASCase;
181 }
182
183 // ============================================================================
184 // Method  : IsPureNMShell
185 // Purpose : Checks if the Shell passed contains only non-manifold Edges
186 // ============================================================================
187
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;
195       break;
196     }    
197   }
198   return result;
199 }
200
201 // ============================================================================
202 // Method  : isEdgeRegisteredAsNM
203 // Purpose : Checks if the Edge passed is registered as non-manifold one
204 // ============================================================================
205
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;
213       break;
214     }
215   }
216   return result;
217 }
218
219 // ============================================================================
220 // Method  : isAdjacentShell
221 // Purpose : Checks if the ShellA is adjacent to the ShellB
222 // ============================================================================
223
224 Standard_Boolean StepToTopoDS_NMTool::isAdjacentShell(const TopoDS_Shape& ShellA,
225                                                       const TopoDS_Shape& ShellB) {
226   if ( ShellA.IsSame(ShellB) )
227     return Standard_False;
228
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;
237     }  
238   }
239
240   return Standard_False;
241 }