]> SALOME platform Git repositories - modules/shaper.git/blob - src/BuildPlugin/BuildPlugin_Solid.cpp
Salome HOME
Update copyrights
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Solid.cpp
1 // Copyright (C) 2017-2019  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_ShapeIterator.h>
26
27 #include <GeomAlgoAPI_MakeVolume.h>
28
29 //=================================================================================================
30 BuildPlugin_Solid::BuildPlugin_Solid()
31 {
32 }
33
34 //=================================================================================================
35 void BuildPlugin_Solid::initAttributes()
36 {
37   data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
38 }
39
40 //=================================================================================================
41 void BuildPlugin_Solid::execute()
42 {
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();
49     if (!aShape.get())
50       aShape = aSelection->context()->shape();
51     anOriginalShapes.push_back(aShape);
52   }
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);
58 }
59
60 void BuildPlugin_Solid::storeResult(const ListOfShape& theOriginalShapes,
61                                     const GeomShapePtr& theResultShape,
62                                     const GeomMakeShapePtr& theAlgorithm)
63 {
64   ResultBodyPtr aResultBody = document()->createBody(data());
65   aResultBody->store(theResultShape);
66
67   // Store faces
68   for (ListOfShape::const_iterator anIt = theOriginalShapes.cbegin();
69        anIt != theOriginalShapes.cend();
70        ++anIt)
71   {
72     GeomShapePtr aShape = *anIt;
73     aResultBody->loadModifiedShapes(theAlgorithm, aShape, GeomAPI_Shape::FACE);
74   }
75   setResult(aResultBody);
76 }
77
78 GeomShapePtr BuildPlugin_Solid::getSingleSubshape(const GeomShapePtr& theCompound)
79 {
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();
85     }
86   }
87   return theCompound;
88 }