1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: FeaturesPlugin_Extrusion.cpp
4 // Created: 30 May 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "FeaturesPlugin_Extrusion.h"
8 #include <ModelAPI_Session.h>
9 #include <ModelAPI_Document.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_ResultConstruction.h>
12 #include <ModelAPI_ResultBody.h>
13 #include <ModelAPI_AttributeDouble.h>
14 #include <ModelAPI_AttributeSelection.h>
15 #include <ModelAPI_AttributeSelectionList.h>
16 #include <ModelAPI_AttributeBoolean.h>
17 #include <GeomAlgoAPI_Extrusion.h>
20 #define _LATERAL_TAG 1
25 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
29 void FeaturesPlugin_Extrusion::initAttributes()
31 data()->addAttribute(FeaturesPlugin_Extrusion::LIST_ID(), ModelAPI_AttributeSelectionList::type());
32 data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
33 data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
36 void FeaturesPlugin_Extrusion::execute()
38 std::shared_ptr<ModelAPI_AttributeSelectionList> aFaceRefs = std::dynamic_pointer_cast<
39 ModelAPI_AttributeSelectionList>(data()->attribute(FeaturesPlugin_Extrusion::LIST_ID()));
40 if (aFaceRefs.get() == NULL || aFaceRefs->size() == 0) {
44 std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(0);
48 std::shared_ptr<GeomAPI_Shape> aFace =
49 std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
53 std::shared_ptr<GeomAPI_Shape> aContext;
54 ResultPtr aContextRes = aFaceRef->context();
55 if (aContextRes && aContextRes->groupName() == ModelAPI_ResultConstruction::group()) {
56 aContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
59 static const std::string aContextError = "The selection context is bad";
60 setError(aContextError);
64 double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
65 if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
68 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
69 GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
70 if(!aFeature.isDone()) {
71 static const std::string aFeatureError = "Extrusion algorithm failed";
72 setError(aFeatureError);
76 // Check if shape is valid
77 if (aFeature.shape()->isNull()) {
78 static const std::string aShapeError = "Resulting shape is Null";
79 setError(aShapeError);
82 if(!aFeature.isValid()) {
83 std::string aFeatureError = "Warning: resulting shape is not valid";
84 setError(aFeatureError);
88 LoadNamingDS(aFeature, aResultBody, aFace, aContext);
90 setResult(aResultBody);
93 //============================================================================
94 void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature,
95 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
96 std::shared_ptr<GeomAPI_Shape> theBasis,
97 std::shared_ptr<GeomAPI_Shape> theContext)
102 if(theBasis->isEqual(theContext))
103 theResultBody->store(theFeature.shape());
105 theResultBody->storeGenerated(theContext, theFeature.shape());
107 GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
108 theFeature.mapOfShapes(*aSubShapes);
110 //Insert lateral face : Face from Edge
111 std::string aLatName = "LateralFace";
112 theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes);
115 std::string aBotName = "BottomFace";
116 std::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();
117 if (!aBottomFace->isNull()) {
118 if (aSubShapes->isBound(aBottomFace)) {
119 aBottomFace = aSubShapes->find(aBottomFace);
121 theResultBody->generated(aBottomFace, aBotName, _FIRST_TAG);
127 std::string aTopName = "TopFace";
128 std::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, aTopName, _LAST_TAG);
138 //============================================================================
139 void FeaturesPlugin_Extrusion::clearResult()
141 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
142 std::shared_ptr<GeomAPI_Shape> anEmptyShape(new GeomAPI_Shape);
143 aResultBody->store(anEmptyShape);
144 setResult(aResultBody);