Salome HOME
updated copyright message
[modules/gui.git] / src / SVTK / SVTK_Recorder.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 955849c..1be7fe3
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -34,6 +34,7 @@
 #include <sstream>
 #include <iomanip>
 #include <iostream>
+#include <math.h>
 
 #ifndef WIN32
 #include <unistd.h>
 #include <QFileInfo>
 #include <QDir>
 
-//#include "utilities.h"
-
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
+#include "utilities.h"
 
 
 namespace
@@ -57,7 +52,7 @@ namespace
   //----------------------------------------------------------------------------
   inline
   void
-  GetNameJPEG(const std::string& thePreffix,  
+  GetNameJPEG(const std::string& thePreffix,
               const int theIndex,
               std::string& theName)
   {
@@ -68,30 +63,30 @@ namespace
 }
 
 //----------------------------------------------------------------------------
-vtkStandardNewMacro(SVTK_Recorder);
+vtkStandardNewMacro(SVTK_Recorder)
 
 
 //----------------------------------------------------------------------------
 SVTK_Recorder
 ::SVTK_Recorder():
-  myRenderWindow(NULL),
   myState(SVTK_Recorder_Stop),
+  myPaused(0),
+  myErrorStatus(0),
+  myPriority(0.0),
+  myTimeStart(0.0),
+  myFrameIndex(0),
+  myNbWrittenFrames(0),
   myNbFPS(5.5),
   myQuality(100),
   myProgressiveMode(true),
   myUseSkippedFrames(true),
-  myErrorStatus(0),
+  myNameAVIMaker("jpeg2yuv"),
   myCommand(vtkCallbackCommand::New()),
-  myPriority(0.0),
-  myTimeStart(0.0),
-  myFrameIndex(0),
-  myPaused(0),
+  myRenderWindow(NULL),
   myFilter(vtkWindowToImageFilter::New()),
-  myWriterMgr(new SVTK_ImageWriterMgr),
-  myNbWrittenFrames(0),
-  myNameAVIMaker("jpeg2yuv")
+  myWriterMgr(new SVTK_ImageWriterMgr)
 {
-  myCommand->SetClientData(this); 
+  myCommand->SetClientData(this);
   myCommand->SetCallback(SVTK_Recorder::ProcessEvents);
 }
 
@@ -133,7 +128,7 @@ SVTK_Recorder
   myName = theName;
 }
 
