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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomAlgoAPI_MakeShapeList.h"
24 #include <NCollection_List.hxx>
25 #include <NCollection_Map.hxx>
26 #include <TopoDS_Shape.hxx>
28 //==================================================================================================
29 GeomAlgoAPI_MakeShapeList::GeomAlgoAPI_MakeShapeList()
30 : GeomAlgoAPI_MakeShape()
33 //==================================================================================================
34 GeomAlgoAPI_MakeShapeList::GeomAlgoAPI_MakeShapeList(const ListOfMakeShape& theMakeShapeList)
35 : GeomAlgoAPI_MakeShape()
37 init(theMakeShapeList);
40 //==================================================================================================
41 void GeomAlgoAPI_MakeShapeList::init(const ListOfMakeShape& theMakeShapeList)
46 myMap.reset(new GeomAPI_DataMapOfShapeShape);
49 myListOfMakeShape = theMakeShapeList;
51 for(ListOfMakeShape::const_iterator anIt = theMakeShapeList.cbegin();
52 anIt != theMakeShapeList.cend(); ++anIt) {
53 myMap->merge((*anIt)->mapOfSubShapes());
57 const ListOfMakeShape& GeomAlgoAPI_MakeShapeList::list() const
59 return myListOfMakeShape;
63 //==================================================================================================
64 void GeomAlgoAPI_MakeShapeList::appendAlgo(
65 const GeomMakeShapePtr theMakeShape)
67 myListOfMakeShape.push_back(theMakeShape);
69 myMap.reset(new GeomAPI_DataMapOfShapeShape());
71 myMap->merge(theMakeShape->mapOfSubShapes());
74 //==================================================================================================
75 const GeomShapePtr GeomAlgoAPI_MakeShapeList::shape() const
77 GeomShapePtr aShape = GeomAlgoAPI_MakeShape::shape();
78 if(aShape.get() && !aShape->impl<TopoDS_Shape>().IsNull()) {
80 } else if(!myListOfMakeShape.empty()) {
81 return myListOfMakeShape.back()->shape();
83 return GeomShapePtr();
86 //==================================================================================================
87 void GeomAlgoAPI_MakeShapeList::generated(const GeomShapePtr theOldShape,
88 ListOfShape& theNewShapes)
90 result(theOldShape, GeomAlgoAPI_MakeShapeList::Generated, theNewShapes);
93 //==================================================================================================
94 void GeomAlgoAPI_MakeShapeList::modified(const GeomShapePtr theOldShape,
95 ListOfShape& theNewShapes)
97 result(theOldShape, GeomAlgoAPI_MakeShapeList::Modified, theNewShapes);
100 //==================================================================================================
101 bool GeomAlgoAPI_MakeShapeList::isDeleted(const GeomShapePtr theOldShape)
103 for (ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin();
104 aBuilderIt != myListOfMakeShape.end();
107 GeomMakeShapePtr aMakeShape = *aBuilderIt;
108 if(aMakeShape->isDeleted(theOldShape)) {
116 //==================================================================================================
117 void GeomAlgoAPI_MakeShapeList::result(const GeomShapePtr theOldShape,
118 OperationType theOperationType,
119 ListOfShape& theNewShapes)
121 if(myListOfMakeShape.empty()) {
125 NCollection_Map<TopoDS_Shape> anAlgoShapes;
126 NCollection_Map<TopoDS_Shape> aResultShapesMap;
127 NCollection_List<TopoDS_Shape> aResultShapesList;
128 anAlgoShapes.Add(theOldShape->impl<TopoDS_Shape>());
129 aResultShapesMap.Add(theOldShape->impl<TopoDS_Shape>());
130 aResultShapesList.Append(theOldShape->impl<TopoDS_Shape>());
132 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin();
133 aBuilderIt != myListOfMakeShape.end();
136 GeomMakeShapePtr aMakeShape = *aBuilderIt;
137 NCollection_Map<TopoDS_Shape> aTempShapes;
138 for (NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(anAlgoShapes);
142 bool hasResults = false;
143 bool anArgumentIsInResult = false;
144 GeomShapePtr aShape(new GeomAPI_Shape);
145 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
146 ListOfShape aGeneratedShapes;
147 aMakeShape->generated(aShape, aGeneratedShapes);
148 for (ListOfShape::const_iterator anIt = aGeneratedShapes.cbegin();
149 anIt != aGeneratedShapes.cend();
152 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
153 if (anItShape.IsSame(aShapeIt.Value())) {
154 anArgumentIsInResult = true;
157 aTempShapes.Add(anItShape);
158 if(aResultShapesMap.Add(anItShape) == Standard_True) {
159 aResultShapesList.Append(anItShape);
163 ListOfShape aModifiedShapes;
164 aMakeShape->modified(aShape, aModifiedShapes);
165 for (ListOfShape::const_iterator anIt = aModifiedShapes.cbegin();
166 anIt != aModifiedShapes.cend();
169 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
170 if (anItShape.IsSame(aShapeIt.Value())) {
171 anArgumentIsInResult = true;
174 aTempShapes.Add(anItShape);
175 if(aResultShapesMap.Add(anItShape) == Standard_True) {
176 aResultShapesList.Append(anItShape);
180 if(hasResults && !anArgumentIsInResult) {
181 const TopoDS_Shape& aTopoDSShape = aShapeIt.Value();
182 if(aResultShapesMap.Remove(aTopoDSShape) == Standard_True) {
183 for(NCollection_List<TopoDS_Shape>::Iterator
184 aResIt(aResultShapesList); aResIt.More(); aResIt.Next()) {
185 if(aTopoDSShape.IsEqual(aResIt.Value())) {
186 aResultShapesList.Remove(aResIt);
193 anAlgoShapes.Unite(aTempShapes);
196 for (NCollection_List<TopoDS_Shape>::Iterator aShapeIt(aResultShapesList);
200 GeomShapePtr aShape(new GeomAPI_Shape());
201 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
202 if (!isValidForHistory(aShape)) continue;
203 fixOrientation(aShape);
204 theNewShapes.push_back(aShape);