From 419821fe2eec493854537f34a21e290246b63dcf Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 2 Dec 2016 09:24:24 +0300 Subject: [PATCH] #1857 In the Sketcher, ability to zoom the view from a given size --- src/ModuleBase/ModuleBase_DoubleSpinBox.cpp | 9 ++--- src/ModuleBase/ModuleBase_LabelValue.cpp | 12 ++----- src/ModuleBase/ModuleBase_Tools.cpp | 12 +++++++ src/ModuleBase/ModuleBase_Tools.h | 6 ++++ src/PartSet/PartSet_WidgetSketchLabel.cpp | 38 +++++++++++++++++++++ src/PartSet/PartSet_WidgetSketchLabel.h | 3 ++ src/XGUI/XGUI_ViewerProxy.cpp | 12 +++---- 7 files changed, 70 insertions(+), 22 deletions(-) diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp index 090cf58f3..b5af3da54 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp @@ -4,6 +4,7 @@ // Author: Sergey TELKOV // #include "ModuleBase_DoubleSpinBox.h" +#include "ModuleBase_Tools.h" #include #include @@ -61,13 +62,7 @@ ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePr myCleared(false), myIsEmitKeyPressEvent(false) { - // VSR 01/07/2010: Disable thousands separator for spin box - // (to avoid inconsistency of double-2-string and string-2-double conversion) - QLocale loc; - loc.setNumberOptions(loc.numberOptions() | - QLocale::OmitGroupSeparator | - QLocale::RejectGroupSeparator); - setLocale(loc); + setLocale(ModuleBase_Tools::doubleLocale()); // MPV 15/09/2014: this must be set before setDecimals; // otherwise in release mode setDecimals may crash diff --git a/src/ModuleBase/ModuleBase_LabelValue.cpp b/src/ModuleBase/ModuleBase_LabelValue.cpp index 46cf12aee..30144d6a9 100644 --- a/src/ModuleBase/ModuleBase_LabelValue.cpp +++ b/src/ModuleBase/ModuleBase_LabelValue.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -31,14 +32,7 @@ ModuleBase_LabelValue::ModuleBase_LabelValue(QWidget* theParent, const QString& myLabelValue = new QLabel("", this); aLayout->addWidget(myLabelValue, 1); - // VSR 01/07/2010: Disable thousands separator for spin box - // (to avoid inconsistency of double-2-string and string-2-double conversion) - QLocale loc; - loc.setNumberOptions(loc.numberOptions() | - QLocale::OmitGroupSeparator | - QLocale::RejectGroupSeparator); - setLocale(loc); - + setLocale(ModuleBase_Tools::doubleLocale()); aLayout->addStretch(1); } @@ -52,5 +46,5 @@ void ModuleBase_LabelValue::setValue(const double theValue) QString aStrValue = locale().toString(theValue, myPrecision >= 0 ? 'f' : 'g', qAbs(myPrecision)); myLabelValue->setText(aStrValue); - myLabelValue->setToolTip(QString::number(theValue)); + myLabelValue->setToolTip(aStrValue); } diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 29a44fd5e..d8bd65675 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -965,6 +965,18 @@ QString wrapTextByWords(const QString& theValue, QWidget* theWidget, return aResult; } +//************************************************************** +QLocale doubleLocale() +{ + // VSR 01/07/2010: Disable thousands separator for spin box + // (to avoid inconsistency of double-2-string and string-2-double conversion) + QLocale aLocale; + aLocale.setNumberOptions(aLocale.numberOptions() | + QLocale::OmitGroupSeparator | + QLocale::RejectGroupSeparator); + return aLocale; +} + //************************************************************** void refsToFeatureInFeatureDocument(const ObjectPtr& theObject, std::set& theRefFeatures) diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 1f53c21b8..44e492df3 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -22,6 +22,7 @@ #include #include +#include #include @@ -254,6 +255,11 @@ MODULEBASE_EXPORT void blockUpdateViewer(const bool theValue); MODULEBASE_EXPORT QString wrapTextByWords(const QString& theValue, QWidget* theWidget, int theMaxLineInPixels = 150); +/// Generates a locale to disable thousands separator for spin box +/// (to avoid inconsistency of double-2-string and string-2-double conversion) +/// \return locale +MODULEBASE_EXPORT QLocale doubleLocale(); + /// Returns a container of referenced feature to the current object in the object document. /// \param theObject an object, which will be casted to a feature type /// \param theRefFeatures an output container diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 702fb6a11..f5f14e8f6 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -51,11 +52,17 @@ #include #include #include +#include #include #include #include #include +#include +#include +#ifndef DBL_MAX +#define DBL_MAX 1.7976931348623158e+308 +#endif PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, @@ -73,6 +80,18 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, // Define label for plane selection QWidget* aFirstWgt = new QWidget(this); + // Size of the View control + mySizeOfViewWidget = new QWidget(aFirstWgt); + QHBoxLayout* aSizeLayout = new QHBoxLayout(mySizeOfViewWidget); + aSizeLayout->addWidget(new QLabel("Size of the view", aFirstWgt)); + mySizeOfView = new QLineEdit(aFirstWgt); + + QDoubleValidator* aValidator = new QDoubleValidator(0, DBL_MAX, 12, mySizeOfView); + aValidator->setLocale(ModuleBase_Tools::doubleLocale()); + aValidator->setNotation(QDoubleValidator::StandardNotation); + mySizeOfView->setValidator(aValidator); + aSizeLayout->addWidget(mySizeOfView); + QString aText = QString::fromStdString(theData->getProperty("title")); QLabel* aLabel = new QLabel(aText, aFirstWgt); aLabel->setWordWrap(true); @@ -82,6 +101,7 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, aLayout = new QVBoxLayout(aFirstWgt); ModuleBase_Tools::zeroMargins(aLayout); + aLayout->addWidget(mySizeOfViewWidget); aLayout->addWidget(aLabel); myStackWidget->addWidget(aFirstWgt); @@ -279,6 +299,20 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs if (aModule) aModule->onViewTransformed(); } + QString aSizeOfViewStr = mySizeOfView->text(); + if (!aSizeOfViewStr.isEmpty()) { + bool isOk; + double aSizeOfView = aSizeOfViewStr.toDouble(&isOk); + if (isOk && aSizeOfView > 0) { + Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView(); + if (!aView3d.IsNull()) { + Bnd_Box aBndBox; + double aHalfSize = aSizeOfView/2.0; + aBndBox.Update(-aHalfSize, -aHalfSize, -aHalfSize, aHalfSize, aHalfSize, aHalfSize); + aView3d->FitAll(aBndBox, 0.01, false); + } + } + } } // 3. Clear text in the label myStackWidget->setCurrentIndex(1); @@ -436,7 +470,11 @@ void PartSet_WidgetSketchLabel::activateCustom() if (!aBodyIsVisualized) { // We have to select a plane before any operation myPreviewPlanes->showPreviewPlanes(myWorkshop); + mySizeOfViewWidget->setVisible(true); } + else + mySizeOfViewWidget->setVisible(false); + activateSelection(true); //myLabel->setText(myText); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 526207a8a..2f0c09808 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -27,6 +27,7 @@ class XGUI_OperationMgr; class XGUI_Workshop; class QCheckBox; class QStackedWidget; +class QLineEdit; /** * \ingroup Modules @@ -182,7 +183,9 @@ private: QMap myShowConstraints; + QWidget* mySizeOfViewWidget; QStackedWidget* myStackWidget; + QLineEdit* mySizeOfView; }; #endif diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index a504708cf..770494651 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -12,11 +12,11 @@ #include #endif -#ifdef VINSPECTOR -#include -#include +#ifdef VINSPECTOR +#include +#include -static bool FirstCall = true; +static bool FirstCall = true; #endif @@ -50,8 +50,8 @@ Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const aContext = myWorkshop->mainWindow()->viewer()->AISContext(); #endif -#ifdef VINSPECTOR - if (FirstCall) { +#ifdef VINSPECTOR + if (FirstCall) { VInspectorAPI_PluginMgr::activateVInspector("VInspector.dll", aContext); FirstCall = false; } -- 2.30.2