-const char* 
+const char*
 SVTK_Recorder::Name() const
 {
   return myName.c_str();
@@ -173,14 +168,14 @@ SVTK_Recorder
 
 
 //----------------------------------------------------------------------------
-void 
+void
 SVTK_Recorder
 ::SetRenderWindow(vtkRenderWindow* theRenderWindow)
 {
   myRenderWindow = theRenderWindow;
 }
 
-vtkRenderWindow* 
+vtkRenderWindow*
 SVTK_Recorder
 ::RenderWindow()
 {
@@ -239,12 +234,12 @@ SVTK_Recorder
 //----------------------------------------------------------------------------
 void
 SVTK_Recorder
-::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
+::ProcessEvents(vtkObject* vtkNotUsed(theObject),
                 unsigned long theEvent,
-                void* theClientData, 
+                void* theClientData,
                 void* vtkNotUsed(theCallData))
 {
-  if(vtkObject* anObj = reinterpret_cast<vtkObject*>(theClientData)){ 
+  if(vtkObject* anObj = reinterpret_cast<vtkObject*>(theClientData)){
     if(SVTK_Recorder* aSelf = dynamic_cast<SVTK_Recorder*>(anObj)){
       if(theEvent==vtkCommand::EndEvent){
         if(aSelf->State() == SVTK_Recorder::SVTK_Recorder_Record){
@@ -284,7 +279,7 @@ SVTK_Recorder
 {
   QApplication::setOverrideCursor( Qt::WaitCursor );
 
-  if(myState == SVTK_Recorder_Record){ 
+  if(myState == SVTK_Recorder_Record){
     if(!myPaused)
       DoRecord();
 
@@ -312,13 +307,15 @@ SVTK_Recorder
   myPaused = myPaused ? 0 : 1;
   if(myPaused && !myFrameIndexes.empty()){
     myFrameIndexes.back() *= -1;
-    if(MYDEBUG) cout<<"SVTK_Recorder::Pause - myFrameIndexes.back() = "<<myFrameIndexes.back()<<endl;
+
+    if(SALOME::VerbosityActivated())
+      cout << "SVTK_Recorder::Pause - myFrameIndexes.back() = " << myFrameIndexes.back() << endl;
   }
 }
 
 
 //----------------------------------------------------------------------------
-inline 
+inline
 int
 GetFrameIndex(double theStartTime,
               double theFPS)
@@ -348,9 +345,11 @@ SVTK_Recorder
     if(aLastFrameIndex < 0){
       myFrameIndexes.back() = abs(myFrameIndexes.back());
       double aPauseTime = fabs((double)(aFrameIndex - myFrameIndex - 1)) / myNbFPS;
-      if(MYDEBUG) 
-        cout<<"SVTK_Recorder::DoRecord - aFrameIndex = "<<aFrameIndex<<
-          "; aPauseTime = "<<aPauseTime<<endl;
+
+      if(SALOME::VerbosityActivated())
+        cout << "SVTK_Recorder::DoRecord - aFrameIndex = " << aFrameIndex <<
+        "; aPauseTime = " << aPauseTime << endl;
+
       myTimeStart += aPauseTime;
     }
 
@@ -362,7 +361,8 @@ SVTK_Recorder
   }
 
   myFrameIndexes.push_back(myFrameIndex);
-  if(MYDEBUG) cout<<"SVTK_Recorder::DoRecord - myFrameIndex = "<<myFrameIndex<<endl;
+  if(SALOME::VerbosityActivated())
+    cout << "SVTK_Recorder::DoRecord - myFrameIndex = " << myFrameIndex << endl;
 
   myRenderWindow->RemoveObserver(myCommand);
   myFilter->Modified();
@@ -372,7 +372,7 @@ SVTK_Recorder
 
   PreWrite();
 
-  vtkImageData *anImageData = vtkImageData::New(); 
+  vtkImageData *anImageData = vtkImageData::New();
   anImageData->DeepCopy(myFilter->GetOutput());
 
   myWriterMgr->StartImageWriter(myFilter,anImageData,aName,myProgressiveMode,myQuality);
@@ -433,17 +433,19 @@ SVTK_Recorder
       aStream<<"COPY /Y "<<QString::fromStdString(anInitialName).replace("/","\\\\").toStdString()<<
                  " "<<QString::fromStdString(anCurrentName).replace("/","\\\\").toStdString()<<" > NUL";
   #endif
-      if(anIndex + 1 < aFinishIndex)
+      if(anIndex + 1 < aFinishIndex) {
   #ifndef WIN32
         aStream<<" \\";
         aStream<<endl;
   #else
         aStream<<" & ";
   #endif
+      }
     }
     std::string aString(aStream.str());
     system(aString.c_str());
-    if(MYDEBUG) cout<<"SVTK_Recorder::AddSkippedFrames - "<<aString<<endl;
+    if(SALOME::VerbosityActivated())
+      cout << "SVTK_Recorder::AddSkippedFrames - " << aString << endl;
   }
 }
 
@@ -461,22 +463,23 @@ SVTK_Recorder
     //" -f "<<int(myNbFPS)<<" "<<
     " -f "<<myNbFPS<<" "<<
     " -n "<<myNbWrittenFrames<<" "<<
-    " -j \""<<myName<<"_\%06d.jpeg\" "<<
+    " -j \""<<myName<<"_%06d.jpeg\" "<<
     "| yuv2lav"<<" -o \""<<myName<<"\"";
 #ifdef WIN32
-  aStream<<" -f aA";   
+  aStream<<" -f aA";
 #endif
   std::string aString(aStream.str());
   myErrorStatus = system(aString.c_str());
 
-  if(MYDEBUG) cout<<"SVTK_Recorder::MakeFileAVI - "<<aString<<endl;
+  if(SALOME::VerbosityActivated())
+    cout << "SVTK_Recorder::MakeFileAVI - " << aString << endl;
 
   QFileInfo aFileInfo(myName.c_str());
   QString aDirPath = aFileInfo.absoluteDir().path();
   QString aBaseName = aFileInfo.fileName();
   QString aCommand;
 #ifndef WIN32
-  aCommand = QString("(cd ") + aDirPath + 
+  aCommand = QString("(cd ") + aDirPath +
     "; ls " +
     " | egrep '" + aBaseName + "_[0-9]*.jpeg'" +
     " | xargs rm " +
@@ -484,11 +487,13 @@ SVTK_Recorder
 #else
   QString tmpFile = QString("_") + aBaseName + "_tempfile";
   QString diskName = aDirPath.split("/")[0];
-  aCommand = diskName + " && (cd " + aDirPath.replace("/","\\\\") + 
-       " && ((dir /b | findstr " + aBaseName + "_[0-9]*.jpeg > " + tmpFile + 
+  aCommand = diskName + " && (cd " + aDirPath.replace("/","\\\\") +
+       " && ((dir /b | findstr " + aBaseName + "_[0-9]*.jpeg > " + tmpFile +
        ") & (for /f %i in (" + tmpFile + ") do (del \"%i\")) & (del " + tmpFile + "))) > NUL";
 #endif
 
-  if(MYDEBUG) cout<<"SVTK_Recorder::MakeFileAVI - "<<(const char*)aCommand.toLatin1()<<endl;
-  system((const char*)aCommand.toLatin1());
+  if(SALOME::VerbosityActivated())
+    cout << "SVTK_Recorder::MakeFileAVI - " << (const char*)aCommand.toUtf8() << endl;
+    
+  system((const char*)aCommand.toUtf8());
 }