/// <summary>
        /// Function that plots a <see cref="Measurement"/> to the <see cref="MeasurementsPlotModel"/>.
        /// </summary>
        /// <param name="measurement"><see cref="Measurement"/> to be plotted.</param>
        public void PlotMeasurement(Measurement measurement)
        {
            if (SelectedDataBindingInterval > 0 && measurement.EnergyCalLinear > SelectedDataBindingInterval)
            { MessageBox.Show("Selected data binding interval is smaller than the actual channel spacing!", "Error"); SelectedDataBindingInterval = 0; return; }

            OfflineUpdateTimer.Stop();

            var MeassuredPlot = new AreaSeries
            {
                Tag = measurement,
                StrokeThickness = 2,
                MarkerSize = 3,
                Color = LineColors[measurement.MeasurementID % LineColors.Count],
                CanTrackerInterpolatePoints = false,
                Title = GetMeasurementTitle(measurement),
                Smooth = false,
            };

            var SimulatedPlot = new AreaSeries
            {
                Tag = measurement,
                StrokeThickness = 2,
                MarkerSize = 3,
                Color = LineColors[measurement.MeasurementID % LineColors.Count],
                CanTrackerInterpolatePoints = false,
                Title = GetMeasurementTitle(measurement) + " (Sim.)",
                Smooth = false,
            };

            float[] spectrumX = measurement.SpectrumXCal;
            int[] spectrumY = measurement.SpectrumY;
            int[] spectrumYCalculated = measurement.SpectrumYSimulated;

            if (spectrumYCalculated == null || ShowSimulatedSpectra == false)
            {
                spectrumYCalculated = new int[measurement.NumOfChannels];
            }

            // Remove "Counts<CutOffCounts" data points from start/end of the spectra
            int BorderOffset = 200;

            double CutOffCounts = spectrumY.Max() * CutOffCountsPercent / 100;
            if (CutOffCounts == 0) CutOffCounts = 1;

            int rightBorderIndex = spectrumY.Count();
            while (spectrumY[rightBorderIndex - 1] < CutOffCounts && rightBorderIndex > 2) rightBorderIndex--;

            int leftBorderIndex = 0;
            while (spectrumY[leftBorderIndex] < CutOffCounts && leftBorderIndex < spectrumY.Count() - 2) leftBorderIndex++;

            if (rightBorderIndex < 5) rightBorderIndex = spectrumY.Count();
            if (leftBorderIndex > spectrumY.Count() - 5) leftBorderIndex = 0;

            if (rightBorderIndex + BorderOffset < spectrumY.Count()) rightBorderIndex += BorderOffset; else rightBorderIndex = spectrumY.Count();
            if (leftBorderIndex - BorderOffset > 0) leftBorderIndex -= BorderOffset; else leftBorderIndex = 0;

            // Add points to plot
            switch (SelectedDataBindingInterval)
            {
                case 0: // Average undistinguishable points in spectrumX/spectrumY
                    {
                        var XAxis = MeasurementsPlotModel.Axes.FirstOrDefault(x => x.Position == AxisPosition.Bottom);

                        int XPlotWidth = (int)(XAxis.ScreenMax.X - XAxis.ScreenMin.X);

                        int XDataWidth = rightBorderIndex - leftBorderIndex;

                        int AverageCount = (int)Math.Floor((double)XDataWidth / XPlotWidth / 2);
                        if (AverageCount == 0) AverageCount = 1;

                        int Count = 0;
                        int newY = 0;
                        int newYCalculated = 0;

                        for (int i = leftBorderIndex; i < rightBorderIndex; i++)
                        {
                            newY += spectrumY[i];
                            newYCalculated = +spectrumYCalculated[i];

                            if (Count < AverageCount - 1)
                            {
                                Count++;
                            }
                            else
                            {
                                if (newY == 0) newY = 1;
                                if (newYCalculated == 0) newYCalculated = 1;

                                MeassuredPlot.Points.Add(new DataPoint(spectrumX[i], (double)newY / AverageCount));
                                MeassuredPlot.Points2.Add(new DataPoint(spectrumX[i], (float)0.0001));

                                SimulatedPlot.Points.Add(new DataPoint(spectrumX[i], (double)newYCalculated / AverageCount));
                                SimulatedPlot.Points2.Add(new DataPoint(spectrumX[i], (float)0.0001));

                                Count = 0;
                                newY = 0;
                                newYCalculated = 0;
                            }
                        }
                        break;
                    }
                default: // Bind points inside SelectedDataBinding intervall
                    {
                        float x, y = 0, yCalculated = 0;
                        float intervalStart = SelectedDataBindingInterval * ((int)(spectrumX[leftBorderIndex] / SelectedDataBindingInterval) + (float)0.5); ;
                        int numOfPoints = 0;

                        for (int i = leftBorderIndex; i < rightBorderIndex; i++)
                        {
                            if (spectrumX[i] - intervalStart > SelectedDataBindingInterval)
                            {
                                x = intervalStart + (float)SelectedDataBindingInterval / 2;

                                if (y == 0) y = (float)0.0001;
                                if (yCalculated == 0) yCalculated = (float)0.0001;

                                MeassuredPlot.Points.Add(new DataPoint(x, y / numOfPoints * (SelectedDataBindingInterval / measurement.EnergyCalLinear)));
                                MeassuredPlot.Points2.Add(new DataPoint(x, (float)0.0001));

                                SimulatedPlot.Points.Add(new DataPoint(x, yCalculated / numOfPoints * (SelectedDataBindingInterval / measurement.EnergyCalLinear)));
                                SimulatedPlot.Points2.Add(new DataPoint(x, (float)0.0001));

                                y = 0;
                                yCalculated = 0;
                                numOfPoints = 0;
                                intervalStart += SelectedDataBindingInterval;
                            }
                            y += spectrumY[i];
                            yCalculated += spectrumYCalculated[i];
                            numOfPoints++;
                        }
                        break;
                    }
            }
            MeasurementsPlotModel.Series.Add(MeassuredPlot);
            if (measurement.SpectrumYSimulated != null && ShowSimulatedSpectra == true)
                MeasurementsPlotModel.Series.Add(SimulatedPlot);
            MeasurementsPlotModel.InvalidatePlot(true);

            // Check if measurement is running on another computer -> update measurement periodically
            if (measurement.Runs == true && MyGlobals.CanMeasure == false)
            {
                OfflineUpdateTimer = new Timer(MyGlobals.OfflineUpdateWorkerInterval);
                OfflineUpdateTimer.Elapsed += delegate { OfflineUpdateWorker(measurement.MeasurementID); };
                OfflineUpdateTimer.Start();
            }

            // Update TimePlotModel
            var lineSeries = (LineSeries)TimePlotModel.Series.FirstOrDefault();

            if (lineSeries.Points.Count() != MyGlobals.Charge_CountsOverTime.Count() && MyGlobals.Charge_CountsOverTime.Count() >= 2)
            {
                lineSeries.Points.Clear();
                foreach (var temp in MyGlobals.Charge_CountsOverTime)
                {
                    if (temp.Value > 0)
                    {
                        lineSeries.Points.Add(new DataPoint(DateTimeAxis.ToDouble(temp.Time), temp.Value));
                    }
                }
                TimePlotModel.Axes.FirstOrDefault(x => x.Position == AxisPosition.Left).Minimum = 0.7 * MyGlobals.Charge_CountsOverTime.Where(x => x.Value > 0).Min(x => x.Value);
                TimePlotModel.Axes.FirstOrDefault(x => x.Position == AxisPosition.Left).Maximum = 1.3 * MyGlobals.Charge_CountsOverTime.Max(x => x.Value);

                TimePlotModel.InvalidatePlot(true);
            }
        }
        /// <summary>
        /// Function that is executed whenever a <see cref="Measurement"/> was updated. It updates the corresponding plot in <see cref="MeasurementsPlotModel"/>.
        /// </summary>
        /// <param name="measurement"></param>
        public void UpdatePlot(Measurement measurement)
        {
            if (!MeasurementIDList.Contains(measurement.MeasurementID))
                return;

            List<Series> updateSeries = MeasurementsPlotModel.Series.Where(x => ((Measurement)x.Tag).MeasurementID == measurement.MeasurementID).ToList();
            foreach (Series updateSerie in updateSeries)
            {
                MeasurementsPlotModel.Series.Remove(updateSerie);
            }
            PlotMeasurement(measurement);
        }
        /// <summary>
        /// Function that is executed whenever a <see cref="Measurement"/> has not to be plotted.
        /// </summary>
        /// <param name="measurement"><see cref="Measurement"/> not to be plotted.</param>
        public void MeasurementNotToPlot(Measurement measurement)
        {
            MeasurementIDList.Remove(measurement.MeasurementID);

            var delSerie = MeasurementsPlotModel.Series.Where(x => ((Measurement)x.Tag).MeasurementID == measurement.MeasurementID).FirstOrDefault();
            if (delSerie != null)
            {
                MeasurementsPlotModel.Series.Remove(delSerie);

                MeasurementsPlotModel.InvalidatePlot(true);
            }

            delSerie = MeasurementsPlotModel.Series.Where(x => ((Measurement)x.Tag).MeasurementID == measurement.MeasurementID).FirstOrDefault();
            if (delSerie != null)
            {
                MeasurementsPlotModel.Series.Remove(delSerie);

                MeasurementsPlotModel.InvalidatePlot(true);
            }
        }
        /// <summary>
        /// Function that is executed whenever a <see cref="Measurement"/> has to be plotted.
        /// </summary>
        /// <param name="measurement"><see cref="Measurement"/> to be plotted.</param>
        public void MeasurementToPlot(Measurement measurement)
        {
            if (MeasurementIDList.Contains(measurement.MeasurementID)) return;

            MeasurementIDList.Add(measurement.MeasurementID);
            PlotMeasurement(measurement);
        }
