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