From: nds Date: Fri, 2 Dec 2016 07:01:31 +0000 (+0300) Subject: #1857 In the Sketcher, ability to zoom the view from a given size X-Git-Tag: V_2.6.0~25 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5320c0c8deb3e7a5a53dbc422207cc711b4726d1;p=modules%2Fshaper.git #1857 In the Sketcher, ability to zoom the view from a given size Correction for Nested Sketch operation (e.g. in Extrusion feature) --- diff --git a/src/PartSet/PartSet_PreviewPlanes.cpp b/src/PartSet/PartSet_PreviewPlanes.cpp index 32126f2cb..344f20ed9 100755 --- a/src/PartSet/PartSet_PreviewPlanes.cpp +++ b/src/PartSet/PartSet_PreviewPlanes.cpp @@ -73,6 +73,13 @@ bool PartSet_PreviewPlanes::hasVisualizedSketch(ModuleBase_IWorkshop* theWorksho return aSketchIsVisualized; } +bool PartSet_PreviewPlanes::isPreviewShape(std::shared_ptr theShape) +{ + return (myYZPlane->getShape()->isEqual(theShape) || + myXZPlane->getShape()->isEqual(theShape) || + myXYPlane->getShape()->isEqual(theShape)); +} + void PartSet_PreviewPlanes::erasePreviewPlanes(ModuleBase_IWorkshop* theWorkshop) { if (myPreviewDisplayed) { diff --git a/src/PartSet/PartSet_PreviewPlanes.h b/src/PartSet/PartSet_PreviewPlanes.h index e6ee2b9df..955f5dcf2 100755 --- a/src/PartSet/PartSet_PreviewPlanes.h +++ b/src/PartSet/PartSet_PreviewPlanes.h @@ -47,6 +47,11 @@ public: /// \return boolean value bool isPreviewDisplayed() const { return myPreviewDisplayed; } + /// Returns true if the shape is one of the preview shapes + /// \param theShape a shape to be checked + /// \return boolean value + bool isPreviewShape(std::shared_ptr theShape); + /// Erase preview planes /// \param theWorkshop the application workshop void erasePreviewPlanes(ModuleBase_IWorkshop* theWorkshop); diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index 8fb404255..6397b3cae 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -47,6 +47,7 @@ #include #include +#include //#include #include #include @@ -71,8 +72,22 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, QString aLabelText = QString::fromStdString(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); + // Size of the View control + mySizeOfViewWidget = new QWidget(this); + QHBoxLayout* aSizeLayout = new QHBoxLayout(mySizeOfViewWidget); + aSizeLayout->addWidget(new QLabel("Size of the view", mySizeOfViewWidget)); + mySizeOfView = new QLineEdit(mySizeOfViewWidget); + + QDoubleValidator* aValidator = new QDoubleValidator(0, DBL_MAX, 12, mySizeOfView); + aValidator->setLocale(ModuleBase_Tools::doubleLocale()); + aValidator->setNotation(QDoubleValidator::StandardNotation); + mySizeOfView->setValidator(aValidator); + aSizeLayout->addWidget(mySizeOfView); + myLabel = new QLabel(aLabelText, this); myLabel->setWordWrap(true); + + aLayout->addWidget(mySizeOfViewWidget); aLayout->addWidget(myLabel); aLayout->addStretch(1); @@ -201,7 +216,12 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec if (!aBodyIsVisualized && !aSketchIsVisualized) { // We have to select a plane before any operation myPreviewPlanes->showPreviewPlanes(myWorkshop); + mySizeOfViewWidget->setVisible(true); } + else { + mySizeOfViewWidget->setVisible(false); + } + } else { bool aHidePreview = myPreviewPlanes->isPreviewDisplayed(); myPreviewPlanes->erasePreviewPlanes(myWorkshop); @@ -322,7 +342,24 @@ bool PartSet_WidgetSketchCreator::startSketchOperation( return aSketchStarted; } aSketchStarted = true; - + // Set View size if a plane is selected + if (myPreviewPlanes->isPreviewDisplayed() && + myPreviewPlanes->isPreviewShape(aValue->shape())) { + 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); + } + } + } + } // manually deactivation because the widget was not activated as has no focus acceptin controls deactivate(); bool aHidePreview = myPreviewPlanes->isPreviewDisplayed(); diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index a4c6ef494..35fe3e04a 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -12,6 +12,7 @@ #include class QLabel; +class QLineEdit; class PartSet_Module; class ModuleBase_Operation; class ModuleBase_IWorkshop; @@ -152,6 +153,8 @@ private: /// to store selection and check validation bool myIsCustomAttribute; + QWidget* mySizeOfViewWidget;///< Size of view widget, visualized if preview planes are shown + QLineEdit* mySizeOfView; ///< Value of square of size of View /// Label of the widget QLabel* myLabel; diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index f5f14e8f6..e0417bc14 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -83,8 +83,8 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, // 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); + aSizeLayout->addWidget(new QLabel("Size of the view", mySizeOfViewWidget)); + mySizeOfView = new QLineEdit(mySizeOfViewWidget); QDoubleValidator* aValidator = new QDoubleValidator(0, DBL_MAX, 12, mySizeOfView); aValidator->setLocale(ModuleBase_Tools::doubleLocale()); @@ -103,6 +103,7 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_Tools::zeroMargins(aLayout); aLayout->addWidget(mySizeOfViewWidget); aLayout->addWidget(aLabel); + aLayout->addStretch(1); myStackWidget->addWidget(aFirstWgt); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 2f0c09808..b4606e57a 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -183,9 +183,9 @@ private: QMap myShowConstraints; - QWidget* mySizeOfViewWidget; + QWidget* mySizeOfViewWidget; ///< Size of view widget, visualized if preview planes are shown + QLineEdit* mySizeOfView; ///< Value of square of size of View QStackedWidget* myStackWidget; - QLineEdit* mySizeOfView; }; #endif