[r1]: / XYChartZoomingPaning.project  Maximize  Restore  History

Download this file

292 lines (254 with data), 2.7 MB

-------------------------------------------------------------------------------
PLC_PRG
-------------------------------------------------------------------------------


PROGRAM PLC_PRG

VAR_INPUT
    rSaveXMin: REAL;
    rSaveXMax: REAL;
    rSaveY1Min: REAL;
    rSaveY1Max: REAL;
    rSaveY2Min: REAL;
    rSaveY2Max: REAL;
    rMinAxisX: REAL;
    rMaxAxisX: REAL;
    rMinAxisY1: REAL;
    rMaxAxisY1: REAL;
    rMinAxisY2: REAL;
    rMaxAxisY2: REAL;
    AxisX: VisuStructXYChartAxis;
    AxisY1: VisuStructXYChartAxis;
    AxisY2: VisuStructXYChartAxis;
END_VAR

VAR
    xDoIt: BOOL;
    xCursorOff: BOOL;
    rTrigCurs: R_TRIG;
    strCursor: string;
    xZoom: BOOL;
    rTrigZoom: R_TRIG;
    strZoom: string;
    xZoomRst: BOOL;
    rTrigZoomRst: R_TRIG;
    xZoomUndo: BOOL;
    rTrigZoomUndo: R_TRIG;
    xPan: BOOL;
    rTrigPan: R_TRIG;
    strPan: string;
    xPanRst: BOOL;
    rTrigPanRst: R_TRIG;
    xCfg0: BOOL;
    rTrigCfg0: R_TRIG;
    xCfg1: BOOL;
    rTrigCfg1: R_TRIG;
    xCfg2: BOOL;
    rTrigCfg2: R_TRIG;
    xRevAxes: BOOL;
    rTrigRevAxes: R_TRIG;
    DataX1: ARRAY [..] OF ;
    DataY1: ARRAY [..] OF ;
    DataX2: ARRAY [..] OF ;
    DataY2: ARRAY [..] OF ;
    xyChart: VisuStructXYChart;
    Curve1: VisuStructXYChartCurve;
    Curve2: VisuStructXYChartCurve;
    xZoomEnableExt: BOOL;
    xZoomHomeExt: BOOL;
    xZoomUndoExt: BOOL;
    xZoomedExt: BOOL;
    strZoomExt: string;
    xPanEnableExt: BOOL;
    strPanExt: string;
    xPanHomeExt: BOOL;
    xPannedExt: BOOL;
    rValue: REAL;
    xFirst: BOOL;
END_VAR
(**********************************************************************************************
   The scope of this application is to show how to use zooming and panning in XYChart element.
***********************************************************************************************)

//------------------------------------------------------------------
// Initial settings
IF xFirst THEN
   DataX1[1] := 10.0 ;
   DataX1[2] := 20.0 ;
   DataX1[3] := 30.0 ;
   DataX1[4] := 40.0 ;
   DataX1[5] := 50.0 ;  
   DataX1[6] := 60.0 ;  
   DataX1[7] := 70.0 ;  
   DataX1[8] := 80.0 ;  
   DataX1[9] := 90.0 ;  
   DataX1[10] := 100.0 ;  
   
   DataY1[1] := 10.0 ;
   DataY1[2] := 20.0 ;
   DataY1[3] := 10.0 ;
   DataY1[4] := 30.0 ;
   DataY1[5] := 10.0 ;
   DataY1[6] := 40.0 ;
   DataY1[7] := 10.0 ;
   DataY1[8] := 50.0 ;
   DataY1[9] := 10.0 ;
   DataY1[10] := 60.0 ;
   
   DataX2[1] := 25.0 ;
   DataX2[2] := 30.0 ;
   DataX2[3] := 35.0 ;
   DataX2[4] := 40.0 ;
   DataX2[5] := 45.0 ;  
   DataX2[6] := 65.0 ;  
   DataX2[7] := 70.0 ;  
   DataX2[8] := 75.0 ;  
   DataX2[9] := 80.0 ;  
   DataX2[10] := 85.0 ;  
   
   DataY2[1] := 15.0 ;
   DataY2[2] := 8.0 ;
   DataY2[3] := 45.0 ;
   DataY2[4] := 25.0 ;
   DataY2[5] := 50.0 ;
   DataY2[6] := 15.0 ;
   DataY2[7] := 8.0 ;
   DataY2[8] := 45.0 ;
   DataY2[9] := 25.0 ;
   DataY2[10] := 50.0 ;
