From: vsv Date: Tue, 3 Jun 2014 14:25:40 +0000 (+0400) Subject: Create Extrusion property panel. X-Git-Tag: V_0.4.4~333 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fdcf8f3f834a16b890b97f6b7668ab06b616d5ba;p=modules%2Fshaper.git Create Extrusion property panel. --- diff --git a/src/ConstructionPlugin/extrusion_widget.xml b/src/ConstructionPlugin/extrusion_widget.xml index 52cf8622f..ed08edc35 100644 --- a/src/ConstructionPlugin/extrusion_widget.xml +++ b/src/ConstructionPlugin/extrusion_widget.xml @@ -3,6 +3,7 @@ label="Select a face" icon=":icons/sketch.png" tooltip="Select a face for extrusion" + activate="true" /> diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index bd726461f..6d7955f4b 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -58,7 +58,7 @@ public: /// Returns true if feature refers to the same model data instance MODELAPI_EXPORT virtual bool isSame(const boost::shared_ptr& theFeature) - {return true;} + {return theFeature.get() == this;} /// To virtually destroy the fields of successors virtual ~ModelAPI_Feature() {} diff --git a/src/ModuleBase/ModuleBase_SelectorWidget.cpp b/src/ModuleBase/ModuleBase_SelectorWidget.cpp index 931c3be6c..f47911d83 100644 --- a/src/ModuleBase/ModuleBase_SelectorWidget.cpp +++ b/src/ModuleBase/ModuleBase_SelectorWidget.cpp @@ -7,6 +7,7 @@ #include "ModuleBase_IWorkshop.h" #include +#include #include #include @@ -15,12 +16,14 @@ #include #include #include +#include +#include ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent), myWorkshop(theWorkshop) +: ModuleBase_ModelWidget(theParent), myWorkshop(theWorkshop), myActivateOnStart(false) { myFeatureAttributeID = theData->widgetId(); @@ -39,6 +42,7 @@ ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent, myTextLine = new QLineEdit(myContainer); myTextLine->setReadOnly(true); myTextLine->setToolTip(aToolTip); + myTextLine->installEventFilter(this); aLayout->addWidget(myTextLine); @@ -46,10 +50,14 @@ ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent, 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); - connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + QString aActivateTxt = QString::fromStdString(theData->getProperty("activate")); + if (!aActivateTxt.isNull()) { + myActivateOnStart = (aActivateTxt == "true"); + } } //******************************************************************** @@ -64,6 +72,8 @@ bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature) boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); + aRef->setFeature(mySelectedFeature); + return true; } @@ -73,7 +83,9 @@ bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature) DataPtr aData = theFeature->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); - + + mySelectedFeature = aRef->value(); + updateSelectionName(); return true; } @@ -102,5 +114,73 @@ QList ModuleBase_SelectorWidget::getControls() const void ModuleBase_SelectorWidget::onSelectionChanged() { QList aFeatures = myWorkshop->selectedFeatures(); - int aCount = aFeatures.size(); + 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 + mySelectedFeature = aFeature; + if (mySelectedFeature) { + updateSelectionName(); + activateSelection(false); + } 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(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) +{ + 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_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); } \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_SelectorWidget.h b/src/ModuleBase/ModuleBase_SelectorWidget.h index cf3468a3f..61d71c415 100644 --- a/src/ModuleBase/ModuleBase_SelectorWidget.h +++ b/src/ModuleBase/ModuleBase_SelectorWidget.h @@ -49,10 +49,26 @@ public: /// \return a control list virtual QList 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); + void updateSelectionName(); + std::string myFeatureAttributeID; QWidget* myContainer; @@ -61,6 +77,10 @@ private: QToolButton* myActivateBtn; ModuleBase_IWorkshop* myWorkshop; + + bool myActivateOnStart; + + FeaturePtr mySelectedFeature; }; #endif \ No newline at end of file