示例#5
0
 partial void DeleteMeasurement(Measurement instance);
示例#6
0
		private void detach_Measurements(Measurement entity)
		{
			this.SendPropertyChanging();
			entity.Isotope = null;
		}
示例#7
0
 partial void InsertMeasurement(Measurement instance);
示例#8
0
 /// <summary>
 /// Function that sends an event (<see cref="EventMeasurementRemove"/>) if a <see cref="Measurement"/> in the database has been removed. The event argument is the removed measurement.
 /// </summary>
 /// <param name="measurement">The measurement which has been removed.</param>
 public static void SendMeasurementRemoveEvent(Measurement measurement)
 {
     if (EventMeasurementRemove != null)
     {
         EventMeasurementRemove(measurement);
     }
 }
        /// <summary>
        /// Function that is executed when a <see cref="Measurement"/> is modified. It updates the <see cref="Measurement"/> in <see cref="MeasurementList"/>.
        /// </summary>
        /// <param name="measurement">Updated <see cref="Measurement"/>.</param>
        public void UpdateMeasurementInList(Measurement measurement)
        {
            SelectableMeasurement updateMeasurement = MeasurementList.FirstOrDefault(x => x.Measurement.MeasurementID == measurement.MeasurementID);

            if (updateMeasurement != null)
            {
                int index = MeasurementList.IndexOf(updateMeasurement);
                MeasurementList[index].Measurement = measurement;
            }
        }
