#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeBoolean.h>
#include <GeomAlgoAPI_Extrusion.h>
void FeaturesPlugin_Extrusion::initAttributes()
{
- data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type());
+ data()->addAttribute(FeaturesPlugin_Extrusion::LIST_ID(), ModelAPI_AttributeSelectionList::type());
data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
}
void FeaturesPlugin_Extrusion::execute()
{
- std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = std::dynamic_pointer_cast<
- ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
+ std::shared_ptr<ModelAPI_AttributeSelectionList> aFaceRefs = std::dynamic_pointer_cast<
+ ModelAPI_AttributeSelectionList>(data()->attribute(FeaturesPlugin_Extrusion::LIST_ID()));
+ if (aFaceRefs.get() == NULL || aFaceRefs->size() == 0) {
+ clearResult();
+ return;
+ }
+ std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(0);
if (!aFaceRef)
return;
std::shared_ptr<GeomAPI_Shape> aContext;
ResultPtr aContextRes = aFaceRef->context();
- if (aContextRes) {
- if (aContextRes->groupName() == ModelAPI_ResultBody::group())
- aContext = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
- else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
- aContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
+ if (aContextRes && aContextRes->groupName() == ModelAPI_ResultConstruction::group()) {
+ aContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
}
if (!aContext) {
static const std::string aContextError = "The selection context is bad";
}
}
+
+//============================================================================
+void FeaturesPlugin_Extrusion::clearResult()
+{
+ std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
+ std::shared_ptr<GeomAPI_Shape> anEmptyShape(new GeomAPI_Shape);
+ aResultBody->store(anEmptyShape);
+ setResult(aResultBody);
+}
\ No newline at end of file
static const std::string MY_FACE_ID("extrusion_face");
return MY_FACE_ID;
}
+ /// attribute name of references sketch entities list, it should contain a sketch result or
+ /// a pair a sketch result to sketch face
+ inline static const std::string& LIST_ID()
+ {
+ static const std::string MY_GROUP_LIST_ID("group_list");
+ return MY_GROUP_LIST_ID;
+ }
+
/// attribute name of extrusion size
inline static const std::string& SIZE_ID()
{
void LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, std::shared_ptr<ModelAPI_ResultBody> theResultBody,
std::shared_ptr<GeomAPI_Shape> theBasis,
std::shared_ptr<GeomAPI_Shape> theContext);
+
+ /// Set an empty shape to the result of extrusion
+ void clearResult();
};
#endif
<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<source>
- <shape_selector id="extrusion_face"
- label="Select a face"
+ <multi_selector id="group_list"
+ label="Select a sketch face"
icon=":icons/sketch.png"
- tooltip="Select a face"
- activate="true"
- shape_types="face"
- object_types="construction">
+ tooltip="Select a sketch face"
+ type_choice="Faces">
<validator id="PartSet_SketchValidator"/>
- </shape_selector>
+ <selection_filter id="SketchEntityFilter"/>
+ </multi_selector>
<doublevalue
id="extrusion_size"
label="Size"
ModuleBase_PageBase.h
ModuleBase_PageWidget.h
ModuleBase_PageGroupBox.h
+ ModuleBase_WidgetValidated.h
)
SET(PROJECT_SOURCES
ModuleBase_PageBase.cpp
ModuleBase_PageWidget.cpp
ModuleBase_PageGroupBox.cpp
+ ModuleBase_WidgetValidated.cpp
)
SET(PROJECT_LIBRARIES
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
const std::string& theParentId)
- : ModuleBase_ModelWidget(theParent, theData, theParentId),
+ : ModuleBase_WidgetValidated(theParent, theData, theParentId),
myWorkshop(theWorkshop), myIsActive(false)
{
QGridLayout* aMainLay = new QGridLayout(this);
myTypeCombo = new QComboBox(this);
// There is no sence to paramerize list of types while we can not parametrize selection mode
- QString aTypesStr("Vertices Edges Faces Solids");
+
+ std::string aPropertyTypes = theData->getProperty("type_choice");
+ QString aTypesStr = aPropertyTypes.c_str();
QStringList aShapeTypes = aTypesStr.split(' ');
+
myTypeCombo->addItems(aShapeTypes);
aMainLay->addWidget(myTypeCombo, 0, 1);
+ // if the xml definition contains one type, the controls to select a type should not be shown
+ if (aShapeTypes.size() == 1) {
+ aTypeLabel->setVisible(false);
+ myTypeCombo->setVisible(false);
+ }
QLabel* aListLabel = new QLabel(tr("Selected objects:"), this);
- aMainLay->addWidget(aListLabel, 1, 0, 1, -1);
+ aMainLay->addWidget(aListLabel, 1, 0);
+ // if the xml definition contains one type, an information label should be shown near to the latest
+ if (aShapeTypes.size() == 1) {
+ QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+ QLabel* aSelectedLabel = new QLabel(aLabelText, this);
+ if (!aLabelIcon.isEmpty())
+ aSelectedLabel->setPixmap(QPixmap(aLabelIcon));
+ aMainLay->addWidget(aSelectedLabel, 1, 1);
+ aMainLay->setColumnStretch(2, 1);
+ }
myListControl = new QListWidget(this);
aMainLay->addWidget(myListControl, 2, 0, 2, -1);
myListControl->addAction(myCopyAction);
myListControl->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(myListControl, SIGNAL(itemSelectionChanged()), SLOT(onListSelection()));
-
- activateSelection(true);
}
ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
{
- activateSelection(false);
+ myIsActive = false;
+ activateShapeSelection();
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::activateCustom()
+{
+ ModuleBase_IViewer* aViewer = myWorkshop->viewer();
+ connect(myWorkshop, SIGNAL(selectionChanged()),
+ this, SLOT(onSelectionChanged()),
+ Qt::UniqueConnection);
+
+ myIsActive = true;
+ activateShapeSelection();
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::deactivate()
+{
+ disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ myIsActive = false;
+ activateShapeSelection();
}
//********************************************************************
return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
}
-//********************************************************************
-void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate)
-{
- myIsActive = toActivate;
- if (myIsActive) {
- connect(myWorkshop, SIGNAL(selectionChanged()),
- this, SLOT(onSelectionChanged()),
- Qt::UniqueConnection);
- activateShapeSelection();
- } else {
- disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- myWorkshop->deactivateSubShapesSelection();
-
- myWorkshop->viewer()->removeSelectionFilter(myEdgesTypeFilter);
- }
-}
-
//********************************************************************
void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
{
emit valuesChanged();
}
-//********************************************************************
-void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
- NCollection_List<TopoDS_Shape>& theResult)
-{
- if(myTypeCombo->count() == 0 || theShapesToFilter.IsEmpty())
- return;
- TopAbs_ShapeEnum aReferenceType =
- ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
- NCollection_List<TopoDS_Shape>::Iterator anIter(theShapesToFilter);
- for (; anIter.More(); anIter.Next()) {
- TopoDS_Shape aShape = anIter.Value();
- if (aShape.IsNull() || aShape.ShapeType() != aReferenceType)
- continue;
- theResult.Append(aShape);
- }
-}
-
//********************************************************************
void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
{
aShapeTypeName = myTypeCombo->itemText(idx);
TopAbs_ShapeEnum aRefType = ModuleBase_WidgetShapeSelector::shapeType(aShapeTypeName);
if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
- activateSelection(false);
+ myIsActive = false;
+ activateShapeSelection();
bool isBlocked = myTypeCombo->blockSignals(true);
myTypeCombo->setCurrentIndex(idx);
+ myIsActive = true;
myTypeCombo->blockSignals(isBlocked);
- activateSelection(true);
+ activateShapeSelection();
break;
}
}
void ModuleBase_WidgetMultiSelector::activateShapeSelection()
{
- QString aNewType = myTypeCombo->currentText();
- QIntList aList;
- aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
- myWorkshop->activateSubShapesSelection(aList);
-
- // it is necessary to filter the selected edges to be non-degenerated
- // it is not possible to build naming name for such edges
- if (aNewType == "Edges") {
- myEdgesTypeFilter = new ModuleBase_FilterNoDegeneratedEdge();
- ModuleBase_IViewer* aViewer = myWorkshop->viewer();
- aViewer->addSelectionFilter(myEdgesTypeFilter);
- }
- else {
- myWorkshop->viewer()->removeSelectionFilter(myEdgesTypeFilter);
+ ModuleBase_IViewer* aViewer = myWorkshop->viewer();
+
+ if (myIsActive) {
+ QString aNewType = myTypeCombo->currentText();
+ QIntList aList;
+ aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
+ myWorkshop->activateSubShapesSelection(aList);
+
+ // it is necessary to filter the selected edges to be non-degenerated
+ // it is not possible to build naming name for such edges
+ if (aNewType == "Edges") {
+ myEdgesTypeFilter = new ModuleBase_FilterNoDegeneratedEdge();
+ aViewer->addSelectionFilter(myEdgesTypeFilter);
+ }
+ else {
+ aViewer->removeSelectionFilter(myEdgesTypeFilter);
+ }
+
+ } else {
+ myWorkshop->deactivateSubShapesSelection();
+ aViewer->removeSelectionFilter(myEdgesTypeFilter);
}
+
+ activateFilters(myWorkshop, myIsActive);
}
//********************************************************************
#define MODULEBASE_WIDGETMULTISELECTOR_H_
#include <ModuleBase.h>
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_WidgetValidated.h>
#include <ModuleBase_FilterNoDegeneratedEdge.h>
#include <GeomAPI_Shape.h>
* - tooltip - a tooltip for the widget
* - type_choice - list of expected shape types.
*/
-class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_ModelWidget
+class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetValidated
{
Q_OBJECT
public:
virtual bool eventFilter(QObject* , QEvent* );
- public slots:
- /// Activate or deactivate selection
- void activateSelection(bool toActivate);
+ /// The methiod called when widget is deactivated
+ virtual void deactivate();
+ public slots:
/// Slot is called on selection type changed
void onSelectionTypeChanged();
void onListSelection();
protected:
+ /// The methiod called when widget is activated
+ virtual void activateCustom();
+
/// Saves the internal parameters to the given feature
/// \return True in success
virtual bool storeValueCustom() const;
- /// Provide filtering of selected shapes
- /// \param theShapesToFilter source list of shapes
- /// \param theResult result list of shapes
- void filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
- NCollection_List<TopoDS_Shape>& theResult);
-
/// Set current shape type for selection
void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
const std::string& theParentId)
- : ModuleBase_ModelWidget(theParent, theData, theParentId),
+ : ModuleBase_WidgetValidated(theParent, theData, theParentId),
myWorkshop(theWorkshop), myIsActive(false)
{
QFormLayout* aLayout = new QFormLayout(this);
std::string aTypes = theData->getProperty("shape_types");
myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts);
-
- std::string aObjTypes = theData->getProperty("object_types");
- myObjectTypes = QString(aObjTypes.c_str()).split(' ', QString::SkipEmptyParts);
}
//********************************************************************
if (!aShape)
return false;
- /// Check that object has acceptable type
- if (!acceptObjectType(aObject))
- return false;
-
// Get sub-shapes from local selection
if (!theValue.shape().IsNull()) {
aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
Handle(SelectMgr_EntityOwner) anOwner = theValue.owner();
if (!anOwner.IsNull()) {
SelectMgr_ListOfFilter aFilters;
- selectionFilters(aFilters);
+ selectionFilters(myWorkshop, aFilters);
SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
for (; aIt.More(); aIt.Next()) {
const Handle(SelectMgr_Filter)& aFilter = aIt.Value();
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 =
- std::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()
{
return;
myIsActive = toActivate;
updateSelectionName();
- ModuleBase_IViewer* aViewer = myWorkshop->viewer();
if (myIsActive) {
- connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
QIntList aList;
foreach (QString aType, myShapeTypes) {
aList.append(shapeType(aType));
}
myWorkshop->activateSubShapesSelection(aList);
} else {
- disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
myWorkshop->deactivateSubShapesSelection();
}
- // the initial code is moved here in order to clear filters, it is possible, that it is excessive and
- // is performed outside
- if (myIsActive && !myObjectTypes.isEmpty()) {
- aViewer->clearSelectionFilters();
- }
- SelectMgr_ListOfFilter aFilters;
- selectionFilters(aFilters);
- SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
- for (; aIt.More(); aIt.Next()) {
- const Handle(SelectMgr_Filter)& aSelFilter = aIt.Value();
- if (myIsActive)
- aViewer->addSelectionFilter(aSelFilter);
- else
- aViewer->removeSelectionFilter(aSelFilter);
- }
- // the internal filter should be removed by the widget deactivation, it is done historically
- if (!myIsActive && !myObjTypeFilter.IsNull()) {
- myObjTypeFilter.Nullify();
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::selectionFilters(SelectMgr_ListOfFilter& theFilters)
-{
- if (!myObjectTypes.isEmpty() && myObjTypeFilter.IsNull()) {
- myObjTypeFilter = new ModuleBase_ObjectTypesFilter(myWorkshop, myObjectTypes);
- }
- if (!myObjTypeFilter.IsNull())
- theFilters.Append(myObjTypeFilter);
-
- // apply filters loaded from the XML definition of the widget
- ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters();
- SelectMgr_ListOfFilter aFilters;
- aFactory->filters(parentID(), attributeID(), aFilters);
- SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
- for (; aIt.More(); aIt.Next()) {
- Handle(SelectMgr_Filter) aSelFilter = aIt.Value();
- if (aSelFilter.IsNull())
- continue;
-
- theFilters.Append(aSelFilter);
- }
+ activateFilters(myWorkshop, myIsActive);
}
//********************************************************************
//********************************************************************
void ModuleBase_WidgetShapeSelector::activateCustom()
{
+ connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
activateSelection(true);
}
void ModuleBase_WidgetShapeSelector::deactivate()
{
activateSelection(false);
+ disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
}
//********************************************************************
bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
{
+ bool isValid = ModuleBase_WidgetValidated::isValid(theObj, theShape);
+ if (!isValid)
+ return false;
+
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
std::list<ModelAPI_Validator*> aValidators;
std::list<std::list<std::string> > anArguments;
aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
- // Check the type of selected object
- std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
- bool isValid = true;
- for (; aValidator != aValidators.end(); aValidator++) {
- const ModelAPI_ResultValidator* aResValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
- if (aResValidator) {
- isValid = false;
- if (aResValidator->isValid(theObj)) {
- isValid = true;
- break;
- }
- }
- }
- if (!isValid)
- return false;
-
// Check the acceptability of the object as attribute
- aValidator = aValidators.begin();
+ std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
for (; aValidator != aValidators.end(); aValidator++, aArgs++) {
const ModelAPI_RefAttrValidator* aAttrValidator =
#define ModuleBase_WidgetShapeSelector_H
#include "ModuleBase.h"
-#include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_WidgetValidated.h"
#include "ModuleBase_ViewerFilters.h"
#include <ModelAPI_Object.h>
#include <GeomAPI_Shape.h>
#include <TopAbs_ShapeEnum.hxx>
-#include <SelectMgr_ListOfFilter.hxx>
#include <QStringList>
* which corresponds to ModelAPI_ResultConstruction object type
* - concealment - hide or not hide selected object after operation
*/
-class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_ModelWidget
+class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetValidated
{
Q_OBJECT
public:
/// \param theShape a shape
virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
- /// Returns true if selected object corresponds to requested Object type
- /// Thid method is used in any selection mode
- /// \param theObject an object
- virtual bool acceptObjectType(const ObjectPtr theObject) const;
-
-
// Set the given object as a value of the widget
/// \param theObj an object
/// \param theShape a shape
/// Clear attribute
void clearAttribute();
- /// Fills the given list with all widget filters. It can be used by activation widget for the viewer
- /// or by checking the selection parameter in addition to check validity of the selection argument
- /// It creates an object type filter if it has not been created yet and save it in the class field
- /// \param theFilters a list of filter
- void selectionFilters(SelectMgr_ListOfFilter& theFilters);
-
//----------- Class members -------------
protected:
/// Label of the widget
/// List of accepting shapes types
QStringList myShapeTypes;
- /// List of accepting object types
- QStringList myObjectTypes;
-
/// Active/inactive flag
bool myIsActive;
-
- /// Filter by objects types
- Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;
};
#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include <ModuleBase_WidgetValidated.h>
+#include <ModuleBase_FilterFactory.h>
+#include <ModuleBase_IViewer.h>
+#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_ResultValidator.h>
+
+#include <QWidget>
+
+ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+ : ModuleBase_ModelWidget(theParent, theData, theParentId)
+{
+}
+
+ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
+{
+}
+
+//********************************************************************
+bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape) const
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ std::list<ModelAPI_Validator*> aValidators;
+ std::list<std::list<std::string> > anArguments;
+ aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
+
+ // Check the type of selected object
+ std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
+ bool isValid = true;
+ for (; aValidator != aValidators.end(); aValidator++) {
+ const ModelAPI_ResultValidator* aResValidator =
+ dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
+ if (aResValidator) {
+ isValid = false;
+ if (aResValidator->isValid(theObj)) {
+ isValid = true;
+ break;
+ }
+ }
+ }
+ return isValid;
+}
+
+void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
+ const bool toActivate) const
+{
+ ModuleBase_IViewer* aViewer = theWorkshop->viewer();
+
+ // apply filters loaded from the XML definition of the widget
+ ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
+ SelectMgr_ListOfFilter aFactoryFilters;
+ aFactory->filters(parentID(), attributeID(), aFactoryFilters);
+ SelectMgr_ListIteratorOfListOfFilter aFactoryIt(aFactoryFilters);
+ for (; aFactoryIt.More(); aFactoryIt.Next()) {
+ Handle(SelectMgr_Filter) aSelFilter = aFactoryIt.Value();
+ if (aSelFilter.IsNull())
+ continue;
+ if (toActivate)
+ aViewer->addSelectionFilter(aSelFilter);
+ else
+ aViewer->removeSelectionFilter(aSelFilter);
+ }
+}
+
+void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop,
+ SelectMgr_ListOfFilter& theFilters) const
+{
+ ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
+ SelectMgr_ListOfFilter aFilters;
+ aFactory->filters(parentID(), attributeID(), aFilters);
+ SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
+ for (; aIt.More(); aIt.Next()) {
+ Handle(SelectMgr_Filter) aSelFilter = aIt.Value();
+ if (aSelFilter.IsNull())
+ continue;
+
+ theFilters.Append(aSelFilter);
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_WidgetValidated.h
+// Created: 12 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+
+#ifndef MODULEBASE_WIDGETVALIDATED_H_
+#define MODULEBASE_WIDGETVALIDATED_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+#include <GeomAPI_Shape.h>
+#include <ModelAPI_Object.h>
+
+#include <SelectMgr_ListOfFilter.hxx>
+
+class QWidget;
+class ModuleBase_IWorkshop;
+class Config_WidgetAPI;
+
+/**
+* \ingroup GUI
+* Implementation of widget with validators and filters processing.
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+ public:
+ /// Constructor
+ /// \param theParent the parent object
+ /// \param theData the widget configuation. The attribute of the model widget is obtained from
+ /// \param theParentId is Id of a parent of the current attribute
+ ModuleBase_WidgetValidated(QWidget* theParent,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId);
+ virtual ~ModuleBase_WidgetValidated();
+
+protected:
+ /// Check the selected with validators if installed
+ /// \param theObj the object for checking
+ /// \param theShape the shape for checking
+ virtual bool isValid(ObjectPtr theObj, GeomShapePtr theShape) 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(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const;
+
+ /// Fills the given list with all widget filters.
+ /// \param theWorkshop an active workshop
+ /// \param theFilters a list of filters
+ void selectionFilters(ModuleBase_IWorkshop* theWorkshop,
+ SelectMgr_ListOfFilter& theFilters) const;
+};
+
+#endif /* MODULEBASE_WIDGETVALIDATED_H_ */
PartSet_WidgetPoint2dDistance.h
PartSet_WidgetShapeSelector.h
PartSet_Filters.h
+ PartSet_FilterSketchEntity.h
PartSet_SketcherMgr.h
)
PartSet_WidgetPoint2dDistance.cpp
PartSet_WidgetShapeSelector.cpp
PartSet_Filters.cpp
+ PartSet_FilterSketchEntity.cpp
PartSet_SketcherMgr.cpp
)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: PartSet_FilterSketchEntity.cpp
+// Created: 13 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include "PartSet_FilterSketchEntity.h"
+
+#include <ModuleBase_IWorkshop.h>
+
+#include <ModelAPI_Feature.h>
+#include <FeaturesPlugin_Group.h>
+
+#include <SketchPlugin_Sketch.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+
+
+IMPLEMENT_STANDARD_HANDLE(PartSet_FilterSketchEntity, ModuleBase_ShapeDocumentFilter);
+IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterSketchEntity, ModuleBase_ShapeDocumentFilter);
+
+Standard_Boolean PartSet_FilterSketchEntity::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+ if (ModuleBase_ShapeDocumentFilter::IsOk(theOwner)) {
+ 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->getKind() == SketchPlugin_Sketch::ID())
+ return Standard_True;
+ }
+ }
+ }
+ }
+ return Standard_False;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: PartSet_FilterSketchEntity.h
+// Created: 13 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_FilterSketchEntity_H
+#define PartSet_FilterSketchEntity_H
+
+#include <ModuleBase_ViewerFilters.h>
+
+/**
+* \class PartSet_FilterSketchEntity
+* \ingroup Modules
+* A class which filters groups object in addition to documents (see issue #310)
+*/
+DEFINE_STANDARD_HANDLE(PartSet_FilterSketchEntity, ModuleBase_ShapeDocumentFilter);
+class PartSet_FilterSketchEntity: public ModuleBase_ShapeDocumentFilter
+{
+public:
+ /// Constructor
+ /// \param theWorkshop a pointer to workshop
+ PartSet_FilterSketchEntity(ModuleBase_IWorkshop* theWorkshop)
+ : ModuleBase_ShapeDocumentFilter(theWorkshop) {}
+
+ /// Returns True if selected presentation can be selected
+ /// \param theOwner an owner of the persentation
+ Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+ DEFINE_STANDARD_RTTI(PartSet_FilterSketchEntity)
+};
+
+#endif
\ No newline at end of file
#include <ModuleBase_FilterMulti.h>
#include <ModuleBase_FilterCustom.h>
#include <ModuleBase_FilterNoConsructionSubShapes.h>
+#include <PartSet_FilterSketchEntity.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Events.h>
Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
aFactory->registerFilter("NoConstructionSubShapesFilter",
new ModuleBase_FilterCustom(aSelectFilter));
+ aSelectFilter = new PartSet_FilterSketchEntity(workshop());
+ aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
}
void PartSet_Module::registerProperties()
//********************************************************************
bool PartSet_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
{
+ bool isValid = ModuleBase_WidgetValidated::isValid(theObj, theShape);
+ if (!isValid)
+ return false;
+
// the method is redefined to analize the selected shape in validators
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
std::list<std::list<std::string> > anArguments;
aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
- // Check the type of selected object
- std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
- bool isValid = true;
- for (; aValidator != aValidators.end(); aValidator++) {
- const ModelAPI_ResultValidator* aResValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
- if (aResValidator) {
- isValid = false;
- if (aResValidator->isValid(theObj)) {
- isValid = true;
- break;
- }
- }
- }
- if (!isValid)
- return false;
-
// Check the acceptability of the object and shape as validator attribute
AttributePtr aPntAttr;
DataPtr aData = myFeature->data();
}
}
// Check the acceptability of the object as attribute
- aValidator = aValidators.begin();
+ std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
for (; aValidator != aValidators.end(); aValidator++, aArgs++) {
const ModelAPI_RefAttrValidator* aAttrValidator =