1 // Copyright (C) 2014-2019 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
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 const ListOfMakeShape& GeomAlgoAPI_MakeShapeList::list() const
58 return myListOfMakeShape;
62 //==================================================================================================
63 void GeomAlgoAPI_MakeShapeList::appendAlgo(
64 const GeomMakeShapePtr theMakeShape)
66 myListOfMakeShape.push_back(theMakeShape);
68 myMap.reset(new GeomAPI_DataMapOfShapeShape());
70 myMap->merge(theMakeShape->mapOfSubShapes());
73 //==================================================================================================
74 const GeomShapePtr GeomAlgoAPI_MakeShapeList::shape() const
76 GeomShapePtr aShape = GeomAlgoAPI_MakeShape::shape();
77 if(aShape.get() && !aShape->impl<TopoDS_Shape>().IsNull()) {
79 } else if(!myListOfMakeShape.empty()) {
80 return myListOfMakeShape.back()->shape();
82 return GeomShapePtr();
85 //==================================================================================================
86 void GeomAlgoAPI_MakeShapeList::generated(const GeomShapePtr theOldShape,
87 ListOfShape& theNewShapes)
89 result(theOldShape, GeomAlgoAPI_MakeShapeList::Generated, theNewShapes);
92 //==================================================================================================
93 void GeomAlgoAPI_MakeShapeList::modified(const GeomShapePtr theOldShape,
94 ListOfShape& theNewShapes)
96 result(theOldShape, GeomAlgoAPI_MakeShapeList::Modified, theNewShapes);
99 //==================================================================================================
100 bool GeomAlgoAPI_MakeShapeList::isDeleted(const GeomShapePtr theOldShape)
102 for (ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin();
103 aBuilderIt != myListOfMakeShape.end();
106 GeomMakeShapePtr aMakeShape = *aBuilderIt;
107 if(aMakeShape->isDeleted(theOldShape)) {
115 //==================================================================================================
116 void GeomAlgoAPI_MakeShapeList::result(const GeomShapePtr theOldShape,
117 OperationType theOperationType,
118 ListOfShape& theNewShapes)
120 if(myListOfMakeShape.empty()) {
124 NCollection_Map<TopoDS_Shape> anAlgoShapes;
125 NCollection_Map<TopoDS_Shape> aResultShapesMap;
126 NCollection_List<TopoDS_Shape> aResultShapesList;
127 anAlgoShapes.Add(theOldShape->impl<TopoDS_Shape>());
128 aResultShapesMap.Add(theOldShape->impl<TopoDS_Shape>());
129 aResultShapesList.Append(theOldShape->impl<TopoDS_Shape>());
131 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin();
132 aBuilderIt != myListOfMakeShape.end();
135 GeomMakeShapePtr aMakeShape = *aBuilderIt;
136 NCollection_Map<TopoDS_Shape> aTempShapes;
137 for (NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(anAlgoShapes);
141 bool hasResults = false;
142 bool anArgumentIsInResult = false;
143 GeomShapePtr aShape(new GeomAPI_Shape);
144 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
145 ListOfShape aGeneratedShapes;
146 aMakeShape->generated(aShape, aGeneratedShapes);
147 for (ListOfShape::const_iterator anIt = aGeneratedShapes.cbegin();
148 anIt != aGeneratedShapes.cend();
151 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
152 if (anItShape.IsSame(aShapeIt.Value())) {
153 anArgumentIsInResult = true;
156 aTempShapes.Add(anItShape);
157 if(aResultShapesMap.Add(anItShape) == Standard_True) {
158 aResultShapesList.Append(anItShape);
162 ListOfShape aModifiedShapes;
163 aMakeShape->modified(aShape, aModifiedShapes);
164 for (ListOfShape::const_iterator anIt = aModifiedShapes.cbegin();
165 anIt != aModifiedShapes.cend();
168 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
169 if (anItShape.IsSame(aShapeIt.Value())) {
170 anArgumentIsInResult = true;
173 aTempShapes.Add(anItShape);
174 if(aResultShapesMap.Add(anItShape) == Standard_True) {
175 aResultShapesList.Append(anItShape);
179 if(hasResults && !anArgumentIsInResult) {
180 const TopoDS_Shape& aTopoDSShape = aShapeIt.Value();
181 if(aResultShapesMap.Remove(aTopoDSShape) == Standard_True) {
182 for(NCollection_List<TopoDS_Shape>::Iterator
183 aResIt(aResultShapesList); aResIt.More(); aResIt.Next()) {
184 if(aTopoDSShape.IsEqual(aResIt.Value())) {
185 aResultShapesList.Remove(aResIt);
192 anAlgoShapes.Unite(aTempShapes);
195 for (NCollection_List<TopoDS_Shape>::Iterator aShapeIt(aResultShapesList);
199 GeomShapePtr aShape(new GeomAPI_Shape());
200 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
201 if (!isValidForHistory(aShape)) continue;
202 fixOrientation(aShape);
203 theNewShapes.push_back(aShape);