示例#10
0
		private void attach_Measurements(Measurement entity)
		{
			this.SendPropertyChanging();
			entity.Sample = this;
		}
        /// <summary>
        /// Function that is executed when a <see cref="Measurement"/> is deleted. It removes the <see cref="Measurement"/> from <see cref="MeasurementList"/> and sends an event not to plot it.
        /// </summary>
        /// <param name="measurement">Deleted <see cref="Measurement"/>.</param>
        public void DeleteRemovedMeasurementFromList(Measurement measurement)
        {
            SelectableMeasurement delMeasurement = MeasurementList.FirstOrDefault(x => x.Measurement.MeasurementID == measurement.MeasurementID);

            if (delMeasurement != null)
                MeasurementList.Remove(delMeasurement);
        }
        /// <summary>
        /// Function that is executed when a new <see cref="Measurement"/> is detected. It adds the <see cref="Measurement"/> to <see cref="MeasurementList"/> and sends an event to plot it.
        /// </summary>
        /// <param name="measurement">New <see cref="Measurement"/>.</param>
        public void AddNewMeasurementToList(Measurement measurement)
        {
            MeasurementList.Add(new SelectableMeasurement() { Selected = true, Measurement = measurement });

            if (EventMeasurementToPlot != null) EventMeasurementToPlot(measurement);
        }
