Salome HOME
Merge branch 'csgroup_IS2'
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index b00a040be13b82bdd46039eb58c7e472e29b7d38..a63aae11ef8226e5a4c161a9126168863b135f31 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -45,7 +45,6 @@
 #include "XGUI_Tools.h"
 #include "XGUI_ViewerProxy.h"
 #include "XGUI_WorkshopListener.h"
-#include <XGUI_CustomPrs.h>
 #include <XGUI_HistoryMenu.h>
 #include <XGUI_QtEvents.h>
 #include <XGUI_DataModel.h>
@@ -81,6 +80,7 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_ResultField.h>
+#include <ModuleBase_IconFactory.h>
 
 //#include <PartSetPlugin_Part.h>
 
 
 #include <ExchangePlugin_ExportPart.h>
 #include <ExchangePlugin_ImportPart.h>
+#include <ExchangePlugin_Import.h>
+#include <ExchangePlugin_ExportFeature.h>
 
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_ShapeExplorer.h>
 
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_IViewer.h>
 #include <QDesktopWidget>
 #include <QProcess>
 #include <QDesktopServices>
+#include <QFormLayout>
+#include <QSpinBox>
+#include <QDialogButtonBox>
 
 #include <iterator>
 
@@ -171,6 +177,7 @@ static Handle(VInspector_CallBack) MyVCallBack;
 //#define DEBUG_WITH_MESSAGE_REPORT
 
 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
+QString XGUI_Workshop::MOVE_TO_END_SPLIT_COMMAND = QObject::tr("Move to the end and split");
 
 //#define DEBUG_DELETE
 //#define DEBUG_FEATURE_NAME
@@ -193,17 +200,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);
@@ -225,7 +232,15 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   // Load translations
   QStringList aLangs;
   aLangs << "*_en.ts"; // load by default eng translations
+
+  /// If version of OCCT is 7.4.0 or more then it means that
+  /// this is version of SALOME older then 9.4.0
+#if OCC_VERSION_HEX >= 0x070400
+  QString aCurrLang = aResMgr->language();
+#else
   QString aCurrLang = aResMgr->stringValue("language", "language", "en");
+#endif
+
   if(aCurrLang != "en") {
     aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
   }
@@ -258,8 +273,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*)),
@@ -279,22 +292,6 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
           myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
 
-  //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
-  //                                 Config_Prop::Color, "225,225,225");
-
-  Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
-                                   Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
-  Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
-                                   Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
-  Config_PropManager::registerProp("Visualization", "result_construction_color",
-                                   "Construction color",
-                                   Config_Prop::Color,
-                                   ModelAPI_ResultConstruction::DEFAULT_COLOR());
-  Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
-                                   Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
-  Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
-                                   Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
-
   Config_PropManager::registerProp("Visualization", "selection_color", "Selection color",
     Config_Prop::Color, "255,255,255");
 
@@ -474,31 +471,49 @@ void XGUI_Workshop::initMenu()
 
 
   // Add commands to a file menu
-  aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
-                                             tr("Export the current document into a native file"),
-                                              QIcon(), QKeySequence(),
-                                              false, "MEN_DESK_FILE");
-  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
-
-  aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
+  // Import sub-menu
+  aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Part set..."),
                                               tr("Import native file"),
                                               QIcon(), QKeySequence(),
-                                              false, "MEN_DESK_FILE");
+                                              false, "MEN_DESK_FILE", tr("Import"), 10, 10);
   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
-  salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
 
