Salome HOME
Constraint sketch entity attribute.
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.cpp
index 44bac35b68d9cc90c691274021ac09fb32bae839..178cf792fcbcf2acd4b9805370480fafe133608e 100644 (file)
 #include "PartSet_WidgetPoint2dDistance.h"
 #include "PartSet_Tools.h"
 
+#include <ModuleBase_WidgetEditor.h>
+
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Displayer.h>
 #include <XGUI_Workshop.h>
+#include <XGUI_ContextMenuMgr.h>
 #include <XGUI_Selection.h>
 #include <XGUI_SelectionMgr.h>
 #include <ModuleBase_ModelWidget.h>
@@ -53,6 +56,7 @@
 //#include <AIS_Shape.hxx>
 
 #include <ModelAPI_Events.h>
+#include <ModelAPI_Session.h>
 
 #include <QMouseEvent>
 #include <QApplication>
@@ -112,7 +116,8 @@ void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
   : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
     myIsPropertyPanelValueChanged(false), myIsMouseOverWindow(false),
-    myIsMouseOverViewProcessed(true)
+    myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
+    myIsPopupMenuActive(false)
 {
   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
   ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
@@ -144,7 +149,7 @@ PartSet_SketcherMgr::~PartSet_SketcherMgr()
 
 void PartSet_SketcherMgr::onEnterViewPort()
 {
-  if (!isNestedCreateOperation())
+  if (!isNestedCreateOperation(getCurrentOperation()))
     return;
   // 1. if the mouse over window, update the next flag. Do not perform update visibility of
   // created feature because it should be done in onMouseMove(). Some widgets watch
@@ -156,7 +161,7 @@ void PartSet_SketcherMgr::onEnterViewPort()
 
 void PartSet_SketcherMgr::onLeaveViewPort()
 {
-  if (!isNestedCreateOperation())
+  if (!isNestedCreateOperation(getCurrentOperation()))
     return;
 
   myIsMouseOverViewProcessed = false;
@@ -169,7 +174,7 @@ void PartSet_SketcherMgr::onLeaveViewPort()
   // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
   // obtained after reset value
   bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
-  ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
+  ModuleBase_Operation* aOperation = getCurrentOperation();
   ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
   ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
   if (aActiveWgt) {
@@ -179,18 +184,53 @@ void PartSet_SketcherMgr::onLeaveViewPort()
 
   // hides the presentation of the current operation feature
   myIsPropertyPanelValueChanged = false;
-  visualizeFeature(aOperation, false);
+  // the feature is to be erased here, but it is correct to call canDisplayObject because
+  // there can be additional check (e.g. editor widget in distance constraint)
+  visualizeFeature(aOperation, canDisplayObject());
+}
+
+void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
+{
+  if (isNestedCreateOperation(getCurrentOperation()))
+    return;
+  // it is necessary to save current selection in order to restore it after the values are modifed
+  storeSelection();
+
+  ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+  myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
+}
+
+void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
+{
+  if (isNestedCreateOperation(getCurrentOperation()))
+    return;
+  // it is necessary to restore current selection in order to restore it after the values are modified
+  restoreSelection();
+  myCurrentSelection.clear();
+
+  // 3. the flag to disable the update viewer should be set in order to avoid blinking in the 
+  // viewer happens by deselect/select the modified objects. The flag should be restored after
+  // the selection processing. The update viewer should be also called.
+  ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+  aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
+  aDisplayer->updateViewer();
 }
 
 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
 {
-  if (!isNestedCreateOperation())
+  if (!isNestedCreateOperation(getCurrentOperation()))
     return;
 
   // visualize the current operation feature
   myIsPropertyPanelValueChanged = true;
-  ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
-  visualizeFeature(aOperation, true);
+  ModuleBase_Operation* aOperation = getCurrentOperation();
+  // the feature is to be erased here, but it is correct to call canDisplayObject because
+  // there can be additional check (e.g. editor widget in distance constraint)
+  visualizeFeature(aOperation, canDisplayObject());
 }
 
 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
@@ -208,7 +248,7 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
   if (!aViewer->canDragByMouse())
     return;
 
-  ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
+  ModuleBase_Operation* aOperation = getCurrentOperation();
   if (aOperation && aOperation->isEditOperation()) {
     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
     ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
@@ -241,20 +281,11 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
 
     // Remember highlighted objects for editing
     ModuleBase_ISelection* aSelect = aWorkshop->selection();
-    QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
-    QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
-    myFeature2AttributeMap.clear();
 
     bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
-    if (aHasShift) {
-      fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
-      fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
-    }
-    else {
-      fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
-    }
+    storeSelection(!aHasShift);
 
-    if (myFeature2AttributeMap.empty()) {
+    if (myCurrentSelection.empty()) {
       if (isSketchOpe && (!isSketcher))
         // commit previous operation
         if (!aOperation->commit())
@@ -289,7 +320,7 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
   ModuleBase_IViewer* aViewer = aWorkshop->viewer();
   if (!aViewer->canDragByMouse())
     return;
-  ModuleBase_Operation* aOp = aWorkshop->currentOperation();
+  ModuleBase_Operation* aOp = getCurrentOperation();
   if (aOp) {
     if (isNestedSketchOperation(aOp)) {
       get2dPoint(theWnd, theEvent, myClickedPoint);
@@ -298,8 +329,7 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
       if (myIsDragging) {
         if (myDragDone) {
           //aOp->commit();
-          myFeature2AttributeMap.clear();
-
+          myCurrentSelection.clear();
           // Reselect edited object
           /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
           if (theEvent->modifiers() & Qt::ShiftModifier)
@@ -317,10 +347,10 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
 
 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
-  if (isNestedCreateOperation() && !myIsMouseOverViewProcessed) {
+  if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
     myIsMouseOverViewProcessed = true;
     // 1. perform the widget mouse move functionality and display the presentation
-    ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
+    ModuleBase_Operation* aOperation = getCurrentOperation();
     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
     ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
     // the mouse move should be processed in the widget, if it can in order to visualize correct
@@ -334,24 +364,22 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     if (aDistanceWdg) {
       aDistanceWdg->onMouseMove(theWnd, theEvent);
     }
-    visualizeFeature(aOperation, true);
+    // the feature is to be erased here, but it is correct to call canDisplayObject because
+    // there can be additional check (e.g. editor widget in distance constraint)
+    visualizeFeature(aOperation, canDisplayObject());
   }
 
   myClickedPoint.clear();
 
   if (myIsDragging) {
-    ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
-    // 1. it is necessary to save current selection in order to restore it after the features moving
-    FeatureToSelectionMap aCurrentSelection;
-    getCurrentSelection(myFeature2AttributeMap, myCurrentSketch, aWorkshop, aCurrentSelection);
-
+    // 1. the current selection is saved in the mouse press method in order to restore it after moving
     // 2. the enable selection in the viewer should be temporary switched off in order to ignore
     // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
     // deselected). This flag should be restored in the slot, processed the mouse release signal.
     ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
     aViewer->enableSelection(false);
 
-    ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
+    ModuleBase_Operation* aOperation = getCurrentOperation();
     if (!aOperation)
       return;
     if (isSketchOperation(aOperation))
@@ -364,6 +392,7 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     double dX =  aX - myCurrentPoint.myCurX;
     double dY =  aY - myCurrentPoint.myCurY;
 
+    ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
     // 3. the flag to disable the update viewer should be set in order to avoid blinking in the 
@@ -373,17 +402,17 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
 
     static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
     //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
-
-    FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
-                                           aLast = myFeature2AttributeMap.end();
+    FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
+                                          aLast = myCurrentSelection.end();
     // 4. the features and attributes modification(move)
     for (; anIt != aLast; anIt++) {
       FeaturePtr aFeature = anIt.key();
 
-      AttributeList anAttributes = anIt.value();
+      std::set<AttributePtr> anAttributes = anIt.value().first;
       // Process selection by attribute: the priority to the attribute
       if (!anAttributes.empty()) {
-        AttributeList::const_iterator anAttIt = anAttributes.begin(), anAttLast = anAttributes.end();
+        std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
+                                               anAttLast = anAttributes.end();
         for (; anAttIt != anAttLast; anAttIt++) {
           AttributePtr anAttr = *anAttIt;
           if (anAttr.get() == NULL)
@@ -415,19 +444,11 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
 
     // 5. it is necessary to save current selection in order to restore it after the features moving
-    FeatureToSelectionMap::const_iterator aSIt = aCurrentSelection.begin(),
-                                          aSLast = aCurrentSelection.end();
-    SelectMgr_IndexedMapOfOwner anOwnersToSelect;
-    for (; aSIt != aSLast; aSIt++) {
-      anOwnersToSelect.Clear();
-      getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, aCurrentSelection,
-                         anOwnersToSelect);
-      aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
-    }
-
+    restoreSelection();
     // 6. restore the update viewer flag and call this update
     aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
     aDisplayer->updateViewer();
+
     myDragDone = true;
     myCurrentPoint.setValue(aX, aY);
   }
@@ -435,7 +456,7 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
 
 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
-  ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
+  ModuleBase_Operation* aOperation = getCurrentOperation();
   if (aOperation && aOperation->isEditOperation()) {
     std::string aId = aOperation->id().toStdString();
     if (isDistanceOperation(aOperation))
@@ -468,6 +489,10 @@ void PartSet_SketcherMgr::onApplicationStarted()
   XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
   connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
   connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
+
+  XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
+  connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
+  connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
 }
 
 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
@@ -475,7 +500,7 @@ void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWid
   if (!myClickedPoint.myIsInitialized)
     return;
 
-  ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
+  ModuleBase_Operation* aOperation = getCurrentOperation();
   // the distance constraint feature should not use the clickedd point
   // this is workaround in order to don't throw down the flyout point value,
   // set by execute() method of these type of features
@@ -488,6 +513,16 @@ void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWid
   }
 }
 
+void PartSet_SketcherMgr::onBeforeContextMenu()
+{
+  myIsPopupMenuActive = true;
+}
+
+void PartSet_SketcherMgr::onAfterContextMenu()
+{
+  myIsPopupMenuActive = false;
+}
+
 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
                                      Point& thePoint)
 {
@@ -513,8 +548,8 @@ void PartSet_SketcherMgr::launchEditing()
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
   aConnector->activateSubShapesSelection(aModes);
 
-  if (!myFeature2AttributeMap.empty()) {
-    FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
+  if (!myCurrentSelection.empty()) {
+    FeaturePtr aFeature = myCurrentSelection.begin().key();
     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
     if (aSPFeature) {
@@ -554,6 +589,21 @@ bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOpera
          PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
 }
 
+bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
+{
+  return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
+}
+
+bool PartSet_SketcherMgr::isEntityOperation(ModuleBase_Operation* theOperation)
+{
+  std::string aId = theOperation ? theOperation->id().toStdString() : "";
+
+  return (aId == SketchPlugin_Line::ID()) ||
+         (aId == SketchPlugin_Point::ID()) ||
+         (aId == SketchPlugin_Arc::ID()) ||
+         (aId == SketchPlugin_Circle::ID());
+}
+
 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
 {
   std::string aId = theOperation ? theOperation->id().toStdString() : "";
@@ -657,23 +707,42 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
   connectToPropertyPanel(false);
   myIsPropertyPanelValueChanged = false;
   myIsMouseOverViewProcessed = true;
-  visualizeFeature(theOperation, true);
+}
+
+void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
+{
+  if (isNestedCreateOperation(theOperation))
+    visualizeFeature(theOperation, true);
 }
 
 bool PartSet_SketcherMgr::canUndo() const
 {
-  return isNestedCreateOperation();
+  return isNestedCreateOperation(getCurrentOperation());
 }
 
 bool PartSet_SketcherMgr::canRedo() const
 {
-  return isNestedCreateOperation();
+  return isNestedCreateOperation(getCurrentOperation());
 }
 
 bool PartSet_SketcherMgr::canDisplayObject() const
 {
   bool aCanDisplay = true;
-  if (!isNestedCreateOperation())
+  if (!isNestedCreateOperation(getCurrentOperation()))
+    return aCanDisplay;
+
+  ModuleBase_Operation* aOperation = getCurrentOperation();
+  ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+  ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
+  // the active widget editor should not influence here. The presentation should be visible always
+  // when this widget is active.
+  if (anActiveWdg) {
+    ModuleBase_WidgetEditor* anEditorWdg = dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg);
+    if (anEditorWdg) {
+      return aCanDisplay;
+    }
+  }
+  if (myIsPopupMenuActive)
     return aCanDisplay;
 
   // during a nested create operation, the feature is redisplayed only if the mouse over view
@@ -682,22 +751,112 @@ bool PartSet_SketcherMgr::canDisplayObject() const
   return aCanDisplay;
 }
 
-void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
+bool PartSet_SketcherMgr::canChangeConstruction(bool& isConstruction) const
 {
-  myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
-}
+  bool anEnabled = false;
+  ModuleBase_Operation* anOperation = getCurrentOperation();
+
+  bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
+                        PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+  if (!isActiveSketch)
+    return anEnabled;
+
+  QObjectPtrList anObjects;
+  // 1. change construction type of a created feature
+  if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
+      PartSet_SketcherMgr::isEntityOperation(anOperation) ) {
+    anObjects.append(anOperation->feature());
+  }
+  else {
+    if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
+      anOperation->abort();
+    // 2. change construction type of selected sketch entities
+    ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
+    anObjects = aSelection->selectedPresentations();
+  }
+  anEnabled = anObjects.size() > 0;
+
+  bool isNotConstructedFound = false;
+  if (anObjects.size() > 0) {
+    QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
+    for (; anIt != aLast && !isNotConstructedFound; anIt++) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+      if (aFeature.get() != NULL) {
+        std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+                            std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+        if (aSketchFeature.get() != NULL) {
+          std::string anAttribute = SketchPlugin_SketchEntity::CONSTRUCTION_ID();
 
-void PartSet_SketcherMgr::getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
-                                              const FeaturePtr& theSketch,
-                                              ModuleBase_IWorkshop* theWorkshop,
-                                              FeatureToSelectionMap& theSelection)
+          std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr = 
+            std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
+          isNotConstructedFound = !aConstructionAttr->value();
+        }
+      }
+    }
+  }
+  isConstruction = anObjects.size() && !isNotConstructedFound;
+  return anEnabled;
+}
+  
+void PartSet_SketcherMgr::setConstruction(const bool isChecked)
 {
-  FeatureToAttributesMap::const_iterator anIt = theFeatureToAttributes.begin(),
-                                         aLast = theFeatureToAttributes.end();
-  for (; anIt != aLast; anIt++) {
-    FeaturePtr aFeature = anIt.key();
-    getCurrentSelection(aFeature, theSketch, theWorkshop, theSelection);
+  ModuleBase_Operation* anOperation = getCurrentOperation();
+
+  bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
+                        PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+  if (!isActiveSketch)
+    return;
+
+  QObjectPtrList anObjects;
+  bool isUseTransaction = false;
+  // 1. change construction type of a created feature
+  if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
+      PartSet_SketcherMgr::isEntityOperation(anOperation) ) {
+    anObjects.append(anOperation->feature());
+  }
+  else {
+    isUseTransaction = true;
+    // 2. change construction type of selected sketch entities
+    ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
+    anObjects = aSelection->selectedPresentations();
   }
+
+  QAction* anAction = myModule->action("CONSTRUCTION_CMD");
+  SessionPtr aMgr = ModelAPI_Session::get();
+  if (isUseTransaction) {
+    if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
+      anOperation->abort();
+    aMgr->startOperation(anAction->text().toStdString());
+  }
+  storeSelection();
+
+  if (anObjects.size() > 0) {
+    QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
+    for (; anIt != aLast; anIt++) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+      if (aFeature.get() != NULL) {
+        std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+                            std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+        if (aSketchFeature.get() != NULL) {
+          std::string anAttribute = SketchPlugin_SketchEntity::CONSTRUCTION_ID();
+
+          std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr = 
+            std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
+          aConstructionAttr->setValue(isChecked);
+        }
+      }
+    }
+  }
+  if (isUseTransaction) {
+    aMgr->finishOperation();
+  }
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  restoreSelection();
+}
+
+void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
+{
+  myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
 }
 
 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
@@ -765,14 +924,29 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
     return;
 
   FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
-  std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
-  std::set<ResultPtr> aSelectedResults = anIt->second.second;
+  std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
+  std::set<ResultPtr> aSelectedResults = anIt.value().second;
 
   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
 
+  // 1. found the feature's owners. Check the AIS objects of the constructions
+  AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
+  if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
+    Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+
+    SelectMgr_IndexedMapOfOwner aSelectedOwners;  
+    aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
+    for  (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
+      Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
+      if (!anOwner.IsNull())
+        anOwnersToSelect.Add(anOwner);
+    }
+  }
+
+  // 2. found the feature results's owners
   std::list<ResultPtr> aResults = theFeature->results();
   std::list<ResultPtr>::const_iterator aIt;
   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
@@ -817,22 +991,31 @@ void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
   if (aPropertyPanel) {
     const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
     foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
-      if (isToConnect)
+      if (isToConnect) {
+        connect(aWidget, SIGNAL(beforeValuesChanged()),
+                this, SLOT(onBeforeValuesChangedInPropertyPanel()));
         connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
-      else
+        connect(aWidget, SIGNAL(afterValuesChanged()),
+                this, SLOT(onAfterValuesChangedInPropertyPanel()));
+      }
+      else {
+        disconnect(aWidget, SIGNAL(beforeValuesChanged()),
+                   this, SLOT(onBeforeValuesChangedInPropertyPanel()));
         disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
+        disconnect(aWidget, SIGNAL(afterValuesChanged()),
+                   this, SLOT(onAfterValuesChangedInPropertyPanel()));
+      }
     }
   }
 }
 
-bool PartSet_SketcherMgr::isNestedCreateOperation() const
+ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
 {
-  ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
-  return aOperation && !aOperation->isEditOperation() && isNestedSketchOperation(aOperation);
+  return myModule->workshop()->currentOperation();
 }
 
 void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
-                                                  const bool isToDisplay)
+                                           const bool isToDisplay)
 {
   if (!theOperation || theOperation->isEditOperation())
     return;
@@ -862,3 +1045,47 @@ void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
   }
   aDisplayer->updateViewer();
 }
