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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _TopoDS_Shape_HeaderFile
18 #define _TopoDS_Shape_HeaderFile
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
23 #include <TopAbs_Orientation.hxx>
24 #include <TopLoc_Location.hxx>
25 #include <TopoDS_TShape.hxx>
27 // resolve name collisions with X11 headers
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.
48 //! Creates a NULL Shape referring to nothing.
49 TopoDS_Shape() : myOrient (TopAbs_EXTERNAL) {}
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(); }
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(); }
60 //! Returns the shape local coordinate system.
61 const TopLoc_Location& Location() const { return myLocation; }
63 //! Sets the shape local coordinate system.
64 void Location (const TopLoc_Location& theLoc) { myLocation = theLoc; }
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
70 TopoDS_Shape aShape (*this);
71 aShape.Location (theLoc);
75 //! Returns the shape orientation.
76 TopAbs_Orientation Orientation() const { return myOrient; }
78 //! Sets the shape orientation.
79 void Orientation (TopAbs_Orientation theOrient) { myOrient = theOrient; }
81 //! Returns a shape similar to <me> with the
82 //! orientation set to <Or>.
83 TopoDS_Shape Oriented (TopAbs_Orientation theOrient) const
85 TopoDS_Shape aShape (*this);
86 aShape.Orientation (theOrient);
90 //! Returns a handle to the actual shape implementation.
91 const Handle(TopoDS_TShape)& TShape() const { return myTShape; }
93 //! Returns the value of the TopAbs_ShapeEnum
94 //! enumeration that corresponds to this shape, for
95 //! example VERTEX, EDGE, and so on.
97 //! Standard_NullObject if this shape is null.
98 TopAbs_ShapeEnum ShapeType() const { return myTShape->ShapeType(); }
100 //! Returns the free flag.
101 Standard_Boolean Free() const { return myTShape->Free(); }
103 //! Sets the free flag.
104 void Free (Standard_Boolean theIsFree) { myTShape->Free (theIsFree); }
106 //! Returns the locked flag.
107 Standard_Boolean Locked() const { return myTShape->Locked(); }
109 //! Sets the locked flag.
110 void Locked (Standard_Boolean theIsLocked) { myTShape->Locked (theIsLocked); }
112 //! Returns the modification flag.
113 Standard_Boolean Modified() const { return myTShape->Modified(); }
115 //! Sets the modification flag.
116 void Modified (Standard_Boolean theIsModified) { myTShape->Modified (theIsModified); }
118 //! Returns the checked flag.
119 Standard_Boolean Checked() const { return myTShape->Checked(); }
121 //! Sets the checked flag.
122 void Checked (Standard_Boolean theIsChecked) { myTShape->Checked (theIsChecked); }
124 //! Returns the orientability flag.
125 Standard_Boolean Orientable() const { return myTShape->Orientable(); }
127 //! Sets the orientability flag.
128 void Orientable (const Standard_Boolean theIsOrientable) { myTShape->Orientable (theIsOrientable); }
130 //! Returns the closedness flag.
131 Standard_Boolean Closed() const { return myTShape->Closed(); }
133 //! Sets the closedness flag.
134 void Closed (Standard_Boolean theIsClosed) { myTShape->Closed (theIsClosed); }
136 //! Returns the infinity flag.
137 Standard_Boolean Infinite() const { return myTShape->Infinite(); }
139 //! Sets the infinity flag.
140 void Infinite (Standard_Boolean theIsInfinite) { myTShape->Infinite (theIsInfinite); }
142 //! Returns the convexness flag.
143 Standard_Boolean Convex() const { return myTShape->Convex(); }
145 //! Sets the convexness flag.
146 void Convex (Standard_Boolean theIsConvex) { myTShape->Convex (theIsConvex); }
148 //! Multiplies the Shape location by thePosition.
149 void Move (const TopLoc_Location& thePosition) { myLocation = thePosition * myLocation; }
151 //! Returns a shape similar to <me> with a location multiplied by thePosition.
152 TopoDS_Shape Moved (const TopLoc_Location& thePosition) const
154 TopoDS_Shape aShape (*this);
155 aShape.Move (thePosition);
159 //! Reverses the orientation, using the Reverse method
160 //! from the TopAbs package.
161 void Reverse() { myOrient = TopAbs::Reverse (myOrient); }
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
168 TopoDS_Shape aShape (*this);
173 //! Complements the orientation, using the Complement
174 //! method from the TopAbs package.
175 void Complement() { myOrient = TopAbs::Complement (myOrient); }
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
182 TopoDS_Shape aShape (*this);
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); }
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
196 TopoDS_Shape aShape (*this);
197 aShape.Compose (theOrient);
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(); }
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); }
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
215 return myTShape == theOther.myTShape
216 && myLocation == theOther.myLocation;
219 //! Returns True if two shapes are equal, i.e. if they
220 //! share the same TShape with the same Locations and
222 Standard_Boolean IsEqual (const TopoDS_Shape& theOther) const
224 return myTShape == theOther.myTShape
225 && myLocation == theOther.myLocation
226 && myOrient == theOther.myOrient;
229 Standard_Boolean operator == (const TopoDS_Shape& theOther) const { return IsEqual (theOther); }
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); }
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;
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(); }
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
251 TopoDS_Shape aShape (*this);
256 void TShape (const Handle(TopoDS_TShape)& theTShape) { myTShape = theTShape; }
260 Handle(TopoDS_TShape) myTShape;
261 TopLoc_Location myLocation;
262 TopAbs_Orientation myOrient;
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)
272 return theShape.HashCode (theUpperBound);
275 #endif // _TopoDS_Shape_HeaderFile