-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathinternal
150 lines (130 loc) · 4.4 KB
/
internal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// SPDX-License-Identifier: LGPL-3.0-or-later
function convert2Terminals(dict,internal,relativePath,mainlib){
var temp={};
if(!mainlib){
mainlib=temp;
}
for(var key in dict){
if(key=='internal')
continue;
var path=relativePath+"."+key;
if(typeof(dict[key]['createFunction'])=='function'){
temp[key]=dict[key].createFunction(internal,path,mainlib);
}else{
temp[key]=convert2Terminals(dict[key],internal,path,mainlib);
}
}
return temp;
}
function expandTypes(a){
var accpetedType=a.split('|');
if(accpetedType.indexOf('ee.Collection')>=0){
accpetedType.push('ee.FeatureCollection','ee.ImageCollection');
}
if(accpetedType.indexOf('ee.Element')>=0){
accpetedType.push('ee.Feature','ee.Image');
}
if(accpetedType.indexOf('integer')>=0){
accpetedType.push('number');
}
return accpetedType;
}
exports.readInputs=function(args,inputs,algoInfo,relPath){
var output={};
var arrayInput=true;
if(args.length==1 && typeof(args[0])==typeof({})
&& (inputs.map(function(x){return x.name}).filter(function(value){return Object.keys(args[0]).indexOf(value)==-1}).length>0 || (Object.keys(args[0]).length===0))){
output=args[0];
arrayInput=false;
}
var listKeys=Object.keys(output);
for (var i=0; i<inputs.length; i++){
if(listKeys.indexOf(inputs[i].name)>=0){
//if in the dictionary
var localType=exports.typeObject(output[inputs[i].name]);
if(expandTypes(inputs[i].type).indexOf(localType)==-1)
{
throw 'type for '+ inputs[i].name+' should be '+ inputs[i].type+', but was '+localType;
}
}
else{
// if list param
if((args.length<=i) || !arrayInput){
//put default value
if(!inputs[i].optional)
if (inputs[i].defaultValue!='undefined')
output[inputs[i].name]=inputs[i].defaultValue;
else
throw relPath+' require '+inputs[i].name+', but no value or default value provided'
}
else{
//if(!inputs[i].optional)
if(args[i]!==undefined)
{
output[inputs[i].name]=args[i];
var localType=exports.typeObject(output[inputs[i].name]);
if(expandTypes(inputs[i].type).indexOf(localType)==-1 && !inputs[i].optional)
{
throw (i+1)+'-th input should be of type for '+ inputs[i].type+', but was '+localType;
}
}
}
}
}
return output;
}
exports.setupLibrary=function(libs,exp){
var teminals=convert2Terminals(libs,libs.internal,"OpenEEL");
teminals.internal=libs;
libs.ref=[];
libs.internal.addRef=function(ref,path){ref.fullpath=path; libs.ref.push(ref);}
teminals.refs=function(){
return libs.ref;
}
return teminals;
};
function getDoc(dict,relativePath){
var temp={};
for(var key in dict){
if(key=='internal')
continue;
var path=relativePath+"."+key;
if(typeof(dict[key]['createFunction'])=='function'){
temp[key]=dict[key].createDocumentation();
temp[key].fullPath=path;
}else{
temp[key]=getDoc(dict[key],path);
}
}
return temp;
}
exports.getDoc=function(obj){return getDoc(obj,'')}
exports.getDocumentation=function(libs,exp){
return convert2Terminals(libs,"OpenEEL");
};
exports.typeObject=function(a){
if(typeof(a)=='object' && a==null)
return 'null';
if(typeof(a)=='object' && String(a).slice(0,3)=='ee.')
{
return String(a).match('ee.*\\(')[0].slice(0,-1);
}
else
return typeof(a);
}
exports.oeeex={sendMessage:function(val){
print('OEEex_AddonManager:'+val,'if you can see this message, you should download OEEex the Open Earth Engine extension to unravel its full potential!')
}}
exports.oeeex.confirm={retain:function(theKeyText){exports.oeeex.sendMessage('emoveConfirmRetain:'+theKeyText);},
release:function(theKeyText){exports.oeeex.sendMessage('removeConfirmRelease:'+theKeyText);}
}
exports.oeeex.export={image:function(config){exports.oeeex.sendMessage('exportImage:'+JSON.stringify(config));},
video:function(config){exports.oeeex.sendMessage('exportVideo:'+JSON.stringify(config));},
table:function(config){exports.oeeex.sendMessage('exportTable:'+JSON.stringify(config));}
}
exports.usePrompToCallPython=function(instruction,name){
var val=prompt("OEEex_Active_AddonPythonCE",instruction);
if(val.answerType=="error")
throw val.message
return val;
}