Esempio n. 1
0
        /// <summary>
        /// Gets information as response spectrum.
        /// </summary>
        /// <returns></returns>
        public SeismicRecordSpectrum ToSeismicRecordSpectrum()
        {
            var buf = new SeismicRecordSpectrum();

            var lines = Regex.Split(fileContent, "\r\n|\r|\n");

            var values = new List <double>();


            for (var i = firstLine - 1; i < lastLine; i++)
            {
                if (contentType == ContentAcceleratinsFormat.SingleAccelerationValuesPerLine ||
                    contentType == ContentAcceleratinsFormat.MultipleAccelerationsPerLine)
                {
                    var vals = lines[i].Split(' ');

                    double tmp;

                    foreach (var val in vals)
                    {
                        if (!string.IsNullOrEmpty(val))
                        {
                            values.Add(GetAccelerationValueInSi(val));
                        }
                    }
                }
            }

            buf.DeltaT             = this.TimeStepDt;
            buf.GroundAcceleration = values.ToArray();

            return(buf);
        }
        private void RemoveFromCharts(SeismicRecordSpectrum rec)
        {
            foreach (var chart in AccelerationCharts.Children)
            {
                if (chart is LineGraph)
                {
                    if ((chart as LineGraph).DataSource is CustomObservableDataSource)
                    {
                        var src = ((chart as LineGraph).DataSource as CustomObservableDataSource);
                        if (ReferenceEquals(src.Record, rec))
                        {
                            AccelerationCharts.Children.Remove(chart);
                            break;
                        }
                    }
                }
            }


            foreach (var chart in VelocityCharts.Children)
            {
                if (chart is LineGraph)
                {
                    if ((chart as LineGraph).DataSource is CustomObservableDataSource)
                    {
                        var src = ((chart as LineGraph).DataSource as CustomObservableDataSource);
                        if (ReferenceEquals(src.Record, rec))
                        {
                            VelocityCharts.Children.Remove(chart);
                            break;
                        }
                    }
                }
            }


            foreach (var chart in DisplacementCharts.Children)
            {
                if (chart is LineGraph)
                {
                    if ((chart as LineGraph).DataSource is CustomObservableDataSource)
                    {
                        var src = ((chart as LineGraph).DataSource as CustomObservableDataSource);
                        if (ReferenceEquals(src.Record, rec))
                        {
                            DisplacementCharts.Children.Remove(chart);
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
            public SeismicRecordSpectrum GenerateRecord()
            {
                var g = 10.0;//in m/s^2

                var buf = new SeismicRecordSpectrum();

                var lines = Regex.Split(accelerationFileContent, "\r\n|\r|\n");

                var accels = new List <double>();
                var times  = new List <double>();

                var lastLine2 = Math.Min(lastLine, lines.Length);

                for (var i = firstLine; i < lastLine2; i++)
                {
                    if (sinlgeAcceleration)
                    {
                        if (IsConvertibleToDouble(lines[i]))
                        {
                            accels.Add(double.Parse(lines[i].Trim()));
                        }
                    }

                    if (timeAndAcceleration)
                    {
                        var splitted = Regex.Split(lines[i].Trim(), @"\s+");

                        if (splitted.Length > 1)
                        {
                            var accelVal = GetIthColumn(splitted, accelerationColumn - 1);
                            var timeVal  = GetIthColumn(splitted, timeColumn - 1);

                            accels.Add(double.Parse(accelVal));
                            times.Add(double.Parse(timeVal));
                        }
                    }

                    if (multipleAcceleration)
                    {
                        var splitted = System.Text.RegularExpressions.Regex.Split(lines[i].Trim(), @"\s+");

                        if (splitted.Length != 0)
                        {
                            AddAccelerationsValuesToList(splitted, accels);
                        }
                    }
                }


                if (timeAndAcceleration)
                {
                    var d0 = times[1] - times[0];

                    for (int i = 0; i < times.Count - 1; i++)
                    {
                        if (Math.Abs(times[i + 1] - times[i] - d0) > 1e-6)
                        {
                            throw new Exception(string.Format("Dt should be constant ({0}'th record)", i + 1));
                        }
                    }
                    buf.DeltaT = d0;
                }
                else
                {
                    buf.DeltaT = this.timeStepDt;
                }


                for (int i = 0; i < accels.Count; i++)
                {
                    accels[i] = accels[i] * scalingFactor * g;
                }

                buf.GroundAcceleration = accels.ToArray();
                buf.TMax  = accels.Count * timeStepDt;
                buf.Title = recordName;
                buf.Color = PickBrush();

                return(buf);
            }
        /// <summary>
        /// Adds to charts.
        /// </summary>
        /// <param name="rec">The record.</param>
        private void AddToCharts(SeismicRecordSpectrum rec)
        {
            var pen = new Pen();

            BindingOperations.SetBinding(pen, Pen.ThicknessProperty,
                                         new Binding("ChartPenThickness")
            {
                Source = ApplicationSettings.Current
            });

            var brush = new SolidColorBrush();

            BindingOperations.SetBinding(brush, SolidColorBrush.ColorProperty,
                                         new Binding("Color")
            {
                Source = rec
            });

            pen.Brush = brush;

            var a = new CustomObservableDataSource(rec.AccelerationSpectrum);

            rec.AccelerationSpectrum.CollectionChanged += (sender, e) => this.DispatcherInvoke(() =>
            {
                a.Collection.Clear();
                a.AppendMany(sender as FastObservableCollection <Point2D>);
            });


            a.SetXMapping(i => i.X);
            a.SetYMapping(i => i.Y);
            a.Record = rec;

            var aGr = AccelerationCharts.AddLineGraph(a, pen, new PenDescription());

            aGr.DataContext = rec;
            aGr.SetBinding(LineGraph.VisibilityProperty, new Binding("IsVisible")
            {
                Converter = new BoolToVisibilityConverter()
            });


            var v = new CustomObservableDataSource(rec.SpeedSpectrum);

            rec.SpeedSpectrum.CollectionChanged += (sender, e) => this.DispatcherInvoke(() =>
            {
                v.Collection.Clear();
                v.AppendMany(sender as FastObservableCollection <Point2D>);
            });


            v.SetXMapping(i => i.X);
            v.SetYMapping(i => i.Y);
            v.Record = rec;

            var vGr = VelocityCharts.AddLineGraph(v, pen, new PenDescription());

            vGr.DataContext = rec;
            vGr.SetBinding(LineGraph.VisibilityProperty, new Binding("IsVisible")
            {
                Converter = new BoolToVisibilityConverter()
            });

            var d = new CustomObservableDataSource(rec.DisplacementSpectrum);

            rec.DisplacementSpectrum.CollectionChanged += (sender, e) => this.DispatcherInvoke(() =>
            {
                d.Collection.Clear();
                d.AppendMany(sender as FastObservableCollection <Point2D>);
            });


            d.SetXMapping(i => i.X);
            d.SetYMapping(i => i.Y);
            d.Record = rec;

            var dGr = DisplacementCharts.AddLineGraph(d, pen, new PenDescription());

            dGr.DataContext = rec;
            dGr.SetBinding(LineGraph.VisibilityProperty, new Binding("IsVisible")
            {
                Converter = new BoolToVisibilityConverter()
            });
        }