Salome HOME
using a better solution to do compare doubles for shape physical properties
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_PointArrayWrapper.cpp
1 // Copyright (C) 2019-2024  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <PlaneGCSSolver_PointArrayWrapper.h>
21 #include <PlaneGCSSolver_Tools.h>
22
23 #include <GeomDataAPI_Point2DArray.h>
24
25 #include <GeomAPI_Pnt2d.h>
26
27 PlaneGCSSolver_PointArrayWrapper::PlaneGCSSolver_PointArrayWrapper(
28     const std::vector<PointWrapperPtr>& thePoints)
29   : myPoints(thePoints)
30 {
31 }
32
33 bool PlaneGCSSolver_PointArrayWrapper::update(AttributePtr theAttribute)
34 {
35   bool isUpdated = false;
36   std::shared_ptr<GeomDataAPI_Point2DArray> aPointArray =
37       std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(theAttribute);
38   if (aPointArray && aPointArray->size() == (int)myPoints.size()) {
39     std::vector<PointWrapperPtr>::iterator aPIt = myPoints.begin();
40     for (int anIndex = 0; aPIt != myPoints.end(); ++aPIt, ++anIndex) {
41       GeomPnt2dPtr aPnt = aPointArray->pnt(anIndex);
42
43       const GCSPointPtr& aGCSPoint = (*aPIt)->point();
44       isUpdated = PlaneGCSSolver_Tools::updateValue(aPnt->x(), *(aGCSPoint->x)) || isUpdated;
45       isUpdated = PlaneGCSSolver_Tools::updateValue(aPnt->y(), *(aGCSPoint->y)) || isUpdated;
46     }
47   }
48   return isUpdated;
49 }