+
+void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
+{
+  ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+  ModuleBase_ISelection* aSelect = aWorkshop->selection();
+  QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
+    
+  QMap<FeaturePtr, QList<AttributePtr> > aFeature2AttributeMap;
+  if (theHighlightedOnly) {
+    fillFeature2Attribute(aHighlighted, aFeature2AttributeMap, myCurrentSketch);
+  }
+  else {
+    fillFeature2Attribute(aHighlighted, aFeature2AttributeMap, myCurrentSketch);
+
+    QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
+    fillFeature2Attribute(aSelected, aFeature2AttributeMap, myCurrentSketch);
+  }
+
+  // 1. it is necessary to save current selection in order to restore it after the features moving
+  myCurrentSelection.clear();
+  QMap<FeaturePtr, QList<AttributePtr> >::const_iterator anIt = aFeature2AttributeMap.begin(),
+                                                         aLast = aFeature2AttributeMap.end();
+  for (; anIt != aLast; anIt++) {
+    FeaturePtr aFeature = anIt.key();
+    getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, myCurrentSelection);
+  }
+  //qDebug(QString("  storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
+}
+
+void PartSet_SketcherMgr::restoreSelection()
+{
+  //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
+  ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+  FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
+                                        aSLast = myCurrentSelection.end();
+  SelectMgr_IndexedMapOfOwner anOwnersToSelect;
+  for (; aSIt != aSLast; aSIt++) {
+    anOwnersToSelect.Clear();
+    getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
+                        anOwnersToSelect);
+    aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
+  }
+}