Salome HOME
Task 2.11. Ability to impose a midpoint on an arc (refers issue #3002)
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_AttributeBuilder.cpp
index 1cae520726c32b8c8a8609f04ea509a903ddef07..ca463c53d70f063745d9f062bf7c250cc6810d24 100644 (file)
@@ -1,13 +1,27 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:    PlaneGCSSolver_AttributeBuilder.cpp
-// Created: 10 Feb 2017
-// Author:  Artem ZHIDKOV
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include <PlaneGCSSolver_AngleWrapper.h>
 #include <PlaneGCSSolver_AttributeBuilder.h>
 #include <PlaneGCSSolver_PointWrapper.h>
 #include <PlaneGCSSolver_ScalarWrapper.h>
+#include <PlaneGCSSolver_BooleanWrapper.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <ModelAPI_AttributeDouble.h>
@@ -31,6 +45,16 @@ static double* createParameter(PlaneGCSSolver_Storage* theStorage)
   return theStorage ? theStorage->createParameter() : (new double(0));
 }
 
+static EntityWrapperPtr createBoolean(const AttributePtr& theAttribute)
+{
+  BooleanWrapperPtr aWrapper;
+  AttributeBooleanPtr aBoolean =
+      std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(theAttribute);
+  if (aBoolean)
+    aWrapper = BooleanWrapperPtr(new PlaneGCSSolver_BooleanWrapper(aBoolean->value()));
+  return aWrapper;
+}
+
 static EntityWrapperPtr createScalar(const AttributePtr&     theAttribute,
                                      PlaneGCSSolver_Storage* theStorage)
 {
@@ -51,7 +75,8 @@ static EntityWrapperPtr createScalar(const AttributePtr&     theAttribute,
   else
     aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_ScalarWrapper(createParameter(theStorage)));
 
-  aWrapper->setValue(aScalar->value());
+  if (aScalar->isInitialized())
+    aWrapper->setValue(aScalar->value());
   return aWrapper;
 }
 
@@ -66,9 +91,11 @@ static EntityWrapperPtr createPoint(const AttributePtr&     theAttribute,
   GCSPointPtr aNewPoint(new GCS::Point);
 
   aNewPoint->x = createParameter(theStorage);
-  *(aNewPoint->x) = aPoint2D->x();
   aNewPoint->y = createParameter(theStorage);
-  *(aNewPoint->y) = aPoint2D->y();
+  if (aPoint2D->isInitialized()) {
+    *(aNewPoint->x) = aPoint2D->x();
+    *(aNewPoint->y) = aPoint2D->y();
+  }
 
   return EntityWrapperPtr(new PlaneGCSSolver_PointWrapper(aNewPoint));
 }
@@ -83,13 +110,9 @@ EntityWrapperPtr PlaneGCSSolver_AttributeBuilder::createAttribute(
     aResult = createPoint(theAttribute, myStorage);
   if (!aResult)
     aResult = createScalar(theAttribute, myStorage);
+  if (!aResult)
+    aResult = createBoolean(theAttribute);
   if (aResult && !myStorage)
     aResult->setExternal(true);
   return aResult;
 }
-
-const std::list<GCSConstraintPtr>& PlaneGCSSolver_AttributeBuilder::constraints() const
-{
-  static std::list<GCSConstraintPtr> aList;
-  return aList;
-}