bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape,
const ModelAPI_FiltersArgs& theArgs) const
{
- return true;
+ AttributePtr aAttr = theArgs.argument("BelongsTo");
+ AttributeSelectionListPtr aList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
+ if (!aList.get())
+ return false;
+ for (int i = 0; i < aList->size(); i++) {
+ AttributeSelectionPtr aAttr = aList->value(i);
+ GeomShapePtr aGeom = aAttr->value();
+ if (aGeom->isSubShape(theShape))
+ return true;
+ }
+ return false;
}
static std::string XMLRepresentation =
-"<filter id = \"Belongs to\">"
-" <multi_selector id=\"Belongs to\""
+"<filter id = \"BelongsTo\">"
+" <multi_selector id=\"BelongsTo__BelongsTo\""
" label = \"Objects:\""
" tooltip = \"Select objects to limit selection.\""
" type_choice = \"objects\">"
void FiltersPlugin_BelongsTo::initAttributes(ModelAPI_FiltersArgs& theArguments)
{
- theArguments.initAttribute("Belongs to", ModelAPI_AttributeSelectionList::typeId());
+ theArguments.initAttribute("BelongsTo", ModelAPI_AttributeSelectionList::typeId());
}
}
}
+struct FilterArgs {
+ FilterPtr myFilter;
+ bool myReverse;
+ std::string myFilterID;
+};
+
bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape)
{
// prepare all filters args
ModelAPI_FiltersArgs anArgs;
- std::map<FilterPtr, bool> aReverseFlags; /// map of all filters to the reverse values
+ std::list<FilterArgs> aFilters; /// all filters and the reverse values
std::list<std::string> aGroups;
theFiltersFeature->data()->allGroups(aGroups);
if (anArgID.empty()) { // reverse flag
std::shared_ptr<ModelAPI_AttributeBoolean> aReverse =
std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(*anAttrIter);
- aReverseFlags[myFilters[*aGIter] ] = aReverse->value();
+ FilterArgs aFArgs = { myFilters[*aGIter] , aReverse->value() , *aGIter };
+ aFilters.push_back(aFArgs);
+
} else {
anArgs.add(*anAttrIter);
}
}
// iterate filters and check shape for validity for all of them
- std::map<FilterPtr, bool>::iterator aFilter = aReverseFlags.begin();
- for(; aFilter != aReverseFlags.end(); aFilter++) {
- bool aResult = aFilter->first->isOk(theShape, anArgs);
- if (aFilter->second)
+ std::list<FilterArgs>::iterator aFilter = aFilters.begin();
+ for(; aFilter != aFilters.end(); aFilter++) {
+ anArgs.setFilter(aFilter->myFilterID);
+ bool aResult = aFilter->myFilter->isOk(theShape, anArgs);
+ if (aFilter->myReverse)
aResult = !aResult;
if (!aResult) // one filter is failed => exit immediately
return false;
}
/// returns the argument of the current filter by the argument id
- AttributePtr argument(const std::string& theID) {
+ AttributePtr argument(const std::string& theID) const {
return myMap.find(myCurrentFilter + kFilterSeparator + theID)->second;
}
/// adds an attribute of the filter
/// \return boolean value
virtual bool hasSHIFTPressed() const = 0;
+ virtual void deactivateCurrentSelector() = 0;
+
signals:
/// Signal selection changed.
void selectionChanged();
#include "ModuleBase_WidgetSelectionFilter.h"
#include "ModuleBase_Tools.h"
#include "ModuleBase_IWorkshop.h"
+#include "ModuleBase_ISelectionActivate.h"
#include "ModuleBase_IModule.h"
#include "ModuleBase_IViewer.h"
#include "ModuleBase_IPropertyPanel.h"
#include <ModelAPI_Session.h>
#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Events.h>
#include <GeomAPI_ShapeExplorer.h>
+#include <Events_Loop.h>
+
#include <AIS_InteractiveContext.hxx>
#include <StdSelect_BRepOwner.hxx>
#include <TopoDS_Compound.hxx>
aLayout->addWidget(aItemRow);
ModuleBase_PageWidget* aParamsWgt = new ModuleBase_PageWidget(this);
+ aParamsWgt->setFrameStyle(QFrame::Box | QFrame::Raised);
aFactory.createWidget(aParamsWgt);
ModuleBase_Tools::zeroMargins(aParamsWgt->layout());
- QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
- foreach(ModuleBase_ModelWidget* aWidget, aWidgets) {
+ myWidgets = aFactory.getModelWidgets();
+ foreach(ModuleBase_ModelWidget* aWidget, myWidgets) {
aWidget->setFeature(theParent->feature());
+ connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
+ theParent, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)));
+ connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
+ theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)));
}
aLayout->addWidget(aParamsWgt);
}
emit deleteItem(this);
}
+QList<QWidget*> ModuleBase_FilterItem::getControls() const
+{
+ QList<QWidget*> aWidgetsList;
+ foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
+ QList<QWidget*> aSubList = aWgt->getControls();
+ foreach(QWidget* aSub, aSubList) {
+ aWidgetsList.append(aSub);
+ }
+ }
+ return aWidgetsList;
+}
+
+
//*****************************************************************************
//*****************************************************************************
updateNumberSelected();
myFiltersCombo->setCurrentIndex(0);
myFiltersCombo->removeItem(theIndex);
+
+ enableFocusProcessing();
}
void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem)
{
std::string aFilter = theItem->filter();
+ QList<ModuleBase_ModelWidget*> aWidgets = theItem->widgets();
+ foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
+ aWgt->deactivate();
+ }
myFiltersLayout->removeWidget(theItem);
theItem->deleteLater();
updateSelectBtn();
clearCurrentSelection(true);
updateNumberSelected();
+
+ enableFocusProcessing();
+ myWorkshop->deactivateCurrentSelector();
+ myWorkshop->selectionActivate()->updateSelectionModes();
+ myWorkshop->selectionActivate()->updateSelectionFilters();
+ redisplayFeature();
+}
+
+
+void ModuleBase_WidgetSelectionFilter::redisplayFeature()
+{
+ static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(myFeature, aDispEvent);
+ Events_Loop::loop()->flush(aDispEvent);
}
void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theItem)
if (myPreview.IsNull()) {
myPreview = new AIS_Shape(theShape);
- myPreview->SetDisplayMode(myShowBtn->isChecked()? AIS_Shaded : AIS_WireFrame);
- myPreview->SetColor(Quantity_NOC_YELLOW);
+ //myPreview->SetDisplayMode(myShowBtn->isChecked()? AIS_Shaded : AIS_WireFrame);
+ myPreview->SetDisplayMode(AIS_Shaded);
+ myPreview->SetColor(Quantity_NOC_BLUE1);
myPreview->SetTransparency();
aCtx->Display(myPreview, true);
aCtx->Deactivate(myPreview);
Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
if (theShow) {
- aCtx->SetDisplayMode(myPreview, AIS_Shaded, false);
myListIO.Clear();
aCtx->DisplayedObjects(AIS_KOI_Shape, -1, myListIO);
myListIO.Remove(myPreview);
}
- else {
- aCtx->SetDisplayMode(myPreview, AIS_WireFrame, false);
- }
AIS_ListOfInteractive::const_iterator aIt;
Handle(AIS_Shape) aShapeIO;
for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
}
QList<QWidget*> ModuleBase_WidgetSelectionFilter::getControls() const
{
- return QList<QWidget*>();
+ QList<QWidget*> aWidgets;
+ QList<ModuleBase_FilterItem*> aItems = myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
+ foreach(ModuleBase_FilterItem* aItem, aItems) {
+ QList<QWidget*> aSubList = aItem->getControls();
+ foreach(QWidget* aWgt, aSubList) {
+ aWidgets.append(aWgt);
+ }
+ }
+ return aWidgets;
}
void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate)
foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) {
aSelListAttr->append(aPrs->object(), aPrs->shape());
}
-}
\ No newline at end of file
+}
+
+bool ModuleBase_WidgetSelectionFilter::storeValueCustom()
+{
+ return true;
+}
+
+bool ModuleBase_WidgetSelectionFilter::restoreValueCustom()
+{
+ ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
+ if (aActive)
+ return aActive->restoreValue();
+ return true;
+}
std::string filter() const { return myFilterID; }
+ /// Returns list of widget controls
+ /// \return a control list
+ QList<QWidget*> getControls() const;
+
+ QList<ModuleBase_ModelWidget*> widgets() const {
+ return myWidgets;
+ }
+
signals:
void deleteItem(ModuleBase_FilterItem* theItem);
void reversedItem(ModuleBase_FilterItem* theItem);
std::string myFilterID;
FiltersFeaturePtr mySelection;
QToolButton* myRevBtn;
+ QList<ModuleBase_ModelWidget*> myWidgets;
};
class ModuleBase_WidgetSelectionFilter : public ModuleBase_ModelWidget
protected:
/// Saves the internal parameters to the given feature (not ussed for this widget)
/// \return True in success
- virtual bool storeValueCustom() { return true; }
+ virtual bool storeValueCustom();
/// Restore value from attribute data to the widget's control (not ussed for this widget)
- virtual bool restoreValueCustom() { return true; }
+ virtual bool restoreValueCustom();
private slots:
void onAddFilter(int);
void updateNumberSelected();
void clearCurrentSelection(bool toUpdate = false);
void updatePreview(const TopoDS_Shape& theShape);
+ void redisplayFeature();
private:
ModuleBase_IWorkshop* myWorkshop;
void XGUI_ActiveControlMgr::onSelectorDeactivated()
{
XGUI_ActiveControlSelector* aSelector = qobject_cast<XGUI_ActiveControlSelector*>(sender());
- if (!aSelector || aSelector != myActiveSelector || !myActiveSelector)
+ deactivateSelector(aSelector);
+}
+
+//********************************************************************
+void XGUI_ActiveControlMgr::deactivateSelector(XGUI_ActiveControlSelector* theSelector)
+{
+ if (!theSelector || theSelector != myActiveSelector || !myActiveSelector)
return;
if (myIsBlocked) // we've come here from the same method
activateSelector(NULL);
XGUI_ActiveControlSelector* aSelectorToBeActivated = 0;
- for (int i = 0, aCount = mySelectors.count(); i < aCount; i++)
- {
+ for (int i = 0, aCount = mySelectors.count(); i < aCount; i++) {
if (!mySelectors[i]->needToBeActiated())
continue;
aSelectorToBeActivated = mySelectors[i];
/// \return selector instance
XGUI_ActiveControlSelector* activeSelector() const { return myActiveSelector; }
+ void deactivateSelector(XGUI_ActiveControlSelector* theSelector);
+
protected slots:
/// Deactivates active selector and set the sender selector as active
void onSelectorActivated();
return std::shared_ptr<Config_FeatureMessage>();
#endif
}
+
+void XGUI_ModuleConnector::deactivateCurrentSelector()
+{
+ myWorkshop->deactivateCurrentSelector();
+}
/// \return boolean value
virtual bool hasSHIFTPressed() const;
+ virtual void deactivateCurrentSelector();
+
//! Returns workshop
XGUI_Workshop* workshop() const { return myWorkshop; }
myPanelPage->clearPage();
myActiveWidget = NULL;
emit propertyPanelDeactivated();
- myOperationMgr->workshop()->selectionActivate()->updateSelectionModes();
- myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters();
+ // VSV: It seems that this code is not necessary:
+ // it is called on propertyPanelDeactivated() event
+ //myOperationMgr->workshop()->selectionActivate()->updateSelectionModes();
+ //myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters();
#ifdef DEBUG_ACTIVE_WIDGET
std::cout << "myActiveWidget = NULL" << std::endl;
#endif
disconnect(myObjectBrowser, SIGNAL(sizeChanged()), this, SLOT(onDockSizeChanged()));
}
}
+
+void XGUI_Workshop::deactivateCurrentSelector()
+{
+ myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector());
+}
void updateAutoComputeState();
+ void deactivateCurrentSelector();
+
signals:
/// Emitted when selection happens in Salome viewer
void salomeViewerSelection();