In this event, it is handy, for example, to use script to set the properties of other Pmg objects (e.g. trend headers - of the PmgWTable object) that are supposed to change based on the current status of the trend viewer.
pMe | (Object) Reference to the PmgTrendViewer object where the event rises. |
---|---|
pEvent | (Object) Reference to object describing detailed information about the specific event. |
//#pragma variable sName=Macro("$.text('sys','name')")
//#pragma variable sUnit=Macro("$.text('sys','unit')")
//#pragma variable sMin=Macro("$.text('sys','minimum')")
//#pragma variable sMax=Macro("$.text('sys','maximum')")
//#pragma variable sValue=Macro("$.text('sys','value')")
var oTHead = pMe.Items("../AxTrendsHead");
var oTView = pMe;
var oTrend, nLength, aTr, trConnect, i, nCount;
if (bInit)
{
oTHead.SetCellText(0, 2, sName);
oTHead.SetCellText(0, 3, sUnit);
oTHead.SetCellText(0, 4, sMin);
oTHead.SetCellText(0, 5, sMax);
oTHead.SetCellText(0, 6, sValue);
//start read and connection parameter "trConnect"
trConnect = pMe.GetPar("trConnect");
if (Pm.IsValid(trConnect) && trConnect != "") //end read and connection parameter "trConnect"
{
aTr = Pm.StringSplit(trConnect, ",", "empty:1;");
nLength = aTr.GetSize(1);
for (i = 0; i < nLength; i += 2)
{
oTrend = oTView.AddTrend("t" + i, "$default");
oTrend.Connect(1, "local", aTr.GetItem(i), aTr.GetItem(i + 1), "iniread=name,unit,min,max,color");
}
}
//end read and connection parameter "trConnect"
pMe.Vars("cfgini").Value = oTView.GetCfg("Trends;TimeZoom;", "");
}
nCount = oTView.TrendsCount;
oTHead.Rows = nCount + 1;
for (i = 1; i <= nCount; i++)
{
oTrend = oTView.Trends(i, -1);
oTHead.SetCellText(i, 1, oTrend.Visible ? "" : "X");
oTHead.SetCellText(i, 2, oTrend.Name);
oTHead.SetCellTextAlign(i, 2, 0);
oTHead.SetCellText(i, 3, oTrend.Unit);
oTHead.SetCellText(i, 4, Pm.Round(oTrend.ValueMin, 0.001));
oTHead.SetCellText(i, 5, Pm.Round(oTrend.ValueMax, 0.001));
if (!oTView.Autoscroll)
oTHead.SetCellText(i, 6, Pm.Round(oTrend.CursorValue(2), 0.001));
oTHead.SetCellBackColor(i, 0, oTrend.GraphDefault.Color);
}
oTHead.SetCellBackColor(oTHead.FocusedRow, -3, "transparent");
oTHead.FocusedRow = oTView.TrendActive + 1;
oTHead.SetCellBackColor(oTView.TrendActive + 1, -3, "#009898");
//text align cols
oTHead.SetCellTextAlign(-3, 1, 1); //Visible - align center
oTHead.SetCellTextAlign(-3, 2, 0); //Name - align left
oTHead.SetCellTextAlign(-3, 3, 1); //Unit - align center
oTHead.SetCellTextAlign(-3, 4, 1); //Min - align center
oTHead.SetCellTextAlign(-3, 5, 1); //Max - align center
oTHead.SetCellTextAlign(-3, 6, 2); //Value - align right
oTHead.Draw();
if (bInit && !oTView.Autoscroll)
oTView.ReadData();