1using BioImager.Properties;
3using System.Collections.Generic;
4using System.ComponentModel;
5using System.Configuration;
10using System.Threading.Tasks;
11using System.Windows.Forms;
18 public partial class FunctionForm : Form
20 public static InputSimulator
input =
new InputSimulator();
22 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
36 InitializeComponent();
42 InitializeComponent();
53 textBox.Text = func.
Script;
55 funcsBox.Items.Clear();
58 funcsBox.Items.Add(f);
61 nameBox.Text = func.
Name;
63 stateBox.Items.Clear();
64 foreach (Function.ButtonState val in Enum.GetValues(typeof(Function.ButtonState)))
66 stateBox.Items.Add(val);
68 stateBox.SelectedItem = func.
State;
72 keysBox.Items.Clear();
73 foreach (VirtualKeyCode val
in Enum.GetValues(typeof(VirtualKeyCode)))
75 keysBox.Items.Add(val);
77 keysBox.SelectedIndex = ind;
81 modifierBox.Items.Clear();
82 modifierBox.Items.Add(VirtualKeyCode.NONAME);
83 modifierBox.Items.Add(VirtualKeyCode.RCONTROL);
84 modifierBox.Items.Add(VirtualKeyCode.LCONTROL);
85 modifierBox.Items.Add(VirtualKeyCode.RSHIFT);
86 modifierBox.Items.Add(VirtualKeyCode.LSHIFT);
87 modifierBox.Items.Add(VirtualKeyCode.MENU);
88 modifierBox.Items.Add(VirtualKeyCode.RWIN);
89 modifierBox.Items.Add(VirtualKeyCode.LWIN);
90 modifierBox.SelectedItem = func.
Modifier;
92 microBox.Items.Clear();
93 foreach (Function.FunctionType f in (Function.FunctionType[])Enum.GetValues(typeof(Function.FunctionType)))
95 microBox.Items.Add(f);
97 microBox.SelectedItem = func.
FuncType;
100 recBox.Items.Clear();
101 foreach (Automation.Recording rec in Automation.Recordings.Values)
103 recBox.Items.Add(rec);
104 string s = System.IO.Path.GetFileNameWithoutExtension(rec.File);
107 recBox.SelectedIndex = ind;
113 propBox.Items.Clear();
114 foreach (Automation.Recording rec in Automation.Properties.Values)
116 propBox.Items.Add(rec);
117 string s = System.IO.Path.GetFileNameWithoutExtension(rec.File);
120 propBox.SelectedIndex = ind;
124 valBox.Value = (decimal)func.
Value;
129 private void UpdateItems()
132 textBox.Text = func.
Script;
133 nameBox.Text = func.
Name;
134 stateBox.SelectedItem = func.
State;
135 keysBox.SelectedItem = func.
Key;
136 modifierBox.SelectedItem = func.
Modifier;
137 microBox.SelectedItem = func.
FuncType;
138 foreach (Automation.Recording rec in Automation.Recordings.Values)
140 string s = System.IO.Path.GetFileNameWithoutExtension(rec.File);
143 recBox.SelectedIndex = ind;
148 foreach (Automation.Recording rec in Automation.Properties.Values)
150 string s = System.IO.Path.GetFileNameWithoutExtension(rec.File);
153 propBox.SelectedIndex = ind;
157 valBox.Value = (decimal)func.
Value;
158 if (func.
FuncType == Function.FunctionType.ImageJ)
159 imageJRadioBut.Checked =
true;
161 imageJRadioBut.Checked =
false;
170 private void keysBox_SelectedIndexChanged(
object sender, EventArgs e)
172 Func.Key = (VirtualKeyCode)keysBox.SelectedItem;
179 private void modifierBox_SelectedIndexChanged(
object sender, EventArgs e)
181 Func.Modifier = (VirtualKeyCode)modifierBox.SelectedItem;
188 private void stateBox_SelectedIndexChanged(
object sender, EventArgs e)
190 Func.State = (Function.ButtonState)stateBox.SelectedItem;
196 private void applyButton_Click(
object sender, EventArgs e)
198 func.Name = nameBox.Text;
199 this.DialogResult = DialogResult.OK;
200 if(!Function.Functions.ContainsKey(func.
Name))
202 Function.Functions.Add(func.
Name, func);
206 Function.Functions[func.
Name] = func;
211 func.MenuPath = func.
MenuPath.TrimEnd(
'/');
224 func.FuncType = (Function.FunctionType)microBox.SelectedItem;
234 private void propBox_SelectedIndexChanged(
object sender, EventArgs e)
236 Func.File = propBox.Text;
237 Func.FuncType = Function.FunctionType.Property;
244 private void recBox_SelectedIndexChanged(
object sender, EventArgs e)
246 Func.File = recBox.Text;
247 Func.FuncType = Function.FunctionType.Recording;
254 private void setMacroFileBut_Click(
object sender, EventArgs e)
256 Func.File = propBox.Text;
257 Func.FuncType = Function.FunctionType.ImageJ;
263 private void setScriptFileBut_Click(
object sender, EventArgs e)
265 Func.File = propBox.Text;
266 Func.FuncType = Function.FunctionType.Script;
273 private void valBox_ValueChanged(
object sender, EventArgs e)
275 Func.Value = (double)valBox.Value;
282 private void performBut_Click(
object sender, EventArgs e)
284 MessageBox.Show(func.
PerformFunction(imageJRadioBut.Checked).ToString());
292 private void cancelBut_Click(
object sender, EventArgs e)
294 this.DialogResult = DialogResult.Cancel;
300 private void textBox_TextChanged(
object sender, EventArgs e)
302 func.Script = textBox.Text;
303 if (bioRadioBut.Checked)
304 func.FuncType = Function.FunctionType.Script;
306 func.FuncType = Function.FunctionType.ImageJ;
313 private void bioRadioBut_CheckedChanged(
object sender, EventArgs e)
315 if(bioRadioBut.Checked)
316 func.FuncType = Function.FunctionType.Script;
323 private void imageJRadioBut_CheckedChanged(
object sender, EventArgs e)
325 if (imageJRadioBut.Checked)
326 func.FuncType = Function.FunctionType.ImageJ;
333 private void menuPath_TextChanged(
object sender, EventArgs e)
335 func.MenuPath = menuPath.Text;
342 private void FunctionForm_Activated(
object sender, EventArgs e)
354 private void funcsBox_SelectedIndexChanged(
object sender, EventArgs e)
356 if (funcsBox.SelectedIndex == -1)
358 func = (Function)funcsBox.SelectedItem;
366 private void FunctionForm_FormClosing(
object sender, FormClosingEventArgs e)
376 private void contextMenuPath_TextChanged(
object sender, EventArgs e)
378 func.ContextPath = contextMenuPath.Text;
386 private void microBox_SelectedIndexChanged(
object sender, EventArgs e)
391 private void nameBox_TextChanged(
object sender, EventArgs e)
399 public static Dictionary<string, Function>
Functions =
new Dictionary<string, Function>();
451 private VirtualKeyCode key;
465 private VirtualKeyCode modifier = VirtualKeyCode.NONAME;
487 functionType = value;
495 set { file = value; }
498 private string script;
501 get {
return script; }
520 private string menuPath;
532 private string contextPath;
567 return JsonConvert.DeserializeObject<
Function>(s);
577 return JsonConvert.SerializeObject(
this);
580 public static InputSimulator
input =
new InputSimulator();
605 if (
Name.StartsWith(
"Get"))
610 else if (
Name.StartsWith(
"Set"))
619 if (
Modifier != VirtualKeyCode.NONAME)
720 string st = Application.StartupPath +
"/Functions";
721 if (!Directory.Exists(st))
722 Directory.CreateDirectory(st);
723 string[] sts = Directory.GetFiles(st);
724 for (
int i = 0; i < sts.Length; i++)
726 string fs = System.IO.File.ReadAllText(sts[i]);
739 if(!Directory.Exists(st +
"/Functions"))
741 Directory.CreateDirectory(st +
"/Functions");
745 System.IO.File.WriteAllText(st +
"/Functions/" + f.
Name +
".func",f.
Serialize());
System.Windows.Forms.Application Application
static void AddMenu(string menu, Function f)
static void AddContextMenu(string menu, Function f)
static Dictionary< string, Recording > Recordings
static Dictionary< string, Recording > Properties
static bool useBioformats
static Function Parse(string s)
object PerformFunction(bool imagej)
override string ToString()
static Dictionary< string, Function > Functions
static InputSimulator input
void Save()
It saves all the functions in the Functions dictionary to a file.
static async void RunOnImage(string con, bool headless, bool onTab, bool bioformats, bool newTab)
object PerformFunction(Function f)
static void MoveFieldUp()
Move the field up by the height of the view.
static void MoveRight(double d)
static RLShutter RLShutter
static void MoveFieldDown()
Move the field down by one unit.
static BioImage TakeImage()
static void SetFocus(double d)
static void MoveDown(double d)
static void MoveFieldRight()
Move the field right by the width of the view.
static void MoveLeft(double d)
static TLShutter TLShutter
static BioImage TakeImageStack()
static void MoveFieldLeft()
Move the field left by the width of the viewport.
static void MoveUp(double d)
static void RunString(string st)