1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_AttributeIntArray.cpp
5 // Author: Natalia ERMOLAEVA
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>
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>
21 int Model_AttributeIntArray::size()
23 // checking the validity because attribute (as a field) may be presented,
24 // but without label: it is undoed
25 return (myArray.IsNull() || !myArray->IsValid()) ? 0 : myArray->Length();
28 void Model_AttributeIntArray::setSize(const int theSize)
30 if (myArray.IsNull() || !myArray->IsValid()) { // create array if it is not done yet
31 if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array)
32 myArray = TDataStd_IntegerArray::Set(myLab, 0, theSize);
33 owner()->data()->sendAttributeUpdated(this);
35 } else { // reset the old array
37 if (theSize != myArray->Length()) { // old data is not keept, a new array is created
38 Handle(TColStd_HArray1OfInteger) aNewArray = new TColStd_HArray1OfInteger(0, theSize - 1);
39 myArray->ChangeArray(aNewArray);
40 owner()->data()->sendAttributeUpdated(this);
42 } else { // size is zero => array must be erased
43 if (!myArray.IsNull()) {
45 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
46 owner()->data()->sendAttributeUpdated(this);
52 void Model_AttributeIntArray::setValue(const int theIndex,
55 if (myArray->Value(theIndex) != theValue) {
56 myArray->SetValue(theIndex, theValue);
57 owner()->data()->sendAttributeUpdated(this);
61 int Model_AttributeIntArray::value(const int theIndex)
63 return myArray->Value(theIndex);
66 Model_AttributeIntArray::Model_AttributeIntArray(TDF_Label& theLabel)
69 // check the attribute could be already presented in this doc (after load document)
71 myLab.FindAttribute(TDataStd_IntegerArray::GetID(), myArray) == Standard_True;