Salome HOME
updated copyright message
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 6963c8426af58ed400ce5e7c7727e14205d5b445..6ae78b95d4bd588ba7199f934272c0fb3a1c06b0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <XGUI_InspectionPanel.h>
 #include <XGUI_CompressFiles.h>
 
-#ifndef HAVE_SALOME
+#ifdef HAVE_SALOME
+#include <SUIT_Application.h>
+#include <SUIT_Session.h>
+#else
 #include <AppElements_Button.h>
 #include <AppElements_Command.h>
 #include <AppElements_MainMenu.h>
@@ -87,6 +90,7 @@
 #include <Events_Loop.h>
 #include <Events_InfoMessage.h>
 #include <Events_LongOp.h>
+#include <Events_MessageBool.h>
 
 #include <ExchangePlugin_ExportPart.h>
 #include <ExchangePlugin_ImportPart.h>
 #include <QSpinBox>
 #include <QDialogButtonBox>
 
+#include <sstream>
 #include <iterator>
 
 #ifdef TINSPECTOR
-#include <CDF_Session.hxx>
-#include <CDF_Application.hxx>
+#include <Model_Session.h>
+#include <TDocStd_Application.hxx>
 #include <inspector/TInspector_Communicator.hxx>
 #include <inspector/VInspector_CallBack.hxx>
 static TInspector_Communicator* MyTCommunicator;
 static Handle(VInspector_CallBack) MyVCallBack;
-
 #endif
 
 #ifdef _DEBUG
@@ -170,6 +174,8 @@ static Handle(VInspector_CallBack) MyVCallBack;
 
 #ifdef WIN32
 #include <windows.h>
+#pragma warning(disable : 4456) // for nested foreach
+#pragma warning(disable : 4189) // for declaration of unused variables (MAYBE_UNUSED)
 #else
 #include <dlfcn.h>
 #endif
@@ -200,17 +206,17 @@ static QString MyImportPartFilter(QObject::tr("Part files (*.shaperpart);;All fi
 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
     : QObject(),
       myModule(NULL),
-      mySalomeConnector(theConnector),
+      myObjectBrowser(0),
       myPropertyPanel(0),
-      myInspectionPanel(0),
       myFacesPanel(0),
-      myObjectBrowser(0),
-      myDisplayer(0)
-      //myViewerSelMode(TopAbs_FACE)
+      myDisplayer(0),
+      mySalomeConnector(theConnector),
+      //myViewerSelMode(TopAbs_FACE),
+      myInspectionPanel(0)
 {
   mySelector = new XGUI_SelectionMgr(this);
   myModuleConnector = new XGUI_ModuleConnector(this);
-  myOperationMgr = new XGUI_OperationMgr(this, 0);
+  myOperationMgr = new XGUI_OperationMgr(this, myModuleConnector);
   ModuleBase_IWorkshop* aWorkshop = moduleConnector();
   // Has to be defined first in order to get errors and messages from other components
   myEventsListener = new XGUI_WorkshopListener(this);
@@ -273,8 +279,6 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   //connect(myViewerProxy, SIGNAL(selectionChanged()),
   //        myActionsMgr,  SLOT(updateOnViewSelection()));
 
-  myOperationMgr->setWorkshop(aWorkshop);
-
   myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
 
   connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
@@ -492,6 +496,12 @@ void XGUI_Workshop::initMenu()
     QKeySequence(), false, "MEN_DESK_FILE", tr("Import"), 10, 10);
   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportShape()));
 
+  aAction = salomeConnector()->addDesktopCommand("IMPORT_IMAGE_CMD", tr("Picture..."),
+    tr("Import a picture from an image file"),
+    QIcon(),
+    QKeySequence(), false, "MEN_DESK_FILE", tr("Import"), 10, 10);
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportImage()));
+
   // Export sub-menu
   aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Part set..."),
                                              tr("Export the current document into a native file"),
