31#include <wx/clipbrd.h>
32#include <wx/dynarray.h>
52 isInsideUndoableAction =
false;
57 for (
unsigned int i = 0; i < undoStack.size(); i++) {
66wxString UndoAction::Description() {
69 case Undo_CreateWaypoint:
70 descr = _(
"Create Mark");
72 case Undo_DeleteWaypoint:
73 descr = _(
"Delete Mark");
75 case Undo_MoveWaypoint:
76 descr = _(
"Move Waypoint");
78 case Undo_AppendWaypoint:
79 descr = _(
"Append Waypoint");
91 wxRealPoint* lastPoint = (wxRealPoint*)action->before[0];
92 lat = currentPoint->m_lat;
93 lon = currentPoint->m_lon;
94 currentPoint->m_lat = lastPoint->y;
95 currentPoint->m_lon = lastPoint->x;
99 selectable->m_slat = currentPoint->m_lat;
100 selectable->m_slon = currentPoint->m_lon;
107 wxArrayPtrVoid* routeArray =
110 for (
unsigned int ir = 0; ir < routeArray->GetCount(); ir++) {
112 pr->FinalizeForRendering();
113 pr->UpdateSegmentDistances();
114 NavObj_dB::GetInstance().UpdateRoute(pr);
122 pSelect->AddSelectableRoutePoint(point->m_lat, point->m_lon, point);
123 NavObj_dB::GetInstance().InsertRoutePoint(point);
127 if (NULL != pWayPointMan) pWayPointMan->
AddRoutePoint(point);
128 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
129 pRouteManagerDialog->UpdateWptListCtrl();
134 NavObj_dB::GetInstance().DeleteRoutePoint(point);
135 pSelect->DeleteSelectablePoint(point, SELTYPE_ROUTEPOINT);
137 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
138 pRouteManagerDialog->UpdateWptListCtrl();
145 bool noRouteLeftToRedo =
false;
146 if ((route->GetnPoints() == 2) && (cc->m_routeState == 0))
147 noRouteLeftToRedo =
true;
149 g_pRouteMan->RemovePointFromRoute(point, route, cc->m_routeState);
150 gFrame->InvalidateAllGL();
152 if (action->beforeType[0] == Undo_IsOrphanded) {
153 NavObj_dB::GetInstance().DeleteRoutePoint(point);
154 pSelect->DeleteSelectablePoint(point, SELTYPE_ROUTEPOINT);
158 if (noRouteLeftToRedo) {
159 cc->undo->InvalidateRedo();
162 if (RouteManagerDialog::getInstanceFlag()) {
163 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
164 pRouteManagerDialog->UpdateWptListCtrl();
167 if (cc->m_routeState > 1) {
169 cc->m_prev_pMousePoint = route->GetLastPoint();
170 cc->m_prev_rlat = cc->m_prev_pMousePoint->m_lat;
171 cc->m_prev_rlon = cc->m_prev_pMousePoint->m_lon;
172 route->m_lastMousePointIndex = route->GetnPoints();
180 if (action->beforeType[0] == Undo_IsOrphanded) {
181 NavObj_dB::GetInstance().InsertRoutePoint(point);
182 pSelect->AddSelectableRoutePoint(point->m_lat, point->m_lon, point);
185 RoutePoint* prevpoint = route->GetLastPoint();
187 route->AddPoint(point);
188 pSelect->AddSelectableRouteSegment(prevpoint->m_lat, prevpoint->m_lon,
189 point->m_lat, point->m_lon, prevpoint,
192 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
193 pRouteManagerDialog->UpdateWptListCtrl();
195 if (cc->m_routeState > 1) {
197 cc->m_prev_pMousePoint = route->GetLastPoint();
198 cc->m_prev_rlat = cc->m_prev_pMousePoint->m_lat;
199 cc->m_prev_rlon = cc->m_prev_pMousePoint->m_lon;
200 route->m_lastMousePointIndex = route->GetnPoints();
204bool Undo::AnythingToUndo() {
return undoStack.size() > stackpointer; }
206bool Undo::AnythingToRedo() {
return stackpointer > 0; }
208UndoAction* Undo::GetNextUndoableAction() {
return undoStack[stackpointer]; }
211 return undoStack[stackpointer - 1];
214void Undo::InvalidateRedo() {
215 if (stackpointer == 0)
return;
220 for (
unsigned int i = 0; i < stackpointer; i++) {
221 switch (undoStack[i]->type) {
222 case Undo_DeleteWaypoint:
223 undoStack[i]->before[0] = NULL;
225 case Undo_CreateWaypoint:
226 case Undo_MoveWaypoint:
227 case Undo_AppendWaypoint:
233 undoStack.erase(undoStack.begin(), undoStack.begin() + stackpointer);
237void Undo::InvalidateUndo() {
242bool Undo::UndoLastAction() {
243 if (!AnythingToUndo())
return false;
246 switch (action->type) {
247 case Undo_CreateWaypoint:
248 doRedoDeleteWaypoint(action,
253 case Undo_MoveWaypoint:
254 doUndoMoveWaypoint(action, GetParent());
258 case Undo_DeleteWaypoint:
259 doUndoDeleteWaypoint(action, GetParent());
263 case Undo_AppendWaypoint:
265 doUndoAppendWaypoint(action, GetParent());
271bool Undo::RedoNextAction() {
272 if (!AnythingToRedo())
return false;
275 switch (action->type) {
276 case Undo_CreateWaypoint:
277 doUndoDeleteWaypoint(action,
282 case Undo_MoveWaypoint:
289 case Undo_DeleteWaypoint:
290 doRedoDeleteWaypoint(action, GetParent());
294 case Undo_AppendWaypoint:
295 doRedoAppendWaypoint(action, GetParent());
302bool Undo::BeforeUndoableAction(UndoType type, UndoItemPointer before,
303 UndoBeforePointerType beforeType,
304 UndoItemPointer selectable) {
305 if (CancelUndoableAction())
return false;
310 candidate->before.clear();
311 candidate->beforeType.clear();
312 candidate->selectable.clear();
313 candidate->after.clear();
315 candidate->type = type;
316 UndoItemPointer subject = before;
318 switch (beforeType) {
319 case Undo_NeedsCopy: {
320 switch (candidate->type) {
321 case Undo_MoveWaypoint: {
322 wxRealPoint* point =
new wxRealPoint;
324 point->x = rp->m_lon;
325 point->y = rp->m_lat;
329 case Undo_CreateWaypoint:
331 case Undo_DeleteWaypoint:
333 case Undo_AppendWaypoint:
338 case Undo_IsOrphanded:
344 candidate->before.push_back(subject);
345 candidate->beforeType.push_back(beforeType);
346 candidate->selectable.push_back(selectable);
348 isInsideUndoableAction =
true;
352bool Undo::AfterUndoableAction(UndoItemPointer after) {
353 if (!isInsideUndoableAction)
return false;
355 candidate->after.push_back(after);
356 undoStack.push_front(candidate);
358 if (undoStack.size() > depthSetting) {
359 undoStack.pop_back();
362 isInsideUndoableAction =
false;
366bool Undo::CancelUndoableAction(
bool noDataDelete) {
367 if (isInsideUndoableAction) {
369 for (
unsigned int i = 0; i < candidate->beforeType.size(); i++) {
370 if (candidate->beforeType[i] == Undo_IsOrphanded) {
371 candidate->beforeType[i] = Undo_HasParent;
375 if (candidate)
delete candidate;
377 isInsideUndoableAction =
false;
385UndoAction::~UndoAction() {
386 assert(before.size() == beforeType.size());
388 for (
unsigned int i = 0; i < before.size(); i++) {
389 switch (beforeType[i]) {
390 case Undo_NeedsCopy: {
392 case Undo_MoveWaypoint:
394 delete (wxRealPoint*)before[i];
398 case Undo_DeleteWaypoint:
400 case Undo_CreateWaypoint:
402 case Undo_AppendWaypoint:
407 case Undo_IsOrphanded: {
409 case Undo_DeleteWaypoint:
414 case Undo_CreateWaypoint:
416 case Undo_MoveWaypoint:
418 case Undo_AppendWaypoint:
Generic Chart canvas base.
ChartCanvas - Main chart display and interaction component.
Represents a waypoint or mark within the navigation system.
Represents a navigational route in the navigation system.
wxArrayPtrVoid * GetRouteArrayContaining(RoutePoint *pWP)
Find all routes that contain the given waypoint.
bool AddRoutePoint(RoutePoint *prp)
Add a point to list which owns it.
bool RemoveRoutePoint(RoutePoint *prp)
Remove a routepoint from list if present, deallocate it all cases.
MarkInfoDlg * g_pMarkInfoDialog
global instance
Waypoint properties maintenance dialog.
MySQL based storage for routes, tracks, etc.
Routeman * g_pRouteMan
Global instance.
Select * pSelect
Global instance.
Selected route, segment, waypoint, etc.
Framework for Undo features.