From e0501ee8b52860730eb29c3233f2f4dc6051b782 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Wed, 12 Oct 2022 17:30:58 +0200 Subject: [PATCH] #3493 ShowNPoints_UndoRedo --- .../wxWindows/widgets/WidgetShowNPoints.cxx | 284 +++++++++++------- .../wxWindows/widgets/WidgetShowNPoints.h | 13 +- 2 files changed, 190 insertions(+), 107 deletions(-) diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx index 22c98a7..47fbbc3 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx @@ -20,9 +20,13 @@ : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) { // EED 2022-05-19 - // mmodelShowNPoints = new ModelShowNPoints(); - mActualCollection= 0; - ModelShowNPoints* modelShowNPoints = new ModelShowNPoints(); + // mmodelShowNPoints = new ModelShowNPoints(); + idUndoRedo = 0; + maxUndoRedo = 0; + UndoRedoDir = "/tmp"; + + mActualCollection = 0; + ModelShowNPoints* modelShowNPoints = new ModelShowNPoints(); lstModelShowNPoints.push_back( modelShowNPoints ); lstViewShowNPoints.push_back( new ViewShowNPoints( modelShowNPoints ) ); @@ -139,6 +143,8 @@ wxButton *btnErasePoint = new wxButton( panel, -1, _T("-") , wxDefaultPosition, sizeButton ); wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("- lst") , wxDefaultPosition, sizeButton ); wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("--") , wxDefaultPosition, sizeButton ); + wxButton *btnUndo = new wxButton( panel, -1, _T("Undo") , wxDefaultPosition, sizeButton ); + wxButton *btnRedo = new wxButton( panel, -1, _T("Redo") , wxDefaultPosition, sizeButton ); wxButton *btnSavePoints = NULL; wxButton *btnLoadPoints = NULL; @@ -170,7 +176,6 @@ Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints); Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints); } // if mtype 0 3 - Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint); Connect(btnInsertPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint); @@ -178,32 +183,33 @@ Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint); Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint); Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints); - Connect(cbTrackPoint->GetId() , wxEVT_CHECKBOX , (wxObjectEventFunction) &WidgetShowNPoints::OnTrackPoint); - - + Connect(cbTrackPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnTrackPoint); + Connect(btnUndo->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnUndo); + Connect(btnRedo->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRedo); wxFlexGridSizer *sizer0 = new wxFlexGridSizer(1); wxFlexGridSizer *sizer1 = new wxFlexGridSizer(2); wxFlexGridSizer *sizer2 = new wxFlexGridSizer(2); wxFlexGridSizer *sizer3 = new wxFlexGridSizer(2); wxFlexGridSizer *sizer4 = new wxFlexGridSizer(2); - - sizer1->Add(textCtrl); - sizer1->Add(btnRenamePoint); - sizer2->Add(btnAddPoint); - sizer2->Add(btnInsertPoint);//CFT - sizer3->Add(btnSetPositionPoint); - sizer3->Add(cbTrackPoint); - sizer4->Add(btnErasePoint); - sizer4->Add(btnEraseLastPoint); - sizer4->Add(btnDeleteAllPoints); - + wxFlexGridSizer *sizer5 = new wxFlexGridSizer(2); + sizer1->Add( textCtrl ); + sizer1->Add( btnRenamePoint ); + sizer2->Add( btnAddPoint ); + sizer2->Add( btnInsertPoint );//CFT + sizer3->Add( btnSetPositionPoint ); + sizer3->Add( cbTrackPoint ); + sizer4->Add( btnErasePoint ); + sizer4->Add( btnEraseLastPoint ); + sizer4->Add( btnDeleteAllPoints ); + sizer5->Add( btnUndo ); + sizer5->Add( btnRedo ); // sizer0->Add(askPointLabel); // JPR sizer0->Add(txtNrPoints); sizer0->Add(sizer2); sizer0->Add(sizer1); sizer0->Add(sizer3); sizer0->Add(sizer4); - + sizer0->Add(sizer5); if ( (mtype==0) || (mtype==3) ) { wxFlexGridSizer *sizer5 = new wxFlexGridSizer(2); @@ -269,11 +275,10 @@ sizer = sizer1; } // bbGetInputType 2 - - panel->SetSizer(sizer); - panel->SetAutoLayout(true); - panel->Layout(); - bookSetPoints->AddPage(panel , _T("Points") ); + panel->SetSizer(sizer); + panel->SetAutoLayout(true); + panel->Layout(); + bookSetPoints->AddPage(panel , _T("Points") ); if ((mtype >= 0) && (mtype <= 3) ) { @@ -466,19 +471,16 @@ void WidgetShowNPoints::AddVtkPoint() //------------------------------------------------------------------------ void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label) { - printf("EED WidgetShowNPoints::OnAddPoint2 Start\n"); GetModelShowNPoints()->AddPoint(x,y,z, label ); // EED 2022-05-19 //AddVtkPoint(); //RefreshPoint(lstActorsSphere.size()-1); GetViewShowNPoints()->AddPoint(); - printf("EED WidgetShowNPoints::OnAddPoint2 End\n"); } //------------------------------------------------------------------------ void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT { - printf("EED WidgetShowNPoints::InsertPoint2 Start\n"); // EED 2022-05-19 //if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 ) //{ @@ -494,20 +496,17 @@ void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT AddPoint(x,y,z,label); } GetViewShowNPoints()->RefreshPoints(); - printf("EED WidgetShowNPoints::InsertPoint2 End\n"); } //------------------------------------------------------------------------ void WidgetShowNPoints::OnInsertPoint_() { - printf("EED WidgetShowNPoints::InsertPoint_ Start\n"); // EED 2022-05-19 //if (this->renderer==NULL) if (GetViewShowNPoints()->renderer==NULL) { return; } - std::vector point = GetModelShowNPoints()->GetReferencePoint(); if (point.size()==3) { @@ -516,48 +515,42 @@ void WidgetShowNPoints::OnInsertPoint_() } else {//mpoint.size printf("creaMaracasVisu::ShowNPoints (not match point) \n"); } - printf("EED WidgetShowNPoints::InsertPoint_ End\n"); } - - //------------------------------------------------------------------------ void WidgetShowNPoints::OnAddPoint_() { - printf("EED WidgetShowNPoints::OnAddPoint_ Start\n"); // EED 2022-05-19 //if (this->renderer==NULL) if (GetViewShowNPoints()->renderer==NULL) { return; } - std::vector point = GetModelShowNPoints()->GetReferencePoint(); if (point.size()==3) { AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) ); - SetOutputBox(); + SetOutputBox(); // EED 2022-05-19 //renderer->GetRenderWindow()->Render(); GetViewShowNPoints()->Render(); } else {//mpoint.size printf("creaMaracasVisu::ShowNPoints (not match point) \n"); } - printf("EED WidgetShowNPoints::OnAddPoint_ End\n"); } //------------------------------------------------------------------------ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) { - printf("EED WidgetShowNPoints::OnAddPoint Start\n"); OnAddPoint_(); - printf("EED WidgetShowNPoints::OnAddPoint End\n"); + UndoRedo_SaveCollection(); } //------------------------------------------------------------------------ void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT { OnInsertPoint_(); + UndoRedo_SaveCollection(); } @@ -684,6 +677,7 @@ void WidgetShowNPoints::OnSetPoint_() void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event) { OnSetPoint_(); + UndoRedo_SaveCollection(); } //------------------------------------------------------------------------ @@ -702,6 +696,7 @@ void WidgetShowNPoints::TrackingPoint( ) GetModelShowNPoints()->SetPointId_mReferencePoint(idTrack); GetViewShowNPoints()->RefreshPoint(idTrack); GetViewShowNPoints()->Render(); + UndoRedo_SaveCollection(); } // if id } // if trackPointFlag } @@ -748,7 +743,8 @@ void WidgetShowNPoints::StopTrackPoint( ) GetViewShowNPoints()->lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) ); GetViewShowNPoints()->Render(); SetOutputBox(); - } + UndoRedo_SaveCollection(); + } // if id } //------------------------------------------------------------------------ @@ -790,6 +786,7 @@ void WidgetShowNPoints::StopTrackPoint( ) void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event) { OnErasePoint_(); + UndoRedo_SaveCollection(); } //------------------------------------------------------------------------ @@ -800,6 +797,7 @@ void WidgetShowNPoints::StopTrackPoint( ) //renderer->GetRenderWindow()->Render(); int id = GetViewShowNPoints()->lstActorsSphere.size()-1; ErasePoint( id ); + UndoRedo_SaveCollection(); GetViewShowNPoints()->Render(); SetOutputBox(); StopTrackPoint(); @@ -814,11 +812,8 @@ void WidgetShowNPoints::DeleteAllPoints() for (id=size-1;id>=0;id--) { ErasePoint(id); - } + }// for id SetOutputBox(); - // EED 2022-05-19 - //renderer->GetRenderWindow()->Render(); - GetViewShowNPoints()->Render(); } @@ -826,6 +821,8 @@ void WidgetShowNPoints::DeleteAllPoints() void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event) { DeleteAllPoints(); + GetViewShowNPoints()->Render(); + UndoRedo_SaveCollection(); } //NTU: Method for updating points opacity and Radio @@ -936,13 +933,13 @@ void WidgetShowNPoints::InsertCollection() view->renderer = lstViewShowNPoints[0]->renderer; lstModelShowNPoints.insert( lstModelShowNPoints.begin()+mActualCollection , model ); lstViewShowNPoints.insert( lstViewShowNPoints.begin()+mActualCollection , view ); - RefreshCollectionText(); } //------------------------------------------------------------------------ void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event) { InsertCollection(); + RefreshCollectionText(); RefreshColourCollection(); StopTrackPoint(); } @@ -952,6 +949,7 @@ void WidgetShowNPoints::OnInsertCollectionAfter_() { mActualCollection++; InsertCollection(); + RefreshCollectionText(); RefreshColourCollection(); StopTrackPoint(); } @@ -983,6 +981,7 @@ void WidgetShowNPoints::DeleteCollection_() void WidgetShowNPoints::OnDeleteCollection_() { DeleteCollection_(); + GetViewShowNPoints()->Render(); RefreshCollectionText(); RefreshColourCollection(); StopTrackPoint(); @@ -992,17 +991,18 @@ void WidgetShowNPoints::OnDeleteCollection_() void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event) { OnDeleteCollection_(); + UndoRedo_SaveCollection(); } //------------------------------------------------------------------------ void WidgetShowNPoints::OnResetCollections_() { - printf("EED WidgetShowNPoints::OnResetCollections_ \n"); int i,size=lstModelShowNPoints.size(); for (i=0;iRender(); RefreshCollectionText(); RefreshColourCollection(); StopTrackPoint(); @@ -1012,6 +1012,7 @@ void WidgetShowNPoints::OnResetCollections_() void WidgetShowNPoints::OnResetCollections(wxCommandEvent &event) { OnResetCollections_(); + UndoRedo_SaveCollection(); } //------------------------------------------------------------------------ @@ -1025,6 +1026,7 @@ void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event) RefreshCollectionText(); RefreshColourCollection(); StopTrackPoint(); + UndoRedo_SaveCollection(); } //------------------------------------------------------------------------ @@ -1038,6 +1040,7 @@ void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event) RefreshCollectionText(); RefreshColourCollection(); StopTrackPoint(); + UndoRedo_SaveCollection(); } //------------------------------------------------------------------------ @@ -1093,6 +1096,28 @@ void WidgetShowNPoints::RefreshCollectionText() } // if mtype 4 } + +//------------------------------------------------------------------------ +void WidgetShowNPoints::OnSaveCollections_( std::string filename ) +{ + FILE *ff; + ff = fopen( filename.c_str() , "w+" ); + if (ff!=NULL) + { + int i,size = lstModelShowNPoints.size(); + fprintf(ff,"NumberOfGroups %d \n",size); + for (i=0 ; iSavePoints_(ff); + } // for i + fclose(ff); + } else { // else ff + printf("WidgetShowNPoints::Save Groups Points ...Error... creating file \n"); + } //ff + +} + + //------------------------------------------------------------------------ void WidgetShowNPoints::OnSaveCollections(wxCommandEvent &event) { @@ -1121,28 +1146,54 @@ void WidgetShowNPoints::OnSaveCollections(wxCommandEvent &event) if (FD->GetReturnCode()==wxID_OK) { std::string filename= (const char*) ( FD->GetPath().mb_str() ); - - FILE *ff; - ff = fopen( filename.c_str() , "w+" ); - if (ff!=NULL) - { - int i,size=lstModelShowNPoints.size(); - fprintf(ff,"NumberOfGroups %d \n",size); - - for (i=0;iSavePoints_(ff); - } // for i - - fclose(ff); - } else { // else ff - printf("WidgetShowNPoints::Save Groups Points ...Error... creating file \n"); - } //ff - - + OnSaveCollections_( filename ); } // dialog box StopTrackPoint(); +} +//------------------------------------------------------------------------ +void WidgetShowNPoints::OnLoadCollections_( std::string filename ) +{ + bool okEraseFirstGroup=false; + if (lstModelShowNPoints.size()==1) + { + if (GetModelShowNPoints()->GetLstPointsSize()==0) { okEraseFirstGroup=true; } + } + FILE *ff = fopen( filename.c_str() , "r+" ); + if (ff!=NULL) + { + int i; + int iGroup,sizeGroups; + int iPoint,numberPointsRead; + char chartmp[256]; + fscanf(ff," %s %d",chartmp,&sizeGroups); + for (iGroup=0;iGroupReadPoints_(ff); + for (i=0;iAddVtkPoint(); + }// for + } // for i + + fclose(ff); + } else { // else ff + printf("WidgetShowNPoints::Load Group of Points ...Error... reading file"); + } //ff + if (okEraseFirstGroup==true) + { + mActualCollection=0; + DeleteCollection_(); + mActualCollection = lstModelShowNPoints.size()-1; + } + GetViewShowNPoints()->Render(); + RefreshCollectionText(); + RefreshColourCollection(); + StopTrackPoint(); } //------------------------------------------------------------------------ @@ -1166,54 +1217,15 @@ void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event) wxFD_OPEN | wxFD_FILE_MUST_EXIST, wxDefaultPosition); #endif - bool okEraseFirstGrout=false; - int result_FD = FD->ShowModal(); // This line is need it by windows //EED FD->SetReturnCode( result_FD ); if (FD->GetReturnCode()==wxID_OK) { - if (lstModelShowNPoints.size()==1) - { - if (GetModelShowNPoints()->GetLstPointsSize()==0) { okEraseFirstGrout=true; } - } std::string filename= (const char*) ( FD->GetPath().mb_str() ); - FILE *ff = fopen( filename.c_str() , "r+" ); - if (ff!=NULL) - { - int i; - int iGroup,sizeGroups; - int iPoint,numberPointsRead; - char chartmp[256]; - fscanf(ff," %s %d",chartmp,&sizeGroups); - for (iGroup=0;iGroupReadPoints_(ff); - for (i=0;iAddVtkPoint(); - }// for - } // for i - - fclose(ff); - } else { // else ff - printf("WidgetShowNPoints::Load Group of Points ...Error... reading file"); - } //ff - if (okEraseFirstGrout==true) - { - mActualCollection=0; - DeleteCollection_(); - mActualCollection = lstModelShowNPoints.size()-1; - } - RefreshCollectionText(); - RefreshColourCollection(); + OnLoadCollections_( filename ); + UndoRedo_SaveCollection(); } // dialog box - StopTrackPoint(); } @@ -1343,3 +1355,63 @@ void WidgetShowNPoints::InvertLstPoints() } // for iM SetOutputBox(); } + + +//------------------------------------------------------------------------ +std::string WidgetShowNPoints::GetUndoRedoFileName() +{ + char buff[20]; + sprintf(buff,"%p_%d",this, idUndoRedo); + return UndoRedoDir+"/"+"UndoRedo_collection_" + std::string(buff) + ".undoredo"; +} + + +//------------------------------------------------------------------------ +void WidgetShowNPoints::OnUndo(wxCommandEvent &event) +{ + OnResetCollections_(); +// if (idUndoRedo==maxUndoRedo+1) +// { +// idUndoRedo--; +// } // if idUndoRedo+1 + idUndoRedo--; + idUndoRedo--; + printf("EED WidgetShowNPoints::OnUndo %d %d\n", idUndoRedo, maxUndoRedo); + if (idUndoRedo<0) + { + idUndoRedo=-1; + } else { + OnLoadCollections_( GetUndoRedoFileName() ); + }// if idUndoRedo + idUndoRedo++; + +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::OnRedo(wxCommandEvent &event) +{ + printf("EED WidgetShowNPoints::OnRedo A %d %d\n", idUndoRedo, maxUndoRedo); + if (idUndoRedo>maxUndoRedo) + { + idUndoRedo=maxUndoRedo+1; + } else { + OnResetCollections_(); + OnLoadCollections_( GetUndoRedoFileName() ); + idUndoRedo++; + }// if idUndoRedo + + printf("EED WidgetShowNPoints::OnRedo B %d %d\n", idUndoRedo, maxUndoRedo); + +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::UndoRedo_SaveCollection() +{ + printf("EED \n EED WidgetShowNPoints::UndoRedo_SaveCollection %d %d\n", idUndoRedo, maxUndoRedo); + OnSaveCollections_( GetUndoRedoFileName() ); + maxUndoRedo = idUndoRedo; + idUndoRedo++; + printf("EED WidgetShowNPoints::UndoRedo_SaveCollection %d %d\n", idUndoRedo, maxUndoRedo); +} + + diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h index 76f25de..a140013 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h @@ -51,9 +51,17 @@ class WidgetShowNPoints : public wxPanel void OnBackCollection(wxCommandEvent &event); void OnNextCollection(wxCommandEvent &event); void OnSaveCollections(wxCommandEvent &event); + void OnSaveCollections_( std::string filename ); void OnLoadCollections(wxCommandEvent &event); + void OnLoadCollections_( std::string filename ); void OnResetCollections(wxCommandEvent &event); void OnResetCollections_(); + + void OnUndo(wxCommandEvent &event); + void OnRedo(wxCommandEvent &event); + void UndoRedo_SaveCollection(); + std::string GetUndoRedoFileName(); + void RefreshCollectionText(); void RefreshColourCollection(); @@ -127,8 +135,11 @@ class WidgetShowNPoints : public wxPanel std::vector lstModelShowNPoints; int mtype; int mActualCollection; -// bool trackPointFlag; +// bool trackPointFlag; int idTrack; + int idUndoRedo; + int maxUndoRedo; + std::string UndoRedoDir; }; -- 2.47.1