Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_GenericAttribute_i.hxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOMEDS_GenericAttribute_i.hxx
25 //  Author : Yves FRICAUD
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef _GENERIC_ATTRIBUTE_I_HXX_
30 #define _GENERIC_ATTRIBUTE_I_HXX_
31
32 #include <TDF_Attribute.hxx>
33 #include <Standard_GUID.hxx>
34
35 // IDL headers
36 #include <SALOMEconfig.h>
37 #include CORBA_SERVER_HEADER(SALOMEDS)
38
39 class SALOMEDS_SObject_i;
40
41 class SALOMEDS_GenericAttribute_i:
42   public virtual POA_SALOMEDS::GenericAttribute,
43   public virtual PortableServer::RefCountServantBase 
44
45 private: 
46   friend class SALOMEDS_SObject_i;
47
48   SALOMEDS_GenericAttribute_i(); // Not implemented
49   void operator=(const SALOMEDS_GenericAttribute_i&);  //Not implemented
50
51 protected:
52   SALOMEDS_SObject_i* _mySObject;
53   Handle(TDF_Attribute) _myBasicAttr;
54
55   SALOMEDS_GenericAttribute_i(const Handle(TDF_Attribute)& theAttr,
56                               SALOMEDS_SObject_i* theSObject);
57   
58   virtual ~SALOMEDS_GenericAttribute_i();
59
60   void SetBasicAttribute(const Handle(TDF_Attribute)& theAttr){
61     _myBasicAttr = theAttr;
62   }
63   
64 public:
65   void Restore(const char*);
66
67   char* Store();
68
69   char* Type();
70   
71   SALOMEDS::SObject_ptr GetSObject();
72
73   void CheckLocked() 
74     throw (SALOMEDS::GenericAttribute::LockProtection);
75
76   virtual void SetAttribute(const Handle(TDF_Attribute)& theAttr) = 0;
77
78   virtual const Handle(TDF_Attribute)& GetAttribute() const = 0;
79
80 };
81
82
83 template<class TDFAttribute, class TStoreTDFAttribute, bool TIsCheckLockedStudy = true>
84 class SALOMEDS_TGenericAttribute_i:
85   public virtual SALOMEDS_GenericAttribute_i
86 {
87 public:
88   typedef TDFAttribute TAttr;
89   typedef TStoreTDFAttribute TStoreAttr;
90
91   virtual void SetAttribute(const Handle(TDF_Attribute)& theAttr){
92     _myAttr = TStoreAttr::DownCast(theAttr);
93     SetBasicAttribute(theAttr);
94   }
95   virtual const Handle(TDF_Attribute)& GetAttribute() const{
96     return _myAttr;
97   }
98   static bool IsCheckLockedStudy(){
99     return TIsCheckLockedStudy;
100   }
101   static Handle(TDF_Attribute) NewAttribute(){
102     return new TAttr;
103   }
104
105 protected:
106   TStoreAttr _myAttr;
107
108   SALOMEDS_TGenericAttribute_i(const Handle(TDF_Attribute)& theAttr,
109                                SALOMEDS_SObject_i* theSObject):
110     SALOMEDS_GenericAttribute_i(theAttr,theSObject),
111     _myAttr(TStoreAttr::DownCast(theAttr))
112   {
113   }
114   
115 private: 
116   friend class SALOMEDS_SObject_i;
117
118   SALOMEDS_TGenericAttribute_i(); //Not implemented
119   void operator=(const SALOMEDS_TGenericAttribute_i&);  //Not implemented
120
121 };
122
123
124 #define DEFINE_DERIVED_ATTR(TName,TAttr,TCheck) \
125   typedef SALOMEDS_TGenericAttribute_i<TAttr,Handle_##TAttr,TCheck> \
126     SALOMEDS_T##TName##_i
127
128
129 #define DEFINE_DERIVED_ATTR_METH_BASE(TName) \
130 public: \
131   friend class SALOMEDS_SObject_i; \
132   static SALOMEDS_GenericAttribute_i* \
133     NewInstance(const Handle(TDF_Attribute)& theAttr, \
134                 SALOMEDS_SObject_i* theSObject) \
135       { return new SALOMEDS_##TName##_i(theAttr,theSObject);} \
136 private: \
137   SALOMEDS_##TName##_i(const Handle(TDF_Attribute)& theAttr, \
138                        SALOMEDS_SObject_i* theSObject): \
139     SALOMEDS_GenericAttribute_i(theAttr,theSObject), \
140     SALOMEDS_T##TName##_i(theAttr,theSObject) \
141     {} \
142   void operator=(const SALOMEDS_##TName##_i&); \
143   SALOMEDS_##TName##_i()
144
145
146 #define DEFINE_DERIVED_ATTR_METH_DEFAULT(TName,TAttr) \
147 DEFINE_DERIVED_ATTR_METH_BASE(TName); \
148 public: \
149   static Standard_GUID GetGUID(){ return TAttr::GetID(); } \
150 private:
151
152
153 #define DEFINE_DERIVED_ATTR_METH(TName,theGUID) \
154 DEFINE_DERIVED_ATTR_METH_BASE(TName); \
155 public: \
156   static Standard_GUID GetGUID(){ return theGUID; } \
157 private:
158
159
160 #endif