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