+ else { // !theValid
+ if (aShape.get()) {
+ const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
+ bool anIValidPrsContains = myInvalidPrs.IsBound(aTDShape) &&
+ theValue.get()->isEqual(myInvalidPrs.Find(aTDShape).get());
+ if (!anIValidPrsContains) {
+ #ifdef LIST_OF_VALID_PRS
+ myInvalidPrs.append(theValue);
+ #else
+ myInvalidPrs.Bind(aTDShape, theValue);
+ #endif
+ //if (!aValidPrs)
+ // myValidPrs.removeOne(theValue);
+ }
+ }
+ }
+ }
+ #ifdef DEBUG_VALID_STATE
+ qDebug(QString("storeValidState: myValidPrs.size() = %1, myInvalidPrs.size() = %2").arg(myValidPrs.count())
+ .arg(myInvalidPrs.count()).toStdString().c_str());
+ #endif
+}
+
+//********************************************************************
+bool ModuleBase_WidgetValidated::getValidState(const ModuleBase_ViewerPrsPtr& theValue, bool& theValid)
+{
+ if (!theValue.get())
+ return false;
+
+#ifdef LIST_OF_VALID_PRS
+ bool aValidPrsContains = myValidPrs.contains(theValue);
+ bool anInvalidPrsContains = myInvalidPrs.contains(theValue);
+#else
+ GeomShapePtr aShape = theValue.get() ? theValue->shape() : GeomShapePtr();
+ if (!aShape.get())
+ return false;
+
+ const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
+ bool aValidPrsContains = myValidPrs.IsBound(aTDShape) &&
+ theValue.get()->isEqual(myValidPrs.Find(aTDShape).get());
+
+ bool anInvalidPrsContains = myInvalidPrs.IsBound(aTDShape) &&
+ theValue.get()->isEqual(myInvalidPrs.Find(aTDShape).get());
+ /*
+ bool aValidPrsContains = false, anInvalidPrsContains = false;
+ GeomShapePtr aShape = theValue.get() ? theValue->shape() : GeomShapePtr();
+ if (aShape.get()) {
+ aValidPrsContains = myValidPrs.contains(aShape);
+ anInvalidPrsContains = myInvalidPrs.contains(aShape);
+
+ if (aValidPrsContains)
+ aValidPrsContains = theValue == myValidPrs[aShape];
+ else
+ anInvalidPrsContains = theValue == myInvalidPrs[aShape];*/
+#endif
+
+ if (aValidPrsContains)
+ theValid = true;
+ else if (anInvalidPrsContains)
+ theValid = false;
+
+ return aValidPrsContains || anInvalidPrsContains;
+}
+
+//********************************************************************
+QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetValidated::getFilteredSelected()
+{
+ QList<ModuleBase_ViewerPrsPtr> aSelected = myWorkshop->selection()->getSelected(
+ ModuleBase_ISelection::Viewer);
+
+ QList<ModuleBase_ViewerPrsPtr> anOBSelected = myWorkshop->selection()->getSelected(
+ ModuleBase_ISelection::Browser);
+ // filter the OB presentations
+ filterPresentations(anOBSelected);
+ if (!anOBSelected.isEmpty())
+ ModuleBase_ISelection::appendSelected(anOBSelected, aSelected);
+
+ filterCompSolids(aSelected);
+
+ return aSelected;
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidated::filterPresentations(QList<ModuleBase_ViewerPrsPtr>& theValues)
+{
+ QList<ModuleBase_ViewerPrsPtr> aValidatedValues;
+
+ QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
+ bool isDone = false;
+ for (; anIt != aLast; anIt++) {
+ if (isValidInFilters(*anIt))
+ aValidatedValues.append(*anIt);
+ }
+ if (aValidatedValues.size() != theValues.size()) {
+ theValues.clear();
+ theValues = aValidatedValues;
+ }
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidated::filterCompSolids(QList<ModuleBase_ViewerPrsPtr>& theValues)
+{
+ std::set<ResultCompSolidPtr> aCompSolids;
+ QList<ModuleBase_ViewerPrsPtr> aValidatedValues;
+
+ // Collect compsolids.
+ QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
+ for (; anIt != aLast; anIt++) {
+ const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt;
+ ObjectPtr anObject = aViewerPrs->object();
+ ResultCompSolidPtr aResultCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anObject);
+ if(aResultCompSolid.get()) {
+ aCompSolids.insert(aResultCompSolid);
+ }
+ }
+
+ // Filter sub-solids of compsolids.
+ anIt = theValues.begin();
+ for (; anIt != aLast; anIt++) {
+ const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt;
+ ObjectPtr anObject = aViewerPrs->object();
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aResult);
+ if(aResCompSolidPtr.get() && (aCompSolids.find(aResCompSolidPtr) != aCompSolids.end())) {
+ // Skip sub-solid of compsolid.
+ continue;
+ } else {
+ aValidatedValues.append(*anIt);
+ }
+ }
+
+ if (aValidatedValues.size() != theValues.size()) {
+ theValues.clear();
+ theValues = aValidatedValues;