-  aAction = salomeConnector()->addDesktopCommand("EXPORT_PART_CMD", tr("Export part..."),
+  aAction = salomeConnector()->addDesktopCommand("IMPORT_PART_CMD", tr("Part..."),
+                                          tr("Import structure of a part"),
+                                          QIcon(), QKeySequence(),
+                                          false, "MEN_DESK_FILE", tr("Import"), 10, 10);
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportPart()));
+
+  aAction = salomeConnector()->addDesktopCommand("IMPORT_SHAPE_CMD", tr("From CAD format..."),
+    tr("Import shape from a CAD format file"),
+    ModuleBase_IconFactory::loadIcon("icons/Exchange/import.png"),
+    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"),
+                                              QIcon(), QKeySequence(),
+                                              false, "MEN_DESK_FILE", tr("Export"), 10, 11);
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
+
+  aAction = salomeConnector()->addDesktopCommand("EXPORT_PART_CMD", tr("Part..."),
                                           tr("Export a part of the current document into a file"),
                                           QIcon(), QKeySequence(),
-                                          false, "MEN_DESK_FILE");
+                                          false, "MEN_DESK_FILE", tr("Export"), 10, 11);
   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportPart()));
 
-  aAction = salomeConnector()->addDesktopCommand("IMPORT_PART_CMD", tr("Import part..."),
-                                          tr("Import structure of a part"),
-                                          QIcon(), QKeySequence(),
-                                          false, "MEN_DESK_FILE");
-  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportPart()));
-  salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
+  aAction = salomeConnector()->addDesktopCommand("EXPORT_SHAPE_CMD", tr("To CAD format..."),
+    tr("Export shape to a CAD format file"),
+    ModuleBase_IconFactory::loadIcon("icons/Exchange/export.png"),
+    QKeySequence(), false, "MEN_DESK_FILE", tr("Export"), 10, 11);
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportShape()));
 
 #else
   // File commands group
@@ -584,13 +599,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();
     }
   }
@@ -599,7 +612,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*>
@@ -628,16 +640,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
@@ -648,21 +666,19 @@ 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)) {
+      QUrl aUrl = QUrl::fromLocalFile(aFileName);
+      QDesktopServices::openUrl(aUrl);
     }
   }
 }
@@ -791,9 +807,11 @@ void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
 #endif
 
   myErrorMgr->setPropertyPanel(myPropertyPanel);
-  theOperation->setHideFacesVisible(myFacesPanel->isVisible());
-  if (aFeatureInfo->isHideFacesPanel() && !myFacesPanel->isVisible())
-    myFacesPanel->show();
+  if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) {
+    theOperation->setHideFacesVisible(myFacesPanel->isVisible());
+    if (aFeatureInfo.get() && aFeatureInfo->isHideFacesPanel() && !myFacesPanel->isVisible())
+      myFacesPanel->show();
+  }
   showPanel(myPropertyPanel);
 }
 
@@ -877,8 +895,10 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
   }
   activateObjectsSelection(anObjects);
 
-  if (!theOperation->isHideFacesVisible())
-    myFacesPanel->hide();
+  if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) {
+    if (!theOperation->isHideFacesVisible())
+      myFacesPanel->close();
+  }
 }
 
 //******************************************************
@@ -1025,8 +1045,6 @@ 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);
@@ -1055,6 +1073,8 @@ void XGUI_Workshop::onNew()
   QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
   aWnd->showMaximized();
   updateCommandStatus();
+  PyConsole_Console* aConsole = myMainWindow->pythonConsole();
+  connect(aConsole, SIGNAL(scriptLoaded()), SLOT(updateCommandStatus()));
 #endif
   myContextMenuMgr->connectViewer();
   QApplication::restoreOverrideCursor();
@@ -1198,20 +1218,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);
@@ -1222,13 +1254,14 @@ 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
       aMgr->redo();
 
-    if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
+    if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND ||
+        QString((*aIt).c_str()) == MOVE_TO_END_SPLIT_COMMAND)
       myObjectBrowser->rebuildDataTree();
   }
   operationMgr()->updateApplyOfOperations();
