]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Selection processing in multiselector control.
authorsbh <sergey.belash@opencascade.com>
Thu, 9 Oct 2014 17:14:49 +0000 (21:14 +0400)
committersbh <sergey.belash@opencascade.com>
Thu, 9 Oct 2014 17:14:49 +0000 (21:14 +0400)
src/FeaturesPlugin/FeaturesPlugin_Group.cpp
src/FeaturesPlugin/FeaturesPlugin_Group.h
src/FeaturesPlugin/group_widget.xml
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp

index 3a9a07a15f86442317430e73d8f91c8a06ac2a11..4a5a34bc21f8077f78054ef9108b6d7c3d63da3b 100644 (file)
@@ -18,15 +18,15 @@ FeaturesPlugin_Group::FeaturesPlugin_Group()
 void FeaturesPlugin_Group::initAttributes()
 {
   data()->addAttribute(FeaturesPlugin_Group::NAME_ID(), ModelAPI_AttributeString::type());
-  data()->addAttribute(FeaturesPlugin_Group::TYPE_ID(), ModelAPI_AttributeInteger::type());
   data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeString::type());
 }
 
 void FeaturesPlugin_Group::execute()
 {
-  AttributeIntegerPtr aTypeAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeInteger>(
-      data()->attribute(FeaturesPlugin_Group::TYPE_ID()));
-  if (!aTypeAttr)
+  AttributeStringPtr aNameAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeString>(
+      data()->attribute(FeaturesPlugin_Group::NAME_ID()));
+  if (!aNameAttr)
     return;
-  int aType = aTypeAttr->value();
+  std::string aName = aNameAttr->value();
+  data()->setName(aName);
 }
index 12d298704092c61778d7bed1e75818144223dc99..34385caab13d67ea3f679f5882011ef9be8f2576 100644 (file)
@@ -18,18 +18,12 @@ class FeaturesPlugin_Group : public ModelAPI_Feature
     static const std::string MY_GROUP_ID("Group");
     return MY_GROUP_ID;
   }
-  /// attribute name of group type
+  /// attribute name of group name
   inline static const std::string& NAME_ID()
   {
     static const std::string MY_GROUP_NAME_ID("group_name");
     return MY_GROUP_NAME_ID;
   }
-  /// attribute name of group type
-  inline static const std::string& TYPE_ID()
-  {
-    static const std::string MY_GROUP_TYPE_ID("group_type");
-    return MY_GROUP_TYPE_ID;
-  }
   /// attribute name of selected entities list
   inline static const std::string& LIST_ID()
   {
index 7b45d68f5efd30a251ea439d8e37de4af35b2838..5d8ad7565a8d812dcb66cdc6726e6fed19c6e79c 100644 (file)
@@ -2,14 +2,8 @@
   <stringvalue
     id="group_name"
     label="Name"
-    tooltip="Name of the group"
-    string_list="Vertices Edges Faces Solids" />
-  <choice
-    id="group_type"
-    label="Type"
-    tooltip="Type of geometry entities"
-    string_list="Vertices Edges Faces Solids" />
+    tooltip="Name of the group" />
   <multi_selector id="group_list" 
-    label="Selected objects:"
-    tooltip="List of selected objects" /> 
+    tooltip="List of selected objects" 
+    type_choice="Vertices Edges Faces Solids" /> 
 </source>
\ No newline at end of file
index ffb17b5c2b2560c666c15fa902234819e1d5da87..8df14bdc35b74bfb93fce4cdb053f9ac5c302114 100644 (file)
@@ -24,8 +24,8 @@ void adjustMargins(QLayout* theLayout)
 {
   if(!theLayout)
     return;
-  theLayout->setContentsMargins(5, 5, 5, 5);
-  theLayout->setSpacing(5);
+  theLayout->setContentsMargins(2, 5, 5, 2);
+  theLayout->setSpacing(4);
 }
 
 void zeroMargins(QWidget* theWidget)
index c7f0c609c5b8be02e7f321f80d16b5bc2f059c36..057c4d5d3b19d3aff33415718fd537ae24d826e8 100644 (file)
@@ -298,7 +298,7 @@ QWidget* ModuleBase_WidgetFactory::lineEditControl(QWidget* theParent)
 QWidget* ModuleBase_WidgetFactory::multiSelectorControl(QWidget* theParent)
 {
   ModuleBase_WidgetMultiSelector* aMultiselectorWgt =
-      new ModuleBase_WidgetMultiSelector(theParent, myWidgetApi,myParentId);
+      new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId);
   myModelWidgets.append(aMultiselectorWgt);
   return aMultiselectorWgt->getControl();
 }
