]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetValidated.cpp
Salome HOME
a02d2589e08de96e083933c1593be234176e2c9a
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidated.cpp
1 // Copyright (C) 2014-2020  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 <ModuleBase_WidgetValidated.h>
21 #include <ModuleBase_IModule.h>
22 #include <ModuleBase_IViewer.h>
23 #include <ModuleBase_IWorkshop.h>
24 #include <ModuleBase_ISelection.h>
25 #include <ModuleBase_ISelectionActivate.h>
26 #include <ModuleBase_WidgetSelectorStore.h>
27 #include <ModuleBase_ViewerPrs.h>
28
29 #include <Events_InfoMessage.h>
30
31 #include <ModelAPI_Session.h>
32 #include <ModelAPI_Validator.h>
33 #include <ModelAPI_AttributeValidator.h>
34 #include <ModelAPI_Events.h>
35 #include <ModelAPI_Tools.h>
36 #include <ModelAPI_AttributeSelection.h>
37
38 #include <BuildPlugin_Face.h>
39 #include <BuildPlugin_Wire.h>
40 #include <BuildPlugin_Solid.h>
41
42 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
43 #include <SelectMgr_EntityOwner.hxx>
44 #include <StdSelect_BRepOwner.hxx>
45
46 #include <Events_Loop.h>
47
48 #include <QWidget>
49
50 //#define DEBUG_VALID_STATE
51
52 ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent,
53                                                        ModuleBase_IWorkshop* theWorkshop,
54                                                        const Config_WidgetAPI* theData)
55 : ModuleBase_ModelWidget(theParent, theData),
56   myWorkshop(theWorkshop), myIsInValidate(false)
57 {
58   myAttributeStore = new ModuleBase_WidgetSelectorStore();
59 }
60
61 ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
62 {
63   delete myAttributeStore;
64 }
65
66 //********************************************************************
67 ObjectPtr ModuleBase_WidgetValidated::findPresentedObject(const AISObjectPtr& theAIS) const
68 {
69   return myPresentedObject;
70 }
71
72 //********************************************************************
73 void ModuleBase_WidgetValidated::deactivate()
74 {
75   clearValidatedCash();
76 }
77
78 //********************************************************************
79 void ModuleBase_WidgetValidated::clearValidatedCash()
80 {
81 #ifdef DEBUG_VALID_STATE
82   qDebug("clearValidatedCash");
83 #endif
84   myValidPrs.Clear();
85   myInvalidPrs.Clear();
86 }
87
88 //********************************************************************
89 void ModuleBase_WidgetValidated::storeAttributeValue(const AttributePtr& theAttribute)
90 {
91   myIsInValidate = true;
92   myAttributeStore->storeAttributeValue(theAttribute, myWorkshop);
93 }
94
95 //********************************************************************
96 void ModuleBase_WidgetValidated::restoreAttributeValue(const AttributePtr& theAttribute,
97                                                        const bool theValid)
98 {
99   myIsInValidate = false;
100   myAttributeStore->restoreAttributeValue(theAttribute, myWorkshop);
101 }
102
103
104 //********************************************************************
105 void ModuleBase_WidgetValidated::collectSubBodies(const ResultBodyPtr& theBody,
106                                                   AIS_NListOfEntityOwner& theList)
107 {
108   AISObjectPtr aIOPtr;
109   TopoDS_Shape aTDShape;
110   int aNb = theBody->numberOfSubs();
111   for (int i = 0; i < aNb; i++) {
112     ResultBodyPtr aSub = theBody->subResult(i);
113     if (aSub->numberOfSubs() > 0)
114       collectSubBodies(aSub, theList);
115     else {
116       aTDShape = aSub->shape()->impl<TopoDS_Shape>();
117       aIOPtr = myWorkshop->findPresentation(aSub);
118       if (aIOPtr.get()) {
119         Handle(AIS_InteractiveObject) anIO = aIOPtr->impl<Handle(AIS_InteractiveObject)>();
120         theList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
121       }
122       else
123         theList.Append(new StdSelect_BRepOwner(aTDShape));
124     }
125   }
126 }
127
128 //********************************************************************
129 bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr& thePrs)
130 {
131   bool aValid = true;
132   AIS_NListOfEntityOwner aOwnersList;
133   if (!thePrs->owner().IsNull())
134     aOwnersList.Append(thePrs->owner());
135
136   // if an owner is null, the selection happens in the Object browser.
137   // creates a selection owner on the base of object shape and the object AIS object
138   if ((aOwnersList.Size() == 0) && thePrs->object().get()) {
139     ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
140     GeomShapePtr aShape = aResult.get() ? aResult->shape() : GeomShapePtr();
141     // some results have no shape, e.g. the parameter one. So, they should not be validated
142     if (aShape.get()) {
143       const TopoDS_Shape aTDShape = aShape->impl<TopoDS_Shape>();
144       Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs);
145       aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
146       myPresentedObject = aResult;
147     }
148     else {
149       //FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
150       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(thePrs->object());
151       if (aFeature.get()) {
152         // Use feature as a reference to all its results
153         myPresentedObject = aFeature;
154         AttributePtr anAttr = attribute();
155         std::string aType = anAttr->attributeType();
156
157         // Check that results of Feature is acceptable by filters for selection attribute
158         if (aType == ModelAPI_AttributeSelection::typeId()) {
159           AttributeSelectionPtr aSelectAttr =
160             std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttr);
161           aSelectAttr->setValue(myPresentedObject, GeomShapePtr(), true);
162           GeomShapePtr aShapePtr = aSelectAttr->value();
163           if (!aShapePtr.get() && aSelectAttr->contextFeature().get() &&
164             aSelectAttr->contextFeature()->firstResult().get()) {
165             aShapePtr = aSelectAttr->contextFeature()->firstResult()->shape();
166           }
167           if (aShapePtr.get()) {
168             const TopoDS_Shape aTDShape = aShapePtr->impl<TopoDS_Shape>();
169             Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs);
170             aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
171           }
172         }
173         else {
174           ResultPtr aFirstRes = aFeature->firstResult();
175           if (aFirstRes.get()) {
176             ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aFirstRes);
177             if (aBody.get() && (aBody->numberOfSubs() > 0))
178               collectSubBodies(aBody, aOwnersList);
179             else {
180               GeomShapePtr aShapePtr = ModelAPI_Tools::shape(aFirstRes);
181               if (aShapePtr.get()) {
182                 TopoDS_Shape aTDShape = aShapePtr->impl<TopoDS_Shape>();
183                 AISObjectPtr aIOPtr = myWorkshop->findPresentation(aFirstRes);
184                 if (aIOPtr.get()) {
185                   Handle(AIS_InteractiveObject) anIO =
186                     aIOPtr->impl<Handle(AIS_InteractiveObject)>();
187                   aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
188                 }
189                 else
190                   aOwnersList.Append(new StdSelect_BRepOwner(aTDShape));
191               }
192             }
193           }
194         }
195       }
196     }
197   }
198   aValid = (aOwnersList.Size() > 0); // only results with a shape can be filtered
199
200   // checks the owner by the AIS context activated filters
201   if (aOwnersList.Size() > 0) {
202     // the widget validator filter should be active, but during check by preselection
203     // it is not yet activated, so we need to activate/deactivate it manually
204     bool isActivated = isFilterActivated();
205     if (!isActivated) {
206       QIntList aModuleSelectionFilters = myWorkshop->module()->selectionFilters();
207       SelectMgr_ListOfFilter aSelectionFilters;
208       selectionFilters(aModuleSelectionFilters, aSelectionFilters);
209       /// after validation, the selection filters should be restored
210       myWorkshop->selectionActivate()->activateSelectionFilters(aSelectionFilters);
211     }
212
213     Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
214     if (!aContext.IsNull()) {
215       const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
216       SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
217       AIS_NListOfEntityOwner::Iterator aOIt;
218       for (; anIt.More() && aValid; anIt.Next()) {
219         Handle(SelectMgr_Filter) aFilter = anIt.Value();
220         for (aOIt.Init(aOwnersList); aOIt.More(); aOIt.Next()) {
221           aValid = aFilter->IsOk(aOIt.Value());
222           if (!aValid)
223             break;
224         }
225         if (!aValid)
226           break;
227       }
228     }
229     if (!isActivated) {
230       // reset filters set in activateSelectionFilters above
231       myWorkshop->selectionActivate()->updateSelectionFilters();
232       clearValidatedCash();
233     }
234   }
235
236   // removes created owner
237   if (aOwnersList.Size() > 0 && thePrs->owner().IsNull()) {
238     myPresentedObject = ObjectPtr();
239   }
240   if (!aValid) {
241     // Clear attribute if it still has selection
242     AttributePtr anAttr = attribute();
243     std::string aType = anAttr->attributeType();
244     if (aType == ModelAPI_AttributeSelection::typeId()) {
245       AttributeSelectionPtr aSelectAttr =
246         std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttr);
247       aSelectAttr->removeTemporaryValues();
248     }
249   }
250   return aValid;
251 }
252
253 //********************************************************************
254 AttributePtr ModuleBase_WidgetValidated::attribute() const
255 {
256   return myFeature->attribute(attributeID());
257 }
258
259 //********************************************************************
260 bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrsPtr& theValue)
261 {
262   bool aValid = false;
263   if (getValidState(theValue, aValid)) {
264     return aValid;
265   }
266   aValid = isValidSelectionCustom(theValue);
267   if (aValid)
268     aValid = isValidSelectionForAttribute(theValue, attribute());
269
270   storeValidState(theValue, aValid);
271   return aValid;
272 }
273
274 //********************************************************************
275 bool ModuleBase_WidgetValidated::isValidSelectionForAttribute(
276                                             const ModuleBase_ViewerPrsPtr& theValue,
277                                             const AttributePtr& theAttribute)
278 {
279   bool aValid = false;
280
281   // stores the current values of the widget attribute
282   bool isFlushesActived, isAttributeSetInitializedBlocked, isAttributeSendUpdatedBlocked;
283
284   blockAttribute(theAttribute, true, isFlushesActived, isAttributeSetInitializedBlocked,
285                  isAttributeSendUpdatedBlocked);
286
287   storeAttributeValue(theAttribute);
288
289   // saves the owner value to the widget attribute
290   aValid = setSelectionCustom(theValue);
291   if (aValid)
292     // checks the attribute validity
293     aValid = isValidAttribute(theAttribute);
294
295   // restores the current values of the widget attribute
296   restoreAttributeValue(theAttribute, aValid);
297
298   blockAttribute(theAttribute, false, isFlushesActived, isAttributeSetInitializedBlocked,
299                  isAttributeSendUpdatedBlocked);
300   /// NDS: The following rows are commented for issue #1452 (to be removed after debug)
301   /// This is not correct to perform it here because it might cause update selection and
302   /// the selection mechanizm will be circled: use the scenario of the bug with preselected point.
303   // In particular case the results are deleted and called as redisplayed inside of this
304   // highlight-selection, to they must be flushed as soon as possible.
305   // Example: selection of group-vertices subshapes with shift pressend on body. Without
306   //  these 4 lines below the application crashes because of left presentations on
307   //  removed results still in the viewer.
308   /*static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
309   static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
310   Events_Loop::loop()->flush(aDeletedEvent);
311   Events_Loop::loop()->flush(aRedispEvent);
312   */
313   return aValid;
314 }
315
316 //********************************************************************
317 bool ModuleBase_WidgetValidated::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
318 {
319   return true;
320 }
321
322 //********************************************************************
323 bool ModuleBase_WidgetValidated::isValidAttribute(const AttributePtr& theAttribute)
324 {
325   SessionPtr aMgr = ModelAPI_Session::get();
326   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
327   std::string aValidatorID;
328   Events_InfoMessage anError;
329   return aFactory->validate(theAttribute, aValidatorID, anError);
330 }
331
332 //********************************************************************
333 bool ModuleBase_WidgetValidated::isFilterActivated() const
334 {
335   Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
336   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
337
338   return aViewer->hasSelectionFilter(aSelFilter);
339 }
340
341 //********************************************************************
342 void ModuleBase_WidgetValidated::selectionFilters(QIntList& theModuleSelectionFilters,
343                                                   SelectMgr_ListOfFilter& theSelectionFilters)
344 {
345   theSelectionFilters.Append(myWorkshop->validatorFilter());
346 }
347
348 //********************************************************************
349 void ModuleBase_WidgetValidated::blockAttribute(const AttributePtr& theAttribute,
350                                                 const bool& theToBlock,
351                                                 bool& isFlushesActived,
352                                                 bool& isAttributeSetInitializedBlocked,
353                                                 bool& isAttributeSendUpdatedBlocked)
354 {
355   blockFeatureAttribute(theAttribute, myFeature, theToBlock, isFlushesActived,
356                         isAttributeSetInitializedBlocked, isAttributeSendUpdatedBlocked);
357 }
358
359 //********************************************************************
360 void ModuleBase_WidgetValidated::blockFeatureAttribute(const AttributePtr& theAttribute,
361                                                 const FeaturePtr& theFeature,
362                                                 const bool& theToBlock,
363                                                 bool& isFlushesActived,
364                                                 bool& isAttributeSetInitializedBlocked,
365                                                 bool& isAttributeSendUpdatedBlocked)
366 {
367   Events_Loop* aLoop = Events_Loop::loop();
368   DataPtr aData = theFeature->data();
369   if (theToBlock) {
370     // blocks the flush signals to avoid the temporary objects visualization in the viewer
371     // they should not be shown in order to do not lose highlight by erasing them
372     isFlushesActived = aLoop->activateFlushes(false);
373
374     isAttributeSendUpdatedBlocked = aData->blockSendAttributeUpdated(true);
375     isAttributeSetInitializedBlocked = theAttribute->blockSetInitialized(true);
376   }
377   else {
378     aData->blockSendAttributeUpdated(isAttributeSendUpdatedBlocked, false);
379     theAttribute->blockSetInitialized(isAttributeSetInitializedBlocked);
380     aLoop->activateFlushes(isFlushesActived);
381   }
382 }
383
384 //********************************************************************
385 void ModuleBase_WidgetValidated::storeValidState(const ModuleBase_ViewerPrsPtr& theValue,
386                                                  const bool theValid)
387 {
388   GeomShapePtr aShape = theValue.get() ? theValue->shape() : GeomShapePtr();
389   if (aShape.get()) {
390     if (theValid) {
391       const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
392       bool aValidPrsContains = myValidPrs.IsBound(aTDShape) &&
393                                theValue.get()->isEqual(myValidPrs.Find(aTDShape).get());
394       if (!aValidPrsContains) {
395   #ifdef LIST_OF_VALID_PRS
396         myValidPrs.append(theValue);
397   #else
398         myValidPrs.Bind(aTDShape, theValue);
399   #endif
400       // the commented code will be useful when the valid state of the presentation
401       // will be changable between activate/deactivate. Currently it does not happen.
402       //if (anInvalidPrs)
403       //  myInvalidPrs.removeOne(theValue);
404       }
405     }
406     else { // !theValid
407       if (aShape.get()) {
408         const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
409         bool anIValidPrsContains = myInvalidPrs.IsBound(aTDShape) &&
410                                    theValue.get()->isEqual(myInvalidPrs.Find(aTDShape).get());
411         if (!anIValidPrsContains) {
412     #ifdef LIST_OF_VALID_PRS
413           myInvalidPrs.append(theValue);
414     #else
415           myInvalidPrs.Bind(aTDShape, theValue);
416     #endif
417         //if (!aValidPrs)
418         //  myValidPrs.removeOne(theValue);
419         }
420       }
421     }
422   }
423   #ifdef DEBUG_VALID_STATE
424     qDebug(QString("storeValidState: myValidPrs.size() = %1, myInvalidPrs.size() = %2")
425                    .arg(myValidPrs.count())
426                    .arg(myInvalidPrs.count()).toStdString().c_str());
427   #endif
428 }
429
430 //********************************************************************
431 bool ModuleBase_WidgetValidated::getValidState(const ModuleBase_ViewerPrsPtr& theValue,
432                                                bool& theValid)
433 {
434   if (!theValue.get())
435     return false;
436
437 #ifdef LIST_OF_VALID_PRS
438   bool aValidPrsContains = myValidPrs.contains(theValue);
439   bool anInvalidPrsContains = myInvalidPrs.contains(theValue);
440 #else
441   GeomShapePtr aShape = theValue.get() ? theValue->shape() : GeomShapePtr();
442   if (!aShape.get())
443     return false;
444
445   const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
446   bool aValidPrsContains = myValidPrs.IsBound(aTDShape) &&
447                            theValue.get()->isEqual(myValidPrs.Find(aTDShape).get());
448
449   bool anInvalidPrsContains = myInvalidPrs.IsBound(aTDShape) &&
450                               theValue.get()->isEqual(myInvalidPrs.Find(aTDShape).get());
451   /*
452   bool aValidPrsContains = false, anInvalidPrsContains = false;
453   GeomShapePtr aShape = theValue.get() ? theValue->shape() : GeomShapePtr();
454   if (aShape.get()) {
455     aValidPrsContains = myValidPrs.contains(aShape);
456     anInvalidPrsContains = myInvalidPrs.contains(aShape);
457
458     if (aValidPrsContains)
459       aValidPrsContains = theValue == myValidPrs[aShape];
460     else
461       anInvalidPrsContains = theValue == myInvalidPrs[aShape];*/
462 #endif
463
464   if (aValidPrsContains)
465     theValid = true;
466   else if (anInvalidPrsContains)
467     theValid = false;
468
469   return aValidPrsContains || anInvalidPrsContains;
470 }
471
472 //********************************************************************
473 QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetValidated::getFilteredSelected()
474 {
475   QList<ModuleBase_ViewerPrsPtr> aSelected = myWorkshop->selection()->getSelected(
476                                                        ModuleBase_ISelection::Viewer);
477
478   QList<ModuleBase_ViewerPrsPtr> anOBSelected = myWorkshop->selection()->getSelected(
479                                                        ModuleBase_ISelection::Browser);
480   // filter the OB presentations
481   filterPresentations(anOBSelected);
482   if (!anOBSelected.isEmpty())
483     ModuleBase_ISelection::appendSelected(anOBSelected, aSelected);
484
485   filterCompSolids(aSelected);
486
487   if (myFeatureId == BuildPlugin_Face::ID() || myFeatureId == BuildPlugin_Wire::ID() ||
488       myFeatureId == BuildPlugin_Solid::ID())
489   {
490     /// remove objects of sub-type if ojects of correct type is in List,  in some cases :
491     /// - Face builder: edges, faces and wires selected
492     ///                 --> remove edges and wires
493     /// Wire builder: wires and edges selected
494     ///               --> remove egdes
495     /// Solid builder: faces and shapes shells or solids seleted
496     ///                --> remove faces
497
498     std::set<GeomAPI_Shape::ShapeType> shapeTypes;
499     for (auto aSelection: aSelected){
500       auto aShape = aSelection->shape();
501       if (aShape)
502         shapeTypes.insert(aShape->shapeType());
503     }
504
505     std::vector<ModuleBase_ViewerPrsPtr> aRemove;
506
507     if (myFeatureId == BuildPlugin_Face::ID() && shapeTypes.find(GeomAPI_Shape::FACE) != shapeTypes.end())
508     {
509       for(auto aSelection: aSelected){
510         auto aType = aSelection->shape()->shapeType();
511         if (aType == GeomAPI_Shape::WIRE || aType == GeomAPI_Shape::EDGE)
512           aRemove.push_back(aSelection);
513       }
514     }
515     else if (myFeatureId == BuildPlugin_Wire::ID() && shapeTypes.find(GeomAPI_Shape::WIRE) != shapeTypes.end())
516     {
517       for(auto aSelection: aSelected){
518         auto aType = aSelection->shape()->shapeType();
519         if (aType == GeomAPI_Shape::EDGE)
520           aRemove.push_back(aSelection);
521       }
522     }
523     else if (myFeatureId == BuildPlugin_Solid::ID() &&
524              (shapeTypes.find(GeomAPI_Shape::SHAPE) != shapeTypes.end() ||
525               shapeTypes.find(GeomAPI_Shape::SOLID) != shapeTypes.end() ||
526               shapeTypes.find(GeomAPI_Shape::SHELL) != shapeTypes.end()) )
527     {
528       for(auto aSelection: aSelected){
529         auto aType = aSelection->shape()->shapeType();
530         if( aType == GeomAPI_Shape::FACE)
531           aRemove.push_back(aSelection);
532       }
533     }
534
535     for(auto aSelection: aRemove){
536       aSelected.removeOne(aSelection);
537     }
538   }
539
540   return aSelected;
541 }
542
543 //********************************************************************
544 void ModuleBase_WidgetValidated::filterPresentations(QList<ModuleBase_ViewerPrsPtr>& theValues)
545 {
546   QList<ModuleBase_ViewerPrsPtr> aValidatedValues;
547   foreach(ModuleBase_ViewerPrsPtr aPrs, theValues) {
548     if (isValidInFilters(aPrs))
549       aValidatedValues.append(aPrs);
550   }
551   if (aValidatedValues.size() != theValues.size()) {
552     theValues.clear();
553     theValues = aValidatedValues;
554   }
555 }
556
557 //********************************************************************
558 void ModuleBase_WidgetValidated::filterCompSolids(QList<ModuleBase_ViewerPrsPtr>& theValues)
559 {
560   std::set<ResultPtr> aFilterOut; // all objects that must be filtered out with their children
561   QList<ModuleBase_ViewerPrsPtr> aValidatedValues;
562
563   // Collect compsolids.
564   QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
565   for(; anIt != aLast; anIt++) {
566     const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt;
567     ObjectPtr anObject = aViewerPrs->object();
568     ResultBodyPtr aResultCompSolid =
569       std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
570     if (aResultCompSolid.get()) {
571       for(int aSubIndex = 0; aSubIndex < aResultCompSolid->numberOfSubs(); aSubIndex++)
572         aFilterOut.insert(aResultCompSolid->subResult(aSubIndex));
573     } else { // it could be a whole feature selected, so, add all results of this feature
574       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
575       if (aFeature.get()) {
576         std::list<ResultPtr>::const_iterator aRes = aFeature->results().cbegin();
577         for(; aRes != aFeature->results().cend(); aRes++)
578           aFilterOut.insert(*aRes);
579       }
580     }
581   }
582
583   // Filter sub-solids of compsolids.
584   anIt = theValues.begin();
585   for(; anIt != aLast; anIt++) {
586     const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt;
587     ObjectPtr anObject = aViewerPrs->object();
588     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
589     while(aResult.get()) {
590       if (aFilterOut.find(aResult) != aFilterOut.end()) // skip if parent is filtered out
591         break;
592       aResult = ModelAPI_Tools::bodyOwner(aResult); // iterate all parents
593     }
594     if (aResult.get()) {
595       continue; // skip
596     } else {
597       aValidatedValues.append(*anIt);
598     }
599   }
600
601   if (aValidatedValues.size() != theValues.size()) {
602     theValues.clear();
603     theValues = aValidatedValues;
604   }
605 }