| 1 |
From 857fadfaf84787b9a5110d5596676688c0c25696 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Teddy <[email protected]> |
| 3 |
Date: Mon, 28 Jul 2025 14:16:31 +0200 |
| 4 |
Subject: [PATCH] Object counter added |
| 5 |
|
| 6 |
--- |
| 7 |
CMakeLists.txt | 6 ++++++ |
| 8 |
ControlInterface.h | 15 +++++++++++++++ |
| 9 |
DataModel/Cluster.cpp | 2 +- |
| 10 |
DataModel/Cluster.h | 9 +++++++-- |
| 11 |
DataModel/Counter.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 12 |
DataModel/Counter.h | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 13 |
DataModel/DataModel.h | 1 + |
| 14 |
DataModel/ObjectIdentifier.cpp | 16 ++++++++++++++++ |
| 15 |
DataModel/Relation.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- |
| 16 |
DataModel/Relation.h | 2 +- |
| 17 |
DataModel/Route.cpp | 7 +++---- |
| 18 |
DataTypes.h | 7 ++++++- |
| 19 |
Languages.cpp | 22 ++++++++++++++++++++++ |
| 20 |
Languages.h | 22 ++++++++++++++++++++++ |
| 21 |
Manager.cpp | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 22 |
Manager.h | 39 +++++++++++++++++++++++++++++++++++++++ |
| 23 |
Server/Web/HtmlTagCounter.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 24 |
Server/Web/HtmlTagCounter.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 25 |
Server/Web/HtmlTagLayoutItem.cpp | 4 ++++ |
| 26 |
Server/Web/WebClient.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------- |
| 27 |
Server/Web/WebClient.h | 3 +++ |
| 28 |
Server/Web/WebClientCounter.cpp | 242 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 29 |
Server/Web/WebClientCounter.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 30 |
Server/Web/WebClientRoute.cpp | 26 ++++++++++++++++++++++++++ |
| 31 |
Server/Web/WebServer.cpp | 18 ++++++++++++++++++ |
| 32 |
Server/Web/WebServer.h | 3 +++ |
| 33 |
Storage/StorageHandler.cpp | 18 +++++++++++++++++- |
| 34 |
Storage/StorageHandler.h | 7 +++++++ |
| 35 |
html/javascript.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 36 |
html/style.css | 4 +++- |
| 37 |
30 files changed, 1255 insertions(+), 61 deletions(-) |
| 38 |
create mode 100644 DataModel/Counter.cpp |
| 39 |
create mode 100644 DataModel/Counter.h |
| 40 |
create mode 100644 Server/Web/HtmlTagCounter.cpp |
| 41 |
create mode 100644 Server/Web/HtmlTagCounter.h |
| 42 |
create mode 100644 Server/Web/WebClientCounter.cpp |
| 43 |
create mode 100644 Server/Web/WebClientCounter.h |
| 44 |
|
| 45 |
Index: railcontrol/CMakeLists.txt |
| 46 |
=================================================================== |
| 47 |
--- railcontrol.orig/CMakeLists.txt 2025-11-24 15:27:28.933374444 +0100 |
| 48 |
+++ railcontrol/CMakeLists.txt 2025-11-24 15:27:28.925867011 +0100 |
| 49 |
@@ -24,6 +24,8 @@ |
| 50 |
DataModel/AccessoryConfig.h |
| 51 |
DataModel/Cluster.cpp |
| 52 |
DataModel/Cluster.h |
| 53 |
+DataModel/Counter.cpp |
| 54 |
+DataModel/Counter.h |
| 55 |
DataModel/DataModel.h |
| 56 |
DataModel/Feedback.cpp |
| 57 |
DataModel/Feedback.h |
| 58 |
@@ -180,6 +182,8 @@ |
| 59 |
Server/Web/HtmlTagButtonPopup.cpp |
| 60 |
Server/Web/HtmlTagButtonPopup.h |
| 61 |
Server/Web/HtmlTagButtonPopupWide.h |
| 62 |
+Server/Web/HtmlTagCounter.cpp |
| 63 |
+Server/Web/HtmlTagCounter.h |
| 64 |
Server/Web/HtmlTagFeedback.cpp |
| 65 |
Server/Web/HtmlTagFeedback.h |
| 66 |
Server/Web/HtmlTagInput.cpp |
| 67 |
@@ -233,6 +237,8 @@ |
| 68 |
Server/Web/ResponseHtmlNotImplemented.h |
| 69 |
Server/Web/WebClientCluster.cpp |
| 70 |
Server/Web/WebClientCluster.h |
| 71 |
+Server/Web/WebClientCounter.cpp |
| 72 |
+Server/Web/WebClientCounter.h |
| 73 |
Server/Web/WebClientRoute.cpp |
| 74 |
Server/Web/WebClientRoute.h |
| 75 |
Server/Web/WebClientSignal.cpp |
| 76 |
Index: railcontrol/ControlInterface.h |
| 77 |
=================================================================== |
| 78 |
--- railcontrol.orig/ControlInterface.h 2025-11-24 15:27:28.933374444 +0100 |
| 79 |
+++ railcontrol/ControlInterface.h 2025-11-24 15:27:28.925970165 +0100 |
| 80 |
@@ -35,6 +35,7 @@ |
| 81 |
namespace DataModel |
| 82 |
{ |
| 83 |
class Accessory; |
| 84 |
+ class Counter; |
| 85 |
class Loco; |
| 86 |
class Signal; |
| 87 |
class Route; |
| 88 |
@@ -308,6 +309,20 @@ |
| 89 |
{ |
| 90 |
} |
| 91 |
|
| 92 |
+ virtual void CounterDelete(__attribute__((unused)) const CounterID counterID, |
| 93 |
+ __attribute__((unused)) const std::string& name) |
| 94 |
+ { |
| 95 |
+ } |
| 96 |
+ |
| 97 |
+ virtual void CounterSettings(__attribute__((unused)) const CounterID counterID, |
| 98 |
+ __attribute__((unused)) const std::string& name) |
| 99 |
+ { |
| 100 |
+ } |
| 101 |
+ |
| 102 |
+ virtual void CounterState(__attribute__((unused)) const DataModel::Counter* const counter) |
| 103 |
+ { |
| 104 |
+ } |
| 105 |
+ |
| 106 |
virtual void LocoBaseSpeedOrientationFunctions(const DataModel::LocoBase* loco, |
| 107 |
const Speed speed, |
| 108 |
const Orientation orientation, |
| 109 |
Index: railcontrol/DataModel/Cluster.cpp |
| 110 |
=================================================================== |
| 111 |
--- railcontrol.orig/DataModel/Cluster.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 112 |
+++ railcontrol/DataModel/Cluster.cpp 2025-11-24 15:27:28.926125013 +0100 |
| 113 |
@@ -122,7 +122,7 @@ |
| 114 |
while (tracks.size() > 0) |
| 115 |
{ |
| 116 |
Relation* trackRelation = tracks.back(); |
| 117 |
- Track* track = dynamic_cast<Track*>(trackRelation->GetObject2()); |
| 118 |
+ Track* track = trackRelation->ObjectType2() == ObjectTypeTrack ? manager->GetTrack(trackRelation->ObjectID2()) : nullptr; |
| 119 |
if (track) |
| 120 |
{ |
| 121 |
track->DeleteCluster(); |
| 122 |
Index: railcontrol/DataModel/Cluster.h |
| 123 |
=================================================================== |
| 124 |
--- railcontrol.orig/DataModel/Cluster.h 2025-11-24 15:27:28.933374444 +0100 |
| 125 |
+++ railcontrol/DataModel/Cluster.h 2025-11-24 15:27:28.926242002 +0100 |
| 126 |
@@ -37,14 +37,18 @@ |
| 127 |
class Cluster : public Object |
| 128 |
{ |
| 129 |
public: |
| 130 |
- inline Cluster(__attribute__((unused)) Manager* manager, const ClusterID clusterID) |
| 131 |
+ inline Cluster(Manager* manager, |
| 132 |
+ const ClusterID clusterID) |
| 133 |
: Object(clusterID), |
| 134 |
+ manager(manager), |
| 135 |
orientation(OrientationRight) |
| 136 |
{ |
| 137 |
} |
| 138 |
|
| 139 |
- inline Cluster(const std::string& serialized) |
| 140 |
+ inline Cluster(Manager* manager, |
| 141 |
+ const std::string& serialized) |
| 142 |
: Object(ClusterNone), |
| 143 |
+ manager(manager), |
| 144 |
orientation(OrientationRight) |
| 145 |
{ |
| 146 |
Deserialize(serialized); |
| 147 |
@@ -91,6 +95,7 @@ |
| 148 |
bool CanSetLocoBaseOrientationUnlocked(const Orientation orientation, |
| 149 |
const ObjectIdentifier& locoBaseIdentifier); |
| 150 |
|
| 151 |
+ Manager* manager; |
| 152 |
Orientation orientation; |
| 153 |
mutable std::mutex orientationMutex; |
| 154 |
std::vector<DataModel::Relation*> tracks; |
| 155 |
Index: railcontrol/DataModel/Counter.cpp |
| 156 |
=================================================================== |
| 157 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 158 |
+++ railcontrol/DataModel/Counter.cpp 2025-11-24 15:27:28.926336483 +0100 |
| 159 |
@@ -0,0 +1,105 @@ |
| 160 |
+/* |
| 161 |
+RailControl - Model Railway Control Software |
| 162 |
+ |
| 163 |
+Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org |
| 164 |
+ |
| 165 |
+RailControl is free software; you can redistribute it and/or modify it |
| 166 |
+under the terms of the GNU General Public License as published by the |
| 167 |
+Free Software Foundation; either version 3, or (at your option) any |
| 168 |
+later version. |
| 169 |
+ |
| 170 |
+RailControl is distributed in the hope that it will be useful, but |
| 171 |
+WITHOUT ANY WARRANTY; without even the implied warranty of |
| 172 |
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 173 |
+See the GNU General Public License for more details. |
| 174 |
+ |
| 175 |
+You should have received a copy of the GNU General Public License |
| 176 |
+along with RailControl; see the file LICENCE. If not see |
| 177 |
+<http://www.gnu.org/licenses/>. |
| 178 |
+*/ |
| 179 |
+ |
| 180 |
+#include "DataModel/Counter.h" |
| 181 |
+#include "DataModel/LockableItem.h" |
| 182 |
+#include "Manager.h" |
| 183 |
+#include "Utils/Utils.h" |
| 184 |
+ |
| 185 |
+using std::map; |
| 186 |
+using std::string; |
| 187 |
+using std::to_string; |
| 188 |
+ |
| 189 |
+namespace DataModel |
| 190 |
+{ |
| 191 |
+ std::string Counter::Serialize() const |
| 192 |
+ { |
| 193 |
+ string str; |
| 194 |
+ str += "objectType=Counter;"; |
| 195 |
+ str += LayoutItem::Serialize(); |
| 196 |
+ str += ";counter="; |
| 197 |
+ str += to_string(counter); |
| 198 |
+ str += ";max="; |
| 199 |
+ str += to_string(max); |
| 200 |
+ str += ";min="; |
| 201 |
+ str += to_string(min); |
| 202 |
+ return str; |
| 203 |
+ } |
| 204 |
+ |
| 205 |
+ void Counter::Deserialize(const string& serialized) |
| 206 |
+ { |
| 207 |
+ map<string,string> arguments; |
| 208 |
+ ParseArguments(serialized, arguments); |
| 209 |
+ string objectType = Utils::Utils::GetStringMapEntry(arguments, "objectType"); |
| 210 |
+ if (objectType.compare("Counter") != 0) |
| 211 |
+ { |
| 212 |
+ return; |
| 213 |
+ } |
| 214 |
+ LayoutItem::Deserialize(arguments); |
| 215 |
+ counter = Utils::Utils::GetIntegerMapEntry(arguments, "counter", 0); |
| 216 |
+ max = Utils::Utils::GetIntegerMapEntry(arguments, "max", 0); |
| 217 |
+ min = Utils::Utils::GetIntegerMapEntry(arguments, "min", 0); |
| 218 |
+ } |
| 219 |
+ |
| 220 |
+ bool Counter::Check(const CounterType type) |
| 221 |
+ { |
| 222 |
+ switch(type) |
| 223 |
+ { |
| 224 |
+ case CounterTypeIncrement: |
| 225 |
+ return (counter < max); |
| 226 |
+ |
| 227 |
+ case CounterTypeDecrement: |
| 228 |
+ return (counter > min); |
| 229 |
+ |
| 230 |
+ default: |
| 231 |
+ return false; |
| 232 |
+ } |
| 233 |
+ } |
| 234 |
+ |
| 235 |
+ bool Counter::Count(const CounterType type) |
| 236 |
+ { |
| 237 |
+ std::lock_guard<std::mutex> Guard(countMutex); |
| 238 |
+ switch(type) |
| 239 |
+ { |
| 240 |
+ case CounterTypeIncrement: |
| 241 |
+ { |
| 242 |
+ if (counter >= max) |
| 243 |
+ { |
| 244 |
+ return false; |
| 245 |
+ } |
| 246 |
+ ++counter; |
| 247 |
+ return true; |
| 248 |
+ } |
| 249 |
+ |
| 250 |
+ case CounterTypeDecrement: |
| 251 |
+ { |
| 252 |
+ if (counter <= min) |
| 253 |
+ { |
| 254 |
+ return false; |
| 255 |
+ } |
| 256 |
+ --counter; |
| 257 |
+ return true; |
| 258 |
+ } |
| 259 |
+ |
| 260 |
+ default: |
| 261 |
+ return false; |
| 262 |
+ } |
| 263 |
+ } |
| 264 |
+} // namespace DataModel |
| 265 |
Index: railcontrol/DataModel/Counter.h |
| 266 |
=================================================================== |
| 267 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 268 |
+++ railcontrol/DataModel/Counter.h 2025-11-24 15:27:28.926496967 +0100 |
| 269 |
@@ -0,0 +1,110 @@ |
| 270 |
+/* |
| 271 |
+RailControl - Model Railway Control Software |
| 272 |
+ |
| 273 |
+Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org |
| 274 |
+ |
| 275 |
+RailControl is free software; you can redistribute it and/or modify it |
| 276 |
+under the terms of the GNU General Public License as published by the |
| 277 |
+Free Software Foundation; either version 3, or (at your option) any |
| 278 |
+later version. |
| 279 |
+ |
| 280 |
+RailControl is distributed in the hope that it will be useful, but |
| 281 |
+WITHOUT ANY WARRANTY; without even the implied warranty of |
| 282 |
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 283 |
+See the GNU General Public License for more details. |
| 284 |
+ |
| 285 |
+You should have received a copy of the GNU General Public License |
| 286 |
+along with RailControl; see the file LICENCE. If not see |
| 287 |
+<http://www.gnu.org/licenses/>. |
| 288 |
+*/ |
| 289 |
+ |
| 290 |
+#pragma once |
| 291 |
+ |
| 292 |
+#include <string> |
| 293 |
+#include <mutex> |
| 294 |
+ |
| 295 |
+#include "DataTypes.h" |
| 296 |
+#include "DataModel/LayoutItem.h" |
| 297 |
+#include "DataModel/LockableItem.h" |
| 298 |
+ |
| 299 |
+class Manager; |
| 300 |
+ |
| 301 |
+namespace DataModel |
| 302 |
+{ |
| 303 |
+ enum CounterType : uint8_t |
| 304 |
+ { |
| 305 |
+ CounterTypeIncrement = 0, |
| 306 |
+ CounterTypeDecrement |
| 307 |
+ }; |
| 308 |
+ |
| 309 |
+ class Counter : public LayoutItem |
| 310 |
+ { |
| 311 |
+ public: |
| 312 |
+ inline Counter(__attribute__((unused)) Manager* manager, const CounterID counterID) |
| 313 |
+ : LayoutItem(counterID), |
| 314 |
+ counter(0), |
| 315 |
+ max(0), |
| 316 |
+ min(0) |
| 317 |
+ { |
| 318 |
+ } |
| 319 |
+ |
| 320 |
+ inline Counter(const std::string& serialized) |
| 321 |
+ : LayoutItem(CounterNone) |
| 322 |
+ { |
| 323 |
+ Deserialize(serialized); |
| 324 |
+ } |
| 325 |
+ |
| 326 |
+ virtual ~Counter() |
| 327 |
+ { |
| 328 |
+ } |
| 329 |
+ |
| 330 |
+ inline ObjectType GetObjectType() const override |
| 331 |
+ { |
| 332 |
+ return ObjectTypeCounter; |
| 333 |
+ } |
| 334 |
+ |
| 335 |
+ inline std::string GetLayoutType() const override |
| 336 |
+ { |
| 337 |
+ return Languages::GetText(Languages::TextCounter); |
| 338 |
+ } |
| 339 |
+ |
| 340 |
+ std::string Serialize() const override; |
| 341 |
+ |
| 342 |
+ void Deserialize(const std::string& serialized) override; |
| 343 |
+ |
| 344 |
+ bool Check(const CounterType type); |
| 345 |
+ |
| 346 |
+ bool Count(const CounterType type); |
| 347 |
+ |
| 348 |
+ inline int GetCounter() const |
| 349 |
+ { |
| 350 |
+ return counter; |
| 351 |
+ } |
| 352 |
+ |
| 353 |
+ inline void SetMax(int max) |
| 354 |
+ { |
| 355 |
+ this->max = max; |
| 356 |
+ } |
| 357 |
+ |
| 358 |
+ inline int GetMax() const |
| 359 |
+ { |
| 360 |
+ return max; |
| 361 |
+ } |
| 362 |
+ |
| 363 |
+ inline void SetMin(int min) |
| 364 |
+ { |
| 365 |
+ this->min = min; |
| 366 |
+ } |
| 367 |
+ |
| 368 |
+ inline int GetMin() const |
| 369 |
+ { |
| 370 |
+ return min; |
| 371 |
+ } |
| 372 |
+ |
| 373 |
+ private: |
| 374 |
+ mutable std::mutex countMutex; |
| 375 |
+ int counter; |
| 376 |
+ int max; |
| 377 |
+ int min; |
| 378 |
+ }; |
| 379 |
+} // namespace DataModel |
| 380 |
Index: railcontrol/DataModel/DataModel.h |
| 381 |
=================================================================== |
| 382 |
--- railcontrol.orig/DataModel/DataModel.h 2025-11-24 15:27:28.933374444 +0100 |
| 383 |
+++ railcontrol/DataModel/DataModel.h 2025-11-24 15:27:28.926671724 +0100 |
| 384 |
@@ -23,6 +23,7 @@ |
| 385 |
#include "DataModel/Accessory.h" |
| 386 |
#include "DataModel/AccessoryBase.h" |
| 387 |
#include "DataModel/Cluster.h" |
| 388 |
+#include "DataModel/Counter.h" |
| 389 |
#include "DataModel/Feedback.h" |
| 390 |
#include "DataModel/Layer.h" |
| 391 |
#include "DataModel/Loco.h" |
| 392 |
Index: railcontrol/DataModel/ObjectIdentifier.cpp |
| 393 |
=================================================================== |
| 394 |
--- railcontrol.orig/DataModel/ObjectIdentifier.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 395 |
+++ railcontrol/DataModel/ObjectIdentifier.cpp 2025-11-24 15:27:28.926748727 +0100 |
| 396 |
@@ -96,6 +96,13 @@ |
| 397 |
return; |
| 398 |
} |
| 399 |
|
| 400 |
+ objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "counter", ObjectNone)); |
| 401 |
+ if (objectID != ObjectNone) |
| 402 |
+ { |
| 403 |
+ objectType = ObjectTypeCounter; |
| 404 |
+ return; |
| 405 |
+ } |
| 406 |
+ |
| 407 |
objectType = ObjectTypeNone; |
| 408 |
} |
| 409 |
|
| 410 |
@@ -185,6 +192,12 @@ |
| 411 |
objectID = Utils::Integer::StringToInteger(text.substr(7), ObjectNone); |
| 412 |
return *this; |
| 413 |
} |
| 414 |
+ if (text.substr(0, 7).compare("counter") == 0) |
| 415 |
+ { |
| 416 |
+ objectType = ObjectTypeCounter; |
| 417 |
+ objectID = Utils::Integer::StringToInteger(text.substr(7), ObjectNone); |
| 418 |
+ return *this; |
| 419 |
+ } |
| 420 |
objectType = ObjectTypeTrack; |
| 421 |
objectID = Utils::Integer::StringToInteger(text, ObjectNone); |
| 422 |
return *this; |
| 423 |
@@ -238,6 +251,9 @@ |
| 424 |
|
| 425 |
case ObjectTypeBooster: |
| 426 |
return "booster"; |
| 427 |
+ |
| 428 |
+ case ObjectTypeCounter: |
| 429 |
+ return "counter"; |
| 430 |
} |
| 431 |
return "object"; |
| 432 |
} |
| 433 |
Index: railcontrol/DataModel/Relation.cpp |
| 434 |
=================================================================== |
| 435 |
--- railcontrol.orig/DataModel/Relation.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 436 |
+++ railcontrol/DataModel/Relation.cpp 2025-11-24 15:27:28.926830973 +0100 |
| 437 |
@@ -129,6 +129,9 @@ |
| 438 |
manager->Booster(ControlTypeInternal, static_cast<BoosterState>(data)); |
| 439 |
return true; |
| 440 |
|
| 441 |
+ case ObjectTypeCounter: |
| 442 |
+ return manager->Count(ObjectID2(), static_cast<CounterType>(data)); |
| 443 |
+ |
| 444 |
default: |
| 445 |
return false; |
| 446 |
} |
| 447 |
@@ -136,7 +139,7 @@ |
| 448 |
return true; |
| 449 |
} |
| 450 |
|
| 451 |
- LockableItem* Relation::GetObject2() |
| 452 |
+ Object* Relation::GetObject2() |
| 453 |
{ |
| 454 |
switch (ObjectType2()) |
| 455 |
{ |
| 456 |
@@ -155,6 +158,9 @@ |
| 457 |
case ObjectTypeRoute: |
| 458 |
return manager->GetRoute(ObjectID2()); |
| 459 |
|
| 460 |
+ case ObjectTypeCounter: |
| 461 |
+ return manager->GetCounter(ObjectID2()); |
| 462 |
+ |
| 463 |
default: |
| 464 |
return nullptr; |
| 465 |
} |
| 466 |
@@ -170,15 +176,34 @@ |
| 467 |
} |
| 468 |
|
| 469 |
const ObjectType objectType2 = ObjectType2(); |
| 470 |
- if (objectType2 == ObjectTypeLoco |
| 471 |
- || objectType2 == ObjectTypePause |
| 472 |
- || objectType2 == ObjectTypeMultipleUnit |
| 473 |
- || objectType2 == ObjectTypeBooster) |
| 474 |
+ switch(objectType2) |
| 475 |
{ |
| 476 |
- return true; |
| 477 |
+ case ObjectTypeLoco: |
| 478 |
+ case ObjectTypePause: |
| 479 |
+ case ObjectTypeMultipleUnit: // abused for loco orientation |
| 480 |
+ case ObjectTypeBooster: |
| 481 |
+ return true; |
| 482 |
+ |
| 483 |
+ case ObjectTypeCounter: |
| 484 |
+ { |
| 485 |
+ Counter* counter = manager->GetCounter(ObjectID2()); |
| 486 |
+ if (counter) |
| 487 |
+ { |
| 488 |
+ return counter->Check(static_cast<CounterType>(data)); |
| 489 |
+ } |
| 490 |
+ else |
| 491 |
+ { |
| 492 |
+ logger->Debug(Languages::TextRelationTargetNotFound); |
| 493 |
+ LockableItem::Release(logger, locoBaseIdentifier); |
| 494 |
+ return false; |
| 495 |
+ } |
| 496 |
+ } |
| 497 |
+ |
| 498 |
+ default: |
| 499 |
+ break; |
| 500 |
} |
| 501 |
|
| 502 |
- LockableItem* lockable = GetObject2(); |
| 503 |
+ LockableItem* lockable = dynamic_cast<LockableItem*>(GetObject2()); |
| 504 |
if (!lockable) |
| 505 |
{ |
| 506 |
logger->Debug(Languages::TextRelationTargetNotFound); |
| 507 |
@@ -204,15 +229,34 @@ |
| 508 |
} |
| 509 |
|
| 510 |
const ObjectType objectType2 = ObjectType2(); |
| 511 |
- if (objectType2 == ObjectTypeLoco |
| 512 |
- || objectType2 == ObjectTypePause |
| 513 |
- || objectType2 == ObjectTypeMultipleUnit |
| 514 |
- || objectType2 == ObjectTypeBooster) |
| 515 |
+ switch(objectType2) |
| 516 |
{ |
| 517 |
- return true; |
| 518 |
+ case ObjectTypeLoco: |
| 519 |
+ case ObjectTypePause: |
| 520 |
+ case ObjectTypeMultipleUnit: // abused for loco orientation |
| 521 |
+ case ObjectTypeBooster: |
| 522 |
+ return true; |
| 523 |
+ |
| 524 |
+ case ObjectTypeCounter: |
| 525 |
+ { |
| 526 |
+ Counter* counter = manager->GetCounter(ObjectID2()); |
| 527 |
+ if (counter) |
| 528 |
+ { |
| 529 |
+ return counter->Check(static_cast<CounterType>(data)); |
| 530 |
+ } |
| 531 |
+ else |
| 532 |
+ { |
| 533 |
+ logger->Debug(Languages::TextRelationTargetNotFound); |
| 534 |
+ LockableItem::Release(logger, locoBaseIdentifier); |
| 535 |
+ return false; |
| 536 |
+ } |
| 537 |
+ } |
| 538 |
+ |
| 539 |
+ default: |
| 540 |
+ break; |
| 541 |
} |
| 542 |
|
| 543 |
- LockableItem* lockable = GetObject2(); |
| 544 |
+ LockableItem* lockable = dynamic_cast<LockableItem*>(GetObject2()); |
| 545 |
if (!lockable) |
| 546 |
{ |
| 547 |
LockableItem::Release(logger, locoBaseIdentifier); |
| 548 |
@@ -243,10 +287,10 @@ |
| 549 |
|
| 550 |
bool Relation::Release(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier) |
| 551 |
{ |
| 552 |
- LockableItem* object = GetObject2(); |
| 553 |
- if (object) |
| 554 |
+ LockableItem* lockable = dynamic_cast<LockableItem*>(GetObject2()); |
| 555 |
+ if (lockable) |
| 556 |
{ |
| 557 |
- object->Release(logger, locoBaseIdentifier); |
| 558 |
+ lockable->Release(logger, locoBaseIdentifier); |
| 559 |
} |
| 560 |
return LockableItem::Release(logger, locoBaseIdentifier); |
| 561 |
} |
| 562 |
Index: railcontrol/DataModel/Relation.h |
| 563 |
=================================================================== |
| 564 |
--- railcontrol.orig/DataModel/Relation.h 2025-11-24 15:27:28.933374444 +0100 |
| 565 |
+++ railcontrol/DataModel/Relation.h 2025-11-24 15:27:28.926937542 +0100 |
| 566 |
@@ -109,7 +109,7 @@ |
| 567 |
return object2; |
| 568 |
} |
| 569 |
|
| 570 |
- LockableItem* GetObject2(); |
| 571 |
+ Object* GetObject2(); |
| 572 |
|
| 573 |
inline RelationType GetType() const |
| 574 |
{ |
| 575 |
Index: railcontrol/DataModel/Route.cpp |
| 576 |
=================================================================== |
| 577 |
--- railcontrol.orig/DataModel/Route.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 578 |
+++ railcontrol/DataModel/Route.cpp 2025-11-24 15:27:28.927063361 +0100 |
| 579 |
@@ -298,11 +298,10 @@ |
| 580 |
|
| 581 |
for (auto relation : relationsAtLock) |
| 582 |
{ |
| 583 |
- bool retRelation = relation->Reserve(logger, locoBaseIdentifier); |
| 584 |
- if (!retRelation) |
| 585 |
+ bool result = relation->Reserve(logger, locoBaseIdentifier); |
| 586 |
+ if (!result) |
| 587 |
{ |
| 588 |
- const LockableItem* item = relation->GetObject2(); |
| 589 |
- const Object* object = dynamic_cast<const Object*>(item); |
| 590 |
+ const Object* object = relation->GetObject2(); |
| 591 |
const string objectName = object ? object->GetName() : Languages::GetText(Languages::TextUnknownElement); |
| 592 |
logger->Debug(Languages::TextUnableToReserveRouteElement, GetName(), objectName); |
| 593 |
ReleaseInternalWithToTrack(logger, locoBaseIdentifier); |
| 594 |
Index: railcontrol/DataTypes.h |
| 595 |
=================================================================== |
| 596 |
--- railcontrol.orig/DataTypes.h 2025-11-24 15:27:28.933374444 +0100 |
| 597 |
+++ railcontrol/DataTypes.h 2025-11-24 15:27:28.927173287 +0100 |
| 598 |
@@ -70,6 +70,9 @@ |
| 599 |
// text |
| 600 |
typedef ObjectID TextID; |
| 601 |
|
| 602 |
+// counter |
| 603 |
+typedef ObjectID CounterID; |
| 604 |
+ |
| 605 |
static const Address AddressNone = 0; |
| 606 |
static const Address AddressDefault = 3; |
| 607 |
static const LocoID LocoNone = 0; |
| 608 |
@@ -90,6 +93,7 @@ |
| 609 |
static const SignalID SignalNone = 0; |
| 610 |
static const ClusterID ClusterNone = 0; |
| 611 |
static const TextID TextNone = 0; |
| 612 |
+static const CounterID CounterNone = 0; |
| 613 |
|
| 614 |
static const Speed MaxSpeed = 1023; |
| 615 |
static const Speed DefaultTravelSpeed = 700; |
| 616 |
@@ -238,7 +242,8 @@ |
| 617 |
ObjectTypeText = 11, |
| 618 |
ObjectTypePause = 12, |
| 619 |
ObjectTypeMultipleUnit = 13, |
| 620 |
- ObjectTypeBooster = 14 |
| 621 |
+ ObjectTypeBooster = 14, |
| 622 |
+ ObjectTypeCounter = 15 |
| 623 |
}; |
| 624 |
|
| 625 |
enum Orientation : uint8_t |
| 626 |
Index: railcontrol/Languages.cpp |
| 627 |
=================================================================== |
| 628 |
--- railcontrol.orig/Languages.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 629 |
+++ railcontrol/Languages.cpp 2025-11-24 15:27:28.927350913 +0100 |
| 630 |
@@ -57,6 +57,7 @@ |
| 631 |
/* TextAccessoryUpdated */ { "Accessory {0} updated", "Zubehörartikel {0} aktualisiert", "Accessorio {0} actualizado" }, |
| 632 |
/* TextActualAndStoredProtocolsDiffer */ { "Actual ({0}) and stored ({1}) protocols differ", "Aktuelles ({0}) und gespeichertes ({1}) Protokoll unterscheiden sich", "protocolo reciente y guardado son diferentes" }, |
| 633 |
/* TextAddAccessory */ { "Add accessory", "Zubehörartikel hinzufügen", "Añadir accesorio" }, |
| 634 |
+/* TextAddCounter */ { "Add counter", "Zähler hinzufügen", "Añadir contador" }, |
| 635 |
/* TextAddFeedback */ { "Add feedback", "Rückmelder hinzufügen", "Añadir retroseñal" }, |
| 636 |
/* TextAddRoute */ { "Add route", "Fahrstrasse hinzufügen", "Añadir itinerario" }, |
| 637 |
/* TextAddSignal */ { "Add signal", "Signal hinzufügen", "Añadir señal" }, |
| 638 |
@@ -135,6 +136,17 @@ |
| 639 |
/* TextControlSaved */ { "Control {0} saved", "Zentrale {0} gespeichert", "Control {0} guardado" }, |
| 640 |
/* TextControls */ { "Controls", "Zentralen", "Controls" }, |
| 641 |
/* TextCopyingFromTo */ { "Copying from {0} to {1}", "Kopiere von {0} nach {1}", "Copiando de {0} a {1}" }, |
| 642 |
+/* TextCounter */ { "Counter", "Zähler", "Contador" }, |
| 643 |
+/* TextCounterDecrement */ { "Decrement counter", "Zähler reduzieren", "Reducir contador" }, |
| 644 |
+/* TextCounterDecremented */ { "Counter decremented", "Zähler reduziert", "Contador reducido" }, |
| 645 |
+/* TextCounterDeleted */ { "Counter {0} deleted", "Zähler {0} gelöscht", "Contador {0} eliminado" }, |
| 646 |
+/* TextCounterDoesNotExist */ { "Counter does not exist", "Zähler existiert nicht", "Contador no existe" }, |
| 647 |
+/* TextCounterIncrement */ { "Increment counter", "Zähler erhöhen", "Aumentar contador" }, |
| 648 |
+/* TextCounterIncremented */ { "Counter incremented", "Zähler erhöht", "Contador aumentado" }, |
| 649 |
+/* TextCounterReachedLimit */ { "Counter reached its limit", "Zähler erreichte seine Limite", "Contador alcanzó su lÃmite" }, |
| 650 |
+/* TextCounterSaved */ { "Counter {0} saved", "Zähler {0} gespeichert", "Contador {0} guardado" }, |
| 651 |
+/* TextCounterUpdated */ { "Counter {0} updated", "Zähler {0} aktualisiert", "Contador {0} actualizado" }, |
| 652 |
+/* TextCounters */ { "Ccounters", "Zähler", "Contadors" }, |
| 653 |
/* TextCrcMissmatch */ { "CRC missmatch: {0} / {1}", "CRC Fehler: {0} / {1}", "Error CRC: {0} / {1}" }, |
| 654 |
/* TextCreatingTable */ { "Creating table {0}", "Erstelle Tabelle {0}", "Creando table {0}" }, |
| 655 |
/* TextCreepAt */ { "Creep at", "Schleichgeschwindigkeit bei", "Velocidad a rastras a" }, |
| 656 |
@@ -160,12 +172,14 @@ |
| 657 |
/* TextDebounceThreadTerminated */ { "Debounce thread terminated", "Entprellthread beendet", "Antirebote thread apagado" }, |
| 658 |
/* TextDebouncer */ { "Debouncer", "Entpreller", "Antirebote" }, |
| 659 |
/* TextDebug */ { "debug", "Entkäfern", "depurar" }, |
| 660 |
+/* TextDecrement */ { "decrement", "reduzieren", "reducir" }, |
| 661 |
/* TextDefault */ { "default", "standard", "predeterminado" }, |
| 662 |
/* TextDefaultSwitchingDuration */ { "Default switching duration (ms)", "Standard Schaltzeit (ms)", "Duración de conmutación por defecto (ms)" }, |
| 663 |
/* TextDelete */ { "Delete", "Löschen", "Eliminar" }, |
| 664 |
/* TextDeleteAccessory */ { "Delete accessory", "Zubehörartikel löschen", "Eliminar accesorio" }, |
| 665 |
/* TextDeleteCluster */ { "Delete track cluster", "Gleisgruppe löschen", "Eliminar grupo de vÃas" }, |
| 666 |
/* TextDeleteControl */ { "Delete control", "Zentrale löschen", "Eliminar control" }, |
| 667 |
+/* TextDeleteCounter */ { "Delete counter", "Zähler löschen", "Eliminar contador" }, |
| 668 |
/* TextDeleteFeedback */ { "Delete feedback", "Rückmelder löschen", "Eliminar retroseñal" }, |
| 669 |
/* TextDeleteLayer */ { "Delete layer", "Schicht löschen", "Eliminar capa" }, |
| 670 |
/* TextDeleteLoco */ { "Delete locomotive", "Lokomotive löschen", "Eliminar locomotora" }, |
| 671 |
@@ -192,6 +206,8 @@ |
| 672 |
/* TextEditAccessory */ { "Edit accessory", "Zubehörartikel bearbeiten", "Editar accesorio" }, |
| 673 |
/* TextEditClusters */ { "Edit track clusters", "Gleisgruppen bearbeiten", "Editar grupos de vÃas" }, |
| 674 |
/* TextEditControls */ { "Edit controls", "Zentralen bearbeiten", "Editar controlos" }, |
| 675 |
+/* TextEditCounter */ { "Edit counter", "Zähler bearbeiten", "Editar contador" }, |
| 676 |
+/* TextEditCounters */ { "Edit counters", "Zähler bearbeiten", "Editar contadores" }, |
| 677 |
/* TextEditFeedback */ { "Edit feedback", "Rückmelder bearbeiten", "Editar retroseñal" }, |
| 678 |
/* TextEditFeedbacks */ { "Edit feedbacks", "Rückmelder bearbeiten", "Editar retroseñales" }, |
| 679 |
/* TextEditLayers */ { "Edit layers", "Schichten bearbeiten", "Editar capas" }, |
| 680 |
@@ -272,6 +288,7 @@ |
| 681 |
/* TextHttpRequest */ { "HTTP request: {0} {1}", "HTTP Anfrage: {0} {1}", "HTTP solicitud: {0} {1}" }, |
| 682 |
/* TextIPAddress */ { "IP address", "IP Adresse", "Dirección IP" }, |
| 683 |
/* TextImport */ { "Import", "Importieren", "Importar" }, |
| 684 |
+/* TextIncrement */ { "increment", "erhöhen", "aumentar" }, |
| 685 |
/* TextIndependentOfControl */ { "Independent of control", "Unabhängig der Zentrale", "Independiente del control" }, |
| 686 |
/* TextIndex */ { "Index", "Index", "Index" }, |
| 687 |
/* TextInfo */ { "info", "Informationen", "informaciones" }, |
| 688 |
@@ -298,6 +315,7 @@ |
| 689 |
/* TextLayerDeleted */ { "Layer {0} deleted", "Schicht {0} gelöscht", "Capa {0} eliminado" }, |
| 690 |
/* TextLayerDoesNotExist */ { "Layer does not exist", "Schicht existiert nicht", "Capa no existe" }, |
| 691 |
/* TextLayerIsUsedByAccessory */ { "Layer {0} is used by accessory {1}", "Schicht {0} wird benutzt von Zubehörartikel {1}", "Capa {0} está usado por accesorio {1}" }, |
| 692 |
+/* TextLayerIsUsedByCounter */ { "Layer {0} is used by counter {1}", "Schicht {0} wird benutzt von Zähler {1}", "Capa {0} está usado por contador {1}" }, |
| 693 |
/* TextLayerIsUsedByFeedback */ { "Layer {0} is used by feedback {1}", "Schicht {0} wird benutzt von Rückmelder {1}", "Capa {0} está usado por retroseñal {1}" }, |
| 694 |
/* TextLayerIsUsedByRoute */ { "Layer {0} is used by route {1}", "Schicht {0} wird benutzt von Fahrstrasse {1}", "Capa {0} está usado por itinerario {1}" }, |
| 695 |
/* TextLayerIsUsedBySignal */ { "Layer {0} is used by signal {1}", "Schicht {0} wird benutzt von Signal {1}", "Capa {0} está usado por señal {1}" }, |
| 696 |
@@ -313,6 +331,7 @@ |
| 697 |
/* TextLoadedAccessory */ { "Loaded accessory {0}: {1}", "Zubehörartikel {0} geladen: {1}", "Cargado accesorio {0}: {1}" }, |
| 698 |
/* TextLoadedCluster */ { "Loaded track cluster {0}: {1}", "Gleisgruppe {0} geladen: {1}", "Cargado grupo de vÃas {0}: {1}" }, |
| 699 |
/* TextLoadedControl */ { "Loaded control {0}: {1}", "Zentrale {0} geladen: {1}", "Cargado control {0}: {1}" }, |
| 700 |
+/* TextLoadedCounter */ { "Loaded counter {0}: {1}", "Zähler {0} geladen: {1}", "Cargado contador {0}: {1}" }, |
| 701 |
/* TextLoadedFeedback */ { "Loaded feedback {0}: {1}", "Rückmelder {0} geladen: {1}", "Cargado retroseñal {0}: {1}" }, |
| 702 |
/* TextLoadedLayer */ { "Loaded layer {0}: {1}", "Schicht {0} geladen: {1}", "Cargado capa {0}: {1}" }, |
| 703 |
/* TextLoadedLoco */ { "Loaded locomotive {0}: {1}", "Lokomotive {0} geladen: {1}", "Cargado locomotora {0}: {1}" }, |
| 704 |
@@ -456,10 +475,12 @@ |
| 705 |
/* TextMainTrack */ { "Main track", "Hauptgleis", "VÃa principal" }, |
| 706 |
/* TextMainTrackHint */ { "If a main track is selected, then this track behaves identically to the main track and is its extension", "Wenn ein Hauptgleis ausgewählt wird, dann verhält sich dieses Gleis identisch wie das Hauptgleis und ist dessen Verlängerung", "Si se selecciona una vÃa principal, esta vÃa se comporta de forma idéntica a la vÃa principal y es su extensión" }, |
| 707 |
/* TextManager */ { "Manager", "Manager", "Manager" }, |
| 708 |
+/* TextMax */ { "Maximum", "Maximum", "Maximum" }, |
| 709 |
/* TextMaxSpeed */ { "Maximum speed", "Maximale Geschwindigkeit", "Velocidad máxima" }, |
| 710 |
/* TextMaxTrainLength */ { "Maximal train length", "Maximale Zuglänge", "Longitud de tren maxima" }, |
| 711 |
/* TextMembers */ { "Members", "Teilnehmer", "Miembros" }, |
| 712 |
/* TextMethodNotImplemented */ { "Method {0} not implemented", "Methode {0} nicht implementiert", "Methodo {0} no implementado" }, |
| 713 |
+/* TextMin */ { "Minimum", "Minimum", "Minimum" }, |
| 714 |
/* TextMinTrackLength */ { "Minimal track length", "Kürzestes Gleis", "VÃa más corta" }, |
| 715 |
/* TextMinTrainLength */ { "Minimal train length", "Minimale Zuglänge", "Longitud de tren minima" }, |
| 716 |
/* TextMultipleUnit */ { "Multiple unit", "Mehrfachtraktion", "Unidad múltiple" }, |
| 717 |
@@ -809,6 +830,7 @@ |
| 718 |
/* TextUnableToAddAccessory */ { "Unable to add accessory", "Nicht möglich den Zubehörartikel hinzuzufügen ", "Imposible añadir el accesorio" }, |
| 719 |
/* TextUnableToAddCluster */ { "Unable to add track cluster", "Nicht möglich die Gleisgruppe hinzuzufügen ", "Imposible añadir el grupo de vÃas" }, |
| 720 |
/* TextUnableToAddControl */ { "Unable to add control", "Nicht möglich die Zentrale hinzuzufügen ", "Imposible añadir el control" }, |
| 721 |
+/* TextUnableToAddCounter */ { "Unable to add counter", "Nicht möglich den Zähler hinzuzufügen ", "Imposible añadir el contador" }, |
| 722 |
/* TextUnableToAddFeedback */ { "Unable to add feedback", "Nicht möglich den Rückmelder hinzuzufügen ", "Imposible añadir la retroseñal" }, |
| 723 |
/* TextUnableToAddLayer */ { "Unable to add layer", "Nicht möglich die Schicht hinzuzufügen ", "Imposible añadir la capa" }, |
| 724 |
/* TextUnableToAddLayer1 */ { "Unable to add initial layer 1", "Nicht möglich die Schicht 1 hinzuzufügen", "Imposible añadir capa 1" }, |
| 725 |
Index: railcontrol/Languages.h |
| 726 |
=================================================================== |
| 727 |
--- railcontrol.orig/Languages.h 2025-11-24 15:27:28.933374444 +0100 |
| 728 |
+++ railcontrol/Languages.h 2025-11-24 15:27:28.927640427 +0100 |
| 729 |
@@ -57,6 +57,7 @@ |
| 730 |
TextAccessoryUpdated, |
| 731 |
TextActualAndStoredProtocolsDiffer, |
| 732 |
TextAddAccessory, |
| 733 |
+ TextAddCounter, |
| 734 |
TextAddFeedback, |
| 735 |
TextAddRoute, |
| 736 |
TextAddSignal, |
| 737 |
@@ -135,6 +136,17 @@ |
| 738 |
TextControlSaved, |
| 739 |
TextControls, |
| 740 |
TextCopyingFromTo, |
| 741 |
+ TextCounter, |
| 742 |
+ TextCounterDecrement, |
| 743 |
+ TextCounterDecremented, |
| 744 |
+ TextCounterDeleted, |
| 745 |
+ TextCounterDoesNotExist, |
| 746 |
+ TextCounterIncrement, |
| 747 |
+ TextCounterIncremented, |
| 748 |
+ TextCounterReachedLimit, |
| 749 |
+ TextCounterSaved, |
| 750 |
+ TextCounterUpdated, |
| 751 |
+ TextCounters, |
| 752 |
TextCrcMissmatch, |
| 753 |
TextCreatingTable, |
| 754 |
TextCreepAt, |
| 755 |
@@ -160,12 +172,14 @@ |
| 756 |
TextDebounceThreadTerminated, |
| 757 |
TextDebouncer, |
| 758 |
TextDebug, |
| 759 |
+ TextDecrement, |
| 760 |
TextDefault, |
| 761 |
TextDefaultSwitchingDuration, |
| 762 |
TextDelete, |
| 763 |
TextDeleteAccessory, |
| 764 |
TextDeleteCluster, |
| 765 |
TextDeleteControl, |
| 766 |
+ TextDeleteCounter, |
| 767 |
TextDeleteFeedback, |
| 768 |
TextDeleteLayer, |
| 769 |
TextDeleteLoco, |
| 770 |
@@ -192,6 +206,8 @@ |
| 771 |
TextEditAccessory, |
| 772 |
TextEditClusters, |
| 773 |
TextEditControls, |
| 774 |
+ TextEditCounter, |
| 775 |
+ TextEditCounters, |
| 776 |
TextEditFeedback, |
| 777 |
TextEditFeedbacks, |
| 778 |
TextEditLayers, |
| 779 |
@@ -272,6 +288,7 @@ |
| 780 |
TextHttpRequest, |
| 781 |
TextIPAddress, |
| 782 |
TextImport, |
| 783 |
+ TextIncrement, |
| 784 |
TextIndependentOfControl, |
| 785 |
TextIndex, |
| 786 |
TextInfo, |
| 787 |
@@ -298,6 +315,7 @@ |
| 788 |
TextLayerDeleted, |
| 789 |
TextLayerDoesNotExist, |
| 790 |
TextLayerIsUsedByAccessory, |
| 791 |
+ TextLayerIsUsedByCounter, |
| 792 |
TextLayerIsUsedByFeedback, |
| 793 |
TextLayerIsUsedByRoute, |
| 794 |
TextLayerIsUsedBySignal, |
| 795 |
@@ -313,6 +331,7 @@ |
| 796 |
TextLoadedAccessory, |
| 797 |
TextLoadedCluster, |
| 798 |
TextLoadedControl, |
| 799 |
+ TextLoadedCounter, |
| 800 |
TextLoadedFeedback, |
| 801 |
TextLoadedLayer, |
| 802 |
TextLoadedLoco, |
| 803 |
@@ -456,10 +475,12 @@ |
| 804 |
TextMainTrack, |
| 805 |
TextMainTrackHint, |
| 806 |
TextManager, |
| 807 |
+ TextMax, |
| 808 |
TextMaxSpeed, |
| 809 |
TextMaxTrainLength, |
| 810 |
TextMembers, |
| 811 |
TextMethodNotImplemented, |
| 812 |
+ TextMin, |
| 813 |
TextMinTrackLength, |
| 814 |
TextMinTrainLength, |
| 815 |
TextMultipleUnit, |
| 816 |
@@ -809,6 +830,7 @@ |
| 817 |
TextUnableToAddAccessory, |
| 818 |
TextUnableToAddCluster, |
| 819 |
TextUnableToAddControl, |
| 820 |
+ TextUnableToAddCounter, |
| 821 |
TextUnableToAddFeedback, |
| 822 |
TextUnableToAddLayer, |
| 823 |
TextUnableToAddLayer1, |
| 824 |
Index: railcontrol/Manager.cpp |
| 825 |
=================================================================== |
| 826 |
--- railcontrol.orig/Manager.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 827 |
+++ railcontrol/Manager.cpp 2025-11-24 15:27:28.927949369 +0100 |
| 828 |
@@ -191,6 +191,12 @@ |
| 829 |
logger->Info(Languages::TextLoadedRoute, route.second->GetID(), route.second->GetName()); |
| 830 |
} |
| 831 |
|
| 832 |
+ storage->AllCounters(counters); |
| 833 |
+ for (auto& counter : counters) |
| 834 |
+ { |
| 835 |
+ logger->Info(Languages::TextLoadedCounter, counter.second->GetID(), counter.second->GetName()); |
| 836 |
+ } |
| 837 |
+ |
| 838 |
storage->AllLocos(locos); |
| 839 |
for (auto& loco : locos) |
| 840 |
{ |
| 841 |
@@ -275,6 +281,7 @@ |
| 842 |
Storage::TransactionGuard guard(storage); |
| 843 |
DeleteAllMapEntries(multipleUnits, multipleUnitMutex); |
| 844 |
DeleteAllMapEntries(locos, locoMutex); |
| 845 |
+ DeleteAllMapEntries(counters, counterMutex); |
| 846 |
DeleteAllMapEntries(routes, routeMutex); |
| 847 |
DeleteAllMapEntries(clusters, clusterMutex); |
| 848 |
DeleteAllMapEntries(switches, switchMutex); |
| 849 |
@@ -2988,6 +2995,14 @@ |
| 850 |
return true; |
| 851 |
} |
| 852 |
} |
| 853 |
+ for (auto& counter : counters) |
| 854 |
+ { |
| 855 |
+ if (counter.second->IsVisibleOnLayer(layerId)) |
| 856 |
+ { |
| 857 |
+ result = Logger::Logger::Format(Languages::GetText(Languages::TextLayerIsUsedByCounter), layer->GetName(), counter.second->GetName()); |
| 858 |
+ return true; |
| 859 |
+ } |
| 860 |
+ } |
| 861 |
return false; |
| 862 |
} |
| 863 |
|
| 864 |
@@ -3642,6 +3657,200 @@ |
| 865 |
} |
| 866 |
|
| 867 |
/*************************** |
| 868 |
+* Counter * |
| 869 |
+***************************/ |
| 870 |
+ |
| 871 |
+DataModel::Counter* Manager::GetCounter(const CounterID counterID) const |
| 872 |
+{ |
| 873 |
+ std::lock_guard<std::mutex> guard(counterMutex); |
| 874 |
+ if (counters.count(counterID) != 1) |
| 875 |
+ { |
| 876 |
+ return nullptr; |
| 877 |
+ } |
| 878 |
+ return counters.at(counterID); |
| 879 |
+} |
| 880 |
+ |
| 881 |
+const map<string,DataModel::Counter*> Manager::CounterListByName() const |
| 882 |
+{ |
| 883 |
+ map<string,DataModel::Counter*> out; |
| 884 |
+ std::lock_guard<std::mutex> guard(counterMutex); |
| 885 |
+ for (auto& counter : counters) |
| 886 |
+ { |
| 887 |
+ out[counter.second->GetName()] = counter.second; |
| 888 |
+ } |
| 889 |
+ return out; |
| 890 |
+} |
| 891 |
+ |
| 892 |
+bool Manager::CounterSave(CounterID counterID, |
| 893 |
+ const string& name, |
| 894 |
+ const int max, |
| 895 |
+ const int min, |
| 896 |
+ const LayoutPosition posX, |
| 897 |
+ const LayoutPosition posY, |
| 898 |
+ const LayoutPosition posZ, |
| 899 |
+ const LayoutRotation rotation, |
| 900 |
+ string& result) |
| 901 |
+{ |
| 902 |
+ Counter* counter = GetCounter(counterID); |
| 903 |
+ if (!CheckLayoutItemPosition(counter, posX, posY, posZ, LayoutItem::Width1, LayoutItem::Height1, rotation, result)) |
| 904 |
+ { |
| 905 |
+ return false; |
| 906 |
+ } |
| 907 |
+ |
| 908 |
+ if (!counter) |
| 909 |
+ { |
| 910 |
+ counter = CreateAndAddObject(counters, counterMutex); |
| 911 |
+ } |
| 912 |
+ |
| 913 |
+ if (!counter) |
| 914 |
+ { |
| 915 |
+ result = Languages::GetText(Languages::TextUnableToAddCounter); |
| 916 |
+ return false; |
| 917 |
+ } |
| 918 |
+ |
| 919 |
+ // if we have a new object we have to update counterID |
| 920 |
+ counterID = counter->GetID(); |
| 921 |
+ |
| 922 |
+ // update existing counter |
| 923 |
+ counter->SetName(CheckObjectName(counters, counterMutex, counterID, name.size() == 0 ? "C" : name)); |
| 924 |
+ counter->SetMax(max); |
| 925 |
+ counter->SetMin(min); |
| 926 |
+ counter->SetPosX(posX); |
| 927 |
+ counter->SetPosY(posY); |
| 928 |
+ counter->SetPosZ(posZ); |
| 929 |
+ counter->SetWidth(LayoutItem::Width1); |
| 930 |
+ counter->SetHeight(LayoutItem::Height1); |
| 931 |
+ counter->SetRotation(rotation); |
| 932 |
+ |
| 933 |
+ CounterSaveAndPublishSettings(counter); |
| 934 |
+ return true; |
| 935 |
+} |
| 936 |
+ |
| 937 |
+bool Manager::CounterPosition(CounterID counterID, |
| 938 |
+ const LayoutPosition posX, |
| 939 |
+ const LayoutPosition posY, |
| 940 |
+ string& result) |
| 941 |
+{ |
| 942 |
+ Counter* counter = GetCounter(counterID); |
| 943 |
+ if (!counter) |
| 944 |
+ { |
| 945 |
+ result = Languages::GetText(Languages::TextCounterDoesNotExist); |
| 946 |
+ return false; |
| 947 |
+ } |
| 948 |
+ |
| 949 |
+ if (!CheckLayoutItemPosition(counter, posX, posY, counter->GetPosZ(), LayoutItem::Width1, LayoutItem::Height1, counter->GetRotation(), result)) |
| 950 |
+ { |
| 951 |
+ return false; |
| 952 |
+ } |
| 953 |
+ |
| 954 |
+ counter->SetPosX(posX); |
| 955 |
+ counter->SetPosY(posY); |
| 956 |
+ |
| 957 |
+ CounterSaveAndPublishSettings(counter); |
| 958 |
+ return true; |
| 959 |
+} |
| 960 |
+ |
| 961 |
+bool Manager::CounterRotate(CounterID counterID, |
| 962 |
+ string& result) |
| 963 |
+{ |
| 964 |
+ Counter* counter = GetCounter(counterID); |
| 965 |
+ if (!counter) |
| 966 |
+ { |
| 967 |
+ result = Languages::GetText(Languages::TextCounterDoesNotExist); |
| 968 |
+ return false; |
| 969 |
+ } |
| 970 |
+ |
| 971 |
+ LayoutRotation newRotation = counter->GetRotation(); |
| 972 |
+ ++newRotation; |
| 973 |
+ if (!CheckLayoutItemPosition(counter, counter->GetPosX(), counter->GetPosY(), counter->GetPosZ(), LayoutItem::Width1, LayoutItem::Height1, newRotation, result)) |
| 974 |
+ { |
| 975 |
+ return false; |
| 976 |
+ } |
| 977 |
+ |
| 978 |
+ counter->SetRotation(newRotation); |
| 979 |
+ |
| 980 |
+ CounterSaveAndPublishSettings(counter); |
| 981 |
+ return true; |
| 982 |
+} |
| 983 |
+ |
| 984 |
+void Manager::CounterSaveAndPublishSettings(const Counter* const counter) |
| 985 |
+{ |
| 986 |
+ // save in db |
| 987 |
+ if (storage) |
| 988 |
+ { |
| 989 |
+ TransactionGuard guard(storage); |
| 990 |
+ storage->Save(*counter); |
| 991 |
+ } |
| 992 |
+ |
| 993 |
+ std::lock_guard<std::mutex> guard(controlMutex); |
| 994 |
+ for (auto& control : controls) |
| 995 |
+ { |
| 996 |
+ control.second->CounterSettings(counter->GetID(), counter->GetName()); |
| 997 |
+ } |
| 998 |
+} |
| 999 |
+ |
| 1000 |
+void Manager::CounterPublishState(const DataModel::Counter* const counter) |
| 1001 |
+{ |
| 1002 |
+ std::lock_guard<std::mutex> guard(controlMutex); |
| 1003 |
+ for (auto& control : controls) |
| 1004 |
+ { |
| 1005 |
+ control.second->CounterState(counter); |
| 1006 |
+ } |
| 1007 |
+} |
| 1008 |
+ |
| 1009 |
+bool Manager::CounterDelete(const CounterID counterID, string& result) |
| 1010 |
+{ |
| 1011 |
+ if (counterID == CounterNone) |
| 1012 |
+ { |
| 1013 |
+ result = Languages::GetText(Languages::TextCounterDoesNotExist); |
| 1014 |
+ return false; |
| 1015 |
+ } |
| 1016 |
+ Counter* counter = nullptr; |
| 1017 |
+ { |
| 1018 |
+ std::lock_guard<std::mutex> guard(counterMutex); |
| 1019 |
+ if (counters.count(counterID) != 1) |
| 1020 |
+ { |
| 1021 |
+ result = Languages::GetText(Languages::TextCounterDoesNotExist); |
| 1022 |
+ return false; |
| 1023 |
+ } |
| 1024 |
+ |
| 1025 |
+ counter = counters.at(counterID); |
| 1026 |
+ counters.erase(counterID); |
| 1027 |
+ } |
| 1028 |
+ |
| 1029 |
+ if (storage) |
| 1030 |
+ { |
| 1031 |
+ TransactionGuard guard(storage); |
| 1032 |
+ storage->DeleteCounter(counterID); |
| 1033 |
+ } |
| 1034 |
+ |
| 1035 |
+ const string& counterName = counter->GetName(); |
| 1036 |
+ std::lock_guard<std::mutex> guard(controlMutex); |
| 1037 |
+ for (auto& control : controls) |
| 1038 |
+ { |
| 1039 |
+ control.second->CounterDelete(counterID, counterName); |
| 1040 |
+ } |
| 1041 |
+ delete counter; |
| 1042 |
+ return true; |
| 1043 |
+} |
| 1044 |
+ |
| 1045 |
+bool Manager::Count(const CounterID counterID, const CounterType type) |
| 1046 |
+{ |
| 1047 |
+ Counter* counter = GetCounter(counterID); |
| 1048 |
+ if (!counter) |
| 1049 |
+ { |
| 1050 |
+ return false; |
| 1051 |
+ } |
| 1052 |
+ const bool result = counter->Count(type); |
| 1053 |
+ if (!result) |
| 1054 |
+ { |
| 1055 |
+ return false; |
| 1056 |
+ } |
| 1057 |
+ CounterPublishState(counter); |
| 1058 |
+ return true; |
| 1059 |
+} |
| 1060 |
+ |
| 1061 |
+/*************************** |
| 1062 |
* Automode * |
| 1063 |
***************************/ |
| 1064 |
|
| 1065 |
@@ -4868,6 +5077,9 @@ |
| 1066 |
case ObjectTypeTrack: |
| 1067 |
return TrackRotate(id, result); |
| 1068 |
|
| 1069 |
+ case ObjectTypeCounter: |
| 1070 |
+ return CounterRotate(id, result); |
| 1071 |
+ |
| 1072 |
case ObjectTypeRoute: |
| 1073 |
default: |
| 1074 |
return false; |
| 1075 |
@@ -4904,6 +5116,9 @@ |
| 1076 |
case ObjectTypeTrack: |
| 1077 |
return TrackPosition(id, posX, posY, result); |
| 1078 |
|
| 1079 |
+ case ObjectTypeCounter: |
| 1080 |
+ return CounterPosition(id, posX, posY, result); |
| 1081 |
+ |
| 1082 |
default: |
| 1083 |
return false; |
| 1084 |
} |
| 1085 |
Index: railcontrol/Manager.h |
| 1086 |
=================================================================== |
| 1087 |
--- railcontrol.orig/Manager.h 2025-11-24 15:27:28.933374444 +0100 |
| 1088 |
+++ railcontrol/Manager.h 2025-11-24 15:27:28.928364912 +0100 |
| 1089 |
@@ -637,6 +637,31 @@ |
| 1090 |
bool TextDelete(const TextID textID, |
| 1091 |
std::string& result); |
| 1092 |
|
| 1093 |
+ // counter |
| 1094 |
+ DataModel::Counter* GetCounter(const CounterID counterID) const; |
| 1095 |
+ |
| 1096 |
+ bool Count(const CounterID counterID, const DataModel::CounterType type); |
| 1097 |
+ |
| 1098 |
+ inline const std::map<TextID,DataModel::Counter*>& CounterList() const |
| 1099 |
+ { |
| 1100 |
+ return counters; |
| 1101 |
+ } |
| 1102 |
+ |
| 1103 |
+ const std::map<std::string,DataModel::Counter*> CounterListByName() const; |
| 1104 |
+ |
| 1105 |
+ bool CounterSave(CounterID counterID, |
| 1106 |
+ const std::string& name, |
| 1107 |
+ const int max, |
| 1108 |
+ const int min, |
| 1109 |
+ const DataModel::LayoutItem::LayoutPosition x, |
| 1110 |
+ const DataModel::LayoutItem::LayoutPosition y, |
| 1111 |
+ const DataModel::LayoutItem::LayoutPosition z, |
| 1112 |
+ const DataModel::LayoutItem::LayoutRotation rotation, |
| 1113 |
+ std::string& result); |
| 1114 |
+ |
| 1115 |
+ bool CounterDelete(const CounterID counterID, |
| 1116 |
+ std::string& result); |
| 1117 |
+ |
| 1118 |
// automode |
| 1119 |
bool LocoBaseIntoTrack(Logger::Logger* logger, const DataModel::ObjectIdentifier& locoBaseIdentifier, const TrackID trackID); |
| 1120 |
bool LocoRelease(const LocoID locoID); |
| 1121 |
@@ -822,6 +847,11 @@ |
| 1122 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 1123 |
std::string& result); |
| 1124 |
|
| 1125 |
+ bool CounterPosition(const CounterID counterID, |
| 1126 |
+ const DataModel::LayoutItem::LayoutPosition posX, |
| 1127 |
+ const DataModel::LayoutItem::LayoutPosition posY, |
| 1128 |
+ std::string& result); |
| 1129 |
+ |
| 1130 |
bool AccessoryRotate(const AccessoryID accessoryID, |
| 1131 |
std::string& result); |
| 1132 |
|
| 1133 |
@@ -840,6 +870,9 @@ |
| 1134 |
bool TrackRotate(const TrackID trackID, |
| 1135 |
std::string& result); |
| 1136 |
|
| 1137 |
+ bool CounterRotate(const CounterID counterID, |
| 1138 |
+ std::string& result); |
| 1139 |
+ |
| 1140 |
void AccessorySaveAndPublishSettings(const DataModel::Accessory* const accessory); |
| 1141 |
void FeedbackSaveAndPublishSettings(const DataModel::Feedback* const feedback); |
| 1142 |
void RouteSaveAndPublishSettings(const DataModel::Route* const route); |
| 1143 |
@@ -847,6 +880,8 @@ |
| 1144 |
void SwitchSaveAndPublishSettings(const DataModel::Switch* const mySwitch); |
| 1145 |
void TextSaveAndPublishSettings(const DataModel::Text* const text); |
| 1146 |
void TrackSaveAndPublishSettings(const DataModel::Track* const track); |
| 1147 |
+ void CounterSaveAndPublishSettings(const DataModel::Counter* const counter); |
| 1148 |
+ void CounterPublishState(const DataModel::Counter* const counter); |
| 1149 |
|
| 1150 |
// layout |
| 1151 |
bool CheckPositionFree(const DataModel::LayoutItem::LayoutPosition posX, |
| 1152 |
@@ -1078,6 +1113,10 @@ |
| 1153 |
std::map<TextID,DataModel::Text*> texts; |
| 1154 |
mutable std::mutex textMutex; |
| 1155 |
|
| 1156 |
+ // counter |
| 1157 |
+ std::map<CounterID,DataModel::Counter*> counters; |
| 1158 |
+ mutable std::mutex counterMutex; |
| 1159 |
+ |
| 1160 |
// storage |
| 1161 |
Storage::StorageHandler* storage; |
| 1162 |
|
| 1163 |
Index: railcontrol/Server/Web/HtmlTagCounter.cpp |
| 1164 |
=================================================================== |
| 1165 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 1166 |
+++ railcontrol/Server/Web/HtmlTagCounter.cpp 2025-11-24 15:27:28.928493482 +0100 |
| 1167 |
@@ -0,0 +1,50 @@ |
| 1168 |
+/* |
| 1169 |
+RailControl - Model Railway Control Software |
| 1170 |
+ |
| 1171 |
+Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org |
| 1172 |
+ |
| 1173 |
+RailControl is free software; you can redistribute it and/or modify it |
| 1174 |
+under the terms of the GNU General Public License as published by the |
| 1175 |
+Free Software Foundation; either version 3, or (at your option) any |
| 1176 |
+later version. |
| 1177 |
+ |
| 1178 |
+RailControl is distributed in the hope that it will be useful, but |
| 1179 |
+WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1180 |
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 1181 |
+See the GNU General Public License for more details. |
| 1182 |
+ |
| 1183 |
+You should have received a copy of the GNU General Public License |
| 1184 |
+along with RailControl; see the file LICENCE. If not see |
| 1185 |
+<http://www.gnu.org/licenses/>. |
| 1186 |
+*/ |
| 1187 |
+ |
| 1188 |
+#include <sstream> |
| 1189 |
+ |
| 1190 |
+#include "DataModel/Counter.h" |
| 1191 |
+#include "Server/Web/HtmlTagCounter.h" |
| 1192 |
+ |
| 1193 |
+using std::string; |
| 1194 |
+using std::to_string; |
| 1195 |
+ |
| 1196 |
+namespace Server { namespace Web |
| 1197 |
+{ |
| 1198 |
+ HtmlTagCounter::HtmlTagCounter(const DataModel::Counter* counter) |
| 1199 |
+ : HtmlTagLayoutItem(dynamic_cast<const DataModel::LayoutItem*>(counter)) |
| 1200 |
+ { |
| 1201 |
+ const string counterIdString = to_string(counter->GetID()); |
| 1202 |
+ image = "<polygon class=\"track\" points=\"15,0 21,0 21,36 15,36\"/>" |
| 1203 |
+ "<text class=\"counter\" id=\"c_" + counterIdString + "_text\" x=\"-28\" y=\"11\" transform=\"rotate(270 0,0)\">" + to_string(counter->GetCounter()) + "</text>"; |
| 1204 |
+ |
| 1205 |
+ imageDiv.AddClass("counter_item"); |
| 1206 |
+ imageDiv.AddAttribute("onclick", "return onClickCounter(" + counterIdString + ");"); |
| 1207 |
+ |
| 1208 |
+ const string& counterName = counter->GetName(); |
| 1209 |
+ AddToolTip(counterName); |
| 1210 |
+ AddContextMenuEntry(counterName); |
| 1211 |
+ AddContextMenuEntry(Languages::TextCounterIncrement, "fireRequestAndForget('/?cmd=counterincrement&counter=" + counterIdString + "');"); |
| 1212 |
+ AddContextMenuEntry(Languages::TextCounterDecrement, "fireRequestAndForget('/?cmd=counterdecrement&counter=" + counterIdString + "');"); |
| 1213 |
+ AddContextMenuEntry(Languages::TextEditCounter, "loadPopup('/?cmd=counteredit&counter=" + counterIdString + "');"); |
| 1214 |
+ AddContextMenuEntry(Languages::TextDeleteCounter, "loadPopup('/?cmd=counteraskdelete&counter=" + counterIdString + "');"); |
| 1215 |
+ FinishInit(); |
| 1216 |
+ } |
| 1217 |
+}} // namespace Server::Web |
| 1218 |
Index: railcontrol/Server/Web/HtmlTagCounter.h |
| 1219 |
=================================================================== |
| 1220 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 1221 |
+++ railcontrol/Server/Web/HtmlTagCounter.h 2025-11-24 15:27:28.928579248 +0100 |
| 1222 |
@@ -0,0 +1,56 @@ |
| 1223 |
+/* |
| 1224 |
+RailControl - Model Railway Control Software |
| 1225 |
+ |
| 1226 |
+Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org |
| 1227 |
+ |
| 1228 |
+RailControl is free software; you can redistribute it and/or modify it |
| 1229 |
+under the terms of the GNU General Public License as published by the |
| 1230 |
+Free Software Foundation; either version 3, or (at your option) any |
| 1231 |
+later version. |
| 1232 |
+ |
| 1233 |
+RailControl is distributed in the hope that it will be useful, but |
| 1234 |
+WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1235 |
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 1236 |
+See the GNU General Public License for more details. |
| 1237 |
+ |
| 1238 |
+You should have received a copy of the GNU General Public License |
| 1239 |
+along with RailControl; see the file LICENCE. If not see |
| 1240 |
+<http://www.gnu.org/licenses/>. |
| 1241 |
+*/ |
| 1242 |
+ |
| 1243 |
+#pragma once |
| 1244 |
+ |
| 1245 |
+#include <string> |
| 1246 |
+ |
| 1247 |
+#include "Server/Web/HtmlTagLayoutItem.h" |
| 1248 |
+ |
| 1249 |
+namespace DataModel |
| 1250 |
+{ |
| 1251 |
+ class Counter; |
| 1252 |
+} |
| 1253 |
+ |
| 1254 |
+namespace Server { namespace Web |
| 1255 |
+{ |
| 1256 |
+ class HtmlTagCounter : public HtmlTagLayoutItem |
| 1257 |
+ { |
| 1258 |
+ public: |
| 1259 |
+ HtmlTagCounter() = delete; |
| 1260 |
+ HtmlTagCounter(const DataModel::Counter* counter); |
| 1261 |
+ |
| 1262 |
+ virtual ~HtmlTagCounter() |
| 1263 |
+ { |
| 1264 |
+ } |
| 1265 |
+ |
| 1266 |
+ virtual inline HtmlTag AddAttribute(const std::string& name, const std::string& value) override |
| 1267 |
+ { |
| 1268 |
+ childTags[0].AddAttribute(name, value); |
| 1269 |
+ return *this; |
| 1270 |
+ } |
| 1271 |
+ |
| 1272 |
+ virtual inline bool IsAttributeSet(const std::string& name) override |
| 1273 |
+ { |
| 1274 |
+ return childTags[0].IsAttributeSet(name); |
| 1275 |
+ } |
| 1276 |
+ }; |
| 1277 |
+}} // namespace Server::Web |
| 1278 |
+ |
| 1279 |
Index: railcontrol/Server/Web/HtmlTagLayoutItem.cpp |
| 1280 |
=================================================================== |
| 1281 |
--- railcontrol.orig/Server/Web/HtmlTagLayoutItem.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 1282 |
+++ railcontrol/Server/Web/HtmlTagLayoutItem.cpp 2025-11-24 15:27:28.928675214 +0100 |
| 1283 |
@@ -71,6 +71,10 @@ |
| 1284 |
identifier = "tx_"; |
| 1285 |
break; |
| 1286 |
|
| 1287 |
+ case ObjectTypeCounter: |
| 1288 |
+ identifier = "c_"; |
| 1289 |
+ break; |
| 1290 |
+ |
| 1291 |
default: |
| 1292 |
identifier = "unknown_"; |
| 1293 |
return; |
| 1294 |
Index: railcontrol/Server/Web/WebClient.cpp |
| 1295 |
=================================================================== |
| 1296 |
--- railcontrol.orig/Server/Web/WebClient.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 1297 |
+++ railcontrol/Server/Web/WebClient.cpp 2025-11-24 15:27:28.928863278 +0100 |
| 1298 |
@@ -46,6 +46,7 @@ |
| 1299 |
#include "Server/Web/HtmlTagButtonOK.h" |
| 1300 |
#include "Server/Web/HtmlTagButtonPopup.h" |
| 1301 |
#include "Server/Web/HtmlTagButtonPopupWide.h" |
| 1302 |
+#include "Server/Web/HtmlTagCounter.h" |
| 1303 |
#include "Server/Web/HtmlTagFeedback.h" |
| 1304 |
#include "Server/Web/HtmlTagInputCheckbox.h" |
| 1305 |
#include "Server/Web/HtmlTagInputCheckboxWithLabel.h" |
| 1306 |
@@ -650,6 +651,38 @@ |
| 1307 |
{ |
| 1308 |
cluster.HandleClusterDelete(arguments); |
| 1309 |
} |
| 1310 |
+ else if (arguments["cmd"].compare("counterlist") == 0) |
| 1311 |
+ { |
| 1312 |
+ counter.HandleCounterList(); |
| 1313 |
+ } |
| 1314 |
+ else if (arguments["cmd"].compare("counteredit") == 0) |
| 1315 |
+ { |
| 1316 |
+ counter.HandleCounterEdit(arguments); |
| 1317 |
+ } |
| 1318 |
+ else if (arguments["cmd"].compare("countersave") == 0) |
| 1319 |
+ { |
| 1320 |
+ counter.HandleCounterSave(arguments); |
| 1321 |
+ } |
| 1322 |
+ else if (arguments["cmd"].compare("counteraskdelete") == 0) |
| 1323 |
+ { |
| 1324 |
+ counter.HandleCounterAskDelete(arguments); |
| 1325 |
+ } |
| 1326 |
+ else if (arguments["cmd"].compare("counterdelete") == 0) |
| 1327 |
+ { |
| 1328 |
+ counter.HandleCounterDelete(arguments); |
| 1329 |
+ } |
| 1330 |
+ else if (arguments["cmd"].compare("counterget") == 0) |
| 1331 |
+ { |
| 1332 |
+ counter.HandleCounterGet(arguments); |
| 1333 |
+ } |
| 1334 |
+ else if (arguments["cmd"].compare("counterincrement") == 0) |
| 1335 |
+ { |
| 1336 |
+ counter.HandleCounterIncrement(arguments); |
| 1337 |
+ } |
| 1338 |
+ else if (arguments["cmd"].compare("counterdecrement") == 0) |
| 1339 |
+ { |
| 1340 |
+ counter.HandleCounterDecrement(arguments); |
| 1341 |
+ } |
| 1342 |
else if (arguments["cmd"].compare("newposition") == 0) |
| 1343 |
{ |
| 1344 |
HandleNewPosition(arguments); |
| 1345 |
@@ -2026,6 +2059,26 @@ |
| 1346 |
content.AddChildTag(HtmlTagText(text.second)); |
| 1347 |
} |
| 1348 |
|
| 1349 |
+ const map<SwitchID,DataModel::Track*>& tracks = manager.TrackList(); |
| 1350 |
+ for (auto& track : tracks) |
| 1351 |
+ { |
| 1352 |
+ if (track.second->IsVisibleOnLayer(layer) == false) |
| 1353 |
+ { |
| 1354 |
+ continue; |
| 1355 |
+ } |
| 1356 |
+ content.AddChildTag(HtmlTagTrack(manager, track.second)); |
| 1357 |
+ } |
| 1358 |
+ |
| 1359 |
+ const map<SignalID,DataModel::Signal*>& signals = manager.SignalList(); |
| 1360 |
+ for (auto& signal : signals) |
| 1361 |
+ { |
| 1362 |
+ if (signal.second->IsVisibleOnLayer(layer) == false) |
| 1363 |
+ { |
| 1364 |
+ continue; |
| 1365 |
+ } |
| 1366 |
+ content.AddChildTag(HtmlTagSignal(manager, signal.second)); |
| 1367 |
+ } |
| 1368 |
+ |
| 1369 |
const map<AccessoryID,DataModel::Accessory*>& accessories = manager.AccessoryList(); |
| 1370 |
for (auto& accessory : accessories) |
| 1371 |
{ |
| 1372 |
@@ -2046,14 +2099,14 @@ |
| 1373 |
content.AddChildTag(HtmlTagSwitch(mySwitch.second)); |
| 1374 |
} |
| 1375 |
|
| 1376 |
- const map<SwitchID,DataModel::Track*>& tracks = manager.TrackList(); |
| 1377 |
- for (auto& track : tracks) |
| 1378 |
+ const map<FeedbackID,Feedback*>& feedbacks = manager.FeedbackList(); |
| 1379 |
+ for (auto& feedback : feedbacks) |
| 1380 |
{ |
| 1381 |
- if (track.second->IsVisibleOnLayer(layer) == false) |
| 1382 |
+ if (feedback.second->IsVisibleOnLayer(layer) == false) |
| 1383 |
{ |
| 1384 |
continue; |
| 1385 |
} |
| 1386 |
- content.AddChildTag(HtmlTagTrack(manager, track.second)); |
| 1387 |
+ content.AddChildTag(HtmlTagFeedback(feedback.second)); |
| 1388 |
} |
| 1389 |
|
| 1390 |
const map<RouteID,DataModel::Route*>& routes = manager.RouteList(); |
| 1391 |
@@ -2066,24 +2119,14 @@ |
| 1392 |
content.AddChildTag(HtmlTagRoute(route.second)); |
| 1393 |
} |
| 1394 |
|
| 1395 |
- const map<FeedbackID,Feedback*>& feedbacks = manager.FeedbackList(); |
| 1396 |
- for (auto& feedback : feedbacks) |
| 1397 |
- { |
| 1398 |
- if (feedback.second->IsVisibleOnLayer(layer) == false) |
| 1399 |
- { |
| 1400 |
- continue; |
| 1401 |
- } |
| 1402 |
- content.AddChildTag(HtmlTagFeedback(feedback.second)); |
| 1403 |
- } |
| 1404 |
- |
| 1405 |
- const map<SignalID,DataModel::Signal*>& signals = manager.SignalList(); |
| 1406 |
- for (auto& signal : signals) |
| 1407 |
+ const map<CounterID,DataModel::Counter*>& counters = manager.CounterList(); |
| 1408 |
+ for (auto& counter : counters) |
| 1409 |
{ |
| 1410 |
- if (signal.second->IsVisibleOnLayer(layer) == false) |
| 1411 |
+ if (counter.second->IsVisibleOnLayer(layer) == false) |
| 1412 |
{ |
| 1413 |
continue; |
| 1414 |
} |
| 1415 |
- content.AddChildTag(HtmlTagSignal(manager, signal.second)); |
| 1416 |
+ content.AddChildTag(HtmlTagCounter(counter.second)); |
| 1417 |
} |
| 1418 |
|
| 1419 |
ReplyHtmlWithHeader(content); |
| 1420 |
@@ -3443,7 +3486,7 @@ |
| 1421 |
{ |
| 1422 |
string s; |
| 1423 |
bool ok = server.NextUpdate(updateID, s); |
| 1424 |
- if (ok == false) |
| 1425 |
+ if (!ok) |
| 1426 |
{ |
| 1427 |
// FIXME: use signaling instead of sleep |
| 1428 |
Utils::Utils::SleepForMilliseconds(100); |
| 1429 |
@@ -3605,17 +3648,19 @@ |
| 1430 |
menuMain.AddChildTag(HtmlTagButtonCommand("<svg width=\"36\" height=\"36\"><polyline points=\"2,12 2,11 11,2 26,2 35,11 35,26 26,35 11,35 2,26 2,12\" stroke=\"black\" stroke-width=\"1\" fill=\"red\"/><text x=\"4\" y=\"22\" fill=\"white\" font-size=\"11\">STOP</text></svg>", "stopallimmediately", Languages::TextStopAllLocos)); |
| 1431 |
menuMain.AddChildTag(HtmlTagButtonCommand("<svg width=\"36\" height=\"36\"><polygon points=\"17,36 17,28 15,28 10,23 10,5 15,0 21,0 26,5 26,23 21,28 19,28 19,36\" fill=\"black\" /><circle cx=\"18\" cy=\"8\" r=\"4\" fill=\"red\" /><circle cx=\"18\" cy=\"20\" r=\"4\" fill=\"darkgray\" /></svg>", "stopall", Languages::TextSetAllLocosToManualMode)); |
| 1432 |
menuMain.AddChildTag(HtmlTagButtonCommand("<svg width=\"36\" height=\"36\"><polygon points=\"17,36 17,28 15,28 10,23 10,5 15,0 21,0 26,5 26,23 21,28 19,28 19,36\" fill=\"black\" /><circle cx=\"18\" cy=\"8\" r=\"4\" fill=\"darkgray\" /><circle cx=\"18\" cy=\"20\" r=\"4\" fill=\"green\" /></svg>", "startall", Languages::TextSetAllLocosToAutomode)); |
| 1433 |
- menuMain.AddChildTag(HtmlTag().AddContent(" ")); |
| 1434 |
+ menuMain.AddChildTag(HtmlTag().AddContent(" ")); |
| 1435 |
menu.AddChildTag(menuMain); |
| 1436 |
|
| 1437 |
HtmlTag menuAdd("div"); |
| 1438 |
menuAdd.AddClass("menu_add"); |
| 1439 |
menuAdd.AddChildTag(HtmlTagButtonCommandFullScreen()); |
| 1440 |
- menuAdd.AddChildTag(HtmlTag().AddContent(" ")); |
| 1441 |
+ menuAdd.AddChildTag(HtmlTag().AddContent(" ")); |
| 1442 |
+ menuAdd.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><circle r=\"7\" cx=\"14\" cy=\"14\" fill=\"black\" /><line x1=\"14\" y1=\"5\" x2=\"14\" y2=\"23\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"9.5\" y1=\"6.2\" x2=\"18.5\" y2=\"21.8\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"6.2\" y1=\"9.5\" x2=\"21.8\" y2=\"18.5\" stroke-width=\"2\" stroke=\"black\" /><line y1=\"14\" x1=\"5\" y2=\"14\" x2=\"23\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"9.5\" y1=\"21.8\" x2=\"18.5\" y2=\"6.2\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"6.2\" y1=\"18.5\" x2=\"21.8\" y2=\"9.5\" stroke-width=\"2\" stroke=\"black\" /><circle r=\"5\" cx=\"14\" cy=\"14\" fill=\"white\" /><circle r=\"4\" cx=\"24\" cy=\"24\" fill=\"black\" /><line x1=\"18\" y1=\"24\" x2=\"30\" y2=\"24\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"28.2\" y1=\"28.2\" x2=\"19.8\" y2=\"19.8\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"24\" y1=\"18\" x2=\"24\" y2=\"30\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"19.8\" y1=\"28.2\" x2=\"28.2\" y2=\"19.8\" stroke-width=\"2\" stroke=\"black\" /><circle r=\"2\" cx=\"24\" cy=\"24\" fill=\"white\" /></svg>", "settingsedit", Languages::TextEditSettings)); |
| 1443 |
+ menuAdd.AddChildTag(HtmlTag().AddContent(" ")); |
| 1444 |
if (manager.CanHandle(Hardware::CapabilityProgram)) |
| 1445 |
{ |
| 1446 |
menuAdd.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"1,5 35,5\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"1,16 35,16\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"3,3 3,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"6,3 6,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"9,3 9,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"12,3 12,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"15,3 15,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"18,3 18,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"21,3 21,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"24,3 24,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"27,3 27,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"30,3 30,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"33,3 33,18\" stroke=\"black\" stroke-width=\"1\" /><text x=\"3\" y=\"31\" fill=\"black\" >Prog</text></svg>", "program", Languages::TextProgrammer)); |
| 1447 |
- menuAdd.AddChildTag(HtmlTag().AddContent(" ")); |
| 1448 |
+ menuAdd.AddChildTag(HtmlTag().AddContent(" ")); |
| 1449 |
} |
| 1450 |
menu.AddChildTag(menuAdd); |
| 1451 |
|
| 1452 |
@@ -3623,14 +3668,12 @@ |
| 1453 |
menuConfigButton.AddClass("menu_configbutton"); |
| 1454 |
menuConfigButton.AddId("menu_configbutton"); |
| 1455 |
menuConfigButton.AddChildTag(HtmlTagButton("<svg width=\"36\" height=\"36\"><polyline points=\"5,11 31,11\" stroke=\"black\" stroke-width=\"3\"/><polyline points=\"5,18 31,18\" stroke=\"black\" stroke-width=\"3\"/><polyline points=\"5,25 31,25\" stroke=\"black\" stroke-width=\"3\"/></svg>", "showmenuconfig", Languages::TextConfigMenu).AddAttribute("onclick", "showMenuConfig(); return false;").AddClass("button_menuconfig")); |
| 1456 |
- menuConfigButton.AddChildTag(HtmlTag().AddContent(" ")); |
| 1457 |
+ menuConfigButton.AddChildTag(HtmlTag().AddContent(" ")); |
| 1458 |
menu.AddChildTag(menuConfigButton); |
| 1459 |
|
| 1460 |
HtmlTag menuConfig("div"); |
| 1461 |
menuConfig.AddClass("menu_config"); |
| 1462 |
menuConfig.AddId("menu_config"); |
| 1463 |
- menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><circle r=\"7\" cx=\"14\" cy=\"14\" fill=\"black\" /><line x1=\"14\" y1=\"5\" x2=\"14\" y2=\"23\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"9.5\" y1=\"6.2\" x2=\"18.5\" y2=\"21.8\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"6.2\" y1=\"9.5\" x2=\"21.8\" y2=\"18.5\" stroke-width=\"2\" stroke=\"black\" /><line y1=\"14\" x1=\"5\" y2=\"14\" x2=\"23\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"9.5\" y1=\"21.8\" x2=\"18.5\" y2=\"6.2\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"6.2\" y1=\"18.5\" x2=\"21.8\" y2=\"9.5\" stroke-width=\"2\" stroke=\"black\" /><circle r=\"5\" cx=\"14\" cy=\"14\" fill=\"white\" /><circle r=\"4\" cx=\"24\" cy=\"24\" fill=\"black\" /><line x1=\"18\" y1=\"24\" x2=\"30\" y2=\"24\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"28.2\" y1=\"28.2\" x2=\"19.8\" y2=\"19.8\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"24\" y1=\"18\" x2=\"24\" y2=\"30\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"19.8\" y1=\"28.2\" x2=\"28.2\" y2=\"19.8\" stroke-width=\"2\" stroke=\"black\" /><circle r=\"2\" cx=\"24\" cy=\"24\" fill=\"white\" /></svg>", "settingsedit", Languages::TextEditSettings)); |
| 1464 |
- menuConfig.AddChildTag(HtmlTag().AddContent(" ")); |
| 1465 |
menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polygon points=\"11,1.5 26,1.5 26,35.5 11,35.5\" fill=\"white\" style=\"stroke:black;stroke-width:1;\"/><polygon points=\"14,4.5 23,4.5 23,8.5 14,8.5\" fill=\"white\" style=\"stroke:black;stroke-width:1;\"/><circle cx=\"15.5\" cy=\"12\" r=\"1\" fill=\"black\"/><circle cx=\"18.5\" cy=\"12\" r=\"1\" fill=\"black\"/><circle cx=\"21.5\" cy=\"12\" r=\"1\" fill=\"black\"/><circle cx=\"15.5\" cy=\"15\" r=\"1\" fill=\"black\"/><circle cx=\"18.5\" cy=\"15\" r=\"1\" fill=\"black\"/><circle cx=\"21.5\" cy=\"15\" r=\"1\" fill=\"black\"/><circle cx=\"15.5\" cy=\"18\" r=\"1\" fill=\"black\"/><circle cx=\"18.5\" cy=\"18\" r=\"1\" fill=\"black\"/><circle cx=\"21.5\" cy=\"18\" r=\"1\" fill=\"black\"/><circle cx=\"15.5\" cy=\"21\" r=\"1\" fill=\"black\"/><circle cx=\"18.5\" cy=\"21\" r=\"1\" fill=\"black\"/><circle cx=\"21.5\" cy=\"21\" r=\"1\" fill=\"black\"/><circle cx=\"18.5\" cy=\"28.5\" r=\"5\" fill=\"black\"/></svg>", "controllist", Languages::TextEditControls)); |
| 1466 |
menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"0,25 35,25\" fill=\"none\" stroke=\"black\"/><polygon points=\"35,22 6,22 5,19 8,10 35,10\" stroke=\"black\" fill=\"black\"/><polygon points=\"10,12 15,12 15,15 9,15\" fill=\"white\"/><polyline points=\"16,9 20,7 16,5\" stroke=\"black\" fill=\"none\"/><circle cx=\"12\" cy=\"22\" r=\"3\"/><circle cx=\"20\" cy=\"22\" r=\"3\"/></svg>", "locolist", Languages::TextEditLocos)); |
| 1467 |
menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"0,25 35,25\" fill=\"none\" stroke=\"black\"/><polygon points=\"0,22 0,10 12,10 15,19 14,22\" stroke=\"black\" fill=\"black\"/><polygon points=\"10,12 11,15 5,15 5,12\" fill=\"white\"/><polyline points=\"8,9 4,7 8,5\" stroke=\"black\" fill=\"none\"/><circle cx=\"8\" cy=\"22\" r=\"3\"/><circle cx=\"0\" cy=\"22\" r=\"3\"/><polygon points=\"35,22 21,22 20,19 23,10 35,10\" stroke=\"black\" fill=\"black\"/><polygon points=\"25,12 30,12 30,15 24,15\" fill=\"white\"/><polyline points=\"27,9 31,7 27,5\" stroke=\"black\" fill=\"none\"/><circle cx=\"27\" cy=\"22\" r=\"3\"/><circle cx=\"35\" cy=\"22\" r=\"3\"/><polyline points=\"0,20 35,20\" fill=\"none\" stroke=\"black\"/></svg>", "multipleunitlist", Languages::TextEditMultipleUnits)); |
| 1468 |
@@ -3642,32 +3685,33 @@ |
| 1469 |
menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"1,20 10,20 30,15\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"28,17 28,20 34,20\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/></svg>", "accessorylist", Languages::TextEditAccessories)); |
| 1470 |
menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"1,25 35,25\" fill=\"none\" stroke=\"black\"/><polygon points=\"4,25 4,23 8,23 8,25\" fill=\"black\" stroke=\"black\"/><polygon points=\"35,22 16,22 15,19 18,10 35,10\" stroke=\"black\" fill=\"black\"/><polygon points=\"20,12 25,12 25,15 19,15\" fill=\"white\"/><polyline points=\"26,10 30,8 26,6\" stroke=\"black\" fill=\"none\"/><circle cx=\"22\" cy=\"22\" r=\"3\"/><circle cx=\"30\" cy=\"22\" r=\"3\"/></svg>", "feedbacklist", Languages::TextEditFeedbacks)); |
| 1471 |
menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"5,34 15,1\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"31,34 21,1\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"18,34 18,30\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"18,24 18,20\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"18,14 18,10\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"18,4 18,1\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/></svg>", "routelist", Languages::TextEditRoutes)); |
| 1472 |
+ menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><text x=\"4\" y=\"22\" fill=\"black\" font-size=\"15\">1 2</text></svg>", "counterlist", Languages::TextEditCounters)); |
| 1473 |
menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><text x=\"4\" y=\"22\" fill=\"black\" font-size=\"15\">Text</text></svg>", "textlist", Languages::TextEditTexts)); |
| 1474 |
menu.AddChildTag(menuConfig); |
| 1475 |
|
| 1476 |
body.AddChildTag(menu); |
| 1477 |
|
| 1478 |
const unsigned int MaxNumberOfLocoControls = 5; |
| 1479 |
- for (unsigned int i = 1; i <= MaxNumberOfLocoControls; ++i) |
| 1480 |
+ for (unsigned int numberOfLocoControl = 1; numberOfLocoControl <= MaxNumberOfLocoControls; ++numberOfLocoControl) |
| 1481 |
{ |
| 1482 |
- const string iText = to_string(i); |
| 1483 |
+ const string numberOfLocoControlText = to_string(numberOfLocoControl); |
| 1484 |
HtmlTag locoContainer("div"); |
| 1485 |
locoContainer.AddClass("loco_container"); |
| 1486 |
- locoContainer.AddId("loco_container_" + iText); |
| 1487 |
+ locoContainer.AddId("loco_container_" + numberOfLocoControlText); |
| 1488 |
|
| 1489 |
HtmlTag locoSelector("div"); |
| 1490 |
locoSelector.AddClass("loco_selector"); |
| 1491 |
- locoSelector.AddClass("loco_selector_" + iText); |
| 1492 |
- locoSelector.AddId("loco_selector_" + iText); |
| 1493 |
- locoSelector.AddChildTag(HtmlTagLocoSelector(iText)); |
| 1494 |
+ locoSelector.AddClass("loco_selector_" + numberOfLocoControlText); |
| 1495 |
+ locoSelector.AddId("loco_selector_" + numberOfLocoControlText); |
| 1496 |
+ locoSelector.AddChildTag(HtmlTagLocoSelector(numberOfLocoControlText)); |
| 1497 |
locoContainer.AddChildTag(locoSelector); |
| 1498 |
|
| 1499 |
HtmlTag loco("div"); |
| 1500 |
loco.AddClass("loco"); |
| 1501 |
- loco.AddClass("loco_" + iText); |
| 1502 |
- loco.AddId("loco_" + iText); |
| 1503 |
+ loco.AddClass("loco_" + numberOfLocoControlText); |
| 1504 |
+ loco.AddId("loco_" + numberOfLocoControlText); |
| 1505 |
locoContainer.AddChildTag(loco); |
| 1506 |
- if (i > 1) |
| 1507 |
+ if (numberOfLocoControl > 1) |
| 1508 |
{ |
| 1509 |
locoContainer.AddClass("hidden"); |
| 1510 |
} |
| 1511 |
@@ -3695,6 +3739,7 @@ |
| 1512 |
.AddChildTag(HtmlTag("li").AddClass("contextentry").AddContent(Languages::GetText(Languages::TextAddFeedback)).AddAttribute("onClick", "loadPopup('/?cmd=feedbackedit&feedback=0');")) |
| 1513 |
.AddChildTag(HtmlTag("li").AddClass("contextentry").AddClass("real_layer_only").AddContent(Languages::GetText(Languages::TextAddRoute)).AddAttribute("onClick", "loadPopup('/?cmd=routeedit&route=0');")) |
| 1514 |
.AddChildTag(HtmlTag("li").AddClass("contextentry").AddClass("real_layer_only").AddContent(Languages::GetText(Languages::TextAddText)).AddAttribute("onClick", "loadPopup('/?cmd=textedit&text=0');")) |
| 1515 |
+ .AddChildTag(HtmlTag("li").AddClass("contextentry").AddClass("real_layer_only").AddContent(Languages::GetText(Languages::TextAddCounter)).AddAttribute("onClick", "loadPopup('/?cmd=counteredit&counter=0');")) |
| 1516 |
)); |
| 1517 |
|
| 1518 |
connection->Send(ResponseHtmlFull("RailControl", body)); |
| 1519 |
Index: railcontrol/Server/Web/WebClient.h |
| 1520 |
=================================================================== |
| 1521 |
--- railcontrol.orig/Server/Web/WebClient.h 2025-11-24 15:27:28.933374444 +0100 |
| 1522 |
+++ railcontrol/Server/Web/WebClient.h 2025-11-24 15:27:28.929143139 +0100 |
| 1523 |
@@ -34,6 +34,7 @@ |
| 1524 |
#include "Network/TcpConnection.h" |
| 1525 |
#include "ResponseHtml.h" |
| 1526 |
#include "Server/Web/WebClientCluster.h" |
| 1527 |
+#include "Server/Web/WebClientCounter.h" |
| 1528 |
#include "Server/Web/WebClientRoute.h" |
| 1529 |
#include "Server/Web/WebClientSignal.h" |
| 1530 |
#include "Server/Web/WebClientStatic.h" |
| 1531 |
@@ -81,6 +82,7 @@ |
| 1532 |
signal(manager, *this, logger), |
| 1533 |
route(manager, *this, logger), |
| 1534 |
text(manager, *this), |
| 1535 |
+ counter(manager, *this), |
| 1536 |
headOnly(false), |
| 1537 |
buttonID(0) |
| 1538 |
{ |
| 1539 |
@@ -304,6 +306,7 @@ |
| 1540 |
WebClientSignal signal; |
| 1541 |
WebClientRoute route; |
| 1542 |
WebClientText text; |
| 1543 |
+ WebClientCounter counter; |
| 1544 |
bool headOnly; |
| 1545 |
unsigned int buttonID; |
| 1546 |
}; |
| 1547 |
Index: railcontrol/Server/Web/WebClientCounter.cpp |
| 1548 |
=================================================================== |
| 1549 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 1550 |
+++ railcontrol/Server/Web/WebClientCounter.cpp 2025-11-24 15:27:28.929232421 +0100 |
| 1551 |
@@ -0,0 +1,242 @@ |
| 1552 |
+/* |
| 1553 |
+RailControl - Model Railway Control Software |
| 1554 |
+ |
| 1555 |
+Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org |
| 1556 |
+ |
| 1557 |
+RailControl is free software; you can redistribute it and/or modify it |
| 1558 |
+under the terms of the GNU General Public License as published by the |
| 1559 |
+Free Software Foundation; either version 3, or (at your option) any |
| 1560 |
+later version. |
| 1561 |
+ |
| 1562 |
+RailControl is distributed in the hope that it will be useful, but |
| 1563 |
+WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1564 |
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 1565 |
+See the GNU General Public License for more details. |
| 1566 |
+ |
| 1567 |
+You should have received a copy of the GNU General Public License |
| 1568 |
+along with RailControl; see the file LICENCE. If not see |
| 1569 |
+<http://www.gnu.org/licenses/>. |
| 1570 |
+*/ |
| 1571 |
+ |
| 1572 |
+#include <vector> |
| 1573 |
+ |
| 1574 |
+#include "DataModel/Counter.h" |
| 1575 |
+#include "Utils/Utils.h" |
| 1576 |
+#include "Server/Web/HtmlTag.h" |
| 1577 |
+#include "Server/Web/HtmlTagButtonCancel.h" |
| 1578 |
+#include "Server/Web/HtmlTagButtonCommandWide.h" |
| 1579 |
+#include "Server/Web/HtmlTagButtonOK.h" |
| 1580 |
+#include "Server/Web/HtmlTagButtonPopupWide.h" |
| 1581 |
+#include "Server/Web/HtmlTagInputHidden.h" |
| 1582 |
+#include "Server/Web/HtmlTagInputIntegerWithLabel.h" |
| 1583 |
+#include "Server/Web/HtmlTagInputTextWithLabel.h" |
| 1584 |
+#include "Server/Web/HtmlTagCounter.h" |
| 1585 |
+#include "Server/Web/WebClient.h" |
| 1586 |
+#include "Server/Web/WebClientCounter.h" |
| 1587 |
+ |
| 1588 |
+using namespace DataModel; |
| 1589 |
+using LayoutPosition = DataModel::LayoutItem::LayoutPosition; |
| 1590 |
+using LayoutItemSize = DataModel::LayoutItem::LayoutItemSize; |
| 1591 |
+using LayoutRotation = DataModel::LayoutItem::LayoutRotation; |
| 1592 |
+using std::map; |
| 1593 |
+using std::string; |
| 1594 |
+using std::to_string; |
| 1595 |
+using std::vector; |
| 1596 |
+ |
| 1597 |
+namespace Server { namespace Web |
| 1598 |
+{ |
| 1599 |
+ void WebClientCounter::HandleCounterEdit(const map<string, string>& arguments) |
| 1600 |
+ { |
| 1601 |
+ HtmlTag content; |
| 1602 |
+ const CounterID counterID = Utils::Utils::GetIntegerMapEntry(arguments, "counter", CounterNone); |
| 1603 |
+ string name = Languages::GetText(Languages::TextNew); |
| 1604 |
+ int max = Utils::Utils::GetIntegerMapEntry(arguments, "max", 1); |
| 1605 |
+ int min = Utils::Utils::GetIntegerMapEntry(arguments, "min", 0); |
| 1606 |
+ LayoutPosition posx = Utils::Utils::GetIntegerMapEntry(arguments, "posx", 0); |
| 1607 |
+ LayoutPosition posy = Utils::Utils::GetIntegerMapEntry(arguments, "posy", 0); |
| 1608 |
+ LayoutPosition posz = Utils::Utils::GetIntegerMapEntry(arguments, "posz", LayerUndeletable); |
| 1609 |
+ LayoutRotation rotation = Utils::Utils::GetIntegerMapEntry(arguments, "rotation", DataModel::LayoutItem::Rotation0); |
| 1610 |
+ |
| 1611 |
+ if (counterID > CounterNone) |
| 1612 |
+ { |
| 1613 |
+ const DataModel::Counter* counter = manager.GetCounter(counterID); |
| 1614 |
+ if (counter != nullptr) |
| 1615 |
+ { |
| 1616 |
+ name = counter->GetName(); |
| 1617 |
+ max = counter->GetMax(); |
| 1618 |
+ min = counter->GetMin(); |
| 1619 |
+ posx = counter->GetPosX(); |
| 1620 |
+ posy = counter->GetPosY(); |
| 1621 |
+ posz = counter->GetPosZ(); |
| 1622 |
+ rotation = counter->GetRotation(); |
| 1623 |
+ } |
| 1624 |
+ } |
| 1625 |
+ |
| 1626 |
+ content.AddChildTag(HtmlTag("h1").AddContent(name).AddId("popup_title")); |
| 1627 |
+ HtmlTag tabMenu("div"); |
| 1628 |
+ tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("main", Languages::TextBasic, true)); |
| 1629 |
+ tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("position", Languages::TextPosition)); |
| 1630 |
+ |
| 1631 |
+ content.AddChildTag(tabMenu); |
| 1632 |
+ |
| 1633 |
+ HtmlTag formContent; |
| 1634 |
+ formContent.AddChildTag(HtmlTagInputHidden("cmd", "countersave")); |
| 1635 |
+ formContent.AddChildTag(HtmlTagInputHidden("counter", to_string(counterID))); |
| 1636 |
+ |
| 1637 |
+ HtmlTag mainContent("div"); |
| 1638 |
+ mainContent.AddId("tab_main"); |
| 1639 |
+ mainContent.AddClass("tab_content"); |
| 1640 |
+ mainContent.AddChildTag(HtmlTagInputTextWithLabel("name", Languages::TextName, name).AddAttribute("onkeyup", "updateName();")); |
| 1641 |
+ mainContent.AddChildTag(HtmlTagInputIntegerWithLabel("max", Languages::TextMax, max, 0, 255)); |
| 1642 |
+ mainContent.AddChildTag(HtmlTagInputIntegerWithLabel("min", Languages::TextMin, min, -255, 0)); |
| 1643 |
+ formContent.AddChildTag(mainContent); |
| 1644 |
+ |
| 1645 |
+ formContent.AddChildTag(client.HtmlTagTabPosition(posx, posy, posz, rotation)); |
| 1646 |
+ |
| 1647 |
+ content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(HtmlTag("form").AddId("editform").AddChildTag(formContent))); |
| 1648 |
+ content.AddChildTag(HtmlTagButtonCancel()); |
| 1649 |
+ content.AddChildTag(HtmlTagButtonOK()); |
| 1650 |
+ client.ReplyHtmlWithHeader(content); |
| 1651 |
+ } |
| 1652 |
+ |
| 1653 |
+ void WebClientCounter::HandleCounterSave(const map<string, string>& arguments) |
| 1654 |
+ { |
| 1655 |
+ const CounterID counterID = Utils::Utils::GetIntegerMapEntry(arguments, "counter", CounterNone); |
| 1656 |
+ const string name = Utils::Utils::GetStringMapEntry(arguments, "name"); |
| 1657 |
+ const int max = Utils::Utils::GetIntegerMapEntry(arguments, "max", 1); |
| 1658 |
+ const int min = Utils::Utils::GetIntegerMapEntry(arguments, "min", 0); |
| 1659 |
+ const LayoutPosition posX = Utils::Utils::GetIntegerMapEntry(arguments, "posx", 0); |
| 1660 |
+ const LayoutPosition posY = Utils::Utils::GetIntegerMapEntry(arguments, "posy", 0); |
| 1661 |
+ const LayoutPosition posZ = Utils::Utils::GetIntegerMapEntry(arguments, "posz", 0); |
| 1662 |
+ const LayoutRotation rotation = Utils::Utils::GetIntegerMapEntry(arguments, "rotation", DataModel::LayoutItem::Rotation0); |
| 1663 |
+ string result; |
| 1664 |
+ if (!manager.CounterSave(counterID, |
| 1665 |
+ name, |
| 1666 |
+ max, |
| 1667 |
+ min, |
| 1668 |
+ posX, |
| 1669 |
+ posY, |
| 1670 |
+ posZ, |
| 1671 |
+ rotation, |
| 1672 |
+ result)) |
| 1673 |
+ { |
| 1674 |
+ client.ReplyResponse(WebClient::ResponseError, result); |
| 1675 |
+ return; |
| 1676 |
+ } |
| 1677 |
+ |
| 1678 |
+ client.ReplyResponse(WebClient::ResponseInfo, Languages::TextCounterSaved, name); |
| 1679 |
+ } |
| 1680 |
+ |
| 1681 |
+ void WebClientCounter::HandleCounterList() |
| 1682 |
+ { |
| 1683 |
+ HtmlTag content; |
| 1684 |
+ content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextCounters)); |
| 1685 |
+ HtmlTag table("table"); |
| 1686 |
+ const map<string,DataModel::Counter*> counterList = manager.CounterListByName(); |
| 1687 |
+ map<string,string> counterArgument; |
| 1688 |
+ for (auto& counter : counterList) |
| 1689 |
+ { |
| 1690 |
+ HtmlTag row("tr"); |
| 1691 |
+ row.AddChildTag(HtmlTag("td").AddContent(counter.first)); |
| 1692 |
+ const string& counterIdString = to_string(counter.second->GetID()); |
| 1693 |
+ counterArgument["counter"] = counterIdString; |
| 1694 |
+ row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextEdit, "counteredit_list_" + counterIdString, counterArgument))); |
| 1695 |
+ row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextDelete, "counteraskdelete_" + counterIdString, counterArgument))); |
| 1696 |
+ table.AddChildTag(row); |
| 1697 |
+ } |
| 1698 |
+ content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(table)); |
| 1699 |
+ content.AddChildTag(HtmlTagButtonCancel()); |
| 1700 |
+ content.AddChildTag(HtmlTagButtonPopupWide(Languages::TextNew, "counteredit_0")); |
| 1701 |
+ client.ReplyHtmlWithHeader(content); |
| 1702 |
+ } |
| 1703 |
+ |
| 1704 |
+ void WebClientCounter::HandleCounterAskDelete(const map<string, string>& arguments) |
| 1705 |
+ { |
| 1706 |
+ const CounterID counterID = Utils::Utils::GetIntegerMapEntry(arguments, "counter", CounterNone); |
| 1707 |
+ if (counterID == CounterNone) |
| 1708 |
+ { |
| 1709 |
+ client.ReplyHtmlWithHeaderAndParagraph(Languages::TextCounterDoesNotExist); |
| 1710 |
+ return; |
| 1711 |
+ } |
| 1712 |
+ |
| 1713 |
+ const DataModel::Counter* counter = manager.GetCounter(counterID); |
| 1714 |
+ if (!counter) |
| 1715 |
+ { |
| 1716 |
+ client.ReplyHtmlWithHeaderAndParagraph(Languages::TextCounterDoesNotExist); |
| 1717 |
+ return; |
| 1718 |
+ } |
| 1719 |
+ |
| 1720 |
+ HtmlTag content; |
| 1721 |
+ const string& counterName = counter->GetName(); |
| 1722 |
+ content.AddContent(HtmlTag("h1").AddContent(Languages::TextDeleteCounter)); |
| 1723 |
+ content.AddContent(HtmlTag("p").AddContent(Languages::TextAreYouSureToDelete, counterName)); |
| 1724 |
+ content.AddContent(HtmlTag("form").AddId("editform") |
| 1725 |
+ .AddContent(HtmlTagInputHidden("cmd", "counterdelete")) |
| 1726 |
+ .AddContent(HtmlTagInputHidden("counter", to_string(counterID)) |
| 1727 |
+ )); |
| 1728 |
+ content.AddContent(HtmlTagButtonCancel()); |
| 1729 |
+ content.AddContent(HtmlTagButtonOK()); |
| 1730 |
+ client.ReplyHtmlWithHeader(content); |
| 1731 |
+ } |
| 1732 |
+ |
| 1733 |
+ void WebClientCounter::HandleCounterDelete(const map<string, string>& arguments) |
| 1734 |
+ { |
| 1735 |
+ const CounterID counterID = Utils::Utils::GetIntegerMapEntry(arguments, "counter", CounterNone); |
| 1736 |
+ const DataModel::Counter* counter = manager.GetCounter(counterID); |
| 1737 |
+ if (!counter) |
| 1738 |
+ { |
| 1739 |
+ client.ReplyResponse(WebClient::ResponseError, Languages::TextCounterDoesNotExist); |
| 1740 |
+ return; |
| 1741 |
+ } |
| 1742 |
+ |
| 1743 |
+ string name = counter->GetName(); |
| 1744 |
+ string result; |
| 1745 |
+ if (!manager.CounterDelete(counterID, result)) |
| 1746 |
+ { |
| 1747 |
+ client.ReplyResponse(WebClient::ResponseError, result); |
| 1748 |
+ return; |
| 1749 |
+ } |
| 1750 |
+ |
| 1751 |
+ client.ReplyResponse(WebClient::ResponseInfo, Languages::TextCounterDeleted, name); |
| 1752 |
+ } |
| 1753 |
+ |
| 1754 |
+ void WebClientCounter::HandleCounterGet(const map<string, string>& arguments) |
| 1755 |
+ { |
| 1756 |
+ const CounterID counterID = Utils::Utils::GetIntegerMapEntry(arguments, "counter"); |
| 1757 |
+ const DataModel::Counter* counter = manager.GetCounter(counterID); |
| 1758 |
+ if (!counter) |
| 1759 |
+ { |
| 1760 |
+ client.ReplyHtmlWithHeader(HtmlTag()); |
| 1761 |
+ return; |
| 1762 |
+ } |
| 1763 |
+ client.ReplyHtmlWithHeader(HtmlTagCounter(counter)); |
| 1764 |
+ } |
| 1765 |
+ |
| 1766 |
+ void WebClientCounter::HandleCounterIncrement(const map<string, string>& arguments) |
| 1767 |
+ { |
| 1768 |
+ const CounterID counterID = Utils::Utils::GetIntegerMapEntry(arguments, "counter"); |
| 1769 |
+ const bool result = manager.Count(counterID, CounterTypeIncrement); |
| 1770 |
+ if (result) |
| 1771 |
+ { |
| 1772 |
+ client.ReplyResponse(WebClient::ResponseInfo, Languages::TextCounterIncremented); |
| 1773 |
+ } |
| 1774 |
+ else |
| 1775 |
+ { |
| 1776 |
+ client.ReplyResponse(WebClient::ResponseWarning, Languages::TextCounterReachedLimit); |
| 1777 |
+ } |
| 1778 |
+ } |
| 1779 |
+ |
| 1780 |
+ void WebClientCounter::HandleCounterDecrement(const map<string, string>& arguments) |
| 1781 |
+ { |
| 1782 |
+ const CounterID counterID = Utils::Utils::GetIntegerMapEntry(arguments, "counter"); |
| 1783 |
+ const bool result = manager.Count(counterID, CounterTypeDecrement); |
| 1784 |
+ if (result) |
| 1785 |
+ { |
| 1786 |
+ client.ReplyResponse(WebClient::ResponseInfo, Languages::TextCounterDecremented); |
| 1787 |
+ } |
| 1788 |
+ else |
| 1789 |
+ { |
| 1790 |
+ client.ReplyResponse(WebClient::ResponseWarning, Languages::TextCounterReachedLimit); |
| 1791 |
+ } |
| 1792 |
+ } |
| 1793 |
+}} // namespace Server::Web |
| 1794 |
Index: railcontrol/Server/Web/WebClientCounter.h |
| 1795 |
=================================================================== |
| 1796 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 1797 |
+++ railcontrol/Server/Web/WebClientCounter.h 2025-11-24 15:27:28.929308047 +0100 |
| 1798 |
@@ -0,0 +1,59 @@ |
| 1799 |
+/* |
| 1800 |
+RailControl - Model Railway Control Software |
| 1801 |
+ |
| 1802 |
+Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org |
| 1803 |
+ |
| 1804 |
+RailControl is free software; you can redistribute it and/or modify it |
| 1805 |
+under the terms of the GNU General Public License as published by the |
| 1806 |
+Free Software Foundation; either version 3, or (at your option) any |
| 1807 |
+later version. |
| 1808 |
+ |
| 1809 |
+RailControl is distributed in the hope that it will be useful, but |
| 1810 |
+WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1811 |
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 1812 |
+See the GNU General Public License for more details. |
| 1813 |
+ |
| 1814 |
+You should have received a copy of the GNU General Public License |
| 1815 |
+along with RailControl; see the file LICENCE. If not see |
| 1816 |
+<http://www.gnu.org/licenses/>. |
| 1817 |
+*/ |
| 1818 |
+ |
| 1819 |
+#pragma once |
| 1820 |
+ |
| 1821 |
+#include <map> |
| 1822 |
+#include <string> |
| 1823 |
+ |
| 1824 |
+#include "Manager.h" |
| 1825 |
+ |
| 1826 |
+namespace Server { namespace Web |
| 1827 |
+{ |
| 1828 |
+ class WebClient; |
| 1829 |
+ |
| 1830 |
+ class WebClientCounter |
| 1831 |
+ { |
| 1832 |
+ public: |
| 1833 |
+ WebClientCounter() = delete; |
| 1834 |
+ WebClientCounter(const WebClientCounter&) = delete; |
| 1835 |
+ WebClientCounter& operator=(const WebClientCounter&) = delete; |
| 1836 |
+ |
| 1837 |
+ inline WebClientCounter(Manager& manager, WebClient& client) |
| 1838 |
+ : manager(manager), |
| 1839 |
+ client(client) |
| 1840 |
+ { |
| 1841 |
+ } |
| 1842 |
+ |
| 1843 |
+ void HandleCounterEdit(const std::map<std::string,std::string>& arguments); |
| 1844 |
+ void HandleCounterSave(const std::map<std::string,std::string>& arguments); |
| 1845 |
+ void HandleCounterList(); |
| 1846 |
+ void HandleCounterAskDelete(const std::map<std::string,std::string>& arguments); |
| 1847 |
+ void HandleCounterDelete(const std::map<std::string,std::string>& arguments); |
| 1848 |
+ void HandleCounterGet(const std::map<std::string, std::string>& arguments); |
| 1849 |
+ void HandleCounterIncrement(const std::map<std::string, std::string>& arguments); |
| 1850 |
+ void HandleCounterDecrement(const std::map<std::string, std::string>& arguments); |
| 1851 |
+ |
| 1852 |
+ private: |
| 1853 |
+ Manager& manager; |
| 1854 |
+ WebClient& client; |
| 1855 |
+ }; |
| 1856 |
+}} // namespace Server::Web |
| 1857 |
+ |
| 1858 |
Index: railcontrol/Server/Web/WebClientRoute.cpp |
| 1859 |
=================================================================== |
| 1860 |
--- railcontrol.orig/Server/Web/WebClientRoute.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 1861 |
+++ railcontrol/Server/Web/WebClientRoute.cpp 2025-11-24 15:27:28.929427558 +0100 |
| 1862 |
@@ -633,6 +633,7 @@ |
| 1863 |
objectTypeOptions[ObjectTypeMultipleUnit] = Languages::TextOrientation; |
| 1864 |
objectTypeOptions[ObjectTypePause] = Languages::TextPause; |
| 1865 |
objectTypeOptions[ObjectTypeBooster] = Languages::TextBooster; |
| 1866 |
+ objectTypeOptions[ObjectTypeCounter] = Languages::TextCounter; |
| 1867 |
HtmlTagSelect select(name + "_type", objectTypeOptions, objectType); |
| 1868 |
select.AddClass("select_relation_objecttype"); |
| 1869 |
select.AddAttribute("onchange", "loadRelationObject('" + atlock + "', '" + priorityString + "');return false;"); |
| 1870 |
@@ -903,6 +904,31 @@ |
| 1871 |
return content; |
| 1872 |
} |
| 1873 |
|
| 1874 |
+ case ObjectTypeCounter: |
| 1875 |
+ { |
| 1876 |
+ std::map<string, Counter*> counters = manager.CounterListByName(); |
| 1877 |
+ map<string, CounterID> counterOptions; |
| 1878 |
+ for (auto& counter : counters) |
| 1879 |
+ { |
| 1880 |
+ counterOptions[counter.first] = counter.second->GetID(); |
| 1881 |
+ } |
| 1882 |
+ CounterID counterId = objectId; |
| 1883 |
+ if ((counterId == CounterNone) && (counterOptions.size() > 0)) |
| 1884 |
+ { |
| 1885 |
+ counterId = counterOptions.begin()->second; |
| 1886 |
+ } |
| 1887 |
+ HtmlTagSelect selectCounter(name + "_id", counterOptions, counterId); |
| 1888 |
+ selectCounter.AddClass("select_relation_id"); |
| 1889 |
+ selectCounter.AddAttribute("onchange", "loadRelationObjectStates('counter', '" + name + "', '" + to_string(counterId) + "');return false;"); |
| 1890 |
+ content.AddChildTag(selectCounter); |
| 1891 |
+ |
| 1892 |
+ map<unsigned int,string> countOptions; |
| 1893 |
+ countOptions[0] = Languages::Languages::GetText(Languages::Languages::TextIncrement); |
| 1894 |
+ countOptions[1u] = Languages::Languages::GetText(Languages::Languages::TextDecrement); |
| 1895 |
+ content.AddChildTag(HtmlTagSelect(name + "_state", countOptions, static_cast<unsigned int>(state)).AddClass("select_relation_state")); |
| 1896 |
+ return content; |
| 1897 |
+ } |
| 1898 |
+ |
| 1899 |
default: |
| 1900 |
{ |
| 1901 |
content.AddContent(Languages::TextUnknownObjectType); |
| 1902 |
Index: railcontrol/Server/Web/WebServer.cpp |
| 1903 |
=================================================================== |
| 1904 |
--- railcontrol.orig/Server/Web/WebServer.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 1905 |
+++ railcontrol/Server/Web/WebServer.cpp 2025-11-24 15:27:28.929540366 +0100 |
| 1906 |
@@ -564,6 +564,24 @@ |
| 1907 |
AddUpdate(command, Languages::TextTextDeleted, name); |
| 1908 |
} |
| 1909 |
|
| 1910 |
+ void WebServer::CounterSettings(const CounterID counterID, const std::string& name) |
| 1911 |
+ { |
| 1912 |
+ const string command = "countersettings;counter=" + to_string(counterID); |
| 1913 |
+ AddUpdate(command, Languages::TextCounterUpdated, name); |
| 1914 |
+ } |
| 1915 |
+ |
| 1916 |
+ void WebServer::CounterDelete(const CounterID counterID, const std::string& name) |
| 1917 |
+ { |
| 1918 |
+ const string command = "counterdelete;counter=" + to_string(counterID); |
| 1919 |
+ AddUpdate(command, Languages::TextCounterDeleted, name); |
| 1920 |
+ } |
| 1921 |
+ |
| 1922 |
+ void WebServer::CounterState(const DataModel::Counter* const counter) |
| 1923 |
+ { |
| 1924 |
+ const string command ="counterstate;counter=" + to_string(counter->GetID()) + ";count=" + to_string(counter->GetCounter()); |
| 1925 |
+ AddUpdate(command, Languages::TextCounterUpdated, counter->GetName()); |
| 1926 |
+ } |
| 1927 |
+ |
| 1928 |
void WebServer::LocoBaseRelease(const DataModel::LocoBase* loco) |
| 1929 |
{ |
| 1930 |
string command("locorelease;loco="); |
| 1931 |
Index: railcontrol/Server/Web/WebServer.h |
| 1932 |
=================================================================== |
| 1933 |
--- railcontrol.orig/Server/Web/WebServer.h 2025-11-24 15:27:28.933374444 +0100 |
| 1934 |
+++ railcontrol/Server/Web/WebServer.h 2025-11-24 15:27:28.929630931 +0100 |
| 1935 |
@@ -123,6 +123,9 @@ |
| 1936 |
void ClusterSettings(const ClusterID clusterID, const std::string& name) override; |
| 1937 |
void TextDelete(const TextID textID, const std::string& name) override; |
| 1938 |
void TextSettings(const TextID textID, const std::string& name) override; |
| 1939 |
+ void CounterDelete(const CounterID counterID, const std::string& name) override; |
| 1940 |
+ void CounterSettings(const CounterID counterID, const std::string& name) override; |
| 1941 |
+ void CounterState(const DataModel::Counter* const counter); |
| 1942 |
void ProgramValue(const CvNumber cv, const CvValue value) override; |
| 1943 |
|
| 1944 |
inline bool UpdateAvailable() |
| 1945 |
Index: railcontrol/Storage/StorageHandler.cpp |
| 1946 |
=================================================================== |
| 1947 |
--- railcontrol.orig/Storage/StorageHandler.cpp 2025-11-24 15:27:28.933374444 +0100 |
| 1948 |
+++ railcontrol/Storage/StorageHandler.cpp 2025-11-24 15:27:28.929714365 +0100 |
| 1949 |
@@ -28,6 +28,7 @@ |
| 1950 |
|
| 1951 |
using DataModel::Accessory; |
| 1952 |
using DataModel::Cluster; |
| 1953 |
+using DataModel::Counter; |
| 1954 |
using DataModel::Feedback; |
| 1955 |
using DataModel::Layer; |
| 1956 |
using DataModel::Loco; |
| 1957 |
@@ -282,7 +283,7 @@ |
| 1958 |
sqlite.ObjectsOfType(ObjectTypeCluster, serializedObjects); |
| 1959 |
for (auto& serializedObject : serializedObjects) |
| 1960 |
{ |
| 1961 |
- Cluster* cluster = new Cluster(serializedObject); |
| 1962 |
+ Cluster* cluster = new Cluster(manager, serializedObject); |
| 1963 |
if (!cluster) |
| 1964 |
{ |
| 1965 |
continue; |
| 1966 |
@@ -308,6 +309,21 @@ |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
+ void StorageHandler::AllCounters(std::map<CounterID,DataModel::Counter*>& counters) |
| 1971 |
+ { |
| 1972 |
+ vector<string> serializedObjects; |
| 1973 |
+ sqlite.ObjectsOfType(ObjectTypeCounter, serializedObjects); |
| 1974 |
+ for (auto& serializedObject : serializedObjects) |
| 1975 |
+ { |
| 1976 |
+ Counter* counter = new Counter(serializedObject); |
| 1977 |
+ if (!counter) |
| 1978 |
+ { |
| 1979 |
+ continue; |
| 1980 |
+ } |
| 1981 |
+ counters[counter->GetID()] = counter; |
| 1982 |
+ } |
| 1983 |
+ } |
| 1984 |
+ |
| 1985 |
void StorageHandler::SaveRelations(const vector<DataModel::Relation*> relations) |
| 1986 |
{ |
| 1987 |
for (auto relation : relations) |
| 1988 |
Index: railcontrol/Storage/StorageHandler.h |
| 1989 |
=================================================================== |
| 1990 |
--- railcontrol.orig/Storage/StorageHandler.h 2025-11-24 15:27:28.933374444 +0100 |
| 1991 |
+++ railcontrol/Storage/StorageHandler.h 2025-11-24 15:27:28.929820934 +0100 |
| 1992 |
@@ -108,6 +108,13 @@ |
| 1993 |
sqlite.DeleteObject(ObjectTypeText, textID); |
| 1994 |
} |
| 1995 |
|
| 1996 |
+ void AllCounters(std::map<CounterID,DataModel::Counter*>& counters); |
| 1997 |
+ |
| 1998 |
+ inline void DeleteCounter(CounterID counterID) |
| 1999 |
+ { |
| 2000 |
+ sqlite.DeleteObject(ObjectTypeCounter, counterID); |
| 2001 |
+ } |
| 2002 |
+ |
| 2003 |
inline void Save(const Hardware::HardwareParams& hardwareParams) |
| 2004 |
{ |
| 2005 |
sqlite.SaveHardwareParams(hardwareParams); |
| 2006 |
Index: railcontrol/html/javascript.js |
| 2007 |
=================================================================== |
| 2008 |
--- railcontrol.orig/html/javascript.js 2025-11-24 15:27:28.933374444 +0100 |
| 2009 |
+++ railcontrol/html/javascript.js 2025-11-24 15:27:28.929935760 +0100 |
| 2010 |
@@ -231,6 +231,10 @@ |
| 2011 |
type = "text"; |
| 2012 |
break; |
| 2013 |
|
| 2014 |
+ case "c": |
| 2015 |
+ type = "counter"; |
| 2016 |
+ break; |
| 2017 |
+ |
| 2018 |
default: |
| 2019 |
type = "object"; |
| 2020 |
break; |
| 2021 |
@@ -863,6 +867,17 @@ |
| 2022 |
return false; |
| 2023 |
} |
| 2024 |
|
| 2025 |
+function onClickCounter(counterID) |
| 2026 |
+{ |
| 2027 |
+ var identifier = 'c_' + counterID; |
| 2028 |
+ if (modifierKeyPressed(event)) |
| 2029 |
+ { |
| 2030 |
+ rotateObject(identifier); |
| 2031 |
+ return; |
| 2032 |
+ } |
| 2033 |
+ return false; |
| 2034 |
+} |
| 2035 |
+ |
| 2036 |
function showMenu(elementName) { |
| 2037 |
var element = document.getElementById(elementName); |
| 2038 |
if (!element) |
| 2039 |
@@ -1487,6 +1502,36 @@ |
| 2040 |
requestUpdateLayoutItem(elementName, url); |
| 2041 |
} |
| 2042 |
|
| 2043 |
+function updateCounterState(argumentMap) |
| 2044 |
+{ |
| 2045 |
+ if (!argumentMap.has('counter') || !argumentMap.has('count')) |
| 2046 |
+ { |
| 2047 |
+ return; |
| 2048 |
+ } |
| 2049 |
+ var elementName = 'c_' + argumentMap.get('counter'); |
| 2050 |
+ var element = document.getElementById(elementName); |
| 2051 |
+ if (!element) |
| 2052 |
+ { |
| 2053 |
+ return; |
| 2054 |
+ } |
| 2055 |
+ var count = argumentMap.get('count'); |
| 2056 |
+ elementName += '_text'; |
| 2057 |
+ element = document.getElementById(elementName); |
| 2058 |
+ if (!element) |
| 2059 |
+ { |
| 2060 |
+ return; |
| 2061 |
+ } |
| 2062 |
+ element.innerHTML = count; |
| 2063 |
+} |
| 2064 |
+ |
| 2065 |
+function updateCounter(counterID) |
| 2066 |
+{ |
| 2067 |
+ elementName = 'c_' + counterID; |
| 2068 |
+ var url = '/?cmd=counterget'; |
| 2069 |
+ url += '&counter=' + counterID; |
| 2070 |
+ requestUpdateLayoutItem(elementName, url); |
| 2071 |
+} |
| 2072 |
+ |
| 2073 |
function dataUpdate(event) |
| 2074 |
{ |
| 2075 |
var status = document.getElementById('status'); |
| 2076 |
@@ -1632,6 +1677,20 @@ |
| 2077 |
deleteElement(elementName); |
| 2078 |
deleteElement(elementName + '_context'); |
| 2079 |
} |
| 2080 |
+ else if (command == 'countersettings') |
| 2081 |
+ { |
| 2082 |
+ updateCounter(argumentMap.get('counter')); |
| 2083 |
+ } |
| 2084 |
+ else if (command == 'counterdelete') |
| 2085 |
+ { |
| 2086 |
+ elementName = 'c_' + argumentMap.get('counter'); |
| 2087 |
+ deleteElement(elementName); |
| 2088 |
+ deleteElement(elementName + '_context'); |
| 2089 |
+ } |
| 2090 |
+ else if (command == 'counterstate') |
| 2091 |
+ { |
| 2092 |
+ updateCounterState(argumentMap); |
| 2093 |
+ } |
| 2094 |
else if (command == 'trackstate') |
| 2095 |
{ |
| 2096 |
updateTrackState(argumentMap); |
| 2097 |
Index: railcontrol/html/style.css |
| 2098 |
=================================================================== |
| 2099 |
--- railcontrol.orig/html/style.css 2025-11-24 15:27:28.933374444 +0100 |
| 2100 |
+++ railcontrol/html/style.css 2025-11-24 15:27:28.930095144 +0100 |
| 2101 |
@@ -73,7 +73,7 @@ |
| 2102 |
width: 110px; |
| 2103 |
} |
| 2104 |
|
| 2105 |
-@media (max-width: 649px) { |
| 2106 |
+@media (max-width: 615px) { |
| 2107 |
.menu_config, |
| 2108 |
.menu_config_visible, |
| 2109 |
.menu_add, |
| 2110 |
@@ -293,6 +293,7 @@ |
| 2111 |
} |
| 2112 |
|
| 2113 |
.accessory_item .track, |
| 2114 |
+.counter_item .track, |
| 2115 |
.feedback_item .track { |
| 2116 |
fill: white; |
| 2117 |
} |
| 2118 |
@@ -437,6 +438,7 @@ |
| 2119 |
display: none; |
| 2120 |
} |
| 2121 |
|
| 2122 |
+.counter, |
| 2123 |
.text_item, |
| 2124 |
.loconame, |
| 2125 |
.trackname { |