├── CityTrafficSimulator ├── Tools │ ├── Math2.cs │ ├── Pair.cs │ ├── Interval.cs │ ├── Vector2.cs │ ├── PriorityQueue.cs │ ├── APriorityQueue.cs │ ├── ObserverPattern │ │ ├── IEventListener.cs │ │ ├── ObserverTreeView.cs │ │ └── EventManager.cs │ ├── ITickable.cs │ ├── SerializableColor.cs │ ├── ProgramSettings.cs │ ├── MyLinkedList.cs │ ├── SortedLinkedList.cs │ ├── Colormap.resx │ ├── IDM.cs │ └── AlgorithmicGeometry.cs ├── bin │ └── Debug │ │ └── MagicLibrary.dll ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── MainForm │ ├── MainForm.DragnDrop.cs │ └── MainForm.resx ├── Program.cs ├── ISavable.cs ├── Vehicle │ ├── VehicleDistanceTime.cs │ ├── Car.cs │ ├── Constants.cs │ ├── VehicleDistance.cs │ ├── Bus.cs │ ├── Truck.cs │ └── Tram.cs ├── Timeline │ ├── TrafficLightTreeView.Designer.cs │ ├── TimelineControl.Designer.cs │ ├── TimelineBlockingEvent.cs │ ├── TrafficLightTreeView.cs │ ├── TimelineControl.resx │ ├── TrafficLightForm.resx │ └── TimelineEvent.cs ├── RechenkaestchenControl.Designer.cs ├── GlobalTime.cs ├── GlobalRandom.cs ├── AboutBox │ └── AboutBox.cs ├── Verkehr │ ├── BunchOfNodes.cs │ └── TrafficVolumeForm.resx ├── LoadingForm │ ├── LoadingForm.cs │ ├── LoadingForm.Designer.cs │ └── LoadingForm.resx ├── NetworkLayer.cs ├── RechenkaestchenControl.resx ├── XmlSaver.cs ├── RechenkaestchenControl.cs └── TrafficLight.cs ├── readme.md ├── CityTrafficSimulator.sln ├── .gitignore └── update_legal_header.py /CityTrafficSimulator/Tools/Math2.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schulteatq/CityTrafficSimulator/HEAD/CityTrafficSimulator/Tools/Math2.cs -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/Pair.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schulteatq/CityTrafficSimulator/HEAD/CityTrafficSimulator/Tools/Pair.cs -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/Interval.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schulteatq/CityTrafficSimulator/HEAD/CityTrafficSimulator/Tools/Interval.cs -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/Vector2.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schulteatq/CityTrafficSimulator/HEAD/CityTrafficSimulator/Tools/Vector2.cs -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/PriorityQueue.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schulteatq/CityTrafficSimulator/HEAD/CityTrafficSimulator/Tools/PriorityQueue.cs -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/APriorityQueue.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schulteatq/CityTrafficSimulator/HEAD/CityTrafficSimulator/Tools/APriorityQueue.cs -------------------------------------------------------------------------------- /CityTrafficSimulator/bin/Debug/MagicLibrary.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schulteatq/CityTrafficSimulator/HEAD/CityTrafficSimulator/bin/Debug/MagicLibrary.dll -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | CityTrafficSimulator 2 | ==================== 3 | 4 | CityTrafficSimulator is a microscopic traffic simulation software for small- to medium-sized traffic networks, such as intersections or small urban areas. 5 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Dieser Code wurde von einem Tool generiert. 4 | // Laufzeitversion:4.0.30319.18444 5 | // 6 | // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn 7 | // der Code erneut generiert wird. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CityTrafficSimulator.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CityTrafficSimulator/MainForm/MainForm.DragnDrop.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.ComponentModel; 23 | using System.Data; 24 | using System.Drawing; 25 | using System.Text; 26 | using System.Windows.Forms; 27 | 28 | namespace CityTrafficSimulator 29 | { 30 | public partial class MainForm : Form 31 | { 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /CityTrafficSimulator.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CityTrafficSimulator", "CityTrafficSimulator\CityTrafficSimulator.csproj", "{5B17E2AC-7B08-4408-9135-0161A24D117E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x64 = Debug|x64 12 | Release|Any CPU = Release|Any CPU 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {5B17E2AC-7B08-4408-9135-0161A24D117E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {5B17E2AC-7B08-4408-9135-0161A24D117E}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {5B17E2AC-7B08-4408-9135-0161A24D117E}.Debug|x64.ActiveCfg = Debug|x64 19 | {5B17E2AC-7B08-4408-9135-0161A24D117E}.Debug|x64.Build.0 = Debug|x64 20 | {5B17E2AC-7B08-4408-9135-0161A24D117E}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {5B17E2AC-7B08-4408-9135-0161A24D117E}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {5B17E2AC-7B08-4408-9135-0161A24D117E}.Release|x64.ActiveCfg = Release|x64 23 | {5B17E2AC-7B08-4408-9135-0161A24D117E}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Program.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Windows.Forms; 23 | 24 | namespace CityTrafficSimulator 25 | { 26 | static class Program 27 | { 28 | /// 29 | /// Der Haupteinstiegspunkt für die Anwendung. 30 | /// 31 | [STAThread] 32 | static void Main() 33 | { 34 | Application.EnableVisualStyles(); 35 | Application.SetCompatibleTextRenderingDefault(false); 36 | Application.Run(new MainForm()); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/ObserverPattern/IEventListener.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator.Tools.ObserverPattern 25 | { 26 | /// 27 | /// EventListener Interface zur Realisierung des Observer Verhaltensmusters. 28 | /// Kann bei einem EventManager angemeldet werden und wird von diesem beizeiten aufgerufen. 29 | /// 30 | public interface IEventListener 31 | { 32 | 33 | /// 34 | /// Methode, die vom EventManager.NotifyListeners() aufgerufen werden soll. 35 | /// 36 | void Notify(); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Allgemeine Informationen über eine Assembly werden über die folgenden 6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 7 | // die mit einer Assembly verknüpft sind. 8 | [assembly: AssemblyTitle("CityTrafficSimulator")] 9 | [assembly: AssemblyDescription("Mircroscopic Traffic Simulation")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Christian Schulte zu Berge")] 12 | [assembly: AssemblyProduct("CityTrafficSimulator")] 13 | [assembly: AssemblyCopyright("Copyright © 2006-2012")] 14 | [assembly: AssemblyTrademark("Christian Schulte zu Berge")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 18 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 19 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. 20 | [assembly: ComVisible(false)] 21 | 22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 23 | [assembly: Guid("e81e8d18-db58-4f68-a757-176972f23a7d")] 24 | 25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 26 | // 27 | // Hauptversion 28 | // Nebenversion 29 | // Buildnummer 30 | // Revision 31 | // 32 | [assembly: AssemblyVersion("0.6.7.0")] 33 | [assembly: AssemblyFileVersion("0.6.7.0")] 34 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/ITickable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator 25 | { 26 | interface ITickable 27 | { 28 | /// 29 | /// lässt die Zeit um einen Tick voranschreiten 30 | /// 31 | /// Länge eines Ticks in Sekunden (berechnet sich mit 1/#Ticks pro Sekunde) 32 | void Tick(double tickLength); 33 | 34 | /// 35 | /// sagt dem Objekt Bescheid, dass der Tick vorbei ist. 36 | /// (wir zur Zeit nur von IVehicle benötigt) 37 | /// 38 | void Reset(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/ObserverPattern/ObserverTreeView.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Windows.Forms; 24 | 25 | using CityTrafficSimulator.Tools.ObserverPattern; 26 | 27 | 28 | namespace CityTrafficSimulator.Tools.ObserverPattern 29 | { 30 | /// 31 | /// TreeView-Control, welches als Observer fungiert und sich so bei einem EventManager anmelden kann. 32 | /// 33 | class ObserverTreeView : TreeView, IEventListener 34 | { 35 | /// 36 | /// Notify-Funktion, die vom EventManager aufgerufen wird. 37 | /// 38 | public virtual void Notify() 39 | { 40 | 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CityTrafficSimulator/ISavable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator 25 | { 26 | interface ISavable 27 | { 28 | /// 29 | /// Bereite alles fürs Speichern vor 30 | /// Hashes berechnen, etc. 31 | /// 32 | void PrepareForSave(); 33 | 34 | /// 35 | /// Stelle den ursprünglich gespeicherten Zustand wieder her 36 | /// zum Beispiel durch die Hashes 37 | /// 38 | /// Version der gespeicherten Datei 39 | /// Liste der bereits wiederhergestellten LineNodes 40 | void RecoverFromLoad(int saveVersion, List nodesList); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Vehicle/VehicleDistanceTime.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator.Vehicle 25 | { 26 | /// 27 | /// kapselt ein Fahrzeug mit zugehörigen Distanz- und Zeitparametern 28 | /// 29 | public struct VehicleDistanceTime 30 | { 31 | /// 32 | /// Fahrzeug 33 | /// 34 | public IVehicle vehicle; 35 | /// 36 | /// Distanz 37 | /// 38 | public double distance; 39 | /// 40 | /// Zeit 41 | /// 42 | public double time; 43 | 44 | 45 | /// 46 | /// Standardkonstruktor 47 | /// 48 | /// Fahrzeug, welches gekapselt wird 49 | /// Distanz, die gekapselt wird 50 | /// Zeit, die gekapselt wird 51 | public VehicleDistanceTime(IVehicle vehicle, double distance, double time) 52 | { 53 | this.distance = distance; 54 | this.vehicle = vehicle; 55 | this.time = time; 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Timeline/TrafficLightTreeView.Designer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | namespace CityTrafficSimulator.Timeline 21 | { 22 | partial class TrafficLightTreeView 23 | { 24 | /// 25 | /// Erforderliche Designervariable. 26 | /// 27 | private System.ComponentModel.IContainer components = null; 28 | 29 | /// 30 | /// Verwendete Ressourcen bereinigen. 31 | /// 32 | /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. 33 | protected override void Dispose(bool disposing) 34 | { 35 | if (disposing && (components != null)) 36 | { 37 | components.Dispose(); 38 | } 39 | base.Dispose(disposing); 40 | } 41 | 42 | #region Vom Komponenten-Designer generierter Code 43 | 44 | /// 45 | /// Erforderliche Methode für die Designerunterstützung. 46 | /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. 47 | /// 48 | private void InitializeComponent() 49 | { 50 | components = new System.ComponentModel.Container(); 51 | } 52 | 53 | #endregion 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # mstest test results 6 | TestResults 7 | 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.sln.docstates 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Rr]elease/ 19 | x64/ 20 | *_i.c 21 | *_p.c 22 | *.ilk 23 | *.meta 24 | *.obj 25 | *.pch 26 | *.pdb 27 | *.pgc 28 | *.pgd 29 | *.rsp 30 | *.sbr 31 | *.tlb 32 | *.tli 33 | *.tlh 34 | *.tmp 35 | *.log 36 | *.vspscc 37 | *.vssscc 38 | .builds 39 | 40 | # Visual C++ cache files 41 | ipch/ 42 | *.aps 43 | *.ncb 44 | *.opensdf 45 | *.sdf 46 | 47 | # Visual Studio profiler 48 | *.psess 49 | *.vsp 50 | *.vspx 51 | 52 | # Guidance Automation Toolkit 53 | *.gpState 54 | 55 | # ReSharper is a .NET coding add-in 56 | _ReSharper* 57 | 58 | # NCrunch 59 | *.ncrunch* 60 | .*crunch*.local.xml 61 | 62 | # Installshield output folder 63 | [Ee]xpress 64 | 65 | # DocProject is a documentation generator add-in 66 | DocProject/buildhelp/ 67 | DocProject/Help/*.HxT 68 | DocProject/Help/*.HxC 69 | DocProject/Help/*.hhc 70 | DocProject/Help/*.hhk 71 | DocProject/Help/*.hhp 72 | DocProject/Help/Html2 73 | DocProject/Help/html 74 | 75 | # Click-Once directory 76 | publish 77 | 78 | # Publish Web Output 79 | *.Publish.xml 80 | 81 | # NuGet Packages Directory 82 | packages 83 | 84 | # Windows Azure Build Output 85 | csx 86 | *.build.csdef 87 | 88 | # Windows Store app package directory 89 | AppPackages/ 90 | 91 | # Others 92 | [Bb]in 93 | [Oo]bj 94 | sql 95 | TestResults 96 | [Tt]est[Rr]esult* 97 | *.Cache 98 | ClientBin 99 | [Ss]tyle[Cc]op.* 100 | ~$* 101 | *.dbmdl 102 | Generated_Code #added for RIA/Silverlight projects 103 | 104 | # Backup & report files from converting an old project file to a newer 105 | # Visual Studio version. Backup files are not needed, because we have git ;-) 106 | _UpgradeReport_Files/ 107 | Backup*/ 108 | UpgradeLog*.XML 109 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Vehicle/Car.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Drawing; 24 | using System.Drawing.Drawing2D; 25 | 26 | namespace CityTrafficSimulator.Vehicle 27 | { 28 | class Car : IVehicle 29 | { 30 | public Car(IVehicle.Physics p) 31 | { 32 | length = GlobalRandom.Instance.Next(28, 45); 33 | 34 | _physics = p; 35 | 36 | // etwas Zufall: 37 | a *= (GlobalRandom.Instance.NextDouble() + 0.5); 38 | b *= (GlobalRandom.Instance.NextDouble() + 0.5); 39 | s0 *= (GlobalRandom.Instance.NextDouble() + 0.5); 40 | T *= (GlobalRandom.Instance.NextDouble() + 0.5); 41 | 42 | _physics.targetVelocity += ((GlobalRandom.Instance.NextDouble() - 0.5) * 4); 43 | 44 | color = Color.FromArgb(GlobalRandom.Instance.Next(256), GlobalRandom.Instance.Next(256), GlobalRandom.Instance.Next(256)); 45 | _vehicleType = VehicleTypes.CAR; 46 | } 47 | 48 | /// 49 | /// Prüfe, ob ich auf der NodeConnection nc fahren darf 50 | /// 51 | /// zu prüfende NodeConnection 52 | /// nc.carsAllowed 53 | public override bool CheckNodeConnectionForSuitability(NodeConnection nc) 54 | { 55 | return nc.carsAllowed; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/ObserverPattern/EventManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator.Tools.ObserverPattern 25 | { 26 | /// 27 | /// Abstrakte EventManager Klasse zur Realisierung des Observer Verhaltensmusters. 28 | /// EventListener können sich hier registrieren und über NotifyListeners() aufgerufen werden. 29 | /// 30 | public abstract class EventManager 31 | { 32 | 33 | /// 34 | /// Liste aller angemeldeten EventListener 35 | /// 36 | private List eventListeners = new List(); 37 | 38 | /// 39 | /// registriert den EventListener ev bei diesem EventManager 40 | /// 41 | /// zu registrierender EventListener 42 | public void RegisterEventListener(IEventListener ev) 43 | { 44 | eventListeners.Add(ev); 45 | } 46 | 47 | /// 48 | /// macht die Registrierung des EventListeners ev bei diesem EventManager rückgängig 49 | /// 50 | /// zu unregistrierender EventListener 51 | /// true, falls das unregistrierung erfolgreich war 52 | public bool UnregisterEventListener(IEventListener ev) 53 | { 54 | return eventListeners.Remove(ev); 55 | } 56 | 57 | /// 58 | /// benachrichtigt alle angemeldeten EventListener 59 | /// 60 | public void NotifyListeners() 61 | { 62 | foreach (IEventListener el in eventListeners) 63 | { 64 | el.Notify(); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Timeline/TimelineControl.Designer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | namespace CityTrafficSimulator 21 | { 22 | partial class TimelineControl 23 | { 24 | /// 25 | /// Erforderliche Designervariable. 26 | /// 27 | private System.ComponentModel.IContainer components = null; 28 | 29 | /// 30 | /// Verwendete Ressourcen bereinigen. 31 | /// 32 | /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. 33 | protected override void Dispose(bool disposing) 34 | { 35 | if (disposing && (components != null)) 36 | { 37 | components.Dispose(); 38 | } 39 | base.Dispose(disposing); 40 | } 41 | 42 | #region Vom Komponenten-Designer generierter Code 43 | 44 | /// 45 | /// Erforderliche Methode für die Designerunterstützung. 46 | /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. 47 | /// 48 | private void InitializeComponent() 49 | { 50 | this.SuspendLayout(); 51 | // 52 | // TimelineControl 53 | // 54 | this.Size = new System.Drawing.Size(435, 147); 55 | this.MouseLeave += new System.EventHandler(this.TimelineControl_MouseLeave); 56 | this.Paint += new System.Windows.Forms.PaintEventHandler(this.TimelineControl_Paint); 57 | this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.TimelineControl_MouseMove); 58 | this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TimelineControl_MouseDown); 59 | this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.TimelineControl_MouseUp); 60 | this.ResumeLayout(false); 61 | 62 | } 63 | 64 | #endregion 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/SerializableColor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Drawing; 23 | using System.Text; 24 | using System.Xml.Serialization; 25 | 26 | namespace CityTrafficSimulator.Tools 27 | { 28 | /// 29 | /// Serializable wrapper struct for System.Drawing.Color 30 | /// 31 | [Serializable] 32 | public struct SerializableColor 33 | { 34 | /// 35 | /// The wrapped Color 36 | /// 37 | private Color _color; 38 | 39 | /// 40 | /// ARGB version of the wrapped color (this will be serialized) 41 | /// 42 | public int argbColor 43 | { 44 | get { return _color.ToArgb(); } 45 | set { _color = Color.FromArgb(value); } 46 | } 47 | 48 | /// 49 | /// Implicit conversion SerializableColor -> Color 50 | /// 51 | /// SerializableColor to convert 52 | /// sc._color 53 | public static implicit operator Color(SerializableColor sc) 54 | { 55 | return sc._color; 56 | } 57 | 58 | /// 59 | /// Implicit conversion Color -> SerializableColor 60 | /// 61 | /// Color to convert 62 | /// new SerializableColor(c) 63 | public static implicit operator SerializableColor(Color c) 64 | { 65 | return new SerializableColor(c); 66 | } 67 | 68 | /// 69 | /// Constructor, _color will be initialized by 70 | /// 71 | /// Color of this object 72 | public SerializableColor(Color c) 73 | { 74 | _color = c; 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/ProgramSettings.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator.Tools 25 | { 26 | /// 27 | /// Record of all program settings which should be saved together with the network 28 | /// 29 | [Serializable] 30 | public struct ProgramSettings 31 | { 32 | /// 33 | /// Simulation Speed 34 | /// 35 | public decimal _simSpeed; 36 | 37 | /// 38 | /// Simulation Steps/s 39 | /// 40 | public decimal _simSteps; 41 | 42 | /// 43 | /// Simulation Duration 44 | /// 45 | public decimal _simDuration; 46 | 47 | /// 48 | /// Random Seed for Simulation 49 | /// 50 | public decimal _simRandomSeed; 51 | 52 | /// 53 | /// Selected Item im Zoom ComboBox 54 | /// 55 | public int _zoomLevel; 56 | 57 | /// 58 | /// Selected Item in Render Quality ComboBox 59 | /// 60 | public int _renderQuality; 61 | 62 | /// 63 | /// Flag whether to render NodeConnection statistics 64 | /// 65 | public bool _renderStatistics; 66 | 67 | /// 68 | /// Flag whether to render vehicle velocity mapping 69 | /// 70 | public bool _renderVelocityMapping; 71 | 72 | /// 73 | /// Flag whether to show FPS 74 | /// 75 | public bool _showFPS; 76 | 77 | /// 78 | /// Render Options for Main Canvas 79 | /// 80 | public NodeSteuerung.RenderOptions _renderOptions; 81 | 82 | /// 83 | /// ColorMap for Velocity Mapping 84 | /// 85 | public Tools.ColorMap _velocityMappingColorMap; 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /CityTrafficSimulator/RechenkaestchenControl.Designer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | namespace CityTrafficSimulator 21 | { 22 | partial class RechenkaestchenControl 23 | { 24 | /// 25 | /// Erforderliche Designervariable. 26 | /// 27 | private System.ComponentModel.IContainer components = null; 28 | 29 | /// 30 | /// Verwendete Ressourcen bereinigen. 31 | /// 32 | /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. 33 | protected override void Dispose(bool disposing) 34 | { 35 | if (disposing && (components != null)) 36 | { 37 | components.Dispose(); 38 | } 39 | base.Dispose(disposing); 40 | } 41 | 42 | #region Vom Komponenten-Designer generierter Code 43 | 44 | /// 45 | /// Erforderliche Methode für die Designerunterstützung. 46 | /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. 47 | /// 48 | private void InitializeComponent() 49 | { 50 | this.SuspendLayout(); 51 | // 52 | // RechenkaestchenControl 53 | // 54 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 55 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 56 | this.BackColor = System.Drawing.Color.White; 57 | this.Name = "RechenkaestchenControl"; 58 | this.Size = new System.Drawing.Size(295, 283); 59 | this.Paint += new System.Windows.Forms.PaintEventHandler(this.RechenkaestchenControl_Paint); 60 | this.ResumeLayout(false); 61 | 62 | } 63 | 64 | #endregion 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /update_legal_header.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import getopt 4 | import string 5 | 6 | dirsToIgnore = ['.svn', 'debug', 'release', 'Debug', 'Release', 'ext', 'bin', 'obj', 'Properties'] 7 | 8 | legal_notice_begin = """/* 9 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 10 | """ 11 | legal_notice = """ * Copyright (C) 2005-2014, Christian Schulte zu Berge 12 | * 13 | * This program is free software; you can redistribute it and/or modify it under the 14 | * terms of the GNU General Public License as published by the Free Software 15 | * Foundation; either version 3 of the License, or (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 19 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along with this 22 | * program; if not, see . 23 | * 24 | * Web: http://www.cszb.net 25 | * Mail: software@cszb.net 26 | """ 27 | legal_notice_end = """ */""" 28 | 29 | def updateLegalHeaderInFile(file): 30 | # read file 31 | f = open(file) 32 | data = f.read() 33 | f.close() 34 | 35 | # look for existing legal notice 36 | start = data.find(legal_notice_begin) 37 | end = data.find(legal_notice_end) 38 | newdata = '' 39 | 40 | if (start == -1 or end == -1): 41 | # no legal notice found, add one 42 | newdata = legal_notice_begin + legal_notice + legal_notice_end + '\n\n' + data 43 | 44 | else: 45 | # legal notice found, check whether a update is necessary: 46 | start2 = start + len(legal_notice_begin) 47 | oldNotice = data[start2:end] 48 | if (oldNotice != legal_notice): 49 | # update necessary 50 | newdata = data[:start2] + legal_notice + data[end:] 51 | else: 52 | # no update necessary 53 | return 54 | 55 | # save changes 56 | f = open(file, "w") 57 | f.write(newdata) 58 | f.close() 59 | print('Updated "' + file + '"') 60 | 61 | def walkDirectory(directory): 62 | for root, dirs, files in os.walk(directory): 63 | for dir in dirsToIgnore: 64 | try: 65 | dirs.remove(dir) 66 | except ValueError: 67 | pass 68 | for file in files: 69 | if (file.endswith('.cs')): 70 | updateLegalHeaderInFile(root + '\\' + file) 71 | 72 | if (len(sys.argv) > 1): 73 | for file in sys.argv[1:]: 74 | if (os.path.exists(file)): 75 | walkDirectory(file) 76 | else: 77 | walkDirectory(os.getcwd()) 78 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/MyLinkedList.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Drawing; 24 | 25 | namespace CityTrafficSimulator 26 | { 27 | /// 28 | /// Wrapperklasse einer LinkedList, welche einen Standardaccessor hat, damit die Liste serialisiert werden kann 29 | /// 30 | /// Typ der Elemente, die in der LinkedListe gespeichert werden sollen 31 | [Serializable] 32 | public class MyLinkedList : LinkedList 33 | { 34 | /// 35 | /// Standardaccessor der LinkedList 36 | /// Gibt oder Setzt das Element Nr. j von vorn 37 | /// 38 | /// Elementnummer, auf das zugegriffen werden soll 39 | /// 40 | public T this[int j] 41 | { 42 | get 43 | { 44 | LinkedListNode toreturn = this.First; 45 | for (int i = 1; i <= j; i++) 46 | { 47 | if (toreturn == null) 48 | { 49 | throw new IndexOutOfRangeException(); 50 | } 51 | toreturn = toreturn.Next; 52 | } 53 | return toreturn.Value; 54 | } 55 | set 56 | { 57 | LinkedListNode toreturn = this.First; 58 | for (int i = 1; i <= j; i++) 59 | { 60 | toreturn = toreturn.Next; 61 | if (toreturn == null) 62 | { 63 | throw new IndexOutOfRangeException(); 64 | } 65 | } 66 | toreturn.Value = value; 67 | } 68 | } 69 | 70 | /// 71 | /// fügt das Element toadd am Ende der verketteten Liste an 72 | /// 73 | /// hinzuzufügendes Element 74 | public void Add(T toadd) 75 | { 76 | this.AddLast(toadd); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Dieser Code wurde von einem Tool generiert. 4 | // Laufzeitversion:4.0.30319.18444 5 | // 6 | // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn 7 | // der Code erneut generiert wird. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CityTrafficSimulator.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. 17 | /// 18 | // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert 19 | // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. 20 | // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen 21 | // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CityTrafficSimulator.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle 51 | /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /CityTrafficSimulator/GlobalTime.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator 25 | { 26 | /// 27 | /// Singleton class for global simulation time 28 | /// 29 | public class GlobalTime 30 | { 31 | #region Singleton stuff 32 | 33 | /// 34 | /// Singleton instance 35 | /// 36 | private static readonly GlobalTime _instance = new GlobalTime(); 37 | 38 | /// 39 | /// Singleton instance 40 | /// 41 | public static GlobalTime Instance 42 | { 43 | get { return _instance; } 44 | } 45 | 46 | /// 47 | /// Private Constructor - only to be used by singleton itsself. 48 | /// 49 | private GlobalTime() 50 | { 51 | currentTime = 0; 52 | cycleTime = 50; 53 | ticksPerSecond = 15; 54 | } 55 | 56 | #endregion 57 | 58 | #region Fields and Variables 59 | 60 | /// 61 | /// cycle time 62 | /// 63 | public double cycleTime { get; private set; } 64 | 65 | /// 66 | /// Number of ticks per second 67 | /// 68 | public double ticksPerSecond { get; private set; } 69 | 70 | /// 71 | /// current simulation time 72 | /// 73 | public double currentTime { get; private set; } 74 | 75 | /// 76 | /// current simulation time casted to float 77 | /// 78 | public float currentTimeAsFloat 79 | { 80 | get { return (float)currentTime; } 81 | } 82 | 83 | /// 84 | /// current tick number modulo cycle time 85 | /// 86 | public int currentCycleTick 87 | { 88 | get { return (int)((currentTime % cycleTime) * ticksPerSecond); } 89 | } 90 | 91 | 92 | #endregion 93 | 94 | #region Methods 95 | 96 | /// 97 | /// Advances current time by time. 98 | /// 99 | /// Time to add to current time 100 | public void Advance(double time) 101 | { 102 | currentTime += time; 103 | } 104 | 105 | /// 106 | /// Resets current time to 0. 107 | /// 108 | public void Reset() 109 | { 110 | currentTime = 0; 111 | } 112 | 113 | /// 114 | /// Updates cylce time and ticks per second parameters. 115 | /// 116 | /// Cycle time 117 | /// Number of ticks/second 118 | public void UpdateSimulationParameters(double cycleTime, double ticksPerSecond) 119 | { 120 | this.cycleTime = cycleTime; 121 | this.ticksPerSecond = ticksPerSecond; 122 | } 123 | 124 | #endregion 125 | 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /CityTrafficSimulator/GlobalRandom.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator 25 | { 26 | /// 27 | /// Singleton class for global random number generation 28 | /// 29 | public class GlobalRandom 30 | { 31 | #region Singleton stuff 32 | 33 | /// 34 | /// Singleton instance 35 | /// 36 | private static readonly GlobalRandom _instance = new GlobalRandom(); 37 | 38 | /// 39 | /// Singleton instance 40 | /// 41 | public static GlobalRandom Instance 42 | { 43 | get { return _instance; } 44 | } 45 | 46 | /// 47 | /// Private Constructor - only to be used by singleton itsself. 48 | /// 49 | private GlobalRandom() 50 | { 51 | _random = new Random(42); 52 | } 53 | 54 | #endregion 55 | 56 | #region Members 57 | 58 | /// 59 | /// random number generator 60 | /// 61 | private Random _random; 62 | 63 | #endregion 64 | 65 | #region Methods 66 | 67 | /// 68 | /// Resets the random number generator by the given seed 69 | /// 70 | /// seed for the random number generator 71 | public void Reset(int seed) 72 | { 73 | _random = new Random(seed); 74 | } 75 | 76 | /// 77 | /// Returns the next random int 78 | /// 79 | /// 80 | public int Next() 81 | { 82 | return _random.Next(); 83 | } 84 | 85 | /// 86 | /// Returns the next random non-negative int which is smaller than maxValue. 87 | /// 88 | /// maximum value 89 | /// a random non-negative int which is smaller than maxValue. 90 | public int Next(int maxValue) 91 | { 92 | return _random.Next(maxValue); 93 | } 94 | 95 | /// 96 | /// Returns the next random non-negative int which is smaller than maxValue and greater than or equals minValue. 97 | /// 98 | /// minimum value 99 | /// maximum value 100 | /// a random non-negative int which is smaller than maxValue and greater than or equals minValue 101 | public int Next(int minValue, int maxValue) 102 | { 103 | return _random.Next(minValue, maxValue); 104 | } 105 | 106 | /// 107 | /// Returns the next random double value in [0, 1). 108 | /// 109 | /// a random double value in [0, 1). 110 | public double NextDouble() 111 | { 112 | return _random.NextDouble(); 113 | } 114 | 115 | #endregion 116 | 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Vehicle/Constants.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator 25 | { 26 | /// 27 | /// statische Klasse, die lediglich einige wichtige Konstanten rund um Vehicles global speichert 28 | /// 29 | internal static class Constants 30 | { 31 | /// 32 | /// Zeitspanne in Sekunden, die in vorausgerechnet werden soll 33 | /// 34 | public const double lookaheadTime = 16; 35 | 36 | /// 37 | /// Entfernung, die vorausgerechnet werden soll 38 | /// 39 | public const double lookaheadDistance = 768; 40 | 41 | /// 42 | /// maximale Entfernung, die ein LineChangePoint entfernt sein darf, damit er benutzt wird 43 | /// 44 | public const double maxDistanceToLineChangePoint = 28; 45 | 46 | 47 | /// 48 | /// maximale Entfernung zwischen zwei parallelen NodeConnections, für einen LineChangePoint 49 | /// 50 | public const double maxDistanceToParallelConnection = 48; 51 | 52 | /// 53 | /// maximaler Winkel zwischen zwei NodeConnections, damit sie für LineChangePoints als parallel angesehen werden 54 | /// 55 | public const double maximumAngleBetweenConnectionsForLineChangePoint = Math.PI / 8; 56 | 57 | /// 58 | /// Standardkapazität der LineChangeInterval-Dictionaries 59 | /// 60 | public const int defaultLineChangeIntervalDictionaryCapacity = 16; 61 | 62 | 63 | /// 64 | /// pauschale Kosten bei der Wegberechnung für einen Spurwechsel 65 | /// 66 | public const double lineChangePenalty = 1536; 67 | 68 | /// 69 | /// pauschale Kosten bei der Wegberechnung für einen Spurwechsel direkt vor einer Ampel 70 | /// 71 | public const double lineChangeBeforeTrafficLightPenalty = lineChangePenalty * 4; 72 | 73 | 74 | /// 75 | /// maximales Verhältnis Wegkosten/Wegkosten nach Spurwechsel, bis zu dem noch ein freiwilliger Spurwechsel durchgeführt werden soll 76 | /// 77 | public const double maxRatioForVoluntaryLineChange = 1.25; 78 | 79 | /// 80 | /// maximales Verhältnis Wegkoste nnach Spurwechsel/Wegkosten ohne Spurwechsel, bis zu dem auf ein einen eigentlich zwangsweisen Spurwechsel verzichtet werden soll 81 | /// 82 | public const double maxRatioForEnforcedLineChange = 2; 83 | 84 | 85 | /// 86 | /// pauschale Kosten bei der Wegberechnung für Fahrzeug was auf dem geplanten Weg fährt 87 | /// 88 | public const double vehicleOnRoutePenalty = 48; 89 | 90 | /// 91 | /// minimale Länge eines LineChangeIntervals, damit es für die Wegberechnung berücksichtigt wird 92 | /// 93 | public const double minimumLineChangeLength = 192; 94 | 95 | /// 96 | /// distance to end of LineChangeInterval where the vehicle shal stop in case of a forced line change 97 | /// 98 | public const double breakPointBeforeForcedLineChange = 48; 99 | 100 | /// 101 | /// lookahead distance for intersections 102 | /// 103 | public const double intersectionLookaheadDistance = 384; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /CityTrafficSimulator/AboutBox/AboutBox.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.ComponentModel; 23 | using System.Drawing; 24 | using System.Reflection; 25 | using System.Windows.Forms; 26 | 27 | namespace CityTrafficSimulator 28 | { 29 | partial class AboutBox : Form 30 | { 31 | public AboutBox() 32 | { 33 | InitializeComponent(); 34 | /* 35 | this.Text = String.Format("Info über {0} {0}", AssemblyTitle); 36 | this.labelProductName.Text = AssemblyProduct; 37 | this.labelVersion.Text = String.Format("Version {0} {0}", AssemblyVersion); 38 | this.labelCopyright.Text = AssemblyCopyright; 39 | this.labelCompanyName.Text = AssemblyCompany; 40 | this.textBoxDescription.Text = AssemblyDescription; 41 | * */ 42 | } 43 | 44 | #region Assemblyattributaccessoren 45 | 46 | public string AssemblyTitle 47 | { 48 | get 49 | { 50 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); 51 | if (attributes.Length > 0) 52 | { 53 | AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0]; 54 | if (titleAttribute.Title != "") 55 | { 56 | return titleAttribute.Title; 57 | } 58 | } 59 | return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); 60 | } 61 | } 62 | 63 | public string AssemblyVersion 64 | { 65 | get 66 | { 67 | return Assembly.GetExecutingAssembly().GetName().Version.ToString(); 68 | } 69 | } 70 | 71 | public string AssemblyDescription 72 | { 73 | get 74 | { 75 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); 76 | if (attributes.Length == 0) 77 | { 78 | return ""; 79 | } 80 | return ((AssemblyDescriptionAttribute)attributes[0]).Description; 81 | } 82 | } 83 | 84 | public string AssemblyProduct 85 | { 86 | get 87 | { 88 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); 89 | if (attributes.Length == 0) 90 | { 91 | return ""; 92 | } 93 | return ((AssemblyProductAttribute)attributes[0]).Product; 94 | } 95 | } 96 | 97 | public string AssemblyCopyright 98 | { 99 | get 100 | { 101 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); 102 | if (attributes.Length == 0) 103 | { 104 | return ""; 105 | } 106 | return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; 107 | } 108 | } 109 | 110 | public string AssemblyCompany 111 | { 112 | get 113 | { 114 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); 115 | if (attributes.Length == 0) 116 | { 117 | return ""; 118 | } 119 | return ((AssemblyCompanyAttribute)attributes[0]).Company; 120 | } 121 | } 122 | #endregion 123 | 124 | private void okButton_Click(object sender, EventArgs e) 125 | { 126 | this.Close(); 127 | } 128 | 129 | private void tableLayoutPanel_Paint(object sender, PaintEventArgs e) 130 | { 131 | 132 | } 133 | 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/SortedLinkedList.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Drawing; 24 | 25 | namespace CityTrafficSimulator.Tools 26 | { 27 | /// 28 | /// Wrapperklasse einer LinkedList, welche eine Vergleichsfunktion besitzt und so die beherbergten Elemente automatisch sortiert hält. 29 | /// 30 | /// Typ der Elemente, die in der LinkedListe gespeichert werden sollen 31 | public class SortedLinkedList : LinkedList 32 | { 33 | /// 34 | /// Delegatedefinition für Vergleichsfunktion 35 | /// 36 | /// erster zu vergleichender Wert 37 | /// zweiter zu vergleichender Wert 38 | /// -1 falls a echt kleiner b, 0 falls a=b, 1 falls a echt größer b 39 | public delegate int CompareDelegate(T a, T b); 40 | 41 | /// 42 | /// Vergleichsfunktion 43 | /// 44 | private CompareDelegate _comparer; 45 | /// 46 | /// Vergleichsfunktion 47 | /// 48 | public CompareDelegate comparer 49 | { 50 | get { return _comparer; } 51 | set { _comparer = value; } 52 | } 53 | 54 | /// 55 | /// Standardaccessor der LinkedList 56 | /// Gibt oder Setzt das Element Nr. j von vorn 57 | /// 58 | /// 59 | /// 60 | public T this[int j] 61 | { 62 | get 63 | { 64 | LinkedListNode toreturn = this.First; 65 | for (int i = 1; i <= j; i++) 66 | { 67 | if (toreturn == null) 68 | { 69 | throw new IndexOutOfRangeException(); 70 | } 71 | toreturn = toreturn.Next; 72 | } 73 | return toreturn.Value; 74 | } 75 | set 76 | { 77 | LinkedListNode toreturn = this.First; 78 | for (int i = 1; i <= j; i++) 79 | { 80 | toreturn = toreturn.Next; 81 | if (toreturn == null) 82 | { 83 | throw new IndexOutOfRangeException(); 84 | } 85 | } 86 | toreturn.Value = value; 87 | } 88 | } 89 | 90 | /// 91 | /// Standardkonstruktor, der einen Comparer entgegennimmt 92 | /// 93 | /// Vergleichsfunktion 94 | public SortedLinkedList(CompareDelegate comparer) 95 | { 96 | this.comparer = comparer; 97 | } 98 | 99 | /// 100 | /// leerer Standardkonstruktor - nicht implementiert! 101 | /// 102 | public SortedLinkedList() 103 | { 104 | throw new NotImplementedException(); 105 | } 106 | 107 | /// 108 | /// fügt toadd der SortedLinkedList hinzu und sorgt dafür, dass die Liste sortiert bleibt 109 | /// 110 | /// hinzuzufügendes Element 111 | /// LinkedListNode, der das hinzugefügte Element enthält 112 | public LinkedListNode Add(T toadd) 113 | { 114 | LinkedListNode lln = this.First; 115 | 116 | while (lln != null && comparer(toadd, lln.Value) == 1) 117 | { 118 | lln = lln.Next; 119 | } 120 | 121 | if (lln != null) 122 | { 123 | /* if (comparer(toadd, lln.Value) == 0) 124 | return lln; 125 | else*/ 126 | return this.AddBefore(lln, toadd); 127 | } 128 | else 129 | return this.AddLast(toadd); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Verkehr/BunchOfNodes.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Xml; 24 | using System.Xml.Serialization; 25 | 26 | 27 | namespace CityTrafficSimulator.Verkehr 28 | { 29 | /// 30 | /// Ansammlung von LineNodes, die unter einem Namen zusammengefasst wird 31 | /// 32 | [Serializable] 33 | public class BunchOfNodes : ISavable 34 | { 35 | #region Hashcodes 36 | 37 | /// 38 | /// Class variable which stores the last used hash code - needs to be incremented on every class instantiation. 39 | /// 40 | public static int hashcodeIndex = 0; 41 | 42 | /// 43 | /// Hash code of this very object. 44 | /// 45 | public int hashcode = -1; 46 | 47 | #endregion 48 | 49 | #region Klassenmember 50 | 51 | /// 52 | /// Name dieser Ansammlung von LineNodes 53 | /// 54 | private string _title; 55 | /// 56 | /// Name dieser Ansammlung von LineNodes 57 | /// 58 | public string title 59 | { 60 | get { return _title; } 61 | set { _title = value; } 62 | } 63 | 64 | /// 65 | /// Liste der teilnehmenden LineNodes 66 | /// 67 | [XmlIgnore] 68 | private List _nodes = new List(); 69 | /// 70 | /// Liste der teilnehmenden LineNodes 71 | /// 72 | [XmlIgnore] 73 | public List nodes 74 | { 75 | get { return _nodes; } 76 | set { _nodes = value; } 77 | } 78 | 79 | #endregion 80 | 81 | #region Konstruktoren & Methoden 82 | 83 | /// 84 | /// Erstellt eine neue leere BunchOfNodes mit dem Titel title 85 | /// 86 | /// List of nodes for this BunchOfNodes 87 | /// Titel dieser Ansammlung von Nodes 88 | public BunchOfNodes(List nodes, string title) 89 | { 90 | hashcode = hashcodeIndex++; 91 | 92 | this._nodes = nodes; 93 | this._title = title; 94 | } 95 | 96 | /// 97 | /// DO NOT USE: Empty Constructor - only needed for XML Serialization 98 | /// 99 | public BunchOfNodes() 100 | { 101 | } 102 | 103 | /// 104 | /// Returns the title of this bunch of nodes 105 | /// 106 | /// this.title 107 | public override string ToString() 108 | { 109 | return _title; 110 | } 111 | 112 | #endregion 113 | 114 | 115 | #region ISavable Member 116 | 117 | /// 118 | /// Hashwerte der Startknoten (nur für XML-Serialisierung benötigt) 119 | /// 120 | public List nodeHashes = new List(); 121 | 122 | /// 123 | /// Bereitet den Fahrauftrag für die XML-Serialisierung vor 124 | /// 125 | public void PrepareForSave() 126 | { 127 | nodeHashes.Clear(); 128 | foreach (LineNode ln in _nodes) 129 | nodeHashes.Add(ln.GetHashCode()); 130 | } 131 | 132 | /// 133 | /// Stellt die Referenzen auf LineNodes wieder her 134 | /// (auszuführen nach XML-Deserialisierung) 135 | /// 136 | /// Version der gespeicherten Datei 137 | /// Liste der bereits wiederhergestellten LineNodes 138 | public void RecoverFromLoad(int saveVersion, List nodesList) 139 | { 140 | foreach (LineNode ln in nodesList) 141 | { 142 | if (nodeHashes.Contains(ln.GetHashCode())) 143 | _nodes.Add(ln); 144 | } 145 | } 146 | 147 | #endregion 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Vehicle/VehicleDistance.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator.Vehicle 25 | { 26 | /// 27 | /// kapselt ein Vehicle und Distanz. 28 | /// TODO: sollte eigentlich ein struct sein, wird aber z.T. mit null initialisert, daher noch eine class... das ist unschön 29 | /// 30 | public class VehicleDistance 31 | { 32 | /// 33 | /// Fahrzeug mit Distanz distance 34 | /// 35 | public IVehicle vehicle; 36 | /// 37 | /// Distanz zum Fahrzeug vehicle 38 | /// 39 | public double distance; 40 | 41 | 42 | /// 43 | /// Standardkonstruktor 44 | /// 45 | /// Fahrzeug, welches gekapselt wird 46 | /// Distanz, die gekapselt wird 47 | public VehicleDistance(IVehicle vehicle, double distance) 48 | { 49 | this.distance = distance; 50 | this.vehicle = vehicle; 51 | } 52 | 53 | /// 54 | /// Returns the VehicleDistance with the smaller distance. 55 | /// 56 | /// Left object to compare 57 | /// Right object to compare 58 | /// The one with the smaller distance. The other if one is null. 59 | public static VehicleDistance Min(VehicleDistance lhs, VehicleDistance rhs) 60 | { 61 | if (lhs == null) 62 | return rhs; 63 | if (rhs == null) 64 | return lhs; 65 | return (lhs.distance < rhs.distance) ? lhs : rhs; 66 | } 67 | 68 | /// 69 | /// Returns the VehicleDistance with the greater distance. 70 | /// 71 | /// Left object to compare 72 | /// Right object to compare 73 | /// The one with the greater distance. The other if one is null. 74 | public static VehicleDistance Max(VehicleDistance lhs, VehicleDistance rhs) 75 | { 76 | if (lhs == null) 77 | return rhs; 78 | if (rhs == null) 79 | return lhs; 80 | return (lhs.distance > rhs.distance) ? lhs : rhs; 81 | } 82 | 83 | 84 | /// 85 | /// Returns the VehicleDistance with the smaller distance to the tail of the vehicle. 86 | /// 87 | /// Left object to compare 88 | /// Right object to compare 89 | /// The one with the smaller distance to the tail of the vehicle. The other if one is null. 90 | public static VehicleDistance MinTail(VehicleDistance lhs, VehicleDistance rhs) 91 | { 92 | if (lhs == null) 93 | return rhs; 94 | if (rhs == null) 95 | return lhs; 96 | return (lhs.distance - lhs.vehicle.length < rhs.distance - rhs.vehicle.length) ? lhs : rhs; 97 | } 98 | 99 | 100 | /// 101 | /// Checks if the distance of lhs is smaller than the distance of rhs. 102 | /// 103 | /// Left object to compare 104 | /// Right object to compare 105 | /// lhs.distance smaller rhs.distance 106 | public static bool operator < (VehicleDistance lhs, VehicleDistance rhs) 107 | { 108 | return lhs.distance < rhs.distance; 109 | } 110 | 111 | /// 112 | /// Checks if the distance of lhs is greater than the distance of rhs. 113 | /// 114 | /// Left object to compare 115 | /// Right object to compare 116 | /// lhs.distance greater rhs.distance 117 | public static bool operator >(VehicleDistance lhs, VehicleDistance rhs) 118 | { 119 | return lhs.distance > rhs.distance; 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /CityTrafficSimulator/LoadingForm/LoadingForm.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.ComponentModel; 23 | using System.Data; 24 | using System.Drawing; 25 | using System.Text; 26 | using System.Windows.Forms; 27 | 28 | namespace CityTrafficSimulator.LoadingForm 29 | { 30 | /// 31 | /// Sehr simples Formular zur Fortschrittsanzeige des Ladevorganges 32 | /// 33 | public partial class LoadingForm : Form 34 | { 35 | /// 36 | /// Log messages 37 | /// 38 | private StringBuilder logMessages = new StringBuilder(); 39 | 40 | /// 41 | /// Number of logged messages 42 | /// 43 | private int numLogs = 0; 44 | 45 | /// 46 | /// Standardkonstruktor 47 | /// 48 | public LoadingForm() 49 | { 50 | InitializeComponent(); 51 | } 52 | 53 | /// 54 | /// Aktualisiert die Anzeige 55 | /// 56 | public override void Refresh() 57 | { 58 | // ja es ist eigentlich Bullshit den Programmablauf aufzuhalten, nur um eine richtige 59 | // Fortschrittsanzeige zu haben, aber form follows function 60 | System.Threading.Thread.Sleep(40); 61 | base.Refresh(); 62 | } 63 | 64 | /// 65 | /// setzt die Anzahl der Schritte für den upperProgress 66 | /// 67 | /// Beschreibung des aktuellen Schrittes 68 | /// Anzahl der insgesamt benötigten Schritte im upperProgress 69 | public void SetupUpperProgress(string stepName, int stepCount) 70 | { 71 | upperLabel.Text = stepName; 72 | upperProgress.Maximum = stepCount; 73 | upperProgress.Value = 0; 74 | 75 | Refresh(); 76 | } 77 | 78 | /// 79 | /// setzt den upperProgress einen Schritt weiter 80 | /// 81 | /// Beschreibung des aktuellen Schrittes 82 | public void StepUpperProgress(string stepName) 83 | { 84 | upperLabel.Text = stepName; 85 | upperProgress.PerformStep(); 86 | 87 | Refresh(); 88 | } 89 | 90 | /// 91 | /// setzt den upperProgress einen Schritt weiter 92 | /// 93 | public void StepUpperProgress() 94 | { 95 | upperProgress.PerformStep(); 96 | 97 | Refresh(); 98 | } 99 | 100 | 101 | /// 102 | /// setzt die Beschreibung und Anzahl Schritte für den lowerProgress 103 | /// 104 | /// Beschreibung des aktuellen Vorgangs 105 | /// Anzahl ingesamt benötigter Schritte im lowerProgress 106 | public void SetupLowerProgess(string stepName, int stepCount) 107 | { 108 | StepUpperProgress(); 109 | 110 | lowerLabel.Text = stepName; 111 | lowerProgress.Maximum = stepCount; 112 | lowerProgress.Value = 0; 113 | lowerLabel.Refresh(); 114 | lowerProgress.Refresh(); 115 | } 116 | 117 | /// 118 | /// setzt den lowerProgress einen Schritt weiter 119 | /// 120 | public void StepLowerProgress() 121 | { 122 | lowerProgress.PerformStep(); 123 | lowerProgress.Refresh(); 124 | } 125 | 126 | /// 127 | /// Append the given message to the log. 128 | /// 129 | /// message to log 130 | public void Log(string message) 131 | { 132 | logMessages.AppendLine(message); 133 | ++numLogs; 134 | } 135 | 136 | /// 137 | /// Shows a dialog with all logged messages 138 | /// 139 | public void ShowLog() 140 | { 141 | if (numLogs > 0) 142 | { 143 | MessageBox.Show(numLogs.ToString() + " error(s) occured:\n" + logMessages.ToString()); 144 | } 145 | } 146 | 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Timeline/TimelineBlockingEvent.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Drawing; 24 | 25 | namespace CityTrafficSimulator.Timeline 26 | { 27 | /// 28 | /// TimelineEvent for blocking the interim times of the parent TimelineEvent on this TimelineEntry 29 | /// 30 | public class TimelineBlockingEvent : TimelineEvent 31 | { 32 | 33 | #region Members and Properties 34 | 35 | /// 36 | /// The parent TimelineEvent this event is blocking for 37 | /// 38 | private TimelineEvent _parentEvent; 39 | /// 40 | /// The parent TimelineEvent this event is blocking for 41 | /// 42 | public TimelineEvent parentEvent 43 | { 44 | get { return _parentEvent; } 45 | set { _parentEvent = value; } 46 | } 47 | 48 | /// 49 | /// Interim time (offset) between parent event and this blocking event 50 | /// 51 | private double _interimTime; 52 | /// 53 | /// Interim time (offset) between parent event and this blocking event 54 | /// 55 | public double interimTime 56 | { 57 | get { return _interimTime; } 58 | set { _interimTime = value; } 59 | } 60 | 61 | /// 62 | /// Additional buffer time before event 63 | /// 64 | private double _bufferTimeBefore; 65 | /// 66 | /// Additional buffer time before event 67 | /// 68 | public double bufferTimeBefore 69 | { 70 | get { return _bufferTimeBefore; } 71 | set { _bufferTimeBefore = value; } 72 | } 73 | 74 | /// 75 | /// Additional buffer time after event 76 | /// 77 | private double _bufferTimeAfter; 78 | /// 79 | /// Additional buffer time after event 80 | /// 81 | public double bufferTimeAfter 82 | { 83 | get { return _bufferTimeAfter; } 84 | set { _bufferTimeAfter = value; } 85 | } 86 | 87 | 88 | #endregion 89 | 90 | #region Methods 91 | 92 | /// 93 | /// Creates a new TimelineBlockingEvent. 94 | /// 95 | /// The parent TimelineEvent this event is blocking for 96 | /// Interim time (offset) between parent event and this blocking event 97 | /// Additional buffer time before event 98 | /// Additional buffer time after event 99 | public TimelineBlockingEvent(TimelineEvent parentEvent, double interimTime, double bufferTimeBefore, double bufferTimeAfter) 100 | : base( 101 | parentEvent.eventTime + interimTime - bufferTimeBefore, 102 | parentEvent.eventLength + bufferTimeBefore + bufferTimeAfter, 103 | Color.DarkGray, 104 | delegate() {}, 105 | delegate() {}) 106 | { 107 | this.parentEvent = parentEvent; 108 | this.interimTime = interimTime; 109 | this.bufferTimeBefore = bufferTimeBefore; 110 | this.bufferTimeAfter = bufferTimeAfter; 111 | 112 | parentEvent.EventTimesChanged += new EventTimesChangedEventHandler(parentEvent_EventTimesChanged); 113 | } 114 | 115 | /// 116 | /// Adjusts the time of this event to the timing of the parent event 117 | /// 118 | protected void adjustEventTimesToParentEvent() 119 | { 120 | eventTime = parentEvent.eventTime + interimTime - bufferTimeBefore; 121 | eventLength = parentEvent.eventLength + bufferTimeBefore + bufferTimeAfter; 122 | } 123 | 124 | #endregion 125 | 126 | #region EventHandlers 127 | 128 | void parentEvent_EventTimesChanged(object sender, TimelineEvent.EventTimesChangedEventArgs e) 129 | { 130 | adjustEventTimesToParentEvent(); 131 | } 132 | 133 | #endregion 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /CityTrafficSimulator/LoadingForm/LoadingForm.Designer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | namespace CityTrafficSimulator.LoadingForm 21 | { 22 | partial class LoadingForm 23 | { 24 | /// 25 | /// Required designer variable. 26 | /// 27 | private System.ComponentModel.IContainer components = null; 28 | 29 | /// 30 | /// Clean up any resources being used. 31 | /// 32 | /// true if managed resources should be disposed; otherwise, false. 33 | protected override void Dispose(bool disposing) 34 | { 35 | if (disposing && (components != null)) 36 | { 37 | components.Dispose(); 38 | } 39 | base.Dispose(disposing); 40 | } 41 | 42 | #region Windows Form Designer generated code 43 | 44 | /// 45 | /// Required method for Designer support - do not modify 46 | /// the contents of this method with the code editor. 47 | /// 48 | private void InitializeComponent() 49 | { 50 | this.upperProgress = new System.Windows.Forms.ProgressBar(); 51 | this.upperLabel = new System.Windows.Forms.Label(); 52 | this.lowerLabel = new System.Windows.Forms.Label(); 53 | this.lowerProgress = new System.Windows.Forms.ProgressBar(); 54 | this.SuspendLayout(); 55 | // 56 | // upperProgress 57 | // 58 | this.upperProgress.Location = new System.Drawing.Point(12, 42); 59 | this.upperProgress.Maximum = 8; 60 | this.upperProgress.Name = "upperProgress"; 61 | this.upperProgress.Size = new System.Drawing.Size(429, 23); 62 | this.upperProgress.Step = 1; 63 | this.upperProgress.TabIndex = 0; 64 | // 65 | // upperLabel 66 | // 67 | this.upperLabel.Location = new System.Drawing.Point(12, 9); 68 | this.upperLabel.Name = "upperLabel"; 69 | this.upperLabel.Size = new System.Drawing.Size(429, 30); 70 | this.upperLabel.TabIndex = 1; 71 | this.upperLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 72 | // 73 | // lowerLabel 74 | // 75 | this.lowerLabel.Location = new System.Drawing.Point(12, 68); 76 | this.lowerLabel.Name = "lowerLabel"; 77 | this.lowerLabel.Size = new System.Drawing.Size(429, 30); 78 | this.lowerLabel.TabIndex = 3; 79 | this.lowerLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 80 | // 81 | // lowerProgress 82 | // 83 | this.lowerProgress.Location = new System.Drawing.Point(12, 101); 84 | this.lowerProgress.Name = "lowerProgress"; 85 | this.lowerProgress.Size = new System.Drawing.Size(429, 23); 86 | this.lowerProgress.Step = 1; 87 | this.lowerProgress.TabIndex = 2; 88 | // 89 | // LoadingForm 90 | // 91 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 92 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 93 | this.ClientSize = new System.Drawing.Size(453, 155); 94 | this.ControlBox = false; 95 | this.Controls.Add(this.lowerLabel); 96 | this.Controls.Add(this.lowerProgress); 97 | this.Controls.Add(this.upperLabel); 98 | this.Controls.Add(this.upperProgress); 99 | this.DoubleBuffered = true; 100 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 101 | this.Name = "LoadingForm"; 102 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 103 | this.Text = "Laden..."; 104 | this.TopMost = true; 105 | this.ResumeLayout(false); 106 | 107 | } 108 | 109 | #endregion 110 | 111 | /// 112 | /// Beschriftung des oberen Fortschrittsbalkens 113 | /// 114 | public System.Windows.Forms.Label upperLabel; 115 | /// 116 | /// Beschriftung des unteren Fortschrittsbalkens 117 | /// 118 | public System.Windows.Forms.Label lowerLabel; 119 | /// 120 | /// unterer Fortschrittsbalken 121 | /// 122 | public System.Windows.Forms.ProgressBar lowerProgress; 123 | /// 124 | /// oberer Fortschrittsbalken 125 | /// 126 | public System.Windows.Forms.ProgressBar upperProgress; 127 | 128 | } 129 | } -------------------------------------------------------------------------------- /CityTrafficSimulator/Vehicle/Bus.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Drawing; 24 | using System.Drawing.Drawing2D; 25 | 26 | namespace CityTrafficSimulator.Vehicle 27 | { 28 | class Bus : IVehicle 29 | { 30 | public Bus(IVehicle.Physics p) 31 | { 32 | length = (GlobalRandom.Instance.Next(2) == 0) ? 120 : 180; 33 | 34 | _physics = p; 35 | color = Color.FromArgb(GlobalRandom.Instance.Next(256), GlobalRandom.Instance.Next(256), GlobalRandom.Instance.Next(256)); 36 | _vehicleType = VehicleTypes.BUS; 37 | 38 | // maximale Beschleunigung 39 | a = 0.9; 40 | 41 | // komfortable Bremsverzögerung 42 | b = 1.0; 43 | } 44 | 45 | /// 46 | /// Berechnet die Absolute Position zur Bogenlängenposition pos. 47 | /// Kann auch mit negativen Positionsangaben umgehen 48 | /// 49 | /// Bogenlängenposition 50 | /// Weltkoordinaten zu Bogenlängenposition pos 51 | private Vector2 GetPositionAbsAtArcPos(double pos) 52 | { 53 | if (pos >= 0) 54 | return currentNodeConnection.lineSegment.AtPosition(pos); 55 | else 56 | { 57 | double remainingDistance = -pos; 58 | foreach (NodeConnection nc in visitedNodeConnections) 59 | { 60 | if (nc.lineSegment.length < remainingDistance) 61 | { 62 | remainingDistance -= nc.lineSegment.length; 63 | continue; 64 | } 65 | else 66 | { 67 | return nc.lineSegment.AtPosition(nc.lineSegment.length - remainingDistance); 68 | } 69 | } 70 | } 71 | return state.positionAbs; 72 | } 73 | 74 | /// 75 | /// Generates the GraphicsPath for rendering the vehicle. Should be overloaded by subclasses with distinct rendering. 76 | /// 77 | /// A GraphicsPath in world coordinates for rendering the vehicle at the current position. 78 | protected override GraphicsPath BuildGraphicsPath() 79 | { 80 | GraphicsPath toReturn = new GraphicsPath(); 81 | 82 | // Solobus 83 | if (_length == 120) 84 | { 85 | Vector2[] positions = { 86 | state.positionAbs, 87 | GetPositionAbsAtArcPos(currentPosition - 120), 88 | }; 89 | if ((positions[0] - positions[1]).IsNotZeroVector()) 90 | { 91 | Vector2[] normals = { 92 | (positions[0] - positions[1]).RotatedClockwise.Normalized, 93 | }; 94 | 95 | PointF[] frontPoints = { 96 | positions[0] - 11*normals[0], 97 | positions[0] + 11*normals[0], 98 | positions[1] + 11*normals[0], 99 | positions[1] - 11*normals[0], 100 | }; 101 | 102 | toReturn.AddPolygon(frontPoints); 103 | } 104 | } 105 | // Gelenkbus 106 | else 107 | { 108 | Vector2[] positions = { 109 | state.positionAbs, 110 | GetPositionAbsAtArcPos(currentPosition - 100), 111 | GetPositionAbsAtArcPos(currentPosition - 105), 112 | GetPositionAbsAtArcPos(currentPosition - 180) 113 | }; 114 | if ((positions[0] - positions[1]).IsNotZeroVector() && (positions[2] - positions[3]).IsNotZeroVector()) 115 | { 116 | Vector2[] normals = { 117 | (positions[0] - positions[1]).RotatedClockwise.Normalized, 118 | (positions[2] - positions[3]).RotatedClockwise.Normalized 119 | }; 120 | 121 | PointF[] frontPoints = { 122 | positions[0] - 11*normals[0], 123 | positions[0] + 11*normals[0], 124 | positions[1] + 11*normals[0], 125 | positions[1] - 11*normals[0], 126 | }; 127 | PointF[] backPoints = { 128 | positions[2] - 11*normals[1], 129 | positions[2] + 11*normals[1], 130 | positions[3] + 11*normals[1], 131 | positions[3] - 11*normals[1], 132 | }; 133 | 134 | toReturn.AddPolygon(frontPoints); 135 | toReturn.AddPolygon(backPoints); 136 | } 137 | } 138 | 139 | return toReturn; 140 | } 141 | 142 | /// 143 | /// Prüfe, ob ich auf der NodeConnection nc fahren darf 144 | /// 145 | /// zu prüfende NodeConnection 146 | /// nc.tramAllowed 147 | public override bool CheckNodeConnectionForSuitability(NodeConnection nc) 148 | { 149 | return nc.busAllowed; 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /CityTrafficSimulator/NetworkLayer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Xml.Serialization; 23 | using System.Text; 24 | 25 | namespace CityTrafficSimulator 26 | { 27 | /// 28 | /// Traffic network layer 29 | /// 30 | [Serializable] 31 | public class NetworkLayer 32 | { 33 | /// 34 | /// Title of this layer 35 | /// 36 | private string _title; 37 | /// 38 | /// Title of this layer 39 | /// 40 | public string title 41 | { 42 | get { return _title; } 43 | set { _title = value; InvokeTitleChanged(new TitleChangedEventArgs()); } 44 | } 45 | 46 | /// 47 | /// Flag whether this layer shall be rendered 48 | /// 49 | private bool _visible; 50 | /// 51 | /// Flag whether this layer shall be rendered 52 | /// 53 | public bool visible 54 | { 55 | get { return _visible; } 56 | set { _visible = value; InvokeVisibleChanged(new VisibleChangedEventArgs()); } 57 | } 58 | 59 | /// 60 | /// Hashcodes of all LineNodes on this NetworkLayer (only used for XML serialization) 61 | /// 62 | public List _nodeHashes = new List(); 63 | 64 | 65 | /// 66 | /// Default constructor 67 | /// 68 | /// Title of this layer 69 | /// Flag whether this layer shall be rendered 70 | public NetworkLayer(string title, bool visible) 71 | { 72 | _title = title; 73 | _visible = visible; 74 | } 75 | 76 | /// 77 | /// Empty default constructor ONLY for (de)serialization. DO NOT USE unless you know what you're doing! 78 | /// 79 | public NetworkLayer() 80 | { 81 | } 82 | 83 | /// 84 | /// Returns a string representation of this NetworkLayer. 85 | /// 86 | /// _title 87 | public override string ToString() 88 | { 89 | return _title; 90 | } 91 | 92 | #region TitleChanged event 93 | 94 | /// 95 | /// EventArgs for a TitleChanged event 96 | /// 97 | public class TitleChangedEventArgs : EventArgs 98 | { 99 | /// 100 | /// Creates new TitleChangedEventArgs 101 | /// 102 | public TitleChangedEventArgs() 103 | { 104 | } 105 | } 106 | 107 | /// 108 | /// Delegate for the TitleChanged-EventHandler, which is called when the title has changed 109 | /// 110 | /// Sneder of the event 111 | /// Event parameter 112 | public delegate void TitleChangedEventHandler(object sender, TitleChangedEventArgs e); 113 | 114 | /// 115 | /// The TitleChanged event occurs when the title has changed 116 | /// 117 | public event TitleChangedEventHandler TitleChanged; 118 | 119 | /// 120 | /// Helper method to initiate the TitleChanged event 121 | /// 122 | /// Event parameters 123 | protected void InvokeTitleChanged(TitleChangedEventArgs e) 124 | { 125 | if (TitleChanged != null) 126 | { 127 | TitleChanged(this, e); 128 | } 129 | } 130 | 131 | #endregion 132 | 133 | #region VisibleChanged event 134 | 135 | /// 136 | /// EventArgs for a VisibleChanged event 137 | /// 138 | public class VisibleChangedEventArgs : EventArgs 139 | { 140 | /// 141 | /// Creates new VisibleChangedEventArgs 142 | /// 143 | public VisibleChangedEventArgs() 144 | { 145 | } 146 | } 147 | 148 | /// 149 | /// Delegate for the VisibleChanged-EventHandler, which is called when the visibility flag has changed 150 | /// 151 | /// Sneder of the event 152 | /// Event parameter 153 | public delegate void VisibleChangedEventHandler(object sender, VisibleChangedEventArgs e); 154 | 155 | /// 156 | /// The VisibleChanged event occurs when the visibility flag has changed 157 | /// 158 | public event VisibleChangedEventHandler VisibleChanged; 159 | 160 | /// 161 | /// Helper method to initiate the VisibleChanged event 162 | /// 163 | /// Event parameters 164 | protected void InvokeVisibleChanged(VisibleChangedEventArgs e) 165 | { 166 | if (VisibleChanged != null) 167 | { 168 | VisibleChanged(this, e); 169 | } 170 | } 171 | 172 | #endregion 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Vehicle/Truck.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Drawing; 24 | using System.Drawing.Drawing2D; 25 | 26 | namespace CityTrafficSimulator.Vehicle 27 | { 28 | class Truck : IVehicle 29 | { 30 | public Truck(IVehicle.Physics p) 31 | { 32 | length = (GlobalRandom.Instance.Next(2) == 0) ? 100 : 165; 33 | 34 | _physics = p; 35 | color = Color.FromArgb(GlobalRandom.Instance.Next(256), GlobalRandom.Instance.Next(256), GlobalRandom.Instance.Next(256)); 36 | 37 | // maximale Beschleunigung 38 | a = 0.6; 39 | 40 | // komfortable Bremsverzögerung 41 | b = 0.7; 42 | 43 | 44 | // etwas Zufall: 45 | a *= (GlobalRandom.Instance.NextDouble() + 0.5); 46 | b *= (GlobalRandom.Instance.NextDouble() + 0.5); 47 | s0 *= (GlobalRandom.Instance.NextDouble() + 0.5); 48 | T *= (GlobalRandom.Instance.NextDouble() + 0.5); 49 | 50 | _physics.targetVelocity += ((GlobalRandom.Instance.NextDouble() - 0.5) * 4); 51 | _vehicleType = VehicleTypes.CAR; 52 | } 53 | 54 | /// 55 | /// Berechnet die Absolute Position zur Bogenlängenposition pos. 56 | /// Kann auch mit negativen Positionsangaben umgehen 57 | /// 58 | /// Bogenlängenposition 59 | /// Weltkoordinaten zu Bogenlängenposition pos 60 | private Vector2 GetPositionAbsAtArcPos(double pos) 61 | { 62 | if (pos >= 0) 63 | return currentNodeConnection.lineSegment.AtPosition(pos); 64 | else 65 | { 66 | double remainingDistance = -pos; 67 | foreach (NodeConnection nc in visitedNodeConnections) 68 | { 69 | if (nc.lineSegment.length < remainingDistance) 70 | { 71 | remainingDistance -= nc.lineSegment.length; 72 | continue; 73 | } 74 | else 75 | { 76 | return nc.lineSegment.AtPosition(nc.lineSegment.length - remainingDistance); 77 | } 78 | } 79 | } 80 | return state.positionAbs; 81 | } 82 | 83 | /// 84 | /// Generates the GraphicsPath for rendering the vehicle. Should be overloaded by subclasses with distinct rendering. 85 | /// 86 | /// A GraphicsPath in world coordinates for rendering the vehicle at the current position. 87 | protected override GraphicsPath BuildGraphicsPath() 88 | { 89 | GraphicsPath toReturn = new GraphicsPath(); 90 | 91 | // LKW 92 | if (_length == 100) 93 | { 94 | Vector2[] positions = { 95 | state.positionAbs, 96 | GetPositionAbsAtArcPos(currentPosition - 100), 97 | }; 98 | if ((positions[0] - positions[1]).IsNotZeroVector()) 99 | { 100 | Vector2[] normals = { 101 | (positions[0] - positions[1]).RotatedClockwise.Normalized, 102 | }; 103 | 104 | PointF[] frontPoints = { 105 | positions[0] - 10*normals[0], 106 | positions[0] + 10*normals[0], 107 | positions[1] + 10*normals[0], 108 | positions[1] - 10*normals[0], 109 | }; 110 | 111 | toReturn.AddPolygon(frontPoints); 112 | } 113 | } 114 | // Sattelzug 115 | else 116 | { 117 | Vector2[] positions = { 118 | state.positionAbs, 119 | GetPositionAbsAtArcPos(currentPosition - 40), 120 | GetPositionAbsAtArcPos(currentPosition - 45), 121 | GetPositionAbsAtArcPos(currentPosition - 165) 122 | }; 123 | if ((positions[0] - positions[1]).IsNotZeroVector() && (positions[2] - positions[3]).IsNotZeroVector()) 124 | { 125 | Vector2[] normals = { 126 | (positions[0] - positions[1]).RotatedClockwise.Normalized, 127 | (positions[2] - positions[3]).RotatedClockwise.Normalized 128 | }; 129 | 130 | PointF[] frontPoints = { 131 | positions[0] - 10*normals[0], 132 | positions[0] + 10*normals[0], 133 | positions[1] + 10*normals[0], 134 | positions[1] - 10*normals[0], 135 | }; 136 | PointF[] backPoints = { 137 | positions[2] - 10*normals[1], 138 | positions[2] + 10*normals[1], 139 | positions[3] + 10*normals[1], 140 | positions[3] - 10*normals[1], 141 | }; 142 | 143 | toReturn.AddPolygon(frontPoints); 144 | toReturn.AddPolygon(backPoints); 145 | } 146 | } 147 | 148 | return toReturn; 149 | } 150 | 151 | /// 152 | /// Prüfe, ob ich auf der NodeConnection nc fahren darf 153 | /// 154 | /// zu prüfende NodeConnection 155 | /// nc.tramAllowed 156 | public override bool CheckNodeConnectionForSuitability(NodeConnection nc) 157 | { 158 | return nc.carsAllowed; 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Timeline/TrafficLightTreeView.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.ComponentModel; 23 | using System.Diagnostics; 24 | using System.Text; 25 | using System.Windows.Forms; 26 | 27 | using CityTrafficSimulator.Tools.ObserverPattern; 28 | 29 | namespace CityTrafficSimulator.Timeline 30 | { 31 | /// 32 | /// TreeView-Control zur Anzeige von geordneten TrafficLights, welches als Observer fungiert und sich so bei einer TimelineSteuerung anmelden kann 33 | /// 34 | public partial class TrafficLightTreeView : System.Windows.Forms.TreeView, IEventListener 35 | { 36 | /// 37 | /// zugeordnete TimelineSteuerung 38 | /// 39 | private TimelineSteuerung m_steuerung; 40 | /// 41 | /// zugeordnete TimelineSteuerung, beim Setzen wird sich automatisch an/abgemeldet. 42 | /// 43 | public TimelineSteuerung steuerung 44 | { 45 | get { return m_steuerung; } 46 | set 47 | { 48 | if (m_steuerung != null) 49 | { 50 | m_steuerung.EntryChanged -= m_steuerung_EntryChanged; 51 | m_steuerung.GroupsChanged -= m_steuerung_GroupsChanged; 52 | } 53 | m_steuerung = value; 54 | if (m_steuerung != null) 55 | { 56 | m_steuerung.EntryChanged += new TimelineSteuerung.EntryChangedEventHandler(m_steuerung_EntryChanged); 57 | m_steuerung.GroupsChanged += new TimelineSteuerung.GroupsChangedEventHandler(m_steuerung_GroupsChanged); 58 | } 59 | 60 | } 61 | } 62 | 63 | void m_steuerung_GroupsChanged(object sender, EventArgs e) 64 | { 65 | UpdateTreeViewData(); 66 | } 67 | 68 | void m_steuerung_EntryChanged(object sender, TimelineSteuerung.EntryChangedEventArgs e) 69 | { 70 | // Gruppen und darin enthaltenen Entries mit e.affectedEntry vergleichen 71 | foreach (TreeNode groupNode in Nodes) 72 | { 73 | foreach (TreeNode entryNode in groupNode.Nodes) 74 | { 75 | if (entryNode.Tag == e.affectedEntry) 76 | { 77 | entryNode.Text = e.affectedEntry.name; 78 | } 79 | } 80 | } 81 | } 82 | 83 | /// 84 | /// Standardkonstruktor 85 | /// 86 | public TrafficLightTreeView() 87 | { 88 | InitializeComponent(); 89 | } 90 | 91 | /// 92 | /// Konstruktor, falls Control in Container 93 | /// 94 | /// übergeordneter Container 95 | public TrafficLightTreeView(IContainer container) 96 | { 97 | container.Add(this); 98 | 99 | InitializeComponent(); 100 | } 101 | 102 | 103 | /// 104 | /// baut den Inhalt der TreeView neu auf 105 | /// 106 | private void UpdateTreeViewData() 107 | { 108 | if (steuerung != null) 109 | { 110 | // SuspendLayout um Rechenzeit zu sparen 111 | this.SuspendLayout(); 112 | 113 | // erstmal alles löschen 114 | Nodes.Clear(); 115 | 116 | // Gruppen und darin enthaltenen Entries hinzufügen 117 | foreach (TimelineGroup tg in steuerung.groups) 118 | { 119 | TreeNode groupNode = new TreeNode(tg.title); 120 | groupNode.Tag = tg; 121 | if (tg.collapsed) 122 | groupNode.Collapse(); 123 | else 124 | groupNode.Expand(); 125 | 126 | 127 | 128 | foreach (TimelineEntry te in tg.entries) 129 | { 130 | TreeNode entryNode = new TreeNode(te.name); 131 | entryNode.Tag = te; 132 | groupNode.Nodes.Add(entryNode); 133 | } 134 | 135 | Nodes.Add(groupNode); 136 | } 137 | 138 | // Layout wieder einschalten 139 | this.ResumeLayout(); 140 | } 141 | } 142 | 143 | /// 144 | /// Selektiert den Knoten des TreeViews, der das TimelineEntry te enthält. 145 | /// 146 | /// zu suchendes TimelineEntry 147 | /// true, falls te gefunden und selektiert wurde, sonst false 148 | public bool SelectNodeByTimelineEntry(TimelineEntry te) 149 | { 150 | foreach (TreeNode groupNode in Nodes) 151 | { 152 | foreach (TreeNode entryNode in groupNode.Nodes) 153 | { 154 | TimelineEntry entryOfNode = entryNode.Tag as TimelineEntry; 155 | if (te == entryOfNode) 156 | { 157 | SelectedNode = entryNode; 158 | Invalidate(); 159 | return true; 160 | } 161 | } 162 | } 163 | 164 | return false; 165 | } 166 | 167 | 168 | #region IEventListener Member 169 | 170 | /// 171 | /// Wird von der TimelineSteuerung aufgerufen und sorgt dafür, dass sich das Control neu aufbaut. 172 | /// 173 | public void Notify() 174 | { 175 | UpdateTreeViewData(); 176 | Invalidate(); 177 | } 178 | 179 | #endregion 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /CityTrafficSimulator/RechenkaestchenControl.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Verkehr/TrafficVolumeForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /CityTrafficSimulator/LoadingForm/LoadingForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | True 122 | 123 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/Colormap.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | False 122 | 123 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Timeline/TimelineControl.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | False 122 | 123 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Timeline/TrafficLightForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 7, 1 122 | 123 | 124 | 27 125 | 126 | -------------------------------------------------------------------------------- /CityTrafficSimulator/XmlSaver.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Drawing; 23 | using System.Drawing.Drawing2D; 24 | using System.Text; 25 | using System.Windows.Forms; 26 | using System.IO; 27 | using System.Xml; 28 | using System.Xml.Serialization; 29 | using System.Threading; 30 | 31 | using CityTrafficSimulator.LoadingForm; 32 | using CityTrafficSimulator.Timeline; 33 | using CityTrafficSimulator.Tools; 34 | 35 | namespace CityTrafficSimulator 36 | { 37 | /// 38 | /// Speichert/Lädt den aktuellen Zustand der nodeSteuerung und timelineSteuerung in/aus eine(r) XML-Datei 39 | /// 40 | public static class XmlSaver 41 | { 42 | 43 | /// 44 | /// Speichert den aktuellen Zustand der nodeSteuerung und timelineSteuerung in die XML-Datei filename 45 | /// 46 | /// Dateiname der zu speichernden Datei 47 | /// NodeSteuerung 48 | /// TimelineSteuerung 49 | /// VerkehrSteuerung 50 | /// ProgramSettings 51 | public static void SaveToFile(string filename, NodeSteuerung nodeSteuerung, TimelineSteuerung timelineSteuerung, Verkehr.VerkehrSteuerung trafficVolumeSteuerung, ProgramSettings ps) 52 | { 53 | try 54 | { 55 | // erstma nen XMLWriter machen 56 | XmlWriterSettings xws = new XmlWriterSettings(); 57 | xws.Indent = true; 58 | xws.NewLineHandling = NewLineHandling.Entitize; 59 | 60 | XmlWriter xw = XmlWriter.Create(filename, xws); 61 | 62 | // leeren XmlSerializerNamespaces Namespace erstellen 63 | XmlSerializerNamespaces xsn = new XmlSerializerNamespaces(); 64 | xsn.Add("", ""); 65 | 66 | xw.WriteStartElement("CityTrafficSimulator"); 67 | 68 | // write saveVersion 69 | xw.WriteStartAttribute("saveVersion"); 70 | xw.WriteString("8"); 71 | xw.WriteEndAttribute(); 72 | 73 | // serialize program settings 74 | XmlSerializer xsPS = new XmlSerializer(typeof(ProgramSettings)); 75 | xsPS.Serialize(xw, ps, xsn); 76 | 77 | nodeSteuerung.SaveToFile(xw, xsn); 78 | timelineSteuerung.SaveToFile(xw, xsn); 79 | trafficVolumeSteuerung.SaveToFile(xw, xsn); 80 | 81 | xw.WriteEndElement(); 82 | 83 | xw.Close(); 84 | 85 | } 86 | catch (IOException e) 87 | { 88 | MessageBox.Show(e.Message); 89 | throw; 90 | } 91 | } 92 | 93 | 94 | /// 95 | /// Läd eine XML Datei und versucht daraus den gespeicherten Zustand wiederherzustellen 96 | /// 97 | /// Dateiname der zu ladenden Datei 98 | /// NodeSteuerung in das Layout eingelesen werden soll 99 | /// TimelineSteuerung in die die LSA eingelesen werden soll 100 | /// VerkehrSteurung to load into 101 | public static ProgramSettings LoadFromFile(String filename, NodeSteuerung nodeSteuerung, TimelineSteuerung timelineSteuerung, Verkehr.VerkehrSteuerung trafficVolumeSteuerung) 102 | { 103 | LoadingForm.LoadingForm lf = new LoadingForm.LoadingForm(); 104 | lf.Text = "Loading file '" + filename + "'..."; 105 | lf.Show(); 106 | 107 | lf.SetupUpperProgress("Loading Document...", 8); 108 | 109 | // Dokument laden 110 | XmlDocument xd = new XmlDocument(); 111 | xd.Load(filename); 112 | 113 | // parse save file version 114 | int saveVersion = 0; 115 | XmlNode mainNode = xd.SelectSingleNode("//CityTrafficSimulator"); 116 | XmlNode saveVersionNode = mainNode.Attributes.GetNamedItem("saveVersion"); 117 | if (saveVersionNode != null) 118 | saveVersion = Int32.Parse(saveVersionNode.Value); 119 | else 120 | saveVersion = 0; 121 | 122 | ProgramSettings ps; 123 | if (saveVersion >= 8) 124 | { 125 | XmlNode xnlLineNode = xd.SelectSingleNode("//CityTrafficSimulator/ProgramSettings"); 126 | TextReader tr = new StringReader(xnlLineNode.OuterXml); 127 | XmlSerializer xsPS = new XmlSerializer(typeof(ProgramSettings)); 128 | ps = (ProgramSettings)xsPS.Deserialize(tr); 129 | } 130 | else 131 | { 132 | // set some okay default settings 133 | ps = new ProgramSettings(); 134 | 135 | ps._simSpeed = 1; 136 | ps._simSteps = 15; 137 | ps._simDuration = 300; 138 | ps._simRandomSeed = 42; 139 | 140 | ps._zoomLevel = 7; 141 | ps._renderQuality = 0; 142 | 143 | ps._renderStatistics = false; 144 | ps._renderVelocityMapping = false; 145 | ps._showFPS = false; 146 | 147 | ps._renderOptions = new NodeSteuerung.RenderOptions(); 148 | ps._renderOptions.renderLineNodes = true; 149 | ps._renderOptions.renderNodeConnections = true; 150 | ps._renderOptions.renderVehicles = true; 151 | ps._renderOptions.performClipping = true; 152 | ps._renderOptions.clippingRect = new Rectangle(0, 0, 10000, 10000); 153 | ps._renderOptions.renderIntersections = false; 154 | ps._renderOptions.renderLineChangePoints = false; 155 | ps._renderOptions.renderLineNodeDebugData = false; 156 | ps._renderOptions.renderNodeConnectionDebugData = false; 157 | ps._renderOptions.renderVehicleDebugData = false; 158 | 159 | List tmp = new List(); 160 | tmp.Add(Color.DarkRed); 161 | tmp.Add(Color.Yellow); 162 | tmp.Add(Color.DarkGreen); 163 | ps._velocityMappingColorMap = new Tools.ColorMap(tmp); 164 | } 165 | 166 | lf.StepUpperProgress("Parsing Network Layout..."); 167 | List toReturn = nodeSteuerung.LoadFromFile(xd, lf); 168 | 169 | lf.StepUpperProgress("Parsing Singnals..."); 170 | timelineSteuerung.LoadFromFile(xd, nodeSteuerung.nodes, lf); 171 | 172 | lf.StepUpperProgress("Parsing Traffic Volume..."); 173 | trafficVolumeSteuerung.LoadFromFile(xd, nodeSteuerung.nodes, lf); 174 | if (saveVersion < 5) 175 | { 176 | trafficVolumeSteuerung.ImportOldTrafficVolumeData(toReturn); 177 | } 178 | 179 | lf.StepUpperProgress("Done"); 180 | lf.ShowLog(); 181 | 182 | lf.Close(); 183 | lf = null; 184 | 185 | return ps; 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/IDM.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | 24 | namespace CityTrafficSimulator 25 | { 26 | /// 27 | /// abstrakte Klasse für das Intelligent Driver Model 28 | /// 29 | public abstract class IDM 30 | { 31 | #region Konstanten 32 | /* 33 | * Berechnungen nach dem IDM Schema der TU Dresden 34 | * http://www.cs.wm.edu/~coppit/csci435-spring2005/project/MOBIL.pdf 35 | */ 36 | /*double T = 10; // Zeitlicher Sicherheitsabstand 37 | double a = 2; // Maxmale Beschleunigung° 38 | double b = 3; // komfortable Bremsverzögerung 39 | double s0 = 20; // Mindestabstand im Stau 40 | */ 41 | 42 | /* 43 | * Konstanten in s, m/s und m/s² 44 | * 45 | protected double T = 2; // Zeitlicher Sicherheitsabstand 46 | protected double a = 1.2; // Maxmale Beschleunigung 47 | protected double b = 1.5; // komfortable Bremsverzögerung 48 | protected double s0 = 10; // Mindestabstand im Stau 49 | //*/ 50 | 51 | /* 52 | * Konstanten in s/20, Pixel/20s^2 53 | * 1 Pixel = 1 dm 54 | */ 55 | /// 56 | /// Zeitlicher Sicherheitsabstand 57 | /// 58 | protected double T = 1.4; 59 | /// 60 | /// Zeitlicher Sicherheitsabstand 61 | /// 62 | public double SafetyTime { get { return T; } } 63 | 64 | /// 65 | /// maximale Beschleunigung 66 | /// 67 | protected double a = 1.2; 68 | 69 | /// 70 | /// komfortable Bremsverzögerung 71 | /// 72 | protected double b = 1.5; 73 | 74 | /// 75 | /// Mindestabstand im Stau 76 | /// 77 | public double s0 = 20; 78 | 79 | 80 | /* MOBIL PARAMETER */ 81 | 82 | 83 | /// 84 | /// Politeness-Faktor von MOBIL 85 | /// 86 | protected double p = 0.2; 87 | 88 | /// 89 | /// Mindest-Vorteilswert für Spurwechsel 90 | /// 91 | protected double lineChangeThreshold = 0.75; 92 | 93 | /// 94 | /// maximale sichere Bremsverzögerung 95 | /// 96 | protected double bSave = -3; 97 | //*/ 98 | 99 | #endregion 100 | 101 | /// 102 | /// Berechnet den Wunschabstand nach dem IDM 103 | /// 104 | /// eigene Geschwindigkeit 105 | /// Differenzgeschwindigkeit zum Vorausfahrenden Fahrzeug 106 | /// 107 | public double CalculateWantedDistance(double velocity, double vDiff) 108 | { 109 | // berechne s* = Wunschabstand 110 | double ss = s0 + T * velocity + (velocity * vDiff) / (2 * Math.Sqrt(a * b)); 111 | 112 | if (ss < s0) 113 | { 114 | ss = s0; 115 | } 116 | 117 | return ss; 118 | } 119 | 120 | /// 121 | /// Berechnet die Beschleunigung frei nach dem IDM 122 | /// http://www.cs.wm.edu/~coppit/csci435-spring2005/project/MOBIL.pdf 123 | /// 124 | /// aktuelle Geschwindigkei 125 | /// Wunschgeschwindigkeit 126 | /// Distanz zum vorausfahrenden Fahrzeug 127 | /// Geschwindigkeitsunterschied zum vorausfahrenden Fahrzeug 128 | /// 129 | public double CalculateAcceleration(double velocity, double desiredVelocity, double distance, double vDiff) 130 | { 131 | // berechne s* = Wunschabstand 132 | double ss = CalculateWantedDistance(velocity, vDiff); 133 | 134 | // Neue Geschwindigkeit berechnen 135 | double vNeu = a * (1 - Math.Pow((velocity / desiredVelocity), 2) - Math2.Square(ss / distance)); 136 | 137 | return vNeu; 138 | } 139 | 140 | /// 141 | /// Berechnet die Beschleunigung frei nach dem IDM, wenn kein Fahrzeug voraus fährt 142 | /// 143 | /// eigene Geschwindigkeit 144 | /// Wunschgeschwindigkeit 145 | /// 146 | public double CalculateAcceleration(double velocity, double desiredVelocity) 147 | { 148 | // Neue Geschwindigkeit berechnen 149 | double vNeu = a * (1 - Math.Pow((velocity / desiredVelocity), 2) ); 150 | 151 | return vNeu; 152 | } 153 | 154 | /// 155 | /// Berechnet die Beschleunigung frei nach dem IDM mit dem Verfahren von Heun (Konsistenzordnung 2!) 156 | /// http://www.cs.wm.edu/~coppit/csci435-spring2005/project/MOBIL.pdf 157 | /// 158 | /// aktuelle Geschwindigkei 159 | /// Wunschgeschwindigkeit 160 | /// Distanz zum vorausfahrenden Fahrzeug 161 | /// Geschwindigkeitsunterschied zum vorausfahrenden Fahrzeug 162 | /// 163 | public double CalculateAccelerationHeun(double velocity, double desiredVelocity, double distance, double vDiff) 164 | { 165 | // erste Näherung: 166 | // berechne s* = Wunschabstand 167 | double ss1 = CalculateWantedDistance(velocity, vDiff); 168 | // Neue Geschwindigkeit berechnen 169 | double vNeu = a * (1 - Math.Pow((velocity / desiredVelocity), 2) - Math2.Square(ss1 / distance)); 170 | 171 | // zweite Näherung: 172 | // berechne s* = Wunschabstand 173 | double ss2 = CalculateWantedDistance(velocity + vNeu, vDiff + vNeu); 174 | // Neue Geschwindigkeit berechnen 175 | vNeu += a * (1 - Math.Pow(((velocity + vNeu) / desiredVelocity), 2) - Math2.Square(ss2 / distance)); 176 | 177 | return vNeu/2; 178 | } 179 | 180 | 181 | 182 | /// 183 | /// Berechnet die Beschleunigung, wenn Wunschabstand schon bekannt nach dem IDM 184 | /// 185 | /// aktuelle Geschwindigkeit 186 | /// Wunschgeschwindigkeit 187 | /// aktueller Abstand 188 | /// Wunschabstand 189 | /// Geschwindigkeitsdifferenz 190 | /// 191 | public double CalculateAcceleration(double velocity, double desiredVelocity, double distance, double wantedDistance, double vDiff) 192 | { 193 | // Neue Geschwindigkeit berechnen 194 | double vNeu = a * (1 - Math.Pow((velocity / desiredVelocity), 2) - Math2.Square(wantedDistance / distance)); 195 | 196 | return vNeu; 197 | } 198 | 199 | 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Timeline/TimelineEvent.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Drawing; 24 | using System.Xml.Serialization; 25 | 26 | namespace CityTrafficSimulator.Timeline 27 | { 28 | /// 29 | /// Einzelnes Event einer Timeline, gehört immer zu einem TimelineEntry, und hat zwei Aktionen die bei eventStart und eventEnde ausgeführt werden sollen. 30 | /// 31 | [Serializable] 32 | public class TimelineEvent : ISavable 33 | { 34 | #region Delegates 35 | 36 | /// 37 | /// delegate für Befehl der ausgeführt werden soll, wenn das TimelineEvent eintritt 38 | /// 39 | public delegate void EventAction(); 40 | 41 | #endregion 42 | 43 | #region Variablen und Eigenschaften 44 | 45 | /// 46 | /// Zeit wenn das TimelineEvent eintritt 47 | /// 48 | private double _eventTime; 49 | /// 50 | /// Zeit wenn das TimelineEvent eintritt 51 | /// 52 | public double eventTime 53 | { 54 | get { return _eventTime; } 55 | set { _eventTime = value; InvokeEventTimesChanged(new EventTimesChangedEventArgs(this)); } 56 | } 57 | 58 | /// 59 | /// Dauer des TimelineEvents 60 | /// 61 | private double _eventLength; 62 | /// 63 | /// Dauer des TimelineEvents 64 | /// 65 | public double eventLength 66 | { 67 | get { return _eventLength; } 68 | set { _eventLength = value; InvokeEventTimesChanged(new EventTimesChangedEventArgs(this)); } 69 | } 70 | 71 | /// 72 | /// End time of this event 73 | /// 74 | public double eventEndTime 75 | { 76 | get { return _eventTime + _eventLength; } 77 | set { eventLength = value - _eventTime; } 78 | } 79 | 80 | /// 81 | /// Befehl der ausgeführt werden soll, wenn das TimelineEvent eintritt 82 | /// 83 | private EventAction _eventStartAction; 84 | /// 85 | /// Befehl der ausgeführt werden soll, wenn das TimelineEvent eintritt 86 | /// 87 | [XmlIgnore] 88 | public EventAction eventStartAction 89 | { 90 | get { return _eventStartAction; } 91 | set { _eventStartAction = value; } 92 | } 93 | 94 | /// 95 | /// Befehl der ausgeführt werden soll, wenn das TimelineEvent zu Ende ist 96 | /// 97 | private EventAction _eventEndAction; 98 | /// 99 | /// Befehl der ausgeführt werden soll, wenn das TimelineEvent zu Ende ist 100 | /// 101 | [XmlIgnore] 102 | public EventAction eventEndAction 103 | { 104 | get { return _eventEndAction; } 105 | set { _eventEndAction = value; } 106 | } 107 | 108 | 109 | /// 110 | /// Farbe durch die das Event repräsentiert werden soll 111 | /// 112 | private Color _color; 113 | /// 114 | /// Farbe durch die das Event repräsentiert werden soll 115 | /// 116 | [XmlIgnore] 117 | public Color color 118 | { 119 | get { return _color; } 120 | set { _color = value; } 121 | } 122 | /// 123 | /// Farbe im ARGB-Format (Für Serialisierung benötigt) 124 | /// 125 | public int argbColor 126 | { 127 | get { return _color.ToArgb(); } 128 | set { _color = Color.FromArgb(value); } 129 | } 130 | 131 | #endregion 132 | 133 | #region Prozeduren 134 | /// 135 | /// Standardkonstruktur nur zur internenen Verwendung! 136 | /// 137 | public TimelineEvent() 138 | { 139 | } 140 | 141 | /// 142 | /// Standardkonstruktor zur erstellung eines neuen TimelineEvents 143 | /// 144 | /// Zeit, wann das Event eintreten soll 145 | /// Länge des Events. 146 | /// Farbe durch die das Event repräsentiert werden soll 147 | /// Funktion die bei Eintreten aufgerufen werden soll 148 | /// Funktion die beim Ende des Events aufgerufen werden soll 149 | public TimelineEvent(double time, double length, Color color, EventAction startAction, EventAction endAction) 150 | { 151 | this.eventTime = time; 152 | this.eventLength = length; 153 | this.color = color; 154 | this.eventStartAction = startAction; 155 | this.eventEndAction = endAction; 156 | } 157 | 158 | #endregion 159 | 160 | #region Events 161 | 162 | #region EventTimesChanged event 163 | 164 | /// 165 | /// EventArgs for a EventTimesChanged event 166 | /// 167 | public class EventTimesChangedEventArgs : EventArgs 168 | { 169 | /// 170 | /// Creates new EventTimesChangedEventArgs 171 | /// 172 | public EventTimesChangedEventArgs(TimelineEvent te) 173 | { 174 | _changedEvent = te; 175 | } 176 | 177 | /// 178 | /// Event that changed its times 179 | /// 180 | public TimelineEvent _changedEvent; 181 | } 182 | 183 | /// 184 | /// Delegate for the EventTimesChanged-EventHandler, which is called when the eventTime or eventLength has changed. 185 | /// 186 | /// Sneder of the event 187 | /// Event parameter 188 | public delegate void EventTimesChangedEventHandler(object sender, EventTimesChangedEventArgs e); 189 | 190 | /// 191 | /// The EventTimesChanged event occurs when the eventTime or eventLength has changed. 192 | /// 193 | public event EventTimesChangedEventHandler EventTimesChanged; 194 | 195 | /// 196 | /// Helper method to initiate the EventTimesChanged event 197 | /// 198 | /// Event parameters 199 | protected void InvokeEventTimesChanged(EventTimesChangedEventArgs e) 200 | { 201 | if (EventTimesChanged != null) 202 | { 203 | EventTimesChanged(this, e); 204 | } 205 | } 206 | 207 | #endregion 208 | 209 | #endregion 210 | 211 | #region ISavable Member 212 | 213 | /// 214 | /// bereitet das TimelineEvent zur Xml-Serialisierung vor 215 | /// 216 | public void PrepareForSave() 217 | { 218 | 219 | } 220 | 221 | /// 222 | /// Stellt das TimelineEvent nach dem Laden wieder her 223 | /// 224 | /// Version der gespeicherten Datei 225 | /// Eine Liste mit sämtlichen existierenden Linien 226 | public void RecoverFromLoad(int saveVersion, List nodesList) 227 | { 228 | 229 | } 230 | 231 | #endregion 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Vehicle/Tram.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Drawing; 24 | using System.Drawing.Drawing2D; 25 | 26 | namespace CityTrafficSimulator.Vehicle 27 | { 28 | class Tram : IVehicle 29 | { 30 | private GraphicsPath[] wagons = new GraphicsPath[5]; 31 | 32 | public Tram(IVehicle.Physics p) 33 | { 34 | length = (GlobalRandom.Instance.Next(2) == 0) ? 250 : 400; 35 | 36 | _physics = p; 37 | color = Color.FromArgb(GlobalRandom.Instance.Next(256), GlobalRandom.Instance.Next(256), GlobalRandom.Instance.Next(256)); 38 | 39 | // maximale Beschleunigung 40 | a = 1.0; 41 | 42 | // komfortable Bremsverzögerung 43 | b = 1.0; 44 | 45 | _vehicleType = VehicleTypes.TRAM; 46 | } 47 | 48 | /// 49 | /// Berechnet die Absolute Position zur Bogenlängenposition pos. 50 | /// Kann auch mit negativen Positionsangaben umgehen 51 | /// 52 | /// Bogenlängenposition 53 | /// Weltkoordinaten zu Bogenlängenposition pos 54 | private Vector2 GetPositionAbsAtArcPos(double pos) 55 | { 56 | if (pos >= 0) 57 | return currentNodeConnection.lineSegment.AtPosition(pos); 58 | else 59 | { 60 | double remainingDistance = -pos; 61 | foreach (NodeConnection nc in visitedNodeConnections) 62 | { 63 | if (nc.lineSegment.length < remainingDistance) 64 | { 65 | remainingDistance -= nc.lineSegment.length; 66 | continue; 67 | } 68 | else 69 | { 70 | return nc.lineSegment.AtPosition(nc.lineSegment.length - remainingDistance); 71 | } 72 | } 73 | } 74 | return state.positionAbs; 75 | } 76 | 77 | /// 78 | /// Generates the GraphicsPath for rendering the vehicle. Should be overloaded by subclasses with distinct rendering. 79 | /// 80 | /// A GraphicsPath in world coordinates for rendering the vehicle at the current position. 81 | protected override GraphicsPath BuildGraphicsPath() 82 | { 83 | GraphicsPath toReturn = new GraphicsPath(); 84 | 85 | // 25-Meter-Zug 86 | if (_length == 250) 87 | { 88 | Vector2[] positions = { 89 | state.positionAbs, 90 | GetPositionAbsAtArcPos(currentPosition - 95), 91 | GetPositionAbsAtArcPos(currentPosition - 100), 92 | GetPositionAbsAtArcPos(currentPosition - 150), 93 | GetPositionAbsAtArcPos(currentPosition - 155), 94 | GetPositionAbsAtArcPos(currentPosition - 250) 95 | }; 96 | Vector2[] normals = { 97 | (positions[0] - positions[1]).RotatedClockwise.Normalized, 98 | (positions[2] - positions[3]).RotatedClockwise.Normalized, 99 | (positions[4] - positions[5]).RotatedClockwise.Normalized 100 | }; 101 | 102 | PointF[] frontPoints = 103 | { 104 | positions[0] - 11*normals[0], 105 | positions[0] + 11*normals[0], 106 | positions[1] + 11*normals[0], 107 | positions[1] - 11*normals[0], 108 | }; 109 | PointF[] midPoints = 110 | { 111 | positions[2] - 11*normals[1], 112 | positions[2] + 11*normals[1], 113 | positions[3] + 11*normals[1], 114 | positions[3] - 11*normals[1], 115 | }; 116 | 117 | PointF[] backPoints = 118 | { 119 | positions[4] - 11*normals[2], 120 | positions[4] + 11*normals[2], 121 | positions[5] + 11*normals[2], 122 | positions[5] - 11*normals[2], 123 | }; 124 | 125 | if (positions[0] != positions[1]) 126 | toReturn.AddPolygon(frontPoints); 127 | if (positions[2] != positions[3]) 128 | toReturn.AddPolygon(midPoints); 129 | if (positions[4] != positions[5]) 130 | toReturn.AddPolygon(backPoints); 131 | } 132 | // 40-Meter-Zug 133 | else 134 | { 135 | Vector2[] positions = { 136 | state.positionAbs, 137 | GetPositionAbsAtArcPos(currentPosition - 95), 138 | GetPositionAbsAtArcPos(currentPosition - 100), 139 | GetPositionAbsAtArcPos(currentPosition - 150), 140 | GetPositionAbsAtArcPos(currentPosition - 155), 141 | GetPositionAbsAtArcPos(currentPosition - 250), 142 | GetPositionAbsAtArcPos(currentPosition - 255), 143 | GetPositionAbsAtArcPos(currentPosition - 300), 144 | GetPositionAbsAtArcPos(currentPosition - 305), 145 | GetPositionAbsAtArcPos(currentPosition - 400) 146 | }; 147 | Vector2[] normals = { 148 | (positions[0] - positions[1]).RotatedClockwise.Normalized, 149 | (positions[2] - positions[3]).RotatedClockwise.Normalized, 150 | (positions[4] - positions[5]).RotatedClockwise.Normalized, 151 | (positions[6] - positions[7]).RotatedClockwise.Normalized, 152 | (positions[7] - positions[9]).RotatedClockwise.Normalized 153 | }; 154 | 155 | PointF[] firstPoints = 156 | { 157 | positions[0] - 11*normals[0], 158 | positions[0] + 11*normals[0], 159 | positions[1] + 11*normals[0], 160 | positions[1] - 11*normals[0], 161 | }; 162 | PointF[] secondPoints = 163 | { 164 | positions[2] - 11*normals[1], 165 | positions[2] + 11*normals[1], 166 | positions[3] + 11*normals[1], 167 | positions[3] - 11*normals[1], 168 | }; 169 | 170 | PointF[] thirdPoints = 171 | { 172 | positions[4] - 11*normals[2], 173 | positions[4] + 11*normals[2], 174 | positions[5] + 11*normals[2], 175 | positions[5] - 11*normals[2], 176 | }; 177 | 178 | PointF[] forthPoints = 179 | { 180 | positions[6] - 11*normals[3], 181 | positions[6] + 11*normals[3], 182 | positions[7] + 11*normals[3], 183 | positions[7] - 11*normals[3], 184 | }; 185 | 186 | PointF[] fifthPoints = 187 | { 188 | positions[8] - 11*normals[4], 189 | positions[8] + 11*normals[4], 190 | positions[9] + 11*normals[4], 191 | positions[9] - 11*normals[4], 192 | }; 193 | 194 | if ((positions[0] - positions[1]).IsNotZeroVector()) 195 | toReturn.AddPolygon(firstPoints); 196 | if ((positions[2] - positions[3]).IsNotZeroVector()) 197 | toReturn.AddPolygon(secondPoints); 198 | if ((positions[4] - positions[5]).IsNotZeroVector()) 199 | toReturn.AddPolygon(thirdPoints); 200 | if ((positions[6] - positions[7]).IsNotZeroVector()) 201 | toReturn.AddPolygon(forthPoints); 202 | if ((positions[8] - positions[9]).IsNotZeroVector()) 203 | toReturn.AddPolygon(fifthPoints); 204 | } 205 | 206 | return toReturn; 207 | } 208 | 209 | /// 210 | /// Prüfe, ob ich auf der NodeConnection nc fahren darf 211 | /// 212 | /// zu prüfende NodeConnection 213 | /// nc.tramAllowed 214 | public override bool CheckNodeConnectionForSuitability(NodeConnection nc) 215 | { 216 | return nc.tramAllowed; 217 | } 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /CityTrafficSimulator/MainForm/MainForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 380, 17 125 | 126 | 127 | 128 | 129 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 130 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI 131 | ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 132 | HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN 133 | rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K 134 | TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx 135 | oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 136 | 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI 137 | xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX 138 | LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd 139 | KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC 140 | 141 | 142 | 143 | 52 144 | 145 | -------------------------------------------------------------------------------- /CityTrafficSimulator/RechenkaestchenControl.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.ComponentModel; 23 | using System.Drawing; 24 | using System.Data; 25 | using System.Text; 26 | using System.Windows.Forms; 27 | 28 | namespace CityTrafficSimulator 29 | { 30 | /// 31 | /// Control welches ein Grid variabler Größe enthalten kann und Unterobjekte daran ausrichten kann 32 | /// 33 | public partial class RechenkaestchenControl : UserControl 34 | { 35 | #region Variablen und Properties 36 | /// 37 | /// Dimension des Grids 38 | /// 39 | private Point m_Dimension; 40 | /// 41 | /// Größe einer einzelnen Zelle 42 | /// 43 | private Size m_CellSize; 44 | /// 45 | /// Flag, ob das Grid gezeichnet werden soll 46 | /// 47 | private bool m_DrawGrid; 48 | 49 | /// 50 | /// Dimension des Grids 51 | /// 52 | public Point Dimension 53 | { 54 | get { return m_Dimension; } 55 | set 56 | { 57 | m_Dimension = value; 58 | Invalidate(); 59 | } 60 | } 61 | 62 | /// 63 | /// Breite des Grids 64 | /// 65 | public int Max_X 66 | { 67 | get { return m_Dimension.X; } 68 | set 69 | { 70 | m_Dimension.X = value; 71 | Invalidate(); 72 | } 73 | } 74 | /// 75 | /// Höhe des Grids 76 | /// 77 | public int Max_Y 78 | { 79 | get { return m_Dimension.Y; } 80 | set 81 | { 82 | m_Dimension.Y = value; 83 | Invalidate(); 84 | } 85 | } 86 | 87 | /// 88 | /// Dimension einer einzelnen Zelle 89 | /// 90 | public Size CellSize 91 | { 92 | get { return m_CellSize; } 93 | set 94 | { 95 | m_CellSize = value; 96 | Invalidate(); 97 | } 98 | } 99 | /// 100 | /// Breite einer einzelnen Zelle 101 | /// 102 | public int CellWidth 103 | { 104 | get { return m_CellSize.Width; } 105 | set 106 | { 107 | m_CellSize.Width = value; 108 | Invalidate(); 109 | } 110 | } 111 | /// 112 | /// Höhe einer einzelnen Zelle 113 | /// 114 | public int CellHeight 115 | { 116 | get { return m_CellSize.Height; } 117 | set 118 | { 119 | m_CellSize.Height = value; 120 | Invalidate(); 121 | } 122 | } 123 | 124 | /// 125 | /// Flag, ob das Grid gezeichnet werden soll 126 | /// 127 | public bool DrawGrid 128 | { 129 | get { return m_DrawGrid; } 130 | set { m_DrawGrid = value; } 131 | } 132 | 133 | #endregion 134 | 135 | #region Prozeduren 136 | /// 137 | /// Standardkonstruktor, initialisiert das Grid als DoubleBuffered 138 | /// 139 | public RechenkaestchenControl() 140 | { 141 | InitializeComponent(); 142 | 143 | this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); 144 | this.DoubleBuffered = true; 145 | 146 | if (DesignMode) 147 | { 148 | this.Dimension = new Point(10, 10); 149 | this.CellSize = new Size(16, 16); 150 | } 151 | 152 | } 153 | 154 | /// 155 | /// richtet den Punkt clientPosition am Raster aus 156 | /// 157 | /// auszurichtender Punkt 158 | /// Flag, ob überhaupt ausgerichtet werden soll 159 | /// Falls DockToGrid==true: der Punkt auf dem Grid der clientPosition am nächsten ist, sonst clientPosition 160 | public Vector2 DockToGrid(Vector2 clientPosition, bool DockToGrid) 161 | { 162 | if (DockToGrid) 163 | { 164 | Vector2 toreturn = new Vector2((float)Math.Floor(clientPosition.X / this.CellWidth) * this.CellWidth, (float)Math.Floor(clientPosition.Y / this.CellHeight) * this.CellHeight); 165 | return toreturn; 166 | } 167 | else 168 | { 169 | return clientPosition; 170 | } 171 | } 172 | 173 | #endregion 174 | 175 | #region Override Prozeduren 176 | /// 177 | /// Override-Methode für IsInputKey 178 | /// 179 | /// keyData 180 | /// true 181 | protected override bool IsInputKey(Keys keyData) 182 | { 183 | return true; 184 | } 185 | #endregion 186 | 187 | #region Event-Handler 188 | /// 189 | /// Paint-Methode. Falls DrawGrid==true wird hier ein Rechenkästchenraster gezeichnet 190 | /// 191 | /// aufrufendes Objekt 192 | /// PaintEvent-Argumente 193 | private void RechenkaestchenControl_Paint(object sender, PaintEventArgs e) 194 | { 195 | e.Graphics.Clear(Color.White); 196 | // zunächst die ganze Geschichte weiß streichen 197 | /* using (Pen BackPen = new Pen(Color.White)) 198 | { 199 | using (SolidBrush BackBrush = new SolidBrush(Color.White)) 200 | { 201 | e.Graphics.FillRectangle(BackBrush, this.ClientRectangle); 202 | e.Graphics.DrawRectangle(BackPen, this.ClientRectangle); 203 | 204 | if (DrawGrid) 205 | { 206 | // nun das Gitternetz anbringen 207 | Pen GridPen = new Pen(Color.LightGray); 208 | GridPen.Width = 1; 209 | // erst die Spalten 210 | for (int i = 0; i <= this.Max_X; i++) 211 | { 212 | e.Graphics.DrawLine(GridPen, i * this.CellWidth, 0, i * this.CellWidth, this.CellHeight * this.Max_Y); 213 | } 214 | // nun die Zeilen 215 | for (int i = 0; i <= this.Max_Y; i++) 216 | { 217 | e.Graphics.DrawLine(GridPen, 0, i * this.CellHeight, this.Max_X * this.CellWidth, i * this.CellHeight); 218 | } 219 | 220 | // aufräumen 221 | GridPen.Dispose(); 222 | } 223 | } 224 | } 225 | */ 226 | } 227 | #endregion 228 | 229 | #region Subklassen 230 | #endregion 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /CityTrafficSimulator/TrafficLight.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Xml; 24 | using System.Xml.Serialization; 25 | using System.Drawing; 26 | 27 | using CityTrafficSimulator.Timeline; 28 | 29 | namespace CityTrafficSimulator 30 | { 31 | /// 32 | /// Kapselt eine Ampel und implementiert ein TimelineEntry 33 | /// 34 | [Serializable] 35 | public class TrafficLight : TimelineEntry, ISavable 36 | { 37 | /// 38 | /// Status einer Ampel (rot oder grün) 39 | /// 40 | public enum State { 41 | /// 42 | /// grüne Ampel 43 | /// 44 | GREEN, 45 | 46 | /// 47 | /// rote Ampel 48 | /// 49 | RED 50 | } 51 | 52 | 53 | /// 54 | /// aktueller Status der Ampel 55 | /// 56 | private State _trafficLightState; 57 | /// 58 | /// aktueller Status der Ampel 59 | /// 60 | [XmlIgnore] 61 | public State trafficLightState 62 | { 63 | get { return _trafficLightState; } 64 | set { _trafficLightState = value; } 65 | } 66 | 67 | /// 68 | /// Liste von LineNodes denen dieses TrafficLight zugeordnet ist 69 | /// 70 | [XmlIgnore] 71 | private List _assignedNodes = new List(); 72 | 73 | /// 74 | /// Liste von LineNodes denen dieses TrafficLight zugeordnet ist 75 | /// 76 | [XmlIgnore] 77 | public List assignedNodes 78 | { 79 | get { return _assignedNodes; } 80 | } 81 | 82 | #region Hashcodes 83 | 84 | /* 85 | * Nachdem der ursprüngliche Ansatz zu Hashen zu argen Kollisionen geführt hat, nun eine verlässliche Methode für Kollisionsfreie Hashes 86 | * mittels eindeutiger IDs für jedes TrafficLight die über statisch Klassenvariablen vergeben werden 87 | */ 88 | 89 | /// 90 | /// Klassenvariable welche den letzten vergebenen hashcode speichert und bei jeder Instanziierung eines Objektes inkrementiert werden muss 91 | /// 92 | [XmlIgnore] 93 | private static int hashcodeIndex = 0; 94 | 95 | /// 96 | /// Hashcode des instanziierten Objektes 97 | /// 98 | public int hashcode = -1; 99 | 100 | /// 101 | /// gibt den Hashcode des Fahrzeuges zurück. 102 | /// 103 | /// 104 | public override int GetHashCode() 105 | { 106 | return hashcode; 107 | } 108 | 109 | /// 110 | /// Setzt die statische Klassenvariable hashcodeIndex zurück. Achtung: darf nur in bestimmten Fällen aufgerufen werden. 111 | /// 112 | public static void ResetHashcodeIndex() 113 | { 114 | hashcodeIndex = 0; 115 | } 116 | 117 | #endregion 118 | 119 | #region Konstruktoren 120 | 121 | /// 122 | /// Konstruktor für TimelineEntry-Ampeln 123 | /// 124 | public TrafficLight() 125 | { 126 | hashcode = hashcodeIndex++; 127 | 128 | // Initial Event anlegen 129 | this.defaultAction = SwitchToRed; 130 | trafficLightState = State.RED; 131 | this.color = Color.Red; 132 | } 133 | #endregion 134 | 135 | 136 | #region Speichern/Laden 137 | /// 138 | /// DEPRECATED: Hash des Elternknotens (wird für Serialisierung gebraucht) 139 | /// 140 | [XmlIgnore] 141 | public int parentNodeHash = 0; 142 | 143 | /// 144 | /// Hashes der zugeordneten LineNodes 145 | /// 146 | public List assignedNodesHashes = new List(); 147 | 148 | /// 149 | /// bereitet das TrafficLight auf die XML-Serialisierung vor. 150 | /// 151 | public override void PrepareForSave() 152 | { 153 | base.PrepareForSave(); 154 | 155 | assignedNodesHashes.Clear(); 156 | foreach (LineNode ln in _assignedNodes) 157 | { 158 | assignedNodesHashes.Add(ln.GetHashCode()); 159 | } 160 | } 161 | /// 162 | /// stellt das TrafficLight nach einer XML-Deserialisierung wieder her 163 | /// 164 | /// Version der gespeicherten Datei 165 | /// Liste von allen existierenden LineNodes 166 | public override void RecoverFromLoad(int saveVersion, List nodesList) 167 | { 168 | // Klassenvariable für Hashcode erhöhen um Kollisionen für zukünftige LineNodes zu verhindern 169 | if (hashcodeIndex <= hashcode) 170 | { 171 | hashcodeIndex = hashcode + 1; 172 | } 173 | 174 | // erstmal EventActions setzen 175 | this.defaultAction = SwitchToRed; 176 | foreach (TimelineEvent e in events) 177 | { 178 | e.eventStartAction = SwitchToGreen; 179 | e.eventEndAction = SwitchToRed; 180 | } 181 | 182 | // nun die assignedNodes aus der nodesList dereferenzieren 183 | foreach (int hash in assignedNodesHashes) 184 | { 185 | foreach (LineNode ln in nodesList) 186 | { 187 | if (ln.GetHashCode() == hash) 188 | { 189 | _assignedNodes.Add(ln); 190 | ln.tLight = this; 191 | break; 192 | } 193 | } 194 | } 195 | 196 | // Alte Versionen konnten nur einen Node pro TrafficLight haben und waren daher anders referenziert, auch darum wollen wir uns kümmern: 197 | if (saveVersion <= 2) 198 | { 199 | foreach (LineNode ln in nodesList) 200 | { 201 | if (ln.GetHashCode() == parentNodeHash) 202 | { 203 | AddAssignedLineNode(ln); 204 | break; 205 | } 206 | } 207 | } 208 | } 209 | #endregion 210 | 211 | /// 212 | /// meldet den LineNode ln bei diesem TrafficLight an, sodass es weiß das es diesem zugeordnet ist 213 | /// 214 | /// anzumeldender LineNode 215 | public void AddAssignedLineNode(LineNode ln) 216 | { 217 | _assignedNodes.Add(ln); 218 | ln.tLight = this; 219 | } 220 | 221 | /// 222 | /// meldet den LineNode ln bei diesem TrafficLight wieder ab, sodass es weiß, dass es diesem nicht mehr zugeordnet ist 223 | /// 224 | /// abzumeldender LineNode 225 | /// true, falls der Abmeldevorgang erfolgreich, sonst false 226 | public bool RemoveAssignedLineNode(LineNode ln) 227 | { 228 | if (ln != null) 229 | { 230 | ln.tLight = null; 231 | return _assignedNodes.Remove(ln); 232 | } 233 | return false; 234 | } 235 | 236 | /// 237 | /// stellt die Ampel auf grün 238 | /// 239 | public void SwitchToGreen() 240 | { 241 | this.trafficLightState = State.GREEN; 242 | } 243 | /// 244 | /// stellt die Ampel auf rot 245 | /// 246 | public void SwitchToRed() 247 | { 248 | this.trafficLightState = State.RED; 249 | } 250 | 251 | 252 | /// 253 | /// meldet das TrafficLight bei den zugeordneten LineNodes ab, sodas das TrafficLight gefahrlos gelöscht werden kann. 254 | /// 255 | public override void Dispose() 256 | { 257 | base.Dispose(); 258 | 259 | while (_assignedNodes.Count > 0) 260 | { 261 | RemoveAssignedLineNode(_assignedNodes[0]); 262 | } 263 | } 264 | 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /CityTrafficSimulator/Tools/AlgorithmicGeometry.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * CityTrafficSimulator - a tool to simulate traffic in urban areas and on intersections 3 | * Copyright (C) 2005-2014, Christian Schulte zu Berge 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the 6 | * terms of the GNU General Public License as published by the Free Software 7 | * Foundation; either version 3 of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this 14 | * program; if not, see . 15 | * 16 | * Web: http://www.cszb.net 17 | * Mail: software@cszb.net 18 | */ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Drawing; 23 | using System.Drawing.Drawing2D; 24 | using System.Text; 25 | 26 | namespace CityTrafficSimulator.Tools 27 | { 28 | /// 29 | /// Implements various algorithms from algorithmic geometry 30 | /// 31 | public class AlgorithmicGeometry 32 | { 33 | /// 34 | /// Computes a GraphicsPath for the convex hull of the given points. 35 | /// Convex hull will be inflated by and contain rounded corners. 36 | /// 37 | /// Input points 38 | /// Radius for rounded corners 39 | /// A GraphicsPath of the convex hull with rounded corners 40 | public static GraphicsPath roundedConvexHullPath(List input, double radius) 41 | { 42 | GraphicsPath toReturn = new GraphicsPath(); 43 | 44 | // build convex hull 45 | LinkedList convexHull = AlgorithmicGeometry.convexHull(input); 46 | if (convexHull.Count == 0) 47 | { 48 | return toReturn; 49 | } 50 | else if (convexHull.Count == 1) 51 | { 52 | toReturn.AddEllipse((float)(convexHull.First.Value.X - radius), (float)(convexHull.First.Value.Y - radius), (float)(2 * radius), (float)(2 * radius)); 53 | return toReturn; 54 | } 55 | 56 | // add the first two points again for easier building of the GraphicsPath 57 | convexHull.AddLast(convexHull.First.Value); 58 | convexHull.AddLast(convexHull.First.Next.Value); 59 | 60 | // build GraphicsPath 61 | LinkedListNode curNode = convexHull.First; 62 | while (curNode.Next.Next != null) 63 | { 64 | // compute orthogonal vectors to point-to-point directions 65 | Vector2 ortho = (curNode.Next.Value - curNode.Value).RotatedClockwise.Normalized * radius; 66 | Vector2 nextOrtho = (curNode.Next.Next.Value - curNode.Next.Value).RotatedClockwise.Normalized * radius; 67 | 68 | // compute angles for rounded corners 69 | float start = (float)(Math.Atan2(ortho.Y, ortho.X) * 180 / Math.PI); 70 | float end = (float)(Math.Atan2(nextOrtho.Y, nextOrtho.X) * 180 / Math.PI); 71 | float sweep = end - start; 72 | if (sweep < 0) 73 | sweep += 360; 74 | 75 | toReturn.AddLine(curNode.Value + ortho, curNode.Next.Value + ortho); 76 | toReturn.AddArc((float)(curNode.Next.Value.X - radius), (float)(curNode.Next.Value.Y - radius), (float)(2 * radius), (float)(2 * radius), start, sweep); 77 | 78 | curNode = curNode.Next; 79 | } 80 | 81 | return toReturn; 82 | } 83 | 84 | /// 85 | /// Computes the convex hull of the given points in . 86 | /// 87 | /// List of points 88 | /// List of the vertices of the convex hull of . 89 | public static LinkedList convexHull(List input) 90 | { 91 | // perform copy of input list to work on 92 | List points = new List(input); 93 | 94 | // make sure point list is well defined 95 | LinkedList toReturn = new LinkedList(); 96 | if (points.Count < 3) 97 | { 98 | foreach (Vector2 p in points) 99 | toReturn.AddLast(p); 100 | return toReturn; 101 | } 102 | 103 | // find point with minimum Y coordinate 104 | Vector2 yMin = points[0]; 105 | foreach (Vector2 p in points) 106 | { 107 | if (p.Y < yMin.Y) 108 | yMin = p; 109 | } 110 | 111 | // sort points in toReturn by polar angle around yMin 112 | points.Sort(delegate(Vector2 left, Vector2 right) 113 | { 114 | if (left == right) 115 | return 0; 116 | if (left == yMin) 117 | return -1; 118 | if (right == yMin) 119 | return 1; 120 | 121 | double o = orientation(yMin, left, right); 122 | if (o > 0) 123 | return -1; 124 | else if (o == 0) 125 | return (left.Y >= yMin.Y && left.X <= right.Y) ? -1 : 1; 126 | return 1; 127 | }); 128 | 129 | // add first three points and start Graham's scan 130 | toReturn.AddLast(points[0]); 131 | toReturn.AddLast(points[1]); 132 | toReturn.AddLast(points[2]); 133 | 134 | // do Graham's scan 135 | for (int i = 3; i < points.Count; ++i) 136 | { 137 | while (!leftTurn(toReturn.Last.Previous.Value, toReturn.Last.Value, points[i])) 138 | toReturn.RemoveLast(); 139 | toReturn.AddLast(points[i]); 140 | } 141 | 142 | return toReturn; 143 | } 144 | 145 | /// 146 | /// Computes the orientation of the three points a, b, c. 147 | /// 148 | /// First point 149 | /// Second point 150 | /// Third point 151 | /// Left turn: < 0, collinear: = 0, right turn: > 0 152 | public static double orientation(Vector2 a, Vector2 b, Vector2 c) 153 | { 154 | return a.X * b.Y + a.Y * c.X + b.X * c.Y - c.X * b.Y - c.Y * a.X - b.X * a.Y; 155 | } 156 | 157 | /// 158 | /// Checks whether the three points are collinear. 159 | /// 160 | /// First point 161 | /// Second point 162 | /// Third point 163 | /// True, when a, b, c are collinear. 164 | public static bool collinear(Vector2 a, Vector2 b, Vector2 c) 165 | { 166 | return (orientation(a, b, c) == 0); 167 | } 168 | 169 | /// 170 | /// Checks whether the three points build a left turn. 171 | /// 172 | /// First point 173 | /// Second point 174 | /// Third point 175 | /// True, when a, b, c build a left turn. 176 | public static bool leftTurn(Vector2 a, Vector2 b, Vector2 c) 177 | { 178 | return (orientation(a, b, c) > 0); 179 | } 180 | 181 | /// 182 | /// Checks whether the three points build a right turn. 183 | /// 184 | /// First point 185 | /// Second point 186 | /// Third point 187 | /// True, when a, b, c build a right turn. 188 | public static bool rightTurn(Vector2 a, Vector2 b, Vector2 c) 189 | { 190 | return (orientation(a, b, c) < 0); 191 | } 192 | 193 | /// 194 | /// Checks whether point is within the circle defined by a, b, c. 195 | /// 196 | /// First point of circle 197 | /// Second point of circle 198 | /// Third point of circle 199 | /// Point to check 200 | /// True, when d is within the circle of a, b, c. 201 | public static bool inCircle(Vector2 a, Vector2 b, Vector2 c, Vector2 d) 202 | { 203 | double det = 0; 204 | det += (a.X - d.X) * (b.Y - d.Y) * ((c.X - d.X) * (c.X - d.X) + (c.Y - d.Y) * (c.Y - d.Y)); 205 | det += (a.Y - d.Y) * ((b.X - d.X) * (b.X - d.X) + (b.Y - d.Y) * (b.Y - d.Y)) * (c.X - d.X); 206 | det += ((a.X - d.X) * (a.X - d.X) + (a.Y - d.Y) * (a.Y - d.Y)) * (b.X - d.X) * (c.Y - d.Y); 207 | 208 | det -= (c.X - d.X) * (b.Y - d.Y) * ((a.X - d.X) * (a.X - d.X) + (a.Y - d.Y) * (a.Y - d.Y)); 209 | det -= (c.Y - d.Y) * ((b.X - d.X) * (b.X - d.X) + (b.Y - d.Y) * (b.Y - d.Y)) * (a.X - d.X); 210 | det -= ((c.X - d.X) * (c.X - d.X) + (c.Y - d.Y) * (c.Y - d.Y)) * (b.X - d.X) * (a.Y - d.Y); 211 | 212 | return (det < 0); 213 | } 214 | } 215 | } 216 | --------------------------------------------------------------------------------