]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx
Undo Redo
[creaMaracasVisu.git] / lib / maracasVisuLib / src / CutModule / kernel / CutModelManager.cxx
index 796932d38addab8292b0b252313cb403e63b79f0..652faa7d6d2d1c2efe72b7a52273ae54e8174aaf 100644 (file)
@@ -3,8 +3,8 @@
   Program:   wxMaracas
   Module:    $RCSfile: CutModelManager.cxx,v $
   Language:  C++
-  Date:      $Date: 2009/09/01 14:01:36 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2009/09/08 08:14:27 $
+  Version:   $Revision: 1.3 $
 
   Copyright: (c) 2002, 2003
   License:
 /**
 **     Start of the manager class
 **/
-CutModelManager::CutModelManager(){
+CutModelManager::CutModelManager(std::string path){
+       _path = path;
        _img = NULL;
        _copyimg = NULL;
        _interactor = NULL;     
        _render = NULL;
+       _currentaction=0;
 }
 CutModelManager::~CutModelManager(){
+       std::string files = _path;
+    files+="/infounrd_0_fig_0.info";   
+       remove(files.c_str());
 }
 
 
@@ -156,9 +161,18 @@ void CutModelManager::RemoveActor(int id)throw( CutModelException){
 
 void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
     checkInvariant();
+               
        CutModelData* current = getCutModelData(id);
        current->ExecuteCut(range, isinside,_copyimg);
 
+
+       /*
+       Setting extra information for the undo
+       */
+       CutModelSaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL_CUT);
+       undoaction->setRange(range);
+       undoaction->setIsInside(isinside);
+
 }
 
 vtkImageData* CutModelManager::GetResultImage(){
@@ -173,4 +187,94 @@ void CutModelManager::RefreshActor(int id){
        _render->AddActor(current->getActor()); 
        current->RefreshViewBox();
        _render->Render();
+}
+
+void CutModelManager::SaveCutModelData(std::string filename)throw( CutModelException){ 
+
+       
+       throw CutModelException("not implemented");
+       
+       
+       
+       
+}
+
+
+
+void CutModelManager::LoadCutModelData(std::string filename)throw( CutModelException){
+       
+       throw CutModelException("not implemented");
+       
+}
+
+CutModelSaveBinInfo* CutModelManager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModelException){
+       
+       for(int i = _undoredo.size()-1; i > _currentaction;i--){
+               delete _undoredo[i];
+               _undoredo.pop_back();           
+       }
+
+       CutModelSaveBinInfo* cutmodel = new CutModelSaveBinInfo(idc, _currentaction, type, _path);
+       if(type == CUTMODEL_CUT){
+               cutmodel->saveMatrix4x4(this->getCutModelData(idc)->getCurrentMatrix()->GetMatrix());
+               cutmodel->setCurrentShape(this->getCutModelData(idc)->getCurrentShape());
+       }
+
+       _undoredo.push_back(cutmodel);
+
+       _currentaction++;// = _undoredo.size();
+       //std::cout<<"current index "<<_currentaction;
+               
+       return cutmodel;
+}
+
+int CutModelManager::Undo()    throw( CutModelException){
+ //&& _currentaction < _undoredo.size()
+       if(_currentaction > 0){
+               int tempaction = _currentaction-1;
+               CutModelSaveBinInfo* currentundo = _undoredo[tempaction];
+               CutModelData* currentmodel;
+
+               if(currentundo->getActionType()==CUTMODEL_CUT){
+                       //Undo the cut
+                       vtkTransform* transform = currentundo->getTransformFromMatrixFile();
+
+                       currentmodel = getCutModelData(currentundo->getId());
+
+                       currentmodel->setTransform(transform, _copyimg);
+
+                       currentmodel->setCurrentShape(currentundo->getCurrentShape());
+
+                       currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img, _copyimg);
+
+               }
+               //Every thing ok
+               _currentaction--;
+               return 0;
+       }
+       return -1;
+}
+
+int CutModelManager::Redo()    throw( CutModelException){
+
+       if(_currentaction >= 0 && _currentaction < _undoredo.size()){
+               
+
+               CutModelSaveBinInfo* currentundo = _undoredo[_currentaction];
+               CutModelData* currentmodel;
+
+               if(currentundo->getActionType()==CUTMODEL_CUT){
+                       //Redo the cut
+                       vtkTransform* transform = currentundo->getTransformFromMatrixFile();
+                       currentmodel = getCutModelData(currentundo->getId());
+                       currentmodel->setTransform(transform, _copyimg);
+                       currentmodel->setCurrentShape(currentundo->getCurrentShape());
+                       currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);
+               }
+
+               _currentaction++;
+
+               return 0;
+       }
+       return -1;
 }
\ No newline at end of file