@@ -1290,26 +1323,52 @@ void XGUI_Workshop::onWidgetObjectUpdated()
 //******************************************************
 void XGUI_Workshop::onImportPart()
 {
-  if (!abortAllOperations())
-    return;
-
-  //show file dialog, check if readable and open
-  qreal aRatio = ModuleBase_Tools::currentPixelRatio();
-  // If the ratio is > 1 (HD screen) then QT has a bug in
-  // displaying of system open file dialog (too small)
-  QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Import part"), QString(),
-        MyImportPartFilter, Q_NULLPTR,
-        ((aRatio > 1) ? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
-  if (!aFile.isNull()) {
+  if (abortAllOperations()) {
     ModuleBase_OperationFeature* anImportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
         module()->createOperation(ExchangePlugin_ImportPart::ID()));
-    if (operationMgr()->startOperation(anImportPartOp)) {
-      // initialize the filename to be imported
-      FeaturePtr aFeature = anImportPartOp->feature();
-      aFeature->string(ExchangePlugin_ImportPart::FILE_PATH_ID())->setValue(aFile.toStdString());
-      ModuleBase_Tools::flushUpdated(aFeature);
-      operationMgr()->commitOperation();
-    }
+    anImportPartOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
+      "importFeature.html");
+    myPropertyPanel->updateApplyPlusButton(anImportPartOp->feature());
+    operationMgr()->startOperation(anImportPartOp);
+  }
+}
+
+//******************************************************
+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);
+  }
+}
+
+//******************************************************
+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);
   }
 }
 
@@ -1319,6 +1378,9 @@ 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);
   }
 }
@@ -1496,6 +1558,7 @@ QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
   myObjectBrowser->initialize(myModule->rootNode());
   myModule->customizeObjectBrowser(myObjectBrowser);
   aObjDock->setWidget(myObjectBrowser);
+  aObjDock->setObjectName("Object browser");
 
   connect(myObjectBrowser, SIGNAL(sizeChanged()), SLOT(onDockSizeChanged()));
 
@@ -1606,7 +1669,7 @@ void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
   // in order to operation manager could process key events of the panel.
   // otherwise they are ignored. It happens only if the same(activateWindow) is
   // not happened by property panel activation(e.g. resume operation of Sketch)
-  ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
+  //ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
 }
 
 //******************************************************
@@ -1665,10 +1728,21 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     deleteObjects();
   else if (theId == "CLEAN_HISTORY_CMD")
     cleanHistory();
-  else if (theId == "MOVE_CMD")
-    moveObjects();
+  else if (theId == "MOVE_CMD" || theId == "MOVE_SPLIT_CMD")
+    moveObjects(theId == "MOVE_SPLIT_CMD");
   else if (theId == "COLOR_CMD")
     changeColor(aObjects);
+  else if (theId == "ISOLINES_CMD")
+    changeIsoLines(aObjects);
+  else if (theId == "SHOW_ISOLINES_CMD") {
+    foreach(ObjectPtr aObj, aObjects) {
+      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+      if (aResult.get())
+        ModelAPI_Tools::showIsoLines(aResult, !ModelAPI_Tools::isShownIsoLines(aResult));
+    }
+    mySelector->clearSelection();
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  }
   else if (theId == "DEFLECTION_CMD")
     changeDeflection(aObjects);
   else if (theId == "TRANSPARENCY_CMD")
@@ -1853,7 +1927,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;
@@ -1878,10 +1952,14 @@ void XGUI_Workshop::deleteObjects()
   // allow the module to delete objects, do nothing if it has succeed
   if (aModule->deleteObjects()) {
     updateCommandStatus();
+    myDisplayer->updateViewer();
     return;
   }
 
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
+  if (anObjects.isEmpty())
+    return;
+
   if (!abortAllOperations())
     return;
 
@@ -1904,7 +1982,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--;
@@ -2055,7 +2133,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(", ");
@@ -2123,7 +2201,7 @@ bool compareFeature(const FeaturePtr& theF1, const FeaturePtr& theF2) {
   DocumentPtr aDoc = theF1->document();
   return aDoc->index(theF1) < aDoc->index(theF2);
 }
