Salome HOME
Copyrights update
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeReference.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 //  File   : SALOMEDSImpl_AttributeReference.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDSImpl_AttributeReference.hxx"
25 #include <TDF_Tool.hxx>
26 #include <TDF_Data.hxx>
27 #include <TDF_RelocationTable.hxx>
28
29 using namespace std;
30
31 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeReference, SALOMEDSImpl_GenericAttribute )
32 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeReference, SALOMEDSImpl_GenericAttribute )
33
34
35 //=======================================================================
36 //function : GetID
37 //purpose  :
38 //=======================================================================
39 const Standard_GUID& SALOMEDSImpl_AttributeReference::GetID ()
40 {
41   static Standard_GUID refID ("D913E0B3-0A9F-4ea6-9480-18A9B72D9D86");
42   return refID;
43
44
45 Handle(SALOMEDSImpl_AttributeReference) SALOMEDSImpl_AttributeReference::Set(const TDF_Label& theLabel, 
46                                                                              const TDF_Label& theRefLabel)
47 {
48   Handle(SALOMEDSImpl_AttributeReference) A;
49   if (!theLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), A)) {
50     A = new  SALOMEDSImpl_AttributeReference(); 
51     theLabel.AddAttribute(A);
52   }
53
54   A->Set(theRefLabel);  
55   return A;  
56 }
57
58 //=======================================================================
59 //function : Set
60 //purpose  :
61 //=======================================================================
62 void SALOMEDSImpl_AttributeReference::Set(const TDF_Label& Origin)
63 {
64   CheckLocked();
65
66   if(myLabel == Origin) return;
67
68   Backup();
69   myLabel = Origin;
70
71   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
72 }  
73
74 //=======================================================================
75 //function : ID
76 //purpose  :
77 //=======================================================================
78 const Standard_GUID& SALOMEDSImpl_AttributeReference::ID () const { return GetID(); } 
79
80
81 TCollection_AsciiString SALOMEDSImpl_AttributeReference::Save() 
82 {
83   TCollection_AsciiString anEntry;
84   TDF_Tool::Entry(myLabel, anEntry);
85   return anEntry;
86 }
87
88 void SALOMEDSImpl_AttributeReference::Load(const TCollection_AsciiString& value) 
89 {
90   TDF_Label aLabel;
91   TDF_Tool::Label(Label().Data(), value, aLabel);
92   myLabel = aLabel;
93 }
94
95 //=======================================================================
96 //function : NewEmpty
97 //purpose  : 
98 //=======================================================================
99 Handle(TDF_Attribute) SALOMEDSImpl_AttributeReference::NewEmpty () const
100 {  
101   return new SALOMEDSImpl_AttributeReference(); 
102 }
103
104 //=======================================================================
105 //function : Restore
106 //purpose  :
107 //=======================================================================
108
109 void SALOMEDSImpl_AttributeReference::Restore(const Handle(TDF_Attribute)& With)
110 {
111   myLabel = Handle(SALOMEDSImpl_AttributeReference)::DownCast (With)->Get ();
112 }
113
114 //=======================================================================
115 //function : Paste
116 //purpose  :
117 //=======================================================================
118
119 void SALOMEDSImpl_AttributeReference::Paste (const Handle(TDF_Attribute)& Into,
120                                              const Handle(TDF_RelocationTable)& RT) const
121 {
122   TDF_Label tLab;
123   if (!myLabel.IsNull()) {
124     if (!RT->HasRelocation(myLabel,tLab)) tLab = myLabel;
125   }
126   Handle(SALOMEDSImpl_AttributeReference)::DownCast(Into)->Set(tLab);
127