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_AttributeBoolean.h>
16 #include <GeomAlgoAPI_Extrusion.h>
19 #define _LATERAL_TAG 1
24 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
28 void FeaturesPlugin_Extrusion::initAttributes()
30 data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::typeId());
31 data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::typeId());
32 data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::typeId());
35 void FeaturesPlugin_Extrusion::execute()
37 std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = std::dynamic_pointer_cast<
38 ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
42 std::shared_ptr<GeomAPI_Shape> aFace =
43 std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
47 std::shared_ptr<GeomAPI_Shape> aContext;
48 ResultPtr aContextRes = aFaceRef->context();
50 if (aContextRes->groupName() == ModelAPI_ResultBody::group())
51 aContext = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
52 else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
53 aContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
56 static const std::string aContextError = "The selection context is bad";
57 setError(aContextError);
61 double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
62 if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
65 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
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);
90 //============================================================================
91 void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature,
92 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
93 std::shared_ptr<GeomAPI_Shape> theBasis,
94 std::shared_ptr<GeomAPI_Shape> theContext)
99 if(theBasis->isEqual(theContext))
100 theResultBody->store(theFeature.shape());
102 theResultBody->storeGenerated(theContext, theFeature.shape());
104 GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
105 theFeature.mapOfShapes(*aSubShapes);
107 //Insert lateral face : Face from Edge
108 std::string aLatName = "LateralFace";
109 theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes);
112 std::string aBotName = "BottomFace";
113 std::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();
114 if (!aBottomFace->isNull()) {
115 if (aSubShapes->isBound(aBottomFace)) {
116 aBottomFace = aSubShapes->find(aBottomFace);
118 theResultBody->generated(aBottomFace, aBotName, _FIRST_TAG);
124 std::string aTopName = "TopFace";
125 std::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
126 if (!aTopFace->isNull()) {
127 if (aSubShapes->isBound(aTopFace)) {
128 aTopFace = aSubShapes->find(aTopFace);
130 theResultBody->generated(aTopFace, aTopName, _LAST_TAG);