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