Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index 0724e6de1fa8e9e92ea5b87cfd001b222135c4a7..99cab29e5c2a2be1f1c3660db3f475f92ec16c61 100644 (file)
@@ -1,20 +1,27 @@
 #include <PartSet_Module.h>
 #include <PartSet_OperationSketch.h>
 #include <PartSet_OperationSketchLine.h>
+#include <PartSet_OperationEditLine.h>
+#include <ModuleBase_Operation.h>
+#include <ModuleBase_OperationDescription.h>
 #include <PartSet_Listener.h>
-#include <PartSet_Tools.h>
+#include <PartSet_TestOCC.h>
 
 #include <ModuleBase_Operation.h>
+#include <ModelAPI_Object.h>
 
 #include <XGUI_MainWindow.h>
 #include <XGUI_Displayer.h>
 #include <XGUI_Viewer.h>
 #include <XGUI_Workshop.h>
 #include <XGUI_OperationMgr.h>
-#include <XGUI_ViewWindow.h>
 #include <XGUI_SelectionMgr.h>
 #include <XGUI_ViewPort.h>
 #include <XGUI_ActionsMgr.h>
+#include <XGUI_ViewerProxy.h>
+#include <XGUI_ContextMenuMgr.h>
+#include <XGUI_PropertyPanel.h>
+#include <XGUI_Tools.h>
 
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
@@ -35,7 +42,6 @@
 #include <QDebug>
 #endif
 
-
 /*!Create and return new instance of XGUI_Module*/
 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
 {
@@ -49,23 +55,35 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
 
   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
 
-  connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
+  connect(anOperationMgr, SIGNAL(operationStarted()),
+          this, SLOT(onOperationStarted()));
+
   connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
-  if (!myWorkshop->isSalomeMode()) {
-    XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
-    connect(aViewer, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-    connect(aViewer, SIGNAL(mouseRelease(XGUI_ViewWindow*, QMouseEvent*)),
-            this, SLOT(onMouseReleased(XGUI_ViewWindow*, QMouseEvent*)));
-    connect(aViewer, SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)),
-            this, SLOT(onMouseMoved(XGUI_ViewWindow*, QMouseEvent*)));
-  }
+
+  XGUI_ContextMenuMgr* aContextMenuMgr = myWorkshop->contextMenuMgr();
+  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*)));
 }
 
 PartSet_Module::~PartSet_Module()
 {
 }
 
+XGUI_Workshop* PartSet_Module::workshop() const
+{
+  return myWorkshop;
+}
+
 void PartSet_Module::createFeatures()
 {
   Config_ModuleReader aXMLReader = Config_ModuleReader();
@@ -73,9 +91,9 @@ void PartSet_Module::createFeatures()
   myFeaturesInFiles = aXMLReader.featuresInFiles();
 }
 
-void PartSet_Module::featureCreated(XGUI_Command* theFeature)
+void PartSet_Module::featureCreated(QAction* theFeature)
 {
-  theFeature->connectTo(this, SLOT(onFeatureTriggered()));
+  connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
 }
 
 QStringList PartSet_Module::nestedFeatures(QString)
