]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Widget selector renamed to shape selector
authorsbh <sergey.belash@opencascade.com>
Mon, 22 Sep 2014 05:52:25 +0000 (09:52 +0400)
committersbh <sergey.belash@opencascade.com>
Mon, 22 Sep 2014 05:52:25 +0000 (09:52 +0400)
src/Config/Config_Keywords.h
src/FeaturesPlugin/boolean_widget.xml
src/FeaturesPlugin/extrusion_widget.xml
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/ModuleBase/ModuleBase_WidgetSelector.cpp [deleted file]
src/ModuleBase/ModuleBase_WidgetSelector.h [deleted file]
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetShapeSelector.h [new file with mode: 0644]

index 8fbcd49a3bf85fe8932612ff718675b37f72f802..37acefda536fd7f8f6e2cebc9571cff9a8ca862a 100644 (file)
@@ -28,7 +28,7 @@ const static char* WDG_TOOLBOX = "toolbox";
 const static char* WDG_TOOLBOX_BOX = "box";
 const static char* WDG_SWITCH = "switch";
 const static char* WDG_SWITCH_CASE = "case";
-const static char* WDG_SELECTOR = "selector";
+const static char* WDG_SHAPE_SELECTOR = "shape_selector";
 const static char* WDG_CHOICE = "choice";
 
 //Specific widgets
index c80856f292c898b922914831e6cbcb1410514dca..cdf8e195ef0b7b990725039730beec66023b5361 100644 (file)
@@ -1,11 +1,11 @@
 <source>
-  <selector id="main_object" 
+  <shape_selector id="main_object" 
     label="Main object" 
     icon=":icons/cut_shape.png" 
     tooltip="Select an object to cut"
     shape_types="solid shell"
   />
-  <selector id="tool_object" 
+  <shape_selector id="tool_object" 
     label="Tool object" 
     icon=":icons/cut_tool.png" 
     tooltip="Select a tool"
index 795db94f0ae424c825e0c658f6d90a463ecf7db5..698905a7fd4a7f9f588c6f043518fbe679eceed5 100644 (file)
@@ -1,5 +1,5 @@
 <source>
-  <selector id="extrusion_face" 
+  <shape_selector id="extrusion_face" 
     label="Select a face" 
     icon=":icons/sketch.png" 
     tooltip="Select a face for extrusion"
index 9dd78b5823b29cce47290457c346ef335561cb2a..4c06e43e343bbef524503c91f54c8504c457de47 100644 (file)
@@ -16,7 +16,7 @@ SET(PROJECT_HEADERS
        ModuleBase_WidgetFeatureOrAttribute.h
        ModuleBase_WidgetPoint2D.h
        ModuleBase_WidgetSwitch.h
-       ModuleBase_WidgetSelector.h
+       ModuleBase_WidgetShapeSelector.h
        ModuleBase_IWorkshop.h
        ModuleBase_WidgetPoint2dDistance.h
        ModuleBase_WidgetValue.h
@@ -43,7 +43,7 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetFeatureOrAttribute.cpp
        ModuleBase_WidgetPoint2D.cpp
        ModuleBase_WidgetSwitch.cpp
-       ModuleBase_WidgetSelector.cpp
+       ModuleBase_WidgetShapeSelector.cpp
        ModuleBase_WidgetPoint2dDistance.cpp
        ModuleBase_WidgetValue.cpp
        ModuleBase_WidgetValueFeature.cpp       
index 0da092c300e1121ba9509b7dbe05a0a064c081dc..90886145f12e9b8e18b2f1b6c9ca5e8b96df6eeb 100644 (file)
@@ -14,7 +14,7 @@
 #include <ModuleBase_WidgetFeature.h>
 #include <ModuleBase_WidgetEditor.h>
 #include <ModuleBase_WidgetSwitch.h>
-#include <ModuleBase_WidgetSelector.h>
+#include <ModuleBase_WidgetShapeSelector.h>
 #include <ModuleBase_WidgetDoubleValue.h>
 #include <ModuleBase_WidgetBoolValue.h>
 #include <ModuleBase_WidgetPoint2dDistance.h>
@@ -125,8 +125,8 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType
   } else if (theType == WDG_INFO) {
     result = labelControl(theParent);
 
-  } else if (theType == WDG_SELECTOR) {
-    result = selectorControl(theParent);
+  } else if (theType == WDG_SHAPE_SELECTOR) {
+    result = shapeSelectorControl(theParent);
 
   } else if (theType == WDG_BOOLVALUE) {
     result = booleanControl(theParent);
@@ -186,85 +186,65 @@ QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, Q
 
 QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent)
 {
-  ModuleBase_WidgetDoubleValue* aDblWgt = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi,
-                                                                           myParentId);
+  ModuleBase_WidgetDoubleValue* aDblWgt =
+      new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId);
   myModelWidgets.append(aDblWgt);
