2using System.Collections.Generic;
5using System.Threading.Tasks;
6using System.Windows.Forms;
7using System.Globalization;
9using System.Diagnostics;
10using System.Threading;
11using System.Reflection;
14using Point = AForge.Point;
16using Bitmap = AForge.Bitmap;
30 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
60 private void MoveWait()
72 Recorder.
AddLine(
"Microscope.Stage.SetPosition(" + px +
"," + py +
");");
75 if(Properties.Settings.Default.PMicroscope)
80 if (Properties.Settings.Default.PycroManager)
85 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
89 else if (Properties.Settings.Default.LibPath.Contains(
"Prio"))
147 if (Properties.Settings.Default.PMicroscope)
154 if (Properties.Settings.Default.PycroManager)
161 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
167 else if (Properties.Settings.Default.LibPath.Contains(
"Prio"))
213 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
230 public void SetSWLimit(
double xmin,
double xmax,
double ymin,
double ymax)
232 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
236 new double[] {xmin,xmax,ymin,ymax}));
239 Recorder.
AddLine(
"Microscope.Focus.SetSWLimit(" + xmin +
"," + xmax +
"," + ymin +
"," + ymax +
");");
248 private static double z;
261 if (Properties.Settings.Default.PMicroscope)
267 if (Properties.Settings.Default.PycroManager)
273 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
279 else if (Properties.Settings.Default.LibPath.Contains(
"Prio"))
306 if (Properties.Settings.Default.PMicroscope)
312 else if(Properties.Settings.Default.PycroManager)
318 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
324 if (Properties.Settings.Default.LibPath.Contains(
"Prio"))
340 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
358 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
362 new double[] { xd, yd }));
367 Recorder.
AddLine(
"Microscope.Focus.SetSWLimit(" + xd +
"," + yd +
");");
378 for (
int i = 0; i < count; i++)
386 public Dictionary<string, object>
config =
new Dictionary<string, object>();
392 public string Configuration =
"";
408 return "Objective " +
Index.ToString();
416 private void MoveWait()
441 Recorder.
AddLine(
"Microscope.Objectives.SetObjective(" + index +
");");
443 if (!Properties.Settings.Default.LibPath.Contains(
"MTB") && !Properties.Settings.Default.LibPath.Contains(
"Prio") &&
Function.
Functions.ContainsKey(
"SetO" + index))
449 else if(Properties.Settings.Default.LibPath.Contains(
"MTB"))
455 else if(Properties.Settings.Default.PycroManager)
463 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
469 else if (Properties.Settings.Default.LibPath.Contains(
"Prio"))
473 else if(Properties.Settings.Default.PycroManager)
541 Console.WriteLine(e.ToString());
574 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
580 if (Properties.Settings.Default.LibPath.Contains(
"Prio"))
618 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
632 internal static int position;
650 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
681 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
712 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
750 if(Properties.Settings.Default.LibPath.Contains(
"MTB"))
756 if (Properties.Settings.Default.PMicroscope)
771 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
776 if (Properties.Settings.Default.PMicroscope)
825 public static Point3D
defaultPos =
new Point3D(30000, 30000, 23900);
826 public static object root =
null;
827 public static StringBuilder
dllVersion =
new StringBuilder();
852 folder = Properties.Settings.Default.ImagingPath;
853 if (Properties.Settings.Default.PMicroscope)
866 if (Properties.Settings.Default.PycroManager)
869 if (Properties.Settings.Default.MMConfig ==
"")
871 OpenFileDialog fl =
new OpenFileDialog();
872 fl.Filter =
"Config Files (*.cfg)|*.cfg";
873 fl.InitialDirectory = Properties.Settings.Default.AppPath;
874 MessageBox.Show(
"Micro-Manager current configuration file not set please select the current configuration.");
875 fl.Title =
"Set Current Config File (Shown in MicroManager GUI)";
876 if (fl.ShowDialog() != DialogResult.OK)
878 Properties.Settings.Default.MMConfig = fl.FileName;
890 if (Properties.Settings.Default.AppPath ==
"")
892 OpenFileDialog fl =
new OpenFileDialog();
893 MessageBox.Show(
"Imaging application path is not set. Please set executable location.");
894 fl.Title =
"Set imaging application location.";
895 if (fl.ShowDialog() != DialogResult.OK)
897 Properties.Settings.Default.AppPath = fl.FileName;
901 if (Properties.Settings.Default.LibPath ==
"")
903 OpenFileDialog fl =
new OpenFileDialog();
904 MessageBox.Show(
"Imaging library path is not set. Please set imaging library.");
905 fl.Title =
"Set imaging library location.";
906 if (fl.ShowDialog() != DialogResult.OK)
908 Properties.Settings.Default.LibPath = fl.FileName;
911 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
929 else if (Properties.Settings.Default.LibPath.Contains(
"Prio"))
935 MessageBox.Show(
"Error getting Prior SDK version (" + err.ToString() +
")");
943 MessageBox.Show(
"Error initialising Prior SDK (" + err.ToString() +
")");
952 MessageBox.Show(
"Error (" +
sessionID.ToString() +
") Creating session in SDK " +
dllVersion);
958 for (
int port = 0; port < 10; port++)
975 MessageBox.Show(
"Error (" + open.ToString() +
") connecting to stage controller ",
"",
976 MessageBoxButtons.OK, MessageBoxIcon.Error);
996 if (Properties.Settings.Default.LibPath.Contains(
"MTB"))
1018 return new Point3D(p.X, p.Y, f);
1029 Microscope.redraw =
true;
1038 Microscope.redraw =
true;
1188 private static string folder =
"";
1201 if (s ==
null && folder ==
"")
1203 FolderBrowserDialog fs =
new FolderBrowserDialog();
1204 fs.Description =
"Select Imaging Folder";
1205 if (fs.ShowDialog() != DialogResult.OK)
1213 Properties.Settings.Default.ImagingPath = fs.SelectedPath;
1214 return fs.SelectedPath;
1219 folder = Properties.Settings.Default.ImagingPath;
1229 if (!Directory.Exists(fol))
1230 Directory.CreateDirectory(fol);
1234 Properties.Settings.Default.ImagingPath = folder;
1235 Properties.Settings.Default.Save();
1248 if (Properties.Settings.Default.SimulateCamera && !Properties.Settings.Default.PMicroscope)
1253 b.Volume.Location =
new Point3D(p.X,p.Y,p.Z);
1255 b.Resolutions[0] =
new Resolution(b.SizeX, b.SizeY, b.Buffers[0].PixelFormat,view.W / b.SizeX, view.H / b.SizeY, b.PhysicalSizeZ,p.X,p.Y,p.Z);
1256 b.Volume.Location = p;
1257 b.Volume.Width = view.W;
1258 b.Volume.Height = view.H;
1260 if (folder ==
"" || folder ==
null)
1261 file = Properties.Settings.Default.ImageName + (
ImageCount++) +
".ome.tif";
1263 file = folder +
"/" + Properties.Settings.Default.ImageName + (
ImageCount++) +
".ome.tif";
1275 else if (Properties.Settings.Default.PMicroscope)
1279 if (folder ==
"" || folder ==
null)
1280 file = Properties.Settings.Default.ImageName + (
ImageCount++).ToString();
1282 file = folder +
"/" + Properties.Settings.Default.ImageName + (
ImageCount++);
1284 byte[] bts = File.ReadAllBytes(file);
1287 Enum.TryParse<
PixelFormat>(Properties.Settings.Default.PCameraFormat, out px);
1290 bf.Stats = Statistics.FromBytes(bf);
1296 Resolution res =
new Resolution(w,h,px,rec.W / bm.SizeX,rec.H / bm.SizeY,1, p.X,p.Y,p.Z);
1297 bm.Volume.Location = p;
1298 bm.Volume.Width = rec.W;
1299 bm.Volume.Height = rec.H;
1300 bm.UpdateCoords(1, 1, 1);
1301 bm.Resolutions.Add(res);
1302 for (
int c = 0; c < bf.RGBChannelsCount; c++)
1304 bm.Channels.Add(
new Channel(c, bf.BitsPerPixel, bf.RGBChannelsCount));
1311 Images.AddImage(bm);
1315 BioImage.SaveAsync(file +
".ome.tif", bm.ID,0,
true);
1316 if (bm.bitsPerPixel > 8)
1317 bm.StackThreshold(
true);
1319 bm.StackThreshold(
false);
1322 bi.Buffers.Add(bm.Buffers[0]);
1328 else if (Properties.Settings.Default.PycroManager)
1332 if (folder ==
"" || folder ==
null)
1333 file = Properties.Settings.Default.ImageName + (
ImageCount++).ToString();
1335 file = folder +
"/" + Properties.Settings.Default.ImageName + (
ImageCount++);
1342 Images.AddImage(bm);
1346 BioImage.SaveAsync(file +
".ome.tif", bm.ID,0,
true);
1350 bi.Buffers.AddRange(bm.Buffers);
1367 MessageBox.Show(
"Go to Microscope Setup to set 'TakeImage' function eg. a Button shortcut or GUI recording. Or set camera simulation on & set Camera image.",
"Function 'TakeImage' not defined.");
1379 static FileSystemWatcher watcher =
new FileSystemWatcher();
1385 watcher.Created += fileSystemWatcher1_Created;
1387 watcher.BeginInit();
1388 watcher.EnableRaisingEvents =
true;
1393 static bool imagingStack =
false;
1394 static List<BioImage> images =
new List<BioImage>();
1395 static Dictionary<int,string> locked =
new Dictionary<int, string>();
1397 static void LockWait()
1402 for (
int i = 0; i < locked.Count; i++)
1408 FileInfo fi =
new FileInfo(locked[i]);
1409 if (pr.Count == 0 && fi.Length > 0)
1414 }
while (imagingStack);
1417 private static void WaitLocking()
1419 System.Threading.Thread t =
new Thread(LockWait);
1428 private static void fileSystemWatcher1_Created(
object sender, FileSystemEventArgs e)
1430 if (!Properties.Settings.Default.PMicroscope)
1433 if (!Path.HasExtension(e.FullPath))
1449 imagingStack =
true;
1452 bi =
new BioImage(Properties.Settings.Default.ImageName);
1456 double dd = d / interval;
1457 for (
int i = 0; i < dd; i++)
1467 if (!Properties.Settings.Default.PMicroscope)
1474 }
while (bi.Buffers.Count < (
int)dd);
1477 bi.UpdateCoords(bi.Buffers.Count, 1, 1);
1478 for (
int c = 0; c < bi.Buffers[0].RGBChannelsCount; c++)
1480 bi.Channels.Add(
new Channel(c, bi.bitsPerPixel, bi.Buffers[c].RGBChannelsCount));
1489 bi.Resolutions.Add(
new Resolution(bi.SizeX, bi.SizeY, bi.Buffers[0].PixelFormat,
1491 bi.Volume =
new VolumeD(
new Point3D(bi.StageSizeX, bi.StageSizeY, bi.StageSizeZ),
new Point3D(bi.SizeX * bi.PhysicalSizeX, bi.SizeY * bi.PhysicalSizeY, bi.StageSizeZ * bi.PhysicalSizeZ));
1493 if (bi.bitsPerPixel > 8)
1494 bi.StackThreshold(
true);
1496 bi.StackThreshold(
false);
1497 Images.AddImage(bi);
1499 imagingStack =
false;
1510 public static BioImage[]
TakeTiles(
int width,
int height,
bool save =
true,
bool addToImages =
true,
bool newTab =
false)
1512 List<BioImage> ims =
new List<BioImage>();
1513 imagingStack =
false;
1514 bool leftright =
false;
1515 if (Properties.Settings.Default.PMicroscope)
1521 for (
int y = 0; y < height; y++)
1527 leftright = !leftright;
1529 for (
int x = 0; x < width - 1; x++)
1544 if(!Properties.Settings.Default.PMicroscope)
1550 }
while (images.Count < width * height);
1551 for (
int i = 0; i < images.Count; i++)
1557 imagingStack =
false;
1558 return ims.ToArray();
1585 if(Properties.Settings.Default.PMicroscope)
AForge.RectangleD RectangleD
System.Windows.Forms.Application Application
AForge.PixelFormat PixelFormat
static void SetProperty(string prop, string val)
static object GetProperty(string prop)
static Dictionary< string, Recording > Properties
static List< Process > Locking(string path)
void SetSWLimit(double xd, double yd)
double GetFocus(bool update)
static Dictionary< string, Function > Functions
void UpdateView(bool refreshImages=true)
void AddImage(BioImage im)
object PerformFunction(Function f)
override string ToString()
void SetPosition(double f)
static List< Objective > List
static void SetPosition(int i)
static int GetPosition(string shutterName)
static void SetPosition(string shutterName, int state)
static void SetPosition(Point3D p)
static bool Initialize(string config)
static void GetPosition(out PointD p, bool update)
static void GetPosition3D(out Point3D p, bool update)
static BioImage TakeImage(string name)
static Command RunCommand(Command c)
static Objectives Objectives
static BioImage[] TakeTiles(int width, int height, bool save=true, bool addToImages=true, bool newTab=false)
static void SetPosition(PointD p)
static void MoveFieldUp()
Move the field up by the height of the view.
static string GetFolder()
static StringBuilder dllVersion
static void CloseRL()
If the shutter is open, then close it.
static void SetPosition(Point3D p)
static PMicroscope pMicroscope
static void OpenRL()
If the shutter is closed, open it.
static RectangleD GetObjectiveViewRectangle()
static void CalibrateXYZ(int calibMode)
static RectangleD GetViewRectangle(bool update)
static FilterWheel RLFilterWheel
static void CloseTL()
If the shutter is open, then we close it.
static void MoveRight(double d)
static RLShutter RLShutter
static BioImage TakeImageStack(double UpperLimit, double LowerLimit, double interval)
static Point3D GetPosition()
static void MoveFieldDown()
Move the field down by one unit.
static BioImage TakeImage()
static bool ArrowKeysEnabled
static void SetFocus(double d)
static void SetFolder(string fol)
static void MoveDown(double d)
static void OpenTL()
If the shutter is closed, open it.
static void MoveFieldRight()
Move the field right by the width of the view.
static BioImage TakeImage(bool save, bool addToImages, bool newTab)
static void MoveLeft(double d)
static int GetShutterPosition(string shutter)
Gets the current position of a named shutter.
static Point3D defaultPos
static FilterWheel TLFilterWheel
static TLShutter TLShutter
static void SetShutterPosition(string shutter, int state)
Sets the current position of a named shutter.
static BioImage TakeImageStack()
static void MoveFieldLeft()
Move the field left by the width of the viewport.
static LightSource TLHalogen
static LightSource RLHalogen
static HXPShutter HXPShutter
static Objectives.Objective Objective
static void MoveUp(double d)
static void SetRL(uint tr)
static void Watcher()
the textbox, sets the watcher's path to that folder, and enables the watcher.
static void SetTL(uint tl)
static FilterWheel FilterWheel
Dictionary< string, object > config
override string ToString()
double AcquisitionExposure
void SetPosition(int index)
bool GetFilterWheelPosition(out int p)
bool TakeImage(string path)
bool GetPosition3D(out Point3D p, bool update)
bool GetPosition(out PointD p, bool update)
bool SetPosition(Point3D p)
bool GetSize(out int width, out int height)
bool SetFilterWheelPosition(int p)
const int PRIOR_OK
SDK ERROR CODES returned directly by the SDk.
static bool recordMicroscope
static void AddLine(string s)
static object GetProperty(Automation.Action.ValueType automation, string pro)
int Cmd(int session, string usertx, ref string userrx, bool displayError=true)
bool SetPosition(PointD p)
int GetNosePiecePositions()
int GetVersion(StringBuilder version)
double GetPositionY(bool update)
PointD GetPosition(bool update)
void UpdateSWLimit()
It gets the software limits of the microscope stage.
void SetPosition(double px, double py)
double GetPositionX(bool update)
void SetSWLimit(double xmin, double xmax, double ymin, double ymax)
void SetPositionY(double py)
void SetPositionX(double px)