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