-void XGUI_Workshop::moveObjects()
+void XGUI_Workshop::moveObjects(const bool theSplit)
 {
   if (!abortAllOperations())
     return;
@@ -2140,7 +2218,7 @@ void XGUI_Workshop::moveObjects()
   if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
     return;
 
-  QString anActionId = "MOVE_CMD";
+  QString anActionId = theSplit ? "MOVE_CMD" : "MOVE_SPLIT_CMD";
   QString aDescription = contextMenuMgr()->action(anActionId)->text();
   aMgr->startOperation(aDescription.toStdString());
 
@@ -2156,11 +2234,12 @@ void XGUI_Workshop::moveObjects()
     if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
       continue;
 
-    anActiveDocument->moveFeature(aFeature, aCurrentFeature);
+    anActiveDocument->moveFeature(aFeature, aCurrentFeature, theSplit);
     aCurrentFeature = anActiveDocument->currentFeature(true);
   }
   aMgr->finishOperation();
   updateCommandStatus();
+  myViewerProxy->update();
 }
 
 //**************************************************************
@@ -2207,8 +2286,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());
       }
     }
 
@@ -2345,24 +2424,27 @@ bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
   return false;
 }
 
-//******************************************************
-void setColor(ResultPtr theResult, const std::vector<int>& theColor)
-{
-  if (!theResult.get())
-    return;
 
-  AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
-  if (aColorAttr.get() != NULL) {
-    if (!aColorAttr->size()) {
-      aColorAttr->setSize(3);
+//**************************************************************
+void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
+  std::vector<int>& theColor)
+{
+  theColor.clear();
+  // get default color from the preferences manager for the given result
+  if (theColor.empty()) {
+    std::string aSection, aName, aDefault;
+    theObject->colorConfigInfo(aSection, aName, aDefault);
+    if (!aSection.empty() && !aName.empty()) {
+      theColor = Config_PropManager::color(aSection, aName);
     }
-    aColorAttr->setValue(0, theColor[0]);
-    aColorAttr->setValue(1, theColor[1]);
-    aColorAttr->setValue(2, theColor[2]);
   }
-  static const Events_ID kRedisplayEvent =
-    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
+  if (!isEmptyColorValid && theColor.empty()) {
+    // all AIS objects, where the color is not set, are in black.
+    // The color should be defined in XML or set in the attribute
+    theColor = Config_PropManager::color("Visualization", "object_default_color");
+    Events_InfoMessage("XGUI_CustomPrs",
+      "A default color is not defined in the preferences for this kind of result").send();
+  }
 }
 
 //**************************************************************
@@ -2376,21 +2458,18 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   foreach(ObjectPtr anObject, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
-      XGUI_CustomPrs::getResultColor(aResult, 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]);
+      ModelAPI_Tools::getColor(aResult, aColor);
+      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);
       }
     }
-    if (!aColor.empty())
-      break;
   }
   if (aColor.size() != 3)
     return;
@@ -2422,42 +2501,16 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
         std::list<ResultPtr> allRes;
         ModelAPI_Tools::allSubs(aBodyResult, allRes);
         for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
-          setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
+          ModelAPI_Tools::setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
         }
       }
-      setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
+      ModelAPI_Tools::setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
     }
   }
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aMgr->finishOperation();
   updateCommandStatus();
-}
-
-//**************************************************************
-void setDeflection(ResultPtr theResult, const double theDeflection)
-{
-  if (!theResult.get())
-    return;
-
-  AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
-  if (aDeflectionAttr.get() != NULL)
-    aDeflectionAttr->setValue(theDeflection);
-  static const Events_ID kRedisplayEvent =
-    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
-}
-
-//**************************************************************
-void setTransparency(ResultPtr theResult, double theTransparency)
-{
-  if (!theResult.get())
-    return;
-
-  AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
-  if (anAttribute.get() != NULL)
-    anAttribute->setValue(theTransparency);
-  static const Events_ID kRedisplayEvent =
-    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
+  myViewerProxy->update();
 }
 
 //**************************************************************
@@ -2470,15 +2523,44 @@ void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
       if (aBodyResult.get() != NULL) { // change property for all sub-solids
         std::list<ResultPtr> allRes;
         ModelAPI_Tools::allSubs(aBodyResult, allRes);
-        for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
-          setTransparency(*aRes, theTransparency);
+        std::list<ResultPtr>::iterator aRes;
+        for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+          ModelAPI_Tools::setTransparency(*aRes, theTransparency);
         }
       }
