1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: FeaturesPlugin_RevolutionBoolean.h
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 ListOfShape FeaturesPlugin_RevolutionBoolean::MakeSolids(const ListOfShape& theFaces)
43 std::shared_ptr<GeomAPI_Ax1> anAxis;
44 std::shared_ptr<GeomAPI_Edge> anEdge;
45 std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_RevolutionBoolean::AXIS_OBJECT_ID());
46 if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
47 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
48 } else if(anObjRef->context() && anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
49 anEdge = std::make_shared<GeomAPI_Edge>(anObjRef->context()->shape());
52 anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
55 // Getting revolution angles.
56 double aToAngle = real(TO_ANGLE_ID())->value();
57 double aFromAngle = real(FROM_ANGLE_ID())->value();
59 if(string(CREATION_METHOD())->value() == "ByAngles") {
60 aToAngle = real(TO_ANGLE_ID())->value();
61 aFromAngle = real(FROM_ANGLE_ID())->value();
63 aToAngle = real(TO_OFFSET_ID())->value();
64 aFromAngle = real(FROM_OFFSET_ID())->value();
67 // Getting revolution bounding planes.
68 std::shared_ptr<GeomAPI_Shape> aToShape;
69 std::shared_ptr<GeomAPI_Shape> aFromShape;
71 if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
72 anObjRef = selection(TO_OBJECT_ID());
73 if(anObjRef.get() != NULL) {
74 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
75 if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
76 aToShape = anObjRef->context()->shape();
79 anObjRef = selection(FROM_OBJECT_ID());
80 if(anObjRef.get() != NULL) {
81 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
82 if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
83 aFromShape = anObjRef->context()->shape();
89 ListOfShape aRevolutionList;
90 for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
91 std::shared_ptr<GeomAPI_Shape> aBaseShape = *aFacesIt;
92 GeomAlgoAPI_Revolution aRevolAlgo(aBaseShape, anAxis, aToShape, aToAngle, aFromShape, aFromAngle);
94 // Checking that the algorithm worked properly.
95 if(!aRevolAlgo.isDone() || aRevolAlgo.shape()->isNull() || !aRevolAlgo.isValid()) {
96 setError("Revolution algorithm failed");
99 aRevolutionList.push_back(aRevolAlgo.shape());
102 return aRevolutionList;