Debian Codegraph @

Server/Web/HtmlTagTrack.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #include "DataModel/ObjectIdentifier.h"
22 #include "DataModel/Route.h"
23 #include "DataModel/Track.h"
24 #include "Manager.h"
25 #include "Server/Web/HtmlTagTrack.h"
26
27 using DataModel::ObjectIdentifier;
28 using std::string;
29 using std::to_string;
30
31 namespace Server { namespace Web
32 {
33 HtmlTagTrack::HtmlTagTrack(const Manager& manager, const DataModel::Track* track)
34 : HtmlTagLayoutItem(dynamic_cast<const DataModel::LayoutItem*>(track))
35 {
36 const bool occupied = track->GetMainStateDelayed() == DataModel::Feedback::FeedbackStateOccupied;
37
38 const ObjectIdentifier locoBaseIdentifier = track->GetMainLocoBaseDelayed();
39 const bool reserved = locoBaseIdentifier.IsSet();
40
41 const bool blocked = track->GetMainBlocked();
42
43 onClickMenuDiv.AddClass(reserved ? "loco_known" : "loco_unknown");
44 onClickMenuDiv.AddClass(blocked ? "track_blocked" : "track_unblocked");
45 onClickMenuDiv.AddClass(track->GetLocoBaseOrientation() == OrientationRight ? "orientation_right" : "orientation_left");
46
47 const string& trackName = track->GetMainName();
48 AddOnClickMenuEntry(trackName);
49 AddContextMenuEntry(trackName);
50 const string urlIdentifier = "track=" + to_string(track->GetID());
51 const string urlMainIdentifier = "track=" + to_string(track->GetMainID());
52
53 imageDiv.AddClass("track_item");
54 string trackClass;
55 if (reserved && occupied)
56 {
57 trackClass = "track_reserved_occupied";
58 }
59 else if (reserved)
60 {
61 trackClass = "track_reserved";
62 }
63 else if (occupied)
64 {
65 trackClass = "track_occupied";
66 }
67 else if (blocked)
68 {
69 trackClass = "track_blocked";
70 }
71 else
72 {
73 trackClass = "track_free";
74 }
75
76 imageDiv.AddClass(trackClass);
77 const DataModel::LayoutItem::LayoutItemSize trackHeight = layout->GetHeight();
78 const string layoutHeight = to_string(EdgeLength * trackHeight);
79
80 switch (track->GetTrackType())
81 {
82 case DataModel::TrackTypeTurn:
83 image = "<polygon class=\"track\" points=\"0,21 0,15 21,36 15,36\"/>";
84 break;
85
86 case DataModel::TrackTypeEnd:
87 image = "<polygon class=\"track\" points=\"15,5 21,5 21," + layoutHeight + " 15," + layoutHeight + "\"/>"
88 "<polygon class=\"track\" points=\"4,10 4,5 32,5 32,10\"/>";
89 break;
90
91 case DataModel::TrackTypeBridge:
92 {
93 const string l1 = to_string(EdgeLength * trackHeight - 5);
94 const string l2 = to_string(EdgeLength * trackHeight - 3);
95 image = "<polygon class=\"track\" points=\"15,0 21,0 21," + layoutHeight + " 15," + layoutHeight + "\"/>"
96 "<polygon class=\"track\" points=\"10,3 12,5 12," + l1 + " 10," + l2 + "\"/>"
97 "<polygon class=\"track\" points=\"26,3 24,5 24," + l1 + " 26," + l2 + "\"/>";
98 break;
99 }
100
101 case DataModel::TrackTypeTunnel:
102 {
103 image = "<polygon class=\"track\" points=\"15,0 21,0 21,12 15,12\"/>"
104 "<polygon class=\"track\" points=\"5,1 10,1 10,10 12,12 24,12 26,10 26,1 31,1 31,3 28,3 28,11 25,14 11,14 8,11 8,3 5,3 \"/>";
105 const int lengthPixel = EdgeLength * trackHeight;
106 TunnelEnd(layoutHeight, lengthPixel);
107 break;
108 }
109
110 case DataModel::TrackTypeTunnelEnd:
111 {
112 const int lengthPixel = EdgeLength * trackHeight - 20;
113 TunnelEnd(layoutHeight, lengthPixel);
114 break;
115 }
116
117 case DataModel::TrackTypeLink:
118 image = "<polygon class=\"track\" points=\"15,22 21,22 21," + layoutHeight + " 15," + layoutHeight + "\"/>"
119 "<polygon class=\"track\" points=\"18,1 6,22 30,22\"/>";
120 break;
121
122 case DataModel::TrackTypeCrossingLeft:
123 image = "<polygon class=\"track\" points=\"15,0 21,0 21,36 36,51 36,57 21,42 21,72 15,72 15,36 0,21 0,15 15,30\"/>";
124 break;
125
126 case DataModel::TrackTypeCrossingRight:
127 image = "<polygon class=\"track\" points=\"15,0 21,0 21,30 36,15 36,21 21,36 21,72 15,72 15,42 0,57 0,51 15,36\"/>";
128 break;
129
130 case DataModel::TrackTypeCrossingSymetric:
131 image = "<polygon class=\"track\" points=\"36,15 36,21 21,36 36,51 36,57 18,39 0,57 0,51 15,36 0,21 0,15 18,33\"/>";
132 break;
133
134 case DataModel::TrackTypeStraight:
135 default:
136 image = "<polygon class=\"track\" points=\"15,0 21,0 21," + layoutHeight + " 15," + layoutHeight + "\"/>";
137 if (track->GetShowName())
138 {
139 const string& orientationSign = track->GetMainLocoOrientation() == OrientationRight ? "&rarr; " : "&larr; ";
140 const string& locoName = reserved ? orientationSign + manager.GetLocoBaseName(locoBaseIdentifier) : "";
141 const string textPositionX = to_string(EdgeLength * trackHeight - 1);
•142 image += "<text class=\"loconame\" x=\"-" + textPositionX + "\" y=\"11\" id=\"" + identifier + "_text_loconame\" transform=\"rotate(270 0,0)\">" + locoName + "</text>";
143 const string& displayName = track->GetMainDisplayName();
•144 image += "<text class=\"trackname\" x=\"-" + textPositionX + "\" y=\"33\" id=\"" + identifier + "_text_trackname\" transform=\"rotate(270 0,0)\">" + (displayName.size() ? displayName : trackName) + "</text>";
145 }
146 break;
147 }
148
149 imageDiv.AddAttribute("onclick", "return onClickWithMenu(event, '" + identifier + "');");
150 AddOnClickMenuEntry(Languages::TextBlockTrack, "fireRequestAndForget('/?cmd=trackblock&" + urlMainIdentifier + "&blocked=true');", "track_block");
151 AddOnClickMenuEntry(Languages::TextUnblockTrack, "fireRequestAndForget('/?cmd=trackblock&" + urlMainIdentifier + "&blocked=false');", "track_unblock");
152 AddOnClickMenuEntry(Languages::TextTurnDirectionOfTravelToLeft, "fireRequestAndForget('/?cmd=trackorientation&orientation=false&" + urlMainIdentifier + "');", "track_left");
153 AddOnClickMenuEntry(Languages::TextTurnDirectionOfTravelToRight, "fireRequestAndForget('/?cmd=trackorientation&orientation=true&" + urlMainIdentifier + "');", "track_right");
154 AddOnClickMenuEntry(Languages::TextSetLoco, "loadPopup('/?cmd=tracksetloco&" + urlMainIdentifier + "');", "track_set");
155 AddOnClickMenuEntry(Languages::TextStartLocoAutomode, "fireRequestAndForget('/?cmd=trackstartloco&" + urlMainIdentifier + "');", "track_start_loco");
156
157 const std::string trackId = std::to_string(track->GetID());
158 const std::vector<const DataModel::Route*> routes = track->GetRoutes();
159 for (auto route : routes)
160 {
161 const std::string cmd = "fireRequestAndForget('/?cmd=locoaddtimetable&track=" + trackId + "&route=" + std::to_string(route->GetID()) + "&followup=";
162 AddOnClickMenuEntry(route->GetName() + " & " + Languages::GetText(Languages::TextStop), cmd + "manual');", "track_start_loco");
163 AddOnClickMenuEntry(route->GetName() + " & " + Languages::GetText(Languages::TextAutomode), cmd + "automode');", "track_start_loco");
164 }
165
166 AddOnClickMenuEntry(Languages::TextStopLoco, "fireRequestAndForget('/?cmd=trackstoploco&" + urlMainIdentifier + "');", "track_stop_loco");
167
168 AddContextMenuEntry(Languages::TextReleaseTrack, "fireRequestAndForget('/?cmd=trackrelease&" + urlMainIdentifier + "');", "track_release");
169 AddContextMenuEntry(Languages::TextReleaseTrackAndLoco, "fireRequestAndForget('/?cmd=locorelease&" + urlMainIdentifier + "');", "track_loco_release");
170 AddContextMenuEntry(Languages::TextEditTrack, "loadPopup('/?cmd=trackedit&" + urlIdentifier + "');");
171 AddContextMenuEntry(Languages::TextDeleteTrack, "loadPopup('/?cmd=trackaskdelete&" + urlIdentifier + "');");
172 AddToolTip(trackName);
173 FinishInit();
174 }
175
176 void HtmlTagTrack::TunnelEnd(const string& layoutHeight, const unsigned int lengthPixel)
177 {
178 const string l14 = to_string(lengthPixel - 14);
179 const string l12 = to_string(lengthPixel - 12);
180 const string l11 = to_string(lengthPixel - 11);
181 const string l10 = to_string(lengthPixel - 10);
182 const string l3 = to_string(lengthPixel - 3);
183 const string l1 = to_string(lengthPixel - 1);
184 image += "<polygon class=\"track\" points=\"15," + l12 + " 21," + l12 + " 21," + layoutHeight + " 15," + layoutHeight + "\"/>"
185 "<polygon class=\"track\" points=\"5," + l1 + " 10," + l1 + " 10," + l10 + " 12," + l12 + " 24," + l12 + " 26," + l10 + " 26," + l1 + " 31," + l1 + " 31," + l3 + " 28," + l3 + " 28," + l11 + " 25," + l14 + " 11," + l14 + " 8," + l11 + " 8," + l3 + " 5," + l3 + "\"/>";
186 }
187 }} // namespace Server::Web