Simply3DScan
ManualControl.cs
Go to the documentation of this file.
1 using System;
2 using System.Drawing.Imaging;
3 using System.Windows.Forms;
5 using Configuration;
6 using SharedObjects;
7 using Syncfusion.Windows.Forms.Tools;
8 using System.Drawing;
9 
10 namespace Simple3DScan.UI
11 {
15  public partial class ManualControl : UserControl
16  {
17  #region fields
18  protected readonly Information ConfigurationInformation = Singleton<Config>.Instance.Information;
22 
26  public ArduinoCommands Arduino { get; set; }
27  #endregion
28 
29  #region constructor
30  [Log]
34  [LogException]
35  public ManualControl()
36  {
37  this.InitializeComponent();
38  }
39 
44  [Log]
45  [LogException]
46  public void Init(ArduinoCommands arduino)
47  {
48  this.Arduino = arduino;
49  this.Arduino.ActivateLaser(false);
50 
51  ButtonRenderer styleRenderer = new ButtonRenderer();
52  this.toggleButtonLaser.Renderer = styleRenderer;
53  this.toggleButtonLight.Renderer = styleRenderer;
54  }
55  #endregion
56 
57  #region controls
58 
64  [Log]
65  [LogException]
66  private void toggleButtonLaser_Click(object sender, EventArgs e)
67  {
68  this.Arduino.ActivateLaser(this.toggleButtonLaser.ToggleState != ToggleButtonState.Active);
69  }
70 
76  [Log]
77  [LogException]
78  private void buttonDetectLaser_Click(object sender, EventArgs e)
79  {
80  this.imagingControl.FilterLaser = !this.imagingControl.FilterLaser;
81  }
82 
88  [Log]
89  [LogException]
90  private void buttonCCW_Click(object sender, EventArgs e)
91  {
92  this.Arduino.RotateTurnTableCcw(100);
93  }
94 
100  [Log]
101  [LogException]
102  private void buttonCW_Click(object sender, EventArgs e)
103  {
104  this.Arduino.RotateTurnTableCw(100);
105  }
106 
112  [Log]
113  [LogException]
114  private void buttonLaserCCW_Click(object sender, EventArgs e)
115  {
116  this.Arduino.RotateLaserCcw(10);
117  }
118 
124  [Log]
125  [LogException]
126  private void buttonLaserCW_Click(object sender, EventArgs e)
127  {
128  this.Arduino.RotateLaserCw(10);
129  }
130 
136  [Log]
137  [LogException]
138  private void toggleButtonLight_Click(object sender, EventArgs e)
139  {
140  if (this.toggleButtonLight.ToggleState != ToggleButtonState.Active)
141  this.Arduino.ActivateLight(true, 10);
142  else
143  this.Arduino.ActivateLight(false, 0);
144  }
145 
151  [Log]
152  [LogException]
153  private void buttonStartCamera_Click(object sender, EventArgs e)
154  {
155  this.imagingControl.LaserLeftPosition = this.ConfigurationInformation.Laser.SwipeMin * this.ConfigurationInformation.Camera.Width / 100;
156  this.imagingControl.LaserRightPosition = this.ConfigurationInformation.Laser.SwipeMax * this.ConfigurationInformation.Camera.Width / 100;
157 
158  this.imagingControl.StartImaging(this.ConfigurationInformation.Camera.Name);
159  }
160 
166  [Log]
167  [LogException]
168  private void buttonStopCamera_Click(object sender, EventArgs e)
169  {
170  this.imagingControl.StopImaging();
171  }
172 
178  [Log]
179  [LogException]
180  private void buttonSaveImage_Click(object sender, EventArgs e)
181  {
182  Image image = this.imagingControl.GetNextPicture();
183  if (null == image)
184  return;
185 
186  SaveFileDialog saveImageDialog = new SaveFileDialog
187  {
188  FileName = "Image_" + DateTime.Now.ToFileTime(),
189  DefaultExt = ".png",
190  Filter = "Images (.png)|*.png"
191  };
192  DialogResult result = saveImageDialog.ShowDialog();
193 
194  if (result != DialogResult.OK)
195  return;
196 
197  string filename = saveImageDialog.FileName;
198  image.Save(filename, ImageFormat.Png);
199  }
200 
201  #endregion
202 
203  #region startstop
204  [Log]
208  [LogException]
209  internal void Stop()
210  {
211  this.imagingControl.StopImaging();
212  }
213 
217  [Log]
218  [LogException]
219  internal void Start()
220  {
221  this.imagingControl.StartImaging(this.ConfigurationInformation.Camera.Name);
222  }
223  #endregion
224 
225  #region dispose
226 
230  [Log]
231  [LogException]
232  protected override void Dispose(bool disposing)
233  {
234  if (disposing)
235  {
236  this.components?.Dispose();
237  }
238  this.imagingControl.StopImaging();
239 
240  base.Dispose(disposing);
241  }
242  #endregion
243  }
244 }
Manual Control of arduino and imaging
Class for detecting an arduino and sending commands to it
Class holding configuration to access an arduino
Definition: Arduino.cs:7
Class holding the configuration information
Definition: Information.cs:8
ManualControl()
Initializes a new instance of the ManualControl class.
void Start()
Starts this instance.
override void Dispose(bool disposing)
Class for creating a singleton for a generic class
Definition: Singleton.cs:9
void Init(ArduinoCommands arduino)
Initializes the control.
Just a class for a special style of the toogle buttons
static T Instance
Gets the instance.
Definition: Singleton.cs:27
void Stop()
Stops this instance.