0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / TopoDS / TopoDS_Shape.hxx
1 // Created on: 1990-12-11
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_Shape_HeaderFile
18 #define _TopoDS_Shape_HeaderFile
19
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
22 #include <TopAbs.hxx>
23 #include <TopAbs_Orientation.hxx>
24 #include <TopLoc_Location.hxx>
25 #include <TopoDS_TShape.hxx>
26
27 // resolve name collisions with X11 headers
28 #ifdef Convex
29   #undef Convex
30 #endif
31
32 //! Describes a shape which
33 //! - references an underlying shape with the potential
34 //! to be given a location and an orientation
35 //! - has a location for the underlying shape, giving its
36 //! placement in the local coordinate system
37 //! - has an orientation for the underlying shape, in
38 //! terms of its geometry (as opposed to orientation in
39 //! relation to other shapes).
40 //! Note: A Shape is empty if it references an underlying
41 //! shape which has an empty list of shapes.
42 class TopoDS_Shape 
43 {
44 public:
45
46   DEFINE_STANDARD_ALLOC
47
48   //! Creates a NULL Shape referring to nothing.
49   TopoDS_Shape() : myOrient (TopAbs_EXTERNAL) {}
50
51   //! Returns true if this shape is null. In other words, it
52   //! references no underlying shape with the potential to
53   //! be given a location and an orientation.
54   Standard_Boolean IsNull() const { return myTShape.IsNull(); }
55
56   //! Destroys the reference to the underlying shape
57   //! stored in this shape. As a result, this shape becomes null.
58   void Nullify() { myTShape.Nullify(); }
59
60   //! Returns the shape local coordinate system.
61   const TopLoc_Location& Location() const { return myLocation; }
62
63   //! Sets the shape local coordinate system.
64   void Location (const TopLoc_Location& theLoc) { myLocation = theLoc; }
65
66   //! Returns a  shape  similar to <me> with   the local
67   //! coordinate system set to <Loc>.
68   TopoDS_Shape Located (const TopLoc_Location& theLoc) const
69   {
70     TopoDS_Shape aShape (*this);
71     aShape.Location (theLoc);
72     return aShape;
73   }
74
75   //! Returns the shape orientation.
76   TopAbs_Orientation Orientation() const { return myOrient; }
77
78   //! Sets the shape orientation.
79   void Orientation (TopAbs_Orientation theOrient) { myOrient = theOrient; }
80
81   //! Returns  a    shape  similar  to  <me>   with  the
82   //! orientation set to <Or>.
83   TopoDS_Shape Oriented (TopAbs_Orientation theOrient) const
84   {
85     TopoDS_Shape aShape (*this);
86     aShape.Orientation (theOrient);
87     return aShape;
88   }
89
90   //! Returns a handle to the actual shape implementation.
91   const Handle(TopoDS_TShape)& TShape() const { return myTShape; }
92
93   //! Returns the value of the TopAbs_ShapeEnum
94   //! enumeration that corresponds to this shape, for
95   //! example VERTEX, EDGE, and so on.
96   //! Exceptions
97   //! Standard_NullObject if this shape is null.
98   TopAbs_ShapeEnum ShapeType() const { return myTShape->ShapeType(); }
99
100   //! Returns the free flag.
101   Standard_Boolean Free() const { return myTShape->Free(); }
102
103   //! Sets the free flag.
104   void Free (Standard_Boolean theIsFree) { myTShape->Free (theIsFree); }
105
106   //! Returns the locked flag.
107   Standard_Boolean Locked() const { return myTShape->Locked(); }
108
109   //! Sets the locked flag.
110   void Locked (Standard_Boolean theIsLocked) { myTShape->Locked (theIsLocked); }
111
112   //! Returns the modification flag.
113   Standard_Boolean Modified() const { return myTShape->Modified(); }
114
115   //! Sets the modification flag.
116   void Modified (Standard_Boolean theIsModified) { myTShape->Modified (theIsModified); }
117
118   //! Returns the checked flag.
119   Standard_Boolean Checked() const { return myTShape->Checked(); }
120
121   //! Sets the checked flag.
122   void Checked (Standard_Boolean theIsChecked) { myTShape->Checked (theIsChecked); }
123
124   //! Returns the orientability flag.
125   Standard_Boolean Orientable() const { return myTShape->Orientable(); }
126
127   //! Sets the orientability flag.
128   void Orientable (const Standard_Boolean theIsOrientable) { myTShape->Orientable (theIsOrientable); }
129
130   //! Returns the closedness flag.
131   Standard_Boolean Closed() const { return myTShape->Closed(); }
132
133   //! Sets the closedness flag.
134   void Closed (Standard_Boolean theIsClosed) { myTShape->Closed (theIsClosed); }
135
136   //! Returns the infinity flag.
137   Standard_Boolean Infinite() const { return myTShape->Infinite(); }
138
139   //! Sets the infinity flag.
140   void Infinite (Standard_Boolean theIsInfinite) { myTShape->Infinite (theIsInfinite); }
141
142   //! Returns the convexness flag.
143   Standard_Boolean Convex() const { return myTShape->Convex(); }
144
145   //! Sets the convexness flag.
146   void Convex (Standard_Boolean theIsConvex) { myTShape->Convex (theIsConvex); }
147
148   //! Multiplies the Shape location by thePosition.
149   void Move (const TopLoc_Location& thePosition) { myLocation = thePosition * myLocation; }
150
151   //! Returns a shape similar to <me> with a location multiplied by thePosition.
152   TopoDS_Shape Moved (const TopLoc_Location& thePosition) const
153   {
154     TopoDS_Shape aShape (*this);
155     aShape.Move (thePosition);
156     return aShape;
157   }
158
159   //! Reverses the orientation, using the Reverse method
160   //! from the TopAbs package.
161   void Reverse() { myOrient = TopAbs::Reverse (myOrient); }
162
163   //! Returns    a shape  similar    to  <me>  with  the
164   //! orientation  reversed, using  the   Reverse method
165   //! from the TopAbs package.
166   TopoDS_Shape Reversed() const
167   {
168     TopoDS_Shape aShape (*this);
169     aShape.Reverse();
170     return aShape;
171   }
172
173   //! Complements the orientation, using the  Complement
174   //! method from the TopAbs package.
175   void Complement() { myOrient = TopAbs::Complement (myOrient); }
176
177   //! Returns  a   shape  similar  to   <me>   with  the
178   //! orientation complemented,  using   the  Complement
179   //! method from the TopAbs package.
180   TopoDS_Shape Complemented() const
181   {
182     TopoDS_Shape aShape (*this);
183     aShape.Complement();
184     return aShape;
185   }
186
187   //! Updates the Shape Orientation by composition with theOrient,
188   //! using the Compose method from the TopAbs package.
189   void Compose (TopAbs_Orientation theOrient) { myOrient = TopAbs::Compose (myOrient, theOrient); }
190
191   //! Returns  a  shape   similar   to  <me>   with  the
192   //! orientation composed with theOrient, using the
193   //! Compose method from the TopAbs package.
194   TopoDS_Shape Composed (TopAbs_Orientation theOrient) const
195   {
196     TopoDS_Shape aShape (*this);
197     aShape.Compose (theOrient);
198     return aShape;
199   }
200
201   //! Returns the number of direct sub-shapes (children).
202   //! @sa TopoDS_Iterator for accessing sub-shapes
203   Standard_Integer NbChildren() const { return myTShape.IsNull() ? 0 : myTShape->NbChildren(); }
204
205   //! Returns True if two shapes  are partners, i.e.  if
206   //! they   share   the   same  TShape.  Locations  and
207   //! Orientations may differ.
208   Standard_Boolean IsPartner (const TopoDS_Shape& theOther) const { return (myTShape == theOther.myTShape); }
209
210   //! Returns True if two shapes are same, i.e.  if they
211   //! share  the  same TShape  with the same  Locations.
212   //! Orientations may differ.
213   Standard_Boolean IsSame (const TopoDS_Shape& theOther) const
214   {
215     return myTShape   == theOther.myTShape
216         && myLocation == theOther.myLocation;
217   }
218
219   //! Returns True if two shapes are equal, i.e. if they
220   //! share the same TShape with  the same Locations and
221   //! Orientations.
222   Standard_Boolean IsEqual (const TopoDS_Shape& theOther) const
223   {
224     return myTShape   == theOther.myTShape
225         && myLocation == theOther.myLocation
226         && myOrient   == theOther.myOrient;
227   }
228
229   Standard_Boolean operator == (const TopoDS_Shape& theOther) const { return IsEqual (theOther); }
230   
231   //! Negation of the IsEqual method.
232   Standard_Boolean IsNotEqual  (const TopoDS_Shape& theOther) const { return !IsEqual (theOther); }
233   Standard_Boolean operator != (const TopoDS_Shape& theOther) const { return IsNotEqual (theOther); }
234
235   //! Returns a hashed value denoting <me>. This value is in the range [1, theUpperBound]. It is computed from the
236   //! TShape and the Location. The Orientation is not used.
237   //! @param theUpperBound the upper bound of the range a computing hash code must be within
238   //! @return a computed hash code, in the range [1, theUpperBound]
239   Standard_EXPORT Standard_Integer HashCode (Standard_Integer theUpperBound) const;
240
241   //! Replace   <me> by  a  new   Shape with the    same
242   //! Orientation and Location and a new TShape with the
243   //! same geometry and no sub-shapes.
244   void EmptyCopy() { myTShape = myTShape->EmptyCopy(); }
245
246   //! Returns a new Shape with the  same Orientation and
247   //! Location and  a new TShape  with the same geometry
248   //! and no sub-shapes.
249   TopoDS_Shape EmptyCopied() const
250   {
251     TopoDS_Shape aShape (*this);
252     aShape.EmptyCopy();
253     return aShape;
254   }
255
256   void TShape (const Handle(TopoDS_TShape)& theTShape) { myTShape = theTShape; }
257
258 private:
259
260   Handle(TopoDS_TShape) myTShape;
261   TopLoc_Location myLocation;
262   TopAbs_Orientation myOrient;
263
264 };
265
266 //! Computes a hash code for the given shape, in the range [1, theUpperBound]
267 //! @param theShape the shape which hash code is to be computed
268 //! @param theUpperBound the upper bound of the range a computing hash code must be within
269 //! @return a computed hash code, in the range [1, theUpperBound]
270 inline Standard_Integer HashCode (const TopoDS_Shape& theShape, const Standard_Integer theUpperBound)
271 {
272   return theShape.HashCode (theUpperBound);
273 }
274
275 #endif // _TopoDS_Shape_HeaderFile