1 // File: FeaturesPlugin_Extrusion.cpp
2 // Created: 30 May 2014
3 // Author: Vitaly SMETANNIKOV
5 #include "FeaturesPlugin_Extrusion.h"
6 #include <ModelAPI_Session.h>
7 #include <ModelAPI_Document.h>
8 #include <ModelAPI_Data.h>
9 #include <ModelAPI_ResultConstruction.h>
10 #include <ModelAPI_ResultBody.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_AttributeSelection.h>
13 #include <ModelAPI_AttributeBoolean.h>
14 #include <Events_Error.h>
15 #include <GeomAlgoAPI_Extrusion.h>
18 #define _LATERAL_TAG 1
27 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
31 void FeaturesPlugin_Extrusion::initAttributes()
33 data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type());
34 data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
35 data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
38 void FeaturesPlugin_Extrusion::execute()
40 boost::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = boost::dynamic_pointer_cast<
41 ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
45 boost::shared_ptr<GeomAPI_Shape> aFace =
46 boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
50 boost::shared_ptr<GeomAPI_Shape> aContext;
51 ResultPtr aContextRes = aFaceRef->context();
53 if (aContextRes->groupName() == ModelAPI_ResultBody::group())
54 aContext = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
55 else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
56 aContext = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
59 std::string aContextError = "The selection context is bad";
60 Events_Error::send(aContextError, this);
64 double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
65 if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
68 boost::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
69 GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
70 if(!aFeature.isDone()) {
71 std::string aFeatureError = "Extrusion algorithm failed";
72 Events_Error::send(aFeatureError, this);
76 // Check if shape is valid
77 if (aFeature.shape()->isNull()) {
78 std::string aShapeError = "Resulting shape is Null";
79 Events_Error::send(aShapeError, this);
81 std::cerr << aShapeError << std::endl;
85 if(!aFeature.isValid()) {
86 std::string aFeatureError = "Warning: resulting shape is not valid";
87 Events_Error::send(aFeatureError, this);
91 LoadNamingDS(aFeature, aResultBody, aFace, aContext);
93 setResult(aResultBody);
96 //============================================================================
97 void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature,
98 boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
99 boost::shared_ptr<GeomAPI_Shape> theBasis,
100 boost::shared_ptr<GeomAPI_Shape> theContext)
105 if(theBasis->isEqual(theContext))
106 theResultBody->store(theFeature.shape());
108 theResultBody->storeGenerated(theContext, theFeature.shape());
110 GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
111 theFeature.mapOfShapes(*aSubShapes);
113 //Insert lateral face : Face from Edge
114 theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, *aSubShapes);
117 boost::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();
118 if (!aBottomFace->isNull()) {
119 if (aSubShapes->isBound(aBottomFace)) {
120 aBottomFace = aSubShapes->find(aBottomFace);
122 theResultBody->generated(aBottomFace, _FIRST_TAG);
128 boost::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
129 if (!aTopFace->isNull()) {
130 if (aSubShapes->isBound(aTopFace)) {
131 aTopFace = aSubShapes->find(aTopFace);
133 theResultBody->generated(aTopFace, _LAST_TAG);