/* ----------------------------------------------------------------------------- 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 getSensors(l)= let sizelist l -> size in let nil -> ndata in let 0 -> i in ( while i < size do ( let nth_list l i -> elem in let strToListSep elem "," -> psensor in ( set ndata = [(strcat "sensor_" (itoa i)) (hd psensor)]::ndata; let (nth_list psensor 1) -> obj in let if !strcmpi obj "none" then "" else obj -> obj in set ndata = [(strcat "sensorObj_" (itoa i)) obj]::ndata; set ndata = [(strcat "sensorSpace_" (itoa i)) (nth_list psensor 2)]::ndata; set ndata = [(strcat "sensorAccel_" (itoa i)) (nth_list psensor 3)]::ndata; set ndata = [(strcat "sensorVelocity_" (itoa i)) (nth_list psensor 4)]::ndata; ); set i = i + 1; ); ndata; );; fun getAnalogEvents(nbval, sepval, state)= if !state then nil else let nil -> ndata in let 0 -> i in ( if sepval then ( while (i < nbval) do ( set ndata = ["EVENT" strcatn "Analog"::(itoa i)::" data"::nil]::ndata; set i = i + 1; ) ) else ( set ndata = ["EVENT" "Analog data"]::ndata; 0; ); if (nbval < 3) then nil else set ndata = ["EVENT" "Control"]::ndata; revertlist ndata; );; fun getButtonEvents(nbval, state)= if !state then nil else let nil -> ndata in let 0 -> i in ( while (i < nbval) do ( set ndata = ["EVENT" strcatn "Button"::(itoa i)::" pressed"::nil]::ndata; set ndata = ["EVENT" strcatn "Button"::(itoa i)::" released"::nil]::ndata; //set ndata = ["EVENT" strcatn "Button"::(itoa i)::" state"::nil]::ndata; set i = i + 1; ); revertlist ndata; );; fun getTrakerEvents(l, state)= if !state then nil else let sizelist l -> size in let nil -> ndata in let 0 -> i in ( while i < size do ( let nth_list l i -> elem in let strToListSep elem "," -> psensor in ( let atoi (hd psensor) -> id in let atoi (nth_list psensor 3) -> accel in let atoi (nth_list psensor 4) -> vel in ( set ndata = ["EVENT" strcatn "Sensor"::(itoa id)::" position"::nil]::ndata; set ndata = ["EVENT" strcatn "Sensor"::(itoa id)::" control"::nil]::ndata; if (!accel) then nil else set ndata = ["EVENT" strcatn "Sensor"::(itoa id)::" acceleration"::nil]::ndata; if (!vel) then nil else set ndata = ["EVENT" strcatn "Sensor"::(itoa id)::" velocity"::nil]::ndata; ); ); set i = i + 1; ); revertlist ndata; );; fun cbCloseEdit(p)= let p -> [ctrlhost ctrlname ctrlanalog ctrlnbanalog ctrlanseperate ctrlbutton ctrlnbbutton ctrltracker ctrlsensors] in let getEdCtrlTextLineValue ctrlhost -> host in let getEdCtrlTextLineValue ctrlname -> name in let getEdCtrlCheckState ctrlanalog -> bAnalog in let ftoi getEdCtrlFloatValue ctrlnbanalog -> nbAnalogValues in let getEdCtrlCheckState ctrlanseperate -> bAnalogSeparateValues in let getEdCtrlCheckState ctrlbutton -> bButton in let ftoi getEdCtrlFloatValue ctrlnbbutton -> nbButtons in let getEdCtrlCheckState ctrltracker -> bTracker in let getEdCtrlListElems ctrlsensors -> lsensor in ["host" host]:: ["name" name]:: ["bAnalog" itoa bAnalog]:: ["nbAnalogValues" itoa nbAnalogValues]:: ["bAnalogSeparateValues" itoa bAnalogSeparateValues]:: ["bButton" itoa bButton]:: ["nbButtons" itoa nbButtons]:: ["bTracker" itoa bTracker]:: lcat lcat (lcat (getSensors lsensor) (getAnalogEvents nbAnalogValues bAnalogSeparateValues bAnalog)) (getButtonEvents nbButtons bButton) (getTrakerEvents lsensor bTracker);; fun cbSelectObj(val, type, p)= let p -> [inst winstr viewstr ctrlobjname] in let V3DgetDefaultSession viewstr -> sessionstr in let SO3SceneGetObject (V3DgetSession sessionstr) val -> obj in if (obj != nil) || (!strcmpi "Current camera" val) || (!strcmpi "Current camera shell" val) then ( setEdCtrlTextLineValue ctrlobjname val; ) else nil; 0;; fun cbCloseRes(ctrlbtn)= setEdCtrlButtonEnable ctrlbtn 1; 0;; fun cbBtnPickObj(ctrlbtn, p)= let p -> [inst winstr viewstr ctrlobjname objname] in ( setEdCtrlButtonEnable ctrlbtn 0; dlgSelectPluginInstanceResource inst winstr iTypeGroup|iTypeEntity|iTypeNode|iTypeLight|iTypeCamera|iTypeParticle|iTypeBone|iTypeCubeMap objname mkfun3 @cbSelectObj [inst winstr viewstr ctrlobjname] mkfun1 @cbCloseRes ctrlbtn 0; ); 0;; fun cbRefreshBtn(pickbtn, p)= let p -> [ctrlobjname] in setEdCtrlTextLineValue ctrlobjname "none"; 0;; fun loadSensors(inst)= let nil -> ndata in let 0 -> i in ( let getPluginInstanceParam inst (strcat "sensor_" (itoa i)) -> id in let getPluginInstanceParam inst (strcat "sensorObj_" (itoa i)) -> obj in let if obj == nil || !strcmpi obj "" then "none" else obj -> obj in let getPluginInstanceParam inst (strcat "sensorSpace_" (itoa i)) -> camspace in let getPluginInstanceParam inst (strcat "sensorAccel_" (itoa i)) -> accel in let getPluginInstanceParam inst (strcat "sensorVelocity_" (itoa i)) -> velocity in while (id != nil) do ( let strcatnSep id::obj::camspace::accel::velocity::nil "," -> elem in set ndata = if i == 0 then elem::nil else lcat ndata elem::nil; set i = i + 1; set id = getPluginInstanceParam inst (strcat "sensor_" (itoa i)); set obj = getPluginInstanceParam inst (strcat "sensorObj_" (itoa i)); if obj == nil || !strcmpi obj "" then set obj = "none" else nil; set camspace = getPluginInstanceParam inst (strcat "sensorSpace_" (itoa i)); set accel = getPluginInstanceParam inst (strcat "sensorAccel_" (itoa i)); set velocity = getPluginInstanceParam inst (strcat "sensorVelocity_" (itoa i)); ); ndata; );; fun cbSetList(ctrlstr, p)= let p -> [ctrllist ctrlsensorid ctrlselectobj ctrlspace ctrlaccel ctrlvelocity] in let itoa (ftoi getEdCtrlFloatValue ctrlsensorid) -> value in if (value == nil) then nil else let getSelectedEdCtrlList ctrllist -> [name _ _] in ( let getEdCtrlTextLineValue ctrlselectobj -> obj in let if obj == nil || !strcmp obj "" then "none" else obj -> obj in let itoa getSelectedEdCtrlSelectPos ctrlspace -> camspace in let itoa getEdCtrlCheckState ctrlaccel -> accel in let itoa getEdCtrlCheckState ctrlvelocity -> velocity in let strcatnSep value::obj::camspace::accel::velocity::nil "," -> nvalue in ( renameEdCtrlListElement ctrllist name nvalue; ); ); 0;; fun cbAddList(ctrlstr, p)= let p -> [ctrllist ctrlsensorid ctrlselectobj ctrlspace ctrlaccel ctrlvelocity] in let itoa (ftoi getEdCtrlFloatValue ctrlsensorid) -> value in if (value == nil) then nil else let getEdCtrlListElems ctrllist -> lelem in ( if (isStringInListiPos lelem value 0 (strlen value)) then nil else let getEdCtrlTextLineValue ctrlselectobj -> obj in let if obj == nil || !strcmp obj "" then "none" else obj -> obj in let itoa getSelectedEdCtrlSelectPos ctrlspace -> camspace in let itoa getEdCtrlCheckState ctrlaccel -> accel in let itoa getEdCtrlCheckState ctrlvelocity -> velocity in let strcatnSep value::obj::camspace::accel::velocity::nil "," -> nvalue in ( addEdCtrlList ctrllist nvalue nil nil; //selectEdCtrlList ctrllist nvalue; setEdCtrlFloatValue ctrlsensorid 0.0; setEdCtrlTextLineValue ctrlselectobj ""; selectEdCtrlSelectByPos ctrlspace 0; setEdCtrlCheckState ctrlaccel 0; setEdCtrlCheckState ctrlvelocity 0; ); ); 0;; fun fillSensorCtrls(value, p)= let p -> [ctrlsensorid ctrlselectobj ctrlspace ctrlaccel ctrlvelocity] in let strToListSep value "," -> psensor in ( setEdCtrlFloatValue ctrlsensorid (atof (hd psensor)); setEdCtrlTextLineValue ctrlselectobj (nth_list psensor 1); selectEdCtrlSelectByPos ctrlspace (atoi (nth_list psensor 2)); setEdCtrlCheckState ctrlaccel (atoi (nth_list psensor 3)); setEdCtrlCheckState ctrlvelocity (atoi (nth_list psensor 4)); ); 0;; fun cbSelectSensor(ctrlstr, pos, elem, lval, type, p)= fillSensorCtrls elem p; 0;; fun cbDelList(ctrlstr, p)= let p -> [ctrllist ctrlsensorid ctrlselectobj ctrlspace ctrlaccel ctrlvelocity] in let getSelectedEdCtrlList ctrllist -> [name _ _] in ( delEdCtrlList ctrllist name; let getSelectedEdCtrlList ctrllist -> [sname _ _] in fillSensorCtrls sname [ctrlsensorid ctrlselectobj ctrlspace ctrlaccel ctrlvelocity]; ); 0;; fun dynamicedit(ewinstr, inst, viewstr, applybtn)= let [420 600] -> [iw ih] in let 10 -> ypos in ( setEdWindowSize ewinstr iw ih; let (getPluginInstanceParam inst "host") -> host in let if host == nil then "localhost" else host -> host in let (getPluginInstanceParam inst "name") -> name in let if name == nil then "" else name -> name in let atoi (getPluginInstanceParam inst "bAnalog") -> bAnalog in let if bAnalog == nil then 0 else bAnalog -> bAnalog in let atof (getPluginInstanceParam inst "nbAnalogValues") -> nbAnalogValues in let if nbAnalogValues == nil then 1.0 else nbAnalogValues -> nbAnalogValues in let atoi (getPluginInstanceParam inst "bAnalogSeparateValues") -> bAnalogSeparateValues in let if bAnalogSeparateValues == nil then 0 else bAnalogSeparateValues -> bAnalogSeparateValues in let atoi (getPluginInstanceParam inst "bButton") -> bButton in let if bButton == nil then 0 else bButton -> bButton in let atof (getPluginInstanceParam inst "nbButtons") -> nbButtons in let if nbButtons == nil then 1.0 else nbButtons -> nbButtons in let atoi (getPluginInstanceParam inst "bTracker") -> bTracker in let if bTracker == nil then 0 else bTracker -> bTracker in let crEdFrameWindow _channel ewinstr 0 0 iw 80 EDWIN_RESIZE_MW nil (loc "OS3DVRPNCONNECTOR_0033") (loc "OS3DVRPNCONNECTOR_0019") -> winfrm in let crEdWindow _channel winfrm 0 18 iw 60 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlLabel winstr 10 ((set ypos = 10) + 2) 160 20 (loc "OS3DVRPNCONNECTOR_0017") nil -> labelhost in let crEdCtrlTextLine winstr 180 ypos 140 20 host nil EDWIN_RESIZE_MW -> ctrlhost in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 160 20 (loc "OS3DVRPNCONNECTOR_0013") nil -> labelname in let crEdCtrlTextLine winstr 180 ypos 140 20 name nil EDWIN_RESIZE_MW -> ctrlname in let crEdFrameWindow _channel ewinstr 0 0 iw 105 EDWIN_RESIZE_MW nil (loc "OS3DVRPNCONNECTOR_0010") (loc "OS3DVRPNCONNECTOR_0019") -> winfrm in let crEdWindow _channel winfrm 0 18 iw 75 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlCheck winstr 10 (set ypos = 10) 280 20 (loc "OS3DVRPNCONNECTOR_0023") EDWIN_RESIZE_MW -> ctrlanalog in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 160 20 (loc "OS3DVRPNCONNECTOR_0021") nil -> labelnbanalog in let crEdCtrlFloat winstr 180 ypos 100 20 nbAnalogValues 1.0 128.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlnbanalog in let crEdCtrlCheck winstr 10 (set ypos = ypos + 25) 280 20 (loc "OS3DVRPNCONNECTOR_0030") EDWIN_RESIZE_MW -> ctrlanseperate in let crEdFrameWindow _channel ewinstr 0 0 iw 80 EDWIN_RESIZE_MW nil (loc "OS3DVRPNCONNECTOR_0011") (loc "OS3DVRPNCONNECTOR_0019") -> winfrm in let crEdWindow _channel winfrm 0 18 iw 60 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlCheck winstr 10 (set ypos = 10) 280 20 (loc "OS3DVRPNCONNECTOR_0024") EDWIN_RESIZE_MW -> ctrlbutton in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 160 20 (loc "OS3DVRPNCONNECTOR_0020") nil -> labelnbbutton in let crEdCtrlFloat winstr 180 ypos 100 20 nbButtons 1.0 128.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlnbbutton in let crEdFrameWindow _channel ewinstr 0 0 iw 330 EDWIN_RESIZE_MW nil (loc "OS3DVRPNCONNECTOR_0032") (loc "OS3DVRPNCONNECTOR_0019") -> winfrm in let crEdWindow _channel winfrm 0 18 iw 310 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlCheck winstr 10 (set ypos = 10) 280 20 (loc "OS3DVRPNCONNECTOR_0025") EDWIN_RESIZE_MW -> ctrltracker in let crEdCtrlList winstr 10 (set ypos = ypos + 25) (iw - 15) 120 LB_BORDER|LB_VSCROLL|ET_TABFOCUS EDWIN_RESIZE_MW|EDWIN_RESIZE_MH -> ctrlsensors in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 125) + 2) 160 20 (loc "OS3DVRPNCONNECTOR_0028") nil -> labelsensorid in let crEdCtrlFloat winstr 180 ypos 100 20 0.0 0.0 256.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlsensorid in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 160 20 (loc "OS3DVRPNCONNECTOR_0029") nil -> labelsensorobj in let crEdCtrlTextLine winstr 180 ypos 145 20 nil nil EDWIN_RESIZE_MW -> ctrlselectobj in let crEdCtrlButton winstr 335 ypos 55 20 "..." nil -> pickobjbtn in let crEdCtrlButton winstr 395 ypos 20 20 "X" nil -> refreshbtn in let crEdCtrlLabel winstr 10 (set ypos = ypos + 25) 160 20 (loc "OS3DVRPNCONNECTOR_0014") nil -> labelspace in let crEdCtrlSelect winstr 180 ypos 145 120 EDWIN_RESIZE_MW -> ctrlspace in let crEdCtrlCheck winstr 10 (set ypos = ypos + 25) 280 20 (loc "OS3DVRPNCONNECTOR_0022") EDWIN_RESIZE_MW -> ctrlaccel in let crEdCtrlCheck winstr 10 (set ypos = ypos + 25) 280 20 (loc "OS3DVRPNCONNECTOR_0026") EDWIN_RESIZE_MW -> ctrlvelocity in let crEdCtrlButton winstr (iw - 275) (set ypos = ypos + 25) 100 20 (loc "OS3DVRPNCONNECTOR_0009") EDWIN_RESIZE_MW -> ctrlbtnadd in let crEdCtrlButton winstr (iw - 170) ypos 80 20 (loc "OS3DVRPNCONNECTOR_0031") EDWIN_RESIZE_MW -> ctrlbtnset in let crEdCtrlButton winstr (iw - 85) ypos 80 20 (loc "OS3DVRPNCONNECTOR_0027") EDWIN_RESIZE_MW -> ctrlbtndel in ( setEdCtrlCheckState ctrlanalog bAnalog; setEdCtrlCheckState ctrlanseperate bAnalogSeparateValues; setEdCtrlCheckState ctrlbutton bButton; setEdCtrlCheckState ctrltracker bTracker; fillEdCtrlSelect ctrlspace (loc "OS3DVRPNCONNECTOR_0034")::(loc "OS3DVRPNCONNECTOR_0018")::(loc "OS3DVRPNCONNECTOR_0012")::nil; selectEdCtrlSelectByPos ctrlspace 0; fillEdCtrlList ctrlsensors (loadSensors inst); setEdCtrlListCbClick ctrlsensors mkfun6 @cbSelectSensor [ctrlsensorid ctrlselectobj ctrlspace ctrlaccel ctrlvelocity]; setEdCtrlButtonCb ctrlbtnadd mkfun2 @cbAddList [ctrlsensors ctrlsensorid ctrlselectobj ctrlspace ctrlaccel ctrlvelocity]; setEdCtrlButtonCb ctrlbtnset mkfun2 @cbSetList [ctrlsensors ctrlsensorid ctrlselectobj ctrlspace ctrlaccel ctrlvelocity]; setEdCtrlButtonCb ctrlbtndel mkfun2 @cbDelList [ctrlsensors ctrlsensorid ctrlselectobj ctrlspace ctrlaccel ctrlvelocity]; setEdCtrlButtonCb pickobjbtn mkfun2 @cbBtnPickObj [inst winstr viewstr ctrlselectobj nil]; setEdCtrlButtonCb refreshbtn mkfun2 @cbRefreshBtn [ctrlselectobj]; setEdCtrlTextLineEnable ctrlselectobj 0; [mkfun1 @cbCloseEdit [ctrlhost ctrlname ctrlanalog ctrlnbanalog ctrlanseperate ctrlbutton ctrlnbbutton ctrltracker ctrlsensors] nil]; ); );;