+void XGUI_OperationMgr::onBeforeOperationStarted()
+{
+ ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
+ if (!aCurrentOperation)
+ return;
+
+ /// Set current feature and remeber old current feature
+ ModuleBase_OperationFeature* aFOperation =
+ dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
+ if (aFOperation) {
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aDoc = aMgr->activeDocument();
+ // the parameter of current feature should be false, we should use all feature, not only
+ // visible in order to correctly save the previous feature of the nested operation, where the
+ // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
+ // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
+ // When sketch entity operation started, the sketch should be cashed here as the current.
+ // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
+ // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
+ // As a result the sketch disappears from the viewer.
+ // However after commit it is displayed back.
+ aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
+
+#ifdef DEBUG_CURRENT_FEATURE
+ FeaturePtr aFeature = aFOperation->feature();
+ QString aKind = aFeature ? aFeature->getKind().c_str() : "";
+ qDebug("");
+ qDebug(QString("onBeforeOperationStarted() isEditOperation = %1, feature = %2")
+ .arg(aFOperation->isEditOperation())
+ .arg(ModuleBase_Tools::objectName(aFeature)).toStdString().c_str());
+ qDebug(QString(" document->currentFeature(false) = %1 : DO: setPreviousCurrentFeature").arg(
+ ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
+#endif
+
+ if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
+ // in create operation, the current feature is changed by addFeature()
+ aDoc->setCurrentFeature(aFOperation->feature(), false);
+#ifdef DEBUG_CURRENT_FEATURE
+ qDebug(QString(" document->setCurrentFeature(false) = %1").arg(
+ ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
+#endif
+ // this is the only place where flushes must be called after setCurrentFeature for the
+ // current moment: after this the opertion is not finished, so, the ObjectBrowser
+ // state may be corrupted (issue #1457)
+ static Events_Loop* aLoop = Events_Loop::loop();
+ static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
+ aLoop->flush(aCreateEvent);
+ static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
+ aLoop->flush(aDeleteEvent);
+ }
+ }
+}
+