#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;
}