void _load_Click(object sender, RoutedEventArgs e) { var dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Title = "Load Activities"; dlg.DefaultExt = ".act"; dlg.Filter = "act documents (.act)|*.act"; Nullable <bool> result = dlg.ShowDialog(this._host); string fileAddress = ""; if (result == true) { fileAddress = dlg.FileName; } else { return; } string unitString = "UNIT:"; bool unitAssigned = false; Length_Unit_Types lengthUnitTypes = Length_Unit_Types.FEET; List <string> lines = new List <string>(); using (System.IO.StreamReader sr = new System.IO.StreamReader(fileAddress)) { string line = string.Empty; while ((line = sr.ReadLine()) != null) { if (!(string.IsNullOrEmpty(line) || string.IsNullOrWhiteSpace(line))) { line = line.TrimStart(' '); if (line[0] != '#')//remove comments { if (line.Length > unitString.Length && line.Substring(0, unitString.Length).ToUpper() == unitString.ToUpper()) { string unitName = line.Substring(unitString.Length, line.Length - unitString.Length).ToUpper().Trim(' '); switch (unitName) { case "METERS": unitAssigned = true; lengthUnitTypes = Length_Unit_Types.METERS; break; case "DECIMETERS": unitAssigned = true; lengthUnitTypes = Length_Unit_Types.DECIMETERS; break; case "CENTIMETERS": unitAssigned = true; lengthUnitTypes = Length_Unit_Types.CENTIMETERS; break; case "MILLIMETERS": unitAssigned = true; lengthUnitTypes = Length_Unit_Types.MILLIMETERS; break; case "FEET": unitAssigned = true; lengthUnitTypes = Length_Unit_Types.FEET; break; case "INCHES": unitAssigned = true; lengthUnitTypes = Length_Unit_Types.METERS; break; default: MessageBox.Show("Failed to parse unit information", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } } else { lines.Add(line); } } } } } if (lines.Count == 0) { MessageBox.Show("The file includes no input", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } //find the project unit type if (!unitAssigned) { MessageBox.Show("The did not include information for 'Unit of Length'", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } int n = 7; if (this._includeGuassian.IsChecked.Value) { double _n = 0; if (!double.TryParse(this._range_guassian.Text, out _n)) { MessageBox.Show("'Neighborhood Size' should be a valid number larger than 0", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } n = (int)_n; if (n < 1) { MessageBox.Show("'Neighborhood Size' should be a valid number larger than 0", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } } double r = 0; if (!double.TryParse(this._range.Text, out r)) { MessageBox.Show("'Neighborhood Size' should be a number larger than 1", "Missing Input", MessageBoxButton.OK, MessageBoxImage.Information); return; } int range = (int)r; if (range < 1) { MessageBox.Show("'Neighborhood Size' should be a number larger than 1", "Missing Input", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (this._host.FieldGenerator == null || this._host.FieldGenerator.Range != range) { this._host.FieldGenerator = new SpatialDataCalculator(this._host, range, OSMDocument.AbsoluteTolerance); } List <ActivityDestination> destinations = new List <ActivityDestination>(); for (int i = 0; i < lines.Count / 4; i++) { try { ActivityDestination destination = ActivityDestination.FromString(lines, i * 4, lengthUnitTypes, this._host.cellularFloor); if (this._host.AllActivities.ContainsKey(destination.Name)) { MessageBox.Show("An activity with the same name exists!", "", MessageBoxButton.OK, MessageBoxImage.Error); } else { destinations.Add(destination); } } catch (Exception error) { MessageBox.Show(error.Report()); } } if (destinations.Count == 0) { return; } Dispatcher.Invoke(new Action(() => { this._report.Visibility = System.Windows.Visibility.Visible; this.grid.IsEnabled = false; this._progressBar.Maximum = destinations.Count; this._activityName.Text = string.Empty; }), System.Windows.Threading.DispatcherPriority.ContextIdle); int count = 0; foreach (var item in destinations) { Dispatcher.Invoke(new Action(() => { this._activityName.Text = item.Name; }), System.Windows.Threading.DispatcherPriority.ContextIdle); count++; try { Activity newField = null; if (this._includeAngularCost.IsChecked.Value) { //double angularVelocityWeight = 0; if (Parameter.DefaultParameters[AgentParameters.MAN_AngularDeviationCost].Value <= 0) { MessageBox.Show("Cost of angular change should be exclusively larger than zero", "Activity Generation", MessageBoxButton.OK, MessageBoxImage.Information); return; } newField = this._host.FieldGenerator.GetDynamicActivity(item, Parameter.DefaultParameters[AgentParameters.MAN_AngularDeviationCost].Value); if (!newField.TrySetEngagementTime(item.MinimumEngagementTime, item.MinimumEngagementTime)) { throw new ArgumentException("Failed to set activity engagement duration!"); } } else { newField = this._host.FieldGenerator.GetStaticActivity(item); if (!newField.TrySetEngagementTime(item.MinimumEngagementTime, item.MaximumEngagementTime)) { throw new ArgumentException("Failed to set activity engagement duration!"); } } if (this._includeGuassian.IsChecked.Value) { //update filter if (this._host.ViewBasedGaussianFilter != null) { if (this._host.ViewBasedGaussianFilter.Range != n) { try { this._host.ViewBasedGaussianFilter = new IsovistClippedGaussian(this._host.cellularFloor, n); } catch (Exception error) { MessageBox.Show(error.Report(), "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } } } else { try { this._host.ViewBasedGaussianFilter = new IsovistClippedGaussian(this._host.cellularFloor, n); } catch (Exception error) { MessageBox.Show(error.Report(), "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } } var data = this._host.ViewBasedGaussianFilter.GetFilteredValues(newField); newField.Potentials = data; } this._host.AddActivity(newField); } catch (Exception error) { MessageBox.Show(error.Report()); } this.updateProgressBar(count); } this.Close(); }
/// <summary> /// Calculates the activity (i.e. potential field) with respect to distance, static cost and angle. /// </summary> /// <param name="activityDestination">The activity destination.</param> /// <param name="angleCost">The angle cost.</param> /// <returns>Activity.</returns> public Activity GetDynamicActivity(ActivityDestination activityDestination, double angleCost) { return(this.GetDynamicActivity(activityDestination.Origins, activityDestination.DestinationArea, activityDestination.DefaultState, activityDestination.Name, angleCost)); }
/// <summary> /// Calculates the activity (i.e. potential field) with respect to distance, static cost and angle. /// </summary> /// <param name="activityDestination">The activity destination.</param> /// <param name="angleCost">The angle cost.</param> /// <param name="radius">The radius.</param> /// <returns>Activity.</returns> public Activity GetDynamicActivity(ActivityDestination activityDestination, double angleCost, double radius) { return(this.GetDynamicActivity(activityDestination.Origins.First(), activityDestination.DestinationArea, activityDestination.DefaultState, activityDestination.Name, angleCost, radius)); }
/// <summary> /// Calculates the activity (i.e. potential field) with respect to distance and static cost only /// </summary> /// <param name="activityDestination">The activity destination.</param> /// <returns>Activity.</returns> public Activity GetStaticActivity(ActivityDestination activityDestination) { return(this.GetStaticActivity(activityDestination.Origins, activityDestination.DestinationArea, activityDestination.DefaultState, activityDestination.Name)); }