1 // Copyright (C) 2014-2022 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, theNewShapes);
92 //==================================================================================================
93 void GeomAlgoAPI_MakeShapeList::modified(const GeomShapePtr theOldShape,
94 ListOfShape& theNewShapes)
96 result(theOldShape, 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 ListOfShape& theNewShapes)
119 if(myListOfMakeShape.empty()) {
123 NCollection_Map<TopoDS_Shape> anAlgoShapes;
124 NCollection_Map<TopoDS_Shape> aResultShapesMap;
125 NCollection_List<TopoDS_Shape> aResultShapesList;
126 anAlgoShapes.Add(theOldShape->impl<TopoDS_Shape>());
127 aResultShapesMap.Add(theOldShape->impl<TopoDS_Shape>());
128 aResultShapesList.Append(theOldShape->impl<TopoDS_Shape>());
130 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin();
131 aBuilderIt != myListOfMakeShape.end();
134 GeomMakeShapePtr aMakeShape = *aBuilderIt;
135 NCollection_Map<TopoDS_Shape> aTempShapes;
136 for (NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(anAlgoShapes);
140 bool hasResults = false;
141 bool anArgumentIsInResult = false;
142 GeomShapePtr aShape(new GeomAPI_Shape);
143 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
144 ListOfShape aGeneratedShapes;
145 aMakeShape->generated(aShape, aGeneratedShapes);
146 for (ListOfShape::const_iterator anIt = aGeneratedShapes.cbegin();
147 anIt != aGeneratedShapes.cend();
150 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
151 if (anItShape.IsSame(aShapeIt.Value())) {
152 anArgumentIsInResult = true;
155 aTempShapes.Add(anItShape);
156 if(aResultShapesMap.Add(anItShape) == Standard_True) {
157 aResultShapesList.Append(anItShape);
161 ListOfShape aModifiedShapes;
162 aMakeShape->modified(aShape, aModifiedShapes);
163 for (ListOfShape::const_iterator anIt = aModifiedShapes.cbegin();
164 anIt != aModifiedShapes.cend();
167 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
168 if (anItShape.IsSame(aShapeIt.Value())) {
169 anArgumentIsInResult = true;
172 aTempShapes.Add(anItShape);
173 if(aResultShapesMap.Add(anItShape) == Standard_True) {
174 aResultShapesList.Append(anItShape);
178 if(hasResults && !anArgumentIsInResult) {
179 const TopoDS_Shape& aTopoDSShape = aShapeIt.Value();
180 if(aResultShapesMap.Remove(aTopoDSShape) == Standard_True) {
181 for(NCollection_List<TopoDS_Shape>::Iterator
182 aResIt(aResultShapesList); aResIt.More(); aResIt.Next()) {
183 if(aTopoDSShape.IsEqual(aResIt.Value())) {
184 aResultShapesList.Remove(aResIt);
191 anAlgoShapes.Unite(aTempShapes);
194 for (NCollection_List<TopoDS_Shape>::Iterator aShapeIt(aResultShapesList);
198 GeomShapePtr aShape(new GeomAPI_Shape());
199 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
200 if (!isValidForHistory(aShape)) continue;
201 fixOrientation(aShape);
202 theNewShapes.push_back(aShape);