]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Union of validator and filter functionalities.
authornds <natalia.donis@opencascade.com>
Mon, 23 Mar 2015 05:40:42 +0000 (08:40 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 23 Mar 2015 05:40:42 +0000 (08:40 +0300)
Validators using for the multi-selection control. It uses the cashed objects mySeleciton for isValid functionality.
The cash between onSelectionChanged and storeCustom is not used anumore.

src/FeaturesPlugin/extrusion_widget.xml
src/ModuleBase/ModuleBase_ISelection.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_Validators.h
src/XGUI/XGUI_Selection.cpp
src/XGUI/XGUI_Selection.h

index d723657a950c0f7345dd84de26c6680d227f72f9..1109883fb1629417b689814a97b8ac81ab5194ec 100644 (file)
@@ -6,7 +6,7 @@
     icon=":icons/sketch.png"
     tooltip="Select a sketch face"
     type_choice="Faces">
-    <selection_filter id="SketchEntityFilter"/>
+    <validator id="PartSet_SketchEntityValidator"/>
   </multi_selector>
   <doublevalue
     id="size"
index a444e586713e2929c848feca2cc2342e2b5b050b..b2686be48496f03077af7524b2bb656e6d7e461c 100644 (file)
@@ -60,6 +60,9 @@ class ModuleBase_ISelection
   //! \param theList returning list of selected AIS objects
   virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const = 0;
 
+  //! Returns list of currently selected QModelIndexes
+  virtual ObjectPtr getSelectableObject(const Handle_SelectMgr_EntityOwner& theOwner) const = 0;
+
   //! Returns list of currently selected shapes and their owners (objects).
   //! Both lists are synchronized
   //! \param theList returning list of selected AIS objects
index af08a6533f1042bbe811e5e3c475187167f093fc..8fc20d6b94e1bd76b76f13f82d4f26c8ce5b487f 100644 (file)
@@ -121,28 +121,8 @@ void ModuleBase_WidgetMultiSelector::deactivate()
 //********************************************************************
 bool ModuleBase_WidgetMultiSelector::storeValueCustom() const
 {
-  // A rare case when plugin was not loaded. 
-  if(!myFeature)
-    return false;
-  DataPtr aData = myFeature->data();
-  AttributeSelectionListPtr aSelectionListAttr = 
-    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
-
-  if (aSelectionListAttr) {
-    aSelectionListAttr->clear();
-    // Store shapes type
-    TopAbs_ShapeEnum aCurrentType =
-          ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
-    aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
-    // Store selection in the attribute
-    foreach (GeomSelection aSelec, mySelection) {
-      aSelectionListAttr->append(aSelec.first, aSelec.second);
-    }
-    //updateSelectionList(aSelectionListAttr);
-    updateObject(myFeature);
-    return true;
-  }
-  return false;
+  // the value is stored on the selection changed signal processing 
+  return true;
 }
 
 //********************************************************************
@@ -156,15 +136,9 @@ bool ModuleBase_WidgetMultiSelector::restoreValue()
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
 
   if (aSelectionListAttr) {
-    mySelection.clear();
     // Restore shape type
     setCurrentShapeType(
       ModuleBase_WidgetShapeSelector::shapeType(aSelectionListAttr->selectionType().c_str()));
-    // Restore selection in the list
-    for (int i = 0; i < aSelectionListAttr->size(); i++) {
-      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
-      mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
-    }
     updateSelectionList(aSelectionListAttr);
     return true;
   }
@@ -174,13 +148,73 @@ bool ModuleBase_WidgetMultiSelector::restoreValue()
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup)
 {
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+  if (aSelectionListAttr.get() == NULL)
+    return;
+
+  if (isBackup) {
+    mySelectionType = aSelectionListAttr->selectionType();
+    mySelection.clear();
+    for (int i = 0; i < aSelectionListAttr->size(); i++) {
+      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+      mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
+    }
+  }
+  else {
+    aSelectionListAttr->clear();
+    // Store shapes type
+    aSelectionListAttr->setSelectionType(mySelectionType);
 
+    // Store selection in the attribute
+    foreach (GeomSelection aSelec, mySelection) {
+      aSelectionListAttr->append(aSelec.first, aSelec.second);
+    }
+  }
 }
 
 //********************************************************************
 bool ModuleBase_WidgetMultiSelector::setSelection(const Handle_SelectMgr_EntityOwner& theOwner)
 {
-  return false;
+  ModuleBase_ViewerPrs aPrs;
+  ModuleBase_ISelection* aSelection = myWorkshop->selection();
+  aSelection->fillPresentation(aPrs, theOwner);
+
+  const TopoDS_Shape& aTDSShape = aPrs.shape();
+  if (aTDSShape.IsNull())
+    return false;
+  GeomShapePtr aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+  aShape->setImpl(new TopoDS_Shape(aTDSShape));
+
+  ObjectPtr anObject = aSelection->getSelectableObject(theOwner);
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+  if (myFeature) {
+    // We can not select a result of our feature
+    const std::list<ResultPtr>& aResList = myFeature->results();
+    std::list<ResultPtr>::const_iterator aIt;
+    bool isSkipSelf = false;
+    for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
+      if ((*aIt) == aResult) {
+        isSkipSelf = true;
+        break;
+      }
+    }
+    if(isSkipSelf)
+      return false;
+  }
+
+  // if the result has the similar shap as the parameter shape, just the context is set to the
+  // selection list attribute.
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+  if (aShape->isEqual(aResult->shape()))
+    aSelectionListAttr->append(aResult, NULL);
+  else
+    aSelectionListAttr->append(aResult, aShape);
+
+  return true;
 }
 
 //********************************************************************
