1 // Copyright (C) 2017-20xx 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 "BuildPlugin_Compound.h"
23 #include <ModelAPI_AttributeSelectionList.h>
24 #include <ModelAPI_ResultBody.h>
26 #include <GeomAlgoAPI_Copy.h>
27 #include <GeomAlgoAPI_CompoundBuilder.h>
30 //=================================================================================================
31 BuildPlugin_Compound::BuildPlugin_Compound()
35 //=================================================================================================
36 void BuildPlugin_Compound::initAttributes()
38 data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
41 //=================================================================================================
42 void BuildPlugin_Compound::execute()
44 // Get base objects list.
45 AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
46 if(!aSelectionList.get()) {
47 setError("Error: Could not get selection list.");
50 if(aSelectionList->size() == 0) {
51 setError("Error: Empty selection list.");
55 // Collect base shapes.
56 ListOfShape anOriginalShapes;
57 for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
58 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
59 GeomShapePtr aShape = aSelection->value();
61 if (!aSelection->context().get()) {
62 setError("Invalid selection");
65 aShape = aSelection->context()->shape();
67 anOriginalShapes.push_back(aShape);
71 GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(anOriginalShapes);
73 GeomAlgoAPI_Copy aCopyAlgo(aCompound);
74 GeomShapePtr aCopyCompound = aCopyAlgo.shape();
76 int anIndexToRemove = 0;
78 std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfShapes = aCopyAlgo.mapOfSubShapes();
80 ResultBodyPtr aResultBody = document()->createBody(data(), anIndexToRemove++);
81 aResultBody->store(aCopyCompound);
82 aResultBody->loadAndOrientModifiedShapes(&aCopyAlgo, aCompound, GeomAPI_Shape::VERTEX,
83 1, "Modified_Vertex", *aMapOfShapes.get(),
85 aResultBody->loadAndOrientModifiedShapes(&aCopyAlgo, aCompound, GeomAPI_Shape::EDGE,
86 100000, "Modified_Edge", *aMapOfShapes.get(),
88 aResultBody->loadAndOrientModifiedShapes(&aCopyAlgo, aCompound, GeomAPI_Shape::FACE,
89 200000, "Modified_Face", *aMapOfShapes.get(),
91 setResult(aResultBody);
93 removeResults(anIndexToRemove);