Salome HOME
0022232: [CEA 837] Memory corruption in GEOM/SMESH that leads to segfault on debian64
[modules/geom.git] / src / GEOM / GEOM_Object.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef _GEOM_Object_HeaderFile
24 #define _GEOM_Object_HeaderFile
25
26 #ifndef _Standard_TypeMismatch_HeaderFile
27 #include <Standard_TypeMismatch.hxx>
28 #endif
29 #ifndef _Standard_HeaderFile
30 #include <Standard.hxx>
31 #endif
32 #ifndef _Standard_Macro_HeaderFile
33 #include <Standard_Macro.hxx>
34 #endif
35 #ifndef _Standard_HeaderFile
36 #include <Standard.hxx>
37 #endif
38 #ifndef _Handle_MMgt_TShared_HeaderFile
39 #include <Handle_MMgt_TShared.hxx>
40 #endif
41 #ifndef _MMgt_TShared_HeaderFile
42 #include <MMgt_TShared.hxx>
43 #endif
44 #ifndef _Standard_GUID_HeaderFile
45 #include <Standard_GUID.hxx>
46 #endif
47 #ifndef _TopoDS_Shape_HeaderFile
48 #include <TopoDS_Shape.hxx>
49 #endif
50 #ifndef _TDF_Label_HeaderFile
51 #include <TDF_Label.hxx>
52 #endif
53 #ifndef _TColStd_HSequenceOfTransient_HeaderFile
54 #include <TColStd_HSequenceOfTransient.hxx>
55 #endif
56 #ifndef _TCollection_AsciiString_HeaderFile
57 #include <TCollection_AsciiString.hxx>
58 #endif
59 #ifndef _Aspect_TypeOfMarker_HeaderFile
60 #include <Aspect_TypeOfMarker.hxx>
61 #endif
62
63
64 class Handle_TColStd_HSequenceOfTransient;
65 class Standard_Transient;
66 class Handle_Standard_Type;
67 class Handle(MMgt_TShared);
68 class GEOM_Object;
69 class Handle(TFunction_Driver);
70
71
72 Standard_EXPORT Handle_Standard_Type& STANDARD_TYPE(GEOM_Object);
73
74 class Handle(GEOM_Object) : public Handle(MMgt_TShared) {
75   public:
76     inline void* operator new(size_t,void* anAddress)
77       {
78         return anAddress;
79       }
80     inline void* operator new(size_t size)
81       {
82         return Standard::Allocate(size);
83       }
84     inline void  operator delete(void *anAddress)
85       {
86         if (anAddress) Standard::Free((Standard_Address&)anAddress);
87       }
88
89     Handle(GEOM_Object)():Handle(MMgt_TShared)() {}
90     Handle(GEOM_Object)(const Handle(GEOM_Object)& aHandle) : Handle(MMgt_TShared)(aHandle)
91      {
92      }
93
94     Handle(GEOM_Object)(const GEOM_Object* anItem) : Handle(MMgt_TShared)((MMgt_TShared *)anItem)
95      {
96      }
97
98     Handle(GEOM_Object)& operator=(const Handle(GEOM_Object)& aHandle)
99      {
100       Assign(aHandle.Access());
101       return *this;
102      }
103
104     Handle(GEOM_Object)& operator=(const GEOM_Object* anItem)
105      {
106       Assign((Standard_Transient *)anItem);
107       return *this;
108      }
109
110     GEOM_Object* operator->()
111      {
112       return (GEOM_Object *)ControlAccess();
113      }
114
115     GEOM_Object* operator->() const
116      {
117       return (GEOM_Object *)ControlAccess();
118      }
119
120    Standard_EXPORT ~Handle(GEOM_Object)() {};
121
122    Standard_EXPORT static const Handle(GEOM_Object) DownCast(const Handle(Standard_Transient)& AnObject);
123 };
124
125
126 #include <Standard_GUID.hxx>
127 #include <TDataStd_TreeNode.hxx>
128 #include "GEOM_Function.hxx"
129 #include "GEOM_Engine.hxx"
130
131 class GEOM_Object : public MMgt_TShared
132 {
133  friend class GEOM_Engine;
134  
135  public:
136   struct Color {
137     //! Red component of the color
138     double R;
139     //! Green component of the color
140     double G;
141     //! Blue component  of the color
142     double B;
143   };
144
145  public:
146   inline void* operator new(size_t,void* anAddress)
147     {
148       return anAddress;
149     }
150   inline void* operator new(size_t size)
151     {
152       return Standard::Allocate(size);
153     }
154   inline void  operator delete(void *anAddress)
155     {
156       if (anAddress) Standard::Free((Standard_Address&)anAddress);
157     }
158
159   // Type management
160   //
161   Standard_EXPORT friend Handle_Standard_Type& GEOM_Object_Type_();
162   Standard_EXPORT const Handle(Standard_Type)& DynamicType() const  { return STANDARD_TYPE(GEOM_Object) ; }
163   Standard_EXPORT Standard_Boolean IsKind(const Handle(Standard_Type)& AType) const
164            { return (STANDARD_TYPE(GEOM_Object) == AType || MMgt_TShared::IsKind(AType)); }
165
166  private:
167   GEOM_Object(TDF_Label& theLabel);
168
169  public:
170   Standard_EXPORT GEOM_Object(TDF_Label& theEntry, int theType);
171   Standard_EXPORT ~GEOM_Object();
172
173   //Finds a GEOM_Object on the label theLabel
174   Standard_EXPORT static Handle(GEOM_Object) GetObject(TDF_Label& theLabel);
175
176   //Finds a GEOM_Object by a reference, stored on the label theLabel
177   Standard_EXPORT static Handle(GEOM_Object) GetReferencedObject(TDF_Label& theLabel);
178
179   //Returns a GEOM_Object common GUID
180   Standard_EXPORT static const Standard_GUID& GetObjectID();
181
182   //Returns a GUID associated with a sub-shape object
183   Standard_EXPORT static const Standard_GUID& GetSubShapeID();
184
185   //###########################################################
186   //Access to properties
187   //###########################################################
188
189   //Returns a TreeNode that presents a root of a function tree for this GEOM_Object
190   Standard_EXPORT Handle(TDataStd_TreeNode) GetRootNode() { return _root; }
191
192   //Returns a label of this GEOM_Object
193   Standard_EXPORT TDF_Label GetEntry() { return _label; }
194
195   //Returns a type of this GEOM_Object (GEOM_POINT, GEOM_VECTOR...)
196   Standard_EXPORT int GetType();
197
198   //Sets the type of this GEOM_Object
199   Standard_EXPORT void SetType(int theType);
200
201   //Modifications counter management
202   Standard_EXPORT int  GetTic();
203   Standard_EXPORT void SetTic(int theTic);
204   Standard_EXPORT void IncrementTic();
205
206   //Returns an ID of the OCAF document where this GEOM_Object is stored
207   Standard_EXPORT int GetDocID();
208
209   //Returns a value (as TopoDS_Shape) of this GEOM_Object
210   Standard_EXPORT TopoDS_Shape GetValue();
211
212   //Sets a name of this GEOM_Object
213   Standard_EXPORT void SetName(const char* theName);
214
215   //Returns a name of this GEOM_Object
216   Standard_EXPORT TCollection_AsciiString GetName();
217
218   //Sets a color of this GEOM_Object
219   Standard_EXPORT void SetColor(const Color& theColor);
220
221   //Returns a color of this GEOM_Object
222   Standard_EXPORT Color GetColor();
223
224   //Toggles an auto color mode on this GEOM_Object
225   Standard_EXPORT void SetAutoColor(bool theAutoColor);
226
227   //Returns a flag of auto color mode of this GEOM_Object
228   Standard_EXPORT bool GetAutoColor();
229
230   //Sets predefined point marker texture
231   Standard_EXPORT void SetMarkerStd(const Aspect_TypeOfMarker theType, double theSize);
232   
233   //Sets custom point marker texture
234   Standard_EXPORT void SetMarkerTexture(int theTextureId);
235
236   //Gets point marker type
237   Standard_EXPORT Aspect_TypeOfMarker GetMarkerType();
238
239   //Gets point marker scale factor / size
240   Standard_EXPORT double GetMarkerSize();
241
242   //Gets custom marker texture ID
243   Standard_EXPORT int GetMarkerTexture();
244
245   //Unsets point marker
246   Standard_EXPORT void UnsetMarker();
247
248   //Sets an auxiliary data
249   Standard_EXPORT void SetAuxData(const char* theData);
250
251   //Returns an auxiliary data
252   Standard_EXPORT TCollection_AsciiString GetAuxData();
253
254   //Set a notebook variables used for object creation
255   Standard_EXPORT void SetParameters(const TCollection_AsciiString& theParameters);
256
257   //Get a notebook variables used for object creation
258   Standard_EXPORT TCollection_AsciiString GetParameters() const;
259
260   //###########################################################
261   // Sub-shape methods
262   //###########################################################
263
264   //Returns false if the object is a sub-shape of another object
265   Standard_EXPORT bool IsMainShape();
266
267   //###########################################################
268   // CORBA related methods
269   //###########################################################
270
271   //Sets an IOR of CORBA GEOM_Object_i which refers to this object
272   Standard_EXPORT void SetIOR(TCollection_AsciiString& theIOR) { _ior = theIOR; }
273
274   //Returns an IOR of CORBA GEOM_Object_i which refers to this object
275   Standard_EXPORT TCollection_AsciiString GetIOR() { return _ior; }
276
277   //###########################################################
278   //Functions methods
279   //###########################################################
280
281   //Adds a function with a driver GUID = theGUID and a type theFunctionType
282   //to the function tree of this GEOM_Object
283   Standard_EXPORT Handle(GEOM_Function) AddFunction(const Standard_GUID& theGUID,
284                                                     int                  theFunctionType,
285                                                     bool                 allowSubShape=false);
286
287   //Returns a number of functions of this GEOM_Object
288   Standard_EXPORT int GetNbFunctions();
289
290   //Returns a function with given number theFunctionNumber
291   Standard_EXPORT Handle(GEOM_Function) GetFunction(int theFunctionNumber);
292
293   //Return the last function of this GEOM_Object
294   Standard_EXPORT Handle(GEOM_Function) GetLastFunction();
295
296   //Returns all dependencies of the object
297   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetAllDependency();
298
299   //Returns the dependencies of the last function
300   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetLastDependency();
301
302   //Returns a driver creator of this object
303   Standard_EXPORT Handle(TFunction_Driver) GetCreationDriver();
304
305   //###########################################################
306   // Internal methods
307   //###########################################################
308
309   //Returns a label which could be used to store some additional data
310   Standard_EXPORT TDF_Label GetFreeLabel();
311
312  private:
313   Handle(TDataStd_TreeNode) _root;
314   TDF_Label                 _label;
315   TCollection_AsciiString   _ior;
316   TCollection_AsciiString   _parameters;
317   int                       _docID;
318
319
320 };
321
322 #endif