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 eraseResults(); // to erase the previously stored naming structures
69 boost::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
70 GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
71 if(!aFeature.isDone()) {
72 std::string aFeatureError = "Extrusion algorithm failed";
73 Events_Error::send(aFeatureError, this);
77 // Check if shape is valid
78 if (aFeature.shape()->isNull()) {
79 std::string aShapeError = "Resulting shape is Null";
80 Events_Error::send(aShapeError, this);
82 std::cerr << aShapeError << std::endl;
86 if(!aFeature.isValid()) {
87 std::string aFeatureError = "Warning: resulting shape is not valid";
88 Events_Error::send(aFeatureError, this);
92 LoadNamingDS(aFeature, aResultBody, aFace, aContext);
94 setResult(aResultBody);
97 //============================================================================
98 void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature,
99 boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
100 boost::shared_ptr<GeomAPI_Shape> theBasis,
101 boost::shared_ptr<GeomAPI_Shape> theContext)
106 if(theBasis->isEqual(theContext))
107 theResultBody->store(theFeature.shape());
109 theResultBody->storeGenerated(theContext, theFeature.shape());
111 GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
112 theFeature.mapOfShapes(*aSubShapes);
114 //Insert lateral face : Face from Edge
115 theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theFeature.shape(), EDGE,_LATERAL_TAG, *aSubShapes);
118 boost::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();
119 if (!aBottomFace->isNull()) {
120 if (aSubShapes->isBound(aBottomFace)) {
121 aBottomFace = aSubShapes->find(aBottomFace);
123 theResultBody->generated(aBottomFace, _FIRST_TAG);
129 boost::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
130 if (!aTopFace->isNull()) {
131 if (aSubShapes->isBound(aTopFace)) {
132 aTopFace = aSubShapes->find(aTopFace);
134 theResultBody->generated(aTopFace, _LAST_TAG);