1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // User Interface //
9 // //
10 // Program: SAGA //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // VIEW_Layout_Info.cpp //
15 // //
16 // Copyright (C) 2005 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. SAGA is free software; you //
22 // can redistribute it and/or modify it under the terms //
23 // of the GNU General Public License as published by the //
24 // Free Software Foundation, either version 2 of the //
25 // License, or (at your option) any later version. //
26 // //
27 // SAGA is distributed in the hope that it will be //
28 // useful, but WITHOUT ANY WARRANTY; without even the //
29 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
30 // PARTICULAR PURPOSE. See the GNU General Public //
31 // License for more details. //
32 // //
33 // You should have received a copy of the GNU General //
34 // Public License along with this program; if not, see //
35 // <http://www.gnu.org/licenses/>. //
36 // //
37 //-------------------------------------------------------//
38 // //
39 // contact: Olaf Conrad //
40 // Institute of Geography //
41 // University of Goettingen //
42 // Germany //
43 // //
44 // e-mail: oconrad@saga-gis.org //
45 // //
46 ///////////////////////////////////////////////////////////
47
48 //---------------------------------------------------------
49 #include <wx/wx.h>
50 #include <wx/print.h>
51 #include <wx/printdlg.h>
52 #include <wx/clipbrd.h>
53 #include <wx/dataobj.h>
54 #include <wx/filename.h>
55
56 #include <saga_api/saga_api.h>
57 #include <saga_gdi/sgdi_helper.h>
58
59 #include "helper.h"
60
61 #include "res_commands.h"
62 #include "res_dialogs.h"
63
64 #include "wksp_map.h"
65
66 #include "view_layout_info.h"
67
68
69 ///////////////////////////////////////////////////////////
70 // //
71 ///////////////////////////////////////////////////////////
72
73 //---------------------------------------------------------
74 #define PointsPerMM (25.4 / 72.)
75
76
77 ///////////////////////////////////////////////////////////
78 // //
79 ///////////////////////////////////////////////////////////
80
81 //---------------------------------------------------------
Get_Item_Type_Name(int Type)82 const char * CVIEW_Layout_Info::Get_Item_Type_Name(int Type)
83 {
84 switch( Type )
85 {
86 case Item_Type_Map : return( "map" );
87 case Item_Type_Scalebar: return( "scalebar" );
88 case Item_Type_Scale : return( "scale" );
89 case Item_Type_Legend : return( "legend" );
90 case Item_Type_Label : return( "label" );
91 case Item_Type_Text : return( "text" );
92 case Item_Type_Image : return( "image" );
93 default : return( "" );
94 }
95 }
96
97
98 ///////////////////////////////////////////////////////////
99 // //
100 // //
101 // //
102 ///////////////////////////////////////////////////////////
103
104 //---------------------------------------------------------
105 class CLayout_Item : public CSGDI_Layout_Items::CSGDI_Layout_Item
106 {
107 public:
108 virtual int Get_Type (void) const = 0;
109
110 //-----------------------------------------------------
CLayout_Item(CVIEW_Layout_Info * pLayout,bool bSizeable=true)111 CLayout_Item(CVIEW_Layout_Info *pLayout, bool bSizeable = true)
112 : m_pLayout(pLayout)
113 {
114 static int Position = 0; Position = 1 + (Position % 10);
115
116 Set_Position(Position, Position + 10, Position, Position + 10); // default size
117
118 //-----------------------------------------------------
119 m_Parameters.Create(this, _TL("Properties"));
120
121 m_Parameters.Add_Node("", "POSITION", _TL("Position"), _TL("Position on paper measured in millimeters from left to right and top to bottom."));
122
123 m_Parameters.Add_Int("POSITION", "POSITION_LEFT", _TL("Left"), _TL(""));
124 m_Parameters.Add_Int("POSITION", "POSITION_TOP" , _TL("Top" ), _TL(""));
125
126 if( bSizeable )
127 {
128 m_Parameters.Add_Int("POSITION", "POSITION_RIGHT" , _TL("Right" ), _TL(""));
129 m_Parameters.Add_Int("POSITION", "POSITION_BOTTOM", _TL("Bottom"), _TL(""));
130 }
131
132 m_Parameters.Set_Callback_On_Parameter_Changed(Parameter_Changed);
133 }
134
135 //-----------------------------------------------------
Set_Position(double xMin,double xMax,double yMin,double yMax)136 bool Set_Position (double xMin, double xMax, double yMin, double yMax)
137 {
138 wxSize Size(m_pLayout->Get_PaperSize());
139
140 m_Rect.x = (int)(0.5 + ( xMin) * Size.GetWidth () / 100.);
141 m_Rect.width = (int)(0.5 + (xMax - xMin) * Size.GetWidth () / 100.);
142 m_Rect.y = (int)(0.5 + ( yMin) * Size.GetHeight() / 100.);
143 m_Rect.height = (int)(0.5 + (yMax - yMin) * Size.GetHeight() / 100.);
144
145 return( true );
146 }
147
148 //-----------------------------------------------------
Update_Position(bool bSave)149 bool Update_Position (bool bSave)
150 {
151 if( bSave )
152 {
153 m_Parameters["POSITION_LEFT"].Set_Value(m_Rect.GetLeft());
154 m_Parameters["POSITION_TOP" ].Set_Value(m_Rect.GetTop ());
155
156 if( m_Parameters("POSITION_RIGHT") )
157 {
158 m_Parameters["POSITION_RIGHT" ].Set_Value(m_Rect.x + m_Rect.width );
159 m_Parameters["POSITION_BOTTOM"].Set_Value(m_Rect.y + m_Rect.height);
160 }
161 }
162 else
163 {
164 wxRect Rect(m_Rect);
165
166 Rect.x = m_Parameters["POSITION_LEFT"].asInt();
167 Rect.y = m_Parameters["POSITION_TOP" ].asInt();
168
169 if( m_Parameters("POSITION_RIGHT") )
170 {
171 Rect.width = m_Parameters["POSITION_RIGHT" ].asInt() - Rect.x;
172 Rect.height = m_Parameters["POSITION_BOTTOM"].asInt() - Rect.y;
173 }
174
175 Set_Rect(Rect);
176 }
177
178 return( true );
179 }
180
181 //-----------------------------------------------------
Properties(wxWindow * pParent)182 virtual bool Properties (wxWindow *pParent)
183 {
184 Update_Position(true);
185
186 if( m_Parameters.Get_Count() > 0 && DLG_Parameters(&m_Parameters) )
187 {
188 Update_Position(false);
189
190 Adjust_Size();
191
192 return( true );
193 }
194
195 return( false );
196 }
197
198 //-----------------------------------------------------
Adjust_Size(void)199 virtual bool Adjust_Size (void)
200 {
201 return( true );
202 }
203
204 //-----------------------------------------------------
On_Parameter_Changed(CSG_Parameters & Parameters,CSG_Parameter & Parameter)205 virtual bool On_Parameter_Changed (CSG_Parameters &Parameters, CSG_Parameter &Parameter)
206 {
207 Parameters.Set_Enabled("POSITION_BOTTOM", ((CLayout_Item *)Parameters.Get_Owner())->m_Ratio <= 0);
208
209 return( true );
210 }
211
Parameter_Changed(CSG_Parameter * pParameter,int Flags)212 static int Parameter_Changed (CSG_Parameter *pParameter, int Flags)
213 {
214 CLayout_Item *pItem = pParameter && pParameter->Get_Parameters() ? (CLayout_Item *)pParameter->Get_Parameters()->Get_Owner() : NULL;
215
216 return( pItem && pItem->On_Parameter_Changed(*pParameter->Get_Parameters(), *pParameter) ? 0 : 1 );
217 }
218
219 //-----------------------------------------------------
220 CVIEW_Layout_Info *m_pLayout; CSG_Parameters m_Parameters;
221 };
222
223
224 ///////////////////////////////////////////////////////////
225 // //
226 ///////////////////////////////////////////////////////////
227
228 //---------------------------------------------------------
229 class CLayout_Map : public CLayout_Item
230 {
231 public:
Get_Type(void) const232 virtual int Get_Type (void) const { return( CVIEW_Layout_Info::Item_Type_Map ); }
233
234 //-----------------------------------------------------
CLayout_Map(CVIEW_Layout_Info * pLayout)235 CLayout_Map(CVIEW_Layout_Info *pLayout)
236 : CLayout_Item(pLayout)
237 {
238 m_Parameters.Add_Bool ("" , "FRAME_SHOW" , _TL("Frame" ), _TL(""), true);
239 m_Parameters.Add_Int ("FRAME_SHOW" , "FRAME_SIZE" , _TL("Size" ), _TL(""), 5, 2, true);
240
241 m_Parameters.Add_Bool ("" , "SCALE_FIXED" , _TL("Fixed Scale" ), _TL(""), false);
242 m_Parameters.Add_Double("SCALE_FIXED", "SCALE_NUMBER", _TL("Scale Number"), _TL(""), 10000, 0.0001, true);
243 }
244
245 //-----------------------------------------------------
On_Parameter_Changed(CSG_Parameters & Parameters,CSG_Parameter & Parameter)246 virtual bool On_Parameter_Changed (CSG_Parameters &Parameters, CSG_Parameter &Parameter)
247 {
248 Parameters.Set_Enabled("FRAME_SIZE" , Parameters["FRAME_SHOW" ].asBool());
249 Parameters.Set_Enabled("SCALE_NUMBER", Parameters["SCALE_FIXED"].asBool());
250
251 return( CLayout_Item::On_Parameter_Changed(Parameters, Parameter) );
252 }
253
254 //-----------------------------------------------------
Get_Rect_DC(void)255 wxRect Get_Rect_DC (void)
256 {
257 wxRect rPaper(m_Rect);
258
259 if( m_Parameters["FRAME_SHOW"].asBool() )
260 {
261 rPaper.Deflate(m_Parameters["FRAME_SIZE"].asInt());
262 }
263
264 return( m_pLayout->Get_Paper2DC(rPaper) );
265 }
266
267 //-----------------------------------------------------
Get_Rect_World(void)268 CSG_Rect Get_Rect_World (void)
269 {
270 wxRect rMap(Get_Rect_DC()); CSG_Rect rWorld(m_pLayout->Get_Map()->Get_World(rMap));
271
272 double Scale = m_Parameters["SCALE_FIXED"].asBool() ? m_Parameters["SCALE_NUMBER"].asDouble() : 0.;
273
274 if( Scale > 0. )
275 {
276 double Width = 0.5 * Scale * rMap.GetWidth() / (1000. * m_pLayout->Get_Paper2DC());
277 double Height = Width * rWorld.Get_YRange() / rWorld.Get_XRange();
278
279 rWorld.Assign(
280 rWorld.Get_XCenter() - Width, rWorld.Get_YCenter() - Height,
281 rWorld.Get_XCenter() + Width, rWorld.Get_YCenter() + Height
282 );
283 }
284
285 return( rWorld );
286 }
287
288 //-----------------------------------------------------
Draw(wxDC & dc)289 virtual bool Draw (wxDC &dc)
290 {
291 wxRect rFrame(m_pLayout->Get_Paper2DC(m_Rect)), rMap(Get_Rect_DC()); CSG_Rect rWorld(Get_Rect_World());
292
293 m_pLayout->Get_Map()->Draw_Map(dc, rWorld, m_pLayout->Get_Paper2DC(), rMap, LAYER_DRAW_FLAG_NOEDITS);
294
295 if( m_Parameters["FRAME_SHOW"].asBool() )
296 {
297 m_pLayout->Get_Map()->Draw_Frame(dc, rWorld, rMap, rMap.x - rFrame.x, false);
298 }
299
300 return( true );
301 }
302
303 //-----------------------------------------------------
Properties(wxWindow * pParent)304 virtual bool Properties (wxWindow *pParent)
305 {
306 if( m_Parameters["SCALE_FIXED"].asBool() == false )
307 {
308 wxRect rMap(Get_Rect_DC());
309
310 double Scale = 1000. * m_pLayout->Get_Map()->Get_World(rMap).Get_XRange() / (rMap.width / m_pLayout->Get_Paper2DC()); // to meter
311
312 m_Parameters["SCALE_NUMBER"].Set_Value(Scale);
313 }
314
315 return( CLayout_Item::Properties(pParent) );
316 }
317 };
318
319
320 ///////////////////////////////////////////////////////////
321 // //
322 ///////////////////////////////////////////////////////////
323
324 //---------------------------------------------------------
325 class CLayout_Scalebar : public CLayout_Item
326 {
327 public:
Get_Type(void) const328 virtual int Get_Type (void) const { return( CVIEW_Layout_Info::Item_Type_Scalebar ); }
329
330 //-----------------------------------------------------
CLayout_Scalebar(CVIEW_Layout_Info * pLayout)331 CLayout_Scalebar(CVIEW_Layout_Info *pLayout)
332 : CLayout_Item(pLayout)
333 {
334 m_Parameters.Add_Choice("",
335 "UNIT" , _TL("Unit"),
336 _TL(""),
337 CSG_String::Format("%s|%s",
338 _TL("do not show"),
339 _TL("automatically")
340 ), 1
341 );
342
343 m_Parameters.Add_Choice("",
344 "STYLE" , _TL("Style"),
345 _TL(""),
346 CSG_String::Format("%s|%s",
347 _TL("scale line"),
348 _TL("alternating scale bar")
349 ), 1
350 );
351 }
352
353 //-----------------------------------------------------
On_Parameter_Changed(CSG_Parameters & Parameters,CSG_Parameter & Parameter)354 virtual bool On_Parameter_Changed (CSG_Parameters &Parameters, CSG_Parameter &Parameter)
355 {
356 return( CLayout_Item::On_Parameter_Changed(Parameters, Parameter) );
357 }
358
359 //-----------------------------------------------------
Draw(wxDC & dc)360 virtual bool Draw (wxDC &dc)
361 {
362 int Style = SCALE_STYLE_LINECONN|SCALE_STYLE_GLOOMING|SCALE_STYLE_UNIT_BELOW;
363
364 if( m_Parameters("STYLE")->asInt() == 1 )
365 {
366 Style |= SCALE_STYLE_BLACKWHITE;
367 }
368
369 //-------------------------------------------------
370 CLayout_Map *pMap = (CLayout_Map *)m_pLayout->Get_Stock_Item(CVIEW_Layout_Info::Item_Type_Map);
371
372 wxRect rDC(m_pLayout->Get_Paper2DC(m_Rect)), rMap(pMap->Get_Rect_DC()); CSG_Rect rWorld(pMap->Get_Rect_World());
373
374 double Width = rDC.GetWidth() * rWorld.Get_XRange() / rMap.GetWidth();
375
376 //-------------------------------------------------
377 CSG_String Unit;
378
379 if( m_Parameters("UNIT")->asInt() >= 1 )
380 {
381 CSG_Projection Projection(m_pLayout->Get_Map()->Get_Projection());
382
383 if( Projection.is_Okay() )
384 {
385 Unit = SG_Get_Projection_Unit_Name(Projection.Get_Unit(), true);
386
387 if( Unit.is_Empty() ) Unit = Projection.Get_Unit_Name();
388
389 if( Projection.Get_Unit() == SG_PROJ_UNIT_Meter && Width > 10000. )
390 {
391 Unit = SG_Get_Projection_Unit_Name(SG_PROJ_UNIT_Kilometer, true);
392
393 Width /= 1000.;
394 }
395 }
396 }
397
398 //-------------------------------------------------
399 Draw_Scale(dc, rDC, 0., Width, SCALE_HORIZONTAL, SCALE_TICK_TOP, Style, Unit.c_str());
400
401 return( true );
402 }
403 };
404
405
406 ///////////////////////////////////////////////////////////
407 // //
408 ///////////////////////////////////////////////////////////
409
410 //---------------------------------------------------------
411 class CLayout_Scale : public CLayout_Item
412 {
413 public:
Get_Type(void) const414 virtual int Get_Type (void) const { return( CVIEW_Layout_Info::Item_Type_Scale ); }
415
416 //-----------------------------------------------------
CLayout_Scale(CVIEW_Layout_Info * pLayout)417 CLayout_Scale(CVIEW_Layout_Info *pLayout)
418 : CLayout_Item(pLayout, false)
419 {
420 m_Parameters.Add_String("", "TEXT" , _TL("Text" ), _TL(""), _TL("Scale"));
421 m_Parameters.Add_Font ("", "FONT" , _TL("Font" ), _TL(""));
422 m_Parameters.Add_Int ("", "DECIMALS", _TL("Decimals"), _TL("Ignored if set to -1."), 0, -1, true);
423
424 Set_Sizer(false);
425
426 Adjust_Size();
427 }
428
429 //-----------------------------------------------------
On_Parameter_Changed(CSG_Parameters & Parameters,CSG_Parameter & Parameter)430 virtual bool On_Parameter_Changed (CSG_Parameters &Parameters, CSG_Parameter &Parameter)
431 {
432 return( CLayout_Item::On_Parameter_Changed(Parameters, Parameter) );
433 }
434
435 //-----------------------------------------------------
Adjust_Size(void)436 virtual bool Adjust_Size (void)
437 {
438 wxRect r(m_Rect);
439 wxFont Font; wxColour Color; Set_Font(m_Parameters("FONT"), Font, Color);
440 wxMemoryDC dc; dc.GetMultiLineTextExtent(Get_Scale_Text(), &r.width, &r.height, NULL, &Font);
441
442 r.width = (int)(0.5 + r.width * PointsPerMM);
443 r.height = (int)(0.5 + r.height * PointsPerMM);
444
445 Set_Rect(r);
446
447 return( true );
448 }
449
450 //-----------------------------------------------------
Draw(wxDC & dc)451 virtual bool Draw (wxDC &dc)
452 {
453 Adjust_Size();
454
455 wxRect rDC(m_pLayout->Get_Paper2DC(m_Rect)), rMap(((CLayout_Map *)m_pLayout->Get_Stock_Item(CVIEW_Layout_Info::Item_Type_Map))->Get_Rect_DC());
456
457 wxFont Font, oldFont(dc.GetFont()); wxColour Color, oldColor = dc.GetTextForeground();
458
459 Set_Font(m_Parameters("FONT"), Font, Color);
460 Font.Scale((float)(PointsPerMM * m_pLayout->Get_Paper2DC()));
461 dc.SetFont(Font);
462 dc.SetTextForeground(Color);
463
464 Draw_Text(dc, TEXTALIGN_CENTER, rDC.x + rDC.width / 2, rDC.y + rDC.height / 2, Get_Scale_Text());
465
466 dc.SetFont(oldFont); // restore old font and color
467 dc.SetTextForeground(oldColor);
468
469 return( true );
470 }
471
472 //-----------------------------------------------------
Get_Scale_Text(void)473 wxString Get_Scale_Text (void)
474 {
475 CLayout_Map *pMap = (CLayout_Map *)m_pLayout->Get_Stock_Item(CVIEW_Layout_Info::Item_Type_Map);
476
477 double Scale = pMap->m_Parameters["SCALE_FIXED"].asBool() ? pMap->m_Parameters["SCALE_NUMBER"].asDouble() : 0.;
478
479 if( Scale <= 0. )
480 {
481 wxRect rMap(pMap->Get_Rect_DC());
482
483 Scale = 1000. * m_pLayout->Get_Map()->Get_World(rMap).Get_XRange() / (rMap.width / m_pLayout->Get_Paper2DC()); // to meter
484 }
485
486 //-------------------------------------------------
487 wxString Text(m_Parameters["TEXT"].asString());
488
489 Text += Text.IsEmpty() ? "1 : " : " 1 : ";
490
491 int Decimals = m_Parameters["DECIMALS"].asInt();
492
493 if( Decimals < 0 )
494 {
495 Text += Get_SignificantDecimals_String(Scale);
496 }
497 else
498 {
499 Text += wxString::Format("%.*f", Decimals, Scale);
500 }
501
502 return( Text );
503 }
504 };
505
506
507 ///////////////////////////////////////////////////////////
508 // //
509 ///////////////////////////////////////////////////////////
510
511 //---------------------------------------------------------
512 class CLayout_Legend : public CLayout_Item
513 {
514 public:
Get_Type(void) const515 virtual int Get_Type (void) const { return( CVIEW_Layout_Info::Item_Type_Legend ); }
516
517 //-----------------------------------------------------
CLayout_Legend(CVIEW_Layout_Info * pLayout)518 CLayout_Legend(CVIEW_Layout_Info *pLayout)
519 : CLayout_Item(pLayout)
520 {
521 m_Parameters.Add_Bool ("" , "FILL" , _TL("Fill" ), _TL(""), false);
522 m_Parameters.Add_Color ("FILL" , "FILL_RGB" , _TL("Color" ), _TL(""), SG_COLOR_WHITE);
523 m_Parameters.Add_Bool ("" , "OUTLINE" , _TL("Outline" ), _TL(""), false);
524 m_Parameters.Add_Color ("OUTLINE", "OUTLINE_RGB" , _TL("Color" ), _TL(""), SG_COLOR_BLACK);
525 m_Parameters.Add_Int ("OUTLINE", "OUTLINE_SIZE", _TL("Width" ), _TL(""), 1, 1, true);
526 m_Parameters.Add_Int ("" , "INFLATE" , _TL("Distance"), _TL(""), 1, 1, true);
527 }
528
529 //-----------------------------------------------------
On_Parameter_Changed(CSG_Parameters & Parameters,CSG_Parameter & Parameter)530 virtual bool On_Parameter_Changed (CSG_Parameters &Parameters, CSG_Parameter &Parameter)
531 {
532 Parameters.Set_Enabled("FILL_RGB" , Parameters["FILL" ].asBool());
533 Parameters.Set_Enabled("OUTLINE_RGB" , Parameters["OUTLINE"].asBool());
534 Parameters.Set_Enabled("OUTLINE_SIZE", Parameters["OUTLINE"].asBool());
535 Parameters.Set_Enabled("INFLATE" , Parameters["OUTLINE"].asBool() || Parameters["FILL"].asBool());
536
537 return( CLayout_Item::On_Parameter_Changed(Parameters, Parameter) );
538 }
539
540 //-----------------------------------------------------
Adjust_Size(void)541 virtual bool Adjust_Size (void)
542 {
543 wxSize Size;
544
545 if( m_pLayout->Get_Map()->Get_Legend_Size(Size, 1.) )
546 {
547 double Ratio = Size.y / (double)Size.x;
548
549 if( Ratio > 0. && Ratio != m_Ratio )
550 {
551 m_Rect.height = Ratio * m_Rect.width;
552
553 return( Set_Ratio(Ratio) );
554 }
555 }
556
557 return( false );
558 }
559
560 //-----------------------------------------------------
Draw(wxDC & dc)561 virtual bool Draw (wxDC &dc)
562 {
563 Adjust_Size();
564
565 wxSize Size;
566
567 if( m_pLayout->Get_Map()->Get_Legend_Size(Size, m_pLayout->Get_Paper2DC()) )
568 {
569 wxRect rDC(m_pLayout->Get_Paper2DC(m_Rect));
570
571 if( m_Parameters["FILL"].asBool() || m_Parameters["OUTLINE"].asBool() )
572 {
573 dc.SetBrush(!m_Parameters["FILL" ].asBool() ? *wxTRANSPARENT_BRUSH : wxBrush(
574 Get_Color_asWX(m_Parameters["FILL_RGB" ].asInt())
575 ));
576
577 dc.SetPen (!m_Parameters["OUTLINE"].asBool() ? *wxTRANSPARENT_PEN : wxPen (
578 Get_Color_asWX(m_Parameters["OUTLINE_RGB"].asInt()), m_Parameters["OUTLINE_SIZE"].asInt()
579 ));
580
581 dc.DrawRectangle(rDC);
582
583 rDC = m_pLayout->Get_Paper2DC(wxRect(m_Rect).Deflate(m_Parameters["INFLATE"].asInt()));
584 }
585
586 double Scale = rDC.GetHeight() / (double)Size.y;
587
588 if( Scale * Size.x > rDC.GetWidth() )
589 {
590 Scale = rDC.GetWidth() / (double)Size.x;
591 }
592
593 m_pLayout->Get_Map()->Draw_Legend(dc, m_pLayout->Get_Paper2DC(), Scale, rDC.GetLeftTop());
594
595 return( true );
596 }
597
598 return( false );
599 }
600 };
601
602
603 ///////////////////////////////////////////////////////////
604 // //
605 ///////////////////////////////////////////////////////////
606
607 //---------------------------------------------------------
608 class CLayout_Label : public CLayout_Item
609 {
610 public:
Get_Type(void) const611 virtual int Get_Type (void) const { return( CVIEW_Layout_Info::Item_Type_Label ); }
612
613 //-----------------------------------------------------
CLayout_Label(CVIEW_Layout_Info * pLayout,bool bProperties=false,const wxString & Text="",bool bLongText=false)614 CLayout_Label(CVIEW_Layout_Info *pLayout, bool bProperties = false, const wxString &Text = "", bool bLongText = false)
615 : CLayout_Item(pLayout, false)
616 {
617 m_Parameters.Add_String("" , "TEXT" , _TL("Text" ), _TL(""), _TL("Text"), bLongText);
618 m_Parameters.Add_Font ("" , "FONT" , _TL("Font" ), _TL(""));
619
620 if( bLongText )
621 {
622 m_Parameters.Add_Choice("" , "ALIGN" , _TL("Align" ), _TL(""), CSG_String::Format("%s|%s|%s", _TL("left"), _TL("center"), _TL("right")));
623 }
624
625 m_Parameters.Add_Bool ("" , "FILL" , _TL("Fill" ), _TL(""), false);
626 m_Parameters.Add_Color ("FILL" , "FILL_RGB" , _TL("Color" ), _TL(""), SG_COLOR_GREY_LIGHT);
627 m_Parameters.Add_Bool ("" , "OUTLINE" , _TL("Outline" ), _TL(""), false);
628 m_Parameters.Add_Color ("OUTLINE", "OUTLINE_RGB" , _TL("Color" ), _TL(""), SG_COLOR_BLACK);
629 m_Parameters.Add_Int ("OUTLINE", "OUTLINE_SIZE", _TL("Width" ), _TL(""), 1, 1, true);
630 m_Parameters.Add_Int ("" , "INFLATE" , _TL("Distance"), _TL(""), 1, 1, true);
631
632 Set_Sizer(false);
633
634 if( !Text.IsEmpty() )
635 {
636 CSG_String _Text(&Text); m_Parameters["TEXT"].Set_Value(_Text);
637 }
638
639 if( bProperties )
640 {
641 Properties(MDI_Get_Frame());
642 }
643
644 Adjust_Size();
645 }
646
647 //-----------------------------------------------------
On_Parameter_Changed(CSG_Parameters & Parameters,CSG_Parameter & Parameter)648 virtual bool On_Parameter_Changed (CSG_Parameters &Parameters, CSG_Parameter &Parameter)
649 {
650 Parameters.Set_Enabled("FILL_RGB" , Parameters["FILL" ].asBool());
651 Parameters.Set_Enabled("OUTLINE_RGB" , Parameters["OUTLINE"].asBool());
652 Parameters.Set_Enabled("OUTLINE_SIZE", Parameters["OUTLINE"].asBool());
653 Parameters.Set_Enabled("INFLATE" , Parameters["OUTLINE"].asBool() || Parameters["FILL"].asBool());
654
655 return( CLayout_Item::On_Parameter_Changed(Parameters, Parameter) );
656 }
657
658 //-----------------------------------------------------
Adjust_Size(void)659 virtual bool Adjust_Size (void)
660 {
661 wxRect r(m_Rect);
662 wxFont Font; wxColour Color; Set_Font(m_Parameters("FONT"), Font, Color);
663 wxMemoryDC dc; dc.GetMultiLineTextExtent(m_Parameters["TEXT"].asString(), &r.width, &r.height, NULL, &Font);
664
665 r.width = (int)(0.5 + r.width * PointsPerMM);
666 r.height = (int)(0.5 + r.height * PointsPerMM);
667
668 r.Inflate(m_Parameters["INFLATE"].asInt());
669
670 Set_Rect(r);
671
672 return( true );
673 }
674
675 //-----------------------------------------------------
Draw(wxDC & dc)676 virtual bool Draw (wxDC &dc)
677 {
678 if( m_Parameters["FILL"].asBool() || m_Parameters["OUTLINE"].asBool() )
679 {
680 wxRect rDC(m_pLayout->Get_Paper2DC(m_Rect));
681
682 dc.SetBrush(!m_Parameters["FILL" ].asBool() ? *wxTRANSPARENT_BRUSH : wxBrush(
683 Get_Color_asWX(m_Parameters["FILL_RGB" ].asInt())
684 ));
685
686 dc.SetPen (!m_Parameters["OUTLINE"].asBool() ? *wxTRANSPARENT_PEN : wxPen (
687 Get_Color_asWX(m_Parameters["OUTLINE_RGB"].asInt()), m_Parameters["OUTLINE_SIZE"].asInt()
688 ));
689
690 dc.DrawRectangle(rDC);
691 }
692
693 wxRect rDC(m_pLayout->Get_Paper2DC(wxRect(m_Rect).Deflate(m_Parameters["INFLATE"].asInt())));
694
695 wxFont Font, oldFont(dc.GetFont()); wxColour Color, oldColor = dc.GetTextForeground();
696
697 Set_Font(m_Parameters("FONT"), Font, Color);
698 Font.Scale((float)(PointsPerMM * m_pLayout->Get_Paper2DC()));
699 dc.SetFont(Font);
700 dc.SetTextForeground(Color);
701
702 if( Get_Type() == CVIEW_Layout_Info::Item_Type_Label )
703 {
704 Draw_Text(dc, TEXTALIGN_LEFT, rDC.x, rDC.y, m_Parameters["TEXT"].asString());
705 }
706 else
707 {
708 int Align = m_Parameters["ALIGN"].asInt();
709
710 dc.DrawLabel(m_Parameters["TEXT"].asString(), rDC, Align == 2 ? wxALIGN_RIGHT : Align == 1 ? wxALIGN_CENTER : wxALIGN_LEFT);
711 }
712
713 dc.SetFont(oldFont); // restore old font and color
714 dc.SetTextForeground(oldColor);
715
716 return( true );
717 }
718 };
719
720 //---------------------------------------------------------
721 class CLayout_Text : public CLayout_Label
722 {
723 public:
Get_Type(void) const724 virtual int Get_Type (void) const { return( CVIEW_Layout_Info::Item_Type_Text ); }
725
726 //-----------------------------------------------------
CLayout_Text(CVIEW_Layout_Info * pLayout,bool bProperties=false,const wxString & Text="")727 CLayout_Text(CVIEW_Layout_Info *pLayout, bool bProperties = false, const wxString &Text = "")
728 : CLayout_Label(pLayout, bProperties, Text, true)
729 {}
730 };
731
732
733 ///////////////////////////////////////////////////////////
734 // //
735 ///////////////////////////////////////////////////////////
736
737 //---------------------------------------------------------
738 class CLayout_Image : public CLayout_Item
739 {
740 public:
Get_Type(void) const741 virtual int Get_Type (void) const { return( CVIEW_Layout_Info::Item_Type_Image ); }
742
743 //-----------------------------------------------------
CLayout_Image(CVIEW_Layout_Info * pLayout,bool bDialog=false)744 CLayout_Image(CVIEW_Layout_Info *pLayout, bool bDialog = false)
745 : CLayout_Item(pLayout)
746 {
747 On_Construction();
748
749 if( bDialog )
750 {
751 Load();
752 }
753 }
754
CLayout_Image(CVIEW_Layout_Info * pLayout,const wxImage & Image)755 CLayout_Image(CVIEW_Layout_Info *pLayout, const wxImage &Image)
756 : CLayout_Item(pLayout), m_Image(Image)
757 {
758 On_Construction();
759
760 if( m_Image.HasAlpha() )
761 {
762 m_Parameters["MASK" ].Set_Value(true);
763 m_Parameters["MASK_RGB"].Set_Value((int)SG_GET_RGB(m_Image.GetMaskRed(), m_Image.GetMaskGreen(), m_Image.GetMaskBlue()));
764 }
765
766 Set_Size(m_Image.GetSize());
767 }
768
769 //-----------------------------------------------------
770 wxImage m_Image; CSG_String m_File;
771
On_Construction(void)772 bool On_Construction (void)
773 {
774 m_Parameters.Add_FilePath("", "FILE", _TL("File"), _TL(""),
775 CSG_String::Format(
776 "%s|*.png;*.jpg;*.tif;*.tiff;*.bmp|"
777 "%s (*.png)|*.png|"
778 "%s (*.jpg)|*.jpg|"
779 "%s (*.tif)|*.tif;*.tiff|"
780 "%s|*.*",
781 _TL("Recognized Files"),
782 _TL("Portable Network Graphics"),
783 _TL("JPEG"),
784 _TL("Tagged Image File Format"),
785 _TL("All Files")
786 )
787 );
788
789 m_Parameters.Add_Bool ("" , "FIXRATIO", _TL("Fix Ratio" ), _TL(""), true);
790 m_Parameters.Add_Bool ("" , "MASK" , _TL("Transparency"), _TL(""), false);
791 m_Parameters.Add_Color("MASK", "MASK_RGB", _TL("Color" ), _TL(""), SG_COLOR_WHITE);
792
793 return( true );
794 }
795
796 //-----------------------------------------------------
On_Parameter_Changed(CSG_Parameters & Parameters,CSG_Parameter & Parameter)797 virtual bool On_Parameter_Changed (CSG_Parameters &Parameters, CSG_Parameter &Parameter)
798 {
799 Parameters.Set_Enabled("MASK_RGB", Parameters["MASK"].asBool());
800
801 return( CLayout_Item::On_Parameter_Changed(Parameters, Parameter) );
802 }
803
804 //-----------------------------------------------------
Set_Size(const wxSize & Size)805 bool Set_Size (const wxSize &Size)
806 {
807 m_Rect.x = 10;
808 m_Rect.y = 10;
809 m_Rect.width = (int)(200 * Size.x / (double)Size.y);
810 m_Rect.height = 200;
811
812 Fix_Ratio(m_Parameters["FIXRATIO"].asBool());
813
814 return( true );
815 }
816
817 //-----------------------------------------------------
Load(void)818 bool Load (void)
819 {
820 wxString File;
821
822 return( DLG_Open(File, _TL("Load Image"), m_Parameters["FILE"].asFilePath()->Get_Filter()) && Load(File, true) );
823 }
824
Load(const wxString & File,bool bAdjustSize)825 bool Load (const wxString &File, bool bAdjustSize)
826 {
827 if( wxFileExists(File) && m_Image.LoadFile(File) && m_Image.IsOk() )
828 {
829 m_File = File.wc_str();
830
831 m_Parameters["FILE"].Set_Value(m_File);
832
833 m_Parameters["MASK" ].Set_Value(m_Image.HasAlpha());
834 m_Parameters["MASK_RGB"].Set_Value((int)SG_GET_RGB(m_Image.GetMaskRed(), m_Image.GetMaskGreen(), m_Image.GetMaskBlue()));
835
836 if( bAdjustSize )
837 {
838 Set_Size(m_Image.GetSize());
839 }
840
841 return( true );
842 }
843
844 return( false );
845 }
846
847 //-----------------------------------------------------
Save(const wxString & File,wxBitmapType Type)848 bool Save (const wxString &File, wxBitmapType Type)
849 {
850 if( m_Image.IsOk() && m_Image.SaveFile(File, Type) )
851 {
852 m_File = File.wc_str();
853
854 m_Parameters["FILE"].Set_Value(m_File);
855
856 return( true );
857 }
858
859 return( false );
860 }
861
Save(void)862 bool Save (void)
863 {
864 wxString File; int Type;
865
866 return( m_Image.IsOk() && DLG_Image_Save(File, Type) && Save(File, (wxBitmapType)Type) );
867 }
868
869 //-----------------------------------------------------
Restore(void)870 bool Restore (void)
871 {
872 if( m_Image.IsOk() )
873 {
874 Refresh(true);
875
876 Set_Rect(wxRect(m_Rect.x, m_Rect.y,
877 m_Image.GetSize().GetWidth (),
878 m_Image.GetSize().GetHeight())
879 );
880
881 Fix_Ratio(m_Parameters["FIXRATIO"].asBool());
882
883 Refresh(false);
884
885 return( true );
886 }
887
888 return( false );
889 }
890
891 //-----------------------------------------------------
Set_Transparency(bool bOn,long Color=0)892 bool Set_Transparency (bool bOn, long Color = 0)
893 {
894 if( m_Image.IsOk() )
895 {
896 if( bOn )
897 {
898 if( m_Image.HasAlpha() )
899 {
900 if( m_Image.GetMaskRed () == SG_GET_R(Color)
901 && m_Image.GetMaskGreen() == SG_GET_G(Color)
902 && m_Image.GetMaskBlue () == SG_GET_B(Color) )
903 {
904 return( true );
905 }
906
907 m_Image.ClearAlpha();
908 }
909
910 m_Image.SetMask();
911 m_Image.SetMaskColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color));
912 m_Image.InitAlpha();
913
914 return( true );
915 }
916 else if( m_Image.HasAlpha() )
917 {
918 m_Image.ClearAlpha();
919
920 return( true );
921 }
922 }
923
924 return( false );
925 }
926
927 //-----------------------------------------------------
Properties(wxWindow * pParent)928 virtual bool Properties (wxWindow *pParent)
929 {
930 if( CLayout_Item::Properties(pParent) )
931 {
932 if( m_File.Cmp(m_Parameters["FILE"].asString()) )
933 {
934 if( !Load(m_Parameters["FILE"].asString(), false) )
935 {
936 m_Parameters["FILE"].Set_Value(m_File);
937 }
938 }
939
940 Set_Transparency(m_Parameters["MASK"].asBool(), m_Parameters["MASK_RGB"].asColor());
941
942 Fix_Ratio(m_Parameters["FIXRATIO"].asBool());
943
944 return( true );
945 }
946
947 return( false );
948 }
949
950 //-----------------------------------------------------
Draw(wxDC & dc)951 virtual bool Draw (wxDC &dc)
952 {
953 if( m_Rect.GetWidth() > 0 && m_Rect.GetHeight() > 0 )
954 {
955 wxRect rDC(m_pLayout->Get_Paper2DC(m_Rect));
956
957 if( m_Image.IsOk() )
958 {
959 dc.DrawBitmap(wxBitmap(m_Image.Scale(rDC.GetWidth(), rDC.GetHeight())), rDC.GetLeft(), rDC.GetTop());
960 }
961 else
962 {
963 wxBrush oldBrush(dc.GetBrush()); dc.SetBrush(*wxTRANSPARENT_BRUSH);
964 wxPen oldPen (dc.GetPen ()); dc.SetPen (*wxRED_PEN );
965
966 dc.DrawRectangle(rDC);
967 dc.DrawLine(rDC.GetBottomLeft (), rDC.GetTopRight());
968 dc.DrawLine(rDC.GetBottomRight(), rDC.GetTopLeft ());
969
970 dc.SetBrush(oldBrush);
971 dc.SetPen (oldPen );
972 }
973
974 return( true );
975 }
976
977 return( false );
978 }
979 };
980
981
982 ///////////////////////////////////////////////////////////
983 // //
984 // //
985 // //
986 ///////////////////////////////////////////////////////////
987
988 //---------------------------------------------------------
989 class CVIEW_Layout_Printout : public wxPrintout
990 {
991 public:
CVIEW_Layout_Printout(CVIEW_Layout_Info * pLayout)992 CVIEW_Layout_Printout(CVIEW_Layout_Info *pLayout)
993 : wxPrintout(pLayout->Get_Name()), m_pLayout(pLayout)
994 {}
995
996 //-----------------------------------------------------
OnPrintPage(int iPage)997 virtual bool OnPrintPage (int iPage)
998 {
999 wxDC *pDC = HasPage(iPage) ? GetDC() : NULL;
1000
1001 if( pDC )
1002 {
1003 if( !m_Bmp.IsOk() ) // initialize bitmap...
1004 {
1005 wxSize Size(pDC->GetSize());
1006
1007 double dpi = Size.GetWidth() * 25.4 / m_pLayout->Get_PaperSize().GetWidth();
1008
1009 if( dpi > m_pLayout->Get_Parameter("MAX_DPI").asDouble() )
1010 {
1011 dpi = m_pLayout->Get_Parameter("MAX_DPI").asDouble();
1012
1013 Size.x = (int)(0.5 + m_pLayout->Get_PaperSize().GetWidth () * dpi / 25.4);
1014 Size.y = (int)(0.5 + m_pLayout->Get_PaperSize().GetHeight() * dpi / 25.4);
1015 }
1016
1017 m_Bmp.Create(Size.x, Size.y);
1018
1019 wxMemoryDC dc_Bmp(m_Bmp);
1020
1021 dc_Bmp.SetBackground(*wxWHITE_BRUSH);
1022 dc_Bmp.Clear();
1023
1024 m_pLayout->Draw(dc_Bmp, true);
1025 }
1026
1027 //---------------------------------------------
1028 if( m_Bmp.IsOk() ) // bitmap has been initialized...
1029 {
1030 wxMemoryDC dc_Bmp(m_Bmp);
1031
1032 if( m_Bmp.GetWidth () != pDC->GetSize().GetWidth ()
1033 || m_Bmp.GetHeight() != pDC->GetSize().GetHeight() )
1034 {
1035 pDC->StretchBlit(wxPoint(0, 0), pDC->GetSize(), &dc_Bmp, wxPoint(0, 0), dc_Bmp.GetSize());
1036 }
1037 else
1038 {
1039 pDC-> Blit(wxPoint(0, 0), pDC->GetSize(), &dc_Bmp, wxPoint(0, 0));
1040 }
1041
1042 return( true );
1043 }
1044 }
1045
1046 return( false );
1047 }
1048
1049 //-----------------------------------------------------
HasPage(int iPage)1050 virtual bool HasPage (int iPage)
1051 {
1052 return( iPage > 0 && iPage <= m_pLayout->Get_Page_Count() );
1053 }
1054
1055 //-----------------------------------------------------
GetPageInfo(int * minPage,int * maxPage,int * selPageFrom,int * selPageTo)1056 virtual void GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
1057 {
1058 *minPage = 1;
1059 *maxPage = m_pLayout->Get_Page_Count();
1060
1061 *selPageFrom = 1;
1062 *selPageTo = m_pLayout->Get_Page_Count();
1063 }
1064
1065
1066 protected:
1067
1068 wxBitmap m_Bmp;
1069
1070 CVIEW_Layout_Info *m_pLayout;
1071
1072 };
1073
1074
1075 ///////////////////////////////////////////////////////////
1076 // //
1077 // //
1078 // //
1079 ///////////////////////////////////////////////////////////
1080
1081 //---------------------------------------------------------
CVIEW_Layout_Info(CWKSP_Map * pMap)1082 CVIEW_Layout_Info::CVIEW_Layout_Info(CWKSP_Map *pMap)
1083 : m_pMap(pMap)
1084 {
1085 m_Zoom = 1.;
1086 m_Paper2DC = 1.;
1087
1088 //-----------------------------------------------------
1089 m_pPrintData = new wxPrintData;
1090 m_pPrintData->SetOrientation (wxLANDSCAPE );
1091 m_pPrintData->SetPaperId (wxPAPER_A4 );
1092
1093 m_pPrintPage = new wxPageSetupDialogData;
1094 m_pPrintPage->SetPrintData (*m_pPrintData );
1095 m_pPrintPage->SetMarginTopLeft (wxPoint(10, 10)); // millimetres
1096 m_pPrintPage->SetMarginBottomRight(wxPoint(10, 10)); // millimetres
1097
1098 //-----------------------------------------------------
1099 m_Items.Add(new CLayout_Map (this));
1100 m_Items.Add(new CLayout_Scalebar(this));
1101 m_Items.Add(new CLayout_Scale (this));
1102 m_Items.Add(new CLayout_Legend (this));
1103
1104 //-----------------------------------------------------
1105 Get_Stock_Item(Item_Type_Map )->Set_Position( 2, 70, 2, 90); // default layout
1106 Get_Stock_Item(Item_Type_Scalebar)->Set_Position( 2, 50, 92, 95);
1107 Get_Stock_Item(Item_Type_Scale )->Set_Position(55, 70, 92, 95); // m_Items.Hide(Get_Stock_Item(Item_Type_Scale));
1108 Get_Stock_Item(Item_Type_Legend )->Set_Position(72, 98, 2, 95);
1109
1110 //-----------------------------------------------------
1111 m_Parameters.Add_Int("",
1112 "MAX_DPI" , _TL("Maximum Resolution"),
1113 _TL("Maximum resolution [dots per inch], ignored if zero."),
1114 300, 0, true
1115 );
1116
1117 m_Parameters.Add_Node("",
1118 "RASTER" , _TL("Raster"),
1119 _TL("")
1120 );
1121
1122 m_Parameters.Add_Bool("RASTER",
1123 "RASTER_SHOW" , _TL("Show"),
1124 _TL(""),
1125 true
1126 );
1127
1128 m_Parameters.Add_Bool("RASTER",
1129 "RASTER_ALIGN" , _TL("Align"),
1130 _TL(""),
1131 true
1132 );
1133
1134 m_Parameters.Add_Int("RASTER",
1135 "RASTER_SIZE" , _TL("Size"),
1136 _TL("Raster size [mm]"),
1137 5, 1, true
1138 );
1139 }
1140
1141 //---------------------------------------------------------
~CVIEW_Layout_Info(void)1142 CVIEW_Layout_Info::~CVIEW_Layout_Info(void)
1143 {
1144 delete(m_pPrintPage);
1145 delete(m_pPrintData);
1146 }
1147
1148
1149 ///////////////////////////////////////////////////////////
1150 // //
1151 ///////////////////////////////////////////////////////////
1152
1153 //---------------------------------------------------------
Get_Name(void)1154 wxString CVIEW_Layout_Info::Get_Name(void)
1155 {
1156 return( m_pMap->Get_Name().c_str() );
1157 }
1158
1159 //---------------------------------------------------------
Get_Page_Count(void)1160 int CVIEW_Layout_Info::Get_Page_Count(void)
1161 {
1162 return( 1 );
1163 }
1164
1165
1166 ///////////////////////////////////////////////////////////
1167 // //
1168 ///////////////////////////////////////////////////////////
1169
1170 //---------------------------------------------------------
Properties(void)1171 bool CVIEW_Layout_Info::Properties(void)
1172 {
1173 if( DLG_Parameters(&m_Parameters) )
1174 {
1175 m_Items.Set_Raster(m_Parameters["RASTER_ALIGN"].asBool() ? m_Parameters["RASTER_SIZE"].asInt() : 0);
1176
1177 return( true );
1178 }
1179
1180 return( false );
1181 }
1182
1183
1184 ///////////////////////////////////////////////////////////
1185 // //
1186 ///////////////////////////////////////////////////////////
1187
1188 //---------------------------------------------------------
Get_PaperSize(void)1189 wxSize CVIEW_Layout_Info::Get_PaperSize(void)
1190 {
1191 wxSize Size(m_pPrintPage->GetPaperSize());
1192
1193 if( (m_pPrintData->GetOrientation() == wxLANDSCAPE && Size.x < Size.y)
1194 || (m_pPrintData->GetOrientation() == wxPORTRAIT && Size.x > Size.y) )
1195 {
1196 m_pPrintPage->SetPaperSize(Size = wxSize(Size.y, Size.x));
1197 }
1198
1199 return( Size );
1200 }
1201
1202 //---------------------------------------------------------
Get_Margins(void)1203 wxRect CVIEW_Layout_Info::Get_Margins(void)
1204 {
1205 wxSize Size(Get_PaperSize());
1206
1207 wxPoint TL(Get_Margin_TopLeft()), BR(Get_Margin_BottomRight()); // millimetres
1208
1209 return( wxRect(TL, wxSize(Size.x - TL.x - BR.x, Size.y - TL.y - BR.y)) );
1210 }
1211
1212 //---------------------------------------------------------
Get_Margin_TopLeft(void)1213 wxPoint CVIEW_Layout_Info::Get_Margin_TopLeft(void)
1214 {
1215 return( m_pPrintPage->GetMarginTopLeft() );
1216 }
1217
1218 //---------------------------------------------------------
Get_Margin_BottomRight(void)1219 wxPoint CVIEW_Layout_Info::Get_Margin_BottomRight(void)
1220 {
1221 return( m_pPrintPage->GetMarginBottomRight() );
1222 }
1223
1224
1225 ///////////////////////////////////////////////////////////
1226 // //
1227 ///////////////////////////////////////////////////////////
1228
1229 //---------------------------------------------------------
Page_Setup(void)1230 bool CVIEW_Layout_Info::Page_Setup(void)
1231 {
1232 (*m_pPrintPage) = *m_pPrintData;
1233
1234 wxPageSetupDialog dlg(MDI_Get_Frame(), m_pPrintPage);
1235
1236 if( dlg.ShowModal() == wxID_OK )
1237 {
1238 (*m_pPrintData) = dlg.GetPageSetupData().GetPrintData();
1239 (*m_pPrintPage) = dlg.GetPageSetupData();
1240
1241 return( true );
1242 }
1243
1244 return( false );
1245 }
1246
1247 //---------------------------------------------------------
Print_Setup(void)1248 bool CVIEW_Layout_Info::Print_Setup(void)
1249 {
1250 wxPrintDialog dlg(MDI_Get_Frame(), m_pPrintData);
1251
1252 if( dlg.ShowModal() == wxID_OK )
1253 {
1254 *m_pPrintData = dlg.GetPrintDialogData().GetPrintData();
1255
1256 return( true );
1257 }
1258
1259 return( false );
1260 }
1261
1262 //---------------------------------------------------------
Print_Preview(void)1263 bool CVIEW_Layout_Info::Print_Preview(void)
1264 {
1265 wxPrintPreview *pPreview = new wxPrintPreview(new CVIEW_Layout_Printout(this), new CVIEW_Layout_Printout(this), m_pPrintData);
1266
1267 if( pPreview->Ok() )
1268 {
1269 wxPreviewFrame *pFrame = new wxPreviewFrame(pPreview, (wxFrame *)MDI_Get_Frame(), _TL("Print Preview"), wxPoint(100, 100), wxSize(600, 650), wxDEFAULT_FRAME_STYLE|wxMAXIMIZE);
1270
1271 pFrame->Centre(wxBOTH);
1272 pFrame->Initialize();
1273 pFrame->Show(true);
1274
1275 return( true );
1276 }
1277
1278 delete(pPreview);
1279
1280 return( false );
1281 }
1282
1283 //---------------------------------------------------------
Print(void)1284 bool CVIEW_Layout_Info::Print(void)
1285 {
1286 wxPrintDialogData PrintData(*m_pPrintData);
1287
1288 wxPrinter Printer(&PrintData);
1289
1290 if( Printer.Print(MDI_Get_Frame(), new CVIEW_Layout_Printout(this), true) )
1291 {
1292 (*m_pPrintData) = Printer.GetPrintDialogData().GetPrintData();
1293 (*m_pPrintPage) = Printer.GetPrintDialogData().GetPrintData();
1294
1295 return( true );
1296 }
1297
1298 if( wxPrinter::GetLastError() == wxPRINTER_ERROR )
1299 {
1300 MSG_Error_Add(_TL("There was a problem with printing.\nPerhaps your current printer is not set correctly?"));
1301 }
1302 else
1303 {
1304 MSG_Error_Add(_TL("You canceled printing"));
1305 }
1306
1307 return( false );
1308 }
1309
1310
1311 ///////////////////////////////////////////////////////////
1312 // //
1313 ///////////////////////////////////////////////////////////
1314
1315 //---------------------------------------------------------
Load(void)1316 bool CVIEW_Layout_Info::Load(void)
1317 {
1318 wxString File, Filter = wxString::Format(
1319 "%s|*.sg-layout;*.xml|"
1320 "%s (*.sg-layout)|*.sg-layout|"
1321 "%s (*.xml)|*.xml|"
1322 "%s|*.*",
1323 _TL("Recognized Files"),
1324 _TL("SAGA Print Layout"),
1325 _TL("XML Files"),
1326 _TL("All Files")
1327 );
1328
1329 if( DLG_Open(File, wxString::Format("%s %s", _TL("Load"), _TL("Print Layout")), Filter) )
1330 {
1331 CSG_MetaData Layout;
1332
1333 return( Layout.Load(&File) && Load(Layout) );
1334 }
1335
1336 return( false );
1337 }
1338
1339 //---------------------------------------------------------
Load(const CSG_MetaData & Layout)1340 bool CVIEW_Layout_Info::Load(const CSG_MetaData &Layout)
1341 {
1342 if( !Layout.Cmp_Name("layout") || !Layout("general") || !Layout("items") )
1343 {
1344 return( false );
1345 }
1346
1347 if( SG_Compare_Version(Layout.Get_Property("saga-version"), "7.8.0") < 0 )
1348 {
1349 SG_UI_Msg_Add_Error(CSG_String::Format("%s %s: %s", _TL("Warning"), _TL("unsupported version"), Layout.Get_Property("saga-version")));
1350 }
1351
1352 for(size_t i=m_Items.Get_Count(); i>0; i--)
1353 {
1354 CLayout_Item *pItem = Get_Item(i - 1);
1355
1356 if( pItem->Get_Type() == Item_Type_Label
1357 || pItem->Get_Type() == Item_Type_Text
1358 || pItem->Get_Type() == Item_Type_Image )
1359 {
1360 m_Items.Del(pItem);
1361 }
1362 }
1363
1364 //-----------------------------------------------------
1365 const CSG_MetaData &General = Layout["general"];
1366
1367 if( General("orientation") )
1368 {
1369 m_pPrintData->SetOrientation(General["orientation"].Cmp_Content("landscape") ? wxLANDSCAPE : wxPORTRAIT);
1370 }
1371
1372 if( General("paperformat") )
1373 {
1374 m_pPrintData->SetPaperId((wxPaperSize)General["paperformat"].Get_Content().asInt());
1375 }
1376
1377 m_pPrintPage->SetPrintData(*m_pPrintData);
1378
1379 if( General("parameters") )
1380 {
1381 m_Parameters.Serialize(*General("parameters"), false);
1382
1383 m_Items.Set_Raster(m_Parameters["RASTER_ALIGN"].asBool() ? m_Parameters["RASTER_SIZE"].asInt() : 0);
1384 }
1385
1386 //-----------------------------------------------------
1387 const CSG_MetaData &Items = Layout["items"];
1388
1389 for(int i=0; i<Items.Get_Children_Count(); i++)
1390 {
1391 const CSG_MetaData &Item = Items[i];
1392
1393 CLayout_Item *pItem = NULL; int Type; if( !Item.Get_Property("type", Type) ) { Type = Item_Type_None; }
1394
1395 switch( Type )
1396 {
1397 case Item_Type_Map : pItem = Get_Stock_Item(Item_Type_Map ); break;
1398 case Item_Type_Scalebar: pItem = Get_Stock_Item(Item_Type_Scalebar); break;
1399 case Item_Type_Scale : pItem = Get_Stock_Item(Item_Type_Scale ); break;
1400 case Item_Type_Legend : pItem = Get_Stock_Item(Item_Type_Legend ); break;
1401
1402 case Item_Type_Label : pItem = new CLayout_Label (this); break;
1403 case Item_Type_Text : pItem = new CLayout_Text (this); break;
1404 case Item_Type_Image : pItem = new CLayout_Image (this); break;
1405 }
1406
1407 if( pItem )
1408 {
1409 if( Item("parameters") )
1410 {
1411 pItem->m_Parameters.Serialize(*Item("parameters"), false);
1412
1413 pItem->Update_Position(false);
1414 }
1415
1416 if( pItem->Get_Type() == Item_Type_Label
1417 || pItem->Get_Type() == Item_Type_Text
1418 || pItem->Get_Type() == Item_Type_Image )
1419 {
1420 if( Type == Item_Type_Image )
1421 {
1422 ((CLayout_Image *)pItem)->Load(
1423 pItem->m_Parameters["FILE"].asString(), false
1424 );
1425
1426 ((CLayout_Image *)pItem)->Set_Transparency(
1427 pItem->m_Parameters["MASK" ].asBool (),
1428 pItem->m_Parameters["MASK_RGB"].asColor()
1429 );
1430 }
1431
1432 pItem->Adjust_Size();
1433
1434 m_Items.Add(pItem);
1435 }
1436 else
1437 {
1438 m_Items.Move_Top(pItem);
1439
1440 if( Item.Cmp_Property("show", "false", true) )
1441 {
1442 m_Items.Hide(pItem);
1443 }
1444 else
1445 {
1446 m_Items.Show(pItem);
1447 }
1448 }
1449 }
1450 }
1451
1452 //-----------------------------------------------------
1453 if( m_Items.Get_Parent() )
1454 {
1455 m_Items.Get_Parent()->Refresh();
1456 }
1457
1458 return( true );
1459 }
1460
1461 //---------------------------------------------------------
Save(void) const1462 bool CVIEW_Layout_Info::Save(void) const
1463 {
1464 wxString File, Filter = wxString::Format(
1465 "%s (*.sg-layout)|*.sg-layout|"
1466 "%s (*.xml)|*.xml|"
1467 "%s|*.*",
1468 _TL("SAGA Print Layout"),
1469 _TL("XML Files"),
1470 _TL("All Files")
1471 );
1472
1473 if( DLG_Save(File, wxString::Format("%s %s", _TL("Save"), _TL("Print Layout")), Filter) )
1474 {
1475 if( 1 ) // automatically save unsaved images...
1476 {
1477 for(size_t i=0, j=0; i<m_Items.Get_Count(); i++)
1478 {
1479 CLayout_Image *pItem = Get_Item(i)->Get_Type() == Item_Type_Image ? (CLayout_Image *)Get_Item(i) : NULL;
1480
1481 if( pItem && !SG_File_Exists(pItem->m_File) )
1482 {
1483 wxFileName fn(File); fn.SetName(fn.GetName() + wxString::Format("_%d", ++j)); fn.SetExt("png");
1484
1485 pItem->Save(fn.GetFullPath(), wxBITMAP_TYPE_PNG);
1486 }
1487 }
1488 }
1489
1490 CSG_MetaData Layout;
1491
1492 return( Save(Layout) && Layout.Save(&File) );
1493 }
1494
1495 return( false );
1496 }
1497
1498 //---------------------------------------------------------
Save(CSG_MetaData & Layout) const1499 bool CVIEW_Layout_Info::Save(CSG_MetaData &Layout) const
1500 {
1501 Layout.Set_Name ("layout");
1502 Layout.Add_Property("saga-version", SAGA_VERSION);
1503
1504 //-----------------------------------------------------
1505 CSG_MetaData &General = *Layout.Add_Child("general");
1506
1507 General.Add_Child("orientation", m_pPrintData->GetOrientation() == wxLANDSCAPE ? "landscape" : "portrait");
1508 General.Add_Child("paperformat", m_pPrintData->GetPaperId());
1509
1510 m_Parameters.Serialize(*General.Add_Child());
1511
1512 //-----------------------------------------------------
1513 CSG_MetaData &Items = *Layout.Add_Child("items");
1514
1515 for(size_t i=0; i<m_Items.Get_Count(); i++)
1516 {
1517 CSG_MetaData &Item = *Items.Add_Child("item");
1518
1519 CLayout_Item *pItem = Get_Item(i);
1520
1521 Item.Add_Property("name", Get_Item_Type_Name(pItem->Get_Type()));
1522 Item.Add_Property("type", pItem->Get_Type());
1523 Item.Add_Property("show", pItem->is_Shown());
1524
1525 pItem->Update_Position(true);
1526
1527 pItem->m_Parameters.Serialize(*Item.Add_Child());
1528 }
1529
1530 //-----------------------------------------------------
1531 return( true );
1532 }
1533
1534
1535 ///////////////////////////////////////////////////////////
1536 // //
1537 ///////////////////////////////////////////////////////////
1538
1539 //---------------------------------------------------------
is_Shown(int Item_Type)1540 bool CVIEW_Layout_Info::is_Shown(int Item_Type)
1541 {
1542 CLayout_Item *pItem = Get_Stock_Item(Item_Type);
1543
1544 return( pItem && pItem->is_Shown() );
1545 }
1546
1547 //---------------------------------------------------------
is_Stock(int Item_Type)1548 bool CVIEW_Layout_Info::is_Stock(int Item_Type)
1549 {
1550 return( Item_Type == Item_Type_Map
1551 || Item_Type == Item_Type_Scalebar
1552 || Item_Type == Item_Type_Scale
1553 || Item_Type == Item_Type_Legend
1554 );
1555 }
1556
1557 //---------------------------------------------------------
Can_Hide(CLayout_Item * pItem)1558 bool CVIEW_Layout_Info::Can_Hide(CLayout_Item *pItem)
1559 {
1560 if( !pItem )
1561 {
1562 pItem = (CLayout_Item *)m_Items.Get_Active();
1563 }
1564
1565 return( pItem // && is_Stock(pItem->Get_Type()) );
1566 && (pItem->Get_Type() == Item_Type_Scalebar
1567 || pItem->Get_Type() == Item_Type_Scale
1568 || pItem->Get_Type() == Item_Type_Legend )
1569 );
1570 }
1571
1572 //---------------------------------------------------------
Can_Delete(CLayout_Item * pItem)1573 bool CVIEW_Layout_Info::Can_Delete(CLayout_Item *pItem)
1574 {
1575 if( !pItem )
1576 {
1577 pItem = (CLayout_Item *)m_Items.Get_Active();
1578 }
1579
1580 return( pItem && !is_Stock(pItem->Get_Type()) );
1581 }
1582
1583 //---------------------------------------------------------
Add_Item(int Item_Type)1584 bool CVIEW_Layout_Info::Add_Item(int Item_Type)
1585 {
1586 switch( Item_Type )
1587 {
1588 case Item_Type_Label: m_Items.Add(new CLayout_Label(this, true), true); break;
1589 case Item_Type_Text : m_Items.Add(new CLayout_Text (this, true), true); break;
1590 case Item_Type_Image: m_Items.Add(new CLayout_Image(this, true), true); break;
1591 }
1592
1593 return( false );
1594 }
1595
1596 //---------------------------------------------------------
Get_Stock_Item(int Item_Type)1597 CLayout_Item * CVIEW_Layout_Info::Get_Stock_Item(int Item_Type)
1598 {
1599 if( is_Stock(Item_Type) )
1600 {
1601 for(size_t i=0; i<m_Items.Get_Count(); i++)
1602 {
1603 if( Get_Item(i)->Get_Type() == Item_Type )
1604 {
1605 return( Get_Item(i) );
1606 }
1607 }
1608 }
1609
1610 return( NULL );
1611 }
1612
1613 //---------------------------------------------------------
Toggle_Stock_Item(int Item_Type)1614 bool CVIEW_Layout_Info::Toggle_Stock_Item(int Item_Type)
1615 {
1616 CLayout_Item *pItem = Get_Stock_Item(Item_Type);
1617
1618 if( pItem )
1619 {
1620 return( pItem->is_Shown() ? m_Items.Hide(pItem) : m_Items.Show(pItem) );
1621 }
1622
1623 return( false );
1624 }
1625
1626 //---------------------------------------------------------
Toggle_Stock_Item(CLayout_Item * pItem)1627 bool CVIEW_Layout_Info::Toggle_Stock_Item(CLayout_Item *pItem)
1628 {
1629 if( !pItem )
1630 {
1631 pItem = (CLayout_Item *)m_Items.Get_Active();
1632 }
1633
1634 if( pItem && Can_Hide(pItem) )
1635 {
1636 return( pItem->is_Shown() ? m_Items.Hide(pItem) : m_Items.Show(pItem) );
1637 }
1638
1639 return( false );
1640 }
1641
1642 //---------------------------------------------------------
Clipboard_Paste(void)1643 bool CVIEW_Layout_Info::Clipboard_Paste(void)
1644 {
1645 bool bResult = false;
1646
1647 Set_Buisy_Cursor(true);
1648
1649 if( wxTheClipboard->Open() )
1650 {
1651 if( wxTheClipboard->IsSupported(wxDF_TEXT) )
1652 {
1653 wxTextDataObject Data;
1654
1655 if( wxTheClipboard->GetData(Data) )
1656 {
1657 m_Items.Add(new CLayout_Text(this, true, Data.GetText()), true);
1658
1659 bResult = true;
1660 }
1661 }
1662
1663 if( wxTheClipboard->IsSupported(wxDF_BITMAP) )
1664 {
1665 wxBitmapDataObject Data;
1666
1667 if( wxTheClipboard->GetData(Data) )
1668 {
1669 m_Items.Add(new CLayout_Image(this, Data.GetBitmap().ConvertToImage()), true);
1670
1671 bResult = true;
1672 }
1673 }
1674
1675 wxTheClipboard->Close();
1676 }
1677
1678 Set_Buisy_Cursor(false);
1679
1680 return( bResult );
1681 }
1682
1683
1684 ///////////////////////////////////////////////////////////
1685 // //
1686 ///////////////////////////////////////////////////////////
1687
1688 //---------------------------------------------------------
Menu_Get_Active(void)1689 wxMenu * CVIEW_Layout_Info::Menu_Get_Active(void)
1690 {
1691 wxMenu *pMenu = new wxMenu;
1692
1693 //-----------------------------------------------------
1694 wxMenu *pMenu_Show = new wxMenu;
1695
1696 // CMD_Menu_Add_Item(pMenu_Show, true, ID_CMD_LAYOUT_ITEM_MAP);
1697 CMD_Menu_Add_Item(pMenu_Show, true, ID_CMD_LAYOUT_ITEM_LEGEND);
1698 CMD_Menu_Add_Item(pMenu_Show, true, ID_CMD_LAYOUT_ITEM_SCALEBAR);
1699 CMD_Menu_Add_Item(pMenu_Show, true, ID_CMD_LAYOUT_ITEM_SCALE);
1700
1701 //-----------------------------------------------------
1702 wxMenu *pMenu_Add = new wxMenu;
1703
1704 CMD_Menu_Add_Item(pMenu_Add, false, ID_CMD_LAYOUT_ITEM_LABEL);
1705 CMD_Menu_Add_Item(pMenu_Add, false, ID_CMD_LAYOUT_ITEM_TEXT);
1706 CMD_Menu_Add_Item(pMenu_Add, false, ID_CMD_LAYOUT_ITEM_IMAGE);
1707
1708 if( wxTheClipboard->IsSupported(wxDF_TEXT )
1709 || wxTheClipboard->IsSupported(wxDF_BITMAP) )
1710 {
1711 CMD_Menu_Add_Item(pMenu_Add, false, ID_CMD_LAYOUT_ITEM_PASTE);
1712 }
1713
1714 //-----------------------------------------------------
1715 if( m_Items.Get_Active() )
1716 {
1717 if( Can_Hide() )
1718 {
1719 CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_ITEM_HIDE);
1720 }
1721
1722 if( Can_Delete() )
1723 {
1724 CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_ITEM_DELETE);
1725 }
1726
1727 if( ((CLayout_Item *)m_Items.Get_Active())->Get_Type() == Item_Type_Image )
1728 {
1729 CLayout_Image *pItem = (CLayout_Image *)m_Items.Get_Active();
1730
1731 if( !SG_File_Exists(pItem->m_File) )
1732 {
1733 CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_IMAGE_SAVE);
1734 }
1735
1736 CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_IMAGE_RESTORE);
1737 }
1738
1739 if( pMenu->GetMenuItemCount() > 0 )
1740 {
1741 pMenu->AppendSeparator();
1742 }
1743
1744 if( m_Items.Get_Count() > 1 )
1745 {
1746 wxMenu *pMenu_Order = new wxMenu;
1747
1748 CMD_Menu_Add_Item(pMenu_Order, false, ID_CMD_LAYOUT_ITEM_MOVE_TOP );
1749 CMD_Menu_Add_Item(pMenu_Order, false, ID_CMD_LAYOUT_ITEM_MOVE_BOTTOM);
1750 CMD_Menu_Add_Item(pMenu_Order, false, ID_CMD_LAYOUT_ITEM_MOVE_UP );
1751 CMD_Menu_Add_Item(pMenu_Order, false, ID_CMD_LAYOUT_ITEM_MOVE_DOWN );
1752
1753 pMenu->AppendSubMenu(pMenu_Order, _TL("Order"));
1754 }
1755
1756 pMenu->AppendSubMenu(pMenu_Show, _TL("Show"));
1757 pMenu->AppendSubMenu(pMenu_Add , _TL("Add" ));
1758
1759 pMenu->AppendSeparator();
1760 CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_ITEM_PROPERTIES);
1761 }
1762
1763 //-----------------------------------------------------
1764 else // Layout Menu...
1765 {
1766 CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_TO_CLIPBOARD);
1767
1768 pMenu->AppendSeparator();
1769
1770 pMenu->AppendSubMenu(pMenu_Show, _TL("Show"));
1771 pMenu->AppendSubMenu(pMenu_Add , _TL("Add" ));
1772
1773 pMenu->AppendSeparator();
1774 CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_PROPERTIES );
1775 }
1776
1777 return( pMenu );
1778 }
1779
1780 //---------------------------------------------------------
Menu_On_Command(wxCommandEvent & event)1781 bool CVIEW_Layout_Info::Menu_On_Command(wxCommandEvent &event)
1782 {
1783 switch( event.GetId() )
1784 {
1785 case ID_CMD_LAYOUT_TO_CLIPBOARD : Clipboard_Copy (); break;
1786 case ID_CMD_LAYOUT_ITEM_PASTE : Clipboard_Paste (); break;
1787
1788 case ID_CMD_LAYOUT_ITEM_MAP : Toggle_Stock_Item(Item_Type_Map ); break;
1789 case ID_CMD_LAYOUT_ITEM_LEGEND : Toggle_Stock_Item(Item_Type_Legend ); break;
1790 case ID_CMD_LAYOUT_ITEM_SCALEBAR : Toggle_Stock_Item(Item_Type_Scalebar); break;
1791 case ID_CMD_LAYOUT_ITEM_SCALE : Toggle_Stock_Item(Item_Type_Scale ); break;
1792 case ID_CMD_LAYOUT_ITEM_LABEL : Add_Item(Item_Type_Label ); break;
1793 case ID_CMD_LAYOUT_ITEM_TEXT : Add_Item(Item_Type_Text ); break;
1794 case ID_CMD_LAYOUT_ITEM_IMAGE : Add_Item(Item_Type_Image ); break;
1795
1796 case ID_CMD_LAYOUT_ITEM_PROPERTIES : m_Items.Active_Properties (); break;
1797 case ID_CMD_LAYOUT_ITEM_DELETE : m_Items.Del(m_Items.Get_Active ()); break;
1798 case ID_CMD_LAYOUT_ITEM_HIDE : Toggle_Stock_Item (); break;
1799
1800 case ID_CMD_LAYOUT_ITEM_MOVE_TOP : m_Items.Active_Move_Top (); break;
1801 case ID_CMD_LAYOUT_ITEM_MOVE_BOTTOM: m_Items.Active_Move_Bottom (); break;
1802 case ID_CMD_LAYOUT_ITEM_MOVE_UP : m_Items.Active_Move_Up (); break;
1803 case ID_CMD_LAYOUT_ITEM_MOVE_DOWN : m_Items.Active_Move_Down (); break;
1804
1805 case ID_CMD_LAYOUT_IMAGE_SAVE : ((CLayout_Image *)m_Items.Get_Active())->Save (); break;
1806 case ID_CMD_LAYOUT_IMAGE_RESTORE : ((CLayout_Image *)m_Items.Get_Active())->Restore(); break;
1807 }
1808
1809 return( true );
1810 }
1811
1812 //---------------------------------------------------------
Menu_On_Command_UI(wxUpdateUIEvent & event)1813 bool CVIEW_Layout_Info::Menu_On_Command_UI(wxUpdateUIEvent &event)
1814 {
1815 switch( event.GetId() )
1816 {
1817 case ID_CMD_LAYOUT_ITEM_MAP : event.Check(is_Shown(Item_Type_Map )); break;
1818 case ID_CMD_LAYOUT_ITEM_LEGEND : event.Check(is_Shown(Item_Type_Legend )); break;
1819 case ID_CMD_LAYOUT_ITEM_SCALEBAR : event.Check(is_Shown(Item_Type_Scalebar)); break;
1820 case ID_CMD_LAYOUT_ITEM_SCALE : event.Check(is_Shown(Item_Type_Scale )); break;
1821
1822 case ID_CMD_LAYOUT_ITEM_MOVE_TOP : event.Enable(!m_Items.Active_is_Top ()); break;
1823 case ID_CMD_LAYOUT_ITEM_MOVE_BOTTOM: event.Enable(!m_Items.Active_is_Bottom()); break;
1824 case ID_CMD_LAYOUT_ITEM_MOVE_UP : event.Enable(!m_Items.Active_is_Top ()); break;
1825 case ID_CMD_LAYOUT_ITEM_MOVE_DOWN : event.Enable(!m_Items.Active_is_Bottom()); break;
1826
1827 case ID_CMD_LAYOUT_ITEM_PASTE : event.Enable(
1828 wxTheClipboard->IsSupported(wxDF_TEXT )
1829 || wxTheClipboard->IsSupported(wxDF_BITMAP) );
1830 break;
1831 }
1832
1833 return( true );
1834 }
1835
1836
1837 ///////////////////////////////////////////////////////////
1838 // //
1839 ///////////////////////////////////////////////////////////
1840
1841 //---------------------------------------------------------
Set_Zoom(double Zoom)1842 bool CVIEW_Layout_Info::Set_Zoom(double Zoom)
1843 {
1844 if( Zoom > 0. && Zoom != m_Zoom )
1845 {
1846 m_Items.Scale(m_Zoom = Zoom);
1847
1848 return( true );
1849 }
1850
1851 return( false );
1852 }
1853
1854 //---------------------------------------------------------
Draw_Paper(wxDC & dc)1855 bool CVIEW_Layout_Info::Draw_Paper(wxDC &dc)
1856 {
1857 dc.SetBrush(*wxWHITE_BRUSH);
1858 dc.SetPen (*wxBLACK_PEN );
1859 dc.DrawRectangle(Get_Rect_Scaled(Get_PaperSize(), m_Zoom));
1860
1861 if( m_Parameters["RASTER_SHOW"].asBool() )
1862 {
1863 double Step = m_Parameters["RASTER_SIZE"].asDouble();
1864
1865 for(int y=Step; y<Get_PaperSize().GetHeight()-1; y+=Step)
1866 {
1867 int yy = (int)(0.5 + y * m_Zoom);
1868
1869 for(int x=Step; x<Get_PaperSize().GetWidth()-1; x+=Step)
1870 {
1871 int xx = (int)(0.5 + x * m_Zoom);
1872
1873 dc.DrawPoint(xx, yy);
1874 }
1875 }
1876 }
1877
1878 return( true );
1879 }
1880
1881 //---------------------------------------------------------
Draw(wxDC & dc,bool bPrintOut)1882 bool CVIEW_Layout_Info::Draw(wxDC &dc, bool bPrintOut)
1883 {
1884 m_Paper2DC = bPrintOut ? dc.GetSize().GetWidth() / ((double)Get_PaperSize().GetWidth()) : m_Zoom;
1885
1886 m_Items.Draw(dc, !bPrintOut);
1887
1888 return( true );
1889 }
1890
1891
1892 ///////////////////////////////////////////////////////////
1893 // //
1894 ///////////////////////////////////////////////////////////
1895
1896 //---------------------------------------------------------
Export(void)1897 bool CVIEW_Layout_Info::Export(void)
1898 {
1899 wxString File; int Type;
1900
1901 if( !DLG_Image_Save(File, Type, "", Get_Name()) )
1902 {
1903 return( false );
1904 }
1905
1906 //-----------------------------------------------------
1907 static int dpi = 150;
1908
1909 if( !DLG_Get_Number(dpi, _TL("Copy Map to Clipboard"), wxString::Format("%s [dpi]", _TL("Resolution"))) )
1910 {
1911 return( false );
1912 }
1913
1914 //-----------------------------------------------------
1915 Set_Buisy_Cursor(true);
1916
1917 wxRect r(Get_Rect_Scaled(Get_PaperSize(), dpi / 25.4));
1918 wxBitmap Bmp(r.GetWidth(), r.GetHeight());
1919 wxMemoryDC dc(Bmp); dc.SetBackground(*wxWHITE_BRUSH); dc.Clear();
1920
1921 Draw(dc, true);
1922
1923 dc.SelectObject(wxNullBitmap);
1924
1925 bool bResult = Bmp.SaveFile(File, (wxBitmapType)Type);
1926
1927 Set_Buisy_Cursor(false);
1928
1929 return( bResult );
1930 }
1931
1932 //---------------------------------------------------------
Clipboard_Copy(void)1933 bool CVIEW_Layout_Info::Clipboard_Copy(void)
1934 {
1935 if( !wxTheClipboard->Open() )
1936 {
1937 return( false );
1938 }
1939
1940 //-----------------------------------------------------
1941 int dpi = 150;
1942
1943 if( !DLG_Get_Number(dpi, _TL("Copy Map to Clipboard"), wxString::Format("%s [dpi]", _TL("Resolution"))) )
1944 {
1945 wxTheClipboard->Close();
1946
1947 return( false );
1948 }
1949
1950 //-----------------------------------------------------
1951 Set_Buisy_Cursor(true);
1952
1953 wxRect r(Get_Rect_Scaled(Get_PaperSize(), dpi / 25.4));
1954 wxBitmap Bmp(r.GetWidth(), r.GetHeight());
1955 wxMemoryDC dc(Bmp); dc.SetBackground(*wxWHITE_BRUSH); dc.Clear();
1956
1957 Draw(dc, true);
1958
1959 dc.SelectObject(wxNullBitmap);
1960
1961 wxTheClipboard->SetData(new wxBitmapDataObject(Bmp));
1962 wxTheClipboard->Close();
1963
1964 Set_Buisy_Cursor(false);
1965
1966 return( true );
1967 }
1968
1969
1970 ///////////////////////////////////////////////////////////
1971 // //
1972 // //
1973 // //
1974 ///////////////////////////////////////////////////////////
1975
1976 //---------------------------------------------------------
1977