1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: FeaturesPlugin_RevolutionSketch.cpp
4 // Created: 11 September 2015
5 // Author: Dmitry Bobylev
7 #include "FeaturesPlugin_RevolutionSketch.h"
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>
15 #include <GeomAlgoAPI_Revolution.h>
16 #include <GeomAPI_Edge.h>
17 #include <GeomAPI_Lin.h>
19 //=================================================================================================
20 FeaturesPlugin_RevolutionSketch::FeaturesPlugin_RevolutionSketch()
24 //=================================================================================================
25 void FeaturesPlugin_RevolutionSketch::initMakeSolidsAttributes()
27 data()->addAttribute(FeaturesPlugin_RevolutionSketch::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
29 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
31 data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
32 data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
34 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
35 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
37 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
38 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
40 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
41 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
44 //=================================================================================================
45 void FeaturesPlugin_RevolutionSketch::makeSolid(const std::shared_ptr<GeomAPI_Shape> theFace,
46 std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape)
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()));
58 anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
61 // Getting revolution angles.
62 double aToAngle = real(TO_ANGLE_ID())->value();
63 double aFromAngle = real(FROM_ANGLE_ID())->value();
65 if(string(CREATION_METHOD())->value() == "ByAngles") {
66 aToAngle = real(TO_ANGLE_ID())->value();
67 aFromAngle = real(FROM_ANGLE_ID())->value();
69 aToAngle = real(TO_OFFSET_ID())->value();
70 aFromAngle = real(FROM_OFFSET_ID())->value();
73 // Getting revolution bounding planes.
74 std::shared_ptr<GeomAPI_Shape> aToShape;
75 std::shared_ptr<GeomAPI_Shape> aFromShape;
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();
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();
95 std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo(new GeomAlgoAPI_Revolution(theFace, anAxis, aToShape, aToAngle, aFromShape, aFromAngle));
97 // Checking that the algorithm worked properly.
98 if(!aRevolAlgo->isDone() || !aRevolAlgo->shape().get() || aRevolAlgo->shape()->isNull() ||
99 !aRevolAlgo->isValid()) {
103 theMakeShape = aRevolAlgo;