1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: FeaturesPlugin_RevolutionBoolean.cpp
4 // Created: 11 June 2015
5 // Author: Dmitry Bobylev
7 #include <FeaturesPlugin_RevolutionBoolean.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 void FeaturesPlugin_RevolutionBoolean::initMakeSolidsAttributes()
22 data()->addAttribute(FeaturesPlugin_RevolutionBoolean::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
24 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
26 data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
27 data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
29 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
30 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
32 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
33 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
35 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
36 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
39 //=================================================================================================
40 void FeaturesPlugin_RevolutionBoolean::makeSolids(const ListOfShape& theFaces,
41 ListOfShape& theResults,
42 std::list<std::shared_ptr<GeomAPI_Interface>>& theAlgos)
45 std::shared_ptr<GeomAPI_Ax1> anAxis;
46 std::shared_ptr<GeomAPI_Edge> anEdge;
47 std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_RevolutionBoolean::AXIS_OBJECT_ID());
48 if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
49 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
50 } else if(anObjRef->context() && anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
51 anEdge = std::make_shared<GeomAPI_Edge>(anObjRef->context()->shape());
54 anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
57 // Getting revolution angles.
58 double aToAngle = real(TO_ANGLE_ID())->value();
59 double aFromAngle = real(FROM_ANGLE_ID())->value();
61 if(string(CREATION_METHOD())->value() == "ByAngles") {
62 aToAngle = real(TO_ANGLE_ID())->value();
63 aFromAngle = real(FROM_ANGLE_ID())->value();
65 aToAngle = real(TO_OFFSET_ID())->value();
66 aFromAngle = real(FROM_OFFSET_ID())->value();
69 // Getting revolution bounding planes.
70 std::shared_ptr<GeomAPI_Shape> aToShape;
71 std::shared_ptr<GeomAPI_Shape> aFromShape;
73 if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
74 anObjRef = selection(TO_OBJECT_ID());
75 if(anObjRef.get() != NULL) {
76 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
77 if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
78 aToShape = anObjRef->context()->shape();
81 anObjRef = selection(FROM_OBJECT_ID());
82 if(anObjRef.get() != NULL) {
83 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
84 if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
85 aFromShape = anObjRef->context()->shape();
92 for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
93 std::shared_ptr<GeomAPI_Shape> aBaseShape = *aFacesIt;
94 std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo = std::make_shared<GeomAlgoAPI_Revolution>(aBaseShape, anAxis,
96 aFromShape, aFromAngle);
98 // Checking that the algorithm worked properly.
99 if(!aRevolAlgo->isDone() || !aRevolAlgo->shape().get() || aRevolAlgo->shape()->isNull() ||
100 !aRevolAlgo->isValid()) {
101 setError("Revolution algorithm failed");
105 theResults.push_back(aRevolAlgo->shape());
106 theAlgos.push_back(aRevolAlgo);