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