342436d3583804ed04a072cf1c61b71c451b3322
[occt.git] / src / TopoDS / TopoDS_TShape.hxx
1 // Created on: 1990-12-13
2 // Created by: Remi Lequette
3 // Copyright (c) 1990-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 _TopoDS_TShape_HeaderFile
18 #define _TopoDS_TShape_HeaderFile
19
20 #include <Standard_Type.hxx>
21 #include <TopAbs.hxx>
22 #include <TopAbs_ShapeEnum.hxx>
23 #include <TopoDS_ListOfShape.hxx>
24
25 class TopoDS_Iterator;
26 class TopoDS_Builder;
27
28 // resolve name collisions with X11 headers
29 #ifdef Convex
30   #undef Convex
31 #endif
32
33 //! A TShape  is a topological  structure describing a
34 //! set of points in a 2D or 3D space.
35 //!
36 //! A topological shape is a structure made from other
37 //! shapes.  This is a deferred class  used to support
38 //! topological objects.
39 //!
40 //! TShapes are   defined   by  their  optional domain
41 //! (geometry)  and  their  components  (other TShapes
42 //! with  Locations and Orientations).  The components
43 //! are stored in a List of Shapes.
44 //!
45 //! A   TShape contains  the   following boolean flags :
46 //!
47 //! - Free       : Free or Frozen.
48 //! - Modified   : Has been modified.
49 //! - Checked    : Has been checked.
50 //! - Orientable : Can be oriented.
51 //! - Closed     : Is closed (note that only Wires and Shells may be closed).
52 //! - Infinite   : Is infinite.
53 //! - Convex     : Is convex.
54 //!
55 //! Users have no direct access to the classes derived
56 //! from TShape.  They  handle them with   the classes
57 //! derived from Shape.
58 class TopoDS_TShape : public Standard_Transient
59 {
60
61 public:
62
63   //! Returns the free flag.
64   Standard_Boolean Free() const { return ((myFlags & TopoDS_TShape_Flags_Free) != 0); }
65
66   //! Sets the free flag.
67   void Free (Standard_Boolean theIsFree) { setFlag (TopoDS_TShape_Flags_Free, theIsFree); }
68
69   //! Returns the locked flag.
70   Standard_Boolean Locked() const { return ((myFlags & TopoDS_TShape_Flags_Locked) != 0); }
71
72   //! Sets the locked flag.
73   void Locked (Standard_Boolean theIsLocked) { setFlag (TopoDS_TShape_Flags_Locked, theIsLocked); }
74
75   //! Returns the modification flag.
76   Standard_Boolean Modified() const { return ((myFlags & TopoDS_TShape_Flags_Modified) != 0); }
77
78   //! Sets the modification flag.
79   void Modified (Standard_Boolean theIsModified)
80   {
81     setFlag (TopoDS_TShape_Flags_Modified, theIsModified);
82     if (theIsModified)
83     {
84       setFlag (TopoDS_TShape_Flags_Checked, false); // when a TShape is modified it is also unchecked
85     }
86   }
87
88   //! Returns the checked flag.
89   Standard_Boolean Checked() const { return ((myFlags & TopoDS_TShape_Flags_Checked) != 0); }
90
91   //! Sets the checked flag.
92   void Checked (Standard_Boolean theIsChecked) { setFlag (TopoDS_TShape_Flags_Checked, theIsChecked); }
93
94   //! Returns the orientability flag.
95   Standard_Boolean Orientable() const { return ((myFlags & TopoDS_TShape_Flags_Orientable) != 0); }
96
97   //! Sets the orientability flag.
98   void Orientable (Standard_Boolean theIsOrientable) { setFlag (TopoDS_TShape_Flags_Orientable, theIsOrientable); }
99
100   //! Returns the closedness flag.
101   Standard_Boolean Closed() const { return ((myFlags & TopoDS_TShape_Flags_Closed) != 0); }
102
103   //! Sets the closedness flag.
104   void Closed (Standard_Boolean theIsClosed) { setFlag (TopoDS_TShape_Flags_Closed, theIsClosed); }
105
106   //! Returns the infinity flag.
107   Standard_Boolean Infinite() const { return ((myFlags & TopoDS_TShape_Flags_Infinite) != 0); }
108
109   //! Sets the infinity flag.
110   void Infinite (Standard_Boolean theIsInfinite) { setFlag (TopoDS_TShape_Flags_Infinite, theIsInfinite); }
111
112   //! Returns the convexness flag.
113   Standard_Boolean Convex() const { return ((myFlags & TopoDS_TShape_Flags_Convex) != 0); }
114
115   //! Sets the convexness flag.
116   void Convex (Standard_Boolean theIsConvex) { setFlag (TopoDS_TShape_Flags_Convex, theIsConvex); }
117
118   //! Returns the type as a term of the ShapeEnum enum :
119   //! VERTEX, EDGE, WIRE, FACE, ....
120   Standard_EXPORT virtual TopAbs_ShapeEnum ShapeType() const = 0;
121   
122   //! Returns a copy  of the  TShape  with no sub-shapes.
123   Standard_EXPORT virtual Handle(TopoDS_TShape) EmptyCopy() const = 0;
124
125   //! Returns the number of direct sub-shapes (children).
126   //! @sa TopoDS_Iterator for accessing sub-shapes
127   Standard_Integer NbChildren() const { return myShapes.Size(); }
128
129   //! Dumps the content of me into the stream
130   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth = -1) const;
131
132 friend class TopoDS_Iterator;
133 friend class TopoDS_Builder;
134
135
136   DEFINE_STANDARD_RTTIEXT(TopoDS_TShape,Standard_Transient)
137
138 protected:
139
140   //! Constructs an empty TShape.
141   //! Free       : True
142   //! Modified   : True
143   //! Checked    : False
144   //! Orientable : True
145   //! Closed     : False
146   //! Infinite   : False
147   //! Convex     : False
148   TopoDS_TShape()
149   : myFlags (TopoDS_TShape_Flags_Free
150            | TopoDS_TShape_Flags_Modified
151            | TopoDS_TShape_Flags_Orientable) {}
152
153 private:
154
155   // Defined mask values
156   enum TopoDS_TShape_Flags
157   {
158     TopoDS_TShape_Flags_Free       = 0x001,
159     TopoDS_TShape_Flags_Modified   = 0x002,
160     TopoDS_TShape_Flags_Checked    = 0x004,
161     TopoDS_TShape_Flags_Orientable = 0x008,
162     TopoDS_TShape_Flags_Closed     = 0x010,
163     TopoDS_TShape_Flags_Infinite   = 0x020,
164     TopoDS_TShape_Flags_Convex     = 0x040,
165     TopoDS_TShape_Flags_Locked     = 0x080
166   };
167
168   //! Set bit flag.
169   void setFlag (TopoDS_TShape_Flags theFlag,
170                 Standard_Boolean    theIsOn)
171   {
172     if (theIsOn) myFlags |=  (Standard_Integer )theFlag;
173     else         myFlags &= ~(Standard_Integer )theFlag;
174   }
175
176 private:
177
178   TopoDS_ListOfShape myShapes;
179   Standard_Integer   myFlags;
180 };
181
182 DEFINE_STANDARD_HANDLE(TopoDS_TShape, Standard_Transient)
183
184 #endif // _TopoDS_TShape_HeaderFile