/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ fun deleteOb(inst)= 0;; struct VarStr = [ PVAR_value : S, PVAR_type : S ] MkVarStr;; fun opFloats(sp, v, op)= let strextr sp -> l in let "" -> nv in ( while (l != nil) do ( let hd l -> lv1 in ( if (((hd lv1) != nil) && ((strlen nv) != 0)) then set nv = strcat nv "\n"; let 0 -> nbval in while (lv1 != nil) do ( let hd lv1 -> v2 in let if (op == 1) then (ftoa ((atof v2) +. v)) else (ftoa ((atof v2) -. v)) -> av in if (nbval == 0) then set nv = strcat nv av else set nv = strcatn nv::" "::av::nil; set lv1 = tl lv1; set nbval = nbval + 1; ); ); set l = tl l; ); nv; );; fun opInts(sp, v, op)= let strextr sp -> l in let "" -> nv in ( while (l != nil) do ( let hd l -> lv1 in ( if (((hd lv1) != nil) && ((strlen nv) != 0)) then set nv = strcat nv "\n"; let 0 -> nbval in while (lv1 != nil) do ( let hd lv1 -> v2 in let if (op == 1) then (itoa ((atoi v2) + v)) else (itoa ((atoi v2) - v)) -> av in if (nbval == 0) then set nv = strcat nv av else set nv = strcatn nv::" "::av::nil; set lv1 = tl lv1; set nbval = nbval + 1; ); ); set l = tl l; ); nv; );; fun cbGetValue(inst, from, action, param, reply, varstr)= // replace $0, $1.. and %var% let _DMSreadParam param varstr.PVAR_value -> value in SendPluginEvent inst "Value" value nil; 0;; fun cbGetLine(inst, from, action, param, reply, varstr)= let if param == nil then 0 else atoi param -> line in SendPluginEvent inst "Value" (strcatnSep (nth_list (strextr varstr.PVAR_value) line) " ") nil; 0;; fun cbSetValue(inst, from, action, param, reply, varstr)= let if !strcmp param "NIL" then nil else param -> param in let if !strcmp varstr.PVAR_type "String" then param else if !strcmp varstr.PVAR_type "Hexa" then itoh (htoi param) else if !strcmp varstr.PVAR_type "Float" then opFloats param 0.0 1 else opInts param 0 1 -> value in set varstr.PVAR_value = value; SendPluginEvent inst "Modified" varstr.PVAR_value nil; 0;; fun cbConcat(inst, from, action, param, reply, varstr)= let strcat varstr.PVAR_value param -> value in ( set varstr.PVAR_value = value; SendPluginEvent inst "Modified" varstr.PVAR_value nil; ); 0;; fun cbIncrement(inst, from, action, param, reply, varstr)= let if !strcmp varstr.PVAR_type "String" then strcat varstr.PVAR_value param else if !strcmp varstr.PVAR_type "Hexa" then itoh ((htoi varstr.PVAR_value) + (htoi param)) else if !strcmp varstr.PVAR_type "Float" then opFloats varstr.PVAR_value (atof param) 1 else opInts varstr.PVAR_value (atoi param) 1 -> value in ( set varstr.PVAR_value = value; SendPluginEvent inst "Modified" varstr.PVAR_value nil; ); 0;; fun cbDecrement(inst, from, action, param, reply, varstr)= let if !strcmp varstr.PVAR_type "String" then (substr varstr.PVAR_value 0 (strlen varstr.PVAR_value)-1) else if !strcmp varstr.PVAR_type "Hexa" then itoh ((htoi varstr.PVAR_value) - (htoi param)) else if !strcmp varstr.PVAR_type "Float" then opFloats varstr.PVAR_value (atof param) 0 else opInts varstr.PVAR_value (atoi param) 0 -> value in ( set varstr.PVAR_value = value; SendPluginEvent inst "Modified" varstr.PVAR_value nil; ); 0;; fun newOb(inst)= let (getPluginInstanceParam inst "value") -> value in let if (value == nil) then "" else value -> value in let (getPluginInstanceParam inst "type") -> stype in let MkVarStr [value stype] -> varstr in ( PluginRegisterAction inst "SetValue" mkfun6 @cbSetValue varstr; PluginRegisterAction inst "GetValue" mkfun6 @cbGetValue varstr; PluginRegisterAction inst "GetLine" mkfun6 @cbGetLine varstr; PluginRegisterAction inst "Concat" mkfun6 @cbConcat varstr; PluginRegisterAction inst "Increment" mkfun6 @cbIncrement varstr; PluginRegisterAction inst "Decrement" mkfun6 @cbDecrement varstr; setPluginInstanceCbDel inst @deleteOb; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;