Salome HOME
GeomAlgoAPI_Revolution now derived from GeomAlgoAPI_MakeSweep
[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<GeomAPI_Shape>& theResult,
47                                                 ListOfShape& theFromFaces,
48                                                 ListOfShape& theToFaces,
49                                                 std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
50                                                 std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theDataMap)
51 {
52   //Getting axis.
53   std::shared_ptr<GeomAPI_Ax1> anAxis;
54   std::shared_ptr<GeomAPI_Edge> anEdge;
55   std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_RevolutionSketch::AXIS_OBJECT_ID());
56   if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
57     anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
58   } else if(anObjRef->context() && anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
59     anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
60   }
61   if(anEdge) {
62     anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
63   }
64
65   // Getting revolution angles.
66   double aToAngle = real(TO_ANGLE_ID())->value();
67   double aFromAngle = real(FROM_ANGLE_ID())->value();
68
69   if(string(CREATION_METHOD())->value() == "ByAngles") {
70     aToAngle = real(TO_ANGLE_ID())->value();
71     aFromAngle =  real(FROM_ANGLE_ID())->value();
72   } else {
73     aToAngle = real(TO_OFFSET_ID())->value();
74     aFromAngle =  real(FROM_OFFSET_ID())->value();
75   }
76
77   // Getting revolution bounding planes.
78   std::shared_ptr<GeomAPI_Shape> aToShape;
79   std::shared_ptr<GeomAPI_Shape> aFromShape;
80
81   if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
82     anObjRef = selection(TO_OBJECT_ID());
83     if(anObjRef.get() != NULL) {
84       aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
85       if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
86         aToShape =  anObjRef->context()->shape();
87       }
88     }
89     anObjRef = selection(FROM_OBJECT_ID());
90     if(anObjRef.get() != NULL) {
91       aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
92       if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
93         aFromShape = anObjRef->context()->shape();
94       }
95     }
96   }
97
98   // Revol face
99   std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo(new GeomAlgoAPI_Revolution(theFace, anAxis, aToShape, aToAngle, aFromShape, aFromAngle));
100
101   // Checking that the algorithm worked properly.
102   if(!aRevolAlgo->isDone() || !aRevolAlgo->shape().get() || aRevolAlgo->shape()->isNull() ||
103      !aRevolAlgo->isValid()) {
104     return;
105   }
106
107   theResult = aRevolAlgo->shape();
108   theFromFaces = aRevolAlgo->fromFaces();
109   theToFaces = aRevolAlgo->toFaces();
110   theMakeShape = aRevolAlgo;
111   theDataMap = aRevolAlgo->mapOfSubShapes();
112 }