Salome HOME
Issue #1933:Set auxiliary presentation style
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.cpp
index a19b96a37ac9d41fc21da278b5df09ae03e4a416..e87806f74e8e236579e55c4ae75a7aafc7561495 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", 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);
+
   QString aText = QString::fromStdString(theData->getProperty("title"));
   QLabel* aLabel = new QLabel(aText, aFirstWgt);
   aLabel->setWordWrap(true);
@@ -82,7 +101,9 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
 
   aLayout = new QVBoxLayout(aFirstWgt);
   ModuleBase_Tools::zeroMargins(aLayout);
+  aLayout->addWidget(mySizeOfViewWidget);
   aLayout->addWidget(aLabel);
+  aLayout->addStretch(1);
 
   myStackWidget->addWidget(aFirstWgt);
 
@@ -97,7 +118,8 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
   myViewInverted = new QCheckBox(tr("Reversed"), aViewBox);
   aViewLayout->addWidget(myViewInverted);
 
-  QPushButton* aSetViewBtn = new QPushButton(QIcon(":icons/plane_view.png"), tr("Set plane view"), aViewBox);
+  QPushButton* aSetViewBtn =
+    new QPushButton(QIcon(":icons/plane_view.png"), tr("Set plane view"), aViewBox);
   connect(aSetViewBtn, SIGNAL(clicked(bool)), this, SLOT(onSetPlaneView()));
   aViewLayout->addWidget(aSetViewBtn);
 
@@ -209,8 +231,9 @@ void PartSet_WidgetSketchLabel::blockAttribute(const AttributePtr& theAttribute,
   }
 }
 
-bool PartSet_WidgetSketchLabel::setSelectionInternal(const QList<ModuleBase_ViewerPrsPtr>& theValues,
-                                                     const bool theToValidate)
+bool PartSet_WidgetSketchLabel::setSelectionInternal(
+                                          const QList<ModuleBase_ViewerPrsPtr>& theValues,
+                                          const bool theToValidate)
 {
   bool aDone = false;
   if (theValues.empty()) {
@@ -277,20 +300,32 @@ 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);
   //myLabel->setText("");
   //myLabel->setToolTip("");
   XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
-  disconnect(aWorkshop->selector(), SIGNAL(selectionChanged()), 
+  disconnect(aWorkshop->selector(), SIGNAL(selectionChanged()),
               this, SLOT(onSelectionChanged()));
   // 4. deactivate face selection filter
   activateFilters(false);
 
   // 5. Clear selection mode and define sketching mode
-  //XGUI_Displayer* aDisp = aWorkshop->displayer();
-  //aDisp->closeLocalContexts();
   emit planeSelected(plane());
   // after the plane is selected in the sketch, the sketch selection should be activated
   // it can not be performed in the sketch label widget because, we don't need to switch off
@@ -386,7 +421,7 @@ bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const FeaturePtr& the
 
   if (thePrs->object() && (theFeature != thePrs->object())) {
     DataPtr aData = theFeature->data();
-    AttributeSelectionPtr aSelAttr = 
+    AttributeSelectionPtr aSelAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
       (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
     if (aSelAttr) {
@@ -434,7 +469,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);