/* ----------------------------------------------------------------------------- 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 */ /*! \brief Callback on instance destruction * * Prototype: fun [PInstance] I * * \param PInstance : destroyed plugIT instance * * \return I : 0 **/ fun deleteOb(inst, p)= let p -> [buff lt trm] in if (trm == nil) then nil else _deltimer trm; setCbCatchLog nil; 0;; fun cbLogTimeout(trm, p)= let p -> [buff lt _] in ( _deltimer trm; if (buff == nil) then nil else addLogMessage buff; mutate p <- [nil _tickcount nil]; ); 0;; /*! \brief Callback on "Show" dms action * * Print data in the console * * Prototype: fun [PInstance DMI S S 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) * * \return I : 0 **/ fun cbPrint(inst, from, action, param, reply, p)= let p -> [buff lt trm] in if ((lt != 0) && ((_tickcount - lt) < 200) && ((strlen buff) < 512)) then ( if (trm == nil) then nil else _deltimer trm; let _rfltimer _starttimer _channel 500 @cbLogTimeout p -> trm in mutate p <- [if (buff == nil) then param else strcat strcat buff "\n>" param _ trm]; 0; ) else ( if (trm == nil) then nil else _deltimer trm; let if (buff == nil) then param else strcat strcat buff "\n>" param -> mess in ( addLogMessage mess; ); mutate p <- [nil _tickcount nil]; 0; ); 0;; fun cbCatchLog(mess, inst)= SendPluginEvent inst "Log" mess 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 atoi (getPluginInstanceParam inst "enable") -> enable in let if enable == nil then 1 else enable -> enable in if !enable then nil else let [nil 0 nil] -> p in ( PluginRegisterAction inst "Print" mkfun6 @cbPrint p; setCbCatchLog mkfun2 @cbCatchLog inst; setPluginInstanceCbDel inst mkfun2 @deleteOb p; ); 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;;