1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Tool Library //
9 // dev_tools //
10 // //
11 //-------------------------------------------------------//
12 // //
13 // arctoolbox.cpp //
14 // //
15 // Copyright (C) 2015 by //
16 // Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. SAGA is free software; you //
22 // can redistribute it and/or modify it under the terms //
23 // of the GNU General Public License as published by the //
24 // Free Software Foundation, either version 2 of the //
25 // License, or (at your option) any later version. //
26 // //
27 // SAGA is distributed in the hope that it will be //
28 // useful, but WITHOUT ANY WARRANTY; without even the //
29 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
30 // PARTICULAR PURPOSE. See the GNU General Public //
31 // License for more details. //
32 // //
33 // You should have received a copy of the GNU General //
34 // Public License along with this program; if not, see //
35 // <http://www.gnu.org/licenses/>. //
36 // //
37 //-------------------------------------------------------//
38 // //
39 // e-mail: oconrad@saga-gis.org //
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Hamburg //
44 // Germany //
45 // //
46 ///////////////////////////////////////////////////////////
47
48 //---------------------------------------------------------
49 #include "arctoolbox.h"
50
51
52 ///////////////////////////////////////////////////////////
53 // //
54 // //
55 // //
56 ///////////////////////////////////////////////////////////
57
58 //---------------------------------------------------------
CArcToolBox(void)59 CArcToolBox::CArcToolBox(void)
60 {
61 Set_Name ("ArcSAGA Toolboxes");
62
63 Set_Author ("O.Conrad (c) 2015");
64
65 Set_Description (_TW(
66 ""
67 ));
68
69 //-----------------------------------------------------
70 Parameters.Add_FilePath(
71 "", "DIRECTORY" , "Output Directory",
72 "",
73 NULL, NULL, true, true
74 );
75
76 Parameters.Add_Choice(
77 "", "BOX_NAMING" , "Toolbox Naming",
78 "",
79 CSG_String::Format("%s|%s",
80 SG_T("library file name"),
81 SG_T("category and library name")
82 ), 0
83 );
84
85 Parameters.Add_Choice(
86 "", "ARC_VERSION" , "ArcGIS Version",
87 "",
88 CSG_String::Format("%s|%s",
89 SG_T("10.1"),
90 SG_T("10.2, 10.3")
91 ), 1
92 );
93 }
94
95
96 ///////////////////////////////////////////////////////////
97 // //
98 ///////////////////////////////////////////////////////////
99
100 //---------------------------------------------------------
On_Execute(void)101 bool CArcToolBox::On_Execute(void)
102 {
103 int nTools = 0;
104
105 m_ArcVersion = Parameters("ARC_VERSION")->asInt();
106
107 //-----------------------------------------------------
108 for(int iLibrary=0; iLibrary<SG_Get_Tool_Library_Manager().Get_Count() && Set_Progress(iLibrary, SG_Get_Tool_Library_Manager().Get_Count()); iLibrary++)
109 {
110 CSG_Tool_Library *pLibrary = SG_Get_Tool_Library_Manager().Get_Library(iLibrary);
111
112 if( !pLibrary->Get_Category ().Cmp("SAGA Development" ) // generally exclude certain categories/libraries
113 || !pLibrary->Get_Category ().Cmp("Garden" )
114 || !pLibrary->Get_Category ().Cmp("Grid Collection" )
115 || !pLibrary->Get_Category ().Cmp("Reports" )
116 || !pLibrary->Get_Category ().Cmp("Simulation" )
117 || !pLibrary->Get_Category ().Cmp("Table" )
118 || !pLibrary->Get_Category ().Cmp("TIN" )
119 || !pLibrary->Get_Category ().Cmp("Visualization" )
120 || !pLibrary->Get_Library_Name().Cmp("grid_calculus_bsl")
121 || !pLibrary->Get_Library_Name().Cmp("db_odbc" )
122 || !pLibrary->Get_Library_Name().Cmp("db_pgsql" ) )
123 {
124 continue;
125 }
126
127 Process_Set_Text(CSG_String::Format("%s: %s", SG_T("Library"), pLibrary->Get_Library_Name().c_str()));
128
129 CSG_Strings Names, Codes, Descs;
130
131 for(int iTool=0; iTool<pLibrary->Get_Count(); iTool++)
132 {
133 CSG_String Code;
134 CSG_MetaData Desc;
135
136 if( Get_Tool(pLibrary, iTool, Code, Desc) )
137 {
138 Names += CSG_String::Format("tool_%d", iTool);
139 Codes += Code;
140 Descs += Desc.asText(1); // '1' => as xml code
141 nTools ++;
142 }
143 }
144
145 Save(pLibrary, Parameters("DIRECTORY")->asString(), Names, Codes, Descs);
146 }
147
148 //-----------------------------------------------------
149 Message_Fmt("Number of added tools: %d", nTools);
150
151 return( true );
152 }
153
154
155 ///////////////////////////////////////////////////////////
156 // //
157 ///////////////////////////////////////////////////////////
158
159 //---------------------------------------------------------
160 enum
161 {
162 FORMAT_ASCII,
163 FORMAT_PLAIN,
164 FORMAT_HTML,
165 FORMAT_HTML_TXT,
166 FORMAT_FILE
167 };
168
169 //---------------------------------------------------------
Get_Formatted(CSG_String String,int Type)170 CSG_String CArcToolBox::Get_Formatted(CSG_String String, int Type)
171 {
172 if( Type == FORMAT_FILE )
173 {
174 String.Replace("/", ".");
175
176 return( String );
177 }
178
179 if( Type == FORMAT_ASCII )
180 {
181 String.Replace("�", "ae");
182 String.Replace("�", "oe");
183 String.Replace("�", "ue");
184 String.Replace("�", "Ae");
185 String.Replace("�", "Oe");
186 String.Replace("�", "Ue");
187 String.Replace("�", "sz");
188 }
189
190 String.Replace("\xb", "");
191 String.Replace("\xB", "");
192
193 String.Replace("�", "2");
194 String.Replace("�", "3");
195
196 String.Replace("\r", "");
197 String.Replace("\t", " ");
198
199 String.Replace("\"", "\\\"");
200
201 if( Type == FORMAT_HTML || Type == FORMAT_HTML_TXT )
202 {
203 if( Type == FORMAT_HTML )
204 {
205 String = "<p>" + String + "</p>";
206 String.Replace("\n", "</p><p>");
207 }
208
209 if( Type == FORMAT_HTML_TXT )
210 {
211 String = "<p>" + String + "</p>";
212 String.Replace("\n", "</p><p>");
213 }
214 }
215 else
216 {
217 String.Replace("\n", "\\n");
218 }
219
220 return( String );
221 }
222
223 //---------------------------------------------------------
Get_Description(CSG_Tool * pTool,int Type)224 CSG_String CArcToolBox::Get_Description(CSG_Tool *pTool, int Type)
225 {
226 CSG_String s; if( pTool ) s += (pTool->Get_Description());
227
228 if( Type == FORMAT_HTML || Type == FORMAT_HTML_TXT )
229 {
230 s += "<p><hr>";
231 s += "<span STYLE=\"font-style:italic;font-size:9pt;font-weight:bold\">";
232 s += "SAGA - System for Automated Geoscientific Analyses<br></span>";
233 s += "<span STYLE=\"font-style:italic;font-size:8pt\">";
234 s += "www.saga-gis.org<br></span>";
235 s += "<span STYLE=\"font-style:italic;font-size:6pt\">_____<br>Reference:<br>";
236 s += "Conrad, O., Bechtel, B., Bock, M., Dietrich, H., Fischer, E., Gerlitz, L., Wehberg, J., Wichmann, V., and B�hner, J. (2015): ";
237 s += "System for Automated Geoscientific Analyses (SAGA) v. 2.1.4, Geosci. Model Dev., 8, 1991-2007, doi:10.5194/gmd-8-1991-2015.";
238 s += "</span></p>";
239 }
240 else
241 {
242 s += "Conrad, O., Bechtel, B., Bock, M., Dietrich, H., Fischer, E., Gerlitz, L., Wehberg, J., Wichmann, V., and B�hner, J. (2015): ";
243 s += "System for Automated Geoscientific Analyses (SAGA) v. 2.1.4, Geosci. Model Dev., 8, 1991-2007, doi:10.5194/gmd-8-1991-2015. ";
244 s += "[SAGA - System for Automated Geoscientific Analyses - saga-gis.org] ";
245 }
246
247 return( Get_Formatted(s, Type) );
248 }
249
250 //---------------------------------------------------------
Get_ID(CSG_Parameter * pParameter,const CSG_String & Modifier)251 CSG_String CArcToolBox::Get_ID(CSG_Parameter *pParameter, const CSG_String &Modifier)
252 {
253 CSG_String ID(pParameter->Get_Parameters()->Get_Identifier());
254
255 if( ID.Length() > 0 )
256 {
257 ID += SG_T("_");
258 }
259
260 ID += pParameter->Get_Identifier();
261
262 if( Modifier.Length() > 0 )
263 {
264 ID += SG_T("_") + Modifier;
265 }
266
267 return( ID );
268 }
269
270 //---------------------------------------------------------
Get_GridTarget(CSG_Parameters * pParameters)271 CSG_Parameter * CArcToolBox::Get_GridTarget(CSG_Parameters *pParameters)
272 {
273 CSG_Parameter *pParameter = pParameters->Get_Parameter("TARGET_DEFINITION");
274
275 if( pParameter && pParameter->Get_Type() == PARAMETER_TYPE_Choice )
276 {
277 return( pParameter );
278 }
279
280
281 return( NULL );
282 }
283
284
285 ///////////////////////////////////////////////////////////
286 // //
287 ///////////////////////////////////////////////////////////
288
289 //---------------------------------------------------------
290 enum
291 {
292 ARC_Raster = 0,
293 ARC_Feature,
294 ARC_TableView,
295 ARC_Boolean,
296 ARC_Long,
297 ARC_Double,
298 ARC_String,
299 ARC_Folder,
300 ARC_File,
301 ARC_Field,
302 ARC_Table,
303 ARC_nTypes
304 };
305
306 //---------------------------------------------------------
307 const CSG_String ArcDataTypes[ARC_nTypes][2] =
308 {
309 { "Raster Layer" , "GPRasterLayer" },
310 { "Feature Layer", "GPFeatureLayer" },
311 { "Table View" , "GPTableView" },
312 { "Boolean" , "GPBoolean" },
313 { "Long" , "GPLong" },
314 { "Double" , "GPDouble" },
315 { "String" , "GPString" },
316 { "Folder" , "DEFolder" },
317 { "File" , "DEFile" },
318 { "Field" , "Field" },
319 { "Table" , "DETable" }
320 };
321
322 //---------------------------------------------------------
323 #define ArcDataType(type, multi) ", datatype=\"" + ArcDataTypes[type][m_ArcVersion] + (multi ? "\", multiValue=True)\n" : "\")\n")
324
325 //---------------------------------------------------------
Get_Parameter(CSG_Parameter * pParameter,CSG_Strings & Infos,CSG_Strings & Init,CSG_MetaData & Descs,const CSG_String & Name,const CSG_String & Identifier)326 bool CArcToolBox::Get_Parameter(CSG_Parameter *pParameter, CSG_Strings &Infos, CSG_Strings &Init, CSG_MetaData &Descs, const CSG_String &Name, const CSG_String &Identifier)
327 {
328 CSG_String Info("\t\tparam = arcpy.Parameter(");
329
330 Info += "displayName=\"" + Name + "\"";
331 Info += ", name=\"" + Identifier + "\"";
332 Info += ", direction=\"" + CSG_String(pParameter->is_Output() ? "Output" : "Input") + "\"";
333 Info += ", parameterType=\"" + CSG_String(pParameter->is_Option() || pParameter->is_Optional() ? "Optional" : "Required") + "\"";
334
335 switch( pParameter->Get_Type() )
336 {
337 //-----------------------------------------------------
338 case PARAMETER_TYPE_Grid : Info += ArcDataType(ARC_Raster , false); break;
339 case PARAMETER_TYPE_Grid_List : Info += ArcDataType(ARC_Raster , true); break;
340
341 case PARAMETER_TYPE_Table : Info += ArcDataType(ARC_TableView, false); break;
342 case PARAMETER_TYPE_Table_List : Info += ArcDataType(ARC_TableView, true); break;
343
344 case PARAMETER_TYPE_Shapes :
345 Info += ArcDataType(ARC_Feature , false);
346 switch( pParameter->is_Input() ? ((CSG_Parameter_Shapes *)pParameter)->Get_Shape_Type() : SHAPE_TYPE_Undefined )
347 {
348 case SHAPE_TYPE_Point : Info += "\t\tparam.filter.list = [\"Point\"]\n" ; break;
349 case SHAPE_TYPE_Points : Info += "\t\tparam.filter.list = [\"Multipoint\"]\n"; break;
350 case SHAPE_TYPE_Line : Info += "\t\tparam.filter.list = [\"Polyline\"]\n" ; break;
351 case SHAPE_TYPE_Polygon: Info += "\t\tparam.filter.list = [\"Polygon\"]\n" ; break;
352 }
353 break;
354
355 case PARAMETER_TYPE_Shapes_List :
356 Info += ArcDataType(ARC_Feature , true);
357 switch( pParameter->is_Input() ? ((CSG_Parameter_Shapes_List *)pParameter)->Get_Shape_Type() : SHAPE_TYPE_Undefined )
358 {
359 case SHAPE_TYPE_Point : Info += "\t\tparam.filter.list = [\"Point\"]\n" ; break;
360 case SHAPE_TYPE_Points : Info += "\t\tparam.filter.list = [\"Multipoint\"]\n"; break;
361 case SHAPE_TYPE_Line : Info += "\t\tparam.filter.list = [\"Polyline\"]\n" ; break;
362 case SHAPE_TYPE_Polygon: Info += "\t\tparam.filter.list = [\"Polygon\"]\n" ; break;
363 }
364 break;
365
366 case PARAMETER_TYPE_PointCloud :
367 case PARAMETER_TYPE_PointCloud_List: return( false );
368
369 case PARAMETER_TYPE_TIN :
370 case PARAMETER_TYPE_TIN_List : return( false );
371
372 case PARAMETER_TYPE_DataObject_Output:
373 return( false );
374
375 //-----------------------------------------------------
376 case PARAMETER_TYPE_Bool:
377 Info += ArcDataType(ARC_Boolean , false);
378 Info += CSG_String::Format("\t\tparam.value = %s\n", pParameter->asBool() ? SG_T("True") : SG_T("False"));
379 break;
380
381 case PARAMETER_TYPE_Int:
382 Info += ArcDataType(ARC_Long , false);
383 Info += CSG_String::Format("\t\tparam.value = %d\n", pParameter->asInt());
384 break;
385
386 case PARAMETER_TYPE_Degree:
387 case PARAMETER_TYPE_Double:
388 Info += ArcDataType(ARC_Double , false);
389 Info += CSG_String::Format("\t\tparam.value = %f\n", pParameter->asDouble());
390 break;
391
392 case PARAMETER_TYPE_Choice:
393 Info += ArcDataType(ARC_String , false);
394 Info += "\t\tparam.filter.list = [\"";
395 for(int i=0; i<pParameter->asChoice()->Get_Count(); i++)
396 {
397 Info += pParameter->asChoice()->Get_Item(i) + CSG_String(i < pParameter->asChoice()->Get_Count() - 1 ? "\", \"" : "\"]\n");
398 }
399 Info += CSG_String::Format("\t\tparam.value = \"%s\"\n", pParameter->asString());
400 break;
401
402 case PARAMETER_TYPE_Date:
403 case PARAMETER_TYPE_String:
404 case PARAMETER_TYPE_Text:
405 Info += ArcDataType(ARC_String , false);
406 Info += CSG_String::Format("\t\tparam.value = \"%s\"\n", Get_Formatted(pParameter->asString(), FORMAT_PLAIN).c_str());
407 break;
408
409 case PARAMETER_TYPE_FilePath:
410 if( pParameter->asFilePath()->is_Directory() )
411 {
412 Info += ArcDataType(ARC_Folder, false);
413 }
414 else
415 {
416 Info += ArcDataType(ARC_File, pParameter->asFilePath()->is_Multiple());
417 }
418 break;
419
420 case PARAMETER_TYPE_FixedTable:
421 Info += ArcDataType(ARC_Table , false);
422 break;
423
424 case PARAMETER_TYPE_Table_Field:
425 Info += ArcDataType(ARC_Field , false);
426 Info += CSG_String::Format("\t\tparam.parameterDependencies = [\"%s\"]\n", pParameter->Get_Parent()->Get_Identifier());
427 break;
428
429 case PARAMETER_TYPE_Table_Fields:
430 Info += ArcDataType(ARC_Field , true);
431 Info += CSG_String::Format("\t\tparam.parameterDependencies = [\"%s\"]\n", pParameter->Get_Parent()->Get_Identifier());
432 break;
433
434 //-----------------------------------------------------
435 case PARAMETER_TYPE_Grid_System:
436 return( pParameter->Get_Children_Count() > 0 );
437 return( true );
438
439 //-----------------------------------------------------
440 case PARAMETER_TYPE_Font:
441 case PARAMETER_TYPE_Color:
442 case PARAMETER_TYPE_Colors:
443 default:
444 return( true );
445 }
446
447 if( Infos.Get_Count() == 0 )
448 {
449 Infos += Info + "\t\tparams = [param]\n";
450 }
451 else
452 {
453 Infos += Info + "\t\tparams += [param]\n";
454 }
455
456 // # param.filter.type = "ValueList"
457 // # param.schema.clone = True
458
459 //-----------------------------------------------------
460 if( pParameter->is_Option() )
461 {
462 Init += CSG_String::Format("\t\tTool.Set_Option('%s', parameters[%d].valueAsText)\n",
463 Identifier.c_str(), Init.Get_Count()
464 );
465 }
466 else if( pParameter->is_Input() )
467 {
468 Init += CSG_String::Format("\t\tTool.Set_Input ('%s', parameters[%d].valueAsText, '%s')\n",
469 Identifier.c_str(), Init.Get_Count(), pParameter->Get_Type_Identifier().c_str()
470 );
471 }
472 else if( pParameter->is_Output() )
473 {
474 Init += CSG_String::Format("\t\tTool.Set_Output('%s', parameters[%d].valueAsText, '%s')\n",
475 Identifier.c_str(), Init.Get_Count(), pParameter->Get_Type_Identifier().c_str()
476 );
477 }
478
479 //-----------------------------------------------------
480 CSG_MetaData &Desc = *Descs.Add_Child("param");
481
482 Desc.Add_Property( "name", Identifier);
483 Desc.Add_Property("displayname", pParameter->Get_Name ());
484 Desc.Add_Property( "type", pParameter->is_Option() || pParameter->is_Optional() ? "Optional" : "Required");
485 Desc.Add_Property( "direction", pParameter->is_Input() ? "Input" : "Output");
486
487 Desc.Add_Child("dialogReference", Get_Formatted(pParameter->Get_Description(PARAMETER_DESCRIPTION_ALL), FORMAT_HTML_TXT));
488
489 //-----------------------------------------------------
490 return( true );
491 }
492
493 //---------------------------------------------------------
Get_Parameter(CSG_Parameter * pParameter,CSG_Strings & Infos,CSG_Strings & Init,CSG_MetaData & Descs,CSG_Parameter * pGridTarget)494 bool CArcToolBox::Get_Parameter(CSG_Parameter *pParameter, CSG_Strings &Infos, CSG_Strings &Init, CSG_MetaData &Descs, CSG_Parameter *pGridTarget)
495 {
496 if( !pParameter->do_UseInCMD() )
497 {
498 return( true );
499 }
500
501 if( pGridTarget )
502 {
503 if( pGridTarget == pParameter )
504 {
505 return( true );
506 }
507
508 if( pGridTarget == pParameter->Get_Parent() && SG_STR_CMP(pParameter->Get_Identifier(), "TARGET_USER_SIZE") )
509 {
510 return( true );
511 }
512 else if( pParameter->Get_Type() == PARAMETER_TYPE_Grid && !SG_STR_CMP(pParameter->Get_Identifier(), "TARGET_TEMPLATE") )
513 {
514 return( true );
515 }
516 }
517
518 CSG_String Name(pParameter->Get_Name());
519
520 switch( pParameter->Get_Type() )
521 {
522 default:
523 return( Get_Parameter(pParameter, Infos, Init, Descs, Name, Get_ID(pParameter, "")) );
524
525 case PARAMETER_TYPE_Range:
526 return( Get_Parameter(pParameter->asRange()->Get_Min_Parameter(), Infos, Init, Descs, Name + " (Minimum)", Get_ID(pParameter, "MIN"))
527 && Get_Parameter(pParameter->asRange()->Get_Max_Parameter(), Infos, Init, Descs, Name + " (Maximum)", Get_ID(pParameter, "MAX")) );
528
529 case PARAMETER_TYPE_Parameters:
530 return( false );
531 }
532 }
533
534
535 ///////////////////////////////////////////////////////////
536 // //
537 ///////////////////////////////////////////////////////////
538
539 //---------------------------------------------------------
Get_Tool(CSG_Tool_Library * pLibrary,int iTool,CSG_String & Code,CSG_MetaData & Description)540 bool CArcToolBox::Get_Tool(CSG_Tool_Library *pLibrary, int iTool, CSG_String &Code, CSG_MetaData &Description)
541 {
542 CSG_Tool *pTool = pLibrary->Get_Tool(iTool);
543
544 if( pTool == NULL || pTool == TLB_INTERFACE_SKIP_TOOL || pTool->needs_GUI() || pTool->is_Interactive() || pTool->Get_Parameters_Count() > 0 )
545 {
546 return( false );
547 }
548
549 Code.Clear();
550
551 //-----------------------------------------------------
552 {
553 Description.Destroy();
554 Description.Set_Name("metadata");
555 Description.Add_Property("xml:lang", "en");
556
557 CSG_MetaData &Esri = *Description.Add_Child("Esri");
558 Esri.Add_Child ("CreaDate" , "20150910");
559 Esri.Add_Child ("CreaTime" , "11550000");
560 Esri.Add_Child ("ArcGISFormat" , "1.0");
561 Esri.Add_Child ("SyncOnce" , "TRUE");
562 Esri.Add_Child ("ArcGISProfile", "ItemDescription");
563
564 CSG_MetaData &Tool = *Description.Add_Child("tool");
565 Tool.Add_Property("name" , CSG_String::Format("tool_%d", iTool));
566 Tool.Add_Property("displayname" , Get_Formatted(pTool->Get_Name(), FORMAT_ASCII));
567 Tool.Add_Property("toolboxalias" , "");
568 Tool.Add_Property("xmlns" , "");
569 // Tool.Add_Child ("arcToolboxHelpPath", "");
570 Tool.Add_Child ("parameters");
571 Tool.Add_Child ("summary" , pTool->Get_Description());
572
573 CSG_MetaData &Info = *Description.Add_Child("dataIdInfo");
574 Info.Add_Child ("idCitation")->Add_Child("resTitle", Get_Formatted(pTool->Get_Author(), FORMAT_ASCII));
575 // Info.Add_Child ("idAbs" , Get_Description(pTool, FORMAT_HTML_TXT));
576 Info.Add_Child ("idCredit" , Get_Description(NULL, FORMAT_ASCII));
577 Info.Add_Child ("searchKeys");
578 Info("searchKeys")->Add_Child("SAGA");
579 }
580
581 //-----------------------------------------------------
582 CSG_Strings Info, Init;
583
584 CSG_Parameter *pGridTarget = Get_GridTarget(pTool->Get_Parameters());
585
586 for(int i=0; i<pTool->Get_Parameters()->Get_Count(); i++)
587 {
588 if( !Get_Parameter(pTool->Get_Parameters()->Get_Parameter(i), Info, Init, *Description["tool"]("parameters"), pGridTarget) )
589 {
590 return( false );
591 }
592 }
593
594 //-----------------------------------------------------
595 Code += "\n";
596 Code += "\n";
597 Code += CSG_String::Format("class tool_%d(object):\n", iTool);
598 Code += "\tdef __init__(self):\n";
599 Code += "\t\tself.label = \"" + pTool->Get_Name() + "\"\n";
600 Code += "\t\tself.description = \"" + Get_Description(pTool, FORMAT_HTML) + "\"\n";
601 Code += "\t\tself.canRunInBackground = False\n";
602
603 //-----------------------------------------------------
604 Code += "\n";
605 Code += "\tdef getParameterInfo(self):\n";
606
607 for(int i=0; i<Info.Get_Count(); i++)
608 {
609 Code += Info[i];
610 }
611
612 Code += "\t\treturn params\n";
613
614 //-----------------------------------------------------
615 // Code += "\n";
616 // Code += "\tdef updateParameters(self, parameters):\n";
617 // Code += "\t\treturn\n";
618
619 // Code += "\n";
620 // Code += "\tdef updateMessages(self, parameters):\n";
621 // Code += "\t\treturn\n";
622
623 //-----------------------------------------------------
624 Code += "\n";
625 Code += "\tdef execute(self, parameters, messages):\n";
626 Code += "\t\tTool = ArcSAGA.SAGA_Tool('" + pLibrary->Get_Library_Name() + "', '" + pTool->Get_ID() + "')\n";
627
628 for(int i=0; i<Init.Get_Count(); i++)
629 {
630 Code += Init[i];
631 }
632
633 Code += "\t\tTool.Run()\n";
634 Code += "\t\treturn\n";
635
636 //-----------------------------------------------------
637 return( true );
638 }
639
640
641 ///////////////////////////////////////////////////////////
642 // //
643 ///////////////////////////////////////////////////////////
644
645 //---------------------------------------------------------
Save(CSG_Tool_Library * pLibrary,const CSG_String & Directory,const CSG_Strings & Names,const CSG_Strings & Codes,const CSG_Strings & Descs)646 bool CArcToolBox::Save(CSG_Tool_Library *pLibrary, const CSG_String &Directory, const CSG_Strings &Names, const CSG_Strings &Codes, const CSG_Strings &Descs)
647 {
648 if( Codes.Get_Count() <= 0 )
649 {
650 return( false );
651 }
652
653 CSG_String FileName = Parameters("BOX_NAMING")->asInt() == 0
654 ? SG_File_Make_Path(Directory, Get_Formatted(pLibrary->Get_Library_Name(), FORMAT_FILE), SG_T(""))
655 : SG_File_Make_Path(Directory, Get_Formatted(pLibrary->Get_Category (), FORMAT_FILE), SG_T("")) + " - " + Get_Formatted(pLibrary->Get_Name(), FORMAT_FILE);
656
657 CSG_File Stream;
658
659 if( !Stream.Open(FileName + ".pyt", SG_FILE_W, true) )
660 {
661 return( false );
662 }
663
664 //-----------------------------------------------------
665 CSG_String s;
666
667 s += "import arcpy, ArcSAGA\n";
668 s += "\n";
669 s += "class Toolbox(object):\n";
670 s += "\tdef __init__(self):\n";
671 s += "\t\tself.label = \"" + pLibrary->Get_Name() + "\"\n";
672 s += "\t\tself.alias = \"\"\n";
673 s += "\t\tself.tools = [";
674
675 for(int i=0; i<Names.Get_Count(); i++)
676 {
677 s += Names[i] + (i < Names.Get_Count() - 1 ? ", " : "]");
678 }
679
680 for(int i=0; i<Codes.Get_Count(); i++)
681 {
682 s += Codes[i];
683 }
684
685 while( s.Length() > 0 )
686 {
687 Stream.Write(s.BeforeFirst('\n')); Stream.Write("\n"); s = s.AfterFirst('\n');
688 }
689
690 //-----------------------------------------------------
691 for(int i=0; i<Descs.Get_Count(); i++)
692 {
693 s = FileName + "." + Names[i] + ".pyt.xml";
694
695 if( Stream.Open(s, SG_FILE_W, true) )
696 {
697 s = Descs[i]; s.Replace("&", "&");
698
699 while( s.Length() > 0 )
700 {
701 Stream.Write(s.BeforeFirst('\n')); Stream.Write("\n"); s = s.AfterFirst('\n');
702 }
703 }
704 }
705
706 //-----------------------------------------------------
707 return( true );
708 }
709
710
711 ///////////////////////////////////////////////////////////
712 // //
713 // //
714 // //
715 ///////////////////////////////////////////////////////////
716
717 //---------------------------------------------------------
718