]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_AttributeBuilder.cpp
Salome HOME
Fix incorrect processing of the copied entities after the "Multi" constraint has...
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_AttributeBuilder.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    PlaneGCSSolver_AttributeBuilder.cpp
4 // Created: 10 Feb 2017
5 // Author:  Artem ZHIDKOV
6
7 #include <PlaneGCSSolver_AngleWrapper.h>
8 #include <PlaneGCSSolver_AttributeBuilder.h>
9 #include <PlaneGCSSolver_PointWrapper.h>
10 #include <PlaneGCSSolver_ScalarWrapper.h>
11
12 #include <GeomDataAPI_Point2D.h>
13 #include <ModelAPI_AttributeDouble.h>
14 #include <SketchPlugin_ConstraintAngle.h>
15 #include <SketchPlugin_MultiRotation.h>
16
17 PlaneGCSSolver_AttributeBuilder::PlaneGCSSolver_AttributeBuilder(
18     PlaneGCSSolver_Storage* theStorage)
19   : PlaneGCSSolver_EntityBuilder(theStorage)
20 {
21 }
22
23 PlaneGCSSolver_AttributeBuilder::PlaneGCSSolver_AttributeBuilder(const StoragePtr& theStorage)
24   : PlaneGCSSolver_EntityBuilder(
25         std::dynamic_pointer_cast<PlaneGCSSolver_Storage>(theStorage).get())
26 {
27 }
28
29 static double* createParameter(PlaneGCSSolver_Storage* theStorage)
30 {
31   return theStorage ? theStorage->createParameter() : (new double(0));
32 }
33
34 static EntityWrapperPtr createScalar(const AttributePtr&     theAttribute,
35                                      PlaneGCSSolver_Storage* theStorage)
36 {
37   AttributeDoublePtr aScalar = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
38   if (!aScalar)
39     return EntityWrapperPtr();
40
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)));
51   else
52     aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_ScalarWrapper(createParameter(theStorage)));
53
54   if (aScalar->isInitialized())
55     aWrapper->setValue(aScalar->value());
56   return aWrapper;
57 }
58
59 static EntityWrapperPtr createPoint(const AttributePtr&     theAttribute,
60                                     PlaneGCSSolver_Storage* theStorage)
61 {
62   std::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
63       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
64   if (!aPoint2D)
65     return EntityWrapperPtr();
66
67   GCSPointPtr aNewPoint(new GCS::Point);
68
69   aNewPoint->x = createParameter(theStorage);
70   aNewPoint->y = createParameter(theStorage);
71   if (aPoint2D->isInitialized()) {
72     *(aNewPoint->x) = aPoint2D->x();
73     *(aNewPoint->y) = aPoint2D->y();
74   }
75
76   return EntityWrapperPtr(new PlaneGCSSolver_PointWrapper(aNewPoint));
77 }
78
79 EntityWrapperPtr PlaneGCSSolver_AttributeBuilder::createAttribute(
80     AttributePtr theAttribute)
81 {
82   EntityWrapperPtr aResult;
83   if (myStorage)
84     aResult = myStorage->entity(theAttribute);
85   if (!aResult)
86     aResult = createPoint(theAttribute, myStorage);
87   if (!aResult)
88     aResult = createScalar(theAttribute, myStorage);
89   if (aResult && !myStorage)
90     aResult->setExternal(true);
91   return aResult;
92 }