1using FlaUI.Core.AutomationElements;
3using System.Collections.Generic;
4using System.ComponentModel;
9using System.Threading.Tasks;
10using System.Windows.Forms;
12using Point = AForge.Point;
17 public partial class StageTool : Form
22 InitializeComponent();
28 folderBox.Text = Properties.Settings.Default.ImagingPath;
29 dockBox.Checked = Properties.Settings.Default.DockMicro;
32 Microscope.viewSize =
new PointD((
double)moveXBox.Value, (
double)moveYBox.Value);
36 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
41 return folderBox.Text;
45 Properties.Settings.Default.ImagingPath = folderBox.Text;
46 Properties.Settings.Default.Save();
49 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
59 Properties.Settings.Default.ImageName = nameBox.Text;
60 Properties.Settings.Default.Save();
63 private void hideToolStripMenuItem_Click(
object sender, EventArgs e)
69 private void toolStripMenuItem1_Click(
object sender, EventArgs e)
74 private void hideToolStripMenuItem1_Click(
object sender, EventArgs e)
80 private void showToolStripMenuItem_Click(
object sender, EventArgs e)
85 private void upBut_Click(
object sender, EventArgs e)
87 Microscope.MoveUp((
double)moveYBox.Value);
88 App.viewer.UpdateOverlay();
91 private void rightBut_Click(
object sender, EventArgs e)
93 Microscope.MoveRight((
double)moveXBox.Value);
94 App.viewer.UpdateOverlay();
97 private void downBut_Click(
object sender, EventArgs e)
99 Microscope.MoveDown((
double)moveYBox.Value);
100 App.viewer.UpdateOverlay();
103 private void leftBut_Click(
object sender, EventArgs e)
105 Microscope.MoveLeft((
double)moveXBox.Value);
106 App.viewer.UpdateOverlay();
109 private void objToolStripMenuItem_Click(
object sender, EventArgs e)
114 private void imagerToolStripMenuItem_Click(
object sender, EventArgs e)
119 private void objBox_SelectedIndexChanged(
object sender, EventArgs e)
121 moveXBox.Value = (decimal)Microscope.Objectives.List[objBox.SelectedIndex].ViewWidth;
122 moveYBox.Value = (decimal)Microscope.Objectives.List[objBox.SelectedIndex].ViewHeight;
124 private void setObjBut_Click(
object sender, EventArgs e)
126 if (objBox.SelectedItem ==
null)
128 Objectives.Objective o = (Objectives.Objective)objBox.SelectedItem;
129 Microscope.Objectives.SetPosition(o.Index);
132 private void topMostBox_CheckedChanged(
object sender, EventArgs e)
134 TopMost = topMostBox.Checked;
137 private void takeImageBut_Click(
object sender, EventArgs e)
139 Microscope.TakeImage();
142 private void stackBut_Click(
object sender, EventArgs e)
144 Microscope.UpperLimit = (double)upperLimBox.Value;
145 Microscope.LowerLimit = (double)lowerLimBox.Value;
146 Microscope.fInterVal = (double)fIntervalBox.Value;
147 Microscope.SetFolder(folderBox.Text);
148 BioImage bm = Microscope.TakeImageStack();
149 App.viewer.AddImage(bm);
156 private void timer_Tick(
object sender, EventArgs e)
160 if (!Properties.Settings.Default.PycroManager && !Properties.Settings.Default.PMicroscope)
163 Win32.Rect r =
new Win32.Rect();
164 Win32.GetWindowRect(Imager.apph, ref r);
165 Point pp =
new Point(r.Right - Width, r.Bottom - Height - App.imager.Height - 30);
166 this.Location =
new System.Drawing.Point((
int)pp.X, (
int)pp.Y);
168 string s = Win32.GetActiveWindowTitle();
170 if (s.Contains(Properties.Settings.Default.AppName))
176 if (!s.Contains(
"Imager"))
191 private void dockBox_CheckedChanged(
object sender, EventArgs e)
193 Properties.Settings.Default.DockMicro = dockBox.Checked;
195 this.Location =
new System.Drawing.Point(0, 0);
203 private void setUpperBut_Click(
object sender, EventArgs e)
205 upperLimBox.Value = (decimal)Microscope.Focus.GetFocus(
true);
212 private void setLowerBut_Click(
object sender, EventArgs e)
214 lowerLimBox.Value = (decimal)Microscope.Focus.GetFocus(
true);
222 private void fIntervalBox_ValueChanged(
object sender, EventArgs e)
224 Microscope.fInterVal = (double)fIntervalBox.Value;
229 private void UpdateSlices()
231 double d = (double)upperLimBox.Value - (
double)lowerLimBox.Value;
232 sliceBox.Value = (decimal)(d / (
double)fIntervalBox.Value);
238 private void sliceBox_ValueChanged(
object sender, EventArgs e)
240 double d = (double)upperLimBox.Value - (
double)lowerLimBox.Value;
241 double interval = d / (double)sliceBox.Value;
242 double dd = interval / (double)fIntervalBox.Value;
243 fIntervalBox.Value = (decimal)interval;
251 private void upperLimBox_ValueChanged(
object sender, EventArgs e)
253 Microscope.UpperLimit = (double)upperLimBox.Value;
261 private void lowerLimBox_ValueChanged(
object sender, EventArgs e)
263 Microscope.LowerLimit = (double)lowerLimBox.Value;
270 private void nameBox_TextChanged(
object sender, EventArgs e)
272 Properties.Settings.Default.ImageName = nameBox.Text;
273 Properties.Settings.Default.Save();
284 private void tilesBut_Click(
object sender, EventArgs e)
286 ImageTiles im =
new ImageTiles();
287 if (im.ShowDialog() != DialogResult.OK)
289 Microscope.TakeTiles(im.SizeX, im.SizeY);
298 private void setFolderBut_Click(
object sender, EventArgs e)
300 FolderBrowserDialog fs =
new FolderBrowserDialog();
301 fs.Description =
"Select Imaging Folder";
302 if (fs.ShowDialog() != DialogResult.OK)
309 folderBox.Text = fs.SelectedPath;
310 Microscope.SetFolder(fs.SelectedPath);
311 Properties.Settings.Default.ImagingPath = fs.SelectedPath;
320 private void moveXBox_ValueChanged(
object sender, EventArgs e)
322 Microscope.viewSize =
new PointD((
double)moveXBox.Value, (
double)moveYBox.Value);
323 if (App.viewer !=
null)
324 App.viewer.UpdateView();
332 private void moveYBox_ValueChanged(
object sender, EventArgs e)
334 Microscope.viewSize =
new PointD((
double)moveXBox.Value, (
double)moveYBox.Value);
335 if (App.viewer !=
null)
336 App.viewer.UpdateView();
339 private void goUpperBut_Click(
object sender, EventArgs e)
341 Microscope.SetFocus((
double)upperLimBox.Value);
344 private void goLowerBut_Click(
object sender, EventArgs e)
346 Microscope.SetFocus((
double)lowerLimBox.Value);
349 private void viewBut_Click(
object sender, EventArgs e)
351 if (!Automation.Properties.ContainsKey(
"LiveView"))
353 MessageBox.Show(
"'LiveView' GUI Property not set. Go to automation tab and create a property corresponding to the live view GUI element.");
356 System.Drawing.Rectangle re = Automation.Properties[
"LiveView"].GetBounds();
357 Microscope.SetFocus((
double)upperLimBox.Value);
358 long max =
long.MinValue;
359 double ud = (double)upperLimBox.Value;
360 for (
double i = 0; i < (double)upperLimBox.Value; i += (double)focusInterval.Value)
362 Microscope.SetFocus((
double)i);
363 System.Drawing.Graphics g;
364 System.Drawing.Bitmap b =
new System.Drawing.Bitmap((
int)re.Width, (
int)re.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
365 g = System.Drawing.Graphics.FromImage(b);
366 g.CopyFromScreen(
new System.Drawing.Point((
int)re.X, (
int)re.Y),
new System.Drawing.Point(0, 0),
new System.Drawing.Size(re.Width, re.Height));
367 Clipboard.SetImage(b);
368 System.Drawing.Imaging.BitmapData d = b.LockBits(
new System.Drawing.Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
369 AForge.Bitmap bf =
new AForge.Bitmap(
"",
new UnmanagedImage(d.Scan0, b.Width, b.Height, b.Width * 4,
PixelFormat.Format32bppArgb),
new ZCT(), 0);
370 long dd =
BioImage.CalculateFocusQuality(bf);
380 Microscope.SetFocus(ud);
AForge.PixelFormat PixelFormat
static MicroscopeSetup setup
static Objectives Objectives
static RectangleD GetObjectiveViewRectangle()