@@ -595,13 +605,11 @@ void XGUI_Workshop::onStartWaiting()
 //******************************************************
 void XGUI_Workshop::onAcceptActionClicked()
 {
-  QAction* anAction = dynamic_cast<QAction*>(sender());
   XGUI_OperationMgr* anOperationMgr = operationMgr();
   if (anOperationMgr) {
     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                     (anOperationMgr->currentOperation());
     if (aFOperation) {
-      //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
       myOperationMgr->commitOperation();
     }
   }
@@ -610,7 +618,6 @@ void XGUI_Workshop::onAcceptActionClicked()
 //******************************************************
 void XGUI_Workshop::onAcceptPlusActionClicked()
 {
-  QAction* anAction = dynamic_cast<QAction*>(sender());
   XGUI_OperationMgr* anOperationMgr = operationMgr();
   if (anOperationMgr) {
     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
@@ -639,16 +646,22 @@ void XGUI_Workshop::onPreviewActionClicked()
 
 
 //******************************************************
-void XGUI_Workshop::onHelpActionClicked()
+void XGUI_Workshop::onHelpActionClicked() const
 {
   XGUI_OperationMgr* anOperationMgr = operationMgr();
   if (anOperationMgr) {
     ModuleBase_Operation* aOperation = anOperationMgr->currentOperation();
     if (aOperation) {
-      QString aHelpPage = aOperation->helpFileName();
-      if (!aHelpPage.isEmpty()) {
-        QString aDocDir;
-        const QChar aSep = QDir::separator();
+      showHelpPage(aOperation->helpFileName());
+    }
+  }
+}
+
+void XGUI_Workshop::showHelpPage(const QString& thePage) const
+{
+  if (!thePage.isEmpty()) {
+    QString aDocDir;
+    const QChar aSep = QDir::separator();
 //        QString platform;
 //        SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
 //#ifdef WIN32
@@ -659,21 +672,29 @@ void XGUI_Workshop::onHelpActionClicked()
 //        QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform);
 
 #ifdef HAVE_SALOME
-        QString aDir(getenv("SHAPER_ROOT_DIR"));
-        if (!aDir.isEmpty()) {
-          aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep +
-            "salome" + aSep + "gui" + aSep + "SHAPER";
-        }
+    QString aDir(getenv("SHAPER_ROOT_DIR"));
+    if (!aDir.isEmpty()) {
+      aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep +
+        "salome" + aSep + "gui" + aSep + "SHAPER";
+    }
 #else
-        QString aDir(getenv("CADBUILDER_ROOT_DIR"));
-        aDocDir = aDir + aSep + "doc" + aSep + "gui";
+    QString aDir(getenv("CADBUILDER_ROOT_DIR"));
+    aDocDir = aDir + aSep + "doc" + aSep + "gui";
 #endif
-        QString aFileName = aDocDir + aSep + aHelpPage;
-        if (QFile::exists(aFileName)) {
-          QUrl aUrl = QUrl::fromLocalFile(aFileName);
-          QDesktopServices::openUrl(aUrl);
-        }
+    QString aFileName = aDocDir + aSep + thePage;
+    if (QFile::exists(aFileName)) {
+#ifdef HAVE_SALOME
+      SUIT_Application* app = SUIT_Session::session()->activeApplication();
+      if (app)
+        app->onHelpContextModule("SHAPER", aFileName);
+      else {
+        QUrl aUrl = QUrl::fromLocalFile(aFileName);
+        QDesktopServices::openUrl(aUrl);
       }
+#else
+      QUrl aUrl = QUrl::fromLocalFile(aFileName);
+      QDesktopServices::openUrl(aUrl);
+#endif
     }
   }
 }
@@ -1040,18 +1061,47 @@ void XGUI_Workshop::openFile(const QString& theDirectory)
 #ifdef _DEBUG
   bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
   if (aNewPart) {
-
-    DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
     int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
     if (aSize > 0 ) {
-      ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
-      ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
+      ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
+      ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
       if (aPart.get())
         aPart->activate();
     }
   }
 #endif
 
+  int anActivationId =
+    ModuleBase_Preferences::resourceMgr()->integerValue("General", "part_activation_study", -1);
+  int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
+
+  if (anActivationId == 0 && aSize > 0) {
+    ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), aSize - 1);
+    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
+    if (aPart.get()) {
+      aPart->activate();
+      ModuleBase_Tools::setDisplaying(aPart);
+    }
+  }
+  else if (anActivationId == 1) {
+    for (int anIndex = 0; anIndex < aSize; ++anIndex) {
+      ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), anIndex);
+      ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
+      if (aPart.get()) {
+        aPart->activate();
+        ModuleBase_Tools::setDisplaying(aPart);
+
+        if (anIndex < aSize - 1) {
+          SessionPtr aMgr = ModelAPI_Session::get();
+          aMgr->startOperation("Activation");
+          aMgr->setActiveDocument(aMgr->moduleDocument());
+          aMgr->finishOperation();
+          updateCommandStatus();
+          viewer()->update();
+        }
+      }
+    }
+  }
   QApplication::restoreOverrideCursor();
 }
 
@@ -1112,6 +1162,12 @@ void XGUI_Workshop::onPreferences()
       } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
         myMainWindow->menuObject()->updateFromResources();
       }
+      else if (aSection == ModuleBase_Preferences::GENERAL_SECTION && aPref.second == "create_init_part") {
+        bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
+          ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
+        Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
+        aCreateMsg.send();
+      }
     }
     std::vector<int> aColor;
     try {
@@ -1215,20 +1271,32 @@ void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, i
     if (anActiveWidget->processAction(theActionType, aParam))
       return;
   }
+  else
+  {
+    XGUI_FacesPanel *  anFacePannel = facesPanel();
+    if(ActionUndo == theActionType && anFacePannel->isActivePanel())
+    {
+      anFacePannel->processUndo();
+      return;
+    }
+  }
   // the viewer update should be blocked in order to avoid the features blinking. For the created
   // feature a results are created, the flush of the created signal caused the viewer redisplay for
   // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
   // until redo of all possible objects happens
   bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
 
