Salome HOME
Fix of 0022530: [CEA 1108] The new macros are deleted at Paravis launch
authorakl <akl@opencascade.com>
Mon, 31 Mar 2014 10:21:11 +0000 (14:21 +0400)
committerakl <akl@opencascade.com>
Mon, 31 Mar 2014 10:21:11 +0000 (14:21 +0400)
src/Macro/CMakeLists.txt
src/Macro/modes.py
src/PVGUI/PVGUI_Module.cxx
src/PVGUI/PVGUI_Module.h

index 2a8ad152ea6a641ba9549e4e298b4f918c9bbd9c..33bced28b2b4e58b5f531234c5769817988a1dfd 100644 (file)
@@ -21,4 +21,24 @@ SET(_PYFILES_TO_INSTALL
   modes.py
   )
 
-INSTALL_AND_COMPILE_PYTHON_FILE("${_PYFILES_TO_INSTALL}" ${SALOME_INSTALL_SCRIPT_PYTHON}/Macro)
+# Add warning message into scripts to be installed
+INSTALL(CODE "
+  SET(warning_str \"\# DO NOT MAKE CHANGES to this file, it will be rewrote 
+\# on activation of SALOME PARAVIS module.
+\# Modify the source file instead.\")
+
+  FOREACH(file ${_PYFILES_TO_INSTALL})
+    SET(tmp_file tmp/\${file})
+    FILE(READ ${CMAKE_CURRENT_SOURCE_DIR}/\${file} tmp_string)
+    STRING(REPLACE \"\# Do not touch this anchor comment\" \"\${warning_str}\" new_tmp_string \${tmp_string})
+    FILE(WRITE \${tmp_file} \${new_tmp_string})
+  ENDFOREACH()
+")
+
+# Install of the modified scripts
+FOREACH(file ${_PYFILES_TO_INSTALL})
+  INSTALL_AND_COMPILE_PYTHON_FILE(${CMAKE_CURRENT_BINARY_DIR}/tmp/\${file} ${SALOME_INSTALL_SCRIPT_PYTHON}/Macro)
+ENDFOREACH()
+
+SET(MAKE_CLEAN_FILES tmp)
+SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MAKE_CLEAN_FILES}")
index eaf168fb8cd559c51cdf241179e14ce0d27e0af0..731f6aeac2de2d43c312dedee19884c87543378d 100644 (file)
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
+#
+# Do not touch this anchor comment
+#
+
 try: paraview.simple
 except: from paraview.simple import *
 paraview.simple._DisableFirstRenderCameraReset()
index 3555f9ad31dfa45f41e218ec2758335da5e88ee5..dcf2a70253be0a4987ecafb4270656f0cfc47f6d 100644 (file)
@@ -351,15 +351,18 @@ PVGUI_Module::PVGUI_Module()
 #endif
   ParavisModule = this;
 
-  // Clear old macros
+  // Clear old copies of embedded macros files
   QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
   QStringList aFilter;
   aFilter << "*.py";
 
   QDir aDestDir(aDestPath);
   QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
-  foreach (QString aStr, aDestFiles) {
-    aDestDir.remove(aStr);
+  foreach (QString aMacrosPath, getEmbeddedMacrosList()) {
+    QString aMacrosName = QFileInfo(aMacrosPath).fileName();
+    if (aDestFiles.contains(aMacrosName)) {
+      aDestDir.remove(aMacrosName);
+    }
   }
 }
 
@@ -672,13 +675,11 @@ void PVGUI_Module::timerEvent(QTimerEvent* te )
 #endif
 }
   
-void PVGUI_Module::updateMacros()
+/*!
+  \brief Get list of embedded macros files
+*/
+QStringList PVGUI_Module::getEmbeddedMacrosList()
 {
-  pqPythonManager* aPythonManager = pqPVApplicationCore::instance()->pythonManager();
-  if(!aPythonManager)  {
-    return;
-  }
-  
   QString aRootDir = getenv("PARAVIS_ROOT_DIR");
 
   QString aSourcePath = aRootDir + "/bin/salome/Macro";
@@ -688,8 +689,22 @@ void PVGUI_Module::updateMacros()
 
   QDir aSourceDir(aSourcePath);
   QStringList aSourceFiles = aSourceDir.entryList(aFilter, QDir::Files);
-  foreach (QString aStr, aSourceFiles) {
-    aPythonManager->addMacro(aSourcePath + "/" + aStr);
+  QStringList aFullPathSourceFiles;
+  foreach (QString aMacrosName, aSourceFiles) {
+    aFullPathSourceFiles << aSourceDir.absoluteFilePath(aMacrosName);
+  }
+  return aFullPathSourceFiles;
+}
+
+void PVGUI_Module::updateMacros()
+{
+  pqPythonManager* aPythonManager = pqPVApplicationCore::instance()->pythonManager();
+  if(!aPythonManager)  {
+    return;
+  }
+  
+  foreach (QString aStr, getEmbeddedMacrosList()) {
+    aPythonManager->addMacro(aStr);
   }
 }
 
index fef41de7e33a64a4f5bafe88c28ffb187fe75059..e55567c18bbe0b16fa0c8e49ff9423f2957f969c 100644 (file)
@@ -208,6 +208,9 @@ private:
   //! Load selected state
   void loadSelectedState(bool toClear);
 
+  //! Get list of embedded macros files
+  QStringList getEmbeddedMacrosList();
+
   //! update macros state
   void updateMacros();