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