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_AttributeBoolean.h>
25 #include <ModelAPI_AttributeDouble.h>
26 #include <ModelAPI_AttributeReference.h>
27 #include <ModelAPI_AttributeInteger.h>
28 #include <ModelAPI_ResultBody.h>
29 #include <ModelAPI_AttributeSelectionList.h>
30 #include <ModelAPI_Session.h>
31 #include <ModelAPI_Validator.h>
32 #include <ModelAPI_Tools.h>
34 #include <GeomAlgoAPI_Boolean.h>
35 #include <GeomAlgoAPI_CompoundBuilder.h>
36 #include <GeomAlgoAPI_MakeShapeCustom.h>
37 #include <GeomAlgoAPI_MakeShapeList.h>
38 #include <GeomAlgoAPI_Partition.h>
39 #include <GeomAlgoAPI_PaveFiller.h>
40 #include <GeomAlgoAPI_ShapeBuilder.h>
41 #include <GeomAlgoAPI_ShapeTools.h>
42 #include <GeomAlgoAPI_Tools.h>
43 #include <GeomAPI_Face.h>
44 #include <GeomAPI_ShapeExplorer.h>
45 #include <GeomAPI_ShapeIterator.h>
51 static const double DEFAULT_FUZZY = 1.e-5;
54 //=================================================================================================
55 FeaturesPlugin_Boolean::FeaturesPlugin_Boolean(const OperationType theOperationType)
56 : myOperationType(theOperationType)
60 //=================================================================================================
61 void FeaturesPlugin_Boolean::initAttributes()
63 data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
64 data()->addAttribute(FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
66 data()->addAttribute(FeaturesPlugin_Boolean::USE_FUZZY_ID(), ModelAPI_AttributeBoolean::typeId());
67 data()->addAttribute(FeaturesPlugin_Boolean::FUZZY_PARAM_ID(), ModelAPI_AttributeDouble::typeId());
68 boolean(USE_FUZZY_ID())->setValue(false); // Do NOT use the fuzzy parameter by default.
69 real(FUZZY_PARAM_ID())->setValue(DEFAULT_FUZZY);
71 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
72 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
75 //=================================================================================================
76 FeaturesPlugin_Boolean::OperationType FeaturesPlugin_Boolean::operationType()
78 return myOperationType;
81 //=================================================================================================
82 void FeaturesPlugin_Boolean::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
83 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
84 const ListOfShape& theTools,
85 const std::shared_ptr<GeomAPI_Shape> theResultShape,
86 const GeomMakeShapePtr& theMakeShape)
89 if(theBaseShape->isEqual(theResultShape)) {
90 theResultBody->store(theResultShape, false);
94 theResultBody->storeModified(theBaseShape, theResultShape);
96 theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::EDGE);
97 theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
99 theResultBody->loadDeletedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
101 for (ListOfShape::const_iterator anIter = theTools.begin();
102 anIter != theTools.end();
105 GeomAPI_Shape::ShapeType aShapeType =
106 (*anIter)->shapeType() <= GeomAPI_Shape::FACE ? GeomAPI_Shape::FACE
107 : GeomAPI_Shape::EDGE;
108 theResultBody->loadModifiedShapes(theMakeShape, *anIter, aShapeType);
110 theResultBody->loadDeletedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE);
114 //=================================================================================================
115 void FeaturesPlugin_Boolean::storeResult(
116 const ListOfShape& theObjects,
117 const ListOfShape& theTools,
118 const GeomShapePtr theResultShape,
120 std::shared_ptr<GeomAlgoAPI_MakeShapeList> theMakeShapeList,
121 std::vector<ModelAPI_Tools::ResultBaseAlgo>& theResultBaseAlgoList)
126 std::shared_ptr<ModelAPI_ResultBody> aResultBody =
127 document()->createBody(data(), theResultIndex);
129 ModelAPI_Tools::loadModifiedShapes(aResultBody,
134 setResult(aResultBody, theResultIndex++);
137 ModelAPI_Tools::ResultBaseAlgo aRBA;
138 aRBA.resultBody = aResultBody;
139 aRBA.baseShape = theObjects.front();
140 for (std::vector<ModelAPI_Tools::ResultBaseAlgo>::iterator
141 aRBAIt = theResultBaseAlgoList.begin();
142 aRBAIt != theResultBaseAlgoList.end(); ++aRBAIt) {
143 theMakeShapeList->appendAlgo(aRBAIt->makeShape);
145 aRBA.makeShape = theMakeShapeList;
146 theResultBaseAlgoList.clear();
147 theResultBaseAlgoList.push_back(aRBA);