BioCore  5.0.0
A Windows .NET microscopy library and application for viewing, editing, and annotating images.
Loading...
Searching...
No Matches
App.cs
Go to the documentation of this file.
1using AForge;
2using BioCore;
3using BioLib;
4namespace BioCore
5{
6 public class App
7 {
8 public static ROIManager manager = null;
9 public static ChannelsTool channelsTool = null;
10 public static TabsView tabsView = null;
11 public static NodeView nodeView = null;
12 public static Scripting runner = null;
13 public static Recorder recorder = null;
14 public static Tools tools = null;
15 public static StackTools stackTools = null;
16 public static ImageView viewer = null;
17 public static Series seriesTool = null;
18 public static BioConsole console = null;
19 public static Library lib = null;
20 public static List<string> recent = new List<string>();
21
22 /* A property that returns the current image. */
28 public static BioImage Image
29 {
30 get
31 {
32 if (ImageView.SelectedImage == null)
33 return tabsView.Image;
35 }
36 }
37 public static List<Channel> Channels
38 {
39 get { return Image.Channels; }
40 }
41
42 public static List<ROI> Annotations
43 {
44 get { return Image.Annotations; }
45 }
46 public static bool Initialized { get; private set; }
48 public static void Initialize(bool requireImageJ = false)
49 {
50
52 OpenFileDialog openFileDialog = new OpenFileDialog();
53 string imj = BioLib.Settings.GetSettings("ImageJPath");
54 if (imj!="")
55 {
56 if(openFileDialog.ShowDialog() == DialogResult.OK)
57 {
58 if(openFileDialog.FileName.Contains("Fiji"))
59 Fiji.Initialize(openFileDialog.FileName);
60 else
61 ImageJ.Initialize(openFileDialog.FileName);
62 }
63 }
64 else
65 {
66 if (openFileDialog.FileName.Contains("Fiji"))
67 Fiji.Initialize(imj);
68 else
69 ImageJ.Initialize(imj);
70 }
71 tabsView = new TabsView();
72 BioImage.Initialize(imj);
73 viewer = new ImageView();
74 stackTools = new StackTools();
75 tools = new Tools();
76 manager = new ROIManager();
77 runner = new Scripting();
78 recorder = new Recorder();
79 seriesTool = new Series();
80 lib = new Library();
81 console = new BioConsole();
82 Initialized = true;
83 }
85 public static void Hide()
86 {
87 tools.Hide();
88 stackTools.Hide();
89 manager.Hide();
90 runner.Hide();
91 recorder.Hide();
92 seriesTool.Hide();
93 console.Hide();
94 }
102 public static ToolStripItem GetMenuItemFromPath(string s)
103 {
104 if (s == "" || s == null)
105 return null;
106 string[] sts = s.Split('/');
107 start:
108 List<ToolStripMenuItem> allItems = GetMenuItems();
109 //Find path or create it.
110 bool found = false;
111 ToolStripMenuItem item = null;
112
113 for (int t = 0; t < sts.Length; t++)
114 {
115 found = false;
116 for (int i = 0; i < allItems.Count; i++)
117 {
118 if (allItems[i].Text == sts[t])
119 {
120 item = allItems[i];
121 found = true;
122 if (t == sts.Length - 1)
123 return allItems[i];
124 }
125 }
126 if (!found)
127 {
128 if (t == 0)
129 {
130 tabsView.MainMenuStrip.Items.Add(sts[t]);
131 goto start;
132 }
133 else if (t > 0 && t < sts.Length)
134 {
135 ToolStripMenuItem itm = new ToolStripMenuItem();
136 itm.Text = Path.GetFileName(s);
137 item.DropDownItems.Add(Path.GetFileName(s), null, ItemClicked);
138 return item;
139 }
140 else
141 {
142 item.DropDownItems.Add(sts[t]);
143 }
144 }
145 }
146 return item;
147 }
155 public static ToolStripItem GetContextMenuItemFromPath(string s)
156 {
157 if (s == "" || s == null)
158 return null;
159 string[] sts = s.Split('/');
160 start:
161 List<ToolStripMenuItem> allItems = GetContextItems();
162 //Find path or create it.
163 bool found = false;
164 ToolStripMenuItem item = null;
165
166 for (int t = 0; t < sts.Length; t++)
167 {
168 found = false;
169 for (int i = 0; i < allItems.Count; i++)
170 {
171 if (allItems[i].Text == sts[t])
172 {
173 item = allItems[i];
174 found = true;
175 if (t == sts.Length - 1)
176 return allItems[i];
177 }
178 }
179 if (!found)
180 {
181 if (t == 0)
182 {
183 viewer.ViewContextMenu.Items.Add(sts[t]);
184 goto start;
185 }
186 else if (t > 0 && t < sts.Length)
187 {
188 ToolStripMenuItem itm = new ToolStripMenuItem();
189 itm.Name = Path.GetFileName(s);
190 item.DropDownItems.Add(Path.GetFileName(s), null, ItemClicked);
191 return item;
192 }
193 else
194 {
195 item.DropDownItems.Add(sts[t]);
196 }
197 }
198 }
199 return item;
200 }
201
207 public static void AddMenu(string menu)
208 {
210 }
215 public static void AddContextMenu(string menu)
216 {
218 }
219
220 public static void SelectWindow(string name)
221 {
222 TabsView tbs = App.tabsView;
223
224 int c = tbs.GetViewerCount();
225 for (int v = 0; v < c; v++)
226 {
227 int cc = tbs.GetViewer(v).Images.Count;
228 for (int im = 0; im < cc; im++)
229 {
230 if (tbs.GetViewer(v).Images[im].Filename == Path.GetFileName(name))
231 {
232 tbs.SetTab(v);
233 BioLib.Recorder.Record("App.SelectWindow(\"" + name + "\")");
234 ImageView.SelectedImage = tbs.GetViewer(v).Images[im];
235 viewer = tbs.GetViewer(v);
236 viewer.BringToFront();
237 viewer.Focus();
238 return;
239 }
240 }
241 }
242 }
243
244 public static void CloseWindow(string name)
245 {
246 BioLib.Recorder.Record("App.CloseWindow(\"" + name + "\")");
247 TabsView tbs = App.tabsView;
248 int c = tbs.GetViewerCount();
249 if (name == "ROI Manager")
250 App.manager.Close();
251 else
252 if (name == "Stack Tool")
253 App.stackTools.Close();
254 else
255 if (name == "Channels Tool")
256 App.channelsTool.Close();
257 else
258 if (name == "Recorder")
259 App.recorder.Close();
260 else
261 if (name == "Tools")
262 App.tools.Close();
263 else
264 for (int v = 0; v < c; v++)
265 {
266 int cc = tbs.GetViewer(v).Images.Count;
267 for (int im = 0; im < cc; im++)
268 {
269 ImageView vi = tbs.GetViewer(v);
270 if (vi.Images[im].Filename == Path.GetFileName(name))
271 {
272 tbs.RemoveTab(name);
273 vi.Dispose();
274 return;
275 }
276 else if (vi.Name == name)
277 {
278 tbs.RemoveTab(name);
279 vi.Dispose();
280 return;
281 }
282 }
283 }
284
285 }
286 public static bool UseFiji
287 {
288 get
289 {
290 if (Fiji.ImageJPath.Contains("Fiji"))
291 return true;
292 else
293 return false;
294 }
295 }
296 public static void Rename(string text)
297 {
299 ImageView.SelectedImage.Rename(text);
301 //TODO v.SetTitle(ImageView.SelectedImage.Filename);
302 BioLib.Recorder.AddLine("App.Rename(\"" + text + "\");", false);
303 }
304
308 private static IEnumerable<ToolStripMenuItem> GetItems(ToolStripMenuItem item)
309 {
310 foreach (var dropDownItem in item.DropDownItems)
311 {
312 if (dropDownItem.GetType() == typeof(ToolStripMenuItem))
313 {
314 if (((ToolStripMenuItem)dropDownItem).HasDropDownItems)
315 {
316 foreach (ToolStripMenuItem subItem in GetItems((ToolStripMenuItem)dropDownItem))
317 yield return subItem;
318 }
319 yield return (ToolStripMenuItem)dropDownItem;
320 }
321 }
322 }
327 public static List<ToolStripMenuItem> GetMenuItems()
328 {
329 List<ToolStripMenuItem> allItems = new List<ToolStripMenuItem>();
330 foreach (ToolStripMenuItem toolItem in tabsView.MainMenuStrip.Items)
331 {
332 allItems.Add(toolItem);
333 allItems.AddRange(GetItems(toolItem));
334 }
335 return allItems;
336 }
341 public static List<ToolStripMenuItem> GetContextItems()
342 {
343 List<ToolStripMenuItem> allItems = new List<ToolStripMenuItem>();
344 foreach (ToolStripMenuItem toolItem in viewer.ViewContextMenu.Items)
345 {
346 allItems.Add(toolItem);
347 allItems.AddRange(GetItems(toolItem));
348 }
349 return allItems;
350 }
358 public static ToolStripItem GetMenuItemFromPath(string s, Function f)
359 {
360 if (s == "" || s == null)
361 return null;
362 string[] sts = s.Split('/');
363 start:
364 List<ToolStripMenuItem> allItems = GetMenuItems();
365 //Find path or create it.
366 bool found = false;
367 ToolStripMenuItem item = null;
368
369 for (int t = 0; t < sts.Length; t++)
370 {
371 found = false;
372 for (int i = 0; i < allItems.Count; i++)
373 {
374 if (allItems[i].Text == sts[t])
375 {
376 item = allItems[i];
377 found = true;
378 if (t == sts.Length - 1)
379 return allItems[i];
380 }
381 }
382 if (!found)
383 {
384 if (t == 0)
385 {
386 tabsView.MainMenuStrip.Items.Add(sts[t]);
387 goto start;
388 }
389 else if (t > 0 && t < sts.Length)
390 {
391 ToolStripMenuItem itm = new ToolStripMenuItem();
392 itm.Tag = f;
393 itm.Name = f.Name;
394 item.DropDownItems.Add(f.Name, null, ItemClicked);
395 return item;
396 }
397 else
398 {
399 item.DropDownItems.Add(sts[t]);
400 }
401 }
402 }
403 return item;
404 }
412 public static ToolStripItem GetContextMenuItemFromPath(string s, Function f)
413 {
414 if (s == "" || s == null)
415 return null;
416 string[] sts = s.Split('/');
417 start:
418 List<ToolStripMenuItem> allItems = GetContextItems();
419 //Find path or create it.
420 bool found = false;
421 ToolStripMenuItem item = null;
422
423 for (int t = 0; t < sts.Length; t++)
424 {
425 found = false;
426 for (int i = 0; i < allItems.Count; i++)
427 {
428 if (allItems[i].Text == sts[t])
429 {
430 item = allItems[i];
431 found = true;
432 if (t == sts.Length - 1)
433 return allItems[i];
434 }
435 }
436 if (!found)
437 {
438 if (t == 0)
439 {
440 viewer.ViewContextMenu.Items.Add(sts[t]);
441 goto start;
442 }
443 else if (t > 0 && t < sts.Length)
444 {
445 ToolStripMenuItem itm = new ToolStripMenuItem();
446 itm.Tag = f;
447 itm.Name = f.Name;
448 item.DropDownItems.Add(f.Name, null, ItemClicked);
449 return item;
450 }
451 else
452 {
453 item.DropDownItems.Add(sts[t]);
454 }
455 }
456 }
457 return item;
458 }
464 public static void AddMenu(string menu, Function f)
465 {
466 GetMenuItemFromPath(menu, f);
467 }
472 public static void AddContextMenu(string menu, Function f)
473 {
475 }
481 private static void ItemClicked(object sender, EventArgs e)
482 {
483 ToolStripMenuItem ts = (ToolStripMenuItem)sender;
484 if (ts.Text.EndsWith(".dll"))
485 {
486 Plugin.Plugins[ts.Text].Execute(new string[] { });
487 }
488 else if (ts.Text.EndsWith(".ijm"))
489 {
490 string s = File.ReadAllText(Path.GetDirectoryName(Fiji.ImageJPath) + "/macros/" + ts.Text);
492 }
493 else
494 {
495 Function f = (Function)ts.Tag;
496 f.PerformFunction(true);
497 }
498 }
502 public static void AddROI(string an)
503 {
504 Annotations.Add(BioImage.StringToROI(an));
505 Recorder.AddLine("App.AddROI(" + '"' + an + "'" + ");");
506 }
507 }
508}
System.Drawing.Image Image
Definition ImageView.cs:15
static Recorder recorder
Definition App.cs:13
static void AddContextMenu(string menu, Function f)
Definition App.cs:472
static NodeView nodeView
Definition App.cs:11
static ToolStripItem GetContextMenuItemFromPath(string s)
Definition App.cs:155
static ChannelsTool channelsTool
Definition App.cs:9
static ToolStripItem GetMenuItemFromPath(string s)
Definition App.cs:102
static Library lib
Definition App.cs:19
static void Hide()
Hide() hides all the tools.
Definition App.cs:85
static void AddMenu(string menu)
Definition App.cs:207
static Scripting runner
Definition App.cs:12
static void Initialize(bool requireImageJ=false)
Initialize() is a function that initializes the BioImage Suite Web viewer.
Definition App.cs:48
static ImageView viewer
Definition App.cs:16
static List< ToolStripMenuItem > GetMenuItems()
Retrieves all the menu items from the main menu strip.
Definition App.cs:327
static TabsView tabsView
Definition App.cs:10
static void AddROI(string an)
Definition App.cs:502
static List< Channel > Channels
Definition App.cs:38
static StackTools stackTools
Definition App.cs:15
static ROIManager manager
Definition App.cs:8
static bool Initialized
Definition App.cs:46
static void SelectWindow(string name)
Definition App.cs:220
static ToolStripItem GetMenuItemFromPath(string s, Function f)
Definition App.cs:358
static void CloseWindow(string name)
Definition App.cs:244
static Tools tools
Definition App.cs:14
static void AddMenu(string menu, Function f)
Definition App.cs:464
static BioConsole console
Definition App.cs:18
static List< string > recent
Definition App.cs:20
static List< ROI > Annotations
Definition App.cs:43
static List< ToolStripMenuItem > GetContextItems()
Definition App.cs:341
static void AddContextMenu(string menu)
Definition App.cs:215
static ToolStripItem GetContextMenuItemFromPath(string s, Function f)
Definition App.cs:412
static void Rename(string text)
Definition App.cs:296
static bool UseFiji
Definition App.cs:287
static Series seriesTool
Definition App.cs:17
static bool newTab
Definition BioConsole.cs:23
static bool useBioformats
Definition BioConsole.cs:21
static bool headless
Definition BioConsole.cs:22
static bool onTab
Definition BioConsole.cs:20
ImageView control for image stacks, pyramidal and whole-slide-images.
new void Dispose()
List< BioImage > Images
Definition ImageView.cs:359
static BioImage SelectedImage
Definition ImageView.cs:306
ContextMenuStrip ViewContextMenu
A property that returns a ContextMenuStrip object. *‍/.
Definition ImageView.cs:826
static void Initialize()
static Dictionary< string, IPlugin > Plugins
Definition Plugin.cs:17
static void AddLine(string s)
Definition Recorder.cs:6
void SetTab(string tabName)
Definition TabsView.cs:168
int GetViewerCount()
Definition TabsView.cs:240
void RemoveTab(string tabName)
Definition TabsView.cs:146
BioImage Image
Definition TabsView.cs:331
ImageView GetViewer(int i)
Definition TabsView.cs:224
void RenameTab(string tabName, string text)
Definition TabsView.cs:177