/* ----------------------------------------------------------------------------- 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 RTLegend = [ RTL_eltstr : VUIelement, RTL_iWidth : I, RTL_iHeight : I, RTL_bNeedUpdate : I ]mkRTLegend;; struct RTScale = [ RTS_eltstr : VUIelement, RTS_iWidth : I, RTS_iHeight : I, RTS_iNbgrad : I, RTS_bNeedUpdate : I ]mkRTScale;; struct RTCurve = [ RTC_sName : S, RTC_fMin : F, RTC_fMax : F, RTC_iNbDecimals : I, RTC_iColor : I, RTC_lValues : tab F, RTC_fCurValue : F, RTC_iLastYPos : I ]mkRTCurve;; struct PlugRTGraph = [ PRTG_inst : PInstance, PRTG_posstr : InterfacePos, PRTG_contstr : VUIcontainer, PRTG_graphEltstr : VUIelement, PRTG_font : VUIfont, PRTG_vScalestr : RTScale, PRTG_hScalestr : RTScale, PRTG_bLegend : I, PRTG_legendstr : RTLegend, PRTG_iArrayIndex : I, PRTG_lCurves : [RTCurve r1], PRTG_lScales : [[F F I I] r1], PRTG_lTimeStamps : tab I, PRTG_iTimeOrigin : I, PRTG_iHScaleHeight : I, PRTG_iVScaleWidth : I, PRTG_iVScaleTop : I, PRTG_iLegendWidth : I, PRTG_iDisplayTime : I, PRTG_iUpdateRate : I, PRTG_sFilePrefix : S, PRTG_iDateFormat : I, PRTG_wFile : W, PRTG_bSaveAsCsv : I, PRTG_bSaveSize : I, PRTG_tPictureSize : [I I], PRTG_iNextUpdate : I, PRTG_bValuesUpdated : I, PRTG_bValuesLinked : I, PRTG_iStoppedAt : I, PRTG_bShown : I, PRTG_bEnabled : I ]mkPlugRTGraph;; var sRealTimeGraphPath = "tmp/realtimegraph/";; fun deleteOb(inst, obstr)= if (obstr.PRTG_contstr == nil) then nil else VUIdestroyContainer obstr.PRTG_contstr; 0;; fun ftoaNd(val, nbdec)= if nbdec >= 6 then ftoa val else if nbdec == 0 then itoa (ftoi val) else if nbdec == 1 then ftoa1d val else if nbdec == 2 then ftoa2d val else if nbdec == 3 then ftoa3d val else if nbdec == 4 then ftoa4d val else if nbdec == 5 then ftoa5d val else nil;; fun getFormattedTime(dateformat)= let (localtime time) -> [seconds minutes hours day month year wd yd] in if dateformat == 0 then (strtrim strreplace (strreplace (ctime time) " " "_") ":" "-") else if dateformat == 1 then strcatn (itoa year)::(if month < 10 then "0" else "")::(itoa month)::(if day < 10 then "0" else "")::(itoa day)::"_"::(if hours < 10 then "0" else "")::(itoa hours)::(if minutes < 10 then "0" else "")::(itoa minutes)::(if seconds < 10 then "0" else "")::(itoa seconds)::nil else itoa abs time;; fun getFileHeader(obstr)= let "Time" -> line in let sizelist obstr.PRTG_lCurves -> nbcurves in ( let 0 -> i in while (i < nbcurves) do ( let nth_list obstr.PRTG_lCurves i -> curvestr in set line = strcatn line::","::curvestr.RTC_sName::nil; set i = i + 1; ); strcat line "\n"; );; fun createSaveFile(inst, obstr, extension)= let getFormattedTime obstr.PRTG_iDateFormat -> formattedtime in let strcatn obstr.PRTG_sFilePrefix::formattedtime::"_"::(getShortName getPluginInstanceFullname inst)::extension::nil -> filename in let _getmodifypack filename -> wfile in ( if ((strcmp extension ".csv") != 0) then nil else _createpack (getFileHeader obstr) wfile; wfile; );; fun cbDrawGraph(eltstr, obstr)= let eltstr.VUIE_resource.VUIR_oBuffer -> buffer in let _GETalphaBitmaps buffer -> [rgbbmp abmp] in let _GETalphaBitmapSize buffer -> [w h] in let sizelist obstr.PRTG_lCurves -> nbcurves in let sizetab obstr.PRTG_lTimeStamps -> nbvalues in let 0 -> i in ( //calculate the last Y position of each curve while (i < nbcurves) do ( let nth_list obstr.PRTG_lCurves i -> curve in let (curve.RTC_lValues.(obstr.PRTG_iArrayIndex) -. curve.RTC_fMin) /. (curve.RTC_fMax -. curve.RTC_fMin) -> coef in set curve.RTC_iLastYPos = (h - 1) - ftoi ((itof (h - 1)) *. coef); set i = i + 1; ); //Draw each curves from the last value to the first or until the graph is full if (obstr.PRTG_iArrayIndex <= 0) then set i = nbvalues - 1 else set i = obstr.PRTG_iArrayIndex - 1; let obstr.PRTG_lTimeStamps.(obstr.PRTG_iArrayIndex) -> reftime in let w - 1 -> lastxpos in let 0 -> xpos in while (i != obstr.PRTG_iArrayIndex && lastxpos > 0) do ( let obstr.PRTG_lTimeStamps.(i) -> timestamp in set xpos = (w - 1) - (w * (reftime - timestamp)) / (1000 * obstr.PRTG_iDisplayTime); let nbcurves -> j in while (j > 0) do ( set j = j - 1; let nth_list obstr.PRTG_lCurves j -> curve in let ((curve.RTC_lValues.(i)) -. curve.RTC_fMin) /. (curve.RTC_fMax -. curve.RTC_fMin) -> coef in let (h - 1) - ftoi ((itof (h - 1)) *. coef) -> ypos in ( _BTDRAWline rgbbmp [lastxpos curve.RTC_iLastYPos] [xpos ypos] curve.RTC_iColor 1; _BTDRAWline8 abmp [lastxpos curve.RTC_iLastYPos] [xpos ypos] 0xff 1; set curve.RTC_iLastYPos = ypos; ); ); set lastxpos = xpos; if (i > 0) then set i = i - 1 else set i = nbvalues - 1; ); ); 0;; fun cbDrawVScale(eltstr, obstr)= let obstr.PRTG_vScalestr -> vscalestr in let eltstr.VUIE_resource.VUIR_oBuffer -> buffer in let _GETalphaBitmapSize buffer -> [w h] in if (w == vscalestr.RTS_iWidth && h == vscalestr.RTS_iHeight && vscalestr.RTS_bNeedUpdate == 0) then nil else ( //addLogMessage "cbDrawVScale"; let _GETalphaBitmaps buffer -> [rgbbmp abmp] in let if obstr.PRTG_hScalestr.RTS_iNbgrad <= 0 then (h - 21) else (h - obstr.PRTG_iHScaleHeight - 1) -> scalestart in ( _BTDRAWline rgbbmp [(w - 1) obstr.PRTG_iVScaleTop] [(w - 1) scalestart] obstr.PRTG_font.VUIF_iColor 1; _BTDRAWline8 abmp [(w - 1) obstr.PRTG_iVScaleTop] [(w - 1) scalestart] 0xff 1; let 0 -> i in while (i < vscalestr.RTS_iNbgrad + 1) do ( let scalestart - ((i * (scalestart - obstr.PRTG_iVScaleTop)) / vscalestr.RTS_iNbgrad) -> ypos in ( _BTDRAWline rgbbmp [(w - 2) ypos] [(w - 7) ypos] obstr.PRTG_font.VUIF_iColor 1; _BTDRAWline8 abmp [(w - 2) ypos] [(w - 7) ypos] 0xff 1; let max obstr.PRTG_font.VUIF_iFontSize 10 -> fontsize in let fontsize * 2 -> tsize in if ((sizelist obstr.PRTG_lScales) == 1) then ( let hd obstr.PRTG_lScales -> [minval maxval nbdec color] in let ftoaNd ((itof i) *. (maxval -. minval) /. (itof vscalestr.RTS_iNbgrad) +. minval) nbdec -> text in VUIdrawTextAlphaBitmap buffer obstr.PRTG_font [0 (ypos - fontsize) (w - 5) tsize] [0 0] obstr.PRTG_font.VUIF_iColor iVUITEXT_HALIGNRIGHT|iVUITEXT_VALIGNCENTER text; ) else ( let hd obstr.PRTG_lScales -> [minval maxval nbdec color] in let ftoaNd ((itof i) *. (maxval -. minval) /. (itof vscalestr.RTS_iNbgrad) +. minval) nbdec -> text in VUIdrawTextAlphaBitmap buffer obstr.PRTG_font [0 (ypos - tsize) (w - 5) tsize] [0 0] color iVUITEXT_HALIGNRIGHT|iVUITEXT_VALIGNBOTTOM text; let hd tl obstr.PRTG_lScales -> [minval maxval nbdec color] in let ftoaNd ((itof i) *. (maxval -. minval) /. (itof vscalestr.RTS_iNbgrad) +. minval) nbdec -> text in VUIdrawTextAlphaBitmap buffer obstr.PRTG_font [0 ypos (w - 5) tsize] [0 0] color iVUITEXT_HALIGNRIGHT|iVUITEXT_VALIGNTOP text; ); ); set i = i + 1; ); ); set vscalestr.RTS_iWidth = w; set vscalestr.RTS_iHeight = h; set vscalestr.RTS_bNeedUpdate = 0; ); 0;; fun cbDrawHScale(eltstr, obstr)= let obstr.PRTG_hScalestr -> hscalestr in let eltstr.VUIE_resource.VUIR_oBuffer -> buffer in let _GETalphaBitmapSize buffer -> [w h] in if (w == hscalestr.RTS_iWidth && h == hscalestr.RTS_iHeight && hscalestr.RTS_bNeedUpdate == 0) then nil else ( //addLogMessage "cbDrawHScale"; let _GETalphaBitmaps buffer -> [rgbbmp abmp] in let if obstr.PRTG_vScalestr.RTS_iNbgrad <= 0 then [20 20] else [(obstr.PRTG_iVScaleWidth) (obstr.PRTG_iVScaleWidth - 1)] -> [scalestart linestart] in let min (w - obstr.PRTG_iLegendWidth - 1) (w - 21) -> scaleend in ( _BTDRAWline rgbbmp [linestart 0] [scaleend 0] obstr.PRTG_font.VUIF_iColor 1; _BTDRAWline8 abmp [linestart 0] [scaleend 0] 0xff 1; let 0 -> i in let -1 -> prev in while (i < hscalestr.RTS_iNbgrad + 1) do ( let scalestart + ((i * (scaleend - scalestart)) / hscalestr.RTS_iNbgrad) -> xpos in ( _BTDRAWline rgbbmp [xpos 1] [xpos 5] obstr.PRTG_font.VUIF_iColor 1; _BTDRAWline8 abmp [xpos 1] [xpos 5] 0xff 1; let (i * obstr.PRTG_iDisplayTime) / hscalestr.RTS_iNbgrad -> sec in if (sec == prev) then nil else ( set prev = sec; VUIdrawTextAlphaBitmap buffer obstr.PRTG_font [(xpos - 20) 0 40 obstr.PRTG_iHScaleHeight] [0 0] obstr.PRTG_font.VUIF_iColor iVUITEXT_HALIGNCENTER|iVUITEXT_VALIGNTOP (itoa sec); ); ); set i = i + 1; ); ); set hscalestr.RTS_iWidth = w; set hscalestr.RTS_iHeight = h; set hscalestr.RTS_bNeedUpdate = 0; ); 0;; fun cbDrawLegend(eltstr, obstr)= let obstr.PRTG_legendstr -> legendstr in let eltstr.VUIE_resource.VUIR_oBuffer -> buffer in let _GETalphaBitmapSize buffer -> [w h] in if (w == legendstr.RTL_iWidth && h == legendstr.RTL_iHeight && legendstr.RTL_bNeedUpdate == 0) then nil else ( //addLogMessage "cbDrawLegend"; let _GETalphaBitmaps buffer -> [rgbbmp abmp] in let sizelist obstr.PRTG_lCurves -> size in let nil -> ltextheights in let 0 -> legendheight in let obstr.PRTG_iLegendWidth - 40 -> textwidth in ( let 0 -> i in while (i < size) do ( let nth_list obstr.PRTG_lCurves i -> curvestr in let VUIgetTextSize obstr.PRTG_font curvestr.RTC_sName textwidth iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNCENTER -> [tw th] in ( set ltextheights = lcat ltextheights th::nil; set legendheight = legendheight + th; ); set i = i + 1; ); let (h - legendheight) / 2 -> startheight in let 0 -> i in while (i < size) do ( let nth_list obstr.PRTG_lCurves i -> curvestr in let nth_list ltextheights i -> textheight in let startheight + (textheight / 2) -> ypos in ( _BTDRAWline rgbbmp [5 ypos] [25 ypos] curvestr.RTC_iColor 1; _BTDRAWline8 abmp [5 ypos] [25 ypos] 0xff 1; VUIdrawTextAlphaBitmap buffer obstr.PRTG_font [30 startheight textwidth textheight] [0 0] obstr.PRTG_font.VUIF_iColor iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNCENTER curvestr.RTC_sName; set startheight = startheight + textheight; ); set i = i + 1; ); ); set legendstr.RTL_iWidth = w; set legendstr.RTL_iHeight = h; set legendstr.RTL_bNeedUpdate = 0; ); 0;; fun getVScaleWidth(obstr, lscales)= let 0 -> width in ( let sizelist lscales -> size in let 0 -> i in while (i < size && i < 2) do ( let nth_list lscales i -> [minval maxval nbdec color] in let VUIgetTextSize obstr.PRTG_font (ftoaNd minval nbdec) nil iVUITEXT_HALIGNRIGHT|iVUITEXT_VALIGNCENTER -> [minw minh] in let VUIgetTextSize obstr.PRTG_font (ftoaNd maxval nbdec) nil iVUITEXT_HALIGNRIGHT|iVUITEXT_VALIGNCENTER -> [maxw maxh] in set width = max (max maxw minw) width; set i = i + 1; ); width; );; fun getVScales(lcurves)= let nil -> lscales in ( let sizelist lcurves -> size in let 0 -> i in while (i < size) do ( let nth_list lcurves i -> curvestr in let sizelist lscales -> ssize in let 0 -> j in let 0 -> found in ( while (j < ssize && found == 0) do ( let nth_list lscales j -> scale in let scale -> [minval maxval nbdec color] in if (curvestr.RTC_fMin != minval || curvestr.RTC_fMax != maxval) then nil else ( if (curvestr.RTC_iNbDecimals <= nbdec) then nil else mutate scale <- [_ _ curvestr.RTC_iNbDecimals _]; set found = 1; ); set j = j + 1; ); if (found == 1) then nil else set lscales = lcat lscales [curvestr.RTC_fMin curvestr.RTC_fMax curvestr.RTC_iNbDecimals curvestr.RTC_iColor]::nil; ); set i = i + 1; ); lscales; );; fun getLegendWidth(obstr)= let 0 -> width in ( let sizelist obstr.PRTG_lCurves -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.PRTG_lCurves i -> curvestr in let VUIgetTextSize obstr.PRTG_font curvestr.RTC_sName nil iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNCENTER -> [tw th] in set width = max tw width; set i = i + 1; ); set width = min (width + 40) 150; width );; fun updateGraphSizes(obstr)= let [20.0 20.0] -> graphPos in let [1 1 (-40) (-40)] -> graphOffset in ( if (!obstr.PRTG_bLegend) then nil else ( set obstr.PRTG_iLegendWidth = getLegendWidth obstr; VUIsetElementSize obstr.PRTG_legendstr.RTL_eltstr [(itof obstr.PRTG_iLegendWidth) 100.0] nil; mutate graphOffset <- [_ _ (-20 - obstr.PRTG_iLegendWidth) _]; ); if (obstr.PRTG_hScalestr.RTS_iNbgrad <= 0) then nil else ( set obstr.PRTG_iHScaleHeight = ((4 * obstr.PRTG_font.VUIF_iFontSize) + 40) / 3; VUIsetElementSize obstr.PRTG_hScalestr.RTS_eltstr [100.0 (itof obstr.PRTG_iHScaleHeight)] nil; mutate graphPos <- [_ (itof obstr.PRTG_iHScaleHeight)]; mutate graphOffset <- [_ _ _ (-20 - obstr.PRTG_iHScaleHeight)]; ); if (obstr.PRTG_vScalestr.RTS_iNbgrad <= 0) then nil else ( set obstr.PRTG_iVScaleWidth = 10 + (getVScaleWidth obstr obstr.PRTG_lScales); set obstr.PRTG_iVScaleTop = (((if ((sizelist obstr.PRTG_lScales) == 1) then 2 else 4) * obstr.PRTG_font.VUIF_iFontSize) + 40) / 3; VUIsetElementSize obstr.PRTG_vScalestr.RTS_eltstr [(itof obstr.PRTG_iVScaleWidth) 100.0] nil; mutate graphPos <- [(itof obstr.PRTG_iVScaleWidth) _]; let graphOffset -> [_ _ ow oh] in mutate graphOffset <- [_ _ (ow + 20 - obstr.PRTG_iVScaleWidth) (oh + 20 - obstr.PRTG_iVScaleTop)]; ); VUIsetElementPos obstr.PRTG_graphEltstr graphPos nil nil; VUIsetElementSize obstr.PRTG_graphEltstr nil graphOffset; ); 0;; fun cbGraphThemeUpdate(contstr, obstr)= //addLogMessage "cbGraphThemeUpdate"; let VUIgetThemeDef (getThemeFromInstance obstr.PRTG_inst) "common" -> defstr in set obstr.PRTG_font = VUIgetFontFromInterface VUIgetThemeFont defstr "font"; updateGraphSizes obstr; set obstr.PRTG_legendstr.RTL_bNeedUpdate = 1; set obstr.PRTG_hScalestr.RTS_bNeedUpdate = 1; set obstr.PRTG_vScalestr.RTS_bNeedUpdate = 1; 0;; fun createGraph(obstr)= set obstr.PRTG_contstr = crInterfacePosContainer obstr.PRTG_inst obstr.PRTG_posstr c3dXsession; VUIsetContainerThemeCallback obstr.PRTG_contstr mkfun2 @cbGraphThemeUpdate obstr; if (!obstr.PRTG_bLegend) then nil else ( let VUIcreateFrame obstr.PRTG_contstr nil [0.0 0.0] [0.0 100.0] [0 0 0 1 0 0 0 0] [2 2] -> legendeltstr in ( set obstr.PRTG_legendstr = mkRTLegend [legendeltstr 0 0 0]; VUIsetElementCbPreDraw legendeltstr mkfun2 @cbDrawLegend obstr; ); ); if (obstr.PRTG_hScalestr.RTS_iNbgrad <= 0) then nil else ( set obstr.PRTG_hScalestr.RTS_eltstr = VUIcreateFrame obstr.PRTG_contstr nil [0.0 0.0] [100.0 0.0] [0 0 1 0 0 0 0 0] [0 2]; VUIsetElementCbPreDraw obstr.PRTG_hScalestr.RTS_eltstr mkfun2 @cbDrawHScale obstr; ); if (obstr.PRTG_vScalestr.RTS_iNbgrad <= 0) then nil else ( set obstr.PRTG_lScales = getVScales obstr.PRTG_lCurves; set obstr.PRTG_vScalestr.RTS_eltstr = VUIcreateFrame obstr.PRTG_contstr nil [0.0 0.0] [0.0 100.0] [0 0 0 1 0 0 0 0] [0 2]; VUIsetElementCbPreDraw obstr.PRTG_vScalestr.RTS_eltstr mkfun2 @cbDrawVScale obstr; ); set obstr.PRTG_graphEltstr = VUIcreateFrame obstr.PRTG_contstr nil [20.0 20.0] [100.0 100.0] [0 0 1 1 0 0 (-40) (-40)] [0 2]; VUIsetElementCbPreDraw obstr.PRTG_graphEltstr mkfun2 @cbDrawGraph obstr; updateGraphSizes obstr; 0;; fun cbPreRender(inst, viewstr, obstr)= if (obstr.PRTG_iTimeOrigin != 0) then nil else set obstr.PRTG_iTimeOrigin = _tickcount; let _tickcount -> curtime in let ftoa3d ((itof (curtime - obstr.PRTG_iTimeOrigin)) /. 1000.0) -> line in let line -> values in if (curtime < obstr.PRTG_iNextUpdate) then nil else ( if (obstr.PRTG_iArrayIndex >= (sizetab obstr.PRTG_lTimeStamps) - 1) then set obstr.PRTG_iArrayIndex = 0 else set obstr.PRTG_iArrayIndex = obstr.PRTG_iArrayIndex + 1; set obstr.PRTG_lTimeStamps.(obstr.PRTG_iArrayIndex) = curtime; let sizelist obstr.PRTG_lCurves -> nbcurves in let 0 -> i in while (i < nbcurves) do ( let nth_list obstr.PRTG_lCurves i -> curvestr in ( set curvestr.RTC_lValues.(obstr.PRTG_iArrayIndex) = curvestr.RTC_fCurValue; let ftoaNd curvestr.RTC_fCurValue curvestr.RTC_iNbDecimals -> textvalue in ( set line = strcatn line::","::textvalue::nil; set values = strcatn values::" "::textvalue::nil; ); ); set i = i + 1; ); if (obstr.PRTG_bShown == 0) then nil else VUIelementNeedUpdate obstr.PRTG_graphEltstr 1; if (!obstr.PRTG_bValuesUpdated) then nil else ( if (!obstr.PRTG_bValuesLinked) then nil else SendPluginEvent inst "Values" values nil; if (!obstr.PRTG_bSaveAsCsv) then nil else _appendpack (strcat line "\n") obstr.PRTG_wFile; set obstr.PRTG_bValuesUpdated = 0; ); if (obstr.PRTG_iNextUpdate < 0) then set obstr.PRTG_iNextUpdate = curtime + obstr.PRTG_iUpdateRate else set obstr.PRTG_iNextUpdate = obstr.PRTG_iNextUpdate + obstr.PRTG_iUpdateRate; ); 0;; fun cbShow(inst, from, action, param, rep, obstr)= if (obstr.PRTG_contstr != nil) then nil else createGraph obstr; VUIshowContainer obstr.PRTG_contstr 1; set obstr.PRTG_bShown = 1; 0;; fun cbHide(inst, from, action, param, rep, obstr)= VUIshowContainer obstr.PRTG_contstr 0; set obstr.PRTG_bShown = 0; 0;; fun cbEnable(inst, from, action, param, rep, obstr)= if (obstr.PRTG_bEnabled) then nil else ( setPluginInstanceCbPreRender inst mkfun3 @cbPreRender obstr; if (!obstr.PRTG_bSaveAsCsv) || (obstr.PRTG_wFile != nil) then nil else set obstr.PRTG_wFile = createSaveFile inst obstr ".csv"; // Allows to continue the curve where it was left after a pause let _tickcount - obstr.PRTG_iStoppedAt -> timepaused in let sizetab obstr.PRTG_lTimeStamps -> size in ( set obstr.PRTG_iTimeOrigin = obstr.PRTG_iTimeOrigin + timepaused; let 0 -> i in while (i < size) do ( if (obstr.PRTG_lTimeStamps.(i) == 0) then nil else set obstr.PRTG_lTimeStamps.(i) = obstr.PRTG_lTimeStamps.(i) + timepaused; set i = i + 1; ); ); SendPluginEvent inst "Started" nil nil; set obstr.PRTG_bEnabled = 1; ); 0;; fun cbDisable(inst, from, action, param, rep, obstr)= if (!obstr.PRTG_bEnabled) then nil else ( setPluginInstanceCbPreRender inst nil; set obstr.PRTG_iStoppedAt = _tickcount; SendPluginEvent inst "Stopped" nil nil; set obstr.PRTG_bEnabled = 0; ); 0;; fun cbReset(inst, from, action, param, rep, obstr)= let sizetab obstr.PRTG_lTimeStamps -> nbvalues in let sizelist obstr.PRTG_lCurves -> nbcurves in ( let 0 -> i in while (i < nbvalues) do ( set obstr.PRTG_lTimeStamps.(i) = nil; let 0 -> j in while (j < nbcurves) do ( let nth_list obstr.PRTG_lCurves j -> curvestr in set curvestr.RTC_lValues.(i) = curvestr.RTC_fMin; set j = j + 1; ); set i = i + 1; ); let 0 -> j in while (j < nbcurves) do ( let nth_list obstr.PRTG_lCurves j -> curvestr in set curvestr.RTC_fCurValue = curvestr.RTC_fMin; set j = j + 1; ); ); set obstr.PRTG_iTimeOrigin = 0; set obstr.PRTG_iStoppedAt = 0; if (!obstr.PRTG_bSaveAsCsv) then nil else // will save in a new file after a reset set obstr.PRTG_wFile = createSaveFile inst obstr ".csv"; VUIelementNeedUpdate obstr.PRTG_graphEltstr 1; SendPluginEvent inst "Reseted" nil nil; 0;; fun cbSaveGraphPicture(inst, from, action, param, rep, obstr)= let createSaveFile inst obstr ".png" -> wfile in let obstr.PRTG_contstr.VUICNT_buffer.VUIE_resource.VUIR_oBuffer -> buffer in let if (obstr.PRTG_bSaveSize) then obstr.PRTG_tPictureSize else _GETalphaBitmapSize buffer -> [bw bh] in let if param != nil then let strextr param -> lp in let atoi (nth_list (hd lp) 0) -> pw in let atoi (nth_list (hd lp) 1) -> ph in [(if (pw <= 0) then bw else pw) (if (ph <= 0) then bh else ph)] else [bw bh] -> [w h] in let obstr.PRTG_contstr.VUICNT_strw.VUIW_vSize -> size in let obstr.PRTG_contstr.VUICNT_strw.VUIW_tPercent -> [_ _ pw ph _ _ ow oh] in ( VUIsetContainerSize obstr.PRTG_contstr [(itof w) (itof h)] [0 0 0 0]; VUIupdateContBuffer obstr.PRTG_contstr; _BTSAVEalphaBitmap obstr.PRTG_contstr.VUICNT_buffer.VUIE_resource.VUIR_oBuffer wfile; VUIsetContainerSize obstr.PRTG_contstr size [pw ph ow oh]; ); 0;; fun cbInputCurValue(inst, from, action, param, rep, p)= let p -> [curvestr obstr] in let atof param -> newval in ( if (newval == curvestr.RTC_fCurValue) then nil else set obstr.PRTG_bValuesUpdated = 1; set curvestr.RTC_fCurValue = newval; ); 0;; fun loadCurves(inst, obstr, size)= let nil -> curvelist in let 0 -> end in let 0 -> i in ( while (end != 1) do ( let getPluginInstanceParam inst (strcat "curveName" (itoa i)) -> curvename in if (curvename == nil) then set end = 1 else let atof (getPluginInstanceParam inst (strcat "curveMin" (itoa i))) -> curvemin in let atof (getPluginInstanceParam inst (strcat "curveMax" (itoa i))) -> curvemax in let atoi (getPluginInstanceParam inst (strcat "curveNbdec" (itoa i))) -> curvenbdec in let atoi (getPluginInstanceParam inst (strcat "curveColor" (itoa i))) -> curvecolor in let mktab size curvemin -> valuetab in let mkRTCurve[curvename curvemin curvemax curvenbdec curvecolor valuetab curvemin 0] -> curvestr in ( PluginRegisterAction inst (strcat "Input " curvename) mkfun6 @cbInputCurValue [curvestr obstr]; set curvelist = curvestr::curvelist; 0; ); set i = i + 1; ); revertlist curvelist; );; fun newOb(inst)= let loadInterfacePos inst c3dXsession -> posstr in let atoi (getPluginInstanceParam inst "displaytime") -> displaytime in let if displaytime == nil then 30 else displaytime -> displaytime in let atoi (getPluginInstanceParam inst "updaterate") -> updaterate in let if updaterate == nil then 50 else updaterate -> updaterate in let atoi (getPluginInstanceParam inst "vgraduations") -> vgraduations in let if vgraduations == nil then 5 else vgraduations -> vgraduations in let atoi (getPluginInstanceParam inst "hgraduations") -> hgraduations in let if hgraduations == nil then 6 else hgraduations -> hgraduations in let atoi (getPluginInstanceParam inst "legend") -> legend in let if legend == nil then 0 else legend -> legend in let getPluginInstanceParam inst "fileprefix" -> fileprefix in let if fileprefix == nil then "%document%/realtimegraph/" else fileprefix -> fileprefix in let atoi (getPluginInstanceParam inst "dateformat") -> dateformat in let if dateformat == nil then 1 else dateformat -> dateformat in let atoi (getPluginInstanceParam inst "savecsv") -> savecsv in let if savecsv == nil then 0 else savecsv -> savecsv in let atoi (getPluginInstanceParam inst "savesize") -> savesize in let if savesize == nil then 0 else savesize -> savesize in let atoi (getPluginInstanceParam inst "picturewidth") -> picturewidth in let if picturewidth == nil then 1920 else picturewidth -> picturewidth in let atoi (getPluginInstanceParam inst "pictureheight") -> pictureheight in let if pictureheight == nil then 1080 else pictureheight -> pictureheight in let atoi (getPluginInstanceParam inst "show") -> show in let if show == nil then 1 else show -> show in let atoi (getPluginInstanceParam inst "enable") -> enable in let if enable == nil then 1 else enable -> enable in let VUIgetThemeDef (getThemeFromInstance inst) "common" -> defstr in let VUIgetFontFromInterface VUIgetThemeFont defstr "font" -> fontstr in let mkRTScale [nil 0 0 vgraduations 1] -> vscalestr in let mkRTScale [nil 0 0 hgraduations 1] -> hscalestr in let (displaytime * 1000 / updaterate) + 1 -> size in let mktab size nil -> timestamptab in let (IsInEditor inst) || IsEventLinked inst "Values" -> bvalueslinked in let mkPlugRTGraph [inst posstr nil nil fontstr vscalestr hscalestr legend nil (size - 1) nil nil timestamptab 0 0 0 0 0 displaytime updaterate fileprefix dateformat nil savecsv savesize [picturewidth pictureheight] (-1) 0 bvalueslinked 0 0 0] -> obstr in ( set obstr.PRTG_lCurves = loadCurves inst obstr size; if !enable then nil else cbEnable inst nil nil nil nil obstr; if !show then nil else cbShow inst nil nil nil nil obstr; PluginRegisterAction inst "Start" mkfun6 @cbEnable obstr; PluginRegisterAction inst "Stop" mkfun6 @cbDisable obstr; PluginRegisterAction inst "Reset" mkfun6 @cbReset obstr; PluginRegisterAction inst "Show" mkfun6 @cbShow obstr; PluginRegisterAction inst "Hide" mkfun6 @cbHide obstr; PluginRegisterAction inst "Save graph picture" mkfun6 @cbSaveGraphPicture obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= VUIsetEnable c3dXsession 1; PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;