Salome HOME
Merge branch 'master' into V9_3_BR
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 823d8fe..b42e4d0
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  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
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "XGUI_Workshop.h"
@@ -171,8 +170,8 @@ QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
 //#define DEBUG_CLEAN_HISTORY
 
 #ifdef HAVE_SALOME
-static QString MyFilter(QObject::tr("OpenParts files (*.shaper *.opp)"));
-static QString MyFilter2(QObject::tr("OpenParts files (*.shaper)"));
+static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.opp)"));
+static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)"));
 static QString MyExtension(".shaper");
 #else
 static QString MyFilter(QObject::tr("OpenParts files (*.opp);;All files (*.*)"));
@@ -442,13 +441,13 @@ void XGUI_Workshop::initMenu()
 
   salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
 
-  aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
-                                              tr("Blocks immediate apply of modifications"),
-                                              QIcon(":pictures/autoapply.png"), QKeySequence(),
-                                              false, "MEN_DESK_EDIT");
-  salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
+  //aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
+  //                                            tr("Blocks immediate apply of modifications"),
+  //                                            QIcon(":pictures/autoapply.png"), QKeySequence(),
+  //                                            false, "MEN_DESK_EDIT");
+  //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
 
-  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onAutoApply()));
+  //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onAutoApply()));
 
   salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
 
@@ -508,7 +507,7 @@ void XGUI_Workshop::initMenu()
   aCommand = aGroup->addFeature("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
                                 tr("Blocks immediate apply of modifications"),
                                 QIcon(":pictures/autoapply_start.png"), QKeySequence());
-  //aCommand->setChecked(ModelAPI_Session::get()->isAutoUpdateBlocked());
+  aCommand->setChecked(ModelAPI_Session::get()->isAutoUpdateBlocked());
   aCommand->connectTo(this, SLOT(onAutoApply()));
 
   aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
@@ -1074,15 +1073,23 @@ bool XGUI_Workshop::onSave()
     aMgr->blockAutoUpdate(false);
 
   std::list<std::string> aFiles;
-  saveDocument(myTmpDir.path(), aFiles);
-  if (!XGUI_CompressFiles::compress(myCurrentFile, aFiles))
-    return false;
+  // issue #2899: create a temporary directory, save and then remove it
+#ifdef HAVE_SALOME
+  std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("SALOME_TMP_DIR");
+#else
+  std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("");
+#endif
+  saveDocument(QString(aTmpDir.c_str()), aFiles);
+  bool aResult = XGUI_CompressFiles::compress(myCurrentFile, aFiles);
+  XGUI_Tools::removeTemporaryFiles(aTmpDir, aFiles);
 
-  updateCommandStatus();
+  if (aResult) {
+    updateCommandStatus();
 #ifndef HAVE_SALOME
     myMainWindow->setModifiedState(false);
 #endif
-  return true;
+  }
+  return aResult;
 }
 
 //******************************************************
@@ -1332,7 +1339,6 @@ void XGUI_Workshop::updateCommandStatus()
           aCmd->setEnabled(myModule->canRedo());
       }
       else if (aId == "AUTOCOMPUTE_CMD") {
-        //aCmd->setChecked(aMgr->isAutoUpdateBlocked());
         aCmd->setIcon(aMgr->isAutoUpdateBlocked() ?
           QIcon(":pictures/autoapply_stop.png") :
           QIcon(":pictures/autoapply_start.png"));
@@ -2216,6 +2222,9 @@ void setColor(ResultPtr theResult, const std::vector<int>& theColor)
     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);
 }
 
 //**************************************************************
@@ -2294,6 +2303,9 @@ void setDeflection(ResultPtr theResult, const double theDeflection)
   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);
 }
 
 //**************************************************************
@@ -2305,6 +2317,9 @@ void setTransparency(ResultPtr theResult, double theTransparency)
   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);
 }
 
 //**************************************************************
@@ -2693,12 +2708,28 @@ void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
       if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
         continue;
-      myDisplayer->display(aObj, false);
+      ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
+      if (aResBody.get())
+        synchronizeResultTree(aResBody, false);
+      else
+        myDisplayer->display(aObj, false);
     }
   }
   if (theUpdateViewer)
     myDisplayer->updateViewer();
 }
+
+void XGUI_Workshop::synchronizeResultTree(const ResultBodyPtr& theRes, bool theUpdateViewer)
+{
+  if (theRes->numberOfSubs() > 0)
+    for (int i = 0; i < theRes->numberOfSubs(); i++) {
+      ResultBodyPtr aRes = theRes->subResult(i);
+      if (aRes.get())
+        synchronizeResultTree(aRes, theUpdateViewer);
+    }
+  else
+    myDisplayer->display(theRes, theUpdateViewer);
+}
 #endif
 
 //******************************************************
@@ -2723,9 +2754,7 @@ void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
   }
   if (aSelList.count() > theObjects.count()) {
     // if something was found
-    bool aBlocked = objectBrowser()->blockSignals(true);
     objectBrowser()->setObjectsSelected(aSelList);
-    objectBrowser()->blockSignals(aBlocked);
     objectBrowser()->ensureVisible(aNewSel.first());
   }
   if (aHasHidden)
@@ -2752,9 +2781,7 @@ void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
   }
   if (aSelList.count() > theObjects.count()) {
     // if something was found
-    bool aBlocked = objectBrowser()->blockSignals(true);
     objectBrowser()->setObjectsSelected(aSelList);
-    objectBrowser()->blockSignals(aBlocked);
     objectBrowser()->ensureVisible(aNewSel.first());
   }
 }
@@ -2844,16 +2871,16 @@ void XGUI_Workshop::updateAutoComputeState()
   SessionPtr aMgr = ModelAPI_Session::get();
   bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
 #ifdef HAVE_SALOME
-  QAction* aUpdateCmd;
-  QList<QAction*> aCommands = mySalomeConnector->commandList();
-  foreach(QAction* aCmd, aCommands) {
-    if (aCmd->data().toString() == "AUTOCOMPUTE_CMD") {
-      aUpdateCmd = aCmd;
-      break;
-    }
-  }
-  aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
-    QIcon(":pictures/autoapply_start.png"));
+//  QAction* aUpdateCmd;
+//  QList<QAction*> aCommands = mySalomeConnector->commandList();
+//  foreach(QAction* aCmd, aCommands) {
+//    if (aCmd->data().toString() == "AUTOCOMPUTE_CMD") {
+//      aUpdateCmd = aCmd;
+//      break;
+//    }
+//  }
+//  aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
+//    QIcon(":pictures/autoapply_start.png"));
 #else
   AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
   AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD");