1 // Copyright (C) 2017-2019 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
20 #include "BuildPlugin_Solid.h"
22 #include <ModelAPI_AttributeSelectionList.h>
23 #include <ModelAPI_ResultBody.h>
25 #include <GeomAPI_ShapeIterator.h>
27 #include <GeomAlgoAPI_MakeVolume.h>
29 //=================================================================================================
30 BuildPlugin_Solid::BuildPlugin_Solid()
34 //=================================================================================================
35 void BuildPlugin_Solid::initAttributes()
37 data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
40 //=================================================================================================
41 void BuildPlugin_Solid::execute()
43 // all the needed checkings are in validator, so, here just make and store result
44 ListOfShape anOriginalShapes;
45 AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
46 for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
47 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
48 GeomShapePtr aShape = aSelection->value();
50 aShape = aSelection->context()->shape();
51 anOriginalShapes.push_back(aShape);
53 std::shared_ptr<GeomAlgoAPI_MakeVolume> anAlgo(
54 new GeomAlgoAPI_MakeVolume(anOriginalShapes, false));
55 // check and process result of volume maker
56 GeomShapePtr aResShape = getSingleSubshape(anAlgo->shape());
57 storeResult(anOriginalShapes, aResShape, anAlgo);
60 void BuildPlugin_Solid::storeResult(const ListOfShape& theOriginalShapes,
61 const GeomShapePtr& theResultShape,
62 const GeomMakeShapePtr& theAlgorithm)
64 ResultBodyPtr aResultBody = document()->createBody(data());
65 aResultBody->store(theResultShape);
68 for (ListOfShape::const_iterator anIt = theOriginalShapes.cbegin();
69 anIt != theOriginalShapes.cend();
72 GeomShapePtr aShape = *anIt;
73 aResultBody->loadModifiedShapes(theAlgorithm, aShape, GeomAPI_Shape::FACE);
75 setResult(aResultBody);
78 GeomShapePtr BuildPlugin_Solid::getSingleSubshape(const GeomShapePtr& theCompound)
80 if (theCompound->shapeType() == GeomAPI_Shape::COMPOUND) {
81 GeomAPI_ShapeIterator anIt(theCompound);
82 GeomShapePtr aFoundSub;
83 for (; anIt.more() && !aFoundSub; anIt.next()) {
84 return anIt.current();