SAGA API Version 9.13
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 if( !Get_Dynamic_Description().is_Empty() )
369 {
370 s += "\n" + Get_Dynamic_Description();
371 }
372
373 //---------------------------------------------
374 if( Description.is_Empty() && Get_References_Table().Get_Count() > 0 )
375 {
376 s += CSG_String::Format("<hr><h4>%s</h4>", _TL("References"));
377
378 CSG_Strings Full(Get_References()), Link;
379
380 for(int i=Full.Get_Count()-1; i>=0; i--)
381 {
382 if( Full[i].Find("<a href") == 0 ) // pure link
383 {
384 Link.Ins(Full[i], 0); Full.Del(i);
385 }
386 }
387
388 if( Full.Get_Count() ) { for(int i=0; i<Full.Get_Count(); i++) { s += "<p>" + Full[i] + "</p>"; } }
389 if( Link.Get_Count() ) { for(int i=0; i<Link.Get_Count(); i++) { s += "<p>" + Link[i] + "</p>"; } }
390 }
391
392 //---------------------------------------------
393 if( bParameters )
394 {
395 s += CSG_String::Format("<hr><h4>%s</h4>", _TL("Parameters"));
396 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",
397 _TL("Name"), _TL("Type"), _TL("Identifier"), _TL("Description"), _TL("Constraints")
398 );
399
400 //-----------------------------------------
401 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
402 {
403 CSG_Parameter *pParameter = Parameters(i);
404
405 if( pParameter->is_Input() )
406 {
407 if( bFirst )
408 {
409 bFirst = 0; s += CSG_String::Format("<tr><th colspan=\"5\">%s</th></tr>", _TL("Input"));
410 }
411
412 s += CSG_String::Format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
413 pParameter->Get_Name(),
414 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE).c_str(), pParameter->do_UseInCMD() ?
415 pParameter->Get_Identifier () : SG_T(""),
416 pParameter->Get_Description(),
418 );
419 }
420 }
421
422 //-----------------------------------------
423 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
424 {
425 CSG_Parameter *pParameter = Parameters(i);
426
427 if( pParameter->is_Output() )
428 {
429 if( bFirst )
430 {
431 bFirst = 0; s += CSG_String::Format("<tr><th colspan=\"5\">%s</th></tr>", _TL("Output"));
432 }
433
434 s += CSG_String::Format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
435 pParameter->Get_Name(),
436 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE).c_str(), pParameter->do_UseInCMD() ?
437 pParameter->Get_Identifier () : SG_T(""),
438 pParameter->Get_Description(),
440 );
441 }
442 }
443
444 //-----------------------------------------
445 #define ADD_PARAMETER_DESC(p) if( bFirst ) { bFirst = 0; s += CSG_String::Format("<tr><th colspan=\"5\">%s</th></tr>", _TL("Options")); }\
446 s += CSG_String::Format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",\
447 p->Get_Name(),\
448 p->Get_Description(PARAMETER_DESCRIPTION_TYPE).c_str(), p->do_UseInCMD() ?\
449 (PrefixID + p->Get_Identifier()).c_str() : SG_T(""),\
450 p->Get_Description(),\
451 p->asParameters() ? SG_T("") : p->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES).c_str()\
452 );
453
454 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
455 {
456 CSG_Parameter *pParameter = Parameters(i); CSG_String PrefixID;
457
458 if( pParameter->is_Option() && pParameter->Get_Type() != PARAMETER_TYPE_Grid_System )
459 {
460 ADD_PARAMETER_DESC(pParameter);
461
462 if( pParameter->asParameters() )
463 {
464 if( pParameter->do_UseInCMD() )
465 {
466 PrefixID.Printf("%s.", pParameter->Get_Identifier());
467
468 for(int i=0; i<pParameter->asParameters()->Get_Count(); i++)
469 {
471 }
472
473 PrefixID.Clear();
474 }
475 }
476 }
477 }
478
479 //-----------------------------------------
480 s += "</table>";
481
482 s.Replace("\n", "<br>");
483 }
484
485 //---------------------------------------------
487 }
488 break;
489
490 //-----------------------------------------------------
491 case SG_SUMMARY_FMT_FLAT: default:
492 {
493 #define SUMMARY_ADD_STR(label, value) CSG_String::Format("%s:\t%s\n", label, value)
494 #define SUMMARY_ADD_INT(label, value) CSG_String::Format("%s:\t%d\n", label, value)
495
496 s += SUMMARY_ADD_STR(_TL("Name" ), Get_Name ().c_str());
497 s += SUMMARY_ADD_STR(_TL("ID" ), Get_ID ().c_str());
498 s += SUMMARY_ADD_STR(_TL("Author" ), Get_Author ().c_str());
499 s += SUMMARY_ADD_STR(_TL("Version"), Get_Version().c_str());
500
501 if( is_Interactive() && is_Grid() )
502 {
503 s += SUMMARY_ADD_STR(_TL("Specification"), CSG_String::Format("%s, %s", _TL("grid"), _TL("interactive")).c_str() );
504 }
505 else if( is_Interactive() )
506 {
507 s += SUMMARY_ADD_STR(_TL("Specification"), _TL("interactive"));
508 }
509 else if( is_Grid() )
510 {
511 s += SUMMARY_ADD_STR(_TL("Specification"), _TL("grid"));
512 }
513
514 if( Get_Type() == TOOL_TYPE_Chain )
515 {
516 s += SUMMARY_ADD_STR(_TL("File"), Get_File_Name().c_str() );
517 }
518
519 if( Menu.Length() > 0 )
520 {
521 s += SUMMARY_ADD_STR(_TL("Menu"), Menu.c_str());
522 }
523
524 #undef SUMMARY_ADD_STR
525 #undef SUMMARY_ADD_INT
526
527 //---------------------------------------------
528 s += "\n____________________________\n";
529
530 s += CSG_String::Format("%s:\n", _TL("Description"));
531
532 if( !Description.is_Empty() )
533 {
534 s += Description;
535 }
536 else
537 {
539
540 if( !Get_Dynamic_Description().is_Empty() )
541 {
543 }
544 }
545
546 //---------------------------------------------
547 if( Description.is_Empty() && Get_References().Get_Count() > 0 )
548 {
549 s += "\n____________________________\n";
550
551 s += CSG_String::Format("\n%s:\n", _TL("References"));
552
553 CSG_Strings References(Get_References(false));
554
555 for(int i=0; i<References.Get_Count(); i++)
556 {
557 s += "\n" + References[i] + "\n";
558 }
559 }
560
561 //---------------------------------------------
562 if( bParameters )
563 {
564 s += "\n";
565
566 //-----------------------------------------
567 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
568 {
569 CSG_Parameter *pParameter = Parameters(i);
570
571 if( pParameter->is_Input() && (has_GUI() || pParameter->do_UseInCMD()) )
572 {
573 if( bFirst )
574 {
575 bFirst = 0;
576 s += "____________________________\n";
577 s += CSG_String::Format("%s:\n", _TL("Input"));
578 }
579
580 s += CSG_String::Format("_\n%s\n%s\n%s\n%s\n%s\n",
581 pParameter->Get_Name (),
582 pParameter->Get_Identifier (),
583 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE ).c_str(),
584 pParameter->Get_Description(),
586 );
587 }
588 }
589
590 //-----------------------------------------
591 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
592 {
593 CSG_Parameter *pParameter = Parameters(i);
594
595 if( pParameter->is_Output() && (has_GUI() || pParameter->do_UseInCMD()) )
596 {
597 if( bFirst )
598 {
599 bFirst = 0;
600 s += "____________________________\n";
601 s += CSG_String::Format("%s:\n", _TL("Output"));
602 }
603
604 s += CSG_String::Format("_\n%s\n%s\n%s\n%s\n%s\n",
605 pParameter->Get_Name (),
606 pParameter->Get_Identifier (),
607 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE ).c_str(),
608 pParameter->Get_Description(),
610 );
611 }
612 }
613
614 //-----------------------------------------
615 for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
616 {
617 CSG_Parameter *pParameter = Parameters(i);
618
619 if( pParameter->is_Option() && (has_GUI() || pParameter->do_UseInCMD()) && pParameter->Get_Type() != PARAMETER_TYPE_Grid_System )
620 {
621 if( bFirst )
622 {
623 bFirst = 0;
624 s += "____________________________\n";
625 s += CSG_String::Format("%s:\n", _TL("Options"));
626 }
627
628 s += CSG_String::Format("_\n%s\n%s\n%s\n%s\n%s\n",
629 pParameter->Get_Name (),
630 pParameter->Get_Identifier (),
631 pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE ).c_str(),
632 pParameter->Get_Description(),
634 );
635 }
636 }
637 }
638
639 //---------------------------------------------
640 if( !Get_Description_Editors().is_Empty() )
641 {
642 s += CSG_String::Format("\n___\n%s: %s\n", _TL("Description editor(s)"), Get_Description_Editors().c_str());
643 }
644 }
645 break;
646 }
647
648 //-----------------------------------------------------
649 return( s );
650}
651
652
654// //
655// Tool Library //
656// //
658
659//---------------------------------------------------------
660CSG_String CSG_Tool_Library::Get_Summary(int Format, bool bWithGUINeeded) const
661{
662 bool bToolChains = Get_File_Name().is_Empty();
663
664 CSG_String s;
665
666 switch( Format )
667 {
668 //-----------------------------------------------------
670
671 s += "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
672 s += CSG_String::Format("<%s>\n" , SG_XML_LIBRARY);
673 s += CSG_String::Format("\t<%s>%s</%s>\n", SG_XML_LIBRARY_PATH, Get_File_Name().c_str(), SG_XML_LIBRARY_PATH);
676
677 for(int i=0; i<Get_Count(); i++)
678 {
679 if( Get_Tool(i) && (bWithGUINeeded || !Get_Tool(i)->needs_GUI()) )
680 {
681 CSG_String Name(Get_Tool(i)->Get_Name());
682 Name.Replace("&", "&amp;");
683 s += CSG_String::Format("\t<%s %s=\"%s\" %s=\"%s\"/>\n", SG_XML_TOOL,
684 SG_XML_TOOL_ATT_ID , Get_Tool(i)->Get_ID().c_str(),
686 );
687 }
688 }
689
690 s += CSG_String::Format("</%s>\n", SG_XML_LIBRARY);
691
692 break;
693
694 //-----------------------------------------------------
695 case SG_SUMMARY_FMT_HTML: default:
696
697 #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)
698 #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)
699
700 s += CSG_String::Format("<h4>%s</h4>", _TL("Tool Library"));
701
702 s += "<table border=\"0\">";
703
704 s += SUMMARY_ADD_STR(_TL("Name" ), Get_Info(TLB_INFO_Name ).c_str());
705 s += SUMMARY_ADD_STR(_TL("Author"), Get_Info(TLB_INFO_Author ).c_str());
706 s += SUMMARY_ADD_STR(_TL("ID" ), Get_Library_Name ().c_str());
707 s += SUMMARY_ADD_STR(_TL("File" ), Get_File_Name ().c_str());
708
709 s += "</table>";
710
711 //-------------------------------------------------
712 s += CSG_String::Format("<hr><h4>%s</h4>", _TL("Description"));
713
714 s += Get_Description();
715
716 if( Get_References().Get_Count() > 0 )
717 {
718 s += CSG_String::Format("<hr><h4>%s</h4>", _TL("References"));
719
720 CSG_Strings References(Get_References());
721
722 for(int i=0; i<References.Get_Count(); i++)
723 {
724 s += "<p>" + References[i] + "</p>";
725 }
726 }
727
728 //-------------------------------------------------
729 s += CSG_String::Format("<hr><h4>%s</h4>", _TL("Tools"));
730
731 s += "<table border=\"0\">";
732
733 s += CSG_String::Format("<tr align=\"left\"><th>%s</th><th>%s</th></tr>", _TL("ID"), _TL("Name"));
734
735 for(int i=0; i<Get_Count(); i++)
736 {
737 if( Get_Tool(i) && (bWithGUINeeded || !Get_Tool(i)->needs_GUI()) )
738 {
739 s += SUMMARY_ADD_STR(Get_Tool(i)->Get_ID().c_str(), Get_Tool(i)->Get_Name().c_str());
740 }
741 }
742
743 s += "</table>";
744
745 s.Replace("\n", "<br>");
746
747 #undef SUMMARY_ADD_STR
748 #undef SUMMARY_ADD_INT
749
750 break;
751
752 //-----------------------------------------------------
754
755 if( !bToolChains )
756 {
757 s += CSG_String::Format("\n%s%s: ", _TL("Library"), SG_T(" ")) + Get_Info(TLB_INFO_Name );
758 s += CSG_String::Format("\n%s%s: ", _TL("Category"), SG_T(" ")) + Get_Info(TLB_INFO_Category);
759 s += CSG_String::Format("\n%s%s: ", _TL("File"), SG_T(" ")) + Get_File_Name();
760 }
761 else
762 {
763 s += CSG_String::Format("\n%s: ", _TL("Tool Chains")) + Get_Info(TLB_INFO_Name);
764 }
765
767
768 if( Get_References().Get_Count() > 0 )
769 {
770 s += CSG_String::Format("\n%s:\n", _TL("References"));
771
772 for(int i=0; i<Get_References().Get_Count(); i++)
773 {
774 s += " - " + Get_References()[i] + "\n";
775 }
776 }
777
778 s += CSG_String::Format("\n\n%s:\n", _TL("Tools"));
779
780 for(int i=0; i<Get_Count(); i++)
781 {
782 if( Get_Tool(i) && (bWithGUINeeded || !Get_Tool(i)->needs_GUI()) )
783 {
784 s += " [" + Get_Tool(i)->Get_ID() + "]\t" + Get_Tool(i)->Get_Name() + "\n";
785 }
786 }
787
788 break;
789 }
790
791 return( s );
792}
793
794
796// //
798
799//---------------------------------------------------------
800// Store tool and tool library description to HTML files.
801//---------------------------------------------------------
803{
804 CSG_File File;
805
806 if( File.Open(SG_File_Make_Path(Path, Get_Library_Name(), "html"), SG_FILE_W, true, SG_FILE_ENCODING_UTF8) )
807 {
808 File.Write(Get_Summary());
809 }
810
811 for(int i=0; i<Get_Count(); i++)
812 {
813 if( Get_Tool(i) && File.Open(SG_File_Make_Path(Path, Get_Library_Name() + "_" + Get_Tool(i)->Get_ID(), "html"), SG_FILE_W, true, SG_FILE_ENCODING_UTF8) )
814 {
815 File.Write(Get_Tool(i)->Get_Summary());
816 }
817 }
818
819 return( true );
820}
821
822
824// //
825// Tool Library Manager //
826// //
828
829//---------------------------------------------------------
831{
832 int nTools = 0; CSG_Table Libraries;
833
834 Libraries.Add_Field("LIB" , SG_DATATYPE_String);
835 Libraries.Add_Field("TOOLS", SG_DATATYPE_Int );
836 Libraries.Add_Field("NAME" , SG_DATATYPE_String);
837 Libraries.Add_Field("PATH" , SG_DATATYPE_String);
838 Libraries.Add_Field("CHAIN", SG_DATATYPE_Int );
839
840 for(int i=0; i<Get_Count(); i++)
841 {
842 if( Get_Library(i)->Get_Count() > 0 )
843 {
844 nTools += Get_Library(i)->Get_Count();
845
846 Libraries.Add_Record();
847
848 Libraries[i].Set_Value(0, Get_Library(i)->Get_Library_Name());
849 Libraries[i].Set_Value(1, Get_Library(i)->Get_Count());
850 Libraries[i].Set_Value(2, Get_Library(i)->Get_Name());
851 Libraries[i].Set_Value(3, SG_File_Get_Path(Get_Library(i)->Get_File_Name()));
852 Libraries[i].Set_Value(4, Get_Library(i)->Get_File_Name().is_Empty() ? 1 : 0);
853 }
854 }
855
857
858 //-----------------------------------------------------
859 CSG_String s;
860
861 switch( Format )
862 {
863 //-----------------------------------------------------
865
866 s += "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
867 s += CSG_String::Format("<%s>\n", SG_XML_SYSTEM);
869
870 for(int i=0; i<Libraries.Get_Count(); i++)
871 {
872 s += CSG_String::Format("\t<%s %s=\"%s\"/>\n", SG_XML_LIBRARY, SG_XML_LIBRARY_NAME, Libraries[i].asString(0));
873 }
874
875 s += CSG_String::Format("</%s>\n", SG_XML_SYSTEM);
876
877 break;
878
879 //-----------------------------------------------------
880 case SG_SUMMARY_FMT_HTML: default:
881
882 #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)
883
884 s += CSG_String::Format("<h4>%s</h4>", _TL("Tool Libraries"));
885
886 s += "<table border=\"0\">";
887
888 s += SUMMARY_ADD_INT(_TL("Libraries"), Libraries.Get_Count());
889 s += SUMMARY_ADD_INT(_TL("Tools" ), nTools);
890
891 s += "</table>";
892
893 s += CSG_String::Format("<hr><h4>%s</h4><table border=\"1\">", _TL("Libraries"));
894
895 s += CSG_String::Format("<tr align=\"left\"><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>",
896 _TL("Library" ),
897 _TL("Tools" ),
898 _TL("Name" ),
899 _TL("Location")
900 );
901
902 for(int i=0; i<Libraries.Get_Count(); i++)
903 {
904 s += CSG_String::Format("<tr><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>",
905 Libraries[i].asString(0),
906 Libraries[i].asInt (1),
907 Libraries[i].asString(2),
908 Libraries[i].asString(3)
909 );
910 }
911
912 s += "</table>";
913
914 #undef SUMMARY_ADD_INT
915
916 break;
917
918 //-----------------------------------------------------
920
921 s += CSG_String::Format("\n%d %s (%d %s):\n", Libraries.Get_Count(), _TL("loaded tool libraries"), nTools, _TL("tools"));
922
923 for(int i=0; i<Libraries.Get_Count(); i++)
924 {
925 if( Libraries[i].asInt(4) == 0 )
926 s += CSG_String::Format(" - %s\n" , Libraries[i].asString(0));
927 else
928 s += CSG_String::Format(" - %s *\n", Libraries[i].asString(0));
929 }
930
931 s += CSG_String::Format("\n\n*) %s\n", _TL("tool chain libraries"));
932
933 break;
934 }
935
936 //-----------------------------------------------------
937 return( s );
938}
939
940
942// //
944
945//---------------------------------------------------------
946// Store tool and tool library description to HTML files.
947//---------------------------------------------------------
949{
950 for(int i=0; i<Get_Count(); i++)
951 {
952 CSG_Tool_Library *pLibrary = Get_Library(i);
953
954 CSG_String Directory = SG_File_Make_Path(Path, pLibrary->Get_Library_Name());
955
956 if( SG_Dir_Create(Directory) )
957 {
958 pLibrary->Get_Summary(Directory);
959 }
960 }
961
962 return( true );
963}
964
965
967// //
968// //
969// //
971
972//---------------------------------------------------------
CSG_String SG_Data_Type_Get_Name(TSG_Data_Type Type, bool bShort)
Definition api_core.cpp:123
SAGA_API_DLL_EXPORT bool SG_Dir_Create(const CSG_String &Directory, bool bFullPath=false)
Definition api_file.cpp:982
#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:1050
@ SG_DATATYPE_String
Definition api_core.h:1055
#define _TL(s)
Definition api_core.h:1618
@ SG_FILE_ENCODING_UTF8
Definition api_core.h:552
@ SG_FILE_W
Definition api_core.h:1161
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:382
void Set_Name(const CSG_String &Name)
Definition metadata.h:136
CSG_String asText(int Flags=0) const
Definition metadata.cpp:721
CSG_MetaData * Add_Child(void)
Definition metadata.cpp:166
bool Add_Property(const CSG_String &Name, const CSG_String &Value)
Definition metadata.cpp:582
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
void Clear(void)
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)
int Printf(const char *Format,...)
bool is_Empty(void) const
int Get_Count(void) const
Definition api_core.h:725
bool Ins(const CSG_String &String, int Index)
Definition api_core.h:730
const SG_Char * Get_Field_Name(int Field) const
Definition table.h:372
virtual bool Set_Value(sLong Index, int Field, const SG_Char *Value)
Definition table.h:429
sLong Get_Count(void) const
Definition table.h:410
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:1485
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
Definition table.cpp:479
TSG_Data_Type Get_Field_Type(int Field) const
Definition table.h:373
static CSG_String Html_to_SimpleText(const CSG_String &Text)
CSG_String Get_Summary(int Format=SG_SUMMARY_FMT_HTML) const
int Get_Count(void) const
CSG_Tool_Library * Get_Library(int i) const
const CSG_String & Get_Description(void) const
virtual CSG_Tool * Get_Tool(int Index, TSG_Tool_Type Type=TOOL_TYPE_Base) const
const CSG_String & Get_Library_Name(void) const
const CSG_String & Get_Name(void) const
CSG_String Get_Summary(int Format=SG_SUMMARY_FMT_HTML, bool bInteractive=true) const
const CSG_String & Get_File_Name(void) const
CSG_Strings Get_References(bool bHTML=true) const
virtual const CSG_String & Get_Info(int Type) const
virtual int Get_Count(void) const
const CSG_String & Get_Library(void) const
Definition tool.cpp:129
const CSG_String & Get_File_Name(void) const
Definition tool.cpp:135
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:274
const CSG_Table & Get_References_Table(void) const
Definition tool.h:170
const CSG_String & Get_Author(void) const
Definition tool.cpp:157
virtual bool is_Interactive(void) const
Definition tool.h:233
const CSG_String & Get_Name(void) const
Definition tool.cpp:146
CSG_Parameters Parameters
Definition tool.h:266
virtual TSG_Tool_Type Get_Type(void) const
Definition tool.h:148
CSG_String Get_Description_Editors(bool bHTML=true)
Definition tool.cpp:525
virtual CSG_String Get_MenuPath(void)
Definition tool.h:167
virtual bool is_Grid(void) const
Definition tool.h:232
const CSG_String & Get_Version(void) const
Definition tool.cpp:168
const CSG_String & Get_Description(void) const
Definition tool.cpp:188
const CSG_String & Get_ID(void) const
Definition tool.h:150
CSG_Strings Get_References(bool bHTML=true) const
Definition tool.cpp:330
const CSG_String & Get_Dynamic_Description(void) const
Definition tool.cpp:206
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
@ 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:657
@ TLB_INFO_Category
Definition tool.h:662
@ TLB_INFO_Author
Definition tool.h:659
@ 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 ADD_PARAMETER_DESC(p)
#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