Salome HOME
Issue #2386: New build features: Solid, Compsolid, Compound
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Compound.cpp
1 // Copyright (C) 2017-20xx  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "BuildPlugin_Compound.h"
22
23 #include <ModelAPI_AttributeSelectionList.h>
24 #include <ModelAPI_ResultBody.h>
25
26 #include <GeomAlgoAPI_CompoundBuilder.h>
27
28
29 //=================================================================================================
30 BuildPlugin_Compound::BuildPlugin_Compound()
31 {
32 }
33
34 //=================================================================================================
35 void BuildPlugin_Compound::initAttributes()
36 {
37   data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
38 }
39
40 //=================================================================================================
41 void BuildPlugin_Compound::execute()
42 {
43   // Get base objects list.
44   AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
45   if(!aSelectionList.get()) {
46     setError("Error: Could not get selection list.");
47     return;
48   }
49   if(aSelectionList->size() == 0) {
50     setError("Error: Empty selection list.");
51     return;
52   }
53
54   // Collect base shapes.
55   ListOfShape anOriginalShapes;
56   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
57     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
58     GeomShapePtr aShape = aSelection->value();
59     if (!aShape.get())
60       aShape = aSelection->context()->shape();
61     anOriginalShapes.push_back(aShape);
62   }
63
64   // Build compound.
65   GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(anOriginalShapes);
66   int anIndexToRemove = 0;
67   if (aCompound) {
68     ResultBodyPtr aResultBody = document()->createBody(data(), anIndexToRemove++);
69     aResultBody->store(aCompound);
70
71 ////    // Store faces
72 ////    std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfSubs = theAlgorithm->mapOfSubShapes();
73 ////    int aModifiedTag = 1;
74 ////    for(ListOfShape::const_iterator anIt = theOriginalShapes.cbegin();
75 ////        anIt != theOriginalShapes.cend(); ++anIt) {
76 ////      GeomShapePtr aShape = *anIt;
77 ////      aResultBody->loadAndOrientModifiedShapes(theAlgorithm.get(), aShape, GeomAPI_Shape::FACE,
78 ////          aModifiedTag, "Modified_Face", *aMapOfSubs.get(), false, true, true);
79 ////    }
80
81     setResult(aResultBody);
82   }
83   removeResults(anIndexToRemove);
84 }