summaryrefslogtreecommitdiff
path: root/src/StepToTopoDS/StepToTopoDS_NMTool.cxx
blob: b20eb6790f86cf9b4d0e890b09d1e0f1fd0b6a47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// File:	StepToTopoDS_NMTool.cxx
// Created:	Mon Nov 15 11:00:00 2010
// Author:	Sergey SLYADNEV
//		<sergey.slyadnev@opencascade.com>

#include <StepToTopoDS_NMTool.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS_Shape.hxx>

// ============================================================================
// Method  : StepToTopoDS_NMTool
// Purpose : Default constructor
// ============================================================================

StepToTopoDS_NMTool::StepToTopoDS_NMTool() {
  myIDEASCase = Standard_False;
  myActiveFlag = Standard_False;
}

// ============================================================================
// Method  : StepToTopoDS_NMTool
// Purpose : Constructor with a Map for Representation Items and their names
// ============================================================================

StepToTopoDS_NMTool::StepToTopoDS_NMTool(const StepToTopoDS_DataMapOfRI& MapOfRI, 
                                         const StepToTopoDS_DataMapOfRINames& MapOfRINames) {
  myIDEASCase = Standard_False;
  myActiveFlag = Standard_False;
  Init(MapOfRI, MapOfRINames);
}

// ============================================================================
// Method  : Init
// Purpose : Initializes internal maps of the tool with the passed ones
// ============================================================================

void StepToTopoDS_NMTool::Init(const StepToTopoDS_DataMapOfRI& MapOfRI, 
                               const StepToTopoDS_DataMapOfRINames& MapOfRINames) { 
  myRIMap = MapOfRI;
  myRINamesMap = MapOfRINames;
}

// ============================================================================
// Method  : SetActive
// Purpose : Turns the tool ON/OFF (OFF by default)
// ============================================================================

void StepToTopoDS_NMTool::SetActive(const Standard_Boolean isActive) {
  myActiveFlag = isActive;
}

// ============================================================================
// Method  : IsActive
// Purpose : TRUE if active, FALSE - otherwise
// ============================================================================

Standard_Boolean StepToTopoDS_NMTool::IsActive() {
  return myActiveFlag;
}

// ============================================================================
// Method  : CleanUp
// Purpose : Clears all internal containers
// ============================================================================

void StepToTopoDS_NMTool::CleanUp() { 
  myRIMap.Clear();
  myRINamesMap.Clear();
}

// ============================================================================
// Method  : IsBound
// Purpose : Indicates weither a RI is bound or not in the Map
// ============================================================================

Standard_Boolean StepToTopoDS_NMTool::IsBound(const Handle(StepRepr_RepresentationItem)& RI) {
  return myRIMap.IsBound(RI);
}

// ============================================================================
// Method  : IsBound
// Purpose : Indicates weither a RI is bound or not in the Map by name
// ============================================================================

Standard_Boolean StepToTopoDS_NMTool::IsBound(const TCollection_AsciiString& RIName) {
  return myRINamesMap.IsBound(RIName);
}

// ============================================================================
// Method  : Bind
// Purpose : Binds a RI with a Shape in the Map
// ============================================================================

void StepToTopoDS_NMTool::Bind(const Handle(StepRepr_RepresentationItem)& RI, const TopoDS_Shape& S) {
  myRIMap.Bind(RI, S);
}

// ============================================================================
// Method  : Bind
// Purpose : Binds a RI's name with a Shape in the Map
// ============================================================================

void StepToTopoDS_NMTool::Bind(const TCollection_AsciiString& RIName, const TopoDS_Shape& S) {
  myRINamesMap.Bind(RIName, S);
}

// ============================================================================
// Method  : Find
// Purpose : Returns the Shape corresponding to the bounded RI
// ============================================================================

const TopoDS_Shape& StepToTopoDS_NMTool::Find(const Handle(StepRepr_RepresentationItem)& RI) {
  return myRIMap.Find(RI);
}

// ============================================================================
// Method  : Find
// Purpose : Returns the Shape corresponding to the bounded RI's name
// ============================================================================