示例#13
0
 /// <summary>
 /// Function that sends an event (<see cref="EventMeasurementUpdate"/>) if a <see cref="Measurement"/> in the database has been modified. The event argument is the modified measurement.
 /// </summary>
 /// <param name="measurement">The measurement which has been modified.</param>
 public static void SendMeasurementUpdateEvent(Measurement measurement)
 {
     if (EventMeasurementUpdate != null)
     {
         EventMeasurementUpdate(measurement);
     }
 }
        /// <summary>
        /// Function that determines the title of a <see cref="Measurement"/> plot according to the <see cref="SelectedLegendCaption"/>.
        /// </summary>
        /// <param name="measurement"><see cref="Measurement"/> for which the title is determined.</param>
        /// <returns></returns>
        private string GetMeasurementTitle(Measurement measurement)
        {
            if (measurement == null) return "";

            switch (SelectedLegendCaption)
            {
                case "Measurement IDs":
                    return "MeasurementID " + measurement.MeasurementID;
                case "Measurement names":
                    return measurement.MeasurementName;
                case "Sample names":
                    return measurement.Sample.SampleName;
                case "Sample remarks":
                    return measurement.SampleRemark;
                case "Sample names + remarks":
                    return measurement.Sample.SampleName + " " + measurement.SampleRemark;
                default:
                    return "MeasurementID " + measurement.MeasurementID;
            }
        }
示例#15
0
 partial void UpdateMeasurement(Measurement instance);
示例#16
0
 /// <summary>
 /// Function that starts a new test measurement.
 /// </summary>
 public void _NewTestMeasurementCommand()
 {
     Views.Utils.ChannelDialog channelDialog = new Views.Utils.ChannelDialog();
     if (channelDialog.ShowDialog() == true)
     {
         Measurement measurement = new Measurement();
         measurement.IsTestMeasurement = true;
         measurement.MeasurementName = "TestMeasurement";
         int SampleID, IncomingIonIsotopeID;
         using (DatabaseDataContext Database = MyGlobals.Database)
         {
             SampleID = Database.Samples.FirstOrDefault(x => x.SampleName == "(undefined)").SampleID;
             IncomingIonIsotopeID = Database.Isotopes.FirstOrDefault(x => x.MassNumber == 1).IsotopeID;
         }
         MeasureSpectra.StartAcquisitions(new List<int> { channelDialog.SelectedChannel }, measurement, SampleID, IncomingIonIsotopeID);
     }
 }
示例#17
0
 /// <summary>
 /// Function that sends an event (<see cref="EventMeasurementNew"/>) if new <see cref="Measurement"/> has been added to the database. The event argument is the new measurement.
 /// </summary>
 /// <param name="measurement">The measurement which has been added to the database.</param>
 public static void SendMeasurementNewEvent(Measurement measurement)
 {
     if (EventMeasurementNew != null)
     {
         EventMeasurementNew(measurement);
     }
 }