This cache exists between activate/deactivate of the widget.
}
}
-//********************************************************************
-void ModuleBase_WidgetMultiSelector::customValidators(
- std::list<ModelAPI_Validator*>& theValidators,
- std::list<std::list<std::string> >& theArguments) const
-{
- return;
- std::list<std::string> anArguments;
-
- theValidators.push_back(myShapeValidator);
- if (true/*myIsUseChoice*/) {
- QString aType = myTypeCombo->currentText();
- anArguments.push_back(validatorType(aType));
- }
- else {
- for(int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) {
- anArguments.push_back(validatorType(myTypeCombo->itemText(i)));
- }
- }
- theArguments.push_back(anArguments);
-}
-
//********************************************************************
bool ModuleBase_WidgetMultiSelector::acceptSubShape(const TopoDS_Shape& theShape) const
{
/// \param theValid a boolean flag, if restore happens for valid parameters
virtual void restoreAttributeValue(const bool theValid);
- /// Puts additional validators to the given list. A separate validator is created for each of the
- /// "type_choice" value
- /// \param theValidators a list of validators
- /// \param theArguments a list of validators arguments
- virtual void customValidators(std::list<ModelAPI_Validator*>& theValidators,
- std::list<std::list<std::string> >& theArguments) const;
-
/// Returns true if selected shape corresponds to requested shape types
/// \param theShape a shape
bool acceptSubShape(const TopoDS_Shape& theShape) const;
}
}
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::customValidators(
- std::list<ModelAPI_Validator*>& theValidators,
- std::list<std::list<std::string> >& theArguments) const
-{
- return;
- theValidators.push_back(myShapeValidator);
-
- std::list<std::string> anArguments;
- foreach(QString aType, myShapeTypes) {
- anArguments.push_back(aType.toStdString().c_str());
- }
- theArguments.push_back(anArguments);
-}
-
//********************************************************************
bool ModuleBase_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
/// \param theValid a boolean flag, if restore happens for valid parameters
virtual void restoreAttributeValue(const bool theValid);
- /// Puts additional validators to the given list. A separate validator is created for each of the
- /// "type_choice" value
- /// \param theValidators a list of validators
- /// \param theArguments a list of validators arguments
- virtual void customValidators(std::list<ModelAPI_Validator*>& theValidators,
- std::list<std::list<std::string> >& theArguments) const;
-
/// Computes and updates name of selected object in the widget
void updateSelectionName();
#include <QWidget>
+//#define DEBUG_VALID_STATE
+
ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent,
const Config_WidgetAPI* theData,
const std::string& theParentId)
//********************************************************************
bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& theValue)
{
- bool aValid = isValidSelectionCustom(theValue);
- if (!aValid)
+ bool aValid = false;
+ if (getValidState(theValue, aValid)) {
+ return aValid;
+ }
+
+ aValid = isValidSelectionCustom(theValue);
+ if (!aValid) {
+ storeValidState(theValue, aValid);
return aValid;
+ }
DataPtr aData = myFeature->data();
AttributePtr anAttribute = myFeature->attribute(attributeID());
aLoop->flush(aDeletedEvent);
aLoop->flush(aRedispEvent);
+ storeValidState(theValue, aValid);
return aValid;
}
std::list<std::list<std::string> > anArguments;
aFactory->validators(myFeature->getKind(), attributeID(), aValidators, anArguments);
- customValidators(aValidators, anArguments);
-
DataPtr aData = myFeature->data();
AttributePtr anAttribute = myFeature->attribute(attributeID());
}
void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
- const bool toActivate) const
+ const bool toActivate)
{
ModuleBase_IViewer* aViewer = theWorkshop->viewer();
Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
if (toActivate)
aViewer->addSelectionFilter(aSelFilter);
- else
+ else {
aViewer->removeSelectionFilter(aSelFilter);
+ clearValidState();
+ }
}
-void ModuleBase_WidgetValidated::customValidators(std::list<ModelAPI_Validator*>& theValidators,
- std::list<std::list<std::string> >& theArguments) const
+//********************************************************************
+void ModuleBase_WidgetValidated::storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid)
{
+ bool aValidPrs = myInvalidPrs.contains(theValue);
+ bool anInvalidPrs = myInvalidPrs.contains(theValue);
+
+ if (theValid) {
+ if (!aValidPrs)
+ myValidPrs.append(theValue);
+ // the commented code will be useful when the valid state of the presentation
+ // will be changable between activate/deactivate. Currently it does not happen.
+ //if (anInvalidPrs)
+ // myInvalidPrs.removeOne(theValue);
+ }
+ else { // !theValid
+ if (!anInvalidPrs)
+ myInvalidPrs.append(theValue);
+ //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_ViewerPrs& theValue, bool& theValid)
+{
+ bool aValidPrs = myValidPrs.contains(theValue);
+ bool anInvalidPrs = myInvalidPrs.contains(theValue);
+
+ if (aValidPrs)
+ theValid = true;
+ else if (anInvalidPrs)
+ theValid = false;
+
+ return aValidPrs || anInvalidPrs;
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidated::clearValidState()
+{
+#ifdef DEBUG_VALID_STATE
+ qDebug("clearValidState");
+#endif
+ myValidPrs.clear();
+ myInvalidPrs.clear();
+}
+
#include <SelectMgr_ListOfFilter.hxx>
+#include <QList>
+
class QWidget;
class ModuleBase_IWorkshop;
class ModuleBase_ISelection;
/// It obtains selection filters from the workshop and activates them in the active viewer
/// \param theWorkshop an active workshop
/// \param toActivate a flag about activation or deactivation the filters
- virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const;
+ virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate);
+
+ /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
+ /// \param theValue a viewer presentation
+ /// \param theValid a valid state
+ bool getValidState(const ModuleBase_ViewerPrs& theValue, bool& theValid);
+
+ /// Store the validity state of the presentation in an internal map
+ /// \param theValue a viewer presentation
+ /// \param theValid a valid state
+ void storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid);
+
+ // Removes all presentations from internal maps.
+ void clearValidState();
- /// Puts additional validators to the given list
- /// \param theValidators a list of validators
- /// \param theArguments a list of validators arguments
- virtual void customValidators(std::list<ModelAPI_Validator*>& theValidators,
- std::list<std::list<std::string> >& theArguments) const;
+private:
+ QList<ModuleBase_ViewerPrs> myValidPrs;
+ QList<ModuleBase_ViewerPrs> myInvalidPrs;
};
#endif /* MODULEBASE_WIDGETVALIDATED_H_ */