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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesPlugin_Extrusion.h"
23 #include <ModelAPI_AttributeDouble.h>
24 #include <ModelAPI_AttributeSelection.h>
25 #include <ModelAPI_AttributeString.h>
26 #include <ModelAPI_Session.h>
27 #include <ModelAPI_Validator.h>
29 #include <GeomAlgoAPI_Prism.h>
31 #include <GeomAPI_Dir.h>
32 #include <GeomAPI_Edge.h>
33 #include <GeomAPI_Lin.h>
35 //=================================================================================================
36 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
40 //=================================================================================================
41 void FeaturesPlugin_Extrusion::initAttributes()
43 initCompositeSketchAttribtues(InitBaseObjectsList);
45 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
47 data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
48 data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
50 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
51 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
53 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
54 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
56 data()->addAttribute(DIRECTION_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
58 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
59 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
60 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), DIRECTION_OBJECT_ID());
62 initCompositeSketchAttribtues(InitSketchLauncher);
65 //=================================================================================================
66 void FeaturesPlugin_Extrusion::execute()
68 ListOfShape aBaseShapesList;
69 ListOfMakeShape aMakeShapesList;
72 if(!makeExtrusions(aBaseShapesList, aMakeShapesList)) {
78 ListOfShape::const_iterator aBaseIt = aBaseShapesList.cbegin();
79 ListOfMakeShape::const_iterator anAlgoIt = aMakeShapesList.cbegin();
80 for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend();
81 ++aBaseIt, ++anAlgoIt) {
82 storeResult(*aBaseIt, *anAlgoIt, aResultIndex++);
85 removeResults(aResultIndex);
88 //=================================================================================================
89 bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes,
90 ListOfMakeShape& theMakeShapes)
92 theMakeShapes.clear();
94 // Getting base shapes.
95 getBaseShapes(theBaseShapes);
98 std::shared_ptr<GeomAPI_Dir> aDir;
99 std::shared_ptr<GeomAPI_Edge> anEdge;
100 AttributeSelectionPtr aSelection = selection(DIRECTION_OBJECT_ID());
101 if(aSelection.get() && aSelection->value().get() && aSelection->value()->isEdge()) {
102 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->value()));
103 } else if(aSelection->context().get() &&
104 aSelection->context()->shape().get() &&
105 aSelection->context()->shape()->isEdge()) {
106 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->context()->shape()));
109 if(anEdge->isLine()) {
110 aDir = anEdge->line()->direction();
115 double aToSize = 0.0;
116 double aFromSize = 0.0;
118 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_SIZES()) {
119 aToSize = real(TO_SIZE_ID())->value();
120 aFromSize = real(FROM_SIZE_ID())->value();
122 aToSize = real(TO_OFFSET_ID())->value();
123 aFromSize = real(FROM_OFFSET_ID())->value();
126 // Getting bounding planes.
127 GeomShapePtr aToShape;
128 GeomShapePtr aFromShape;
130 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) {
131 aSelection = selection(TO_OBJECT_ID());
132 if(aSelection.get()) {
133 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
134 if(!aToShape.get() && aSelection->context().get()) {
135 aToShape = aSelection->context()->shape();
138 aSelection = selection(FROM_OBJECT_ID());
139 if(aSelection.get()) {
140 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
141 if(!aFromShape.get() && aSelection->context().get()) {
142 aFromShape = aSelection->context()->shape();
147 // Generating result for each base shape.
148 for(ListOfShape::const_iterator
149 anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
150 std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIter;
152 std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(new GeomAlgoAPI_Prism(aBaseShape, aDir,
154 aFromShape, aFromSize));
155 if(!isMakeShapeValid(aPrismAlgo)) {
159 theMakeShapes.push_back(aPrismAlgo);