-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathformManager.cs
284 lines (207 loc) · 8.59 KB
/
formManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
* Yocto-Visualization, a free application to visualize Yoctopuce Sensors.
*
* widgets forms generic management
*
*
* - - - - - - - - - License information: - - - - - - - - -
*
* Copyright (C) 2017 and beyond by Yoctopuce Sarl, Switzerland.
*
* Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
* non-exclusive license to use, modify, copy and integrate this
* file into your software for the sole purpose of interfacing
* with Yoctopuce products.
*
* You may reproduce and distribute copies of this file in
* source or object form, as long as the sole purpose of this
* code is to interface with Yoctopuce products. You must retain
* this notice in the distributed source file.
*
* You should refer to Yoctopuce General Terms and Conditions
* for additional information regarding your rights and
* obligations.
*
* THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
* WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
* EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
* COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
* SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
* LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
* CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
* BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
* WARRANTY, OR OTHERWISE.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using YoctoVisualization.Properties;
using YColors;
using YDataRendering;
namespace YoctoVisualisation
{
class formManager
{
Form myForm;
private XmlNode initDataNode;
private string formDesc;
private StartForm mainForm;
private GenericProperties settings;
private bool Closing = false;
public void AjustHint(string description)
{
}
public formManager(Form form, StartForm main, XmlNode initnode, string description, GenericProperties formsettings)
{
formDesc = description;
mainForm = main;
initDataNode = initnode;
settings = formsettings;
myForm = form;
form.FormClosing += targetFormClosing;
form.Shown += target_Shown;
}
public void proportionalValuechanged(Proportional source)
{
Object parent = source.directParent;
if (parent is YFontParams)
{
object userData = ((YFontParams)parent).userData;
if (userData != null)
{
double newvalue = (Math.Round(source.value * 1000)) / 1000;
if (((FontDescription)userData).size != newvalue)
{
((FontDescription)userData).size = newvalue;
mainForm.refreshPropertiesForm();
}
}
}
}
private void target_Shown(object sender, EventArgs e)
{
}
public void configureContextMenu(Form parentForm, ContextMenuStrip menu, EventHandler ShowConfig, EventHandler SwitchConfig, EventHandler Capture)
{
menu.Items.Add(new ToolStripMenuItem("Configure this " + this.formDesc, Resources.menu_configure_item, ShowConfig));
menu.Items.Add(new ToolStripMenuItem("Delete this " + this.formDesc, Resources.deleted, deleteCurrentForm));
menu.Items.Add(new ToolStripSeparator());
menu.Items.Add(new ToolStripMenuItem("Add a new solid gauge", Resources.menu_add_solidgauge, AddNewSolidGauge));
menu.Items.Add(new ToolStripMenuItem("Add a new angular gauge", Resources.rmenu_add_gauge, AddNewAngularGauge));
menu.Items.Add(new ToolStripMenuItem("Add a new digital display", Resources.menu_add_digital, AddNewDigitalDisplay));
menu.Items.Add(new ToolStripMenuItem("Add a new graph", Resources.menu_add_graph, AddNewGraph));
menu.Items.Add(new ToolStripMenuItem("Show Raw data", Resources.menu_rawdata, ShowRawData));
menu.Items.Add(new ToolStripMenuItem("Snapshot", Resources.snapshot, Capture));
menu.Items.Add(new ToolStripSeparator());
menu.Items.Add(new ToolStripMenuItem("Global configuration ", Resources.menu_configure, ConfigureUSBNet));
menu.Items.Add(new ToolStripMenuItem("Save now", Resources.save, savenow));
menu.Items.Add(new ToolStripMenuItem("Show logs", Resources.menu_logs, showlogs));
menu.Items.Add(new ToolStripMenuItem("Close the whole application", Resources.exit, ExitTheApplication));
}
private void showlogs(object sender, EventArgs e)
{ LogManager.Show(); }
private void ConfigureUSBNet(object sender, EventArgs e)
{ mainForm.ConfigureUSBNet(); }
private void savenow(object sender, EventArgs e)
{ LogManager.Log("Saving..."); mainForm.SaveConfig(); }
private void ShowRawData(object sender, EventArgs e)
{ mainForm.ShowRawData(); }
private void AddNewSolidGauge(object sender, EventArgs e)
{
mainForm.NewSolidGaugeForm(null);
}
private void AddNewAngularGauge(object sender, EventArgs e)
{
mainForm.NewAngularGaugeForm(null);
}
private void AddNewDigitalDisplay(object sender, EventArgs e)
{
mainForm.NewDigitalDisplayForm(null);
}
private void AddNewGraph(object sender, EventArgs e)
{ mainForm.NewGraphForm(null); }
private void targetFormClosing(object sender, FormClosingEventArgs e)
{
formClosing(e);
}
private void ExitTheApplication(object sender, EventArgs e)
{
mainForm.Terminate();
}
private void deleteCurrentForm(object sender, EventArgs e)
{
mainForm.hidePropertyEditor();
deleteForm(true);
}
public string getConfigData()
{
Point p = (myForm.WindowState == FormWindowState.Normal) ? myForm.Location : myForm.RestoreBounds.Location;
Size s = (myForm.WindowState == FormWindowState.Normal) ? myForm.Size : myForm.RestoreBounds.Size;
return " <location x='" + p.X.ToString() + "' y='" + p.Y.ToString() + "'/>\n"
+" <size w='" + s.Width.ToString() + "' h='" + s.Height.ToString() + "' state='"+myForm.WindowState.ToString() +"'/>\n"
+ settings.getXml(1);
}
public void setData(System.Reflection.PropertyInfo info, object target, string propertyName, string value)
{
switch (info.PropertyType.ToString())
{
case "System.Drawing.Color": info.SetValue(target, YColor.fromString(value).toColor(),null); break;
case "System.Windows.Forms.FormBorderStyle": /* info.SetValue(target, GenericProperties.BordersModeFromString(value),null);*/ break;
default: info.SetValue(target, value,null); break;
}
}
public bool initForm()
{
if (initDataNode != null)
{
StartForm.RestoreWindowPosition(myForm, initDataNode);
foreach (XmlNode node in initDataNode.ChildNodes)
{
switch (node.Name)
{
default:
if ((node.Name.Length >= 5) && (node.Name.Substring(0, 5) == "Form_"))
{
string propname = node.Name.Substring(5);
string value = node.Attributes["value"].InnerText;
System.Reflection.PropertyInfo info = myForm.GetType().GetProperty(propname);
if (info!=null) setData(info, myForm, propname, value);
}
break;
}
}
return true;
}
return false;
}
public bool deleteForm(bool explicitCall)
{
bool userResponse = (MessageBox.Show("You really want to delete this " + formDesc + " ?", "deleting " + formDesc,
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes);
//looks like MessageBox is causing the main form to automatically pop-up in mono
if (constants.MonoRunning) mainForm.Hide();
if (userResponse){
Closing = true;
mainForm.removeForm(myForm);
myForm.Close();
return true;
}
return false;
}
public void formClosing(FormClosingEventArgs e)
{
if ((e.CloseReason == CloseReason.UserClosing) && (!mainForm.isClosing) && (!Closing))
{
mainForm.Terminate();
e.Cancel = true;
YAPI.FreeAPI();
}
}
}
}