/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ struct VarStr = [ PVAR_sName : S, PVAR_value : S, PVAR_type : S, PVAR_lInstance : [PInstance r1] ] MkVarStr;; typeof lGlobalVar = [[S VarStr] r1];; fun deleteOb(inst, varstr)= set varstr.PVAR_lInstance = remove_from_list varstr.PVAR_lInstance inst; //remove the variable from list only if there is no more instance if (varstr.PVAR_lInstance != nil) then nil else ( set lGlobalVar = remove_sid_from_list lGlobalVar varstr.PVAR_sName; _DMSremoveGlobalVar varstr.PVAR_sName; ); 0;; 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 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 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; _DMSsetGlobalVar varstr.PVAR_sName varstr.PVAR_value; let sizelist varstr.PVAR_lInstance -> size in let 0 -> i in while (i < size) do ( let nth_list varstr.PVAR_lInstance i -> cinst in SendPluginEvent cinst "Modified" varstr.PVAR_value nil; set i = i + 1; ); 0;; fun cbConcat(inst, from, action, param, reply, varstr)= let strcat varstr.PVAR_value param -> value in ( set varstr.PVAR_value = value; _DMSsetGlobalVar varstr.PVAR_sName varstr.PVAR_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; _DMSsetGlobalVar varstr.PVAR_sName varstr.PVAR_value; let sizelist varstr.PVAR_lInstance -> size in let 0 -> i in while (i < size) do ( let nth_list varstr.PVAR_lInstance i -> cinst in SendPluginEvent cinst "Modified" varstr.PVAR_value nil; set i = i + 1; ); ); 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; _DMSsetGlobalVar varstr.PVAR_sName varstr.PVAR_value; let sizelist varstr.PVAR_lInstance -> size in let 0 -> i in while (i < size) do ( let nth_list varstr.PVAR_lInstance i -> cinst in SendPluginEvent cinst "Modified" varstr.PVAR_value nil; set i = i + 1; ); ); 0;; fun newOb(inst)= let (getPluginInstanceParam inst "name") -> name in let (getPluginInstanceParam inst "value") -> value in let (getPluginInstanceParam inst "type") -> stype in let switchstr lGlobalVar name -> varstr in let if varstr == nil then let MkVarStr [name value stype nil] -> tmpstr in ( set lGlobalVar = [name tmpstr]::lGlobalVar; tmpstr; ) else varstr -> varstr in ( _DMSsetGlobalVar varstr.PVAR_sName varstr.PVAR_value; set varstr.PVAR_lInstance = inst::varstr.PVAR_lInstance; 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 mkfun2 @deleteOb varstr; ); 0;; fun IniPlug(file)= set lGlobalVar = nil; PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;