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 AttributeSelectionListPtr aSelection =
32 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
33 FeaturesPlugin_Extrusion::LIST_ID(), ModelAPI_AttributeSelectionList::type()));
34 // extrusion works with faces always
35 aSelection->setSelectionType("FACE");
36 data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
37 data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
40 void FeaturesPlugin_Extrusion::execute()
42 AttributeSelectionListPtr aFaceRefs = selectionList(FeaturesPlugin_Extrusion::LIST_ID());
44 // for each selected face generate a result
46 for(; anIndex < aFaceRefs->size(); anIndex++) {
47 std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(anIndex);
50 std::shared_ptr<GeomAPI_Shape> aFace = aFaceRef->value();
53 ResultPtr aContextRes = aFaceRef->context();
54 std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
55 if (!aContext.get()) {
56 static const std::string aContextError = "The selection context is bad";
57 setError(aContextError);
61 double aSize = real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
62 if (boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
65 ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
66 GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
67 if(!aFeature.isDone()) {
68 static const std::string aFeatureError = "Extrusion algorithm failed";
69 setError(aFeatureError);
73 // Check if shape is valid
74 if (aFeature.shape()->isNull()) {
75 static const std::string aShapeError = "Resulting shape is Null";
76 setError(aShapeError);
79 if(!aFeature.isValid()) {
80 std::string aFeatureError = "Warning: resulting shape is not valid";
81 setError(aFeatureError);
85 LoadNamingDS(aFeature, aResultBody, aFace, aContext);
87 setResult(aResultBody, anIndex);
89 // remove the rest results if there were produced in the previous pass
90 removeResults(anIndex);
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);