+  int aTimes = theTimes;
   SessionPtr aMgr = ModelAPI_Session::get();
   if (aMgr->isOperation()) {
     XGUI_OperationMgr* aOpMgr = operationMgr();
     /// this is important for nested operations
     /// when sketch operation is active, this condition is false and
     /// the sketch operation is not aborted
-    if (aOpMgr->canStopOperation(aOpMgr->currentOperation()))
+    if (aOpMgr->canStopOperation(aOpMgr->currentOperation())) {
       aOpMgr->abortOperation(aOpMgr->currentOperation());
+      aTimes--;
+    }
     else
     {
       myDisplayer->enableUpdateViewer(isUpdateEnabled);
@@ -1239,7 +1307,7 @@ void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, i
   std::list<std::string> anActionList = theActionType == ActionUndo ? aMgr->undoList()
     : aMgr->redoList();
   std::list<std::string>::const_iterator aIt = anActionList.cbegin();
-  for (int i = 0; (i < theTimes) && (aIt != anActionList.cend()); ++i, ++aIt) {
+  for (int i = 0; (i < aTimes) && (aIt != anActionList.cend()); ++i, ++aIt) {
     if (theActionType == ActionUndo)
       aMgr->undo();
     else
@@ -1253,6 +1321,11 @@ void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, i
   facesPanel()->reset(true);
   updateCommandStatus();
 
+  QObjectPtrList aList = myDisplayer->displayedObjects();
+  foreach(ObjectPtr aObj, aList) {
+    module()->customizePresentation(aObj, myDisplayer->getAISObject(aObj));
+  }
+
   // unblock the viewer update functionality and make update on purpose
   myDisplayer->enableUpdateViewer(isUpdateEnabled);
   myDisplayer->updateViewer();
@@ -1311,6 +1384,8 @@ void XGUI_Workshop::onImportPart()
   if (abortAllOperations()) {
     ModuleBase_OperationFeature* anImportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
         module()->createOperation(ExchangePlugin_ImportPart::ID()));
+    anImportPartOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
+      "importFeature.html");
     myPropertyPanel->updateApplyPlusButton(anImportPartOp->feature());
     operationMgr()->startOperation(anImportPartOp);
   }
@@ -1322,6 +1397,21 @@ void XGUI_Workshop::onImportShape()
   if (abortAllOperations()) {
     ModuleBase_OperationFeature* anImportOp = dynamic_cast<ModuleBase_OperationFeature*>(
         module()->createOperation(ExchangePlugin_Import::ID()));
+    anImportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
+      "importFeature.html");
+    myPropertyPanel->updateApplyPlusButton(anImportOp->feature());
+    operationMgr()->startOperation(anImportOp);
+  }
+}
+
+//******************************************************
+void XGUI_Workshop::onImportImage()
+{
+  if (abortAllOperations()) {
+    ModuleBase_OperationFeature* anImportOp = dynamic_cast<ModuleBase_OperationFeature*>(
+        module()->createOperation(ExchangePlugin_Import_Image::ID()));
+    anImportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
+      "importFeature.html");
     myPropertyPanel->updateApplyPlusButton(anImportOp->feature());
     operationMgr()->startOperation(anImportOp);
   }
@@ -1333,6 +1423,8 @@ void XGUI_Workshop::onExportShape()
   if (abortAllOperations()) {
     ModuleBase_OperationFeature* anExportOp = dynamic_cast<ModuleBase_OperationFeature*>(
         module()->createOperation(ExchangePlugin_ExportFeature::ID()));
+    anExportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
+      "exportFeature.html");
     myPropertyPanel->updateApplyPlusButton(anExportOp->feature());
     operationMgr()->startOperation(anExportOp);
   }
@@ -1344,6 +1436,8 @@ void XGUI_Workshop::onExportPart()
   if (abortAllOperations()) {
     ModuleBase_OperationFeature* anExportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
         module()->createOperation(ExchangePlugin_ExportPart::ID()));
+    anExportPartOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
+      "exportFeature.html");
     myPropertyPanel->updateApplyPlusButton(anExportPartOp->feature());
     operationMgr()->startOperation(anExportPartOp);
   }
