/* ----------------------------------------------------------------------------- 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 VarrayStr = [ PVARRAY_values : tab tab S, PVARRAY_type : S, PVARRAY_iNbRows : I, PVARRAY_iNbCols : I, PVARRAY_iRowIndex : I, PVARRAY_iColIndex : I ] MkVarrayStr;; fun getArrayValue(obstr, row, col)= if ((row >= obstr.PVARRAY_iNbRows) || (col >= obstr.PVARRAY_iNbCols)) then nil else obstr.PVARRAY_values.(row).(col);; fun setArrayValue(obstr, row, col, val)= if ((row >= obstr.PVARRAY_iNbRows) || (col >= obstr.PVARRAY_iNbCols)) then nil else set obstr.PVARRAY_values.(row).(col) = val;; fun getArrayParam(param)= let strextr param -> lp in let hd lp -> pp in let if ((atoi (hd pp)) == nil) then 0 else (atoi (hd pp)) -> row in let if ((atoi (hd tl pp)) == nil) then 0 else (atoi (hd tl pp)) -> col in let strbuildn (tl tl pp)::(tl lp) -> p in [row col p];; fun getArrayIndexParam(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 getArrayFromParam(obstr, param)= let getArrayParam param -> [row col p] in getArrayValue obstr row col;; 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, obstr)= let getArrayParam param -> [row col p] in let getArrayValue obstr row col -> value in SendPluginEvent inst "Value" strcatn (itoa row)::" "::(itoa col)::" "::value::nil nil; 0;; fun cbSetValue(inst, from, action, param, reply, obstr)= let getArrayParam param -> [row col p] in let if !strcmp p "NIL" then nil else p -> p in let if !strcmp obstr.PVARRAY_type "String" then p else if !strcmp obstr.PVARRAY_type "Hexa" then itoh (htoi p) else if !strcmp obstr.PVARRAY_type "Float" then opFloats p 0.0 1 else opInts p 0 1 -> value in ( setArrayValue obstr row col value; SendPluginEvent inst "Modified" strcatn (itoa row)::" "::(itoa col)::" "::value::nil nil; ); 0;; fun cbConcat(inst, from, action, param, reply, obstr)= let getArrayParam param -> [row col p] in let strcat (getArrayValue obstr row col) p -> value in ( setArrayValue obstr row col value; SendPluginEvent inst "Modified" strcatn (itoa row)::" "::(itoa col)::" "::value::nil nil; ); 0;; fun cbIncrement(inst, from, action, param, reply, obstr)= let getArrayParam param -> [row col p] in let getArrayValue obstr row col -> cval in let if !strcmp obstr.PVARRAY_type "String" then strcat cval p else if !strcmp obstr.PVARRAY_type "Hexa" then itoh ((htoi cval) + (htoi p)) else if !strcmp obstr.PVARRAY_type "Float" then opFloats cval (atof p) 1 else opInts cval (atoi p) 1 -> value in ( setArrayValue obstr row col value; SendPluginEvent inst "Modified" strcatn (itoa row)::" "::(itoa col)::" "::value::nil nil; ); 0;; fun cbDecrement(inst, from, action, param, reply, obstr)= let getArrayParam param -> [row col p] in let getArrayValue obstr row col -> cval in let if !strcmp obstr.PVARRAY_type "String" then (substr cval 0 (strlen cval)-1) else if !strcmp obstr.PVARRAY_type "Hexa" then itoh ((htoi cval) - (htoi p)) else if !strcmp obstr.PVARRAY_type "Float" then opFloats cval (atof p) 0 else opInts cval (atoi p) 0 -> value in ( setArrayValue obstr row col value; SendPluginEvent inst "Modified" strcatn (itoa row)::" "::(itoa col)::" "::value::nil nil; ); 0;; fun cbSetArray(inst, from, action, param, reply, obstr)= let if (param == nil) || (!strcmp param "") then let mktab obstr.PVARRAY_iNbRows nil -> mtab in ( let 0 -> t in while (t < obstr.PVARRAY_iNbRows) do ( set mtab.(t) = mktab obstr.PVARRAY_iNbCols ""; set t = t + 1; ); mtab; ) else readCSVdataToTabSized param nil obstr.PVARRAY_iNbRows obstr.PVARRAY_iNbCols -> data in set obstr.PVARRAY_values = data; 0;; fun cbSetNextRow(inst, from, action, param, reply, obstr)= let if (param == nil) || (!strcmp param "") then let "" -> str in ( let 0 -> t in while (t < obstr.PVARRAY_iNbCols) do ( set str = strcat str ";"; set t = t + 1; ); str ) else param -> param in set obstr.PVARRAY_values = readCSVdataToTabRow param nil obstr.PVARRAY_iRowIndex obstr.PVARRAY_values obstr.PVARRAY_iNbRows obstr.PVARRAY_iNbCols; set obstr.PVARRAY_iRowIndex = obstr.PVARRAY_iRowIndex + 1; 0;; fun cbSetRow(inst, from, action, param, reply, obstr)= if (param == nil) || (!strcmp param "") then nil else ( let getArrayIndexParam param -> [index param] in set obstr.PVARRAY_values = readCSVdataToTabRow param nil index obstr.PVARRAY_values obstr.PVARRAY_iNbRows obstr.PVARRAY_iNbCols; ); 0;; fun cbSetNextColumn(inst, from, action, param, reply, obstr)= let if (param == nil) || (!strcmp param "") then let "" -> str in ( let 0 -> t in while (t < obstr.PVARRAY_iNbRows) do ( set str = strcat str ";\n"; set t = t + 1; ); str ) else param -> param in set obstr.PVARRAY_values = readCSVdataToTabColumn param nil obstr.PVARRAY_iColIndex obstr.PVARRAY_values obstr.PVARRAY_iNbRows obstr.PVARRAY_iNbCols; set obstr.PVARRAY_iColIndex = obstr.PVARRAY_iColIndex + 1; 0;; fun cbSetColumn(inst, from, action, param, reply, obstr)= if (param == nil) || (!strcmp param "") then nil else ( let getArrayIndexParam param -> [index param] in set obstr.PVARRAY_values = readCSVdataToTabColumn param nil index obstr.PVARRAY_values obstr.PVARRAY_iNbRows obstr.PVARRAY_iNbCols; ); 0;; fun cbGetArray(inst, from, action, param, reply, obstr)= SendPluginEvent inst "Array" formatCSV nil nil (readCSVTabToData obstr.PVARRAY_values obstr.PVARRAY_iNbRows obstr.PVARRAY_iNbCols) nil; 0;; fun cbReset(inst, from, action, param, reply, obstr)= let mktab obstr.PVARRAY_iNbRows nil -> mtab in ( let 0 -> t in while (t < obstr.PVARRAY_iNbRows) do ( set mtab.(t) = mktab obstr.PVARRAY_iNbCols ""; set t = t + 1; ); set obstr.PVARRAY_values = mtab; set obstr.PVARRAY_iRowIndex = 0; set obstr.PVARRAY_iColIndex = 0; ); 0;; fun newOb(inst)= let (getPluginInstanceParam inst "value") -> value in let (getPluginInstanceParam inst "type") -> stype in let atoi (getPluginInstanceParam inst "nbcols") -> nbcols in let if (nbcols == nil) then 5 else nbcols -> nbcols in let atoi (getPluginInstanceParam inst "nbrows") -> nbrows in let if (nbrows == nil) then 5 else nbrows -> nbrows in let readCSVdataToTabSized value nil nbrows nbcols -> data in let MkVarrayStr [data stype nbrows nbcols 0 0] -> obstr in ( PluginRegisterAction inst "Set array" mkfun6 @cbSetArray obstr; PluginRegisterAction inst "Set next row" mkfun6 @cbSetNextRow obstr; PluginRegisterAction inst "Set row" mkfun6 @cbSetRow obstr; PluginRegisterAction inst "Set next column" mkfun6 @cbSetNextColumn obstr; PluginRegisterAction inst "Set column" mkfun6 @cbSetColumn obstr; PluginRegisterAction inst "Get array" mkfun6 @cbGetArray obstr; PluginRegisterAction inst "Set value" mkfun6 @cbSetValue obstr; PluginRegisterAction inst "Get value" mkfun6 @cbGetValue 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;;