1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesPlugin_Intersection.h"
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_Document.h>
25 #include <ModelAPI_BodyBuilder.h>
26 #include <ModelAPI_ResultBody.h>
27 #include <ModelAPI_AttributeSelectionList.h>
29 #include <GeomAlgoAPI_Intersection.h>
30 #include <GeomAlgoAPI_Tools.h>
31 #include <GeomAPI_ShapeExplorer.h>
35 //=================================================================================================
36 FeaturesPlugin_Intersection::FeaturesPlugin_Intersection()
40 //=================================================================================================
41 void FeaturesPlugin_Intersection::initAttributes()
43 data()->addAttribute(OBJECT_LIST_ID(),
44 ModelAPI_AttributeSelectionList::typeId());
47 //=================================================================================================
48 void FeaturesPlugin_Intersection::execute()
50 ListOfShape anObjects;
53 AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECT_LIST_ID());
54 for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
55 std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
56 anObjectsSelList->value(anObjectsIndex);
57 std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
58 if (!anObject.get()) {
61 anObjects.push_back(anObject);
64 if(anObjects.empty()) {
65 setError("Error: Objects or tools are empty.");
72 GeomMakeShapePtr anIntersectionAlgo(new GeomAlgoAPI_Intersection(anObjects));
74 // Checking that the algorithm worked properly.
76 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anIntersectionAlgo, getKind(), anError)) {
81 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
82 loadNamingDS(aResultBody, anObjects, anIntersectionAlgo);
83 setResult(aResultBody, aResultIndex);
87 // remove the rest results if there were produced in the previous pass
88 removeResults(aResultIndex);
91 //=================================================================================================
92 void FeaturesPlugin_Intersection::loadNamingDS(ResultBodyPtr theResultBody,
93 const ListOfShape& theObjects,
94 const GeomMakeShapePtr& theMakeShape)
96 std::shared_ptr<GeomAPI_Shape> aResultShape = theMakeShape->shape();
98 if(theObjects.front()->isEqual(aResultShape)) {
99 theResultBody->store(aResultShape, false);
103 theResultBody->storeModified(theObjects.front(), aResultShape);
105 const int aShapeTypesNb = 3;
106 const GeomAPI_Shape::ShapeType aShapeTypes[aShapeTypesNb] = {GeomAPI_Shape::VERTEX,
108 GeomAPI_Shape::FACE };
109 for (ListOfShape::const_iterator anIt = theObjects.cbegin(); anIt != theObjects.cend(); ++anIt) {
110 const GeomShapePtr aShape = *anIt;
111 for(int anIndex = 0; anIndex < aShapeTypesNb; ++anIndex) {
112 theResultBody->loadModifiedShapes(theMakeShape, aShape, aShapeTypes[anIndex]);
113 theResultBody->loadGeneratedShapes(theMakeShape, aShape, aShapeTypes[anIndex]);