END_IF

// Switch on/off cursor
rTrigCurs(CLK:=xCursorOff, Q=>xDoIt);
IF xDoIt THEN
   IF xyChart.eCursor = VisuEnumXYChartCursorVisible.NOVIS THEN
      xyChart.eCursor := VisuEnumXYChartCursorVisible.VISIBLE_MAIN;
      strCursor := 'Curs OFF';
   ELSE   
      xyChart.eCursor := VisuEnumXYChartCursorVisible.NOVIS;
      strCursor := 'Curs ON';
	END_IF
END_IF

// Zoom start/stop using element structure 
rTrigZoom(CLK:=xZoom, Q=>xDoIt);
IF xDoIt THEN
   IF (xyChart.eActivity = VisuEnumXYChartActivityType.NO) OR (xyChart.eActivity = VisuEnumXYChartActivityType.PAN)  THEN 
      xyChart.eActivity := VisuEnumXYChartActivityType.ZOOM;
   ELSE   
      xyChart.eActivity := VisuEnumXYChartActivityType.NO;
	END_IF
END_IF

// Reset zoom
rTrigZoomRst(CLK:=xZoomRst, Q=>xDoIt);
IF xDoIt THEN
   xyChart.eCommand := VisuEnumXYChartCommands.ZOOM_HOME;
END_IF

// Undo zoom
rTrigZoomUndo(CLK:=xZoomUndo, Q=>xDoIt);
IF xDoIt THEN
   xyChart.eCommand := VisuEnumXYChartCommands.ZOOM_UNDO;
END_IF


// Pan start/stop using element structure 
rTrigPan(CLK:=xPan, Q=>xDoIt);
IF xDoIt THEN
   IF (xyChart.eActivity = VisuEnumXYChartActivityType.NO) OR (xyChart.eActivity = VisuEnumXYChartActivityType.ZOOM)  THEN 
      xyChart.eActivity := VisuEnumXYChartActivityType.PAN;
   ELSE   
      xyChart.eActivity := VisuEnumXYChartActivityType.NO;
	END_IF
END_IF

// Reset panning
rTrigPanRst(CLK:=xPanRst, Q=>xDoIt);
IF xDoIt THEN
   xyChart.eCommand := VisuEnumXYChartCommands.PAN_HOME;
END_IF



// Set default axes configuration
rTrigCfg0(CLK:=xCfg0, Q=>xDoIt);
IF xDoIt THEN
   AxisX.rMin  := rMinAxisX  := rSaveXMin;
   AxisX.rMax  := rMaxAxisX  := rSaveXMax;
   AxisY1.rMin := rMinAxisY1 := rSaveY1Min;
   AxisY1.rMax := rMaxAxisY1 := rSaveY1Max;
   AxisY2.rMin := rMinAxisY2 := rSaveY2Min;
   AxisY2.rMax := rMaxAxisY2 := rSaveY2Max;
END_IF

// Set axes configuration #1
rTrigCfg1(CLK:=xCfg1, Q=>xDoIt);
IF xDoIt THEN
   AxisX.rMin  := rMinAxisX  := -100;
   AxisX.rMax  := rMaxAxisX  := 200;
   AxisY1.rMin := rMinAxisY1 := 0;
   AxisY1.rMax := rMaxAxisY1 := 120;
   AxisY2.rMin := rMinAxisY2 := 0;
   AxisY2.rMax := rMaxAxisY2 := 180;
