using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using com.quinncurtis.chart2dnet;
using com.quinncurtis.spcchartnet;
namespace SPCApplication1
{
///
/// Summary description for SPCApplicationUserControl1.
///
public class SPCApplicationUserControl1 : com.quinncurtis.spcchartnet.SPCTimeVariableControlChart
{
private class ZoomWithStack : ChartZoom
{
public ZoomWithStack(ChartView component, PhysicalCoordinates transform, bool brescale)
:
base(component, transform, brescale)
{
}
public override void OnMouseDown(MouseEventArgs mouseevent)
{
if ((mouseevent.Button & MouseButtons.Right) != 0)
this.PopZoomStack();
else
base.OnMouseDown(mouseevent);
}
}
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
ChartCalendar startTime = new ChartCalendar();
// The time increment between adjacent subgroups
int timeincrementminutes = 15;
// Number of samples per sub group
int numsamplespersubgroup = 5;
public SPCApplicationUserControl1()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
// Have the chart fill parent client area
this.Dock = DockStyle.Fill;
// Define and draw chart
InitializeChart();
}
public void InitializeChart()
{
// SPC variable control chart type
int charttype = SPCControlChartData.MEAN_RANGE_CHART;
// Number of datapoints in the view
int numdatapointsinview = 200;
// Initialize the SPCTimeVariableControlChart
this.InitSPCTimeVariableControlChart(charttype,
numsamplespersubgroup, numdatapointsinview, timeincrementminutes);
#if true
this.HeaderStringsLevel = SPCControlChartData.HEADER_STRINGS_LEVEL1;
// Set the strings used in the header section of the table
this.ChartData.Title = "Variable Control Chart (X-Bar & R)";
this.ChartData.PartNumber = "283501";
this.ChartData.ChartNumber="17";
this.ChartData.PartName= "Transmission Casing Bolt";
this.ChartData.Operation = "Threading";
// Display the Sampled value rows of the table
this.EnableInputStringsDisplay= true;
// Display the Sampled value rows of the table
this.EnableCategoryValues= true;
// Display the Calculated value rows of the table
this.EnableCalculatedValues= true;
// Display the total samples per subgroup value row
this.EnableTotalSamplesValues= true;
// Display the Notes row of the table
this.EnableNotes= true;
// Display the time stamp row of the table
this.EnableTimeValues = true;
//You can control the decimal precision of the sampled values using
this.ChartData.DefectiveDecimalPrecision = 1;
//You can control the decimal precision of the calculated values (Mean, Range, Sum) using
this.ChartData.CalculatedValueDecimalPrecision = 1;
this.PrimaryChart.DisplayFrequencyHistogram = true;
this.SecondaryChart.DisplayFrequencyHistogram = true;
this.TableAlarmEmphasisMode = SPCChartBase.ALARM_HIGHLIGHT_BAR;
this.AutoLogAlarmsAsNotes = true;
#else // want no table at all - use this instead
// primary chart, secondary chart, histograms, chart title
this.UseNoTable(true, true, true, "Place your chart title here");
#endif
this.EnableScrollBar = true;
this.ChartAlarmEmphasisMode= SPCChartBase.ALARM_HIGHLIGHT_SYMBOL;
// this.PrimaryChart.ProcessVariableData.LineMarkerPlot.LineColor = Color.Black;
// this.PrimaryChart.ProcessVariableData.LineMarkerPlot.SymbolAttributes.PrimaryColor = Color.BlueViolet;
// this.PrimaryChart.ProcessVariableData.LineMarkerPlot.SymbolAttributes.FillColor = Color.Beige;
// frequency histogram for both charts
this.UseNoTable(true, true, false, "XXXX");
// training data
SimulateData(50, 30, 10);
// Calculate the SPC control limits for both graphs of the current SPC chart (X-Bar R)
this.AutoCalculateControlLimits();
// New data added after limits calculated
SimulateData(150, 30, 15);
// Scale the y-axis of the X-Bar chart to display all data and control limits
this.AutoScalePrimaryChartYRange();
// Scale the y-axis of the Range chart to display all data and control limits
this.AutoScaleSecondaryChartYRange();
// Rebuild the chart using the current data and settings
this.RebuildChartUsingCurrentData();
ZoomWithStack zoomObj = new ZoomWithStack(this, this.PrimaryChart.PPhysTransform1, true);
zoomObj.SetButtonMask(MouseButtons.Left);
zoomObj.SetZoomYEnable(true);
zoomObj.SetZoomXEnable(true);
zoomObj.SetZoomXRoundMode(ChartObj.AUTOAXES_FAR);
zoomObj.SetZoomYRoundMode(ChartObj.AUTOAXES_FAR);
zoomObj.SetEnable(true);
zoomObj.SetZoomStackEnable(true);
// set range limits to 1000 ms, 1 degree
// zoomObj.SetZoomRangeLimitsRatio(new Dimension(1.0, 1.0));
this.SetCurrentMouseListener(zoomObj);
}
private void SimulateData(int count, double mean, double std)
{
int datalogflags = SPCControlChartData.DATALOG_FILE_TIME_STAMP |
SPCControlChartData.DATALOG_FILE_SAMPLED_VALUES;
this.ChartData.DataLogFileOpenForWrite("DatalogFile1.txt", datalogflags);
this.ChartData.DatalLogEnable = true;
for (int i=0; i < count; i++)
{
ChartCalendar timestamp = (ChartCalendar) startTime.Clone();
// Use the ChartData sample simulator to make an array of sample data
DoubleArray samples = this.ChartData.SimulateMeasurementRecord(mean, std);
// In a non-simulated application, you would define samples to have a size equal to your sample sub group size, then assign individual elements of the array
#if false
DoubleArray samples = new DoubleArray(numsamplespersubgroup); // where numsamplespersubgroup = 5
samples[0] = samplevalue0; // the samplevalue values come from your process
samples[1] = samplevalue1; // the samplevalue values come from your process
samples[2] = samplevalue2; // the samplevalue values come from your process
samples[3] = samplevalue3; // the samplevalue values come from your process
samples[4] = samplevalue4; // the samplevalue values come from your process
#endif
// Add the new sample subgroup to the chart
this.ChartData.AddNewSampleRecord(timestamp, samples);
// increment simulated time by timeincrementminutes minutes
startTime.Add(ChartObj.MINUTE, timeincrementminutes);
}
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}