Salome HOME
First stable version after merging with V3_2_2
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeSequenceOfInteger.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_AttributeSequenceOfInteger.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDSImpl_AttributeSequenceOfInteger.hxx"
25 #include <Standard_GUID.hxx>
26
27 using namespace std;
28
29 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute )
30 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute )
31
32
33 //=======================================================================
34 //function : GetID
35 //purpose  : 
36 //=======================================================================
37
38 const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::GetID () 
39 {
40   static Standard_GUID SALOMEDSImpl_AttributeSequenceOfIntegerID ("12837182-8F52-11d6-A8A3-0001021E8C7F");
41   return SALOMEDSImpl_AttributeSequenceOfIntegerID;
42 }
43
44
45
46 //=======================================================================
47 //function : Set
48 //purpose  : 
49 //=======================================================================
50
51 Handle(SALOMEDSImpl_AttributeSequenceOfInteger) SALOMEDSImpl_AttributeSequenceOfInteger::Set (const TDF_Label& L) 
52 {
53   Handle(SALOMEDSImpl_AttributeSequenceOfInteger) A;
54   if (!L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfInteger::GetID(),A)) {
55     A = new  SALOMEDSImpl_AttributeSequenceOfInteger(); 
56     L.AddAttribute(A);
57   }
58   return A;
59 }
60
61
62 //=======================================================================
63 //function : constructor
64 //purpose  : 
65 //=======================================================================
66 SALOMEDSImpl_AttributeSequenceOfInteger::SALOMEDSImpl_AttributeSequenceOfInteger()
67 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfInteger")
68
69   myValue = new TColStd_HSequenceOfInteger();
70 }
71
72 //=======================================================================
73 //function : ID
74 //purpose  : 
75 //=======================================================================
76
77 const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::ID () const { return GetID(); }
78
79
80 //=======================================================================
81 //function : NewEmpty
82 //purpose  : 
83 //=======================================================================
84
85 Handle(TDF_Attribute) SALOMEDSImpl_AttributeSequenceOfInteger::NewEmpty () const
86 {  
87   return new SALOMEDSImpl_AttributeSequenceOfInteger(); 
88 }
89
90 //=======================================================================
91 //function : Restore
92 //purpose  : 
93 //=======================================================================
94
95 void SALOMEDSImpl_AttributeSequenceOfInteger::Restore(const Handle(TDF_Attribute)& with) 
96 {
97   Standard_Integer i;
98   Handle(SALOMEDSImpl_AttributeSequenceOfInteger) anSeq = Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(with);
99   if(!anSeq->myValue.IsNull()) {
100     myValue = new TColStd_HSequenceOfInteger();
101     Standard_Integer Len = anSeq->Length();
102     for(i = 1; i<=Len; i++) Add(anSeq->Value(i)); 
103   }
104   else
105     myValue.Nullify();
106   return;
107 }
108
109 //=======================================================================
110 //function : Paste
111 //purpose  : 
112 //=======================================================================
113
114 void SALOMEDSImpl_AttributeSequenceOfInteger::Paste (const Handle(TDF_Attribute)& into,
115                                     const Handle(TDF_RelocationTable)& ) const
116 {
117   if(!myValue.IsNull()) {
118     Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast (into)->Assign(myValue);
119   }
120 }
121
122 void SALOMEDSImpl_AttributeSequenceOfInteger::Assign(const Handle(TColStd_HSequenceOfInteger)& other) 
123 {
124   CheckLocked();
125   Backup();
126   if (myValue.IsNull()) myValue = new TColStd_HSequenceOfInteger;
127   myValue->ChangeSequence() = other->Sequence();
128
129   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
130 }
131
132 void SALOMEDSImpl_AttributeSequenceOfInteger::ChangeValue(const Standard_Integer Index,const Standard_Integer Value) 
133 {
134   CheckLocked();  
135   Backup();
136   myValue->SetValue(Index, Value);
137   
138   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
139 }
140
141 void SALOMEDSImpl_AttributeSequenceOfInteger::Add(const Standard_Integer Value) 
142 {
143   CheckLocked();  
144   Backup();
145   myValue->Append(Value);
146   
147   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
148 }
149
150 void SALOMEDSImpl_AttributeSequenceOfInteger::Remove(const Standard_Integer Index) 
151 {
152   CheckLocked();  
153   Backup();
154   myValue->Remove(Index);
155   
156   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
157 }
158
159 Standard_Integer SALOMEDSImpl_AttributeSequenceOfInteger::Length() 
160 {
161   return myValue->Length();
162 }
163 Standard_Integer SALOMEDSImpl_AttributeSequenceOfInteger::Value(const Standard_Integer Index) 
164 {
165   return myValue->Value(Index);
166 }
167
168
169
170 TCollection_AsciiString SALOMEDSImpl_AttributeSequenceOfInteger::Save() 
171 {
172   Standard_Integer aLength = Length();
173   char* aResult = new char[aLength * 25];
174   aResult[0] = 0;
175   Standard_Integer aPosition = 0;
176   for (int i = 1; i <= aLength; i++) {
177     sprintf(aResult + aPosition , "%d ", Value(i));
178     aPosition += strlen(aResult + aPosition);
179   }
180   TCollection_AsciiString ret(aResult);
181   delete aResult;
182   
183   return ret;
184 }
185                         
186 void SALOMEDSImpl_AttributeSequenceOfInteger::Load(const TCollection_AsciiString& value) 
187 {
188   Handle(TColStd_HSequenceOfInteger) CasCadeSeq = new TColStd_HSequenceOfInteger;
189                           
190   char* aCopy = value.ToCString();
191   char* adr = strtok(aCopy, " ");
192   while (adr) {
193     int l =  atol(adr);
194     CasCadeSeq->Append(l);
195     adr = strtok(NULL, " ");
196   }
197   Assign(CasCadeSeq);
198 }