Microscopic Traffic Simulator

- Main Page
- Packages
- Classes
- Files

- File List

CanvasRoadPreviewer.cs
Go to the documentation of this file.
1 using Microscopic_Traffic_Simulator.Renderers;
2 using Microscopic_Traffic_Simulator.ViewModels;
3 using System.Collections.Generic;
4 using System.Windows;
5
6 namespace Microscopic_Traffic_Simulator.Views.MainWindowView
7 {
11 class CanvasRoadPreviewer
12 {
16 private LaneBuildingRenderer currentLaneBuildingRenderer;
17
21 private Dictionary<LaneType, LaneBuildingRenderer> laneTypeToRenderer;
22
26 private TopologyRenderer topologyRenderer;
27
31 private CanvasViewModel canvasViewModel;
32
36 private LaneType previousLaneType;
37
43 internal CanvasRoadPreviewer(Dictionary<LaneType, LaneBuildingRenderer> laneTypeToRenderer,
44 TopologyRenderer topologyRenderer)
45 {
46 this.laneTypeToRenderer = laneTypeToRenderer;
47 this.topologyRenderer = topologyRenderer;
48 currentLaneBuildingRenderer = laneTypeToRenderer[previousLaneType];
49 }
50
55 internal void LaneTypeWasChanged()
56 {
57 if (previousLaneType != canvasViewModel.CurrentLaneType)
58 {
59 foreach (KeyValuePair<LaneType, LaneBuildingRenderer> laneTypeRendererTuple in laneTypeToRenderer)
60 {
61 if (laneTypeRendererTuple.Key == canvasViewModel.CurrentLaneType)
62 {
63 laneTypeToRenderer[canvasViewModel.CurrentLaneType].TransferPoints(currentLaneBuildingRenderer);
64 }
65 }
66 currentLaneBuildingRenderer = laneTypeToRenderer[canvasViewModel.CurrentLaneType];
67 foreach (KeyValuePair<LaneType, LaneBuildingRenderer> laneTypeRendererTuple in laneTypeToRenderer)
68 {
69 if (laneTypeRendererTuple.Key != canvasViewModel.CurrentLaneType)
70 {
71 laneTypeRendererTuple.Value.ResetRendererAndClearAnyPreview();
72 }
73 }
74 currentLaneBuildingRenderer.RenderBuildingLane();
75 previousLaneType = canvasViewModel.CurrentLaneType;
76 }
77 }
78
82 internal void ClearPreviewOfBuildingOfAnyRoads()
83 {
84 currentLaneBuildingRenderer.ResetRendererAndClearAnyPreview();
85 }
86
93 internal void MouseLeftButtonUp(Point cursorCanvasLocation)
94 {
95 if (currentLaneBuildingRenderer.IsSomePointBeingDragged)
96 {
97 // resets dragginf of point
98 currentLaneBuildingRenderer.ResetDraggingOfPoint();
99 }
100 else if (currentLaneBuildingRenderer.IsLaneDefined)
101 {
102 // builds new road and re-render current lane renderer and topology renderer
103 if (canvasViewModel.CurrentLaneType == LaneType.Straight)
104 {
105 canvasViewModel.BuildNewStraightLane(currentLaneBuildingRenderer.StartWorldPoint.Value,
106 currentLaneBuildingRenderer.EndWorldPoint.Value);
107 }
108 else if (canvasViewModel.CurrentLaneType == LaneType.Bezier)
109 {
110 BezierLaneBuildingRenderer bezierLaneBuildingRenderer =
111 currentLaneBuildingRenderer as BezierLaneBuildingRenderer;
112 canvasViewModel.BuildNewBezierLaneLane(bezierLaneBuildingRenderer.StartWorldPoint.Value,
113 bezierLaneBuildingRenderer.FirstWorldControlPoint.Value,
114 bezierLaneBuildingRenderer.SecondWorldControlPoint.Value,
115 bezierLaneBuildingRenderer.EndWorldPoint.Value);
116 }
117 currentLaneBuildingRenderer.ResetRendererAndClearAnyPreview();
118 topologyRenderer.RenderTopology();
119 }
120 else
121 {
122 // sets new point of a lane which is previewed
123 currentLaneBuildingRenderer.SetPoint(cursorCanvasLocation);
124 }
125 }
126
131 internal void MouseLeftButtonDown(Point cursorCanvasLocation)
132 {
133 if (currentLaneBuildingRenderer.IsLaneDefined)
134 {
135 currentLaneBuildingRenderer.InitializeDraggingModeOfAPointIfAnyIsNear(cursorCanvasLocation);
136 }
137 }
138
143 internal void RenderBuildingLane(Point cursorCanvasLocation)
144 {
145 currentLaneBuildingRenderer.RenderBuildingLane(cursorCanvasLocation);
146 }
147
152 internal void MovePointOfLaneIfCursorIsNear(Point cursorCanvasLocation)
153 {
154 if (currentLaneBuildingRenderer.IsLaneDefined)
155 {
156 currentLaneBuildingRenderer.MovePointOfLane(cursorCanvasLocation);
157 }
158 }
159
164 internal void SetCanvasViewModel(CanvasViewModel canvasViewModel)
165 {
166 this.canvasViewModel = canvasViewModel;
167 }
168 }
169 }
Microscopic_Traffic_Simulator.Renderers.TopologyRenderer
Geometric topology renderer.
Definition: TopologyRenderer.cs:12
Microscopic_Traffic_Simulator.Renderers.BezierLaneBuildingRenderer
Renderer for drawing bezier lanes during their building.
Definition: BezierLaneBuildingRenderer.cs:12
Microscopic_Traffic_Simulator.Views.MainWindowView.CanvasRoadPreviewer
Previewer of building roads on canvas.
Definition: CanvasRoadPreviewer.cs:11
System
Microscopic_Traffic_Simulator.ViewModels
Definition: CanvasViewModel.cs:8
Microscopic_Traffic_Simulator.Renderers.BezierLaneBuildingRenderer.SecondWorldControlPoint
Point SecondWorldControlPoint
The second control point of a previewing building lane.
Definition: BezierLaneBuildingRenderer.cs:49
Microscopic_Traffic_Simulator.ViewModels.CanvasViewModel
Viewmodel for canvas panel.
Definition: CanvasViewModel.cs:13
Microscopic_Traffic_Simulator.Renderers.LaneBuildingRenderer
Renderer for drawing lanes during their building.
Definition: LaneBuildingRenderer.cs:12
Microscopic_Traffic_Simulator
Definition: App.xaml.cs:12
Microscopic_Traffic_Simulator.Renderers
Definition: BezierCurveGeometryCreator.cs:5
Microscopic_Traffic_Simulator.Renderers.BezierLaneBuildingRenderer.FirstWorldControlPoint
Point FirstWorldControlPoint
The first control point of a previewing building lane.
Definition: BezierLaneBuildingRenderer.cs:35