1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_AttributeDoubleArray.cpp
4 // Created: 08 July 2016
5 // Author: Dmitry Bobylev
7 #include "Model_AttributeDoubleArray.h"
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Object.h>
12 #include <TColStd_HArray1OfReal.hxx>
16 //==================================================================================================
17 int Model_AttributeDoubleArray::size()
19 if (myArray.IsNull() || !myArray->IsValid()) {
20 // this could be on undo and then redo creation of the attribute
21 // in result creation it may be uninitialized
22 myIsInitialized = myLab.FindAttribute(TDataStd_RealArray::GetID(), myArray) == Standard_True;
24 // checking the validity because attribute (as a field) may be presented,
25 // but without label: it is undoed
26 return (myArray.IsNull() || !myArray->IsValid()) ? 0 : myArray->Length();
29 //==================================================================================================
30 void Model_AttributeDoubleArray::setSize(const int theSize)
32 if (myArray.IsNull() || !myArray->IsValid()) { // create array if it is not done yet
33 if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array)
34 myArray = TDataStd_RealArray::Set(myLab, 0, theSize - 1);
35 owner()->data()->sendAttributeUpdated(this);
37 } else { // reset the old array
39 if (theSize != myArray->Length()) { // old data is not keept, a new array is created
40 Handle(TColStd_HArray1OfReal) aNewArray = new TColStd_HArray1OfReal(0, theSize - 1);
41 myArray->ChangeArray(aNewArray);
42 owner()->data()->sendAttributeUpdated(this);
44 } else { // size is zero => array must be erased
45 if (!myArray.IsNull()) {
47 myLab.ForgetAttribute(TDataStd_RealArray::GetID());
48 owner()->data()->sendAttributeUpdated(this);
54 //==================================================================================================
55 void Model_AttributeDoubleArray::setValue(const int theIndex,
56 const double theValue)
58 if (myArray->Value(theIndex) != theValue) {
59 myArray->SetValue(theIndex, theValue);
60 owner()->data()->sendAttributeUpdated(this);
64 //==================================================================================================
65 double Model_AttributeDoubleArray::value(const int theIndex)
67 return myArray->Value(theIndex);
70 //==================================================================================================
71 Model_AttributeDoubleArray::Model_AttributeDoubleArray(TDF_Label& theLabel)
77 void Model_AttributeDoubleArray::reinit()
79 // check the attribute could be already presented in this doc (after load document)
81 myLab.FindAttribute(TDataStd_RealArray::GetID(), myArray) == Standard_True;