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 //                   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 //                                                       //
48 ///////////////////////////////////////////////////////////
49 
50 //---------------------------------------------------------
51 #include "saga_api.h"
52 
53 
54 ///////////////////////////////////////////////////////////
55 //														 //
56 //		XML tags for mark-up of tool synopsis	 		 //
57 //														 //
58 ///////////////////////////////////////////////////////////
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 
103 ///////////////////////////////////////////////////////////
104 //														 //
105 //						Tool							 //
106 //														 //
107 ///////////////////////////////////////////////////////////
108 
109 //---------------------------------------------------------
SG_XML_Add_Parameter(CSG_MetaData * pParent,CSG_Parameter * pParameter,CSG_String ID="")110 void 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 
119 	pItem->Add_Child(SG_XML_PARAM_IDENTIFIER, ID);
120 
121 	if( pParameter->Get_Type() == PARAMETER_TYPE_DataObject_Output )
122 	{
123 	    pItem->Add_Child(SG_XML_PARAM_TYPE , CSG_String::Format("%s %s",
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 	//-----------------------------------------------------
146 	case PARAMETER_TYPE_Bool:
147 		pItem->Add_Child(SG_XML_PARAM_DEFAULT, pParameter->asBool());
148 		break;
149 
150 	//-----------------------------------------------------
151 	case PARAMETER_TYPE_Int:
152 	case PARAMETER_TYPE_Double:
153 	case PARAMETER_TYPE_Degree:
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 	//-----------------------------------------------------
160 	case PARAMETER_TYPE_Date:
161 		break;
162 
163 	case PARAMETER_TYPE_Range:
164 		break;
165 
166 	//-----------------------------------------------------
167 	case PARAMETER_TYPE_Choice:
168 		{
169 			CSG_MetaData	*pChild	= pItem->Add_Child(SG_XML_PARAM_LIST);
170 
171 			for(int i=0; i<pParameter->asChoice()->Get_Count(); i++)
172 			{
173 				pChild->Add_Child(SG_XML_PARAM_ITEM, pParameter->asChoice()->Get_Item(i));
174 			}
175 
176 			if( !pParameter->asChoice()->Get_Default().is_Empty() )
177 			{
178 				pItem->Add_Child(SG_XML_PARAM_DEFAULT, pParameter->asChoice()->Get_Default());
179 			}
180 		}
181 		break;
182 
183 	//-----------------------------------------------------
184 	case PARAMETER_TYPE_Choices:
185 		{
186 			CSG_MetaData	*pChild	= pItem->Add_Child(SG_XML_PARAM_LIST);
187 
188 			for(int i=0; i<pParameter->asChoices()->Get_Item_Count(); i++)
189 			{
190 				pChild->Add_Child(SG_XML_PARAM_ITEM, pParameter->asChoices()->Get_Item(i));
191 			}
192 
193 			if( !pParameter->asChoices()->Get_Default().is_Empty() )
194 			{
195 				pItem->Add_Child(SG_XML_PARAM_DEFAULT, pParameter->asChoices()->Get_Default());
196 			}
197 		}
198 		break;
199 
200 	//-----------------------------------------------------
201 	case PARAMETER_TYPE_String:
202 	case PARAMETER_TYPE_Text:
203 	case PARAMETER_TYPE_FilePath:
204 		break;
205 
206 	case PARAMETER_TYPE_Font:
207 		break;
208 
209 	case PARAMETER_TYPE_Color:
210 	case PARAMETER_TYPE_Colors:
211 		break;
212 
213 	//-----------------------------------------------------
214 	case PARAMETER_TYPE_FixedTable:
215 		{
216 			CSG_MetaData	*pChild	= pItem->Add_Child(SG_XML_PARAM_TABLE);
217 
218 			for(int i=0; i<pParameter->asTable()->Get_Field_Count(); i++)
219 			{
220 				CSG_MetaData	*pField	= pChild->Add_Child(SG_XML_PARAM_FIELD);
221 
222 				pField->Add_Property(SG_XML_PARAM_FIELD_ATT_NAME, pParameter->asTable()->Get_Field_Name(i));
223 				pField->Add_Property(SG_XML_PARAM_FIELD_ATT_TYPE, SG_Data_Type_Get_Name(pParameter->asTable()->Get_Field_Type(i)));
224 			}
225 		}
226 		break;
227 
228 	//-----------------------------------------------------
229 	case PARAMETER_TYPE_Grid_System:
230 		break;
231 
232 	//-----------------------------------------------------
233 	case PARAMETER_TYPE_Table_Field:
234 	case PARAMETER_TYPE_Table_Fields:
235 		if( pParameter->Get_Parent() )
236 		{
237 			pItem->Add_Child(SG_XML_PARAM_PARENT, pParameter->Get_Parent()->Get_Identifier());
238 		}
239 		break;
240 
241 	//-----------------------------------------------------
242 	case PARAMETER_TYPE_Parameters:
243 		{
244 			for(int i=0; i<pParameter->asParameters()->Get_Count(); i++)
245 			{
246 				SG_XML_Add_Parameter(pItem, pParameter->asParameters()->Get_Parameter(i), ID);
247 			}
248 		}
249 
250 	//-----------------------------------------------------
251 	default:
252 		break;
253 	}
254 }
255 
256 //---------------------------------------------------------
Get_Summary(bool bParameters,const CSG_String & Menu,const CSG_String & Description,int Format)257 CSG_String CSG_Tool::Get_Summary(bool bParameters, const CSG_String &Menu, const CSG_String &Description, int Format)
258 {
259 	CSG_String	s;
260 
261 	//-----------------------------------------------------
262 	switch( Format )
263 	{
264 	case SG_SUMMARY_FMT_XML:
265 		{
266 			CSG_MetaData	m;
267 
268 			m.Set_Name    (SG_XML_TOOL);
269 			m.Add_Property(SG_XML_TOOL_ATT_NAME   , Get_Name       ());
270 			m.Add_Property(SG_XML_TOOL_ATT_ID     , Get_ID         ());
271 			m.Add_Property(SG_XML_TOOL_ATT_AUTHOR , Get_Author     ());
272 			m.Add_Property(SG_XML_TOOL_ATT_VERSION, Get_Version    ());
273 			m.Add_Child   (SG_XML_DESCRIPTION     , Get_Description());
274 			m.Add_Child   (SG_XML_MENU            , Get_MenuPath   ());
275 			m.Add_Child   (SG_XML_SPEC_ATT_GRID   , is_Grid        () ? "true" : "false");
276 			m.Add_Child   (SG_XML_SPEC_ATT_INTERA , is_Interactive () ? "true" : "false");
277 
278 		//	CSG_MetaData	*pChild	= m.Add_Child(SG_XML_SPECIFICATION);
279 		//	pChild->Add_Property(SG_XML_SPEC_ATT_GRID  , is_Grid        () ? "true" : "false");
280 		//	pChild->Add_Property(SG_XML_SPEC_ATT_INTERA, is_Interactive () ? "true" : "false");
281 
282 			if( bParameters )
283 			{
284 				for(int i=0; i<Parameters.Get_Count(); i++)
285 				{
286 					if( Parameters(i)->is_Input() )
287  					{
288 						SG_XML_Add_Parameter(&m, Parameters(i));
289 					}
290 				}
291 
292 				for(int i=0; i<Parameters.Get_Count(); i++)
293 				{
294 					if( Parameters(i)->is_Output() )
295  					{
296 						SG_XML_Add_Parameter(&m, Parameters(i));
297 					}
298 				}
299 
300 				for(int i=0; i<Parameters.Get_Count(); i++)
301 				{
302 					if( Parameters(i)->is_Option()
303 					&&  Parameters(i)->Get_Type() != PARAMETER_TYPE_Node
304 					&&  Parameters(i)->Get_Type() != PARAMETER_TYPE_Grid_System )
305  					{
306 						SG_XML_Add_Parameter(&m, Parameters(i));
307 					}
308 				}
309 			}
310 
311 			s	= m.asText(1);
312 		}
313 		break;
314 
315 	//-----------------------------------------------------
316 	case SG_SUMMARY_FMT_HTML:
317 		{
318 			#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)
319 			#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)
320 
321 			s	+= CSG_String::Format("<h4>%s</h4><table border=\"0\">", _TL("Tool"));
322 
323 			s	+= SUMMARY_ADD_STR(_TL("Name"   ), Get_Name   ().c_str());
324 			s	+= SUMMARY_ADD_STR(_TL("Author" ), Get_Author ().c_str());
325 			s	+= SUMMARY_ADD_STR(_TL("Version"), Get_Version().c_str());
326 			s	+= SUMMARY_ADD_STR(_TL("Library"), Get_Library().c_str());
327 			s	+= SUMMARY_ADD_STR(_TL("ID"     ), Get_ID     ().c_str());
328 
329 			if( is_Interactive() && is_Grid() )
330 			{
331 				s	+= SUMMARY_ADD_STR(_TL("Specification"), CSG_String::Format("%s, %s", _TL("grid"), _TL("interactive")).c_str() );
332 			}
333 			else if( is_Interactive() )
334 			{
335 				s	+= SUMMARY_ADD_STR(_TL("Specification"), _TL("interactive"));
336 			}
337 			else if( is_Grid() )
338 			{
339 				s	+= SUMMARY_ADD_STR(_TL("Specification"), _TL("grid"));
340 			}
341 
342 			if( Get_Type() == TOOL_TYPE_Chain )
343 			{
344 				s	+= SUMMARY_ADD_STR(_TL("File"), Get_File_Name().c_str() );
345 			}
346 
347 			if( Menu.Length() > 0 )
348 			{
349 				CSG_String	sMenu(Menu);
350 
351 				sMenu.Replace("|", " <b>></b> ");
352 
353 				s	+= SUMMARY_ADD_STR(_TL("Menu"  ), sMenu.c_str());
354 			}
355 
356 			s	+= "</table>";
357 
358 			#undef SUMMARY_ADD_STR
359 			#undef SUMMARY_ADD_INT
360 
361 			//---------------------------------------------
362 			s	+= CSG_String::Format("<hr><h4>%s</h4>", _TL("Description"));
363 
364 			s	+= !Description.is_Empty() ? Description : Get_Description();
365 
366 			//---------------------------------------------
367 			if( Description.is_Empty() && Get_References().Get_Count() > 0 )
368 			{
369 				s	+= CSG_String::Format("<hr><h4>%s</h4><ul>", _TL("References"));
370 
371 				for(int i=0; i<Get_References().Get_Count(); i++)
372 				{
373 					s	+= "<li>" + Get_References()[i] + "</li>";
374 				}
375 
376 				s	+= "</ul>";
377 			}
378 
379 			//---------------------------------------------
380 			if( bParameters )
381 			{
382 				s	+= CSG_String::Format("<hr><h4>%s</h4>", _TL("Parameters"));
383 				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",
384 						_TL("Name"), _TL("Type"), _TL("Identifier"), _TL("Description"), _TL("Constraints")
385 					);
386 
387 				//-----------------------------------------
388 				for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
389 				{
390 					CSG_Parameter	*pParameter	= Parameters(i);
391 
392 					if( pParameter->is_Input() )
393 					{
394 						if( bFirst )
395 						{
396 							bFirst = 0; s += CSG_String::Format("<tr><th colspan=\"5\">%s</th></tr>", _TL("Input"));
397 						}
398 
399 						s	+= CSG_String::Format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
400 							pParameter->Get_Name(),
401 							pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE      ).c_str(),
402 							pParameter->Get_Identifier (),
403 							pParameter->Get_Description(),
404 							pParameter->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES).c_str()
405 						);
406 					}
407 				}
408 
409 				//-----------------------------------------
410 				for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
411 				{
412 					CSG_Parameter	*pParameter	= Parameters(i);
413 
414 					if( pParameter->is_Output() )
415 					{
416 						if( bFirst )
417 						{
418 							bFirst = 0; s += CSG_String::Format("<tr><th colspan=\"5\">%s</th></tr>", _TL("Output"));
419 						}
420 
421 						s	+= CSG_String::Format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
422 							pParameter->Get_Name(),
423 							pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE      ).c_str(),
424 							pParameter->Get_Identifier (),
425 							pParameter->Get_Description(),
426 							pParameter->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES).c_str()
427 						);
428 					}
429 				}
430 
431 				//-----------------------------------------
432 				for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
433 				{
434 					CSG_Parameter	*pParameter	= Parameters(i);
435 
436 					if( pParameter->is_Option() && pParameter->Get_Type() != PARAMETER_TYPE_Grid_System )
437 					{
438 						if( bFirst )
439 						{
440 							bFirst = 0; s += CSG_String::Format("<tr><th colspan=\"5\">%s</th></tr>", _TL("Options"));
441 						}
442 
443 						s	+= CSG_String::Format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
444 							pParameter->Get_Name(),
445 							pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE      ).c_str(),
446 							pParameter->Get_Identifier (),
447 							pParameter->Get_Description(),
448 							pParameter->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES).c_str()
449 						);
450 					}
451 				}
452 
453 				//-----------------------------------------
454 				s	+= "</table>";
455 
456 				s.Replace("\n", "<br>");
457 			}
458 		}
459 		break;
460 
461 	//-----------------------------------------------------
462 	case SG_SUMMARY_FMT_FLAT: default:
463 		{
464 			#define SUMMARY_ADD_STR(label, value)	CSG_String::Format("%s:\t%s\n", label, value)
465 			#define SUMMARY_ADD_INT(label, value)	CSG_String::Format("%s:\t%d\n", label, value)
466 
467 			s	+= SUMMARY_ADD_STR(_TL("Name"   ), Get_Name   ().c_str());
468 			s	+= SUMMARY_ADD_STR(_TL("ID"     ), Get_ID     ().c_str());
469 			s	+= SUMMARY_ADD_STR(_TL("Author" ), Get_Author ().c_str());
470 			s	+= SUMMARY_ADD_STR(_TL("Version"), Get_Version().c_str());
471 
472 			if( is_Interactive() && is_Grid() )
473 			{
474 				s	+= SUMMARY_ADD_STR(_TL("Specification"), CSG_String::Format("%s, %s", _TL("grid"), _TL("interactive")).c_str() );
475 			}
476 			else if( is_Interactive() )
477 			{
478 				s	+= SUMMARY_ADD_STR(_TL("Specification"), _TL("interactive"));
479 			}
480 			else if( is_Grid() )
481 			{
482 				s	+= SUMMARY_ADD_STR(_TL("Specification"), _TL("grid"));
483 			}
484 
485 			if( Get_Type() == TOOL_TYPE_Chain )
486 			{
487 				s	+= SUMMARY_ADD_STR(_TL("File"), Get_File_Name().c_str() );
488 			}
489 
490 			if( Menu.Length() > 0 )
491 			{
492 				CSG_String	sMenu(Menu);
493 
494 				sMenu.Replace("|", " <b>></b> ");
495 
496 				s	+= SUMMARY_ADD_STR(_TL("Menu"  ), sMenu.c_str());
497 			}
498 
499 			#undef SUMMARY_ADD_STR
500 			#undef SUMMARY_ADD_INT
501 
502 			//---------------------------------------------
503 			s	+= "\n____________________________\n";
504 
505 			s	+= CSG_String::Format("%s:\n", _TL("Description"));
506 
507 			s	+= !Description.is_Empty() ? Description : Get_Description();
508 
509 			//---------------------------------------------
510 			if( Description.is_Empty() && Get_References().Get_Count() > 0 )
511 			{
512 				s	+= "\n____________________________\n";
513 
514 				s	+= CSG_String::Format("\n%s:\n", _TL("References"));
515 
516 				for(int i=0; i<Get_References().Get_Count(); i++)
517 				{
518 					s	+= " - " + Get_References()[i] + "\n";
519 				}
520 			}
521 
522 			//---------------------------------------------
523 			if( bParameters )
524 			{
525 				s	+= "\n";
526 
527 				//-----------------------------------------
528 				for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
529 				{
530 					CSG_Parameter	*pParameter	= Parameters(i);
531 
532 					if( pParameter->is_Input() )
533 					{
534 						if( bFirst )
535 						{
536 							bFirst	= 0;
537 							s	+= "____________________________\n";
538 							s	+= CSG_String::Format("%s:\n", _TL("Input"));
539 						}
540 
541 						s	+= CSG_String::Format("_\n%s\n%s\n%s\n%s\n%s\n",
542 							pParameter->Get_Name       (),
543 							pParameter->Get_Identifier (),
544 							pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE      ).c_str(),
545 							pParameter->Get_Description(),
546 							pParameter->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES).c_str()
547 						);
548 					}
549 				}
550 
551 				//-----------------------------------------
552 				for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
553 				{
554 					CSG_Parameter	*pParameter	= Parameters(i);
555 
556 					if( pParameter->is_Output() )
557 					{
558 						if( bFirst )
559 						{
560 							bFirst	= 0;
561 							s	+= "____________________________\n";
562 							s	+= CSG_String::Format("%s:\n", _TL("Output"));
563 						}
564 
565 						s	+= CSG_String::Format("_\n%s\n%s\n%s\n%s\n%s\n",
566 							pParameter->Get_Name       (),
567 							pParameter->Get_Identifier (),
568 							pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE      ).c_str(),
569 							pParameter->Get_Description(),
570 							pParameter->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES).c_str()
571 						);
572 					}
573 				}
574 
575 				//-----------------------------------------
576 				for(int i=0, bFirst=1; i<Parameters.Get_Count(); i++)
577 				{
578 					CSG_Parameter	*pParameter	= Parameters(i);
579 
580 					if( pParameter->is_Option() && pParameter->Get_Type() != PARAMETER_TYPE_Grid_System )
581 					{
582 						if( bFirst )
583 						{
584 							bFirst	= 0;
585 							s	+= "____________________________\n";
586 							s	+= CSG_String::Format("%s:\n", _TL("Options"));
587 						}
588 
589 						s	+= CSG_String::Format("_\n%s\n%s\n%s\n%s\n%s\n",
590 							pParameter->Get_Name       (),
591 							pParameter->Get_Identifier (),
592 							pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE      ).c_str(),
593 							pParameter->Get_Description(),
594 							pParameter->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES).c_str()
595 						);
596 					}
597 				}
598 			}
599 		}
600 		break;
601 	}
602 
603 	//-----------------------------------------------------
604 	return( s );
605 }
606 
607 
608 ///////////////////////////////////////////////////////////
609 //														 //
610 //					Tool Library						 //
611 //														 //
612 ///////////////////////////////////////////////////////////
613 
614 //---------------------------------------------------------
Get_Summary(int Format,bool bWithGUINeeded) const615 CSG_String CSG_Tool_Library::Get_Summary(int Format, bool bWithGUINeeded) const
616 {
617 	bool	bToolChains	= Get_File_Name().is_Empty();
618 
619 	CSG_String	s;
620 
621 	switch( Format )
622 	{
623 	//-----------------------------------------------------
624 	case SG_SUMMARY_FMT_XML:
625 
626 		s	+= "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
627 		s	+= CSG_String::Format("<%s>\n"         , SG_XML_LIBRARY);
628 		s	+= CSG_String::Format("\t<%s>%s</%s>\n", SG_XML_LIBRARY_PATH, Get_File_Name().c_str(), SG_XML_LIBRARY_PATH);
629 		s	+= CSG_String::Format("\t<%s>%s</%s>\n", SG_XML_LIBRARY_NAME, Get_Info(TLB_INFO_Name).c_str(), SG_XML_LIBRARY_NAME);
630 		s	+= CSG_String::Format("\t<%s>%s</%s>\n", SG_XML_LIBRARY_CATEGORY, Get_Info(TLB_INFO_Category).c_str(), SG_XML_LIBRARY_CATEGORY);
631 
632 		for(int i=0; i<Get_Count(); i++)
633 		{
634 			if( Get_Tool(i) && (bWithGUINeeded || !Get_Tool(i)->needs_GUI()) )
635 			{
636 				CSG_String Name(Get_Tool(i)->Get_Name());
637 				Name.Replace("&", "&amp;");
638 				s	+= CSG_String::Format("\t<%s %s=\"%s\" %s=\"%s\"/>\n", SG_XML_TOOL,
639 					SG_XML_TOOL_ATT_ID  , Get_Tool(i)->Get_ID().c_str(),
640 					SG_XML_TOOL_ATT_NAME, Name.c_str()
641 				);
642 			}
643 		}
644 
645 		s	+= CSG_String::Format("</%s>\n", SG_XML_LIBRARY);
646 
647 		break;
648 
649 	//-----------------------------------------------------
650 	case SG_SUMMARY_FMT_HTML: default:
651 
652 		#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)
653 		#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)
654 
655 		s	+= CSG_String::Format("<h4>%s</h4>", _TL("Tool Library"));
656 
657 		s	+= "<table border=\"0\">";
658 
659 		s	+= SUMMARY_ADD_STR(_TL("Name"  ), Get_Info(TLB_INFO_Name   ).c_str());
660 		s	+= SUMMARY_ADD_STR(_TL("Author"), Get_Info(TLB_INFO_Author ).c_str());
661 		s	+= SUMMARY_ADD_STR(_TL("ID"    ), Get_Library_Name        ().c_str());
662 		s	+= SUMMARY_ADD_STR(_TL("File"  ), Get_File_Name           ().c_str());
663 
664 		s	+= "</table>";
665 
666 		//-------------------------------------------------
667 		s	+= CSG_String::Format("<hr><h4>%s</h4>", _TL("Description"));
668 
669 		s	+= Get_Info(TLB_INFO_Description);
670 
671 		if( Get_References().Get_Count() > 0 )
672 		{
673 			s	+= CSG_String::Format("<hr><h4>%s</h4><ul>", _TL("References"));
674 
675 			for(int i=0; i<Get_References().Get_Count(); i++)
676 			{
677 				s	+= "<li>" + Get_References()[i] + "</li>";
678 			}
679 
680 			s	+= "</ul>";
681 		}
682 
683 		//-------------------------------------------------
684 		s	+= CSG_String::Format("<hr><h4>%s</h4>", _TL("Tools"));
685 
686 		s	+= "<table border=\"0\">";
687 
688 		s	+= CSG_String::Format("<tr align=\"left\"><th>%s</th><th>%s</th></tr>", _TL("ID"), _TL("Name"));
689 
690 		for(int i=0; i<Get_Count(); i++)
691 		{
692 			if( Get_Tool(i) && (bWithGUINeeded || !Get_Tool(i)->needs_GUI()) )
693 			{
694 				s	+= SUMMARY_ADD_STR(Get_Tool(i)->Get_ID().c_str(), Get_Tool(i)->Get_Name().c_str());
695 			}
696 		}
697 
698 		s	+= "</table>";
699 
700 		s.Replace("\n", "<br>");
701 
702 		#undef SUMMARY_ADD_STR
703 		#undef SUMMARY_ADD_INT
704 
705 		break;
706 
707 	//-----------------------------------------------------
708 	case SG_SUMMARY_FMT_FLAT:
709 
710 		if( !bToolChains )
711 		{
712 			s	+= CSG_String::Format("\n%s:\t", _TL("Library" )) + Get_Info(TLB_INFO_Name    );
713 			s	+= CSG_String::Format("\n%s:\t", _TL("Category")) + Get_Info(TLB_INFO_Category);
714 			s	+= CSG_String::Format("\n%s:\t", _TL("File"    )) + Get_File_Name();
715 		}
716 		else
717 		{
718 			s	+= CSG_String::Format("\n%s:\t", _TL("Tool Chains")) + Get_Info(TLB_INFO_Name);
719 		}
720 
721 		s	+= CSG_String::Format("\n%s:\n", _TL("Description")) + Get_Info(TLB_INFO_Description);
722 
723 		if( Get_References().Get_Count() > 0 )
724 		{
725 			s	+= CSG_String::Format("\n%s:\n", _TL("References"));
726 
727 			for(int i=0; i<Get_References().Get_Count(); i++)
728 			{
729 				s	+= " - " + Get_References()[i] + "\n";
730 			}
731 		}
732 
733 		s	+= CSG_String::Format("\n\n%s:\n", _TL("Tools"));
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	+= " [" + Get_Tool(i)->Get_ID() + "]\t" + Get_Tool(i)->Get_Name() + "\n";
740 			}
741 		}
742 
743 		break;
744 	}
745 
746 	return( s );
747 }
748 
749 
750 ///////////////////////////////////////////////////////////
751 //														 //
752 ///////////////////////////////////////////////////////////
753 
754 //---------------------------------------------------------
755 // Store tool and tool library description to HTML files.
756 //---------------------------------------------------------
Get_Summary(const CSG_String & Path) const757 bool CSG_Tool_Library::Get_Summary(const CSG_String &Path)	const
758 {
759 	CSG_File	f;
760 
761 	if( f.Open(SG_File_Make_Path(Path, Get_Library_Name(), "html"), SG_FILE_W) )
762 	{
763 		f.Write(Get_Summary());
764 	}
765 
766 	for(int j=0; j<Get_Count(); j++)
767 	{
768 		if( Get_Tool(j) && f.Open(SG_File_Make_Path(Path, Get_Library_Name() + "_" + Get_Tool(j)->Get_ID(), "html"), SG_FILE_W) )
769 		{
770 			f.Write(Get_Tool(j)->Get_Summary());
771 		}
772 	}
773 
774 	return( true );
775 }
776 
777 
778 ///////////////////////////////////////////////////////////
779 //														 //
780 //				Tool Library Manager					 //
781 //														 //
782 ///////////////////////////////////////////////////////////
783 
784 //---------------------------------------------------------
Get_Summary(int Format) const785 CSG_String CSG_Tool_Library_Manager::Get_Summary(int Format)	const
786 {
787 	//-----------------------------------------------------
788 	int			i, nTools;
789 
790 	CSG_Table	Libraries;
791 
792 	Libraries.Add_Field("LIB"  , SG_DATATYPE_String);
793 	Libraries.Add_Field("TOOLS", SG_DATATYPE_Int   );
794 	Libraries.Add_Field("NAME" , SG_DATATYPE_String);
795 	Libraries.Add_Field("PATH" , SG_DATATYPE_String);
796 	Libraries.Add_Field("CHAIN", SG_DATATYPE_Int   );
797 
798 	for(i=0, nTools=0; i<Get_Count(); i++)
799 	{
800 		if( Get_Library(i)->Get_Count() > 0 )
801 		{
802 			nTools	+= Get_Library(i)->Get_Count();
803 
804 			Libraries.Add_Record();
805 
806 			Libraries[i].Set_Value(0, Get_Library(i)->Get_Library_Name());
807 			Libraries[i].Set_Value(1, Get_Library(i)->Get_Count());
808 			Libraries[i].Set_Value(2, Get_Library(i)->Get_Name());
809 			Libraries[i].Set_Value(3, SG_File_Get_Path(Get_Library(i)->Get_File_Name()));
810 			Libraries[i].Set_Value(4, Get_Library(i)->Get_File_Name().is_Empty() ? 1 : 0);
811 		}
812 	}
813 
814 	Libraries.Set_Index(4, TABLE_INDEX_Ascending, 0, TABLE_INDEX_Ascending);
815 
816 	//-----------------------------------------------------
817 	CSG_String	s;
818 
819 	switch( Format )
820 	{
821 	//-----------------------------------------------------
822 	case SG_SUMMARY_FMT_XML:
823 
824 		s	+= "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
825 		s	+= CSG_String::Format("<%s>\n", SG_XML_SYSTEM);
826 		s	+= CSG_String::Format("<%s>%s</%s>\n", SG_XML_SYSTEM_VER, SAGA_VERSION, SG_XML_SYSTEM_VER);
827 
828 		for(i=0; i<Libraries.Get_Count(); i++)
829 		{
830 			s	+= CSG_String::Format("\t<%s %s=\"%s\"/>\n", SG_XML_LIBRARY, SG_XML_LIBRARY_NAME, Libraries[i].asString(0));
831 		}
832 
833 		s	+= CSG_String::Format("</%s>\n", SG_XML_SYSTEM);
834 
835 		break;
836 
837 	//-----------------------------------------------------
838 	case SG_SUMMARY_FMT_HTML: default:
839 
840 		#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)
841 
842 		s	+= CSG_String::Format("<h4>%s</h4>", _TL("Tool Libraries"));
843 
844 		s	+= "<table border=\"0\">";
845 
846 		s	+= SUMMARY_ADD_INT(_TL("Libraries"), Libraries.Get_Count());
847 		s	+= SUMMARY_ADD_INT(_TL("Tools"    ), nTools);
848 
849 		s	+= "</table>";
850 
851 		s	+= CSG_String::Format("<hr><h4>%s</h4><table border=\"1\">", _TL("Libraries"));
852 
853 		s	+= CSG_String::Format("<tr align=\"left\"><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>",
854 				_TL("Library" ),
855 				_TL("Tools"   ),
856 				_TL("Name"    ),
857 				_TL("Location")
858 			);
859 
860 		for(i=0; i<Libraries.Get_Count(); i++)
861 		{
862 			s	+= CSG_String::Format("<tr><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>",
863 					Libraries[i].asString(0),
864 					Libraries[i].asInt   (1),
865 					Libraries[i].asString(2),
866 					Libraries[i].asString(3)
867 				);
868 		}
869 
870 		s	+= "</table>";
871 
872 		#undef SUMMARY_ADD_INT
873 
874 		break;
875 
876 	//-----------------------------------------------------
877 	case SG_SUMMARY_FMT_FLAT:
878 
879 		s	+= CSG_String::Format("\n%d %s (%d %s):\n", Libraries.Get_Count(), _TL("loaded tool libraries"), nTools, _TL("tools"));
880 
881 		for(i=0; i<Libraries.Get_Count(); i++)
882 		{
883 			if( Libraries[i].asInt(4) == 0 )
884 				s	+= CSG_String::Format(" - %s\n"  , Libraries[i].asString(0));
885 			else
886 				s	+= CSG_String::Format(" - %s *\n", Libraries[i].asString(0));
887 		}
888 
889 		s	+= CSG_String::Format("\n\n*) %s\n", _TL("tool chain libraries"));
890 
891 		break;
892 	}
893 
894 	//-----------------------------------------------------
895 	return( s );
896 }
897 
898 
899 ///////////////////////////////////////////////////////////
900 //														 //
901 ///////////////////////////////////////////////////////////
902 
903 //---------------------------------------------------------
904 // Store tool and tool library description to HTML files.
905 //---------------------------------------------------------
Get_Summary(const CSG_String & Path) const906 bool CSG_Tool_Library_Manager::Get_Summary(const CSG_String &Path)	const
907 {
908 	for(int i=0; i<Get_Count(); i++)
909 	{
910 		CSG_Tool_Library	*pLibrary	= Get_Library(i);
911 
912 		CSG_String	Directory	= SG_File_Make_Path(Path, pLibrary->Get_Library_Name());
913 
914 		if( SG_Dir_Create(Directory) )
915 		{
916 			pLibrary->Get_Summary(Directory);
917 		}
918 	}
919 
920 	return( true );
921 }
922 
923 
924 ///////////////////////////////////////////////////////////
925 //														 //
926 //														 //
927 //														 //
928 ///////////////////////////////////////////////////////////
929 
930 //---------------------------------------------------------
931