BioGTK  5.1.1
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images.
Loading...
Searching...
No Matches
BioGTK.Function Class Reference

Public Types

enum  FunctionType {
  Key , Microscope , Objective , StoreCoordinate ,
  NextCoordinate , PreviousCoordinate , NextSnapCoordinate , PreviousSnapCoordinate ,
  Recording , Property , ImageJ , Script ,
  None
}
 
enum  ButtonState { Pressed = 0 , Released = 1 }
 

Public Member Functions

override string ToString ()
 
string Serialize ()
 
object PerformFunction (bool imagej)
 
void Save ()
 It saves the function to a file.
 

Static Public Member Functions

static Function Parse (string s)
 
static void InitializeMainMenu ()
 
static void InitializeContextMenu ()
 
static void SaveAll ()
 It saves all the functions in the Functions dictionary to a file.
 

Static Public Attributes

static Dictionary< string, FunctionFunctions = new Dictionary<string, Function>()
 

Properties

ButtonState State [get, set]
 
Gdk.Key Key [get, set]
 
Gdk.ModifierType Modifier [get, set]
 
FunctionType FuncType [get, set]
 
string File [get, set]
 
string Script [get, set]
 
string Name [get, set]
 
string MenuPath [get, set]
 
string ContextPath [get, set]
 
double Value [get, set]
 
string Microscope [get, set]
 

Member Enumeration Documentation

◆ ButtonState

Enumerator
Pressed 
Released 

◆ FunctionType

Enumerator
Key 
Microscope 
Objective 
StoreCoordinate 
NextCoordinate 
PreviousCoordinate 
NextSnapCoordinate 
PreviousSnapCoordinate 
Recording 
Property 
ImageJ 
Script 
None 

Member Function Documentation

◆ InitializeContextMenu()

static void BioGTK.Function.InitializeContextMenu ( )
inlinestatic

It reads all the files in the Functions folder, parses them into Function objects, and adds them to the Functions dictionary

626 {
627 string st = System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/Functions";
628 if (!Directory.Exists(st))
629 Directory.CreateDirectory(st);
630 string[] sts = Directory.GetFiles(st);
631 for (int i = 0; i < sts.Length; i++)
632 {
633 string fs = System.IO.File.ReadAllText(sts[i]);
634 Function f = Function.Parse(fs);
635 if (!Functions.ContainsKey(f.Name))
636 Functions.Add(f.Name, f);
637 App.AddContextMenu(f.ContextPath);
638 }
639 }
static Dictionary< string, Function > Functions
Definition Functions.cs:397

◆ InitializeMainMenu()

static void BioGTK.Function.InitializeMainMenu ( )
inlinestatic

It reads all the files in the Functions folder, parses them into Function objects, and adds them to the Functions dictionary

609 {
610 string st = System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/Functions";
611 if (!Directory.Exists(st))
612 Directory.CreateDirectory(st);
613 string[] sts = Directory.GetFiles(st);
614 for (int i = 0; i < sts.Length; i++)
615 {
616 string fs = System.IO.File.ReadAllText(sts[i]);
617 Function f = Function.Parse(fs);
618 if (!Functions.ContainsKey(f.Name))
619 Functions.Add(f.Name, f);
620 App.AddMenu(f.MenuPath);
621 }
622 }

◆ Parse()

static Function BioGTK.Function.Parse ( string  s)
inlinestatic

It converts a string to a function.

Parameters
sThe string to parse
Returns
A function object.
565 {
566 if (s == "")
567 return new Function();
568 return JsonConvert.DeserializeObject<Function>(s);
569 }

◆ PerformFunction()

object BioGTK.Function.PerformFunction ( bool  imagej)
inline

If the function type is a key, and the script is not empty, then if the imagej flag is true, set the function type to imagej, otherwise set the function type to script. If the function type is a script, run the script. If the function type is imagej, run the script on the image

