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_Intersection.h"
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Document.h>
24 #include <ModelAPI_BodyBuilder.h>
25 #include <ModelAPI_ResultBody.h>
26 #include <ModelAPI_AttributeDouble.h>
27 #include <ModelAPI_AttributeSelectionList.h>
28 #include <ModelAPI_Tools.h>
30 #include <GeomAlgoAPI_Intersection.h>
31 #include <GeomAlgoAPI_MakeShapeList.h>
32 #include <GeomAlgoAPI_Tools.h>
33 #include <GeomAPI_ShapeExplorer.h>
38 static const std::string INTERSECTION_VERSION_1("v9.5");
40 //=================================================================================================
41 FeaturesPlugin_Intersection::FeaturesPlugin_Intersection()
45 //=================================================================================================
46 void FeaturesPlugin_Intersection::initAttributes()
48 AttributePtr anObjectsAttr = data()->addAttribute(OBJECT_LIST_ID(),
49 ModelAPI_AttributeSelectionList::typeId());
51 data()->addAttribute(FUZZY_PARAM_ID(), ModelAPI_AttributeDouble::typeId());
52 // Initialize the fuzzy parameter with a value below Precision::Confusion() to indicate,
53 // that the internal algorithms should use their default fuzzy value, if none was specified
55 real(FUZZY_PARAM_ID())->setValue(1.e-8);
57 initVersion(INTERSECTION_VERSION_1, anObjectsAttr, AttributePtr());
60 //=================================================================================================
61 void FeaturesPlugin_Intersection::execute()
63 GeomAPI_ShapeHierarchy anObjectsHierarchy;
66 if (!processAttribute(OBJECT_LIST_ID(), anObjectsHierarchy, aPlanes)) {
67 setError("Error: Objects or tools are empty.");
71 // Getting fuzzy parameter.
72 // Used as additional tolerance to eliminate tiny results.
73 double aFuzzy = real(FUZZY_PARAM_ID())->value();
78 const ListOfShape& anObjects = anObjectsHierarchy.objects();
79 GeomMakeShapePtr anIntersectionAlgo(new GeomAlgoAPI_Intersection(anObjects, aFuzzy));
81 // Checking that the algorithm worked properly.
83 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anIntersectionAlgo, getKind(), anError)) {
88 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList);
89 aMakeShapeList->appendAlgo(anIntersectionAlgo);
91 GeomShapePtr aResShape = anIntersectionAlgo->shape();
92 if (data()->version() == INTERSECTION_VERSION_1) {
93 // merge hierarchies of compounds containing objects and tools
94 // and append the result of the FUSE operation
95 aResShape = keepUnusedSubsOfCompound(aResShape, anObjectsHierarchy,
96 GeomAPI_ShapeHierarchy(), aMakeShapeList);
99 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
100 ModelAPI_Tools::loadModifiedShapes(aResultBody,
105 setResult(aResultBody, aResultIndex);
108 ModelAPI_Tools::loadDeletedShapes(aResultBody,
114 // remove the rest results if there were produced in the previous pass
115 removeResults(aResultIndex);