From 045e6d867c97a06a882b5834179ccf97fcaa7cf1 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 1 Dec 2016 12:45:03 +0300 Subject: [PATCH] Issue #1852 In the Sketcher, replace all disabled real inputs by labels --- src/Config/Config_Keywords.h | 1 + src/ModuleBase/CMakeLists.txt | 4 + src/ModuleBase/ModuleBase_LabelValue.cpp | 44 +++++++ src/ModuleBase/ModuleBase_LabelValue.h | 50 ++++++++ src/ModuleBase/ModuleBase_WidgetFactory.cpp | 3 + .../ModuleBase_WidgetLabelValue.cpp | 57 +++++++++ src/ModuleBase/ModuleBase_WidgetLabelValue.h | 43 +++++++ src/PartSet/PartSet_WidgetPoint2d.cpp | 110 +++++++++++------- src/PartSet/PartSet_WidgetPoint2d.h | 10 +- src/SketchPlugin/plugin-Sketch.xml | 15 ++- 10 files changed, 282 insertions(+), 55 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_LabelValue.cpp create mode 100644 src/ModuleBase/ModuleBase_LabelValue.h create mode 100644 src/ModuleBase/ModuleBase_WidgetLabelValue.cpp create mode 100644 src/ModuleBase/ModuleBase_WidgetLabelValue.h diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index a99495114..503215422 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -27,6 +27,7 @@ const static char* PROPERTY_PANEL_ID = "property_panel_id"; // Widgets const static char* WDG_INFO = "label"; const static char* WDG_DOUBLEVALUE = "doublevalue"; +const static char* WDG_DOUBLEVALUELABEL = "labelvalue"; const static char* WDG_INTEGERVALUE = "integervalue"; const static char* WDG_BOOLVALUE = "boolvalue"; const static char* WDG_STRINGVALUE = "stringvalue"; diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 7ff157483..e71e3501b 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -22,6 +22,7 @@ SET(PROJECT_HEADERS ModuleBase_IViewer.h ModuleBase_IWidgetCreator.h ModuleBase_IWorkshop.h + ModuleBase_LabelValue.h ModuleBase_ModelWidget.h ModuleBase_Operation.h ModuleBase_OperationAction.h @@ -53,6 +54,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetFileSelector.h ModuleBase_WidgetIntValue.h ModuleBase_WidgetLabel.h + ModuleBase_WidgetLabelValue.h ModuleBase_WidgetLineEdit.h ModuleBase_WidgetMultiSelector.h ModuleBase_WidgetOptionalBox.h @@ -84,6 +86,7 @@ SET(PROJECT_SOURCES ModuleBase_IViewer.cpp ModuleBase_IWidgetCreator.cpp ModuleBase_IWorkshop.cpp + ModuleBase_LabelValue.cpp ModuleBase_ModelWidget.cpp ModuleBase_Operation.cpp ModuleBase_OperationAction.cpp @@ -114,6 +117,7 @@ SET(PROJECT_SOURCES ModuleBase_WidgetFileSelector.cpp ModuleBase_WidgetIntValue.cpp ModuleBase_WidgetLabel.cpp + ModuleBase_WidgetLabelValue.cpp ModuleBase_WidgetLineEdit.cpp ModuleBase_WidgetMultiSelector.cpp ModuleBase_WidgetOptionalBox.cpp diff --git a/src/ModuleBase/ModuleBase_LabelValue.cpp b/src/ModuleBase/ModuleBase_LabelValue.cpp new file mode 100644 index 000000000..15ac0080e --- /dev/null +++ b/src/ModuleBase/ModuleBase_LabelValue.cpp @@ -0,0 +1,44 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_IWorkshop.cpp +// Created: 30 Nov 2016 +// Author: Natalia ERMOLAEVA + +#include +#include + +#include +#include + +ModuleBase_LabelValue::ModuleBase_LabelValue(QWidget* theParent, const QString& theText, + const QString& theToolTip, const QString& theIcon) +: QWidget(theParent) +{ + QHBoxLayout* aLayout = new QHBoxLayout(this); + aLayout->setContentsMargins(2, 0, 0, 0); + aLayout->setSpacing(0); + + myLabel = new QLabel(QString("%1 : ").arg(theText), this); + if (!theIcon.isEmpty()) { + myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(theIcon)); + aLayout->setSpacing(4); + } + myLabel->setToolTip(!theToolTip.isEmpty() ? theToolTip : theText); + aLayout->addWidget(myLabel); + + myLabelValue = new QLabel("", this); + aLayout->addWidget(myLabelValue, 1); + + aLayout->addStretch(1); +} + +ModuleBase_LabelValue::~ModuleBase_LabelValue() +{ +} + +void ModuleBase_LabelValue::setValue(const double theValue) +{ + myValue = theValue; + myLabelValue->setText(QString::number(theValue)); + myLabelValue->setToolTip(QString::number(theValue)); +} diff --git a/src/ModuleBase/ModuleBase_LabelValue.h b/src/ModuleBase/ModuleBase_LabelValue.h new file mode 100644 index 000000000..69e1df97b --- /dev/null +++ b/src/ModuleBase/ModuleBase_LabelValue.h @@ -0,0 +1,50 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_LabelValue.h +// Created: 30 Nov 2016 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_LabelValue_H +#define ModuleBase_LabelValue_H + +#include "ModuleBase.h" + +#include + +class QLabel; + +/** +* \ingroup GUI +* Implementation of model widget for a label control +*/ +class MODULEBASE_EXPORT ModuleBase_LabelValue : public QWidget +{ + Q_OBJECT +public: + /// Constructor + /// \param theParent the parent object + /// \param theText a text value + /// \param theToolTip a tool tip value + /// \param theIcon a icon value + ModuleBase_LabelValue(QWidget* theParent, const QString& theText, + const QString& theToolTip = "", + const QString& theIcon = ""); + + virtual ~ModuleBase_LabelValue(); + + /// Fills the label value with the given value + /// \param theValue a value + void setValue(const double theValue); + + /// Returns double value + /// \return the value + double value() const { return myValue; } + +protected: + QLabel* myLabel; ///< A label information control + QLabel* myLabelValue; ///< A label value control + + double myValue; ///< A cashed value to avoid a string conversion +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index d4c1b9ef4..c58af6149 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -286,6 +287,8 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std:: result = new ModuleBase_WidgetLabel(theParent, myWidgetApi); } else if (theType == WDG_DOUBLEVALUE) { result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi); + } else if (theType == WDG_DOUBLEVALUELABEL) { + result = new ModuleBase_WidgetLabelValue(theParent, myWidgetApi); } else if (theType == WDG_INTEGERVALUE) { result = new ModuleBase_WidgetIntValue(theParent, myWidgetApi); } else if (theType == WDG_SHAPE_SELECTOR) { diff --git a/src/ModuleBase/ModuleBase_WidgetLabelValue.cpp b/src/ModuleBase/ModuleBase_WidgetLabelValue.cpp new file mode 100644 index 000000000..aafbb4ba2 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetLabelValue.cpp @@ -0,0 +1,57 @@ +// Copyright (C) 2014-2016 CEA/DEN, EDF R&D + +// File: ModuleBase_WidgetLabelValue.cpp +// Created: 30 Nov 2016 +// Author: Natalia ERMOLAEVA + +#include "ModuleBase_WidgetLabelValue.h" + +#include +#include +#include + +#include + +#include +#include + +ModuleBase_WidgetLabelValue::ModuleBase_WidgetLabelValue(QWidget* theParent, + const Config_WidgetAPI* theData) +: ModuleBase_ModelWidget(theParent, theData) +{ + QVBoxLayout* aLayout = new QVBoxLayout(this); + aLayout->setContentsMargins(0, 0, 0, 0); + aLayout->setSpacing(0); + + QString aText = QString::fromStdString(theData->widgetLabel()); + QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); + QString aToolTip = QString::fromStdString(theData->widgetTooltip()); + + myLabel = new ModuleBase_LabelValue(theParent, aText, aToolTip, aLabelIcon); + aLayout->addWidget(myLabel); +} + +ModuleBase_WidgetLabelValue::~ModuleBase_WidgetLabelValue() +{ +} + +QList ModuleBase_WidgetLabelValue::getControls() const +{ + return QList(); +} + +bool ModuleBase_WidgetLabelValue::restoreValueCustom() +{ + DataPtr aData = myFeature->data(); + AttributeDoublePtr anAttribute = aData->real(attributeID()); + double aValue = 0; + if (anAttribute.get() && anAttribute->isInitialized()) + aValue = anAttribute->value(); + myLabel->setValue(aValue); + return true; +} + +bool ModuleBase_WidgetLabelValue::storeValueCustom() +{ + return true; +} diff --git a/src/ModuleBase/ModuleBase_WidgetLabelValue.h b/src/ModuleBase/ModuleBase_WidgetLabelValue.h new file mode 100644 index 000000000..f1fb4d6f9 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetLabelValue.h @@ -0,0 +1,43 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_WidgetLabelValue.h +// Created: 30 Nov 2016 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_WidgetLabelValue_H +#define ModuleBase_WidgetLabelValue_H + +#include "ModuleBase.h" +#include "ModuleBase_ModelWidget.h" + +class ModuleBase_LabelValue; + +/** +* \ingroup GUI +* Implementation of model widget for a label control +*/ +class MODULEBASE_EXPORT ModuleBase_WidgetLabelValue : public ModuleBase_ModelWidget +{ +Q_OBJECT + public: + /// Constructor + /// \param theParent the parent object + /// \param theData the widget configuation. The attribute of the model widget is obtained from + ModuleBase_WidgetLabelValue(QWidget* theParent, const Config_WidgetAPI* theData); + + virtual ~ModuleBase_WidgetLabelValue(); + + virtual bool restoreValueCustom(); + + virtual QList getControls() const; + +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValueCustom(); + +private: + ModuleBase_LabelValue* myLabel; ///< A label control +}; + +#endif diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index df82c9b5f..0abbeab32 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -90,33 +91,34 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, aGroupLay->setColumnStretch(1, 1); { QLabel* aLabel = new QLabel(myGroupBox); - aLabel->setText(tr("X ")); - aGroupLay->addWidget(aLabel, 0, 0); - - myXSpin = new ModuleBase_ParamSpinBox(myGroupBox); - myXSpin->setAcceptVariables(aAcceptVariables); - myXSpin->setMinimum(-DBL_MAX); - myXSpin->setMaximum(DBL_MAX); - myXSpin->setToolTip(tr("X")); + + myXSpin = new ModuleBase_LabelValue(myGroupBox, tr("X")); + //ModuleBase_ParamSpinBox(myGroupBox); + //myXSpin->setAcceptVariables(aAcceptVariables); + //myXSpin->setMinimum(-DBL_MAX); + //myXSpin->setMaximum(DBL_MAX); + //myXSpin->setToolTip(tr("X")); aGroupLay->addWidget(myXSpin, 0, 1); - connect(myXSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified())); - myXSpin->setValueEnabled(isValueEnabled()); + //connect(myXSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified())); + //myXSpin->setValueEnabled(isValueEnabled()); } { - QLabel* aLabel = new QLabel(myGroupBox); - aLabel->setText(tr("Y ")); - aGroupLay->addWidget(aLabel, 1, 0); - - myYSpin = new ModuleBase_ParamSpinBox(myGroupBox); - myYSpin->setAcceptVariables(aAcceptVariables); - myYSpin->setMinimum(-DBL_MAX); - myYSpin->setMaximum(DBL_MAX); - myYSpin->setToolTip(tr("Y")); + //QLabel* aLabel = new QLabel(myGroupBox); + //aLabel->setText(tr("Y ")); + //aGroupLay->addWidget(aLabel, 1, 0); + + myYSpin = new ModuleBase_LabelValue(myGroupBox, tr("Y")); + //ModuleBase_ParamSpinBox(myGroupBox); + //myYSpin = new ModuleBase_ParamSpinBox(myGroupBox); + //myYSpin->setAcceptVariables(aAcceptVariables); + //myYSpin->setMinimum(-DBL_MAX); + //myYSpin->setMaximum(DBL_MAX); + //myYSpin->setToolTip(tr("Y")); aGroupLay->addWidget(myYSpin, 1, 1); - connect(myYSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified())); - myYSpin->setValueEnabled(isValueEnabled()); + //connect(myYSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified())); + //myYSpin->setValueEnabled(isValueEnabled()); } QVBoxLayout* aLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aLayout); @@ -174,7 +176,7 @@ bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr bool PartSet_WidgetPoint2D::resetCustom() { bool aDone = false; - if (!isUseReset() || isComputedDefault() || myXSpin->hasVariable() || myYSpin->hasVariable()) { + if (!isUseReset() || isComputedDefault() /*|| myXSpin->hasVariable() || myYSpin->hasVariable()*/) { aDone = false; } else { @@ -189,8 +191,11 @@ bool PartSet_WidgetPoint2D::resetCustom() double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk); // it is important to block the spin box control in order to do not through out the // locking of the validating state. - ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0); - ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0); + myXSpin->setValue(isOk ? aDefValue : 0.0); + myYSpin->setValue(isOk ? aDefValue : 0.0); + + //ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0); + //ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0); storeValueCustom(); aDone = true; } @@ -225,7 +230,7 @@ bool PartSet_WidgetPoint2D::setSelection(QList& theValu void PartSet_WidgetPoint2D::selectContent() { - myXSpin->selectAll(); + // myXSpin->selectAll(); } bool PartSet_WidgetPoint2D::setPoint(double theX, double theY) @@ -235,8 +240,11 @@ bool PartSet_WidgetPoint2D::setPoint(double theX, double theY) if (fabs(theY) >= MaxCoordinate) return false; - ModuleBase_Tools::setSpinValue(myXSpin, theX); - ModuleBase_Tools::setSpinValue(myYSpin, theY); + myXSpin->setValue(theX); + myYSpin->setValue(theY); + + //ModuleBase_Tools::setSpinValue(myXSpin, theX); + //ModuleBase_Tools::setSpinValue(myYSpin, theY); storeValue(); return true; @@ -256,10 +264,11 @@ bool PartSet_WidgetPoint2D::storeValueCustom() // if text is not empty then setValue will be ignored // so we should set the text at first - aPoint->setText(myXSpin->hasVariable() ? myXSpin->text().toStdString() : "", - myYSpin->hasVariable() ? myYSpin->text().toStdString() : ""); - aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(), - !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y()); + //aPoint->setText(myXSpin->hasVariable() ? myXSpin->text().toStdString() : "", + // myYSpin->hasVariable() ? myYSpin->text().toStdString() : ""); + //aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(), + // !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y()); + aPoint->setValue(myXSpin->value(), myYSpin->value()); // after movement the solver will call the update event: optimization moveObject(myFeature); @@ -280,22 +289,26 @@ bool PartSet_WidgetPoint2D::restoreValueCustom() bool isDouble = false; double aVal = 0; if (aTextX.isEmpty()) { - ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x()); + myXSpin->setValue(aPoint->x()); + //ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x()); } else { aVal = aTextX.toDouble(&isDouble); - if (isDouble) + myXSpin->setValue(aVal); + /*if (isDouble) ModuleBase_Tools::setSpinValue(myXSpin, aVal); else - ModuleBase_Tools::setSpinText(myXSpin, aTextX); + ModuleBase_Tools::setSpinText(myXSpin, aTextX);*/ } if (aTextY.isEmpty()) { - ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y()); + myYSpin->setValue(aPoint->y()); + //ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y()); } else { aVal = aTextY.toDouble(&isDouble); - if (isDouble) - ModuleBase_Tools::setSpinValue(myYSpin, aVal); - else - ModuleBase_Tools::setSpinText(myYSpin, aTextY); + myYSpin->setValue(aVal); + //if (isDouble) + // ModuleBase_Tools::setSpinValue(myYSpin, aVal); + //else + // ModuleBase_Tools::setSpinText(myYSpin, aTextY); } //if (aTextX.empty() || aTextY.empty()) { // ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x()); @@ -310,8 +323,8 @@ bool PartSet_WidgetPoint2D::restoreValueCustom() void PartSet_WidgetPoint2D::storeCurentValue() { // do not use cash if a variable is used - if (myXSpin->hasVariable() || myYSpin->hasVariable()) - return; + //if (myXSpin->hasVariable() || myYSpin->hasVariable()) + // return; myValueIsCashed = true; myIsFeatureVisibleInCash = XGUI_Displayer::isVisible( @@ -329,8 +342,10 @@ bool PartSet_WidgetPoint2D::restoreCurentValue() myValueIsCashed = false; myIsFeatureVisibleInCash = true; - ModuleBase_Tools::setSpinValue(myXSpin, myXValueInCash); - ModuleBase_Tools::setSpinValue(myYSpin, myYValueInCash); + myXSpin->setValue(myXValueInCash); + myYSpin->setValue(myYValueInCash); + //ModuleBase_Tools::setSpinValue(myXSpin, myXValueInCash); + //ModuleBase_Tools::setSpinValue(myYSpin, myYValueInCash); // store value to the model storeValueCustom(); @@ -367,6 +382,10 @@ void PartSet_WidgetPoint2D::activateCustom() } } +void PartSet_WidgetPoint2D::setHighlighted(bool isHighlighted) +{ +} + void PartSet_WidgetPoint2D::deactivate() { // the value of the control should be stored to model if it was not @@ -667,7 +686,8 @@ void PartSet_WidgetPoint2D::initializeValueByActivate() bool PartSet_WidgetPoint2D::processEnter() { - bool isModified = getValueState() == ModifiedInPP; + return false; + /*bool isModified = getValueState() == ModifiedInPP; if (isModified) { bool isXModified = myXSpin->hasFocus(); emit valuesChanged(); @@ -676,7 +696,7 @@ bool PartSet_WidgetPoint2D::processEnter() else myYSpin->selectAll(); } - return isModified; + return isModified;*/ } bool PartSet_WidgetPoint2D::useSelectedShapes() const diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index a12e35d0f..ab56c058b 100755 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -22,6 +22,7 @@ class ModelAPI_Feature; class ModuleBase_IWorkshop; class ModuleBase_ParamSpinBox; class ModuleBase_IViewWindow; +class ModuleBase_LabelValue; class GeomAPI_Pnt2d; class ModuleBase_IWorkshop; @@ -138,6 +139,9 @@ protected: /// The methiod called when widget is activated virtual void activateCustom(); + //! Switch On/Off highlighting of the widget + virtual void setHighlighted(bool isHighlighted); + /// Returns true if the feature contains Point2D attribute with the same coordinates /// The attribute of the widget is not processed. /// \param theFeature a feature @@ -197,8 +201,10 @@ protected: private: QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets - ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate - ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate + //ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate + //ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate + ModuleBase_LabelValue* myXSpin; ///< the label for the X coordinate + ModuleBase_LabelValue* myYSpin; ///< the label for the Y coordinate /// value used as selection in mouse release method std::shared_ptr myPreSelected; diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index bc8d02f5b..b646f0ca3 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -31,7 +31,7 @@ enable_value="enable_by_preferences"/> - @@ -99,14 +99,13 @@ enable_value="enable_by_preferences"/> - - - + - + @@ -123,10 +122,10 @@ clear_in_neutral_point="false"> - - + -- 2.39.2