Parameters
imagejboolean, whether to run the function as an ImageJ macro or not
Returns
The return value is the result of the function.
587 {
588 if (FuncType == FunctionType.Key && Script != "")
589 if (imagej)
590 {
591 FuncType = FunctionType.ImageJ;
592 }
593 else
594 FuncType = FunctionType.Script;
595 if (FuncType == Function.FunctionType.Script)
596 {
597 return Scripting.RunString(script);
598 }
599 if (FuncType == Function.FunctionType.ImageJ)
600 {
601 ImageJ.RunOnImage(script, false, BioConsole.onTab, BioConsole.useBioformats, BioConsole.resultInNewTab);
602 }
603 return null;
604 }
FunctionType
Definition Functions.cs:400
FunctionType FuncType
Definition Functions.cs:466

◆ Save()

void BioGTK.Function.Save ( )
inline

It saves the function to a file.

656 {
657 string st = System.IO.Path.GetDirectoryName(Environment.ProcessPath);
658 if (!Directory.Exists(st + "/Functions"))
659 {
660 Directory.CreateDirectory(st + "/Functions");
661 }
662 System.IO.File.WriteAllText(st + "/Functions/" + Name + ".func", Serialize());
663 }
string Name
Definition Functions.cs:496
string Serialize()
Definition Functions.cs:574

◆ SaveAll()

static void BioGTK.Function.SaveAll ( )
inlinestatic

It saves all the functions in the Functions dictionary to a file.

642 {
643 string st = System.IO.Path.GetDirectoryName(Environment.ProcessPath);
644
645 if (!Directory.Exists(st + "/Functions"))
646 {
647 Directory.CreateDirectory(st + "/Functions");
648 }
649 foreach (Function f in Functions.Values)
650 {
651 System.IO.File.WriteAllText(st + "/Functions/" + f.Name + ".func", f.Serialize());
652 }
653 }

◆ Serialize()

string BioGTK.Function.Serialize ( )
inline

It takes the current object and converts it to a JSON string.

Returns
The object is being serialized into a JSON string.
575 {
576 return JsonConvert.SerializeObject(this);
577 }

◆ ToString()

override string BioGTK.Function.ToString ( )
inline
556 {
557 return name + ", " + MenuPath;
558 }
string MenuPath
Definition Functions.cs:508

Member Data Documentation

◆ Functions

Dictionary<string, Function> BioGTK.Function.Functions = new Dictionary<string, Function>()
static

Property Documentation

◆ ContextPath

string BioGTK.Function.ContextPath
getset
520 {
521 get
522 {
523 return contextPath;
524 }
525 set
526 {
527 contextPath = value;
528 }
529 }

◆ File

string BioGTK.Function.File
getset
479 {
480 get { return file; }
481 set { file = value; }
482 }

◆ FuncType

FunctionType BioGTK.Function.FuncType
getset
466 {
467 get
468 {
469 return functionType;
470 }
471 set
472 {
473 functionType = value;
474 }
475 }

◆ Key

Gdk.Key BioGTK.Function.Key
getset
438 {
439 get
440 {
441 return key;
442 }
443 set
444 {
445 key = value;
447 }
448 }

◆ MenuPath

string BioGTK.Function.MenuPath
getset
508 {
509 get
510 {
511 return menuPath;
512 }
513 set
514 {
515 menuPath = value;
516 }
517 }

◆ Microscope

string BioGTK.Function.Microscope
getset
545 {
546 get
547 {
548 return microscope;
549 }
550 set
551 {
552 microscope = value;
553 }
554 }

◆ Modifier

Gdk.ModifierType BioGTK.Function.Modifier
getset
452 {
453 get
454 {
455 return modifier;
456 }
457 set
458 {
460 modifier = value;
461 }
462 }

◆ Name

string BioGTK.Function.Name
getset
496 {
497 get
498 {
499 return name;
500 }
501 set
502 {
503 name = value;
504 }
505 }

◆ Script

string BioGTK.Function.Script
getset
486 {
487 get { return script; }
488 set
489 {
490 script = value;
491 }
492 }

◆ State

ButtonState BioGTK.Function.State
getset
425 {
426 get
427 {
428 return buttonState;
429 }
430 set
431 {
432 buttonState = value;
433 }
434 }

◆ Value

double BioGTK.Function.Value
getset
533 {
534 get
535 {
536 return val;
537 }
538 set
539 {
540 val = value;
541 }
542 }

The documentation for this class was generated from the following file: