Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeStudyProperties_i.cxx
1 //  File   : SALOMEDS_AttributeStudyProperties_i.cxx
2 //  Author : Sergey RUIN
3 //  Module : SALOME
4
5
6 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
7 #include "SALOMEDS.hxx"
8 #include <TColStd_HSequenceOfExtendedString.hxx>
9 #include <TColStd_HSequenceOfInteger.hxx>
10 #include <TCollection_ExtendedString.hxx>
11
12 using namespace std;
13
14 #define CREATION_MODE_NOTDEFINED 0
15 #define CREATION_MODE_SCRATCH 1
16 #define CREATION_MODE_COPY 2
17
18 void SALOMEDS_AttributeStudyProperties_i::SetUserName(const char* theName)
19 {
20   SALOMEDS::Locker lock;
21   CheckLocked();
22   Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl)->ChangeCreatorName((char*)theName);
23 }
24
25 char* SALOMEDS_AttributeStudyProperties_i::GetUserName()
26 {
27   SALOMEDS::Locker lock;
28   TCollection_ExtendedString S =
29     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl)->GetCreatorName();
30   CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(S).ToCString());
31   return c_s._retn();
32 }
33
34 void SALOMEDS_AttributeStudyProperties_i::SetCreationDate(CORBA::Long theMinute,
35                                                           CORBA::Long theHour,
36                                                           CORBA::Long theDay,
37                                                           CORBA::Long theMonth,
38                                                           CORBA::Long theYear)
39 {
40   SALOMEDS::Locker lock;
41   CheckLocked();
42   Handle(SALOMEDSImpl_AttributeStudyProperties) aProp =
43     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl);
44   int aTmp;
45   if (aProp->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
46   TCollection_ExtendedString S;
47   aProp->SetModification(S, theMinute, theHour, theDay, theMonth, theYear);
48 }
49
50 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::GetCreationDate(CORBA::Long& theMinute,
51                                                                     CORBA::Long& theHour,
52                                                                     CORBA::Long& theDay,
53                                                                     CORBA::Long& theMonth,
54                                                                     CORBA::Long& theYear)
55 {
56   SALOMEDS::Locker lock;
57   Standard_Integer aMinute;
58   Standard_Integer aHour;
59   Standard_Integer aDay;
60   Standard_Integer aMonth;
61   Standard_Integer aYear;
62   if (Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast
63       (_impl)->GetCreationDate(aMinute, aHour, aDay, aMonth, aYear)) {
64     theMinute = aMinute;
65     theHour = aHour;
66     theDay = aDay;
67     theMonth = aMonth;
68     theYear = aYear;
69     return Standard_True;
70   }
71   return Standard_False;
72 }
73
74 void SALOMEDS_AttributeStudyProperties_i::SetCreationMode(const char* theMode)
75 {
76   SALOMEDS::Locker lock;
77   CheckLocked();
78   Handle(SALOMEDSImpl_AttributeStudyProperties) aProp =
79     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl);
80   if (strcmp(theMode,"from scratch")==0) aProp->SetCreationMode(CREATION_MODE_SCRATCH);
81   else if (strcmp(theMode,"copy from")==0) aProp->SetCreationMode(CREATION_MODE_COPY);
82   else aProp->SetCreationMode(CREATION_MODE_NOTDEFINED);
83 }
84
85 char* SALOMEDS_AttributeStudyProperties_i::GetCreationMode()
86 {
87   SALOMEDS::Locker lock;
88   CORBA::String_var c_s;
89   switch (Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl)->GetCreationMode()) {
90   case CREATION_MODE_SCRATCH: c_s = "from scratch"; break;
91   case CREATION_MODE_COPY: c_s = "copy from"; break;
92   default: c_s = "";
93   }
94   return c_s._retn();
95 }
96
97 void SALOMEDS_AttributeStudyProperties_i::SetModified(CORBA::Long theModified)
98 {
99   SALOMEDS::Locker lock;
100   Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl)->SetModified(theModified);
101 }
102
103 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsModified()
104 {
105   SALOMEDS::Locker lock;
106   return Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl)->IsModified();
107 }
108
109 CORBA::Long SALOMEDS_AttributeStudyProperties_i::GetModified()
110 {
111   SALOMEDS::Locker lock;
112   return Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl)->GetModified();
113 }
114
115 void SALOMEDS_AttributeStudyProperties_i::SetLocked(CORBA::Boolean theLocked)
116 {
117   SALOMEDS::Locker lock;
118   Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl)->SetLocked(theLocked);
119 }
120
121 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsLocked()
122 {
123   SALOMEDS::Locker lock;
124   return Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl)->IsLocked();
125 }
126
127 void SALOMEDS_AttributeStudyProperties_i::SetModification(const char* theName,
128                                                           CORBA::Long theMinute,
129                                                           CORBA::Long theHour,
130                                                           CORBA::Long theDay,
131                                                           CORBA::Long theMonth,
132                                                           CORBA::Long theYear)
133 {
134   SALOMEDS::Locker lock;
135   CheckLocked();
136   Handle(SALOMEDSImpl_AttributeStudyProperties) aProp =
137     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl);
138   aProp->SetModification((char*)theName, (int)theMinute, (int)theHour,
139                          (int)theDay, (int)theMonth, (int)theYear);
140 }
141
142 void SALOMEDS_AttributeStudyProperties_i::GetModificationsList(SALOMEDS::StringSeq_out theNames,
143                                                                SALOMEDS::LongSeq_out theMinutes,
144                                                                SALOMEDS::LongSeq_out theHours,
145                                                                SALOMEDS::LongSeq_out theDays,
146                                                                SALOMEDS::LongSeq_out theMonths,
147                                                                SALOMEDS::LongSeq_out theYears,
148                                                                CORBA::Boolean theWithCreator)
149 {
150   SALOMEDS::Locker lock;
151   Handle(TColStd_HSequenceOfExtendedString) aNames;
152   Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
153   Handle(SALOMEDSImpl_AttributeStudyProperties) aProp =
154     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_impl);
155   aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
156   int aLength = aNames->Length();
157   int aRetLength = aLength - ((theWithCreator) ? 0 : 1);
158   theNames = new SALOMEDS::StringSeq;
159   theMinutes = new SALOMEDS::LongSeq;
160   theHours = new SALOMEDS::LongSeq;
161   theDays = new SALOMEDS::LongSeq;
162   theMonths = new SALOMEDS::LongSeq;
163   theYears = new SALOMEDS::LongSeq;
164   theNames->length(aRetLength);
165   theMinutes->length(aRetLength);
166   theHours->length(aRetLength);
167   theDays->length(aRetLength);
168   theMonths->length(aRetLength);
169   theYears->length(aRetLength);
170   int a = 0, ind = ((theWithCreator) ? 1 : 2);
171   for (; ind <= aLength; a++, ind++) {
172     (*theNames)[a] = CORBA::string_dup(TCollection_AsciiString(aNames->Value(ind)).ToCString());
173     (*theMinutes)[a] = aMinutes->Value(ind);
174     (*theHours)[a] = aHours->Value(ind);
175     (*theDays)[a] = aDays->Value(ind);
176     (*theMonths)[a] = aMonths->Value(ind);
177     (*theYears)[a] = aYears->Value(ind);
178   }
179 }