-      setTransparency(aResult, theTransparency);
+      ModelAPI_Tools::setTransparency(aResult, theTransparency);
     }
   }
 }
 
+//**************************************************************
+double getDefaultDeflection(const ObjectPtr& theObject)
+{
+  double aDeflection = -1;
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+  if (aResult.get()) {
+    bool isConstruction = false;
+
+    std::string aResultGroup = aResult->groupName();
+    if (aResultGroup == ModelAPI_ResultConstruction::group())
+      isConstruction = true;
+    else if (aResultGroup == ModelAPI_ResultBody::group()) {
+      GeomShapePtr aGeomShape = aResult->shape();
+      if (aGeomShape.get()) {
+        // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
+        // correction of deviation for them should not influence to the application performance
+        GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
+        isConstruction = !anExp.more();
+      }
+    }
+    if (isConstruction)
+      aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
+    else
+      aDeflection = Config_PropManager::real("Visualization", "body_deflection");
+  }
+  return aDeflection;
+}
+
 //**************************************************************
 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
 {
@@ -2489,7 +2571,9 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
   foreach(ObjectPtr anObject, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
-      aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
+      aDeflection = ModelAPI_Tools::getDeflection(aResult);
+      if (aDeflection < 0)
+        aDeflection = getDefaultDeflection(aResult);
     }
     else {
       // TODO: remove the obtaining a property from the AIS object
@@ -2532,16 +2616,23 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
         std::list<ResultPtr> allRes;
         ModelAPI_Tools::allSubs(aBodyResult, allRes);
         for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
-          setDeflection(*aRes, aDeflection);
+          ModelAPI_Tools::setDeflection(*aRes, aDeflection);
         }
       }
-      setDeflection(aResult, aDeflection);
+      ModelAPI_Tools::setDeflection(aResult, aDeflection);
     }
   }
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aMgr->finishOperation();
   updateCommandStatus();
 }
 
+//**************************************************************
+double getDefaultTransparency(const ResultPtr& theResult)
+{
+  return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.;
+}
+
 //**************************************************************
 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
 {
@@ -2552,7 +2643,9 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
   foreach(ObjectPtr anObject, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
-      aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult);
+      aCurrentValue = ModelAPI_Tools::getTransparency(aResult);
+      if (aCurrentValue < 0)
+        aCurrentValue = getDefaultTransparency(aResult);
     }
     if (aCurrentValue > 0)
       break;
@@ -2599,7 +2692,11 @@ void XGUI_Workshop::onTransparencyValueChanged()
 
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
   setTransparency(aTransparencyWidget->getValue(), anObjects);
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  static const Events_ID kRedisplayEvent =
+    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  Events_Loop::loop()->flush(kRedisplayEvent);
+
+  myViewerProxy->update();
 }
 
 
@@ -2622,6 +2719,7 @@ void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
   myObjectBrowser->updateAllIndexes();
 
   updateColorScaleVisibility();
+  displayer()->updateViewer();
 }
 
 //**************************************************************
@@ -2662,6 +2760,7 @@ void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
   // Necessary for update icons in ObjectBrowser on Linux
   myObjectBrowser->updateAllIndexes();
   updateColorScaleVisibility();
+  displayer()->updateViewer();
 }
 
 
@@ -2692,7 +2791,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);
         }
       }
@@ -2709,7 +2808,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;
     }
@@ -2726,7 +2825,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;
@@ -2739,7 +2837,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();
 }
 
 //**************************************************************
@@ -2869,33 +2967,45 @@ void XGUI_Workshop::synchronizeViewer()
   aDocs.append(aMgr->moduleDocument());
 
   foreach(DocumentPtr aDoc, aDocs) {
-    synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
-    synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
-    synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
-    synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
+    synchronizeGroupInViewer(aDoc, false);
   }
 }
 
 //******************************************************
 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
