#include "MeshManagerModel.h"
+//
+//HISTORY HANDLER
+//
template <class T>
HistoryHandler<T>::HistoryHandler(int maxElements)
{
}
template <class T>
-T* HistoryHandler<T>::Undo()
+T* HistoryHandler<T>::Undo(T* state)
{
- if(!undoStack.empty() && undoStack.size()>1)
+ if(!undoStack.empty())
{
auto lastElem = undoStack.back();
undoStack.pop_back();
- redoStack.push_back(lastElem);
- return undoStack.back();
+ redoStack.push_back(state);
+ return lastElem;//undoStack.back();
+ }else{
+ delete state;
}
return NULL;
}
template <class T>
-T* HistoryHandler<T>::Redo()
+T* HistoryHandler<T>::Redo(T* state)
{
if(!redoStack.empty())
{
auto lastElem = redoStack.back();
redoStack.pop_back();
- undoStack.push_back(lastElem);
+ undoStack.push_back(state);
return lastElem;
+ }else{
+ delete state;
}
return NULL;
}
}
}
+template <class T>
+T* HistoryHandler<T>::GetPrevious()
+{
+ if(!undoStack.empty()){
+ return undoStack.back();
+ }
+ return NULL;
+}
+
+template <class T>
+T* HistoryHandler<T>::GetNext()
+{
+ if(!redoStack.empty()){
+ return redoStack.back();
+ }
+ return NULL;
+}
+
template <class T>
int HistoryHandler<T>::UndoSize()
{
MeshModel::MeshModel(vtkPolyData* mesh, int id)
{
if(mesh != NULL){
- _meshBase = mesh;
+ _meshBase = vtkPolyData::New();//mesh;
+ _meshBase->DeepCopy(mesh);
_meshTemp = vtkPolyData::New();
_meshTemp->DeepCopy(_meshBase);
_meshId = id;
if(_meshBase != NULL){
_meshBase->Delete();
}
- _meshBase = mesh;
+ _meshBase = vtkPolyData::New();
+ _meshBase->DeepCopy(mesh);
ResetMeshTemp_();
} // if mesh
}
void MeshModel::SetMeshMemoryMode(vtkPolyData* mesh)
{
- //if(_meshBase != NULL)
- //{
- // _meshBase->Delete();
- // _meshBase = NULL;
- //}
- //if (_meshTemp != NULL)
- //{
- // _meshTemp->Delete();
- // _meshTemp = NULL;
- //}
- _meshBase = mesh;
+ if(_meshBase != NULL)
+ {
+ _meshBase->Delete();
+ _meshBase = NULL;
+ }
+ if(mesh != NULL)
+ {
+ _meshBase = vtkPolyData::New();
+ _meshBase->DeepCopy(mesh);
+ }
}
void MeshModel::ResetMeshTemp()
currentMesh = 0;
meshId = 0;
history = new HistoryHandler<ManagerState>(20);
+ lastModified = 0;
}
MeshManagerModel::~MeshManagerModel()
void MeshManagerModel::ResetHistory()
{
history->CleanHistory();
- Save();
-}
-
-void MeshManagerModel::UpdateMeshReference(vtkPolyData* mesh)
-{
- _meshes.at(currentMesh)->SetMeshBase(mesh);
- RefreshOutputs(true);
+ //Save();
}
int MeshManagerModel::GetNumberOfMeshes()
void MeshManagerModel::AddMesh(vtkPolyData* mesh)
{
- AddMesh_(mesh);
Save();
+ AddMesh_(mesh);
+ lastModified = currentMesh;
RefreshOutputs(true);
}
void MeshManagerModel::AddMeshes(std::vector<vtkPolyData*> meshList)
{
- AddMeshes_(meshList);
Save();
+ AddMeshes_(meshList);
+ lastModified = currentMesh;
RefreshOutputs(true);
}
void MeshManagerModel::AddEmptyMesh()
{
- AddEmptyMesh_();
Save();
+ AddEmptyMesh_();
+ lastModified = currentMesh;
RefreshOutputs(true);
}
void MeshManagerModel::InsertMeshesAtCurrent(std::vector<vtkPolyData*> meshList)
{
- InsertMeshesAtCurrent_(meshList);
Save();
+ InsertMeshesAtCurrent_(meshList);
+ lastModified = currentMesh;
RefreshOutputs(true);
}
void MeshManagerModel::DeleteMesh(int position)
{
- DeleteMesh_(position);
Save();
+ DeleteMesh_(position);
+ lastModified = currentMesh;
RefreshOutputs(true);
}
void MeshManagerModel::DeleteCurrentMesh()
{
if(!_meshes.empty()){
- DeleteMesh_(currentMesh);
Save();
+ DeleteMesh_(currentMesh);
+ lastModified = currentMesh;
RefreshOutputs(true);
}
}
void MeshManagerModel::ReplaceMesh(std::vector<vtkPolyData*> meshList)
{
+ Save();
if(GetNumberOfMeshes() >= 1)
{
DeleteMesh_(currentMesh);
}
InsertMeshesAtCurrent_(meshList);
- Save();
+ lastModified = currentMesh;
RefreshOutputs(true);
}
void MeshManagerModel::DeleteAll()
{
- DeleteAll_();
Save();
+ DeleteAll_();
+ lastModified = currentMesh;
RefreshOutputs(true);
}
void MeshManagerModel::SetMeshBase(vtkPolyData* mesh)
{
if(!_meshes.empty()){
+ Save();
_meshes.at(currentMesh) = std::make_shared<MeshModel>(_meshes.at(currentMesh).get());
_meshes.at(currentMesh)->SetMeshBase(mesh);
- Save();
+ lastModified = currentMesh;
RefreshOutputs(true);
}else{
printf("PG MeshManagerModel::SetMeshBase Mesh vector is empty \n");
{
if(!_meshes.empty())
{
+ Save();
_meshes.at(currentMesh) = std::make_shared<MeshModel>(_meshes.at(currentMesh).get());
_meshes.at(currentMesh)->CopySetMeshBase(mesh);
- Save();
+ lastModified = currentMesh;
RefreshOutputs(true);
}
else{
return names;
}
+std::vector<vtkPolyData*> MeshManagerModel::GetAllPolyDatas()
+{
+ std::vector<vtkPolyData*> polydatas;
+ for(int i = 0; i < _meshes.size(); i++){
+ polydatas.push_back(_meshes.at(i)->GetMeshBase());
+ }
+ return polydatas;
+}
+
+int MeshManagerModel::GetCurrentMesh()
+{
+ return currentMesh;
+}
+
void MeshManagerModel::Undo()
{
- RestoreState(history->Undo());
- RefreshOutputs(true);
+ if(history->UndoSize() > 0){
+ RestoreState(history->Undo(new ManagerState(_meshes, meshId, lastModified)));
+ RefreshOutputs(true);
+ }
}
void MeshManagerModel::Redo()
{
- RestoreState(history->Redo());
- RefreshOutputs(true);
+ if(history->RedoSize() > 0)
+ {
+ RestoreState(history->Redo(new ManagerState(_meshes, meshId, lastModified)));
+ RefreshOutputs(true);
+ }
}
void MeshManagerModel::Save()
{
history->Save(new ManagerState(_meshes, meshId, currentMesh));
+ //lastModified = currentMesh;
}
void MeshManagerModel::RestoreState(ManagerState* state)
{
_meshes = state->GetMeshes();
meshId = state->GetMeshId();
- currentMesh = state->GetCurrentMesh();
+ currentMesh = state->GetModifiedPos();
+ lastModified = state->GetModifiedPos();
+// cout << "PG MeshManagerModel::RestoreState currentMesh: " << currentMesh << endl;
}
}
//
//Manager State
//
-MeshManagerModel::ManagerState::ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int currentMesh)
+MeshManagerModel::ManagerState::ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedPos)
{
savedMeshes = meshesToSave;
savedId = meshId;
- savedCurrentMesh = currentMesh;
+ savedModifiedPos = modifiedPos;
}
MeshManagerModel::ManagerState::~ManagerState()
{
return savedId;
}
-int MeshManagerModel::ManagerState::GetCurrentMesh()
+int MeshManagerModel::ManagerState::GetModifiedPos()
{
- return savedCurrentMesh;
+ return savedModifiedPos;
}