1 // Created on: 1999-04-27
2 // Created by: Pavel DURANDIN
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <ShapeAnalysis_Edge.hxx>
19 #include <ShapeExtend_WireData.hxx>
20 #include <ShapeFix_WireSegment.hxx>
21 #include <TopoDS_Edge.hxx>
22 #include <TopoDS_Vertex.hxx>
23 #include <TopoDS_Wire.hxx>
25 //=======================================================================
26 //function : ShapeFix_WireSegment
28 //=======================================================================
29 ShapeFix_WireSegment::ShapeFix_WireSegment()
32 myOrient = TopAbs_FORWARD;
35 //=======================================================================
36 //function : ShapeFix_WireSegment
38 //=======================================================================
40 ShapeFix_WireSegment::ShapeFix_WireSegment(const Handle(ShapeExtend_WireData)& wire,
41 const TopAbs_Orientation ori)
47 //=======================================================================
50 //=======================================================================
52 void ShapeFix_WireSegment::Clear()
54 myWire = new ShapeExtend_WireData;
55 myWire->ManifoldMode() = Standard_False;
56 myIUMin = new TColStd_HSequenceOfInteger;
57 myIUMax = new TColStd_HSequenceOfInteger;
58 myIVMin = new TColStd_HSequenceOfInteger;
59 myIVMax = new TColStd_HSequenceOfInteger;
60 myVertex = TopoDS_Vertex();
63 //=======================================================================
66 //=======================================================================
68 void ShapeFix_WireSegment::Load (const Handle(ShapeExtend_WireData)& wire)
72 myWire->ManifoldMode() = wire->ManifoldMode();
73 for ( Standard_Integer i=1; i <= wire->NbEdges(); i++ )
74 AddEdge ( i, wire->Edge(i) );
77 //=======================================================================
80 //=======================================================================
82 const Handle(ShapeExtend_WireData)& ShapeFix_WireSegment::WireData() const
87 //=======================================================================
88 //function : Orientation
90 //=======================================================================
92 void ShapeFix_WireSegment::Orientation(const TopAbs_Orientation ori)
97 //=======================================================================
98 //function : Orientation
100 //=======================================================================
102 TopAbs_Orientation ShapeFix_WireSegment::Orientation() const
107 //=======================================================================
108 //function : FirstVertex
110 //=======================================================================
112 TopoDS_Vertex ShapeFix_WireSegment::FirstVertex() const
114 ShapeAnalysis_Edge sae;
115 return sae.FirstVertex (myWire->Edge(1));
118 //=======================================================================
119 //function : LastVertex
121 //=======================================================================
123 TopoDS_Vertex ShapeFix_WireSegment::LastVertex() const
125 ShapeAnalysis_Edge sae;
126 return sae.LastVertex (myWire->Edge(myWire->NbEdges()));
129 //=======================================================================
130 //function : IsClosed
132 //=======================================================================
134 Standard_Boolean ShapeFix_WireSegment::IsClosed() const
138 return v.IsSame(LastVertex());
141 //=======================================================================
142 // WORK with EDGES and PATCH INDICES
143 //=======================================================================
145 #define MININD -32000
148 //=======================================================================
151 //=======================================================================
153 Standard_Integer ShapeFix_WireSegment::NbEdges() const
155 return myWire->NbEdges();
158 //=======================================================================
161 //=======================================================================
163 TopoDS_Edge ShapeFix_WireSegment::Edge (const Standard_Integer i) const
166 return myWire->Edge(i);
169 //=======================================================================
172 //=======================================================================
174 void ShapeFix_WireSegment::SetEdge (const Standard_Integer i,
175 const TopoDS_Edge &edge)
177 myWire->Set ( edge, i );
180 //=======================================================================
183 //=======================================================================
185 void ShapeFix_WireSegment::AddEdge (const Standard_Integer i,
186 const TopoDS_Edge &edge)
188 AddEdge ( i, edge, MININD, MAXIND, MININD, MAXIND );
191 //=======================================================================
194 //=======================================================================
196 void ShapeFix_WireSegment::AddEdge (const Standard_Integer i,
197 const TopoDS_Edge &edge,
198 const Standard_Integer iumin,
199 const Standard_Integer iumax,
200 const Standard_Integer ivmin,
201 const Standard_Integer ivmax)
203 myWire->Add ( edge, i );
205 myIUMin->Append ( iumin );
206 myIUMax->Append ( iumax );
207 myIVMin->Append ( ivmin );
208 myIVMax->Append ( ivmax );
211 myIUMin->InsertBefore ( i, iumin );
212 myIUMax->InsertBefore ( i, iumax );
213 myIVMin->InsertBefore ( i, ivmin );
214 myIVMax->InsertBefore ( i, ivmax );
218 //=======================================================================
219 //function : SetPatchIndex
221 //=======================================================================
223 void ShapeFix_WireSegment::SetPatchIndex (const Standard_Integer i,
224 const Standard_Integer iumin,
225 const Standard_Integer iumax,
226 const Standard_Integer ivmin,
227 const Standard_Integer ivmax)
229 myIUMin->SetValue ( i, iumin );
230 myIUMax->SetValue ( i, iumax );
231 myIVMin->SetValue ( i, ivmin );
232 myIVMax->SetValue ( i, ivmax );
235 //=======================================================================
236 //function : DefineIUMin
238 //=======================================================================
240 void ShapeFix_WireSegment::DefineIUMin (const Standard_Integer i,
241 const Standard_Integer iumin)
243 if ( myIUMin->Value(i) < iumin ) myIUMin->SetValue ( i, iumin );
245 if ( myIUMin->Value(i) > myIUMax->Value(i) )
246 cout << "Warning: ShapeFix_WireSegment::DefineIUMin: indexation error" << endl;
250 //=======================================================================
251 //function : DefineIUMax
253 //=======================================================================
255 void ShapeFix_WireSegment::DefineIUMax (const Standard_Integer i,
256 const Standard_Integer iumax)
258 if ( myIUMax->Value(i) > iumax ) myIUMax->SetValue ( i, iumax );
260 Standard_Integer iun = myIUMin->Value(i), iux = myIUMax->Value(i);
262 cout << "Warning: ShapeFix_WireSegment::DefineIUMax: indexation error" << endl;
266 //=======================================================================
267 //function : DefineIVMin
269 //=======================================================================
271 void ShapeFix_WireSegment::DefineIVMin (const Standard_Integer i,
272 const Standard_Integer ivmin)
274 if ( myIVMin->Value(i) < ivmin ) myIVMin->SetValue ( i, ivmin );
276 Standard_Integer ivn = myIVMin->Value(i), ivx = myIVMax->Value(i);
278 cout << "Warning: ShapeFix_WireSegment::DefineIVMin: indexation error" << endl;
282 //=======================================================================
283 //function : DefineIVMax
285 //=======================================================================
287 void ShapeFix_WireSegment::DefineIVMax (const Standard_Integer i,
288 const Standard_Integer ivmax)
290 if ( myIVMax->Value(i) > ivmax ) myIVMax->SetValue ( i, ivmax );
292 Standard_Integer ivn = myIVMin->Value(i), ivx = myIVMax->Value(i);
294 cout << "Warning: ShapeFix_WireSegment::DefineIVMax: indexation error" << endl;
298 //=======================================================================
299 //function : GetPatchIndex
301 //=======================================================================
303 void ShapeFix_WireSegment::GetPatchIndex (const Standard_Integer i,
304 Standard_Integer &iumin,
305 Standard_Integer &iumax,
306 Standard_Integer &ivmin,
307 Standard_Integer &ivmax) const
309 iumin = myIUMin->Value(i);
310 iumax = myIUMax->Value(i);
311 ivmin = myIVMin->Value(i);
312 ivmax = myIVMax->Value(i);
315 //=======================================================================
316 //function : CheckPatchIndex
318 //=======================================================================
320 Standard_Boolean ShapeFix_WireSegment::CheckPatchIndex (const Standard_Integer i) const
322 Standard_Integer dU = myIUMax->Value(i) - myIUMin->Value(i);
323 Standard_Integer dV = myIVMax->Value(i) - myIVMin->Value(i);
324 Standard_Boolean ok = ( dU ==0 || dU ==1 ) && ( dV ==0 || dV ==1 );
327 cout << "Warning: ShapeFix_WireSegment::CheckPatchIndex: incomplete indexation" << endl;
332 //=======================================================================
333 //function : SetVertex
335 //=======================================================================
337 void ShapeFix_WireSegment::SetVertex(const TopoDS_Vertex& theVertex)
339 myVertex = theVertex;
340 //SetVertex(theVertex, MININD, MAXIND, MININD, MAXIND);
343 /*//=======================================================================
344 //function : SetVertex
346 //=======================================================================
348 void ShapeFix_WireSegment::SetVertex(const TopoDS_Vertex& theVertex,
349 Standard_Integer iumin,
350 Standard_Integer iumax,
351 Standard_Integer ivmin,
352 Standard_Integer ivmax)
353 myVertex = theVertex;
354 myIUMin->Append ( iumin );
355 myIUMax->Append ( iumax );
356 myIVMin->Append ( ivmin );
357 myIVMax->Append ( ivmax );
360 //=======================================================================
361 //function : GetVertex
363 //=======================================================================
365 TopoDS_Vertex ShapeFix_WireSegment::GetVertex() const
370 //=======================================================================
371 //function : IsVertex
373 //=======================================================================
375 Standard_Boolean ShapeFix_WireSegment::IsVertex() const
377 return !myVertex.IsNull();