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
<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"
<source>
- <selector id="extrusion_face"
+ <shape_selector id="extrusion_face"
label="Select a face"
icon=":icons/sketch.png"
tooltip="Select a face for extrusion"
ModuleBase_WidgetFeatureOrAttribute.h
ModuleBase_WidgetPoint2D.h
ModuleBase_WidgetSwitch.h
- ModuleBase_WidgetSelector.h
+ ModuleBase_WidgetShapeSelector.h
ModuleBase_IWorkshop.h
ModuleBase_WidgetPoint2dDistance.h
ModuleBase_WidgetValue.h
ModuleBase_WidgetFeatureOrAttribute.cpp
ModuleBase_WidgetPoint2D.cpp
ModuleBase_WidgetSwitch.cpp
- ModuleBase_WidgetSelector.cpp
+ ModuleBase_WidgetShapeSelector.cpp
ModuleBase_WidgetPoint2dDistance.cpp
ModuleBase_WidgetValue.cpp
ModuleBase_WidgetValueFeature.cpp
#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>
} 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);
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();
}
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);
+}
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);
+++ /dev/null
-// 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;
-}
+++ /dev/null
-// 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
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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