]> Creatis software - creaMaracasVisu.git/commitdiff
DFCH: imageUndoRedo 100% =)
authorDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Tue, 13 Dec 2011 10:12:07 +0000 (10:12 +0000)
committerDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Tue, 13 Dec 2011 10:12:07 +0000 (10:12 +0000)
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx

index 41c29693580c84c0a07c422080ad78521c8ddfa5..efd0d91e8160f3c76d3185d78f503092f210b1ea 100755 (executable)
 #include <sstream>
 
 // ----------------------------------------------------------------------------------
-Image3DDequeUR::Image3DDequeUR() {
-       this->m_GlobalPath = "/home/caceres/temporal/";
+Image3DDequeUR::Image3DDequeUR( )
+{
+
+
+#ifdef _WIN32
+       this->m_GlobalPath = std::getenv("TEMP");
+#endif
+#ifdef _WIN64
+       this->m_GlobalPath = std::getenv("TEMP");
+#endif
+#ifdef LINUX
+       this->m_GlobalPath = "/tmp/";
+#endif // MACOSX
        this->m_CurrentURPos = -1;
 }
 // ----------------------------------------------------------------------------------
 //virtual
-Image3DDequeUR::~Image3DDequeUR() {
-       this->CleanHardDisk();
+Image3DDequeUR::~Image3DDequeUR( )
+{
+       this->CleanHardDisk( );
 }
 // ----------------------------------------------------------------------------------
 //virtual
-void Image3DDequeUR::AddImagesToURContainer(VTKImageDataPointerType imgUndo,
-               VTKImageDataPointerType imgRedo, ImageMManager* imMManager) {
-       this->CleanURContainerFromIndex(this->m_CurrentURPos + 1);
+void Image3DDequeUR::AddImagesToURContainer( VTKImageDataPointerType imgUndo,
+       VTKImageDataPointerType imgRedo, ImageMManager* imMManager )
+{
+       this->CleanURContainerFromIndex( this->m_CurrentURPos + 1 );
        //Adding image
-       ImageInfoUR* imageInfo = new ImageInfoUR();
-       imageInfo->SetImageName(this->GetImageName(this->m_ImgURDeque.size()));
-       imageInfo->SetImages(imgUndo, imgRedo);
-       imageInfo->SetImageMManager(imMManager);
+       ImageInfoUR* imageInfo = new ImageInfoUR( );
+       imageInfo->SetImageName( this->GetImageName( this->m_ImgURDeque.size( ) ) );
+       imageInfo->SetImages( imgUndo, imgRedo );
+       imageInfo->SetImageMManager( imMManager );
        //Adding to deque
-       this->m_ImgURDeque.push_back(imageInfo);
-       this->m_CurrentURPos = this->m_ImgURDeque.size() - 1;
+       this->m_ImgURDeque.push_back( imageInfo );
+       this->m_CurrentURPos = this->m_ImgURDeque.size( ) - 1;
        //Managing memory
-       this->ManageMemory();
+       this->ManageMemory( );
 }
 // ----------------------------------------------------------------------------------
 //virtual
-ImageInfoUR* Image3DDequeUR::Undo() {
+ImageInfoUR* Image3DDequeUR::Undo( )
+{
        ImageInfoUR* imgRet = NULL;
-       int imgURDequeSize = this->m_ImgURDeque.size();
-       if ((this->m_ImgURDeque.size() > 0) && (this->m_CurrentURPos != -1)
-                       && (this->m_CurrentURPos < imgURDequeSize)) {
-               imgRet = this->m_ImgURDeque[m_CurrentURPos];
+       int imgURDequeSize = this->m_ImgURDeque.size( );
+       if( ( this->m_ImgURDeque.size( ) > 0 ) && ( this->m_CurrentURPos != -1 )
+               && ( this->m_CurrentURPos < imgURDequeSize ) )
+       {
+               imgRet = this->m_ImgURDeque[ m_CurrentURPos ];
                this->m_CurrentURPos--;
        } //fi
-       return (imgRet);
+       return ( imgRet );
 }
 // ----------------------------------------------------------------------------------
 //virtual
-ImageInfoUR* Image3DDequeUR::Redo() {
+ImageInfoUR* Image3DDequeUR::Redo( )
+{
        ImageInfoUR* imgRet = NULL;
        this->m_CurrentURPos++;
-       int imgURDequeSize = this->m_ImgURDeque.size();
-       if ((this->m_ImgURDeque.size() > 0) && (this->m_CurrentURPos != -1)
-                       && (this->m_CurrentURPos < imgURDequeSize)) {
-               imgRet = this->m_ImgURDeque[m_CurrentURPos];
+       int imgURDequeSize = this->m_ImgURDeque.size( );
+       if( ( this->m_ImgURDeque.size( ) > 0 ) && ( this->m_CurrentURPos != -1 )
+               && ( this->m_CurrentURPos < imgURDequeSize ) )
+       {
+               imgRet = this->m_ImgURDeque[ m_CurrentURPos ];
        } //fi
-       else {
+       else
+       {
                this->m_CurrentURPos--;
        }
-       return (imgRet);
+       return ( imgRet );
 }
 // ----------------------------------------------------------------------------------
 //virtual
-void Image3DDequeUR::CleanURContainerFromIndex(const int& index) {
+void Image3DDequeUR::CleanURContainerFromIndex( const int& index )
+{
        int count = 0;
-       for (unsigned int i = index; i < this->m_ImgURDeque.size(); i++) {
-               this->m_ImgURDeque[i]->RemoveImagesFromMemory(this->m_GlobalPath);
-               this->m_ImgURDeque[i]->RemoveImagesFromDisk(this->m_GlobalPath);
+       for( unsigned int i = index; i < this->m_ImgURDeque.size( ); i++ )
+       {
+               this->m_ImgURDeque[ i ]->RemoveImagesFromMemory( this->m_GlobalPath );
+               this->m_ImgURDeque[ i ]->RemoveImagesFromDisk( this->m_GlobalPath );
                count++;
        }
-       for (int i = 0; i < count; i++) {
-               this->m_ImgURDeque.pop_back();
+       for( int i = 0; i < count; i++ )
+       {
+               this->m_ImgURDeque.pop_back( );
        } //rof
 }
 // ----------------------------------------------------------------------------------
 //virtual
-void Image3DDequeUR::ManageMemory() {
-       int imgURDequeSize = this->m_ImgURDeque.size();
-       for (int i = 0; i < imgURDequeSize; i++) {
-               if (this->m_ImgURDeque[i]->GetStatus()) {
-                       this->m_ImgURDeque[i]->RemoveImagesFromMemory(this->m_GlobalPath);
+void Image3DDequeUR::ManageMemory( )
+{
+       int imgURDequeSize = this->m_ImgURDeque.size( );
+       for( int i = 0; i < imgURDequeSize; i++ )
+       {
+               if( this->m_ImgURDeque[ i ]->GetStatus( ) )
+               {
+                       this->m_ImgURDeque[ i ]->RemoveImagesFromMemory(
+                               this->m_GlobalPath );
                } //fi
        } //rof
          //Adding CurrentUndoPos to memory
-       if ((this->m_CurrentURPos != -1)
-                       && !(this->m_ImgURDeque[this->m_CurrentURPos]->GetStatus())) {
-               this->m_ImgURDeque[this->m_CurrentURPos]->LoadImagesToMemory(
-                               this->m_GlobalPath);
+       if( ( this->m_CurrentURPos != -1 )
+               && !( this->m_ImgURDeque[ this->m_CurrentURPos ]->GetStatus( ) ) )
+       {
+               this->m_ImgURDeque[ this->m_CurrentURPos ]->LoadImagesToMemory(
+                       this->m_GlobalPath );
        }
        int currentRedoPos = this->m_CurrentURPos + 1;
-       if ((currentRedoPos < imgURDequeSize)
-                       && !(this->m_ImgURDeque[currentRedoPos]->GetStatus())) {
-               this->m_ImgURDeque[currentRedoPos]->LoadImagesToMemory(
-                               this->m_GlobalPath);
+       if( ( currentRedoPos < imgURDequeSize )
+               && !( this->m_ImgURDeque[ currentRedoPos ]->GetStatus( ) ) )
+       {
+               this->m_ImgURDeque[ currentRedoPos ]->LoadImagesToMemory(
+                       this->m_GlobalPath );
        }
 }
 // ----------------------------------------------------------------------------------
-void Image3DDequeUR::SetGlobalPath(const StringType& globalPath) {
+void Image3DDequeUR::SetGlobalPath( const StringType& globalPath )
+{
        this->m_GlobalPath = globalPath;
 }
 // ----------------------------------------------------------------------------------
-void Image3DDequeUR::CleanHardDisk() {
-       for (unsigned int i = 0; i < this->m_ImgURDeque.size(); i++) {
-               this->m_ImgURDeque[i]->RemoveImagesFromDisk(this->m_GlobalPath);
+void Image3DDequeUR::CleanHardDisk( )
+{
+       for( unsigned int i = 0; i < this->m_ImgURDeque.size( ); i++ )
+       {
+               this->m_ImgURDeque[ i ]->RemoveImagesFromDisk( this->m_GlobalPath );
        }
 }
 // ----------------------------------------------------------------------------------
-Image3DDequeUR::StringType Image3DDequeUR::GetGlobalPath() {
-       return (this->m_GlobalPath);
+Image3DDequeUR::StringType Image3DDequeUR::GetGlobalPath( )
+{
+       return ( this->m_GlobalPath );
 }
 // ----------------------------------------------------------------------------------
-Image3DDequeUR::StringType Image3DDequeUR::GetImageName(const int & pos) {
+Image3DDequeUR::StringType Image3DDequeUR::GetImageName( const int & pos )
+{
 //Giving a name to an image using the date and time
-       if (this->m_IDImages.empty()) {
+       if( this->m_IDImages.empty( ) )
+       {
                time_t rawtime;
                struct tm * timeinfo;
-               char buffer[80];
-               time(&rawtime);
-               timeinfo = localtime(&rawtime);
-               strftime(buffer, 80, "%H%M%S_%a_%d_%b_%y_", timeinfo);
-               StringType date(buffer);
-               StringType aux(buffer);
+               char buffer[ 80 ];
+               time( &rawtime );
+               timeinfo = localtime( &rawtime );
+               strftime( buffer, 80, "%H%M%S_%a_%d_%b_%y_", timeinfo );
+               StringType date( buffer );
+               StringType aux( buffer );
                this->m_IDImages = "img_" + aux;
        }
        std::stringstream ss; //create a stringstream
        ss << pos; //add number to the stream
-       StringType imageName = this->m_IDImages + ss.str();
-       return (imageName);
+       StringType imageName = this->m_IDImages + ss.str( );
+       return ( imageName );
 }
 // ----------------------------------------------------------------------------------