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