Salome HOME
Issue #251. Append Export/Import NewGeom commands in the SALOME desktop.
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index b2f838d1a9a7d72038c3b586a9613c81c4cb8865..d2c0d9de888270eb9e21938692d81e911602edaa 100644 (file)
@@ -1,7 +1,6 @@
 #include <PartSet_Module.h>
 #include <PartSet_OperationSketch.h>
 #include <PartSet_OperationFeatureCreate.h>
-#include <PartSet_OperationFeatureEditMulti.h>
 #include <PartSet_OperationFeatureEdit.h>
 #include <PartSet_Listener.h>
 #include <PartSet_TestOCC.h>
@@ -18,6 +17,7 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Session.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Point.h>
@@ -87,16 +87,6 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
           SLOT(onContextMenuCommand(const QString&, bool)));
 
-  connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
-          SLOT(onMousePressed(QMouseEvent*)));
-  connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
-          SLOT(onMouseReleased(QMouseEvent*)));
-  connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
-          SLOT(onMouseMoved(QMouseEvent*)));
-  connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
-          SLOT(onKeyRelease(QKeyEvent*)));
-  connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
-          SLOT(onMouseDoubleClick(QMouseEvent*)));
 }
 
 PartSet_Module::~PartSet_Module()
@@ -195,6 +185,7 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
           aDisplayer->activate(*anIt, aModes);
         }
         aDisplayer->activate(aFeature, aModes);
+        aDisplayer->clearSelected();
       }
     }
   }// else {
@@ -224,14 +215,9 @@ void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
   XGUI_Workshop* aXWshp = xWorkshop();
   PartSet_OperationSketchBase* aPreviewOp = 
     dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
-  Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
-  if (aPreviewOp && (!aView.IsNull())) {
+  if (aPreviewOp) {
     ModuleBase_ISelection* aSelection = workshop()->selection();
-    // Initialise operation with preliminary selection
-    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-
-    aPreviewOp->mousePressed(theEvent, aView, aSelected, aHighlighted);
+    aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection);
   }
 }
 
@@ -239,14 +225,10 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
 {
   PartSet_OperationSketchBase* aPreviewOp = 
     dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
-  Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
-  if (aPreviewOp && (!aView.IsNull())) {
+  if (aPreviewOp) {
     ModuleBase_ISelection* aSelection = workshop()->selection();
     // Initialise operation with preliminary selection
-    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-
-    aPreviewOp->mouseReleased(theEvent, aView, aSelected, aHighlighted);
+    aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer(), aSelection);
   }
 }
 
@@ -254,9 +236,8 @@ void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
 {
   PartSet_OperationSketchBase* aPreviewOp = 
     dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
-  Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
-  if (aPreviewOp && (!aView.IsNull()))
-    aPreviewOp->mouseMoved(theEvent, aView);
+  if (aPreviewOp)
+    aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer());
 }
 
 void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
@@ -276,15 +257,17 @@ void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
   if (aPreviewOp && (!aView.IsNull())) {
     ModuleBase_ISelection* aSelection = workshop()->selection();
     // Initialise operation with preliminary selection
-    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-    aPreviewOp->mouseDoubleClick(theEvent, aView, aSelected, aHighlighted);
+    aPreviewOp->mouseDoubleClick(theEvent, aView, aSelection);
   }
 }
 
 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
 {
   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
+}
+
+void PartSet_Module::onSketchLaunched()
+{
   xWorkshop()->actionsMgr()->update();
   // Set working plane
   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
@@ -314,19 +297,17 @@ void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject
     }
     ModuleBase_ISelection* aSelection = workshop()->selection();
     // Initialise operation with preliminary selection
-    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-    aSketchOp->initSelection(aSelected, aHighlighted);
-  } //else if (aFeature) {
-    //anOperation->setFeature(aFeature);
+    aSketchOp->initSelection(aSelection, myWorkshop->viewer());
+  } else if (aFeature) { // In case of edit operation: set the previously created feature to the operation
+    anOperation->setFeature(aFeature);
     ////Deactivate result of current feature in order to avoid its selection
-    //XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
-    //std::list<ResultPtr> aResults = aFeature->results();
-    //std::list<ResultPtr>::const_iterator aIt;
-    //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
-    //  aDisplayer->deactivate(*aIt);
-    //}
-  //}
+    XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+    std::list<ResultPtr> aResults = aFeature->results();
+    std::list<ResultPtr>::const_iterator aIt;
+    for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+      aDisplayer->deactivate(*aIt);
+    }
+  }
   sendOperation(anOperation);
   xWorkshop()->actionsMgr()->updateCheckState();
 }
@@ -371,13 +352,14 @@ void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
   // Clear standard selection modes
   aDisplayer->setSelectionModes(aModes);
   aDisplayer->openLocalContext();
-  // Get default selection modes
-  aModes = sketchSelectionModes(ObjectPtr());
-  aDisplayer->activateObjectsOutOfContext(aModes);
 
   // Set filter
   mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
   aDisplayer->addSelectionFilter(mySketchFilter);
+
+  // Get default selection modes
+  aModes = sketchSelectionModes(ObjectPtr());
+  aDisplayer->activateObjectsOutOfContext(aModes);
 }
 
 void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
@@ -423,8 +405,6 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
     }
     if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) {
       anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
-    } else if (theCmdId == PartSet_OperationFeatureEditMulti::Type()) {
-      anOperation = new PartSet_OperationFeatureEditMulti(theCmdId.c_str(), this, aSketch);
     } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) {
       anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
     }
@@ -453,8 +433,10 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
             SLOT(onFeatureConstructed(ObjectPtr, int)));
     connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
             SLOT(onRestartOperation(std::string, ObjectPtr)));
-    connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
-            SLOT(onMultiSelectionEnabled(bool)));
+    // If manage multi selection the it will be impossible to select more then one
+    // object under operation Edit
+//    connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
+//            SLOT(onMultiSelectionEnabled(bool)));
 
     connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
             SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
@@ -466,6 +448,7 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
               SLOT(onPlaneSelected(double, double, double)));
       connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
+      connect(aSketchOp, SIGNAL(launchSketch()), this, SLOT(onSketchLaunched()));
     }
   }
 
@@ -605,3 +588,25 @@ gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
   return gp_Pln(aOrig, aDir);
 }
 
+
+void PartSet_Module::onSelectionChanged()
+{
+  ModuleBase_ISelection* aSelect = myWorkshop->selection();
+  QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
+  // We need to stop edit operation if selection is cleared
+  if (aSelected.size() == 0) {
+    // do not perform commit of the current edit operation here, because
+    // this functionality is realized inside this operation
+    /*PartSet_OperationFeatureEdit* anEditOp = 
+      dynamic_cast<PartSet_OperationFeatureEdit*>(myWorkshop->currentOperation());
+    if (!anEditOp)
+      return;
+    anEditOp->commit();*/
+  } else {
+    PartSet_OperationSketchBase* aSketchOp = 
+      dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
+    if (aSketchOp) {
+      aSketchOp->selectionChanged(aSelect);
+    }
+  }
+}