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