1 // Copyright (C) 2014-2019 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 <PlaneGCSSolver_AngleWrapper.h>
21 #include <PlaneGCSSolver_AttributeBuilder.h>
22 #include <PlaneGCSSolver_PointWrapper.h>
23 #include <PlaneGCSSolver_ScalarWrapper.h>
25 #include <GeomDataAPI_Point2D.h>
26 #include <ModelAPI_AttributeDouble.h>
27 #include <SketchPlugin_ConstraintAngle.h>
28 #include <SketchPlugin_MultiRotation.h>
30 PlaneGCSSolver_AttributeBuilder::PlaneGCSSolver_AttributeBuilder(
31 PlaneGCSSolver_Storage* theStorage)
32 : PlaneGCSSolver_EntityBuilder(theStorage)
36 PlaneGCSSolver_AttributeBuilder::PlaneGCSSolver_AttributeBuilder(const StoragePtr& theStorage)
37 : PlaneGCSSolver_EntityBuilder(
38 std::dynamic_pointer_cast<PlaneGCSSolver_Storage>(theStorage).get())
42 static double* createParameter(PlaneGCSSolver_Storage* theStorage)
44 return theStorage ? theStorage->createParameter() : (new double(0));
47 static EntityWrapperPtr createScalar(const AttributePtr& theAttribute,
48 PlaneGCSSolver_Storage* theStorage)
50 AttributeDoublePtr aScalar = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
52 return EntityWrapperPtr();
54 ScalarWrapperPtr aWrapper;
55 // following attributes should be converted from degrees to radians
56 // - value of the Angle constraint
57 // - angle of the Multi-Rotation constraint
58 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
59 if ((theAttribute->id() == SketchPlugin_Constraint::VALUE() &&
60 anOwner->getKind() == SketchPlugin_ConstraintAngle::ID()) ||
61 (theAttribute->id() == SketchPlugin_MultiRotation::ANGLE_ID() &&
62 anOwner->getKind() == SketchPlugin_MultiRotation::ID()))
63 aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_AngleWrapper(createParameter(theStorage)));
65 aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_ScalarWrapper(createParameter(theStorage)));
67 if (aScalar->isInitialized())
68 aWrapper->setValue(aScalar->value());
72 static EntityWrapperPtr createPoint(const AttributePtr& theAttribute,
73 PlaneGCSSolver_Storage* theStorage)
75 std::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
76 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
78 return EntityWrapperPtr();
80 GCSPointPtr aNewPoint(new GCS::Point);
82 aNewPoint->x = createParameter(theStorage);
83 aNewPoint->y = createParameter(theStorage);
84 if (aPoint2D->isInitialized()) {
85 *(aNewPoint->x) = aPoint2D->x();
86 *(aNewPoint->y) = aPoint2D->y();
89 return EntityWrapperPtr(new PlaneGCSSolver_PointWrapper(aNewPoint));
92 EntityWrapperPtr PlaneGCSSolver_AttributeBuilder::createAttribute(
93 AttributePtr theAttribute)
95 EntityWrapperPtr aResult;
97 aResult = myStorage->entity(theAttribute);
99 aResult = createPoint(theAttribute, myStorage);
101 aResult = createScalar(theAttribute, myStorage);
102 if (aResult && !myStorage)
103 aResult->setExternal(true);