SAGA API Version 9.14
Loading...
Searching...
No Matches
map_shapes.cpp
Go to the documentation of this file.
1
3// //
4// SAGA //
5// //
6// System for Automated Geoscientific Analyses //
7// //
8// Application Programming Interface //
9// //
10// Library: SAGA_API //
11// //
12//-------------------------------------------------------//
13// //
14// map_shapes.cpp //
15// //
16// Copyright (C) 2026 by //
17// Olaf Conrad //
18// //
19//-------------------------------------------------------//
20// //
21// This file is part of 'SAGA - System for Automated //
22// Geoscientific Analyses'. SAGA is free software; you //
23// can redistribute it and/or modify it under the terms //
24// of the GNU General Public License as published by the //
25// Free Software Foundation, either version 2 of the //
26// License, or (at your option) any later version. //
27// //
28// SAGA is distributed in the hope that it will be //
29// useful, but WITHOUT ANY WARRANTY; without even the //
30// implied warranty of MERCHANTABILITY or FITNESS FOR A //
31// PARTICULAR PURPOSE. See the GNU General Public //
32// License for more details. //
33// //
34// You should have received a copy of the GNU General //
35// Public License along with this program; if not, see //
36// <http://www.gnu.org/licenses/>. //
37// //
38//-------------------------------------------------------//
39// //
40// e-mail: oconrad@saga-gis.org //
41// //
42// contact: Olaf Conrad //
43// Institute of Geography //
44// University of Hamburg //
45// Germany //
46// //
48
49//---------------------------------------------------------
50#include "../dc_helper.h"
51
52#include "map_symbology.h"
53
54#include "map_layer.h"
55
56
58// //
59// //
60// //
62
63//---------------------------------------------------------
71
72
74// //
76
77//---------------------------------------------------------
79{
81
82 //-----------------------------------------------------
83 // Display...
84
85 Parameters.Add_Choice("NODE_DISPLAY" , "DRAWING_ORDER" , _TL("Drawing Order" ), _TL(""), CSG_String::Format("%s|%s",
86 _TL("data set"),
87 _TL("attribute sorting"))
88 );
89
90 //-----------------------------------------------------
91 // Classification...
92
93 Parameters.Add_Bool ("NODE_COLORS" , "NODATA_SHOW" , _TL("Show No-Data" ), _TL(""), true);
94 Parameters.Add_Color ("NODATA_SHOW" , "NODATA_COLOR" , _TL("Color" ), _TL(""), SG_COLOR_GREY_LIGHT);
95
96 //-----------------------------------------------------
97 // Label...
98
99 Parameters.Add_Choice("NODE_LABEL" , "LABEL_FIELD" , _TL("Field" ), _TL(""), CSG_String::Format("<%s>", _TL("default")));
100 Parameters.Add_Font ("LABEL_FIELD" , "LABEL_FIELD_FONT" , _TL("Font" ), _TL(""));
101
102 #ifndef _SAGA_MSW
103 Parameters.Add_Color ("LABEL_FIELD_FONT" , "LABEL_COLOR" , _TL("Color" ), _TL(""), SG_Get_Color(SG_System_Get_Color_Foreground()));
104 #endif
105
106 Parameters.Add_Choice("LABEL_FIELD" , "LABEL_FIELD_EFFECT" , _TL("Boundary Effect" ), _TL(""), CSG_String::Format("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s",
107 _TL("none"),
108 _TL("full frame"),
109 _TL("top"),
110 _TL("top left"),
111 _TL("left"),
112 _TL("bottom left"),
113 _TL("bottom"),
114 _TL("bottom right"),
115 _TL("right"),
116 _TL("top right")), 1
117 );
118
119 Parameters.Add_Color ("LABEL_FIELD_EFFECT", "LABEL_FIELD_EFFECT_COLOR", _TL("Color" ), _TL(""), SG_Get_Color(SG_System_Get_Color_Background()));
120 Parameters.Add_Int ("LABEL_FIELD_EFFECT", "LABEL_FIELD_EFFECT_SIZE" , _TL("Size" ), _TL(""), 1, 1, true);
121 Parameters.Add_Choice("LABEL_FIELD" , "LABEL_FIELD_PREC" , _TL("Numerical Precision"), _TL(""), CSG_String::Format("%s|%s|%s",
122 _TL("fit to value"),
123 _TL("standard"),
124 SG_T("0|0.1|0.12|0.123|0.1234|0.12345|0.1234567|0.12345678|0.123456789|0.1234567890|0.12345678901|0.123456789012|0.1234567890123|0.12345678901234|0.123456789012345|0.1234567890123456|0.12345678901234567|0.123456789012345678|0.1234567890123456789|0.12345678901234567890")), 0
125 );
126
127 Parameters.Add_Choice("LABEL_FIELD" , "LABEL_FIELD_SIZE_TYPE" , _TL("Size relates to..." ), _TL(""), CSG_String::Format("%s|%s|",
128 _TL("Screen"),
129 _TL("Map Units")), 0
130 );
131
132 Parameters.Add_Choice("LABEL_FIELD" , "LABEL_FIELD_SIZEBY" , _TL("Size by Attribute" ), _TL(""), CSG_String::Format("<%s>", _TL("<default>")));
133
134 Parameters.Add_Double("LABEL_FIELD_SIZEBY", "LABEL_FIELD_SIZE" , _TL("Default Size" ), _TL(""), 100., 0., true);
135
136 //-----------------------------------------------------
137 // Charts...
138
139 Parameters.Add_Bool ("NODE_CHART", "CHART_SHOW" , _TL("Show" ), _TL(""), false);
140 Parameters.Add_Parameters("CHART_SHOW", "CHART_SETTINGS", _TL("Settings"), _TL(""));
141
142 //-----------------------------------------------------
143 return( true );
144}
145
146
148// //
150
151//---------------------------------------------------------
152bool CSG_Map_Shapes::Parameter_Changed(CSG_Parameters &Parameters, CSG_Parameter &Parameter, int Flags)
153{
154 //-----------------------------------------------------
155 if( Flags & PARAMETER_CHECK_VALUES )
156 {
157 // ...
158 }
159
160 //-----------------------------------------------------
161 if( Flags & PARAMETER_CHECK_ENABLE )
162 {
163 if( Parameters.Cmp_Identifier("CHART_SETTINGS") )
164 {
165 if( Parameter.Cmp_Identifier("SIZE_FIELD") )
166 {
167 int Field = Get_Fields_Choice(Parameter);
168
169 Parameters.Set_Enabled("SIZE_RANGE" , Field >= 0);
170 Parameters.Set_Enabled("SIZE_DEFAULT", Field < 0);
171 }
172 else
173 {
174 CSG_String ID(Parameter.Get_Identifier());
175
176 if( ID.Find("FIELD_") == 0 )
177 {
178 ID.Replace("FIELD_", "COLOR_");
179
180 Parameters.Set_Enabled(ID, Parameter.asBool());
181 }
182 }
183
184 return( 1 );
185 }
186
187 //-------------------------------------------------
188 if( Parameter.Cmp_Identifier("COLOR_SYMBOLS") )
189 {
190 Parameters.Set_Enabled("NODATA_SHOW" , Parameter.asInt() > 0); // not 'single symbol'
191 }
192
193 if( Parameter.Cmp_Identifier("NODATA_SHOW") )
194 {
195 Parameters.Set_Enabled("NODATA_COLOR" , Parameter.asBool());
196 }
197
198 if( Parameter.Cmp_Identifier("OUTLINE") )
199 {
200 Parameters.Set_Enabled("OUTLINE_COLOR", Parameter.asBool());
201 Parameters.Set_Enabled("OUTLINE_SIZE" , Parameter.asBool());
202 }
203
204 if( Parameter.Cmp_Identifier("LABEL_FIELD") )
205 {
206 Parameter.Set_Children_Enabled(Get_Fields_Choice(Parameter) >= 0);
207 }
208
209 if( Parameter.Cmp_Identifier("LABEL_FIELD_SIZE_TYPE")
210 || Parameter.Cmp_Identifier("LABEL_FIELD_SIZEBY" ) )
211 {
212 bool Value = Parameters["LABEL_FIELD_SIZE_TYPE"].asInt() != 0 || Get_Fields_Choice(Parameters["LABEL_FIELD_SIZEBY"]) >= 0;
213
214 Parameters.Set_Enabled("LABEL_FIELD_SIZE", Value);
215 }
216
217 if( Parameter.Cmp_Identifier("LABEL_FIELD_EFFECT") )
218 {
219 Parameter.Set_Children_Enabled(Parameter.asInt() != 0);
220 }
221
222 if( Parameter.Cmp_Identifier("CHART_SHOW") )
223 {
224 Parameters.Set_Enabled("CHART_SETTINGS", Parameter.asBool());
225 }
226 }
227
228 //-----------------------------------------------------
229 return( CSG_Map_Layer::Parameter_Changed(Parameters, Parameter, Flags) );
230}
231
232
234// //
236
237//---------------------------------------------------------
239{
241
242 //-----------------------------------------------------
243 Set_Fields_Choice(m_Parameters["CLASSIFIED_FIELD" ], false, false, false);
244 Set_Fields_Choice(m_Parameters["CLASSIFIED_NORMALIZE"], true, true, true);
245 Set_Fields_Choice(m_Parameters["STRETCH_FIELD" ], true, false, false);
246 Set_Fields_Choice(m_Parameters["STRETCH_NORMALIZE" ], true, true, true);
247 Set_Fields_Choice(m_Parameters["LABEL_FIELD" ], false, true, true);
248 Set_Fields_Choice(m_Parameters["LABEL_FIELD_SIZEBY" ], true, true, true);
249
250 m_Chart.Set_Options(m_pObject->asShapes(), *m_Parameters["CHART_SETTINGS"].asParameters());
251
252 //-----------------------------------------------------
253 return( true );
254}
255
256//---------------------------------------------------------
258{
260
261 //-----------------------------------------------------
262 switch( m_Parameters["COLOR_SYMBOLS"].asInt() )
263 {
264 default: // CSG_Map_Symbology::SINGLE
265 m_Stretch.Value = -1;
266 m_Stretch.Normal = -1;
267 break;
268
269 case 1: // CSG_Map_Symbology::CLASSIFIED
270 m_Stretch.Value = Get_Fields_Choice(m_Parameters["CLASSIFIED_FIELD" ]);
271 m_Stretch.Normal = Get_Fields_Choice(m_Parameters["CLASSIFIED_NORMALIZE"]);
272 m_Stretch.Scale = 1.;
273 break;
274
275 case 2: // CSG_Map_Symbology::DISCRETE
276 case 3: // CSG_Map_Symbology::GRADUATED
277 m_Stretch.Value = Get_Fields_Choice(m_Parameters["STRETCH_FIELD" ]);
278 m_Stretch.Normal = Get_Fields_Choice(m_Parameters["STRETCH_NORMALIZE" ]);
279 m_Stretch.Scale = m_Parameters["STRETCH_NORMALIZE_FORMAT"].asInt() == 0 ? 1. : 100.;
280 break;
281 }
282
283 if( m_Stretch.Value < 0 )
284 {
286 }
287 else if( m_Parameters["COLOR_SYMBOLS"].asInt() == 2 || m_Parameters["COLOR_SYMBOLS"].asInt() == 3 ) // discrete/graduated
288 {
290
291 m_pSymbology->Set_Stretch(
292 m_Parameters["STRETCH_RANGE.MIN" ].asDouble(),
293 m_Parameters["STRETCH_RANGE.MAX" ].asDouble(),
294 m_Parameters["STRETCH_INTERVALS" ].asInt (),
295 m_Parameters["STRETCH_INTERVALS_LOG" ].asDouble()
296 );
297
298 m_pSymbology->Update();
299 }
300
301 //-----------------------------------------------------
302 m_bNoData = m_Parameters["NODATA_SHOW"].asBool();
303
304 //-----------------------------------------------------
305 m_Label.Field = Get_Fields_Choice(m_Parameters["LABEL_FIELD"]);
306
307 m_Label.Effect_Color = m_Parameters["LABEL_FIELD_EFFECT_COLOR"].asColor();
308 m_Label.Effect_Size = m_Parameters["LABEL_FIELD_EFFECT_SIZE" ].asInt ();
309 m_Label.Precision = m_Parameters["LABEL_FIELD_PREC" ].asInt ();
310
311 switch( m_Label.Precision )
312 {
313 case 0: m_Label.Precision = -m_Parameters["TABLE_FLT_DECIMALS"].asInt(); break;
314 case 1: m_Label.Precision = -99; break;
315 default: m_Label.Precision -= 2; break;
316 }
317
318 switch( m_Parameters["LABEL_FIELD_EFFECT"].asInt() )
319 {
320 default: m_Label.Effect = SG_DC_TEXTEFFECT_NONE ; break;
321 case 1: m_Label.Effect = SG_DC_TEXTEFFECT_FRAME ; break;
322 case 2: m_Label.Effect = SG_DC_TEXTEFFECT_TOP ; break;
323 case 3: m_Label.Effect = SG_DC_TEXTEFFECT_TOPLEFT ; break;
324 case 4: m_Label.Effect = SG_DC_TEXTEFFECT_LEFT ; break;
325 case 5: m_Label.Effect = SG_DC_TEXTEFFECT_BOTTOMLEFT ; break;
326 case 6: m_Label.Effect = SG_DC_TEXTEFFECT_BOTTOM ; break;
327 case 7: m_Label.Effect = SG_DC_TEXTEFFECT_BOTTOMRIGHT; break;
328 case 8: m_Label.Effect = SG_DC_TEXTEFFECT_RIGHT ; break;
329 case 9: m_Label.Effect = SG_DC_TEXTEFFECT_TOPRIGHT ; break;
330 }
331
332 //-----------------------------------------------------
333 m_Chart.Get_Options(m_pObject->asShapes(), *m_Parameters["CHART_SETTINGS"].asParameters());
334
335 //-----------------------------------------------------
336 return( true );
337}
338
339
341// //
343
344//---------------------------------------------------------
346{
347 return( !m_DrawOrder ? m_pObject->asShapes()->Get_Shape(i) : m_pObject->asShapes()->Get_Shape_byIndex(i) );
348}
349
350
352// //
354
355//---------------------------------------------------------
356void CSG_Map_Shapes::On_Draw(CSG_Map_DC &dc_Map, int Flags)
357{
358 if( Get_Extent().Intersects(dc_Map.rWorld()) == INTERSECTION_None )
359 {
360 return;
361 }
362
363 //-----------------------------------------------------
364 if( (Flags & LAYER_DRAW_FLAG_THUMBNAIL) != 0 )
365 {
367
368 Draw_Thumbnails(dc_Map, 0);
369
370 return;
371 }
372
373 //-----------------------------------------------------
374 if( m_Parameters["TRANSPARENCY"].asDouble() > 0. )
375 {
376 dc_Map.Draw_Layer_Begin();
377 }
378
379 m_DrawOrder = m_Parameters["DRAWING_ORDER"].asInt();
380
381 Draw_Initialize(dc_Map, Flags);
382
383 //-----------------------------------------------------
384 for(sLong i=0; i<m_pObject->asShapes()->Get_Count(); i++)
385 {
386 if( (Flags & LAYER_DRAW_FLAG_NOEDITS) != 0 || !Get_Shape(i)->is_Selected() )
387 {
388 _Draw_Shape(dc_Map, Get_Shape(i));
389 }
390 }
391
392 if( m_Parameters["CHART_SHOW"].asBool() && m_Chart.is_Valid() )
393 {
394 for(sLong i=0; i<m_pObject->asShapes()->Get_Count(); i++)
395 {
396 if( (Flags & LAYER_DRAW_FLAG_NOEDITS) != 0 || !Get_Shape(i)->is_Selected() )
397 {
398 m_Chart.Draw(dc_Map, Get_Shape(i));
399 }
400 }
401 }
402
403 //-----------------------------------------------------
404 if( (Flags & LAYER_DRAW_FLAG_NOLABELS) == 0 && m_Label.Field >= 0 ) // Labels
405 {
406 int iSize = Get_Fields_Choice(m_Parameters["LABEL_FIELD_SIZEBY"]);
407 double dSize = m_Parameters["LABEL_FIELD_SIZE_TYPE"].asInt() == 1
408 ? dc_Map.World2DC() * m_Parameters["LABEL_FIELD_SIZE"].asDouble() : 1.;
409
410 dc_Map.SetFont(SG_Get_wxFont(m_Parameters("LABEL_FIELD_FONT")));
411 dc_Map.Get_DC().SetTextForeground(m_Parameters[m_Parameters("LABEL_COLOR") ? "LABEL_COLOR" : "LABEL_FIELD_FONT"].asColor());
412
413 if( iSize >= 0 && iSize < m_pObject->asShapes()->Get_Field_Count() ) // size by attribute
414 {
415 for(sLong i=0; i<m_pObject->asShapes()->Get_Count(); i++)
416 {
417 int Size = (int)(0.5 + dSize * Get_Shape(i)->asDouble(iSize));
418
419 if( Size > 0 )
420 {
421 _Draw_Label(dc_Map, Get_Shape(i), Size);
422 }
423 }
424 }
425 else // one size fits all
426 {
427 int Size = m_Parameters["LABEL_FIELD_SIZE_TYPE"].asInt() == 1 ? (int)(0.5 + dSize) : dc_Map.Get_DC().GetFont().GetPointSize();
428
429 if( Size > 0 )
430 {
431 for(sLong i=0; i<m_pObject->asShapes()->Get_Count(); i++)
432 {
433 _Draw_Label(dc_Map, Get_Shape(i), Size);
434 }
435 }
436 }
437 }
438
439 //-----------------------------------------------------
440 if( m_Parameters["TRANSPARENCY"].asDouble() > 0. ) // Transparency ?
441 {
442 dc_Map.Draw_Layer_End(m_Parameters["TRANSPARENCY"].asDouble() / 100.);
443 }
444}
445
446//---------------------------------------------------------
448{
450
451 if( Limit < 1 || m_pObject->asShapes()->Get_Count() <= Limit )
452 {
453 for(sLong i=0; i<m_pObject->asShapes()->Get_Count(); i++)
454 {
456 }
457 }
458 else
459 {
460 double d = m_pObject->asShapes()->Get_Count() / (double)Limit;
461
462 for(double i=0; (sLong)i<m_pObject->asShapes()->Get_Count(); i+=d)
463 {
465 }
466 }
467}
468
469//---------------------------------------------------------
470void CSG_Map_Shapes::_Draw_Shape(CSG_Map_DC &dc_Map, CSG_Shape *pShape, int Flags)
471{
472 if( pShape && dc_Map.rWorld().Intersects(pShape->Get_Extent()) != INTERSECTION_None )
473 {
474 Draw_Shape(dc_Map, pShape, Flags);
475
476 if( m_bVertices > 0 )
477 {
478 wxPen oldPen (dc_Map.Get_DC().GetPen ()); dc_Map.SetPen (*wxBLACK_PEN );
479 wxBrush oldBrush(dc_Map.Get_DC().GetBrush()); dc_Map.SetBrush(*wxWHITE_BRUSH);
480
481 bool bLabel = m_bVertices == 2 && ((Flags & LAYER_DRAW_FLAG_SELECTION) || m_pObject->asShapes()->Get_Selection_Count() == 0);
482
483 for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
484 {
485 for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
486 {
487 TSG_Point_Int A = dc_Map.World2DC(pShape->Get_Point(iPoint, iPart));
488
489 dc_Map.DrawCircle(A.x, A.y, 2);
490
491 if( bLabel )
492 {
493 dc_Map.DrawText(SG_DC_TEXTALIGN_TOPLEFT, A.x, A.y, wxString::Format("%d", iPoint + 1));
494 }
495 }
496 }
497
498 dc_Map.SetPen (oldPen );
499 dc_Map.SetBrush(oldBrush);
500 }
501 }
502}
503
504//---------------------------------------------------------
505void CSG_Map_Shapes::_Draw_Label(CSG_Map_DC &dc_Map, CSG_Shape *pShape, int PointSize)
506{
507 if( pShape && dc_Map.rWorld().Intersects(pShape->Get_Extent()) != INTERSECTION_None )
508 {
509 wxString Label(pShape->asString(m_Label.Field, m_Label.Precision)); Label.Trim(true).Trim(false);
510
511 if( !Label.IsEmpty() )
512 {
513 if( PointSize > 0 && PointSize != dc_Map.Get_DC().GetFont().GetPointSize() )
514 {
515 wxFont Font(dc_Map.Get_DC().GetFont());
516
517 Font.SetPointSize(PointSize);
518
519 dc_Map.SetFont(Font);
520 }
521
522 Draw_Label(dc_Map, pShape, Label);
523 }
524 }
525}
526
527
529// //
531
532//---------------------------------------------------------
533CSG_Parameter * CSG_Map_Shapes::BrushList_Add(CSG_Parameters &Parameters, const CSG_String &ParentID, const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description) const
534{
535 return( Parameters.Add_Choice(ParentID, Identifier, Name, Description,
536 CSG_String::Format("%s|%s|%s|%s|%s|%s|%s|%s|",
537 _TL("Opaque" ),
538 _TL("Transparent" ),
539 _TL("Backward Diagonal"),
540 _TL("Cross Diagonal" ),
541 _TL("Forward Diagonal" ),
542 _TL("Cross" ),
543 _TL("Horizontal" ),
544 _TL("Vertical" )
545 ), 0)
546 );
547}
548
549//---------------------------------------------------------
550wxBrushStyle CSG_Map_Shapes::BrushList_Get_Style(const CSG_String &Identifier)
551{
552 switch( m_Parameters[Identifier].asInt() )
553 {
554 default: return( wxBRUSHSTYLE_SOLID );
555 case 1: return( wxBRUSHSTYLE_TRANSPARENT );
556 case 2: return( wxBRUSHSTYLE_BDIAGONAL_HATCH );
557 case 3: return( wxBRUSHSTYLE_CROSSDIAG_HATCH );
558 case 4: return( wxBRUSHSTYLE_FDIAGONAL_HATCH );
559 case 5: return( wxBRUSHSTYLE_CROSS_HATCH );
560 case 6: return( wxBRUSHSTYLE_HORIZONTAL_HATCH);
561 case 7: return( wxBRUSHSTYLE_VERTICAL_HATCH );
562 }
563}
564
565//---------------------------------------------------------
566CSG_Parameter * CSG_Map_Shapes::PenList_Add(CSG_Parameters &Parameters, const CSG_String &ParentID, const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description) const
567{
568 return( Parameters.Add_Choice(ParentID, Identifier, Name, Description,
569 CSG_String::Format("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|",
570 _TL("Solid style"),
571 _TL("Dotted style"),
572 _TL("Long dashed style"),
573 _TL("Short dashed style"),
574 _TL("Dot and dash style"),
575 _TL("Backward diagonal hatch"),
576 _TL("Cross-diagonal hatch"),
577 _TL("Forward diagonal hatch"),
578 _TL("Cross hatch"),
579 _TL("Horizontal hatch"),
580 _TL("Vertical hatch")
581 // _TL("Use the stipple bitmap")
582 // _TL("Use the user dashes")
583 // _TL("No pen is used")
584 ), 0)
585 );
586}
587
588//---------------------------------------------------------
590{
591 switch( m_Parameters[Identifier].asInt() )
592 {
593 default: return( wxPENSTYLE_SOLID ); // Solid style.
594 case 1: return( wxPENSTYLE_DOT ); // Dotted style.
595 case 2: return( wxPENSTYLE_LONG_DASH ); // Long dashed style.
596 case 3: return( wxPENSTYLE_SHORT_DASH ); // Short dashed style.
597 case 4: return( wxPENSTYLE_DOT_DASH ); // Dot and dash style.
598 case 5: return( wxPENSTYLE_BDIAGONAL_HATCH ); // Backward diagonal hatch.
599 case 6: return( wxPENSTYLE_CROSSDIAG_HATCH ); // Cross-diagonal hatch.
600 case 7: return( wxPENSTYLE_FDIAGONAL_HATCH ); // Forward diagonal hatch.
601 case 8: return( wxPENSTYLE_CROSS_HATCH ); // Cross hatch.
602 case 9: return( wxPENSTYLE_HORIZONTAL_HATCH ); // Horizontal hatch.
603 case 10: return( wxPENSTYLE_VERTICAL_HATCH ); // Vertical hatch.
604// case 11: return( wxPENSTYLE_STIPPLE ); // Use the stipple bitmap.
605// case 12: return( wxPENSTYLE_USER_DASH ); // Use the user dashes: see wxPen::SetDashes.
606// case 13: return( wxPENSTYLE_TRANSPARENT ); // No pen is used.
607 }
608}
609
610
612// //
614
615//---------------------------------------------------------
617{
618 if( m_pSymbology->Get_Mode() == CSG_Map_Symbology::SINGLE )
619 {
620 Color = m_pSymbology->Get_Single_Color();
621
622 return( true );
623 }
624
625 //-----------------------------------------------------
626 if( m_Stretch.Value >= 0 )
627 {
628 if( m_pSymbology->Get_Mode() == CSG_Map_Symbology::CLASSIFIED && SG_Data_Type_is_Numeric(m_pObject->asShapes()->Get_Field_Type(m_Stretch.Value)) == false )
629 {
630 if( m_pSymbology->Get_Class_Color_byValue(pShape->asString(m_Stretch.Value), Color) )
631 {
632 return( true );
633 }
634 }
635 else
636 {
637 double Value;
638
639 if( CSG_Map_Layer::Get_Field_Value(pShape->Get_Index(), m_Stretch.Value, m_Stretch.Normal, m_Stretch.Scale, Value)
640 && m_pSymbology->Get_Class_Color_byValue(Value, Color) )
641 {
642 return( true );
643 }
644 }
645 }
646
647 //-----------------------------------------------------
648 Color = m_pSymbology->Get_NoData_Color();
649
650 return( false );
651}
652
653
655// //
656// //
657// //
659
660//---------------------------------------------------------
661bool CSG_Map_Shapes::CChart::Set_Options(const CSG_Shapes *pShapes, CSG_Parameters &Parameters)
662{
663 Parameters.Del_Parameters(); m_Fields.Clear();
664
665 CSG_Array_Int Fields;
666
667 for(int i=0; i<pShapes->Get_Field_Count(); i++)
668 {
669 if( SG_Data_Type_is_Numeric(pShapes->Get_Field_Type(i)) )
670 {
671 Fields += i;
672 }
673 }
674
675 if( Fields.Get_Size() < 1 )
676 {
677 return( false );
678 }
679
680 //-----------------------------------------------------
681 Parameters.Set_Callback(false);
682
683 Parameters.Add_Choice("" , "TYPE" , _TL("Chart Type" ), _TL(""), CSG_String::Format("%s|%s", _TL("bar"), _TL("pie")), 0);
684 Parameters.Add_Bool ("TYPE" , "OUTLINE" , _TL("Outline" ), _TL(""), false );
685
686 Parameters.Add_Choice("" , "SIZE_FIELD" , _TL("Size Field" ), _TL(""), CSG_String::Format("%s|", _TL("<not set>")), 0);
687 Parameters.Add_Range ("SIZE_FIELD", "SIZE_RANGE" , _TL("Size Range" ), _TL(""), 5., 25., 0., true);
688 Parameters.Add_Double("SIZE_FIELD", "SIZE_DEFAULT", _TL("Default Size" ), _TL(""), 15., 0., true);
689 Parameters.Add_Choice("SIZE_FIELD", "SIZE_TYPE" , _TL("Size relates to..."), _TL(""), CSG_String::Format("%s|%s|", _TL("Screen"), _TL("Map Units")), 0);
690
691 Parameters.Add_Node ("", "FIELDS", _TL("Fields"), _TL(""));
692
693 CSG_String Choices; CSG_Colors Colors((int)Fields.Get_Size());
694
695 for(int i=0; i<(int)Fields.Get_Size(); i++)
696 {
697 Choices += CSG_String::Format("{%d}%s|", Fields[i], pShapes->Get_Field_Name(Fields[i]));
698
699 CSG_String ID; ID.Printf("FIELD_%d", Fields[i]);
700
701 Parameters.Add_Bool("FIELDS", ID, pShapes->Get_Field_Name(Fields[i]), "", false);
702 Parameters.Add_Color(ID, CSG_String::Format("COLOR_%d", Fields[i]), "", "", Colors.Get_Color(i));
703 }
704
705 Choices += CSG_String::Format("{%d}%s|", -1, _TL("<none>"));
706
707 Parameters["SIZE_FIELD"].asChoice()->Set_Items(Choices);
708 Parameters["SIZE_FIELD"].Set_Value((int)Fields.Get_Size());
709
710 Parameters.Set_Callback(true);
711
712 return( true );
713}
714
715//---------------------------------------------------------
716bool CSG_Map_Shapes::CChart::Get_Options(const CSG_Shapes *pShapes, const CSG_Parameters &Parameters)
717{
718 m_Fields.Clear(); m_Size.Field = -1;
719
720 if( Parameters("FIELDS") )
721 {
722 for(int i=0; i<pShapes->Get_Field_Count(); i++)
723 {
724 CSG_Parameter *pParameter = Parameters(CSG_String::Format("FIELD_%d", i));
725
726 if( pParameter )
727 {
728 if( pParameter->asBool() && (pParameter = Parameters(CSG_String::Format("COLOR_%d", i))) != NULL )
729 {
730 m_Fields.Add(i, pParameter->asColor());
731 }
732 }
733 }
734
735 switch( Parameters["TYPE"].asInt() )
736 {
737 default: m_Type = Parameters["OUTLINE"].asBool() ? 0 : 1; break; // bar
738 case 1: m_Type = Parameters["OUTLINE"].asBool() ? 2 : 3; break; // pie
739 }
740
741 m_Size.Field = Get_Fields_Choice(Parameters["SIZE_FIELD"]);
742 m_Size.Size = m_Size.Field < 0
743 ? Parameters["SIZE_DEFAULT" ].asDouble()
744 : Parameters["SIZE_RANGE.MIN"].asDouble();
745 m_Size.Range = Parameters["SIZE_RANGE.MAX"].asDouble() - m_Size.Size;
746 m_Size.Type = Parameters["SIZE_TYPE" ].asInt ();
747
748 return( true );
749 }
750
751 return( false );
752}
753
754//---------------------------------------------------------
755void CSG_Map_Shapes::CChart::Draw(CSG_Map_DC &dc_Map, CSG_Shape *pShape)
756{
757 if( dc_Map.rWorld().Intersects(pShape->Get_Extent()) != INTERSECTION_None )
758 {
759 TSG_Point_Int point; double scale = m_Size.Size;
760
761 if( m_Size.Field >= 0 )
762 {
763 double range = pShape->Get_Table()->Get_Range(m_Size.Field);
764
765 if( range > 0. )
766 {
767 scale += m_Size.Range * ((pShape->asDouble(m_Size.Field) - pShape->Get_Table()->Get_Minimum(m_Size.Field)) / range);
768 }
769 }
770
771 int size = (int)(scale * (m_Size.Type == 1 ? dc_Map.World2DC() : dc_Map.Scale()));
772
773 switch( pShape->Get_Type() )
774 {
775 default : point = dc_Map.World2DC(pShape->Get_Extent().Get_Center() ); break;
776 case SHAPE_TYPE_Polygon: point = dc_Map.World2DC(((CSG_Shape_Polygon *)pShape)->Get_Centroid()); break;
777 }
778
779 dc_Map.SetPen(*wxBLACK_PEN);
780
781 switch( m_Type )
782 {
783 default: _Draw_Bar(dc_Map, pShape, true, point.x, point.y, (int)(0.8 * size), size); break; // bar outlined
784 case 1: _Draw_Bar(dc_Map, pShape, false, point.x, point.y, (int)(0.8 * size), size); break; // bar
785 case 2: _Draw_Pie(dc_Map, pShape, true, point.x, point.y, (int)(1.0 * size) ); break; // pie outlined
786 case 3: _Draw_Pie(dc_Map, pShape, false, point.x, point.y, (int)(1.0 * size) ); break; // pie
787 }
788 }
789}
790
791//---------------------------------------------------------
792void CSG_Map_Shapes::CChart::_Draw_Pie(CSG_Map_DC &dc_Map, CSG_Table_Record *pRecord, bool bOutline, int x, int y, int size)
793{
794 double sum = 0.;
795
796 for(int i=0; i<m_Fields.Get_Count(); i++)
797 {
798 sum += fabs(pRecord->asDouble(m_Fields[i].x));
799 }
800
801 if( sum > 0. )
802 {
803 sum = M_PI_360 / sum; double d = 0.;
804
805 for(int i=0, jx=x, jy=y-size; i<m_Fields.Get_Count(); i++)
806 {
807 if( !bOutline )
808 {
809 dc_Map.SetPen(wxPen(SG_Get_wxColor(m_Fields[i].y)));
810 }
811
812 dc_Map.SetBrush(wxBrush(SG_Get_wxColor(m_Fields[i].y)));
813
814 d += sum * fabs(pRecord->asDouble(m_Fields[i].x));
815
816 int ix = jx; jx = x - (int)(size * sin(-d));
817 int iy = jy; jy = y - (int)(size * cos(-d));
818
819 dc_Map.DrawArc(jx, jy, ix, iy, x, y);
820 }
821 }
822}
823
824//---------------------------------------------------------
825void CSG_Map_Shapes::CChart::_Draw_Bar(CSG_Map_DC &dc_Map, CSG_Table_Record *pRecord, bool bOutline, int x, int y, int sx, int sy)
826{
827 double max = fabs(pRecord->asDouble(m_Fields[0].x));
828
829 for(int i=1; i<m_Fields.Get_Count(); i++)
830 {
831 double d = fabs(pRecord->asDouble(m_Fields[i].x));
832
833 if( max < d )
834 {
835 max = d;
836 }
837 }
838
839 if( max != 0. )
840 {
841 y += sy / 2; max = sy / max; double dx = sx / (double)m_Fields.Get_Count(), ix = x - sx / 2.;
842
843 for(int i=0; i<m_Fields.Get_Count(); i++, ix+=dx)
844 {
845 if( !bOutline )
846 {
847 dc_Map.SetPen(wxPen(SG_Get_wxColor(m_Fields[i].y)));
848 }
849
850 dc_Map.SetBrush(wxBrush(SG_Get_wxColor(m_Fields[i].y)));
851
852 double dy = -pRecord->asDouble(m_Fields[i].x) * max;
853
854 dc_Map.DrawRectangle((int)ix, y, (int)dx, (int)dy);
855 }
856
857 if( !bOutline )
858 {
859 dc_Map.SetPen(*wxBLACK_PEN); dc_Map.DrawLine(x - sx / 2, y, x + sx / 2, y);
860 }
861 }
862}
863
864
866// //
867// //
868// //
870
871//---------------------------------------------------------
bool SG_Data_Type_is_Numeric(TSG_Data_Type Type)
Definition api_core.cpp:199
#define SG_COLOR_GREY_LIGHT
Definition api_core.h:1356
signed long long sLong
Definition api_core.h:158
#define SG_T(s)
Definition api_core.h:537
#define _TL(s)
Definition api_core.h:1619
sLong Get_Size(void) const
Definition api_core.h:436
class CSG_Shapes * asShapes(bool bPolymorph=false) const
void SetBrush(const wxBrush &Brush)
Definition map_dc.cpp:495
bool Draw_Layer_Begin(void)
Definition map_dc.cpp:271
void SetPen(const wxPen &Pen)
Definition map_dc.cpp:482
void DrawArc(int xStart, int yStart, int xEnd, int yEnd, int xc, int yc)
Definition map_dc.cpp:567
void DrawCircle(int x, int y, int radius)
Definition map_dc.cpp:556
const CSG_Rect & rWorld(void) const
Definition map_dc.h:124
bool Draw_Layer_End(double Transparency=0.)
Definition map_dc.cpp:290
void DrawLine(int x1, int y1, int x2, int y2)
Definition map_dc.cpp:524
wxMemoryDC & Get_DC(void)
Definition map_dc.h:96
const double & Scale(void) const
Definition map_dc.h:122
const double & World2DC(void) const
Definition map_dc.h:131
void SetFont(const wxFont &Font)
Definition map_dc.cpp:471
void DrawText(int Align, int x, int y, const wxString &Text)
Definition map_dc.cpp:616
void DrawRectangle(int x1, int y1, int width, int height)
Definition map_dc.cpp:535
virtual bool Parameters_Changed(void)
bool Set_Fields_Choice(CSG_Parameter &Choice, bool bNumeric, bool bAddNone, bool bSelectNone=false)
bool Get_Field_Value(sLong Index, int Field, int Normalize, double Scale, wxString &Value) const
static int Get_Fields_Choice(CSG_Parameter &Choice)
virtual bool DataObject_Changed(void)
TSG_Data_Object_Type m_Type
Definition map_layer.h:147
virtual bool Parameter_Changed(CSG_Parameters &Parameters, CSG_Parameter &Parameter, int Flags)
CSG_Data_Object * m_pObject
Definition map_layer.h:151
bool Set_Stretch(CSG_Parameters &Parameters, CSG_Data_Object *pObject=NULL, const CSG_String &Suffix="")
CSG_Rect Get_Extent(void) const
CSG_Parameters m_Parameters
Definition map_layer.h:149
class CSG_Map_Symbology * m_pSymbology
Definition map_layer.h:153
virtual bool Add_Parameters(CSG_Parameters &Parameters)
CSG_Map_Layer(void)
Definition map_layer.h:90
virtual bool Add_Parameters(CSG_Parameters &Parameters)
CSG_Parameter * BrushList_Add(CSG_Parameters &Parameters, const CSG_String &ParentID, const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description) const
virtual bool Parameter_Changed(CSG_Parameters &Parameters, CSG_Parameter &Parameter, int Flags)
virtual void On_Draw(CSG_Map_DC &dc_Map, int Flags)
virtual void Draw_Shape(CSG_Map_DC &dc_Map, CSG_Shape *pShape, int Flags=0)
Definition map_layer.h:654
wxBrushStyle BrushList_Get_Style(const CSG_String &Identifier)
bool Get_Class_Color(CSG_Shape *pShape, int &Color)
CSG_Shape * Get_Shape(sLong i)
class CSG_Map_Shapes::CLabel m_Label
virtual void Draw_Initialize(CSG_Map_DC &dc_Map, int Flags)
Definition map_layer.h:687
class CSG_Map_Shapes::CStretch m_Stretch
int PenList_Get_Style(const CSG_String &Identifier)
CSG_Parameter * PenList_Add(CSG_Parameters &Parameters, const CSG_String &ParentID, const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description) const
virtual void Draw_Label(CSG_Map_DC &dc_Map, CSG_Shape *pShape, const wxString &Label)
Definition map_layer.h:655
virtual bool Parameters_Changed(void)
virtual bool DataObject_Changed(void)
virtual void Draw_Thumbnails(CSG_Map_DC &dc_Map, int Limit)
const SG_Char * Get_Identifier(void) const
bool Set_Children_Enabled(bool bEnabled=true)
bool asBool(void) const
Definition parameters.h:286
bool Cmp_Identifier(const CSG_String &Identifier) const
long asColor(void) const
Definition parameters.h:288
int asInt(void) const
Definition parameters.h:287
bool Set_Callback(bool bActive=true)
CSG_Parameter * Add_Choice(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, const CSG_String &Items, int Default=0)
void Set_Enabled(bool bEnabled=true)
bool Del_Parameters(void)
CSG_Parameter * Add_Double(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, double Value=0.0, double Minimum=0.0, bool bMinimum=false, double Maximum=0.0, bool bMaximum=false)
CSG_Parameter * Add_Parameters(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description)
CSG_Parameter * Add_Int(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, int Value=0, int Minimum=0, bool bMinimum=false, int Maximum=0, bool bMaximum=false)
CSG_Parameter * Add_Node(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, bool bCollapsed=false)
CSG_Parameter * Add_Color(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, int Value=0)
CSG_Parameter * Add_Font(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, const SG_Char *pInit=NULL)
CSG_Parameter * Add_Bool(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, bool Value=false)
bool Cmp_Identifier(const CSG_String &Identifier) const
CSG_Parameter * Add_Range(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, double Range_Min=0.0, double Range_Max=0.0, double Minimum=0.0, bool bMinimum=false, double Maximum=0.0, bool bMaximum=false)
bool Clear(void)
Definition geo_tools.h:434
TSG_Intersection Intersects(const CSG_Rect &Rect) const
CSG_Point Get_Center(void) const
Definition geo_tools.h:519
virtual int Get_Point_Count(void) const =0
TSG_Shape_Type Get_Type(void) const
Definition shape.cpp:88
virtual int Get_Part_Count(void) const =0
virtual TSG_Point Get_Point(int iPoint=0) const =0
virtual const CSG_Rect & Get_Extent(void)=0
size_t Replace(const CSG_String &Old, const CSG_String &New, bool bReplaceAll=true)
static CSG_String Format(const char *Format,...)
int Find(char Character, bool fromEnd=false) const
int Printf(const char *Format,...)
sLong Get_Index(void) const
Definition table.h:136
double asDouble(int Field) const
class CSG_Table * Get_Table(void)
Definition table.h:135
const SG_Char * asString(int Field, int Decimals=-99) const
const SG_Char * Get_Field_Name(int Field) const
Definition table.h:372
double Get_Minimum(int Field) const
Definition table.h:391
int Get_Field_Count(void) const
Definition table.h:371
double Get_Range(int Field) const
Definition table.h:393
TSG_Data_Type Get_Field_Type(int Field) const
Definition table.h:373
@ SG_DATAOBJECT_TYPE_Shapes
Definition dataobject.h:121
wxColour SG_System_Get_Color_Foreground(int Mode)
wxColour SG_System_Get_Color_Background(int Mode)
wxColour SG_Get_wxColor(int Color)
Definition dc_helper.cpp:70
int SG_Get_Color(const wxColour &Color)
Definition dc_helper.cpp:64
wxFont SG_Get_wxFont(CSG_Parameter *pFont)
#define SG_DC_TEXTEFFECT_TOPRIGHT
Definition dc_helper.h:149
#define SG_DC_TEXTEFFECT_LEFT
Definition dc_helper.h:144
#define SG_DC_TEXTEFFECT_BOTTOM
Definition dc_helper.h:146
#define SG_DC_TEXTEFFECT_NONE
Definition dc_helper.h:141
#define SG_DC_TEXTEFFECT_BOTTOMRIGHT
Definition dc_helper.h:147
#define SG_DC_TEXTEFFECT_TOPLEFT
Definition dc_helper.h:143
#define SG_DC_TEXTEFFECT_BOTTOMLEFT
Definition dc_helper.h:145
#define SG_DC_TEXTALIGN_TOPLEFT
Definition dc_helper.h:131
#define SG_DC_TEXTEFFECT_RIGHT
Definition dc_helper.h:148
#define SG_DC_TEXTEFFECT_TOP
Definition dc_helper.h:142
#define SG_DC_TEXTEFFECT_FRAME
Definition dc_helper.h:150
#define A
struct SSG_Point_Int TSG_Point_Int
@ INTERSECTION_None
Definition geo_tools.h:102
#define LAYER_DRAW_FLAG_THUMBNAIL
Definition map_layer.h:74
#define LAYER_DRAW_FLAG_NOLABELS
Definition map_layer.h:78
#define LAYER_DRAW_FLAG_NOEDITS
Definition map_layer.h:77
#define LAYER_DRAW_FLAG_SELECTION
Definition map_layer.h:75
#define asDouble(i)
#define M_PI_360
Definition mat_tools.h:106
#define PARAMETER_CHECK_ENABLE
Definition parameters.h:191
#define PARAMETER_CHECK_VALUES
Definition parameters.h:190
@ SHAPE_TYPE_Polygon
Definition shapes.h:105