const TopoDS_Shape& StepToTopoDS_NMTool::Find(const TCollection_AsciiString& RIName) {
  return myRINamesMap.Find(RIName);
}

// ============================================================================
// Method  : RegisterNMEdge
// Purpose : Register non-manifold Edge in the internal storage if it wasn't
//           registered before
// ============================================================================

void StepToTopoDS_NMTool::RegisterNMEdge(const TopoDS_Shape& Edge) {
  if ( !this->isEdgeRegisteredAsNM(Edge) )
    myNMEdges.Append(Edge);
}

// ============================================================================
// Method  : IsSuspectedAsClosing
// Purpose : Checks whether SuspectedShell is pure non-manifold and adjacent
//           to BaseShell
// ============================================================================

Standard_Boolean StepToTopoDS_NMTool::IsSuspectedAsClosing(const TopoDS_Shape& BaseShell,
                                                           const TopoDS_Shape& SuspectedShell) {
  return this->IsPureNMShell(SuspectedShell) &&
         this->isAdjacentShell(BaseShell, SuspectedShell);

}

// ============================================================================
// Method  : SetIDEASCase
// Purpose : Sets myIDEASCase flag (I-DEAS-like STP is processed)
// ============================================================================

void StepToTopoDS_NMTool::SetIDEASCase(const Standard_Boolean IDEASCase) {
  myIDEASCase = IDEASCase;
}

// ============================================================================
// Method  : GetIDEASCase
// Purpose : Gets myIDEASCase flag (I-DEAS-like STP is processed)
// ============================================================================

Standard_Boolean StepToTopoDS_NMTool::IsIDEASCase() {
  return myIDEASCase;
}

// ============================================================================
// Method  : IsPureNMShell
// Purpose : Checks if the Shell passed contains only non-manifold Edges
// ============================================================================

Standard_Boolean StepToTopoDS_NMTool::IsPureNMShell(const TopoDS_Shape& Shell) {
  Standard_Boolean result = Standard_True;
  TopExp_Explorer edgeExp(Shell, TopAbs_EDGE);
  for ( ; edgeExp.More(); edgeExp.Next() ) {
    TopoDS_Shape currentEdge = edgeExp.Current();
    if ( !this->isEdgeRegisteredAsNM(currentEdge) ) {
      result = Standard_False;
      break;
    }    
  }
  return result;
}

// ============================================================================
// Method  : isEdgeRegisteredAsNM
// Purpose : Checks if the Edge passed is registered as non-manifold one
// ============================================================================

Standard_Boolean StepToTopoDS_NMTool::isEdgeRegisteredAsNM(const TopoDS_Shape& Edge) {
  Standard_Boolean result = Standard_False;
  TopTools_ListIteratorOfListOfShape it(myNMEdges);
  for ( ; it.More(); it.Next() ) {
    TopoDS_Shape currentShape = it.Value();
    if ( currentShape.IsSame(Edge) ) {
      result =  Standard_True;
      break;
    }
  }
  return result;
}

// ============================================================================
// Method  : isAdjacentShell
// Purpose : Checks if the ShellA is adjacent to the ShellB
// ============================================================================

Standard_Boolean StepToTopoDS_NMTool::isAdjacentShell(const TopoDS_Shape& ShellA,
                                                      const TopoDS_Shape& ShellB) {
  if ( ShellA.IsSame(ShellB) )
    return Standard_False;

  TopExp_Explorer edgeExpA(ShellA, TopAbs_EDGE);
  for ( ; edgeExpA.More(); edgeExpA.Next() ) {
    TopoDS_Shape currentEdgeA = edgeExpA.Current();
    TopExp_Explorer edgeExpB(ShellB, TopAbs_EDGE);
    for ( ; edgeExpB.More(); edgeExpB.Next() ) {
      TopoDS_Shape currentEdgeB = edgeExpB.Current();
      if ( currentEdgeA.IsSame(currentEdgeB) )
        return Standard_True;
    }  
  }

  return Standard_False;
}