]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Multi-selection widget to be used in the extrusion feature.
authornds <natalia.donis@opencascade.com>
Fri, 13 Mar 2015 08:29:19 +0000 (11:29 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 13 Mar 2015 08:29:19 +0000 (11:29 +0300)
15 files changed:
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.h
src/FeaturesPlugin/extrusion_widget.xml
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/ModuleBase/ModuleBase_WidgetValidated.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetValidated.h [new file with mode: 0644]
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_FilterSketchEntity.cpp [new file with mode: 0644]
src/PartSet/PartSet_FilterSketchEntity.h [new file with mode: 0644]
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_WidgetShapeSelector.cpp

index 265ba65761ebb4871d0d9eea4dfe68ca8a2b9cd4..d3473fa850734c1f68185faee75bfb61447ed88f 100644 (file)
@@ -12,6 +12,7 @@
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeBoolean.h>
 #include <GeomAlgoAPI_Extrusion.h>
 
@@ -27,15 +28,20 @@ FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
 
 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;
 
@@ -46,11 +52,8 @@ void FeaturesPlugin_Extrusion::execute()
 
   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";
@@ -131,3 +134,12 @@ void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature,
   }
   
 }
+
+//============================================================================
+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
index bbc636c9251fdda8b8d7a64f0f654dfe6dfbd92a..87f33180d46f1b46c11bcc91ef32654818610523 100644 (file)
@@ -36,6 +36,14 @@ class FeaturesPlugin_Extrusion : public ModelAPI_Feature
     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()
   {
@@ -69,6 +77,9 @@ private:
   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
index 6f2ea7d180a200a40a376c189a38778ea59fd114..9e385774290d2251122294300fd83cca80c01ca0 100644 (file)
@@ -1,15 +1,14 @@
 <!-- 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"
index ea3235e1982f7c6642c5d1f815b5bcbda724631c..9b834e9ad5e7c9d02f0c6e6344c90e2c5117db9a 100644 (file)
@@ -48,6 +48,7 @@ SET(PROJECT_HEADERS
        ModuleBase_PageBase.h
        ModuleBase_PageWidget.h 
        ModuleBase_PageGroupBox.h
+       ModuleBase_WidgetValidated.h
 )
 
 SET(PROJECT_SOURCES
@@ -86,6 +87,7 @@ SET(PROJECT_SOURCES
        ModuleBase_PageBase.cpp
        ModuleBase_PageWidget.cpp
        ModuleBase_PageGroupBox.cpp
+       ModuleBase_WidgetValidated.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 18ae5e6a08542b7db828724375026a568382089f..cef4dbf0de4876394986ff80beb45be04221bd62 100644 (file)
@@ -38,7 +38,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
                                                                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);
@@ -49,13 +49,31 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
 
   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);
@@ -72,13 +90,32 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   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();
 }
 
 //********************************************************************
@@ -150,23 +187,6 @@ bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEve
   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()
 {
@@ -213,23 +233,6 @@ void ModuleBase_WidgetMultiSelector::onSelectionChanged()
   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)
 {
@@ -239,11 +242,13 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum
     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;
     }
   }
@@ -251,21 +256,30 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum
 
 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);
 }
 
 //********************************************************************
index 660fe06983aaa8cbb572d5b53c065e63003ee896..bdb1a46eddf75f4409a19db057d769d27cb9b214 100644 (file)
@@ -11,7 +11,7 @@
 #define MODULEBASE_WIDGETMULTISELECTOR_H_
 
 #include <ModuleBase.h>
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_WidgetValidated.h>
 #include <ModuleBase_FilterNoDegeneratedEdge.h>
 
 #include <GeomAPI_Shape.h>
@@ -47,7 +47,7 @@ class QAction;
 * - 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:
@@ -70,10 +70,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model
 
   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();
 
@@ -88,16 +88,13 @@ protected slots:
   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);
 
index 5514a06e34dbfbff28dbd0468317c85b4fad57f3..3d376aacea74c20b135de20aae5fbdfdc5943044 100644 (file)
@@ -93,7 +93,7 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen
                                                      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);