@@ -212,42 +246,25 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::onSelectionChanged()
 {
-  ModuleBase_ISelection* aSelection = myWorkshop->selection();
-  NCollection_List<TopoDS_Shape> aSelectedShapes;
-  std::list<ObjectPtr> aOwnersList;
-  aSelection->selectedShapes(aSelectedShapes, aOwnersList);
-
-  mySelection.clear();
-  std::list<ObjectPtr>::const_iterator aIt;
-  NCollection_List<TopoDS_Shape>::Iterator aShpIt(aSelectedShapes);
-  GeomShapePtr aShape;
-  for (aIt = aOwnersList.cbegin(); aIt != aOwnersList.cend(); aShpIt.Next(), aIt++) {
-    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
-    if (myFeature) {
-      // We can not select a result of our feature
-      const std::list<ResultPtr>& aResList = myFeature->results();
-      std::list<ResultPtr>::const_iterator aIt;
-      bool isSkipSelf = false;
-      for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
-        if ((*aIt) == aResult) {
-          isSkipSelf = true;
-          break;
-        }
+  QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected();
+
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+  aSelectionListAttr->clear();
+  if (aSelected.size() > 0) {
+    foreach (ModuleBase_ViewerPrs aPrs, aSelected) {
+      Handle(SelectMgr_EntityOwner) anOwner = aPrs.owner();
+      if (isValid(anOwner)) {
+        setSelection(anOwner);
       }
-      if(isSkipSelf)
-        continue;
     }
-    aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-    aShape->setImpl(new TopoDS_Shape(aShpIt.Value()));
-
-    // if the result has the similar shap as the parameter shape, just the context is set to the
-    // selection list attribute.
-    if (aShape->isEqual(aResult->shape()))
-      mySelection.append(GeomSelection(aResult, NULL));
-    else
-      mySelection.append(GeomSelection(aResult, aShape));
   }
-  //updateSelectionList();
+  // the updateObject method should be called to flush the updated sigal. The workshop listens it,
+  // calls validators for the feature and, as a result, updates the Apply button state.
+  updateObject(myFeature);
+
   emit valuesChanged();
 }
 
index 385eabf3fc4dc9f7f0c5bf138c1ec4059cdd09f2..ce904a981c9443e92d6d56f9834905dd56679da2 100644 (file)
@@ -131,14 +131,20 @@ protected slots:
   /// Provides correspondance between Result object and its shape
   typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
 
-  /// Variable of GeomSelection type
-  QList<GeomSelection> mySelection;
-
   /// An action for pop-up menu in a list control
   QAction* myCopyAction;
 
   /// A filter for the Edges type, which avoid the generated edges selection
   Handle(ModuleBase_FilterNoDegeneratedEdge) myEdgesTypeFilter;
+
+  /// backup parameters of the model attribute. The class processes three types of attribute:
+  /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
+  /// values are reserved in the backup
+  /// Variable of selection type
+  std::string mySelectionType;
+
+  /// Variable of GeomSelection
+  QList<GeomSelection> mySelection;
 };
 
 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
index 79d5b9664242dda853ff7b77a93f94f55f9fed1a..6299ff04ad4fed863865986c61b67f69adbab122 100644 (file)
@@ -139,6 +139,9 @@ void PartSet_Module::registerValidators()
 
   aFactory->registerValidator("ModuleBase_ValidatorNoConstructionSubShapes",
                               new ModuleBase_ValidatorNoConstructionSubShapes);
+
+  aFactory->registerValidator("PartSet_SketchEntityValidator",
+                              new PartSet_SketchEntityValidator);
 }
 
 void PartSet_Module::registerFilters()
