Salome HOME
2.17. Improved management of overconstraint situation: Processing added arguments...
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_RevolutionSketch.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        FeaturesPlugin_RevolutionSketch.cpp
4 // Created:     11 September 2015
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesPlugin_RevolutionSketch.h"
8
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_AttributeSelection.h>
11 #include <ModelAPI_AttributeString.h>
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Validator.h>
14
15 #include <GeomAlgoAPI_Revolution.h>
16 #include <GeomAPI_Edge.h>
17 #include <GeomAPI_Lin.h>
18
19 //=================================================================================================
20 FeaturesPlugin_RevolutionSketch::FeaturesPlugin_RevolutionSketch()
21 {
22 }
23
24 //=================================================================================================
25 void FeaturesPlugin_RevolutionSketch::initMakeSolidsAttributes()
26 {
27   data()->addAttribute(FeaturesPlugin_RevolutionSketch::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
28
29   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
30
31   data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
32   data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
33
34   data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
35   data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
36
37   data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
38   data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
39
40   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
41   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
42 }
43
44 //=================================================================================================
45 void FeaturesPlugin_RevolutionSketch::makeSolid(const std::shared_ptr<GeomAPI_Shape> theFace,
46                                                 std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape)
47 {
48   //Getting axis.
49   std::shared_ptr<GeomAPI_Ax1> anAxis;
50   std::shared_ptr<GeomAPI_Edge> anEdge;
51   std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_RevolutionSketch::AXIS_OBJECT_ID());
52   if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
53     anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
54   } else if(anObjRef->context() && anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
55     anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
56   }
57   if(anEdge) {
58     anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
59   }
60
61   // Getting revolution angles.
62   double aToAngle = real(TO_ANGLE_ID())->value();
63   double aFromAngle = real(FROM_ANGLE_ID())->value();
64
65   if(string(CREATION_METHOD())->value() == "ByAngles") {
66     aToAngle = real(TO_ANGLE_ID())->value();
67     aFromAngle =  real(FROM_ANGLE_ID())->value();
68   } else {
69     aToAngle = real(TO_OFFSET_ID())->value();
70     aFromAngle =  real(FROM_OFFSET_ID())->value();
71   }
72
73   // Getting revolution bounding planes.
74   std::shared_ptr<GeomAPI_Shape> aToShape;
75   std::shared_ptr<GeomAPI_Shape> aFromShape;
76
77   if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
78     anObjRef = selection(TO_OBJECT_ID());
79     if(anObjRef.get() != NULL) {
80       aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
81       if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
82         aToShape =  anObjRef->context()->shape();
83       }
84     }
85     anObjRef = selection(FROM_OBJECT_ID());
86     if(anObjRef.get() != NULL) {
87       aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
88       if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
89         aFromShape = anObjRef->context()->shape();
90       }
91     }
92   }
93
94   // Revol face
95   std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo(new GeomAlgoAPI_Revolution(theFace, anAxis, aToShape, aToAngle, aFromShape, aFromAngle));
96
97   // Checking that the algorithm worked properly.
98   if(!aRevolAlgo->isDone() || !aRevolAlgo->shape().get() || aRevolAlgo->shape()->isNull() ||
99      !aRevolAlgo->isValid()) {
100     return;
101   }
102
103   theMakeShape = aRevolAlgo;
104 }