Final modification to use filters from context in:1. preselection processing, 2. onSelectionChanged[for objects from OB only]
ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
+ if (!anActiveWidget)
+ anActiveWidget = aPanel->preselectionWidget();
ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
- (anActiveWidget);
+ (anActiveWidget);
ModuleBase_ViewerPrs aPrs;
myWorkshop->selection()->fillPresentation(aPrs, theOwner);
/// \param theOperation the operation\r
virtual void sendOperation(ModuleBase_Operation* theOperation);\r
\r
+ //! Returns data object by AIS\r
+ virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;\r
+\r
signals:\r
void operationLaunched();\r
\r
/// \return Enable/Disable state of Cancel button
virtual bool isCancelEnabled() const = 0;
+ /// Returns widget processed by preselection
+ virtual ModuleBase_ModelWidget* preselectionWidget() const = 0;
+
+ /// Sets widget processed by preselection
+ virtual void setPreselectionWidget(ModuleBase_ModelWidget* theWidget) = 0;
+
signals:
/// The signal about key release on the control, that corresponds to the attribute
/// \param theEvent key release event
#include "ModuleBase_ISelection.h"
+//********************************************************************
+void ModuleBase_ISelection::appendSelected(const QList<ModuleBase_ViewerPrs> theValues,
+ QList<ModuleBase_ViewerPrs>& theValuesTo)
+{
+ // collect the objects from the viewer
+ QObjectPtrList anExistedObjects;
+ QList<ModuleBase_ViewerPrs>::const_iterator aPrsIt = theValuesTo.begin(),
+ aPrsLast = theValuesTo.end();
+ for (; aPrsIt != aPrsLast; aPrsIt++) {
+ if ((*aPrsIt).owner() && (*aPrsIt).object())
+ anExistedObjects.push_back((*aPrsIt).object());
+ }
+
+
+ QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(),
+ aLast = theValues.end();
+ for (; anIt != aLast; anIt++) {
+ ObjectPtr anObject = (*anIt).object();
+ if (anObject.get() != NULL && !anExistedObjects.contains(anObject)) {
+ theValuesTo.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
+ }
+ }
+
+}
+
//********************************************************************
ResultPtr ModuleBase_ISelection::getResult(const ModuleBase_ViewerPrs& thePrs)
{
/// \return list of presentations
virtual QList<ModuleBase_ViewerPrs> getSelected(const SelectionPlace& thePlace = Browser) const = 0;
+ /// The values are appended to the first parameter list if the first list does not contain an item
+ /// with the same object
+ /// \param theValues a list of new values
+ /// \param theValuesTo a list, that will be changed
+ static void appendSelected(const QList<ModuleBase_ViewerPrs> theValues,
+ QList<ModuleBase_ViewerPrs>& theValuesTo);
+
/// Returns a list of viewer highlited presentations
/// \return list of presentations
virtual QList<ModuleBase_ViewerPrs> getHighlighted() const = 0;
aWgt = (*aWIt);
if (!aWgt->canSetValue())
continue;
-
+ myPropertyPanel->setPreselectionWidget(aWgt);
if (!aWgt->setSelection(myPreSelection, true)) {
isSet = false;
break;
aFilledWgt = aWgt;
}
}
+ myPropertyPanel->setPreselectionWidget(NULL);
// in order to redisplay object in the viewer, the update/redisplay signals should be flushed
// it is better to perform it not in setSelection of each widget, but do it here,
// after the preselection is processed
if (!anOperation)
return true;
+ std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
if (theOwner->HasSelectable()) {
- Handle(AIS_InteractiveObject) aAisObj =
- Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+ Handle(AIS_InteractiveObject) aAisObj =
+ Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
if (!aAisObj.IsNull()) {
- std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
- ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
- if (aObj) {
- DocumentPtr aDoc = aObj->document();
- SessionPtr aMgr = ModelAPI_Session::get();
- return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
- }
- else {
- // This is not object controlled by the filter
- return Standard_True;
- }
}
}
+ ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+ if (aObj) {
+ DocumentPtr aDoc = aObj->document();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
+ }
+ else {
+ // This object is not controlled by the filter
+ return Standard_True;
+ }
return Standard_False;
}
{
clearAttribute();
- QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(
- ModuleBase_ISelection::AllControls);
- bool isDone = setSelection(aSelected, true);
+ QList<ModuleBase_ViewerPrs> aSelected = getFilteredSelected();
+ bool isDone = setSelection(aSelected, false);
emit valuesChanged();
// the updateObject method should be called to flush the updated sigal. The workshop listens it,
// calls validators for the feature and, as a result, updates the Apply button state.
activateSelection(false);
activateFilters(false);
}
+
return isDone;
}
+//********************************************************************
+ObjectPtr ModuleBase_WidgetValidated::findPresentedObject(const AISObjectPtr& theAIS) const
+{
+ return myPresentedObject;
+}
+
//********************************************************************
bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrs& thePrs)
{
bool aValid = true;
Handle(SelectMgr_EntityOwner) anOwner = thePrs.owner();
- // if an owern is null, the selection happens in the Object browser.
+ // if an owner is null, the selection happens in the Object browser.
// creates a selection owner on the base of object shape and the object AIS object
if (anOwner.IsNull() && thePrs.owner().IsNull() && thePrs.object().get()) {
ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
if (aResult.get()) {
GeomShapePtr aShape = aResult->shape();
-
const TopoDS_Shape aTDShape = aShape->impl<TopoDS_Shape>();
Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs);
anOwner = new StdSelect_BRepOwner(aTDShape, anIO);
+ myPresentedObject = aResult;
}
+ else
+ aValid = false; // only results can be filtered
}
- // finds
+ // checks the owner by the AIS context activated filters
if (!anOwner.IsNull()) {
+ // the widget validator filter should be active, but during check by preselection
+ // it is not yet activated, so we need to activate/deactivate it manually
+ bool isActivated = isFilterActivated();
+ if (!isActivated)
+ activateFilters(true);
+
const SelectMgr_ListOfFilter& aFilters = myWorkshop->viewer()->AISContext()->Filters();
SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
for (; anIt.More() && aValid; anIt.Next()) {
Handle(SelectMgr_Filter) aFilter = anIt.Value();
- //if (aFilter == myWorkshop->validatorFilter())
- // continue;
aValid = aFilter->IsOk(anOwner);
}
+ if (!isActivated)
+ activateFilters(false);
}
+
// removes created owner
- if (!anOwner.IsNull() && anOwner != thePrs.owner())
+ if (!anOwner.IsNull() && anOwner != thePrs.owner()) {
anOwner.Nullify();
+ myPresentedObject = ObjectPtr();
+ }
return aValid;
}
return aValid;
}
+bool ModuleBase_WidgetValidated::isFilterActivated() const
+{
+ bool isActivated = false;
+
+ Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
+
+ const SelectMgr_ListOfFilter& aFilters = myWorkshop->viewer()->AISContext()->Filters();
+ SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
+ for (; aIt.More(); aIt.Next()) {
+ if (aSelFilter.Access() == aIt.Value().Access())
+ isActivated = true;
+ }
+ return isActivated;
+}
+
+
void ModuleBase_WidgetValidated::activateFilters(const bool toActivate)
{
ModuleBase_IViewer* aViewer = myWorkshop->viewer();
myInvalidPrs.clear();
}
+//********************************************************************
+QList<ModuleBase_ViewerPrs> ModuleBase_WidgetValidated::getFilteredSelected()
+{
+ QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(
+ ModuleBase_ISelection::Viewer);
+
+ QList<ModuleBase_ViewerPrs> anOBSelected = myWorkshop->selection()->getSelected(
+ ModuleBase_ISelection::Browser);
+ // filter the OB presentations
+ filterPresentations(anOBSelected);
+ if (!anOBSelected.isEmpty())
+ ModuleBase_ISelection::appendSelected(anOBSelected, aSelected);
+
+ return aSelected;
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidated::filterPresentations(QList<ModuleBase_ViewerPrs>& theValues)
+{
+ QList<ModuleBase_ViewerPrs> aValidatedValues;
+
+ QList<ModuleBase_ViewerPrs>::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;
+ }
+}
#include <ModuleBase_ModelWidget.h>
#include <GeomAPI_Shape.h>
+#include <GeomAPI_AISObject.h>
#include <ModelAPI_Object.h>
#include <SelectMgr_ListOfFilter.hxx>
/// \param theValues the wrapped selection values
virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
const bool theToValidate);
+
+ //! Returns data object by AIS
+ ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
+
protected:
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
// \return true if all validators return that the attribute is valid
bool isValidAttribute() const;
+ /// Returns true if the workshop validator filter has been already activated
+ /// \return boolean value
+ bool isFilterActivated() const;
+
/// 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(const bool toActivate);
+ void activateFilters(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
// Removes all presentations from internal maps.
void clearValidState();
+ /// Returns a list of selected presentations in the viewer and object browser
+ /// The presentations from the object browser are filtered by the AIS context filters
+ /// \return a list of presentations
+ QList<ModuleBase_ViewerPrs> getFilteredSelected();
+
+ /// Applies AIS context filters to the parameter list. The not approved presentations are
+ /// removed from the parameters.
+ /// \param theValues a list of presentations.
+ void filterPresentations(QList<ModuleBase_ViewerPrs>& theValues);
+
protected:
ModuleBase_IWorkshop* myWorkshop; /// Reference to workshop
private:
+ ObjectPtr myPresentedObject; /// back up of the filtered object
QList<ModuleBase_ViewerPrs> myValidPrs;
QList<ModuleBase_ViewerPrs> myInvalidPrs;
bool isValidateBlocked;
return true;
if (ModuleBase_ShapeDocumentFilter::IsOk(theOwner)) {
+ std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
if (theOwner->HasSelectable()) {
Handle(AIS_InteractiveObject) aAisObj =
Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
if (!aAisObj.IsNull()) {
- std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
- ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
- if (aObj) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
- if (aFeature) {
- return aFeature->getKind() != FeaturesPlugin_Group::ID();
- } else
- return Standard_True;
- } else
- // This is not object controlled by the filter
- return Standard_True;
}
}
+ ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+ if (aObj) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
+ if (aFeature) {
+ return aFeature->getKind() != FeaturesPlugin_Group::ID();
+ } else
+ return Standard_True;
+ } else
+ // This is not object controlled by the filter
+ return Standard_True;
}
return Standard_False;
}
#include "PartSet_WidgetSketchLabel.h"
#include "PartSet_Validators.h"
#include "PartSet_Tools.h"
+#include "ModuleBase_WidgetValidated.h"
#include "PartSet_WidgetPoint2d.h"
#include "PartSet_WidgetPoint2dDistance.h"
#include "PartSet_WidgetShapeSelector.h"
}
}
+ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
+{
+ ObjectPtr anObject;
+ ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
+ if (aOperation) {
+ /// If last line finished on vertex the lines creation sequence has to be break
+ ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
+ // if there is an active widget, find the presented object in it
+ if (!anActiveWidget)
+ anActiveWidget = aPanel->preselectionWidget();
+
+ ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
+ (anActiveWidget);
+ if (aWidgetValidated)
+ anObject = aWidgetValidated->findPresentedObject(theAIS);
+ }
+ return anObject;
+}
void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
{
/// Returns the viewer Z layer
int getVisualLayerId() const { return myVisualLayerId; }
+ //! Returns data object by AIS
+ virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
+
public slots:
/// SLOT, that is called by no more widget signal emitted by property panel
/// Set a specific flag to restart the sketcher operation
void PartSet_WidgetSketchLabel::onSelectionChanged()
{
- QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(
- ModuleBase_ISelection::AllControls);
+ QList<ModuleBase_ViewerPrs> aSelected = getFilteredSelected();
+
if (aSelected.empty())
return;
ModuleBase_ViewerPrs aPrs = aSelected.first();
ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
{
XGUI_Displayer* aDisp = myWorkshop->displayer();
- return aDisp->getObject(theAIS);
+ ObjectPtr anObject = aDisp->getObject(theAIS);
+ if (!anObject.get())
+ anObject = module()->findPresentedObject(theAIS);
+ return anObject;
}
void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrs>& theValues)
XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
: ModuleBase_IPropertyPanel(theParent),
myActiveWidget(NULL),
+ myPreselectionWidget(NULL),
myPanelPage(NULL)
{
this->setWindowTitle(tr("Property Panel"));
aBtn->setDefaultAction(anAct);
}
}
+
+ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const
+{
+ return myPreselectionWidget;
+}
+
+void XGUI_PropertyPanel::setPreselectionWidget(ModuleBase_ModelWidget* theWidget)
+{
+ myPreselectionWidget = theWidget;
+}
//! Allows to set predefined actions for the property panel fetched from the ActionsMgr
void setupActions(XGUI_ActionsMgr* theMgr);
+ /// Returns widget processed by preselection
+ virtual ModuleBase_ModelWidget* preselectionWidget() const;
+
+ /// Sets widget processed by preselection
+ virtual void setPreselectionWidget(ModuleBase_ModelWidget* theWidget);
+
public slots:
/// \brief Update all widgets in property panel with values from the given feature
/// Currently active widget
ModuleBase_ModelWidget* myActiveWidget;
+ /// Currently widget processed by preselection
+ ModuleBase_ModelWidget* myPreselectionWidget;
};
#endif /* XGUI_PROPERTYPANEL_H_ */