@@ -147,14 +150,14 @@ void PartSet_Module::registerFilters()
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
 
-  aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
-  aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
-  aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
-  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));
+  //aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
+  //aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
+  //aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
+  //Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
+  //aFactory->registerFilter("NoConstructionSubShapesFilter",
+  //          new ModuleBase_FilterCustom(aSelectFilter));
+  //Handle(SelectMgr_Filter) aSelectFilter = new PartSet_FilterSketchEntity(workshop());
+  //aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
 }
 
 void PartSet_Module::registerProperties()
index 7ac0693b5b7f64712d5825a607a911468b1a3e88..305647650d0372de3edb8be328155e8e5f92fe00 100644 (file)
@@ -17,6 +17,7 @@
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Object.h>
 
 #include <SketchPlugin_Sketch.h>
@@ -188,6 +189,30 @@ bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr&
   return true;
 }
 
+bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
+                                            const std::list<std::string>& theArguments) const
+{
+  AttributeSelectionListPtr aSelectionListAttr = 
+                    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+
+  // it filters only selection list attributes
+  if (aSelectionListAttr.get() == NULL)
+    return true;
+
+  std::string aType = aSelectionListAttr->selectionType().c_str();
+
+  // all context objects should be sketch entities
+  bool isSketchEntities = true;
+  int aSize = aSelectionListAttr->size();
+  for (int i = 0; i < aSelectionListAttr->size(); i++) {
+    AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+    ObjectPtr anObject = aSelectAttr->context();
+    FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+    isSketchEntities = aFeature->getKind() == SketchPlugin_Sketch::ID();
+  }
+  return isSketchEntities;
+}
+
 bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const
 {
   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
index 0dc5f46195d640760a9d7c4b6b2f4a91a0ee8161..556c2ce06d4e15888c25c59c964d14ddb7913f6c 100644 (file)
@@ -91,6 +91,20 @@ protected:
   bool featureHasReferences(const AttributePtr& theAttribute) const;
 };
 
+/**
+* \ingroup Validators
+* A validator which checks that objects selected for feature attributes are different (not the same)
+*/
+class PartSet_SketchEntityValidator : public ModelAPI_RefAttrValidator
+{
+ public:
+  //! Returns true if the attribute is good for the feature attribute
+  //! \param theAttribute an attribute
+  //! \param theArguments a list of arguments (names of attributes to check)
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments) const;
+};
+
 /**
 * \ingroup Validators
 * A Validator which validates tha selected object is a Sketch
index 0de6255da0409c105be963a079a74d2ab4e0551c..56eea5db52da72f63a9015db7f11bcf6328bd031 100644 (file)
@@ -162,6 +162,20 @@ void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
     theList.Append(aContext->SelectedInteractive());
 }
 
+//**************************************************************
+ObjectPtr XGUI_Selection::getSelectableObject(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  ObjectPtr anObject;
+
+  Handle(SelectMgr_EntityOwner) aEO = theOwner;
+  if (!aEO.IsNull()) {
+    Handle(AIS_InteractiveObject) anObj = 
+      Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
+    anObject = myWorkshop->displayer()->getObject(anObj);
+  }
+  return anObject;
+}
+
 //**************************************************************
 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList, 
                                     std::list<ObjectPtr>& theOwners) const
index a782444c81a693a3d12a1318358c2e8ad712126f..ea5886a8a94013c33809a2f0bc1c3e36a71f2c1b 100644 (file)
@@ -61,9 +61,18 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection
   //! Returns list of currently selected QModelIndexes
   virtual QModelIndexList selectedIndexes() const;
 
+  //! Returns list of currently selected QModelIndexes
+  ObjectPtr getSelectableObject(const Handle(SelectMgr_EntityOwner)& theOwner);
+
   //! Returns list of currently selected AIS objects
   virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const;
 
+  //! Return a selectable object by the entity owner. It founds AIS object in the viewer
+  //! and returns the corresponded object
+  /// \param theOwner an entity owner
+  /// \return a found object or NULL
+  ObjectPtr getSelectableObject(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
   //! Returns list of currently selected shapes
   virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theShapes, 
     std::list<ObjectPtr>& theOwners) const;