BioImager  5.0.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
App.cs
Go to the documentation of this file.
1using AForge;
2using BioImager;
3using System;
4using System.Collections.Generic;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8using System.Windows.Forms;
9using BioLib;
10namespace BioImager
11{
12 public class App
13 {
14 public static ROIManager manager = null;
15 public static ChannelsTool channelsTool = null;
16 public static TabsView tabsView = null;
17 public static NodeView nodeView = null;
18 public static Scripting runner = null;
19 public static Recorder recorder = null;
20 public static Imager imager = null;
21 public static Tools tools = null;
22 public static StackTools stackTools = null;
23 public static ImageView viewer = null;
24 public static StageTool stage = null;
25 public static Series seriesTool = null;
26 public static Recordings recordings = null;
27 public static Automation automation = null;
28 public static MicroscopeSetup setup = null;
29 public static CellImager cellImager = null;
30 public static SlideImager slideImager = null;
31 public static BioConsole console = null;
32 public static Light lightTool = null;
33 public static Library lib = null;
34 public static List<string> recent = new List<string>();
35
36
37 public static void UpdateImages()
38 {
39 do
40 {
41 Thread.Sleep(1000);
42 var images = Images.images.ToList();
43 var tabs = App.tabsView;
44 if (tabs == null)
45 continue;
46
47 foreach (var item in images)
48 {
49 if (tabs.HasTab(item))
50 continue;
51 else
52 tabs.AddTab(item);
53 }
54 } while (true);
55 }
56
57 /* A property that returns the current image. */
58 public static BioImage Image
59 {
60 get
61 {
62 if (ImageView.SelectedImage == null)
63 return tabsView.Image;
65 }
66 }
67 public static List<Channel> Channels
68 {
69 get { return Image.Channels; }
70 }
71
72 public static List<ROI> Annotations
73 {
74 get { return Image.Annotations; }
75 }
77 public static void Initialize()
78 {
79 BioImage.Initialize(ImageJ.ImageJPath);
80 Thread th = new Thread(UpdateImages);
81 th.Start();
82 do
83 {
84 Thread.Sleep(100);
85 } while (!BioImage.Initialized);
86 imager = new Imager();
89 setup = new MicroscopeSetup();
90 stage = new StageTool();
91 cellImager = new CellImager();
92 stackTools = new StackTools();
93 tools = new Tools();
94 manager = new ROIManager();
95 runner = new Scripting();
96 recorder = new Recorder();
97 seriesTool = new Series();
98 recordings = new Recordings();
99 automation = new Automation();
100 slideImager = new SlideImager();
101 if (!Properties.Settings.Default.PycroManager && !Properties.Settings.Default.PMicroscope)
102 {
103 lightTool = new Light();
104 }
105 lib = new Library();
106
107 console = new BioConsole();
108 imager.Show();
109
110 //ImageJ.Initialize(Properties.Settings.Default.ImageJPath);
111 }
113 public static void Hide()
114 {
115 tools.Hide();
116 stackTools.Hide();
117 manager.Hide();
118 runner.Hide();
119 recorder.Hide();
120 seriesTool.Hide();
121 recordings.Hide();
122 console.Hide();
123 }
124
128 private static IEnumerable<ToolStripMenuItem> GetItems(ToolStripMenuItem item)
129 {
130 foreach (var dropDownItem in item.DropDownItems)
131 {
132 if (dropDownItem.GetType() == typeof(ToolStripMenuItem))
133 {
134 if (((ToolStripMenuItem)dropDownItem).HasDropDownItems)
135 {
136 foreach (ToolStripMenuItem subItem in GetItems((ToolStripMenuItem)dropDownItem))
137 yield return subItem;
138 }
139 yield return (ToolStripMenuItem)dropDownItem;
140 }
141 }
142 }
146 public static List<ToolStripMenuItem> GetMenuItems()
147 {
148 List<ToolStripMenuItem> allItems = new List<ToolStripMenuItem>();
149 foreach (ToolStripMenuItem toolItem in tabsView.MainMenuStrip.Items)
150 {
151 allItems.Add(toolItem);
152 allItems.AddRange(GetItems(toolItem));
153 }
154 return allItems;
155 }
159 public static List<ToolStripMenuItem> GetContextItems()
160 {
161 List<ToolStripMenuItem> allItems = new List<ToolStripMenuItem>();
162 foreach (ToolStripMenuItem toolItem in viewer.ViewContextMenu.Items)
163 {
164 allItems.Add(toolItem);
165 allItems.AddRange(GetItems(toolItem));
166 }
167 return allItems;
168 }
176 public static ToolStripItem GetMenuItemFromPath(string s, Function f)
177 {
178 if (s == "" || s == null)
179 return null;
180 string[] sts = s.Split('/');
181 start:
182 List<ToolStripMenuItem> allItems = GetMenuItems();
183 //Find path or create it.
184 bool found = false;
185 ToolStripMenuItem item = null;
186
187 for (int t = 0; t < sts.Length; t++)
188 {
189 found = false;
190 for (int i = 0; i < allItems.Count; i++)
191 {
192 if (allItems[i].Text == sts[t])
193 {
194 item = allItems[i];
195 found = true;
196 if (t == sts.Length - 1)
197 return allItems[i];
198 }
199 }
200 if (!found)
201 {
202 if(t == 0)
203 {
204 tabsView.MainMenuStrip.Items.Add(sts[t]);
205 goto start;
206 }
207 else if(t > 0 && t < sts.Length)
208 {
209 ToolStripMenuItem itm = new ToolStripMenuItem();
210 itm.Tag = f;
211 itm.Name = f.Name;
212 item.DropDownItems.Add(f.Name, null, ItemClicked);
213 return item;
214 }
215 else
216 {
217 item.DropDownItems.Add(sts[t]);
218 }
219 }
220 }
221 return item;
222 }
230 public static ToolStripItem GetContextMenuItemFromPath(string s, Function f)
231 {
232 if (s == "" || s == null)
233 return null;
234 string[] sts = s.Split('/');
235 start:
236 List<ToolStripMenuItem> allItems = GetContextItems();
237 //Find path or create it.
238 bool found = false;
239 ToolStripMenuItem item = null;
240
241 for (int t = 0; t < sts.Length; t++)
242 {
243 found = false;
244 for (int i = 0; i < allItems.Count; i++)
245 {
246 if (allItems[i].Text == sts[t])
247 {
248 item = allItems[i];
249 found = true;
250 if (t == sts.Length - 1)
251 return allItems[i];
252 }
253 }
254 if (!found)
255 {
256 if (t == 0)
257 {
258 viewer.ViewContextMenu.Items.Add(sts[t]);
259 goto start;
260 }
261 else if (t > 0 && t < sts.Length)
262 {
263 ToolStripMenuItem itm = new ToolStripMenuItem();
264 itm.Tag = f;
265 itm.Name = f.Name;
266 item.DropDownItems.Add(f.Name, null, ItemClicked);
267 return item;
268 }
269 else
270 {
271 item.DropDownItems.Add(sts[t]);
272 }
273 }
274 }
275 return item;
276 }
277
285 public static ToolStripItem GetMenuItemFromPath(string s)
286 {
287 if (s == "" || s == null)
288 return null;
289 string[] sts = s.Split('/');
290 start:
291 List<ToolStripMenuItem> allItems = GetMenuItems();
292 //Find path or create it.
293 bool found = false;
294 ToolStripMenuItem item = null;
295
296 for (int t = 0; t < sts.Length; t++)
297 {
298 found = false;
299 for (int i = 0; i < allItems.Count; i++)
300 {
301 if (allItems[i].Text == sts[t])
302 {
303 item = allItems[i];
304 found = true;
305 if (t == sts.Length - 1)
306 return allItems[i];
307 }
308 }
309 if (!found)
310 {
311 if (t == 0)
312 {
313 tabsView.MainMenuStrip.Items.Add(sts[t]);
314 goto start;
315 }
316 else if (t > 0 && t < sts.Length)
317 {
318 ToolStripMenuItem itm = new ToolStripMenuItem();
319 itm.Text = Path.GetFileName(s);
320 item.DropDownItems.Add(Path.GetFileName(s), null, ItemClicked);
321 return item;
322 }
323 else
324 {
325 item.DropDownItems.Add(sts[t]);
326 }
327 }
328 }
329 return item;
330 }
338 public static ToolStripItem GetContextMenuItemFromPath(string s)
339 {
340 if (s == "" || s == null)
341 return null;
342 string[] sts = s.Split('/');
343 start:
344 List<ToolStripMenuItem> allItems = GetContextItems();
345 //Find path or create it.
346 bool found = false;
347 ToolStripMenuItem item = null;
348
349 for (int t = 0; t < sts.Length; t++)
350 {
351 found = false;
352 for (int i = 0; i < allItems.Count; i++)
353 {
354 if (allItems[i].Text == sts[t])
355 {
356 item = allItems[i];
357 found = true;
358 if (t == sts.Length - 1)
359 return allItems[i];
360 }
361 }
362 if (!found)
363 {
364 if (t == 0)
365 {
366 viewer.ViewContextMenu.Items.Add(sts[t]);
367 goto start;
368 }
369 else if (t > 0 && t < sts.Length)
370 {
371 ToolStripMenuItem itm = new ToolStripMenuItem();
372 itm.Name = Path.GetFileName(s);
373 item.DropDownItems.Add(Path.GetFileName(s), null, ItemClicked);
374 return item;
375 }
376 else
377 {
378 item.DropDownItems.Add(sts[t]);
379 }
380 }
381 }
382 return item;
383 }
384
390 public static void AddMenu(string menu, Function f)
391 {
392 GetMenuItemFromPath(menu, f);
393 }
398 public static void AddContextMenu(string menu, Function f)
399 {
401 }
402
408 public static void AddMenu(string menu)
409 {
411 }
416 public static void AddContextMenu(string menu)
417 {
419 }
420
421
427 private static void ItemClicked(object sender, EventArgs e)
428 {
429 ToolStripMenuItem ts = (ToolStripMenuItem)sender;
430 if(ts.Text.EndsWith(".dll"))
431 {
432 try
433 {
434 Plugin.Plugins[ts.Text].Execute(new string[] { });
435 }
436 catch (Exception ex)
437 {
438 Console.WriteLine(ex.ToString());
439 }
440
441 }
442 else if(ts.Text.EndsWith(".ijm"))
443 {
444 string st = File.ReadAllText(Path.GetDirectoryName(ImageJ.ImageJPath) + "/macros/" + ts.Text);
446 }
447 else if(ts.Text.EndsWith(".pt") || ts.Text.EndsWith(".onnx"))
448 {
449 try
450 {
451 ML.ML.Run(ts.Text, ImageView.SelectedImage);
452 }
453 catch (Exception ex)
454 {
455 Console.WriteLine(ex.Message.ToString());
456 }
457 }
458 else
459 {
460 Function f = (Function)ts.Tag;
461 f.PerformFunction(true);
462 }
463 }
467 public static void AddROI(string an)
468 {
469 Annotations.Add(BioImage.StringToROI(an));
470 Recorder.AddLine("App.AddROI(" + '"' + an + "'" + ");");
471 }
472 }
473}
System.Drawing.Image Image
Definition ImageView.cs:16
BioLib.BioImage BioImage
Definition TabsView.cs:15
static void UpdateImages()
Definition App.cs:37
static ROIManager manager
Definition App.cs:14
static Series seriesTool
Definition App.cs:25
static void AddMenu(string menu, Function f)
Definition App.cs:390
static NodeView nodeView
Definition App.cs:17
static MicroscopeSetup setup
Definition App.cs:28
static void Hide()
Hide() hides all the tools.
Definition App.cs:113
static Tools tools
Definition App.cs:21
static BioConsole console
Definition App.cs:31
static ToolStripItem GetMenuItemFromPath(string s)
Definition App.cs:285
static ToolStripItem GetContextMenuItemFromPath(string s, Function f)
Definition App.cs:230
static StackTools stackTools
Definition App.cs:22
static ToolStripItem GetMenuItemFromPath(string s, Function f)
Definition App.cs:176
static List< ROI > Annotations
Definition App.cs:73
static List< string > recent
Definition App.cs:34
static List< ToolStripMenuItem > GetContextItems()
Definition App.cs:159
static ToolStripItem GetContextMenuItemFromPath(string s)
Definition App.cs:338
static void AddContextMenu(string menu)
Definition App.cs:416
static Library lib
Definition App.cs:33
static SlideImager slideImager
Definition App.cs:30
static List< ToolStripMenuItem > GetMenuItems()
Definition App.cs:146
static TabsView tabsView
Definition App.cs:16
static Recorder recorder
Definition App.cs:19
static List< Channel > Channels
Definition App.cs:68
static void Initialize()
Initialize() is a function that initializes the BioImager UI.
Definition App.cs:77
static void AddROI(string an)
Definition App.cs:467
static StageTool stage
Definition App.cs:24
static ChannelsTool channelsTool
Definition App.cs:15
static Light lightTool
Definition App.cs:32
static CellImager cellImager
Definition App.cs:29
static void AddMenu(string menu)
Definition App.cs:408
static void AddContextMenu(string menu, Function f)
Definition App.cs:398
static Recordings recordings
Definition App.cs:26
static ImageView viewer
Definition App.cs:23
static Scripting runner
Definition App.cs:18
static Imager imager
Definition App.cs:20
static Automation automation
Definition App.cs:27
static bool useBioformats
Definition BioConsole.cs:20
static bool headless
Definition BioConsole.cs:21
static bool newTab
Definition BioConsole.cs:22
static bool onTab
Definition BioConsole.cs:19
static async void RunOnImage(string con, bool headless, bool onTab, bool bioformats, bool newTab)
Definition ImageJ.cs:189
static string ImageJPath
Definition ImageJ.cs:105
static bool Initialize()
Definition ImageJ.cs:247
ImageView control for image stacks, pyramidal and whole-slide-images.
static BioImage SelectedImage
Definition ImageView.cs:270
ContextMenuStrip ViewContextMenu
A property that returns a ContextMenuStrip object. *‍/.
Definition ImageView.cs:794
static void Initialize()
static Dictionary< string, IPlugin > Plugins
Definition Plugin.cs:16
static void AddLine(string s)
Definition Recorder.cs:16