]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Improve multi-selector control to provide width colored presentation of selected...
authornds <nds@opencascade.com>
Tue, 12 Jan 2016 13:13:22 +0000 (16:13 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:03:01 +0000 (17:03 +0300)
src/ModuleBase/ModuleBase_IModule.cpp
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/PartSet/PartSet_CustomPrs.cpp
src/PartSet/PartSet_CustomPrs.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationPrs.cpp
src/XGUI/XGUI_WorkshopListener.cpp

index a4fb017577a7bc20c8d46fd5d92e489cdc418fa6..76c8991611bef98ce8e4bf8536633a60d32cb140 100644 (file)
@@ -81,7 +81,9 @@ ModuleBase_Operation* ModuleBase_IModule::getNewOperation(const std::string& the
   return new ModuleBase_OperationFeature(theFeatureId.c_str(), this);
 }
 
-bool ModuleBase_IModule::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
+bool ModuleBase_IModule::customizeObject(ObjectPtr theObject,
+                                         const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+                                         const bool theUpdateViewer)
 {
   return false;
 }
index ac70964372e9bc16625a6602e8d3bb868a4fcbbf..45c895ded35147f81ab5f3727f49997f4773b8cc 100755 (executable)
@@ -32,6 +32,12 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
 {\r
   Q_OBJECT\r
  public:\r
+  /// enumeration to know which objects should be customized\r
+  enum ModuleBase_CustomizeFlag {\r
+    CustomizeDependedAndResults = 0x00000000,\r
+    CustomizeHighlightedObjects = 0x00000001,\r
+    CustomizeAllObjects = CustomizeDependedAndResults | CustomizeHighlightedObjects\r
+  };\r
 \r
    /// Constructor\r
    /// \param theParent instance of workshop interface\r
@@ -158,10 +164,13 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   * If the object is result with the color attribute value set, it is used,\r
   * otherwise the customize is applyed to the object's feature if it is a custom prs\r
   * \param theObject an object instance\r
+  * \param theFlag a flag of level of customization, which means that only part of sub-elements\r
+  * should be updated(e.g. only highlighted elements)\r
   * \param theUpdateViewer the parameter whether the viewer should be update immediately\r
   * \returns true if the object is modified\r
   */\r
-  virtual bool customizeObject(ObjectPtr theObject, const bool theUpdateViewer);\r
+  virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,\r
+                               const bool theUpdateViewer);\r
 \r
   /// This method is called on object browser creation for customization of module specific features\r
   /// \param theObjectBrowser a pinter on Object Browser widget\r
index b08a0a55122549bd5e61a8ba5559986029c0cbba..9f7c999806a9882eefe0180a62e340ff42bdf275 100644 (file)
@@ -111,6 +111,10 @@ Q_OBJECT
     return false;
   }
 
+  /// Returns values which should be highlighted when the whidget is active
+  /// \param theValues a list of presentations
+  virtual void getHighlighted(QList<ModuleBase_ViewerPrs>& theValues) {};
+
   /// Restore value from attribute data to the widget's control. Emits signals before and after store
   /// \return True in success
   bool restoreValue();