index 4ee9a4b253029170957a8d7d70e5b536a1aaaf94..189b659c4d2f89a281b1f8e895fb608f9d2ac8b9 100644 (file)
@@ -6,6 +6,9 @@
  */
 
 #include <ModuleBase_WidgetMultiSelector.h>
+#include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_Tools.h>
 
 #include <ModelAPI_AttributeString.h>
 
 #include <Config_WidgetAPI.h>
 
-#include <QVBoxLayout>
+#include <QGridLayout>
 #include <QLabel>
 #include <QTextEdit>
 #include <QObject>
 #include <QString>
+#include <QComboBox>
+#include <QEvent>
 
 #include <boost/smart_ptr/shared_ptr.hpp>
 #include <string>
 
 ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
-                                                     const Config_WidgetAPI* theData,
-                                                     const std::string& theParentId)
-    : ModuleBase_ModelWidget(theParent, theData, theParentId)
+                                                               ModuleBase_IWorkshop* theWorkshop,
+                                                               const Config_WidgetAPI* theData,
+                                                               const std::string& theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId),
+      myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false)
 {
   myMainWidget = new QWidget(theParent);
-  QVBoxLayout* aMainLay = new QVBoxLayout(myMainWidget);
+  QGridLayout* aMainLay = new QGridLayout(myMainWidget);
   ModuleBase_Tools::adjustMargins(aMainLay);
-  QString aTitle = QString::fromStdString(theData->widgetLabel());
-  QLabel* aTitleLabel = new QLabel(aTitle, myMainWidget);
-  aMainLay->addWidget(aTitleLabel);
+  QLabel* aTypeLabel = new QLabel(tr("Type"), myMainWidget);
+  aMainLay->addWidget(aTypeLabel, 0, 0);
+  myTypeCombo = new QComboBox(myMainWidget);
+  std::string aTypes = theData->getProperty("type_choice");
+  myShapeTypes = QString::fromStdString(aTypes).split(' ');
+  myTypeCombo->addItems(myShapeTypes);
+  aMainLay->addWidget(myTypeCombo, 0, 1);
+  QLabel* aListLabel = new QLabel(tr("Selected objects:"), myMainWidget);
+  aMainLay->addWidget(aListLabel, 1, 0, 1, -1);
   myListControl = new QTextEdit(myMainWidget);
   myListControl->setReadOnly(true);
-  aMainLay->addWidget(myListControl);
-  myListControl->setMinimumHeight(20);
+  aMainLay->addWidget(myListControl, 2, 0, 2, -1);
+  aMainLay->setColumnStretch(1, 1);
   myMainWidget->setLayout(aMainLay);
 
-  connect(myListControl, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged()));
+  //TODO: Move into the base class
+  myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false);
+  //TODO_END
+  connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged()));
+  activateSelection(true);
 }
 
 ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
 {
+  activateSelection(false);
 }
 
 bool ModuleBase_WidgetMultiSelector::storeValue() const
@@ -63,6 +81,7 @@ bool ModuleBase_WidgetMultiSelector::storeValue() const
 
 bool ModuleBase_WidgetMultiSelector::restoreValue()
 {
+  return false;
   // A rare case when plugin was not loaded. 
   if(!myFeature)
     return false;
@@ -84,6 +103,66 @@ QWidget* ModuleBase_WidgetMultiSelector::getControl() const
 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
 {
   QList<QWidget*> result;
+  result << myTypeCombo;
   result << myListControl;
   return result;
 }
+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+  if (theObj == myListControl) {
+    if (theEvent->type() == QEvent::FocusIn)
+      activateSelection(true);
+  }
+  return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
+}
+
+void ModuleBase_WidgetMultiSelector::onSelectionChanged()
+{
+  ModuleBase_ISelection* aSelection = myWorkshop->selection();
+  NCollection_List<TopoDS_Shape> aSelectedShapes, aFilteredShapes;
+  aSelection->selectedShapes(aSelectedShapes);
+  QString aText;
+  if (!aSelectedShapes.IsEmpty()) {
+    filterShapes(aSelectedShapes, aFilteredShapes);
+    aText = QString("Items selected: %1").arg(aFilteredShapes.Size());
+  }
+  myListControl->setText(aText);
+}
+
+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::activateSelection(bool toActivate)
+{
+  myIsActive = toActivate;
+  if (myIsActive) {
+    connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+    onSelectionTypeChanged();
+  } else {
+    disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+    myWorkshop->deactivateSubShapesSelection();
+  }
+}
+
+void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
+{
+  QString aNewType = myTypeCombo->currentText();
+  QIntList aList;
+  aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
+  myWorkshop->activateSubShapesSelection(aList);
+}
index d631f35ef09a3c9c2e43bfa0ed401e4231b7885e..bc184d5e57323fb3c08d0f289e634a232434e130 100644 (file)
 #include <ModuleBase.h>
 #include <ModuleBase_ModelWidget.h>
 
