1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_AttributeStringArray.cpp
4 // Created: 14 Nov 2016
5 // Author: Mikhail Ponikarov
7 #include "Model_AttributeStringArray.h"
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Object.h>
12 #include <TColStd_HArray1OfExtendedString.hxx>
14 //==================================================================================================
15 int Model_AttributeStringArray::size()
17 if (myArray.IsNull() || !myArray->IsValid()) {
18 // this could be on undo and then redo creation of the attribute
19 // in result creation it may be uninitialized
21 myLab.FindAttribute(TDataStd_ExtStringArray::GetID(), myArray) == Standard_True;
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 //==================================================================================================
29 void Model_AttributeStringArray::setSize(const int theSize)
31 if (myArray.IsNull() || !myArray->IsValid()) { // create array if it is not done yet
32 if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array)
33 myArray = TDataStd_ExtStringArray::Set(myLab, 0, theSize - 1);
34 owner()->data()->sendAttributeUpdated(this);
36 } else { // reset the old array
38 if (theSize != myArray->Length()) { // old data is not keept, a new array is created
39 Handle(TColStd_HArray1OfExtendedString) aNewArray =
40 new TColStd_HArray1OfExtendedString(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_ExtStringArray::GetID());
48 owner()->data()->sendAttributeUpdated(this);
54 //==================================================================================================
55 void Model_AttributeStringArray::setValue(const int theIndex,
56 const std::string theValue)
58 if (!myArray->Value(theIndex).IsEqual(theValue.c_str())) {
59 myArray->SetValue(theIndex, theValue.c_str());
60 owner()->data()->sendAttributeUpdated(this);
64 //==================================================================================================
65 std::string Model_AttributeStringArray::value(const int theIndex)
67 return TCollection_AsciiString(myArray->Value(theIndex)).ToCString();
70 //==================================================================================================
71 Model_AttributeStringArray::Model_AttributeStringArray(TDF_Label& theLabel)
75 myLab.FindAttribute(TDataStd_ExtStringArray::GetID(), myArray) == Standard_True;