Microscopic Traffic Simulator

- Main Page
- Packages
- Classes
- Files

- File List

GUIInteractions.cs
Go to the documentation of this file.
1 using Microscopic_Traffic_Simulator.ViewModels;
2 using Microsoft.Win32;
3 using System;
4 using System.Windows;
5
6 namespace Microscopic_Traffic_Simulator.Views
7 {
11 class GUIInteractions : IInteractions
12 {
16 private App app;
17
22 internal GUIInteractions(App app)
23 {
24 this.app = app;
25 }
26
33 private bool? YesNoCancel(string title, string message)
34 {
35 MessageBoxResult result = MessageBox.Show(message, title,
36 MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
37 if (result == MessageBoxResult.Yes)
38 return true;
39 else if (result == MessageBoxResult.No)
40 return false;
41 else if (result == MessageBoxResult.Cancel)
42 return null;
43 else
44 throw new
45 ApplicationException(app.FindStringResource("UnexpectedErrorMessage"));
46 }
47
53 private string GetPathToOpenFile(string filter)
54 {
55 OpenFileDialog ofd = new OpenFileDialog();
56 ofd.Filter = filter;
57 bool? result = ofd.ShowDialog();
58 if (result == true)
59 return ofd.FileName;
60 else
61 return null;
62 }
63
69 private string GetPathToSaveFile(string filter)
70 {
71 SaveFileDialog sfd = new SaveFileDialog();
72 sfd.Filter = filter;
73 bool? result = sfd.ShowDialog();
74 if (result == true)
75 return sfd.FileName;
76 else
77 return null;
78 }
79
84 public bool? SaveChangesYesNoCancel()
85 {
86 return YesNoCancel(app.FindStringResource("MainWindow_Title"),
87 app.FindStringResource("SaveChanges"));
88 }
89
94 public string GetPathToOpenTopologyFile()
95 {
96 return GetPathToOpenFile(app.FindStringResource("GeometricTopologiesFilter"));
97 }
98
103 public string GetPathToSaveTopologyFile()
104 {
105 return GetPathToSaveFile(app.FindStringResource("GeometricTopologiesFilter"));
106 }
107
112 public string GetPathToOpenParametersFile()
113 {
114 return GetPathToOpenFile(app.FindStringResource("ParametersFilter"));
115 }
116
121 public string GetPathToSaveParametersFile()
122 {
123 return GetPathToSaveFile(app.FindStringResource("ParametersFilter"));
124 }
125
130 public void ScreamErrorMessage(string errorMessage)
131 {
132 MessageBox.Show(errorMessage, app.FindStringResource("MainWindow_Title"),
133 MessageBoxButton.OK, MessageBoxImage.Error);
134 }
135 }
136 }
Microscopic_Traffic_Simulator.App
GUIInteractions logic for App.xaml
Definition: App.xaml.cs:17
System
Microscopic_Traffic_Simulator.Views.GUIInteractions.GetPathToOpenTopologyFile
string GetPathToOpenTopologyFile()
Provide OpenFileDialog to open the topology file.
Definition: GUIInteractions.cs:94
Microscopic_Traffic_Simulator.ViewModels
Definition: CanvasViewModel.cs:8
Microscopic_Traffic_Simulator.Views.GUIInteractions
Class implements IInteractions interface by message boxes or dialogs.
Definition: GUIInteractions.cs:11
Microscopic_Traffic_Simulator.ViewModels.IInteractions
Interface for interactions with user.
Definition: IInteractions.cs:6
Microscopic_Traffic_Simulator.Views.GUIInteractions.GetPathToOpenParametersFile
string GetPathToOpenParametersFile()
Asking which parameters file to open for loading.
Definition: GUIInteractions.cs:112
Microscopic_Traffic_Simulator
Definition: App.xaml.cs:12
Microscopic_Traffic_Simulator.Views.GUIInteractions.SaveChangesYesNoCancel
bool SaveChangesYesNoCancel()
Provide MessageBoxButton to ask question whether to save changes.
Definition: GUIInteractions.cs:84
Microscopic_Traffic_Simulator.Views.GUIInteractions.ScreamErrorMessage
void ScreamErrorMessage(string errorMessage)
Provide MessageBox to scream error message.
Definition: GUIInteractions.cs:130
Microscopic_Traffic_Simulator.Views.GUIInteractions.GetPathToSaveParametersFile
string GetPathToSaveParametersFile()
Asking which paramters file the data to be saved into.
Definition: GUIInteractions.cs:121
Microscopic_Traffic_Simulator.Views.GUIInteractions.GetPathToSaveTopologyFile
string GetPathToSaveTopologyFile()
Provide SaveFileDialog to get the path to file the topology to be saved to.
Definition: GUIInteractions.cs:103