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_ExtrusionFuse.h"
22 #include <ModelAPI_AttributeString.h>
23 #include <ModelAPI_AttributeSelectionList.h>
25 #include <GeomAlgoAPI_Boolean.h>
26 #include <GeomAlgoAPI_Prism.h>
27 #include <GeomAlgoAPI_ThroughAll.h>
28 #include <GeomAlgoAPI_CompoundBuilder.h>
30 //=================================================================================================
31 FeaturesPlugin_ExtrusionFuse::FeaturesPlugin_ExtrusionFuse()
34 myOperationType = BOOL_FUSE;
37 //=================================================================================================
38 void FeaturesPlugin_ExtrusionFuse::execute()
40 if (string(CREATION_METHOD())->value() != CREATION_METHOD_THROUGH_ALL())
41 executeCompositeBoolean();
43 executeFuseThroughAll();
47 //=================================================================================================
48 void FeaturesPlugin_ExtrusionFuse::executeFuseThroughAll()
51 ListOfShape anObjects;
52 AttributeSelectionListPtr anObjectsSelList = myFeature->selectionList(OBJECTS_ID());
53 for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
54 AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex);
55 GeomShapePtr anObject = anObjectAttr->value();
56 if (!anObject.get()) {
57 myFeature->setError("Error: Could not get object.");
60 anObjects.push_back(anObject);
64 ListOfShape aGenBaseShapes;
65 ListOfMakeShape aGenMakeShapes;
66 if (!makeGeneration(aGenBaseShapes, aGenMakeShapes)) {
71 ListOfShape aNewTools;
72 ListOfMakeShape aToolsMakeShapes;
73 for (ListOfMakeShape::const_iterator
74 anIt = aGenMakeShapes.cbegin(); anIt != aGenMakeShapes.cend(); ++anIt) {
75 GeomMakeShapePtr anAlgo = (*anIt);
76 std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo = std::dynamic_pointer_cast<GeomAlgoAPI_Prism>(anAlgo);
78 // Cut the prism by all objects and throw away end pieces
79 std::shared_ptr<GeomAlgoAPI_ThroughAll> aToolAlgo (new GeomAlgoAPI_ThroughAll(aPrismAlgo, anObjects));
81 // Checking that the algorithm worked properly
82 if (!aToolAlgo->isDone() || aToolAlgo->shape()->isNull() || !aToolAlgo->isValid()) {
83 myFeature->setError("Error: ThroughAll algorithm failed.");
85 GeomShapePtr aCuttedTool = aToolAlgo->shape();
86 aNewTools.push_back(aCuttedTool);
87 aToolsMakeShapes.push_back(aToolAlgo);
91 // Perform FeaturesPlugin_CompositeBoolean::makeBoolean() with new (cutted) tools
92 ListOfShape aBooleanObjects;
93 ListOfMakeShape aBooleanMakeShapes;
94 if (!makeBoolean(aNewTools, aBooleanObjects, aBooleanMakeShapes)) {
98 if (myOperationType == BOOL_FUSE) {
99 aNewTools.splice(aNewTools.begin(), aBooleanObjects);
100 aBooleanObjects.splice(aBooleanObjects.begin(), aNewTools, aNewTools.begin());
103 // 4. Store result (like in FeaturesPlugin_CompositeBoolean::executeCompositeBoolean())
104 int aResultIndex = 0;
105 std::vector<ResultBaseAlgo> aResultBaseAlgoList;
106 ListOfShape aResultShapesList;
107 ListOfShape::const_iterator aBoolObjIt = aBooleanObjects.cbegin();
108 ListOfMakeShape::const_iterator aBoolMSIt = aBooleanMakeShapes.cbegin();
109 for(; aBoolObjIt != aBooleanObjects.cend() && aBoolMSIt != aBooleanMakeShapes.cend();
110 ++aBoolObjIt, ++aBoolMSIt) {
112 ResultBodyPtr aResultBody = myFeature->document()->createBody(myFeature->data(), aResultIndex);
114 if((*aBoolObjIt)->isEqual((*aBoolMSIt)->shape())) {
115 aResultBody->store((*aBoolMSIt)->shape(), false);
119 aResultBody->storeModified(*aBoolObjIt, (*aBoolMSIt)->shape());
121 // Store generation history.
122 ListOfShape::const_iterator aGenBaseIt = aGenBaseShapes.cbegin();
123 ListOfMakeShape::const_iterator aGenMSIt = aGenMakeShapes.cbegin();
124 for(; aGenBaseIt != aGenBaseShapes.cend() && aGenMSIt != aGenMakeShapes.cend();
125 ++aGenBaseIt, ++aGenMSIt) {
128 ListOfMakeShape::const_iterator aToolsMSIt = aToolsMakeShapes.cbegin();
129 for(; aToolsMSIt != aToolsMakeShapes.cend(); ++aToolsMSIt) {
130 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMSList(new GeomAlgoAPI_MakeShapeList());
133 aMSList->appendAlgo(*aGenMSIt);
135 // tool modification (cut by objects)
136 aMSList->appendAlgo(*aToolsMSIt);
139 aMSList->appendAlgo(*aBoolMSIt);
140 storeGenerationHistory(aResultBody, *aGenBaseIt, aMSList);
144 storeModificationHistory(aResultBody, *aBoolObjIt, aNewTools, *aBoolMSIt);
147 aRBA.resultBody = aResultBody;
148 aRBA.baseShape = *aBoolObjIt;
149 aRBA.makeShape = *aBoolMSIt;
150 aResultBaseAlgoList.push_back(aRBA);
151 aResultShapesList.push_back((*aBoolMSIt)->shape());
154 myFeature->setResult(aResultBody, aResultIndex++);
157 // Store deleted shapes after all results has been proceeded. This is to avoid issue when in one
158 // result shape has been deleted, but in another it was modified or stayed.
159 GeomShapePtr aResultShapesCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList);
160 storeDeletedShapes(aResultBaseAlgoList, aNewTools, aResultShapesCompound);
162 myFeature->removeResults(aResultIndex);