Salome HOME
Merging from V3_2_6pre4
[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/ or email : webmaster.salome@opencascade.com
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
136   if(Index <= 0 || Index > myValue->Length()) Standard_Failure::Raise("Out of range");
137
138   myValue->SetValue(Index, Value);
139   
140   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
141 }
142
143 void SALOMEDSImpl_AttributeSequenceOfReal::Add(const Standard_Real Value) 
144 {
145   CheckLocked();  
146   Backup();
147   myValue->Append(Value);
148   
149   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
150 }
151
152 void SALOMEDSImpl_AttributeSequenceOfReal::Remove(const Standard_Integer Index) 
153 {
154   CheckLocked();  
155   Backup();
156
157   if(Index <= 0 || Index > myValue->Length()) Standard_Failure::Raise("Out of range");
158
159   myValue->Remove(Index);
160   
161   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
162 }
163
164 Standard_Integer SALOMEDSImpl_AttributeSequenceOfReal::Length() 
165 {
166   return myValue->Length();
167 }
168
169 Standard_Real SALOMEDSImpl_AttributeSequenceOfReal::Value(const Standard_Integer Index) 
170 {
171   if(Index <= 0 || Index > myValue->Length()) Standard_Failure::Raise("Out of range");
172   return myValue->Value(Index);
173 }
174
175
176 TCollection_AsciiString SALOMEDSImpl_AttributeSequenceOfReal::Save()
177 {
178   Standard_Integer aLength = Length();
179   char* aResult = new char[aLength * 25];
180   aResult[0] = 0;
181   Standard_Integer aPosition = 0;
182   for (int i = 1; i <= aLength; i++) {
183     sprintf(aResult + aPosition , "%f ", Value(i));
184     aPosition += strlen(aResult + aPosition);
185   }
186   TCollection_AsciiString ret(aResult);
187   delete aResult;
188                           
189   return ret;
190 }
191                             
192 void SALOMEDSImpl_AttributeSequenceOfReal::Load(const TCollection_AsciiString& value)
193 {
194   Handle(TColStd_HSequenceOfReal) CasCadeSeq = new TColStd_HSequenceOfReal;
195                               
196   char* aCopy = value.ToCString();
197   char* adr = strtok(aCopy, " ");
198   char *err = NULL; 
199   while (adr) {
200     Standard_Real r =  strtod(adr, &err); 
201     CasCadeSeq->Append(r);
202     adr = strtok(NULL, " ");
203   }
204   Assign(CasCadeSeq);
205 }