]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Added a mutex for VISU_TimeAnimation::myDumpPath member (to avoid problems with anima...
authorouv <ouv@opencascade.com>
Wed, 27 Apr 2011 09:24:55 +0000 (09:24 +0000)
committerouv <ouv@opencascade.com>
Wed, 27 Apr 2011 09:24:55 +0000 (09:24 +0000)
src/VISU_I/VISU_TimeAnimation.cxx
src/VISU_I/VISU_TimeAnimation.h

index 497166a38e43062e3488d62a6ccc8d0dd027c31b..48465c8509cf1f22def38c7f5ca9c4d1411e3a83 100644 (file)
@@ -118,6 +118,30 @@ namespace VISU
   };
 
 
+  //------------------------------------------------------------------------
+  class DumpPath 
+  {
+    QString myPath;
+    QMutex myPathMutex;
+  public:
+    DumpPath(QString thePath = QString())
+      : myPath(thePath) {}
+
+    QString GetPath() {
+      QString aPath;
+      myPathMutex.lock();
+      aPath = myPath;
+      myPathMutex.unlock();
+      return aPath;
+    }
+    void SetPath(QString thePath) {
+      myPathMutex.lock();
+      myPath = thePath;
+      myPathMutex.unlock();
+    }
+  };
+
+
   //------------------------------------------------------------------------
   struct TCompositeMinMaxController : virtual TVTKMinMaxController
   {
@@ -205,7 +229,8 @@ VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy,
 
   myAnimEntry = "";
 
-  myDumpPath = "";
+  myDumpPath = new VISU::DumpPath( "" );
+
   myAVIMaker = "jpeg2yuv";
 
   myDumpMode = VISU::GetResourceMgr()->integerValue("VISU", "dump_mode", 0);
@@ -231,7 +256,7 @@ VISU_TimeAnimation::~VISU_TimeAnimation()
 
   delete myExecutionState;
 
-  myDumpPath = "";
+  delete myDumpPath;
 
   /* Terminates the execution of the thread. 
    * The thread may or may not be terminated immediately, 
@@ -1248,7 +1273,7 @@ void VISU_TimeAnimation::parallelAnimation( bool& theIsDumping, QList<int>& theI
       }
     }
     int delay = (int)(1000. * k / mySpeed);
-    theIsDumping = !myDumpPath.isEmpty();
+    theIsDumping = !myDumpPath->GetPath().isEmpty();
     if (delay < 1 && theIsDumping) {
       // We must unlock mutex for some time before grabbing to allow view updating
       delay = 1;
@@ -1362,7 +1387,7 @@ void VISU_TimeAnimation::successiveAnimation( bool& theIsDumping, QList<int>& th
           }
         }
         int delay = (int)(1000. * k / mySpeed);
-        theIsDumping = !myDumpPath.isEmpty();
+        theIsDumping = !myDumpPath->GetPath().isEmpty();
         if (delay < 1 && theIsDumping) {
           // We must unlock mutex for some time before grabbing to allow view updating
           delay = 1;
@@ -1401,7 +1426,7 @@ void VISU_TimeAnimation::saveImages( int theFieldId,
                                      QList<int>& theIndexList )
 {
   if (myDumpFormat.compare("AVI") != 0) {
-    QString aFile(myDumpPath);
+    QString aFile(myDumpPath->GetPath());
 
     int aFrameNb = myFrame; // parallel animation mode
     if ( myAnimationMode == VISU::Animation::SUCCESSIVE ) // successive animation mode
@@ -1426,7 +1451,7 @@ void VISU_TimeAnimation::saveImages( int theFieldId,
     ProcessEvent(new TMemFun2ArgEvent<SUIT_ViewWindow,bool,const QString&,const QString&>
                  (myView,&SUIT_ViewWindow::dumpViewToFormat,aFile,myDumpFormat));
   } else {
-    QFileInfo aFileInfo(myDumpPath);
+    QFileInfo aFileInfo(myDumpPath->GetPath());
     QString aDirPath = aFileInfo.absolutePath();
     QString aBaseName = aFileInfo.fileName();
     
@@ -1481,7 +1506,7 @@ void VISU_TimeAnimation::run()
     return;
   }
 
-  bool isDumping = !myDumpPath.isEmpty();
+  bool isDumping = !myDumpPath->GetPath().isEmpty();
   myFileIndex = 0;
   QList<int> anIndexList;
 
@@ -1494,7 +1519,7 @@ void VISU_TimeAnimation::run()
   if (isDumping && myDumpFormat.compare("AVI") == 0 && myExecutionState->IsActive()) {
     double aFPS = 17.3 * mySpeed / myTimeStampFrequency;
 
-    QFileInfo aFileInfo(myDumpPath);
+    QFileInfo aFileInfo(myDumpPath->GetPath());
     QString aDirPath = aFileInfo.absolutePath();
     QString aBaseName = aFileInfo.fileName();
 
@@ -1535,7 +1560,7 @@ void VISU_TimeAnimation::run()
     aCmd += QString(" -n %1").arg(myFileIndex+1);
     aCmd += QString(" -j \"%1\"").arg(aPattern);
     aCmd += " | yuv2lav";
-    aCmd += QString(" -o \"%1\"").arg(myDumpPath);
+    aCmd += QString(" -o \"%1\"").arg(myDumpPath->GetPath());
   #ifdef WIN32
     aCmd += " -f aA";   
   #endif
@@ -1671,6 +1696,12 @@ bool VISU_TimeAnimation::getIndicesFromSequence( QString theSequence, QList<long
   return isCorrect;
 }
 
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::dumpTo(const char* thePath)
+{
+  myDumpPath->SetPath( QString( thePath ) );
+}
+
 //------------------------------------------------------------------------
 std::string VISU_TimeAnimation::setDumpFormat(const char* theFormat)
 {
index ececa386b9266a36a026aa7da42b67899e644c35..3618c6232204a5322a3b0e0406e60dc40cac7ce5 100644 (file)
@@ -46,6 +46,7 @@ namespace VISU
   //class Result_i;
   class ColoredPrs3d_i;
   class ExecutionState;
+  class DumpPath;
 }
 
 struct FieldData
@@ -155,7 +156,7 @@ class VISU_I_EXPORT VISU_TimeAnimation: public QThread
 
   bool getIndicesFromSequence( QString theSequence, QList<long>& theIndices );
 
-  void dumpTo(const char* thePath) { myDumpPath = thePath; }
+  void dumpTo(const char* thePath);
   std::string setDumpFormat(const char* theFormat);
 
   void setTimeStampFrequency(CORBA::Long theFrequency);
@@ -218,11 +219,12 @@ class VISU_I_EXPORT VISU_TimeAnimation: public QThread
   bool myCleaningMemoryAtEachFrame;
   _PTR(Study) myStudy;
 
+  VISU::DumpPath* myDumpPath;
+
   VISU::Animation::AnimationMode myAnimationMode;
   double myTimeMinVal, myTimeMaxVal; //!< Range of time stams, set by user
   double myTimeMin   , myTimeMax   ; //!< Range of time stams, available for animation
   QString mySequence;
-  QString myDumpPath;
   QString myDumpFormat;
   QString myAVIMaker;
   long myFileIndex;