Salome HOME
Copyright update 2022
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Shape.cpp
1 // Copyright (C) 2014-2022  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 email : webmaster.salome@opencascade.com
18 //
19
20 #include "BuildPlugin_Shape.h"
21
22 #include <ModelAPI_AttributeSelectionList.h>
23 #include <ModelAPI_ResultBody.h>
24
25 #include <GeomAlgoAPI_MakeShape.h>
26
27 #include <GeomAPI_PlanarEdges.h>
28
29
30 //=================================================================================================
31 void BuildPlugin_Shape::storeResult(const GeomMakeShapePtr& theAlgorithm,
32                                     const ListOfShape& theOriginalShapes,
33                                     const ListOfShape& theOriginalSolids,
34                                     const GeomShapePtr& theResultShape,
35                                     const int theResultIndex)
36 {
37   ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex);
38   aResultBody->storeModified(theOriginalSolids, theResultShape, theAlgorithm);
39
40   for (ListOfShape::const_iterator anIt = theOriginalShapes.cbegin();
41        anIt != theOriginalShapes.cend();
42        ++anIt)
43   {
44     GeomShapePtr aShape = *anIt;
45     aResultBody->loadModifiedShapes(theAlgorithm, aShape, GeomAPI_Shape::VERTEX);
46     aResultBody->loadModifiedShapes(theAlgorithm, aShape, GeomAPI_Shape::EDGE);
47     aResultBody->loadModifiedShapes(theAlgorithm, aShape, GeomAPI_Shape::FACE);
48   }
49   setResult(aResultBody, theResultIndex);
50 }
51
52 //=================================================================================================
53 void BuildPlugin_Shape::getOriginalShapesAndContexts(const std::string& theSelectionListID,
54                                                      ListOfShape& theShapes,
55                                                      ListOfShape& theContexts)
56 {
57   std::set<GeomShapePtr, GeomAPI_Shape::Comparator> aContexts;
58
59   AttributeSelectionListPtr aSelectionList = selectionList(theSelectionListID);
60   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
61     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
62     GeomShapePtr aShape = aSelection->value();
63     GeomShapePtr aContext = aSelection->context()->shape();
64     if (!aShape.get())
65       aShape = aContext;
66     theShapes.push_back(aShape);
67
68     // do not collect sketch faces, because they are stored as compounds
69     // and then are treated as modified by the algorithm
70     if (!std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContext).get())
71       aContexts.insert(aContext);
72   }
73
74   std::set<GeomShapePtr, GeomAPI_Shape::Comparator>::const_iterator anIt = aContexts.begin();
75   for (; anIt != aContexts.end(); ++anIt)
76     theContexts.push_back(*anIt);
77 }