END_IF

// Set axes configuration #2
rTrigCfg2(CLK:=xCfg2, Q=>xDoIt);
IF xDoIt THEN
   AxisX.rMin  := rMinAxisX  := 20;
   AxisX.rMax  := rMaxAxisX  := 80;
   AxisY1.rMin := rMinAxisY1 := -100;
   AxisY1.rMax := rMaxAxisY1 := 200;
   AxisY2.rMin := rMinAxisY2 := -100;
   AxisY2.rMax := rMaxAxisY2 := 200;
END_IF

// Reverse axes
rTrigRevAxes(CLK:=xRevAxes, Q=>xDoIt);
IF xDoIt THEN
   rValue := AxisX.rMin;
   AxisX.rMin := AxisX.rMax;
   AxisX.rMax := rValue;
   
   rValue := AxisY1.rMin;
   AxisY1.rMin := AxisY1.rMax;
   AxisY1.rMax := rValue;
   
   rValue := AxisY2.rMin;
   AxisY2.rMin := AxisY2.rMax;
   AxisY2.rMax := rValue;

   rValue := rMinAxisX;
   rMinAxisX := rMaxAxisX;
   rMaxAxisX := rValue;

   rValue := rMinAxisY1;
   rMinAxisY1 := rMaxAxisY1;
   rMaxAxisY1 := rValue;
   
   rValue := rMinAxisY2;
   rMinAxisY2 := rMaxAxisY2;
   rMaxAxisY2 := rValue;
END_IF

// Display setting
IF xyChart.eActivity = VisuEnumXYChartActivityType.PAN THEN
   strPan := 'Pan OUT';
   strZoom := 'Zoom IN';
END_IF
IF xyChart.eActivity = VisuEnumXYChartActivityType.ZOOM THEN
   strZoom := 'Zoom OUT';
   strPan := 'Pan IN';
END_IF
IF xyChart.eActivity = VisuEnumXYChartActivityType.NO THEN
   strPan := 'Pan IN';
   strZoom := 'Zoom IN';
END_IF

IF xZoomEnableExt THEN 
   strZoomExt := 'Zoom OUT';
ELSE   
   strZoomExt := 'Zoom IN';
END_IF

IF xPanEnableExt THEN 
   strPanExt := 'Pan OUT';
ELSE   
   strPanExt := 'Pan IN';
END_IF


xFirst := FALSE;

-------------------------------------------------------------------------------
VISU_INIT
-------------------------------------------------------------------------------


PROGRAM VISU_INIT

VAR
    xFirst: BOOL;
END_VAR
IF xFirst THEN
   PLC_PRG.rMinAxisX  := PLC_PRG.AxisX.rMin;
   PLC_PRG.rMaxAxisX  := PLC_PRG.AxisX.rMax;
   PLC_PRG.rMinAxisY1 := PLC_PRG.AxisY1.rMin;
   PLC_PRG.rMaxAxisY1 := PLC_PRG.AxisY1.rMax;
   PLC_PRG.rMinAxisY2 := PLC_PRG.AxisY2.rMin;
   PLC_PRG.rMaxAxisY2 := PLC_PRG.AxisY2.rMax;
   
   PLC_PRG.rSaveXMin  := PLC_PRG.rMinAxisX;
   PLC_PRG.rSaveXMax  := PLC_PRG.rMaxAxisX;
   PLC_PRG.rSaveY1Min := PLC_PRG.AxisY1.rMin;
   PLC_PRG.rSaveY1Max := PLC_PRG.AxisY1.rMax;
   PLC_PRG.rSaveY2Min := PLC_PRG.AxisY2.rMin;
   PLC_PRG.rSaveY2Max := PLC_PRG.AxisY2.rMax;
END_IF
xFirst := FALSE;