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_AttributeSequenceOfInteger.cxx
21 // Author : Sergey RUIN
24 #include "SALOMEDSImpl_AttributeSequenceOfInteger.hxx"
25 #include <Standard_GUID.hxx>
29 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute )
30 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute )
33 //=======================================================================
36 //=======================================================================
38 const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::GetID ()
40 static Standard_GUID SALOMEDSImpl_AttributeSequenceOfIntegerID ("12837182-8F52-11d6-A8A3-0001021E8C7F");
41 return SALOMEDSImpl_AttributeSequenceOfIntegerID;
46 //=======================================================================
49 //=======================================================================
51 Handle(SALOMEDSImpl_AttributeSequenceOfInteger) SALOMEDSImpl_AttributeSequenceOfInteger::Set (const TDF_Label& L)
53 Handle(SALOMEDSImpl_AttributeSequenceOfInteger) A;
54 if (!L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfInteger::GetID(),A)) {
55 A = new SALOMEDSImpl_AttributeSequenceOfInteger();
62 //=======================================================================
63 //function : constructor
65 //=======================================================================
66 SALOMEDSImpl_AttributeSequenceOfInteger::SALOMEDSImpl_AttributeSequenceOfInteger()
67 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfInteger")
69 myValue = new TColStd_HSequenceOfInteger();
72 //=======================================================================
75 //=======================================================================
77 const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::ID () const { return GetID(); }
80 //=======================================================================
83 //=======================================================================
85 Handle(TDF_Attribute) SALOMEDSImpl_AttributeSequenceOfInteger::NewEmpty () const
87 return new SALOMEDSImpl_AttributeSequenceOfInteger();
90 //=======================================================================
93 //=======================================================================
95 void SALOMEDSImpl_AttributeSequenceOfInteger::Restore(const Handle(TDF_Attribute)& with)
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));
109 //=======================================================================
112 //=======================================================================
114 void SALOMEDSImpl_AttributeSequenceOfInteger::Paste (const Handle(TDF_Attribute)& into,
115 const Handle(TDF_RelocationTable)& ) const
117 if(!myValue.IsNull()) {
118 Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast (into)->Assign(myValue);
122 void SALOMEDSImpl_AttributeSequenceOfInteger::Assign(const Handle(TColStd_HSequenceOfInteger)& other)
126 if (myValue.IsNull()) myValue = new TColStd_HSequenceOfInteger;
127 myValue->ChangeSequence() = other->Sequence();
129 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
132 void SALOMEDSImpl_AttributeSequenceOfInteger::ChangeValue(const Standard_Integer Index,const Standard_Integer Value)
136 myValue->SetValue(Index, Value);
138 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
141 void SALOMEDSImpl_AttributeSequenceOfInteger::Add(const Standard_Integer Value)
145 myValue->Append(Value);
147 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
150 void SALOMEDSImpl_AttributeSequenceOfInteger::Remove(const Standard_Integer Index)
154 myValue->Remove(Index);
156 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
159 Standard_Integer SALOMEDSImpl_AttributeSequenceOfInteger::Length()
161 return myValue->Length();
163 Standard_Integer SALOMEDSImpl_AttributeSequenceOfInteger::Value(const Standard_Integer Index)
165 return myValue->Value(Index);
170 TCollection_AsciiString SALOMEDSImpl_AttributeSequenceOfInteger::Save()
172 Standard_Integer aLength = Length();
173 char* aResult = new char[aLength * 25];
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);
180 TCollection_AsciiString ret(aResult);
186 void SALOMEDSImpl_AttributeSequenceOfInteger::Load(const TCollection_AsciiString& value)
188 Handle(TColStd_HSequenceOfInteger) CasCadeSeq = new TColStd_HSequenceOfInteger;
190 char* aCopy = value.ToCString();
191 char* adr = strtok(aCopy, " ");
194 CasCadeSeq->Append(l);
195 adr = strtok(NULL, " ");