SAGA API v9.10
Loading...
Searching...
No Matches
tool_summary.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// tool_summary.cpp //
15// //
16// Copyright (C) 2018 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 Hamburg //
44// Germany //
45// //
46// e-mail: oconrad@saga-gis.org //
47// //
49
50//---------------------------------------------------------
51#include "saga_api.h"
52
53
55// //
56// XML tags for mark-up of tool synopsis //
57// //
59
60//---------------------------------------------------------
61#define SG_XML_SYSTEM SG_T("system")
62#define SG_XML_SYSTEM_VER SG_T("version")
63#define SG_XML_SYSTEM_MLP SG_T("library-path")
64#define SG_XML_LIBRARY SG_T("library")
65#define SG_XML_LIBRARY_PATH SG_T("path")
66#define SG_XML_LIBRARY_NAME SG_T("name")
67#define SG_XML_LIBRARY_CATEGORY SG_T("category")
68#define SG_XML_TOOL SG_T("module")
69#define SG_XML_TOOL_ATT_NAME SG_T("name")
70#define SG_XML_TOOL_ATT_ID SG_T("id")
71#define SG_XML_TOOL_ATT_VERSION SG_T("version")
72#define SG_XML_TOOL_ATT_AUTHOR SG_T("author")
73#define SG_XML_SPECIFICATION SG_T("specification")
74#define SG_XML_SPEC_ATT_GRID SG_T("grid")
75#define SG_XML_SPEC_ATT_INTERA SG_T("interactive")
76#define SG_XML_MENU SG_T("menu")
77#define SG_XML_DESCRIPTION SG_T("description")
78#define SG_XML_PARAM SG_T("parameter")
79#define SG_XML_PARAM_ATT_NAME SG_T("name")
80#define SG_XML_PARAM_ATT_CLASS SG_T("class")
81#define SG_XML_PARAM_MANDATORY SG_T("mandatory")
82#define SG_XML_PARAM_WITH_GUI SG_T("with_gui")
83#define SG_XML_PARAM_WITH_CMD SG_T("with_cmd")
84#define SG_XML_PARAM_TYPE SG_T("type")
85#define SG_XML_PARAM_IDENTIFIER SG_T("identifier")
86#define SG_XML_PARAM_PARENT SG_T("parent")
87#define SG_XML_PARAM_LIST SG_T("list")
88#define SG_XML_PARAM_ITEM SG_T("item")
89#define SG_XML_PARAM_TABLE SG_T("table")
90#define SG_XML_PARAM_FIELD SG_T("field")
91#define SG_XML_PARAM_FIELD_ATT_NAME SG_T("name")
92#define SG_XML_PARAM_FIELD_ATT_TYPE SG_T("type")
93#define SG_XML_PARAM_MIN SG_T("min")
94#define SG_XML_PARAM_MAX SG_T("max")
95#define SG_XML_PARAM_DEFAULT SG_T("default")
96
97//---------------------------------------------------------
98#define SG_GET_XML_TAGGED_STR(value, tag) CSG_String::Format("<%s>%s</%s>", tag, value, tag)
99#define SG_GET_XML_TAGGED_INT(value, tag) CSG_String::Format("<%s>%d</%s>", tag, value, tag)
100#define SG_GET_XML_TAGGED_FLT(value, tag) CSG_String::Format("<%s>%f</%s>", tag, value, tag)
101
102
104// //
105// Tool //
106// //
108
109//---------------------------------------------------------
110void SG_XML_Add_Parameter(CSG_MetaData *pParent, CSG_Parameter *pParameter, CSG_String ID = "")
111{
112 if( !ID.is_Empty() ) { ID += "_"; } ID += pParameter->Get_Identifier();
113
114 CSG_MetaData *pItem = pParent->Add_Child(SG_XML_PARAM);
115
116 pItem->Add_Property(SG_XML_PARAM_ATT_NAME , pParameter->Get_Name());
117 pItem->Add_Property(SG_XML_PARAM_ATT_CLASS, pParameter->is_Input() ? "input" : pParameter->is_Output() ? "output" : "option");
118
120
121 if( pParameter->Get_Type() == PARAMETER_TYPE_DataObject_Output )
122 {
124 pParameter->Get_Type_Name().Make_Lower().c_str(),
125 SG_Get_DataObject_Name(pParameter->Get_DataObject_Type()).Make_Lower().c_str()
126 ));
127 }
128 else
129 {
130 pItem->Add_Child(SG_XML_PARAM_TYPE , pParameter->Get_Type_Name().Make_Lower());
131 }
132
133 pItem->Add_Child(SG_XML_DESCRIPTION, pParameter->Get_Description());
134
135 if( !pParameter->is_Option() )
136 {
137 pItem->Add_Child(SG_XML_PARAM_MANDATORY, pParameter->is_Optional() ? "false" : "true");
138 }
139
140 if( !pParameter->do_UseInGUI() ) pItem->Add_Child(SG_XML_PARAM_WITH_GUI, "false");
141 if( !pParameter->do_UseInCMD() ) pItem->Add_Child(SG_XML_PARAM_WITH_CMD, "false");
142
143 switch( pParameter->Get_Type() )
144 {
145 //-----------------------------------------------------
147 pItem->Add_Child(SG_XML_PARAM_DEFAULT, pParameter->asBool());
148 break;
149
150 //-----------------------------------------------------
154 if( pParameter->asValue()->has_Minimum() ) pItem->Add_Child(SG_XML_PARAM_MIN , pParameter->asValue()->Get_Minimum());
155 if( pParameter->asValue()->has_Maximum() ) pItem->Add_Child(SG_XML_PARAM_MAX , pParameter->asValue()->Get_Maximum());
156 if( !pParameter->Get_Default().is_Empty() ) pItem->Add_Child(SG_XML_PARAM_DEFAULT, pParameter ->Get_Default());
157 break;
158
159 //-----------------------------------------------------
161 break;
162
164 break;
165
166 //-----------------------------------------------------
169 {
170 CSG_MetaData *pChild = pItem->Add_Child(SG_XML_PARAM_LIST);
171
172 for(int i=0; i<pParameter->asChoice()->Get_Count(); i++)
173 {
174 pChild->Add_Child(SG_XML_PARAM_ITEM, pParameter->asChoice()->Get_Item(i));
175 }
176
177 if( !pParameter->asChoice()->Get_Default().is_Empty() )
178 {
179 pItem->Add_Child(SG_XML_PARAM_DEFAULT, pParameter->asChoice()->Get_Default());
180 }
181 }
182 break;
183
184 //-----------------------------------------------------
186 {
187 CSG_MetaData *pChild = pItem->Add_Child(SG_XML_PARAM_LIST);
188
189 for(int i=0; i<pParameter->asChoices()->Get_Item_Count(); i++)
190 {
191 pChild->Add_Child(SG_XML_PARAM_ITEM, pParameter->asChoices()->Get_Item(i));
192 }
193
194 if( !pParameter->asChoices()->Get_Default().is_Empty() )
195 {
196 pItem->Add_Child(SG_XML_PARAM_DEFAULT, pParameter->asChoices()->Get_Default());
197 }
198 }
199 break;
200
201 //-----------------------------------------------------
205 break;
206
208 break;
209
212 break;
213
214 //-----------------------------------------------------
216 {
217 CSG_MetaData *pChild = pItem->Add_Child(SG_XML_PARAM_TABLE);
218
219 for(int i=0; i<pParameter->asTable()->Get_Field_Count(); i++)
220 {
221 CSG_MetaData *pField = pChild->Add_Child(SG_XML_PARAM_FIELD);
222
225 }
226 }
227 break;
228
229 //-----------------------------------------------------
231 break;
232
233 //-----------------------------------------------------
236 if( pParameter->Get_Parent() )
237 {
238 pItem->Add_Child(SG_XML_PARAM_PARENT, pParameter->Get_Parent()->Get_Identifier());
239 }
240 break;
241
242 //-----------------------------------------------------
244 {
245 for(int i=0; i<pParameter->asParameters()->Get_Count(); i++)
246 {
247 SG_XML_Add_Parameter(pItem, pParameter->asParameters()->Get_Parameter(i), ID);
248 }
249 }
250
251 //-----------------------------------------------------
252 default:
253 break;
254 }
255}
256
257//---------------------------------------------------------
258CSG_String CSG_Tool::Get_Summary(bool bParameters, const CSG_String &Menu, const CSG_String &Description, int Format)
259{
260 CSG_String s;
261
262 //-----------------------------------------------------
263 switch( Format )
264 {
266 {
267 CSG_MetaData m;
268
276 m.Add_Child (SG_XML_SPEC_ATT_GRID , is_Grid () ? "true" : "false");
277 m.Add_Child (SG_XML_SPEC_ATT_INTERA , is_Interactive () ? "true" : "false");
278
279 // CSG_MetaData *pChild = m.Add_Child(SG_XML_SPECIFICATION);
280 // pChild->Add_Property(SG_XML_SPEC_ATT_GRID , is_Grid () ? "true" : "false");
281 // pChild->Add_Property(SG_XML_SPEC_ATT_INTERA, is_Interactive () ? "true" : "false");
282
283 if( bParameters )
284 {
285 for(int i=0; i<Parameters.Get_Count(); i++)
286 {
287 if( Parameters(i)->is_Input() )
288 {
290 }
291 }
292
293 for(int i=0; i<Parameters.Get_Count(); i++)
294 {
295 if( Parameters(i)->is_Output() )
296 {
298 }
299 }
300
301 for(int i=0; i<Parameters.Get_Count(); i++)
302 {
303 if( Parameters(i)->is_Option()
306 {
308 }
309 }
310 }
311
312 s = m.asText(1);
313 }
314 break;
315
316 //-----------------------------------------------------
318 {
319 #define SUMMARY_ADD_STR(label, value) CSG_String::Format("<tr><td valign=\"top\"><b>%s</b></td><td valign=\"top\">%s</td></tr>", label, value)
320 #define SUMMARY_ADD_INT(label, value) CSG_String::Format("<tr><td valign=\"top\"><b>%s</b></td><td valign=\"top\">%d</td></tr>", label, value)
321
322 s += CSG_String::Format("<h4>%s</h4><table border=\"0\">", _TL("Tool"));
323
324 s += SUMMARY_ADD_STR(_TL("Name" ), Get_Name ().c_str());
325 s += SUMMARY_ADD_STR(_TL("Author" ), Get_Author ().c_str());
326 s += SUMMARY_ADD_STR(_TL("Version"), Get_Version().c_str());
327 s += SUMMARY_ADD_STR(_TL("Library"), Get_Library().c_str());
328 s += SUMMARY_ADD_STR(_TL("ID" ), Get_ID ().c_str());
329
330 if( is_Interactive() && is_Grid() )
331 {
332 s += SUMMARY_ADD_STR(_TL("Specification"), CSG_String::Format("%s, %s", _TL("grid"), _TL("interactive")).c_str() );
333 }
334 else if( is_Interactive() )
335 {
336 s += SUMMARY_ADD_STR(_TL("Specification"), _TL("interactive"));
337 }
338 else if( is_Grid() )
339 {
340 s += SUMMARY_ADD_STR(_TL("Specification"), _TL("grid"));
341 }
342
343 if( Get_Type() == TOOL_TYPE_Chain )
344 {
345 s += SUMMARY_ADD_STR(_TL("File"), Get_File_Name().c_str() );
346 }
347
348 if( Menu.Length() > 0 )
349 {
350 CSG_String sMenu(Menu);
351
352 sMenu.Replace("|", " <b>></b> ");
353 sMenu.Replace(";", " <br> ");
354
355 s += SUMMARY_ADD_STR(_TL("Menu" ), sMenu.c_str());
356 }
357
358 s += "</table>";
359
360 #undef SUMMARY_ADD_STR
361 #undef SUMMARY_ADD_INT
362
363 //---------------------------------------------
364 s += CSG_String::Format("<hr><h4>%s</h4>", _TL("Description"));
365
366 s += !Description.is_Empty() ? Description : Get_Description();
367
368 //---------------------------------------------
369 if( Description.is_Empty() && Get_References().Get_Count() > 0 )
370 {
371 s += CSG_String::Format("<hr><h4>%s</h4><ul>", _TL("References"));
372
373 for(int i=0; i<Get_References().Get_Count(); i++)
374 {
375 s += "<li>" + Get_References()[i] + "</li>";
376 }
377
378 s += "</ul>";
379 }
380
381 //---------------------------------------------
382 if( bParameters )
383 {
384 s += CSG_String::Format("<hr><h4>%s</h4>", _TL("Parameters"));
385 s += CSG_String::Format("<table border=\"1\" width=\"100%%\" valign=\"top\" cellpadding=\"5\" rules=\"all\"><tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n",
386 _TL("Name"), _TL("Type"), _TL("Identifier"), _TL("Description"), _TL("Constraints")
387 );
388
389 //-----------------------------------------
390 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
391 {
392 CSG_Parameter *pParameter = Parameters(i);
393
394 if( pParameter->is_Input() )
395 {
396 if( bFirst )
397 {
398 bFirst = 0; s += CSG_String::Format("<tr><th colspan=\"5\">%s</th></tr>", _TL("Input"));
399 }
400
401 s += CSG_String::Format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
402 pParameter->Get_Name(),
403 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE).c_str(), pParameter->do_UseInCMD() ?
404 pParameter->Get_Identifier () : SG_T(""),
405 pParameter->Get_Description(),
407 );
408 }
409 }
410
411 //-----------------------------------------
412 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
413 {
414 CSG_Parameter *pParameter = Parameters(i);
415
416 if( pParameter->is_Output() )
417 {
418 if( bFirst )
419 {
420 bFirst = 0; s += CSG_String::Format("<tr><th colspan=\"5\">%s</th></tr>", _TL("Output"));
421 }
422
423 s += CSG_String::Format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
424 pParameter->Get_Name(),
425 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE).c_str(), pParameter->do_UseInCMD() ?
426 pParameter->Get_Identifier () : SG_T(""),
427 pParameter->Get_Description(),
429 );
430 }
431 }
432
433 //-----------------------------------------
434 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
435 {
436 CSG_Parameter *pParameter = Parameters(i);
437
438 if( pParameter->is_Option() && pParameter->Get_Type() != PARAMETER_TYPE_Grid_System )
439 {
440 if( bFirst )
441 {
442 bFirst = 0; s += CSG_String::Format("<tr><th colspan=\"5\">%s</th></tr>", _TL("Options"));
443 }
444
445 s += CSG_String::Format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
446 pParameter->Get_Name(),
447 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE).c_str(), pParameter->do_UseInCMD() ?
448 pParameter->Get_Identifier () : SG_T(""),
449 pParameter->Get_Description(),
451 );
452 }
453 }
454
455 //-----------------------------------------
456 s += "</table>";
457
458 s.Replace("\n", "<br>");
459 }
460 }
461 break;
462
463 //-----------------------------------------------------
464 case SG_SUMMARY_FMT_FLAT: default:
465 {
466 #define SUMMARY_ADD_STR(label, value) CSG_String::Format("%s:\t%s\n", label, value)
467 #define SUMMARY_ADD_INT(label, value) CSG_String::Format("%s:\t%d\n", label, value)
468
469 s += SUMMARY_ADD_STR(_TL("Name" ), Get_Name ().c_str());
470 s += SUMMARY_ADD_STR(_TL("ID" ), Get_ID ().c_str());
471 s += SUMMARY_ADD_STR(_TL("Author" ), Get_Author ().c_str());
472 s += SUMMARY_ADD_STR(_TL("Version"), Get_Version().c_str());
473
474 if( is_Interactive() && is_Grid() )
475 {
476 s += SUMMARY_ADD_STR(_TL("Specification"), CSG_String::Format("%s, %s", _TL("grid"), _TL("interactive")).c_str() );
477 }
478 else if( is_Interactive() )
479 {
480 s += SUMMARY_ADD_STR(_TL("Specification"), _TL("interactive"));
481 }
482 else if( is_Grid() )
483 {
484 s += SUMMARY_ADD_STR(_TL("Specification"), _TL("grid"));
485 }
486
487 if( Get_Type() == TOOL_TYPE_Chain )
488 {
489 s += SUMMARY_ADD_STR(_TL("File"), Get_File_Name().c_str() );
490 }
491
492 if( Menu.Length() > 0 )
493 {
494 s += SUMMARY_ADD_STR(_TL("Menu"), Menu.c_str());
495 }
496
497 #undef SUMMARY_ADD_STR
498 #undef SUMMARY_ADD_INT
499
500 //---------------------------------------------
501 s += "\n____________________________\n";
502
503 s += CSG_String::Format("%s:\n", _TL("Description"));
504
505 s += !Description.is_Empty() ? Description : SG_HTML_Tag_Replacer(Get_Description());
506
507 //---------------------------------------------
508 if( Description.is_Empty() && Get_References().Get_Count() > 0 )
509 {
510 s += "\n____________________________\n";
511
512 s += CSG_String::Format("\n%s:\n", _TL("References"));
513
514 for(int i=0; i<Get_References().Get_Count(); i++)
515 {
516 CSG_String Reference(Get_References()[i]);
517
518 Reference.Replace("<b>" , "");
519 Reference.Replace("</b>" , "");
520 Reference.Replace("<a href=\"", "");
521 Reference.Replace("\">" , " (");
522 Reference.Replace("</a>" , ")");
523
524 s += " - " + Reference + "\n";
525 }
526 }
527
528 //---------------------------------------------
529 if( bParameters )
530 {
531 s += "\n";
532
533 //-----------------------------------------
534 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
535 {
536 CSG_Parameter *pParameter = Parameters(i);
537
538 if( pParameter->is_Input() && (has_GUI() || pParameter->do_UseInCMD()) )
539 {
540 if( bFirst )
541 {
542 bFirst = 0;
543 s += "____________________________\n";
544 s += CSG_String::Format("%s:\n", _TL("Input"));
545 }
546
547 s += CSG_String::Format("_\n%s\n%s\n%s\n%s\n%s\n",
548 pParameter->Get_Name (),
549 pParameter->Get_Identifier (),
550 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE ).c_str(),
551 pParameter->Get_Description(),
553 );
554 }
555 }
556
557 //-----------------------------------------
558 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
559 {
560 CSG_Parameter *pParameter = Parameters(i);
561
562 if( pParameter->is_Output() && (has_GUI() || pParameter->do_UseInCMD()) )
563 {
564 if( bFirst )
565 {
566 bFirst = 0;
567 s += "____________________________\n";
568 s += CSG_String::Format("%s:\n", _TL("Output"));
569 }
570
571 s += CSG_String::Format("_\n%s\n%s\n%s\n%s\n%s\n",
572 pParameter->Get_Name (),
573 pParameter->Get_Identifier (),
574 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE ).c_str(),
575 pParameter->Get_Description(),
577 );
578 }
579 }
580
581 //-----------------------------------------
582 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
583 {
584 CSG_Parameter *pParameter = Parameters(i);
585
586 if( pParameter->is_Option() && (has_GUI() || pParameter->do_UseInCMD()) && pParameter->Get_Type() != PARAMETER_TYPE_Grid_System )
587 {
588 if( bFirst )
589 {
590 bFirst = 0;
591 s += "____________________________\n";
592 s += CSG_String::Format("%s:\n", _TL("Options"));
593 }
594
595 s += CSG_String::Format("_\n%s\n%s\n%s\n%s\n%s\n",
596 pParameter->Get_Name (),
597 pParameter->Get_Identifier (),
598 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE ).c_str(),
599 pParameter->Get_Description(),
601 );
602 }
603 }
604 }
605 }
606 break;
607 }
608
609 //-----------------------------------------------------
610 return( s );
611}
612
613
615// //
616// Tool Library //
617// //
619
620//---------------------------------------------------------
621CSG_String CSG_Tool_Library::Get_Summary(int Format, bool bWithGUINeeded) const
622{
623 bool bToolChains = Get_File_Name().is_Empty();
624
625 CSG_String s;
626
627 switch( Format )
628 {
629 //-----------------------------------------------------
631
632 s += "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
633 s += CSG_String::Format("<%s>\n" , SG_XML_LIBRARY);
634 s += CSG_String::Format("\t<%s>%s</%s>\n", SG_XML_LIBRARY_PATH, Get_File_Name().c_str(), SG_XML_LIBRARY_PATH);
637
638 for(int i=0; i<Get_Count(); i++)
639 {
640 if( Get_Tool(i) && (bWithGUINeeded || !Get_Tool(i)->needs_GUI()) )
641 {
642 CSG_String Name(Get_Tool(i)->Get_Name());
643 Name.Replace("&", "&amp;");
644 s += CSG_String::Format("\t<%s %s=\"%s\" %s=\"%s\"/>\n", SG_XML_TOOL,
645 SG_XML_TOOL_ATT_ID , Get_Tool(i)->Get_ID().c_str(),
647 );
648 }
649 }
650
651 s += CSG_String::Format("</%s>\n", SG_XML_LIBRARY);
652
653 break;
654
655 //-----------------------------------------------------
656 case SG_SUMMARY_FMT_HTML: default:
657
658 #define SUMMARY_ADD_STR(label, value) CSG_String::Format("<tr><td valign=\"top\"><b>%s</b></td><td valign=\"top\">%s</td></tr>", label, value)
659 #define SUMMARY_ADD_INT(label, value) CSG_String::Format("<tr><td valign=\"top\"><b>%s</b></td><td valign=\"top\">%d</td></tr>", label, value)
660
661 s += CSG_String::Format("<h4>%s</h4>", _TL("Tool Library"));
662
663 s += "<table border=\"0\">";
664
665 s += SUMMARY_ADD_STR(_TL("Name" ), Get_Info(TLB_INFO_Name ).c_str());
666 s += SUMMARY_ADD_STR(_TL("Author"), Get_Info(TLB_INFO_Author ).c_str());
667 s += SUMMARY_ADD_STR(_TL("ID" ), Get_Library_Name ().c_str());
668 s += SUMMARY_ADD_STR(_TL("File" ), Get_File_Name ().c_str());
669
670 s += "</table>";
671
672 //-------------------------------------------------
673 s += CSG_String::Format("<hr><h4>%s</h4>", _TL("Description"));
674
676
677 if( Get_References().Get_Count() > 0 )
678 {
679 s += CSG_String::Format("<hr><h4>%s</h4><ul>", _TL("References"));
680
681 for(int i=0; i<Get_References().Get_Count(); i++)
682 {
683 s += "<li>" + Get_References()[i] + "</li>";
684 }
685
686 s += "</ul>";
687 }
688
689 //-------------------------------------------------
690 s += CSG_String::Format("<hr><h4>%s</h4>", _TL("Tools"));
691
692 s += "<table border=\"0\">";
693
694 s += CSG_String::Format("<tr align=\"left\"><th>%s</th><th>%s</th></tr>", _TL("ID"), _TL("Name"));
695
696 for(int i=0; i<Get_Count(); i++)
697 {
698 if( Get_Tool(i) && (bWithGUINeeded || !Get_Tool(i)->needs_GUI()) )
699 {
700 s += SUMMARY_ADD_STR(Get_Tool(i)->Get_ID().c_str(), Get_Tool(i)->Get_Name().c_str());
701 }
702 }
703
704 s += "</table>";
705
706 s.Replace("\n", "<br>");
707
708 #undef SUMMARY_ADD_STR
709 #undef SUMMARY_ADD_INT
710
711 break;
712
713 //-----------------------------------------------------
715
716 if( !bToolChains )
717 {
718 s += CSG_String::Format("\n%s%s: ", _TL("Library"), SG_T(" ")) + Get_Info(TLB_INFO_Name );
719 s += CSG_String::Format("\n%s%s: ", _TL("Category"), SG_T(" ")) + Get_Info(TLB_INFO_Category);
720 s += CSG_String::Format("\n%s%s: ", _TL("File"), SG_T(" ")) + Get_File_Name();
721 }
722 else
723 {
724 s += CSG_String::Format("\n%s: ", _TL("Tool Chains")) + Get_Info(TLB_INFO_Name);
725 }
726
728
729 if( Get_References().Get_Count() > 0 )
730 {
731 s += CSG_String::Format("\n%s:\n", _TL("References"));
732
733 for(int i=0; i<Get_References().Get_Count(); i++)
734 {
735 s += " - " + Get_References()[i] + "\n";
736 }
737 }
738
739 s += CSG_String::Format("\n\n%s:\n", _TL("Tools"));
740
741 for(int i=0; i<Get_Count(); i++)
742 {
743 if( Get_Tool(i) && (bWithGUINeeded || !Get_Tool(i)->needs_GUI()) )
744 {
745 s += " [" + Get_Tool(i)->Get_ID() + "]\t" + Get_Tool(i)->Get_Name() + "\n";
746 }
747 }
748
749 break;
750 }
751
752 return( s );
753}
754
755
757// //
759
760//---------------------------------------------------------
761// Store tool and tool library description to HTML files.
762//---------------------------------------------------------
764{
765 CSG_File File;
766
767 if( File.Open(SG_File_Make_Path(Path, Get_Library_Name(), "html"), SG_FILE_W) )
768 {
769 File.Write(Get_Summary());
770 }
771
772 for(int i=0; i<Get_Count(); i++)
773 {
774 if( Get_Tool(i) && File.Open(SG_File_Make_Path(Path, Get_Library_Name() + "_" + Get_Tool(i)->Get_ID(), "html"), SG_FILE_W) )
775 {
776 File.Write(Get_Tool(i)->Get_Summary());
777 }
778 }
779
780 return( true );
781}
782
783
785// //
786// Tool Library Manager //
787// //
789
790//---------------------------------------------------------
792{
793 int nTools = 0; CSG_Table Libraries;
794
795 Libraries.Add_Field("LIB" , SG_DATATYPE_String);
796 Libraries.Add_Field("TOOLS", SG_DATATYPE_Int );
797 Libraries.Add_Field("NAME" , SG_DATATYPE_String);
798 Libraries.Add_Field("PATH" , SG_DATATYPE_String);
799 Libraries.Add_Field("CHAIN", SG_DATATYPE_Int );
800
801 for(int i=0; i<Get_Count(); i++)
802 {
803 if( Get_Library(i)->Get_Count() > 0 )
804 {
805 nTools += Get_Library(i)->Get_Count();
806
807 Libraries.Add_Record();
808
809 Libraries[i].Set_Value(0, Get_Library(i)->Get_Library_Name());
810 Libraries[i].Set_Value(1, Get_Library(i)->Get_Count());
811 Libraries[i].Set_Value(2, Get_Library(i)->Get_Name());
812 Libraries[i].Set_Value(3, SG_File_Get_Path(Get_Library(i)->Get_File_Name()));
813 Libraries[i].Set_Value(4, Get_Library(i)->Get_File_Name().is_Empty() ? 1 : 0);
814 }
815 }
816
818
819 //-----------------------------------------------------
820 CSG_String s;
821
822 switch( Format )
823 {
824 //-----------------------------------------------------
826
827 s += "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
828 s += CSG_String::Format("<%s>\n", SG_XML_SYSTEM);
830
831 for(int i=0; i<Libraries.Get_Count(); i++)
832 {
833 s += CSG_String::Format("\t<%s %s=\"%s\"/>\n", SG_XML_LIBRARY, SG_XML_LIBRARY_NAME, Libraries[i].asString(0));
834 }
835
836 s += CSG_String::Format("</%s>\n", SG_XML_SYSTEM);
837
838 break;
839
840 //-----------------------------------------------------
841 case SG_SUMMARY_FMT_HTML: default:
842
843 #define SUMMARY_ADD_INT(label, value) CSG_String::Format("<tr><td valign=\"top\"><b>%s</b></td><td valign=\"top\">%d</td></tr>", label, value)
844
845 s += CSG_String::Format("<h4>%s</h4>", _TL("Tool Libraries"));
846
847 s += "<table border=\"0\">";
848
849 s += SUMMARY_ADD_INT(_TL("Libraries"), Libraries.Get_Count());
850 s += SUMMARY_ADD_INT(_TL("Tools" ), nTools);
851
852 s += "</table>";
853
854 s += CSG_String::Format("<hr><h4>%s</h4><table border=\"1\">", _TL("Libraries"));
855
856 s += CSG_String::Format("<tr align=\"left\"><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>",
857 _TL("Library" ),
858 _TL("Tools" ),
859 _TL("Name" ),
860 _TL("Location")
861 );
862
863 for(int i=0; i<Libraries.Get_Count(); i++)
864 {
865 s += CSG_String::Format("<tr><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>",
866 Libraries[i].asString(0),
867 Libraries[i].asInt (1),
868 Libraries[i].asString(2),
869 Libraries[i].asString(3)
870 );
871 }
872
873 s += "</table>";
874
875 #undef SUMMARY_ADD_INT
876
877 break;
878
879 //-----------------------------------------------------
881
882 s += CSG_String::Format("\n%d %s (%d %s):\n", Libraries.Get_Count(), _TL("loaded tool libraries"), nTools, _TL("tools"));
883
884 for(int i=0; i<Libraries.Get_Count(); i++)
885 {
886 if( Libraries[i].asInt(4) == 0 )
887 s += CSG_String::Format(" - %s\n" , Libraries[i].asString(0));
888 else
889 s += CSG_String::Format(" - %s *\n", Libraries[i].asString(0));
890 }
891
892 s += CSG_String::Format("\n\n*) %s\n", _TL("tool chain libraries"));
893
894 break;
895 }
896
897 //-----------------------------------------------------
898 return( s );
899}
900
901
903// //
905
906//---------------------------------------------------------
907// Store tool and tool library description to HTML files.
908//---------------------------------------------------------
910{
911 for(int i=0; i<Get_Count(); i++)
912 {
913 CSG_Tool_Library *pLibrary = Get_Library(i);
914
915 CSG_String Directory = SG_File_Make_Path(Path, pLibrary->Get_Library_Name());
916
917 if( SG_Dir_Create(Directory) )
918 {
919 pLibrary->Get_Summary(Directory);
920 }
921 }
922
923 return( true );
924}
925
926
928// //
929// //
930// //
932
933//---------------------------------------------------------
CSG_String SG_Data_Type_Get_Name(TSG_Data_Type Type, bool bShort)
Definition api_core.cpp:123
SAGA_API_DLL_EXPORT CSG_String SG_HTML_Tag_Replacer(const CSG_String &Text)
SAGA_API_DLL_EXPORT bool SG_Dir_Create(const CSG_String &Directory, bool bFullPath=false)
Definition api_file.cpp:972
#define SG_T(s)
Definition api_core.h:537
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Path(const CSG_String &full_Path)
SAGA_API_DLL_EXPORT CSG_String SG_File_Make_Path(const CSG_String &Directory, const CSG_String &Name)
@ SG_DATATYPE_Int
Definition api_core.h:1004
@ SG_DATATYPE_String
Definition api_core.h:1009
#define _TL(s)
Definition api_core.h:1568
@ SG_FILE_W
Definition api_core.h:1115
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
Definition api_file.cpp:113
size_t Write(void *Buffer, size_t Size, size_t Count=1) const
Definition api_file.cpp:370
void Set_Name(const CSG_String &Name)
Definition metadata.h:130
CSG_String asText(int Flags=0) const
Definition metadata.cpp:698
CSG_MetaData * Add_Child(void)
Definition metadata.cpp:166
bool Add_Property(const CSG_String &Name, const CSG_String &Value)
Definition metadata.cpp:559
const SG_Char * Get_Item(int Index) const
const CSG_String & Get_Item(int i) const
Definition parameters.h:768
double Get_Minimum(void) const
Definition parameters.h:448
double Get_Maximum(void) const
Definition parameters.h:452
bool has_Maximum(void) const
Definition parameters.h:453
bool has_Minimum(void) const
Definition parameters.h:449
const SG_Char * Get_Identifier(void) const
class CSG_Parameters * asParameters(void) const
CSG_String Get_Type_Name(void) const
bool is_Optional(void) const
Definition parameters.h:238
TSG_Data_Object_Type Get_DataObject_Type(void) const
class CSG_Parameter_Choice * asChoice(void) const
class CSG_Parameter_Value * asValue(void) const
CSG_Parameter * Get_Parent(void) const
virtual TSG_Parameter_Type Get_Type(void) const =0
bool asBool(void) const
Definition parameters.h:286
bool is_Input(void) const
Definition parameters.h:236
const SG_Char * Get_Name(void) const
class CSG_Parameter_Choices * asChoices(void) const
bool is_Option(void) const
bool is_Output(void) const
Definition parameters.h:237
bool do_UseInCMD(void) const
const CSG_String & Get_Default(void) const
CSG_Table * asTable(void) const
const SG_Char * Get_Description(void) const
bool do_UseInGUI(void) const
CSG_Parameter * Get_Parameter(int i) const
size_t Length(void) const
size_t Replace(const CSG_String &Old, const CSG_String &New, bool bReplaceAll=true)
static CSG_String Format(const char *Format,...)
const SG_Char * c_str(void) const
CSG_String & Make_Lower(void)
bool is_Empty(void) const
int Get_Count(void) const
Definition api_core.h:714
const SG_Char * Get_Field_Name(int Field) const
Definition table.h:362
sLong Get_Count(void) const
Definition table.h:400
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
Definition table.cpp:823
bool Set_Index(CSG_Index &Index, int Field, bool bAscending=true) const
Definition table.cpp:1508
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
Definition table.cpp:479
virtual bool Set_Value(sLong Index, int Field, const SG_Char *Value)
Definition table.cpp:1159
TSG_Data_Type Get_Field_Type(int Field) const
Definition table.h:363
CSG_String Get_Summary(int Format=SG_SUMMARY_FMT_HTML) const
int Get_Count(void) const
CSG_Tool_Library * Get_Library(int i) const
virtual CSG_Tool * Get_Tool(int Index, TSG_Tool_Type Type=TOOL_TYPE_Base) const
const CSG_String & Get_Library_Name(void) const
virtual CSG_String Get_Info(int Type) const
const CSG_Strings & Get_References(void) const
CSG_String Get_Summary(int Format=SG_SUMMARY_FMT_HTML, bool bInteractive=true) const
const CSG_String & Get_File_Name(void) const
virtual int Get_Count(void) const
CSG_String Get_Name(void) const
const CSG_String & Get_Library(void) const
Definition tool.cpp:115
const CSG_String & Get_File_Name(void) const
Definition tool.cpp:121
CSG_String Get_Summary(bool bParameters=true, const CSG_String &Menu="", const CSG_String &Description="", int Format=SG_SUMMARY_FMT_HTML)
bool has_GUI(void) const
Definition tool.cpp:239
const CSG_String & Get_Author(void) const
Definition tool.cpp:143
virtual bool is_Interactive(void) const
Definition tool.h:223
const CSG_String & Get_Name(void) const
Definition tool.cpp:132
const CSG_Strings & Get_References(void) const
Definition tool.cpp:181
CSG_Parameters Parameters
Definition tool.h:256
virtual TSG_Tool_Type Get_Type(void) const
Definition tool.h:148
virtual CSG_String Get_MenuPath(void)
Definition tool.h:162
virtual bool is_Grid(void) const
Definition tool.h:222
const CSG_String & Get_Version(void) const
Definition tool.cpp:154
const CSG_String & Get_Description(void) const
Definition tool.cpp:165
const CSG_String & Get_ID(void) const
Definition tool.h:150
CSG_String SG_Get_DataObject_Name(TSG_Data_Object_Type Type)
#define PARAMETER_DESCRIPTION_PROPERTIES
Definition parameters.h:110
#define PARAMETER_DESCRIPTION_TYPE
Definition parameters.h:108
@ PARAMETER_TYPE_Degree
Definition parameters.h:129
@ PARAMETER_TYPE_FixedTable
Definition parameters.h:142
@ PARAMETER_TYPE_Node
Definition parameters.h:124
@ PARAMETER_TYPE_Text
Definition parameters.h:136
@ PARAMETER_TYPE_Int
Definition parameters.h:127
@ PARAMETER_TYPE_Table_Fields
Definition parameters.h:146
@ PARAMETER_TYPE_Color
Definition parameters.h:140
@ PARAMETER_TYPE_Colors
Definition parameters.h:141
@ PARAMETER_TYPE_DataObject_Output
Definition parameters.h:162
@ PARAMETER_TYPE_Double
Definition parameters.h:128
@ PARAMETER_TYPE_Grid_System
Definition parameters.h:144
@ PARAMETER_TYPE_Font
Definition parameters.h:139
@ PARAMETER_TYPE_Date
Definition parameters.h:130
@ PARAMETER_TYPE_Choices
Definition parameters.h:134
@ PARAMETER_TYPE_Data_Type
Definition parameters.h:132
@ PARAMETER_TYPE_Range
Definition parameters.h:131
@ PARAMETER_TYPE_Table_Field
Definition parameters.h:145
@ PARAMETER_TYPE_Parameters
Definition parameters.h:164
@ PARAMETER_TYPE_FilePath
Definition parameters.h:137
@ PARAMETER_TYPE_Bool
Definition parameters.h:126
@ PARAMETER_TYPE_String
Definition parameters.h:135
@ PARAMETER_TYPE_Choice
Definition parameters.h:133
#define SAGA_VERSION
Definition saga_api.h:90
@ TABLE_INDEX_Ascending
Definition table.h:105
@ SG_SUMMARY_FMT_HTML
Definition tool.h:94
@ SG_SUMMARY_FMT_FLAT
Definition tool.h:93
@ SG_SUMMARY_FMT_XML
Definition tool.h:95
@ TLB_INFO_Name
Definition tool.h:637
@ TLB_INFO_Category
Definition tool.h:642
@ TLB_INFO_Description
Definition tool.h:638
@ TLB_INFO_Author
Definition tool.h:639
@ TOOL_TYPE_Chain
Definition tool.h:106
#define SG_XML_PARAM_ATT_CLASS
#define SG_XML_TOOL
#define SG_XML_PARAM_DEFAULT
#define SG_XML_MENU
#define SG_XML_LIBRARY_PATH
#define SG_XML_PARAM_FIELD_ATT_NAME
#define SG_XML_SYSTEM_VER
#define SG_XML_TOOL_ATT_AUTHOR
#define SG_XML_PARAM
#define SG_XML_PARAM_TABLE
#define SG_XML_PARAM_WITH_CMD
#define SG_XML_SYSTEM
#define SG_XML_PARAM_MAX
#define SUMMARY_ADD_INT(label, value)
#define SG_XML_TOOL_ATT_VERSION
#define SG_XML_PARAM_IDENTIFIER
#define SG_XML_SPEC_ATT_GRID
#define SUMMARY_ADD_STR(label, value)
#define SG_XML_PARAM_PARENT
#define SG_XML_PARAM_WITH_GUI
#define SG_XML_PARAM_ATT_NAME
#define SG_XML_LIBRARY_CATEGORY
#define SG_XML_LIBRARY
#define SG_XML_PARAM_LIST
#define SG_XML_PARAM_ITEM
#define SG_XML_PARAM_FIELD
#define SG_XML_PARAM_FIELD_ATT_TYPE
#define SG_XML_PARAM_MANDATORY
#define SG_XML_DESCRIPTION
void SG_XML_Add_Parameter(CSG_MetaData *pParent, CSG_Parameter *pParameter, CSG_String ID="")
#define SG_XML_PARAM_TYPE
#define SG_XML_SPEC_ATT_INTERA
#define SG_XML_TOOL_ATT_ID
#define SG_XML_PARAM_MIN
#define SG_XML_LIBRARY_NAME
#define SG_XML_TOOL_ATT_NAME