Salome HOME
7e226fde7f76b2b48fe350b175e57b5e888024df
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Solid.cpp
1 // Copyright (C) 2017-2023  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "BuildPlugin_Solid.h"
21
22 #include <ModelAPI_AttributeSelectionList.h>
23 #include <ModelAPI_ResultBody.h>
24
25 #include <GeomAPI_ShapeExplorer.h>
26 #include <GeomAPI_ShapeIterator.h>
27
28 #include <GeomAlgoAPI_MakeVolume.h>
29
30 //=================================================================================================
31 BuildPlugin_Solid::BuildPlugin_Solid()
32 {
33 }
34
35 //=================================================================================================
36 void BuildPlugin_Solid::initAttributes()
37 {
38   data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
39 }
40
41 //=================================================================================================
42 void BuildPlugin_Solid::execute()
43 {
44   // all the needed checkings are in validator, so, here just make and store result
45   ListOfShape anOriginalFaces;
46   ListOfShape anOriginalSolids;
47   getOriginalShapesAndContexts(BASE_OBJECTS_ID(), anOriginalFaces, anOriginalSolids);
48
49   std::shared_ptr<GeomAlgoAPI_MakeVolume> anAlgo(
50     new GeomAlgoAPI_MakeVolume(anOriginalFaces, false));
51   // check and process result of volume maker
52   GeomShapePtr aResShape = getSingleSubshape(anAlgo->shape());
53   storeResult(anAlgo, anOriginalFaces, anOriginalSolids, aResShape);
54 }
55
56 GeomShapePtr BuildPlugin_Solid::getSingleSubshape(const GeomShapePtr& theCompound)
57 {
58   if (theCompound->shapeType() == GeomAPI_Shape::COMPOUND) {
59     GeomAPI_ShapeIterator anIt(theCompound);
60     return anIt.current();
61   }
62   return theCompound;
63 }