]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_AttributeBuilder.cpp
Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_AttributeBuilder.cpp
index 24659d40681c0a562ca0c1616bfb3ed6898d1e47..d129baeffacc0040eb13ddd86f3fbf4b3797f6a0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -33,6 +33,7 @@
 #include <ModelAPI_AttributeDoubleArray.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <SketchPlugin_BSpline.h>
+#include <SketchPlugin_BSplinePeriodic.h>
 #include <SketchPlugin_ConstraintAngle.h>
 #include <SketchPlugin_MultiRotation.h>
 
@@ -88,8 +89,9 @@ static EntityWrapperPtr createScalar(const AttributePtr&     theAttribute,
      (theAttribute->id() == SketchPlugin_MultiRotation::ANGLE_ID() &&
       anOwner->getKind() == SketchPlugin_MultiRotation::ID()))
     aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_AngleWrapper(createParameter(theStorage)));
-  else if (anOwner->getKind() == SketchPlugin_BSpline::ID() &&
-           theAttribute->id() == SketchPlugin_BSpline::DEGREE_ID())
+  else if ((anOwner->getKind() == SketchPlugin_BSpline::ID() ||
+            anOwner->getKind() == SketchPlugin_BSplinePeriodic::ID()) &&
+           theAttribute->id() == SketchPlugin_BSplineBase::DEGREE_ID())
     // Degree of B-spline is not processed by the solver
     aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_ScalarWrapper(createParameter(nullptr)));
   else
@@ -99,6 +101,13 @@ static EntityWrapperPtr createScalar(const AttributePtr&     theAttribute,
   return aWrapper;
 }
 
+template <typename TYPE>
+static bool nonSolverAttribute(const FeaturePtr theOwner, const std::string& theAttrId)
+{
+  return theOwner->getKind() == TYPE::ID() && (theAttrId == TYPE::WEIGHTS_ID()
+      || theAttrId == TYPE::KNOTS_ID() || theAttrId == TYPE::MULTS_ID());
+}
+
 static EntityWrapperPtr createScalarArray(const AttributePtr&     theAttribute,
                                           PlaneGCSSolver_Storage* theStorage)
 {
@@ -110,10 +119,8 @@ static EntityWrapperPtr createScalarArray(const AttributePtr&     theAttribute,
   PlaneGCSSolver_Storage* aStorage = theStorage;
   // Weights, knots and multiplicities of B-spline curve are not processed by the solver
   FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
-  if (anOwner->getKind() == SketchPlugin_BSpline::ID() &&
-      (theAttribute->id() == SketchPlugin_BSpline::WEIGHTS_ID() ||
-       theAttribute->id() == SketchPlugin_BSpline::KNOTS_ID() ||
-       theAttribute->id() == SketchPlugin_BSpline::MULTS_ID()))
+  if (nonSolverAttribute<SketchPlugin_BSpline>(anOwner, theAttribute->id()) ||
+      nonSolverAttribute<SketchPlugin_BSplinePeriodic>(anOwner, theAttribute->id()))
     aStorage = 0;
 
   int aSize = anArray.size();
@@ -209,11 +216,20 @@ bool PlaneGCSSolver_AttributeBuilder::updateAttribute(
     std::shared_ptr<GeomDataAPI_Point2DArray> anAttribute =
         std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(theAttribute);
 
+    std::vector<PointWrapperPtr> aPointsArray = aWrapper->array();
+    std::vector<PointWrapperPtr>::iterator aPos = aPointsArray.begin();
     if (aWrapper->size() != anAttribute->size()) {
-      std::vector<PointWrapperPtr> aPointsArray = aWrapper->array();
       while (anAttribute->size() > (int)aPointsArray.size()) {
         // add points to the middle of array
-        aPointsArray.insert(--aPointsArray.end(), createPoint(GeomPnt2dPtr(), myStorage));
+        GeomPnt2dPtr aValue;
+        for (; aPos != aPointsArray.end(); ++aPos) {
+          aValue = anAttribute->pnt(aPos - aPointsArray.begin());
+          if (aValue->distance(PlaneGCSSolver_Tools::point(*aPos)) > tolerance)
+            break;
+        }
+        int aShift = aPos - aPointsArray.begin();
+        aPointsArray.insert(aPos, createPoint(aValue, myStorage));
+        aPos = aPointsArray.begin() + aShift;
       }
 
       while (anAttribute->size() < (int)aPointsArray.size()) {
@@ -226,6 +242,15 @@ bool PlaneGCSSolver_AttributeBuilder::updateAttribute(
 
       aWrapper->setArray(aPointsArray);
     }
+    else {
+      // update coordinates of points
+      for (int anIndex = 0; aPos != aPointsArray.end(); ++aPos, ++anIndex) {
+        const GCSPointPtr& aGCSPoint = (*aPos)->point();
+        GeomPnt2dPtr aCoord = anAttribute->pnt(anIndex);
+        *aGCSPoint->x = aCoord->x();
+        *aGCSPoint->y = aCoord->y();
+      }
+    }
   }
   else if (theEntity->type() == ENTITY_SCALAR_ARRAY) {
     std::shared_ptr<PlaneGCSSolver_ScalarArrayWrapper> aWrapper =
@@ -234,7 +259,7 @@ bool PlaneGCSSolver_AttributeBuilder::updateAttribute(
       aParamsToRemove = PlaneGCSSolver_Tools::parameters(aWrapper);
       std::shared_ptr<PlaneGCSSolver_ScalarArrayWrapper> aNewArray =
           std::dynamic_pointer_cast<PlaneGCSSolver_ScalarArrayWrapper>(
-          createAttribute(theAttribute));
+          createScalarArray(theAttribute, myStorage));
       aWrapper->setArray(aNewArray->array());
       isUpdated = true;
     }