Beispiel #1
0
        private PlotController Import(string path)
        {
            PlotController plotController;

            using (var sr = new StreamReader(path))
            {
                var type = sr.ReadLine();
                switch (type)
                {
                case nameof(PlotController):
                    double.TryParse(sr.ReadLine(), out var initialTime);
                    double.TryParse(sr.ReadLine(), out var finalTime);
                    double?period;
                    if (!double.TryParse(sr.ReadLine(), out var p))
                    {
                        period = null;
                    }
                    else
                    {
                        period = p;
                    }

                    double.TryParse(sr.ReadLine(), out var samplingFrequency);
                    List <double> amplitudes = sr.ReadLine()?.Split(" ".ToArray(), StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToList();
                    List <double> resultTime = new List <double>();
                    for (double i = initialTime; i < finalTime; i += 1.0 / samplingFrequency)
                    {
                        resultTime.Add(i);
                    }

                    List <DataPoint> resultPoints = new List <DataPoint>();
                    for (int i = 0; i < amplitudes.Count; i++)
                    {
                        resultPoints.Add(new DataPoint(resultTime[i], amplitudes[i]));
                    }

                    plotController = new PlotController()
                    {
                        Title = "zaimportowany"
                    };
                    plotController.DataPoints = resultPoints;
                    break;

                default:
                    plotController = null;
                    break;
                }
            }

            return(plotController);
        }
Beispiel #2
0
        private void sygProstokątnyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PlotController plotController = new PlotController()
            {
                PlotType = PlotType.Prostokatny,
                Title    = "Prostokątny",
            };

            plotController.DrawPlot();
            // Set the Parent Form of the Child window.
            plotController.MdiParent = this;
            // Display the new form.
            plotController.Show();
        }
Beispiel #3
0
        private void sygSinusoidalnyWyprostowanyDwupolowkowoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PlotController plotController = new PlotController()
            {
                PlotType = PlotType.SinusoidalnyWyprostowanyDwupolowkowo,
                Title    = "Sinusoidalny wyprostowany dwupołówkowo",
            };

            plotController.DrawPlot();
            // Set the Parent Form of the Child window.
            plotController.MdiParent = this;
            // Display the new form.
            plotController.Show();
        }
Beispiel #4
0
        private void szumGaussowskiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PlotController plotController = new PlotController()
            {
                PlotType = PlotType.SzumGaussowski,
                Title    = "Szum Gaussowski",
            };

            plotController.DrawPlot();
            // Set the Parent Form of the Child window.
            plotController.MdiParent = this;
            // Display the new form.
            plotController.Show();
        }
Beispiel #5
0
        private void impulsJednostkowyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PlotController plotController = new PlotController()
            {
                PlotType = PlotType.ImpulsJednostkowy,
                Title    = "Impuls Jednostkowy",
            };

            plotController.DrawPlot();
            // Set the Parent Form of the Child window.
            plotController.MdiParent = this;
            // Display the new form.
            plotController.Show();
        }
Beispiel #6
0
        private void odczytajZPlikuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                PlotController plotController = Import(openFileDialog.FileName);
                if (plotController != null)
                {
                    plotController.PlotType = PlotType.WynikDzialania;
                    plotController.DrawPlot();
                    plotController.MdiParent = this;
                    plotController.Show();
                }
            }
        }
Beispiel #7
0
        private void dzielenieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <PlotController> plotters = new List <PlotController>();

            foreach (PlotController p in MdiChildren)
            {
                plotters.Add(p);
            }

            Operation operation = new Operation(OperationType.Dividing, plotters);

            operation.ShowDialog();
            PlotController plotController = operation.Result;

            if (plotController != null)
            {
                plotController.PlotType = PlotType.WynikDzialania;
                plotController.DrawPlot();
                plotController.MdiParent = this;
                plotController.Show();
            }
        }
Beispiel #8
0
        private void buttonGeneratePlot_Click(object sender, System.EventArgs e)
        {
            var selectedItem = comboBoxCurrentPlots.SelectedItem;

            if (selectedItem != null)
            {
                if (!(selectedItem is PlotController selectedPlot))
                {
                    Close();
                    return;
                }

                Result = new PlotController
                {
                    Title         = singlePlotOperationType.ToString(),
                    DataPoints    = selectedPlot.DataPoints,
                    complexPoints = selectedPlot.complexPoints,
                    InitialTime   = selectedPlot.InitialTime,
                    FinalTime     = selectedPlot.FinalTime,
                    Frequency     = selectedPlot.Frequency
                };
            }
            Close();
        }
