Salome HOME
Copyright update 2022
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_ExtrusionBoolean.cpp
1 // Copyright (C) 2014-2022  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 "FeaturesPlugin_ExtrusionBoolean.h"
21
22 #include <ModelAPI_AttributeSelectionList.h>
23 #include <ModelAPI_AttributeString.h>
24
25 #include <GeomAlgoAPI_ShapeTools.h>
26
27 //=================================================================================================
28 void FeaturesPlugin_ExtrusionBoolean::initAttributes()
29 {
30   FeaturesPlugin_Extrusion::initAttributes();
31
32   initBooleanAttributes();
33 }
34
35 //=================================================================================================
36 bool FeaturesPlugin_ExtrusionBoolean::makeGeneration(ListOfShape& theBaseShapes,
37                                                      ListOfMakeShape& theMakeShapes)
38 {
39   ListOfShape aBoundaryShapes;
40   return makeExtrusions(theBaseShapes, aBoundaryShapes, theMakeShapes);
41 }
42
43 //=================================================================================================
44 void FeaturesPlugin_ExtrusionBoolean::storeGenerationHistory(ResultBodyPtr theResultBody,
45                                         const GeomShapePtr theBaseShape,
46                                         const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape)
47 {
48   FeaturesPlugin_Extrusion::storeGenerationHistory(theResultBody, theBaseShape, theMakeShape);
49 }
50
51 //=================================================================================================
52 void FeaturesPlugin_ExtrusionBoolean::getSizes(double& theToSize, double& theFromSize)
53 {
54   if (string(CREATION_METHOD())->value() != CREATION_METHOD_THROUGH_ALL()) {
55     FeaturesPlugin_Extrusion::getSizes(theToSize, theFromSize);
56   } else {
57     // Getting objects.
58     ListOfShape anObjects;
59     AttributeSelectionListPtr anObjectsSelList = myFeature->selectionList(OBJECTS_ID());
60     for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
61       AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex);
62       GeomShapePtr anObject = anObjectAttr->value();
63       if (!anObject.get()) {
64         myFeature->setError("Error: Could not get object.");
65         return;
66       }
67       anObjects.push_back(anObject);
68     }
69
70     // Getting prism bases.
71     ListOfShape aBaseShapes;
72     getBaseShapes(aBaseShapes);
73
74     // Getting prism direction.
75     std::shared_ptr<GeomAPI_Dir> aDir;
76     getDirection(aDir);
77
78     // Calculate sizes
79     GeomAlgoAPI_ShapeTools::computeThroughAll(anObjects, aBaseShapes, aDir, theToSize, theFromSize);
80   }
81 }