1 | #include <locale.h> |
---|
2 | |
---|
3 | #include <wx/app.h> |
---|
4 | #include <wx/utils.h> |
---|
5 | |
---|
6 | #include <api_core.h> |
---|
7 | #include <module_library.h> |
---|
8 | |
---|
9 | int Callback(TSG_UI_Callback_ID ID, CSG_UI_Parameter &Param_1, CSG_UI_Parameter &Param_2){ |
---|
10 | return( 1 ); |
---|
11 | } |
---|
12 | |
---|
13 | TSG_PFNC_UI_Callback Get_Callback(void){ |
---|
14 | return( &Callback ); |
---|
15 | } |
---|
16 | |
---|
17 | void cleanAbstract(CSG_String abstract,char**res){ |
---|
18 | char* tmp=strdup(abstract.b_str()); |
---|
19 | CSG_String val=CSG_String("")+tmp; |
---|
20 | if(val.Contains("\r")){ |
---|
21 | val.Replace("\r","<br/>"); |
---|
22 | } |
---|
23 | if(val.Contains("\n")){ |
---|
24 | val.Replace("\n","<br/>"); |
---|
25 | } |
---|
26 | if(val.Contains("<")){ |
---|
27 | val.Replace("<","<"); |
---|
28 | } |
---|
29 | if(val.Contains(">")){ |
---|
30 | val.Replace(">",">"); |
---|
31 | } |
---|
32 | free(tmp); |
---|
33 | if(val.is_Empty()) |
---|
34 | *res=NULL; |
---|
35 | else |
---|
36 | *res=strdup(val.b_str()); |
---|
37 | } |
---|
38 | |
---|
39 | void printBasicMetadata(FILE* stdout,CSG_Parameter* param,bool out=false,bool range=false,bool min=true,bool tin=false,char* tname=NULL,char* ttitle=NULL){ |
---|
40 | fprintf(stdout," [%s]\n",(CSG_String(param->Get_Identifier())+(range?(min?"_MIN":"_MAX"):(tin?CSG_String("_")+tname:""))).b_str()); |
---|
41 | fprintf(stdout," Title = %s\n",(CSG_String(param->Get_Name())+(range?(min?" (min value)":" (max value)"):(tin&&ttitle!=NULL?ttitle:""))).b_str()); |
---|
42 | if(CSG_String(param->Get_Description()).is_Empty()) |
---|
43 | fprintf(stdout," Abstract = %s\n",CSG_String(param->Get_Name()).b_str()); |
---|
44 | else{ |
---|
45 | char* tmp=strdup(CSG_String(param->Get_Description()).b_str()); |
---|
46 | CSG_String val=CSG_String("")+tmp; |
---|
47 | if(val.Contains("\r")){ |
---|
48 | val.Replace("\r","<br/>"); |
---|
49 | } |
---|
50 | if(val.Contains("\n")){ |
---|
51 | val.Replace("\n","<br/>"); |
---|
52 | } |
---|
53 | if(val.Contains("<")){ |
---|
54 | val.Replace("<","<"); |
---|
55 | } |
---|
56 | if(val.Contains(">")){ |
---|
57 | val.Replace(">",">"); |
---|
58 | } |
---|
59 | free(tmp); |
---|
60 | fprintf(stdout," Abstract = %s\n",val.b_str()); |
---|
61 | } |
---|
62 | if(!out){ |
---|
63 | if(param->is_Option() || param->is_Optional()){ |
---|
64 | fprintf(stdout," minOccurs = 0\n"); |
---|
65 | if(param->is_Option()) |
---|
66 | fprintf(stdout," maxOccurs = 1\n"); |
---|
67 | else{ |
---|
68 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("_list"))) |
---|
69 | fprintf(stdout," maxOccurs = 1024\n"); |
---|
70 | else |
---|
71 | fprintf(stdout," maxOccurs = 1\n"); |
---|
72 | } |
---|
73 | }else{ |
---|
74 | if(param->is_Input()) |
---|
75 | fprintf(stdout," minOccurs = 1\n"); |
---|
76 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("_list"))) |
---|
77 | fprintf(stdout," maxOccurs = 1024\n"); |
---|
78 | else |
---|
79 | fprintf(stdout," maxOccurs = 1\n"); |
---|
80 | } |
---|
81 | } |
---|
82 | if(range){ |
---|
83 | |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | void printGrids(FILE* stdout){ |
---|
88 | fprintf(stdout," <ComplexData>\n"); |
---|
89 | fprintf(stdout," <Default>\n"); |
---|
90 | fprintf(stdout," mimeType = image/tiff\n"); |
---|
91 | fprintf(stdout," </Default>\n"); |
---|
92 | fprintf(stdout," <Supported>\n"); |
---|
93 | fprintf(stdout," mimeType = application/x-ogc-envi\n"); |
---|
94 | fprintf(stdout," </Supported>\n"); |
---|
95 | fprintf(stdout," <Supported>\n"); |
---|
96 | fprintf(stdout," mimeType = application/x-ogc-aaigrid\n"); |
---|
97 | fprintf(stdout," </Supported>\n"); |
---|
98 | fprintf(stdout," </ComplexData>\n"); |
---|
99 | } |
---|
100 | |
---|
101 | void printShapes(FILE* stdout){ |
---|
102 | fprintf(stdout," <ComplexData>\n"); |
---|
103 | fprintf(stdout," <Default>\n"); |
---|
104 | fprintf(stdout," mimeType = text/xml\n"); |
---|
105 | fprintf(stdout," encoding = utf-8\n"); |
---|
106 | fprintf(stdout," </Default>\n"); |
---|
107 | fprintf(stdout," <Supported>\n"); |
---|
108 | fprintf(stdout," mimeType = application/vnd.google-earth.kml+xml\n"); |
---|
109 | fprintf(stdout," </Supported>\n"); |
---|
110 | fprintf(stdout," <Supported>\n"); |
---|
111 | fprintf(stdout," mimeType = application/json\n"); |
---|
112 | fprintf(stdout," </Supported>\n"); |
---|
113 | fprintf(stdout," </ComplexData>\n"); |
---|
114 | } |
---|
115 | |
---|
116 | void printTables(FILE* stdout){ |
---|
117 | fprintf(stdout," <ComplexData>\n"); |
---|
118 | fprintf(stdout," <Default>\n"); |
---|
119 | fprintf(stdout," mimeType = text/csv\n"); |
---|
120 | fprintf(stdout," encoding = utf-8\n"); |
---|
121 | fprintf(stdout," </Default>\n"); |
---|
122 | fprintf(stdout," <Supported>\n"); |
---|
123 | fprintf(stdout," mimeType = text/csv\n"); |
---|
124 | fprintf(stdout," encoding = base64\n"); |
---|
125 | fprintf(stdout," </Supported>\n"); |
---|
126 | fprintf(stdout," </ComplexData>\n"); |
---|
127 | } |
---|
128 | |
---|
129 | void printPoints(FILE* stdout){ |
---|
130 | fprintf(stdout," <ComplexData>\n"); |
---|
131 | fprintf(stdout," <Default>\n"); |
---|
132 | fprintf(stdout," mimeType = application/x-ogc-lasf\n"); |
---|
133 | fprintf(stdout," extension = las\n"); |
---|
134 | fprintf(stdout," </Default>\n"); |
---|
135 | fprintf(stdout," </ComplexData>\n"); |
---|
136 | } |
---|
137 | |
---|
138 | int main(int argc, char *argv[]) { |
---|
139 | if( !wxInitialize() ){ |
---|
140 | fprintf(stderr,"initialisation failed"); |
---|
141 | return -1; |
---|
142 | } |
---|
143 | setlocale(LC_NUMERIC, "C"); |
---|
144 | static bool g_bShow_Messages = false; |
---|
145 | SG_Set_UI_Callback(Get_Callback()); |
---|
146 | int n = SG_Get_Module_Library_Manager().Add_Directory(wxT(MODULE_LIBRARY_PATH),false); |
---|
147 | if( SG_Get_Module_Library_Manager().Get_Count() <= 0 ){ |
---|
148 | fprintf(stderr,"could not load any tool library"); |
---|
149 | return -2; |
---|
150 | } |
---|
151 | |
---|
152 | for(int i=0;i<SG_Get_Module_Library_Manager().Get_Count();i++){ |
---|
153 | |
---|
154 | CSG_Module_Library * library=SG_Get_Module_Library_Manager().Get_Library(i); |
---|
155 | int lc=library->Get_Count(); |
---|
156 | if(!library->Get_Library_Name().Contains("io_")) { |
---|
157 | |
---|
158 | for(int j=0;j<lc;j++){ |
---|
159 | CSG_Module * module=library->Get_Module(j); |
---|
160 | if(module!=NULL && !module->needs_GUI() /*&& !module->is_Interactive()*/ ){ |
---|
161 | |
---|
162 | mkdir(library->Get_Library_Name().b_str(),0755); |
---|
163 | |
---|
164 | FILE *stdout1=fopen((library->Get_Library_Name()+"/"+module->Get_ID()+".zcfg").b_str(),"w+"); |
---|
165 | fprintf(stdout1,"[%d]\n",j); |
---|
166 | fprintf(stdout1," Title = %s\n",module->Get_Name().b_str()); |
---|
167 | if(CSG_String(module->Get_Description()).is_Empty() || |
---|
168 | module->Get_Description().Length()<module->Get_Name().Length() ) |
---|
169 | fprintf(stdout1," Abstract = %s\n",module->Get_Name().b_str()); |
---|
170 | else{ |
---|
171 | char *val0; |
---|
172 | cleanAbstract(module->Get_Description(),&val0); |
---|
173 | if(val0==NULL) |
---|
174 | fprintf(stdout1," Abstract = %s\n",module->Get_Name().b_str()); |
---|
175 | else{ |
---|
176 | fprintf(stdout1," Abstract = %s\n",val0); |
---|
177 | free(val0); |
---|
178 | } |
---|
179 | } |
---|
180 | fprintf(stdout1," storeSupported = true\n"); |
---|
181 | fprintf(stdout1," statusSupported = true\n"); |
---|
182 | fprintf(stdout1," serviceType = SAGA\n"); |
---|
183 | fprintf(stdout1," serviceProvider = %s\n",library->Get_Library_Name().b_str()); |
---|
184 | CSG_Parameters * params=module->Get_Parameters(); |
---|
185 | int pc=params->Get_Count(); |
---|
186 | |
---|
187 | fprintf(stdout1," <DataInputs>\n"); |
---|
188 | for(int k=0;k<pc;k++){ |
---|
189 | CSG_Parameter * param=params->Get_Parameter(k); |
---|
190 | |
---|
191 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("parameters"),true)){ |
---|
192 | int pc0=param->asParameters()->Get_Count(); |
---|
193 | int l; |
---|
194 | fprintf(stderr,"%s\n",CSG_String(param->Get_Name()).b_str()); |
---|
195 | for(l=0;l<pc0;l++){ |
---|
196 | CSG_Parameter * param0=param->asParameters()->Get_Parameter(l); |
---|
197 | fprintf(stderr,"%s\n",CSG_String(param0->Get_Type_Identifier()).b_str()); |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | // Node should be used for defining Complex ComplexData |
---|
202 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("color"))){ |
---|
203 | |
---|
204 | } |
---|
205 | else if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("range"),true)){ |
---|
206 | |
---|
207 | param->Restore_Default(); |
---|
208 | |
---|
209 | printBasicMetadata(stdout1,param,false,true,true); |
---|
210 | fprintf(stdout1," <LiteralData>\n"); |
---|
211 | fprintf(stdout1," dataType = float\n"); |
---|
212 | CSG_Parameter_Range *range=param->asRange(); |
---|
213 | fprintf(stdout1," <Default>\n"); |
---|
214 | fprintf(stdout1," value = %f\n",((CSG_Parameter_Range*)param->Get_Data())->Get_LoVal()); |
---|
215 | fprintf(stdout1," </Default>\n"); |
---|
216 | fprintf(stdout1," </LiteralData>\n"); |
---|
217 | |
---|
218 | printBasicMetadata(stdout1,param,false,true,false); |
---|
219 | fprintf(stdout1," <LiteralData>\n"); |
---|
220 | fprintf(stdout1," dataType = float\n"); |
---|
221 | fprintf(stdout1," <Default>\n"); |
---|
222 | fprintf(stdout1," value = %f\n",((CSG_Parameter_Range*)param->Get_Data())->Get_HiVal()); |
---|
223 | fprintf(stdout1," </Default>\n"); |
---|
224 | fprintf(stdout1," </LiteralData>\n"); |
---|
225 | |
---|
226 | } |
---|
227 | else if(param!=NULL && !param->is_Output() |
---|
228 | && |
---|
229 | !CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("parameters"),true) |
---|
230 | && |
---|
231 | !CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("grid_system"),true) |
---|
232 | && |
---|
233 | !CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("node"),true)){ |
---|
234 | |
---|
235 | printBasicMetadata(stdout1,param); |
---|
236 | |
---|
237 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("file"),true)){ |
---|
238 | if(CSG_String(param->Get_Description()).Contains(CSG_String("HTML"))){ |
---|
239 | fprintf(stdout1," <ComplexData>\n"); |
---|
240 | fprintf(stdout1," <Default>\n"); |
---|
241 | fprintf(stdout1," mimeType = text/html\n"); |
---|
242 | fprintf(stdout1," encoding = utf-8\n"); |
---|
243 | fprintf(stdout1," </Default>\n"); |
---|
244 | fprintf(stdout1," <ComplexData>\n"); |
---|
245 | } |
---|
246 | else{ |
---|
247 | fprintf(stdout1," <ComplexData>\n"); |
---|
248 | fprintf(stdout1," <Default>\n"); |
---|
249 | if(CSG_String(param->Get_Description()).Contains(CSG_String("HTML"))){ |
---|
250 | fprintf(stdout1," mimeType = text/html\n"); |
---|
251 | }else |
---|
252 | if(CSG_String(param->Get_Description()).Contains(CSG_String("SVG"))){ |
---|
253 | fprintf(stdout1," mimeType = image/svg+xml\n"); |
---|
254 | }else |
---|
255 | fprintf(stdout1," mimeType = text/plain\n"); |
---|
256 | if(CSG_String(param->Get_Description()).Contains(CSG_String("ASCII"))){ |
---|
257 | fprintf(stdout1," encoding = ascii\n"); |
---|
258 | }else |
---|
259 | fprintf(stdout1," encoding = utf-8\n"); |
---|
260 | fprintf(stdout1," </Default>\n"); |
---|
261 | fprintf(stdout1," </ComplexData>\n"); |
---|
262 | } |
---|
263 | } |
---|
264 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("shapes")) || |
---|
265 | CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin")) ){ |
---|
266 | printShapes(stdout1); |
---|
267 | } |
---|
268 | if(CSG_String(param->Get_Type_Identifier()).Contains("points")){ |
---|
269 | printPoints(stdout1); |
---|
270 | } |
---|
271 | if(CSG_String(param->Get_Type_Identifier()).Contains("grid") || |
---|
272 | CSG_String(param->Get_Type_Identifier()).Contains("data_")){ |
---|
273 | printGrids(stdout1); |
---|
274 | } |
---|
275 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("table"))){ |
---|
276 | printTables(stdout1); |
---|
277 | } |
---|
278 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("text"))){ |
---|
279 | fprintf(stdout1," <LiteralData>\n"); |
---|
280 | fprintf(stdout1," dataType = string\n"); |
---|
281 | fprintf(stdout1," <Default>\n"); |
---|
282 | if( !param->Get_Data()->Get_Default().is_Empty() ){ |
---|
283 | fprintf(stdout1," value = %s\n",param->Get_Data()->Get_Default().b_str()); |
---|
284 | } |
---|
285 | fprintf(stdout1," </Default>\n"); |
---|
286 | fprintf(stdout1," </LiteralData>\n"); |
---|
287 | } |
---|
288 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("double"),true) |
---|
289 | || |
---|
290 | CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("degree"),true) |
---|
291 | || |
---|
292 | CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("integer"),true)){ |
---|
293 | fprintf(stdout1," <LiteralData>\n"); |
---|
294 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("double"),true) || |
---|
295 | CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("degree"),true)) |
---|
296 | fprintf(stdout1," dataType = float\n"); |
---|
297 | else |
---|
298 | fprintf(stdout1," dataType = integer\n"); |
---|
299 | |
---|
300 | fprintf(stdout1," <Default>\n"); |
---|
301 | if( !param->Get_Data()->Get_Default().is_Empty() ){ |
---|
302 | fprintf(stdout1," value = %s\n",param->Get_Data()->Get_Default().b_str()); |
---|
303 | } |
---|
304 | if(param->asValue()->has_Minimum() && param->asValue()->has_Maximum()){ |
---|
305 | fprintf(stdout1," rangeMin = %f\n",param->asValue()->Get_Minimum()); |
---|
306 | fprintf(stdout1," rangeMax = %f\n",param->asValue()->Get_Maximum()); |
---|
307 | fprintf(stdout1," rangeClosure = c\n"); |
---|
308 | } |
---|
309 | fprintf(stdout1," </Default>\n"); |
---|
310 | fprintf(stdout1," </LiteralData>\n"); |
---|
311 | } |
---|
312 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("boolean"),true)){ |
---|
313 | fprintf(stdout1," <LiteralData>\n"); |
---|
314 | fprintf(stdout1," dataType = bool\n"); |
---|
315 | fprintf(stdout1," <Default>\n"); |
---|
316 | if( !param->Get_Data()->Get_Default().is_Empty() ){ |
---|
317 | fprintf(stdout1," value = %s\n",(param->Get_Data()->Get_Default().Contains("0")?"false":"true")); |
---|
318 | } |
---|
319 | fprintf(stdout1," </Default>\n"); |
---|
320 | fprintf(stdout1," </LiteralData>\n"); |
---|
321 | } |
---|
322 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("choice"),true)){ |
---|
323 | CSG_Parameter_Choice* choice=param->asChoice(); |
---|
324 | if(choice!=NULL){ |
---|
325 | fprintf(stdout1," <LiteralData>\n"); |
---|
326 | fprintf(stdout1," dataType = string\n"); |
---|
327 | fprintf(stdout1," AllowedValues = "); |
---|
328 | int clen=choice->Get_Count(); |
---|
329 | if(clen>0){ |
---|
330 | for(int l=0;l<clen;l++){ |
---|
331 | //fprintf(stdout1,"%d",l); |
---|
332 | fprintf(stdout1,"%s",(CSG_String(choice->Get_Item(l))).b_str()); |
---|
333 | if(l+1<clen) |
---|
334 | fprintf(stdout1,","); |
---|
335 | } |
---|
336 | fprintf(stdout1,"\n"); |
---|
337 | } |
---|
338 | fprintf(stdout1," <Default>\n"); |
---|
339 | if( !param->Get_Data()->Get_Default().is_Empty() ){ |
---|
340 | fprintf(stdout1," value = %s\n",CSG_String(choice->Get_Item(atoi(param->Get_Data()->Get_Default()))).b_str()); |
---|
341 | } |
---|
342 | fprintf(stdout1," </Default>\n"); |
---|
343 | fprintf(stdout1," </LiteralData>\n"); |
---|
344 | } |
---|
345 | } |
---|
346 | } |
---|
347 | } |
---|
348 | fprintf(stdout1," </DataInputs>\n"); |
---|
349 | fprintf(stdout1," <DataOutputs>\n"); |
---|
350 | |
---|
351 | bool hasOutput=false; |
---|
352 | |
---|
353 | for(int k=0;k<pc;k++){ |
---|
354 | CSG_Parameter * param=params->Get_Parameter(k); |
---|
355 | if(param!=NULL && param->is_Output()){ |
---|
356 | hasOutput=true; |
---|
357 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin"))){ |
---|
358 | char* tinOut[5]={ |
---|
359 | (char*)"POINTS", |
---|
360 | (char*)"CENTER", |
---|
361 | (char*)"EDGES", |
---|
362 | (char*)"TRIANGLES", |
---|
363 | (char*)"POLYGONS" |
---|
364 | }; |
---|
365 | for(int l=0;l<5;l++){ |
---|
366 | char *ttitle=(char*)malloc((strlen(tinOut[l])+8)*sizeof(char)); |
---|
367 | sprintf(ttitle,"%s Shapes",tinOut[l]); |
---|
368 | printBasicMetadata(stdout1,param,true,false,true,true,tinOut[l],ttitle); |
---|
369 | printShapes(stdout1); |
---|
370 | } |
---|
371 | } |
---|
372 | else { |
---|
373 | printBasicMetadata(stdout1,param,true); |
---|
374 | |
---|
375 | if(CSG_String(param->Get_Type_Identifier()).Contains("points")){ |
---|
376 | printPoints(stdout1); |
---|
377 | } |
---|
378 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("shapes"))){ |
---|
379 | printShapes(stdout1); |
---|
380 | } |
---|
381 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("grid")) || |
---|
382 | CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("data_object"))){ |
---|
383 | printGrids(stdout1); |
---|
384 | } |
---|
385 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("table"))){ |
---|
386 | printTables(stdout1); |
---|
387 | } |
---|
388 | |
---|
389 | } |
---|
390 | } |
---|
391 | } |
---|
392 | fprintf(stdout1,"</DataOutputs>\n"); |
---|
393 | fclose(stdout1); |
---|
394 | if(!hasOutput) |
---|
395 | unlink((library->Get_Library_Name()+"/"+module->Get_ID()+".zcfg").b_str()); |
---|
396 | } |
---|
397 | } |
---|
398 | } |
---|
399 | } |
---|
400 | wxUninitialize(); |
---|
401 | |
---|
402 | return 0; |
---|
403 | } |
---|