Beispiel #9
0
        private void Add()
        {
            PlotController leftPlot = (PlotController)comboBoxLeft.SelectedItem, rightPlot = (PlotController)comboBoxRight.SelectedItem;

            if (Math.Abs(leftPlot.Frequency - rightPlot.Frequency) > 1e-6)
            {
                MessageBox.Show("Wykresy mają różną częstotliwość próbkowania");
                return;
            }

            double initialTime       = Math.Min(leftPlot.InitialTime, rightPlot.InitialTime);
            double finalTime         = Math.Max(leftPlot.FinalTime, rightPlot.FinalTime);
            double samplingFrequency = leftPlot.Frequency;

            if (rightPlot.InitialTime < leftPlot.InitialTime)
            {
                PlotController temp = leftPlot;
                leftPlot  = rightPlot;
                rightPlot = temp;
            }

            int leftLenght  = Convert.ToInt32(finalTime - leftPlot.FinalTime);
            int rightLenght = Convert.ToInt32(rightPlot.InitialTime - initialTime);

            List <double> list = new List <double>();

            for (int i = 0; i < leftLenght * samplingFrequency; i++)
            {
                list.Add(0.0);
            }

            List <double> leftAmplitudes = leftPlot.DataPoints.Select(x => x.Y).Concat(list).ToList();

            list.Clear();

            for (int i = 0; i < rightLenght * samplingFrequency; i++)
            {
                list.Add(0.0);
            }

            List <double> rightAmplitudes = rightPlot.DataPoints.Select(y => y.Y).Concat(list).ToList();

            List <double> resultAmplitudes = rightAmplitudes.Select((y, i) => leftAmplitudes[i] + y).ToList();


            List <double> resultTime = new List <double>();

            for (double i = initialTime; i < finalTime; i += 1.0 / samplingFrequency)
            {
                resultTime.Add(i);
            }

            List <DataPoint> resultPoints = new List <DataPoint>();

            for (int i = 0; i < resultAmplitudes.Count; i++)
            {
                resultPoints.Add(new DataPoint(resultTime[i], resultAmplitudes[i]));
            }

            Result = new PlotController
            {
                Title       = textBoxTitle.Text,
                DataPoints  = resultPoints,
                InitialTime = initialTime,
                FinalTime   = finalTime,
                Frequency   = samplingFrequency
            };
        }
Beispiel #10
0
        private void Divide()
        {
            bool dividend;

            PlotController leftPlot = (PlotController)comboBoxLeft.SelectedItem, rightPlot = (PlotController)comboBoxRight.SelectedItem;

            if (Math.Abs(leftPlot.Frequency - rightPlot.Frequency) > 1e-6)
            {
                MessageBox.Show("Wykresy mają różną częstotliwość próbkowania");
                return;
            }

            double initialTime       = Math.Min(leftPlot.InitialTime, rightPlot.InitialTime);
            double finalTime         = Math.Max(leftPlot.FinalTime, rightPlot.FinalTime);
            double samplingFrequency = leftPlot.Frequency;

            PlotController leftSignal;
            PlotController rightSignal;

            if (leftPlot.InitialTime < rightPlot.InitialTime)
            {
                dividend    = true;
                leftSignal  = leftPlot;
                rightSignal = rightPlot;
            }
            else
            {
                dividend    = false;
                leftSignal  = rightPlot;
                rightSignal = leftPlot;
            }

            var length1 = Convert.ToInt32(finalTime - leftSignal.FinalTime);
            var length2 = Convert.ToInt32(rightSignal.InitialTime - initialTime);

            var list = new List <double>();

            for (var i = 0; i < length1 * samplingFrequency; i++)
            {
                list.Add(0.0);
            }

            List <double> leftAmplitudes = leftPlot.DataPoints.Select(x => x.Y).Concat(list).ToList();

            list = new List <double>();

            for (var i = 0; i < length2 * samplingFrequency; i++)
            {
                list.Add(0.0);
            }

            List <double> rightAmplitudes  = rightPlot.DataPoints.Select(y => y.Y).Concat(list).ToList();
            List <double> resultAmplitudes = dividend ? rightAmplitudes.Select((t, i) => (Math.Abs(leftAmplitudes[i]) < 1e-10 || Math.Abs(t) < 1e-10) ? 0 : leftAmplitudes[i] / t).ToList() : leftAmplitudes.Select((t, i) => (Math.Abs(rightAmplitudes[i]) < 1e-10 || Math.Abs(t) < 1e-10) ? 0 : rightAmplitudes[i] / t).ToList();

            List <double> resultTime = new List <double>();

            for (double i = initialTime; i < finalTime; i += 1.0 / samplingFrequency)
            {
                resultTime.Add(i);
            }

            List <DataPoint> resultPoints = new List <DataPoint>();

            for (int i = 0; i < resultAmplitudes.Count; i++)
            {
                resultPoints.Add(new DataPoint(resultTime[i], resultAmplitudes[i]));
            }

            Result = new PlotController()
            {
                Title = textBoxTitle.Text
            };
            Result.DataPoints  = resultPoints;
            Result.InitialTime = initialTime;
            Result.FinalTime   = finalTime;
            Result.Frequency   = samplingFrequency;
        }