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