1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDSImpl_AttributeSequenceOfReal.cxx
21 // Author : Sergey RUIN
24 #include "SALOMEDSImpl_AttributeSequenceOfReal.hxx"
25 #include <Standard_GUID.hxx>
29 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeSequenceOfReal, SALOMEDSImpl_GenericAttribute )
30 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeSequenceOfReal, SALOMEDSImpl_GenericAttribute )
32 //=======================================================================
35 //=======================================================================
37 const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfReal::GetID ()
39 static Standard_GUID SALOMEDSImpl_AttributeSequenceOfRealID ("12837183-8F52-11d6-A8A3-0001021E8C7F");
40 return SALOMEDSImpl_AttributeSequenceOfRealID;
45 //=======================================================================
48 //=======================================================================
50 Handle(SALOMEDSImpl_AttributeSequenceOfReal) SALOMEDSImpl_AttributeSequenceOfReal::Set (const TDF_Label& L)
52 Handle(SALOMEDSImpl_AttributeSequenceOfReal) A;
53 if (!L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfReal::GetID(),A)) {
54 A = new SALOMEDSImpl_AttributeSequenceOfReal();
61 //=======================================================================
62 //function : constructor
64 //=======================================================================
65 SALOMEDSImpl_AttributeSequenceOfReal::SALOMEDSImpl_AttributeSequenceOfReal()
66 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfReal")
68 myValue = new TColStd_HSequenceOfReal();
71 //=======================================================================
74 //=======================================================================
76 const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfReal::ID () const { return GetID(); }
79 //=======================================================================
82 //=======================================================================
84 Handle(TDF_Attribute) SALOMEDSImpl_AttributeSequenceOfReal::NewEmpty () const
86 return new SALOMEDSImpl_AttributeSequenceOfReal();
89 //=======================================================================
92 //=======================================================================
94 void SALOMEDSImpl_AttributeSequenceOfReal::Restore(const Handle(TDF_Attribute)& with)
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));
108 //=======================================================================
111 //=======================================================================
113 void SALOMEDSImpl_AttributeSequenceOfReal::Paste (const Handle(TDF_Attribute)& into,
114 const Handle(TDF_RelocationTable)& ) const
116 if(!myValue.IsNull()) {
117 Handle(SALOMEDSImpl_AttributeSequenceOfReal)::DownCast (into)->Assign(myValue);
121 void SALOMEDSImpl_AttributeSequenceOfReal::Assign(const Handle(TColStd_HSequenceOfReal)& other)
125 if (myValue.IsNull()) myValue = new TColStd_HSequenceOfReal;
126 myValue->ChangeSequence() = other->Sequence();
128 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
131 void SALOMEDSImpl_AttributeSequenceOfReal::ChangeValue(const Standard_Integer Index,const Standard_Real Value)
135 myValue->SetValue(Index, Value);
137 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
140 void SALOMEDSImpl_AttributeSequenceOfReal::Add(const Standard_Real Value)
144 myValue->Append(Value);
146 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
149 void SALOMEDSImpl_AttributeSequenceOfReal::Remove(const Standard_Integer Index)
153 myValue->Remove(Index);
155 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
158 Standard_Integer SALOMEDSImpl_AttributeSequenceOfReal::Length()
160 return myValue->Length();
163 Standard_Real SALOMEDSImpl_AttributeSequenceOfReal::Value(const Standard_Integer Index)
165 return myValue->Value(Index);
169 TCollection_AsciiString SALOMEDSImpl_AttributeSequenceOfReal::Save()
171 Standard_Integer aLength = Length();
172 char* aResult = new char[aLength * 25];
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);
179 TCollection_AsciiString ret(aResult);
185 void SALOMEDSImpl_AttributeSequenceOfReal::Load(const TCollection_AsciiString& value)
187 Handle(TColStd_HSequenceOfReal) CasCadeSeq = new TColStd_HSequenceOfReal;
189 char* aCopy = value.ToCString();
190 char* adr = strtok(aCopy, " ");
193 Standard_Real r = strtod(adr, &err);
194 CasCadeSeq->Append(r);
195 adr = strtok(NULL, " ");