Debian Codegraph @

Server/Web/HtmlTagSwitch.cpp

raw symbols SCIP
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/Switch.h"
22 #include "Server/Web/HtmlTagSwitch.h"
23
24 using std::string;
25 using std::to_string;
26
27 namespace Server { namespace Web
28 {
29 HtmlTagSwitch::HtmlTagSwitch(const DataModel::Switch* mySwitch)
30 : HtmlTagLayoutItem(dynamic_cast<const DataModel::LayoutItem*>(mySwitch))
31 {
32 const string& switchName = mySwitch->GetName();
33
34 string idText = to_string(mySwitch->GetID());
35
36 imageDiv.AddClass("switch_item");
37
38 const DataModel::AccessoryType type = mySwitch->GetAccessoryType();
39 switch (type)
40 {
41 case DataModel::SwitchTypeLeft:
42 image = "<polygon points=\"15,30 21,36 15,36\" fill=\"white\" />"
43 "<polygon points=\"0,15 15,30 15,36 0,21\" fill=\"gray\" class=\"turnout\"/>"
44 "<polygon points=\"15,0 21,0 21,36 15,30\" fill=\"gray\" class=\"straight\"/>";
45 imageDiv.AddAttribute("onclick", "return onClickSwitch(event, " + idText + ");");
46 break;
47
48 case DataModel::SwitchTypeRight:
49 image = "<polygon points=\"21,30 21,36 15,36\" fill=\"white\" />"
50 "<polygon points=\"21,30 36,15 36,21 21,36\" fill=\"gray\" class=\"turnout\"/>"
51 "<polygon points=\"15,0 21,0 21,30 15,36\" fill=\"gray\" class=\"straight\"/>";
52 imageDiv.AddAttribute("onclick", "return onClickSwitch(event, " + idText + ");");
53 break;
54
55 case DataModel::SwitchTypeThreeWay:
56 image = "<polygon points=\"18,33 21,36 15,36\" fill=\"white\" />"
57 "<polygon points=\"0,15 15,30 15,36 0,21\" fill=\"gray\" class=\"turnout\"/>"
58 "<polygon points=\"15,36 15,30 18,33\" fill=\"gray\" class=\"turnout straight\"/>"
59 "<polygon points=\"15,0 21,0 21,30 18,33 15,30\" fill=\"gray\" class=\"straight\"/>"
60 "<polygon points=\"21,30 21,36 18,33\" fill=\"gray\" class=\"straight third\"/>"
61 "<polygon points=\"21,30 36,15 36,21 21,36\" fill=\"gray\" class=\"third\"/>";
62 AddOnClickMenuEntry(switchName);
63 AddOnClickMenuEntry(Languages::TextSwitchStateLeft, "fireRequestAndForget('/?cmd=switchstate&switch=" + idText + "&state=turnout');", "menu_turnout");
64 AddOnClickMenuEntry(Languages::TextSwitchStateStraight, "fireRequestAndForget('/?cmd=switchstate&switch=" + idText + "&state=straight');", "menu_straight");
65 AddOnClickMenuEntry(Languages::TextSwitchStateRight, "fireRequestAndForget('/?cmd=switchstate&switch=" + idText + "&state=third');", "menu_third");
66 break;
67
68 case DataModel::SwitchTypeMaerklinLeft:
69 image = "<polygon points=\"0,15 9,24 9,30 0,21\" fill=\"white\" />"
70 "<polygon points=\"15,0 21,0 21,24 15,18\" fill=\"white\" />"
71 "<polygon points=\"27,42 36,51 36,57 27,48\" fill=\"white\" />"
72 "<polygon points=\"15,48 21,54 21,72 15,72\" fill=\"white\" />"
73 "<polygon points=\"3,24 9,30 9,42 15,48 15,54 3,42\" fill=\"gray\" class=\"turnout\" />"
74 "<polygon points=\"21,18 33,30 33,48 27,42 27,30 21,24\" fill=\"gray\" class=\"turnout\" />"
75 "<polygon points=\"9,24 15,30 15,18 21,24 21,36 27,42 27,48 21,42 21,54 15,48 15,36 9,30\" fill=\"gray\" class=\"straight\" />";
76 imageDiv.AddAttribute("onclick", "return onClickSwitch(event, " + idText + ");");
77 break;
78
79 case DataModel::SwitchTypeMaerklinRight:
80 image = "<polygon points=\"0,51 9,42 9,48 0,57\" fill=\"white\" />"
81 "<polygon points=\"15,0 21,0 21,18 15,24\" fill=\"white\" />"
82 "<polygon points=\"27,24 36,15 36,21 27,30\" fill=\"white\" />"
83 "<polygon points=\"15,54 21,48 21,72 15,72\" fill=\"white\" />"
84 "<polygon points=\"3,48 3,30 15,18 15,24 9,30 9,42\" fill=\"gray\" class=\"turnout\" />"
85 "<polygon points=\"21,48 27,42 27,30 33,24 33,42 21,54\" fill=\"gray\" class=\"turnout\" />"
86 "<polygon points=\"9,42 15,36 15,24 21,18 21,30 27,24 27,30 21,36 21,48 15,54 15,42 9,48\" fill=\"gray\" class=\"straight\" />";
87 imageDiv.AddAttribute("onclick", "return onClickSwitch(event, " + idText + ");");
88 break;
89
90 default:
91 break;
92 }
93
94 string stateClass;
95 const DataModel::AccessoryState state = mySwitch->GetAccessoryState();
96 switch (state)
97 {
98 case DataModel::SwitchStateTurnout:
99 stateClass = "switch_turnout";
100 break;
101
102 case DataModel::SwitchStateStraight:
103 stateClass = "switch_straight";
104 break;
105
106 case DataModel::SwitchStateThird:
107 stateClass = "switch_third";
108 break;
109
110 default:
111 break;
112 }
113 imageDiv.AddClass(stateClass);
114 onClickMenuDiv.AddClass(stateClass);
115
116 AddToolTip(switchName + " (addr=" + to_string(mySwitch->GetAddress()) + ")");
117 AddContextMenuEntry(switchName);
118 AddContextMenuEntry(Languages::TextReleaseSwitch, "fireRequestAndForget('/?cmd=switchrelease&switch=" + idText + "');");
119 AddContextMenuEntry(Languages::TextEditSwitch, "loadPopup('/?cmd=switchedit&switch=" + idText + "');");
120 AddContextMenuEntry(Languages::TextDeleteSwitch, "loadPopup('/?cmd=switchaskdelete&switch=" + idText + "');");
121 FinishInit();
122 }
123 }} // namespace Server::Web