b311480e |
1 | // Created on: 1999-04-27 |
2 | // Created by: Pavel DURANDIN |
3 | // Copyright (c) 1999-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <ShapeFix_WireSegment.ixx> |
18 | #include <ShapeAnalysis_Edge.hxx> |
19 | #include <TopoDS_Edge.hxx> |
20 | |
21 | //======================================================================= |
22 | //function : ShapeFix_WireSegment |
23 | //purpose : |
24 | //======================================================================= |
25 | |
26 | ShapeFix_WireSegment::ShapeFix_WireSegment() |
27 | { |
28 | Clear(); |
29 | myOrient = TopAbs_FORWARD; |
30 | } |
31 | |
32 | //======================================================================= |
33 | //function : ShapeFix_WireSegment |
34 | //purpose : |
35 | //======================================================================= |
36 | |
37 | ShapeFix_WireSegment::ShapeFix_WireSegment(const Handle(ShapeExtend_WireData)& wire, |
38 | const TopAbs_Orientation ori) |
39 | { |
40 | Load ( wire ); |
41 | myOrient = ori; |
42 | } |
43 | |
44 | //======================================================================= |
45 | //function : Clear |
46 | //purpose : |
47 | //======================================================================= |
48 | |
49 | void ShapeFix_WireSegment::Clear() |
50 | { |
51 | myWire = new ShapeExtend_WireData; |
52 | myWire->ManifoldMode() = Standard_False; |
53 | myIUMin = new TColStd_HSequenceOfInteger; |
54 | myIUMax = new TColStd_HSequenceOfInteger; |
55 | myIVMin = new TColStd_HSequenceOfInteger; |
56 | myIVMax = new TColStd_HSequenceOfInteger; |
57 | myVertex = TopoDS_Vertex(); |
58 | } |
59 | |
60 | //======================================================================= |
61 | //function : Load |
62 | //purpose : |
63 | //======================================================================= |
64 | |
65 | void ShapeFix_WireSegment::Load (const Handle(ShapeExtend_WireData)& wire) |
66 | { |
67 | // myWire = wire; |
68 | Clear(); |
69 | myWire->ManifoldMode() = wire->ManifoldMode(); |
70 | for ( Standard_Integer i=1; i <= wire->NbEdges(); i++ ) |
71 | AddEdge ( i, wire->Edge(i) ); |
72 | } |
73 | |
74 | //======================================================================= |
75 | //function : WireData |
76 | //purpose : |
77 | //======================================================================= |
78 | |
79 | const Handle(ShapeExtend_WireData)& ShapeFix_WireSegment::WireData() const |
80 | { |
81 | return myWire; |
82 | } |
83 | |
84 | //======================================================================= |
85 | //function : Orientation |
86 | //purpose : |
87 | //======================================================================= |
88 | |
89 | void ShapeFix_WireSegment::Orientation(const TopAbs_Orientation ori) |
90 | { |
91 | myOrient = ori; |
92 | } |
93 | |
94 | //======================================================================= |
95 | //function : Orientation |
96 | //purpose : |
97 | //======================================================================= |
98 | |
99 | TopAbs_Orientation ShapeFix_WireSegment::Orientation() const |
100 | { |
101 | return myOrient; |
102 | } |
103 | |
104 | //======================================================================= |
105 | //function : FirstVertex |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | TopoDS_Vertex ShapeFix_WireSegment::FirstVertex() const |
110 | { |
111 | ShapeAnalysis_Edge sae; |
112 | return sae.FirstVertex (myWire->Edge(1)); |
113 | } |
114 | |
115 | //======================================================================= |
116 | //function : LastVertex |
117 | //purpose : |
118 | //======================================================================= |
119 | |
120 | TopoDS_Vertex ShapeFix_WireSegment::LastVertex() const |
121 | { |
122 | ShapeAnalysis_Edge sae; |
123 | return sae.LastVertex (myWire->Edge(myWire->NbEdges())); |
124 | } |
125 | |
126 | //======================================================================= |
127 | //function : IsClosed |
128 | //purpose : |
129 | //======================================================================= |
130 | |
131 | Standard_Boolean ShapeFix_WireSegment::IsClosed() const |
132 | { |
133 | TopoDS_Vertex v; |
134 | v = FirstVertex(); |
135 | return v.IsSame(LastVertex()); |
136 | } |
137 | |
138 | //======================================================================= |
139 | // WORK with EDGES and PATCH INDICES |
140 | //======================================================================= |
141 | |
142 | #define MININD -32000 |
143 | #define MAXIND 32000 |
144 | |
145 | //======================================================================= |
146 | //function : NbEdges |
147 | //purpose : |
148 | //======================================================================= |
149 | |
150 | Standard_Integer ShapeFix_WireSegment::NbEdges() const |
151 | { |
152 | return myWire->NbEdges(); |
153 | } |
154 | |
155 | //======================================================================= |
156 | //function : Edge |
157 | //purpose : |
158 | //======================================================================= |
159 | |
160 | TopoDS_Edge ShapeFix_WireSegment::Edge (const Standard_Integer i) const |
161 | { |
162 | |
163 | return myWire->Edge(i); |
164 | } |
165 | |
166 | //======================================================================= |
167 | //function : SetEdge |
168 | //purpose : |
169 | //======================================================================= |
170 | |
171 | void ShapeFix_WireSegment::SetEdge (const Standard_Integer i, |
172 | const TopoDS_Edge &edge) |
173 | { |
174 | myWire->Set ( edge, i ); |
175 | } |
176 | |
177 | //======================================================================= |
178 | //function : AddEdge |
179 | //purpose : |
180 | //======================================================================= |
181 | |
182 | void ShapeFix_WireSegment::AddEdge (const Standard_Integer i, |
183 | const TopoDS_Edge &edge) |
184 | { |
185 | AddEdge ( i, edge, MININD, MAXIND, MININD, MAXIND ); |
186 | } |
187 | |
188 | //======================================================================= |
189 | //function : AddEdge |
190 | //purpose : |
191 | //======================================================================= |
192 | |
193 | void ShapeFix_WireSegment::AddEdge (const Standard_Integer i, |
194 | const TopoDS_Edge &edge, |
195 | const Standard_Integer iumin, |
196 | const Standard_Integer iumax, |
197 | const Standard_Integer ivmin, |
198 | const Standard_Integer ivmax) |
199 | { |
200 | myWire->Add ( edge, i ); |
201 | if ( i ==0 ) { |
202 | myIUMin->Append ( iumin ); |
203 | myIUMax->Append ( iumax ); |
204 | myIVMin->Append ( ivmin ); |
205 | myIVMax->Append ( ivmax ); |
206 | } |
207 | else { |
208 | myIUMin->InsertBefore ( i, iumin ); |
209 | myIUMax->InsertBefore ( i, iumax ); |
210 | myIVMin->InsertBefore ( i, ivmin ); |
211 | myIVMax->InsertBefore ( i, ivmax ); |
212 | } |
213 | } |
214 | |
215 | //======================================================================= |
216 | //function : SetPatchIndex |
217 | //purpose : |
218 | //======================================================================= |
219 | |
220 | void ShapeFix_WireSegment::SetPatchIndex (const Standard_Integer i, |
221 | const Standard_Integer iumin, |
222 | const Standard_Integer iumax, |
223 | const Standard_Integer ivmin, |
224 | const Standard_Integer ivmax) |
225 | { |
226 | myIUMin->SetValue ( i, iumin ); |
227 | myIUMax->SetValue ( i, iumax ); |
228 | myIVMin->SetValue ( i, ivmin ); |
229 | myIVMax->SetValue ( i, ivmax ); |
230 | } |
231 | |
232 | //======================================================================= |
233 | //function : DefineIUMin |
234 | //purpose : |
235 | //======================================================================= |
236 | |
237 | void ShapeFix_WireSegment::DefineIUMin (const Standard_Integer i, |
238 | const Standard_Integer iumin) |
239 | { |
240 | if ( myIUMin->Value(i) < iumin ) myIUMin->SetValue ( i, iumin ); |
63c629aa |
241 | #ifdef SHAPEFIX_DEB |
7fd59977 |
242 | if ( myIUMin->Value(i) > myIUMax->Value(i) ) |
243 | cout << "Warning: ShapeFix_WireSegment::DefineIUMin: indexation error" << endl; |
244 | #endif |
245 | } |
246 | |
247 | //======================================================================= |
248 | //function : DefineIUMax |
249 | //purpose : |
250 | //======================================================================= |
251 | |
252 | void ShapeFix_WireSegment::DefineIUMax (const Standard_Integer i, |
253 | const Standard_Integer iumax) |
254 | { |
255 | if ( myIUMax->Value(i) > iumax ) myIUMax->SetValue ( i, iumax ); |
63c629aa |
256 | #ifdef SHAPEFIX_DEB |
7fd59977 |
257 | Standard_Integer iun = myIUMin->Value(i), iux = myIUMax->Value(i); |
258 | if ( iun > iux ) |
259 | cout << "Warning: ShapeFix_WireSegment::DefineIUMax: indexation error" << endl; |
260 | #endif |
261 | } |
262 | |
263 | //======================================================================= |
264 | //function : DefineIVMin |
265 | //purpose : |
266 | //======================================================================= |
267 | |
268 | void ShapeFix_WireSegment::DefineIVMin (const Standard_Integer i, |
269 | const Standard_Integer ivmin) |
270 | { |
271 | if ( myIVMin->Value(i) < ivmin ) myIVMin->SetValue ( i, ivmin ); |
63c629aa |
272 | #ifdef SHAPEFIX_DEB |
7fd59977 |
273 | Standard_Integer ivn = myIVMin->Value(i), ivx = myIVMax->Value(i); |
274 | if ( ivn > ivx ) |
275 | cout << "Warning: ShapeFix_WireSegment::DefineIVMin: indexation error" << endl; |
276 | #endif |
277 | } |
278 | |
279 | //======================================================================= |
280 | //function : DefineIVMax |
281 | //purpose : |
282 | //======================================================================= |
283 | |
284 | void ShapeFix_WireSegment::DefineIVMax (const Standard_Integer i, |
285 | const Standard_Integer ivmax) |
286 | { |
287 | if ( myIVMax->Value(i) > ivmax ) myIVMax->SetValue ( i, ivmax ); |
63c629aa |
288 | #ifdef SHAPEFIX_DEB |
7fd59977 |
289 | Standard_Integer ivn = myIVMin->Value(i), ivx = myIVMax->Value(i); |
290 | if ( ivn > ivx ) |
291 | cout << "Warning: ShapeFix_WireSegment::DefineIVMax: indexation error" << endl; |
292 | #endif |
293 | } |
294 | |
295 | //======================================================================= |
296 | //function : GetPatchIndex |
297 | //purpose : |
298 | //======================================================================= |
299 | |
300 | void ShapeFix_WireSegment::GetPatchIndex (const Standard_Integer i, |
301 | Standard_Integer &iumin, |
302 | Standard_Integer &iumax, |
303 | Standard_Integer &ivmin, |
304 | Standard_Integer &ivmax) const |
305 | { |
306 | iumin = myIUMin->Value(i); |
307 | iumax = myIUMax->Value(i); |
308 | ivmin = myIVMin->Value(i); |
309 | ivmax = myIVMax->Value(i); |
310 | } |
311 | |
312 | //======================================================================= |
313 | //function : CheckPatchIndex |
314 | //purpose : |
315 | //======================================================================= |
316 | |
317 | Standard_Boolean ShapeFix_WireSegment::CheckPatchIndex (const Standard_Integer i) const |
318 | { |
319 | Standard_Integer dU = myIUMax->Value(i) - myIUMin->Value(i); |
320 | Standard_Integer dV = myIVMax->Value(i) - myIVMin->Value(i); |
321 | Standard_Boolean ok = ( dU ==0 || dU ==1 ) && ( dV ==0 || dV ==1 ); |
63c629aa |
322 | #ifdef SHAPEFIX_DEB |
7fd59977 |
323 | if ( ! ok ) |
324 | cout << "Warning: ShapeFix_WireSegment::CheckPatchIndex: incomplete indexation" << endl; |
325 | #endif |
326 | return ok; |
327 | } |
328 | |
329 | //======================================================================= |
330 | //function : SetVertex |
331 | //purpose : |
332 | //======================================================================= |
333 | |
334 | void ShapeFix_WireSegment::SetVertex(const TopoDS_Vertex& theVertex) |
335 | { |
336 | myVertex = theVertex; |
337 | //SetVertex(theVertex, MININD, MAXIND, MININD, MAXIND); |
338 | } |
339 | |
340 | /*//======================================================================= |
341 | //function : SetVertex |
342 | //purpose : |
343 | //======================================================================= |
344 | |
345 | void ShapeFix_WireSegment::SetVertex(const TopoDS_Vertex& theVertex, |
346 | Standard_Integer iumin, |
347 | Standard_Integer iumax, |
348 | Standard_Integer ivmin, |
349 | Standard_Integer ivmax) |
350 | myVertex = theVertex; |
351 | myIUMin->Append ( iumin ); |
352 | myIUMax->Append ( iumax ); |
353 | myIVMin->Append ( ivmin ); |
354 | myIVMax->Append ( ivmax ); |
355 | } |
356 | */ |
357 | //======================================================================= |
358 | //function : GetVertex |
359 | //purpose : |
360 | //======================================================================= |
361 | |
362 | TopoDS_Vertex ShapeFix_WireSegment::GetVertex() const |
363 | { |
364 | return myVertex; |
365 | } |
366 | |
367 | //======================================================================= |
368 | //function : IsVertex |
369 | //purpose : |
370 | //======================================================================= |
371 | |
372 | Standard_Boolean ShapeFix_WireSegment::IsVertex() const |
373 | { |
374 | return !myVertex.IsNull(); |
375 | } |