1 // Copyright (C) 2019-2020 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 email : webmaster.salome@opencascade.com
20 #include "GeomData_Point2DArray.h"
22 #include <GeomAPI_Pnt2d.h>
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_Events.h>
26 #include <ModelAPI_Expression.h>
27 #include <ModelAPI_Feature.h>
31 GeomData_Point2DArray::GeomData_Point2DArray(TDF_Label& theLabel)
37 void GeomData_Point2DArray::reinit()
39 // check the attribute could be already presented in this doc (after load document)
40 myIsInitialized = myLab.FindAttribute(TDataStd_RealArray::GetID(), myArray) == Standard_True;
43 bool GeomData_Point2DArray::assign(std::shared_ptr<GeomDataAPI_Point2DArray> theOther)
45 std::shared_ptr<GeomData_Point2DArray> anOther =
46 std::dynamic_pointer_cast<GeomData_Point2DArray>(theOther);
50 setSize(anOther->size());
51 myArray->ChangeArray(anOther->myArray->Array(), false);
54 int GeomData_Point2DArray::size()
56 if (myArray.IsNull() || !myArray->IsValid()) {
57 // this could be on undo and then redo creation of the attribute
58 // in result creation it may be uninitialized
59 myIsInitialized = myLab.FindAttribute(TDataStd_RealArray::GetID(), myArray) == Standard_True;
61 // checking the validity because attribute (as a field) may be presented,
62 // but without label: it is undoed
63 return (myArray.IsNull() || !myArray->IsValid()) ? 0 : myArray->Length() / 2;
66 void GeomData_Point2DArray::setSize(const int theSize)
68 int aValuesSize = 2 * theSize;
69 if (myArray.IsNull() || !myArray->IsValid()) { // create array if it is not done yet
70 if (aValuesSize != 0) { // if size is zero, nothing to do (null array means there is no array)
71 myArray = TDataStd_RealArray::Set(myLab, 0, aValuesSize - 1);
72 owner()->data()->sendAttributeUpdated(this);
75 else { // reset the old array
77 if (aValuesSize != myArray->Length()) { // old data is not keept, a new array is created
78 Handle(TColStd_HArray1OfReal) aNewArray = new TColStd_HArray1OfReal(0, aValuesSize - 1);
79 myArray->ChangeArray(aNewArray);
80 owner()->data()->sendAttributeUpdated(this);
83 else { // size is zero => array must be erased
84 if (!myArray.IsNull()) {
86 myLab.ForgetAttribute(TDataStd_RealArray::GetID());
87 owner()->data()->sendAttributeUpdated(this);
93 void GeomData_Point2DArray::setPnt(const int theIndex,
97 if (myArray->Value(2 * theIndex) != theX || myArray->Value(2 * theIndex + 1) != theY) {
98 myArray->SetValue(2 * theIndex, theX);
99 myArray->SetValue(2 * theIndex + 1, theY);
100 owner()->data()->sendAttributeUpdated(this);
104 void GeomData_Point2DArray::setPnt(const int theIndex, const GeomPnt2dPtr& thePoint)
106 setPnt(theIndex, thePoint->x(), thePoint->y());
109 GeomPnt2dPtr GeomData_Point2DArray::pnt(const int theIndex)
112 if (theIndex >= 0 && theIndex * 2 < myArray->Length())
113 aPoint.reset(new GeomAPI_Pnt2d(myArray->Value(2 * theIndex), myArray->Value(2 * theIndex + 1)));