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_Session.h>
12 #include <ModelAPI_Validator.h>
14 #include <GeomAlgoAPI_Revolution.h>
15 #include <GeomAPI_Edge.h>
16 #include <GeomAPI_Lin.h>
18 //=================================================================================================
19 void FeaturesPlugin_RevolutionBoolean::initMakeSolidsAttributes()
21 data()->addAttribute(FeaturesPlugin_RevolutionBoolean::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
23 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
24 data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
26 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
27 data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
29 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
30 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
33 //=================================================================================================
34 ListOfShape FeaturesPlugin_RevolutionBoolean::MakeSolids(const ListOfShape& theFaces)
37 std::shared_ptr<GeomAPI_Ax1> anAxis;
38 std::shared_ptr<GeomAPI_Edge> anEdge;
39 std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_RevolutionBoolean::AXIS_OBJECT_ID());
40 if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
41 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
44 anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
47 // Getting revolution bounding planes.
48 std::shared_ptr<GeomAPI_Shape> aFromShape;
49 std::shared_ptr<GeomAPI_Shape> aToShape;
50 anObjRef = selection(FROM_OBJECT_ID());
52 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
54 anObjRef = selection(TO_OBJECT_ID());
56 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
59 // Getting revolution angles.
60 double aFromAngle = real(FROM_ANGLE_ID())->value();
61 double aToAngle = real(TO_ANGLE_ID())->value();
64 ListOfShape aRevolutionList;
65 for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
66 std::shared_ptr<GeomAPI_Shape> aBaseShape = *aFacesIt;
67 GeomAlgoAPI_Revolution aRevolAlgo(aBaseShape, anAxis, aFromShape, aFromAngle, aToShape, aToAngle);
69 // Checking that the algorithm worked properly.
70 if(!aRevolAlgo.isDone() || aRevolAlgo.shape()->isNull() || !aRevolAlgo.isValid()) {
71 setError("Revolution algorithm failed");
74 aRevolutionList.push_back(aRevolAlgo.shape());
77 return aRevolutionList;