tooltip="Select a face for extrusion"
activate="true"
shape_types="face"
+ object_types="construction"
use_subshapes="true"
/>
<doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="1" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
/// \param theZ the Z projection value
virtual void setViewProjection(double theX, double theY, double theZ) = 0;
+ /// Add selection filter to the viewer
+ virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
+
+ /// Remove selection filter from the viewer
+ virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
+
+ /// Remove all selection filters from the viewer
+ virtual void clearSelectionFilters() = 0;
signals:
void lastViewClosed();
#include <ModelAPI_Session.h>
#include <ModelAPI_Document.h>
+#include <ModelAPI_ResultConstruction.h>
#include <AIS_InteractiveObject.hxx>
#include <AIS_Shape.hxx>
}
return Standard_False;
}
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
+
+
+//TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
+Standard_Boolean ModuleBase_ObjectTypesFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+ Standard_Boolean isOk = ModuleBase_ShapeDocumentFilter::IsOk(theOwner);
+ if (isOk && theOwner->HasSelectable()) {
+ Handle(AIS_InteractiveObject) aAisObj =
+ Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+ if (!aAisObj.IsNull()) {
+ boost::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
+ ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+
+ foreach (QString aType, myTypes) {
+ if (aType.toLower() == "construction") {
+ ResultConstructionPtr aConstr =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+ return (aConstr != NULL);
+ } // ToDo: Process other types of objects
+ }
+ }
+ }
+ return Standard_False;
+}
#ifndef ModuleBase_ViewerFilters_H
#define ModuleBase_ViewerFilters_H
+#include <QStringList>
+
#include <SelectMgr_Filter.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <gp_Pln.hxx>
DEFINE_STANDARD_RTTI(ModuleBase_ShapeDocumentFilter)
-private:
+protected:
ModuleBase_IWorkshop* myWorkshop;
};
gp_Pln myPlane;
};
+
+/**
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select only object of requested type
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
+class ModuleBase_ObjectTypesFilter: public ModuleBase_ShapeDocumentFilter
+{
+public:
+ Standard_EXPORT ModuleBase_ObjectTypesFilter(ModuleBase_IWorkshop* theWorkshop, const QStringList& theTypes):
+ ModuleBase_ShapeDocumentFilter(theWorkshop), myTypes(theTypes) {}
+
+ Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+ DEFINE_STANDARD_RTTI(ModuleBase_ObjectTypesFilter)
+private:
+ QStringList myTypes;
+};
+
#endif
\ No newline at end of file
#include <ModuleBase_Definitions.h>
#include <ModuleBase_ISelection.h>
#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IViewer.h>
#include <ModuleBase_Tools.h>
#include <ModuleBase_WidgetValueFeature.h>
+
#include <Config_WidgetAPI.h>
#include <Events_Loop.h>
#include <Events_Message.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
+#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_Session.h>
std::string aTypes = theData->getProperty("shape_types");
myShapeTypes = QString(aTypes.c_str()).split(' ');
+ std::string aObjTypes = theData->getProperty("object_types");
+ myObjectTypes = QString(aObjTypes.c_str()).split(' ');
+
myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false);
}
if (!aShape)
return;
+ /// Check that object has acceptable type
+ if (!acceptObjectType(aObject))
+ return;
+
// Get sub-shapes from local selection
if (myUseSubShapes) {
NCollection_List<TopoDS_Shape> aShapeList;
// Check that the selection corresponds to selection type
if (myUseSubShapes) {
- if (!isAccepted(aShape))
+ if (!acceptSubShape(aShape))
return;
} else {
- if (!isAccepted(aObject))
+ if (!acceptObjectShape(aObject))
return;
}
setObject(aObject, aShape);
}
//********************************************************************
-bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
+bool ModuleBase_WidgetShapeSelector::acceptObjectShape(const ObjectPtr theResult) const
{
ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theResult);
}
//********************************************************************
-bool ModuleBase_WidgetShapeSelector::isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const
+bool ModuleBase_WidgetShapeSelector::acceptSubShape(boost::shared_ptr<GeomAPI_Shape> theShape) const
{
TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
foreach (QString aType, myShapeTypes) {
return false;
}
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::acceptObjectType(const ObjectPtr theObject) const
+{
+ // Definition of types is not obligatory. If types are not defined then
+ // it means that accepted any type
+ if (myObjectTypes.isEmpty())
+ return true;
+
+ foreach (QString aType, myObjectTypes) {
+ if (aType.toLower() == "construction") {
+ ResultConstructionPtr aConstr =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theObject);
+ return (aConstr != NULL);
+ } // ToDo: Process other types of objects
+ }
+ // Object type is defined but not found
+ return false;
+}
+
+
//********************************************************************
void ModuleBase_WidgetShapeSelector::updateSelectionName()
{
if (myIsActive) {
connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
if (myUseSubShapes) {
+
QIntList aList;
foreach (QString aType, myShapeTypes)
aList.append(shapeType(aType));
myWorkshop->activateSubShapesSelection(aList);
+ if (!myObjectTypes.isEmpty()) {
+ myObjTypeFilter = new ModuleBase_ObjectTypesFilter(myWorkshop, myObjectTypes);
+ myWorkshop->viewer()->clearSelectionFilters();
+ myWorkshop->viewer()->addSelectionFilter(myObjTypeFilter);
+ }
}
} else {
disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- if (myUseSubShapes)
+ if (myUseSubShapes) {
+ if (!myObjTypeFilter.IsNull()) {
+ myWorkshop->viewer()->removeSelectionFilter(myObjTypeFilter);
+ myObjTypeFilter.Nullify();
+ }
myWorkshop->deactivateSubShapesSelection();
+ }
}
}
dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
if (aFeatureValue && aFeatureValue->object()) {
ObjectPtr aObject = aFeatureValue->object();
- if (isAccepted(aObject)) {
+ if (acceptObjectShape(aObject)) {
setObject(aObject);
return true;
}
#include "ModuleBase.h"
#include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_ViewerFilters.h"
#include <ModelAPI_Object.h>
#include <GeomAPI_Shape.h>
protected:
bool eventFilter(QObject* theObj, QEvent* theEvent);
-private:
void updateSelectionName();
void raisePanel() const;
- bool isAccepted(const ObjectPtr theObject) const;
- bool isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const;
+
+ /// Returns true if Sape of given object corresponds to requested shape type
+ /// This method is called only in non sub-shapes selection mode
+ virtual bool acceptObjectShape(const ObjectPtr theObject) const;
+
+ /// Returns true if selected shape corresponds to requested shape types
+ /// This method is called only in sub-shapes selection mode
+ virtual bool acceptSubShape(boost::shared_ptr<GeomAPI_Shape> theShape) const;
+
+ /// Returns true if selected object corresponds to requested Object type
+ /// Thid method is used in any selection mode
+ virtual bool acceptObjectType(const ObjectPtr theObject) const;
+
// Set the given object as a value of the widget
void setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape = boost::shared_ptr<GeomAPI_Shape>());
+ //----------- Class members -------------
QWidget* myContainer;
QLabel* myLabel;
QLineEdit* myTextLine;
- //QToolButton* myActivateBtn;
ModuleBase_IWorkshop* myWorkshop;
boost::shared_ptr<GeomAPI_Shape> myShape;
QStringList myShapeTypes;
+ QStringList myObjectTypes;
/// If true then local selector has to be activated in context
bool myUseSubShapes;
QPalette myInactivePalet;
bool myIsActive;
+
+ Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;
};
#endif
aView3d->SetZSize(0.);
}
}
-}
\ No newline at end of file
+}
+
+//***************************************
+void NewGeom_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (!aContext.IsNull()) {
+ aContext->AddFilter(theFilter);
+ }
+}
+
+//***************************************
+void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (!aContext.IsNull()) {
+ aContext->RemoveFilter(theFilter);
+ }
+}
+
+//***************************************
+void NewGeom_SalomeViewer::clearSelectionFilters()
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (!aContext.IsNull()) {
+ aContext->RemoveFilters();
+ }
+}
void setSelector(NewGeom_OCCSelector* theSel);
+ /// Add selection filter to the viewer
+ virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+ /// Remove selection filter from the viewer
+ virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+ /// Remove all selection filters from the viewer
+ virtual void clearSelectionFilters();
+
NewGeom_OCCSelector* selector() const
{
return mySelector;
return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
}
}
+
+//***************************************
+void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (!aContext.IsNull()) {
+ aContext->AddFilter(theFilter);
+ }
+}
+
+//***************************************
+void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (!aContext.IsNull()) {
+ aContext->RemoveFilter(theFilter);
+ }
+}
+
+//***************************************
+void XGUI_ViewerProxy::clearSelectionFilters()
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (!aContext.IsNull()) {
+ aContext->RemoveFilters();
+ }
+}
/// Connects to a viewer according to current environment
void connectToViewer();
+ /// Add selection filter to the viewer
+ virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+ /// Remove selection filter from the viewer
+ virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+ /// Remove all selection filters from the viewer
+ virtual void clearSelectionFilters();
+
private slots:
void onMousePress(XGUI_ViewWindow*, QMouseEvent*);
void onMouseRelease(XGUI_ViewWindow*, QMouseEvent*);