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<GeomAPI_Shape>& theResult,
47 ListOfShape& theFromFaces,
48 ListOfShape& theToFaces,
49 std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
50 std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theDataMap)
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()));
62 anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
65 // Getting revolution angles.
66 double aToAngle = real(TO_ANGLE_ID())->value();
67 double aFromAngle = real(FROM_ANGLE_ID())->value();
69 if(string(CREATION_METHOD())->value() == "ByAngles") {
70 aToAngle = real(TO_ANGLE_ID())->value();
71 aFromAngle = real(FROM_ANGLE_ID())->value();
73 aToAngle = real(TO_OFFSET_ID())->value();
74 aFromAngle = real(FROM_OFFSET_ID())->value();
77 // Getting revolution bounding planes.
78 std::shared_ptr<GeomAPI_Shape> aToShape;
79 std::shared_ptr<GeomAPI_Shape> aFromShape;
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();
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();
99 std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo(new GeomAlgoAPI_Revolution(theFace, anAxis, aToShape, aToAngle, aFromShape, aFromAngle));
101 // Checking that the algorithm worked properly.
102 if(!aRevolAlgo->isDone() || !aRevolAlgo->shape().get() || aRevolAlgo->shape()->isNull() ||
103 !aRevolAlgo->isValid()) {
107 theResult = aRevolAlgo->shape();
108 theFromFaces = aRevolAlgo->fromFaces();
109 theToFaces = aRevolAlgo->toFaces();
110 theMakeShape = aRevolAlgo;
111 theDataMap = aRevolAlgo->mapOfSubShapes();