+#include <NCollection_List.hxx>
+#include <TopoDS_Shape.hxx>
+
 #include <QList>
 #include <QString>
 #include <QStringList>
 
 class QWidget;
 class QTextEdit;
+class QComboBox;
+class ModuleBase_IWorkshop;
 
 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_ModelWidget
 {
   Q_OBJECT
  public:
   ModuleBase_WidgetMultiSelector(QWidget* theParent,
-                                const Config_WidgetAPI* theData,
-                                const std::string& theParentId);
+                                 ModuleBase_IWorkshop* theWorkshop,
+                                 const Config_WidgetAPI* theData,
+                                 const std::string& theParentId);
   virtual ~ModuleBase_WidgetMultiSelector();
 
   /// Saves the internal parameters to the given feature
@@ -41,11 +47,29 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model
   /// \return a control list
   virtual QList<QWidget*> getControls() const;
 
- //public slots:
+  virtual bool eventFilter(QObject* theObj, QEvent* theEvent);
+
+ public slots:
+  void activateSelection(bool toActivate);
+  void onSelectionTypeChanged();
+  void onSelectionChanged();
+
+ protected:
+  void filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
+                    NCollection_List<TopoDS_Shape>& theResult);
 
  private:
   QTextEdit* myListControl;
+  QComboBox* myTypeCombo;
   QWidget* myMainWidget;
+
+  //TODO: Move into the base of selectors
+  ModuleBase_IWorkshop* myWorkshop;
+
+  /// If true then local selector has to be activated in context
+  QStringList myShapeTypes;
+  bool myUseSubShapes;
+  bool myIsActive;
 };
 
 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
index 7c1d0f69a48d3b6f966b51bf0c49d4682d50f9bb..0b433e663447f23a3311ecccd08f27d019fd88eb 100644 (file)
@@ -2,24 +2,29 @@
 // Created:     2 June 2014
 // Author:      Vitaly Smetannikov
 
-#include "ModuleBase_WidgetShapeSelector.h"
-#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_Definitions.h>
 #include <ModuleBase_ISelection.h>
-#include "ModuleBase_WidgetValue.h"
+#include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_Tools.h>
-#include "ModuleBase_WidgetValueFeature.h"
-
+#include <ModuleBase_WidgetValueFeature.h>
+#include <Config_WidgetAPI.h>
 #include <Events_Loop.h>
-#include <ModelAPI_Events.h>
-#include <ModelAPI_Tools.h>
-
+#include <Events_Message.h>
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_Shape.h>
+#include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
-#include <ModelAPI_Object.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
 #include <Config_WidgetAPI.h>
+#include <Events_Error.h>
 
 #include <GeomAPI_Shape.h>
 
 #include <QEvent>
 #include <QDockWidget>
 
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <list>
 #include <stdexcept>
+#include <xstring>
 
 typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
 static ShapeTypes MyShapeTypes;
@@ -44,16 +56,21 @@ TopAbs_ShapeEnum ModuleBase_WidgetShapeSelector::shapeType(const QString& theTyp
 {
   if (MyShapeTypes.count() == 0) {
     MyShapeTypes["face"] = TopAbs_FACE;
+    MyShapeTypes["faces"] = TopAbs_FACE;
     MyShapeTypes["vertex"] = TopAbs_VERTEX;
+    MyShapeTypes["vertices"] = TopAbs_VERTEX;
     MyShapeTypes["wire"] = TopAbs_WIRE;
     MyShapeTypes["edge"] = TopAbs_EDGE;
+    MyShapeTypes["edges"] = TopAbs_EDGE;
     MyShapeTypes["shell"] = TopAbs_SHELL;
     MyShapeTypes["solid"] = TopAbs_SOLID;
+    MyShapeTypes["solids"] = TopAbs_SOLID;
   }
   QString aType = theType.toLower();
   if (MyShapeTypes.contains(aType))
     return MyShapeTypes[aType];
-  throw std::invalid_argument("Shape type defined in XML is not implemented!");
+  Events_Error::send("Shape type defined in XML is not implemented!");
+  return TopAbs_SHAPE;
 }
 
 ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,