From: Diego Caceres Date: Tue, 8 Nov 2011 16:38:50 +0000 (+0000) Subject: DFCH: ManualPaint- imageUNDOREDO (Undo now working but still some big changes to... X-Git-Tag: v1.0.4~44 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=bdde32eafd443eacaca7876a95d5a64bce9aa471;p=creaMaracasVisu.git DFCH: ManualPaint- imageUNDOREDO (Undo now working but still some big changes to make redo works) ---- BaseLine before make redo works --- diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx index d24c809..41d7c56 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx @@ -14,6 +14,7 @@ Image3DDequeUR::~Image3DDequeUR() { //virtual void Image3DDequeUR::AddImageToUndoContainer(VTKImageDataPointerType img, ImageMManagerType* imMManager) { + this->CleanUndoContainerFromIndex(this->m_CurrentUndoPos + 1); //Adding image ImageInfoUR* imageInfo = new ImageInfoUR(); imageInfo->SetImageName( @@ -25,6 +26,8 @@ void Image3DDequeUR::AddImageToUndoContainer(VTKImageDataPointerType img, this->m_CurrentUndoPos = this->m_ImgUndoDeque.size() - 1; //Managing memory this->ManageMemory(); + //clean redo container + this->CleanRedoContainer(); } //virtual ImageInfoUR* Image3DDequeUR::Undo() { @@ -38,11 +41,27 @@ ImageInfoUR* Image3DDequeUR::Undo() { //virtual void Image3DDequeUR::AddImageToRedoContainer(VTKImageDataPointerType img, ImageMManagerType* imMManager) { + //Adding image + ImageInfoUR* imageInfo = new ImageInfoUR(); + imageInfo->SetImageName( + this->GetImageName(this->m_ImgRedoDeque.size(), false)); + imageInfo->SetImage(img); + imageInfo->SetImageMManager(imMManager); + //Adding to deque + this->m_ImgRedoDeque.push_back(imageInfo); + this->m_CurrentRedoPos = this->m_ImgRedoDeque.size() - 1; + //Managing memory + this->ManageMemory(); + } //virtual ImageInfoUR* Image3DDequeUR::Redo() { - - ImageInfoUR* imgRet = new ImageInfoUR(); + ImageInfoUR* imgRet = NULL; + if ((this->m_ImgRedoDeque.size() > 0) && (this->m_CurrentRedoPos != -1)) { + imgRet = this->m_ImgRedoDeque[m_CurrentRedoPos]; + this->m_CurrentRedoPos--; + this->m_CurrentUndoPos++; + } //fi return (imgRet); } //virtual @@ -56,10 +75,13 @@ void Image3DDequeUR::CleanUndoContainerFromIndex(const int& index) { for (int i = 0; i < count; i++) { this->m_ImgUndoDeque.pop_back(); } //rof - } //virtual -void Image3DDequeUR::CleanRedoContainerFromIndex(const int& index) { +void Image3DDequeUR::CleanRedoContainer() { + for (unsigned int i = 0; i < this->m_ImgRedoDeque.size(); i++) { + this->m_ImgRedoDeque[i]->RemoveImageFromMemory(this->m_GlobalPath); + this->m_ImgRedoDeque[i]->RemoveImageFromDisk(this->m_GlobalPath); + } } //virtual void Image3DDequeUR::CleanContainers() { @@ -89,6 +111,17 @@ void Image3DDequeUR::ManageMemory() { this->m_GlobalPath); } //The same for the redo queue + for (int i = 0; (unsigned int) i < this->m_ImgRedoDeque.size(); i++) { + if (this->m_ImgRedoDeque[i]->GetStatus()) { + this->m_ImgRedoDeque[i]->RemoveImageFromMemory(this->m_GlobalPath); + } //fi + } //rof + //Adding CurrentUndoPos to memory + if ((this->m_CurrentRedoPos != -1) + && !(this->m_ImgRedoDeque[this->m_CurrentRedoPos]->GetStatus())) { + this->m_ImgRedoDeque[this->m_CurrentRedoPos]->LoadImageMHDToMemory( + this->m_GlobalPath); + } } void Image3DDequeUR::SetGlobalPath(const StringType& globalPath) { @@ -128,6 +161,5 @@ Image3DDequeUR::StringType Image3DDequeUR::GetImageName(const int & pos, imgType = "redo"; } StringType imageName = this->m_IDImages + imgType + ss.str(); - imageName.append(".mhd"); return (imageName); } diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h index dd861b2..718b4e2 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h @@ -24,7 +24,7 @@ public: virtual void AddImageToRedoContainer(VTKImageDataPointerType img, ImageMManagerType* imMManager); virtual void CleanUndoContainerFromIndex(const int& index); - virtual void CleanRedoContainerFromIndex(const int& index); + virtual void CleanRedoContainer( ); virtual void CleanContainers(); virtual void ManageMemory(); virtual ImageInfoUR* Undo(); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.cxx index a97ee3d..a51a77d 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.cxx @@ -15,7 +15,7 @@ void ImageDequeUR::AddImageToRedoContainer(VTKImageDataPointerType img, void ImageDequeUR::CleanUndoContainerFromIndex(const int& index) { } -void ImageDequeUR::CleanRedoContainerFromIndex(const int& index) { +void ImageDequeUR::CleanRedoContainer( ) { } void ImageDequeUR::CleanContainers() { diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.h index b7b8522..a5660b6 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.h @@ -31,7 +31,7 @@ public: virtual void AddImageToRedoContainer(VTKImageDataPointerType img, ImageMManager* imMManager); virtual void CleanUndoContainerFromIndex(const int& index); - virtual void CleanRedoContainerFromIndex(const int& index); + virtual void CleanRedoContainer(); virtual void CleanContainers(); virtual void ManageMemory(); virtual ImageInfoUR* Undo(); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageInfoUR.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageInfoUR.cxx index 263bce8..c00e972 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageInfoUR.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageInfoUR.cxx @@ -50,6 +50,7 @@ void ImageInfoUR::RemoveImageFromMemory(const StringType& gPath) { } void ImageInfoUR::LoadImageMHDToMemory(const StringType& gPath) { StringType filename = gPath + this->m_ImageName; + filename.append(".mhd"); VTKMetaImageReaderPointerType reader = VTKMetaImageReaderPointerType::New(); reader->SetFileName(filename.c_str()); this->m_Image = reader->GetOutput(); @@ -59,6 +60,7 @@ void ImageInfoUR::LoadImageMHDToMemory(const StringType& gPath) { void ImageInfoUR::SaveImageAsMHD(const StringType& gPath) { this->m_OnDisk = true; StringType filename = gPath + this->m_ImageName; + filename.append(".mhd"); //managing temporary files mkstemp((char*) filename.c_str()); VTKMetaImageWriterPointerType w = VTKMetaImageWriterPointerType::New(); @@ -70,8 +72,11 @@ void ImageInfoUR::SaveImageAsMHD(const StringType& gPath) { } void ImageInfoUR::RemoveImageFromDisk(const StringType& gPath) { - std::cout << "Borrando archivo" << endl; StringType filename = gPath + this->m_ImageName; - std::cout << filename << std::endl; + filename.append(".mhd"); + StringType filenameRaw = gPath + this->m_ImageName; + filenameRaw.append(".raw"); + mkstemp((char*) filenameRaw.c_str()); unlink((char*) filename.c_str()); + unlink((char*) filenameRaw.c_str()); } diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx index dd9bcec..bf52444 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx @@ -19,14 +19,18 @@ void ImageUndoRedo::Undo() { ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo(); if (imageInfo != NULL) { - //this->SetRedoImage(imageInfo->GetRegion()); + //this->SetRedoImage(imageInfo->GetImageMManager()); this->DrawUR(imageInfo); this->UpdateUndoImage(); } } //virtual void ImageUndoRedo::Redo() { - + /*ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo(); + if (imageInfo != NULL) + { + this->DrawUR(imageInfo); + }*/ } void ImageUndoRedo::SetImage(VTKImageDataPointerType image) { this->m_CurrentImage = image; @@ -48,11 +52,19 @@ void ImageUndoRedo::SetUndoImage(ImageMManagerType* imMManager) { } } //virtual -void ImageUndoRedo::SetRedoImage(const ImageMManagerType* imMManager) { - /*RegionSType region = imMManager.GetModifiedRegion(); - VTKImageDataPointerType imgResult = this->ImageMManagerType(region, - this->m_CurrentImage); - this->m_ImagesDeque->AddImageToRedoContainer(imgResult, imMManager);*/ +void ImageUndoRedo::SetRedoImage(ImageMManagerType* imMManager) { + /*this->m_CurrentImage->Update(); + ImageMManagerType* newImageManager = new ImageMManagerType(imMManager); + if (newImageManager->ValidateRegion()) { + RegionSType region = newImageManager->GetModifiedRegion(); + VTKImageDataPointerType imgResult = this->GetImageRegion(region, + this->m_CurrentImage); + this->m_ImagesDeque->AddImageToRedoContainer(imgResult, + newImageManager); + imgResult->Update(); + } else { + std::cerr << "INVALID REGION" << std::endl; + }*/ } void ImageUndoRedo::UpdateUndoImage() { diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h index c06caa7..d426d6f 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h @@ -18,7 +18,7 @@ public: virtual void Redo(); virtual void SetImage(VTKImageDataPointerType image); virtual void SetUndoImage(ImageMManagerType* imMManager); - virtual void SetRedoImage(const ImageMManagerType* imMManager); + virtual void SetRedoImage(ImageMManagerType* imMManager); void UpdateUndoImage(); void SetCurrentImage(VTKImageDataPointerType img); VTKImageDataPointerType GetImageRegion(const RegionSType& region, diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/managerUR.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/managerUR.cxx index afd33b6..289662f 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/managerUR.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/managerUR.cxx @@ -25,7 +25,7 @@ void ManagerUR::Redo() { void ManagerUR::SetUndoImage(ImageMManagerType* imMManager) { } -void ManagerUR::SetRedoImage(ImageMManagerType* imMManager) { +void ManagerUR::SetRedoImage(ImageMManagerType* imMManager){ } void ManagerUR::DrawUR(ImageInfoUR imageInfo) { diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp index eec9a1b..6414f88 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp @@ -108,3 +108,7 @@ void ManualPaintModel::SetUndoImage() { void ManualPaintModel::Undo() { this->_imageUndoRedo->Undo(); } + +void ManualPaintModel::Redo() { + this->_imageUndoRedo->Redo(); +} diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.h index 06d3142..55694ac 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.h @@ -26,6 +26,7 @@ public: void GetScalarRange(double * range); void SetUndoImage(); //DFCH void Undo(); //DFCH + void Redo(); //DFCH private: int _tool; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.cpp b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.cpp index 7c659eb..ae063ce 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.cpp +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.cpp @@ -79,6 +79,7 @@ wxManualPaintPanel::wxManualPaintPanel(wxWindow * parent) : wxButton *btnCopy = new wxButton(panel, -1, _T("Copy")); btnCopy->Disable(); wxButton *btnUndo = new wxButton(panel, -1, _T("Undo")); + wxButton *btnRedo = new wxButton(panel, -1, _T("Redo")); //btnUndo->Disable(); Connect( @@ -139,14 +140,19 @@ Connect ( btnCopy->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) (void(wxPanel::*)( - wxCommandEvent&)) &wxManualPaintPanel::OnCopy);Connect - ( + wxCommandEvent&)) &wxManualPaintPanel::OnCopy); + +Connect ( btnUndo->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) (void(wxPanel::*)( - wxCommandEvent&)) &wxManualPaintPanel::OnUndo); + wxCommandEvent&)) &wxManualPaintPanel::OnUndo);this + ->Connect(btnRedo->GetId(), + wxEVT_COMMAND_BUTTON_CLICKED, + (wxObjectEventFunction) (void(wxPanel::*)( + wxCommandEvent&)) &wxManualPaintPanel::OnRedo); //DFCH -Connect ( + Connect( _mBarSlices->GetId(), wxEVT_TSBAR, (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onBarrange); @@ -215,6 +221,7 @@ Connect ( sizer1->Add(btnCopy, 1, wxGROW); sizer1->Add(new wxStaticText(panel, -1, _T(" "))); sizer1->Add(btnUndo, 1, wxGROW); + sizer1->Add(btnRedo, 1, wxGROW); sizer = sizer1; panel->SetSizer(sizer); @@ -343,6 +350,11 @@ void wxManualPaintPanel::OnUndo(wxCommandEvent &event) { this->_manualPaintModel->Undo(); } +//--------------------------------------------------------------------------- +void wxManualPaintPanel::OnRedo(wxCommandEvent &event) { + this->_manualPaintModel->Redo(); +} + //-------------------------------------------------------------------------------------------------------------------------------- // Min-Max Barrange received events //-------------------------------------------------------------------------------------------------------------------------------- diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.h index 9097598..f31216e 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.h @@ -3,68 +3,62 @@ #include "ManualPaintPanel.h" - #include "mBarRange.h" //DFCH #include "creaWx.h" //DFCH - #include #include -class wxManualPaintPanel : public wxPanel , public ManualPaintPanel { +class wxManualPaintPanel: public wxPanel, public ManualPaintPanel { public: wxManualPaintPanel(wxWindow * parent); virtual ~wxManualPaintPanel(); - void OnBrushSize(wxScrollEvent& event); - void OnSldGrayLevel(wxScrollEvent& event); - void OnCtrTxtGrayLevel(wxCommandEvent &event); - void On2D3D(wxCommandEvent &event); - void OnBrushForm(wxCommandEvent &event); - void OnBrushTool(wxCommandEvent &event); - void OnCopy(wxCommandEvent &event); - void OnUndo(wxCommandEvent &event); - void DisableControls(); - void OnSldToleranceFill(wxScrollEvent& event); - void OnCtrTxtToleranceFill(wxCommandEvent &event); - void OnSldDistanceFill(wxScrollEvent& event); - void OnCtrTxtDistanceFill(wxCommandEvent &event); - //This method changes the min/max in the Selected Range Widget - //-------------------------------------------------------------------------------------------------------------------------------- - // Min-Max Barrange received events - //-------------------------------------------------------------------------------------------------------------------------------- - void onBarrange(wxCommandEvent& event); - void onActualChange_Bar(wxCommandEvent& event); - void onStartChange_Bar(wxCommandEvent& event); - void onEndChange_Bar(wxCommandEvent& event); - void onSelectionEnd(wxCommandEvent& event); - void onMovedBar(wxCommandEvent& event); + void OnBrushSize(wxScrollEvent& event); + void OnSldGrayLevel(wxScrollEvent& event); + void OnCtrTxtGrayLevel(wxCommandEvent &event); + void On2D3D(wxCommandEvent &event); + void OnBrushForm(wxCommandEvent &event); + void OnBrushTool(wxCommandEvent &event); + void OnCopy(wxCommandEvent &event); + void OnUndo(wxCommandEvent &event); + void OnRedo(wxCommandEvent &event); + void DisableControls(); + void OnSldToleranceFill(wxScrollEvent& event); + void OnCtrTxtToleranceFill(wxCommandEvent &event); + void OnSldDistanceFill(wxScrollEvent& event); + void OnCtrTxtDistanceFill(wxCommandEvent &event); + //This method changes the min/max in the Selected Range Widget + //-------------------------------------------------------------------------------------------------------------------------------- + // Min-Max Barrange received events + //-------------------------------------------------------------------------------------------------------------------------------- + void onBarrange(wxCommandEvent& event); + void onActualChange_Bar(wxCommandEvent& event); + void onStartChange_Bar(wxCommandEvent& event); + void onEndChange_Bar(wxCommandEvent& event); + void onSelectionEnd(wxCommandEvent& event); + void onMovedBar(wxCommandEvent& event); private: - wxStaticText *_txtBrushSize; - wxSlider *_sldBrushSize; - - wxSlider *_sldGrayLevel; - wxTextCtrl *_graylevelCtrl; - wxRadioBox *_rbBrushForm; - wxRadioBox *_rb2D3D; - wxRadioBox *_rbBrushTool; - - wxStaticText *_txtToleranceFill; - wxSlider *_sldToleranceFill; - wxTextCtrl *_tolerancefillCtrl; - - wxStaticText *_txtDistanceFill; - wxSlider *_sldDistanceFill; - wxTextCtrl *_distancefillCtrl; - - mBarRange * _mBarSlices; //DFCH + wxStaticText *_txtBrushSize; + wxSlider *_sldBrushSize; + wxSlider *_sldGrayLevel; + wxTextCtrl *_graylevelCtrl; + wxRadioBox *_rbBrushForm; + wxRadioBox *_rb2D3D; + wxRadioBox *_rbBrushTool; + wxStaticText *_txtToleranceFill; + wxSlider *_sldToleranceFill; + wxTextCtrl *_tolerancefillCtrl; + wxStaticText *_txtDistanceFill; + wxSlider *_sldDistanceFill; + wxTextCtrl *_distancefillCtrl; + mBarRange * _mBarSlices; //DFCH protected: }; - #endif // _WX_MANUAL_PAINT_PANEL_H_