Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/yacs.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeStudyProperties.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/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDSImpl_AttributeStudyProperties.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include <SALOMEDSImpl_AttributeStudyProperties.hxx>
25 #include <Standard_GUID.hxx>
26 #include <TCollection_ExtendedString.hxx>
27
28 using namespace std;
29
30 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeStudyProperties, SALOMEDSImpl_GenericAttribute )
31 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeStudyProperties, SALOMEDSImpl_GenericAttribute )
32
33 const Standard_GUID& SALOMEDSImpl_AttributeStudyProperties::GetID()
34 {
35   static Standard_GUID SALOMEDSImpl_AttributeStudyPropertiesID ("128371A2-8F52-11d6-A8A3-0001021E8C7F");
36   return SALOMEDSImpl_AttributeStudyPropertiesID;
37 }
38
39 Handle(SALOMEDSImpl_AttributeStudyProperties) SALOMEDSImpl_AttributeStudyProperties::Set(const TDF_Label& label)
40 {
41   Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
42   if (!label.FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(),anAttr)) {
43     anAttr = new SALOMEDSImpl_AttributeStudyProperties();
44     label.AddAttribute(anAttr);
45   }
46   return anAttr;
47 }
48
49 SALOMEDSImpl_AttributeStudyProperties::SALOMEDSImpl_AttributeStudyProperties()
50 :SALOMEDSImpl_GenericAttribute("AttributeStudyProperties")
51 {
52   myLocked = Standard_False;
53   myLockChanged = Standard_False;
54   Init();
55 }
56
57 void SALOMEDSImpl_AttributeStudyProperties::Init()
58 {
59   myUserName = new TColStd_HSequenceOfExtendedString();
60   myMinute = new TColStd_HSequenceOfInteger();
61   myHour = new TColStd_HSequenceOfInteger();
62   myDay = new TColStd_HSequenceOfInteger();
63   myMonth = new TColStd_HSequenceOfInteger();
64   myYear = new TColStd_HSequenceOfInteger();
65 //  myModified = 0;
66   myMode = 0; // none
67 }
68
69 void SALOMEDSImpl_AttributeStudyProperties::SetModification(const TCollection_ExtendedString& theUserName,
70                                                             const Standard_Integer            theMinute,
71                                                             const Standard_Integer            theHour,
72                                                             const Standard_Integer            theDay,
73                                                             const Standard_Integer            theMonth,
74                                                             const Standard_Integer            theYear)
75 {
76   if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 ||
77       theDay<0 || theDay>31 || theMonth<0 || theMonth>12)
78     return;
79
80   CheckLocked();
81   Backup();
82
83   myUserName->Append(theUserName);
84   myMinute->Append(theMinute);
85   myHour->Append(theHour);
86   myDay->Append(theDay);
87   myMonth->Append(theMonth);
88   myYear->Append(theYear);
89 }
90
91 void SALOMEDSImpl_AttributeStudyProperties::GetModifications
92                   (Handle(TColStd_HSequenceOfExtendedString)& theUserNames,
93                    Handle(TColStd_HSequenceOfInteger)&        theMinutes,
94                    Handle(TColStd_HSequenceOfInteger)&        theHours,
95                    Handle(TColStd_HSequenceOfInteger)&        theDays,
96                    Handle(TColStd_HSequenceOfInteger)&        theMonths,
97                    Handle(TColStd_HSequenceOfInteger)&        theYears) const
98 {
99   theUserNames = myUserName;
100   theMinutes = myMinute;
101   theHours = myHour;
102   theDays = myDay;
103   theMonths = myMonth;
104   theYears = myYear;
105 }
106
107 TCollection_ExtendedString SALOMEDSImpl_AttributeStudyProperties::GetCreatorName() const
108 {
109   if (myUserName->Length() == 0)
110     return TCollection_ExtendedString("");
111   return myUserName->Value(1);
112 }
113
114 Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::GetCreationDate
115                               (Standard_Integer&           theMinute,
116                                Standard_Integer&           theHour,
117                                Standard_Integer&           theDay,
118                                Standard_Integer&           theMonth,
119                                Standard_Integer&           theYear) const
120 {
121   if (myMinute->Length() != 0) {
122     theMinute = myMinute->Value(1);
123     theHour = myHour->Value(1);
124     theDay = myDay->Value(1);
125     theMonth = myMonth->Value(1);
126     theYear = myYear->Value(1);
127     return Standard_True;
128   }
129   return Standard_False;
130 }
131
132 void SALOMEDSImpl_AttributeStudyProperties::ChangeCreatorName(const TCollection_ExtendedString& theName)
133 {
134   if (myUserName->Length() > 0) {
135     CheckLocked();
136     Backup();
137     myUserName->SetValue(1, theName);
138   }
139 }
140
141 void SALOMEDSImpl_AttributeStudyProperties::SetCreationMode(const Standard_Integer theMode)
142 {
143   CheckLocked();
144   Backup();
145   myMode = theMode;
146 }
147
148 Standard_Integer SALOMEDSImpl_AttributeStudyProperties::GetCreationMode() const
149 {
150   return myMode;
151 }
152
153 void SALOMEDSImpl_AttributeStudyProperties::SetModified(const Standard_Integer theModified)
154 {
155   myModified = theModified;
156 }
157
158 Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::IsModified() const
159 {
160   return (myModified != 0);
161 }
162
163 Standard_Integer SALOMEDSImpl_AttributeStudyProperties::GetModified() const
164 {
165   return myModified;
166 }
167
168 void SALOMEDSImpl_AttributeStudyProperties::SetLocked(const Standard_Boolean theLocked)
169 {
170 //  Backup();
171   if (myLocked != theLocked) {
172     myLockChanged = Standard_True;
173     myLocked = theLocked;
174   }
175 }
176
177 Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::IsLocked() const
178 {
179   return myLocked;
180 }
181
182 Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::IsLockChanged(const Standard_Boolean theErase) {
183   if (!myLockChanged) return Standard_False;
184   if (theErase) myLockChanged = Standard_False;
185   return Standard_True;
186 }
187
188 const Standard_GUID& SALOMEDSImpl_AttributeStudyProperties::ID() const
189 {
190   return GetID();
191 }
192
193 void SALOMEDSImpl_AttributeStudyProperties::Restore(const Handle(TDF_Attribute)& with)
194 {
195   Handle(SALOMEDSImpl_AttributeStudyProperties) aProp =
196     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(with);
197   Init();
198   Standard_Integer i;
199   Handle(TColStd_HSequenceOfExtendedString) aNames;
200   Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
201   aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
202   for (i = aNames->Length(); i > 0; i--) {
203     myUserName->Prepend(aNames->Value(i));
204     myMinute->Prepend(aMinutes->Value(i));
205     myHour->Prepend(aHours->Value(i));
206     myDay->Prepend(aDays->Value(i));
207     myMonth->Prepend(aMonths->Value(i));
208     myYear->Prepend(aYears->Value(i));
209   }
210   myMode = aProp->GetCreationMode();
211 //  myModified = aProp->GetModified();
212 //  myLocked = aProp->IsLocked();
213 }
214
215 Handle(TDF_Attribute) SALOMEDSImpl_AttributeStudyProperties::NewEmpty() const
216 {
217   return new SALOMEDSImpl_AttributeStudyProperties();
218 }
219
220 void SALOMEDSImpl_AttributeStudyProperties::Paste(const Handle(TDF_Attribute)& into,
221                                                   const Handle(TDF_RelocationTable)&) const
222 {
223   Handle(SALOMEDSImpl_AttributeStudyProperties) aProp =
224     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(into);
225   aProp->Init();
226
227   Standard_Integer i;
228   for(i = 1; i <= myUserName->Length(); i++) {
229     aProp->SetModification(myUserName->Value(i),
230                            myMinute->Value(i), myHour->Value(i),
231                            myDay->Value(i), myMonth->Value(i), myYear->Value(i));
232   }
233
234   aProp->SetCreationMode(myMode);
235 //  aProp->SetModified(myModified);
236 //  aProp->SetLocked(myLocked);
237 }
238
239
240 TCollection_AsciiString SALOMEDSImpl_AttributeStudyProperties::Save()
241 {
242   Handle(TColStd_HSequenceOfExtendedString) aNames;
243   Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
244   GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
245
246   int aLength, anIndex;
247   for (aLength = 0, anIndex = aNames->Length(); anIndex > 0; anIndex--)
248     aLength += aNames->Value(anIndex).Length() + 1;
249
250   char* aProperty = new char[3 + aLength + 12 * aNames->Length()];
251
252   char crMode = (char)GetCreationMode();
253
254   sprintf(aProperty,"%c%c", crMode, IsLocked()?'l':'u');
255
256   aLength = aNames->Length();
257   int a = 2;
258   for (anIndex = 1; anIndex  <= aLength; anIndex++) {
259     sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
260             (int)(aMinutes->Value(anIndex)),
261             (int)(aHours->Value(anIndex)),
262             (int)(aDays->Value(anIndex)),
263             (int)(aMonths->Value(anIndex)),
264             (int)(aYears->Value(anIndex)),
265             (char*)(TCollection_AsciiString(aNames->Value(anIndex)).ToCString()));
266     a = strlen(aProperty);
267     aProperty[a++] = 1;
268   }
269   aProperty[a] = 0;
270   TCollection_AsciiString prop(aProperty);
271   delete aProperty;
272
273   return prop;
274 }
275
276 void SALOMEDSImpl_AttributeStudyProperties::Load(const TCollection_AsciiString& value)
277 {
278   char* aCopy = value.ToCString();
279
280   int crMode = (int)aCopy[0];
281   SetCreationMode(crMode);
282
283   int anIndex;
284   for (anIndex = 2; anIndex + 2 < value.Length() ;) {
285     char str[10];
286     Standard_Integer aMinute, aHour, aDay, aMonth, aYear;
287     str[0] = aCopy[anIndex++];
288     str[1] = aCopy[anIndex++];
289     str[2] = 0;
290     aMinute = atoi(str);
291     str[0] = aCopy[anIndex++];
292     str[1] = aCopy[anIndex++];
293     aHour =  atoi(str);
294     str[0] = aCopy[anIndex++];
295     str[1] = aCopy[anIndex++];
296     aDay =  atoi(str);
297     str[0] = aCopy[anIndex++];
298     str[1] = aCopy[anIndex++];
299     aMonth =  atoi(str);
300     str[0] = aCopy[anIndex++];
301     str[1] = aCopy[anIndex++];
302     str[2] = aCopy[anIndex++];
303     str[3] = aCopy[anIndex++];
304     str[4] = 0;
305     aYear = atoi(str);
306
307     int aNameSize;
308     for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
309     char *aName = new char[aNameSize+1];
310     strncpy(aName, &(aCopy[anIndex]), aNameSize);
311     aName[aNameSize] = 0;
312     SetModification(aName,aMinute,aHour,aDay,aMonth,aYear);
313     delete(aName);
314     anIndex += aNameSize + 1;
315   }
316   if (aCopy[1] == 'l') {
317     SetLocked(Standard_True);
318   }
319   SetModified(0);
320 }