42cf5bc1 |
1 | // Created on: 1998-06-03 |
2 | // Created by: data exchange team |
3 | // Copyright (c) 1998-1999 Matra Datavision |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
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. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _ShapeExtend_WireData_HeaderFile |
18 | #define _ShapeExtend_WireData_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_Type.hxx> |
22 | |
23 | #include <TopTools_HSequenceOfShape.hxx> |
24 | #include <TColStd_HSequenceOfInteger.hxx> |
25 | #include <Standard_Integer.hxx> |
25e59720 |
26 | #include <Standard_Transient.hxx> |
42cf5bc1 |
27 | class TopoDS_Wire; |
28 | class TopoDS_Edge; |
29 | class TopoDS_Shape; |
30 | class TopoDS_Face; |
31 | |
32 | |
33 | class ShapeExtend_WireData; |
25e59720 |
34 | DEFINE_STANDARD_HANDLE(ShapeExtend_WireData, Standard_Transient) |
42cf5bc1 |
35 | |
36 | //! This class provides a data structure necessary for work with the wire as with |
37 | //! ordered list of edges, what is required for many algorithms. The advantage of |
38 | //! this class is that it allows to work with wires which are not correct. |
39 | //! The object of the class ShapeExtend_WireData can be initialized by |
40 | //! TopoDS_Wire, and converted back to TopoDS_Wire. |
41 | //! An edge in the wire is defined by its rank number. Operations of accessing, |
42 | //! adding and removing edge at the given rank number are provided. On the whole |
43 | //! wire, operations of circular permutation and reversing (both orientations of |
44 | //! all edges and order of edges) are provided as well. |
45 | //! This class also provides a method to check if the edge in the wire is a seam |
46 | //! (if the wire lies on a face). |
47 | //! This class is handled by reference. Such an approach gives the following advantages: |
48 | //! 1. Sharing the object of this class strongly optimizes the processes of |
49 | //! analysis and fixing performed in parallel on the wire stored in the form |
50 | //! of this class. Fixing tool (e.g. ShapeFix_Wire) fixes problems one by |
51 | //! one using analyzing tool (e.g. ShapeAnalysis_Wire). Sharing allows not |
52 | //! to reinitialize each time the analyzing tool with modified |
53 | //! ShapeExtend_WireData what consumes certain time. |
54 | //! 2. No copying of contents. The object of ShapeExtend_WireData class has |
55 | //! quite big size, returning it as a result of the function would cause |
56 | //! additional copying of contents if this class were one handled by value. |
57 | //! Moreover, this class is stored as a field in other classes which are |
58 | //! they returned as results of functions, storing only a handle to |
59 | //! ShapeExtend_WireData saves time and memory. |
25e59720 |
60 | class ShapeExtend_WireData : public Standard_Transient |
42cf5bc1 |
61 | { |
62 | |
63 | public: |
64 | |
316ea293 |
65 | |
42cf5bc1 |
66 | //! Empty constructor, creates empty wire with no edges |
67 | Standard_EXPORT ShapeExtend_WireData(); |
316ea293 |
68 | |
42cf5bc1 |
69 | //! Constructor initializing the data from TopoDS_Wire. Calls Init(wire,chained). |
70 | Standard_EXPORT ShapeExtend_WireData(const TopoDS_Wire& wire, const Standard_Boolean chained = Standard_True, const Standard_Boolean theManifoldMode = Standard_True); |
316ea293 |
71 | |
42cf5bc1 |
72 | //! Copies data from another WireData |
73 | Standard_EXPORT void Init (const Handle(ShapeExtend_WireData)& other); |
316ea293 |
74 | |
42cf5bc1 |
75 | //! Loads an already existing wire |
76 | //! If <chained> is True (default), edges are added in the |
77 | //! sequence as they are explored by TopoDS_Iterator |
78 | //! Else, if <chained> is False, wire is explored by |
79 | //! BRepTools_WireExplorer and it is guaranteed that edges will |
316ea293 |
80 | //! be sequentially connected. |
42cf5bc1 |
81 | //! Remark : In the latter case it can happen that not all edges |
82 | //! will be found (because of limitations of |
83 | //! BRepTools_WireExplorer for disconnected wires and wires |
84 | //! with seam edges). |
85 | Standard_EXPORT Standard_Boolean Init (const TopoDS_Wire& wire, const Standard_Boolean chained = Standard_True, const Standard_Boolean theManifoldMode = Standard_True); |
316ea293 |
86 | |
42cf5bc1 |
87 | //! Clears data about Wire. |
88 | Standard_EXPORT void Clear(); |
316ea293 |
89 | |
42cf5bc1 |
90 | //! Computes the list of seam edges |
91 | //! By default (direct call), computing is enforced |
92 | //! For indirect call (from IsSeam) it is redone only if not yet |
93 | //! already done or if the list of edges has changed |
94 | //! Remark : A Seam Edge is an Edge present twice in the list, once as |
95 | //! FORWARD and once as REVERSED |
96 | //! Each sense has its own PCurve, the one for FORWARD |
97 | //! must be set in first |
98 | Standard_EXPORT void ComputeSeams (const Standard_Boolean enforce = Standard_True); |
316ea293 |
99 | |
42cf5bc1 |
100 | //! Does a circular permutation in order to set <num>th edge last |
101 | Standard_EXPORT void SetLast (const Standard_Integer num); |
316ea293 |
102 | |
42cf5bc1 |
103 | //! When the wire contains at least one degenerated edge, sets it |
104 | //! as last one |
105 | //! Note : It is useful to process pcurves, for instance, while the pcurve |
106 | //! of a DGNR may not be computed from its 3D part (there is none) |
107 | //! it is computed after the other edges have been computed and |
108 | //! chained. |
109 | Standard_EXPORT void SetDegeneratedLast(); |
316ea293 |
110 | |
42cf5bc1 |
111 | //! Adds an edge to a wire, being defined (not yet ended) |
112 | //! This is the plain, basic, function to add an edge |
113 | //! <num> = 0 (D): Appends at end |
114 | //! <num> = 1: Preprends at start |
115 | //! else, Insert before <num> |
116 | //! Remark : Null Edge is simply ignored |
117 | Standard_EXPORT void Add (const TopoDS_Edge& edge, const Standard_Integer atnum = 0); |
316ea293 |
118 | |
42cf5bc1 |
119 | //! Adds an entire wire, considered as a list of edges |
120 | //! Remark : The wire is assumed to be ordered (TopoDS_Iterator |
121 | //! is used) |
122 | Standard_EXPORT void Add (const TopoDS_Wire& wire, const Standard_Integer atnum = 0); |
316ea293 |
123 | |
42cf5bc1 |
124 | //! Adds a wire in the form of WireData |
125 | Standard_EXPORT void Add (const Handle(ShapeExtend_WireData)& wire, const Standard_Integer atnum = 0); |
316ea293 |
126 | |
42cf5bc1 |
127 | //! Adds an edge or a wire invoking corresponding method Add |
128 | Standard_EXPORT void Add (const TopoDS_Shape& shape, const Standard_Integer atnum = 0); |
316ea293 |
129 | |
42cf5bc1 |
130 | //! Adds an edge to start or end of <me>, according to <mode> |
131 | //! 0: at end, as direct |
132 | //! 1: at end, as reversed |
133 | //! 2: at start, as direct |
134 | //! 3: at start, as reversed |
135 | //! < 0: no adding |
136 | Standard_EXPORT void AddOriented (const TopoDS_Edge& edge, const Standard_Integer mode); |
316ea293 |
137 | |
42cf5bc1 |
138 | //! Adds a wire to start or end of <me>, according to <mode> |
139 | //! 0: at end, as direct |
140 | //! 1: at end, as reversed |
141 | //! 2: at start, as direct |
142 | //! 3: at start, as reversed |
143 | //! < 0: no adding |
144 | Standard_EXPORT void AddOriented (const TopoDS_Wire& wire, const Standard_Integer mode); |
316ea293 |
145 | |
42cf5bc1 |
146 | //! Adds an edge or a wire invoking corresponding method |
147 | //! AddOriented |
148 | Standard_EXPORT void AddOriented (const TopoDS_Shape& shape, const Standard_Integer mode); |
316ea293 |
149 | |
42cf5bc1 |
150 | //! Removes an Edge, given its rank. By default removes the last edge. |
151 | Standard_EXPORT void Remove (const Standard_Integer num = 0); |
316ea293 |
152 | |
42cf5bc1 |
153 | //! Replaces an edge at the given |
154 | //! rank number <num> with new one. Default is last edge (<num> = 0). |
155 | Standard_EXPORT void Set (const TopoDS_Edge& edge, const Standard_Integer num = 0); |
316ea293 |
156 | |
42cf5bc1 |
157 | //! Reverses the sense of the list and the orientation of each Edge |
158 | //! This method should be called when either wire has no seam edges |
159 | //! or face is not available |
160 | Standard_EXPORT void Reverse(); |
316ea293 |
161 | |
42cf5bc1 |
162 | //! Reverses the sense of the list and the orientation of each Edge |
163 | //! The face is necessary for swapping pcurves for seam edges |
164 | //! (first pcurve corresponds to orientation FORWARD, and second to |
165 | //! REVERSED; when edge is reversed, pcurves must be swapped) |
166 | //! If face is NULL, no swapping is performed |
167 | Standard_EXPORT void Reverse (const TopoDS_Face& face); |
316ea293 |
168 | |
42cf5bc1 |
169 | //! Returns the count of currently recorded edges |
170 | Standard_EXPORT Standard_Integer NbEdges() const; |
316ea293 |
171 | |
42cf5bc1 |
172 | //! Returns the count of currently recorded non-manifold edges |
173 | Standard_EXPORT Standard_Integer NbNonManifoldEdges() const; |
316ea293 |
174 | |
42cf5bc1 |
175 | //! Returns <num>th nonmanifold Edge |
176 | Standard_EXPORT TopoDS_Edge NonmanifoldEdge (const Standard_Integer num) const; |
316ea293 |
177 | |
42cf5bc1 |
178 | //! Returns sequence of non-manifold edges |
179 | //! This sequence can be not empty if wire data set in manifold mode but |
180 | //! initial wire has INTERNAL orientation or contains INTERNAL edges |
181 | Standard_EXPORT Handle(TopTools_HSequenceOfShape) NonmanifoldEdges() const; |
316ea293 |
182 | |
42cf5bc1 |
183 | //! Returns mode defining manifold wire data or not. |
184 | //! If manifold that nonmanifold edges will not be not |
185 | //! consider during operations(previous behaviour) |
186 | //! and they will be added only in result wire |
187 | //! else non-manifold edges will consider during operations |
188 | Standard_EXPORT Standard_Boolean& ManifoldMode(); |
316ea293 |
189 | |
42cf5bc1 |
190 | //! Returns <num>th Edge |
191 | Standard_EXPORT TopoDS_Edge Edge (const Standard_Integer num) const; |
316ea293 |
192 | |
42cf5bc1 |
193 | //! Returns the index of the edge |
194 | //! If the edge is a seam the orientation is also checked |
195 | //! Returns 0 if the edge is not found in the list |
196 | Standard_EXPORT Standard_Integer Index (const TopoDS_Edge& edge); |
316ea293 |
197 | |
42cf5bc1 |
198 | //! Tells if an Edge is seam (see ComputeSeams) |
199 | //! An edge is considered as seam if it presents twice in |
200 | //! the edge list, once as FORWARD and once as REVERSED. |
201 | Standard_EXPORT Standard_Boolean IsSeam (const Standard_Integer num); |
316ea293 |
202 | |
42cf5bc1 |
203 | //! Makes TopoDS_Wire using |
204 | //! BRep_Builder (just creates the TopoDS_Wire object and adds |
205 | //! all edges into it). This method should be called when |
206 | //! the wire is correct (for example, after successful |
207 | //! fixes by ShapeFix_Wire) and adjacent edges share common |
208 | //! vertices. In case if adjacent edges do not share the same |
209 | //! vertices the resulting TopoDS_Wire will be invalid. |
210 | Standard_EXPORT TopoDS_Wire Wire() const; |
316ea293 |
211 | |
42cf5bc1 |
212 | //! Makes TopoDS_Wire using |
213 | //! BRepAPI_MakeWire. Class BRepAPI_MakeWire merges |
214 | //! geometrically coincided vertices and can disturb |
215 | //! correct order of edges in the wire. If this class fails, |
216 | //! null shape is returned. |
217 | Standard_EXPORT TopoDS_Wire WireAPIMake() const; |
218 | |
219 | |
220 | |
221 | |
25e59720 |
222 | DEFINE_STANDARD_RTTIEXT(ShapeExtend_WireData,Standard_Transient) |
42cf5bc1 |
223 | |
224 | protected: |
225 | |
226 | |
227 | |
228 | |
229 | private: |
230 | |
231 | |
232 | Handle(TopTools_HSequenceOfShape) myEdges; |
233 | Handle(TopTools_HSequenceOfShape) myNonmanifoldEdges; |
234 | Handle(TColStd_HSequenceOfInteger) mySeams; |
235 | Standard_Integer mySeamF; |
236 | Standard_Integer mySeamR; |
237 | Standard_Boolean myManifoldMode; |
238 | |
239 | |
240 | }; |
241 | |
242 | |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | #endif // _ShapeExtend_WireData_HeaderFile |