Microscopic Traffic Simulator

- Main Page
- Packages
- Classes
- Files

- File List

GeneratorBuildingRenderer.cs
Go to the documentation of this file.
1 using Microscopic_Traffic_Simulator___Model.GeometricObjects.Lanes;
2 using System;
3 using System.Collections.Generic;
4 using System.Collections.ObjectModel;
5 using System.Linq;
6 using System.Text;
7 using System.Threading.Tasks;
8 using System.Windows;
9 using System.Windows.Media;
10
11 namespace Microscopic_Traffic_Simulator.Renderers
12 {
13 class GeneratorPossibleLocationsRenderer : VisualCanvasRenderer
14 {
15 private const double PenThickness = 1.0;
16 private const double BoldPenThickness = 2.0;
17 private const double CircleRadius = 4.0;
18 private const double CircleRadiusSquared = CircleRadius * CircleRadius;
19
20 private Pen pen = new Pen(Brushes.Blue, PenThickness);
21 private Pen boldPen = new Pen(Brushes.Blue, BoldPenThickness);
22
23 private ReadOnlyCollection<Lane> lanes;
24 internal ReadOnlyCollection<Lane> Lanes { set { lanes = value; } }
25
26 private Lane laneWithNearestStartPointToCursor = null;
27
28 internal GeneratorPossibleLocationsRenderer(DrawingVisual visual)
29 : base(visual)
30 {
31 pen.Freeze();
32 }
33
34 protected override void Render(Point currentMouseLocation)
35 {
36 RenderPossibleLocations(currentMouseLocation);
37 }
38
39 internal void MouseMove(Point currentMouseLocation)
40 {
41 Render(currentMouseLocation);
42 }
43
44 internal Lane MouseLeftButtonUp()
45 {
46 if (laneWithNearestStartPointToCursor == null)
47 {
48 return null;
49 }
50 else
51 {
52 Lane laneWithNearestStartPointToCursorToReturn = laneWithNearestStartPointToCursor;
53 return laneWithNearestStartPointToCursorToReturn;
54 }
55 }
56
57 internal void Clear()
58 {
59 laneWithNearestStartPointToCursor = null;
60 using (DrawingContext dc = visual.RenderOpen())
61 {
62
63 }
64 }
65
66 internal void RenderPossibleLocations(Point? currentMouseLocation = null)
67 {
68 using (DrawingContext dc = visual.RenderOpen())
69 {
70 dynamic laneWithNearestStartPointToCursor = null;
71 foreach (Lane lane in lanes)
72 {
73 if (!lane.StartNode.ContainsGenerator)
74 {
75 Point startPointOnCanvas = TransformRealWorldPoint(lane.StartNode.Location);
76 dc.DrawEllipse(null, pen, startPointOnCanvas, CircleRadius, CircleRadius);
77
78 if (currentMouseLocation.HasValue)
79 {
80 double distanceFromStartPointToCursorSquared =
81 (startPointOnCanvas - currentMouseLocation.Value).LengthSquared;
82
83 if (distanceFromStartPointToCursorSquared < CircleRadiusSquared &&
84 (laneWithNearestStartPointToCursor == null ||
85 distanceFromStartPointToCursorSquared <
86 laneWithNearestStartPointToCursor.DistanceToStartPointSquared))
87 {
88 laneWithNearestStartPointToCursor = new
89 {
90 Lane = lane,
91 DistanceToStartPointSquared = distanceFromStartPointToCursorSquared
92 };
93 }
94 }
95 }
96 }
97 if (laneWithNearestStartPointToCursor != null)
98 {
99 dc.DrawEllipse(null, boldPen,
100 TransformRealWorldPoint(laneWithNearestStartPointToCursor.Lane.StartNode.Location),
101 CircleRadius, CircleRadius);
102 this.laneWithNearestStartPointToCursor = laneWithNearestStartPointToCursor.Lane;
103 }
104 }
105 }
106 }
107 }
Microscopic_Traffic_Simulator.Renderers.GeneratorPossibleLocationsRenderer.Render
override void Render(Point currentMouseLocation)
Method defining render method to be implemented for all renderers. Current mouse location
Definition: GeneratorBuildingRenderer.cs:34
System
Microscopic_Traffic_Simulator.Renderers.VisualCanvasRenderer
Base class for drawing visual renderer.
Definition: VisualCanvasRenderer.cs:9
Microscopic_Traffic_Simulator___Model.GeometricObjects.Lanes.Lane.StartNode
StartNode StartNode
Node on the input end of lane.
Definition: Lane.cs:23
Microscopic_Traffic_Simulator___Model.GeometricObjects.Lanes.Lane
Represent single lane.
Definition: Lane.cs:14
Microscopic_Traffic_Simulator
Definition: App.xaml.cs:12
Microscopic_Traffic_Simulator___Model.GeometricObjects.Lanes.Lane.Lane
Lane(Point startPoint, Point endPoint)
Lane constructor.
Definition: Lane.cs:48
Microscopic_Traffic_Simulator.Renderers.GeneratorPossibleLocationsRenderer
Definition: GeneratorBuildingRenderer.cs:13
Microscopic_Traffic_Simulator___Model.GeometricObjects.Lanes
Definition: BezierLane.cs:5
Microscopic_Traffic_Simulator___Model.GeometricObjects
Definition: GeometricTopology.cs:8
Microscopic_Traffic_Simulator___Model