Salome HOME
Update copyrights
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Boolean.cpp
1 // Copyright (C) 2014-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 "FeaturesPlugin_Boolean.h"
21
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Document.h>
24 #include <ModelAPI_AttributeReference.h>
25 #include <ModelAPI_AttributeInteger.h>
26 #include <ModelAPI_ResultBody.h>
27 #include <ModelAPI_AttributeSelectionList.h>
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Validator.h>
30 #include <ModelAPI_Tools.h>
31
32 #include <GeomAlgoAPI_Boolean.h>
33 #include <GeomAlgoAPI_MakeShapeCustom.h>
34 #include <GeomAlgoAPI_MakeShapeList.h>
35 #include <GeomAlgoAPI_Partition.h>
36 #include <GeomAlgoAPI_PaveFiller.h>
37 #include <GeomAlgoAPI_ShapeTools.h>
38 #include <GeomAPI_Face.h>
39 #include <GeomAPI_ShapeExplorer.h>
40 #include <GeomAPI_ShapeIterator.h>
41
42 #include <algorithm>
43 #include <map>
44
45 //=================================================================================================
46 FeaturesPlugin_Boolean::FeaturesPlugin_Boolean(const OperationType theOperationType)
47 : myOperationType(theOperationType)
48 {
49 }
50
51 //=================================================================================================
52 void FeaturesPlugin_Boolean::initAttributes()
53 {
54   AttributeSelectionListPtr aSelection =
55     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
56     FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
57
58   aSelection = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
59     FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
60
61   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
62   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
63 }
64
65 //=================================================================================================
66 FeaturesPlugin_Boolean::OperationType FeaturesPlugin_Boolean::operationType()
67 {
68   return myOperationType;
69 }
70
71 //=================================================================================================
72 void FeaturesPlugin_Boolean::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
73                                           const std::shared_ptr<GeomAPI_Shape> theBaseShape,
74                                           const ListOfShape& theTools,
75                                           const std::shared_ptr<GeomAPI_Shape> theResultShape,
76                                           const GeomMakeShapePtr& theMakeShape)
77 {
78   //load result
79   if(theBaseShape->isEqual(theResultShape)) {
80     theResultBody->store(theResultShape, false);
81     return;
82   }
83
84   theResultBody->storeModified(theBaseShape, theResultShape);
85
86   theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::EDGE);
87   theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
88
89   theResultBody->loadDeletedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
90
91   for (ListOfShape::const_iterator anIter = theTools.begin();
92        anIter != theTools.end();
93        ++anIter)
94   {
95     GeomAPI_Shape::ShapeType aShapeType =
96       (*anIter)->shapeType() <= GeomAPI_Shape::FACE ? GeomAPI_Shape::FACE
97                                                     : GeomAPI_Shape::EDGE;
98     theResultBody->loadModifiedShapes(theMakeShape, *anIter, aShapeType);
99
100     theResultBody->loadDeletedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE);
101   }
102 }