ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
vtkUndoStack.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkUndoStack.cxx
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkUndoStack.h"
16 
17 #include "vtkCommand.h"
18 #include "vtkObjectFactory.h"
19 #include "vtkUndoStackInternal.h"
20 
22 //-----------------------------------------------------------------------------
24 {
25  this->Internal = new vtkUndoStackInternal;
26  this->InUndo = false;
27  this->InRedo = false;
28  this->StackDepth = 10;
29 }
30 
31 //-----------------------------------------------------------------------------
33 {
34  delete this->Internal;
35 }
36 
37 //-----------------------------------------------------------------------------
39 {
40  this->Internal->UndoStack.clear();
41  this->Internal->RedoStack.clear();
42  this->InvokeEvent(vtkUndoStack::UndoSetClearedEvent);
43  this->Modified();
44 }
45 
46 //-----------------------------------------------------------------------------
47 void vtkUndoStack::Push(const char* label, vtkUndoSet* changeSet)
48 {
49  this->Internal->RedoStack.clear();
50 
51  while (this->Internal->UndoStack.size() >= static_cast<unsigned int>(this->StackDepth) &&
52  this->StackDepth > 0)
53  {
54  this->Internal->UndoStack.erase(this->Internal->UndoStack.begin());
55  this->InvokeEvent(vtkUndoStack::UndoSetRemovedEvent);
56  }
57  this->Internal->UndoStack.push_back(vtkUndoStackInternal::Element(label, changeSet));
58  this->Modified();
59 }
60 
61 //-----------------------------------------------------------------------------
63 {
64  return static_cast<unsigned int>(this->Internal->UndoStack.size());
65 }
66 
67 //-----------------------------------------------------------------------------
69 {
70  return static_cast<unsigned int>(this->Internal->RedoStack.size());
71 }
72 
73 //-----------------------------------------------------------------------------
74 const char* vtkUndoStack::GetUndoSetLabel(unsigned int position)
75 {
76  if (position >= this->Internal->UndoStack.size())
77  {
78  return NULL;
79  }
80  position = (static_cast<unsigned int>(this->Internal->UndoStack.size()) - position) - 1;
81  return this->Internal->UndoStack[position].Label.c_str();
82 }
83 
84 //-----------------------------------------------------------------------------
85 const char* vtkUndoStack::GetRedoSetLabel(unsigned int position)
86 {
87  if (position >= this->Internal->RedoStack.size())
88  {
89  return NULL;
90  }
91  position = (static_cast<unsigned int>(this->Internal->RedoStack.size()) - position) - 1;
92  return this->Internal->RedoStack[position].Label.c_str();
93 }
94 
95 //-----------------------------------------------------------------------------
97 {
98  if (this->Internal->UndoStack.empty())
99  {
100  return 0;
101  }
102  this->InUndo = true;
103  this->InvokeEvent(vtkCommand::StartEvent);
104  int status = this->Internal->UndoStack.back().UndoSet.GetPointer()->Undo();
105  if (status)
106  {
107  this->PopUndoStack();
108  }
109  this->InvokeEvent(vtkCommand::EndEvent);
110  this->InUndo = false;
111  return status;
112 }
113 
114 //-----------------------------------------------------------------------------
116 {
117  if (this->Internal->RedoStack.empty())
118  {
119  return 0;
120  }
121  this->InRedo = true;
122  this->InvokeEvent(vtkCommand::StartEvent);
123  int status = this->Internal->RedoStack.back().UndoSet.GetPointer()->Redo();
124  if (status)
125  {
126  this->PopRedoStack();
127  }
128  this->InvokeEvent(vtkCommand::EndEvent);
129  this->InRedo = false;
130  return status;
131 }
132 
133 //-----------------------------------------------------------------------------
135 {
136  if (this->Internal->UndoStack.empty())
137  {
138  return;
139  }
140  this->Internal->RedoStack.push_back(this->Internal->UndoStack.back());
141  this->Internal->UndoStack.pop_back();
142  this->Modified();
143 }
144 
145 //-----------------------------------------------------------------------------
147 {
148  if (this->Internal->RedoStack.empty())
149  {
150  return;
151  }
152  this->Internal->UndoStack.push_back(this->Internal->RedoStack.back());
153  this->Internal->RedoStack.pop_back();
154  this->Modified();
155 }
156 
157 //-----------------------------------------------------------------------------
159 {
160  if (!this->CanUndo())
161  {
162  return NULL;
163  }
164  return this->Internal->UndoStack.back().UndoSet.GetPointer();
165 }
166 
167 //-----------------------------------------------------------------------------
169 {
170  if (!this->CanRedo())
171  {
172  return NULL;
173  }
174  return this->Internal->RedoStack.back().UndoSet.GetPointer();
175 }
176 
177 //-----------------------------------------------------------------------------
178 void vtkUndoStack::PrintSelf(ostream& os, vtkIndent indent)
179 {
180  this->Superclass::PrintSelf(os, indent);
181  os << indent << "InUndo: " << this->InUndo << endl;
182  os << indent << "InRedo: " << this->InRedo << endl;
183  os << indent << "StackDepth: " << this->StackDepth << endl;
184 }
math::float3 position
#define NULL
~vtkUndoStack() override
const char * GetRedoSetLabel(unsigned int position)
unsigned int GetNumberOfUndoSets()
virtual int Undo()
virtual int Redo()
void PrintSelf(ostream &os, vtkIndent indent) override
unsigned int GetNumberOfRedoSets()
virtual void Push(const char *label, vtkUndoSet *changeSet)
void PopUndoStack()
virtual vtkUndoSet * GetNextUndoSet()
virtual vtkUndoSet * GetNextRedoSet()
const char * GetUndoSetLabel(unsigned int position)
void PopRedoStack()
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
vtkStandardNewMacro(vtkUndoStack)