-
Notifications
You must be signed in to change notification settings - Fork 156
/
TemplateFrame.cpp
881 lines (773 loc) · 27.5 KB
/
TemplateFrame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
/**
* GeoDa TM, Copyright (C) 2011-2015 by Luc Anselin - all rights reserved
*
* This file is part of GeoDa.
*
* GeoDa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GeoDa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/msgdlg.h>
#include <wx/filedlg.h>
#include <wx/dcmemory.h>
#include <wx/dataobj.h>
#include <wx/dcsvg.h>
#include <wx/dcps.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/xrc/xmlres.h>
#include "DataViewer/TableInterface.h"
#include "DataViewer/TableState.h"
#include "DataViewer/TimeState.h"
#include "FramesManager.h"
#include "TemplateFrame.h"
#include "TemplateCanvas.h"
#include "TemplateLegend.h"
#include "Explore/MapNewView.h"
#include "Explore/CartogramNewView.h"
#include "Explore/ConditionalMapView.h"
#include "Explore/LisaScatterPlotView.h"
#include "Explore/PCPNewView.h"
#include "Explore/ScatterNewPlotView.h"
#include "Explore/MapLayoutView.h"
#include "DialogTools/AdjustYAxisDlg.h"
#include "rc/GeoDaIcon-16x16.xpm"
#include "GeneralWxUtils.h"
#include "GeoDa.h"
#include "Project.h"
#include "logger.h"
IMPLEMENT_CLASS(TemplateFrame, wxFrame)
BEGIN_EVENT_TABLE(TemplateFrame, wxFrame)
EVT_CHAR_HOOK(TemplateFrame::OnKeyEvent)
END_EVENT_TABLE()
TemplateFrame* TemplateFrame::activeFrame = 0;
wxString TemplateFrame::activeFrName = wxEmptyString;
TemplateFrame::TemplateFrame(wxFrame *parent, Project* project_s,
const wxString& title,
const wxPoint& pos,
const wxSize& size, const long style)
: wxFrame(parent, wxID_ANY, title, pos, size, style),
template_canvas(0), template_legend(0), project(project_s),
frames_manager(project_s->GetFramesManager()),
table_state(project_s->GetTableState()),
time_state(project_s->GetTimeState()),
is_status_bar_visible(false),
get_status_bar_string_from_frame(false),
supports_timeline_changes(false),
depends_on_non_simple_groups(true), toolbar(NULL)
{
SetIcon(wxIcon(GeoDaIcon_16x16_xpm));
frames_manager->registerObserver(this);
table_state->registerObserver(this);
time_state->registerObserver(this);
}
TemplateFrame::~TemplateFrame()
{
LOG_MSG("Called TemplateFrame::~TemplateFrame()");
if (HasCapture()) ReleaseMouse();
frames_manager->removeObserver(this);
table_state->removeObserver(this);
time_state->removeObserver(this);
}
void TemplateFrame::OnSelectWithRect(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnSelectWithRect");
if (!template_canvas) return;
template_canvas->SetBrushType(TemplateCanvas::rectangle);
template_canvas->SetMouseMode(TemplateCanvas::select);
UpdateOptionMenuItems();
}
void TemplateFrame::OnSelectWithCircle(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnSelectWithCircle");
if (!template_canvas) return;
template_canvas->SetBrushType(TemplateCanvas::circle);
template_canvas->SetMouseMode(TemplateCanvas::select);
UpdateOptionMenuItems();
}
void TemplateFrame::OnSelectWithLine(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnSelectWithLine");
if (!template_canvas) return;
template_canvas->SetBrushType(TemplateCanvas::line);
template_canvas->SetMouseMode(TemplateCanvas::select);
UpdateOptionMenuItems();
}
void TemplateFrame::OnSelectWithCustom(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnSelectWithCustom");
if (!template_canvas) return;
template_canvas->SetBrushType(TemplateCanvas::custom_select);
template_canvas->SetMouseMode(TemplateCanvas::select);
UpdateOptionMenuItems();
}
void TemplateFrame::OnDisplayStatusBar(wxCommandEvent& event)
{
DisplayStatusBar(!IsStatusBarVisible());
}
TemplateLegend* TemplateFrame::GetTemplateLegend()
{
return template_legend;
}
bool TemplateFrame::AllowObservationAddDelete()
{
return false;
}
bool TemplateFrame::IsStatusBarVisible()
{
return is_status_bar_visible;
}
Project* TemplateFrame::GetProject()
{
return project;
}
void TemplateFrame::OnSelectionMode(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnSelectionMode");
if (!template_canvas) return;
template_canvas->SetMouseMode(TemplateCanvas::select);
UpdateOptionMenuItems();
}
void TemplateFrame::OnResetMap(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnResetMap");
if (!template_canvas) return;
template_canvas->ResetShapes();
UpdateOptionMenuItems();
}
void TemplateFrame::OnRefreshMap(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnResetMap");
if (!template_canvas) return;
template_canvas->ReDraw();
}
void TemplateFrame::OnFitToWindowMode(wxCommandEvent& event)
{
LOG_MSG("Entering TemplateFrame::OnFitToWindowMode");
if (!template_canvas) return;
template_canvas->SetFitToWindowMode(
!template_canvas->GetFitToWindowMode());
UpdateOptionMenuItems();
LOG_MSG("Exiting TemplateFrame::OnFitToWindowMode");
}
void TemplateFrame::OnFixedAspectRatioMode(wxCommandEvent& event)
{
if (!template_canvas) return;
template_canvas->SetFixedAspectRatioMode(
!template_canvas->GetFixedAspectRatioMode());
UpdateOptionMenuItems();
}
void TemplateFrame::OnSetAxisDisplayPrecision(wxCommandEvent& event)
{
if (!template_canvas) return;
int display_precision = template_canvas->axis_display_precision;
bool display_fixed_point = template_canvas->axis_display_fixed_point;
SetDisplayPrecisionDlg dlg(display_precision, display_fixed_point, this);
if (dlg.ShowModal () != wxID_OK) return;
int def_precision = dlg.precision;
bool def_fixed_point = dlg.fixed_point;
template_canvas->SetAxisDisplayPrecision(def_precision, def_fixed_point);
UpdateOptionMenuItems();
}
void TemplateFrame::OnDisplayPrecision(wxCommandEvent& event)
{
// display precision for any printed numbers on canvas (not include axes)
if (template_canvas == NULL) return;
int disp_precision = template_canvas->GetDisplayPrecision();
bool fixed_point = template_canvas->GetDisplayFixedPoint();
SetDisplayPrecisionDlg dlg(disp_precision, fixed_point, this);
if (dlg.ShowModal () != wxID_OK) return;
disp_precision = dlg.precision;
fixed_point = dlg.fixed_point;
template_canvas->SetDisplayPrecision(disp_precision, fixed_point);
UpdateOptionMenuItems();
}
void TemplateFrame::OnLegendDisplayPrecision(wxCommandEvent& event)
{
int disp_precision = template_canvas->category_disp_precision;
bool fixed_point = template_canvas->category_disp_fixed_point;
SetDisplayPrecisionDlg dlg(disp_precision, fixed_point, this);
if (dlg.ShowModal () != wxID_OK) return;
disp_precision = dlg.precision;
fixed_point = dlg.fixed_point;
template_canvas->SetCategoryDisplayPrecision(disp_precision, fixed_point);
if (MapCanvas* canvas = dynamic_cast<MapCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
} else if (CartogramNewCanvas* canvas = dynamic_cast<CartogramNewCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
} else if (CartogramNewCanvas* canvas = dynamic_cast<CartogramNewCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
} else if (ConditionalMapCanvas* canvas = dynamic_cast<ConditionalMapCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
} else if (PCPCanvas* canvas = dynamic_cast<PCPCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
} else if (ScatterNewPlotCanvas* canvas = dynamic_cast<ScatterNewPlotCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
}
template_legend->Recreate();
UpdateOptionMenuItems();
}
void TemplateFrame::OnZoomMode(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnZoomMode");
if (!template_canvas) return;
template_canvas->SetMouseMode(TemplateCanvas::zoom);
UpdateOptionMenuItems();
}
void TemplateFrame::OnZoomOutMode(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnZoomMode");
if (!template_canvas) return;
template_canvas->SetMouseMode(TemplateCanvas::zoomout);
UpdateOptionMenuItems();
}
void TemplateFrame::OnPanMode(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnPanMode");
if (!template_canvas) return;
template_canvas->SetMouseMode(TemplateCanvas::pan);
UpdateOptionMenuItems();
}
void TemplateFrame::OnPrintCanvasState(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnPrintCanvasState");
if (template_canvas) {
}
}
void TemplateFrame::UpdateOptionMenuItems()
{
if (template_canvas == 0) return;
wxMenuBar* mb = GdaFrame::GetGdaFrame()->GetMenuBar();
// Update the checkmarks and enable/disable state for the
// following menu items if they were specified for this particular
// view in the xrc file. Items that cannot be enable/disabled,
// or are not checkable do not appear.
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_SELECT_WITH_RECT"),
template_canvas->GetBrushType() ==
TemplateCanvas::rectangle);
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_SELECT_WITH_CIRCLE"),
template_canvas->GetBrushType() ==
TemplateCanvas::circle);
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_SELECT_WITH_LINE"),
template_canvas->GetBrushType() ==
TemplateCanvas::line);
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_SELECT_WITH_CUSTOM"),
template_canvas->GetBrushType() ==
TemplateCanvas::custom_select);
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_SELECTION_MODE"),
template_canvas->GetMouseMode() ==
TemplateCanvas::select);
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_FIT_TO_WINDOW_MODE"),
template_canvas->GetFitToWindowMode());
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_FIXED_ASPECT_RATIO_MODE"),
template_canvas->GetFixedAspectRatioMode());
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_ZOOM_MODE"),
template_canvas->GetMouseMode() ==
TemplateCanvas::zoom);
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_PAN_MODE"),
template_canvas->GetMouseMode() ==
TemplateCanvas::pan);
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_SELECTABLE_OUTLINE_VISIBLE"),
template_canvas->
IsSelectableOutlineVisible());
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_CANVAS_BACKGROUND_COLOR"),
template_canvas->
IsUserBackgroundColorVisible());
GeneralWxUtils::CheckMenuItem(mb, XRCID("ID_DISPLAY_STATUS_BAR"),
IsStatusBarVisible());
}
void TemplateFrame::UpdateContextMenuItems(wxMenu* menu)
{
// Update the checkmarks and enable/disable state for the
// following menu items if they were specified for this particular
// view in the xrc file. Items that cannot be enable/disabled,
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_DISPLAY_STATUS_BAR"),
IsStatusBarVisible());
if (template_canvas == 0) return;
// or are not checkable do not appear.
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_SELECT_WITH_RECT"),
template_canvas->GetBrushType() ==
TemplateCanvas::rectangle);
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_SELECT_WITH_CIRCLE"),
template_canvas->GetBrushType() ==
TemplateCanvas::circle);
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_SELECT_WITH_LINE"),
template_canvas->GetBrushType() ==
TemplateCanvas::line);
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_SELECT_WITH_CUSTOM"),
template_canvas->GetBrushType() ==
TemplateCanvas::custom_select);
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_SELECTION_MODE"),
template_canvas->GetMouseMode() ==
TemplateCanvas::select);
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_FIT_TO_WINDOW_MODE"),
template_canvas->GetFitToWindowMode());
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_FIXED_ASPECT_RATIO_MODE"),
template_canvas->GetFixedAspectRatioMode());
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_ZOOM_MODE"),
template_canvas->GetMouseMode() ==
TemplateCanvas::zoom);
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_PAN_MODE"),
template_canvas->GetMouseMode() ==
TemplateCanvas::pan);
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_SELECTABLE_OUTLINE_VISIBLE"),
template_canvas->
IsSelectableOutlineVisible());
GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_CANVAS_BACKGROUND_COLOR"),
template_canvas->
IsUserBackgroundColorVisible());
}
void TemplateFrame::UpdateTitle()
{
if (template_canvas) SetTitle(template_canvas->GetCanvasTitle());
if (GetActiveFrame()==this) GdaFrame::GetGdaFrame()->SetTitle(GetTitle());
}
void TemplateFrame::OnTimeSyncVariable(int var_index)
{
if (!template_canvas) return;
template_canvas->TimeSyncVariableToggle(var_index);
UpdateOptionMenuItems();
}
void TemplateFrame::OnFixedScaleVariable(int var_index)
{
if (!template_canvas) return;
template_canvas->FixedScaleVariableToggle(var_index);
UpdateOptionMenuItems();
}
void TemplateFrame::OnPlotsPerView(int plots_per_view)
{
if (!template_canvas) return;
template_canvas->PlotsPerView(plots_per_view);
UpdateOptionMenuItems();
UpdateTitle();
}
void TemplateFrame::OnPlotsPerViewOther()
{
if (!template_canvas) return;
template_canvas->PlotsPerViewOther();
UpdateOptionMenuItems();
UpdateTitle();
}
void TemplateFrame::OnPlotsPerViewAll()
{
if (!template_canvas) return;
template_canvas->PlotsPerViewAll();
UpdateOptionMenuItems();
UpdateTitle();
}
void TemplateFrame::DisplayStatusBar(bool show)
{
LOG_MSG("Entering TemplateFrame::DisplayStatusBar");
wxStatusBar* sb = 0;
if (!is_status_bar_visible && show) {
is_status_bar_visible = true;
if (!GetStatusBar()) {
sb = new wxStatusBar(this);
SetStatusBar(sb);
}
SendSizeEvent();
} else if (is_status_bar_visible && !show) {
is_status_bar_visible = false;
sb = GetStatusBar();
if (sb) {
SetStatusBar(0);
delete sb;
}
SendSizeEvent();
}
LOG_MSG("Exiting TemplateFrame::DisplayStatusBar");
}
bool TemplateFrame::GetStatusBarStringFromFrame()
{
return get_status_bar_string_from_frame;
}
void TemplateFrame::SetGetStatusBarStringFromFrame(bool get_sb_string)
{
get_status_bar_string_from_frame = get_sb_string;
}
wxString TemplateFrame::GetUpdateStatusBarString(const std::vector<int>& hover_obs, int total_hover_obs)
{
return "";
}
void TemplateFrame::RegisterAsActive(const wxString& name,
const wxString& title)
{
if (!GdaFrame::GetGdaFrame()) {
// ~GdaFrame() has been called, program is exiting
return;
}
if (!activeFrame || activeFrame != this) {
if (activeFrame && activeFrame != this)
activeFrame->DeregisterAsActive();
MapMenus();
// Enable the Close menu item. This saves including this code in every
// single MapMenus call by all classes that inherit this class.
GeneralWxUtils::EnableMenuItem(GdaFrame::GetGdaFrame()->GetMenuBar(),
GdaFrame::GetGdaFrame()->GetMenuBar()->GetMenuLabelText(0),
wxID_CLOSE, true);
activeFrame = this;
activeFrName = name;
GdaFrame::GetGdaFrame()->SetTitle(title);
}
}
void TemplateFrame::DeregisterAsActive()
{
LOG_MSG("In TemplateFrame::DeregisterAsActive");
if (!GdaFrame::GetGdaFrame()) {
// ~GdaFrame() has been called, program is exiting
return;
}
if (activeFrame == this) {
activeFrame = NULL;
activeFrName = wxEmptyString;
// restore to a default state.
GdaFrame::GetGdaFrame()->UpdateToolbarAndMenus();
}
}
wxString TemplateFrame::GetActiveName()
{
return activeFrName;
}
TemplateFrame* TemplateFrame::GetActiveFrame()
{
return activeFrame;
}
void TemplateFrame::MapMenus()
{
}
void TemplateFrame::OnKeyEvent(wxKeyEvent& event)
{
//LOG_MSG("In TemplateFrame::OnKeyEvent");
if (event.GetModifiers() == wxMOD_CMD &&
project && project->GetTimeState() &&
project->GetTableInt()->IsTimeVariant() &&
(event.GetKeyCode() == WXK_LEFT || event.GetKeyCode() == WXK_RIGHT)) {
TimeState* time_state = project->GetTimeState();
int del = (event.GetKeyCode() == WXK_LEFT) ? -1 : 1;
time_state->SetCurrTime(time_state->GetCurrTime() + del);
if (time_state->GetCurrTime() < 0) {
time_state->SetCurrTime(time_state->GetTimeSteps()-1);
} else if (time_state->GetCurrTime() >= time_state->GetTimeSteps()) {
time_state->SetCurrTime(0);
}
time_state->notifyObservers();
return;
}
event.Skip();
}
void TemplateFrame::ExportImage(TemplateCanvas* canvas, const wxString& type)
{
wxLogMessage("Entering TemplateFrame::ExportImage");
wxBitmap* main_map = template_canvas->GetPrintLayer();
int canvas_width = main_map->GetWidth();
int canvas_height = main_map->GetHeight();
double scale = template_canvas->GetContentScaleFactor();
if (GdaConst::enable_high_dpi_support) {
canvas_width = canvas_width / scale;
canvas_height = canvas_height / scale;
}
if (template_legend ) {
// with legend
// try to keep maplayout dialog fixed size
int dlg_width = 900;
int dlg_height = dlg_width * canvas_height / (double)canvas_width + 160;
wxSize sz(dlg_width, dlg_height);
wxString title = project->GetProjectTitle();
MapCanvas* map_canvas = dynamic_cast<MapCanvas*>(template_canvas);
CanvasLayoutDialog* lo_dlg;
if (map_canvas) {
lo_dlg = new MapLayoutDialog(title, template_legend, template_canvas, _("Map Layout Preview"), wxDefaultPosition, sz);
} else {
lo_dlg = new CanvasLayoutDialog(title, template_legend, template_canvas, _("Canvas Layout Preview"), wxDefaultPosition, sz);
}
lo_dlg->ShowModal();
delete lo_dlg;
} else {
// without legend
int default_width = canvas_width*2;
int default_height = canvas_height*2;
CanvasExportSettingDialog setting_dlg(default_width, default_height, _("Image Dimension Settings"));
if (setting_dlg.ShowModal() == wxID_OK) {
int out_res_x = setting_dlg.GetMapWidth();
int out_res_y = setting_dlg.GetMapHeight();
double canvas_scale = (double) out_res_x / canvas_width;
wxString default_fname(project->GetProjectTitle());
wxString filter ="BMP|*.bmp|PNG|*.png|SVG|*.svg";
int filter_index = 1;
wxFileDialog dialog(canvas, _("Save Image to File"), wxEmptyString,
default_fname, filter,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
dialog.SetFilterIndex(filter_index);
if (dialog.ShowModal() != wxID_OK) {
return;
}
wxFileName fname = wxFileName(dialog.GetPath());
wxString str_fname = fname.GetPathWithSep() + fname.GetName();
switch (dialog.GetFilterIndex()) {
case 0:
{
wxLogMessage("BMP selected");
wxBitmap canvas_bm;
canvas_bm.CreateScaled(canvas_width, canvas_height, 32, canvas_scale);
wxMemoryDC canvas_dc(canvas_bm);
canvas_dc.SetBackground(*wxWHITE_BRUSH);
canvas_dc.Clear();
template_canvas->RenderToDC(canvas_dc, out_res_x, out_res_y);
canvas_bm.SaveFile(str_fname + ".bmp", wxBITMAP_TYPE_PNG);
}
break;
case 1:
{
wxLogMessage("PNG selected");
wxBitmap canvas_bm;
canvas_bm.CreateScaled(canvas_width, canvas_height, 32, canvas_scale);
wxMemoryDC canvas_dc(canvas_bm);
canvas_dc.SetBackground(*wxWHITE_BRUSH);
canvas_dc.Clear();
template_canvas->RenderToDC(canvas_dc, out_res_x, out_res_y);
canvas_bm.SaveFile(str_fname + ".png", wxBITMAP_TYPE_PNG);
}
break;
case 2:
{
wxLogMessage("SVG selected");
wxSVGFileDC dc(str_fname + ".svg", out_res_x, out_res_y);
template_canvas->RenderToSVG(dc, out_res_x, out_res_y);
}
break;
default:
{
}
break;
}
}
}
wxLogMessage("Exiting TemplateFrame::ExportImage");
}
void TemplateFrame::OnChangeMapTransparency()
{
// should be overrided.
}
void TemplateFrame::OnSaveCanvasImageAs(wxCommandEvent& event)
{
if (!template_canvas) return;
ExportImage(template_canvas, activeFrName);
}
void TemplateFrame::OnCopyLegendToClipboard(wxCommandEvent& event)
{
LOG_MSG("Entering TemplateFrame::OnCopyLegendToClipboard");
if (!template_legend) return;
wxSize sz = template_legend->GetVirtualSize();
wxBitmap bitmap(sz.x, sz.y);
wxMemoryDC dc;
dc.SelectObject(bitmap);
wxBrush brush;
brush.SetColour(template_legend->GetBackgroundColour());
dc.SetBrush(brush);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.DrawRectangle(0, 0, sz.x, sz.y);
dc.SetPen(*wxBLACK_PEN);
template_legend->OnDraw(dc);
dc.SelectObject(wxNullBitmap);
if (!wxTheClipboard->Open()) {
wxMessageBox("Can't open clipboard.");
} else {
wxTheClipboard->AddData(new wxBitmapDataObject(bitmap));
wxTheClipboard->Close();
}
LOG_MSG("Exiting TemplateFrame::OnCopyLegendToClipboard");
}
void TemplateFrame::OnCopyImageToClipboard(wxCommandEvent& event)
{
LOG_MSG("Entering TemplateFrame::OnCopyImageToClipboard");
if (!template_canvas) return;
wxSize sz = template_canvas->GetVirtualSize();
wxBitmap bitmap( sz.x, sz.y );
wxMemoryDC dc;
dc.SelectObject( bitmap );
dc.DrawBitmap(*template_canvas->GetLayer2(), 0, 0);
dc.SelectObject( wxNullBitmap );
if ( !wxTheClipboard->Open() ) {
wxMessageBox("Can't open clipboard.");
} else {
wxTheClipboard->AddData(new wxBitmapDataObject(bitmap));
wxTheClipboard->Close();
}
LOG_MSG("Exiting TemplateFrame::OnCopyImageToClipboard");
}
void TemplateFrame::OnLegendUseScientificNotation(wxCommandEvent& event)
{
bool flag = template_canvas->useScientificNotation;
template_canvas->SetScientificNotation(!flag);
if (MapCanvas* canvas = dynamic_cast<MapCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
} else if (CartogramNewCanvas* canvas = dynamic_cast<CartogramNewCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
} else if (CartogramNewCanvas* canvas = dynamic_cast<CartogramNewCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
} else if (ConditionalMapCanvas* canvas = dynamic_cast<ConditionalMapCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
} else if (PCPCanvas* canvas = dynamic_cast<PCPCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
} else if (ScatterNewPlotCanvas* canvas = dynamic_cast<ScatterNewPlotCanvas*>(template_canvas)) {
canvas->CreateAndUpdateCategories();
}
template_legend->Recreate();
UpdateOptionMenuItems();
}
void TemplateFrame::OnLegendBackgroundColor(wxCommandEvent& event)
{
if (!template_legend) return;
wxColour col = template_legend->GetBackgroundColour();
wxColourData data;
data.SetColour(col);
data.SetChooseFull(true);
for (int i = 0; i < 16; i++) {
wxColour colour(i*16, i*16, i*16);
data.SetCustomColour(i, colour);
}
wxColourDialog dialog(this, &data);
dialog.SetTitle("Legend Background Color");
if (dialog.ShowModal() == wxID_OK) {
wxColourData retData = dialog.GetColourData();
col = retData.GetColour();
template_legend->legend_background_color = col;
template_legend->Refresh();
}
UpdateOptionMenuItems();
}
bool TemplateFrame::GetColorFromUser(wxWindow* parent,
const wxColour& cur_color,
wxColour& ret_color,
const wxString& title)
{
wxColourData data;
data.SetColour(cur_color);
data.SetChooseFull(true);
for (int i=0; i<16; i++) {
wxColour color(i*16, i*16, i*16);
data.SetCustomColour(i, color);
}
wxColourDialog dialog(parent, &data);
dialog.SetTitle(title);
if (dialog.ShowModal() == wxID_OK) {
wxColourData retData = dialog.GetColourData();
ret_color = retData.GetColour();
return true;
}
return false;
}
void TemplateFrame::OnCanvasBackgroundColor(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnCanvasBackgroundColor");
if (!template_canvas) return;
wxColour new_color;
if ( GetColorFromUser(this,
template_canvas->canvas_background_color,
new_color,
"Background Color") ) {
template_canvas->SetCanvasBackgroundColor(new_color);
}
UpdateOptionMenuItems();
}
void TemplateFrame::OnSelectableFillColor(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnSelectableOutlineColor");
if (!template_canvas) return;
wxColour new_color;
if ( GetColorFromUser(this,
template_canvas->selectable_fill_color,
new_color,
"Fill Color") ) {
template_canvas->SetSelectableFillColor(new_color);
}
UpdateOptionMenuItems();
}
void TemplateFrame::OnSelectableOutlineColor(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnSelectableOutlineColor");
if (!template_canvas) return;
wxColour new_color;
if ( GetColorFromUser(this,
template_canvas->selectable_outline_color,
new_color,
"Outline Color") ) {
template_canvas->SetSelectableOutlineColor(new_color);
}
UpdateOptionMenuItems();
}
void TemplateFrame::OnUserBackgroundColorVisible(wxCommandEvent& event)
{
if (!template_canvas) return;
template_canvas->SetBackgroundColorVisible(
!template_canvas->user_canvas_background_color);
UpdateOptionMenuItems();
}
void TemplateFrame::OnSelectableOutlineVisible(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnSelectableOutlineVisible");
if (!template_canvas) return;
template_canvas->SetSelectableOutlineVisible(
!template_canvas->selectable_outline_visible);
UpdateOptionMenuItems();
}
void TemplateFrame::OnHighlightColor(wxCommandEvent& event)
{
LOG_MSG("Called TemplateFrame::OnHighlightColor");
if (!template_canvas) return;
wxColour new_color;
if ( GetColorFromUser(this,
template_canvas->highlight_color,
new_color,
"Highlight Color") ) {
template_canvas->SetHighlightColor(new_color);
}
UpdateOptionMenuItems();
}
void TemplateFrame::update(FramesManager* o)
{
}
void TemplateFrame::update(TableState* o)
{
}
void TemplateFrame::update(TimeState* o)
{
}
void TemplateFrame::SetDependsOnNonSimpleGroups(bool v)
{
depends_on_non_simple_groups = v;
}
bool TemplateFrame::AllowTimelineChanges()
{
if (supports_timeline_changes) return true;
return !depends_on_non_simple_groups;
}
bool TemplateFrame::AllowGroupModify(const wxString& grp_nm)
{
return (grp_dependencies.find(grp_nm) == grp_dependencies.end());
}
void TemplateFrame::AddGroupDependancy(const wxString& grp_nm)
{
grp_dependencies.insert(grp_nm);
}
void TemplateFrame::RemoveGroupDependancy(const wxString& grp_nm)
{
grp_dependencies.erase(grp_nm);
}
void TemplateFrame::ClearAllGroupDependencies()
{
grp_dependencies.clear();
}
int TemplateFrame::GetCurrentCanvasTimeStep()
{
return template_canvas ? template_canvas->cat_data.GetCurrentCanvasTmStep() : -1;
}