Salome HOME
DCQ : Merge with Ecole_ete_a6.
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_StudyPropertiesAttribute.cxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SALOMEDS_StudyPropertiesAttribute.cxx
8 //  Author : Yves FRICAUD
9 //  Module : SALOME
10 //  $Header$
11
12 using namespace std;
13 #include <SALOMEDS_StudyPropertiesAttribute.ixx>
14
15 const Standard_GUID& SALOMEDS_StudyPropertiesAttribute::GetID() 
16 {
17   static Standard_GUID SALOMEDS_StudyPropertiesAttributeID ("128371A2-8F52-11d6-A8A3-0001021E8C7F");
18   return SALOMEDS_StudyPropertiesAttributeID;
19 }
20
21 Handle(SALOMEDS_StudyPropertiesAttribute) SALOMEDS_StudyPropertiesAttribute::Set(const TDF_Label& label) 
22 {
23   Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
24   if (!label.FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(),anAttr)) {
25     anAttr = new SALOMEDS_StudyPropertiesAttribute();
26     label.AddAttribute(anAttr);
27   }
28   return anAttr;
29 }
30
31 SALOMEDS_StudyPropertiesAttribute::SALOMEDS_StudyPropertiesAttribute()
32 {
33   myLocked = Standard_False;
34   myLockChanged = Standard_False;
35   Init();
36 }
37
38 void SALOMEDS_StudyPropertiesAttribute::Init()
39 {
40   myUserName = new TColStd_HSequenceOfExtendedString();
41   myMinute = new TColStd_HSequenceOfInteger();
42   myHour = new TColStd_HSequenceOfInteger();
43   myDay = new TColStd_HSequenceOfInteger();
44   myMonth = new TColStd_HSequenceOfInteger();
45   myYear = new TColStd_HSequenceOfInteger();
46 //  myModified = 0;
47   myMode = 0; // none
48 }
49
50 void SALOMEDS_StudyPropertiesAttribute::SetUserName(const TCollection_ExtendedString& theName) 
51 {
52   Backup();
53   myUserName->Append(theName);
54 }
55
56 void SALOMEDS_StudyPropertiesAttribute::SetFirstName(const TCollection_ExtendedString& theName)
57 {
58   Backup();
59   if (myUserName->Length() == 0) myUserName->Append(theName);
60   else myUserName->SetValue(1, theName);
61 }
62
63 TCollection_ExtendedString SALOMEDS_StudyPropertiesAttribute::GetCreatorName() const
64 {
65   if (myUserName->Length() == 0) return TCollection_ExtendedString("");
66   return myUserName->Value(1);
67 }
68
69 Handle(TColStd_HSequenceOfExtendedString) SALOMEDS_StudyPropertiesAttribute::GetUserNames() const
70 {
71   return myUserName;
72 }
73
74 void SALOMEDS_StudyPropertiesAttribute::SetModificationDate(const Standard_Integer theMinute,
75                                                         const Standard_Integer theHour,
76                                                         const Standard_Integer theDay,
77                                                         const Standard_Integer theMonth,
78                                                         const Standard_Integer theYear) 
79 {
80   Backup();
81   if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 || theDay<0 || theDay>31 || theMonth<0 || theMonth>12)
82     return;
83   myMinute->Append(theMinute);
84   myHour->Append(theHour);
85   myDay->Append(theDay);
86   myMonth->Append(theMonth);
87   myYear->Append(theYear);
88 }
89
90 Standard_Boolean SALOMEDS_StudyPropertiesAttribute::GetCreationDate(Standard_Integer& theMinute,
91                                                                     Standard_Integer& theHour,
92                                                                     Standard_Integer& theDay,
93                                                                     Standard_Integer& theMonth,
94                                                                     Standard_Integer& theYear) const
95 {
96   if (myMinute->Length() != 0) {
97     theMinute = myMinute->Value(1);
98     theHour = myHour->Value(1);
99     theDay = myDay->Value(1);
100     theMonth = myMonth->Value(1);
101     theYear = myYear->Value(1);
102     return Standard_True;
103   }
104   return Standard_False;
105 }
106
107 void SALOMEDS_StudyPropertiesAttribute::GetModificationDates(Handle(TColStd_HSequenceOfInteger)& theMinutes,
108                                                              Handle(TColStd_HSequenceOfInteger)& theHours,
109                                                              Handle(TColStd_HSequenceOfInteger)& theDays,
110                                                              Handle(TColStd_HSequenceOfInteger)& theMonths,
111                                                              Handle(TColStd_HSequenceOfInteger)& theYears) const
112 {
113   theMinutes = myMinute;
114   theHours = myHour;
115   theDays = myDay;
116   theMonths = myMonth;
117   theYears = myYear;
118 }
119
120 void SALOMEDS_StudyPropertiesAttribute::SetCreationMode(const Standard_Integer theMode) 
121 {
122   Backup();
123   myMode = theMode;
124 }
125
126 Standard_Integer SALOMEDS_StudyPropertiesAttribute::GetCreationMode() const
127 {
128   return myMode;
129 }
130
131 void SALOMEDS_StudyPropertiesAttribute::SetModified(const Standard_Integer theModified) 
132 {
133   myModified = theModified;
134 }
135
136 Standard_Boolean SALOMEDS_StudyPropertiesAttribute::IsModified() const
137 {
138   return (myModified != 0);
139 }
140
141 Standard_Integer SALOMEDS_StudyPropertiesAttribute::GetModified() const
142 {
143   return myModified;
144 }
145
146 void SALOMEDS_StudyPropertiesAttribute::SetLocked(const Standard_Boolean theLocked) 
147 {
148 //  Backup();
149   if (myLocked != theLocked) {
150     myLockChanged = Standard_True;
151     myLocked = theLocked;
152   }
153 }
154
155 Standard_Boolean SALOMEDS_StudyPropertiesAttribute::IsLocked() const
156 {
157   return myLocked;
158 }
159
160 Standard_Boolean SALOMEDS_StudyPropertiesAttribute::IsLockChanged(const Standard_Boolean theErase) {
161   if (!myLockChanged) return Standard_False;
162   if (theErase) myLockChanged = Standard_False;
163   return Standard_True;
164 }
165
166 const Standard_GUID& SALOMEDS_StudyPropertiesAttribute::ID() const
167 {
168   return GetID();
169 }
170
171 void SALOMEDS_StudyPropertiesAttribute::Restore(const Handle(TDF_Attribute)& with) 
172 {
173   Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(with);
174   Init();
175   Standard_Integer i;
176   Handle(TColStd_HSequenceOfExtendedString) aNames = aProp->GetUserNames();
177   for(i = aNames->Length(); i > 0; i--) {
178     myUserName->Prepend(aNames->Value(i));
179   }
180   Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
181   aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears);
182   for(i = aMinutes->Length(); i > 0; i--) {
183     myMinute->Prepend(aMinutes->Value(i));
184     myHour->Prepend(aHours->Value(i));
185     myDay->Prepend(aDays->Value(i));
186     myMonth->Prepend(aMonths->Value(i));
187     myYear->Prepend(aYears->Value(i));
188   }
189   myMode = aProp->GetCreationMode();
190 //  myModified = aProp->GetModified();
191 //  myLocked = aProp->IsLocked();
192 }
193
194 Handle(TDF_Attribute) SALOMEDS_StudyPropertiesAttribute::NewEmpty() const
195 {
196   return new SALOMEDS_StudyPropertiesAttribute();
197 }
198
199 void SALOMEDS_StudyPropertiesAttribute::Paste(const Handle(TDF_Attribute)& into,
200                                               const Handle(TDF_RelocationTable)&) const
201 {
202   Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(into);
203   aProp->Init();
204
205   Standard_Integer i;
206   for(i = 1; i <= myUserName->Length(); i++) {
207     aProp->SetUserName(myUserName->Value(i));
208   }
209   for(i = 1; i <= myMinute->Length(); i++) {
210     aProp->SetModificationDate(myMinute->Value(i), myHour->Value(i), myDay->Value(i), myMonth->Value(i), myYear->Value(i));
211   }
212
213   aProp->SetCreationMode(myMode);
214 //  aProp->SetModified(myModified);
215 //  aProp->SetLocked(myLocked);
216 }
217