From: sbh Date: Mon, 22 Sep 2014 05:52:25 +0000 (+0400) Subject: Widget selector renamed to shape selector X-Git-Tag: V_0.4.4~39 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2ff69695395d934619d400eca4bf151bde32bc03;p=modules%2Fshaper.git Widget selector renamed to shape selector --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 8fbcd49a3..37acefda5 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -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 diff --git a/src/FeaturesPlugin/boolean_widget.xml b/src/FeaturesPlugin/boolean_widget.xml index c80856f29..cdf8e195e 100644 --- a/src/FeaturesPlugin/boolean_widget.xml +++ b/src/FeaturesPlugin/boolean_widget.xml @@ -1,11 +1,11 @@ - - - #include #include -#include +#include #include #include #include @@ -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); +} diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index 1b9e031bf..320e88f95 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -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 index f5b5af3b1..000000000 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ /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 -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -typedef QMap 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 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 aRef = aData->reference(attributeID()); - - bool isBlocked = this->blockSignals(true); - mySelectedObject = aRef->value(); - updateSelectionName(); - - this->blockSignals(isBlocked); - return true; -} - -//******************************************************************** -QList ModuleBase_WidgetSelector::getControls() const -{ - QList aControls; - aControls.append(myLabel); - aControls.append(myTextLine); - aControls.append(myActivateBtn); - return aControls; -} - -//******************************************************************** -void ModuleBase_WidgetSelector::onSelectionChanged() -{ - QList 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(theResult); - boost::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); - if (!aShapePtr) - return false; - TopoDS_Shape aShape = aShapePtr->impl(); - 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 aChldList = aParent->findChildren(); - 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 index e39f97f32..000000000 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ /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 - -#include - -#include -#include - -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 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 index 000000000..3fe721135 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -0,0 +1,263 @@ +// File: ModuleBase_WidgetShapeSelector.h +// Created: 2 June 2014 +// Author: Vitaly Smetannikov + +#include "ModuleBase_WidgetShapeSelector.h" +#include "ModuleBase_IWorkshop.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +typedef QMap 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 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 aRef = aData->reference(attributeID()); + + bool isBlocked = this->blockSignals(true); + mySelectedObject = aRef->value(); + updateSelectionName(); + + this->blockSignals(isBlocked); + return true; +} + +//******************************************************************** +QList ModuleBase_WidgetShapeSelector::getControls() const +{ + QList aControls; + aControls.append(myLabel); + aControls.append(myTextLine); + aControls.append(myActivateBtn); + return aControls; +} + +//******************************************************************** +void ModuleBase_WidgetShapeSelector::onSelectionChanged() +{ + QList 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(theResult); + boost::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); + if (!aShapePtr) + return false; + TopoDS_Shape aShape = aShapePtr->impl(); + 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 aChldList = aParent->findChildren(); + 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 index 000000000..ffab7c6d8 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -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 + +#include + +#include +#include + +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 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