1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "GeomAlgoAPI_MakeShapeList.h"
23 #include <NCollection_List.hxx>
24 #include <NCollection_Map.hxx>
25 #include <TopoDS_Shape.hxx>
27 //=================================================================================================
28 GeomAlgoAPI_MakeShapeList::GeomAlgoAPI_MakeShapeList()
29 : GeomAlgoAPI_MakeShape()
32 //=================================================================================================
33 GeomAlgoAPI_MakeShapeList::GeomAlgoAPI_MakeShapeList(const ListOfMakeShape& theMakeShapeList)
34 : GeomAlgoAPI_MakeShape()
36 init(theMakeShapeList);
39 //=================================================================================================
40 void GeomAlgoAPI_MakeShapeList::init(const ListOfMakeShape& theMakeShapeList)
45 myMap.reset(new GeomAPI_DataMapOfShapeShape);
48 myListOfMakeShape = theMakeShapeList;
50 for(ListOfMakeShape::const_iterator anIt = theMakeShapeList.cbegin();
51 anIt != theMakeShapeList.cend(); ++anIt) {
52 myMap->merge((*anIt)->mapOfSubShapes());
56 //=================================================================================================
57 void GeomAlgoAPI_MakeShapeList::appendAlgo(
58 const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape)
60 myListOfMakeShape.push_back(theMakeShape);
62 myMap.reset(new GeomAPI_DataMapOfShapeShape());
64 myMap->merge(theMakeShape->mapOfSubShapes());
67 //=================================================================================================
68 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShapeList::shape() const
70 std::shared_ptr<GeomAPI_Shape> aShape = GeomAlgoAPI_MakeShape::shape();
71 if(aShape.get() && !aShape->impl<TopoDS_Shape>().IsNull()) {
73 } else if(!myListOfMakeShape.empty()) {
74 return myListOfMakeShape.back()->shape();
76 return std::shared_ptr<GeomAPI_Shape>();
79 //=================================================================================================
80 void GeomAlgoAPI_MakeShapeList::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
81 ListOfShape& theHistory)
83 result(theShape, GeomAlgoAPI_MakeShapeList::Generated, theHistory);
86 //=================================================================================================
87 void GeomAlgoAPI_MakeShapeList::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
88 ListOfShape& theHistory)
90 result(theShape, GeomAlgoAPI_MakeShapeList::Modified, theHistory);
93 bool GeomAlgoAPI_MakeShapeList::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
95 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin();
96 aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
97 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
98 if(aMakeShape->isDeleted(theShape)) {
106 void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr<GeomAPI_Shape> theShape,
107 OperationType theOperationType,
108 ListOfShape& theHistory)
110 if(myListOfMakeShape.empty()) {
114 NCollection_Map<TopoDS_Shape> anAlgoShapes;
115 NCollection_Map<TopoDS_Shape> aResultShapesMap;
116 NCollection_List<TopoDS_Shape> aResultShapesList;
117 anAlgoShapes.Add(theShape->impl<TopoDS_Shape>());
118 aResultShapesMap.Add(theShape->impl<TopoDS_Shape>());
119 aResultShapesList.Append(theShape->impl<TopoDS_Shape>());
121 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin();
122 aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
123 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
124 NCollection_Map<TopoDS_Shape> aTempShapes;
125 bool hasResults = false;
126 for(NCollection_Map<TopoDS_Shape>::Iterator
127 aShapeIt(anAlgoShapes); aShapeIt.More(); aShapeIt.Next()) {
128 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
129 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
130 ListOfShape aGeneratedShapes;
131 aMakeShape->generated(aShape, aGeneratedShapes);
132 for(ListOfShape::const_iterator
133 anIt = aGeneratedShapes.cbegin(); anIt != aGeneratedShapes.cend(); anIt++) {
134 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
135 aTempShapes.Add(anItShape);
136 if(aResultShapesMap.Add(anItShape) == Standard_True) {
137 aResultShapesList.Append(anItShape);
141 ListOfShape aModifiedShapes;
142 aMakeShape->modified(aShape, aModifiedShapes);
143 for(ListOfShape::const_iterator
144 anIt = aModifiedShapes.cbegin(); anIt != aModifiedShapes.cend(); anIt++) {
145 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
146 aTempShapes.Add(anItShape);
147 if(aResultShapesMap.Add(anItShape) == Standard_True) {
148 aResultShapesList.Append(anItShape);
153 const TopoDS_Shape& aTopoDSShape = aShapeIt.Value();
154 if(aResultShapesMap.Remove(aTopoDSShape) == Standard_True) {
155 for(NCollection_List<TopoDS_Shape>::Iterator
156 aResIt(aResultShapesList); aResIt.More(); aResIt.Next()) {
157 if(aTopoDSShape.IsEqual(aResIt.Value())) {
158 aResultShapesList.Remove(aResIt);
165 anAlgoShapes.Unite(aTempShapes);
168 for(NCollection_List<TopoDS_Shape>::Iterator
169 aShapeIt(aResultShapesList); aShapeIt.More(); aShapeIt.Next()) {
170 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
171 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
172 theHistory.push_back(aShape);