@@ -93,147 +111,309 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId)
  */
 void PartSet_Module::onFeatureTriggered()
 {
-  XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
+  //PartSet_TestOCC::local_selection_change_shape(myWorkshop->viewer()->AISContext(),
+  //                                   myWorkshop->viewer()->activeView());
+
+  //PartSet_TestOCC::local_selection_erase(myWorkshop->viewer()->AISContext(),
+  //                                       myWorkshop->viewer()->activeView());
+  QAction* aCmd = dynamic_cast<QAction*>(sender());
   //Do nothing on uncheck
   if(aCmd->isCheckable() && !aCmd->isChecked())
     return;
-  launchOperation(aCmd->id());
+  launchOperation(aCmd->data().toString());
 }
   
 void PartSet_Module::launchOperation(const QString& theCmdId)
 {
-  std::string aStdCmdId = theCmdId.toStdString();
-  std::string aPluginFileName = featureFile(aStdCmdId);
-  Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
-  aWdgReader.readAll();
-  std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
-  std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
-  ModuleBase_PropPanelOperation* aPartSetOp;
-  if (theCmdId == "Sketch" ) {
-    aPartSetOp = new PartSet_OperationSketch(theCmdId, this);
+  ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
+  sendOperation(anOperation);
+}
+
+void PartSet_Module::onOperationStarted()
+{
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
+                                       myWorkshop->operationMgr()->currentOperation());
+  if (aPreviewOp) {
+    XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
+    connect(aPreviewOp, SIGNAL(focusActivated(const std::string&)),
+            aPropPanel, SLOT(onFocusActivated(const std::string&)));
   }
-  else if(theCmdId == "SketchLine") {
-    ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
-    boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
-    if (anOperation)
-      aSketchFeature = anOperation->feature();
-    aPartSetOp = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature);
+}
+
+void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
+{
+  if (!theOperation)
+    return;
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
+  if (aPreviewOp) {
+    XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
+    disconnect(aPreviewOp, SIGNAL(focusActivated(const std::string&)),
+               aPropPanel, SLOT(onFocusActivated(const std::string&)));
   }
-  else {
-    aPartSetOp = new ModuleBase_PropPanelOperation(theCmdId, this);
+}
+
+void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
+{
+  QFeatureList aFeatures = myWorkshop->selector()->selectedFeatures();
+  if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
+    editFeature(aFeatures.first());
   }
-  aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
-  aPartSetOp->setDescription(QString::fromStdString(aDescription));
+}
 
-  //TODO(sbh): Implement static method to extract event id [SEID]
-  static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
-  Config_PointerMessage aMessage(aModuleEvent, this);
-  aMessage.setPointer(aPartSetOp);
-  Events_Loop::loop()->send(aMessage);
+void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
+{
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
+                                       myWorkshop->operationMgr()->currentOperation());
+  if (aPreviewOp)
+  {
+    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
+    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+
+    aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
+  }
 }
 
-void PartSet_Module::onOperationStarted()
+void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
 {
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
+                                       myWorkshop->operationMgr()->currentOperation());
+  if (aPreviewOp)
+  {
+    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
+    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+
+    aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
+  }
+}
 
+void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
+{
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
+                                       myWorkshop->operationMgr()->currentOperation());
+  if (aPreviewOp)
+    aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView());
+}
+
+void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
+{
+  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp) {
-    visualizePreview(true);
-
-    PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
-    if (aSketchOp) {
-      connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
-              this, SLOT(onPlaneSelected(double, double, double)));
-    }
+    aPreviewOp->keyReleased(theEvent->key());
   }
 }
 
-void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
+void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
 {
-  ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
-  if (!anOperation)
-    return;
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-  //if (aPreviewOp)
-  //  visualizePreview(false);
+  myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
+  myWorkshop->actionsMgr()->update();
+
+  //PartSet_TestOCC::testSelection(myWorkshop);
 }
 
-void PartSet_Module::onSelectionChanged()
+void PartSet_Module::onFitAllView()
 {
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  myWorkshop->viewer()->fitAll();
+}
+
+void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  ModuleBase_Operation* anOperation = createOperation(theName.c_str());
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-  if (aPreviewOp) {
-    XGUI_SelectionMgr* aSelector = myWorkshop->selector();
-    if (aSelector) {
-      NCollection_List<TopoDS_Shape> aList;
-      aSelector->selectedShapes(aList);
-      aPreviewOp->setSelectedShapes(aList);
+  if (aPreviewOp)
+  {
+    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+      // refill the features list with avoiding of the features, obtained only by vertex shape (TODO)
+    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected(TopAbs_VERTEX);
+    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted(TopAbs_VERTEX);
+    aPreviewOp->init(theFeature, aSelected, aHighlighted);
+  }
+  sendOperation(anOperation);
+  myWorkshop->actionsMgr()->updateCheckState();
+}
+
+void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
+{
+  XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+  aViewer->enableMultiselection(theEnabled);
+}
+
+void PartSet_Module::onStopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop)
+{
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  if (!isStop) {
+    std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
+    boost::shared_ptr<ModelAPI_Feature> aFeature;
+    for (; anIt != aLast; anIt++) {
+      activateFeature((*anIt).feature(), false);
     }
   }
+  aDisplayer->StopSelection(theFeatures, isStop, false);
+
+  XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+  aViewer->enableSelection(!isStop);
+
+  aDisplayer->UpdateViewer();
 }
 