@@ -116,9 +116,6 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen
 
   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);
 }
 
 //********************************************************************
@@ -266,10 +263,6 @@ bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue)
   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());
@@ -286,7 +279,7 @@ bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue)
   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();
@@ -354,26 +347,6 @@ bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptr<GeomAPI_Shap
   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()
 {
@@ -406,62 +379,18 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
     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);
 }
 
 //********************************************************************
@@ -484,6 +413,7 @@ void ModuleBase_WidgetShapeSelector::raisePanel() const
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::activateCustom()
 {
+  connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
   activateSelection(true);
 }
 
@@ -491,36 +421,24 @@ void ModuleBase_WidgetShapeSelector::activateCustom()
 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 =
index 98a1e4c34c02c35e8e5aee81ef10e0feb989a7d7..f4be3ab69ffa2499beb27462788a3bc7ea937a27 100644 (file)
@@ -8,14 +8,13 @@
 #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>
 
@@ -52,7 +51,7 @@ class ModuleBase_IWorkshop;
 *        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:
@@ -124,12 +123,6 @@ Q_OBJECT
   /// \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
@@ -143,12 +136,6 @@ Q_OBJECT
   /// 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
@@ -169,14 +156,8 @@ Q_OBJECT
   /// 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
diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp
new file mode 100644 (file)
index 0000000..a6f05af
--- /dev/null
@@ -0,0 +1,86 @@
+// 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);
+  }
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h
new file mode 100644 (file)
index 0000000..014668e
--- /dev/null
@@ -0,0 +1,58 @@
+// 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_ */
index 60388bb2b90d155ed946041041759df8116c481e..326fb1c617c8d63001749973073fd1fca40ed34d 100644 (file)
@@ -16,6 +16,7 @@ SET(PROJECT_HEADERS
        PartSet_WidgetPoint2dDistance.h
        PartSet_WidgetShapeSelector.h
        PartSet_Filters.h
+       PartSet_FilterSketchEntity.h
        PartSet_SketcherMgr.h
 )
 
@@ -29,6 +30,7 @@ SET(PROJECT_SOURCES
        PartSet_WidgetPoint2dDistance.cpp
        PartSet_WidgetShapeSelector.cpp
        PartSet_Filters.cpp
+       PartSet_FilterSketchEntity.cpp
        PartSet_SketcherMgr.cpp
 )
 
diff --git a/src/PartSet/PartSet_FilterSketchEntity.cpp b/src/PartSet/PartSet_FilterSketchEntity.cpp
new file mode 100644 (file)
index 0000000..04b5f4f
--- /dev/null
@@ -0,0 +1,43 @@
+// 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;
+}
diff --git a/src/PartSet/PartSet_FilterSketchEntity.h b/src/PartSet/PartSet_FilterSketchEntity.h
new file mode 100644 (file)
index 0000000..62849e6
--- /dev/null
@@ -0,0 +1,33 @@
+// 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
index 08191e8d311d101e083164a93a15ba36b4b1b420..ebc5db7324ace9de80c416d0630dfa7cdd8fa9d5 100644 (file)
@@ -21,6 +21,7 @@
 #include <ModuleBase_FilterMulti.h>
 #include <ModuleBase_FilterCustom.h>
 #include <ModuleBase_FilterNoConsructionSubShapes.h>
+#include <PartSet_FilterSketchEntity.h>
 
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
@@ -139,6 +140,8 @@ void PartSet_Module::registerFilters()
   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()
index bd9e1ce81cbbcc4d253a54955adeab7c7b09b2a3..d51be0d51f5318fe90fbe977bf44722fb4f5590e 100644 (file)
@@ -65,6 +65,10 @@ bool PartSet_WidgetShapeSelector::storeValueCustom() const
 //********************************************************************
 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();
@@ -72,23 +76,6 @@ bool PartSet_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<Geom
   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();
@@ -102,7 +89,7 @@ bool PartSet_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<Geom
     }
   }
   // 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 =