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