32#include <wx/clipbrd.h>
33#include <wx/dynarray.h>
53 isInsideUndoableAction =
false;
58 for (
unsigned int i = 0; i < undoStack.size(); i++) {
67wxString UndoAction::Description() {
70 case Undo_CreateWaypoint:
71 descr = _(
"Create Mark");
73 case Undo_DeleteWaypoint:
74 descr = _(
"Delete Mark");
76 case Undo_MoveWaypoint:
77 descr = _(
"Move Waypoint");
79 case Undo_AppendWaypoint:
80 descr = _(
"Append Waypoint");
92 wxRealPoint* lastPoint = (wxRealPoint*)action->before[0];
93 lat = currentPoint->m_lat;
94 lon = currentPoint->m_lon;
95 currentPoint->m_lat = lastPoint->y;
96 currentPoint->m_lon = lastPoint->x;
100 selectable->m_slat = currentPoint->m_lat;
101 selectable->m_slon = currentPoint->m_lon;
108 wxArrayPtrVoid* routeArray =
111 for (
unsigned int ir = 0; ir < routeArray->GetCount(); ir++) {
113 pr->FinalizeForRendering();
114 pr->UpdateSegmentDistances();
115 NavObj_dB::GetInstance().UpdateRoute(pr);
123 pSelect->AddSelectableRoutePoint(point->m_lat, point->m_lon, point);
124 NavObj_dB::GetInstance().InsertRoutePoint(point);
128 if (NULL != pWayPointMan) pWayPointMan->
AddRoutePoint(point);
129 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
130 pRouteManagerDialog->UpdateWptListCtrl();
135 NavObj_dB::GetInstance().DeleteRoutePoint(point);
136 pSelect->DeleteSelectablePoint(point, SELTYPE_ROUTEPOINT);
138 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
139 pRouteManagerDialog->UpdateWptListCtrl();
146 bool noRouteLeftToRedo =
false;
147 if ((route->GetnPoints() == 2) && (cc->m_routeState == 0))
148 noRouteLeftToRedo =
true;
150 g_pRouteMan->RemovePointFromRoute(point, route, cc->m_routeState);
151 gFrame->InvalidateAllGL();
153 if (action->beforeType[0] == Undo_IsOrphanded) {
154 NavObj_dB::GetInstance().DeleteRoutePoint(point);
155 pSelect->DeleteSelectablePoint(point, SELTYPE_ROUTEPOINT);
159 if (noRouteLeftToRedo) {
160 cc->undo->InvalidateRedo();
163 if (RouteManagerDialog::getInstanceFlag()) {
164 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
165 pRouteManagerDialog->UpdateWptListCtrl();
168 if (cc->m_routeState > 1) {
170 cc->m_prev_pMousePoint = route->GetLastPoint();
171 cc->m_prev_rlat = cc->m_prev_pMousePoint->m_lat;
172 cc->m_prev_rlon = cc->m_prev_pMousePoint->m_lon;
173 route->m_lastMousePointIndex = route->GetnPoints();
181 if (action->beforeType[0] == Undo_IsOrphanded) {
182 NavObj_dB::GetInstance().InsertRoutePoint(point);
183 pSelect->AddSelectableRoutePoint(point->m_lat, point->m_lon, point);
186 RoutePoint* prevpoint = route->GetLastPoint();
188 route->AddPoint(point);
189 pSelect->AddSelectableRouteSegment(prevpoint->m_lat, prevpoint->m_lon,
190 point->m_lat, point->m_lon, prevpoint,
193 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
194 pRouteManagerDialog->UpdateWptListCtrl();
196 if (cc->m_routeState > 1) {
198 cc->m_prev_pMousePoint = route->GetLastPoint();
199 cc->m_prev_rlat = cc->m_prev_pMousePoint->m_lat;
200 cc->m_prev_rlon = cc->m_prev_pMousePoint->m_lon;
201 route->m_lastMousePointIndex = route->GetnPoints();
205bool Undo::AnythingToUndo() {
return undoStack.size() > stackpointer; }
207bool Undo::AnythingToRedo() {
return stackpointer > 0; }
209UndoAction* Undo::GetNextUndoableAction() {
return undoStack[stackpointer]; }
212 return undoStack[stackpointer - 1];
215void Undo::InvalidateRedo() {
216 if (stackpointer == 0)
return;
221 for (
unsigned int i = 0; i < stackpointer; i++) {
222 switch (undoStack[i]->type) {
223 case Undo_DeleteWaypoint:
224 undoStack[i]->before[0] = NULL;
226 case Undo_CreateWaypoint:
227 case Undo_MoveWaypoint:
228 case Undo_AppendWaypoint:
234 undoStack.erase(undoStack.begin(), undoStack.begin() + stackpointer);
238void Undo::InvalidateUndo() {
243bool Undo::UndoLastAction() {
244 if (!AnythingToUndo())
return false;
247 switch (action->type) {
248 case Undo_CreateWaypoint:
249 doRedoDeleteWaypoint(action,
254 case Undo_MoveWaypoint:
255 doUndoMoveWaypoint(action, GetParent());
259 case Undo_DeleteWaypoint:
260 doUndoDeleteWaypoint(action, GetParent());
264 case Undo_AppendWaypoint:
266 doUndoAppendWaypoint(action, GetParent());
272bool Undo::RedoNextAction() {
273 if (!AnythingToRedo())
return false;
276 switch (action->type) {
277 case Undo_CreateWaypoint:
278 doUndoDeleteWaypoint(action,
283 case Undo_MoveWaypoint:
290 case Undo_DeleteWaypoint:
291 doRedoDeleteWaypoint(action, GetParent());
295 case Undo_AppendWaypoint:
296 doRedoAppendWaypoint(action, GetParent());
303bool Undo::BeforeUndoableAction(UndoType type, UndoItemPointer before,
304 UndoBeforePointerType beforeType,
305 UndoItemPointer selectable) {
306 if (CancelUndoableAction())
return false;
311 candidate->before.clear();
312 candidate->beforeType.clear();
313 candidate->selectable.clear();
314 candidate->after.clear();
316 candidate->type = type;
317 UndoItemPointer subject = before;
319 switch (beforeType) {
320 case Undo_NeedsCopy: {
321 switch (candidate->type) {
322 case Undo_MoveWaypoint: {
323 wxRealPoint* point =
new wxRealPoint;
325 point->x = rp->m_lon;
326 point->y = rp->m_lat;
330 case Undo_CreateWaypoint:
332 case Undo_DeleteWaypoint:
334 case Undo_AppendWaypoint:
339 case Undo_IsOrphanded:
345 candidate->before.push_back(subject);
346 candidate->beforeType.push_back(beforeType);
347 candidate->selectable.push_back(selectable);
349 isInsideUndoableAction =
true;
353bool Undo::AfterUndoableAction(UndoItemPointer after) {
354 if (!isInsideUndoableAction)
return false;
356 candidate->after.push_back(after);
357 undoStack.push_front(candidate);
359 if (undoStack.size() > depthSetting) {
360 undoStack.pop_back();
363 isInsideUndoableAction =
false;
367bool Undo::CancelUndoableAction(
bool noDataDelete) {
368 if (isInsideUndoableAction) {
370 for (
unsigned int i = 0; i < candidate->beforeType.size(); i++) {
371 if (candidate->beforeType[i] == Undo_IsOrphanded) {
372 candidate->beforeType[i] = Undo_HasParent;
376 if (candidate)
delete candidate;
378 isInsideUndoableAction =
false;
386UndoAction::~UndoAction() {
387 assert(before.size() == beforeType.size());
389 for (
unsigned int i = 0; i < before.size(); i++) {
390 switch (beforeType[i]) {
391 case Undo_NeedsCopy: {
393 case Undo_MoveWaypoint:
395 delete (wxRealPoint*)before[i];
399 case Undo_DeleteWaypoint:
401 case Undo_CreateWaypoint:
403 case Undo_AppendWaypoint:
408 case Undo_IsOrphanded: {
410 case Undo_DeleteWaypoint:
415 case Undo_CreateWaypoint:
417 case Undo_MoveWaypoint:
419 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.