Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
maintenance for accessories (#83)
Browse files Browse the repository at this point in the history
* started #79

* allow to set "maintenance" / "malfunction" for accessory, i.e. will not be used in AutoMode : closes #79

Co-authored-by: Christian Benjamin Ries <c.ries@beckhoff.com>
  • Loading branch information
cbries and Christian Benjamin Ries committed Apr 5, 2021
1 parent b1c299d commit bd35292
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 15 deletions.
7 changes: 7 additions & 0 deletions EcosApp/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ html, body {
/ Workspace Selection
*/

.accessoryMaintenance {
background-color: rgba(215, 0,0, 1.0);
-webkit-box-shadow: inset 0 0 0 1px #000;
-moz-box-shadow: inset 0 0 0 1px #000;
box-shadow: inset 0 0 0 1px #000;
}

div.elementLabelTxt {
position: relative;
font-weight: bold;
Expand Down
2 changes: 1 addition & 1 deletion EcosApp/railessentials.min.js

Large diffs are not rendered by default.

86 changes: 76 additions & 10 deletions EcosApp/src/planField.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Planfield {
*
* @param {any} options : {
* isEditMode [bool] }
*/
*/
constructor(options = {}) {
console.log("**** construct Planfield");
this.planfieldElement = null;
Expand Down Expand Up @@ -370,8 +370,8 @@ class Planfield {
for (i = 0; i < iMax; ++i) {
$(childs[i]).droppable({
accept: "div.locomotiveInfo",
// drop: function (event, ui) {
// }
// drop: function (event, ui) {
// }
});
}

Expand Down Expand Up @@ -415,7 +415,7 @@ class Planfield {
if (blockCtrls == null) return;
if (blockCtrls.length === 0) return;

let i = 0;
let i = 0;
for (; i < noOfFeedbacks; ++i) {
const fbData = feedbacks.data[i];
if (typeof fbData === "undefined") continue;
Expand All @@ -429,7 +429,7 @@ class Planfield {
if (blockCtrl == null) continue;
blockCtrl.addClass("blockDisabledState");
}
catch(err) {
catch (err) {
// ignore
}
}
Expand All @@ -449,7 +449,7 @@ class Planfield {

__removeAllDisabledFlags(blockCtrls) {
if (typeof blockCtrls === "undefined" || blockCtrls == null || blockCtrls.length === 0) return;
let i = 0;
let i = 0;
const iMax = blockCtrls.length;
for (; i < iMax; ++i) {
const fb = blockCtrls[i];
Expand Down Expand Up @@ -486,7 +486,7 @@ class Planfield {
const fbItem = getFbByEcosAddr(fbCtrls, addr);
if (typeof fbItem === "undefined") continue;
if (fbItem === null) continue;

let newImgEnding = "";
const mask = 1 << jj;
if ((fb.stateOriginal & mask) !== 0) {
Expand Down Expand Up @@ -609,7 +609,7 @@ class Planfield {
} else if (targetState === true) {
newimgfname += "-t";
}
}
}

let currentSrc = img.attr("src");
let isOcc = false;
Expand Down Expand Up @@ -835,7 +835,9 @@ class Planfield {
textfieldElement.setEditMode(true);
}
else {
//
// general approach to create track element
//

newCtrl = $('<div>')
.addClass("ctrlItem")
Expand All @@ -846,6 +848,10 @@ class Planfield {
width: w + "px",
height: h + "px"
});

if (jsonData.isMaintenance === true)
newCtrl.addClass("accessoryMaintenance");

newCtrl.data(constDataThemeItemObject, jsonData);
newCtrl.data(constDataThemeDimensionIndex, jsonData.editor.themeDimIdx);

Expand Down Expand Up @@ -903,7 +909,7 @@ class Planfield {
}

//
// init drop for block
// init drop and ctx menu for block
//
if (isBlock(jsonData.editor.themeId)) {
this.__initBlockDrop(newCtrl);
Expand All @@ -918,7 +924,7 @@ class Planfield {
const blockId = newCtrl.attr("id");
let i = 0;
const iMax = self.__recentFbEventsData.length;
for (; i < iMax; ++i ) {
for (; i < iMax; ++i) {
const fbData = self.__recentFbEventsData[i];
if (typeof fbData === "undefined") continue;
if (fbData == null) continue;
Expand Down Expand Up @@ -974,6 +980,66 @@ class Planfield {
});
}

//
// init ctx menu for accessory
//
if (isSwitchOrAccessory(jsonData.editor.themeId)) {
newCtrl.on("contextmenu", function (event) {
event.preventDefault();

const data = newCtrl.data(constDataThemeItemObject);
if (typeof data === "undefined") return;
if (data == null) return;

let isMaintenance = data.isMaintenance;
if (typeof isMaintenance === "undefined" || isMaintenance == null)
isMaintenance = false;

let maintenanceLabel = "Enable Maintenance";
let maintenanceIcon = "fas fa-stethoscope";
if (isMaintenance === true) {
maintenanceLabel = "Disable Maintenance";
maintenanceIcon = "far fa-thumbs-up";
}

new Contextual({
isSticky: false,
items: [
{
cssIcon: maintenanceIcon,
enabled: true,
label: maintenanceLabel, onClick: () => {

const newMaintenanceState = !isMaintenance;

// do not wait for the server
// to change the content of
// the maintained accessory
// this will be waste performance
data.isMaintenance = newMaintenanceState;
newCtrl.data(constDataThemeItemObject, data);

if (newMaintenanceState === true)
newCtrl.addClass("accessoryMaintenance");
else
newCtrl.removeClass("accessoryMaintenance");

self.__trigger('setting',
{
'mode': 'accessory',
'cmd': 'maintenance',
'value': {
identifier: data.identifier,
state: newMaintenanceState
}
});
}
}
]
});
});
}

newCtrl.appendTo(this.planfieldElement);

newCtrl.click(function (ev) {
Expand Down
17 changes: 14 additions & 3 deletions railessentials/AutoMode/AutoMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ private NextRouteInformation CheckForRoutesAndAssign()
// has already a destination
if (!string.IsNullOrEmpty(itOccBlock.FinalBlock)) continue;

//
// the most interesting call is `GetNextRoute(..)` which
// is responsible for selecting the best next journey path
//
var nextRoute = GetNextRoute(itOccBlock, out var locomotiveObjectId);
if (nextRoute == null) continue;

Expand Down Expand Up @@ -649,7 +653,7 @@ public Route.Route GetNextRoute(
if (locData == null) return null;

//
// NOTE check of the OCC has waiting long enough for a new start
// NOTE check if the OCC has waited long enough for a new start
//
var lastReachedTime = occBlock.ReachedTime;
var allowedMinimumTime = lastReachedTime.AddSeconds(occBlock.SecondsToWait);
Expand Down Expand Up @@ -843,13 +847,20 @@ public Route.Route GetNextRoute(
SaveOccAndPromote();

#endregion (4)

}
var routesFromFiltered = routesFrom.FilterBy(locDataEcos, locData, _metadata.FeedbacksData);
var routesFromNotOccupied = routesFromFiltered.FilterNotOccupiedOrLocked(_metadata.Occ);
if (routesFromNotOccupied.Count == 0) return null;

var routesNoCross = routesFromNotOccupied.FilterNoCrossingOccupied(_routeList);
//
// filter routes if any accessory is in "maintenance" mode
//
var routesNoMaintenance = routesFromNotOccupied.FilterSwitchesMaintenance(_metadata.Metamodel);

//
// filter all routes which cross occupied routes
//
var routesNoCross = routesNoMaintenance.FilterNoCrossingOccupied(_routeList);
if (routesNoCross.Count == 0)
{
//
Expand Down
19 changes: 19 additions & 0 deletions railessentials/ClientHandler/ClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,25 @@ private void HandleSettingAccessory(string cmd, JToken value)

switch (cmd.ToLower())
{
case "maintenance":
{
var accIdentifier = data.GetString("identifier", string.Empty);
if (string.IsNullOrEmpty(accIdentifier)) return;

lock (_metadataLock)
{
var acc = _metadata?.GetMetamodelItem(accIdentifier);
if (acc == null) return;
var isMaintenance = data.GetBool("state", false);
acc["isMaintenance"] = isMaintenance;

_metadata?.Save(Metadata.SaveModelType.MetamodelData);
}

SendModelToClients(ModelType.UpdateMetamodel);
}
break;

case "groupname":
{
var accIdentifier = data.GetString("identifier", string.Empty);
Expand Down
5 changes: 4 additions & 1 deletion railessentials/Plan/PlanItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ public partial class PlanItem
public PlanItemEditor editor { get; set; } = new();
public List<PlanItemDimension> dimensions { get; set; } = new();

[JsonProperty(PropertyName = "isMaintenance")]
public bool IsMaintenance { get; set; } = false;

[JsonProperty(PropertyName = "addresses")]
public PlanItemAddresses Addresses { get; set; } = new();

[JsonProperty(PropertyName = "groupName")]
public string GroupName { get; set; } // see #70

#endregion metamodel
#endregion /metamodel

/// <summary>
/// Returns the current `themeDimIdx` values.
Expand Down
45 changes: 45 additions & 0 deletions railessentials/Route/RouterListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
using System;
using System.Collections.Generic;
using ecoslib.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using railessentials.Feedbacks;
using railessentials.Plan;

namespace railessentials.Route
{
Expand Down Expand Up @@ -159,5 +162,47 @@ public static bool Contains(this RouteList routeList, Route route)
}
return false;
}

public static RouteList FilterSwitchesMaintenance(
this RouteList routeList,
JObject metamodel
)
{
if (routeList == null) return routeList;
if (routeList.Count == 0) return routeList;

var planField = metamodel?["planField"] as JObject;
if (planField == null) return routeList;

var res = new RouteList();

foreach (var it in routeList)
{
if (it == null) continue;

var addToResult = true;

foreach(var itSwitch in it.Switches)
{
if (itSwitch == null) continue;
var key = $"{itSwitch.x}x{itSwitch.y}";
if(planField[key] != null)
{
var itemObj = JsonConvert.DeserializeObject<PlanItem>(planField[key].ToString());
if (itemObj == null) continue;
if(itemObj.IsMaintenance)
{
addToResult = false;
break;
}
}
}

if(addToResult)
res.Add(it);
}

return res;
}
}
}

0 comments on commit bd35292

Please sign in to comment.