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 | // Node should be used for defining Complex ComplexData |
---|
192 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("color"))){ |
---|
193 | |
---|
194 | } |
---|
195 | else if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("range"),true)){ |
---|
196 | |
---|
197 | param->Restore_Default(); |
---|
198 | |
---|
199 | printBasicMetadata(stdout1,param,false,true,true); |
---|
200 | fprintf(stdout1," <LiteralData>\n"); |
---|
201 | fprintf(stdout1," dataType = float\n"); |
---|
202 | CSG_Parameter_Range *range=param->asRange(); |
---|
203 | fprintf(stdout1," <Default>\n"); |
---|
204 | fprintf(stdout1," value = %f\n",((CSG_Parameter_Range*)param->Get_Data())->Get_LoVal()); |
---|
205 | fprintf(stdout1," </Default>\n"); |
---|
206 | fprintf(stdout1," </LiteralData>\n"); |
---|
207 | |
---|
208 | printBasicMetadata(stdout1,param,false,true,false); |
---|
209 | fprintf(stdout1," <LiteralData>\n"); |
---|
210 | fprintf(stdout1," dataType = float\n"); |
---|
211 | fprintf(stdout1," <Default>\n"); |
---|
212 | fprintf(stdout1," value = %f\n",((CSG_Parameter_Range*)param->Get_Data())->Get_HiVal()); |
---|
213 | fprintf(stdout1," </Default>\n"); |
---|
214 | fprintf(stdout1," </LiteralData>\n"); |
---|
215 | |
---|
216 | } |
---|
217 | else if(param!=NULL && !param->is_Output() |
---|
218 | && |
---|
219 | !CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("parameters"),true) |
---|
220 | && |
---|
221 | !CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("grid_system"),true) |
---|
222 | && |
---|
223 | !CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("node"),true)){ |
---|
224 | |
---|
225 | printBasicMetadata(stdout1,param); |
---|
226 | |
---|
227 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("file"),true)){ |
---|
228 | if(CSG_String(param->Get_Description()).Contains(CSG_String("HTML"))){ |
---|
229 | fprintf(stdout1," <ComplexData>\n"); |
---|
230 | fprintf(stdout1," <Default>\n"); |
---|
231 | fprintf(stdout1," mimeType = text/html\n"); |
---|
232 | fprintf(stdout1," encoding = utf-8\n"); |
---|
233 | fprintf(stdout1," </Default>\n"); |
---|
234 | fprintf(stdout1," <ComplexData>\n"); |
---|
235 | } |
---|
236 | else{ |
---|
237 | fprintf(stdout1," <ComplexData>\n"); |
---|
238 | fprintf(stdout1," <Default>\n"); |
---|
239 | if(CSG_String(param->Get_Description()).Contains(CSG_String("HTML"))){ |
---|
240 | fprintf(stdout1," mimeType = text/html\n"); |
---|
241 | }else |
---|
242 | if(CSG_String(param->Get_Description()).Contains(CSG_String("SVG"))){ |
---|
243 | fprintf(stdout1," mimeType = image/svg+xml\n"); |
---|
244 | }else |
---|
245 | fprintf(stdout1," mimeType = text/plain\n"); |
---|
246 | if(CSG_String(param->Get_Description()).Contains(CSG_String("ASCII"))){ |
---|
247 | fprintf(stdout1," encoding = ascii\n"); |
---|
248 | }else |
---|
249 | fprintf(stdout1," encoding = utf-8\n"); |
---|
250 | fprintf(stdout1," </Default>\n"); |
---|
251 | fprintf(stdout1," </ComplexData>\n"); |
---|
252 | } |
---|
253 | } |
---|
254 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("shapes")) || |
---|
255 | CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin")) ){ |
---|
256 | printShapes(stdout1); |
---|
257 | } |
---|
258 | if(CSG_String(param->Get_Type_Identifier()).Contains("points")){ |
---|
259 | printPoints(stdout1); |
---|
260 | } |
---|
261 | if(CSG_String(param->Get_Type_Identifier()).Contains("grid") || |
---|
262 | CSG_String(param->Get_Type_Identifier()).Contains("data_")){ |
---|
263 | printGrids(stdout1); |
---|
264 | } |
---|
265 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("table"))){ |
---|
266 | printTables(stdout1); |
---|
267 | } |
---|
268 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("text"))){ |
---|
269 | fprintf(stdout1," <LiteralData>\n"); |
---|
270 | fprintf(stdout1," dataType = string\n"); |
---|
271 | fprintf(stdout1," <Default>\n"); |
---|
272 | if( !param->Get_Data()->Get_Default().is_Empty() ){ |
---|
273 | fprintf(stdout1," value = %s\n",param->Get_Data()->Get_Default().b_str()); |
---|
274 | } |
---|
275 | fprintf(stdout1," </Default>\n"); |
---|
276 | fprintf(stdout1," </LiteralData>\n"); |
---|
277 | } |
---|
278 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("double"),true) |
---|
279 | || |
---|
280 | CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("degree"),true) |
---|
281 | || |
---|
282 | CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("integer"),true)){ |
---|
283 | fprintf(stdout1," <LiteralData>\n"); |
---|
284 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("double"),true) || |
---|
285 | CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("degree"),true)) |
---|
286 | fprintf(stdout1," dataType = float\n"); |
---|
287 | else |
---|
288 | fprintf(stdout1," dataType = integer\n"); |
---|
289 | |
---|
290 | fprintf(stdout1," <Default>\n"); |
---|
291 | if( !param->Get_Data()->Get_Default().is_Empty() ){ |
---|
292 | fprintf(stdout1," value = %s\n",param->Get_Data()->Get_Default().b_str()); |
---|
293 | } |
---|
294 | if(param->asValue()->has_Minimum() && param->asValue()->has_Maximum()){ |
---|
295 | fprintf(stdout1," rangeMin = %f\n",param->asValue()->Get_Minimum()); |
---|
296 | fprintf(stdout1," rangeMax = %f\n",param->asValue()->Get_Maximum()); |
---|
297 | fprintf(stdout1," rangeClosure = c\n"); |
---|
298 | } |
---|
299 | fprintf(stdout1," </Default>\n"); |
---|
300 | fprintf(stdout1," </LiteralData>\n"); |
---|
301 | } |
---|
302 | if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("boolean"),true)){ |
---|
303 | fprintf(stdout1," <LiteralData>\n"); |
---|
304 | fprintf(stdout1," dataType = bool\n"); |
---|
305 | fprintf(stdout1," <Default>\n"); |
---|
306 | if( !param->Get_Data()->Get_Default().is_Empty() ){ |
---|
307 | fprintf(stdout1," value = %s\n",(param->Get_Data()->Get_Default().Contains("0")?"false":"true")); |
---|
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("choice"),true)){ |
---|
313 | CSG_Parameter_Choice* choice=param->asChoice(); |
---|
314 | if(choice!=NULL){ |
---|
315 | fprintf(stdout1," <LiteralData>\n"); |
---|
316 | fprintf(stdout1," dataType = string\n"); |
---|
317 | fprintf(stdout1," AllowedValues = "); |
---|
318 | int clen=choice->Get_Count(); |
---|
319 | if(clen>0){ |
---|
320 | for(int l=0;l<clen;l++){ |
---|
321 | //fprintf(stdout1,"%d",l); |
---|
322 | fprintf(stdout1,"%s",(CSG_String(choice->Get_Item(l))).b_str()); |
---|
323 | if(l+1<clen) |
---|
324 | fprintf(stdout1,","); |
---|
325 | } |
---|
326 | fprintf(stdout1,"\n"); |
---|
327 | } |
---|
328 | fprintf(stdout1," <Default>\n"); |
---|
329 | if( !param->Get_Data()->Get_Default().is_Empty() ){ |
---|
330 | fprintf(stdout1," value = %s\n",CSG_String(choice->Get_Item(atoi(param->Get_Data()->Get_Default()))).b_str()); |
---|
331 | } |
---|
332 | fprintf(stdout1," </Default>\n"); |
---|
333 | fprintf(stdout1," </LiteralData>\n"); |
---|
334 | } |
---|
335 | } |
---|
336 | } |
---|
337 | } |
---|
338 | fprintf(stdout1," </DataInputs>\n"); |
---|
339 | fprintf(stdout1," <DataOutputs>\n"); |
---|
340 | |
---|
341 | bool hasOutput=false; |
---|
342 | |
---|
343 | for(int k=0;k<pc;k++){ |
---|
344 | CSG_Parameter * param=params->Get_Parameter(k); |
---|
345 | if(param!=NULL && param->is_Output()){ |
---|
346 | hasOutput=true; |
---|
347 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin"))){ |
---|
348 | char* tinOut[5]={ |
---|
349 | (char*)"POINTS", |
---|
350 | (char*)"CENTER", |
---|
351 | (char*)"EDGES", |
---|
352 | (char*)"TRIANGLES", |
---|
353 | (char*)"POLYGONS" |
---|
354 | }; |
---|
355 | for(int l=0;l<5;l++){ |
---|
356 | char *ttitle=(char*)malloc((strlen(tinOut[l])+8)*sizeof(char)); |
---|
357 | sprintf(ttitle,"%s Shapes",tinOut[l]); |
---|
358 | printBasicMetadata(stdout1,param,true,false,true,true,tinOut[l],ttitle); |
---|
359 | printShapes(stdout1); |
---|
360 | } |
---|
361 | } |
---|
362 | else { |
---|
363 | printBasicMetadata(stdout1,param,true); |
---|
364 | |
---|
365 | if(CSG_String(param->Get_Type_Identifier()).Contains("points")){ |
---|
366 | printPoints(stdout1); |
---|
367 | } |
---|
368 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("shapes"))){ |
---|
369 | printShapes(stdout1); |
---|
370 | } |
---|
371 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("grid")) || |
---|
372 | CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("data_object"))){ |
---|
373 | printGrids(stdout1); |
---|
374 | } |
---|
375 | if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("table"))){ |
---|
376 | printTables(stdout1); |
---|
377 | } |
---|
378 | |
---|
379 | } |
---|
380 | } |
---|
381 | } |
---|
382 | fprintf(stdout1,"</DataOutputs>\n"); |
---|
383 | fclose(stdout1); |
---|
384 | if(!hasOutput) |
---|
385 | unlink((library->Get_Library_Name()+"/"+module->Get_ID()+".zcfg").b_str()); |
---|
386 | } |
---|
387 | } |
---|
388 | } |
---|
389 | } |
---|
390 | wxUninitialize(); |
---|
391 | |
---|
392 | return 0; |
---|
393 | } |
---|