0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / TopoDS / TopoDS_Shape.hxx
CommitLineData
42cf5bc1 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
42cf5bc1 20#include <Standard_DefineAlloc.hxx>
21#include <Standard_Handle.hxx>
b2d1851c 22#include <TopAbs.hxx>
42cf5bc1 23#include <TopAbs_Orientation.hxx>
b2d1851c 24#include <TopLoc_Location.hxx>
25#include <TopoDS_TShape.hxx>
42cf5bc1 26
9fd2d2c3 27// resolve name collisions with X11 headers
28#ifdef Convex
29 #undef Convex
30#endif
42cf5bc1 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.
42class TopoDS_Shape
43{
44public:
45
46 DEFINE_STANDARD_ALLOC
47
42cf5bc1 48 //! Creates a NULL Shape referring to nothing.
b2d1851c 49 TopoDS_Shape() : myOrient (TopAbs_EXTERNAL) {}
50
42cf5bc1 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.
b2d1851c 54 Standard_Boolean IsNull() const { return myTShape.IsNull(); }
55
42cf5bc1 56 //! Destroys the reference to the underlying shape
57 //! stored in this shape. As a result, this shape becomes null.
b2d1851c 58 void Nullify() { myTShape.Nullify(); }
59
42cf5bc1 60 //! Returns the shape local coordinate system.
b2d1851c 61 const TopLoc_Location& Location() const { return myLocation; }
62
42cf5bc1 63 //! Sets the shape local coordinate system.
b2d1851c 64 void Location (const TopLoc_Location& theLoc) { myLocation = theLoc; }
65
42cf5bc1 66 //! Returns a shape similar to <me> with the local
67 //! coordinate system set to <Loc>.
b2d1851c 68 TopoDS_Shape Located (const TopLoc_Location& theLoc) const
69 {
70 TopoDS_Shape aShape (*this);
71 aShape.Location (theLoc);
72 return aShape;
73 }
74
42cf5bc1 75 //! Returns the shape orientation.
b2d1851c 76 TopAbs_Orientation Orientation() const { return myOrient; }
77
42cf5bc1 78 //! Sets the shape orientation.
b2d1851c 79 void Orientation (TopAbs_Orientation theOrient) { myOrient = theOrient; }
80
42cf5bc1 81 //! Returns a shape similar to <me> with the
82 //! orientation set to <Or>.
b2d1851c 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
42cf5bc1 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.
b2d1851c 98 TopAbs_ShapeEnum ShapeType() const { return myTShape->ShapeType(); }
99
42cf5bc1 100 //! Returns the free flag.
b2d1851c 101 Standard_Boolean Free() const { return myTShape->Free(); }
102
42cf5bc1 103 //! Sets the free flag.
b2d1851c 104 void Free (Standard_Boolean theIsFree) { myTShape->Free (theIsFree); }
105
42cf5bc1 106 //! Returns the locked flag.
b2d1851c 107 Standard_Boolean Locked() const { return myTShape->Locked(); }
108
42cf5bc1 109 //! Sets the locked flag.
b2d1851c 110 void Locked (Standard_Boolean theIsLocked) { myTShape->Locked (theIsLocked); }
111
42cf5bc1 112 //! Returns the modification flag.
b2d1851c 113 Standard_Boolean Modified() const { return myTShape->Modified(); }
114
42cf5bc1 115 //! Sets the modification flag.
b2d1851c 116 void Modified (Standard_Boolean theIsModified) { myTShape->Modified (theIsModified); }
117
42cf5bc1 118 //! Returns the checked flag.
b2d1851c 119 Standard_Boolean Checked() const { return myTShape->Checked(); }
120
42cf5bc1 121 //! Sets the checked flag.
b2d1851c 122 void Checked (Standard_Boolean theIsChecked) { myTShape->Checked (theIsChecked); }
123
42cf5bc1 124 //! Returns the orientability flag.
b2d1851c 125 Standard_Boolean Orientable() const { return myTShape->Orientable(); }
126
42cf5bc1 127 //! Sets the orientability flag.
b2d1851c 128 void Orientable (const Standard_Boolean theIsOrientable) { myTShape->Orientable (theIsOrientable); }
129
42cf5bc1 130 //! Returns the closedness flag.
b2d1851c 131 Standard_Boolean Closed() const { return myTShape->Closed(); }
132
42cf5bc1 133 //! Sets the closedness flag.
b2d1851c 134 void Closed (Standard_Boolean theIsClosed) { myTShape->Closed (theIsClosed); }
135
42cf5bc1 136 //! Returns the infinity flag.
b2d1851c 137 Standard_Boolean Infinite() const { return myTShape->Infinite(); }
138
42cf5bc1 139 //! Sets the infinity flag.
b2d1851c 140 void Infinite (Standard_Boolean theIsInfinite) { myTShape->Infinite (theIsInfinite); }
141
42cf5bc1 142 //! Returns the convexness flag.
b2d1851c 143 Standard_Boolean Convex() const { return myTShape->Convex(); }
144
42cf5bc1 145 //! Sets the convexness flag.
b2d1851c 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
42cf5bc1 159 //! Reverses the orientation, using the Reverse method
160 //! from the TopAbs package.
b2d1851c 161 void Reverse() { myOrient = TopAbs::Reverse (myOrient); }
162
42cf5bc1 163 //! Returns a shape similar to <me> with the
164 //! orientation reversed, using the Reverse method
165 //! from the TopAbs package.
b2d1851c 166 TopoDS_Shape Reversed() const
167 {
168 TopoDS_Shape aShape (*this);
169 aShape.Reverse();
170 return aShape;
171 }
172
42cf5bc1 173 //! Complements the orientation, using the Complement
174 //! method from the TopAbs package.
b2d1851c 175 void Complement() { myOrient = TopAbs::Complement (myOrient); }
176
42cf5bc1 177 //! Returns a shape similar to <me> with the
178 //! orientation complemented, using the Complement
179 //! method from the TopAbs package.
b2d1851c 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
42cf5bc1 191 //! Returns a shape similar to <me> with the
b2d1851c 192 //! orientation composed with theOrient, using the
42cf5bc1 193 //! Compose method from the TopAbs package.
b2d1851c 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
42cf5bc1 205 //! Returns True if two shapes are partners, i.e. if
206 //! they share the same TShape. Locations and
207 //! Orientations may differ.
b2d1851c 208 Standard_Boolean IsPartner (const TopoDS_Shape& theOther) const { return (myTShape == theOther.myTShape); }
209
42cf5bc1 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.
b2d1851c 213 Standard_Boolean IsSame (const TopoDS_Shape& theOther) const
214 {
215 return myTShape == theOther.myTShape
216 && myLocation == theOther.myLocation;
217 }
218
42cf5bc1 219 //! Returns True if two shapes are equal, i.e. if they
220 //! share the same TShape with the same Locations and
221 //! Orientations.
b2d1851c 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); }
42cf5bc1 230
231 //! Negation of the IsEqual method.
b2d1851c 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
2b2be3fb 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;
b2d1851c 240
42cf5bc1 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.
b2d1851c 244 void EmptyCopy() { myTShape = myTShape->EmptyCopy(); }
245
42cf5bc1 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.
b2d1851c 249 TopoDS_Shape EmptyCopied() const
250 {
251 TopoDS_Shape aShape (*this);
252 aShape.EmptyCopy();
253 return aShape;
254 }
42cf5bc1 255
b2d1851c 256 void TShape (const Handle(TopoDS_TShape)& theTShape) { myTShape = theTShape; }
42cf5bc1 257
258private:
259
42cf5bc1 260 Handle(TopoDS_TShape) myTShape;
261 TopLoc_Location myLocation;
262 TopAbs_Orientation myOrient;
263
42cf5bc1 264};
265
2b2be3fb 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]
270inline Standard_Integer HashCode (const TopoDS_Shape& theShape, const Standard_Integer theUpperBound)
271{
272 return theShape.HashCode (theUpperBound);
42cf5bc1 273}
274
42cf5bc1 275#endif // _TopoDS_Shape_HeaderFile