Salome HOME
Copyright update 2022
[modules/shaper.git] / src / Model / Model_ResultBody.cpp
1 // Copyright (C) 2014-2022  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 <Model_ResultBody.h>
21
22 #include <Model_Document.h>
23 #include <Model_Objects.h>
24 #include <Model_BodyBuilder.h>
25 #include <Model_Document.h>
26 #include <ModelAPI_Object.h>
27 #include <ModelAPI_Events.h>
28 #include <ModelAPI_Tools.h>
29 #include <ModelAPI_AttributeImage.h>
30 #include <Model_Data.h>
31 #include <Events_Loop.h>
32 #include <GeomAPI_ShapeIterator.h>
33 #include <GeomAPI_ShapeExplorer.h>
34 #include <GeomAPI_Face.h>
35 #include <GeomAPI_Pnt.h>
36
37 #include <TopoDS_Shape.hxx>
38 #include <TopExp_Explorer.hxx>
39 #include <TopTools_MapOfShape.hxx>
40 #include <TDataStd_UAttribute.hxx>
41
42 // if this attribute exists, the shape is connected topology
43 Standard_GUID kIsConnectedTopology("e51392e0-3a4d-405d-8e36-bbfe19858ef5");
44 // if this attribute exists, the connected topology flag must be recomputed
45 Standard_GUID kUpdateConnectedTopology("01ef7a45-0bec-4266-b0b4-4aa570921818");
46
47 Model_ResultBody::Model_ResultBody() : ModelAPI_ResultBody()
48 {
49   myBuilder = new Model_BodyBuilder(this);
50   myLastConcealed = false;
51   updateSubs(shape()); // in case of open, etc.
52 }
53
54 Model_ResultBody::~Model_ResultBody()
55 {
56   updateSubs(std::shared_ptr<GeomAPI_Shape>()); // erase sub-results
57   delete myBuilder;
58 }
59
60 void Model_ResultBody::initAttributes()
61 {
62   ModelAPI_Result::initAttributes();
63   // append the image attribute. It is empty, the attribute will be filled by a request
64   data()->addAttribute(IMAGE_ID(), ModelAPI_AttributeImage::typeId())->setIsArgument(false);
65 }
66
67 bool Model_ResultBody::generated(const GeomShapePtr& theNewShape,
68   const std::string& theName, const bool theCheckIsInResult)
69 {
70   bool aResult = false;
71   if (mySubs.size()) { // consists of subs
72     for (std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
73          aSubIter != mySubs.cend();
74          ++aSubIter)
75     {
76       const ResultBodyPtr& aSub = *aSubIter;
77       if (aSub->generated(theNewShape, theName, theCheckIsInResult))
78         aResult = true;
79     }
80   } else { // do for this directly
81     if (myBuilder->generated(theNewShape, theName, theCheckIsInResult))
82       aResult = true;
83   }
84   return aResult;
85 }
86
87 void Model_ResultBody::loadGeneratedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
88                                            const GeomShapePtr& theOldShape,
89                                            const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
90                                            const std::string& theName,
91                                            const bool theSaveOldIfNotInTree)
92 {
93   if (mySubs.size()) { // consists of subs
94     for (std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
95          aSubIter != mySubs.cend();
96          ++aSubIter)
97     {
98       const ResultBodyPtr& aSub = *aSubIter;
99       aSub->loadGeneratedShapes(
100         theAlgo, theOldShape, theShapeTypeToExplore, theName, theSaveOldIfNotInTree);
101     }
102   } else { // do for this directly
103     myBuilder->loadGeneratedShapes(
104       theAlgo, theOldShape, theShapeTypeToExplore, theName, theSaveOldIfNotInTree);
105   }
106 }
107
108 void Model_ResultBody::loadModifiedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
109                                           const GeomShapePtr& theOldShape,
110                                           const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
111                                           const std::string& theName)
112 {
113   if (mySubs.size()) { // consists of subs
114     // optimization of getting of new shapes for specific sub-result
115     if (!theAlgo->isNewShapesCollected(theOldShape, theShapeTypeToExplore))
116       theAlgo->collectNewShapes(theOldShape, theShapeTypeToExplore);
117     std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
118     for(; aSubIter != mySubs.cend(); aSubIter++) {
119       (*aSubIter)->loadModifiedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theName);
120     }
121   } else { // do for this directly
122     myBuilder->loadModifiedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theName);
123   }
124 }
125
126 void Model_ResultBody::loadFirstLevel(GeomShapePtr theShape, const std::string& theName)
127 {
128   if (mySubs.size()) { // consists of subs
129     for (std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
130       aSubIter != mySubs.cend();
131       ++aSubIter)
132     {
133       const ResultBodyPtr& aSub = *aSubIter;
134       aSub->loadFirstLevel(theShape, theName);
135     }
136   } else { // do for this directly
137     myBuilder->loadFirstLevel(theShape, theName);
138   }
139 }
140
141 int Model_ResultBody::numberOfSubs(bool /*forTree*/) const
142 {
143   return int(mySubs.size());
144 }
145
146 ResultBodyPtr Model_ResultBody::subResult(const int theIndex, bool /*forTree*/) const
147 {
148   if (theIndex >= int(mySubs.size()))
149     return ResultBodyPtr();
150   return mySubs.at(theIndex);
151 }
152
153 bool Model_ResultBody::isSub(ObjectPtr theResult, int& theIndex) const
154 {
155   std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theResult);
156   if (aFound != mySubsMap.end()) {
157     theIndex = aFound->second;
158     return true;
159   }
160   return false;
161 }
162
163 void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
164   std::string& theDefault)
165 {
166   theSection = "Visualization";
167   theName = "result_body_color";
168   theDefault = DEFAULT_COLOR();
169 }
170
171 bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
172 {
173   bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
174   if (aChanged) { // state is changed, so modifications are needed
175     updateSubs(shape(), false); // to set disabled/enabled
176   }
177   return aChanged;
178 }
179
180 bool Model_ResultBody::isConcealed()
181 {
182   return myLastConcealed;
183 }
184
185 void Model_ResultBody::setIsConcealed(const bool theValue, const bool theForced)
186 {
187   if (ModelAPI_ResultBody::isConcealed() != theValue) {
188     ModelAPI_ResultBody::setIsConcealed(theValue, theForced);
189     updateConcealment();
190   }
191 }
192
193 // recursively check all subs for concealment flag, returns true if everybody have "flag" state,
194 // in theAll returns results with "flag" state
195 static bool checkAllSubs(ResultBodyPtr theParent, bool theFlag, std::list<ResultBodyPtr>& theAll)
196 {
197   if (theParent->isConcealed() != theFlag)
198     theAll.push_back(theParent);
199   bool aResult = theParent->ModelAPI_ResultBody::isConcealed() == theFlag;
200   for(int a = 0; a < theParent->numberOfSubs(); a++) {
201     bool aSubRes = checkAllSubs(theParent->subResult(a), theFlag, theAll);
202     if (theFlag)
203       aResult = aResult || aSubRes; // concealed: one makes concealed everyone
204     else
205       aResult = aResult && aSubRes; // not concealed: all must be not concealed
206   }
207   return aResult;
208 }
209
210 void Model_ResultBody::updateConcealment()
211 {
212   if (myLastConcealed != ModelAPI_ResultBody::isConcealed()) {
213     // check the whole tree of results: if one is concealed, everybody are concealed
214     ResultBodyPtr anOwner = std::dynamic_pointer_cast<ModelAPI_ResultBody>(data()->owner());
215     if (!anOwner.get())
216       return; // "this" is invalid
217     ResultBodyPtr aParent = ModelAPI_Tools::bodyOwner(anOwner);
218     while(aParent.get()) {
219       anOwner = aParent;
220       aParent = ModelAPI_Tools::bodyOwner(anOwner);
221     }
222     // iterate all results and collect all results whose state may be updated
223     std::list<ResultBodyPtr> anUpdated;
224     bool aNewFlag = !myLastConcealed;
225     if (checkAllSubs(anOwner, aNewFlag, anUpdated)) { // state of everyone must be updated
226       std::list<ResultBodyPtr>::iterator aRes = anUpdated.begin();
227       for(; aRes != anUpdated.end(); aRes++) {
228         bool aLastConcealed = (*aRes)->isConcealed();
229         if (aNewFlag != aLastConcealed) {
230           std::dynamic_pointer_cast<Model_ResultBody>(*aRes)->myLastConcealed = aNewFlag;
231           if (aNewFlag) { // become concealed, behaves like removed
232             ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
233           } else { // become not-concealed, behaves like created
234             static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
235             ModelAPI_EventCreator::get()->sendUpdated(*aRes, anEvent);
236           }
237           static Events_ID EVENT_DISP = // must be redisplayed in any case
238             Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
239           ModelAPI_EventCreator::get()->sendUpdated(*aRes, EVENT_DISP);
240         }
241       }
242     }
243   }
244 }
245
246 void Model_ResultBody::addShapeColor( const std::wstring& theName,std::vector<int>& color) {
247
248   if (myColorsShape.find(theName) == myColorsShape.end())
249     myColorsShape[ theName ] =  color;
250 }
251
252 std::wstring Model_ResultBody::addShapeName(std::shared_ptr<GeomAPI_Shape> theshape,
253                                             const std::wstring& theName ){
254
255   int indice = 1;
256   std::wstringstream aName;
257   aName << theName;
258   while(myNamesShape.find(aName.str()) != myNamesShape.end() ){
259     aName.str(L"");
260     aName << theName << L"__" << indice;
261     indice++;
262   }
263   myNamesShape[ aName.str() ] = theshape;
264
265   return aName.str();
266 }
267
268 std::wstring Model_ResultBody::findShapeName(std::shared_ptr<GeomAPI_Shape> theShape){
269
270   TopoDS_Shape  aShape =  theShape->impl<TopoDS_Shape>();
271   for (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> >::iterator it =
272                                                                 myNamesShape.begin();
273         it != myNamesShape.end();
274         ++it)
275   {
276     TopoDS_Shape curSelectedShape = (*it).second->impl<TopoDS_Shape>();
277     if ((aShape.IsSame(curSelectedShape)))  {
278       return (*it).first;
279     }
280   }
281   return  L"material not found" ;
282 }
283
284 void Model_ResultBody::setShapeName(
285                 std::map< std::wstring, std::shared_ptr<GeomAPI_Shape>>& theShapeName,
286                 std::map< std::wstring, std::vector<int>>& theColorsShape)
287 {
288   myNamesShape = theShapeName;
289   myColorsShape = theColorsShape;
290 }
291
292 void Model_ResultBody::clearShapeNameAndColor(){
293   myNamesShape.clear();
294   myColorsShape.clear();
295 }
296
297 void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape,
298                                   const bool theShapeChanged)
299 {
300   static Events_Loop* aLoop = Events_Loop::loop();
301   static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
302   static Events_ID EVENT_UPD = aLoop->eventByName(EVENT_OBJECT_UPDATED);
303   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
304   // erase flag that topology is connected: the shape is new
305   if (theShapeChanged && data().get()) {
306     TDF_Label aDataLab = std::dynamic_pointer_cast<Model_Data>(data())->label();
307     if (!aDataLab.IsNull()) {
308       TDataStd_UAttribute::Set(aDataLab, kUpdateConnectedTopology);
309       isConnectedTopology(); // to store this flag in transaction, #2630
310     }
311   }
312   // iterate all sub-solids of compsolid to make sub-results synchronized with them
313   TopoDS_Shape aThisShape;
314   if (theThisShape.get()) aThisShape = theThisShape->impl<TopoDS_Shape>();
315   if (!aThisShape.IsNull() && (aThisShape.ShapeType() == TopAbs_COMPSOLID ||
316        aThisShape.ShapeType() == TopAbs_COMPOUND)) {
317     bool aWasEmpty = mySubs.empty();
318     Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
319     unsigned int aSubIndex = 0;
320     TopoDS_Iterator aShapesIter(aThisShape);
321     for(; aShapesIter.More(); aShapesIter.Next(), aSubIndex++) {
322       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
323       aShape->setImpl(new TopoDS_Shape(aShapesIter.Value()));
324       ResultBodyPtr aSub;
325       if (mySubs.size() <= aSubIndex) { // it is needed to create a new sub-result
326         std::wstring thenameshape = L"";
327         // find shape name read
328         for (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> >::iterator it =
329                                                                             myNamesShape.begin();
330            it != myNamesShape.end();
331            ++it)
332         {
333             TopoDS_Shape curSelectedShape = (*it).second->impl<TopoDS_Shape>();
334             if (!(aShapesIter.Value().IsSame(curSelectedShape))) continue;
335             thenameshape = (*it).first;
336             break;
337         }
338         aSub = anObjects->createBody(this->data(), aSubIndex,thenameshape);
339         //finf color read
340         std::map< std::wstring, std::vector<int>>::iterator itColor =
341                                                           myColorsShape.find(thenameshape);
342         if (itColor != myColorsShape.end()){
343             ModelAPI_Tools::setColor(aSub,(*itColor).second);
344         }
345         aSub->setShapeName(myNamesShape,myColorsShape);
346         mySubs.push_back(aSub);
347         mySubsMap[aSub] = int(mySubs.size() - 1);
348         if (isConcealed()) { // for issue #2579 note7
349           aSub->ModelAPI_ResultBody::setIsConcealed(true);
350           std::dynamic_pointer_cast<Model_ResultBody>(aSub)->updateConcealment();
351         }
352
353       } else { // just update shape of this result
354         aSub = mySubs[aSubIndex];
355       }
356       GeomShapePtr anOldSubShape = aSub->shape();
357       if (!aShape->isEqual(anOldSubShape)) {
358         if (myAlgo.get()) {
359           std::list<GeomShapePtr> anOldForSub;
360           computeOldForSub(aShape, myOlds, anOldForSub);
361           myIsGenerated ? aSub->storeGenerated(anOldForSub, aShape, myAlgo) :
362             aSub->storeModified(anOldForSub, aShape, myAlgo);
363         } else {
364           aSub->store(aShape, false);
365         }
366         aECreator->sendUpdated(aSub, EVENT_DISP);
367         aECreator->sendUpdated(aSub, EVENT_UPD);
368       }
369       aSub->setDisabled(aSub, isDisabled());
370     }
371     // erase left, unused results
372     while(mySubs.size() > aSubIndex) {
373       ResultBodyPtr anErased = *(mySubs.rbegin());
374       if (anErased->ModelAPI_ResultBody::isConcealed()) {
375         anErased->ModelAPI_ResultBody::setIsConcealed(false);
376         std::dynamic_pointer_cast<Model_ResultBody>(anErased)->updateConcealment();
377       }
378       anErased->setDisabled(anErased, true);
379       mySubsMap.erase(anErased);
380       mySubs.pop_back();
381     }
382     if (aWasEmpty) { // erase all subs
383       // redisplay this because result with and without subs are displayed differently
384       aECreator->sendUpdated(data()->owner(), EVENT_DISP);
385     }
386     cleanCash();
387   } else if (!mySubs.empty()) { // erase all subs
388     while(!mySubs.empty()) {
389       ResultBodyPtr anErased = *(mySubs.rbegin());
390       if (anErased->ModelAPI_ResultBody::isConcealed()) {
391         anErased->ModelAPI_ResultBody::setIsConcealed(false);
392         std::dynamic_pointer_cast<Model_ResultBody>(anErased)->updateConcealment();
393       }
394       anErased->setDisabled(anErased, true); // even if it is invalid (to erase subs on abort/undo)
395       mySubs.pop_back();
396     }
397     mySubsMap.clear();
398     // redisplay this because result with and without subs are displayed differently
399     aECreator->sendUpdated(data()->owner(), EVENT_DISP);
400   }
401 }
402
403 void Model_ResultBody::updateSubs(
404   const GeomShapePtr& theThisShape, const std::list<GeomShapePtr>& theOlds,
405   const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape, const bool isGenerated)
406 {
407   myAlgo = theMakeShape;
408   myOlds = theOlds;
409   myIsGenerated = isGenerated;
410   // to avoid changing of "isDisabled" flag in the "updateSubs" cycle
411   isDisabled();
412
413   updateSubs(theThisShape, true);
414   myAlgo.reset();
415   myOlds.clear();
416   myHistoryCash.Clear();
417 }
418
419 bool Model_ResultBody::isConnectedTopology()
420 {
421   TDF_Label aDataLab = std::dynamic_pointer_cast<Model_Data>(data())->label();
422   if (!aDataLab.IsNull()) {
423     if (aDataLab.IsAttribute(kUpdateConnectedTopology)) { // recompute state
424       aDataLab.ForgetAttribute(kUpdateConnectedTopology);
425       GeomShapePtr aShape = shape();
426       if (aShape.get() && aShape->isConnectedTopology()) {
427         TDataStd_UAttribute::Set(aDataLab, kIsConnectedTopology);
428       } else {
429         aDataLab.ForgetAttribute(kIsConnectedTopology);
430       }
431     }
432     return aDataLab.IsAttribute(kIsConnectedTopology);
433   }
434   return false; // invalid case
435 }
436
437 void Model_ResultBody::cleanCash()
438 {
439   myBuilder->cleanCash();
440   for (std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
441     aSubIter != mySubs.cend(); ++aSubIter)
442   {
443     const ResultBodyPtr& aSub = *aSubIter;
444     aSub->cleanCash();
445   }
446 }
447
448 bool Model_ResultBody::hasTexture()
449 {
450   AttributeImagePtr anImageAttr =
451     data()->image(ModelAPI_ResultBody::IMAGE_ID());
452   if (anImageAttr.get()) {
453     return anImageAttr->hasTexture();
454   }
455   return false;
456 }
457
458 // adds to the theSubSubs map all sub-shapes of theSub if it is compound of compsolid
459 static void collectSubs(
460   const GeomShapePtr theSub, TopTools_MapOfShape& theSubSubs, const bool theOneLevelMore)
461 {
462   if (theSub->isNull())
463     return;
464   if (theSubSubs.Add(theSub->impl<TopoDS_Shape>()))  {
465     bool aIsComp = theSub->isCompound() || theSub->isCompSolid();
466     if (aIsComp) {
467       for(GeomAPI_ShapeIterator anIter(theSub); anIter.more(); anIter.next())
468         collectSubs(anIter.current(), theSubSubs, theOneLevelMore);
469     } else if (theOneLevelMore) {
470       GeomAPI_Shape::ShapeType aSubType = GeomAPI_Shape::ShapeType(int(theSub->shapeType()) + 1);
471       if (aSubType == GeomAPI_Shape::SHAPE)
472         return;
473       if (aSubType == GeomAPI_Shape::SHELL)
474         aSubType = GeomAPI_Shape::FACE;
475       if (aSubType == GeomAPI_Shape::WIRE)
476         aSubType = GeomAPI_Shape::EDGE;
477
478       for(GeomAPI_ShapeExplorer anExp(theSub, aSubType); anExp.more(); anExp.next()) {
479         collectSubs(anExp.current(), theSubSubs, false);
480       }
481     }
482   }
483 }
484
485 void Model_ResultBody::computeOldForSub(const GeomShapePtr& theSub,
486   const std::list<GeomShapePtr>& theAllOlds, std::list<GeomShapePtr>& theOldForSub)
487 {
488   // the old can be also used for sub-shape of theSub; collect all subs of compound or compsolid
489   TopTools_MapOfShape aSubSubs;
490   collectSubs(theSub, aSubSubs, false);
491
492   std::list<GeomShapePtr>::const_iterator aRootOlds = theAllOlds.cbegin();
493   for (; aRootOlds != theAllOlds.cend(); aRootOlds++) {
494     // use sub-shapes of olds too if they are compounds or compsolids
495     TopTools_MapOfShape anOldSubs;
496     // iterate one level more (for intersection of solids this is face)
497     collectSubs(*aRootOlds, anOldSubs, true);
498     for (TopTools_MapOfShape::Iterator anOldIter(anOldSubs); anOldIter.More(); anOldIter.Next()) {
499       TopoDS_Shape anOldShape = anOldIter.Value();
500       if (anOldShape.ShapeType() == TopAbs_COMPOUND || anOldShape.ShapeType() == TopAbs_SHELL ||
501           anOldShape.ShapeType() == TopAbs_WIRE || anOldShape.ShapeType() == TopAbs_COMPSOLID)
502         continue; // container old-shapes are not supported by the history, may cause crash
503       GeomShapePtr anOldSub(new GeomAPI_Shape);
504       anOldSub->setImpl<TopoDS_Shape>(new TopoDS_Shape(anOldShape));
505
506       ListOfShape aNews;
507       if (myHistoryCash.IsBound(anOldShape)) {
508         const TopTools_ListOfShape& aList = myHistoryCash.Find(anOldShape);
509         for(TopTools_ListIteratorOfListOfShape anIter(aList); anIter.More(); anIter.Next()) {
510           GeomShapePtr aShape(new GeomAPI_Shape);
511           aShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(anIter.Value()));
512           aNews.push_back(aShape);
513         }
514       } else {
515         myIsGenerated ? myAlgo->generated(anOldSub, aNews) : myAlgo->modified(anOldSub, aNews);
516         // MakeShape may return alone old shape if there is no history information for this input
517         if (aNews.size() == 1 && aNews.front()->isEqual(anOldSub))
518           aNews.clear();
519         // store result in the history
520         TopTools_ListOfShape aList;
521         for (ListOfShape::iterator aNewIter = aNews.begin(); aNewIter != aNews.end(); aNewIter++) {
522           aList.Append((*aNewIter)->impl<TopoDS_Shape>());
523         }
524         myHistoryCash.Bind(anOldShape, aList);
525       }
526
527       for (ListOfShape::iterator aNewIter = aNews.begin(); aNewIter != aNews.end(); aNewIter++) {
528         if (aSubSubs.Contains((*aNewIter)->impl<TopoDS_Shape>())) {
529           // check list already contains this sub
530           std::list<GeomShapePtr>::iterator aResIter = theOldForSub.begin();
531           for(; aResIter != theOldForSub.end(); aResIter++)
532             if ((*aResIter)->isSame(anOldSub))
533               break;
534           if (aResIter == theOldForSub.end())
535             theOldForSub.push_back(anOldSub); // found old used for new theSubShape creation
536           break;
537         }
538       }
539     }
540   }
541 }