1 // Copyright (C) 2014-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 "FeaturesPlugin_Boolean.h"
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>
32 #include <GeomAlgoAPI_Boolean.h>
33 #include <GeomAlgoAPI_CompoundBuilder.h>
34 #include <GeomAlgoAPI_MakeShapeCustom.h>
35 #include <GeomAlgoAPI_MakeShapeList.h>
36 #include <GeomAlgoAPI_Partition.h>
37 #include <GeomAlgoAPI_PaveFiller.h>
38 #include <GeomAlgoAPI_ShapeBuilder.h>
39 #include <GeomAlgoAPI_ShapeTools.h>
40 #include <GeomAlgoAPI_Tools.h>
41 #include <GeomAPI_Face.h>
42 #include <GeomAPI_ShapeExplorer.h>
43 #include <GeomAPI_ShapeIterator.h>
48 //=================================================================================================
49 FeaturesPlugin_Boolean::FeaturesPlugin_Boolean(const OperationType theOperationType)
50 : myOperationType(theOperationType)
54 //=================================================================================================
55 void FeaturesPlugin_Boolean::initAttributes()
57 AttributeSelectionListPtr aSelection =
58 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
59 FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
61 aSelection = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
62 FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
64 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
65 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
68 //=================================================================================================
69 FeaturesPlugin_Boolean::OperationType FeaturesPlugin_Boolean::operationType()
71 return myOperationType;
74 //=================================================================================================
75 void FeaturesPlugin_Boolean::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
76 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
77 const ListOfShape& theTools,
78 const std::shared_ptr<GeomAPI_Shape> theResultShape,
79 const GeomMakeShapePtr& theMakeShape)
82 if(theBaseShape->isEqual(theResultShape)) {
83 theResultBody->store(theResultShape, false);
87 theResultBody->storeModified(theBaseShape, theResultShape);
89 theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::EDGE);
90 theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
92 theResultBody->loadDeletedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
94 for (ListOfShape::const_iterator anIter = theTools.begin();
95 anIter != theTools.end();
98 GeomAPI_Shape::ShapeType aShapeType =
99 (*anIter)->shapeType() <= GeomAPI_Shape::FACE ? GeomAPI_Shape::FACE
100 : GeomAPI_Shape::EDGE;
101 theResultBody->loadModifiedShapes(theMakeShape, *anIter, aShapeType);
103 theResultBody->loadDeletedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE);
107 //=================================================================================================
108 void FeaturesPlugin_Boolean::storeResult(
109 const ListOfShape& theObjects,
110 const ListOfShape& theTools,
111 const GeomShapePtr theResultShape,
113 std::shared_ptr<GeomAlgoAPI_MakeShapeList> theMakeShapeList,
114 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList)
119 std::shared_ptr<ModelAPI_ResultBody> aResultBody =
120 document()->createBody(data(), theResultIndex);
122 FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
127 setResult(aResultBody, theResultIndex++);
130 FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
131 aRBA.resultBody = aResultBody;
132 aRBA.baseShape = theObjects.front();
133 for (std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>::iterator
134 aRBAIt = theResultBaseAlgoList.begin();
135 aRBAIt != theResultBaseAlgoList.end(); ++aRBAIt) {
136 theMakeShapeList->appendAlgo(aRBAIt->makeShape);
138 aRBA.makeShape = theMakeShapeList;
139 theResultBaseAlgoList.clear();
140 theResultBaseAlgoList.push_back(aRBA);