-void PartSet_Module::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
+void PartSet_Module::onSetSelection(const std::list<XGUI_ViewerPrs>& theFeatures)
 {
-  QPoint aPoint = theEvent->pos();
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-  if (aPreviewOp) {
-    XGUI_SelectionMgr* aSelector = myWorkshop->selector();
-    if (aSelector) {
-      XGUI_ViewWindow* aWindow = myWorkshop->mainWindow()->viewer()->activeViewWindow();
-      if (aWindow) {
-        Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
-        if ( !aView3d.IsNull() ) {
-          gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(aPoint, aView3d);
-          aPreviewOp->mouseReleased(aPnt);
-        }
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  aDisplayer->SetSelected(theFeatures, false);
+  aDisplayer->UpdateViewer();
+}
+
+void PartSet_Module::onCloseLocalContext()
+{
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  aDisplayer->CloseLocalContexts();
+}
+
+void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                          int theMode)
+{
+  bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
+  visualizePreview(theFeature, isDisplay, false);
+  if (!isDisplay) {
+    ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
+    boost::shared_ptr<ModelAPI_Feature> aSketch;
+    PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
+    if (aPrevOp) {
+      std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
+                                                                         aList = aPrevOp->subPreview();
+      XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+      std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
+
+      std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
+                                                             anIt = aList.begin(), aLast = aList.end();
+      for (; anIt != aLast; anIt++) {
+        boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
+        visualizePreview(aFeature, false, false);
       }
+      aDisplayer->UpdateViewer();
     }
   }
+
+  if (theMode == PartSet_OperationSketchBase::FM_Activation ||
+      theMode == PartSet_OperationSketchBase::FM_Deactivation)
+    activateFeature(theFeature, true);
 }
 
-void PartSet_Module::onMouseMoved(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
+ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId)
 {
-  QPoint aPoint = theEvent->pos();
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  // get operation xml description
+  std::string aStdCmdId = theCmdId;
+  if (aStdCmdId == PartSet_OperationEditLine::Type())
+    aStdCmdId = PartSet_OperationSketchLine::Type();
+  std::string aPluginFileName = featureFile(aStdCmdId);
+  Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
+  aWdgReader.readAll();
+  std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
+  std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
+
+  // create the operation
+  ModuleBase_Operation* anOperation;
+  if (theCmdId == PartSet_OperationSketch::Type()) {
+    anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
+  }
+  else if(theCmdId == PartSet_OperationSketchLine::Type() ||
+          theCmdId == PartSet_OperationEditLine::Type()) {
+    ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
+    boost::shared_ptr<ModelAPI_Feature> aSketch;
+    PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
+    if (aPrevOp)
+      aSketch = aPrevOp->sketch();
+    if (theCmdId == PartSet_OperationSketchLine::Type())
+      anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch);
+    else
+      anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
+  }
+  else {
+    anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
+  }
+  anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
+  anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
+
+  // connect the operation
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp) {
-    XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
-    if (aViewer) {
-      XGUI_ViewWindow* aWindow = aViewer->activeViewWindow();
-      if (aWindow) {
-        Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
-        if ( !aView3d.IsNull() ) {
-          gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(aPoint, aView3d);
-          aPreviewOp->mouseMoved(aPnt);
-        }
-      }
+    connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)),
+            this, SLOT(onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)));
+    connect(aPreviewOp, SIGNAL(launchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)),
+            this, SLOT(onLaunchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)));
+    connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
+            this, SLOT(onMultiSelectionEnabled(bool)));
+
+    connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
+            this, SLOT(onMultiSelectionEnabled(bool)));
+    connect(aPreviewOp, SIGNAL(stopSelection(const std::list<XGUI_ViewerPrs>&, const bool)),
+            this, SLOT(onStopSelection(const std::list<XGUI_ViewerPrs>&, const bool)));
+    connect(aPreviewOp, SIGNAL(setSelection(const std::list<XGUI_ViewerPrs>&)),
+            this, SLOT(onSetSelection(const std::list<XGUI_ViewerPrs>&)));
+
+     connect(aPreviewOp, SIGNAL(closeLocalContext()),
+             this, SLOT(onCloseLocalContext()));
+
+    PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+    if (aSketchOp) {
+      connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
+              this, SLOT(onPlaneSelected(double, double, double)));
+      connect(aSketchOp, SIGNAL(fitAllView()),
+              this, SLOT(onFitAllView()));
     }
   }
