1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "Model_AttributeDoubleArray.h"
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_Object.h>
26 #include <TColStd_HArray1OfReal.hxx>
30 //==================================================================================================
31 int Model_AttributeDoubleArray::size()
33 if (myArray.IsNull() || !myArray->IsValid()) {
34 // this could be on undo and then redo creation of the attribute
35 // in result creation it may be uninitialized
36 myIsInitialized = myLab.FindAttribute(TDataStd_RealArray::GetID(), myArray) == Standard_True;
38 // checking the validity because attribute (as a field) may be presented,
39 // but without label: it is undoed
40 return (myArray.IsNull() || !myArray->IsValid()) ? 0 : myArray->Length();
43 //==================================================================================================
44 void Model_AttributeDoubleArray::setSize(const int theSize)
46 if (myArray.IsNull() || !myArray->IsValid()) { // create array if it is not done yet
47 if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array)
48 myArray = TDataStd_RealArray::Set(myLab, 0, theSize - 1);
49 owner()->data()->sendAttributeUpdated(this);
51 } else { // reset the old array
53 if (theSize != myArray->Length()) { // old data is not keept, a new array is created
54 Handle(TColStd_HArray1OfReal) aNewArray = new TColStd_HArray1OfReal(0, theSize - 1);
55 myArray->ChangeArray(aNewArray);
56 owner()->data()->sendAttributeUpdated(this);
58 } else { // size is zero => array must be erased
59 if (!myArray.IsNull()) {
61 myLab.ForgetAttribute(TDataStd_RealArray::GetID());
62 owner()->data()->sendAttributeUpdated(this);
68 //==================================================================================================
69 void Model_AttributeDoubleArray::setValue(const int theIndex,
70 const double theValue)
72 if (myArray->Value(theIndex) != theValue) {
73 myArray->SetValue(theIndex, theValue);
74 owner()->data()->sendAttributeUpdated(this);
78 //==================================================================================================
79 double Model_AttributeDoubleArray::value(const int theIndex)
81 return myArray->Value(theIndex);
84 //==================================================================================================
85 Model_AttributeDoubleArray::Model_AttributeDoubleArray(TDF_Label& theLabel)
91 void Model_AttributeDoubleArray::reinit()
93 // check the attribute could be already presented in this doc (after load document)
95 myLab.FindAttribute(TDataStd_RealArray::GetID(), myArray) == Standard_True;