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