@@ -1639,11 +1733,14 @@ void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
 //******************************************************
 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
 {
-  if (theDockWidget && theDockWidget == myPropertyPanel) {
+  if (!theDockWidget) return;
+
+  if (theDockWidget == myPropertyPanel) {
     QAction* aViewAct = theDockWidget->toggleViewAction();
     ///<! Do not allow to show empty property panel
     aViewAct->setEnabled(false);
   }
+
   theDockWidget->hide();
 
   // the property panel is active window of the desktop, when it is
@@ -1687,19 +1784,23 @@ ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
 //**************************************************************
 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
 {
-  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+  QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
   if (theId == "DELETE_CMD")
     deleteObjects();
   else if (theId == "CLEAN_HISTORY_CMD")
     cleanHistory();
   else if (theId == "MOVE_CMD" || theId == "MOVE_SPLIT_CMD")
     moveObjects(theId == "MOVE_SPLIT_CMD");
+  else if (theId == "RECOVER_CMD")
+    recoverFeature();
   else if (theId == "COLOR_CMD")
-    changeColor(aObjects);
+    changeColor(anObjects);
+  else if (theId == "AUTOCOLOR_CMD")
+    changeAutoColor(anObjects);
   else if (theId == "ISOLINES_CMD")
-    changeIsoLines(aObjects);
+    changeIsoLines(anObjects);
   else if (theId == "SHOW_ISOLINES_CMD") {
-    foreach(ObjectPtr aObj, aObjects) {
+    foreach(ObjectPtr aObj, anObjects) {
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
       if (aResult.get())
         ModelAPI_Tools::showIsoLines(aResult, !ModelAPI_Tools::isShownIsoLines(aResult));
@@ -1708,27 +1809,31 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   }
   else if (theId == "DEFLECTION_CMD")
-    changeDeflection(aObjects);
+    changeDeflection(anObjects);
   else if (theId == "TRANSPARENCY_CMD")
-    changeTransparency(aObjects);
+    changeTransparency(anObjects);
   else if (theId == "SHOW_CMD") {
-    showObjects(aObjects, true);
+    showObjects(anObjects, true);
     mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
     updateCommandStatus();
   }
   else if (theId == "HIDE_CMD") {
-    showObjects(aObjects, false);
+    showObjects(anObjects, false);
     updateCommandStatus();
   }
   else if (theId == "SHOW_ONLY_CMD") {
-    showOnlyObjects(aObjects);
+    showOnlyObjects(anObjects);
     mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
     updateCommandStatus();
   }
   else if (theId == "SHADING_CMD")
-    setDisplayMode(aObjects, XGUI_Displayer::Shading);
+    setDisplayMode(anObjects, XGUI_Displayer::Shading);
   else if (theId == "WIREFRAME_CMD")
-    setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
+    setDisplayMode(anObjects, XGUI_Displayer::Wireframe);
+  else if (theId == "SHOW_EDGES_DIRECTION_CMD")
+    toggleEdgesDirection(anObjects);
+  else if (theId == "BRING_TO_FRONT_CMD")
+    toggleBringToFront(anObjects);
   else if (theId == "HIDEALL_CMD") {
     QObjectPtrList aList = myDisplayer->displayedObjects();
     foreach (ObjectPtr aObj, aList) {
@@ -1765,9 +1870,9 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
     setViewerSelectionMode(TopAbs_COMPSOLID);
   } else if (theId == "SHOW_RESULTS_CMD") {
-    highlightResults(aObjects);
+    highlightResults(anObjects);
   } else if (theId == "SHOW_FEATURE_CMD") {
-    highlightFeature(aObjects);
+    highlightFeature(anObjects);
   } else if (theId == "SET_VIEW_NORMAL_CMD") {
     setNormalView();
   } else if (theId == "SET_VIEW_INVERTEDNORMAL_CMD") {
@@ -1775,7 +1880,10 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
   }
 #ifdef TINSPECTOR
   else if (theId == "TINSPECTOR_VIEW") {
-    Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
+    std::shared_ptr<Model_Session> aSession =
+      std::dynamic_pointer_cast<Model_Session>(ModelAPI_Session::get());
+
+    Handle(TDocStd_Application) anApplication = aSession->application();
     if (!anApplication.IsNull())
     {
       if (!MyTCommunicator)
@@ -1891,7 +1999,7 @@ bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) con
     if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
       continue;
     aHiddenObjects.insert(*anObjectsIt);
-    aHiddenObjectNames.append((*anObjectsIt)->data()->name().c_str());
+    aHiddenObjectNames.append(QString::fromStdWString((*anObjectsIt)->data()->name()));
   }
   if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face
     return true;
@@ -1933,8 +2041,9 @@ void XGUI_Workshop::deleteObjects()
   bool hasCompositeOwner = false;
   bool hasResultInHistory = false;
   bool hasFolder = false;
+  bool hasGroupsOnly = false;
   ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
-                                 hasResultInHistory, hasFolder);
+                                 hasResultInHistory, hasFolder, hasGroupsOnly);
   if (!(hasResult || hasFeature || hasParameter || hasFolder))
     return;
 
@@ -1946,7 +2055,7 @@ void XGUI_Workshop::deleteObjects()
     ResultConstructionPtr aConstr = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
     if (aFeature) {
-      notDelete = (!aFeature->isInHistory()) && aConstr->isInfinite();
+      notDelete = (!aFeature->isInHistory()) && (aConstr && aConstr->isInfinite());
       if (notDelete) {
         anObjects.removeAll(aObj);
         aIt--;
@@ -2097,7 +2206,7 @@ void XGUI_Workshop::cleanHistory()
   if (!anUnusedObjects.empty()) {
     QStringList aNames;
     foreach (const FeaturePtr& aFeature, anUnusedObjects) {
-      aNames.append(aFeature->name().c_str());
+      aNames.append(QString::fromStdWString(aFeature->name()));
     }
     aNames.sort();
     QString anUnusedNames = aNames.join(", ");
@@ -2206,6 +2315,15 @@ void XGUI_Workshop::moveObjects(const bool theSplit)
   myViewerProxy->update();
 }
 
+void XGUI_Workshop::recoverFeature()
+{
+  if (!abortAllOperations())
+    return;
+
+  static const QString RECOVER_OP_NAME = "Recover";
+  module()->launchOperation(RECOVER_OP_NAME, false);
+}
+
 //**************************************************************
 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
 {
@@ -2250,8 +2368,8 @@ std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
           std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
       if (aResultPart.get() && aResultPart->partDoc().get()) {
         // Recursion
-        std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
-        aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
+        std::list<FeaturePtr> aPartFeatures = allFeatures(aResultPart->partDoc());
+        aResultList.insert(aResultList.end(), aPartFeatures.begin(), aPartFeatures.end());
       }
     }
 
@@ -2269,9 +2387,9 @@ std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
   DocumentPtr aDocument = theObject->document();
   std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
   // find the object iterator
-  std::list<FeaturePtr>::iterator aObjectIt =
+  std::list<FeaturePtr>::iterator anObjectIt =
     std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
-  if (aObjectIt == anAllFeatures.end())
+  if (anObjectIt == anAllFeatures.end())
     return aResult;
   // find the current feature iterator
   std::list<FeaturePtr>::iterator aCurrentIt =
@@ -2279,14 +2397,14 @@ std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
   if (aCurrentIt == anAllFeatures.end())
     return aResult;
   // check the right order
-  if (std::distance(aObjectIt, anAllFeatures.end()) <=
+  if (std::distance(anObjectIt, anAllFeatures.end()) <=
       std::distance(aCurrentIt, anAllFeatures.end()))
     return aResult;
   // exclude the object
-  std::advance(aObjectIt, 1);
+  std::advance(anObjectIt, 1);
   // include the current feature
   std::advance(aCurrentIt, 1);
-  return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
+  return std::list<FeaturePtr>(anObjectIt, aCurrentIt);
 }
 
 //******************************************************
@@ -2294,55 +2412,80 @@ bool XGUI_Workshop::canMoveFeature()
 {
   QString anActionId = "MOVE_CMD";
 
-  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+  QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
   QObjectPtrList aValidatedObjects;
-  foreach (ObjectPtr aObject, aObjects) {
-    if (!myModule->canApplyAction(aObject, anActionId))
+  std::set<FeaturePtr> aSelectedFeatures;
+  foreach (ObjectPtr anObject, anObjects) {
+    if (!myModule->canApplyAction(anObject, anActionId))
       continue;
     // To be moved feature should be in active document
-    if (aObject->document() != ModelAPI_Session::get()->activeDocument())
+    if (anObject->document() != ModelAPI_Session::get()->activeDocument())
       continue;
-    aValidatedObjects.append(aObject);
+    aValidatedObjects.append(anObject);
+    FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
+    aSelectedFeatures.insert(aFeat);
   }
-  if (aValidatedObjects.size() != aObjects.size())
-    aObjects = aValidatedObjects;
+  if (aValidatedObjects.size() != anObjects.size())
+    anObjects = aValidatedObjects;
 
-  bool aCanMove = !aObjects.empty();
+  bool aCanMove = !anObjects.empty();
 
-  QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
+  QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
   for (; anIt != aLast && aCanMove; anIt++) {
-    ObjectPtr aObject = *anIt;
-    if (!aObject.get() || !aObject->data().get() || !aObject->data()->isValid()) {
+    ObjectPtr anObject = *anIt;
+    if (!anObject.get() || !anObject->data().get() || !anObject->data()->isValid()) {
       aCanMove = false;
       break;
     }
-    FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
-    // only groups can be moved to the end for now (#2451)
-    if (aFeat.get() && aFeat->getKind() != "Group") {
-      aCanMove = false;
-      break;
+    FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
+    // only groups can be moved to the end for now (#2451 old_id, #23105 tuleap id)
+    // and groups created by other groups (#34401)
+    if (aFeat.get()) {
+      std::string aKindOfFeature = aFeat->getKind();
+      if (aKindOfFeature != "Group" &&
+          aKindOfFeature != "GroupSubstraction" &&
+          aKindOfFeature != "GroupAddition" &&
+          aKindOfFeature != "GroupIntersection") {
+        aCanMove = false;
+        break;
+      }
     }
 
+    // Check that the feature can be moved due to its dependencies
+    // i.e. Check that there are no features between the moved one and its destination
+    // with references to it
+    // Details on #21340 (old_id #660)
+    // NOTE: we can ignore dependend features, if they are also moved!
+
     // 1. Get features placed between selected and current in the document
-    std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
-    // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
+    std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(anObject);
+    // if aFeaturesBetween is empty it means wrong order or anObject is the current feature
     if (aFeaturesBetween.empty())
       aCanMove = false;
     else {
       std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
       // 2. Get all reference features to the selected object in the document
       std::set<FeaturePtr> aRefFeatures;
-      ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
+      ModuleBase_Tools::refsToFeatureInFeatureDocument(anObject, aRefFeatures);
 
       if (aRefFeatures.empty())
         continue;
       else {
-        // 3. Find any placed features in all reference features
+        // 3.1. Check, if any reference feature is going to be moved, too.
+        //      If it is, we can ignore its dependency in our subsequent check (3.2)
+        std::set<FeaturePtr> aNoMoveRefFeatures;
+        std::set_difference(aRefFeatures.begin(), aRefFeatures.end(),
+                            aSelectedFeatures.begin(), aSelectedFeatures.end(),
+                            std::inserter(aNoMoveRefFeatures, aNoMoveRefFeatures.begin()));
+        if (aNoMoveRefFeatures.empty())
+          continue;
+
+        // 3.2. Find any placed features in all remaining (non-moved) reference features
         std::set<FeaturePtr> aIntersectionFeatures;
-        std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
+        std::set_intersection(aNoMoveRefFeatures.begin(), aNoMoveRefFeatures.end(),
                               aPlacedFeatures.begin(), aPlacedFeatures.end(),
                               std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
-        // 4. Return false if any reference feature is placed before current feature
+        // 4. Return false if any (non-moved) reference feature is placed before current feature
         if (!aIntersectionFeatures.empty())
           aCanMove = false;
       }
@@ -2375,7 +2518,7 @@ bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
   if (theActionName == "COLOR_CMD" ||
       theActionName == "DEFLECTION_CMD" ||
       theActionName == "TRANSPARENCY_CMD") {
-    QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+    QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
 
     std::set<std::string> aTypes;
     aTypes.insert(ModelAPI_ResultGroup::group());
@@ -2383,7 +2526,16 @@ bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
     aTypes.insert(ModelAPI_ResultBody::group());
     aTypes.insert(ModelAPI_ResultPart::group());
 
-    return hasResults(aObjects, aTypes);
+    return hasResults(anObjects, aTypes);
+  }
+  if (theActionName == "AUTOCOLOR_CMD") {
+
+    QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
+
+    std::set<std::string> aTypes;
+    aTypes.insert(ModelAPI_ResultGroup::group());
+
+    return hasResults(anObjects, aTypes);
   }
   return false;
 }
@@ -2423,22 +2575,17 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
       ModelAPI_Tools::getColor(aResult, aColor);
-      if (aColor.empty())
+      if (aColor.empty()) {
+        AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+        if (anAISObj.get()) {
+          aColor.resize(3);
+          anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
+        }
+      }
+      if (aColor.empty()) {
         getDefaultColor(aResult, false, aColor);
-    }
-    else {
-      // TODO: remove the obtaining a color from the AIS object
-      // this does not happen never because:
-      // 1. The color can be changed only on results
-      // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
-      AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
-      if (anAISObj.get()) {
-        aColor.resize(3);
-        anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
       }
     }
-    if (!aColor.empty())
-      break;
   }
   if (aColor.size() != 3)
     return;
@@ -2458,6 +2605,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   // 3. abort the previous operation and start a new one
   SessionPtr aMgr = ModelAPI_Session::get();
   QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
+
   aMgr->startOperation(aDescription.toStdString());
 
   // 4. set the value to all results
@@ -2482,6 +2630,56 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   myViewerProxy->update();
 }
 
+//**************************************************************
+void XGUI_Workshop::changeAutoColor(const QObjectPtrList& theObjects)
+{
+  if (!abortAllOperations())
+  return;
+
+  std::vector<int> aColor;
+
+  // abort the previous operation and start a new one
+  SessionPtr aMgr = ModelAPI_Session::get();
+  QString aDescription = contextMenuMgr()->action("AUTOCOLOR_CMD")->text();
+  aMgr->startOperation(aDescription.toStdString());
+
+    if (Config_PropManager::getAutoColorStatus()) {
+      contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Auto color"));
+      Config_PropManager::setAutoColorStatus(false);
+      ModelAPI_Tools::findRandomColor(aColor, true);
+    } else {
+      // set the value to all results
+      foreach (ObjectPtr anObj, theObjects) {
+        DocumentPtr aDocument = anObj->document();
+        std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
+        // find the object iterator
+        std::list<FeaturePtr>::iterator anObjectIt = anAllFeatures.begin();
+        for (; anObjectIt !=  anAllFeatures.end(); ++ anObjectIt) {
+          FeaturePtr aFeature = *anObjectIt;
+          if (aFeature.get()) {
+            std::list<ResultPtr> aResults;
+            ModelAPI_Tools::allResults(aFeature, aResults);
+            std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
+            for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
+              ResultPtr aGroupResult = *aIt;
+              if (aGroupResult.get() &&
+                  aGroupResult->groupName() == ModelAPI_ResultGroup::group()) {
+                ModelAPI_Tools::findRandomColor(aColor);
+                ModelAPI_Tools::setColor(aGroupResult, aColor);
+              }
+            }
+          }
+        }
+      }
+      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+      aMgr->finishOperation();
+      updateCommandStatus();
+      myViewerProxy->update();
+      contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Disable auto color"));
+      Config_PropManager::setAutoColorStatus(true);
+    }
+}
+
 //**************************************************************
 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
 {
@@ -2736,11 +2934,11 @@ void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
 //**************************************************************
 void XGUI_Workshop::updateColorScaleVisibility()
 {
-  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
-  viewer()->setColorScaleShown(false);
-  if (aObjects.size() == 1) {
+  QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
+  myViewerProxy->setColorScaleShown(false);
+  if (anObjects.size() == 1) {
     FieldStepPtr aStep =
-      std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObjects.first());
+      std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(anObjects.first());
     if (aStep.get() && myDisplayer->isVisible(aStep)) {
       AISObjectPtr aAisPtr = myDisplayer->getAISObject(aStep);
       Handle(AIS_InteractiveObject) aIO = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
@@ -2760,7 +2958,7 @@ void XGUI_Workshop::updateColorScaleVisibility()
             aPrs->dataRange(aMin, aMax);
             myViewerProxy->setColorScaleRange(aMin, aMax);
           }
-          myViewerProxy->setColorScaleTitle(aStep->name().c_str());
+          myViewerProxy->setColorScaleTitle(QString::fromStdWString(aStep->name()));
           myViewerProxy->setColorScaleShown(true);
         }
       }
@@ -2768,6 +2966,55 @@ void XGUI_Workshop::updateColorScaleVisibility()
   }
 }
 
+//**************************************************************
+void XGUI_Workshop::updateGroupsText()
+{
+  ModuleBase_IViewer::TextColor aText;
+
+  int aSize = 10;
+  SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
+  if (aResMgr->booleanValue("Viewer", "group_names_display")) {
+    // the first item in the TextColor list is font name -> text color
+    QColor aTextColor = aResMgr->colorValue("Viewer", "group_names_color");
+    std::vector<int> aTextCV;
+    aTextCV.push_back(aTextColor.red());
+    aTextCV.push_back(aTextColor.green());
+    aTextCV.push_back(aTextColor.blue());
+    QString aFontName = aResMgr->stringValue("Viewer", "group_names_font");
+    aText.push_back(std::pair<std::wstring, std::vector<int> >(aFontName.toStdWString(), aTextCV));
+    aSize = aResMgr->integerValue("Viewer", "group_names_size");
+
+    DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument();
+    int aNbGroups = aDoc->size(ModelAPI_ResultGroup::group());
+    for (int aGIndex = 0; aGIndex < aNbGroups; aGIndex++)
+    {
+      ResultGroupPtr aGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
+        aDoc->object(ModelAPI_ResultGroup::group(), aGIndex));
+      if (aGroup.get() && !aGroup->isDisabled() && aGroup->isDisplayed())
+      {
+        std::vector<int> aColor;
+        ModelAPI_Tools::getColor(aGroup, aColor);
+        if (aColor.empty())
+        { // default groups colors
+          std::string aSection, aName, aDefault;
+          aGroup->colorConfigInfo(aSection, aName, aDefault);
+          if (!aSection.empty() && !aName.empty()) {
+            aColor = Config_PropManager::color(aSection, aName);
+          }
+        }
+        if (aColor.empty())
+        {
+          aColor.push_back(150.);
+          aColor.push_back(150.);
+          aColor.push_back(150.);
+        }
+        aText.push_back(std::pair<std::wstring, std::vector<int> >(aGroup->data()->name(), aColor));
+      }
+    }
+  }
+  myViewerProxy->setText(aText, aSize);
+}
+
 
 //**************************************************************
 void XGUI_Workshop::setNormalView(bool toInvert)
@@ -2777,7 +3024,7 @@ void XGUI_Workshop::setNormalView(bool toInvert)
   GeomShapePtr aPlanarFace;
   foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
     GeomShapePtr aShape = aPrs->shape();
-    if (aShape.get() && aShape->isPlanar()) {
+    if (aShape.get() && aShape->isFace() && aShape->isPlanar()) {
       aPlanarFace = aShape;
       break;
     }
@@ -2794,7 +3041,6 @@ void XGUI_Workshop::setNormalView(bool toInvert)
     aFace->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
 
     Handle(V3d_View) aView = myViewerProxy->activeView();
-    double aScale = aView->Scale();
     aView->SetAt(aPos->x(), aPos->y(), aPos->z());
     aView->SetProj(aNormal->x(), aNormal->y(), aNormal->z());
     Bnd_Box aBox;
@@ -2807,7 +3053,7 @@ void XGUI_Workshop::setNormalView(bool toInvert)
 void XGUI_Workshop::registerValidators() const
 {
   SessionPtr aMgr = ModelAPI_Session::get();
-  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  MAYBE_UNUSED ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
 }
 
 //**************************************************************
@@ -2847,6 +3093,49 @@ void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
     myDisplayer->updateViewer();
 }
 
+//**************************************************************
+void XGUI_Workshop::toggleEdgesDirection(const QObjectPtrList& theList)
+{
+  foreach(ObjectPtr anObj, theList) {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+    if (aResult.get() != NULL)
+    {
+      bool aToShow = !ModelAPI_Tools::isShowEdgesDirection(aResult);
+      ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+      if (aBodyResult.get() != NULL) { // change property for all sub-solids
+        std::list<ResultPtr> allRes;
+        ModelAPI_Tools::allSubs(aBodyResult, allRes);
+        std::list<ResultPtr>::iterator aRes;
+        for (aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+          ModelAPI_Tools::showEdgesDirection(*aRes, aToShow);
+          myDisplayer->redisplay(*aRes, false);
+        }
+      }
+      ModelAPI_Tools::showEdgesDirection(aResult, aToShow);
+      myDisplayer->redisplay(anObj, false);
+    }
+  }
+  if (theList.size() > 0)
+    myDisplayer->updateViewer();
+}
+
+//**************************************************************
+void XGUI_Workshop::toggleBringToFront(const QObjectPtrList& theList)
+{
+  // Toggle the "BringToFront" state of all objects in the list
+  foreach(ObjectPtr anObj, theList) {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+    if (aResult.get() != NULL)
+    {
+      bool aBringToFront = !ModelAPI_Tools::isBringToFront(aResult);
+      ModelAPI_Tools::bringToFront(aResult, aBringToFront);
+      myDisplayer->redisplay(anObj, false);
+    }
+  }
+  if (theList.size() > 0)
+    myDisplayer->updateViewer();
+}
+
 //**************************************************************
 void XGUI_Workshop::closeDocument()
 {
@@ -3055,10 +3344,10 @@ void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
 
 void XGUI_Workshop::insertFeatureFolder()
 {
-  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
-  if (aObjects.isEmpty())
+  QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
+  if (anObjects.isEmpty())
     return;
-  ObjectPtr aObj = aObjects.first();
+  ObjectPtr aObj = anObjects.first();
   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
   if (aFeature.get() == NULL)
     return;
@@ -3131,12 +3420,12 @@ void XGUI_Workshop::onAutoApply()
   SessionPtr aMgr = ModelAPI_Session::get();
   bool isBlocked = aMgr->isAutoUpdateBlocked();
   aMgr->blockAutoUpdate(!isBlocked);
+  myDisplayer->updateViewer();
 }
 
 void XGUI_Workshop::updateAutoComputeState()
 {
   SessionPtr aMgr = ModelAPI_Session::get();
-  bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
 #ifdef HAVE_SALOME
 //  QAction* aUpdateCmd;
 //  QList<QAction*> aCommands = mySalomeConnector->commandList();
@@ -3149,6 +3438,7 @@ void XGUI_Workshop::updateAutoComputeState()
 //  aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
 //    QIcon(":pictures/autoapply_start.png"));
 #else
+  bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
   AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
   AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD");
   aUpdateCmd->button()->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
@@ -3205,9 +3495,9 @@ void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects)
   std::vector<int> aValues;
   bool isVisible;
   if (aResultList.size() == 1) {
-    ResultPtr aRes = aResultList.first();
-    if (aRes.get())
-      ModelAPI_Tools::getIsoLines(aRes, isVisible, aValues);
+    ResultPtr aResult = aResultList.first();
+    if (aResult.get())
+      ModelAPI_Tools::getIsoLines(aResult, isVisible, aValues);
     else
       return;
   }
@@ -3242,12 +3532,12 @@ void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects)
 
     aValues[0] = aUNb->value();
     aValues[1] = aVNb->value();
-    foreach(ResultPtr aRes, aResultList) {
-      ModelAPI_Tools::setIsoLines(aRes, aValues);
+    foreach(ResultPtr aResult, aResultList) {
+      ModelAPI_Tools::setIsoLines(aResult, aValues);
     }
     mySelector->clearSelection();
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
     aMgr->finishOperation();
     updateCommandStatus();
   }
-}
\ No newline at end of file
+}