Salome HOME
Issue #3221: Visual separation for features
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchCreator.cpp
index 6397b3caefd7f54a00169ecd1e292b882f1209d1..5fe28ccc83abd3bbd8118f15f7a163391de181d4 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        PartSet_WidgetSketchCreator.cpp
-// Created:     08 June 2015
-// Author:      Vitaly SMETANNIKOV
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include "PartSet_WidgetSketchCreator.h"
 #include "PartSet_Module.h"
@@ -69,13 +82,13 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
 
   ModuleBase_Tools::adjustMargins(aLayout);
 
-  QString aLabelText = QString::fromStdString(theData->widgetLabel());
+  QString aLabelText = translate(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));
+  aSizeLayout->addWidget(new QLabel(tr("Size of the view"), mySizeOfViewWidget));
   mySizeOfView = new QLineEdit(mySizeOfViewWidget);
 
   QDoubleValidator* aValidator = new QDoubleValidator(0, DBL_MAX, 12, mySizeOfView);
@@ -181,6 +194,10 @@ bool PartSet_WidgetSketchCreator::isValidSelectionCustom(const ModuleBase_Viewer
 
 void PartSet_WidgetSketchCreator::activateSelectionControl()
 {
+  // reset previously set size of view needed on restart extrusion after Sketch
+  if (myModule->sketchMgr()->previewSketchPlane()->isUseSizeOfView())
+    myModule->sketchMgr()->previewSketchPlane()->setSizeOfView(0, false);
+
   // we need to call activate here as the widget has no focus accepted controls
   // if these controls are added here, activate will happens automatically after focusIn()
   XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop());
@@ -271,8 +288,6 @@ bool PartSet_WidgetSketchCreator::isSelectionMode() const
 bool PartSet_WidgetSketchCreator::hasSubObjects() const
 {
   bool aHasSubObjects = false;
-
-  bool aCanSetFocus = true;
   CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
   if (aComposite.get())
     aHasSubObjects = aComposite->numberOfSubs() > 0;
@@ -309,10 +324,12 @@ bool PartSet_WidgetSketchCreator::setSelection(QList<ModuleBase_ViewerPrsPtr>& t
 }
 
 //********************************************************************
-void PartSet_WidgetSketchCreator::onSelectionChanged()
+bool PartSet_WidgetSketchCreator::processSelection()
 {
   QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
   bool isDone = setSelection(aSelected, true/*false*/);
+
+  return isDone;
 }
 
 //********************************************************************
@@ -345,30 +362,23 @@ bool PartSet_WidgetSketchCreator::startSketchOperation(
   // Set View size if a plane is selected
   if (myPreviewPlanes->isPreviewDisplayed() &&
       myPreviewPlanes->isPreviewShape(aValue->shape())) {
+    // set default plane size
+    bool isSetSizeOfView = false;
+    double aSizeOfView = 0;
     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);
-        }
+      aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView);
+      if (isSetSizeOfView && aSizeOfView <= 0) {
+        isSetSizeOfView = false;
       }
     }
+    if (isSetSizeOfView)
+      myModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, true);
   }
   // manually deactivation because the widget was not activated as has no focus acceptin controls
   deactivate();
-  bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
   myPreviewPlanes->erasePreviewPlanes(myWorkshop);
 
-  // Launch Sketch operation
-  CompositeFeaturePtr aCompFeature =
-    std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
-
   // start edit operation for the sketch
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                             (myModule->createOperation("Sketch"));
@@ -428,7 +438,6 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp)
   AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID);
   if (aCompFeature->numberOfSubs() > 0) {
     // set the sub feature to attribute selection list and check whether sketch is valid
-    SessionPtr aMgr = ModelAPI_Session::get();
     const static std::string aNestedOpID("Set Sketch result into Selection list");
     aMgr->startOperation(aNestedOpID, false); // false to not attach to Extrusion operation
     setSketchObjectToList(aCompFeature, anAttrList);
@@ -502,7 +511,6 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp)
                                     (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
       ResultPtr aRes = aSelAttr.get() ? aSelAttr->context() : ResultPtr();
       if (aRes.get()) {
-        SessionPtr aMgr = ModelAPI_Session::get();
         ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
         AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute);
         std::string aValidatorID;