Salome HOME
#1857 In the Sketcher, ability to zoom the view from a given size
authornds <nds@opencascade.com>
Fri, 2 Dec 2016 06:24:24 +0000 (09:24 +0300)
committernds <nds@opencascade.com>
Fri, 2 Dec 2016 06:24:24 +0000 (09:24 +0300)
src/ModuleBase/ModuleBase_DoubleSpinBox.cpp
src/ModuleBase/ModuleBase_LabelValue.cpp
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_Tools.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h
src/XGUI/XGUI_ViewerProxy.cpp

index 090cf58f313f407e85842105dde7982de2254806..b5af3da5403a93398878c9f581c3f389e69242d5 100644 (file)
@@ -4,6 +4,7 @@
 // Author:    Sergey TELKOV
 //
 #include "ModuleBase_DoubleSpinBox.h"
+#include "ModuleBase_Tools.h"
 
 #include <QLineEdit>
 #include <QDoubleValidator>
@@ -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
index 46cf12aee5ca6a29a93d66cb18ac526f4b142e1f..30144d6a9db0b009143ca7b5dfc43d02193fb009 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <ModuleBase_LabelValue.h>
 #include <ModuleBase_IconFactory.h>
+#include <ModuleBase_Tools.h>
 
 #include <QHBoxLayout>
 #include <QLabel>
@@ -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);
 }
index 29a44fd5e02043c0602e3a877d54b8dc488d702b..d8bd656751fceb6eba0465c80f2f5cd67d771b62 100755 (executable)
@@ -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<FeaturePtr>& theRefFeatures)
index 1f53c21b8b0d96b6859a9e048132015b5616db56..44e492df369412e4ec02a1b8043cf0cff1dd34f7 100755 (executable)
@@ -22,6 +22,7 @@
 
 #include <QIcon>
 #include <QPixmap>
+#include <QLocale>
 
 #include <map>
 
@@ -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
index 702fb6a11a2de3e9bfe7f8b3728cde54a702b737..f5f14e8f6cbe3e626528f1dede1e2b30378bf7bd 100644 (file)
@@ -44,6 +44,7 @@
 #include <gp_Dir.hxx>
 #include <AIS_Shape.hxx>
 #include <AIS_DimensionSelectionMode.hxx>
+#include <Bnd_Box.hxx>
 
 #include <Config_WidgetAPI.h>
 #include <Config_PropManager.h>
 #include <QLabel>
 #include <QApplication>
 #include <QVBoxLayout>
+#include <QHBoxLayout>
 #include <QCheckBox>
 #include <QGroupBox>
 #include <QPushButton>
 #include <QStackedWidget>
+#include <QLineEdit>
+#include <QDoubleValidator>
 
+#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);
index 526207a8a3dd1a6574b1063569422991e617296e..2f0c0980865c5d583b1a8669f8330460a66ea1f1 100644 (file)
@@ -27,6 +27,7 @@ class XGUI_OperationMgr;
 class XGUI_Workshop;
 class QCheckBox;
 class QStackedWidget;
+class QLineEdit;
 
 /**
 * \ingroup Modules
@@ -182,7 +183,9 @@ private:
 
   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
 
+  QWidget* mySizeOfViewWidget;
   QStackedWidget* myStackWidget;
+  QLineEdit* mySizeOfView;
 };
 
 #endif
index a504708cf4fb4363b8e8ed45866cce1a245b2d16..770494651b3b8cfe85670dbf89110a01f1f51316 100644 (file)
   #include <AppElements_Viewer.h>
 #endif
 
-#ifdef VINSPECTOR\r
-#include <VInspectorAPI_PluginMgr.h>\r
-#include <VInspectorAPI_Communicator.h>\r
+#ifdef VINSPECTOR
+#include <VInspectorAPI_PluginMgr.h>
+#include <VInspectorAPI_Communicator.h>
 
-static bool FirstCall = true;\r
+static bool FirstCall = true;
 
 #endif
 
@@ -50,8 +50,8 @@ Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
   aContext = myWorkshop->mainWindow()->viewer()->AISContext();
 #endif
 
-#ifdef VINSPECTOR\r
-  if (FirstCall) {\r
+#ifdef VINSPECTOR
+  if (FirstCall) {
     VInspectorAPI_PluginMgr::activateVInspector("VInspector.dll", aContext);
     FirstCall = false;
   }