/* ----------------------------------------------------------------------------- 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 PlugListStr = [ PLSTR_type : S, PLSTR_list : [S r1], PLSTR_iIndex : I ] mkPlugListStr;; fun deleteOb(inst)= 0;; fun setListValue(obstr, idx, val)= let sizelist obstr.PLSTR_list -> size in if (idx < size) then set obstr.PLSTR_list = replace_nth_in_list obstr.PLSTR_list idx val else ( let idx - size -> missing in while (missing > 0) do ( set obstr.PLSTR_list = lcat obstr.PLSTR_list ""::nil; set missing = missing - 1; ); set obstr.PLSTR_list = lcat obstr.PLSTR_list val::nil; ); 0;; fun getListParam(param)= let strextr param -> lp in let hd lp -> pp in let if ((atoi (hd pp)) == nil) then 0 else (atoi (hd pp)) -> index in let strbuildn (tl pp)::(tl lp) -> p in [index p];; 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 cbSetList(inst, from, action, param, reply, obstr)= let if (param == nil) || (!strcmp param "") then nil else strToListSep param ";" -> list in set obstr.PLSTR_list = list; 0;; fun cbGetList(inst, from, action, param, reply, obstr)= SendPluginEvent inst "List" (strcatnSep obstr.PLSTR_list ";") nil; 0;; fun cbGetAllValues(inst, from, action, param, reply, obstr)= let sizelist obstr.PLSTR_list -> size in let 0 -> i in while (i < size) do ( SendPluginEvent inst "Value" (nth_list obstr.PLSTR_list i) nil; set i = i + 1; ); 0;; fun cbSetElement(inst, from, action, param, reply, obstr)= if (param == nil || (strcmp (strtrim param) "") == 0) then nil else let getListParam param -> [idx p] in let if !strcmp p "NIL" then nil else p -> p in let if !strcmp obstr.PLSTR_type "String" then p else if !strcmp obstr.PLSTR_type "Hexa" then itoh (htoi p) else if !strcmp obstr.PLSTR_type "Float" then opFloats p 0.0 1 else opInts p 0 1 -> value in ( setListValue obstr idx value; SendPluginEvent inst "Modified" strcatn (itoa idx)::" "::value::nil nil; ); 0;; fun cbGetElement(inst, from, action, param, reply, obstr)= if (param == nil || (strcmp (strtrim param) "") == 0) then nil else let getListParam param -> [idx p] in let nth_list obstr.PLSTR_list idx -> value in SendPluginEvent inst "Element" value nil; 0;; fun cbAddElement(inst, from, action, param, reply, obstr)= set obstr.PLSTR_list = lcat obstr.PLSTR_list param::nil; 0;; fun cbRemoveElement(inst, from, action, param, reply, obstr)= if (param == nil || (strcmp (strtrim param) "") == 0) then set obstr.PLSTR_list = tl obstr.PLSTR_list else let getListParam param -> [idx p] in set obstr.PLSTR_list = remove_nth_from_list obstr.PLSTR_list idx; 0;; fun cbSetIndex(inst, from, action, param, reply, obstr)= if (param == nil || (strcmp (strtrim param) "") == 0) then set obstr.PLSTR_iIndex = (-1) else let getListParam param -> [idx p] in set obstr.PLSTR_iIndex = idx; 0;; fun cbGetCurrentElement(inst, from, action, param, reply, obstr)= let if obstr.PLSTR_iIndex < 0 then 0 else obstr.PLSTR_iIndex -> idx in let nth_list obstr.PLSTR_list idx -> value in SendPluginEvent inst "Element" value nil; 0;; fun cbNextElement(inst, from, action, param, reply, obstr)= if (obstr.PLSTR_iIndex >= ((sizelist obstr.PLSTR_list) - 1)) then SendPluginEvent inst "End of list" nil nil else ( let if obstr.PLSTR_iIndex < (-1) then (-1) else obstr.PLSTR_iIndex -> idx in set obstr.PLSTR_iIndex = idx + 1; let nth_list obstr.PLSTR_list obstr.PLSTR_iIndex -> value in SendPluginEvent inst "Element" value nil; ); 0;; fun cbPreviousElement(inst, from, action, param, reply, obstr)= let sizelist obstr.PLSTR_list -> size in if (obstr.PLSTR_iIndex == 0 || size == 0) then SendPluginEvent inst "Start of list" nil nil else ( let if obstr.PLSTR_iIndex < 0 || obstr.PLSTR_iIndex > size then size else obstr.PLSTR_iIndex -> idx in set obstr.PLSTR_iIndex = idx - 1; let nth_list obstr.PLSTR_list obstr.PLSTR_iIndex -> value in SendPluginEvent inst "Element" value nil; ); 0;; fun cbConcat(inst, from, action, param, reply, obstr)= let getListParam param -> [idx p] in let strcat (nth_list obstr.PLSTR_list idx) p -> value in ( setListValue obstr idx value; SendPluginEvent inst "Modified" strcatn (itoa idx)::" "::value::nil nil; ); 0;; fun cbIncrement(inst, from, action, param, reply, obstr)= let getListParam param -> [idx p] in let nth_list obstr.PLSTR_list idx -> cval in let if !strcmp obstr.PLSTR_type "String" then strcat cval p else if !strcmp obstr.PLSTR_type "Hexa" then itoh ((htoi cval) + (htoi p)) else if !strcmp obstr.PLSTR_type "Float" then opFloats cval (atof p) 1 else opInts cval (atoi p) 1 -> value in ( setListValue obstr idx value; SendPluginEvent inst "Modified" strcatn (itoa idx)::" "::value::nil nil; ); 0;; fun cbDecrement(inst, from, action, param, reply, obstr)= let getListParam param -> [idx p] in let nth_list obstr.PLSTR_list idx -> cval in let if !strcmp obstr.PLSTR_type "String" then (substr cval 0 (strlen cval)-1) else if !strcmp obstr.PLSTR_type "Hexa" then itoh ((htoi cval) - (htoi p)) else if !strcmp obstr.PLSTR_type "Float" then opFloats cval (atof p) 0 else opInts cval (atoi p) 0 -> value in ( setListValue obstr idx value; SendPluginEvent inst "Modified" strcatn (itoa idx)::" "::value::nil nil; ); 0;; fun cbReset(inst, from, action, param, reply, obstr)= set obstr.PLSTR_list = nil; set obstr.PLSTR_iIndex = -1; 0;; fun loadList(inst)= let 0 -> i in let nil -> list in let getPluginInstanceParam inst (strcat "elem_" (itoa i)) -> elem in ( while (elem != nil) do ( set i = i + 1; set list = elem::list; set elem = getPluginInstanceParam inst (strcat "elem_" (itoa i)); ); revertlist list; );; fun newOb(inst)= let (getPluginInstanceParam inst "type") -> stype in let loadList inst -> list in let mkPlugListStr [stype list (-1)] -> obstr in ( PluginRegisterAction inst "Set list" mkfun6 @cbSetList obstr; PluginRegisterAction inst "Get list" mkfun6 @cbGetList obstr; PluginRegisterAction inst "Get all values" mkfun6 @cbGetAllValues obstr; PluginRegisterAction inst "Set element" mkfun6 @cbSetElement obstr; PluginRegisterAction inst "Get element" mkfun6 @cbGetElement obstr; PluginRegisterAction inst "Add element" mkfun6 @cbAddElement obstr; PluginRegisterAction inst "Remove element" mkfun6 @cbRemoveElement obstr; PluginRegisterAction inst "Set index" mkfun6 @cbSetIndex obstr; PluginRegisterAction inst "Get current element" mkfun6 @cbGetCurrentElement obstr; PluginRegisterAction inst "Next element" mkfun6 @cbNextElement obstr; PluginRegisterAction inst "Previous element" mkfun6 @cbPreviousElement obstr; PluginRegisterAction inst "Concat" mkfun6 @cbConcat obstr; PluginRegisterAction inst "Increment" mkfun6 @cbIncrement obstr; PluginRegisterAction inst "Decrement" mkfun6 @cbDecrement obstr; PluginRegisterAction inst "Reset" mkfun6 @cbReset obstr; setPluginInstanceCbDel inst @deleteOb; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;