1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PlaneGCSSolver_AttributeBuilder.cpp
4 // Created: 10 Feb 2017
5 // Author: Artem ZHIDKOV
7 #include <PlaneGCSSolver_AngleWrapper.h>
8 #include <PlaneGCSSolver_AttributeBuilder.h>
9 #include <PlaneGCSSolver_PointWrapper.h>
10 #include <PlaneGCSSolver_ScalarWrapper.h>
12 #include <GeomDataAPI_Point2D.h>
13 #include <ModelAPI_AttributeDouble.h>
14 #include <SketchPlugin_ConstraintAngle.h>
15 #include <SketchPlugin_MultiRotation.h>
17 PlaneGCSSolver_AttributeBuilder::PlaneGCSSolver_AttributeBuilder(
18 PlaneGCSSolver_Storage* theStorage)
19 : PlaneGCSSolver_EntityBuilder(theStorage)
23 PlaneGCSSolver_AttributeBuilder::PlaneGCSSolver_AttributeBuilder(const StoragePtr& theStorage)
24 : PlaneGCSSolver_EntityBuilder(
25 std::dynamic_pointer_cast<PlaneGCSSolver_Storage>(theStorage).get())
29 static double* createParameter(PlaneGCSSolver_Storage* theStorage)
31 return theStorage ? theStorage->createParameter() : (new double(0));
34 static EntityWrapperPtr createScalar(const AttributePtr& theAttribute,
35 PlaneGCSSolver_Storage* theStorage)
37 AttributeDoublePtr aScalar = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
39 return EntityWrapperPtr();
41 ScalarWrapperPtr aWrapper;
42 // following attributes should be converted from degrees to radians
43 // - value of the Angle constraint
44 // - angle of the Multi-Rotation constraint
45 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
46 if ((theAttribute->id() == SketchPlugin_Constraint::VALUE() &&
47 anOwner->getKind() == SketchPlugin_ConstraintAngle::ID()) ||
48 (theAttribute->id() == SketchPlugin_MultiRotation::ANGLE_ID() &&
49 anOwner->getKind() == SketchPlugin_MultiRotation::ID()))
50 aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_AngleWrapper(createParameter(theStorage)));
52 aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_ScalarWrapper(createParameter(theStorage)));
54 aWrapper->setValue(aScalar->value());
58 static EntityWrapperPtr createPoint(const AttributePtr& theAttribute,
59 PlaneGCSSolver_Storage* theStorage)
61 std::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
62 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
64 return EntityWrapperPtr();
66 GCSPointPtr aNewPoint(new GCS::Point);
68 aNewPoint->x = createParameter(theStorage);
69 *(aNewPoint->x) = aPoint2D->x();
70 aNewPoint->y = createParameter(theStorage);
71 *(aNewPoint->y) = aPoint2D->y();
73 return EntityWrapperPtr(new PlaneGCSSolver_PointWrapper(aNewPoint));
76 EntityWrapperPtr PlaneGCSSolver_AttributeBuilder::createAttribute(
77 AttributePtr theAttribute)
79 EntityWrapperPtr aResult;
81 aResult = myStorage->entity(theAttribute);
83 aResult = createPoint(theAttribute, myStorage);
85 aResult = createScalar(theAttribute, myStorage);
86 if (aResult && !myStorage)
87 aResult->setExternal(true);
91 const std::list<GCSConstraintPtr>& PlaneGCSSolver_AttributeBuilder::constraints() const
93 static std::list<GCSConstraintPtr> aList;