-
   return aDblWgt->getControl();
 }
 
 QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent)
 {
-  ModuleBase_WidgetPoint2D* aWidget = new ModuleBase_WidgetPoint2D(theParent, myWidgetApi,
-                                                                   myParentId);
+  ModuleBase_WidgetPoint2D* aWidget =
+      new ModuleBase_WidgetPoint2D(theParent, myWidgetApi,myParentId);
   myModelWidgets.append(aWidget);
   return aWidget->getControl();
 }
 
 QWidget* ModuleBase_WidgetFactory::featureSelectorControl(QWidget* theParent)
 {
-  ModuleBase_WidgetFeature* aWidget = new ModuleBase_WidgetFeature(theParent, myWidgetApi,
-                                                                   myParentId);
+  ModuleBase_WidgetFeature* aWidget =
+      new ModuleBase_WidgetFeature(theParent, myWidgetApi,myParentId);
   myModelWidgets.append(aWidget);
   return aWidget->getControl();
 }
 
 QWidget* ModuleBase_WidgetFactory::featureOrAttributeSelectorControl(QWidget* theParent)
 {
-  ModuleBase_WidgetFeatureOrAttribute* aWidget = new ModuleBase_WidgetFeatureOrAttribute(
-      theParent, myWidgetApi, myParentId);
+  ModuleBase_WidgetFeatureOrAttribute* aWidget =
+      new ModuleBase_WidgetFeatureOrAttribute(theParent, myWidgetApi, myParentId);
   myModelWidgets.append(aWidget);
   return aWidget->getControl();
 }
 
 QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent)
 {
-  ModuleBase_WidgetEditor* aWidget = new ModuleBase_WidgetEditor(theParent, myWidgetApi,
-                                                                 myParentId);
+  ModuleBase_WidgetEditor* aWidget =
+      new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId);
   myModelWidgets.append(aWidget);
   return aWidget->getControl();
 }
 
-QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
-{
-  return QString::fromStdString(theStdString);
-}
-
-bool ModuleBase_WidgetFactory::isInternalWidget(const std::string& theType)
-{
-  std::string prop = myWidgetApi->getProperty(FEATURE_INTERNAL);
-
-  std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
-  if (prop.empty() || prop == "false" || prop == "0") {
-    return false;
-  }
-  return true;
-}
-
-QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent)
+QWidget* ModuleBase_WidgetFactory::shapeSelectorControl(QWidget* theParent)
 {
-  ModuleBase_WidgetSelector* aSelector = new ModuleBase_WidgetSelector(theParent, myWorkshop,
-                                                                       myWidgetApi, myParentId);
+  ModuleBase_WidgetShapeSelector* aSelector =
+      new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
   myModelWidgets.append(aSelector);
   return aSelector->getControl();
 }
 
 QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent)
 {
-  ModuleBase_WidgetBoolValue* aBoolWgt = new ModuleBase_WidgetBoolValue(theParent, myWidgetApi,
-                                                                        myParentId);
+  ModuleBase_WidgetBoolValue* aBoolWgt =
+      new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId);
   myModelWidgets.append(aBoolWgt);
-
   return aBoolWgt->getControl();
 }
 
 QWidget* ModuleBase_WidgetFactory::point2dDistanceControl(QWidget* theParent)
 {
-  ModuleBase_WidgetPoint2dDistance* aDistWgt = new ModuleBase_WidgetPoint2dDistance(theParent,
-                                                                                    myWidgetApi,
-                                                                                    myParentId);
+  ModuleBase_WidgetPoint2dDistance* aDistWgt =
+      new ModuleBase_WidgetPoint2dDistance(theParent, myWidgetApi, myParentId);
   myModelWidgets.append(aDistWgt);
-
   return aDistWgt->getControl();
 }
 
@@ -273,16 +253,29 @@ QWidget* ModuleBase_WidgetFactory::fileSelectorControl(QWidget* theParent)
   ModuleBase_WidgetFileSelector* aFileSelectorWgt =
       new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId);
   myModelWidgets.append(aFileSelectorWgt);
