]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#1857 In the Sketcher, ability to zoom the view from a given size
authornds <nds@opencascade.com>
Fri, 2 Dec 2016 07:01:31 +0000 (10:01 +0300)
committernds <nds@opencascade.com>
Fri, 2 Dec 2016 07:01:31 +0000 (10:01 +0300)
Correction for Nested Sketch operation (e.g. in Extrusion feature)

src/PartSet/PartSet_PreviewPlanes.cpp
src/PartSet/PartSet_PreviewPlanes.h
src/PartSet/PartSet_WidgetSketchCreator.cpp
src/PartSet/PartSet_WidgetSketchCreator.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h

index 32126f2cb992f798cae18b84b0e6cf72b93da96e..344f20ed9782150e08c95f572a50c3f22e9d1637 100755 (executable)
@@ -73,6 +73,13 @@ bool PartSet_PreviewPlanes::hasVisualizedSketch(ModuleBase_IWorkshop* theWorksho
   return aSketchIsVisualized;
 }
 
+bool PartSet_PreviewPlanes::isPreviewShape(std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  return (myYZPlane->getShape()->isEqual(theShape) ||
+          myXZPlane->getShape()->isEqual(theShape) ||
+          myXYPlane->getShape()->isEqual(theShape));
+}
+
 void PartSet_PreviewPlanes::erasePreviewPlanes(ModuleBase_IWorkshop* theWorkshop)
 {
   if (myPreviewDisplayed) {
index e6ee2b9df124136f6e31817de56067a59a769105..955f5dcf2516489ff81432f3b0c8949c6d012df8 100755 (executable)
@@ -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<GeomAPI_Shape> theShape);
+
   /// Erase preview planes
   /// \param theWorkshop the application workshop
   void erasePreviewPlanes(ModuleBase_IWorkshop* theWorkshop);
index 8fb4042553d6ce5f279c065970495e817f52d213..6397b3caefd7f54a00169ecd1e292b882f1209d1 100644 (file)
@@ -47,6 +47,7 @@
 
 #include <QLabel>
 #include <QLineEdit>
+#include <QDoubleValidator>
 //#include <QFormLayout>
 #include <QVBoxLayout>
 #include <QMessageBox>
@@ -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();
index a4c6ef494d35dabaa4b1741104a0e83d6c27bdde..35fe3e04a47e89499f3e03b246843e9e792d3bc7 100644 (file)
@@ -12,6 +12,7 @@
 #include <ModuleBase_WidgetSelector.h>
 
 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;
 
index f5f14e8f6cbe3e626528f1dede1e2b30378bf7bd..e0417bc142059ce3852349aea10a5c0c80af5a73 100644 (file)
@@ -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);
 
index 2f0c0980865c5d583b1a8669f8330460a66ea1f1..b4606e57af194d664e0b7a5d4baf850695388e07 100644 (file)
@@ -183,9 +183,9 @@ private:
 
   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> 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