index ffc380878cb756b4f99caada00d4250fdc254ce8..714e4ef7f389c06ed7f6e55306d97cb619d0db98 100755 (executable)
@@ -14,6 +14,7 @@
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_Definitions.h>
+#include <ModuleBase_IModule.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
@@ -292,6 +293,15 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& t
   return isDone;
 }
 
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::getHighlighted(QList<ModuleBase_ViewerPrs>& theValues)
+{
+  std::set<int> anAttributeIds;
+  getSelectedAttributeIndices(anAttributeIds);
+  if (!anAttributeIds.empty())
+    convertIndicesToViewerSelection(anAttributeIds, theValues);
+}
+
 //********************************************************************
 bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
 {
@@ -395,35 +405,7 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum
 QList<ModuleBase_ViewerPrs> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
 {
   QList<ModuleBase_ViewerPrs> aSelected;
-  // Restore selection in the viewer by the attribute selection list
-  if(myFeature) {
-    AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
-    if (aSelectionListAttr.get()) {
-      for (int i = 0; i < aSelectionListAttr->size(); i++) {
-        AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
-        ResultPtr anObject = anAttr->context();
-        if (anObject.get()) {
-          TopoDS_Shape aShape;
-          std::shared_ptr<GeomAPI_Shape> aShapePtr = anAttr->value();
-          if (aShapePtr.get()) {
-            aShape = aShapePtr->impl<TopoDS_Shape>();
-          }
-          aSelected.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
-        }
-      }
-    }
-    else {
-      AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID());
-      if (aRefListAttr.get()) {
-        for (int i = 0; i < aRefListAttr->size(); i++) {
-          ObjectPtr anObject = aRefListAttr->object(i);
-          if (anObject.get()) {
-            aSelected.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
-          }
-        }
-      }
-    }
-  }
+  convertIndicesToViewerSelection(std::set<int>(), aSelected);
   return aSelected;
 }
 
@@ -494,13 +476,9 @@ void ModuleBase_WidgetMultiSelector::onCopyItem()
 void ModuleBase_WidgetMultiSelector::onDeleteItem()
 {
   // find attribute indices to delete
-  QList<QListWidgetItem*> aItems = myListControl->selectedItems();
   std::set<int> anAttributeIds;
-  foreach(QListWidgetItem* anItem, aItems) {
-    int anIndex = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
-    if (anAttributeIds.find(anIndex) == anAttributeIds.end())
-      anAttributeIds.insert(anIndex);
-  }
+  getSelectedAttributeIndices(anAttributeIds);
+
   // refill attribute by the items which indices are not in the list of ids
   bool aDone = false;
   AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
@@ -518,6 +496,8 @@ void ModuleBase_WidgetMultiSelector::onDeleteItem()
   if (aDone) {
     restoreValue();
     myWorkshop->setSelected(getAttributeSelection());
+
+    myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeAllObjects, true);
   }
 }
 
@@ -527,9 +507,57 @@ void ModuleBase_WidgetMultiSelector::onListSelection()
   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
   myCopyAction->setEnabled(!aItems.isEmpty());
   myDeleteAction->setEnabled(!aItems.isEmpty());
-
-  //myWorkshop->setSelected(>setSelected(getAttributeSelection());
-  QList<ModuleBase_ViewerPrs> aSelectedItems;
   
-  emit itemsSelected(aSelectedItems);
+  myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
+                                        true);
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
+{
+  QList<QListWidgetItem*> aItems = myListControl->selectedItems();
+  foreach(QListWidgetItem* anItem, aItems) {
+    int anIndex = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
+    if (theAttributeIds.find(anIndex) == theAttributeIds.end())
+      theAttributeIds.insert(anIndex);
+  }
+}
+
+void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
+                                                      QList<ModuleBase_ViewerPrs>& theValues) const
+{
+  if(myFeature.get() == NULL)
+    return;
+  AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+  if (aSelectionListAttr.get()) {
+    for (int i = 0; i < aSelectionListAttr->size(); i++) {
+      // filter by attribute indices only if the container is not empty otherwise return all items
+      if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
+        continue;
+      AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
+      ResultPtr anObject = anAttr->context();
+      if (anObject.get()) {
+        TopoDS_Shape aShape;
+        std::shared_ptr<GeomAPI_Shape> aShapePtr = anAttr->value();
+        if (aShapePtr.get()) {
+          aShape = aShapePtr->impl<TopoDS_Shape>();
+        }
+        theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
+      }
+    }
+  }
+  else {
+    AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID());
+    if (aRefListAttr.get()) {
+      for (int i = 0; i < aRefListAttr->size(); i++) {
+        // filter by attribute indices only if the container is not empty otherwise return all items
+        if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
+          continue;
+        ObjectPtr anObject = aRefListAttr->object(i);
+        if (anObject.get()) {
+          theValues.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
+        }
+      }
+    }
+  }
 }
