]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/FeaturesPlugin_Tools.cpp
Salome HOME
High level objects history implementation for LinearCopy and AngularCopy features.
[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 ListOfShape& theBaseShapes,
30                                               const ListOfShape& theTools,
31                                               const GeomMakeShapePtr& theMakeShape,
32                                               const GeomShapePtr theResultShape,
33                                               const std::string& theNamePrefix)
34 {
35   theResultBody->storeModified(theBaseShapes, theResultShape, theMakeShape);
36
37   ListOfShape aShapes = theBaseShapes;
38   ListOfShape::const_iterator aToolIter = theTools.cbegin();
39   for(; aToolIter != theTools.cend(); aToolIter++)
40     aShapes.push_back(*aToolIter);
41
42   std::string aVertexName, anEdgeName, aFaceName;
43   if (!theNamePrefix.empty()) {
44     aVertexName = theNamePrefix + "_Vertex";
45     anEdgeName = theNamePrefix + "_Edge";
46     aFaceName = theNamePrefix + "_Face";
47   }
48
49   for (ListOfShape::const_iterator anIter = aShapes.begin(); anIter != aShapes.end(); ++anIter)
50   {
51     theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::VERTEX, aVertexName);
52     theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::EDGE, anEdgeName);
53     theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE, aFaceName);
54   }
55 }
56
57 //==================================================================================================
58 void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody,
59                                               const GeomShapePtr& theBaseShape,
60                                               const GeomMakeShapePtr& theMakeShape,
61                                               const std::string theName)
62 {
63   switch(theBaseShape->shapeType()) {
64     case GeomAPI_Shape::COMPOUND: {
65       for(GeomAPI_ShapeIterator anIt(theBaseShape); anIt.more(); anIt.next())
66       {
67         loadModifiedShapes(theResultBody,
68                            anIt.current(),
69                            theMakeShape,
70                            theName);
71       }
72       break;
73     }
74     case GeomAPI_Shape::COMPSOLID:
75     case GeomAPI_Shape::SOLID:
76     case GeomAPI_Shape::SHELL: {
77       theResultBody->loadModifiedShapes(theMakeShape,
78                                         theBaseShape,
79                                         GeomAPI_Shape::FACE,
80                                         theName);
81     }
82     case GeomAPI_Shape::FACE:
83     case GeomAPI_Shape::WIRE: {
84       theResultBody->loadModifiedShapes(theMakeShape,
85                                         theBaseShape,
86                                         GeomAPI_Shape::EDGE,
87                                         theName);
88     }
89     case GeomAPI_Shape::EDGE: {
90       theResultBody->loadModifiedShapes(theMakeShape,
91                                         theBaseShape,
92                                         GeomAPI_Shape::VERTEX,
93                                         theName);
94     }
95   }
96 }
97
98 //==================================================================================================
99 void FeaturesPlugin_Tools::loadDeletedShapes(ResultBodyPtr theResultBody,
100   const GeomShapePtr theBaseShape,
101   const ListOfShape& theTools,
102   const GeomMakeShapePtr& theMakeShape,
103   const GeomShapePtr theResultShapesCompound)
104 {
105   ListOfShape aShapes = theTools;
106   if (theBaseShape.get())
107     aShapes.push_front(theBaseShape);
108
109   for (ListOfShape::const_iterator anIter = aShapes.begin(); anIter != aShapes.end(); anIter++)
110   {
111     theResultBody->loadDeletedShapes(theMakeShape,
112                                      *anIter,
113                                      GeomAPI_Shape::VERTEX,
114                                      theResultShapesCompound);
115     theResultBody->loadDeletedShapes(theMakeShape,
116                                      *anIter,
117                                      GeomAPI_Shape::EDGE,
118                                      theResultShapesCompound);
119     theResultBody->loadDeletedShapes(theMakeShape,
120                                      *anIter,
121                                      GeomAPI_Shape::FACE,
122                                      theResultShapesCompound);
123   }
124 }
125
126 //==================================================================================================
127 void FeaturesPlugin_Tools::loadDeletedShapes(
128   std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
129   const ListOfShape& theTools,
130   const GeomShapePtr theResultShapesCompound)
131 {
132   for (std::vector<ResultBaseAlgo>::iterator anIt = theResultBaseAlgoList.begin();
133        anIt != theResultBaseAlgoList.end();
134        ++anIt)
135   {
136     ResultBaseAlgo& aRCA = *anIt;
137     loadDeletedShapes(aRCA.resultBody,
138                       aRCA.baseShape,
139                       theTools,
140                       aRCA.makeShape,
141                       theResultShapesCompound);
142   }
143 }