-                                             const std::string& theGroup,
                                              bool theUpdateViewer)
 {
-  ObjectPtr aObj;
-  int aSize = theDoc->size(theGroup);
+  FeaturePtr aFeature;
+  ResultPtr aRes;
+  int aSize = theDoc->numInternalFeatures();
   for (int i = 0; i < aSize; i++) {
-    aObj = theDoc->object(theGroup, i);
-    if (aObj->isDisplayed()) {
-      // Hide the presentation with an empty shape. But isDisplayed state of the object should not
-      // be changed to the object becomes visible when the shape becomes not empty
-      ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
-      if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
-        continue;
-      ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
-      if (aResBody.get())
-        synchronizeResultTree(aResBody, false);
-      else
-        myDisplayer->display(aObj, false);
+    aFeature = theDoc->internalFeature(i);
+    if (!aFeature.get())
+      continue;
+    const std::list<ResultPtr>& aResults = aFeature->results();
+    std::list<ResultPtr>::const_iterator aIt;
+    aFeature->setDisplayed(false);
+    for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
+      aRes = (*aIt);
+      if (aRes->isDisplayed() && !aRes->isConcealed()) {
+        // Hide the presentation with an empty shape. But isDisplayed state of the object should not
+        // be changed to the object becomes visible when the shape becomes not empty
+        if (!aRes->shape().get() || aRes->shape()->isNull())
+          continue;
+        ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aRes);
+        if (aResBody.get())
+          synchronizeResultTree(aResBody, false);
+        else {
+          if (aRes->isInHistory()) {
+            if (aRes->isDisplayed())
+              myDisplayer->display(aRes, false);
+            else
+              myDisplayer->erase(aRes, false);
+          }
+          else
+            aRes->setDisplayed(false);
+        }
+      }
     }
   }
   if (theUpdateViewer)
@@ -3051,12 +3161,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();
@@ -3069,6 +3179,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") :
@@ -3108,3 +3219,66 @@ void XGUI_Workshop::deactivateCurrentSelector()
 {
   myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector());
 }
+
+void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects)
+{
+  if (theObjects.isEmpty())
+    return;
+
+  QList<ResultPtr> aResultList;
+  ResultPtr aRes;
+  foreach(ObjectPtr aObj, theObjects) {
+    aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+    if (aRes.get())
+      aResultList.append(aRes);
+  }
+
+  std::vector<int> aValues;
+  bool isVisible;
+  if (aResultList.size() == 1) {
+    ResultPtr aResult = aResultList.first();
+    if (aResult.get())
+      ModelAPI_Tools::getIsoLines(aResult, isVisible, aValues);
+    else
+      return;
+  }
+  if (aValues.size() == 0) {
+    aValues.push_back(1);
+    aValues.push_back(1);
+  }
+
+  if (!abortAllOperations())
+    return;
+
+  XGUI_PropertyDialog aDlg(desktop());
+  aDlg.setWindowTitle(tr("Number of Iso-lines"));
+
+  QWidget* aIsosWgt = new QWidget(&aDlg);
+  QFormLayout* aLayout = new QFormLayout(aIsosWgt);
+  ModuleBase_Tools::adjustMargins(aLayout);
+  aDlg.setContent(aIsosWgt);
+
+  QSpinBox* aUNb = new QSpinBox(&aDlg);
+  aUNb->setValue(aValues[0]);
+  aLayout->addRow("U:", aUNb);
+
+  QSpinBox* aVNb = new QSpinBox(&aDlg);
+  aVNb->setValue(aValues[1]);
+  aLayout->addRow("V:", aVNb);
+
+  if (aDlg.exec() == QDialog::Accepted) {
+    SessionPtr aMgr = ModelAPI_Session::get();
+    QString aDescription = contextMenuMgr()->action("ISOLINES_CMD")->text();
+    aMgr->startOperation(aDescription.toStdString());
+
+    aValues[0] = aUNb->value();
+    aValues[1] = aVNb->value();
+    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();
+  }
+}