1 // Copyright (C) 2014-2022 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_AttributeDouble.h>
25 #include <ModelAPI_AttributeReference.h>
26 #include <ModelAPI_AttributeInteger.h>
27 #include <ModelAPI_ResultBody.h>
28 #include <ModelAPI_AttributeSelectionList.h>
29 #include <ModelAPI_Session.h>
30 #include <ModelAPI_Validator.h>
31 #include <ModelAPI_Tools.h>
33 #include <GeomAlgoAPI_Boolean.h>
34 #include <GeomAlgoAPI_CompoundBuilder.h>
35 #include <GeomAlgoAPI_MakeShapeCustom.h>
36 #include <GeomAlgoAPI_MakeShapeList.h>
37 #include <GeomAlgoAPI_Partition.h>
38 #include <GeomAlgoAPI_PaveFiller.h>
39 #include <GeomAlgoAPI_ShapeBuilder.h>
40 #include <GeomAlgoAPI_ShapeTools.h>
41 #include <GeomAlgoAPI_Tools.h>
42 #include <GeomAPI_Face.h>
43 #include <GeomAPI_ShapeExplorer.h>
44 #include <GeomAPI_ShapeIterator.h>
49 //=================================================================================================
50 FeaturesPlugin_Boolean::FeaturesPlugin_Boolean(const OperationType theOperationType)
51 : myOperationType(theOperationType)
55 //=================================================================================================
56 void FeaturesPlugin_Boolean::initAttributes()
58 data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
59 data()->addAttribute(FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
61 data()->addAttribute(FeaturesPlugin_Boolean::FUZZY_PARAM_ID(), ModelAPI_AttributeDouble::typeId());
62 // Initialize the fuzzy parameter with a value below Precision::Confusion() to indicate,
63 // that the internal algorithms should use their default fuzzy value, if none was specified
65 real(FUZZY_PARAM_ID())->setValue(1.e-8);
67 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
68 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
71 //=================================================================================================
72 FeaturesPlugin_Boolean::OperationType FeaturesPlugin_Boolean::operationType()
74 return myOperationType;
77 //=================================================================================================
78 void FeaturesPlugin_Boolean::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
79 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
80 const ListOfShape& theTools,
81 const std::shared_ptr<GeomAPI_Shape> theResultShape,
82 const GeomMakeShapePtr& theMakeShape)
85 if(theBaseShape->isEqual(theResultShape)) {
86 theResultBody->store(theResultShape, false);
90 theResultBody->storeModified(theBaseShape, theResultShape);
92 theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::EDGE);
93 theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
95 theResultBody->loadDeletedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
97 for (ListOfShape::const_iterator anIter = theTools.begin();
98 anIter != theTools.end();
101 GeomAPI_Shape::ShapeType aShapeType =
102 (*anIter)->shapeType() <= GeomAPI_Shape::FACE ? GeomAPI_Shape::FACE
103 : GeomAPI_Shape::EDGE;
104 theResultBody->loadModifiedShapes(theMakeShape, *anIter, aShapeType);
106 theResultBody->loadDeletedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE);
110 //=================================================================================================
111 void FeaturesPlugin_Boolean::storeResult(
112 const ListOfShape& theObjects,
113 const ListOfShape& theTools,
114 const GeomShapePtr theResultShape,
116 std::shared_ptr<GeomAlgoAPI_MakeShapeList> theMakeShapeList,
117 std::vector<ModelAPI_Tools::ResultBaseAlgo>& theResultBaseAlgoList)
122 std::shared_ptr<ModelAPI_ResultBody> aResultBody =
123 document()->createBody(data(), theResultIndex);
125 ModelAPI_Tools::loadModifiedShapes(aResultBody,
130 setResult(aResultBody, theResultIndex++);
133 ModelAPI_Tools::ResultBaseAlgo aRBA;
134 aRBA.resultBody = aResultBody;
135 aRBA.baseShape = theObjects.front();
136 for (std::vector<ModelAPI_Tools::ResultBaseAlgo>::iterator
137 aRBAIt = theResultBaseAlgoList.begin();
138 aRBAIt != theResultBaseAlgoList.end(); ++aRBAIt) {
139 theMakeShapeList->appendAlgo(aRBAIt->makeShape);
141 aRBA.makeShape = theMakeShapeList;
142 theResultBaseAlgoList.clear();
143 theResultBaseAlgoList.push_back(aRBA);