-
   return aFileSelectorWgt->getControl();
 }
 
 QWidget* ModuleBase_WidgetFactory::choiceControl(QWidget* theParent)
 {
-  ModuleBase_WidgetChoice* aChoiceWgt = new ModuleBase_WidgetChoice(theParent, myWidgetApi,
-                                                                        myParentId);
+  ModuleBase_WidgetChoice* aChoiceWgt =
+      new ModuleBase_WidgetChoice(theParent, myWidgetApi,myParentId);
   myModelWidgets.append(aChoiceWgt);
-
   return aChoiceWgt->getControl();
 }
 
+bool ModuleBase_WidgetFactory::isInternalWidget(const std::string& theType)
+{
+  std::string prop = myWidgetApi->getProperty(FEATURE_INTERNAL);
+
+  std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
+  if (prop.empty() || prop == "false" || prop == "0") {
+    return false;
+  }
+  return true;
+}
+
+QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
+{
+  return QString::fromStdString(theStdString);
+}
index 1b9e031bf7fcad51a7de5b74c8abae0481181b10..320e88f95ccd602e6dc2aef3d42ec4491a1a3944 100644 (file)
@@ -36,14 +36,14 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory
  protected:
   //Widgets
   QWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL);
+  QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
   QWidget* labelControl(QWidget* theParent);
   QWidget* doubleSpinBoxControl(QWidget* theParent);
   QWidget* pointSelectorControl(QWidget* theParent);
   QWidget* featureSelectorControl(QWidget* theParent);
   QWidget* featureOrAttributeSelectorControl(QWidget* theParent);
   QWidget* doubleValueEditor(QWidget* theParent);
-  QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
-  QWidget* selectorControl(QWidget* theParent);
+  QWidget* shapeSelectorControl(QWidget* theParent);
   QWidget* booleanControl(QWidget* theParent);
   QWidget* point2dDistanceControl(QWidget* theParent);
   QWidget* fileSelectorControl(QWidget* theParent);
diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp
deleted file mode 100644 (file)
index f5b5af3..0000000
+++ /dev/null
@@ -1,263 +0,0 @@
-// File:        ModuleBase_WidgetSelector.h
-// Created:     2 June 2014
-// Author:      Vitaly Smetannikov
-
-#include "ModuleBase_WidgetSelector.h"
-#include "ModuleBase_IWorkshop.h"
-
-#include <Events_Loop.h>
-#include <ModelAPI_Events.h>
-#include <ModelAPI_Tools.h>
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_Result.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>
-
-#include <stdexcept>
-
-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,
-                                                     const std::string& theParentId)
-    : ModuleBase_ModelWidget(theParent, theData, theParentId),
-      myWorkshop(theWorkshop)
-{
-  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);
-  if (!aLabelIcon.isEmpty())
-    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);
-
-  myBasePalet = myTextLine->palette();
-  myInactivePalet = myBasePalet;
-  myInactivePalet.setBrush(QPalette::Base, QBrush(Qt::gray, Qt::Dense6Pattern));
-  myTextLine->setPalette(myInactivePalet);
-
-  aLayout->addWidget(myTextLine, 1);
-
-  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);
-
-  std::string aTypes = theData->getProperty("shape_types");
-  myShapeTypes = QString(aTypes.c_str()).split(' ');
-}
-
-//********************************************************************
-ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector()
-{
-}
-
-//********************************************************************
-bool ModuleBase_WidgetSelector::storeValue() const
-{
-  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
-  if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
-    return false;
-
-  DataPtr aData = myFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeReference> aRef = boost::dynamic_pointer_cast<
-      ModelAPI_AttributeReference>(aData->attribute(attributeID()));
-
-  ObjectPtr aObject = aRef->value();
-  if (!(aObject && aObject->isSame(mySelectedObject))) {
-    aRef->setValue(mySelectedObject);
-    updateObject(myFeature);
-  }
-  return true;
-}
-
-//********************************************************************
-bool ModuleBase_WidgetSelector::restoreValue()
-{
-  DataPtr aData = myFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
-
-  bool isBlocked = this->blockSignals(true);
-  mySelectedObject = 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<ObjectPtr> aObjects = myWorkshop->selectedObjects();
-  if (aObjects.size() > 0) {
-    ObjectPtr aObject = aObjects.first();
-    if ((!mySelectedObject) && (!aObject))
-      return;
-    if (mySelectedObject && aObject && mySelectedObject->isSame(aObject))
-      return;
-
-    // Check that the selection corresponds to selection type
-    if (!isAccepted(aObject))
-      return;
-
-    mySelectedObject = aObject;
-    if (mySelectedObject) {
-      updateSelectionName();
-      myActivateBtn->setChecked(false);
-      raisePanel();
-    } else {
-      myTextLine->setText("");
-    }
-    emit valuesChanged();
-    emit focusOutWidget(this);
-  }
-}
-
-//********************************************************************
-bool ModuleBase_WidgetSelector::isAccepted(const ObjectPtr theResult) const
-{
-  ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theResult);
-  boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-  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 (mySelectedObject) {
-    std::string aName = mySelectedObject->data()->name();
-
-    myTextLine->setText(QString::fromStdString(aName));
-  } else
-    myTextLine->setText("");
-}
-
-//********************************************************************
-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)
-    myTextLine->setPalette(myBasePalet);
-  else
-    myTextLine->setPalette(myInactivePalet);
-
-  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();
-  }
-}
-
-//********************************************************************
-bool ModuleBase_WidgetSelector::focusTo()
-{
-  myActivateBtn->setChecked(true);
-  return true;
-}
diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h
deleted file mode 100644 (file)
index e39f97f..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-// 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_Object.h>
-
-#include <TopAbs_ShapeEnum.hxx>
-
-#include <QStringList>
-#include <QPalette>
-
-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, const std::string& theParentId);
-
-  virtual ~ModuleBase_WidgetSelector();
-
-  /// Saves the internal parameters to the given feature
-  /// \param theObject a model feature to be changed
-  virtual bool storeValue() const;
-
-  virtual bool restoreValue();
-
-  virtual bool focusTo();
-
-  /// 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;
-
-  ObjectPtr selectedFeature() const
-  {
-    return mySelectedObject;
-  }
-
- public slots:
-
-  /// Activate or deactivate selection
-  void activateSelection(bool toActivate);
-
- private slots:
-  void onSelectionChanged();
-
- private:
-  void enableOthersControls(bool toEnable) const;
-  void updateSelectionName();
-  void raisePanel() const;
-  bool isAccepted(const ObjectPtr theObject) const;
-
-  static TopAbs_ShapeEnum shapeType(const QString& theType);
-
-  QWidget* myContainer;
-  QLabel* myLabel;
-  QLineEdit* myTextLine;
-  QToolButton* myActivateBtn;
-
-  ModuleBase_IWorkshop* myWorkshop;
-
-  ObjectPtr mySelectedObject;
-  QStringList myShapeTypes;
-
-  QPalette myBasePalet;
-  QPalette myInactivePalet;
-};
-
-#endif
diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
new file mode 100644 (file)
index 0000000..3fe7211
--- /dev/null
@@ -0,0 +1,263 @@
+// File:        ModuleBase_WidgetShapeSelector.h
+// Created:     2 June 2014
+// Author:      Vitaly Smetannikov
+
+#include "ModuleBase_WidgetShapeSelector.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <Events_Loop.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Tools.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Result.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>
+
+#include <stdexcept>
+
+typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
+static ShapeTypes MyShapeTypes;
+
+TopAbs_ShapeEnum ModuleBase_WidgetShapeSelector::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_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,
+                                                     ModuleBase_IWorkshop* theWorkshop,
+                                                     const Config_WidgetAPI* theData,
+                                                     const std::string& theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId),
+      myWorkshop(theWorkshop)
+{
+  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);
+  if (!aLabelIcon.isEmpty())
+    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);
+
+  myBasePalet = myTextLine->palette();
+  myInactivePalet = myBasePalet;
+  myInactivePalet.setBrush(QPalette::Base, QBrush(Qt::gray, Qt::Dense6Pattern));
+  myTextLine->setPalette(myInactivePalet);
+
+  aLayout->addWidget(myTextLine, 1);
+
+  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);
+
+  std::string aTypes = theData->getProperty("shape_types");
+  myShapeTypes = QString(aTypes.c_str()).split(' ');
+}
+
+//********************************************************************
+ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
+{
+}
+
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::storeValue() const
+{
+  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
+  if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
+    return false;
+
+  DataPtr aData = myFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeReference> aRef = boost::dynamic_pointer_cast<
+      ModelAPI_AttributeReference>(aData->attribute(attributeID()));
+
+  ObjectPtr aObject = aRef->value();
+  if (!(aObject && aObject->isSame(mySelectedObject))) {
+    aRef->setValue(mySelectedObject);
+    updateObject(myFeature);
+  }
+  return true;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::restoreValue()
+{
+  DataPtr aData = myFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
+
+  bool isBlocked = this->blockSignals(true);
+  mySelectedObject = aRef->value();
+  updateSelectionName();
+
+  this->blockSignals(isBlocked);
+  return true;
+}
+
+//********************************************************************
+QList<QWidget*> ModuleBase_WidgetShapeSelector::getControls() const
+{
+  QList<QWidget*> aControls;
+  aControls.append(myLabel);
+  aControls.append(myTextLine);
+  aControls.append(myActivateBtn);
+  return aControls;
+}
+
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::onSelectionChanged()
+{
+  QList<ObjectPtr> aObjects = myWorkshop->selectedObjects();
+  if (aObjects.size() > 0) {
+    ObjectPtr aObject = aObjects.first();
+    if ((!mySelectedObject) && (!aObject))
+      return;
+    if (mySelectedObject && aObject && mySelectedObject->isSame(aObject))
+      return;
+
+    // Check that the selection corresponds to selection type
+    if (!isAccepted(aObject))
+      return;
+
+    mySelectedObject = aObject;
+    if (mySelectedObject) {
+      updateSelectionName();
+      myActivateBtn->setChecked(false);
+      raisePanel();
+    } else {
+      myTextLine->setText("");
+    }
+    emit valuesChanged();
+    emit focusOutWidget(this);
+  }
+}
+
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
+{
+  ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theResult);
+  boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
+  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_WidgetShapeSelector::updateSelectionName()
+{
+  if (mySelectedObject) {
+    std::string aName = mySelectedObject->data()->name();
+
+    myTextLine->setText(QString::fromStdString(aName));
+  } else
+    myTextLine->setText("");
+}
+
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::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_WidgetShapeSelector::activateSelection(bool toActivate)
+{
+  enableOthersControls(!toActivate);
+  //myTextLine->setEnabled(toActivate);
+  if (toActivate)
+    myTextLine->setPalette(myBasePalet);
+  else
+    myTextLine->setPalette(myInactivePalet);
+
+  if (toActivate)
+    connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+  else
+    disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+
+  myActivateBtn->setDown(toActivate);
+}
+
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::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();
+  }
+}
+
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::focusTo()
+{
+  myActivateBtn->setChecked(true);
+  return true;
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h
new file mode 100644 (file)
index 0000000..ffab7c6
--- /dev/null
@@ -0,0 +1,88 @@
+// File:        ModuleBase_WidgetShapeSelector.h
+// Created:     2 June 2014
+// Author:      Vitaly Smetannikov
+
+#ifndef ModuleBase_WidgetShapeSelector_H
+#define ModuleBase_WidgetShapeSelector_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+#include <ModelAPI_Object.h>
+
+#include <TopAbs_ShapeEnum.hxx>
+
+#include <QStringList>
+#include <QPalette>
+
+class Config_WidgetAPI;
+class QWidget;
+class QLabel;
+class QLineEdit;
+class QToolButton;
+class ModuleBase_IWorkshop;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_ModelWidget
+{
+Q_OBJECT
+ public:
+  ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+                            const Config_WidgetAPI* theData, const std::string& theParentId);
+
+  virtual ~ModuleBase_WidgetShapeSelector();
+
+  /// Saves the internal parameters to the given feature
+  /// \param theObject a model feature to be changed
+  virtual bool storeValue() const;
+
+  virtual bool restoreValue();
+
+  virtual bool focusTo();
+
+  /// 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;
+
+  ObjectPtr selectedFeature() const
+  {
+    return mySelectedObject;
+  }
+
+ public slots:
+
+  /// Activate or deactivate selection
+  void activateSelection(bool toActivate);
+
+ private slots:
+  void onSelectionChanged();
+
+ private:
+  void enableOthersControls(bool toEnable) const;
+  void updateSelectionName();
+  void raisePanel() const;
+  bool isAccepted(const ObjectPtr theObject) const;
+
+  static TopAbs_ShapeEnum shapeType(const QString& theType);
+
+  QWidget* myContainer;
+  QLabel* myLabel;
+  QLineEdit* myTextLine;
+  QToolButton* myActivateBtn;
+
+  ModuleBase_IWorkshop* myWorkshop;
+
+  ObjectPtr mySelectedObject;
+  QStringList myShapeTypes;
+
+  QPalette myBasePalet;
+  QPalette myInactivePalet;
+};
+
+#endif