Salome HOME
Merge remote-tracking branch 'origin/Toolbars_Management'
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Tools.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 "FeaturesPlugin_Tools.h"
22
23 #include <ModelAPI_ResultBody.h>
24
25 #include <GeomAPI_ShapeIterator.h>
26
27 //==================================================================================================
28 void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody,
29                                               const GeomShapePtr theBaseShape,
30                                               const ListOfShape& theTools,
31                                               const GeomMakeShapePtr& theMakeShape,
32                                               const GeomShapePtr theResultShape)
33 {
34   if (theBaseShape->isEqual(theResultShape)) {
35     theResultBody->store(theResultShape, false);
36     return;
37   }
38
39   theResultBody->storeModified(theBaseShape, theResultShape);
40
41   ListOfShape aShapes = theTools;
42   aShapes.push_front(theBaseShape);
43
44   for (ListOfShape::const_iterator anIter = aShapes.begin(); anIter != aShapes.end(); ++anIter)
45   {
46     theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::VERTEX);
47     theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::EDGE);
48     theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE);
49   }
50 }
51
52 //==================================================================================================
53 void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody,
54                                               const GeomShapePtr theBaseShape,
55                                               const GeomMakeShapePtr& theMakeShape,
56                                               const std::string theName)
57 {
58   switch(theBaseShape->shapeType()) {
59     case GeomAPI_Shape::COMPOUND: {
60       for(GeomAPI_ShapeIterator anIt(theBaseShape); anIt.more(); anIt.next())
61       {
62         loadModifiedShapes(theResultBody,
63                            anIt.current(),
64                            theMakeShape,
65                            theName);
66       }
67       break;
68     }
69     case GeomAPI_Shape::COMPSOLID:
70     case GeomAPI_Shape::SOLID:
71     case GeomAPI_Shape::SHELL: {
72       theResultBody->loadModifiedShapes(theMakeShape,
73                                         theBaseShape,
74                                         GeomAPI_Shape::FACE,
75                                         theName);
76     }
77     case GeomAPI_Shape::FACE:
78     case GeomAPI_Shape::WIRE: {
79       theResultBody->loadModifiedShapes(theMakeShape,
80                                         theBaseShape,
81                                         GeomAPI_Shape::EDGE,
82                                         theName);
83     }
84     case GeomAPI_Shape::EDGE: {
85       theResultBody->loadModifiedShapes(theMakeShape,
86                                         theBaseShape,
87                                         GeomAPI_Shape::VERTEX,
88                                         theName);
89     }
90   }
91 }
92
93 //==================================================================================================
94 void FeaturesPlugin_Tools::loadDeletedShapes(ResultBodyPtr theResultBody,
95   const GeomShapePtr theBaseShape,
96   const ListOfShape& theTools,
97   const GeomMakeShapePtr& theMakeShape,
98   const GeomShapePtr theResultShapesCompound)
99 {
100   ListOfShape aShapes = theTools;
101   aShapes.push_front(theBaseShape);
102
103   for (ListOfShape::const_iterator anIter = aShapes.begin(); anIter != aShapes.end(); anIter++)
104   {
105     theResultBody->loadDeletedShapes(theMakeShape,
106                                      *anIter,
107                                      GeomAPI_Shape::VERTEX,
108                                      theResultShapesCompound);
109     theResultBody->loadDeletedShapes(theMakeShape,
110                                      *anIter,
111                                      GeomAPI_Shape::EDGE,
112                                      theResultShapesCompound);
113     theResultBody->loadDeletedShapes(theMakeShape,
114                                      *anIter,
115                                      GeomAPI_Shape::FACE,
116                                      theResultShapesCompound);
117   }
118 }
119
120 //==================================================================================================
121 void FeaturesPlugin_Tools::loadDeletedShapes(
122   std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
123   const ListOfShape& theTools,
124   const GeomShapePtr theResultShapesCompound)
125 {
126   for (std::vector<ResultBaseAlgo>::iterator anIt = theResultBaseAlgoList.begin();
127        anIt != theResultBaseAlgoList.end();
128        ++anIt)
129   {
130     ResultBaseAlgo& aRCA = *anIt;
131     loadDeletedShapes(aRCA.resultBody,
132                       aRCA.baseShape,
133                       theTools,
134                       aRCA.makeShape,
135                       theResultShapesCompound);
136   }
137 }