]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Define selection type for selection control
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 10 Jun 2014 06:01:57 +0000 (10:01 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 10 Jun 2014 06:01:57 +0000 (10:01 +0400)
src/ConstructionPlugin/extrusion_widget.xml
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_SelectorWidget.cpp [deleted file]
src/ModuleBase/ModuleBase_SelectorWidget.h [deleted file]
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetSelector.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetSelector.h [new file with mode: 0644]
src/XGUI/XGUI_Workshop.cpp

index f368a68cd06329b06e35370e617e47a284b3781f..c0069ca67cfd56b2d851ad6e68fdff65e62430df 100644 (file)
@@ -3,7 +3,8 @@
     label="Select a face" 
     icon=":icons/sketch.png" 
     tooltip="Select a face for extrusion"
-       activate="true"
+    activate="true"
+    shape_types="face"
   />
   <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set size of extrusion"/>
   <boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
index 4593a68fe499a7c5c8ed37b28979c1f9d8238bc9..b56c217912ed10bb62d52ebd8cbf69d9b73832f6 100644 (file)
@@ -12,7 +12,7 @@ SET(PROJECT_HEADERS
        ModuleBase_WidgetFactory.h
        ModuleBase_WidgetPoint2D.h
        ModuleBase_WidgetSwitch.h
-       ModuleBase_SelectorWidget.h
+       ModuleBase_WidgetSelector.h
        ModuleBase_IWorkshop.h
 )
 
@@ -26,7 +26,7 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetFactory.cpp
        ModuleBase_WidgetPoint2D.cpp
        ModuleBase_WidgetSwitch.cpp
-       ModuleBase_SelectorWidget.cpp
+       ModuleBase_WidgetSelector.cpp
 )
 
 SET(PROJECT_LIBRARIES
@@ -54,6 +54,7 @@ INCLUDE_DIRECTORIES(
     ${CMAKE_SOURCE_DIR}/src/Model
     ${CMAKE_SOURCE_DIR}/src/ModelAPI
     ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
+    ${CMAKE_SOURCE_DIR}/src/GeomAPI
 )
 
 ADD_DEFINITIONS(-DMODULEBASE_EXPORTS ${CAS_DEFINITIONS})
diff --git a/src/ModuleBase/ModuleBase_SelectorWidget.cpp b/src/ModuleBase/ModuleBase_SelectorWidget.cpp
deleted file mode 100644 (file)
index f3f19b1..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-// File:        ModuleBase_SelectorWidget.h
-// Created:     2 June 2014
-// Author:      Vitaly Smetannikov
-
-
-#include "ModuleBase_SelectorWidget.h"
-#include "ModuleBase_IWorkshop.h"
-
-#include <Events_Loop.h>
-#include <Model_Events.h>
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_AttributeReference.h>
-#include <Config_WidgetAPI.h>
-
-#include <QWidget>
-#include <QLayout>
-#include <QLabel>
-#include <QLineEdit>
-#include <QToolButton>
-#include <QString>
-#include <QEvent>
-#include <QDockWidget>
-
-
-ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent, 
-                                                     ModuleBase_IWorkshop* theWorkshop, 
-                                                     const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop), myActivateOnStart(false)
-{
-  myContainer = new QWidget(theParent);
-  QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
-
-  aLayout->setContentsMargins(0, 0, 0, 0);
-  QString aLabelText = QString::fromStdString(theData->widgetLabel());
-  QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
-  myLabel = new QLabel(aLabelText, myContainer);
-  myLabel->setPixmap(QPixmap(aLabelIcon));
-
-  aLayout->addWidget(myLabel);
-
-  QString aToolTip = QString::fromStdString(theData->widgetTooltip());
-  myTextLine = new QLineEdit(myContainer);
-  myTextLine->setReadOnly(true);
-  myTextLine->setToolTip(aToolTip);
-  myTextLine->installEventFilter(this);
-
-  aLayout->addWidget(myTextLine);
-
-  myActivateBtn = new QToolButton(myContainer);
-  myActivateBtn->setIcon(QIcon(":icons/hand_point.png"));
-  myActivateBtn->setCheckable(true);
-  myActivateBtn->setToolTip(tr("Activate/Deactivate selection"));
-  connect(myActivateBtn, SIGNAL(toggled(bool)), this, SLOT(activateSelection(bool)));
-
-  aLayout->addWidget(myActivateBtn);
-
-  QString aActivateTxt = QString::fromStdString(theData->getProperty("activate"));
-  if (!aActivateTxt.isNull()) {
-    myActivateOnStart = (aActivateTxt == "true");
-  }
-}
-
-//********************************************************************
-ModuleBase_SelectorWidget::~ModuleBase_SelectorWidget()
-{
-}
-
-//********************************************************************
-bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature) const
-{
-  DataPtr aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
-    boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
-
-  FeaturePtr aFeature = aRef->value();
-  if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
-    aRef->setValue(mySelectedFeature);
-    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
-  }
-  return true;
-}
-
-//********************************************************************
-bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature)
-{
-  DataPtr aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
-
-  bool isBlocked = this->blockSignals(true);
-  mySelectedFeature = aRef->value();
-  updateSelectionName(); 
-
-  this->blockSignals(isBlocked);
-  return true;
-}
-
-//********************************************************************
-QList<QWidget*> ModuleBase_SelectorWidget::getControls() const
-{
-  QList<QWidget*> aControls;
-  aControls.append(myLabel);
-  aControls.append(myTextLine);
-  aControls.append(myActivateBtn);
-  return aControls;
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::onSelectionChanged()
-{
-  QList<FeaturePtr> aFeatures = myWorkshop->selectedFeatures();
-  if (aFeatures.size() > 0) {
-    FeaturePtr aFeature = aFeatures.first();
-    if ((!mySelectedFeature) && (!aFeature))
-      return;
-    if (mySelectedFeature && aFeature && mySelectedFeature->isSame(aFeature))
-      return;
-
-    // TODO: Check that the selection corresponds to selection type
-    // TODO: Use the feature kind definition like SKETCH_KIND instead of the direct text
-    if (aFeature->getKind().compare("Sketch") != 0)
-      return;
-
-    mySelectedFeature = aFeature;
-    if (mySelectedFeature) {
-      updateSelectionName();
-      activateSelection(false);
-      raisePanel();
-    } else {
-      myTextLine->setText("");
-    }
-    emit valuesChanged();
-  }
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::updateSelectionName()
-{
-  if (mySelectedFeature) {
-    std::string aName;
-    if (mySelectedFeature->data())
-      aName = mySelectedFeature->data()->getName();
-    else 
-      aName = boost::dynamic_pointer_cast<ModelAPI_Object>(mySelectedFeature)->getName();
-    myTextLine->setText(QString::fromStdString(aName));
-  } else 
-    myTextLine->setText("");
-}
-
-//********************************************************************
-bool ModuleBase_SelectorWidget::eventFilter(QObject* theObj, QEvent* theEvent)
-{
-  if (theObj == myTextLine) {
-    if (theEvent->type() == QEvent::Polish) {
-      activateSelection(myActivateOnStart);
-      onSelectionChanged();
-    }
-  }
-  return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::enableOthersControls(bool toEnable) const
-{
-  QWidget* aParent = myContainer->parentWidget();
-  QList<QWidget*> aChldList = aParent->findChildren<QWidget*>();
-  foreach(QWidget* aWgt, aChldList) {
-    if ((aWgt != myLabel) && (aWgt != myActivateBtn) && (aWgt != myTextLine) && (aWgt != myContainer))
-      aWgt->setEnabled(toEnable);
-  }
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::activateSelection(bool toActivate)
-{
-  enableOthersControls(!toActivate);
-  myTextLine->setEnabled(toActivate);
-
-  if (toActivate)
-    connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-  else
-    disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-
-  myActivateBtn->setDown(toActivate);
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::raisePanel() const
-{
-  QWidget* aParent = myContainer->parentWidget();
-  QWidget* aLastPanel = 0;
-  while (!aParent->inherits("QDockWidget")) {
-    aLastPanel = aParent;
-    aParent = aParent->parentWidget();
-    if (!aParent) return;
-  }
-  if (aParent->inherits("QDockWidget")) {
-    QDockWidget* aTabWgt = (QDockWidget*) aParent;
-    aTabWgt->raise();
-  }
-}
\ No newline at end of file
diff --git a/src/ModuleBase/ModuleBase_SelectorWidget.h b/src/ModuleBase/ModuleBase_SelectorWidget.h
deleted file mode 100644 (file)
index 48e3984..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// File:        ModuleBase_SelectorWidget.h
-// Created:     2 June 2014
-// Author:      Vitaly Smetannikov
-
-#ifndef ModuleBase_SelectorWidget_H
-#define ModuleBase_SelectorWidget_H
-
-#include "ModuleBase.h"
-#include "ModuleBase_ModelWidget.h"
-
-#include <ModelAPI_Feature.h>
-
-
-class Config_WidgetAPI;
-class QWidget;
-class QLabel;
-class QLineEdit;
-class QToolButton;
-class ModuleBase_IWorkshop;
-
-class MODULEBASE_EXPORT ModuleBase_SelectorWidget: public ModuleBase_ModelWidget
-{
-  Q_OBJECT
-public:
-  ModuleBase_SelectorWidget(QWidget* theParent, 
-                            ModuleBase_IWorkshop* theWorkshop, 
-                            const Config_WidgetAPI* theData);
-
-  virtual ~ModuleBase_SelectorWidget();
-
-  /// Saves the internal parameters to the given feature
-  /// \param theFeature a model feature to be changed
-  virtual bool storeValue(FeaturePtr theFeature) const;
-
-  virtual bool restoreValue(FeaturePtr theFeature);
-
-  /// Returns the internal parent wiget control, that can be shown anywhere
-  /// \returns the widget
-  QWidget* getControl() const { return myContainer; }
-
-  /// Returns list of widget controls
-  /// \return a control list
-  virtual QList<QWidget*> getControls() const;
-
-  void setActivationOnStart(bool toActivate) { myActivateOnStart = toActivate; }
-  bool activateOnStart() const { return myActivateOnStart; }
-
-  FeaturePtr selectedFeature() const { return mySelectedFeature; }
-
-public slots:
-
-  /// Activate or deactivate selection
-  void activateSelection(bool toActivate);
-
-protected:
-  bool eventFilter(QObject* theObj, QEvent* theEvent);
-
-private slots:
-  void onSelectionChanged();
-
-private:
-  void enableOthersControls(bool toEnable) const;
-  void updateSelectionName();
-  void raisePanel() const;
-
-  QWidget*     myContainer;
-  QLabel*      myLabel;
-  QLineEdit*   myTextLine;
-  QToolButton* myActivateBtn;
-
-  ModuleBase_IWorkshop* myWorkshop;
-
-  bool myActivateOnStart;
-
-  FeaturePtr mySelectedFeature;
-};
-
-#endif
\ No newline at end of file
index 4c011a454f7d05974be69764bf676f708b2d3af9..e52d5b2d4a78f6bdc8948b3face829e1ba38b22e 100644 (file)
@@ -11,7 +11,7 @@
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetPoint2D.h>
 #include <ModuleBase_WidgetSwitch.h>
-#include <ModuleBase_SelectorWidget.h>
+#include <ModuleBase_WidgetSelector.h>
 #include <ModuleBase_WidgetDoubleValue.h>
 #include <ModuleBase_WidgetBoolValue.h>
 
@@ -191,7 +191,7 @@ QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
 
 QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent)
 {
-  ModuleBase_SelectorWidget* aSelector = new ModuleBase_SelectorWidget(theParent, myWorkshop, myWidgetApi);
+  ModuleBase_WidgetSelector* aSelector = new ModuleBase_WidgetSelector(theParent, myWorkshop, myWidgetApi);
   
   QObject::connect(aSelector, SIGNAL(valuesChanged()),  myOperation, SLOT(storeCustomValue()));
 
diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp
new file mode 100644 (file)
index 0000000..df7b431
--- /dev/null
@@ -0,0 +1,254 @@
+// File:        ModuleBase_WidgetSelector.h
+// Created:     2 June 2014
+// Author:      Vitaly Smetannikov
+
+
+#include "ModuleBase_WidgetSelector.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeReference.h>
+#include <Config_WidgetAPI.h>
+
+#include <GeomAPI_Shape.h>
+
+#include <TopoDS_Shape.hxx>
+#include <TopExp_Explorer.hxx>
+
+#include <QWidget>
+#include <QLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QToolButton>
+#include <QString>
+#include <QEvent>
+#include <QDockWidget>
+
+
+typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
+static ShapeTypes MyShapeTypes;
+
+TopAbs_ShapeEnum ModuleBase_WidgetSelector::shapeType(const QString& theType)
+{
+  if (MyShapeTypes.count() == 0) {
+    MyShapeTypes["face"] = TopAbs_FACE;
+    MyShapeTypes["vertex"] = TopAbs_VERTEX;
+    MyShapeTypes["wire"] = TopAbs_WIRE;
+    MyShapeTypes["edge"] = TopAbs_EDGE;
+    MyShapeTypes["shell"] = TopAbs_SHELL;
+    MyShapeTypes["solid"] = TopAbs_SOLID;
+  }
+  if (MyShapeTypes.contains(theType)) 
+    return MyShapeTypes[theType];
+  throw std::invalid_argument("Shape type defined in XML is not implemented!");
+}
+
+
+
+
+ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent, 
+                                                     ModuleBase_IWorkshop* theWorkshop, 
+                                                     const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop), myActivateOnStart(false)
+{
+  myContainer = new QWidget(theParent);
+  QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
+
+  aLayout->setContentsMargins(0, 0, 0, 0);
+  QString aLabelText = QString::fromStdString(theData->widgetLabel());
+  QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+  myLabel = new QLabel(aLabelText, myContainer);
+  myLabel->setPixmap(QPixmap(aLabelIcon));
+
+  aLayout->addWidget(myLabel);
+
+  QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+  myTextLine = new QLineEdit(myContainer);
+  myTextLine->setReadOnly(true);
+  myTextLine->setToolTip(aToolTip);
+  myTextLine->installEventFilter(this);
+
+  aLayout->addWidget(myTextLine);
+
+  myActivateBtn = new QToolButton(myContainer);
+  myActivateBtn->setIcon(QIcon(":icons/hand_point.png"));
+  myActivateBtn->setCheckable(true);
+  myActivateBtn->setToolTip(tr("Activate/Deactivate selection"));
+  connect(myActivateBtn, SIGNAL(toggled(bool)), this, SLOT(activateSelection(bool)));
+
+  aLayout->addWidget(myActivateBtn);
+
+  QString aActivateTxt = QString::fromStdString(theData->getProperty("activate"));
+  if (!aActivateTxt.isNull()) {
+    myActivateOnStart = (aActivateTxt == "true");
+  }
+
+  std::string aTypes = theData->getProperty("shape_types");
+  myShapeTypes = QString(aTypes.c_str()).split(',');
+}
+
+//********************************************************************
+ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector()
+{
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::storeValue(FeaturePtr theFeature) const
+{
+  DataPtr aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
+
+  FeaturePtr aFeature = aRef->value();
+  if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
+    aRef->setValue(mySelectedFeature);
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+  }
+  return true;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::restoreValue(FeaturePtr theFeature)
+{
+  DataPtr aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
+
+  bool isBlocked = this->blockSignals(true);
+  mySelectedFeature = aRef->value();
+  updateSelectionName(); 
+
+  this->blockSignals(isBlocked);
+  return true;
+}
+
+//********************************************************************
+QList<QWidget*> ModuleBase_WidgetSelector::getControls() const
+{
+  QList<QWidget*> aControls;
+  aControls.append(myLabel);
+  aControls.append(myTextLine);
+  aControls.append(myActivateBtn);
+  return aControls;
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::onSelectionChanged()
+{
+  QList<FeaturePtr> aFeatures = myWorkshop->selectedFeatures();
+  if (aFeatures.size() > 0) {
+    FeaturePtr aFeature = aFeatures.first();
+    if ((!mySelectedFeature) && (!aFeature))
+      return;
+    if (mySelectedFeature && aFeature && mySelectedFeature->isSame(aFeature))
+      return;
+
+    // Check that the selection corresponds to selection type
+    if (!isAccepted(aFeature)) return;
+
+    mySelectedFeature = aFeature;
+    if (mySelectedFeature) {
+      updateSelectionName();
+      activateSelection(false);
+      raisePanel();
+    } else {
+      myTextLine->setText("");
+    }
+    emit valuesChanged();
+  }
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::isAccepted(const FeaturePtr theFeature) const
+{
+  boost::shared_ptr<GeomAPI_Shape> aShapePtr = theFeature->data()->shape();
+  if (!aShapePtr) return false;
+  TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+  if (aShape.IsNull()) return false;
+
+  TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
+  if (aShapeType == TopAbs_COMPOUND) {
+    foreach (QString aType, myShapeTypes) {
+      TopExp_Explorer aEx(aShape, shapeType(aType));
+      if (aEx.More())
+        return true;
+    }
+  } else {
+    foreach (QString aType, myShapeTypes) {
+      if (shapeType(aType) == aShapeType)
+        return true;
+    }
+  }
+  return false;
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::updateSelectionName()
+{
+  if (mySelectedFeature) {
+    std::string aName;
+    if (mySelectedFeature->data())
+      aName = mySelectedFeature->data()->getName();
+    else 
+      aName = boost::dynamic_pointer_cast<ModelAPI_Object>(mySelectedFeature)->getName();
+    myTextLine->setText(QString::fromStdString(aName));
+  } else 
+    myTextLine->setText("");
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+  if (theObj == myTextLine) {
+    if (theEvent->type() == QEvent::Polish) {
+      activateSelection(myActivateOnStart);
+      onSelectionChanged();
+    }
+  }
+  return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::enableOthersControls(bool toEnable) const
+{
+  QWidget* aParent = myContainer->parentWidget();
+  QList<QWidget*> aChldList = aParent->findChildren<QWidget*>();
+  foreach(QWidget* aWgt, aChldList) {
+    if ((aWgt != myLabel) && (aWgt != myActivateBtn) && (aWgt != myTextLine) && (aWgt != myContainer))
+      aWgt->setEnabled(toEnable);
+  }
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
+{
+  enableOthersControls(!toActivate);
+  myTextLine->setEnabled(toActivate);
+
+  if (toActivate)
+    connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+  else
+    disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+
+  myActivateBtn->setDown(toActivate);
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::raisePanel() const
+{
+  QWidget* aParent = myContainer->parentWidget();
+  QWidget* aLastPanel = 0;
+  while (!aParent->inherits("QDockWidget")) {
+    aLastPanel = aParent;
+    aParent = aParent->parentWidget();
+    if (!aParent) return;
+  }
+  if (aParent->inherits("QDockWidget")) {
+    QDockWidget* aTabWgt = (QDockWidget*) aParent;
+    aTabWgt->raise();
+  }
+}
\ No newline at end of file
diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h
new file mode 100644 (file)
index 0000000..0d411f3
--- /dev/null
@@ -0,0 +1,86 @@
+// File:        ModuleBase_WidgetSelector.h
+// Created:     2 June 2014
+// Author:      Vitaly Smetannikov
+
+#ifndef ModuleBase_WidgetSelector_H
+#define ModuleBase_WidgetSelector_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+#include <ModelAPI_Feature.h>
+
+#include <TopAbs_ShapeEnum.hxx>
+
+#include <QStringList>
+
+
+class Config_WidgetAPI;
+class QWidget;
+class QLabel;
+class QLineEdit;
+class QToolButton;
+class ModuleBase_IWorkshop;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetSelector: public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+public:
+  ModuleBase_WidgetSelector(QWidget* theParent, 
+                            ModuleBase_IWorkshop* theWorkshop, 
+                            const Config_WidgetAPI* theData);
+
+  virtual ~ModuleBase_WidgetSelector();
+
+  /// Saves the internal parameters to the given feature
+  /// \param theFeature a model feature to be changed
+  virtual bool storeValue(FeaturePtr theFeature) const;
+
+  virtual bool restoreValue(FeaturePtr theFeature);
+
+  /// Returns the internal parent wiget control, that can be shown anywhere
+  /// \returns the widget
+  QWidget* getControl() const { return myContainer; }
+
+  /// Returns list of widget controls
+  /// \return a control list
+  virtual QList<QWidget*> getControls() const;
+
+  void setActivationOnStart(bool toActivate) { myActivateOnStart = toActivate; }
+  bool activateOnStart() const { return myActivateOnStart; }
+
+  FeaturePtr selectedFeature() const { return mySelectedFeature; }
+
+public slots:
+
+  /// Activate or deactivate selection
+  void activateSelection(bool toActivate);
+
+protected:
+  bool eventFilter(QObject* theObj, QEvent* theEvent);
+
+private slots:
+  void onSelectionChanged();
+
+private:
+  void enableOthersControls(bool toEnable) const;
+  void updateSelectionName();
+  void raisePanel() const;
+  bool isAccepted(const FeaturePtr theFeature) const;
+
+  static TopAbs_ShapeEnum shapeType(const QString& theType);
+
+  QWidget*     myContainer;
+  QLabel*      myLabel;
+  QLineEdit*   myTextLine;
+  QToolButton* myActivateBtn;
+
+  ModuleBase_IWorkshop* myWorkshop;
+
+  bool myActivateOnStart;
+
+  FeaturePtr mySelectedFeature;
+  QStringList myShapeTypes;
+};
+
+#endif
\ No newline at end of file
index f038d3133a239c8d6e76c7188c4f0ed8cdf940fc..3ff0a00463a827badf234ed8c5de717103df3893 100644 (file)
@@ -269,8 +269,12 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage)
     std::set<FeaturePtr>::const_iterator aIt;
     for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
       FeaturePtr aFeature = (*aIt);
-      if (aFeature->getKind() != PARTSET_PART_KIND)
-        myDisplayer->redisplay(aFeature, false);
+      if (aFeature->getKind() != PARTSET_PART_KIND) {
+        if (myDisplayer->isVisible(aFeature))
+          myDisplayer->redisplay(aFeature, false);
+        else 
+          myDisplayer->display(aFeature, false);
+      }
     }
     myDisplayer->updateViewer();
   }