0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / ShapeFix / ShapeFix_Face.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 _ShapeFix_Face_HeaderFile
18 #define _ShapeFix_Face_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <TopoDS_Face.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <Standard_Integer.hxx>
26 #include <ShapeFix_Root.hxx>
27 #include <TopTools_DataMapOfShapeListOfShape.hxx>
28 #include <TopTools_SequenceOfShape.hxx>
29 #include <ShapeFix_DataMapOfShapeBox2d.hxx>
30 #include <ShapeExtend_Status.hxx>
31 class ShapeAnalysis_Surface;
32 class ShapeFix_Wire;
33 class Geom_Surface;
34 class ShapeExtend_BasicMsgRegistrator;
35 class TopoDS_Wire;
36 class ShapeExtend_WireData;
37 class TopoDS_Vertex;
38
39 // resolve name collisions with X11 headers
40 #ifdef Status
41   #undef Status
42 #endif
43
44 class ShapeFix_Face;
45 DEFINE_STANDARD_HANDLE(ShapeFix_Face, ShapeFix_Root)
46
47 //! This operator allows to perform various fixes on face
48 //! and its wires: fixes provided by ShapeFix_Wire,
49 //! fixing orientation of wires, addition of natural bounds,
50 //! fixing of missing seam edge,
51 //! and detection and removal of null-area wires
52 class ShapeFix_Face : public ShapeFix_Root
53 {
54
55 public:
56
57   
58   //! Creates an empty tool
59   Standard_EXPORT ShapeFix_Face();
60   
61   //! Creates a tool and loads a face
62   Standard_EXPORT ShapeFix_Face(const TopoDS_Face& face);
63   
64   //! Sets all modes to default
65   Standard_EXPORT virtual void ClearModes();
66   
67   //! Loads a whole face already created, with its wires, sense and
68   //! location
69   Standard_EXPORT void Init (const TopoDS_Face& face);
70   
71   //! Starts the creation of the face
72   //! By default it will be FORWARD, or REVERSED if <fwd> is False
73   Standard_EXPORT void Init (const Handle(Geom_Surface)& surf, const Standard_Real preci, const Standard_Boolean fwd = Standard_True);
74   
75   //! Starts the creation of the face
76   //! By default it will be FORWARD, or REVERSED if <fwd> is False
77   Standard_EXPORT void Init (const Handle(ShapeAnalysis_Surface)& surf, const Standard_Real preci, const Standard_Boolean fwd = Standard_True);
78   
79   //! Sets message registrator
80   Standard_EXPORT virtual void SetMsgRegistrator (const Handle(ShapeExtend_BasicMsgRegistrator)& msgreg) Standard_OVERRIDE;
81   
82   //! Sets basic precision value (also to FixWireTool)
83   Standard_EXPORT virtual void SetPrecision (const Standard_Real preci) Standard_OVERRIDE;
84   
85   //! Sets minimal allowed tolerance (also to FixWireTool)
86   Standard_EXPORT virtual void SetMinTolerance (const Standard_Real mintol) Standard_OVERRIDE;
87   
88   //! Sets maximal allowed tolerance (also to FixWireTool)
89   Standard_EXPORT virtual void SetMaxTolerance (const Standard_Real maxtol) Standard_OVERRIDE;
90   
91   //! Returns (modifiable) the mode for applying fixes of
92   //! ShapeFix_Wire, by default True.
93     Standard_Integer& FixWireMode();
94   
95   //! Returns (modifiable) the fix orientation mode, by default
96   //! True. If True, wires oriented to border limited square.
97     Standard_Integer& FixOrientationMode();
98   
99   //! Returns (modifiable) the add natural bound mode.
100   //! If true, natural boundary is added on faces that miss them.
101   //! Default is False for faces with single wire (they are
102   //! handled by FixOrientation in that case) and True for others.
103     Standard_Integer& FixAddNaturalBoundMode();
104   
105   //! Returns (modifiable) the fix missing seam mode, by default
106   //! True. If True, tries to insert seam is missed.
107     Standard_Integer& FixMissingSeamMode();
108   
109   //! Returns (modifiable) the fix small area wire mode, by default
110   //! False. If True, drops small wires.
111     Standard_Integer& FixSmallAreaWireMode();
112   
113   //! Returns (modifiable) the remove face with small area, by default
114   //! False. If True, drops faces with small outer wires.
115     Standard_Integer& RemoveSmallAreaFaceMode();
116   
117   //! Returns (modifiable) the fix intersecting wires mode
118   //! by default True.
119     Standard_Integer& FixIntersectingWiresMode();
120   
121   //! Returns (modifiable) the fix loop wires mode
122   //! by default True.
123     Standard_Integer& FixLoopWiresMode();
124   
125   //! Returns (modifiable) the fix split face mode
126   //! by default True.
127     Standard_Integer& FixSplitFaceMode();
128   
129   //! Returns (modifiable) the auto-correct precision mode
130   //! by default False.
131     Standard_Integer& AutoCorrectPrecisionMode();
132   
133   //! Returns (modifiable) the activation flag for periodic
134   //! degenerated fix. False by default.
135     Standard_Integer& FixPeriodicDegeneratedMode();
136   
137   //! Returns a face which corresponds to the current state
138   //! Warning: The finally produced face may be another one ... but with the
139   //! same support
140     TopoDS_Face Face() const;
141   
142   //! Returns resulting shape (Face or Shell if split)
143   //! To be used instead of Face() if FixMissingSeam involved
144     TopoDS_Shape Result() const;
145   
146   //! Add a wire to current face using BRep_Builder.
147   //! Wire is added without taking into account orientation of face
148   //! (as if face were FORWARD).
149   Standard_EXPORT void Add (const TopoDS_Wire& wire);
150   
151   //! Performs all the fixes, depending on modes
152   //! Function Status returns the status of last call to Perform()
153   //! ShapeExtend_OK   : face was OK, nothing done
154   //! ShapeExtend_DONE1: some wires are fixed
155   //! ShapeExtend_DONE2: orientation of wires fixed
156   //! ShapeExtend_DONE3: missing seam added
157   //! ShapeExtend_DONE4: small area wire removed
158   //! ShapeExtend_DONE5: natural bounds added
159   //! ShapeExtend_FAIL1: some fails during fixing wires
160   //! ShapeExtend_FAIL2: cannot fix orientation of wires
161   //! ShapeExtend_FAIL3: cannot add missing seam
162   //! ShapeExtend_FAIL4: cannot remove small area wire
163   Standard_EXPORT Standard_Boolean Perform();
164   
165   //! Fixes orientation of wires on the face
166   //! It tries to make all wires lie outside all others (according
167   //! to orientation) by reversing orientation of some of them.
168   //! If face lying on sphere or torus has single wire and
169   //! AddNaturalBoundMode is True, that wire is not reversed in
170   //! any case (supposing that natural bound will be added).
171   //! Returns True if wires were reversed
172   Standard_EXPORT Standard_Boolean FixOrientation();
173   
174   //! Fixes orientation of wires on the face
175   //! It tries to make all wires lie outside all others (according
176   //! to orientation) by reversing orientation of some of them.
177   //! If face lying on sphere or torus has single wire and
178   //! AddNaturalBoundMode is True, that wire is not reversed in
179   //! any case (supposing that natural bound will be added).
180   //! Returns True if wires were reversed
181   //! OutWires return information about out wires + list of
182   //! internal wires for each (for performing split face).
183   Standard_EXPORT Standard_Boolean FixOrientation (TopTools_DataMapOfShapeListOfShape& MapWires);
184   
185   //! Adds natural boundary on face if it is missing.
186   //! Two cases are supported:
187   //! - face has no wires
188   //! - face lies on geometrically double-closed surface
189   //! (sphere or torus) and none of wires is left-oriented
190   //! Returns True if natural boundary was added
191   Standard_EXPORT Standard_Boolean FixAddNaturalBound();
192   
193   //! Detects and fixes the special case when face on a closed
194   //! surface is given by two wires closed in 3d but with gap in 2d.
195   //! In that case it creates a new wire from the two, and adds a
196   //! missing seam edge
197   //! Returns True if missing seam was added
198   Standard_EXPORT Standard_Boolean FixMissingSeam();
199   
200   //! Detects wires with small area (that is less than
201   //! 100*Precision::PConfusion(). Removes these wires if they are internal.
202   //! Returns : True if at least one small wire removed,
203   //! False if does nothing.
204   Standard_EXPORT Standard_Boolean FixSmallAreaWire (const Standard_Boolean theIsRemoveSmallFace);
205   
206   //! Detects if wire has a loop and fixes this situation by splitting on the few parts.
207   //! if wire has a loops and it was split Status was set to value ShapeExtend_DONE6.
208   Standard_EXPORT Standard_Boolean FixLoopWire (TopTools_SequenceOfShape& aResWires);
209   
210   //! Detects and fixes the special case when face has more than one wire
211   //! and this wires have intersection point
212   Standard_EXPORT Standard_Boolean FixIntersectingWires();
213   
214   //! If wire contains two coincidence edges it must be removed
215   //! Queries on status after Perform()
216   Standard_EXPORT Standard_Boolean FixWiresTwoCoincEdges();
217   
218   //! Split face if there are more than one out wire
219   //! using inrormation after FixOrientation()
220   Standard_EXPORT Standard_Boolean FixSplitFace (const TopTools_DataMapOfShapeListOfShape& MapWires);
221   
222   //! Fixes topology for a specific case when face is composed
223   //! by a single wire belting a periodic surface. In that case
224   //! a degenerated edge is reconstructed in the degenerated pole
225   //! of the surface. Initial wire gets consistent orientation.
226   //! Must be used in couple and before FixMissingSeam routine
227   Standard_EXPORT Standard_Boolean FixPeriodicDegenerated();
228   
229   //! Returns the status of last call to Perform()
230   //! ShapeExtend_OK   : face was OK, nothing done
231   //! ShapeExtend_DONE1: some wires are fixed
232   //! ShapeExtend_DONE2: orientation of wires fixed
233   //! ShapeExtend_DONE3: missing seam added
234   //! ShapeExtend_DONE4: small area wire removed
235   //! ShapeExtend_DONE5: natural bounds added
236   //! ShapeExtend_DONE8: face may be splited
237   //! ShapeExtend_FAIL1: some fails during fixing wires
238   //! ShapeExtend_FAIL2: cannot fix orientation of wires
239   //! ShapeExtend_FAIL3: cannot add missing seam
240   //! ShapeExtend_FAIL4: cannot remove small area wire
241     Standard_Boolean Status (const ShapeExtend_Status status) const;
242   
243   //! Returns tool for fixing wires.
244     Handle(ShapeFix_Wire) FixWireTool();
245
246
247
248
249   DEFINE_STANDARD_RTTIEXT(ShapeFix_Face,ShapeFix_Root)
250
251 protected:
252
253
254   Handle(ShapeAnalysis_Surface) mySurf;
255   TopoDS_Face myFace;
256   TopoDS_Shape myResult;
257   Handle(ShapeFix_Wire) myFixWire;
258   Standard_Boolean myFwd;
259   Standard_Integer myStatus;
260
261
262 private:
263
264   //! Returns True if the face needs to add natural bound and corresponded option of shape healing is ON
265   Standard_Boolean isNeedAddNaturalBound(const TopTools_SequenceOfShape& theOrientedWires);
266
267   Standard_EXPORT Standard_Boolean SplitEdge (const Handle(ShapeExtend_WireData)& sewd, const Standard_Integer num, const Standard_Real param, const TopoDS_Vertex& vert, const Standard_Real preci, ShapeFix_DataMapOfShapeBox2d& boxes);
268   
269   Standard_EXPORT Standard_Boolean SplitEdge (const Handle(ShapeExtend_WireData)& sewd, const Standard_Integer num, const Standard_Real param1, const Standard_Real param2, const TopoDS_Vertex& vert, const Standard_Real preci, ShapeFix_DataMapOfShapeBox2d& boxes);
270
271   Standard_Integer myFixWireMode;
272   Standard_Integer myFixOrientationMode;
273   Standard_Integer myFixAddNaturalBoundMode;
274   Standard_Integer myFixMissingSeamMode;
275   Standard_Integer myFixSmallAreaWireMode;
276   Standard_Integer myRemoveSmallAreaFaceMode;
277   Standard_Integer myFixLoopWiresMode;
278   Standard_Integer myFixIntersectingWiresMode;
279   Standard_Integer myFixSplitFaceMode;
280   Standard_Integer myAutoCorrectPrecisionMode;
281   Standard_Integer myFixPeriodicDegenerated;
282
283
284 };
285
286
287 #include <ShapeFix_Face.lxx>
288
289
290
291
292
293 #endif // _ShapeFix_Face_HeaderFile