1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // parameter.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'. //
22 // //
23 // This library is free software; you can redistribute //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free //
26 // Software Foundation, either version 2.1 of the //
27 // License, or (at your option) any later version. //
28 // //
29 // This library is distributed in the hope that it will //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details. //
34 // //
35 // You should have received a copy of the GNU Lesser //
36 // General Public License along with this program; if //
37 // not, see <http://www.gnu.org/licenses/>. //
38 // //
39 //-------------------------------------------------------//
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Goettingen //
44 // Germany //
45 // //
46 // e-mail: oconrad@saga-gis.org //
47 // //
48 ///////////////////////////////////////////////////////////
49
50 //---------------------------------------------------------
51 #include "parameters.h"
52 #include "data_manager.h"
53 #include "tool.h"
54
55
56 ///////////////////////////////////////////////////////////
57 // //
58 // //
59 // //
60 ///////////////////////////////////////////////////////////
61
62 //---------------------------------------------------------
CSG_Parameter(CSG_Parameters * pParameters,CSG_Parameter * pParent,const CSG_String & Identifier,const CSG_String & Name,const CSG_String & Description,int Constraint)63 CSG_Parameter::CSG_Parameter(CSG_Parameters *pParameters, CSG_Parameter *pParent, const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description, int Constraint)
64 {
65 m_pParameters = pParameters;
66 m_pParent = pParent;
67 m_Identifier = Identifier;
68 m_Name = Name;
69 m_Description = Description;
70 m_Constraint = Constraint;
71
72 m_bEnabled = true;
73
74 //-----------------------------------------------------
75 m_nChildren = 0;
76 m_Children = NULL;
77
78 if( m_pParent )
79 {
80 m_pParent->_Add_Child(this);
81 }
82 }
83
84 //---------------------------------------------------------
~CSG_Parameter(void)85 CSG_Parameter::~CSG_Parameter(void)
86 {
87 if( m_Children )
88 {
89 SG_Free(m_Children);
90 }
91 }
92
93
94 ///////////////////////////////////////////////////////////
95 // //
96 ///////////////////////////////////////////////////////////
97
98 //---------------------------------------------------------
Get_Parameters(void) const99 CSG_Parameters * CSG_Parameter::Get_Parameters(void) const
100 {
101 return( m_pParameters );
102 }
103
104 //---------------------------------------------------------
Get_Parent(void) const105 CSG_Parameter * CSG_Parameter::Get_Parent(void) const
106 {
107 return( m_pParent );
108 }
109
110 //---------------------------------------------------------
Get_Manager(void) const111 CSG_Data_Manager * CSG_Parameter::Get_Manager(void) const
112 {
113 return( m_pParameters ? m_pParameters->Get_Manager() : NULL );
114 }
115
116
117 ///////////////////////////////////////////////////////////
118 // //
119 ///////////////////////////////////////////////////////////
120
121 //---------------------------------------------------------
Get_Type_Identifier(void) const122 CSG_String CSG_Parameter::Get_Type_Identifier(void) const
123 {
124 return( SG_Parameter_Type_Get_Identifier(Get_Type()) );
125 }
126
127 //---------------------------------------------------------
Get_Type_Name(void) const128 CSG_String CSG_Parameter::Get_Type_Name(void) const
129 {
130 return( SG_Parameter_Type_Get_Name(Get_Type()) );
131 }
132
133
134 ///////////////////////////////////////////////////////////
135 // //
136 ///////////////////////////////////////////////////////////
137
138 //---------------------------------------------------------
Set_UseInGUI(bool bDoUse)139 void CSG_Parameter::Set_UseInGUI(bool bDoUse)
140 {
141 if( bDoUse )
142 {
143 m_Constraint &= ~PARAMETER_NOT_FOR_GUI;
144 }
145 else
146 {
147 m_Constraint |= PARAMETER_NOT_FOR_GUI;
148 }
149 }
150
151 //---------------------------------------------------------
Set_UseInCMD(bool bDoUse)152 void CSG_Parameter::Set_UseInCMD(bool bDoUse)
153 {
154 if( bDoUse )
155 {
156 m_Constraint &= ~PARAMETER_NOT_FOR_CMD;
157 }
158 else
159 {
160 m_Constraint |= PARAMETER_NOT_FOR_CMD;
161 }
162 }
163
164 //---------------------------------------------------------
do_UseInGUI(void) const165 bool CSG_Parameter::do_UseInGUI(void) const
166 {
167 return( !(m_Constraint & PARAMETER_NOT_FOR_GUI) && (Get_Parent() == NULL || Get_Parent()->do_UseInGUI()) );
168 }
169
170 //---------------------------------------------------------
do_UseInCMD(void) const171 bool CSG_Parameter::do_UseInCMD(void) const
172 {
173 return( !(m_Constraint & PARAMETER_NOT_FOR_CMD) && (Get_Parent() == NULL || Get_Parent()->do_UseInCMD()) );
174 }
175
176 //---------------------------------------------------------
ignore_Projection(bool bIgnore)177 void CSG_Parameter::ignore_Projection(bool bIgnore)
178 {
179 if( bIgnore )
180 {
181 m_Constraint &= ~PARAMETER_IGNORE_PROJECTION;
182 }
183 else
184 {
185 m_Constraint |= PARAMETER_IGNORE_PROJECTION;
186 }
187 }
188
189
190 ///////////////////////////////////////////////////////////
191 // //
192 ///////////////////////////////////////////////////////////
193
194 //---------------------------------------------------------
Set_Enabled(bool bEnabled)195 bool CSG_Parameter::Set_Enabled(bool bEnabled)
196 {
197 if( m_bEnabled != bEnabled )
198 {
199 m_bEnabled = bEnabled;
200
201 return( !bEnabled );
202 }
203
204 return( bEnabled );
205 }
206
207 //---------------------------------------------------------
is_Enabled(bool bCheckEnv) const208 bool CSG_Parameter::is_Enabled(bool bCheckEnv) const
209 {
210 if( bCheckEnv )
211 {
212 if( !do_UseInGUI() && m_pParameters->has_GUI() )
213 {
214 return( false );
215 }
216
217 if( !do_UseInCMD() && !m_pParameters->has_GUI() )
218 {
219 return( false );
220 }
221 }
222
223 return( m_bEnabled && (m_pParent == NULL || m_pParent->is_Enabled()) );
224 }
225
226 //---------------------------------------------------------
Set_Children_Enabled(bool bEnabled)227 bool CSG_Parameter::Set_Children_Enabled(bool bEnabled)
228 {
229 for(int i=0; i<Get_Children_Count(); i++)
230 {
231 Get_Child(i)->Set_Enabled(bEnabled);
232 }
233
234 return( true );
235 }
236
237 //---------------------------------------------------------
is_Option(void) const238 bool CSG_Parameter::is_Option(void) const
239 {
240 if( !is_Information() )
241 {
242 switch( Get_Type() )
243 {
244 case PARAMETER_TYPE_Bool :
245 case PARAMETER_TYPE_Int :
246 case PARAMETER_TYPE_Double :
247 case PARAMETER_TYPE_Degree :
248 case PARAMETER_TYPE_Date :
249 case PARAMETER_TYPE_Range :
250 case PARAMETER_TYPE_Choice :
251 case PARAMETER_TYPE_Choices :
252 case PARAMETER_TYPE_String :
253 case PARAMETER_TYPE_Text :
254 case PARAMETER_TYPE_FilePath :
255 case PARAMETER_TYPE_Font :
256 case PARAMETER_TYPE_Color :
257 case PARAMETER_TYPE_Colors :
258 case PARAMETER_TYPE_FixedTable :
259 case PARAMETER_TYPE_Grid_System :
260 case PARAMETER_TYPE_Table_Field :
261 case PARAMETER_TYPE_Table_Fields:
262 case PARAMETER_TYPE_Parameters :
263 return( true );
264
265 default:
266 return( false );
267 }
268 }
269
270 return( false );
271 }
272
273 //---------------------------------------------------------
is_DataObject(void) const274 bool CSG_Parameter::is_DataObject(void) const
275 {
276 switch( Get_Type() )
277 {
278 case PARAMETER_TYPE_DataObject_Output:
279 case PARAMETER_TYPE_Grid :
280 case PARAMETER_TYPE_Grids :
281 case PARAMETER_TYPE_Table :
282 case PARAMETER_TYPE_Shapes :
283 case PARAMETER_TYPE_TIN :
284 case PARAMETER_TYPE_PointCloud :
285 return( true );
286
287 default:
288 return( false );
289 }
290 }
291
292 //---------------------------------------------------------
is_DataObject_List(void) const293 bool CSG_Parameter::is_DataObject_List(void) const
294 {
295 switch( Get_Type() )
296 {
297 case PARAMETER_TYPE_Grid_List :
298 case PARAMETER_TYPE_Grids_List :
299 case PARAMETER_TYPE_Table_List :
300 case PARAMETER_TYPE_Shapes_List :
301 case PARAMETER_TYPE_TIN_List :
302 case PARAMETER_TYPE_PointCloud_List:
303 return( true );
304
305 default:
306 return( false );
307 }
308 }
309
310 //---------------------------------------------------------
is_Parameters(void) const311 bool CSG_Parameter::is_Parameters(void) const
312 {
313 return( Get_Type() == PARAMETER_TYPE_Parameters );
314 }
315
316 //---------------------------------------------------------
is_Serializable(void) const317 bool CSG_Parameter::is_Serializable(void) const
318 {
319 switch( Get_Type() )
320 {
321 case PARAMETER_TYPE_Undefined :
322 case PARAMETER_TYPE_Node :
323 case PARAMETER_TYPE_DataObject_Output:
324 return( false );
325
326 case PARAMETER_TYPE_String :
327 return( ((CSG_Parameter_String *)this)->is_Password() == false );
328
329 default:
330 return( !is_Information() );
331 }
332 }
333
334 //---------------------------------------------------------
is_Compatible(CSG_Parameter * pParameter) const335 bool CSG_Parameter::is_Compatible(CSG_Parameter *pParameter) const
336 {
337 if( pParameter && pParameter->Get_Type() == Get_Type() )
338 {
339 switch( Get_Type() )
340 {
341 //-------------------------------------------------
342 case PARAMETER_TYPE_Choice :
343 {
344 bool bResult = pParameter->asChoice()->Get_Count() == asChoice()->Get_Count();
345
346 for(int i=0; bResult && i<asChoice()->Get_Count(); i++)
347 {
348 bResult = SG_STR_CMP(pParameter->asChoice()->Get_Item(i), asChoice()->Get_Item(i)) == 0;
349 }
350
351 return( bResult );
352 }
353
354 //-------------------------------------------------
355 case PARAMETER_TYPE_Choices :
356 {
357 bool bResult = pParameter->asChoices()->Get_Item_Count() == asChoices()->Get_Item_Count();
358
359 for(int i=0; bResult && i<asChoices()->Get_Item_Count(); i++)
360 {
361 bResult = SG_STR_CMP(pParameter->asChoices()->Get_Item(i), asChoices()->Get_Item(i)) == 0;
362 }
363
364 return( bResult );
365 }
366
367 //-------------------------------------------------
368 case PARAMETER_TYPE_FixedTable : return( pParameter->asTable()->is_Compatible(asTable()) );
369
370 //-------------------------------------------------
371 case PARAMETER_TYPE_Parameters :
372 {
373 bool bResult = pParameter->asParameters()->Get_Count() == asParameters()->Get_Count();
374
375 for(int i=0; bResult && i<asParameters()->Get_Count(); i++)
376 {
377 bResult = pParameter->asParameters()->Get_Parameter(i)->is_Compatible(asParameters()->Get_Parameter(i));
378 }
379
380 return( bResult );
381 }
382
383 //-------------------------------------------------
384 default:
385 return( true );
386 }
387 }
388
389 return( false );
390 }
391
392 //---------------------------------------------------------
is_Value_Equal(CSG_Parameter * pParameter) const393 bool CSG_Parameter::is_Value_Equal(CSG_Parameter *pParameter) const
394 {
395 if( pParameter && pParameter->Get_Type() == Get_Type() )
396 {
397 switch( Get_Type() )
398 {
399 case PARAMETER_TYPE_Node : return( true );
400
401 //-------------------------------------------------
402 case PARAMETER_TYPE_Bool : return( pParameter->asBool () == asBool () );
403 case PARAMETER_TYPE_Table_Field :
404 case PARAMETER_TYPE_Choice :
405 case PARAMETER_TYPE_Color :
406 case PARAMETER_TYPE_Int : return( pParameter->asInt () == asInt () );
407 case PARAMETER_TYPE_Date :
408 case PARAMETER_TYPE_Degree :
409 case PARAMETER_TYPE_Double : return( pParameter->asDouble() == asDouble() );
410
411 case PARAMETER_TYPE_Table_Fields :
412 case PARAMETER_TYPE_Font :
413 case PARAMETER_TYPE_Text :
414 case PARAMETER_TYPE_FilePath :
415 case PARAMETER_TYPE_String : return( SG_STR_CMP(pParameter->asString(), asString()) == 0 );
416
417 case PARAMETER_TYPE_Range : return( pParameter->asRange()->Get_Min() == asRange()->Get_Min()
418 && pParameter->asRange()->Get_Max() == asRange()->Get_Max() );
419
420 case PARAMETER_TYPE_Grid_System : return( pParameter->asGrid_System()->is_Equal(*asGrid_System()) );
421
422 //-------------------------------------------------
423 case PARAMETER_TYPE_Choices :
424 {
425 bool bResult = pParameter->asChoices()->Get_Selection_Count() == asChoices()->Get_Selection_Count();
426
427 for(int i=0; bResult && i<asChoices()->Get_Selection_Count(); i++)
428 {
429 bResult = pParameter->asChoices()->Get_Selection_Index(i) == asChoices()->Get_Selection_Index(i);
430 }
431
432 return( bResult );
433 }
434
435 //-------------------------------------------------
436 case PARAMETER_TYPE_Colors :
437 {
438 bool bResult = pParameter->asColors()->Get_Count() == asColors()->Get_Count();
439
440 for(int i=0; bResult && i<asColors()->Get_Count(); i++)
441 {
442 bResult = pParameter->asColors()->Get_Color(i) == asColors()->Get_Color(i);
443 }
444
445 return( bResult );
446 }
447
448 //-------------------------------------------------
449 case PARAMETER_TYPE_FixedTable :
450 {
451 bool bResult = pParameter->asTable()->is_Compatible(asTable()) && pParameter->asTable()->Get_Count() == asTable()->Get_Count();
452
453 for(int i=0; bResult && i<asTable()->Get_Count(); i++)
454 {
455 CSG_Table_Record *pA = pParameter->asTable()->Get_Record(i), *pB = asTable()->Get_Record(i);
456
457 for(int j=0; bResult && j<asTable()->Get_Field_Count(); j++)
458 {
459 bResult = SG_STR_CMP(pA->asString(j), pB->asString(j)) == 0;
460 }
461 }
462
463 return( bResult );
464 }
465
466 //-------------------------------------------------
467 case PARAMETER_TYPE_DataObject_Output:
468 case PARAMETER_TYPE_Grid :
469 case PARAMETER_TYPE_Grids :
470 case PARAMETER_TYPE_Table :
471 case PARAMETER_TYPE_Shapes :
472 case PARAMETER_TYPE_TIN :
473 case PARAMETER_TYPE_PointCloud : return( pParameter->asDataObject() == asDataObject() );
474
475 //-------------------------------------------------
476 case PARAMETER_TYPE_Grid_List :
477 case PARAMETER_TYPE_Grids_List :
478 case PARAMETER_TYPE_Table_List :
479 case PARAMETER_TYPE_Shapes_List :
480 case PARAMETER_TYPE_TIN_List :
481 case PARAMETER_TYPE_PointCloud_List :
482 {
483 bool bResult = pParameter->asList()->Get_Item_Count() == asList()->Get_Item_Count();
484
485 for(int i=0; bResult && i<asList()->Get_Item_Count(); i++)
486 {
487 bResult = pParameter->asList()->Get_Item(i) == asList()->Get_Item(i);
488 }
489
490 return( bResult );
491 }
492
493 //-------------------------------------------------
494 case PARAMETER_TYPE_Parameters :
495 {
496 bool bResult = pParameter->asParameters()->Get_Count() == asParameters()->Get_Count();
497
498 for(int i=0; bResult && i<asParameters()->Get_Count(); i++)
499 {
500 bResult = pParameter->asParameters()->Get_Parameter(i)->is_Value_Equal(asParameters()->Get_Parameter(i));
501 }
502
503 return( bResult );
504 }
505
506 //-------------------------------------------------
507 default: break;
508 }
509 }
510
511 return( false );
512 }
513
514 //---------------------------------------------------------
Get_DataObject_Type(void) const515 TSG_Data_Object_Type CSG_Parameter::Get_DataObject_Type(void) const
516 {
517 switch( Get_Type() )
518 {
519 default : return( SG_DATAOBJECT_TYPE_Undefined );
520 case PARAMETER_TYPE_Grid :
521 case PARAMETER_TYPE_Grid_List : return( SG_DATAOBJECT_TYPE_Grid );
522 case PARAMETER_TYPE_Grids :
523 case PARAMETER_TYPE_Grids_List : return( SG_DATAOBJECT_TYPE_Grids );
524 case PARAMETER_TYPE_Table :
525 case PARAMETER_TYPE_Table_List : return( SG_DATAOBJECT_TYPE_Table );
526 case PARAMETER_TYPE_Shapes :
527 case PARAMETER_TYPE_Shapes_List : return( SG_DATAOBJECT_TYPE_Shapes );
528 case PARAMETER_TYPE_TIN :
529 case PARAMETER_TYPE_TIN_List : return( SG_DATAOBJECT_TYPE_TIN );
530 case PARAMETER_TYPE_PointCloud :
531 case PARAMETER_TYPE_PointCloud_List : return( SG_DATAOBJECT_TYPE_PointCloud );
532 case PARAMETER_TYPE_DataObject_Output:
533 return( ((CSG_Parameter_Data_Object_Output *)this)->Get_DataObject_Type() );
534 }
535 }
536
537
538 ///////////////////////////////////////////////////////////
539 // //
540 ///////////////////////////////////////////////////////////
541
542 //---------------------------------------------------------
Get_Identifier(void) const543 const SG_Char * CSG_Parameter::Get_Identifier(void) const
544 {
545 return( m_Identifier );
546 }
547
548 //---------------------------------------------------------
Cmp_Identifier(const CSG_String & Identifier) const549 bool CSG_Parameter::Cmp_Identifier(const CSG_String &Identifier) const
550 {
551 return( !m_Identifier.Cmp(Identifier) || !m_Identifier.Cmp(Identifier + ".Default") );
552 }
553
554 //---------------------------------------------------------
Set_Name(const CSG_String & Name)555 bool CSG_Parameter::Set_Name(const CSG_String &Name)
556 {
557 m_Name = Name;
558
559 return( true );
560 }
561
Get_Name(void) const562 const SG_Char * CSG_Parameter::Get_Name(void) const
563 {
564 return( m_Name );
565 }
566
567 //---------------------------------------------------------
Set_Description(const CSG_String & Description)568 bool CSG_Parameter::Set_Description(const CSG_String &Description)
569 {
570 m_Description = Description;
571
572 return( true );
573 }
574
Get_Description(void) const575 const SG_Char * CSG_Parameter::Get_Description(void) const
576 {
577 return( m_Description );
578 }
579
580 //---------------------------------------------------------
Get_Description(int Flags) const581 CSG_String CSG_Parameter::Get_Description(int Flags) const
582 {
583 return( Get_Description(Flags, SG_T("\n")) );
584 }
585
586 //---------------------------------------------------------
587 #define SEPARATE if( bSeparate ) s.Append(Separator); bSeparate = true;
588
589 //---------------------------------------------------------
Get_Description(int Flags,const SG_Char * Separator) const590 CSG_String CSG_Parameter::Get_Description(int Flags, const SG_Char *Separator) const
591 {
592 if( !Separator || !Separator[0] )
593 {
594 return( Get_Description(Flags) );
595 }
596
597 bool bSeparate = false;
598 int i;
599 CSG_String s;
600
601 //-----------------------------------------------------
602 if( (Flags & PARAMETER_DESCRIPTION_NAME) != 0 )
603 {
604 SEPARATE; s += CSG_String::Format("%s", Get_Name());
605 }
606
607 //-----------------------------------------------------
608 if( (Flags & PARAMETER_DESCRIPTION_TYPE) != 0 )
609 {
610 SEPARATE;
611
612 if( is_DataObject() && Get_Type() == PARAMETER_TYPE_DataObject_Output )
613 {
614 s += CSG_String::Format("%s %s", Get_Type_Name().c_str(), SG_Get_DataObject_Name(Get_DataObject_Type()).c_str());
615 }
616 else
617 {
618 s += CSG_String::Format("%s", Get_Type_Name().c_str());
619 }
620
621 if( is_DataObject() || is_DataObject_List() )
622 {
623 s += CSG_String::Format(", %s", is_Input() ? _TL("input") : _TL("output"));
624
625 if( is_Optional() )
626 {
627 s += CSG_String::Format(", %s", _TL("optional"));
628 }
629 }
630
631 if( do_UseInGUI() != do_UseInCMD() )
632 {
633 s += CSG_String::Format(", %s", do_UseInGUI() ? SG_T("GUI") : SG_T("CMD"));
634 }
635 }
636
637 //-----------------------------------------------------
638 if( (Flags & PARAMETER_DESCRIPTION_OPTIONAL) != 0 && is_Optional() )
639 {
640 SEPARATE; s += CSG_String::Format("%s", _TL("optional"));
641 }
642
643 //-----------------------------------------------------
644 if( (Flags & PARAMETER_DESCRIPTION_PROPERTIES) != 0 )
645 {
646 switch( Get_Type() )
647 {
648 default:
649 break;
650
651 case PARAMETER_TYPE_Choice:
652 SEPARATE; s += CSG_String::Format("%s:", _TL("Available Choices"));
653
654 for(i=0; i<asChoice()->Get_Count(); i++)
655 {
656 s += CSG_String::Format("%s[%d] %s", Separator, i, asChoice()->Get_Item(i));
657 }
658 break;
659
660 case PARAMETER_TYPE_Choices:
661 SEPARATE; s += CSG_String::Format("%s:", _TL("Available Choices"));
662
663 for(i=0; i<asChoices()->Get_Item_Count(); i++)
664 {
665 s += CSG_String::Format("%s[%d] %s", Separator, i, asChoices()->Get_Item(i).c_str());
666 }
667 break;
668
669 case PARAMETER_TYPE_Int:
670 if( asValue()->has_Minimum() )
671 {
672 SEPARATE; s += CSG_String::Format("%s: %d", _TL("Minimum"), (int)asValue()->Get_Minimum());
673 }
674
675 if( asValue()->has_Maximum() )
676 {
677 SEPARATE; s += CSG_String::Format("%s: %d", _TL("Maximum"), (int)asValue()->Get_Maximum());
678 }
679 break;
680
681 case PARAMETER_TYPE_Double:
682 case PARAMETER_TYPE_Degree:
683 // case PARAMETER_TYPE_Range:
684 if( asValue()->has_Minimum() )
685 {
686 SEPARATE; s += CSG_String::Format("%s: %f", _TL("Minimum"), asValue()->Get_Minimum());
687 }
688
689 if( asValue()->has_Maximum() )
690 {
691 SEPARATE; s += CSG_String::Format("%s: %f", _TL("Maximum"), asValue()->Get_Maximum());
692 }
693 break;
694
695 case PARAMETER_TYPE_FixedTable:
696 SEPARATE; s += CSG_String::Format("%d %s:%s", asTable()->Get_Field_Count(), _TL("Fields"), Separator);
697
698 for(i=0; i<asTable()->Get_Field_Count(); i++)
699 {
700 s += CSG_String::Format("- %d. [%s] %s%s", i + 1, SG_Data_Type_Get_Name(asTable()->Get_Field_Type(i)).c_str(), asTable()->Get_Field_Name(i), Separator);
701 }
702 break;
703
704 case PARAMETER_TYPE_Parameters:
705 SEPARATE; s += CSG_String::Format("%d %s:%s", asParameters()->Get_Count(), _TL("Parameters"), Separator);
706
707 for(i=0; i<asParameters()->Get_Count(); i++)
708 {
709 s += CSG_String::Format("- %d. %s%s", i + 1, asParameters()->Get_Parameter(i)->Get_Description(Flags, Separator).c_str(), Separator);
710 }
711 break;
712 }
713
714 if( !m_Default.is_Empty() )
715 {
716 SEPARATE; s += CSG_String::Format("%s: %s", _TL("Default"), m_Default.c_str());
717 }
718 }
719
720 //-----------------------------------------------------
721 if( (Flags & PARAMETER_DESCRIPTION_TEXT) != 0 && m_Description.Length() > 0 )
722 {
723 SEPARATE;
724
725 s += m_Description;
726 }
727
728 //-----------------------------------------------------
729 return( s );
730 }
731
732
733 ///////////////////////////////////////////////////////////
734 // //
735 ///////////////////////////////////////////////////////////
736
737 //---------------------------------------------------------
_Set_Value(int Value)738 int CSG_Parameter::_Set_Value(int Value) { return( SG_PARAMETER_DATA_SET_FALSE ); }
_Set_Value(double Value)739 int CSG_Parameter::_Set_Value(double Value) { return( SG_PARAMETER_DATA_SET_FALSE ); }
_Set_Value(const CSG_String & Value)740 int CSG_Parameter::_Set_Value(const CSG_String &Value) { return( SG_PARAMETER_DATA_SET_FALSE ); }
_Set_Value(void * Value)741 int CSG_Parameter::_Set_Value(void *Value) { return( SG_PARAMETER_DATA_SET_FALSE ); }
742
743 //---------------------------------------------------------
Set_Value(int Value)744 bool CSG_Parameter::Set_Value(int Value)
745 {
746 switch( _Set_Value(Value) )
747 {
748 case SG_PARAMETER_DATA_SET_FALSE:
749 return( false );
750
751 case SG_PARAMETER_DATA_SET_CHANGED:
752 has_Changed();
753 }
754
755 return( true );
756 }
757
758 //---------------------------------------------------------
Set_Value(double Value)759 bool CSG_Parameter::Set_Value(double Value)
760 {
761 switch( _Set_Value(Value) )
762 {
763 case SG_PARAMETER_DATA_SET_FALSE:
764 return( false );
765
766 case SG_PARAMETER_DATA_SET_CHANGED:
767 has_Changed();
768 }
769
770 return( true );
771 }
772
773 //---------------------------------------------------------
Set_Value(const char * Value)774 bool CSG_Parameter::Set_Value(const char *Value) { return( Set_Value(CSG_String(Value)) ); }
Set_Value(const wchar_t * Value)775 bool CSG_Parameter::Set_Value(const wchar_t *Value) { return( Set_Value(CSG_String(Value)) ); }
Set_Value(const CSG_String & Value)776 bool CSG_Parameter::Set_Value(const CSG_String &Value)
777 {
778 switch( _Set_Value(Value) )
779 {
780 case SG_PARAMETER_DATA_SET_FALSE:
781 return( false );
782
783 case SG_PARAMETER_DATA_SET_CHANGED:
784 has_Changed();
785 }
786
787 return( true );
788 }
789
790 //---------------------------------------------------------
Set_Value(void * Value)791 bool CSG_Parameter::Set_Value(void *Value)
792 {
793 switch( _Set_Value(Value) )
794 {
795 case SG_PARAMETER_DATA_SET_FALSE:
796 return( false );
797
798 case SG_PARAMETER_DATA_SET_CHANGED:
799 has_Changed();
800 }
801
802 return( true );
803 }
804
805 //---------------------------------------------------------
Set_Value(CSG_Parameter * Value)806 bool CSG_Parameter::Set_Value(CSG_Parameter *Value)
807 {
808 if( Value )
809 {
810 switch( Value->Get_Type() )
811 {
812 default:
813 break;
814
815 case PARAMETER_TYPE_Choice:
816 return( Set_Value(Value->asInt()) );
817 }
818 }
819
820 return( Assign(Value) );
821 }
822
823 //---------------------------------------------------------
has_Changed(int Check_Flags)824 bool CSG_Parameter::has_Changed(int Check_Flags)
825 {
826 _Set_String();
827
828 return( m_pParameters && m_pParameters->_On_Parameter_Changed(this, Check_Flags) );
829 }
830
831 //---------------------------------------------------------
_Set_String(void)832 void CSG_Parameter::_Set_String(void)
833 {
834 // nop
835 }
836
837
838 ///////////////////////////////////////////////////////////
839 // //
840 ///////////////////////////////////////////////////////////
841
842 //---------------------------------------------------------
Set_Default(int Value)843 bool CSG_Parameter::Set_Default(int Value)
844 {
845 m_Default.Printf("%d", Value);
846
847 return( true );
848 }
849
850 //---------------------------------------------------------
Set_Default(double Value)851 bool CSG_Parameter::Set_Default(double Value)
852 {
853 m_Default.Printf("%f", Value);
854
855 return( true );
856 }
857
858 //---------------------------------------------------------
Set_Default(const CSG_String & Value)859 bool CSG_Parameter::Set_Default(const CSG_String &Value)
860 {
861 m_Default = Value;
862
863 return( true );
864 }
865
866 //---------------------------------------------------------
Get_Default(void) const867 const CSG_String & CSG_Parameter::Get_Default(void) const
868 {
869 return( m_Default );
870 }
871
872 //---------------------------------------------------------
Restore_Default(void)873 bool CSG_Parameter::Restore_Default(void)
874 {
875 return( Set_Value(m_Default) );
876 }
877
878
879 ///////////////////////////////////////////////////////////
880 // //
881 ///////////////////////////////////////////////////////////
882
883 //---------------------------------------------------------
Check(bool bSilent)884 bool CSG_Parameter::Check(bool bSilent)
885 {
886 if( Get_Type() == PARAMETER_TYPE_Parameters )
887 {
888 return( asParameters()->DataObjects_Check(bSilent) );
889 }
890
891 //-----------------------------------------------------
892 if( Get_Type() == PARAMETER_TYPE_Grid_System )
893 {
894 if( m_pParameters->Get_Manager() && !m_pParameters->Get_Manager()->Exists(*asGrid_System()) )
895 {
896 Set_Value((void *)NULL);
897 }
898
899 return( true ); // ( false );
900 }
901
902 //-----------------------------------------------------
903 if( is_DataObject() )
904 {
905 if( is_Input() || (is_Output() && asDataObject() != DATAOBJECT_CREATE) )
906 {
907 if( m_pParameters->Get_Manager() && !m_pParameters->Get_Manager()->Exists(asDataObject()) )
908 {
909 Set_Value(DATAOBJECT_NOTSET);
910 }
911 }
912
913 return( is_Optional() || !is_Enabled() || asDataObject() );
914 }
915
916 //-----------------------------------------------------
917 else if( is_DataObject_List() )
918 {
919 for(int j=asList()->Get_Item_Count()-1; j>=0; j--)
920 {
921 CSG_Data_Object *pDataObject = asList()->Get_Item(j);
922
923 if( !pDataObject || (m_pParameters->Get_Manager() && !m_pParameters->Get_Manager()->Exists(pDataObject)) )
924 {
925 asList()->Del_Item(j, false);
926 }
927 }
928
929 _Set_String();
930
931 asList()->Update_Data();
932
933 return( is_Optional() || !is_Enabled() || is_Output() || asList()->Get_Item_Count() > 0 );
934 }
935
936 //-----------------------------------------------------
937 return( true );
938 }
939
940
941 ///////////////////////////////////////////////////////////
942 // //
943 ///////////////////////////////////////////////////////////
944
945 //---------------------------------------------------------
_asInt(void) const946 int CSG_Parameter::_asInt (void) const { return( 0 ); }
_asDouble(void) const947 double CSG_Parameter::_asDouble (void) const { return( 0. ); }
_asPointer(void) const948 void * CSG_Parameter::_asPointer (void) const { return( NULL ); }
_asString(void) const949 const SG_Char * CSG_Parameter::_asString (void) const { return( m_String ); }
950
951 //---------------------------------------------------------
asColors(void) const952 CSG_Colors * CSG_Parameter::asColors (void) const { return( Get_Type() != PARAMETER_TYPE_Colors ? NULL : (CSG_Colors *)asPointer() ); }
asFont(void) const953 const SG_Char * CSG_Parameter::asFont (void) const { return( Get_Type() != PARAMETER_TYPE_Font ? NULL : (const SG_Char *)asPointer() ); }
asGrid_System(void) const954 CSG_Grid_System * CSG_Parameter::asGrid_System (void) const { return( Get_Type() != PARAMETER_TYPE_Grid_System ? NULL : (CSG_Grid_System *)asPointer() ); }
asParameters(void) const955 CSG_Parameters * CSG_Parameter::asParameters (void) const { return( Get_Type() != PARAMETER_TYPE_Parameters ? NULL : (CSG_Parameters *)asPointer() ); }
956
957 //---------------------------------------------------------
asDataObject(void) const958 CSG_Data_Object * CSG_Parameter::asDataObject (void) const { return( !is_DataObject() ? NULL : (CSG_Data_Object *)asPointer() ); }
asGrid(void) const959 CSG_Grid * CSG_Parameter::asGrid (void) const { CSG_Data_Object *pObject = asDataObject(); return( !pObject || pObject == DATAOBJECT_CREATE || pObject->Get_ObjectType() != SG_DATAOBJECT_TYPE_Grid ? NULL : (CSG_Grid *)pObject ); }
asGrids(void) const960 CSG_Grids * CSG_Parameter::asGrids (void) const { CSG_Data_Object *pObject = asDataObject(); return( !pObject || pObject == DATAOBJECT_CREATE || pObject->Get_ObjectType() != SG_DATAOBJECT_TYPE_Grids ? NULL : (CSG_Grids *)pObject ); }
asTIN(void) const961 CSG_TIN * CSG_Parameter::asTIN (void) const { CSG_Data_Object *pObject = asDataObject(); return( !pObject || pObject == DATAOBJECT_CREATE || pObject->Get_ObjectType() != SG_DATAOBJECT_TYPE_TIN ? NULL : (CSG_TIN *)pObject ); }
asPointCloud(void) const962 CSG_PointCloud * CSG_Parameter::asPointCloud (void) const { CSG_Data_Object *pObject = asDataObject(); return( !pObject || pObject == DATAOBJECT_CREATE || pObject->Get_ObjectType() != SG_DATAOBJECT_TYPE_PointCloud ? NULL : (CSG_PointCloud *)pObject ); }
963
964 //---------------------------------------------------------
asShapes(void) const965 CSG_Shapes * CSG_Parameter::asShapes (void) const
966 {
967 CSG_Data_Object *pObject = asDataObject();
968
969 if( pObject && pObject != DATAOBJECT_CREATE
970 && (pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_Shapes
971 || pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_PointCloud) )
972 {
973 return( (CSG_Shapes *)pObject );
974 }
975
976 return( NULL );
977 }
978
979 //---------------------------------------------------------
asTable(void) const980 CSG_Table * CSG_Parameter::asTable (void) const
981 {
982 switch( Get_Type() )
983 {
984 default: {
985 CSG_Data_Object *pObject = asDataObject();
986
987 if( pObject && pObject != DATAOBJECT_CREATE
988 && (pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_Table
989 || pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_Shapes
990 || pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_TIN
991 || pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_PointCloud) )
992 {
993 return( (CSG_Table *)pObject );
994 }
995 } break;
996
997 case PARAMETER_TYPE_Grids :
998 return( asGrids() ? asGrids()->Get_Attributes_Ptr() : NULL );
999
1000 case PARAMETER_TYPE_FixedTable:
1001 return( (CSG_Table *)asPointer() );
1002 }
1003
1004 return( NULL );
1005 }
1006
1007 //---------------------------------------------------------
asValue(void) const1008 CSG_Parameter_Value * CSG_Parameter::asValue (void) const
1009 {
1010 if( Get_Type() == PARAMETER_TYPE_Double
1011 || Get_Type() == PARAMETER_TYPE_Degree
1012 || Get_Type() == PARAMETER_TYPE_Int
1013 || Get_Type() == PARAMETER_TYPE_Color
1014 || Get_Type() == PARAMETER_TYPE_Table_Field )
1015 {
1016 return( (CSG_Parameter_Value *)this );
1017 }
1018
1019 return( NULL );
1020 }
1021
asDate(void) const1022 CSG_Parameter_Date * CSG_Parameter::asDate (void) const { return( Get_Type() != PARAMETER_TYPE_Date ? NULL : (CSG_Parameter_Date *)this ); }
asChoice(void) const1023 CSG_Parameter_Choice * CSG_Parameter::asChoice (void) const { return( Get_Type() != PARAMETER_TYPE_Choice ? NULL : (CSG_Parameter_Choice *)this ); }
asChoices(void) const1024 CSG_Parameter_Choices * CSG_Parameter::asChoices (void) const { return( Get_Type() != PARAMETER_TYPE_Choices ? NULL : (CSG_Parameter_Choices *)this ); }
asRange(void) const1025 CSG_Parameter_Range * CSG_Parameter::asRange (void) const { return( Get_Type() != PARAMETER_TYPE_Range ? NULL : (CSG_Parameter_Range *)this ); }
asFilePath(void) const1026 CSG_Parameter_File_Name * CSG_Parameter::asFilePath (void) const { return( Get_Type() != PARAMETER_TYPE_FilePath ? NULL : (CSG_Parameter_File_Name *)this ); }
asTableFields(void) const1027 CSG_Parameter_Table_Fields * CSG_Parameter::asTableFields (void) const { return( Get_Type() != PARAMETER_TYPE_Table_Fields ? NULL : (CSG_Parameter_Table_Fields *)this ); }
1028
1029 //---------------------------------------------------------
asList(void) const1030 CSG_Parameter_List * CSG_Parameter::asList (void) const { return( !is_DataObject_List() ? NULL : (CSG_Parameter_List *)this ); }
asGridList(void) const1031 CSG_Parameter_Grid_List * CSG_Parameter::asGridList (void) const { return( Get_Type() != PARAMETER_TYPE_Grid_List ? NULL : (CSG_Parameter_Grid_List *)this ); }
asGridsList(void) const1032 CSG_Parameter_Grids_List * CSG_Parameter::asGridsList (void) const { return( Get_Type() != PARAMETER_TYPE_Grids_List ? NULL : (CSG_Parameter_Grids_List *)this ); }
asTableList(void) const1033 CSG_Parameter_Table_List * CSG_Parameter::asTableList (void) const { return( Get_Type() != PARAMETER_TYPE_Table_List ? NULL : (CSG_Parameter_Table_List *)this ); }
asShapesList(void) const1034 CSG_Parameter_Shapes_List * CSG_Parameter::asShapesList (void) const { return( Get_Type() != PARAMETER_TYPE_Shapes_List ? NULL : (CSG_Parameter_Shapes_List *)this ); }
asTINList(void) const1035 CSG_Parameter_TIN_List * CSG_Parameter::asTINList (void) const { return( Get_Type() != PARAMETER_TYPE_TIN_List ? NULL : (CSG_Parameter_TIN_List *)this ); }
asPointCloudList(void) const1036 CSG_Parameter_PointCloud_List * CSG_Parameter::asPointCloudList(void) const { return( Get_Type() != PARAMETER_TYPE_PointCloud_List ? NULL : (CSG_Parameter_PointCloud_List *)this ); }
1037
1038
1039 ///////////////////////////////////////////////////////////
1040 // //
1041 ///////////////////////////////////////////////////////////
1042
1043 //---------------------------------------------------------
_Add_Child(CSG_Parameter * pChild)1044 void CSG_Parameter::_Add_Child(CSG_Parameter *pChild)
1045 {
1046 m_Children = (CSG_Parameter **)SG_Realloc(m_Children, (m_nChildren + 1) * sizeof(CSG_Parameter *));
1047 m_Children[m_nChildren++] = pChild;
1048 }
1049
1050
1051 ///////////////////////////////////////////////////////////
1052 // //
1053 ///////////////////////////////////////////////////////////
1054
1055 //---------------------------------------------------------
Assign(CSG_Parameter * pSource)1056 bool CSG_Parameter::Assign(CSG_Parameter *pSource)
1057 {
1058 if( pSource && Get_Type() == pSource->Get_Type() )
1059 {
1060 m_bEnabled = pSource->m_bEnabled;
1061 m_Default = pSource->m_Default;
1062
1063 if( _Assign(pSource) )
1064 {
1065 _Set_String();
1066
1067 return( true );
1068 }
1069 }
1070
1071 return( false );
1072 }
1073
_Assign(CSG_Parameter * pSource)1074 bool CSG_Parameter::_Assign(CSG_Parameter *pSource)
1075 {
1076 return( true );
1077 }
1078
1079 //---------------------------------------------------------
Serialize(CSG_MetaData & MetaData,bool bSave)1080 bool CSG_Parameter::Serialize(CSG_MetaData &MetaData, bool bSave)
1081 {
1082 if( bSave )
1083 {
1084 if( is_Information() || Get_Type() == PARAMETER_TYPE_Node || Get_Type() == PARAMETER_TYPE_Undefined )
1085 {
1086 return( true );
1087 }
1088
1089 CSG_MetaData &Child = *MetaData.Add_Child(
1090 is_Option () ? "OPTION" :
1091 is_DataObject () ? "DATA" :
1092 is_DataObject_List() ? "DATA_LIST" : "PARAMETER"
1093 );
1094
1095 Child.Add_Property("type" , Get_Type_Identifier ());
1096 Child.Add_Property("id" , Get_Identifier ());
1097 Child.Add_Property("name" , Get_Name ());
1098 Child.Add_Property("parms", Get_Parameters()->Get_Identifier());
1099
1100 _Serialize(Child, bSave);
1101
1102 return( true );
1103 }
1104 else if( MetaData.Cmp_Property("type", Get_Type_Identifier())
1105 && MetaData.Cmp_Property("id" , Get_Identifier ())
1106 && _Serialize(MetaData, bSave) )
1107 {
1108 _Set_String();
1109
1110 return( true );
1111 }
1112
1113 return( false );
1114 }
1115
_Serialize(CSG_MetaData & Entry,bool bSave)1116 bool CSG_Parameter::_Serialize(CSG_MetaData &Entry, bool bSave)
1117 {
1118 Entry.Set_Content("-");
1119
1120 return( true );
1121 }
1122
1123
1124 ///////////////////////////////////////////////////////////
1125 // //
1126 ///////////////////////////////////////////////////////////
1127
1128 //---------------------------------------------------------
CSG_Parameters_Grid_Target(void)1129 CSG_Parameters_Grid_Target::CSG_Parameters_Grid_Target(void)
1130 {
1131 m_pParameters = NULL;
1132 }
1133
1134 //---------------------------------------------------------
Create(CSG_Parameters * pParameters,bool bAddDefaultGrid,CSG_Parameter * pParent,const CSG_String & Prefix)1135 bool CSG_Parameters_Grid_Target::Create(CSG_Parameters *pParameters, bool bAddDefaultGrid, CSG_Parameter *pParent, const CSG_String &Prefix)
1136 {
1137 return( Create(pParameters, bAddDefaultGrid, pParent ? pParent->Get_Identifier() : SG_T(""), Prefix) );
1138 }
1139
Create(CSG_Parameters * pParameters,bool bAddDefaultGrid,const CSG_String & ParentID,const CSG_String & Prefix)1140 bool CSG_Parameters_Grid_Target::Create(CSG_Parameters *pParameters, bool bAddDefaultGrid, const CSG_String &ParentID, const CSG_String &Prefix)
1141 {
1142 if( pParameters == NULL )
1143 {
1144 return( false );
1145 }
1146
1147 m_pParameters = pParameters;
1148 m_Prefix = Prefix;
1149
1150 //-----------------------------------------------------
1151 CSG_String TargetID(m_Prefix + "DEFINITION");
1152
1153 m_pParameters->Add_Choice(
1154 ParentID, TargetID, _TL("Target Grid System"),
1155 _TL(""),
1156 CSG_String::Format("%s|%s",
1157 _TL("user defined"),
1158 _TL("grid or grid system")
1159 ), 0
1160 );
1161
1162 //-----------------------------------------------------
1163 m_pParameters->Add_Double(TargetID, m_Prefix + "USER_SIZE", _TL("Cellsize"), _TL(""), 1., 0., true);
1164 m_pParameters->Add_Double(TargetID, m_Prefix + "USER_XMIN", _TL("West" ), _TL(""), 0.);
1165 m_pParameters->Add_Double(TargetID, m_Prefix + "USER_XMAX", _TL("East" ), _TL(""), 100.);
1166 m_pParameters->Add_Double(TargetID, m_Prefix + "USER_YMIN", _TL("South" ), _TL(""), 0.);
1167 m_pParameters->Add_Double(TargetID, m_Prefix + "USER_YMAX", _TL("North" ), _TL(""), 100.);
1168 m_pParameters->Add_Int (TargetID, m_Prefix + "USER_COLS", _TL("Columns" ), _TL("Number of cells in East-West direction." ), 101, 1, true);
1169 m_pParameters->Add_Int (TargetID, m_Prefix + "USER_ROWS", _TL("Rows" ), _TL("Number of cells in North-South direction."), 101, 1, true);
1170 m_pParameters->Add_Choice(TargetID, m_Prefix + "USER_FITS", _TL("Fit" ), _TL(""),
1171 CSG_String::Format("%s|%s",
1172 _TL("nodes"),
1173 _TL("cells")
1174 ), 0
1175 );
1176
1177 //-----------------------------------------------------
1178 m_pParameters->Add_Grid_System(TargetID, m_Prefix + "SYSTEM", _TL("Grid System"), _TL(""));
1179
1180 m_pParameters->Add_Grid(m_Prefix + "SYSTEM", m_Prefix + "TEMPLATE", _TL("Target System"),
1181 _TL("use this grid's system for output grids"), PARAMETER_INPUT_OPTIONAL, false
1182 )->Set_UseInGUI(false);
1183
1184 //-----------------------------------------------------
1185 if( bAddDefaultGrid )
1186 {
1187 Add_Grid(m_Prefix + "OUT_GRID", _TL("Target Grid"), false);
1188 }
1189
1190 return( true );
1191 }
1192
1193
1194 ///////////////////////////////////////////////////////////
1195 // //
1196 ///////////////////////////////////////////////////////////
1197
1198 //---------------------------------------------------------
On_Parameter_Changed(CSG_Parameters * pParameters,CSG_Parameter * pParameter)1199 bool CSG_Parameters_Grid_Target::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
1200 {
1201 if( !m_pParameters || !pParameters || m_pParameters->Get_Identifier().Cmp(pParameters->Get_Identifier()) || !pParameter )
1202 {
1203 return( false );
1204 }
1205
1206 CSG_Parameter *pSize = (*pParameters)(m_Prefix + "USER_SIZE");
1207 CSG_Parameter *pXMin = (*pParameters)(m_Prefix + "USER_XMIN");
1208 CSG_Parameter *pXMax = (*pParameters)(m_Prefix + "USER_XMAX");
1209 CSG_Parameter *pYMin = (*pParameters)(m_Prefix + "USER_YMIN");
1210 CSG_Parameter *pYMax = (*pParameters)(m_Prefix + "USER_YMAX");
1211 CSG_Parameter *pRows = (*pParameters)(m_Prefix + "USER_ROWS");
1212 CSG_Parameter *pCols = (*pParameters)(m_Prefix + "USER_COLS");
1213 CSG_Parameter *pFits = (*pParameters)(m_Prefix + "USER_FITS");
1214
1215 double Size = pSize->asDouble();
1216
1217 double xMin = pXMin->asDouble(), xMax = pXMax->asDouble();
1218 double yMin = pYMin->asDouble(), yMax = pYMax->asDouble();
1219
1220 //-----------------------------------------------------
1221 bool bChanged = true;
1222
1223 if( pParameter->Cmp_Identifier(pFits->Get_Identifier()) )
1224 {
1225 if( pFits->asInt() == 0 ) // fit cells >> fit nodes
1226 {
1227 xMin += 0.5 * Size; xMax -= 0.5 * Size;
1228 yMin += 0.5 * Size; yMax -= 0.5 * Size;
1229 }
1230 }
1231 else
1232 {
1233 if( pFits->asInt() == 1 ) // fit cells >> fit nodes
1234 {
1235 xMin += 0.5 * Size; xMax -= 0.5 * Size;
1236 yMin += 0.5 * Size; yMax -= 0.5 * Size;
1237 }
1238
1239 if( pParameter->Cmp_Identifier(pSize->Get_Identifier()) && Size > 0. )
1240 {
1241 xMax = xMin + Size * (int)(0.5 + (xMax - xMin) / Size);
1242 yMax = yMin + Size * (int)(0.5 + (yMax - yMin) / Size);
1243 }
1244 else if( pParameter->Cmp_Identifier(pCols->Get_Identifier()) && pCols->asInt() > 0 )
1245 {
1246 xMax = xMin + Size * (pCols->asInt() - 1);
1247 }
1248 else if( pParameter->Cmp_Identifier(pXMin->Get_Identifier()) )
1249 {
1250 xMax = xMin + Size * (xMin > xMax ? (pCols->asInt() - 1) : (int)(0.5 + (xMax - xMin) / Size));
1251 }
1252 else if( pParameter->Cmp_Identifier(pXMax->Get_Identifier()) )
1253 {
1254 xMin = xMax - Size * (xMin > xMax ? (pCols->asInt() - 1) : (int)(0.5 + (xMax - xMin) / Size));
1255 }
1256 else if( pParameter->Cmp_Identifier(pRows->Get_Identifier()) && pRows->asInt() > 0 )
1257 {
1258 yMax = yMin + Size * (pRows->asInt() - 1);
1259 }
1260 else if( pParameter->Cmp_Identifier(pYMin->Get_Identifier()) )
1261 {
1262 yMax = yMin + Size * (yMin > yMax ? (pRows->asInt() - 1) : (int)(0.5 + (yMax - yMin) / Size));
1263 }
1264 else if( pParameter->Cmp_Identifier(pYMax->Get_Identifier()) )
1265 {
1266 yMin = yMax - Size * (yMin > yMax ? (pRows->asInt() - 1) : (int)(0.5 + (yMax - yMin) / Size));
1267 }
1268 else
1269 {
1270 bChanged = false; // none of the relevant parameters did change so far
1271 }
1272 }
1273
1274 //-----------------------------------------------------
1275 if( bChanged )
1276 {
1277 pCols->Set_Value(1 + (int)((xMax - xMin) / Size));
1278 pRows->Set_Value(1 + (int)((yMax - yMin) / Size));
1279
1280 if( pFits->asInt() == 1 )
1281 {
1282 xMin -= 0.5 * Size; xMax += 0.5 * Size;
1283 yMin -= 0.5 * Size; yMax += 0.5 * Size;
1284 }
1285
1286 pXMin->Set_Value(xMin);
1287 pXMax->Set_Value(xMax);
1288 pYMin->Set_Value(yMin);
1289 pYMax->Set_Value(yMax);
1290
1291 return( true );
1292 }
1293
1294 //-----------------------------------------------------
1295 CSG_Parameter *pZSize = (*pParameters)(m_Prefix + "USER_ZSIZE");
1296 CSG_Parameter *pZMin = (*pParameters)(m_Prefix + "USER_ZMIN");
1297 CSG_Parameter *pZMax = (*pParameters)(m_Prefix + "USER_ZMAX");
1298 CSG_Parameter *pZNum = (*pParameters)(m_Prefix + "USER_ZNUM");
1299
1300 if( pZSize && pZMin && pZMax && pZNum )
1301 {
1302 double zSize = pZSize->asDouble(), zMin = pZMin ->asDouble(), zMax = pZMax ->asDouble();
1303
1304 bChanged = true;
1305
1306 if( pParameter->Cmp_Identifier(pZSize->Get_Identifier()) && zSize > 0. )
1307 {
1308 zMax = zMin + zSize * (int)(0.5 + (zMax - zMin) / zSize);
1309 }
1310 else if( pParameter->Cmp_Identifier(pZNum->Get_Identifier()) && pZNum->asInt() > 0 )
1311 {
1312 zMax = zMin + zSize * pZNum->asInt();
1313 }
1314 else if( pParameter->Cmp_Identifier(pZMin->Get_Identifier()) )
1315 {
1316 zMax = zMin + zSize * (zMin > zMax ? pZNum->asInt() : (int)(0.5 + (zMax - zMin) / zSize));
1317 }
1318 else if( pParameter->Cmp_Identifier(pZMax->Get_Identifier()) )
1319 {
1320 zMin = zMax - zSize * (zMin > zMax ? pZNum->asInt() : (int)(0.5 + (zMax - zMin) / zSize));
1321 }
1322 else
1323 {
1324 bChanged = false;
1325 }
1326
1327 if( bChanged )
1328 {
1329 pZNum->Set_Value(1 + (int)((zMax - zMin) / zSize));
1330
1331 pZMin->Set_Value(zMin);
1332 pZMax->Set_Value(zMax);
1333 }
1334 }
1335
1336 return( true );
1337 }
1338
1339 //---------------------------------------------------------
On_Parameters_Enable(CSG_Parameters * pParameters,CSG_Parameter * pParameter)1340 bool CSG_Parameters_Grid_Target::On_Parameters_Enable(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
1341 {
1342 if( !m_pParameters || !pParameters || m_pParameters->Get_Identifier().Cmp(pParameters->Get_Identifier()) || !pParameter )
1343 {
1344 return( false );
1345 }
1346
1347 if( (pParameter = (*pParameters)(m_Prefix + "DEFINITION")) == NULL )
1348 {
1349 return( false );
1350 }
1351
1352 pParameters->Set_Enabled(m_Prefix + "SYSTEM" , pParameter->asInt() == 1);
1353 pParameters->Set_Enabled(m_Prefix + "TEMPLATE" , pParameter->asInt() == 1);
1354
1355 pParameters->Set_Enabled(m_Prefix + "USER_SIZE", pParameter->asInt() == 0);
1356 pParameters->Set_Enabled(m_Prefix + "USER_XMIN", pParameter->asInt() == 0);
1357 pParameters->Set_Enabled(m_Prefix + "USER_XMAX", pParameter->asInt() == 0);
1358 pParameters->Set_Enabled(m_Prefix + "USER_YMIN", pParameter->asInt() == 0);
1359 pParameters->Set_Enabled(m_Prefix + "USER_YMAX", pParameter->asInt() == 0);
1360 pParameters->Set_Enabled(m_Prefix + "USER_ROWS", pParameter->asInt() == 0);
1361 pParameters->Set_Enabled(m_Prefix + "USER_COLS", pParameter->asInt() == 0);
1362 pParameters->Set_Enabled(m_Prefix + "USER_FITS", pParameter->asInt() == 0);
1363 pParameters->Set_Enabled(m_Prefix + "USER_OPTS", pParameter->asInt() == 0);
1364 pParameters->Set_Enabled(m_Prefix + "USER_Z" , pParameter->asInt() == 0);
1365
1366 return( true );
1367 }
1368
1369 //---------------------------------------------------------
1370 /**
1371 * Initializes the grid system from extent and number of rows.
1372 * Extent calculation is done for grid nodes and will automatically
1373 * become adjusted to match the grid cells if necessary. If Rounding is
1374 * greater than zero it specifies the number of significant figures to which
1375 * the cell size is rounded and also adjusts the extent coordinates
1376 * to be a multiple of cell size.
1377 */
Set_User_Defined(CSG_Parameters * pParameters,const TSG_Rect & Extent,int Rows,int Rounding)1378 bool CSG_Parameters_Grid_Target::Set_User_Defined(CSG_Parameters *pParameters, const TSG_Rect &Extent, int Rows, int Rounding)
1379 {
1380 if( !m_pParameters->Get_Tool()->has_GUI() ) // no cancel button, so set parameters directly
1381 {
1382 pParameters = m_pParameters;
1383 }
1384
1385 if( !m_pParameters || !pParameters || m_pParameters->Get_Identifier().Cmp(pParameters->Get_Identifier()) )
1386 {
1387 return( false );
1388 }
1389
1390 if( Rows < 1 && (Rows = (*m_pParameters)(m_Prefix + "USER_ROWS")->asInt()) < 1 )
1391 {
1392 Rows = 100;
1393 }
1394
1395 //-----------------------------------------------------
1396 CSG_Rect r(Extent);
1397
1398 if( r.Get_XRange() == 0. && r.Get_YRange() == 0. )
1399 {
1400 r.Inflate(0.5 * Rows, false); // assume cellsize = 1.
1401 }
1402 else if( r.Get_XRange() == 0. )
1403 {
1404 double d = 0.5 * r.Get_YRange() / Rows; r.m_rect.xMin -= d; r.m_rect.xMax += d; // inflate by half cellsize
1405 }
1406 else if( r.Get_YRange() == 0. )
1407 {
1408 double d = 0.5 * r.Get_XRange() / Rows; r.m_rect.yMin -= d; r.m_rect.yMax += d; // inflate by half cellsize
1409 }
1410
1411 //-----------------------------------------------------
1412 double Size = r.Get_YRange() / (Rows - 1);
1413
1414 int Cols = 1 + (int)(0.5 + r.Get_XRange() / Size);
1415
1416 if( Rounding > 0 )
1417 {
1418 Size = SG_Get_Rounded_To_SignificantFigures(Size, Rounding);
1419
1420 r.m_rect.xMin = r.Get_XCenter() - Size * Cols / 2.;
1421 r.m_rect.yMin = r.Get_YCenter() - Size * Rows / 2.;
1422 r.m_rect.yMax = r.Get_YMin () + Size * (Rows - 1);
1423 }
1424
1425 r.m_rect.xMax = r.Get_XMin() + Size * (Cols - 1);
1426
1427 //-----------------------------------------------------
1428 if( (*pParameters)(m_Prefix + "USER_FITS")->asInt() == 1 ) // fit to cells
1429 {
1430 r.Inflate(0.5 * Size, false);
1431 }
1432
1433 bool bCallback = pParameters->Set_Callback(false);
1434
1435 pParameters->Set_Parameter(m_Prefix + "USER_SIZE", Size );
1436 pParameters->Set_Parameter(m_Prefix + "USER_XMIN", r.Get_XMin());
1437 pParameters->Set_Parameter(m_Prefix + "USER_XMAX", r.Get_XMax());
1438 pParameters->Set_Parameter(m_Prefix + "USER_YMIN", r.Get_YMin());
1439 pParameters->Set_Parameter(m_Prefix + "USER_YMAX", r.Get_YMax());
1440 pParameters->Set_Parameter(m_Prefix + "USER_COLS", Cols );
1441 pParameters->Set_Parameter(m_Prefix + "USER_ROWS", Rows );
1442
1443 pParameters->Set_Callback(bCallback);
1444
1445 return( true );
1446 }
1447
1448 //---------------------------------------------------------
1449 /**
1450 * Initializes the grid system from 'pPoints' extent and fits number of columns/rows to the average point density.
1451 * Number of columns/rows can be increased if 'Scale' is greater than 1.
1452 */
Set_User_Defined(CSG_Parameters * pParameters,CSG_Shapes * pPoints,int Scale,int Rounding)1453 bool CSG_Parameters_Grid_Target::Set_User_Defined(CSG_Parameters *pParameters, CSG_Shapes *pPoints, int Scale, int Rounding)
1454 {
1455 if( !pPoints || pPoints->Get_Count() <= 0 || pPoints->Get_Extent().Get_Area() <= 0. )
1456 {
1457 return( false );
1458 }
1459
1460 CSG_Rect r = pPoints->Get_Extent();
1461
1462 double Size = sqrt(r.Get_Area() / pPoints->Get_Count()) / (Scale > 1 ? Scale : 1); // edge length of a square given as average area per point (cell size)
1463
1464 if( Rounding > 0 )
1465 {
1466 Size = SG_Get_Rounded_To_SignificantFigures(Size, Rounding);
1467
1468 r.m_rect.xMin = Size * floor(r.m_rect.xMin / Size);
1469 r.m_rect.xMax = Size * ceil (r.m_rect.xMax / Size);
1470 r.m_rect.yMin = Size * floor(r.m_rect.yMin / Size);
1471 r.m_rect.yMax = Size * ceil (r.m_rect.yMax / Size);
1472 }
1473
1474 int Rows = 1 + (int)(0.5 + r.Get_YRange() / Size);
1475
1476 return( Set_User_Defined(pParameters, r, Rows, 0) );
1477 }
1478
1479 //---------------------------------------------------------
1480 /**
1481 * Initializes the grid system from 'System', if it represents a valid grid system.
1482 */
Set_User_Defined(CSG_Parameters * pParameters,const CSG_Grid_System & System)1483 bool CSG_Parameters_Grid_Target::Set_User_Defined(CSG_Parameters *pParameters, const CSG_Grid_System &System)
1484 {
1485 return( System.is_Valid() && Set_User_Defined(pParameters, System.Get_Extent(), System.Get_NY(), 0) );
1486 }
1487
1488 //---------------------------------------------------------
1489 /**
1490 * Initializes the grid system from lower left cell center coordinate, cell size and number of columns and rows (nx, ny).
1491 */
Set_User_Defined(CSG_Parameters * pParameters,double xMin,double yMin,double Cellsize,int nx,int ny)1492 bool CSG_Parameters_Grid_Target::Set_User_Defined(CSG_Parameters *pParameters, double xMin, double yMin, double Cellsize, int nx, int ny)
1493 {
1494 return( Set_User_Defined(pParameters, CSG_Grid_System(Cellsize, xMin, yMin, nx, ny)) );
1495 }
1496
1497 //---------------------------------------------------------
1498 /**
1499 * Initializes the grid collection's z level arrangement.
1500 */
Set_User_Defined_ZLevels(CSG_Parameters * pParameters,double zMin,double zMax,int nLevels,int Rounding)1501 bool CSG_Parameters_Grid_Target::Set_User_Defined_ZLevels(CSG_Parameters *pParameters, double zMin, double zMax, int nLevels, int Rounding)
1502 {
1503 if( !m_pParameters->Get_Tool()->has_GUI() ) // no cancel button, so set parameters directly
1504 {
1505 pParameters = m_pParameters;
1506 }
1507
1508 if( !m_pParameters || !pParameters || m_pParameters->Get_Identifier().Cmp(pParameters->Get_Identifier()) )
1509 {
1510 return( false );
1511 }
1512
1513 if( nLevels < 1 )
1514 {
1515 nLevels = 100;
1516 }
1517
1518 //-----------------------------------------------------
1519 if( zMin > zMax )
1520 {
1521 double z = zMin; zMin = zMax; zMax = z;
1522 }
1523
1524 if( zMax - zMin <= 0. )
1525 {
1526 zMin -= 0.5 * nLevels;
1527 zMax += 0.5 * nLevels; // assume cellsize = 1.
1528 }
1529
1530 //-----------------------------------------------------
1531 double Size = (zMax - zMin) / (nLevels - 1.);
1532
1533 if( Rounding > 0 )
1534 {
1535 Size = SG_Get_Rounded_To_SignificantFigures(Size, Rounding);
1536
1537 zMin = Size * floor(zMin / Size);
1538 zMax = Size * ceil (zMax / Size);
1539 }
1540
1541 //-----------------------------------------------------
1542 if( (*pParameters)(m_Prefix + "USER_FITS")->asInt() == 1 )
1543 {
1544 zMin -= 0.5 * Size;
1545 zMax += 0.5 * Size;
1546 }
1547
1548 bool bCallback = pParameters->Set_Callback(false);
1549
1550 pParameters->Set_Parameter(m_Prefix + "USER_ZSIZE", Size );
1551 pParameters->Set_Parameter(m_Prefix + "USER_ZMIN" , zMin );
1552 pParameters->Set_Parameter(m_Prefix + "USER_ZMAX" , zMax );
1553 pParameters->Set_Parameter(m_Prefix + "USER_ZNUM" , nLevels);
1554
1555 pParameters->Set_Callback(bCallback);
1556
1557 return( true );
1558 }
1559
1560
1561 ///////////////////////////////////////////////////////////
1562 // //
1563 ///////////////////////////////////////////////////////////
1564
1565 //---------------------------------------------------------
Add_Grid(const CSG_String & Identifier,const CSG_String & Name,bool bOptional)1566 bool CSG_Parameters_Grid_Target::Add_Grid(const CSG_String &Identifier, const CSG_String &Name, bool bOptional)
1567 {
1568 if( !m_pParameters || Identifier.Length() == 0 || (*m_pParameters)(Identifier) != NULL )
1569 {
1570 return( false );
1571 }
1572
1573 CSG_Parameter *pTarget = (*m_pParameters)(m_Prefix + "DEFINITION");
1574 CSG_Parameter *pSystem = NULL;
1575
1576 for(int i=0; i<pTarget->Get_Children_Count() && !pSystem; i++)
1577 {
1578 if( pTarget->Get_Child(i)->Get_Type() == PARAMETER_TYPE_Grid_System )
1579 {
1580 pSystem = pTarget->Get_Child(i);
1581 }
1582 }
1583
1584 m_pParameters->Add_Grid (pSystem ? pSystem->Get_Identifier() : SG_T(""), Identifier, Name, _TL(""), bOptional ? PARAMETER_OUTPUT_OPTIONAL : PARAMETER_OUTPUT, false);
1585
1586 if( bOptional && m_pParameters->Get_Tool()->has_GUI() )
1587 {
1588 CSG_Parameter *pNode = (*m_pParameters)(m_Prefix + "USER_OPTS");
1589
1590 if( !pNode )
1591 {
1592 pNode = m_pParameters->Add_Node(pTarget->Get_Identifier(), m_Prefix + "USER_OPTS", _TL("Optional Target Grids"), _TL(""));
1593 }
1594
1595 m_pParameters->Add_Bool(pNode->Get_Identifier(), Identifier + "_CREATE", Name, _TL(""), false);
1596 }
1597
1598 return( true );
1599 }
1600
1601 //---------------------------------------------------------
Add_Grids(const CSG_String & Identifier,const CSG_String & Name,bool bOptional,bool bZLevels)1602 bool CSG_Parameters_Grid_Target::Add_Grids(const CSG_String &Identifier, const CSG_String &Name, bool bOptional, bool bZLevels)
1603 {
1604 if( !m_pParameters || Identifier.Length() == 0 || (*m_pParameters)(Identifier) != NULL )
1605 {
1606 return( false );
1607 }
1608
1609 CSG_Parameter *pTarget = (*m_pParameters)(m_Prefix + "DEFINITION");
1610 CSG_Parameter *pSystem = NULL;
1611
1612 for(int i=0; i<pTarget->Get_Children_Count() && !pSystem; i++)
1613 {
1614 if( pTarget->Get_Child(i)->Get_Type() == PARAMETER_TYPE_Grid_System )
1615 {
1616 pSystem = pTarget->Get_Child(i);
1617 }
1618 }
1619
1620 m_pParameters->Add_Grids(pSystem ? pSystem->Get_Identifier() : SG_T(""), Identifier, Name, _TL(""), bOptional ? PARAMETER_OUTPUT_OPTIONAL : PARAMETER_OUTPUT, false);
1621
1622 if( bOptional && m_pParameters->Get_Tool()->has_GUI() )
1623 {
1624 CSG_Parameter *pNode = (*m_pParameters)(m_Prefix + "USER_OPTS");
1625
1626 if( !pNode )
1627 {
1628 pNode = m_pParameters->Add_Node(pTarget->Get_Identifier(), m_Prefix + "USER_OPTS", _TL("Optional Target Grids"), _TL(""));
1629 }
1630
1631 m_pParameters->Add_Bool(pNode->Get_Identifier(), Identifier + "_CREATE", Name, _TL(""), false);
1632 }
1633
1634 if( bZLevels )
1635 {
1636 pTarget = m_pParameters->Add_Node(pTarget, "USER_Z", _TL("Z Levels"), _TL(""));
1637
1638 m_pParameters->Add_Double(pTarget, m_Prefix + "USER_ZSIZE", _TL("Cellsize"), _TL(""), 1., 0., true);
1639 m_pParameters->Add_Double(pTarget, m_Prefix + "USER_ZMIN" , _TL("Bottom" ), _TL(""), 0.);
1640 m_pParameters->Add_Double(pTarget, m_Prefix + "USER_ZMAX" , _TL("Top" ), _TL(""), 100.);
1641 m_pParameters->Add_Int (pTarget, m_Prefix + "USER_ZNUM" , _TL("Levels" ), _TL(""), 101, 1, true);
1642 }
1643
1644 return( true );
1645 }
1646
1647
1648 ///////////////////////////////////////////////////////////
1649 // //
1650 ///////////////////////////////////////////////////////////
1651
1652 //---------------------------------------------------------
Get_System(void)1653 CSG_Grid_System CSG_Parameters_Grid_Target::Get_System(void)
1654 {
1655 CSG_Grid_System System;
1656
1657 if( m_pParameters )
1658 {
1659 if( (*m_pParameters)(m_Prefix + "DEFINITION")->asInt() == 0 ) // user defined
1660 {
1661 double Size = (*m_pParameters)(m_Prefix + "USER_SIZE")->asDouble();
1662
1663 CSG_Rect r(
1664 (*m_pParameters)(m_Prefix + "USER_XMIN")->asDouble(),
1665 (*m_pParameters)(m_Prefix + "USER_YMIN")->asDouble(),
1666 (*m_pParameters)(m_Prefix + "USER_XMAX")->asDouble(),
1667 (*m_pParameters)(m_Prefix + "USER_YMAX")->asDouble()
1668 );
1669
1670 if( (*m_pParameters)(m_Prefix + "USER_FITS")->asInt() == 1 )
1671 {
1672 r.Deflate(0.5 * Size, false);
1673 }
1674
1675 System.Assign(Size, r);
1676 }
1677 else
1678 {
1679 CSG_Parameter *pParameter = (*m_pParameters)(m_Prefix + "SYSTEM");
1680
1681 if( pParameter->asGrid_System() )
1682 {
1683 System.Assign(*pParameter->asGrid_System());
1684 }
1685 }
1686 }
1687
1688 return( System );
1689 }
1690
1691 //---------------------------------------------------------
Get_Grid(const CSG_String & Identifier,TSG_Data_Type Type)1692 CSG_Grid * CSG_Parameters_Grid_Target::Get_Grid(const CSG_String &Identifier, TSG_Data_Type Type)
1693 {
1694 if( !m_pParameters )
1695 {
1696 return( NULL );
1697 }
1698
1699 CSG_Parameter *pParameter = (*m_pParameters)(Identifier);
1700
1701 if( !pParameter || pParameter->Get_Type() != PARAMETER_TYPE_Grid )
1702 {
1703 return( NULL );
1704 }
1705
1706 CSG_Grid_System System(Get_System());
1707
1708 if( !System.is_Valid() )
1709 {
1710 return( NULL );
1711 }
1712
1713 CSG_Parameter *pSystem = (*m_pParameters)(m_Prefix + "SYSTEM");
1714
1715 if( pSystem->asGrid_System() && !pSystem->asGrid_System()->is_Equal(System) )
1716 {
1717 pSystem->asGrid_System()->Assign(System);
1718 }
1719
1720 CSG_Grid *pGrid = NULL;
1721
1722 if( (*m_pParameters)(m_Prefix + "DEFINITION")->asInt() == 0 && m_pParameters->Get_Tool()->has_GUI() )
1723 {
1724 if( (*m_pParameters)(Identifier + "_CREATE") == NULL
1725 || (*m_pParameters)(Identifier + "_CREATE")->asBool() )
1726 {
1727 pGrid = SG_Create_Grid(System, Type);
1728 }
1729 }
1730 else
1731 {
1732 pGrid = pParameter->asGrid();
1733
1734 if( pParameter->asPointer() == DATAOBJECT_CREATE || (!pGrid && !pParameter->is_Optional()) )
1735 {
1736 pGrid = SG_Create_Grid(System, Type);
1737 }
1738 else if( pGrid && pGrid->Get_Type() != Type )
1739 {
1740 pGrid->Create(pGrid->Get_System(), Type);
1741 }
1742 }
1743
1744 if( pGrid && pGrid != pParameter->asGrid() )
1745 {
1746 pParameter->Set_Value(pGrid);
1747 }
1748
1749 return( pGrid );
1750 }
1751
1752
1753 ///////////////////////////////////////////////////////////
1754 // //
1755 ///////////////////////////////////////////////////////////
1756
1757 //---------------------------------------------------------
Get_Grid(TSG_Data_Type Type)1758 CSG_Grid * CSG_Parameters_Grid_Target::Get_Grid(TSG_Data_Type Type)
1759 {
1760 return( Get_Grid(m_Prefix + "OUT_GRID", Type) );
1761 }
1762
1763 //---------------------------------------------------------
Get_Grids(const CSG_String & Identifier,TSG_Data_Type Type)1764 CSG_Grids * CSG_Parameters_Grid_Target::Get_Grids(const CSG_String &Identifier, TSG_Data_Type Type)
1765 {
1766 if( !m_pParameters )
1767 {
1768 return( NULL );
1769 }
1770
1771 CSG_Parameter *pParameter = (*m_pParameters)(Identifier);
1772
1773 if( !pParameter || pParameter->Get_Type() != PARAMETER_TYPE_Grids )
1774 {
1775 return( NULL );
1776 }
1777
1778 CSG_Grid_System System(Get_System());
1779
1780 if( !System.is_Valid() )
1781 {
1782 return( NULL );
1783 }
1784
1785 CSG_Grids *pGrids = NULL;
1786
1787 if( (*m_pParameters)(m_Prefix + "DEFINITION")->asInt() == 0
1788 && (*m_pParameters)(Identifier + "_CREATE") )
1789 {
1790 if( (*m_pParameters)(Identifier + "_CREATE")->asBool() )
1791 {
1792 pGrids = SG_Create_Grids(System, 0, 0., Type);
1793 }
1794 }
1795 else
1796 {
1797 pGrids = pParameter->asGrids();
1798
1799 if( pParameter->asPointer() == DATAOBJECT_CREATE || (!pGrids && !pParameter->is_Optional()) )
1800 {
1801 pGrids = SG_Create_Grids(System, 0, 0., Type);
1802 }
1803 }
1804
1805 if( pGrids && pGrids != pParameter->asGrids() )
1806 {
1807 pParameter->Set_Value(pGrids);
1808 }
1809
1810 if( pGrids
1811 && (*m_pParameters)(m_Prefix + "USER_ZSIZE")
1812 && (*m_pParameters)(m_Prefix + "USER_ZMIN" )
1813 && (*m_pParameters)(m_Prefix + "USER_ZNUM" ) )
1814 {
1815 int nz = (*m_pParameters)(m_Prefix + "USER_ZNUM" )->asInt ();
1816 double z = (*m_pParameters)(m_Prefix + "USER_ZMIN" )->asDouble();
1817 double dz = (*m_pParameters)(m_Prefix + "USER_ZSIZE")->asDouble();
1818
1819 pGrids->Del_Grids();
1820
1821 for(int iz=0; iz<nz; iz++, z+=dz)
1822 {
1823 pGrids->Add_Grid(z);
1824 }
1825 }
1826
1827 return( pGrids );
1828 }
1829
1830 //---------------------------------------------------------
Get_Grids(TSG_Data_Type Type)1831 CSG_Grids * CSG_Parameters_Grid_Target::Get_Grids(TSG_Data_Type Type)
1832 {
1833 return( Get_Grids(m_Prefix + "OUT_GRIDS", Type) );
1834 }
1835
1836
1837 ///////////////////////////////////////////////////////////
1838 // //
1839 // //
1840 // //
1841 ///////////////////////////////////////////////////////////
1842
1843 //---------------------------------------------------------
1844