/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ /* Version : 1.0 First version : 05/08/2010 Author : Bourineau Bastien */ var XFLAG = 1;; var YFLAG = 2;; var ZFLAG = 4;; /*! \brief Callback on instance destruction * * Prototype: fun [PInstance] I * * \param PInstance : destroyed plugIT instance * * \return I : 0 **/ fun deleteOb(inst)= 0;; /*! \brief Callback on "Set Z" dms action * * Set the Z value in the vector tupple and manage state vector flag * * Prototype: fun [PInstance DMI S S I [F F F I]] I * * \param PInstance : plugIT instance * \param DMI : DMS module who call the action (not used) * \param S : name of the launched action * \param S : data posted in DMS action link * \param I : reply flag (not used) * \param [F F F I] : X, Y, Z float value and vector state int value * * \return I : 0 **/ fun cbSetZ(inst, from, action, param, reply, p)= let p -> [x y _ state] in let if (state == XFLAG|YFLAG|ZFLAG) then ZFLAG else (state|ZFLAG) -> nstate in let if (atof param) == nil then 0.0 else (atof param) -> z in ( mutate p <- [_ _ z nstate]; if (nstate == XFLAG|YFLAG|ZFLAG) then SendPluginEvent inst "Out" (strcatnSep (ftoa x)::(ftoa y)::(ftoa z)::nil " ") nil else nil ; ); 0;; /*! \brief Callback on "Set Y" dms action * * Set the Y value in the vector tupple and manage state vector flag * * Prototype: fun [PInstance DMI S S I [F F F I]] I * * \param PInstance : plugIT instance * \param DMI : DMS module who call the action (not used) * \param S : name of the launched action * \param S : data posted in DMS action link * \param I : reply flag (not used) * \param [F F F I] : X, Y, Z float value and vector state int value * * \return I : 0 **/ fun cbSetY(inst, from, action, param, reply, p)= let p -> [x _ z state] in let if (state == XFLAG|YFLAG|ZFLAG) then YFLAG else (state|YFLAG) -> nstate in let if (atof param) == nil then 0.0 else (atof param) -> y in ( mutate p <- [_ y _ nstate]; if (nstate == XFLAG|YFLAG|ZFLAG) then SendPluginEvent inst "Out" (strcatnSep (ftoa x)::(ftoa y)::(ftoa z)::nil " ") nil else nil ; ); 0;; /*! \brief Callback on "Set X" dms action * * Set the X value in the vector tupple and manage state vector flag * * Prototype: fun [PInstance DMI S S I [F F F I]] I * * \param PInstance : plugIT instance * \param DMI : DMS module who call the action (not used) * \param S : name of the launched action * \param S : data posted in DMS action link * \param I : reply flag (not used) * \param [F F F I] : X, Y, Z float value and vector state int value * * \return I : 0 **/ fun cbSetX(inst, from, action, param, reply, p)= let p -> [_ y z state] in let if (state == XFLAG|YFLAG|ZFLAG) then XFLAG else (state|XFLAG) -> nstate in let if (atof param) == nil then 0.0 else (atof param) -> x in ( mutate p <- [x _ _ nstate]; if (nstate == XFLAG|YFLAG|ZFLAG) then SendPluginEvent inst "Out" (strcatnSep (ftoa x)::(ftoa y)::(ftoa z)::nil " ") nil else nil ; ); 0;; /*! \brief Callback on "Get Vector" dms action * * Send directly the current vector * * Prototype: fun [PInstance DMI S S I [F F F I]] I * * \param PInstance : plugIT instance * \param DMI : DMS module who call the action (not used) * \param S : name of the launched action * \param S : data posted in DMS action link * \param I : reply flag (not used) * \param [F F F I] : X, Y, Z float value and vector state int value * * \return I : 0 **/ fun cbGetVec(inst, from, action, param, reply, p)= let p -> [x y z state] in SendPluginEvent inst "Out" (strcatnSep (ftoa x)::(ftoa y)::(ftoa z)::nil " ") nil ; 0;; /*! \brief Callback on "Set Vector" dms action * * Set the current vector * * Prototype: fun [PInstance DMI S S I [F F F I]] I * * \param PInstance : plugIT instance * \param DMI : DMS module who call the action (not used) * \param S : name of the launched action * \param S : data posted in DMS action link * \param I : reply flag (not used) * \param [F F F I] : X, Y, Z float value and vector state int value * * \return I : 0 **/ fun cbSetVec(inst, from, action, param, reply, p)= let 0 -> state in let hd strextr param -> lsvec in let if (atof (hd lsvec)) == nil then 0.0 else (set state = (state|XFLAG); (atof (hd lsvec))) -> x in let if (atof (hd tl lsvec)) == nil then 0.0 else (set state = (state|YFLAG); (atof (hd tl lsvec))) -> y in let if (atof (hd tl tl lsvec)) == nil then 0.0 else (set state = (state|ZFLAG); (atof (hd tl tl lsvec))) -> z in ( mutate p <- [x y z state]; if (state == XFLAG|YFLAG|ZFLAG) then SendPluginEvent inst "Out" (strcatnSep (ftoa x)::(ftoa y)::(ftoa z)::nil " ") nil else nil; ); 0;; /*! \brief Callback on new plugIT instance * * Read the parameters from editor values * * Prototype: fun [PInstance] I * * \param PInstance : plugIT instance * * \return I : 0 **/ fun newOb(inst)= let atof (getPluginInstanceParam inst "x") -> x in let atof (getPluginInstanceParam inst "y") -> y in let atof (getPluginInstanceParam inst "z") -> z in let [x y z (1|2|4)] -> p in ( PluginRegisterAction inst "Set X" mkfun6 @cbSetX p; PluginRegisterAction inst "Set Y" mkfun6 @cbSetY p; PluginRegisterAction inst "Set Z" mkfun6 @cbSetZ p; PluginRegisterAction inst "Get vector" mkfun6 @cbGetVec p; PluginRegisterAction inst "Set vector" mkfun6 @cbSetVec p; ); setPluginInstanceCbDel inst @deleteOb; 0;; /*! \brief Global plugIT function to initialize the plugIT callbacks * * Prototype: fun [S] I * * \param S : plugIT file path * * \return I : 0 **/ fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;