+
+  return anOperation;
 }
 
-void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
+void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
 {
-  XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
-  if (aViewer) {
-    aViewer->setViewProjection(theX, theY, theZ);
-  }
+  //TODO(sbh): Implement static method to extract event id [SEID]
+  static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
+  Config_PointerMessage aMessage(aModuleEvent, this);
+  aMessage.setPointer(theOperation);
+  Events_Loop::loop()->send(aMessage);
+}
 
+void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay,
+                                      const bool isUpdateViewer)
+{
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
-  if (anOperation) {
-    PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-    if (aPreviewOp) {
-      aPreviewOp->setEditMode(true);
-      // the preview should be shown in another local context
-      visualizePreview(false);
-      visualizePreview(true);
-    }
+  if (!anOperation)
+    return;
+
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+  if (!aPreviewOp)
+    return;
+
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  if (isDisplay) {
+    boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
+    aDisplayer->Redisplay(theFeature,
+                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
   }
+  else
+    aDisplayer->Erase(theFeature, false);
 
-  myWorkshop->actionsMgr()->setNestedActionsEnabled(true);
+  if (isUpdateViewer)
+    aDisplayer->UpdateViewer();
 }
 
-void PartSet_Module::visualizePreview(bool isDisplay)
+void PartSet_Module::activateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                     const bool isUpdateViewer)
+{
+  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+  if (aPreviewOp) {
+    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+    aDisplayer->ActivateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
+                                       isUpdateViewer);
+  }
+}
+
+void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
 {
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
   if (!anOperation)
@@ -243,16 +423,42 @@ void PartSet_Module::visualizePreview(bool isDisplay)
   if (!aPreviewOp)
     return;
 
+  boost::shared_ptr<ModelAPI_Feature> aFeature = aPreviewOp->feature();
+  if (!aFeature || aFeature->getKind() != theCmdId)
+    return;
+
+  std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
+                                                                     aList = aPreviewOp->subPreview();
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-  if (isDisplay) {
-    boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview();
-    if (aPreview) {
-      aDisplayer->LocalSelection(anOperation->feature(),
-                                   aPreview->impl<TopoDS_Shape>(), aPreviewOp->getSelectionMode());
-    }
+  std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
+
+  std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
+                                                         anIt = aList.begin(), aLast = aList.end();
+  for (; anIt != aLast; anIt++) {
+    boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
+    boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
+    aDisplayer->Redisplay(aFeature,
+                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+    aDisplayer->ActivateInLocalContext(aFeature, aModes, false);
   }
-  else {
-    aDisplayer->GlobalSelection(false);
-    aDisplayer->Erase(anOperation->feature());
+  aDisplayer->UpdateViewer();
+}
+
+void PartSet_Module::editFeature(FeaturePtr theFeature)
+{
+  if (!theFeature)
+    return;
+
+  if (theFeature->getKind() == "Sketch") {
+    FeaturePtr aFeature = theFeature;
+    if (XGUI_Tools::isModelObject(aFeature)) {
+      ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
+      aFeature = aObject->featureRef();
+    }
+
+    if (aFeature) {
+      onLaunchOperation(aFeature->getKind(), aFeature);
+      updateCurrentPreview(aFeature->getKind());
+    }
   }
 }