123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746 |
- namespace OINA.Extender.Testharness
- {
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- using OINA.Extender.Acquisition;
- using OINA.Extender.Acquisition.Ed;
- using OINA.Extender.Controls;
- using OINA.Extender.Controls.Common;
- using OINA.Extender.Controls.Image;
- using OINA.Extender.Controls.Spectrum;
- using OINA.Extender.Data;
- using OINA.Extender.Data.Ed;
- using OINA.Extender.Data.Image;
- using OINA.Extender.Processing;
- using OINA.Extender.Processing.Quant;
- using OINA.Extender.Testharness.Properties;
- using WindowsMedia = System.Windows.Media;
- /// <summary>
- /// MainForm Class
- /// </summary>
- public partial class MainForm : Form
- {
- /// <summary>
- /// List of EdSpectrum objects
- /// </summary>
- private readonly Dictionary<IEdSpectrum, AcquisitionItem> edSpectrumList = new Dictionary<IEdSpectrum, AcquisitionItem>();
- /// <summary>
- /// List of ElectronImage objects
- /// </summary>
- private readonly List<IElectronImage> electronImageList = new List<IElectronImage>();
- /// <summary>
- /// SpectrumViewer object
- /// </summary>
- private SpectrumViewer spectrumViewer;
- /// <summary>
- /// ElementCombo object for exclude element
- /// </summary>
- private ElementCombo excludeElementCombo;
- /// <summary>
- /// ElementCombo object for deconvolution element
- /// </summary>
- private ElementCombo deconvolutionElementCombo;
- /// <summary>
- /// The periodic table control
- /// </summary>
- private PeriodicTableControl periodicTableControl;
- /// <summary>
- /// imageViewer object
- /// </summary>
- private ImageViewer imageViewer;
- /// <summary>
- /// The comparison spectra
- /// </summary>
- private List<IEdSpectrum> comparisonSpectra;
- /// <summary>
- /// The periodic table control visual settings window
- /// </summary>
- private Form periodicTableVisualSettings;
- /// <summary>
- /// The element combo control visual settings window
- /// </summary>
- private Form elementComboVisualSettings;
- /// <summary>
- /// The spectrum viewer control visual settings window
- /// </summary>
- private Form spectrumViewerVisualSettings;
- /// <summary>
- /// The image viewer control visual settings window
- /// </summary>
- private Form imageViewVisualSettingsForm;
- /// <summary>
- /// The brightness/contrast dialog visual settings window
- /// </summary>
- private Form brightnessContrastDialogVisualSettings;
- /// <summary>
- /// The details dialog visual settings window
- /// </summary>
- private Form detailsDialogVisualSettingsForm;
- /// <summary>
- /// MainForm Constructor
- /// </summary>
- public MainForm()
- {
- this.InitializeComponent();
- this.LoadComparisonSpectra();
- this.cbCompareColor.DataSource = Enum.GetValues(typeof(KnownColor));
- this.imageToolComboBox.DataSource = Enum.GetValues(typeof(ImageInteractionTool));
- this.spectrumInteractionToolComboBox.DataSource = Enum.GetValues(typeof(InteractionTool));
- // Binding spectrum acquisition controller events
- OIHelper.EdSpectrumAcquisitionController.ExperimentStarted += this.OnEdSpectrumExperimentStarted;
- OIHelper.EdSpectrumAcquisitionController.ExperimentFinished += this.OnEdSpectrumExperimentFinished;
- // Binding image acquisition controller events
- OIHelper.ImageAcquisitionController.ExperimentStarted += this.OnImageExperimentStarted;
- OIHelper.ImageAcquisitionController.ExperimentFinished += this.OnImageExperimentFinished;
- // Initial UI contents
- this.InitialSpectrumViewerElementHost();
- this.InitialImageViewerElementHost();
- this.InitialPeriodicTableElementHost();
- this.InitialSpectrumSettingsContent();
- this.InitialImageSettingsContent();
- this.InitialTimers();
- this.InitialProcessingSettingsContent();
- this.InitializeEnabledElementsMenuItems();
- this.cbCompareColor.SelectedItem = GetRandomColor();
- this.spectrumInteractionToolComboBox.SelectedItem = this.spectrumViewer.InteractionTool;
- this.UpdateHighlightedElementInTable();
- }
- /// <summary>
- /// Gets the random color.
- /// </summary>
- /// <returns>A random color</returns>
- private static KnownColor GetRandomColor()
- {
- Random randomGen = new Random();
- KnownColor[] colors = Enum.GetValues(typeof(KnownColor)) as KnownColor[];
- int index = randomGen.Next(colors.Length);
- return colors[index];
- }
- /// <summary>
- /// Gets a value indicating whether this instance is acquiring.
- /// </summary>
- /// <value>
- /// <c>true</c> if this instance is acquiring; otherwise, <c>false</c>.
- /// </value>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "n/a")]
- private bool IsAcquiring
- {
- get { return OIHelper.EdSpectrumAcquisitionController.IsAcquiring; }
- }
- #region Status Event Handlers
- /// <summary>
- /// OnAcquisitionStatusTimerTicked
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EvenArgs</param>
- private void OnAcquisitionStatusTimerTicked(object sender, EventArgs e)
- {
- if (OIHelper.EdSpectrumAcquisitionController.IsAcquiring || OIHelper.ImageAcquisitionController.IsAcquiring)
- {
- this.lblAcquisitionStatus.Visible = !this.lblAcquisitionStatus.Visible;
- }
- else
- {
- this.lblAcquisitionStatus.Visible = false;
- }
- }
- /// <summary>
- /// OnIdentifyTimerTicked
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void OnIdentifyTimerTicked(object sender, EventArgs e)
- {
- this.DoAutoID();
- }
- /// <summary>
- /// Called when [ed spectrum experiment started].
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The <see cref="AcquisitionFinishedEventArgs{IEdSpectrum}"/> instance containing the event data.</param>
- private void OnEdSpectrumExperimentStarted(object sender, AcquisitionStartedEventArgs<IEdSpectrum> e)
- {
- var edSpectrum = e.Value;
- // execute on UI thread
- this.BeginInvoke((Action)delegate
- {
- this.spectrumViewer.Spectrum = edSpectrum;
- // Clear periodic table included and excluded elements
- this.periodicTableControl.ClearAll();
- // Update Known Elements
- this.periodicTableControl.IncludeElements(OIHelper.AutoIdSettings.KnownElements.ToArray());
- this.tmrIdentifyElements.Tick += this.OnIdentifyTimerTicked;
- this.tmrIdentifyElements.Enabled = true;
- });
- edSpectrum.PropertyChanged += this.OnPropertyChanged;
- }
- /// <summary>
- /// Called when [image experiment started].
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The instance containing the event data.</param>
- private void OnImageExperimentStarted(object sender, AcquisitionStartedEventArgs<IElectronImage[]> e)
- {
- // execute on UI thread
- this.BeginInvoke((Action)delegate
- {
- this.imageViewer.DisplayImage = e.Value[0];
- });
- }
- /// <summary>
- /// OnExperimentFinished
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">The instance containing the event data.</param>
- private void OnEdSpectrumExperimentFinished(object sender, AcquisitionFinishedEventArgs<IEdSpectrum> e)
- {
- e.Value.PropertyChanged -= this.OnPropertyChanged;
- this.tmrIdentifyElements.Tick -= this.OnIdentifyTimerTicked;
- this.tmrIdentifyElements.Enabled = false;
- // execute on UI thread
- this.BeginInvoke((Action)delegate
- {
- this.DoAutoID();
- this.UpdatePeriodicTable();
- this.DoQuant();
- if (this.edSpectrumList.ContainsKey(e.Value))
- {
- this.AcquisitionQueueListBox.Items.Remove(this.edSpectrumList[e.Value]);
- this.edSpectrumList.Remove(e.Value);
- }
- // *** If this is the last experiment, call EndMultipleAcquisition on the Acquisition
- // *** controller, to re-enable external scan switching
- if (!this.edSpectrumList.Any())
- {
- OIHelper.EdSpectrumAcquisitionController.EndMultipleAcquisition();
- }
- });
- }
- /// <summary>
- /// Called when [image experiment finished].
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The instance containing the event data.</param>
- private void OnImageExperimentFinished(object sender, AcquisitionFinishedEventArgs<IElectronImage[]> e)
- {
- // execute on UI thread
- this.BeginInvoke((Action)delegate
- {
- e.Value.ToList().ForEach(i =>
- {
- this.electronImageList.Remove(i);
- this.ImageAcquisitionQueueListBox.Items.Remove(i);
- });
- });
- }
- /// <summary>
- /// OnPropertyChanged
- /// </summary>
- /// <param name="sender">Event source</param>
- /// <param name="e">Event arguments</param>
- private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- var edSpectrum = sender as IEdSpectrum;
- switch (e.PropertyName)
- {
- case "RealTimeSeconds":
- this.Invoke((MethodInvoker)delegate
- {
- this.textRealTimeSeconds.Text = edSpectrum.RealTimeSeconds.ToString(@"0.000", CultureInfo.InvariantCulture);
- });
- break;
- case "LiveTimeSeconds":
- this.Invoke((MethodInvoker)delegate
- {
- this.textLiveTimeSeconds.Text = edSpectrum.LiveTimeSeconds.ToString(@"0.000", CultureInfo.InvariantCulture);
- });
- break;
- case "OutputRate":
- this.Invoke((MethodInvoker)delegate
- {
- this.outputStatus.Text = OIHelper.MonitoringController.EdStatus.Values.Sum(status => status.OutputRate).ToString(CultureInfo.InvariantCulture) + @"cps";
- });
- break;
- case "DeadTime":
- this.Invoke((MethodInvoker)delegate
- {
- this.deadtimeStatus.Text = OIHelper.MonitoringController.EdStatus.Values.Max(status => status.DeadTime).ToString(CultureInfo.InvariantCulture) + @"%";
- });
- break;
- }
- }
- #endregion
- #region Update UI status
- /// <summary>
- /// InitialSpectrumSettingsContent
- /// </summary>
- private void InitialSpectrumSettingsContent()
- {
- if (OIHelper.EdSpectrumSettings.EdCapabilities.HasHardwareConnection)
- {
- this.textSpectrumLabel.Text = @"Spectrum 1";
- this.cbAcquisitionMode.Items.Add(EdAcquireMode.LiveTime);
- this.cbAcquisitionMode.Items.Add(EdAcquireMode.RealTime);
- this.cbAcquisitionMode.SelectedIndex = 0;
- this.AcquisitionTimeNumericUpDown.Value = 10;
- this.cbProcessTime.DataSource = OIHelper.EdSpectrumSettings.EdCapabilities.AllowedProcessTimes;
- this.cbProcessTime.SelectedIndex = 3;
- this.cbEnergyRange.DataSource = OIHelper.EdSpectrumSettings.EdCapabilities.AllowedEnergyRanges;
- this.cbEnergyRange.SelectedIndex = 1;
- this.cbChannelNumber.DataSource = OIHelper.EdSpectrumSettings.EdCapabilities.AllowedNumberOfChannels;
- this.cbChannelNumber.SelectedIndex = 1;
- }
- }
- /// <summary>
- /// InitialImageSettingsContent
- /// </summary>
- private void InitialImageSettingsContent()
- {
- var settings = OIHelper.ImageSettings;
- if (settings.ImageCapabilities.HasHardwareConnection)
- {
- this.cbImageScanSize.DataSource = OIHelper.GetScanSizes(
- settings.ScanCapabilities.MinimumPixelSize,
- settings.ScanCapabilities.MaximumPixelSize);
- this.cbImageScanSize.SelectedIndex = this.cbImageScanSize.Items.Count > 4 ? 4 : this.cbImageScanSize.Items.Count - 1;
- this.cbInputSignal.DataSource = settings.ImageCapabilities.AllowedInputSources;
- this.cbInputSignal.SelectedIndex = 0;
- this.tbNumberOfFrames.Text = @"1";
- this.tbDwellTime.Text = @"40";
- }
- }
- /// <summary>
- /// Initial Timers
- /// </summary>
- private void InitialTimers()
- {
- this.tmrAcquisitionStatus.Enabled = true;
- this.tmrAcquisitionStatus.Interval = 1000;
- this.tmrAcquisitionStatus.Tick += this.OnAcquisitionStatusTimerTicked;
- this.tmrIdentifyElements.Enabled = false;
- this.tmrIdentifyElements.Interval = 1000;
- }
- /// <summary>
- /// InitialProcessingSettingsContent
- /// </summary>
- private void InitialProcessingSettingsContent()
- {
- this.rbAllElements.Checked = true;
- this.tbCombinedElement.Enabled = false;
- this.tbCombinedElement.Text = @"8";
- this.tbNumberOfIons.Enabled = false;
- this.tbNumberOfIons.Text = @"3.0";
- this.deconvolutionElementCombo = new ElementCombo();
- this.ehDeconvolutionElement.Child = this.deconvolutionElementCombo;
- this.deconvolutionElementCombo.DisplayFormat = ElementComboDisplayFormat.ShowSymbol;
- foreach (int i in OIHelper.SEMQuantSettings.DeconvolutionElements)
- {
- this.tbDeconvolutionElementList.Text += i.ToString(CultureInfo.InvariantCulture) + System.Environment.NewLine;
- }
- this.cbThresholding.Checked = false;
- this.tbSigmaLevel.Enabled = false;
- this.tbSigmaLevel.Text = @"3.0";
- this.cbIsCoated.Checked = OIHelper.SEMQuantSettings.SampleCoating.IsCoated;
- this.tbCoatingElement.Enabled = OIHelper.SEMQuantSettings.SampleCoating.IsCoated;
- this.tbCoatingElement.Text = OIHelper.SEMQuantSettings.SampleCoating.CoatingElement.ToString(CultureInfo.InvariantCulture);
- this.tbDensity.Enabled = OIHelper.SEMQuantSettings.SampleCoating.IsCoated;
- this.tbDensity.Text = OIHelper.SEMQuantSettings.SampleCoating.Density.ToString(CultureInfo.InvariantCulture);
- this.tbThickness.Enabled = OIHelper.SEMQuantSettings.SampleCoating.IsCoated;
- this.tbThickness.Text = OIHelper.SEMQuantSettings.SampleCoating.Thickness.ToString(CultureInfo.InvariantCulture);
- this.excludeElementCombo = new ElementCombo();
- this.ehExcludeElement.Child = this.excludeElementCombo;
- this.excludeElementCombo.DisplayFormat = ElementComboDisplayFormat.ShowName;
- this.excludeElementCombo.PropertyChanged += this.ExcludeElementCombo_PropertyChanged;
- this.UpdateElementsList(this.periodicTableControl.ExcludedElements, this.tbExcludedElementList);
- this.UpdateElementsList(this.periodicTableControl.IncludedElements, this.tbIncludedElementList);
- this.UpdateElementsList(this.periodicTableControl.UnsetElements, this.tbUnsetElementList);
- }
- /// <summary>
- /// InitialSpectrumViewerElementHost
- /// </summary>
- private void InitialSpectrumViewerElementHost()
- {
- this.spectrumViewer = new SpectrumViewer();
- this.ehSpectrumViewer.Child = this.spectrumViewer;
- this.spectrumViewer.IsXAxisAutoScaleEnabled = false;
- this.spectrumViewer.IsYAxisAutoScaleEnabled = true;
- }
- /// <summary>
- /// InitialImageViewerElementHost
- /// </summary>
- private void InitialImageViewerElementHost()
- {
- this.imageViewer = new ImageViewer();
- this.ehImageViewer.Child = this.imageViewer;
- }
- /// <summary>
- /// Initials the periodic table element host.
- /// </summary>
- private void InitialPeriodicTableElementHost()
- {
- this.periodicTableControl = new PeriodicTableControl();
- this.periodicTableElementHost.Child = this.periodicTableControl;
- // Set the Periodic Table BackColor (0xFF07366B) same as Spectrum Viewer
- this.periodicTableElementHost.BackColor = Color.FromArgb(255, 7, 54, 107);
- foreach (object knownColor in Enum.GetValues(typeof(System.Drawing.KnownColor)))
- {
- this.periodicTableBackgroundToolStripComboBox.Items.Add(knownColor);
- }
- ((INotifyCollectionChanged)this.periodicTableControl.ExcludedElements).CollectionChanged += this.PeriodicTableExcludedElements_CollectionChanged;
- ((INotifyCollectionChanged)this.periodicTableControl.IncludedElements).CollectionChanged += this.PeriodicTableIncludedElements_CollectionChanged;
- ((INotifyCollectionChanged)this.periodicTableControl.UnsetElements).CollectionChanged += this.PeriodicTableUnsetElements_CollectionChanged;
- }
- /// <summary>
- /// Update the Periodic Table content after acquisition finished
- /// </summary>
- private void UpdatePeriodicTable()
- {
- this.periodicTableControl.IncludeElements(this.spectrumViewer.Spectrum.IdentifiedElements.ToArray());
- }
- /// <summary>
- /// Updates the elements list.
- /// </summary>
- /// <param name="data">The data.</param>
- /// <param name="list">The list.</param>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Ignore")]
- private void UpdateElementsList(IEnumerable<int> data, TextBox list)
- {
- list.Clear();
- foreach (int i in data.OrderBy(x => x).ToArray<int>())
- {
- list.Text += ElementProperties.GetElementName(i) + System.Environment.NewLine;
- }
- }
- #endregion
- #region Control acquisition from UI
- /// <summary>
- /// StartAcquisition button click handler
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void StartAcquisitionButton_Click(object sender, EventArgs e)
- {
- this.spectrumViewer.ClearComparisonSpectra();
- this.AcquireSpectrum(false);
- }
- /// <summary>
- /// ResumeAcquisition button click handler
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void ResumeAcquisitionButton_Click(object sender, EventArgs e)
- {
- if (this.spectrumViewer.Spectrum != null && !this.IsAcquiring)
- {
- this.AcquireSpectrum(true);
- }
- }
- /// <summary>
- /// Start Acquire Spectrum Process
- /// </summary>
- /// <param name="isResume">true if is resume</param>
- private void AcquireSpectrum(bool isResume)
- {
- IEdSpectrum edSpectrum = null;
- // Spectrum acquisition settings confirm
- var edSpectrumSettings = OIHelper.EdSpectrumSettings;
- var edSpectrumAcquisitionController = OIHelper.EdSpectrumAcquisitionController;
- edSpectrumSettings.EdSettings.AcquisitionMode = (EdAcquireMode)this.cbAcquisitionMode.SelectedItem;
- edSpectrumSettings.EdSettings.AcquisitionTime = TimeSpan.FromSeconds((int)this.AcquisitionTimeNumericUpDown.Value);
- edSpectrumSettings.EdSettings.ProcessTime = (int)this.cbProcessTime.SelectedValue;
- edSpectrumSettings.EdSettings.EnergyRange = (int)this.cbEnergyRange.SelectedValue;
- edSpectrumSettings.EdSettings.NumberOfChannels = (int)this.cbChannelNumber.SelectedValue;
- edSpectrumSettings.ScanSettings.AcquisitionRegion.CreateMicroscopeRegion();
- // SpectrumViewer settings confirm
- this.spectrumViewer.MaximumEnergy = edSpectrumSettings.EdSettings.EnergyRange;
- // If Ed hardware is not ready, the software will crash.
- if (edSpectrumAcquisitionController.IsEdHardwareReady(edSpectrumSettings))
- {
- // *** If this is the first acquisition, call BeginMultipleAcquisition
- // *** on the AcquisitionController to suppress external scan switching
- if (!this.edSpectrumList.Any())
- {
- edSpectrumAcquisitionController.BeginMultipleAcquisition();
- }
- if (!isResume)
- {
- // Start spectrum acquisition
- try
- {
- edSpectrum = edSpectrumAcquisitionController.StartAcquisition(edSpectrumSettings);
- edSpectrum.Label = string.Format(CultureInfo.CurrentCulture, @"{0} ({1:HH:mm:ss})", this.textSpectrumLabel.Text, DateTime.Now);
- this.edSpectrumList.Add(edSpectrum, new AcquisitionItem(edSpectrum, OIHelper.EdSpectrumSettings.EdSettings.AcquisitionMode, OIHelper.EdSpectrumSettings.EdSettings.AcquisitionTime.TotalMilliseconds, this.AcquisitionQueueListBox));
- this.AcquisitionQueueListBox.Items.Add(this.edSpectrumList[edSpectrum]);
- }
- catch (InvalidSettingsException invalidSettingsException)
- {
- MessageBox.Show(invalidSettingsException.Message, Resources.CannotStartAcquisitionTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
- }
- catch (AcquisitionStartException acquisitionStartException)
- {
- MessageBox.Show(acquisitionStartException.Message, Resources.CannotStartAcquisitionTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
- }
- }
- else
- {
- edSpectrum = this.spectrumViewer.Spectrum;
- edSpectrumAcquisitionController.ResumeAcquisition(edSpectrumSettings, edSpectrum);
- this.edSpectrumList.Add(edSpectrum, new AcquisitionItem(edSpectrum, OIHelper.EdSpectrumSettings.EdSettings.AcquisitionMode, OIHelper.EdSpectrumSettings.EdSettings.AcquisitionTime.TotalMilliseconds, this.AcquisitionQueueListBox));
- this.AcquisitionQueueListBox.Items.Add(this.edSpectrumList[edSpectrum]);
- }
- }
- }
- /// <summary>
- /// StopAcquisition button click handler
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void StopAcquisitionButton_Click(object sender, EventArgs e)
- {
- if (OIHelper.EdSpectrumAcquisitionController.IsAcquiring == true)
- {
- OIHelper.EdSpectrumAcquisitionController.StopAcquisition();
- }
- }
- /// <summary>
- /// Handles the Click event of Calculate button.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void CalculateButton_Click(object sender, EventArgs e)
- {
- try
- {
- int atomicNum = ElementProperties.GetAtomicNumberByElementSymbol(this.tbIdentifiedElement.SelectedText);
- var peakParameters = OIHelper.EdSpectrumProcessing.CalculatePeakParameters(this.spectrumViewer.Spectrum, atomicNum);
- this.tbEnergy.Text = peakParameters.Centre.ToString(CultureInfo.InvariantCulture);
- this.tbFWHM.Text = peakParameters.FWHM.ToString(CultureInfo.InvariantCulture);
- }
- catch (NullReferenceException)
- {
- }
- catch (FormatException)
- {
- }
- catch (InvalidOperationException)
- {
- }
- }
- /// <summary>
- /// Handles the Click event of StartImageScan button.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void StartImageScanButton_Click(object sender, EventArgs e)
- {
- var imageSettings = OIHelper.ImageSettings.ImageSettings;
- var imageCapabilities = OIHelper.ImageSettings.ImageCapabilities;
- var scanSettings = OIHelper.ImageSettings.ScanSettings;
- var imageAcquisitionController = OIHelper.ImageAcquisitionController;
- this.tbImageData.Text = string.Empty;
- this.tbPointX.Text = string.Empty;
- this.tbPointY.Text = string.Empty;
- var value = int.Parse(this.tbDwellTime.Text, CultureInfo.InvariantCulture);
- if (value > imageCapabilities.MaximumImageDwellMicroseconds)
- {
- imageSettings.DwellTimeMicroSeconds = imageCapabilities.MaximumImageDwellMicroseconds;
- }
- if (value < imageCapabilities.MinimumImageDwellMicroseconds)
- {
- imageSettings.DwellTimeMicroSeconds = imageCapabilities.MinimumImageDwellMicroseconds;
- }
- else
- {
- imageSettings.DwellTimeMicroSeconds = value;
- }
- // *** Disable all input sources before enabling the one that the user has chosen
- imageSettings.InputSources.ToList().ForEach(i => imageSettings.EnableInputSource(i.Key, false));
- imageSettings.EnableInputSource((ImageInputSources)this.cbInputSignal.SelectedItem, true);
- scanSettings.FrameCount = int.Parse(this.tbNumberOfFrames.Text, CultureInfo.InvariantCulture);
- var pixelSize = 1d / double.Parse(this.cbImageScanSize.Text, CultureInfo.InvariantCulture);
- scanSettings.AcquisitionRegion.CreateFullFieldRegion(pixelSize);
- try
- {
- var images = imageAcquisitionController.StartAcquisition(OIHelper.ImageSettings).ToList();
- images.ForEach(i =>
- {
- i.Label = string.Format(CultureInfo.CurrentCulture, @"{0} ({1:HH:mm:ss})", @"ElectronImage", DateTime.Now);
- this.electronImageList.Add(i);
- this.ImageAcquisitionQueueListBox.Items.Add(i);
- });
- }
- catch (InvalidSettingsException exception)
- {
- var sb = new StringBuilder(@"Invalid settings have been supplied:");
- sb.AppendLine();
- exception.ValidationResults.ValidationErrors
- .ToList()
- .ForEach(ve => sb.AppendFormat(CultureInfo.CurrentCulture, @"{0} {1}", Environment.NewLine, ve));
- MessageBox.Show(sb.ToString(), @"Invalid settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- }
- /// <summary>
- /// Handles the Click event of StopImageScan button.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void StopImageScanButton_Click(object sender, EventArgs e)
- {
- if (OIHelper.ImageAcquisitionController.IsAcquiring)
- {
- OIHelper.ImageAcquisitionController.StopAcquisition();
- }
- }
- /// <summary>
- /// Handles the Click event of GetPixelData button.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void GetPixelDataButton_Click(object sender, EventArgs e)
- {
- if ((!OIHelper.ImageAcquisitionController.IsAcquiring) & (this.imageViewer.DisplayImage != null))
- {
- var electronImage = this.imageViewer.DisplayImage as IElectronImage;
- if (electronImage != null)
- {
- try
- {
- int x = int.Parse(this.tbPointX.Text, CultureInfo.InvariantCulture);
- int y = int.Parse(this.tbPointY.Text, CultureInfo.InvariantCulture);
- var stringBuilder = new StringBuilder();
- stringBuilder.AppendFormat(CultureInfo.CurrentCulture, @" Point({0},{1}), Value: {2}", x, y, electronImage.GetData(new Point(x, y)));
- stringBuilder.Append(Environment.NewLine);
- this.tbImageData.Text = stringBuilder.ToString();
- }
- catch (ArgumentOutOfRangeException)
- {
- //// stringBuilder - The length of the expanded string would exceed MaxCapacity.
- }
- catch (FormatException)
- {
- //// int.Parse - The x or y coordinates are not in the correct format.
- }
- }
- }
- }
- #endregion
- #region ToolStripMenuItem handlers
- /// <summary>
- /// Handles the Click event of the elementComboVisualSettingsToolStripMenuItem control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">instance containing the event data.</param>
- private void ExportSpectrumAsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- string filter = @"Bitmap (*.bmp)|*.bmp|PNG (*.png)|*.png|TIFF (*.tif)|*.tif|JPEG (*.jpg)|*.jpg";
- string title = @"Export Spectrum As...";
- try
- {
- short width = (short)this.spectrumViewer.ActualWidth;
- short height = (short)this.spectrumViewer.ActualHeight;
- Bitmap bitmap = OIHelper.EdSpectrumProcessing.CreateBitmap(this.spectrumViewer.Spectrum, width, height);
- using (SaveFileDialog exportSpectrumDialog = new SaveFileDialog())
- {
- exportSpectrumDialog.Filter = filter;
- exportSpectrumDialog.Title = title;
- exportSpectrumDialog.FilterIndex = 1;
- if (exportSpectrumDialog.ShowDialog() == DialogResult.OK)
- {
- switch (exportSpectrumDialog.FilterIndex)
- {
- case 1:
- bitmap.Save(exportSpectrumDialog.FileName, ImageFormat.Bmp);
- break;
- case 2:
- bitmap.Save(exportSpectrumDialog.FileName, ImageFormat.Png);
- break;
- case 3:
- bitmap.Save(exportSpectrumDialog.FileName, ImageFormat.Tiff);
- break;
- case 4:
- bitmap.Save(exportSpectrumDialog.FileName, ImageFormat.Jpeg);
- break;
- default:
- bitmap.Save(exportSpectrumDialog.FileName, ImageFormat.Bmp);
- break;
- }
- }
- }
- }
- catch (ArgumentException)
- {
- }
- }
- /// <summary>
- /// ExitToolStripMenuItem click handler
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- /// <summary>
- /// Detector Control Tool strip menu item click handler
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void DetectorControlToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Form detectorControlPanel = new DetectorControlPanel(OIHelper.EdDetectorControl);
- detectorControlPanel.Show();
- }
- /// <summary>
- /// Microscope Control Tool strip menu item click handler
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void MicroscopeControlToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Form microscopeControlPanel = new MicroscopeControlPanel();
- microscopeControlPanel.Show();
- }
- /// <summary>
- /// Calibrate ToolStrip MenuItem Click event handler.
- /// </summary>
- /// <param name="sender">sender</param>
- /// <param name="e">e</param>
- private void CalibrateToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Form calibrate = new Calibrate();
- calibrate.Show();
- }
- /// <summary>
- /// Auto Id Settings Form
- /// </summary>
- /// <param name="sender">sender</param>
- /// <param name="e">EventArgs</param>
- private void AutoIdSettingsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Form autoIDSettings = new AutoIdSettings();
- autoIDSettings.Show();
- }
- /// <summary>
- /// Handles the Click event of the periodicTableVisualSettingsToolStripMenuItem control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void PeriodicTableVisualSettingsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (this.periodicTableVisualSettings == null || this.periodicTableVisualSettings.IsDisposed)
- {
- this.periodicTableVisualSettings = new PeriodicTableVisualSettings();
- }
- this.periodicTableVisualSettings.Show();
- this.periodicTableVisualSettings.BringToFront();
- }
- /// <summary>
- /// Handles the Click event of the elementComboVisualSettingsToolStripMenuItem control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void ElementComboVisualSettingsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (this.elementComboVisualSettings == null || this.elementComboVisualSettings.IsDisposed)
- {
- this.elementComboVisualSettings = new ElementComboVisualSettings();
- }
- this.elementComboVisualSettings.Show();
- this.elementComboVisualSettings.BringToFront();
- }
- /// <summary>
- /// Handles the Click event of the SpectrumViewerVisualSettingsToolStripMenuItem control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void SpectrumViewerVisualSettingsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (this.spectrumViewerVisualSettings == null || this.spectrumViewerVisualSettings.IsDisposed)
- {
- this.spectrumViewerVisualSettings = new SpectrumViewerVisualSettings();
- }
- this.spectrumViewerVisualSettings.Show();
- this.spectrumViewerVisualSettings.BringToFront();
- }
- /// <summary>
- /// Handles the Click event of the ImageViewerVisualSetting control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void ImageViewerVisualSetting_Click(object sender, EventArgs e)
- {
- if (this.imageViewVisualSettingsForm == null || this.imageViewVisualSettingsForm.IsDisposed)
- {
- this.imageViewVisualSettingsForm = new ImageViewerVisualSettings();
- }
- this.imageViewVisualSettingsForm.Show();
- this.imageViewVisualSettingsForm.BringToFront();
- }
- /// <summary>
- /// Handles the Click event of the BrightnessContractDialogVisualSettingsToolStripMenuItem control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void BrightnessContractDialogVisualSettingsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (this.brightnessContrastDialogVisualSettings == null || this.brightnessContrastDialogVisualSettings.IsDisposed)
- {
- this.brightnessContrastDialogVisualSettings = new BCDialogVisualSettings();
- }
- this.brightnessContrastDialogVisualSettings.Show();
- this.brightnessContrastDialogVisualSettings.BringToFront();
- }
- /// <summary>
- /// Called when [details visual settings menu item click].
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void OnDetailsVisualSettingsMenuItemClick(object sender, EventArgs e)
- {
- if (this.detailsDialogVisualSettingsForm == null || this.detailsDialogVisualSettingsForm.IsDisposed)
- {
- this.detailsDialogVisualSettingsForm = new DetailDialogVisualSettings();
- }
- this.detailsDialogVisualSettingsForm.Show();
- this.detailsDialogVisualSettingsForm.BringToFront();
- }
- /// <summary>
- /// Handles the Click event of the LoadSpectrumDataToolStripMenuItem_Click.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void LoadSpectrumDataToolStripMenuItem_Click(object sender, EventArgs e)
- {
- try
- {
- using (var of_dlg = new OpenFileDialog())
- {
- of_dlg.Title = @"Select a file";
- of_dlg.Filter = @"Esd(*.esd)|*.esd|Iex(*.iex)|*.iex";
- of_dlg.FilterIndex = 1;
- if (of_dlg.ShowDialog() == DialogResult.OK)
- {
- if (!File.Exists(of_dlg.FileName))
- {
- throw new InvalidOperationException("File does not exists!");
- }
- this.spectrumViewer.ClearComparisonSpectra();
- switch (of_dlg.FilterIndex)
- {
- case 1:
- this.spectrumViewer.Spectrum = DataFactory.LoadEdSpectrum(OIHelper.FileToByteArray(of_dlg.FileName));
- break;
- case 2:
- this.spectrumViewer.Spectrum = DataFactory.LoadEdSpectrumFromIex(of_dlg.FileName);
- break;
- }
- // Set Periodic Table control element state
- this.periodicTableControl.ClearAll();
- this.periodicTableControl.IncludeElements(this.spectrumViewer.Spectrum.IdentifiedElements.ToArray());
- }
- }
- }
- catch (SerializationException)
- {
- }
- }
- /// <summary>
- /// SaveSpectrumDataToolStripMenuItem_Click
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void SaveSpectrumDataToolStripMenuItem_Click(object sender, EventArgs e)
- {
- string filter = @"Esd(*.esd)|*.esd|Iex(*.iex)|*.iex";
- string title = @"Save spectrum as";
- var spectrum = this.spectrumViewer.Spectrum;
- if (spectrum != null)
- {
- try
- {
- using (var dialog = new SaveFileDialog())
- {
- dialog.Filter = filter;
- dialog.Title = title;
- dialog.FilterIndex = 1;
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- switch (dialog.FilterIndex)
- {
- case 1:
- byte[] spectrumData = spectrum.Save();
- OIHelper.ByteArrayToFile(dialog.FileName, spectrumData);
- break;
- case 2:
- OIHelper.EdSpectrumProcessing.CreateIexSpectrum(dialog.FileName, spectrum);
- break;
- default:
- break;
- }
- }
- }
- }
- catch (ArgumentException)
- {
- }
- }
- }
- /// <summary>
- /// Handles the Click event of the LoadImageDataToolStripMenuItem_Click.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void LoadImageDataToolStripMenuItem_Click(object sender, EventArgs e)
- {
- try
- {
- using (OpenFileDialog dialog = new OpenFileDialog())
- {
- dialog.Title = @"Select a file";
- dialog.Filter = @"Img(*.img)|*.img";
- dialog.FilterIndex = 1;
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- this.imageViewer.DisplayImage = null;
- if (!File.Exists(dialog.FileName))
- {
- throw new System.InvalidOperationException("File does not exists!");
- }
- this.imageViewer.DisplayImage = DataFactory.LoadElectronImage(OIHelper.FileToByteArray(dialog.FileName));
- }
- }
- }
- catch (SerializationException)
- {
- }
- }
- /// <summary>
- /// SaveImageDataToolStripMenuItem_Click
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void SaveImageDataToolStripMenuItem_Click(object sender, EventArgs e)
- {
- string filter = @"Img(*.img)|*.img";
- string title = @"Save image as";
- if (this.imageViewer.DisplayImage != null)
- {
- try
- {
- var electronImage = this.imageViewer.DisplayImage;
- using (SaveFileDialog dialog = new SaveFileDialog())
- {
- dialog.Filter = filter;
- dialog.Title = title;
- dialog.FilterIndex = 1;
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- byte[] imageData = electronImage.Save();
- OIHelper.ByteArrayToFile(dialog.FileName, imageData);
- }
- }
- }
- catch (ArgumentException)
- {
- }
- }
- }
- /// <summary>
- /// EDMapAcquisitionToolStripMenuItem_Click
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">instance containing the event data.</param>
- private void EDMapAcquisitionToolStripMenuItem_Click(object sender, EventArgs e)
- {
- #if ENABLE_MAP_ACQUIRE
- EdMapAcquisition edMapAcquisition = new EdMapAcquisition();
- edMapAcquisition.Show();
- #endif
- }
- #endregion
- #region Control Spectrum Processing
- #region Control AutoID
- /// <summary>
- /// Add element to excluded list
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void AddExcludeButton_Click(object sender, EventArgs e)
- {
- int element = this.excludeElementCombo.CurrentElement;
- try
- {
- this.periodicTableControl.ExcludeElements(element);
- }
- catch (FormatException fe)
- {
- this.tbExcludedElementList.Text = fe.Message;
- }
- }
- /// <summary>
- /// Remove element from excluded list
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void DeleteExcludeButton_Click(object sender, EventArgs e)
- {
- int element = this.excludeElementCombo.CurrentElement;
- try
- {
- this.periodicTableControl.Clear(element);
- }
- catch (FormatException fe)
- {
- this.tbExcludedElementList.Text = fe.Message;
- }
- }
- /// <summary>
- /// Do AutoID Button Click Handler
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void DoAutoIDButton_Click(object sender, EventArgs e)
- {
- this.DoAutoID();
- }
- /// <summary>
- /// Do AutoID
- /// </summary>
- private void DoAutoID()
- {
- var spectrum = this.spectrumViewer.Spectrum;
- if (spectrum != null)
- {
- this.tbIdentifiedElement.Clear();
- IEnumerable<int> elementList = OIHelper.EdSpectrumProcessing.IdentifyElements(
- spectrum,
- OIHelper.AutoIdSettings);
- foreach (int i in elementList)
- {
- this.tbIdentifiedElement.Text = this.tbIdentifiedElement.Text +
- ElementProperties.GetElementSymbol(i) +
- Environment.NewLine;
- }
- // Update spectrum peak label
- this.UpdateSpectrumPeakLabels();
- }
- }
- /// <summary>
- /// Update current spectrum peak labels
- /// </summary>
- private void UpdateSpectrumPeakLabels()
- {
- try
- {
- OIHelper.EdSpectrumProcessing.UpdatePeakLabels(this.spectrumViewer.Spectrum, null);
- }
- catch (ArgumentNullException)
- {
- }
- catch (InvalidOperationException)
- {
- }
- }
- #endregion
- #region Control Quantitative Analysis
- /// <summary>
- /// Do quant button click handler
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void DoQuantButton_Click(object sender, EventArgs e)
- {
- this.DoQuant();
- }
- /// <summary>
- /// Do quantitative processing and display
- /// </summary>
- private void DoQuant()
- {
- switch (OIHelper.SEMQuantSettings.ProcessingOption)
- {
- case ProcessingOption.ElementByDifference:
- OIHelper.SEMQuantSettings.CombinedElement = int.Parse(this.tbCombinedElement.Text, CultureInfo.InvariantCulture);
- break;
- case ProcessingOption.ElementByStoichiometry:
- // While it is possible to choose other elements, Oxygen is the only supported element by stoichiometry.
- OIHelper.SEMQuantSettings.CombinedElement = 8;
- OIHelper.SEMQuantSettings.TypeOfIon = IonType.Anion;
- OIHelper.SEMQuantSettings.NumberOfIons = double.Parse(this.tbNumberOfIons.Text, CultureInfo.InvariantCulture);
- break;
- case ProcessingOption.AllElements:
- default:
- break;
- }
- if (this.cbIsCoated.Checked)
- {
- OIHelper.SEMQuantSettings.SampleCoating.IsCoated = true;
- OIHelper.SEMQuantSettings.SampleCoating.Thickness = double.Parse(this.tbThickness.Text, CultureInfo.InvariantCulture);
- OIHelper.SEMQuantSettings.SampleCoating.Density = double.Parse(this.tbDensity.Text, CultureInfo.InvariantCulture);
- OIHelper.SEMQuantSettings.SampleCoating.CoatingElement = int.Parse(this.tbCoatingElement.Text, CultureInfo.InvariantCulture);
- }
- else
- {
- OIHelper.SEMQuantSettings.SampleCoating.IsCoated = false;
- }
- if (this.cbThresholding.Checked)
- {
- OIHelper.SEMQuantSettings.Thresholding = true;
- OIHelper.SEMQuantSettings.SigmaLevel = double.Parse(this.tbSigmaLevel.Text, CultureInfo.InvariantCulture);
- }
- else
- {
- OIHelper.SEMQuantSettings.Thresholding = false;
- }
- OIHelper.SEMQuantSettings.Normalised = this.cbNormalised.Checked;
- this.dgQuantResult.Rows.Clear();
- try
- {
- ISEMQuantStatus quantStatus = OIHelper.EdSpectrumProcessing.SEMQuantifySpectrum(this.spectrumViewer.Spectrum, OIHelper.SEMQuantSettings);
- this.tbQuantStatusMessage.Text = quantStatus.Status.ToString() + System.Environment.NewLine +
- quantStatus.StatusMessage;
- double totalWeightPercent = 0;
- double totalAtomicPercent = 0;
- foreach (ISEMQuantResult result in quantStatus.Results)
- {
- if (result.WeightPercent != 0)
- {
- this.dgQuantResult.Rows.Add(new object[]
- {
- ElementProperties.GetElementSymbol(result.AtomicNumber), result.LineType,
- Math.Round(result.WeightPercent, 2), Math.Round(result.WeightPercentSigma, 6),
- Math.Round(result.AtomicPercent, 2)
- });
- }
- totalWeightPercent += result.WeightPercent;
- totalAtomicPercent += result.AtomicPercent;
- }
- this.dgQuantResult.Rows.Add(new object[]
- {
- @"Total", null, Math.Round(totalWeightPercent, 2), null, Math.Round(totalAtomicPercent, 2)
- });
- this.spectrumViewer.SEMQuantify(OIHelper.SEMQuantSettings);
- }
- catch (QuantificationException ex)
- {
- MessageBox.Show(ex.Message, @"Quantification Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- catch (ArgumentNullException)
- {
- }
- }
- /// <summary>
- /// The last element set
- /// </summary>
- private int lastElementSet = -1;
- /// <summary>
- /// ExcludeElementCombo_PropertyChanged
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">PropertyChangedEventArgs</param>
- private void ExcludeElementCombo_PropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- if (e.PropertyName == @"CurrentElement")
- {
- this.UpdateHighlightedElementInTable();
- }
- }
- /// <summary>
- /// Updates the highlighted element in table.
- /// </summary>
- private void UpdateHighlightedElementInTable()
- {
- if (this.lastElementSet != -1)
- {
- this.periodicTableControl.SetElementColor(this.lastElementSet, System.Windows.Media.Colors.Transparent);
- }
- System.Windows.Media.Color currentElementColor = System.Windows.Media.Color.FromArgb(255, 200, 255, 0);
- this.periodicTableControl.SetElementColor(this.excludeElementCombo.CurrentElement, currentElementColor);
- this.periodicTableControl.ShowElementColors = true;
- this.lastElementSet = this.excludeElementCombo.CurrentElement;
- }
- /// <summary>
- /// Add deconvolution element to list
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void AddDeconvolutionButton_Click(object sender, EventArgs e)
- {
- this.tbDeconvolutionElementList.Clear();
- int element = this.deconvolutionElementCombo.CurrentElement;
- try
- {
- OIHelper.SEMQuantSettings.SetDeconvolutionElement(element, true);
- foreach (int i in OIHelper.SEMQuantSettings.DeconvolutionElements)
- {
- this.tbDeconvolutionElementList.Text += i.ToString(CultureInfo.InvariantCulture) + System.Environment.NewLine;
- }
- }
- catch (FormatException fe)
- {
- this.tbDeconvolutionElementList.Text = fe.Message;
- }
- catch (ArgumentOutOfRangeException ae)
- {
- this.tbDeconvolutionElementList.Text = ae.Message;
- }
- }
- /// <summary>
- /// Remove element from deconvolution list
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void DeleteDeconvolutionButton_Click(object sender, EventArgs e)
- {
- this.tbDeconvolutionElementList.Clear();
- int element = this.deconvolutionElementCombo.CurrentElement;
- try
- {
- OIHelper.SEMQuantSettings.SetDeconvolutionElement(element, false);
- foreach (int i in OIHelper.SEMQuantSettings.DeconvolutionElements)
- {
- this.tbDeconvolutionElementList.Text += i.ToString(CultureInfo.InvariantCulture) + System.Environment.NewLine;
- }
- }
- catch (FormatException fe)
- {
- this.tbDeconvolutionElementList.Text = fe.Message;
- }
- }
- /// <summary>
- /// Clear deconvolution elements
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void ClearListButton_Click(object sender, EventArgs e)
- {
- this.tbDeconvolutionElementList.Clear();
- OIHelper.SEMQuantSettings.ClearDeconvolutionElements();
- foreach (int i in OIHelper.SEMQuantSettings.DeconvolutionElements)
- {
- this.tbDeconvolutionElementList.Text += i.ToString(CultureInfo.InvariantCulture) + System.Environment.NewLine;
- }
- }
- /// <summary>
- /// Used when processing spectra from specimens in which all elements yield X-rays which can be readily detected.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void AllElementsRadiobutton_Click(object sender, EventArgs e)
- {
- OIHelper.SEMQuantSettings.ProcessingOption = ProcessingOption.AllElements;
- this.cbNormalised.Enabled = true;
- this.tbCombinedElement.Enabled = false;
- this.tbNumberOfIons.Enabled = false;
- }
- /// <summary>
- /// Calculated assuming that the difference between the analyzed total and 100%
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void ElementByDifferenceRadioButton_Click(object sender, EventArgs e)
- {
- OIHelper.SEMQuantSettings.ProcessingOption = ProcessingOption.ElementByDifference;
- this.cbNormalised.Checked = false;
- this.cbNormalised.Enabled = false;
- this.tbCombinedElement.Enabled = true;
- this.tbNumberOfIons.Enabled = false;
- }
- /// <summary>
- /// Concentration of oxygen to be calculated.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void ElementByStoichiometryRadiobutton_Click(object sender, EventArgs e)
- {
- OIHelper.SEMQuantSettings.ProcessingOption = ProcessingOption.ElementByStoichiometry;
- this.cbNormalised.Enabled = true;
- this.tbCombinedElement.Enabled = false;
- this.tbNumberOfIons.Enabled = true;
- }
- /// <summary>
- /// ThresholdingCheckbox checked
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void ThresholdingCheckbox_CheckedChanged(object sender, EventArgs e)
- {
- this.tbSigmaLevel.Enabled = this.cbThresholding.Checked;
- }
- /// <summary>
- /// IsCoatedCheckbox checked
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void IsCoatedCheckbox_CheckedChanged(object sender, EventArgs e)
- {
- this.tbCoatingElement.Enabled = this.cbIsCoated.Checked;
- this.tbDensity.Enabled = this.cbIsCoated.Checked;
- this.tbThickness.Enabled = this.cbIsCoated.Checked;
- }
- #endregion
- #endregion
- #region Periodic Table
- /// <summary>
- /// Handles the CollectionChanged event of the PeriodicTableExcludedElements control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
- private void PeriodicTableExcludedElements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- this.UpdateElementsList(this.periodicTableControl.ExcludedElements, this.tbExcludedElementList);
- }
- /// <summary>
- /// Handles the CollectionChanged event of the PeriodicTableIncludedElements control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
- private void PeriodicTableIncludedElements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- this.UpdateElementsList(this.periodicTableControl.IncludedElements, this.tbIncludedElementList);
- var spectrum = this.spectrumViewer.Spectrum;
- if (spectrum != null)
- {
- switch (e.Action)
- {
- case NotifyCollectionChangedAction.Add:
- foreach (int i in e.NewItems.Cast<int>())
- {
- spectrum.SetIdentifiedElement(i, true);
- }
- break;
- case NotifyCollectionChangedAction.Remove:
- foreach (int i in e.OldItems.Cast<int>())
- {
- spectrum.SetIdentifiedElement(i, false);
- }
- break;
- default:
- break;
- }
- this.UpdateSpectrumPeakLabels();
- }
- }
- /// <summary>
- /// Handles the CollectionChanged event of the PeriodicTableUnsetElements control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
- private void PeriodicTableUnsetElements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- this.UpdateElementsList(this.periodicTableControl.UnsetElements, this.tbUnsetElementList);
- }
- /// <summary>
- /// Handles the CheckedChanged event of the EnableMultiselectToolStripMenuItem control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void EnableMultiselectToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
- {
- this.periodicTableControl.SelectionMode = this.enableMultiselectToolStripMenuItem.Checked ?
- System.Windows.Controls.SelectionMode.Multiple : System.Windows.Controls.SelectionMode.Single;
- }
- /// <summary>
- /// Handles the SelectedIndexChanged event of the PeriodicTableBackgroundToolStripComboBox control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void PeriodicTableBackgroundToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.periodicTableBackgroundToolStripComboBox.SelectedItem != null)
- {
- System.Drawing.Color selectedColor = System.Drawing.Color.FromKnownColor((System.Drawing.KnownColor)this.periodicTableBackgroundToolStripComboBox.SelectedItem);
- this.periodicTableElementHost.BackColor = selectedColor;
- this.periodicTableBackgroundToolStripComboBox.BackColor = selectedColor;
- this.periodicTableBackgroundToolStripComboBox.ForeColor = selectedColor.ToArgb() > (0xFFFFFFFF / 2) ? System.Drawing.Color.Black : System.Drawing.Color.LightGray;
- }
- }
- /// <summary>
- /// Initializes the enabled elements menu items.
- /// </summary>
- private void InitializeEnabledElementsMenuItems()
- {
- ToolStripMenuItem item;
- for (int element = 1; element <= 103; element++)
- {
- IPeriodicTableElement info = this.periodicTableControl.LookupElementInfo(element);
- if (info != null)
- {
- item = new ToolStripMenuItem(info.ElementName);
- item.CheckOnClick = true;
- item.Checked = true;
- item.Tag = element;
- item.CheckedChanged += this.ElementEnabled_CheckedChanged;
- this.enabledElementsMenuItem.DropDownItems.Add(item);
- }
- }
- }
- /// <summary>
- /// Handles the CheckedChanged event of the ElementEnabled control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void ElementEnabled_CheckedChanged(object sender, EventArgs e)
- {
- ToolStripMenuItem menuItem = sender as ToolStripMenuItem;
- if (menuItem != null)
- {
- int elementNo = (int)menuItem.Tag;
- this.periodicTableControl.EnableElements(menuItem.Checked, elementNo);
- }
- }
- #endregion
- /// <summary>
- /// Handles the SelectedIndexChanged event of the CbCompareColor control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
- private void CbCompareColor_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.addCompareSpectraButton.BackColor = Color.FromKnownColor((KnownColor)this.cbCompareColor.SelectedItem);
- }
- /// <summary>
- /// Called when [image tool ComboBox selected index changed].
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void OnImageToolComboBoxSelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.imageViewer != null)
- {
- this.imageViewer.InteractionTool = (ImageInteractionTool)this.imageToolComboBox.SelectedItem;
- }
- }
- /// <summary>
- /// Called when [spectrum tool ComboBox selected index changed].
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void OnSpectrumToolComboBoxSelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.spectrumViewer != null)
- {
- this.spectrumViewer.InteractionTool = (InteractionTool)this.spectrumInteractionToolComboBox.SelectedItem;
- }
- }
- /// <summary>
- /// Adds a spectrum for comparison.
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void OnAddCompareSpectraButtonClick(object sender, EventArgs e)
- {
- var spectrum = this.cbCompareSpectraComboBox.SelectedItem as IEdSpectrum;
- if (spectrum != null)
- {
- // Add Current Spectrum to Compare source
- WindowsMedia.Color spectrumColor = ColorConverter.Convert(this.addCompareSpectraButton.BackColor);
- this.spectrumViewer.AddComparisonSpectrum(spectrum, spectrumColor);
- this.cbCompareColor.SelectedItem = GetRandomColor();
- }
- }
- /// <summary>
- /// Loads the comparison spectra.
- /// </summary>
- private void LoadComparisonSpectra()
- {
- byte[] data;
- this.comparisonSpectra = new List<IEdSpectrum>();
- using (FileStream file = new FileStream(@"ComparisonSpectra\Nickel.spec", FileMode.Open))
- {
- data = new byte[file.Length];
- file.Read(data, 0, (int)file.Length);
- this.comparisonSpectra.Add(DataFactory.LoadEdSpectrum(data));
- }
- using (FileStream file = new FileStream(@"ComparisonSpectra\Preview spectrum.spec", FileMode.Open))
- {
- data = new byte[file.Length];
- file.Read(data, 0, (int)file.Length);
- this.comparisonSpectra.Add(DataFactory.LoadEdSpectrum(data));
- }
- using (FileStream file = new FileStream(@"ComparisonSpectra\Tungsten particle.spec", FileMode.Open))
- {
- data = new byte[file.Length];
- file.Read(data, 0, (int)file.Length);
- this.comparisonSpectra.Add(DataFactory.LoadEdSpectrum(data));
- }
- this.cbCompareSpectraComboBox.DataSource = this.comparisonSpectra;
- this.cbCompareSpectraComboBox.DisplayMember = @"Label";
- this.cbCompareSpectraComboBox.SelectedIndex = 0;
- }
- /// <summary>
- /// Called when [clear excluded list button clicked].
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void OnClearExcludedListButtonClicked(object sender, EventArgs e)
- {
- foreach (int element in this.periodicTableControl.ExcludedElements)
- {
- this.periodicTableControl.Clear(element);
- }
- this.UpdateElementsList(this.periodicTableControl.ExcludedElements, this.tbExcludedElementList);
- }
- /// <summary>
- /// Called when [export tiff button clicked].
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void OnExportTiffButtonClicked(object sender, EventArgs e)
- {
- // Export a tiff synchronously on the calling thread.
- var syncTiff = this.spectrumViewer.CreateImage(ExportImageType.Tiff);
- File.WriteAllBytes(Path.Combine(Path.GetTempPath(), @"zSpectrumSync.tiff"), syncTiff);
- // Export a tiff asynchronously on a background thread.
- // The thread must be created with an apartment state set to STA.
- // Calls to CreateImage() must be made on the same thread that created the viewer.
- var spectrum = this.spectrumViewer.Spectrum;
- var thread = new System.Threading.Thread(() =>
- {
- // For optimum performance, create a single spectrum viewer and change the spectrum
- // and viewer settings where required for all spectra that you need images for.
- var backgroundViewer = new SpectrumViewer();
- // A height and width must be set to provide the image dimensions in pixels.
- backgroundViewer.Width = 500;
- backgroundViewer.Height = 500;
- backgroundViewer.IsYAxisAutoScaleEnabled = true;
- backgroundViewer.YAxisType = ScaleType.Logarithmic;
- backgroundViewer.MaximumEnergy = 8;
- backgroundViewer.Spectrum = spectrum;
- var asyncTiff = backgroundViewer.CreateImage(ExportImageType.Tiff);
- File.WriteAllBytes(Path.Combine(Path.GetTempPath(), @"zSpectrumAsync.tiff"), asyncTiff);
- backgroundViewer.Dispatcher.InvokeShutdown();
- });
- thread.IsBackground = true;
- thread.SetApartmentState(ApartmentState.STA);
- thread.Start();
- }
- }
- }
|