index 49dbc1a7c40551ff1cfc4ca2578a7e0b52af7d20..bebc59c91f0c40b8f878d8552cb626c85fda379f 100755 (executable)
@@ -72,6 +72,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge
   virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
                             const bool theToValidate);
 
+  /// Returns values which should be highlighted when the whidget is active
+  /// \param theValues a list of presentations
+  virtual void getHighlighted(QList<ModuleBase_ViewerPrs>& theValues);
+
   /// Checks the widget validity. By default, it returns true.
   /// \param thePrs a selected presentation in the view
   /// \return a boolean value
@@ -81,10 +85,6 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge
   /// Slot is called on selection type changed
   void onSelectionTypeChanged();
 
-signals:
-  /// Signals about items selected in the list view
-  void itemsSelected(const QList<ModuleBase_ViewerPrs>& theItems);
-
 protected slots:
   /// Slot for copy command in a list pop-up menu
   void onCopyItem();
@@ -148,6 +148,17 @@ protected:
   /// For example, the "Edges" is converted to "edge"
   std::string validatorType(const QString& theType) const;
 
+protected:
+  /// Returns attribute indices selected in the widget selection list 
+  /// \param theIndices a list of indices
+  void getSelectedAttributeIndices(std::set<int>& theIndices);
+
+  /// Gets the feature attribute and fill a list of viewer presentation for the attribute
+  /// indices. If the the container of indices is empty, it returns all objects.
+  /// \param theAttributeIds indices in attribute list to be returned
+  /// \param theValues the result presentations, filled with object and shape of an attribute item
+  void convertIndicesToViewerSelection(std::set<int> theAttributeIds,
+                                       QList<ModuleBase_ViewerPrs>& theValues) const;
 protected:
   /// List control
   QListWidget* myListControl;
index b2315bffb8d578dffb406e9742b6241f3be9e72d..ed43e19bd2953568e6fb26e480d15dcb49e33d82 100755 (executable)
@@ -116,7 +116,9 @@ Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation()
   return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
 }
 
-bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, const bool theUpdateViewer)
+bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject,
+                                  const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+                                  const bool theUpdateViewer)
 {
 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
   return false;
index c12768e0e549f4248fdcba0c060e0255722e3d81..1d12d68029d219d00ad95fde307a685e2062b2cb 100755 (executable)
@@ -11,6 +11,7 @@
 
 #include "PartSet_OperationPrs.h"
 
+#include <ModuleBase_IModule.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Feature.h>
@@ -53,7 +54,8 @@ public:
   /// \param theObject an object to redisplay
   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
   /// \returns true if the presentation is redisplayed
-  bool redisplay(const ObjectPtr& theObject, const bool theUpdateViewer);
+  bool redisplay(const ObjectPtr& theObject,
+                 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, const bool theUpdateViewer);
 
   /// Nullify the operation presentation. For example, it can be useful when the viewer/context
   /// is closed. If this is not performed and the presentation is assigned in another context,
index 93a81075085ae3b0df0e3d953225b9656e54b8ed..5baf6b713997ab2ebc691e7491f6b1f4e41a5627 100755 (executable)
@@ -131,7 +131,6 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
           SLOT(onViewTransformed(int)));
   connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
           SLOT(onViewCreated(ModuleBase_IViewWindow*)));
-
   myMenuMgr = new PartSet_MenuMgr(this);
   myCustomPrs = new PartSet_CustomPrs(theWshop);
 
@@ -729,11 +728,12 @@ void PartSet_Module::onViewTransformed(int theTrsfType)
     aDisplayer->updateViewer();
 }
 
-bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
+bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
+                                     const bool theUpdateViewer)
 {
   bool isRedisplayed = false;
   if (myCustomPrs->isActive())
-    isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
+    isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
 
   return isRedisplayed;
 }
index f074786d33f30c8d1a9be9eaf39cf43253e53767..956d0954474c662c827673932ab666d4ff6a9662 100755 (executable)
@@ -184,10 +184,13 @@ public:
   * If the object is result with the color attribute value set, it is used,
   * otherwise the customize is applyed to the object's feature if it is a custom prs
   * \param theObject an object instance
+  * \param theFlag a flag of level of customization, which means that only part of sub-elements
+  * should be updated(e.g. only highlighted elements)
   * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
   * \returns true if the object is modified
   */
-  virtual bool customizeObject(ObjectPtr theObject, const bool theUpdateViewer);
+  virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
+                               const bool theUpdateViewer);
 
   /// This method is called on object browser creation for customisation of module specific features
   /// \param theObjectBrowser a pinter on Object Browser widget
index 5252aac4833bc6fa5fd6212dc631fab3e9cbc9bc..9b41b2effbdbaa48d2552f175bbc6c0bf0642d23 100755 (executable)
@@ -79,6 +79,8 @@ bool PartSet_OperationPrs::hasShapes()
   return !myFeatureShapes.empty() || !myFeatureResults.empty();
 }
 
+#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_ModelWidget.h>
 void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
                                    const Handle(Prs3d_Presentation)& thePresentation, 
                                    const Standard_Integer theMode)
@@ -98,6 +100,7 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
 
   // create presentations on the base of the shapes
   Handle(Prs3d_Drawer) aDrawer = Attributes();
+
   QMap<ObjectPtr, QList<GeomShapePtr> >::const_iterator anIt = myFeatureShapes.begin(),
                                                         aLast = myFeatureShapes.end();
   for (; anIt != aLast; anIt++) {
@@ -134,6 +137,45 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
     ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, aDrawer);
     StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer);
   }
+  QList<ModuleBase_ViewerPrs> aValues;
+  ModuleBase_IPropertyPanel* aPanel = myWorkshop->propertyPanel();
+  if (aPanel) {
+    ModuleBase_ModelWidget* aWidget = aPanel->activeWidget();
+    if (aWidget) {
+      aWidget->getHighlighted(aValues);
+    }
+  }
+
+  Standard_Real aPreviousWidth = Width();
+  setWidth(aDrawer, aPreviousWidth+3);
+  Handle(AIS_InteractiveContext) aContext = GetContext();
+  Quantity_NameOfColor anHColor = aContext->HilightColor();
+
+  aColor = Quantity_Color(anHColor);
+  aColor = Quantity_Color((1. + aColor.Red())/2., (1. + aColor.Green())/2.,
+                          (1. + aColor.Blue())/2., Quantity_TOC_RGB);
+  SetColor(aColor);
+
+  QList<ModuleBase_ViewerPrs>::const_iterator anIIt = aValues.begin(),
+                                              aILast = aValues.end();
+  for (; anIIt != aILast; anIIt++) {
+    ModuleBase_ViewerPrs aPrs = *anIIt;
+    ObjectPtr anObject = aPrs.object();
+    TopoDS_Shape aShape = aPrs.shape();
+    if (aShape.IsNull()) {
+      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+      if (aResult.get()) {
+        GeomShapePtr aGeomShape = aResult->shape();
+        if (aGeomShape.get())
+          aShape = aGeomShape->impl<TopoDS_Shape>();
+      }
+    }
+    if (!aShape.IsNull()) {
+      ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, aDrawer);
+      StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer);
+    }
+  }
+  setWidth(aDrawer, aPreviousWidth);
 }
 
 void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
index d446330332722e5d3dc5c2933efa2d6ed7a869a3..457d41216fce446429020c748d1d3a158c2cc037 100755 (executable)
@@ -571,7 +571,8 @@ bool XGUI_WorkshopListener::customizeCurrentObject()
     if (aFOperation) {
       FeaturePtr aCurrentFeature = aFOperation->feature();
       if (aCurrentFeature.get())
-        aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, false);
+        aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
+                                           ModuleBase_IModule::CustomizeAllObjects, false);
     }
   }
   return aCustomized;