Salome HOME
Task 2.5. Combination operations on Groups (issue #2935)
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.cpp
index 8714eb98d5d4fe387583b7772b3079bc3acd9585..231c512fa895b2770608c9b24c5c84b1e9240fd0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  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
 //
 // 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "PartSet_WidgetSketchLabel.h"
@@ -42,6 +41,7 @@
 #include <ModuleBase_ViewerPrs.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_IModule.h>
+#include <ModuleBase_IPropertyPanel.h>
 
 #include <GeomAlgoAPI_FaceBuilder.h>
 #include <GeomAlgoAPI_ShapeTools.h>
@@ -85,7 +85,8 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
                         ModuleBase_IWorkshop* theWorkshop,
                         const Config_WidgetAPI* theData,
                         const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints)
-: ModuleBase_WidgetValidated(theParent, theWorkshop, theData)
+: ModuleBase_WidgetValidated(theParent, theWorkshop, theData), myOpenTransaction(false),
+myIsSelection(false)
 {
   QVBoxLayout* aLayout = new QVBoxLayout(this);
   ModuleBase_Tools::zeroMargins(aLayout);
@@ -120,6 +121,12 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
   ModuleBase_Tools::zeroMargins(aLayout);
   aLayout->addWidget(mySizeOfViewWidget);
   aLayout->addWidget(aLabel);
+
+  myRemoveExternal = new QCheckBox(tr("Remove external dependencies"), aFirstWgt);
+  myRemoveExternal->setChecked(false);
+  aLayout->addWidget(myRemoveExternal);
+  myRemoveExternal->setVisible(false);
+
   aLayout->addStretch(1);
 
   myStackWidget->addWidget(aFirstWgt);
@@ -160,6 +167,13 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
     if (toShowConstraints.contains(aState))
       aShowConstraints->setChecked(toShowConstraints[aState]);
   }
+  myShowPoints = new QCheckBox(tr("Show free points"), this);
+  connect(myShowPoints, SIGNAL(toggled(bool)), this, SIGNAL(showFreePoints(bool)));
+  aLayout->addWidget(myShowPoints);
+
+  QPushButton* aPlaneBtn = new QPushButton(tr("Change sketch plane"), aSecondWgt);
+  connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane()));
+  aLayout->addWidget(aPlaneBtn);
 
   myStackWidget->addWidget(aSecondWgt);
   //setLayout(aLayout);
@@ -270,8 +284,11 @@ bool PartSet_WidgetSketchLabel::setSelectionInternal(
   else {
     // it removes the processed value from the parameters list
     ModuleBase_ViewerPrsPtr aValue = theValues.first();//.takeFirst();
-    if (!theToValidate || isValidInFilters(aValue))
+    if (!theToValidate || isValidInFilters(aValue)) {
+      myIsSelection = true;
       aDone = setSelectionCustom(aValue);
+      myIsSelection = false;
+    }
   }
 
   return aDone;
@@ -297,11 +314,8 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
         isSetSizeOfView = false;
       }
     }
-    if (isSetSizeOfView)
-      aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, true);
+    aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, isSetSizeOfView);
     aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
-    if (isSetSizeOfView)
-      aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, false);
   }
   // 2. if the planes were displayed, change the view projection
 
@@ -329,9 +343,11 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
       }
     }
   }
-  if (aModule)
-    aModule->onViewTransformed();
-
+  if (myOpenTransaction) {
+    SessionPtr aMgr = ModelAPI_Session::get();
+    aMgr->finishOperation();
+    myOpenTransaction = false;
+  }
   // 3. Clear text in the label
   myStackWidget->setCurrentIndex(1);
   //myLabel->setText("");
@@ -346,12 +362,17 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   myWorkshop->selectionActivate()->updateSelectionFilters();
   myWorkshop->selectionActivate()->updateSelectionModes();
 
+  if (aModule)
+    aModule->onViewTransformed();
+
   // 6. Update sketcher actions
   XGUI_ActionsMgr* anActMgr = aWorkshop->actionsMgr();
 
   myWorkshop->updateCommandStatus();
   aWorkshop->selector()->clearSelection();
   myWorkshop->viewer()->update();
+
+  myRemoveExternal->setVisible(false);
 }
 
 std::shared_ptr<GeomAPI_Pln> PartSet_WidgetSketchLabel::plane() const
@@ -394,6 +415,11 @@ void PartSet_WidgetSketchLabel::restoreAttributeValue(const AttributePtr& theAtt
 
 bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
 {
+  if (myIsSelection && myRemoveExternal->isVisible()) {
+    if (myRemoveExternal->isChecked()) {
+      myFeature->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
+    }
+  }
   return fillSketchPlaneBySelection(thePrs);
 }
 
@@ -465,10 +491,11 @@ bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_View
       else {
         aSelAttr->setValue(aFeature, GeomShapePtr());
         GeomShapePtr aShape = aSelAttr->value();
-        if (!aShape.get() && aSelAttr->contextFeature()->firstResult().get()) {
+        if (!aShape.get() && aSelAttr->contextFeature().get() &&
+          aSelAttr->contextFeature()->firstResult().get()) {
           aShape = aSelAttr->contextFeature()->firstResult()->shape();
         }
-        if (aShape.get()) {
+        if (aShape.get() && aShape->isPlanar()) {
           const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
           setSketchPlane(aTDShape);
           isOwnerSet = true;
@@ -643,3 +670,38 @@ QList<std::shared_ptr<ModuleBase_ViewerPrs>> PartSet_WidgetSketchLabel::findCirc
   }
   return aResult;
 }
+
+//******************************************************
+void PartSet_WidgetSketchLabel::onChangePlane()
+{
+  PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+  if (aModule) {
+    mySizeOfViewWidget->setVisible(false);
+    myRemoveExternal->setVisible(true);
+    myStackWidget->setCurrentIndex(0);
+
+    CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+    PartSet_Tools::nullifySketchPlane(aSketch);
+
+    Handle(SelectMgr_Filter) aFilter = aModule->selectionFilter(SF_SketchPlaneFilter);
+    if (!aFilter.IsNull()) {
+      std::shared_ptr<GeomAPI_Pln> aPln;
+      Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
+    }
+    XGUI_Workshop* aWorkshop = aModule->getWorkshop();
+
+    aWorkshop->selectionActivate()->updateSelectionFilters();
+    aWorkshop->selectionActivate()->updateSelectionModes();
+
+    SessionPtr aMgr = ModelAPI_Session::get();
+    aMgr->startOperation("Change Sketch plane");
+    myOpenTransaction = true;
+  }
+}
+
+void PartSet_WidgetSketchLabel::setShowPointsState(bool theState)
+{
+  bool aBlock = myShowPoints->blockSignals(true);
+  myShowPoints->setChecked(theState);
+  myShowPoints->blockSignals(aBlock);
+}