Salome HOME
updated copyright message
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.cpp
index 9df9fad5ade0b3fbe87819f67bc6c683c6f8c25f..4a5edfa01266b8b6093f1fb59bbbf450bf1e9feb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -63,7 +63,6 @@
 #include <gp_Pnt.hxx>
 #include <gp_Dir.hxx>
 #include <AIS_Shape.hxx>
-#include <AIS_DimensionSelectionMode.hxx>
 #include <Bnd_Box.hxx>
 
 #include <Config_WidgetAPI.h>
 #include <QDialog>
 #include <QTimer>
 
+#ifdef WIN32
+#pragma warning(disable : 4456) // for nested foreach
+#endif
+
 #ifndef DBL_MAX
 #define DBL_MAX 1.7976931348623158e+308
 #endif
@@ -163,8 +166,17 @@ myIsSelection(false)
   myViewInverted = new QCheckBox(tr("Reversed"), aViewBox);
   aViewLayout->addWidget(myViewInverted, 0, 0);
 
+  // Sketch plane visibility
   myViewVisible = new QCheckBox(tr("Visible"), aViewBox);
-  myViewVisible->setChecked(true);
+  PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+  PartSet_PreviewSketchPlane* aPreviewPlane = aModule->sketchMgr()->previewSketchPlane();
+  if (aPreviewPlane->isPlaneCreated())
+    // init with current state
+    myViewVisible->setChecked(aPreviewPlane->isDisplayed());
+  else
+    // true by default (at start of sketch creation)
+    myViewVisible->setChecked(true);
+
   aViewLayout->addWidget(myViewVisible, 0, 1, Qt::AlignRight);
   connect(myViewVisible, SIGNAL(toggled(bool)), this, SLOT(onShowViewPlane(bool)));
 
@@ -351,21 +363,23 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   // 1. hide main planes if they have been displayed and display sketch preview plane
   myPreviewPlanes->erasePreviewPlanes(myWorkshop);
 
+  QString aSizeOfViewStr = mySizeOfView->text();
+  bool isSetSizeOfView = false;
+  double aSizeOfView = 0;
+  if (!aSizeOfViewStr.isEmpty()) {
+    aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView);
+    if (isSetSizeOfView && aSizeOfView <= 0) {
+      isSetSizeOfView = false;
+    }
+  }
   PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
   if (aModule) {
     CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
-    bool isSetSizeOfView = false;
-    double aSizeOfView = 0;
-    QString aSizeOfViewStr = mySizeOfView->text();
-    if (!aSizeOfViewStr.isEmpty()) {
-      aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView);
-      if (isSetSizeOfView && aSizeOfView <= 0) {
-        isSetSizeOfView = false;
-      }
-    }
     aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, isSetSizeOfView);
     if (myViewVisible->isChecked())
       aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
+    else
+      aModule->sketchMgr()->previewSketchPlane()->clearPlanePreview();
   }
   // 2. if the planes were displayed, change the view projection
 
@@ -379,18 +393,13 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   if (aRotate) {
     myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist);
   }
-  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);
-      }
+  if (isSetSizeOfView && 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);
     }
   }
   if (myOpenTransaction) {
@@ -415,9 +424,6 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   if (aModule)
     aModule->onViewTransformed();
 
-  // 6. Update sketcher actions
-  XGUI_ActionsMgr* anActMgr = aWorkshop->actionsMgr();
-
   myWorkshop->updateCommandStatus();
   aWorkshop->selector()->clearSelection();
   myWorkshop->viewer()->update();
@@ -495,8 +501,6 @@ bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrsPtr& the
   }
   // check plane or planar face of any non-sketch object
   if (aCanFillSketch) {
-    std::shared_ptr<GeomAPI_Face> aGeomFace;
-
     GeomShapePtr aGeomShape = thePrs->shape();
     if ((!aGeomShape.get() || aGeomShape->isNull()) && aResult.get()) {
       aGeomShape = aResult->shape();
@@ -549,13 +553,13 @@ bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_View
       }
       else {
         aSelAttr->setValue(aFeature, GeomShapePtr());
-        GeomShapePtr aShape = aSelAttr->value();
-        if (!aShape.get() && aSelAttr->contextFeature().get() &&
+        GeomShapePtr aSelShape = aSelAttr->value();
+        if (!aSelShape.get() && aSelAttr->contextFeature().get() &&
           aSelAttr->contextFeature()->firstResult().get()) {
-          aShape = aSelAttr->contextFeature()->firstResult()->shape();
+          aSelShape = aSelAttr->contextFeature()->firstResult()->shape();
         }
-        if (aShape.get() && aShape->isPlanar()) {
-          const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
+        if (aSelShape.get() && aSelShape->isPlanar()) {
+          const TopoDS_Shape& aTDShape = aSelShape->impl<TopoDS_Shape>();
           setSketchPlane(aTDShape);
           isOwnerSet = true;
         }
@@ -899,12 +903,16 @@ bool PartSet_WidgetSketchLabel::eventFilter(QObject* theObj, QEvent* theEvent)
 void PartSet_WidgetSketchLabel::onShowViewPlane(bool toShow)
 {
   PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+  PartSet_PreviewSketchPlane* aPreviewPlane = aModule->sketchMgr()->previewSketchPlane();
   if (toShow) {
     CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
-    aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
+    if (aPreviewPlane->isPlaneCreated())
+      aPreviewPlane->displaySketchPlane(myWorkshop);
+    else
+      aPreviewPlane->createSketchPlane(aSketch, myWorkshop);
   }
   else {
-    aModule->sketchMgr()->previewSketchPlane()->eraseSketchPlane(myWorkshop, false);
+    aPreviewPlane->eraseSketchPlane(myWorkshop, false);
   }
   myWorkshop->viewer()->update();
 }