SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
ConfigureGraph.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 
10 namespace SeciUserInterface.Dialogs.Graphs
11 {
12  public partial class ConfigureGraph : Form
13  {
15 
16  public ConfigureGraph()
17  {
18  InitializeComponent();
19  }
20 
21  private void ConfigureGraph_Load(object sender, EventArgs e)
22  {
23  if (Graph != null)
24  {
25  txtTitle.Text = Graph.Title;
26  txtYlabel.Text = Graph.YLabel;
27  txtY2label.Text = Graph.Y2Label;
28  comboRate.SelectedIndex = findIndex(Graph.UpdateRate);
29  chkShowZero1.Checked = Graph.ShowZeroY1;
30  chkShowZero2.Checked = Graph.ShowZeroY2;
31 
32  updatePlotList();
33  }
34  else
35  {
37  comboRate.SelectedIndex = 5;
38  chkShowZero1.Checked = true;
39  chkShowZero2.Checked = true;
40  }
41  }
42 
43  private int findIndex(Double updaterate)
44  {
45  for (int i = 0; i < comboRate.Items.Count; ++i)
46  {
47  if (comboRate.Items[i].ToString().StartsWith(updaterate.ToString()))
48  {
49  return i;
50  }
51  }
52 
53  return 5;
54  }
55 
56  private void btnAdd_Click(object sender, EventArgs e)
57  {
58  if (Graph.Plots.Count < Seci.Definitions.Status.MaxNumberPlotsPerGraph)
59  {
60 
61  AddEditPlot add = new AddEditPlot();
62 
63  if (add.ShowDialog() == DialogResult.OK)
64  {
65  if (!lstPlots.Items.Contains(add.Plot.BlockName))
66  {
67  Graph.Plots.Add(add.Plot);
68 
69  updatePlotList();
70  }
71  else
72  {
73  MessageBox.Show("Plot not added: Block is already plotted in this graph.");
74  }
75  }
76  }
77  else
78  {
79  MessageBox.Show("Maximum number of plots allowed is " + Seci.Definitions.Status.MaxNumberPlotsPerGraph + ".");
80  }
81  }
82 
83  private void btnEdit_Click(object sender, EventArgs e)
84  {
85  if (lstPlots.SelectedIndex != -1)
86  {
87  int index = lstPlots.SelectedIndex;
88  AddEditPlot edit = new AddEditPlot();
89  edit.Plot = Graph.Plots[lstPlots.SelectedIndex];
90 
91  if (edit.ShowDialog() == DialogResult.OK)
92  {
93  lstPlots.Items.RemoveAt(lstPlots.SelectedIndex);
94  if (!lstPlots.Items.Contains(edit.Plot.BlockName))
95  {
96  Graph.Plots[index] = edit.Plot;
97  }
98  else
99  {
100  MessageBox.Show("Plot not changed: Block is already plotted in this graph.");
101  }
102  updatePlotList();
103  }
104  }
105  }
106 
107  private void btnDelete_Click(object sender, EventArgs e)
108  {
109  if (lstPlots.SelectedIndex != -1)
110  {
111  Graph.Plots.RemoveAt(lstPlots.SelectedIndex);
112 
113  updatePlotList();
114  }
115  }
116 
117  private void updatePlotList()
118  {
119  lstPlots.Items.Clear();
120 
121  foreach (Seci.Definitions.PlotDefinition plot in Graph.Plots)
122  {
123  lstPlots.Items.Add(plot.BlockName);
124  }
125  }
126 
127  private void btnOK_Click(object sender, EventArgs e)
128  {
129  if (txtTitle.Text.Trim() != "")
130  {
131  Graph.Title = txtTitle.Text.Trim();
132  Graph.YLabel = txtYlabel.Text.Trim();
133  Graph.Y2Label = txtY2label.Text.Trim();
134  String val = comboRate.SelectedItem.ToString();
135  double rate = 30;
136  if (Double.TryParse(val.Substring(0, val.IndexOf(' ')), out rate))
137  {
138  Graph.UpdateRate = rate;
139  }
140  else
141  {
142  Graph.UpdateRate = 30.0;
143  }
144 
145  Graph.ShowZeroY1 = chkShowZero1.Checked;
146  Graph.ShowZeroY2 = chkShowZero2.Checked;
147 
148  DialogResult = DialogResult.OK;
149  Close();
150  }
151  else
152  {
153  MessageBox.Show("Please fill in the Graph Title", "Missing Title", MessageBoxButtons.OK, MessageBoxIcon.Warning);
154  }
155  }
156 
157 
158  }
159 }
This class is used for serializing the graphs for saving in the configuration.
void btnDelete_Click(object sender, EventArgs e)
Seci.Definitions.GraphDefinition Graph
void btnAdd_Click(object sender, EventArgs e)
void btnEdit_Click(object sender, EventArgs e)
Seci.Definitions.PlotDefinition Plot
Definition: AddEditPlot.cs:14
void btnOK_Click(object sender, EventArgs e)
void ConfigureGraph_Load(object sender, EventArgs e)