1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "FeaturesPlugin_Extrusion.h"
22 #include <ModelAPI_AttributeDouble.h>
23 #include <ModelAPI_AttributeSelection.h>
24 #include <ModelAPI_AttributeString.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_Validator.h>
28 #include <GeomAlgoAPI_Prism.h>
30 #include <GeomAPI_Dir.h>
31 #include <GeomAPI_Edge.h>
32 #include <GeomAPI_Lin.h>
34 //=================================================================================================
35 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
39 //=================================================================================================
40 void FeaturesPlugin_Extrusion::initAttributes()
42 initCompositeSketchAttribtues(InitBaseObjectsList);
44 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
46 data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
47 data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
49 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
50 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
52 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
53 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
55 data()->addAttribute(DIRECTION_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
57 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
58 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
59 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), DIRECTION_OBJECT_ID());
61 initCompositeSketchAttribtues(InitSketchLauncher);
64 //=================================================================================================
65 void FeaturesPlugin_Extrusion::execute()
67 ListOfShape aBaseShapesList;
68 ListOfMakeShape aMakeShapesList;
71 if(!makeExtrusions(aBaseShapesList, aMakeShapesList)) {
77 ListOfShape::const_iterator aBaseIt = aBaseShapesList.cbegin();
78 ListOfMakeShape::const_iterator anAlgoIt = aMakeShapesList.cbegin();
79 for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend();
80 ++aBaseIt, ++anAlgoIt) {
81 storeResult(*aBaseIt, *anAlgoIt, aResultIndex++);
84 removeResults(aResultIndex);
87 //=================================================================================================
88 bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes,
89 ListOfMakeShape& theMakeShapes)
91 theMakeShapes.clear();
93 // Getting base shapes.
94 getBaseShapes(theBaseShapes);
97 std::shared_ptr<GeomAPI_Dir> aDir;
98 std::shared_ptr<GeomAPI_Edge> anEdge;
99 AttributeSelectionPtr aSelection = selection(DIRECTION_OBJECT_ID());
100 if(aSelection.get() && aSelection->value().get() && aSelection->value()->isEdge()) {
101 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->value()));
102 } else if(aSelection->context().get() &&
103 aSelection->context()->shape().get() &&
104 aSelection->context()->shape()->isEdge()) {
105 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->context()->shape()));
108 if(anEdge->isLine()) {
109 aDir = anEdge->line()->direction();
114 double aToSize = 0.0;
115 double aFromSize = 0.0;
117 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_SIZES()) {
118 aToSize = real(TO_SIZE_ID())->value();
119 aFromSize = real(FROM_SIZE_ID())->value();
121 aToSize = real(TO_OFFSET_ID())->value();
122 aFromSize = real(FROM_OFFSET_ID())->value();
125 // Getting bounding planes.
126 GeomShapePtr aToShape;
127 GeomShapePtr aFromShape;
129 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) {
130 aSelection = selection(TO_OBJECT_ID());
131 if(aSelection.get()) {
132 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
133 if(!aToShape.get() && aSelection->context().get()) {
134 aToShape = aSelection->context()->shape();
137 aSelection = selection(FROM_OBJECT_ID());
138 if(aSelection.get()) {
139 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
140 if(!aFromShape.get() && aSelection->context().get()) {
141 aFromShape = aSelection->context()->shape();
146 // Generating result for each base shape.
147 for(ListOfShape::const_iterator
148 anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
149 std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIter;
151 std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(new GeomAlgoAPI_Prism(aBaseShape, aDir,
153 aFromShape, aFromSize));
154 if(!isMakeShapeValid(aPrismAlgo)) {
158 theMakeShapes.push_back(aPrismAlgo);