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>
24 #include <PlaneGCSSolver_BooleanWrapper.h>
26 #include <GeomDataAPI_Point2D.h>
27 #include <ModelAPI_AttributeDouble.h>
28 #include <SketchPlugin_ConstraintAngle.h>
29 #include <SketchPlugin_MultiRotation.h>
31 PlaneGCSSolver_AttributeBuilder::PlaneGCSSolver_AttributeBuilder(
32 PlaneGCSSolver_Storage* theStorage)
33 : PlaneGCSSolver_EntityBuilder(theStorage)
37 PlaneGCSSolver_AttributeBuilder::PlaneGCSSolver_AttributeBuilder(const StoragePtr& theStorage)
38 : PlaneGCSSolver_EntityBuilder(
39 std::dynamic_pointer_cast<PlaneGCSSolver_Storage>(theStorage).get())
43 static double* createParameter(PlaneGCSSolver_Storage* theStorage)
45 return theStorage ? theStorage->createParameter() : (new double(0));
48 static EntityWrapperPtr createBoolean(const AttributePtr& theAttribute)
50 BooleanWrapperPtr aWrapper;
51 AttributeBooleanPtr aBoolean =
52 std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(theAttribute);
54 aWrapper = BooleanWrapperPtr(new PlaneGCSSolver_BooleanWrapper(aBoolean->value()));
58 static EntityWrapperPtr createScalar(const AttributePtr& theAttribute,
59 PlaneGCSSolver_Storage* theStorage)
61 AttributeDoublePtr aScalar = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
63 return EntityWrapperPtr();
65 ScalarWrapperPtr aWrapper;
66 // following attributes should be converted from degrees to radians
67 // - value of the Angle constraint
68 // - angle of the Multi-Rotation constraint
69 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
70 if ((theAttribute->id() == SketchPlugin_Constraint::VALUE() &&
71 anOwner->getKind() == SketchPlugin_ConstraintAngle::ID()) ||
72 (theAttribute->id() == SketchPlugin_MultiRotation::ANGLE_ID() &&
73 anOwner->getKind() == SketchPlugin_MultiRotation::ID()))
74 aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_AngleWrapper(createParameter(theStorage)));
76 aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_ScalarWrapper(createParameter(theStorage)));
78 if (aScalar->isInitialized())
79 aWrapper->setValue(aScalar->value());
83 static EntityWrapperPtr createPoint(const AttributePtr& theAttribute,
84 PlaneGCSSolver_Storage* theStorage)
86 std::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
87 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
89 return EntityWrapperPtr();
91 GCSPointPtr aNewPoint(new GCS::Point);
93 aNewPoint->x = createParameter(theStorage);
94 aNewPoint->y = createParameter(theStorage);
95 if (aPoint2D->isInitialized()) {
96 *(aNewPoint->x) = aPoint2D->x();
97 *(aNewPoint->y) = aPoint2D->y();
100 return EntityWrapperPtr(new PlaneGCSSolver_PointWrapper(aNewPoint));
103 EntityWrapperPtr PlaneGCSSolver_AttributeBuilder::createAttribute(
104 AttributePtr theAttribute)
106 EntityWrapperPtr aResult;
108 aResult = myStorage->entity(theAttribute);
110 aResult = createPoint(theAttribute, myStorage);
112 aResult = createScalar(theAttribute, myStorage);
114 aResult = createBoolean(theAttribute);
115 if (aResult && !myStorage)
116 aResult->setExternal(true);