Commit 973715b8 authored by Claes Sjofors's avatar Claes Sjofors

java pwg read, Pie and BarChart added

parent 8e675309
......@@ -13,6 +13,8 @@ extern_java_sources := \
GlowSliderInfo.java,\
GlowTableInfo.java,\
GlowMenuInfo.java,\
GlowPieInfo.java,\
GlowBarChartInfo.java,\
GlowTransform.java,\
GlowEvent.java,\
GlowArrayElem.java,\
......@@ -52,10 +54,13 @@ extern_java_sources := \
GrowTrend.java,\
GrowScrollBarIfc.java,\
GrowScrollBar.java,\
GrowXYCurve.java,\
GrowTable.java,\
GrowImage.java,\
GrowWindow.java,\
GrowFolder.java,\
GrowPie.java,\
GrowBarChart.java,\
GrowConGlue.java,\
GlowVector.java,\
GrowCtx.java,\
......
......@@ -6487,12 +6487,20 @@ public class Dyn {
}
public class DynPie extends DynElem {
public static final int MAX_SECTORS = 12;
String[] attribute = new String[12];
String[] attribute = new String[GrowPie.PIE_MAX_SECTORS];
int sectors;
double min_value;
double max_value;
int fix_range;
int attr_type;
int p[] = new int[GrowPie.PIE_MAX_SECTORS];
PwrtRefId[] subid = new PwrtRefId[GrowPie.PIE_MAX_SECTORS];
boolean[] inverted = new boolean[GrowPie.PIE_MAX_SECTORS];
int[] a_typeid = new int[GrowPie.PIE_MAX_SECTORS];
boolean[] attrFound = new boolean[GrowPie.PIE_MAX_SECTORS];
float[] oldValueF;
int[] oldValueI;
boolean firstScan = true;
public DynPie( Dyn dyn) {
super(dyn, Dyn.mDynType1_Pie, 0, 0, 0, Dyn.eDynPrio_Pie);
......@@ -6500,7 +6508,7 @@ public class Dyn {
public DynPie( DynPie x) {
super(x);
for ( int i = 0; i < MAX_SECTORS; i++)
for ( int i = 0; i < GrowPie.PIE_MAX_SECTORS; i++)
attribute[i] = x.attribute[i];
sectors = x.sectors;
min_value = x.min_value;
......@@ -6522,6 +6530,9 @@ public class Dyn {
switch ( key) {
case Dyn.eSave_Pie:
break;
case Dyn.eSave_Pie_fix_range:
fix_range = Integer.valueOf(token.nextToken());
break;
case Dyn.eSave_Pie_attribute1:
if ( token.hasMoreTokens())
attribute[0] = token.nextToken();
......@@ -6587,16 +6598,148 @@ public class Dyn {
}
}
public int connect(GlowArrayElem o) {
GrowPie object = (GrowPie)o;
GlowPieInfo info = object.get_conf();
min_value = info.min_val;
max_value = info.max_val;
sectors = info.sector_num;
if ( sectors > GrowPie.PIE_MAX_SECTORS)
sectors = GrowPie.PIE_MAX_SECTORS;
for ( int i = 0; i < sectors; i++) {
if ( attribute[i] == null)
continue;
DynParsedAttrName pname = dyn.parseAttrName(attribute[i]);
if ( pname == null || pname.name.equals(""))
continue;
if ( i == 0) {
attr_type = pname.type;
switch ( attr_type) {
case Pwr.eType_Float32:
oldValueF = new float[GrowPie.PIE_MAX_SECTORS];
break;
case Pwr.eType_Int32:
oldValueI = new int[GrowPie.PIE_MAX_SECTORS];
break;
default:
return 1;
}
}
else {
if ( attr_type != pname.type)
continue;
}
GdhrRefObjectInfo ret = null;
switch( pname.database) {
case GraphIfc.eDatabase_Gdh:
ret = dyn.graph.getGdh().refObjectInfo( pname.tname);
break;
default:
ret = null;
}
if ( ret == null || ret.evenSts()) {
System.out.println("Pie: " + attribute[i]);
return 1;
}
p[i] = ret.id;
subid[i] = ret.refid;
inverted[i] = pname.inverted;
a_typeid[i] = pname.type;
attrFound[i] = true;
}
return 1;
}
public void disconnect() {
for ( int i = 0; i < sectors; i++) {
if ( attrFound[i])
dyn.graph.getGdh().unrefObjectInfo(subid[i]);
}
}
public void scan( GlowArrayElem o) {
GrowPie object = (GrowPie)o;
switch ( attr_type) {
case Pwr.eType_Float32: {
float[] val = new float[GrowPie.PIE_MAX_SECTORS];
for ( int i = 0; i < sectors; i++)
val[i] = dyn.graph.getGdh().getObjectRefInfoFloat( p[i]);
if ( !firstScan) {
int update = 0;
for ( int i = 0; i < sectors; i++) {
if ( Math.abs( oldValueF[i] - val[i]) > Float.MIN_VALUE) {
update = 1;
break;
}
}
if ( update == 0)
return;
}
else
firstScan = false;
if ( Math.abs( max_value - min_value) < Float.MIN_VALUE)
return;
double[] dval = new double[GrowPie.PIE_MAX_SECTORS];
if ( fix_range != 0|| sectors == 1) {
for ( int i = 0; i < sectors; i++)
dval[i] = val[i];
}
else {
double sum = 0;
for ( int i = 0; i < sectors; i++)
sum += val[i];
for ( int i = 0; i < sectors; i++) {
if ( Math.abs( sum) < Double.MIN_VALUE)
dval[i] = 0;
else
dval[i] = val[i] / sum * (max_value - min_value);
}
}
object.set_values( dval);
for ( int i = 0; i < sectors; i++)
oldValueF[i] = val[i];
break;
}
case Pwr.eType_Int32: {
break;
}
default: ;
}
}
}
public class DynBarChart extends DynElem {
public static final int MAX_BARSEGMENTS = 12;
String[] attribute = new String[12];
String[] attribute = new String[GrowBarChart.BARCHART_MAX_BARSEGMENTS];
int bars;
int barsegments;
double min_value;
double max_value;
boolean fix_range;
int fix_range;
float[][] valueF;
int[][] valueI;
float[][] oldValueF;
int[][] oldValueI;
int attr_type;
int p[] = new int[GrowBarChart.BARCHART_MAX_BARSEGMENTS];
PwrtRefId[] subid = new PwrtRefId[GrowBarChart.BARCHART_MAX_BARSEGMENTS];
boolean[] inverted = new boolean[GrowBarChart.BARCHART_MAX_BARSEGMENTS];
int[] a_typeid = new int[GrowBarChart.BARCHART_MAX_BARSEGMENTS];
boolean[] attrFound = new boolean[GrowBarChart.BARCHART_MAX_BARSEGMENTS];
boolean firstScan = true;
public DynBarChart( Dyn dyn) {
super(dyn, Dyn.mDynType1_BarChart, 0, 0, 0, Dyn.eDynPrio_BarChart);
......@@ -6609,7 +6752,7 @@ public class Dyn {
min_value = x.min_value;
max_value = x.max_value;
fix_range = x.fix_range;
for ( int i = 0; i < MAX_BARSEGMENTS; i++)
for ( int i = 0; i < GrowBarChart.BARCHART_MAX_BARSEGMENTS; i++)
attribute[i] = x.attribute[i];
}
......@@ -6627,6 +6770,9 @@ public class Dyn {
switch ( key) {
case Dyn.eSave_BarChart:
break;
case Dyn.eSave_BarChart_fix_range:
fix_range = Integer.valueOf(token.nextToken());
break;
case Dyn.eSave_BarChart_attribute1:
if ( token.hasMoreTokens())
attribute[0] = token.nextToken();
......@@ -6692,6 +6838,121 @@ public class Dyn {
}
}
public int connect(GlowArrayElem o) {
GrowBarChart object = (GrowBarChart)o;
GlowBarChartInfo info = object.get_conf();
min_value = info.min_value;
max_value = info.max_value;
bars = info.bars;
barsegments = info.barsegments;
for ( int i = 0; i < barsegments; i++) {
if ( attribute[i] == null)
continue;
DynParsedAttrName pname = dyn.parseAttrName(attribute[i]);
if ( pname == null || pname.name.equals(""))
continue;
if ( pname.elements == 0)
continue;
bars = Math.min( bars, pname.elements);
if ( i == 0) {
attr_type = pname.type;
switch ( attr_type) {
case Pwr.eType_Float32:
valueF = new float[barsegments][];
break;
case Pwr.eType_Int32:
valueI = new int[barsegments][];
break;
default:
return 1;
}
}
else {
if ( attr_type != pname.type)
continue;
}
GdhrRefObjectInfo ret = null;
switch( pname.database) {
case GraphIfc.eDatabase_Gdh:
ret = dyn.graph.getGdh().refObjectInfo( pname.tname);
break;
default:
ret = null;
}
if ( ret == null || ret.evenSts()) {
System.out.println("Pie: " + attribute[i]);
return 1;
}
p[i] = ret.id;
subid[i] = ret.refid;
inverted[i] = pname.inverted;
a_typeid[i] = pname.type;
attrFound[i] = true;
}
return 1;
}
public void disconnect() {
for ( int i = 0; i < barsegments; i++) {
if ( attrFound[i])
dyn.graph.getGdh().unrefObjectInfo(subid[i]);
}
}
public void scan( GlowArrayElem o) {
GrowBarChart object = (GrowBarChart)o;
switch ( attr_type) {
case Pwr.eType_Float32: {
valueF = new float[GrowBarChart.BARCHART_MAX_BARSEGMENTS][];
for ( int i = 0; i < barsegments; i++) {
valueF[i] = dyn.graph.getGdh().getObjectRefInfoFloatArray( p[i], bars);
}
if ( !firstScan) {
int update = 0;
for ( int i = 0; i < barsegments && valueF[i] != null; i++) {
for ( int j = 0; j < bars; j++) {
if ( Math.abs( oldValueF[i][j] - valueF[i][j]) > Float.MIN_VALUE) {
update = 1;
break;
}
}
if ( update == 1)
break;
}
if ( update == 0)
return;
}
else
firstScan = false;
if ( Math.abs( max_value - min_value) < Float.MIN_VALUE)
return;
object.set_values( valueF[0], valueF[1], valueF[2], valueF[3], valueF[4],
valueF[5], valueF[6], valueF[7], valueF[8], valueF[9],
valueF[10], valueF[11]);
oldValueF = valueF;
break;
}
case Pwr.eType_Int32: {
break;
}
default: ;
}
}
}
public class DynAxis extends DynElem {
......
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2014 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
package jpwr.jopg;
public class GlowBarChartInfo {
public int bars;
public int barsegments;
public double min_value;
public double max_value;
}
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2014 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
package jpwr.jopg;
public class GlowPieInfo {
public int sector_num;
public double min_val;
public double max_val;
}
......@@ -243,6 +243,18 @@ public class GlowVector {
a.add( c);
break;
}
case Glow.eSave_GrowPie: {
GrowPie c = new GrowPie( cmn);
c.open( reader);
a.add( c);
break;
}
case Glow.eSave_GrowBarChart: {
GrowBarChart c = new GrowBarChart( cmn);
c.open( reader);
a.add( c);
break;
}
case Glow.eSave_Point: {
GlowPoint c = new GlowPoint();
c.open( reader);
......
......@@ -443,6 +443,10 @@ public class GrowArc extends GlowArrayElem {
}
public Object getCmn() {
return cmn;
}
public String getName() {
return n_name;
}
......
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2014 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
package jpwr.jopg;
import jpwr.rt.*;
import java.io.*;
import java.util.*;
public class GrowBarChart extends GrowRect {
public static final int BARCHART_MAX_BARSEGMENTS = 12;
public static final int BARCHART_MAX_BARS = 200;
int bars;
int barsegments;
double min_value;
double max_value;
int vertical_lines;
int horizontal_lines;
int line_color;
int[] bar_color = new int[BARCHART_MAX_BARSEGMENTS];
float[] bar_values = new float[BARCHART_MAX_BARSEGMENTS * BARCHART_MAX_BARS];
Object userdata;
public GrowBarChart(GrowCmn cmn) {
super(cmn);
}
public int type() {
return Glow.eObjectType_GrowBarChart;
}
public void open(BufferedReader reader) {
String line;
StringTokenizer token;
boolean end_found = false;
try {
while( (line = reader.readLine()) != null) {
token = new StringTokenizer(line);
int key = Integer.valueOf(token.nextToken());
if ( cmn.debug) System.out.println( "GrowBarChart : " + line);
switch ( key) {
case Glow.eSave_GrowBarChart:
break;
case Glow.eSave_GrowBarChart_rect_part:
super.open( reader);
break;
case Glow.eSave_GrowBarChart_bars:
bars = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_barsegments:
barsegments = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_max_value:
max_value = new Double(token.nextToken()).doubleValue();
break;
case Glow.eSave_GrowBarChart_min_value:
min_value = new Double(token.nextToken()).doubleValue();
break;
case Glow.eSave_GrowBarChart_horizontal_lines:
horizontal_lines = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_vertical_lines:
vertical_lines = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_line_color:
line_color = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color1:
bar_color[0] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color2:
bar_color[1] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color3:
bar_color[2] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color4:
bar_color[3] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color5:
bar_color[4] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color6:
bar_color[5] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color7:
bar_color[6] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color8:
bar_color[7] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color9:
bar_color[8] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color10:
bar_color[9] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color11:
bar_color[10] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_bar_color12:
bar_color[11] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowBarChart_userdata_cb:
if ( cmn.appl != null)
userdata = cmn.appl.growUserdataOpen( reader, this, Glow.eUserdataCbType_Node);
break;
case Glow.eSave_End:
end_found = true;
break;
default:
System.out.println( "Syntax error in GrowBarChart");
break;
}
if ( end_found)
break;
}
} catch ( Exception e) {
System.out.println( "IOException GrowBarChart");
}
}
public void draw(GlowTransform t, int highlight, int hot, Object node, Object colornode) {
if ( cmn.nodraw != 0)
return;
int drawtype;
int idx;
int chot = 0;
if ( cmn.hot_indication == Glow.eHotIndication_No)
hot = 0;
else if ( cmn.hot_indication == Glow.eHotIndication_DarkColor) {
chot = hot;
hot = 0;
}
else if ( cmn.hot_indication == Glow.eHotIndication_LightColor) {
chot = -hot;
hot = 0;
}
if ( node != null && ((GrowNode)node).line_width != 0)
idx = (int)( cmn.mw.zoom_factor_y / cmn.mw.base_zoom_factor *
((GrowNode)node).line_width - 1);
else
idx = (int)( cmn.mw.zoom_factor_y / cmn.mw.base_zoom_factor * line_width - 1);
idx += hot;
idx = Math.max( 0, idx);
idx = Math.min( idx, Glow.DRAW_TYPE_SIZE-1);
int x1, y1, x2, y2, ll_x, ll_y, ur_x, ur_y, rot;
if ( t == null) {
x1 = (int)( trf.x( ll.x, ll.y) * cmn.mw.zoom_factor_x + 0.5) - cmn.mw.offset_x;
y1 = (int)( trf.y( ll.x, ll.y) * cmn.mw.zoom_factor_y + 0.5) - cmn.mw.offset_y;
x2 = (int)( trf.x( ur.x, ur.y) * cmn.mw.zoom_factor_x + 0.5) - cmn.mw.offset_x;
y2 = (int)( trf.y( ur.x, ur.y) * cmn.mw.zoom_factor_y + 0.5) - cmn.mw.offset_y;
rot = (int)( trf.rot());
}
else {
x1 = (int)( trf.x( t, ll.x, ll.y) * cmn.mw.zoom_factor_x + 0.5) - cmn.mw.offset_x;
y1 = (int)( trf.y( t, ll.x, ll.y) * cmn.mw.zoom_factor_y + 0.5) - cmn.mw.offset_y;
x2 = (int)( trf.x( t, ur.x, ur.y) * cmn.mw.zoom_factor_x + 0.5) - cmn.mw.offset_x;
y2 = (int)( trf.y( t, ur.x, ur.y) * cmn.mw.zoom_factor_y + 0.5) - cmn.mw.offset_y;
rot = (int)( trf.rot( t));
}
ll_x = Math.min( x1, x2);
ur_x = Math.max( x1, x2);
ll_y = Math.min( y1, y2);
ur_y = Math.max( y1, y2);
int grad = gradient;
if ( gradient == Glow.eGradient_No &&
(node != null && ((GrowNode)node).gradient != Glow.eGradient_No) && disable_gradient == 0)
grad = ((GrowNode)node).gradient;
int skip;
int bar_ll_x, bar_ur_x;
int bar_ll_y, bar_ur_y;
double f_bar_ll_y;
double width;
int brect_ll_x = 0;
int brect_ll_y = 0;
int brect_width = 0;
int brect_height = 0;
width = (double)(ur_x - ll_x) / bars;
bar_ur_x = ll_x;
for ( int j = 0; j < bars; j++) {
bar_ll_x = bar_ur_x;
if ( j == bars - 1)
bar_ur_x = ur_x;
else
bar_ur_x = ll_x + (int)((j + 1) * width);
bar_ll_y = ur_y;
f_bar_ll_y = ur_y;
for ( int i = 0; i < barsegments + 1; i++) {
int fillcolor = 0;
skip = 0;
bar_ur_y = bar_ll_y;
if ( i == barsegments) {
if ( bar_ll_y <= ll_y)
skip = 1;
else
bar_ll_y = ll_y;
fillcolor = GlowColor.get_drawtype( fill_drawtype, Glow.eDrawType_FillHighlight,
highlight, colornode, 1, 0 );
}
else {
if ( bar_values[i * bars + j] <= min_value)
skip = 1;
else if ( bar_ur_y <= ll_y)
skip = 1;
else {
f_bar_ll_y -= bar_values[i*bars+j] * (ur_y - ll_y) / (max_value - min_value);
bar_ll_y = (int)f_bar_ll_y;
if ( bar_ll_y < ll_y)
bar_ll_y = ll_y;
fillcolor = GlowColor.get_drawtype( bar_color[i], Glow.eDrawType_FillHighlight,
highlight, colornode, 1, 0);
}
}
if ( skip == 0) {
if ( grad == Glow.eGradient_No || fillcolor == Glow.eDrawType_ColorRed || i == barsegments) {
if ( chot != 0)
drawtype = GlowColor.shift_drawtype( fillcolor, chot, null);
else
drawtype = fillcolor;
cmn.gdraw.fill_rect( bar_ll_x, bar_ll_y, bar_ur_x - bar_ll_x, bar_ur_y - bar_ll_y, drawtype);
}
else {
int f1, f2;
if ( gradient_contrast >= 0) {
f2 = GlowColor.shift_drawtype( fillcolor, -gradient_contrast/2 + chot, null);
f1 = GlowColor.shift_drawtype( fillcolor, (int)((float)(gradient_contrast)/2+0.6) + chot, null);
}
else {
f2 = GlowColor.shift_drawtype( fillcolor, -(int)((float)(gradient_contrast)/2-0.6) + chot, null);
f1 = GlowColor.shift_drawtype( fillcolor, gradient_contrast/2 + chot, null);
}
cmn.gdraw.gradient_fill_rect( bar_ll_x, bar_ll_y, bar_ur_x - bar_ll_x,
bar_ur_y - bar_ll_y, fillcolor, f1, f2, grad);
}
}
if ( border != 0 && i == barsegments) {
// Draw previous bar border
if ( j > 0) {
drawtype = GlowColor.get_drawtype( draw_type, Glow.eDrawType_LineHighlight,
highlight, colornode, 0, 0);
cmn.gdraw.rect( brect_ll_x, brect_ll_y, brect_width, brect_height,
drawtype, idx, 0);
}
if ( skip == 0) {
brect_ll_x = bar_ll_x;
brect_ll_y = bar_ur_y;
brect_width = bar_ur_x - bar_ll_x;
brect_height = ur_y - bar_ur_y;
}
else {
brect_ll_x = bar_ll_x;
brect_ll_y = ll_y;
brect_width = bar_ur_x - bar_ll_x;
brect_height = ur_y - ll_y;
}
if ( j == bars - 1) {
// Draw last bar border
drawtype = GlowColor.get_drawtype( draw_type, Glow.eDrawType_LineHighlight,
highlight, colornode, 0, 0);
cmn.gdraw.rect( brect_ll_x, brect_ll_y, brect_width, brect_height,
drawtype, idx, 0);
}
}
}
}
drawtype = GlowColor.get_drawtype( line_color, Glow.eDrawType_LineHighlight,
highlight, colornode, 0, 0);
for ( int i = 0; i < vertical_lines; i++) {
int x = (int)( ll_x + (double)(ur_x - ll_x) / (vertical_lines + 1) * (i + 1));
cmn.gdraw.line( x, ll_y, x, ur_y, drawtype, 0, 0);
}
for ( int i = 0; i < horizontal_lines; i++) {
int y = (int)( ll_y + (double)(ur_y - ll_y) / (horizontal_lines + 1) * (i + 1));
cmn.gdraw.line( ll_x, y, ur_x, y, drawtype, 0, 0);
}
if ( border != 0) {
drawtype = GlowColor.get_drawtype( draw_type, Glow.eDrawType_LineHighlight,
highlight, colornode, 0, 0);
// printf( "draw: %d %d\n", ll_x, ll_y);
cmn.gdraw.rect( ll_x, ll_y, ur_x - ll_x, ur_y - ll_y,
drawtype, idx, 0);
}
}
public void set_conf( int bar_num, int barsegment_num, double min_val, double max_val,
int vert_lines, int horiz_lines, int lcolor, int[] color) {
bars = bar_num;
barsegments = barsegment_num;
min_value = min_val;
max_value = max_val;
vertical_lines = vert_lines;
horizontal_lines = horiz_lines;
line_color = lcolor;
for ( int i = 0; i < bars; i++)
bar_color[i] = color[i];
draw();
}
public GlowBarChartInfo get_conf() {
GlowBarChartInfo info = new GlowBarChartInfo();
info.bars = bars;
info.barsegments = barsegments;
info.max_value = max_value;
info.min_value = min_value;
return info;
}
public void set_values( float[] values1, float[] values2, float[] values3, float[] values4,
float[] values5, float[] values6, float[] values7, float[] values8,
float[] values9, float[] values10, float[] values11, float[] values12) {
int j = 0;
if ( j < barsegments && values1 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values1[i];
}
j++;
if ( j < barsegments && values2 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values2[i];
}
j++;
if ( j < barsegments && values3 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values3[i];
}
j++;
if ( j < barsegments && values4 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values4[i];
}
j++;
if ( j < barsegments && values5 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values5[i];
}
j++;
if ( j < barsegments && values6 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values6[i];
}
j++;
if ( j < barsegments && values7 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values7[i];
}
j++;
if ( j < barsegments && values8 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values8[i];
}
j++;
if ( j < barsegments && values9 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values9[i];
}
j++;
if ( j < barsegments && values10 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values10[i];
}
j++;
if ( j < barsegments && values11 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values11[i];
}
j++;
if ( j < barsegments && values12 != null) {
for ( int i = 0; i < bars; i++)
bar_values[j*bars + i] = values12[i];
}
}
public Object getUserData() {
return userdata;
}
}
......@@ -612,8 +612,9 @@ public class GrowCtx implements GrowCtxIfc {
cmn.a.get(i).type() == Glow.eObjectType_GrowSlider ||
cmn.a.get(i).type() == Glow.eObjectType_GrowWindow ||
cmn.a.get(i).type() == Glow.eObjectType_GrowFolder ||
cmn.a.get(i).type() == Glow.eObjectType_GrowXYCurve) {
System.out.println("GrowCtx connect " + i + " (" + cmn.a.size() + ") " + cmn.a.get(i));
cmn.a.get(i).type() == Glow.eObjectType_GrowXYCurve ||
cmn.a.get(i).type() == Glow.eObjectType_GrowPie ||
cmn.a.get(i).type() == Glow.eObjectType_GrowBarChart) {
cmn.appl.traceConnect(cmn.a.get(i));
if ( cmn.a.get(i).type() == Glow.eObjectType_GrowGroup) {
for ( int j = 0; j < ((GrowNode)cmn.a.get(i)).nc.a.size(); j++) {
......@@ -646,7 +647,9 @@ public class GrowCtx implements GrowCtxIfc {
cmn.a.get(i).type() == Glow.eObjectType_GrowSlider ||
cmn.a.get(i).type() == Glow.eObjectType_GrowWindow ||
cmn.a.get(i).type() == Glow.eObjectType_GrowFolder ||
cmn.a.get(i).type() == Glow.eObjectType_GrowXYCurve) {
cmn.a.get(i).type() == Glow.eObjectType_GrowXYCurve ||
cmn.a.get(i).type() == Glow.eObjectType_GrowPie ||
cmn.a.get(i).type() == Glow.eObjectType_GrowBarChart) {
cmn.appl.traceDisconnect(cmn.a.get(i));
if ( cmn.a.get(i).type() == Glow.eObjectType_GrowGroup) {
for ( int j = 0; j < ((GrowNode)cmn.a.get(i)).nc.a.size(); j++) {
......@@ -676,7 +679,9 @@ public class GrowCtx implements GrowCtxIfc {
cmn.a.get(i).type() == Glow.eObjectType_GrowSlider ||
cmn.a.get(i).type() == Glow.eObjectType_GrowWindow ||
cmn.a.get(i).type() == Glow.eObjectType_GrowFolder ||
cmn.a.get(i).type() == Glow.eObjectType_GrowXYCurve) {
cmn.a.get(i).type() == Glow.eObjectType_GrowXYCurve ||
cmn.a.get(i).type() == Glow.eObjectType_GrowPie ||
cmn.a.get(i).type() == Glow.eObjectType_GrowBarChart) {
cmn.appl.traceScan(cmn.a.get(i));
if ( cmn.a.get(i).type() == Glow.eObjectType_GrowGroup) {
for ( int j = 0; j < ((GrowNode)cmn.a.get(i)).nc.a.size(); j++) {
......
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2014 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
package jpwr.jopg;
import jpwr.rt.*;
import java.io.*;
import java.util.*;
public class GrowPie extends GrowArc {
public static final int PIE_MAX_SECTORS = 12;
int sectors;
double min_value;
double max_value;
int[] sector_color = new int[PIE_MAX_SECTORS];
double[] sector_size = new double[PIE_MAX_SECTORS];
Object userdata;
public GrowPie(GrowCmn cmn) {
super(cmn);
}
public int type() {
return Glow.eObjectType_GrowPie;
}
public void open(BufferedReader reader) {
String line;
StringTokenizer token;
boolean end_found = false;
try {
while( (line = reader.readLine()) != null) {
token = new StringTokenizer(line);
int key = Integer.valueOf(token.nextToken());
if ( cmn.debug) System.out.println( "GrowPie : " + line);
switch ( key) {
case Glow.eSave_GrowPie:
break;
case Glow.eSave_GrowPie_arc_part:
super.open( reader);
break;
case Glow.eSave_GrowPie_sectors:
sectors = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_max_value:
max_value = new Double(token.nextToken()).doubleValue();
break;
case Glow.eSave_GrowPie_min_value:
min_value = new Double(token.nextToken()).doubleValue();
break;
case Glow.eSave_GrowPie_sector_color1:
sector_color[0] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color2:
sector_color[1] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color3:
sector_color[2] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color4:
sector_color[3] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color5:
sector_color[4] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color6:
sector_color[5] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color7:
sector_color[6] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color8:
sector_color[7] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color9:
sector_color[8] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color10:
sector_color[9] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color11:
sector_color[10] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_color12:
sector_color[11] = Integer.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size1:
sector_size[0] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size2:
sector_size[1] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size3:
sector_size[2] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size4:
sector_size[3] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size5:
sector_size[4] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size6:
sector_size[5] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size7:
sector_size[6] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size8:
sector_size[7] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size9:
sector_size[8] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size10:
sector_size[9] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size11:
sector_size[10] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_sector_size12:
sector_size[11] = Double.valueOf(token.nextToken());
break;
case Glow.eSave_GrowPie_userdata_cb:
if ( cmn.appl != null)
userdata = cmn.appl.growUserdataOpen( reader, this, Glow.eUserdataCbType_Node);
break;
case Glow.eSave_End:
end_found = true;
break;
default:
System.out.println( "Syntax error in GrowPie");
break;
}
if ( end_found)
break;
}
} catch ( Exception e) {
System.out.println( "IOException GrowPie");
}
}
public void draw(GlowTransform t, int highlight, int hot, Object node, Object colornode) {
if ( cmn.nodraw != 0)
return;
int drawtype;
int idx;
int chot = 0;
if ( cmn.hot_indication == Glow.eHotIndication_No)
hot = 0;
else if ( cmn.hot_indication == Glow.eHotIndication_DarkColor) {
chot = hot;
hot = 0;
}
else if ( cmn.hot_indication == Glow.eHotIndication_LightColor) {
chot = -hot;
hot = 0;
}
if ( fixcolor != 0)
colornode = null;
if ( node != null && ((GrowNode)node).line_width != 0)
idx = (int)( cmn.mw.zoom_factor_y / cmn.mw.base_zoom_factor *
((GrowNode)node).line_width - 1);
else
idx = (int)( cmn.mw.zoom_factor_y / cmn.mw.base_zoom_factor * line_width - 1);
idx += hot;
idx = Math.max( 0, idx);
idx = Math.min( idx, Glow.DRAW_TYPE_SIZE-1);
int x1, y1, x2, y2, ll_x, ll_y, ur_x, ur_y, rot;
if ( t == null) {
x1 = (int)( trf.x( ll.x, ll.y) * cmn.mw.zoom_factor_x + 0.5) - cmn.mw.offset_x;
y1 = (int)( trf.y( ll.x, ll.y) * cmn.mw.zoom_factor_y + 0.5) - cmn.mw.offset_y;
x2 = (int)( trf.x( ur.x, ur.y) * cmn.mw.zoom_factor_x + 0.5) - cmn.mw.offset_x;
y2 = (int)( trf.y( ur.x, ur.y) * cmn.mw.zoom_factor_y + 0.5) - cmn.mw.offset_y;
rot = (int)( trf.rot());
}
else {
x1 = (int)( trf.x( t, ll.x, ll.y) * cmn.mw.zoom_factor_x + 0.5) - cmn.mw.offset_x;
y1 = (int)( trf.y( t, ll.x, ll.y) * cmn.mw.zoom_factor_y + 0.5) - cmn.mw.offset_y;
x2 = (int)( trf.x( t, ur.x, ur.y) * cmn.mw.zoom_factor_x + 0.5) - cmn.mw.offset_x;
y2 = (int)( trf.y( t, ur.x, ur.y) * cmn.mw.zoom_factor_y + 0.5) - cmn.mw.offset_y;
rot = (int)( trf.rot( t));
}
ll_x = Math.min( x1, x2);
ur_x = Math.max( x1, x2);
ll_y = Math.min( y1, y2);
ur_y = Math.max( y1, y2);
boolean display_shadow = ((node != null && ((GrowNode)node).shadow != 0) || shadow != 0) && disable_shadow == 0;
int grad = gradient;
if ( gradient == Glow.eGradient_No &&
(node != null && ((GrowNode)node).gradient != Glow.eGradient_No) && disable_gradient == 0)
grad = ((GrowNode)node).gradient;
double a1 = angle1;
double a2 = 0;
int ia1 = angle1;
int ia2;
for ( int i = 0; i < sectors + 1; i++) {
int fillcolor;
if ( i == sectors) {
if ( ia1 >= angle1 + angle2)
break;
ia2 = angle1 + angle2 - ia1;
fillcolor = GlowColor.get_drawtype( fill_drawtype, Glow.eDrawType_FillHighlight,
highlight, colornode, 1, 0);
}
else {
if ( sector_size[i] <= min_value)
continue;
if ( a1 >= angle2 + angle1)
break;
a2 = sector_size[i] / (max_value - min_value) * angle2;
if ( a1 + a2 > angle1 + angle2)
a2 = angle1 + angle2 - a1;
ia2 = (int)((double)a2 + a1 - ia1 + 0.5);
fillcolor = GlowColor.get_drawtype( sector_color[i], Glow.eDrawType_FillHighlight,
highlight, colornode, 1, 0);
}
if ( grad == Glow.eGradient_No || fillcolor == Glow.eDrawType_ColorRed) {
if ( chot != 0)
drawtype = GlowColor.shift_drawtype( fillcolor, chot, null);
else
drawtype = fillcolor;
cmn.gdraw.fill_arc( ll_x, ll_y, ur_x - ll_x, ur_y - ll_y,
ia1 - rot, ia2, drawtype);
}
else if ( !display_shadow || shadow_width == 0) {
int f1, f2;
if ( gradient_contrast >= 0) {
f2 = GlowColor.shift_drawtype( fillcolor, -gradient_contrast/2 + chot, null);
f1 = GlowColor.shift_drawtype( fillcolor, (int)((float)(gradient_contrast)/2+0.6) + chot, null);
}
else {
f2 = GlowColor.shift_drawtype( fillcolor, -(int)((float)(gradient_contrast)/2-0.6) + chot, null);
f1 = GlowColor.shift_drawtype( fillcolor, gradient_contrast/2 + chot, 0);
}
cmn.gdraw.gradient_fill_arc( ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, ia1 - rot,
ia2, fillcolor, f1, f2, grad);
}
else {
int ish = (int)( shadow_width / 100 * Math.min(ur_x - ll_x, ur_y - ll_y) + 0.5);
int drawtype_incr = shadow_contrast;
if ( relief == Glow.eRelief_Down)
drawtype_incr = -shadow_contrast;
int f1, f2;
// Draw shadow
f1 = GlowColor.shift_drawtype( fillcolor, -drawtype_incr + chot, colornode);
f2 = GlowColor.shift_drawtype( fillcolor, drawtype_incr + chot, colornode);
cmn.gdraw.gradient_fill_arc( ll_x, ll_y, ur_x - ll_x, ur_y - ll_y,
ia1 - rot, ia2, fillcolor, f2, f1, Glow.eGradient_DiagonalUpperLeft);
// Draw circle
if ( gradient_contrast >= 0) {
f2 = GlowColor.shift_drawtype( fillcolor, -gradient_contrast/2 + chot, null);
f1 = GlowColor.shift_drawtype( fillcolor, (int)((float)(gradient_contrast)/2+0.6) + chot, null);
}
else {
f2 = GlowColor.shift_drawtype( fillcolor, -(int)((float)(gradient_contrast)/2-0.6) + chot, null);
f1 = GlowColor.shift_drawtype( fillcolor, gradient_contrast/2 + chot, null);
}
cmn.gdraw.gradient_fill_arc( ll_x + ish, ll_y + ish, ur_x - ll_x - 2*ish, ur_y - ll_y - 2*ish,
ia1 - rot, ia2, fillcolor, f1, f2, grad);
}
a1 += a2;
ia1 += ia2;
}
if ( border != 0) {
drawtype = GlowColor.get_drawtype( draw_type, Glow.eDrawType_LineHighlight,
highlight, colornode, 0, 0);
cmn.gdraw.arc( ll_x, ll_y, ur_x - ll_x, ur_y - ll_y,
angle1 - rot, angle2, drawtype, idx, 0);
}
}
public void set_conf( int sector_num, double min_val, double max_val, int[] color) {
sectors = sector_num;
min_value = min_val;
max_value = max_val;
for ( int i = 0; i < sectors; i++)
sector_color[i] = color[i];
draw();
}
public GlowPieInfo get_conf() {
GlowPieInfo info = new GlowPieInfo();
info.sector_num = sectors;
info.min_val = min_value;
info.max_val = max_value;
return info;
}
public void set_values( double[] values) {
for ( int i = 0; i < sectors; i++)
sector_size[i] = values[i];
draw();
}
public Object getUserData() {
return userdata;
}
}
......@@ -12,6 +12,8 @@ local_java_sources := \
GlowSliderInfo.java,\
GlowTableInfo.java,\
GlowMenuInfo.java,\
GlowPieInfo.java,\
GlowBarChartInfo.java,\
GlowTransform.java,\
GlowEvent.java,\
GlowArrayElem.java,\
......@@ -55,6 +57,8 @@ local_java_sources := \
GrowScrollBarIfc.java,\
GrowScrollBar.java,\
GrowTable.java,\
GrowPie.java,\
GrowBarChart.java,\
GrowConGlue.java,\
GrowImage.java,\
GrowWindow.java,\
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment