Exemple #1
0
        private void WindowSettings_Click(object sender, RoutedEventArgs e)
        {
            WindowSettingsDialog dlg = new WindowSettingsDialog();

            dlg.Owner = App.Current.MainWindow;

            if (dlg.ShowDialog() != true)
            { //Nullable
                return;
            }

            MainWindow mainWindow = (MainWindow)App.Current.MainWindow;
            double     xMin, xMax, yMin, yMax;

            if (!double.TryParse(dlg.xMin.Text, out xMin))
            {
                DialogUtilities.ShowCouldNotParseNumberError("X Min", dlg.xMin.Text);
                return;
            }
            if (!double.TryParse(dlg.xMax.Text, out xMax))
            {
                DialogUtilities.ShowCouldNotParseNumberError("X Max", dlg.xMax.Text);
                return;
            }
            if (!double.TryParse(dlg.yMin.Text, out yMin))
            {
                DialogUtilities.ShowCouldNotParseNumberError("Y Min", dlg.yMin.Text);
                return;
            }
            if (!double.TryParse(dlg.yMax.Text, out yMax))
            {
                DialogUtilities.ShowCouldNotParseNumberError("Y Max", dlg.yMax.Text);
                return;
            }

            mainWindow.plotFrame.plt.Axis(xMin, xMax, yMin, yMax);
            mainWindow.plotFrame.Render();
        }
Exemple #2
0
        private void LoadCSVSeries_Click(object sender, RoutedEventArgs e)
        {
            string plotType = ((MenuItem)e.OriginalSource).Header.ToString().ToUpperInvariant();

            PlotType type = new PlotType();

            switch (plotType)
            {
            case "SCATTER PLOT":
                type = PlotType.scatter;
                break;

            case "SIGNAL":
                type = PlotType.signal;
                break;

            case "BAR PLOT":
                type = PlotType.bar;
                break;

            case "HISTOGRAM":
                type = PlotType.histogram;
                break;

            case "BOX AND WHISKER":
                type = PlotType.box_whisker;
                break;

            case "GROUPED BAR PLOT":
                type = PlotType.bar_grouped;
                break;
            }

            SettingsDialog settingsDialog = new SettingsDialog(type);

            settingsDialog.Owner = App.Current.MainWindow;

            DrawSettings drawSettings;

            drawSettings = FetchSettingsFromDialog(settingsDialog, type);
            if (!drawSettings.valid)
            {
                return;
            }

            Dictionary <string, object> metadata = new Dictionary <string, object>();

            if (type == PlotType.signal)
            {
                SignalFrequencyDialog dlg = new SignalFrequencyDialog();
                dlg.Owner = App.Current.MainWindow;
                if (dlg.ShowDialog() != true)
                { //Nullable
                    return;
                }

                double sampleRate;
                if (!double.TryParse(dlg.frequency, out sampleRate))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("Sample Rate", dlg.frequency);
                    return;
                }

                double xOffset;
                if (double.TryParse(dlg.xOffsetTextBox.Text, out xOffset))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("X-Offset", dlg.xOffsetTextBox.Text);
                    return;
                }

                metadata.Add("sampleRate", sampleRate);
                metadata.Add("xOffset", xOffset);
            }
            else if (type == PlotType.bar_grouped)
            {
                GroupedPlotDialog dlg = new GroupedPlotDialog();
                dlg.Owner = App.Current.MainWindow;
                if (dlg.ShowDialog() != true)
                { //Nullable
                    return;
                }

                if (dlg.groupNamesTextBox.Text != "")
                {
                    metadata.Add("group_names", dlg.groupNamesTextBox.Text.Split(','));
                }

                if (dlg.seriesNamesTextBox.Text != "")
                {
                    metadata.Add("series_names", dlg.seriesNamesTextBox.Text.Split(','));
                }
            }


            FilePickerDialog filePickerDialog = new FilePickerDialog(drawSettings.type == PlotType.bar_grouped);

            filePickerDialog.Owner = App.Current.MainWindow;

            try
            {
                if (filePickerDialog.ShowDialog() == true)
                {
                    PlotParameters plotParams = new PlotParameters();
                    plotParams = (App.Current as App).AddSeriesFromCSVFile(filePickerDialog.filepath, drawSettings, metadata);
                    if (settingsDialog.errorDataCSV != null)
                    {
                        ((App)App.Current).AddErrorFromCSVFile(plotParams, settingsDialog.errorDataCSV);
                    }
                    statusMessage.Text = $"{filePickerDialog.filepath} loaded";
                }
            }
            catch
            {
                DialogUtilities.ShowGenericPlotNotAddedError();
                return;
            }
        }
Exemple #3
0
        private void PrefabSeries_Click(object sender, RoutedEventArgs e)
        {
            string plotType = ((MenuItem)e.OriginalSource).Header.ToString().ToUpperInvariant();

            PlotType type = new PlotType();

            switch (plotType)
            {
            case "SIGNAL":
                type = PlotType.signal;
                break;
            }

            SettingsDialog settingsDialog = new SettingsDialog(type);

            settingsDialog.Owner = App.Current.MainWindow;

            DrawSettings drawSettings;

            drawSettings = FetchSettingsFromDialog(settingsDialog, type);
            if (!drawSettings.valid)
            {
                return;
            }

            Dictionary <string, object> metadata = new Dictionary <string, object>();

            if (type == PlotType.signal)
            {
                PrefabSignalDialog prefabSignalDialog = new PrefabSignalDialog();
                prefabSignalDialog.Owner = App.Current.MainWindow;
                if (prefabSignalDialog.ShowDialog() != true) //Nullable
                {
                    return;
                }

                double   cycleCount = 10;
                double   frequency  = 1000;
                WaveType waveType   = WaveType.sine;

                if (!double.TryParse(prefabSignalDialog.cycleCountTextBox.Text, out cycleCount))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("Cycle Count", prefabSignalDialog.cycleCountTextBox.Text);
                    return;
                }

                if (!double.TryParse(prefabSignalDialog.frequencyTextBox.Text, out frequency))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("Frequency", prefabSignalDialog.frequencyTextBox.Text);
                    return;
                }

                switch (prefabSignalDialog.waveTypeComboBox.Text.ToUpperInvariant())
                {
                case "SINE WAVE":
                    waveType = WaveType.sine;
                    break;

                case "SQUARE WAVE":
                    waveType = WaveType.square;
                    break;
                }

                SignalFrequencyDialog dlg = new SignalFrequencyDialog(true);
                dlg.Owner = App.Current.MainWindow;
                if (dlg.ShowDialog() != true)
                { //Nullable
                    return;
                }

                double sampleRate;
                if (!double.TryParse(dlg.frequency, out sampleRate))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("Sample Rate", dlg.frequency);
                    return;
                }

                double xOffset;
                if (!double.TryParse(dlg.xOffsetTextBox.Text, out xOffset))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("X-Offset", dlg.xOffsetTextBox.Text);
                    return;
                }

                metadata.Add("xOffset", xOffset);

                StringBuilder dataStr = new StringBuilder();

                int      upperBound = (int)Math.Ceiling(cycleCount * frequency);
                double[] data       = new double[upperBound];


                metadata.Add("sampleRate", frequency * frequency);

                if (waveType == WaveType.sine)
                {
                    data = ScottPlot.DataGen.Sin(upperBound, cycleCount);
                }
                else if (waveType == WaveType.square)
                {
                    bool high = false;
                    for (int i = 0; i < upperBound; i++)
                    {
                        if (i % (frequency / 2) == 0)
                        {
                            high = !high;
                        }

                        data[i] = high ? 1 : 0;
                    }
                }

                for (int i = 0; i < upperBound; i++)
                {
                    dataStr.Append(data[i]);
                    if (i != upperBound - 1)
                    {
                        dataStr.Append(',');
                    }
                }


                try
                {
                    ((App)App.Current).AddSeriesFromString(dataStr.ToString(), drawSettings, metadata);
                }
                catch
                {
                    DialogUtilities.ShowGenericPlotNotAddedError();
                    return;
                }
            }
        }