1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <PlaneGCSSolver_AngleWrapper.h>
22 #include <PlaneGCSSolver_AttributeBuilder.h>
23 #include <PlaneGCSSolver_PointWrapper.h>
24 #include <PlaneGCSSolver_ScalarWrapper.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 createScalar(const AttributePtr& theAttribute,
49 PlaneGCSSolver_Storage* theStorage)
51 AttributeDoublePtr aScalar = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
53 return EntityWrapperPtr();
55 ScalarWrapperPtr aWrapper;
56 // following attributes should be converted from degrees to radians
57 // - value of the Angle constraint
58 // - angle of the Multi-Rotation constraint
59 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
60 if ((theAttribute->id() == SketchPlugin_Constraint::VALUE() &&
61 anOwner->getKind() == SketchPlugin_ConstraintAngle::ID()) ||
62 (theAttribute->id() == SketchPlugin_MultiRotation::ANGLE_ID() &&
63 anOwner->getKind() == SketchPlugin_MultiRotation::ID()))
64 aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_AngleWrapper(createParameter(theStorage)));
66 aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_ScalarWrapper(createParameter(theStorage)));
68 if (aScalar->isInitialized())
69 aWrapper->setValue(aScalar->value());
73 static EntityWrapperPtr createPoint(const AttributePtr& theAttribute,
74 PlaneGCSSolver_Storage* theStorage)
76 std::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
77 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
79 return EntityWrapperPtr();
81 GCSPointPtr aNewPoint(new GCS::Point);
83 aNewPoint->x = createParameter(theStorage);
84 aNewPoint->y = createParameter(theStorage);
85 if (aPoint2D->isInitialized()) {
86 *(aNewPoint->x) = aPoint2D->x();
87 *(aNewPoint->y) = aPoint2D->y();
90 return EntityWrapperPtr(new PlaneGCSSolver_PointWrapper(aNewPoint));
93 EntityWrapperPtr PlaneGCSSolver_AttributeBuilder::createAttribute(
94 AttributePtr theAttribute)
96 EntityWrapperPtr aResult;
98 aResult = myStorage->entity(theAttribute);
100 aResult = createPoint(theAttribute, myStorage);
102 aResult = createScalar(theAttribute, myStorage);
103 if (aResult && !myStorage)
104 aResult->setExternal(true);