]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_AttributeIntArray.cpp
Salome HOME
Implementation of color as integer array attribute
[modules/shaper.git] / src / Model / Model_AttributeIntArray.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_AttributeIntArray.cpp
4 // Created:     6 Mar 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <Model_AttributeIntArray.h>
8 #include <ModelAPI_AttributeString.h>
9 #include <ModelAPI_Attribute.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_Object.h>
12
13 #include <Standard_TypeDef.hxx>
14 #include <TCollection_AsciiString.hxx>
15 #include <TCollection_ExtendedString.hxx>
16 #include <TDataStd_Integer.hxx>
17 #include <TDataStd_Name.hxx>
18
19 #include <string>
20
21 int Model_AttributeIntArray::size()
22 {
23   return myArray.IsNull() ? 0 : myArray->Length();
24 }
25
26 void Model_AttributeIntArray::setSize(const int theSize)
27 {
28   if (myArray.IsNull()) { // create array if it is not done yet
29     if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array)
30       myArray = TDataStd_IntegerArray::Set(myLab, 0, theSize);
31       owner()->data()->sendAttributeUpdated(this);
32     }
33   } else { // reset the old array
34     if (theSize) {
35       if (theSize != myArray->Length()) { // old data is not keept, a new array is created
36         Handle(TColStd_HArray1OfInteger) aNewArray = new TColStd_HArray1OfInteger(0, theSize - 1);
37         myArray->ChangeArray(aNewArray);
38         owner()->data()->sendAttributeUpdated(this);
39       }
40     } else { // size is zero => array must be erased
41       if (!myArray.IsNull()) {
42         myArray.Nullify();
43         myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
44         owner()->data()->sendAttributeUpdated(this);
45       }
46     }
47   }
48 }
49
50 void Model_AttributeIntArray::setValue(const int theIndex,
51                                        const int theValue)
52 {
53   if (myArray->Value(theIndex) != theValue) {
54     myArray->SetValue(theIndex, theValue);
55     owner()->data()->sendAttributeUpdated(this);
56   }
57 }
58
59 int Model_AttributeIntArray::value(const int theIndex)
60 {
61   return myArray->Value(theIndex);
62 }
63
64 Model_AttributeIntArray::Model_AttributeIntArray(TDF_Label& theLabel)
65 {
66   myLab = theLabel;
67   // check the attribute could be already presented in this doc (after load document)
68   myIsInitialized = 
69     myLab.FindAttribute(TDataStd_IntegerArray::GetID(), myArray) == Standard_True;
70 }