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 AttributeSelectionListPtr aFaceRefs = selectionList(FeaturesPlugin_Extrusion::LIST_ID());
40 // for each selected face generate a result
42 for(; anIndex < aFaceRefs->size(); anIndex++) {
43 std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(anIndex);
46 std::shared_ptr<GeomAPI_Shape> aFace = aFaceRef->value();
49 ResultPtr aContextRes = aFaceRef->context();
50 std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
51 if (!aContext.get()) {
52 static const std::string aContextError = "The selection context is bad";
53 setError(aContextError);
57 double aSize = real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
58 if (boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
61 ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
62 GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
63 if(!aFeature.isDone()) {
64 static const std::string aFeatureError = "Extrusion algorithm failed";
65 setError(aFeatureError);
69 // Check if shape is valid
70 if (aFeature.shape()->isNull()) {
71 static const std::string aShapeError = "Resulting shape is Null";
72 setError(aShapeError);
75 if(!aFeature.isValid()) {
76 std::string aFeatureError = "Warning: resulting shape is not valid";
77 setError(aFeatureError);
81 LoadNamingDS(aFeature, aResultBody, aFace, aContext);
83 setResult(aResultBody, anIndex);
85 // remove the rest results if there were produced in the previous pass
86 removeResults(anIndex);
89 //============================================================================
90 void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature,
91 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
92 std::shared_ptr<GeomAPI_Shape> theBasis,
93 std::shared_ptr<GeomAPI_Shape> theContext)
98 if(theBasis->isEqual(theContext))
99 theResultBody->store(theFeature.shape());
101 theResultBody->storeGenerated(theContext, theFeature.shape());
103 GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
104 theFeature.mapOfShapes(*aSubShapes);
106 //Insert lateral face : Face from Edge
107 std::string aLatName = "LateralFace";
108 theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes);
111 std::string aBotName = "BottomFace";
112 std::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();
113 if (!aBottomFace->isNull()) {
114 if (aSubShapes->isBound(aBottomFace)) {
115 aBottomFace = aSubShapes->find(aBottomFace);
117 theResultBody->generated(aBottomFace, aBotName, _FIRST_TAG);
123 std::string aTopName = "TopFace";
124 std::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
125 if (!aTopFace->isNull()) {
126 if (aSubShapes->isBound(aTopFace)) {
127 aTopFace = aSubShapes->find(aTopFace);
129 theResultBody->generated(aTopFace, aTopName, _LAST_TAG);
134 //============================================================================
135 void FeaturesPlugin_Extrusion::clearResult()
137 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
138 std::shared_ptr<GeomAPI_Shape> anEmptyShape(new GeomAPI_Shape);
139 aResultBody->store(anEmptyShape);
140 setResult(aResultBody);