2using System.Collections.Generic;
3using System.ComponentModel;
5using System.Drawing.Imaging;
9using System.Threading.Tasks;
10using System.Runtime.InteropServices;
11using System.Windows.Forms;
12using System.Diagnostics;
13using System.Globalization;
14using System.Threading;
17using System.Configuration;
18using BioImager.Properties;
19using Settings =
BioImager.Properties.Settings;
24 public partial class Imager : Form
26 private static Process AppP =
null;
27 public static IntPtr apph;
28 private System.Drawing.Point mainWinDefLocation =
new System.Drawing.Point(1473, 509);
29 public static string AppPath =
"";
30 public static List<BioImage> StoredImages =
new List<BioImage>();
31 public Controller controller;
32 public Gamepad gamepad, previousGamepadState;
33 public bool prevState =
false;
34 public bool connected =
false;
35 public float leftTrigger, rightTrigger;
36 public int deadzone = 5;
39 public string ID => this.m_ID;
40 public static Process ZenP
51 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
52 public uint ImagesPerSlice
56 return (uint)imagesPerSliceBox.Value;
60 imagesPerSliceBox.Value = (decimal)value;
63 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
64 public uint SliceIncrement
68 return (uint)sliceIncrementBox.Value;
72 sliceIncrementBox.Value = (decimal)value;
75 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
76 public uint SlicesPerSlide
80 return (uint)slicesPerSlideBox.Value;
84 slicesPerSlideBox.Value = (decimal)value;
88 public Profile CurrentProfile =
new Profile(
"Default");
93 public string FilePath =
"";
94 public string Name =
"";
95 public string DirName =
"";
96 public void Save(
string path)
98 List<string> sts =
new List<string>();
99 foreach (SettingsProperty currentProperty
in Settings.Default.Properties)
101 string s = currentProperty.Name +
"=" + Settings.Default[currentProperty.Name].ToString();
104 File.WriteAllLines(path, sts.ToArray());
110 if (path !=
"Default")
112 Name = Path.GetFileNameWithoutExtension(FilePath);
113 DirName = Path.GetDirectoryName(FilePath);
119 string[] sts = File.ReadAllLines(FilePath);
120 foreach (
string s
in sts)
122 string[] ss = s.Split(
'=');
123 if (Settings.Default[ss[0]].GetType() == typeof(
double))
125 Settings.Default[ss[0]] =
double.Parse(ss[1]);
128 if (Settings.Default[ss[0]].GetType() == typeof(
string))
130 Settings.Default[ss[0]] = ss[1];
135 public override string ToString()
137 return Name +
" " + DirName;
144 InitializeComponent();
145 if (Settings.Default.PycroManager)
147 topMostCheckBox.Checked =
false;
148 dockToApp.Checked =
false;
150 Stopwatch timer =
new Stopwatch();
152 TimeSpan st1 = timer.Elapsed;
154 if (Settings.Default.AppPath !=
"" && !Settings.Default.AppPath.Contains(
"ImageJ"))
157 AppPath = Settings.Default.AppPath;
158 if (!File.Exists(AppPath))
160 MessageBox.Show(
"Error!",
"Imaging appplication not found. Please locate the executable.");
162 if (openExeFileDialog.ShowDialog() != DialogResult.OK)
164 Settings.Default.AppPath = openExeFileDialog.FileName;
166 string pn = Path.GetFileNameWithoutExtension(AppPath);
167 Process[] prs = Process.GetProcessesByName(pn);
170 AppP = Process.Start(AppPath);
174 apph = AppP.MainWindowHandle;
178 AppP.WaitForInputIdle();
186 for (UserIndex i = UserIndex.One; i <= UserIndex.Four; i++)
188 controller =
new Controller(i);
189 if (controller.IsConnected)
194 else controller =
null;
197 ControllerFuncs.LoadSettings();
199 controllerJoystickUpdate.Start();
201 controllerButtonUpdate.Start();
204 if (!Directory.Exists(Application.StartupPath +
"\\Profiles"))
205 Directory.CreateDirectory(Application.StartupPath +
"\\Profiles");
206 string[] sts = Directory.GetFiles(Application.StartupPath +
"\\Profiles");
207 foreach (
string s
in sts)
209 Profile p =
new Profile(s);
210 profilesBox.Items.Add(p);
213 if (Settings.Default.PreviousProfile !=
"Default")
215 CurrentProfile =
new Profile(Settings.Default.PreviousProfile);
216 CurrentProfile.Load();
218 foreach (Profile item
in profilesBox.Items)
220 if (item.FilePath == Settings.Default.PreviousProfile)
222 profilesBox.SelectedIndex = index;
228 this.TopMost = topMostCheckBox.Checked;
230 if (dockToApp.Checked && !Properties.Settings.Default.PycroManager)
233 Win32.Rect r =
new Win32.Rect();
234 Win32.GetWindowRect(apph, ref r);
235 System.Drawing.Point pp =
new System.Drawing.Point(r.Right -
this.Width, r.Bottom -
this.Height - 23);
236 this.Location =
new System.Drawing.Point((
int)pp.X, (
int)pp.Y);
252 Point3D p = Microscope.GetPosition();
253 double f = Microscope.GetFocus();
254 Point3D point =
new Point3D(p.X, p.Y, f);
255 statusLabel.Text =
"Stage: " + p.X +
" , " + p.Y +
" Focus: " + f;
256 if (StoredImages.Count > storedImageBox.Items.Count)
258 int dif = StoredImages.Count - storedImageBox.Items.Count;
259 for (
int i = 0; i < dif; i++)
261 int index = (StoredImages.Count - 1) + dif;
262 storedImageBox.Items.Add(StoredImages[index - 1]);
267 public void StoreCoordinate()
269 Point3D p3 = Microscope.GetPosition();
270 storedCoordsBox.Items.Add(p3);
271 storedCoordsBox.SelectedIndex = storedCoordsBox.Items.Count - 1;
274 public static bool? liveStatus =
null;
275 private void MainForm_FormClosing(
object sender, FormClosingEventArgs e)
277 if (App.viewer !=
null)
278 Properties.Settings.Default.Origin = App.viewer.Origin.ToString();
279 Settings.Default.PreviousProfile = CurrentProfile.FilePath;
280 Settings.Default.Save();
281 if (CurrentProfile.FilePath !=
"Default")
282 CurrentProfile.Save(CurrentProfile.FilePath);
286 private void deadzoneBox_ValueChanged(
object sender, EventArgs e)
288 deadzone = (int)deadzoneBox.Value;
291 private void storedCoordsBox_SelectedIndexChanged(
object sender, EventArgs e)
293 Point3D p = (Point3D)storedCoordsBox.SelectedItem;
294 xCoordBox.Value = (decimal)p.X;
295 yCoordBox.Value = (decimal)p.Y;
296 zCoordBox.Value = (decimal)p.Z;
299 private void addCoordBut_Click(
object sender, EventArgs e)
304 private void goToToolStripMenuItem_Click(
object sender, EventArgs e)
306 if (storedImageBox.SelectedIndex == -1)
308 BioImage s = (BioImage)storedImageBox.SelectedItem;
309 Microscope.SetPosition(s.Volume.Location);
312 private void deleteToolStripMenuItem_Click(
object sender, EventArgs e)
314 if (storedImageBox.SelectedIndex == -1)
316 storedImageBox.Items.RemoveAt(storedImageBox.SelectedIndex);
317 storedImageBox.SelectedIndex = storedImageBox.Items.Count - 1;
320 private void clearBut_Click(
object sender, EventArgs e)
323 storedCoordsBox.Items.Clear();
326 private void clearToolStripMenuItem_Click(
object sender, EventArgs e)
328 storedImageBox.Items.Clear();
331 private void clearToolStripMenuItem1_Click(
object sender, EventArgs e)
333 storedCoordsBox.Items.Clear();
336 private void goToToolStripMenuItem1_Click(
object sender, EventArgs e)
338 Point3D p = (Point3D)storedCoordsBox.SelectedItem;
339 Microscope.SetPosition(p);
348 private void deleteToolStripMenuItem1_Click(
object sender, EventArgs e)
350 if (storedCoordsBox.SelectedIndex == -1)
352 storedCoordsBox.Items.RemoveAt(storedCoordsBox.SelectedIndex);
353 storedCoordsBox.SelectedIndex = storedCoordsBox.Items.Count - 1;
362 private void controllerJoystickUpdate_Tick(
object sender, EventArgs e)
373 gamepad = controller.GetState().Gamepad;
376 leftTrigger = ((float)(gamepad.LeftTrigger) / 255) * 100;
377 rightTrigger = ((float)(gamepad.RightTrigger) / 255) * 100;
380 if (rightTrigger > 0)
383 double curpos = Microscope.GetFocus();
384 Microscope.SetFocus((((
double)triggerFocusBox.Value) * rightTrigger) + curpos);
389 double curpos = Microscope.GetFocus();
390 Microscope.SetFocus((-1 * (((
double)triggerFocusBox.Value) * leftTrigger)) + curpos);
396 double maxVal = ushort.MaxValue / 2;
397 double minVal = maxVal * -1;
398 if (gamepad.LeftThumbX > deadzone)
399 Microscope.MoveRight((((
float)gamepad.LeftThumbX) / maxVal) * (
float)LJoystickStageMoveAmountBox.Value);
400 if (gamepad.LeftThumbX < -deadzone)
401 Microscope.MoveLeft((((
float)gamepad.LeftThumbX) / minVal) * (
float)LJoystickStageMoveAmountBox.Value);
402 if (gamepad.LeftThumbY < -deadzone)
403 Microscope.MoveUp((((
float)gamepad.LeftThumbY) / maxVal) * (
float)LJoystickStageMoveAmountBox.Value);
404 if (gamepad.LeftThumbY > deadzone)
405 Microscope.MoveDown((((
float)gamepad.LeftThumbY) / minVal) * (
float)LJoystickStageMoveAmountBox.Value);
408 if (gamepad.RightThumbX > deadzone)
409 Microscope.MoveRight(((
float)gamepad.RightThumbX / maxVal) * (
float)RJoystickStageMoveAmountBox.Value);
410 if (gamepad.RightThumbX < -deadzone)
411 Microscope.MoveLeft((((
float)gamepad.RightThumbX) / minVal) * (
float)RJoystickStageMoveAmountBox.Value);
412 if (gamepad.RightThumbY < -deadzone)
413 Microscope.MoveUp((((
float)gamepad.RightThumbY) / maxVal) * (
float)RJoystickStageMoveAmountBox.Value);
414 if (gamepad.RightThumbY > deadzone)
415 Microscope.MoveDown((((
float)gamepad.RightThumbY) / minVal) * (
float)RJoystickStageMoveAmountBox.Value);
418 LJoystickLabel.Text =
"X: " + gamepad.LeftThumbX.ToString(
"0.000") +
" Y:" + gamepad.LeftThumbY.ToString(
"0.000");
419 RJoystickLabel.Text =
"X: " + gamepad.RightThumbX.ToString(
"0.000") +
" Y:" + gamepad.RightThumbY.ToString(
"0.000");
421 leftTriggerLabel.Text = leftTrigger.ToString();
422 rightTriggerLabel.Text = rightTrigger.ToString();
425 if (storedCoordsBox.Items.Count > 0 && storedCoordsBox.SelectedIndex != -1)
427 Point3D p0 = (Point3D)storedCoordsBox.Items[storedCoordsBox.Items.Count - 1];
428 Point3D p1 = Microscope.GetPosition();
429 lastCoordDistanceLabel.Text = Point3D.Distance(p0, p1).ToString();
431 Point3D pp0 = (Point3D)storedCoordsBox.Items[storedCoordsBox.SelectedIndex];
432 Point3D pp1 = Microscope.GetPosition();
433 lastSelectedCoordsLabel.Text = Point3D.Distance(pp0, pp1).ToString();
436 if (storedImageBox.Items.Count > 0 && storedImageBox.SelectedIndex != -1)
438 BioImage s = (BioImage)storedImageBox.Items[storedImageBox.Items.Count - 1];
439 Point3D p0 = s.Volume.Location;
440 Point3D p1 = Microscope.GetPosition();
441 lastSnapDistanceLabel.Text = Point3D.Distance(p0, p1).ToString();
443 BioImage ss = (BioImage)storedImageBox.Items[storedImageBox.SelectedIndex];
444 Point3D pp0 = ss.Volume.Location;
445 Point3D pp1 = Microscope.GetPosition();
446 lastSelectedSnapDistanceLabel.Text = Point3D.Distance(pp0, pp1).ToString();
458 private void controllerButtonUpdate_Tick(
object sender, EventArgs e)
468 gamepad = controller.GetState().Gamepad;
473 previousGamepadState = gamepad;
485 for (
int i = 0; i < str.Length; i++)
487 if ((str[i] >=
'0') && (str[i] <=
'9'))
499 private void statusTimer_Tick(
object sender, EventArgs e)
502 if (dockToApp.Checked && !Properties.Settings.Default.PycroManager && !Properties.Settings.Default.PMicroscope)
506 Win32.GetWindowRect(apph, ref r);
507 System.Drawing.Point pp =
new System.Drawing.Point((r.Right) -
this.Width, (r.Bottom) -
this.Height - 30);
508 this.Location =
new System.Drawing.Point((
int)pp.X,(
int)pp.Y);
510 string s = Win32.GetActiveWindowTitle();
511 if(Microscope.initialized)
512 statusLabel.Text = Microscope.GetPosition().ToString();
514 if (s.Contains(Settings.Default.AppName))
516 if (dockToApp.Checked)
520 if (!s.Contains(
"Imager"))
522 if (dockToApp.Checked)
529 #region Labels Double Clicked
539 private void YPressedLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
541 FunctionForm form =
new FunctionForm(ControllerFuncs.Y,
"YButton");
542 if (form.ShowDialog() != DialogResult.OK)
544 ControllerFuncs.Y = form.Func;
545 Settings.Default.Y = ControllerFuncs.Y.Serialize();
546 Settings.Default.Save();
547 ControllerFuncs.LoadSettings();
557 private void BPressedLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
559 FunctionForm form =
new FunctionForm(ControllerFuncs.B,
"BButton");
560 if (form.ShowDialog() != DialogResult.OK)
562 ControllerFuncs.B = form.Func;
563 Settings.Default.B = ControllerFuncs.B.Serialize();
564 Settings.Default.Save();
565 ControllerFuncs.LoadSettings();
575 private void APressedLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
577 FunctionForm form =
new FunctionForm(ControllerFuncs.A,
"AButton");
578 if (form.ShowDialog() != DialogResult.OK)
580 ControllerFuncs.A = form.Func;
581 Settings.Default.A = ControllerFuncs.A.Serialize();
582 Settings.Default.Save();
583 ControllerFuncs.LoadSettings();
593 private void XPressedLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
595 FunctionForm form =
new FunctionForm(ControllerFuncs.X,
"XButton");
596 if (form.ShowDialog() != DialogResult.OK)
598 ControllerFuncs.X = form.Func;
599 Settings.Default.X = ControllerFuncs.X.Serialize();
600 Settings.Default.Save();
601 ControllerFuncs.LoadSettings();
610 private void BackPressedLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
612 FunctionForm form =
new FunctionForm(ControllerFuncs.Back,
"BackButton");
613 if (form.ShowDialog() != DialogResult.OK)
615 ControllerFuncs.Back = form.Func;
616 Settings.Default.Back = ControllerFuncs.Back.Serialize();
617 Settings.Default.Save();
618 ControllerFuncs.LoadSettings();
627 private void StartPressedLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
629 FunctionForm form =
new FunctionForm(ControllerFuncs.Start,
"StartButton");
630 if (form.ShowDialog() != DialogResult.OK)
632 Settings.Default.Start = ControllerFuncs.Start.Serialize();
633 Settings.Default.Save();
634 ControllerFuncs.LoadSettings();
644 private void DPadUpLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
646 FunctionForm form =
new FunctionForm(ControllerFuncs.DPadUp,
"DPadUpButton");
647 if (form.ShowDialog() != DialogResult.OK)
649 ControllerFuncs.DPadUp = form.Func;
650 Settings.Default.DPadUp = ControllerFuncs.DPadUp.Serialize();
651 Settings.Default.Save();
652 ControllerFuncs.LoadSettings();
662 private void DPadRightLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
664 FunctionForm form =
new FunctionForm(ControllerFuncs.DPadRight,
"DPadRightButton");
665 if (form.ShowDialog() != DialogResult.OK)
667 ControllerFuncs.DPadRight = form.Func;
668 Settings.Default.DPadRight = ControllerFuncs.DPadRight.Serialize();
669 Settings.Default.Save();
670 ControllerFuncs.LoadSettings();
680 private void DPadDownLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
682 FunctionForm form =
new FunctionForm(ControllerFuncs.DPadDown,
"DPadDownButton");
683 if (form.ShowDialog() != DialogResult.OK)
685 ControllerFuncs.DPadDown = form.Func;
686 Settings.Default.DPadDown = ControllerFuncs.DPadDown.Serialize();
687 Settings.Default.Save();
688 ControllerFuncs.LoadSettings();
698 private void DPadLeftLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
700 FunctionForm form =
new FunctionForm(ControllerFuncs.DPadLeft,
"DPadLeftButton");
701 if (form.ShowDialog() != DialogResult.OK)
703 ControllerFuncs.DPadLeft = form.Func;
704 Settings.Default.DPadLeft = ControllerFuncs.DPadLeft.Serialize();
705 Settings.Default.Save();
706 ControllerFuncs.LoadSettings();
716 private void shoulderLeftLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
718 FunctionForm form =
new FunctionForm(ControllerFuncs.LShoulder,
"ShoulderLeftButton");
719 if (form.ShowDialog() != DialogResult.OK)
721 ControllerFuncs.LShoulder = form.Func;
722 Settings.Default.LShoulder = ControllerFuncs.LShoulder.Serialize();
723 Settings.Default.Save();
724 ControllerFuncs.LoadSettings();
733 private void shoulderRightLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
735 FunctionForm form =
new FunctionForm(ControllerFuncs.RShoulder,
"ShoulderRightButton");
736 if (form.ShowDialog() != DialogResult.OK)
738 ControllerFuncs.RShoulder = form.Func;
739 Settings.Default.RShoulder = ControllerFuncs.RShoulder.Serialize();
740 Settings.Default.Save();
741 ControllerFuncs.LoadSettings();
750 private void r3PressedLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
752 FunctionForm form =
new FunctionForm(ControllerFuncs.R3,
"R3");
753 if (form.ShowDialog() != DialogResult.OK)
755 ControllerFuncs.R3 = form.Func;
756 Settings.Default.Right3 = ControllerFuncs.R3.Serialize();
757 Settings.Default.Save();
758 ControllerFuncs.LoadSettings();
768 private void l3PressedLabel_MouseDoubleClick(
object sender, MouseEventArgs e)
770 FunctionForm form =
new FunctionForm(ControllerFuncs.L3,
"L3");
771 if (form.ShowDialog() != DialogResult.OK)
773 Settings.Default.Left3 = ControllerFuncs.L3.Serialize();
774 Settings.Default.Save();
775 ControllerFuncs.LoadSettings();
787 private void openFileToolStripMenuItem_Click(
object sender, EventArgs e)
789 if (storedImageBox.SelectedItem ==
null)
791 BioImage s = (BioImage)storedImageBox.SelectedItem;
792 if (s.Filename ==
"")
795 Process.Start(s.Filename);
804 private void openProfileBut_Click(
object sender, EventArgs e)
806 openProfileFileDialog.InitialDirectory = Application.StartupPath +
"\\Profiles";
807 if (openProfileFileDialog.ShowDialog() != DialogResult.OK)
809 CurrentProfile =
new Profile(openProfileFileDialog.FileName);
810 CurrentProfile.Load();
811 profilesBox.Items.Add(CurrentProfile);
813 foreach (Profile item
in profilesBox.Items)
815 if (item.FilePath == CurrentProfile.FilePath)
817 profilesBox.SelectedIndex = index;
831 private void profilesBox_SelectedIndexChanged(
object sender, EventArgs e)
833 if (profilesBox.SelectedIndex == -1)
835 if (profilesBox.Text ==
"Default" || profilesBox.SelectedItem.ToString() ==
"Default")
837 CurrentProfile = (Profile)profilesBox.SelectedItem;
846 private void saveProfileBut_Click(
object sender, EventArgs e)
848 saveFileDialog.InitialDirectory = Application.StartupPath +
"\\Profiles\\";
849 if (profilesBox.Text !=
"")
850 saveFileDialog.FileName = profilesBox.Text;
852 if (profilesBox.SelectedItem !=
null)
853 if (profilesBox.SelectedItem.ToString() ==
"Default" || profilesBox.Text ==
"Default")
855 MessageBox.Show(
"You are saving the default profile, are you sure you want to do this?",
"NOTICE!");
856 Settings.Default.Save();
859 if (saveFileDialog.ShowDialog() != DialogResult.OK)
861 CurrentProfile.Save(saveFileDialog.FileName);
864 private void clearSnapsBut_Click(
object sender, EventArgs e)
866 storedImageBox.Items.Clear();
876 private void storedSnapBox_SelectedIndexChanged(
object sender, EventArgs e)
878 if (storedImageBox.SelectedItem ==
null)
880 BioImage s = (BioImage)storedImageBox.SelectedItem;
881 xCoordBox.Value = (decimal)s.Volume.Location.X;
882 yCoordBox.Value = (decimal)s.Volume.Location.Y;
883 zCoordBox.Value = (decimal)s.Volume.Location.Z;
886 private void goToLocBox_Click(
object sender, EventArgs e)
888 Point3D p =
new Point3D((
double)xCoordBox.Value, (
double)yCoordBox.Value, (
double)zCoordBox.Value);
889 Microscope.SetPosition(p);
891 private void tabContextMenu_Opening(
object sender, CancelEventArgs e)
902 private void borderToolStripMenuItem_Click(
object sender, EventArgs e)
904 if (this.FormBorderStyle == FormBorderStyle.Sizable)
906 this.FormBorderStyle = FormBorderStyle.None;
907 borderToolStripMenuItem.Text =
"Window Border Normal";
911 this.FormBorderStyle = FormBorderStyle.Sizable;
912 borderToolStripMenuItem.Text =
"Window Border None";
916 private void hideToolStripMenuItem_Click(
object sender, EventArgs e)
921 private void closeToolStripMenuItem_Click(
object sender, EventArgs e)
933 private void openInImageViewToolStripMenuItem_Click(
object sender, EventArgs e)
935 if (storedImageBox.SelectedIndex == -1)
937 BioImage s = (BioImage)storedImageBox.SelectedItem;
947 private void MainForm_KeyDown(
object sender, KeyEventArgs e)
949 if (e.KeyCode == Keys.S && e.Control)
951 if (saveImageDialog.ShowDialog() != DialogResult.OK)
962 private void copyToolStripMenuItem1_Click(
object sender, EventArgs e)
964 Clipboard.SetText(storedImageBox.SelectedItem.ToString());
972 private void copyToolStripMenuItem_Click(
object sender, EventArgs e)
974 Clipboard.SetText(storedCoordsBox.SelectedItem.ToString());
981 private void dockToApp_CheckedChanged(
object sender, EventArgs e)
990 private void topMostCheckBox_CheckedChanged(
object sender, EventArgs e)
992 this.TopMost = topMostCheckBox.Checked;
1007 if (prevState.Buttons == GamepadButtonFlags.Y && state.Buttons != GamepadButtonFlags.Y)
1010 prevState.Buttons = GamepadButtonFlags.None;
1011 YPressedLabel.Text =
"Y: released";
1014 YPressedLabel.Text =
"Y: not pressed";
1018 if (state.Buttons == GamepadButtonFlags.Y)
1021 prevState.Buttons = GamepadButtonFlags.None;
1022 YPressedLabel.Text =
"Y: pressed";
1025 YPressedLabel.Text =
"Y: not pressed";
1029 if (prevState.Buttons == GamepadButtonFlags.B && state.Buttons != GamepadButtonFlags.B)
1032 prevState.Buttons = GamepadButtonFlags.None;
1033 state.Buttons = GamepadButtonFlags.None;
1034 BPressedLabel.Text =
"B: released";
1037 BPressedLabel.Text =
"B: not pressed";
1041 if (state.Buttons == GamepadButtonFlags.B)
1044 prevState.Buttons = GamepadButtonFlags.None;
1045 BPressedLabel.Text =
"B: pressed";
1048 BPressedLabel.Text =
"B: not pressed";
1052 if (prevState.Buttons == GamepadButtonFlags.A && state.Buttons != GamepadButtonFlags.A)
1055 prevState.Buttons = GamepadButtonFlags.None;
1056 APressedLabel.Text =
"A: released";
1059 APressedLabel.Text =
"A: not pressed";
1063 if (state.Buttons == GamepadButtonFlags.A)
1066 prevState.Buttons = GamepadButtonFlags.None;
1067 APressedLabel.Text =
"A: pressed";
1070 APressedLabel.Text =
"A: not pressed";
1074 if (prevState.Buttons == GamepadButtonFlags.X && state.Buttons != GamepadButtonFlags.X)
1077 prevState.Buttons = GamepadButtonFlags.None;
1078 XPressedLabel.Text =
"X: released";
1081 XPressedLabel.Text =
"X: not pressed";
1085 if (state.Buttons == GamepadButtonFlags.X)
1088 prevState.Buttons = GamepadButtonFlags.None;
1089 XPressedLabel.Text =
"X: pressed";
1092 XPressedLabel.Text =
"X: not pressed";
1096 #region Back & Start Keys
1099 if (prevState.Buttons == GamepadButtonFlags.Start && state.Buttons != GamepadButtonFlags.Start)
1102 prevState.Buttons = GamepadButtonFlags.None;
1103 StartPressedLabel.Text =
"Start: released";
1106 StartPressedLabel.Text =
"Start: not pressed";
1110 if (state.Buttons == GamepadButtonFlags.Start)
1113 prevState.Buttons = GamepadButtonFlags.None;
1114 StartPressedLabel.Text =
"Start: pressed";
1117 StartPressedLabel.Text =
"Start: not pressed";
1121 if (prevState.Buttons == GamepadButtonFlags.Back && state.Buttons != GamepadButtonFlags.Back)
1124 prevState.Buttons = GamepadButtonFlags.None;
1125 BackPressedLabel.Text =
"Back: released";
1128 BackPressedLabel.Text =
"Back: not pressed";
1132 if (state.Buttons == GamepadButtonFlags.Back)
1135 prevState.Buttons = GamepadButtonFlags.None;
1136 BackPressedLabel.Text =
"Back: pressed";
1139 BackPressedLabel.Text =
"Back: not pressed";
1146 if (prevState.Buttons == GamepadButtonFlags.RightShoulder && state.Buttons != GamepadButtonFlags.RightShoulder)
1149 prevState.Buttons = GamepadButtonFlags.None;
1150 shoulderRightLabel.Text =
"Right: released";
1153 shoulderRightLabel.Text =
"Right: not pressed";
1157 if (state.Buttons == GamepadButtonFlags.RightShoulder)
1160 prevState.Buttons = GamepadButtonFlags.None;
1161 shoulderRightLabel.Text =
"Right: pressed";
1164 shoulderRightLabel.Text =
"Right: not pressed";
1168 if (prevState.Buttons == GamepadButtonFlags.LeftShoulder && state.Buttons != GamepadButtonFlags.LeftShoulder)
1171 prevState.Buttons = GamepadButtonFlags.None;
1172 shoulderLeftLabel.Text =
"Left: released";
1175 shoulderLeftLabel.Text =
"Left: not pressed";
1179 if (state.Buttons == GamepadButtonFlags.LeftShoulder)
1182 prevState.Buttons = GamepadButtonFlags.None;
1183 shoulderLeftLabel.Text =
"Left: pressed";
1186 shoulderLeftLabel.Text =
"Left: not pressed";
1194 if (prevState.Buttons == GamepadButtonFlags.RightThumb && state.Buttons != GamepadButtonFlags.RightThumb)
1197 prevState.Buttons = GamepadButtonFlags.None;
1198 r3PressedLabel.Text =
"R3: released";
1201 r3PressedLabel.Text =
"R3: not pressed";
1205 if (state.Buttons == GamepadButtonFlags.RightThumb)
1208 prevState.Buttons = GamepadButtonFlags.None;
1209 r3PressedLabel.Text =
"R3: pressed";
1212 r3PressedLabel.Text =
"R3: not pressed";
1217 if (prevState.Buttons == GamepadButtonFlags.LeftThumb && state.Buttons != GamepadButtonFlags.LeftThumb)
1220 prevState.Buttons = GamepadButtonFlags.None;
1221 l3PressedLabel.Text =
"L3: released";
1224 l3PressedLabel.Text =
"L3: not pressed";
1228 if (state.Buttons == GamepadButtonFlags.LeftThumb)
1231 prevState.Buttons = GamepadButtonFlags.None;
1232 l3PressedLabel.Text =
"L3: pressed";
1235 l3PressedLabel.Text =
"L3: not pressed";
1239 #region DPAD BUTTONS
1242 if (prevState.Buttons == GamepadButtonFlags.DPadUp && state.Buttons != GamepadButtonFlags.DPadUp)
1245 prevState.Buttons = GamepadButtonFlags.None;
1246 DPadUpLabel.Text =
"Up: released";
1249 DPadUpLabel.Text =
"Up: not pressed";
1253 if (state.Buttons == GamepadButtonFlags.DPadUp)
1256 prevState.Buttons = GamepadButtonFlags.None;
1257 DPadUpLabel.Text =
"Up: pressed";
1260 DPadUpLabel.Text =
"Up: not pressed";
1265 if (prevState.Buttons == GamepadButtonFlags.DPadRight && state.Buttons != GamepadButtonFlags.DPadRight)
1268 prevState.Buttons = GamepadButtonFlags.None;
1269 DPadRightLabel.Text =
"Right: released";
1272 DPadRightLabel.Text =
"Right: not pressed";
1276 if (state.Buttons == GamepadButtonFlags.DPadRight)
1279 prevState.Buttons = GamepadButtonFlags.None;
1280 DPadRightLabel.Text =
"Right: pressed";
1283 DPadRightLabel.Text =
"Right: not pressed";
1288 if (prevState.Buttons == GamepadButtonFlags.DPadDown && state.Buttons != GamepadButtonFlags.DPadDown)
1291 prevState.Buttons = GamepadButtonFlags.None;
1292 DPadDownLabel.Text =
"Down: released";
1295 DPadDownLabel.Text =
"Down: not pressed";
1299 if (state.Buttons == GamepadButtonFlags.DPadDown)
1302 prevState.Buttons = GamepadButtonFlags.None;
1303 DPadDownLabel.Text =
"Down: pressed";
1306 DPadDownLabel.Text =
"Down: not pressed";
1311 if (prevState.Buttons == GamepadButtonFlags.DPadLeft && state.Buttons != GamepadButtonFlags.DPadLeft)
1314 prevState.Buttons = GamepadButtonFlags.None;
1315 DPadLeftLabel.Text =
"Left: released";
1318 DPadLeftLabel.Text =
"Left: not pressed";
1322 if (state.Buttons == GamepadButtonFlags.DPadLeft)
1325 prevState.Buttons = GamepadButtonFlags.None;
1326 DPadLeftLabel.Text =
"Left: pressed";
1329 DPadLeftLabel.Text =
"Left: not pressed";
1336 public static InputSimulator input =
new InputSimulator();
1345 if (f.FuncType ==
Function.FunctionType.Key)
1351 AppP.WaitForInputIdle();
1353 Win32.SetForegroundWindow(apph);
1354 if (f.Modifier != VirtualKeyCode.NONAME)
1356 input.Keyboard.ModifiedKeyStroke(f.Modifier, f.Key);
1360 input.Keyboard.KeyPress(f.Key);
1364 if (f.FuncType ==
Function.FunctionType.Objective)
1367 Microscope.Objectives.SetPosition((
int)f.Value);
1370 LJoystickStageMoveAmountBox.Value = (decimal)obj.MoveAmountL;
1371 RJoystickStageMoveAmountBox.Value = (decimal)obj.MoveAmountR;
1372 triggerFocusBox.Value = (decimal)obj.FocusMoveAmount;
1375 if (f.FuncType ==
Function.FunctionType.StoreCoordinate)
1380 if (f.FuncType ==
Function.FunctionType.NextCoordinate)
1384 if (storedCoordsBox.SelectedIndex != -1)
1387 if (storedCoordsBox.SelectedIndex + 1 < storedCoordsBox.Items.Count)
1389 Point3D p = (Point3D)storedCoordsBox.Items[storedCoordsBox.SelectedIndex + 1];
1390 Microscope.SetPosition(p);
1391 storedCoordsBox.SelectedIndex = storedCoordsBox.SelectedIndex + 1;
1393 if (storedCoordsBox.SelectedIndex == 0)
1395 Point3D p = (Point3D)storedCoordsBox.Items[storedCoordsBox.SelectedIndex];
1396 Microscope.SetPosition(p);
1401 if (f.FuncType ==
Function.FunctionType.PreviousCoordinate)
1408 if (storedCoordsBox.SelectedIndex != -1)
1410 if (storedCoordsBox.SelectedIndex == 0)
1412 Point3D p = (Point3D)storedCoordsBox.Items[storedCoordsBox.SelectedIndex];
1413 Microscope.SetPosition(p);
1415 if (storedCoordsBox.SelectedIndex > 0)
1417 Point3D p = (Point3D)storedCoordsBox.Items[storedCoordsBox.SelectedIndex - 1];
1418 Microscope.SetPosition(p);
1419 storedCoordsBox.SelectedIndex = storedCoordsBox.SelectedIndex - 1;
1424 if (f.FuncType ==
Function.FunctionType.NextSnapCoordinate)
1428 if (storedImageBox.SelectedIndex != -1)
1431 if (storedImageBox.SelectedIndex + 1 < storedImageBox.Items.Count)
1433 Point3D p = (Point3D)storedImageBox.Items[storedImageBox.SelectedIndex + 1];
1434 Microscope.SetPosition(p);
1435 storedImageBox.SelectedIndex = storedImageBox.SelectedIndex + 1;
1437 if (storedImageBox.SelectedIndex == 0)
1439 Point3D p = (Point3D)storedImageBox.Items[storedImageBox.SelectedIndex];
1440 Microscope.SetPosition(p);
1445 if (f.FuncType ==
Function.FunctionType.PreviousSnapCoordinate)
1452 if (storedImageBox.SelectedIndex != -1)
1454 if (storedImageBox.SelectedIndex == 0)
1456 Point3D p = (Point3D)storedImageBox.Items[storedImageBox.SelectedIndex];
1457 Microscope.SetPosition(p);
1459 if (storedImageBox.SelectedIndex > 0)
1461 Point3D p = (Point3D)storedImageBox.Items[storedImageBox.SelectedIndex - 1];
1462 Microscope.SetPosition(p);
1464 storedImageBox.SelectedIndex = storedImageBox.SelectedIndex - 1;
1469 if (f.FuncType ==
Function.FunctionType.Script)
1473 if (f.FuncType ==
Function.FunctionType.ImageJ)
1477 if (f.FuncType.ToString() ==
"StageUp")
1479 Microscope.MoveUp(f.Value);
1482 if (f.FuncType.ToString() ==
"StageRight")
1484 Microscope.MoveRight(f.Value);
1487 if (f.FuncType.ToString() ==
"StageDown")
1489 Microscope.MoveDown(f.Value);
1492 if (f.FuncType.ToString() ==
"StageLeft")
1494 Microscope.MoveLeft(f.Value);
1497 if (f.FuncType.ToString() ==
"FocusUp")
1499 Microscope.SetFocus(f.Value);
1502 if (f.FuncType.ToString() ==
"FocusDown")
1504 Microscope.SetFocus(-f.Value);
1507 if (f.FuncType.ToString() ==
"StageFieldUp")
1509 Microscope.MoveFieldUp();
1512 if (f.FuncType.ToString() ==
"StageFieldRight")
1514 Microscope.MoveFieldRight();
1517 if (f.FuncType.ToString() ==
"StageFieldDown")
1519 Microscope.MoveFieldDown();
1522 if (f.FuncType.ToString() ==
"StageFieldLeft")
1524 Microscope.MoveFieldLeft();
1527 if (f.FuncType.ToString() ==
"TakeImage")
1529 Microscope.TakeImage();
1532 if (f.FuncType.ToString() ==
"TakeImageStack")
1534 Microscope.TakeImageStack();
1537 if (f.FuncType.ToString() ==
"RL")
1539 Microscope.RLShutter.SetPosition((
int)f.Value);
1542 if (f.FuncType.ToString() ==
"TL")
1544 Microscope.TLShutter.SetPosition((
int)f.Value);
1546 if (f.FuncType ==
Function.FunctionType.Property)
1548 if (f.Name.StartsWith(
"Get"))
1553 else if (f.Name.StartsWith(
"Set"))
1556 r.Set(f.Value.ToString());
1560 if (f.FuncType ==
Function.FunctionType.Recording)
1572 public static Function Y, B, A, X, DPadUp, DPadRight, DPadDown, DPadLeft, Start, Back, RShoulder, LShoulder, R3, L3;
1573 public static bool Initialized =
false;
1574 public static void LoadSettings()
1576 Y =
Function.Parse(Settings.Default.Y.ToString());
1577 B =
Function.Parse(Settings.Default.B.ToString());
1578 A =
Function.Parse(Settings.Default.A.ToString());
1579 X =
Function.Parse(Settings.Default.X.ToString());
1580 DPadUp =
Function.Parse(Settings.Default.DPadUp.ToString());
1581 DPadRight =
Function.Parse(Settings.Default.DPadRight.ToString());
1582 DPadDown =
Function.Parse(Settings.Default.DPadDown.ToString());
1583 DPadLeft =
Function.Parse(Settings.Default.DPadLeft.ToString());
1584 Start =
Function.Parse(Settings.Default.Start.ToString());
1585 Back =
Function.Parse(Settings.Default.Back.ToString());
1586 RShoulder =
Function.Parse(Settings.Default.RShoulder.ToString());
1587 LShoulder =
Function.Parse(Settings.Default.LShoulder.ToString());
1588 R3 =
Function.Parse(Settings.Default.Right3.ToString());
1589 L3 =
Function.Parse(Settings.Default.Left3.ToString());
1591 if (Settings.Default.Y.ToString() ==
"")
1592 Initialized =
false;
1596 private void ImagingTab_Click(
object sender, EventArgs e)
1598 statusLabel.Text = Microscope.GetPosition().ToString();
static void RunMacro(string file, string param)
static int DigitsInString(string str)
void CheckGamepadButtons(Gamepad state, Gamepad prevState)
object PerformFunction(Function f)
static void RunScript(string file)