package art.client.maps; import art.client.models.Shared; import art.library.model.devices.*; import art.library.model.devices.colors.controller.M.M_Controller; import art.library.model.devices.colors.controller.M.M_ControllerRealtime; import art.library.model.devices.colors.controller.M.M_ControllerStatus; import art.library.model.devices.colors.controller.M.M_ControllerStatusSubcontroller; import art.library.model.devices.colors.controller.M.M_SubcontrollerConfiguration; import art.library.model.devices.colors.controller.M.configuration.M_Plan; import art.library.model.devices.colors.controller.M.realtime.M_ControllerRealtimeGroup; import art.library.model.devices.colors.controller.M.realtime.M_ControllerRealtimeSubcontroller; import art.library.model.devices.vms.general.VmsGeneral; import art.library.model.devices.vms.general.status.VmsGeneralStatusMessage; import art.library.vmsboard.BoardDocument; import com.kitfox.svg.*; import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; import java.awt.Shape; import java.awt.image.BufferedImage; import java.io.File; import java.util.*; import static svgdevicestest.PanelScaleVectorGraphics.getBoundingBox; public class Corridor extends DeviceGraphicsRuntime { private boolean even = false; public Corridor(SVGDiagram diagram) { super(diagram); } public void status() { Calendar calendardate = java.util.Calendar.getInstance(); calendardate.set(java.util.Calendar.MILLISECOND, 0); long seconds = calendardate.getTimeInMillis()/1000; even = (seconds % 2) == 0; try { List lelement = getElementsContainingField("art.device"); for (SVGElement element : lelement) { try { Device device = null; device = Shared.model.modelDevices.getDevice(getAttribute(element, "art.device")); if ((device != null) && (device instanceof VmsGeneral)) { status((VmsGeneral)device,element); } else { SVGElement arrow = getChildContainingField(element, "art.id", "Arrow"); if (arrow == null) { statusBox(element); } else { statusGroup(element); } } } catch (Exception e) { } } } catch (Exception e) { } } /**/ public void status(VmsGeneral svgDevice, SVGElement element) throws Exception { SVGElement background = getChildContainingField(element, "art.id", "Background"); SVGElement alarm = getChildContainingField(element, "art.id", "Alarm"); String backGroundColor = "#000000"; String alarmColor = "#00FF00"; switch (svgDevice.getDeviceStatus().status) { case DeviceStatus.STATUS_ALARM: alarmColor = "#FF0000"; break; case DeviceStatus.STATUS_OFFLINE: case DeviceStatus.STATUS_UNKNOWN: backGroundColor = "#FF00FF"; alarmColor = "#800080"; break; } setAttribute(background, "fill", backGroundColor, 999); setAttribute(alarm, "stroke", alarmColor, 999); } /**/ private void statusBox(SVGElement element) throws Exception { String identifier = getAttribute(element, "art.device"); SVGElement background = getChildContainingField(element, "art.id", "Background"); SVGElement border = getChildContainingField(element, "art.id", "Border"); SVGElement alarm = getChildContainingField(element, "art.id", "Alarm"); SVGElement textInformation = getChildContainingField(element, "art.id", "Text information"); SVGElement textCycle = getChildContainingField(element, "art.id", "Text cycle"); SVGElement textOffset = getChildContainingField(element, "art.id", "Text offset"); SVGElement textElapsed = getChildContainingField(element, "art.id", "Text elapsed"); setAttribute(background, "fill", "#F000F0"); setAttribute(border, "stroke", "#F000F0"); setAttribute(alarm, "display", "none"); setText(textInformation, ""); setText(textCycle, ""); setText(textElapsed, ""); setText(textOffset, ""); setAttribute(border, "stroke-width", 0.75); M_Controller controller = (M_Controller)art.client.models.Shared.model.modelDevices.getDevice(identifier); M_ControllerStatus controllerStatus = controller.getDeviceStatus(); M_ControllerStatusSubcontroller subcontrollerStatus = null; M_ControllerRealtimeSubcontroller subcontrollerRealtime = null; M_SubcontrollerConfiguration subcontrollerConfiguration = null; if (controller.status != null) subcontrollerStatus = controller.getDeviceStatus().getStatusSubcontroller(); if (controller.realtime != null) subcontrollerRealtime = controller.getDeviceRealtime().getRealtimeSubcontroller(); if (controller.configuration != null) subcontrollerConfiguration = controller.getDeviceConfiguration().getSubcontroller(); /* Alarm */ int severityAlarm = controller.getDeviceAlarms().getServerityAlarm(); double strokeopacity = Math.pow(2, severityAlarm)/32; if (severityAlarm > 0) { setAttribute(alarm, "display", "inline"); setAttribute(alarm, "stroke", "#FF0000", 999); setAttribute(alarm, "stroke-opacity", strokeopacity, 999); setAttribute(alarm, "stroke-width", (0.5 + (1 * strokeopacity)), 999); setAttribute(alarm, "stroke-width", 2, 999); } /* Status */ switch (controllerStatus.status) { case DeviceStatus.STATUS_ONLINE: case DeviceStatus.STATUS_WARNING: case DeviceStatus.STATUS_ALARM: { switch (subcontrollerStatus.colorsMode) { case M_ControllerStatusSubcontroller.COLORS_OFF : setAttribute(background, "fill", "#808080"); setAttribute(border, "stroke", "#404040"); setText(textInformation, "OFF"); break; case M_ControllerStatusSubcontroller.COLORS_FLASHING : setText(textInformation, "Y^"); if (even == true) { setAttribute(background, "fill", "#F0F0F0"); } else { setAttribute(background, "fill", "#FFFF00"); } break; case M_ControllerStatusSubcontroller.COLORS_COLORS : setAttribute(background, "fill", "#F0F0F0"); break; } } break; } /* State, cycle */ if (subcontrollerStatus.colorsMode == M_ControllerStatusSubcontroller.COLORS_COLORS) { M_Plan plan = null; if (subcontrollerStatus.plan > 0) { try { plan = subcontrollerConfiguration.getMPlan(subcontrollerRealtime.plan); } catch (Exception e) { } } else { plan = subcontrollerStatus.recordablePlan; } if (plan != null) { String information = ""; switch (subcontrollerStatus.operationMode) { case M_ControllerStatusSubcontroller.OPERATIONMODE_FIXED: information = "F"; break; case M_ControllerStatusSubcontroller.OPERATIONMODE_SEMIACTUATED: information = "S"; break; case M_ControllerStatusSubcontroller.OPERATIONMODE_ACTUATED: information = "A"; break; } information = information + plan.number; switch (subcontrollerStatus.planSelection) { case M_ControllerStatusSubcontroller.PLANSELECTION_TIMETABLE: information = information + "t"; break; case M_ControllerStatusSubcontroller.PLANSELECTION_EXTERNAL_PLANS: information = information + "e"; break; case M_ControllerStatusSubcontroller.PLANSELECTION_ICF: information = information + "i"; break; case M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER: information = information + "c"; break; } switch (subcontrollerStatus.planSelectionComputer) { case M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_MACRO: information = information + ""; break; case M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_SELECTION: information = information + "+"; break; case M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_GENERATION: information = information + "+"; break; case M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_ADAPTATIVE: information = information + "+"; break; } setText(textInformation, information); if (plan.offset > 0) { setText(textOffset, "" + plan.offset); } setText(textCycle, "" + plan.cycleTime); if (subcontrollerRealtime != null) { String text = subcontrollerRealtime.phase + ":" + subcontrollerRealtime.cycle; switch (subcontrollerRealtime.adjust) { case M_ControllerRealtimeSubcontroller.ADJUST_POSITIVE: text = text + "+"; break; case M_ControllerRealtimeSubcontroller.ADJUST_NEGATIVE: text = text + "-"; break; } setText(textElapsed, text); } } } } private void statusGroup(SVGElement element) throws Exception { String identifier = getAttribute(element, "art.device"); String group = getAttribute(element, "art.device.group"); SVGElement background = getChildContainingField(element, "art.id", "Background"); SVGElement border = getChildContainingField(element, "art.id", "Border"); SVGElement arrow = getChildContainingField(element, "art.id", "Arrow"); setAttribute(background, "fill", "#F000F0"); setAttribute(border, "display", "none"); setAttribute(arrow, "fill", "#FFFFFF"); M_Controller controller = (M_Controller)art.client.models.Shared.model.modelDevices.getDevice(identifier); M_ControllerStatus controllerStatus = controller.getDeviceStatus(); M_ControllerRealtime controllerRealtime = controller.getDeviceRealtime(); /* Status */ if (controllerStatus.getStatusGroup(Integer.parseInt(group)).hasAlarm() == true) { if (even == true) { setAttribute(border, "display", "inline"); setAttribute(border, "stroke", "#FF0000"); setAttribute(border, "stroke-width", 1.0); } } /* Realtime */ if (even == true) { switch (controllerRealtime.getStatusGroup(Integer.parseInt(group)).getColor()) { case M_ControllerRealtimeGroup.M_GROUP_COLOR_OFF: setAttribute(background, "fill", "#4B4B4B"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_GREEN: setAttribute(background, "fill", "#00E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_YELLOW: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_RED: setAttribute(background, "fill", "#E00000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FAST_FLASHING_GREEN: setAttribute(background, "fill", "#00E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FLAHING_YELLOW:setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_GREEN_FLASHING_YELLOW_DOUBLE: setAttribute(background, "fill", "#00E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FLASHING_GREEN_RED: setAttribute(background, "fill", "#00E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_RED_YELLOW: setAttribute(background, "fill", "#E00000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_GREEN_FLASHING_YELLOW_PROTECTION: setAttribute(background, "fill", "#00E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FAST_FLASHING_GREEN_FLASHING_YELLOW_PROTECTION: setAttribute(background, "fill", "#00E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_RED_FLASHING_YELLOW_PROTECTION: setAttribute(background, "fill", "#E00000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_SLOW_FLASHING_GREEN: setAttribute(background, "fill", "#00E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_SLOW_FLASHING_RED: setAttribute(background, "fill", "#E00000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FLASHING_YELLOW_DOUBLE: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FAST_FLASHING_RED_FLASHING_YELLOW: setAttribute(background, "fill", "#E00000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FLASHING_YELLOW_DOUBLE_WITH_GREEN_SIGNAL: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_GREEN_FLASHING_YELOW_DOUBLE_WITH_RED_SIGNAL: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_GREEN_YELLOW: setAttribute(background, "fill", "#00E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_UNKNOWN: setAttribute(background, "fill", "#E000E0"); break; default: } } else { switch (controllerRealtime.getStatusGroup(Integer.parseInt(group)).getColor()) { case M_ControllerRealtimeGroup.M_GROUP_COLOR_OFF: setAttribute(background, "fill", "#4B4B4B"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_GREEN: setAttribute(background, "fill", "#00E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_YELLOW: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_RED: setAttribute(background, "fill", "#E00000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FAST_FLASHING_GREEN: setAttribute(background, "fill", "#4B4B4B"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FLAHING_YELLOW:setAttribute(background, "fill", "#4B4B4B"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_GREEN_FLASHING_YELLOW_DOUBLE: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FLASHING_GREEN_RED: setAttribute(background, "fill", "#E00000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_RED_YELLOW: setAttribute(background, "fill", "#E0E0000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_GREEN_FLASHING_YELLOW_PROTECTION: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FAST_FLASHING_GREEN_FLASHING_YELLOW_PROTECTION: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_RED_FLASHING_YELLOW_PROTECTION: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_SLOW_FLASHING_GREEN: setAttribute(background, "fill", "#4B4B4B"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_SLOW_FLASHING_RED: setAttribute(background, "fill", "#4B4B4B"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FLASHING_YELLOW_DOUBLE: setAttribute(background, "fill", "#4B4B4B"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FAST_FLASHING_RED_FLASHING_YELLOW: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_FLASHING_YELLOW_DOUBLE_WITH_GREEN_SIGNAL: setAttribute(background, "fill", "#00E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_GREEN_FLASHING_YELOW_DOUBLE_WITH_RED_SIGNAL: setAttribute(background, "fill", "#E00000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_GREEN_YELLOW: setAttribute(background, "fill", "#E0E000"); break; case M_ControllerRealtimeGroup.M_GROUP_COLOR_UNKNOWN: setAttribute(background, "fill", "#E000E0"); break; default: } } } private final HashMap mapMessages = new HashMap<>(); public void paint(Graphics2D g2) { for (SVGElement element : getElementsContainingField("art.device")) { try { Device device = Shared.model.modelDevices.getDevice(getAttribute(element, "art.device")); if (device instanceof VmsGeneral) { if (element.getStyleAbsolute("display").getStringValue().equals("none")) { continue; } VmsGeneral vms = (VmsGeneral) device; VmsMessageStorage storemessage = new VmsMessageStorage(); if (!mapMessages.containsKey(vms.getIdentifier())) { mapMessages.put(vms.getIdentifier(), storemessage); } VmsMessageStorage messageStore = mapMessages.get(vms.getIdentifier()); SVGElement background = getChildContainingField(element, "art.id", "Background"); Shape shape = getBoundingBox(background); double w = shape.getBounds2D().getWidth() * g2.getTransform().getScaleX(); double h = shape.getBounds2D().getHeight() * g2.getTransform().getScaleY(); messageStore.getNextMessage(vms.getDeviceStatus().lmessage).ifPresent(message -> { BoardDocument document = message.document; boolean width = w < document.width * 1.25f; boolean height = h < document.height * 1.25f; if (width || height) { BufferedImage image = document.getBufferedImage(); g2.drawImage(image.getScaledInstance((int) shape.getBounds2D().getWidth(), (int) shape.getBounds2D().getHeight(), Image.SCALE_SMOOTH), (int) shape.getBounds2D().getX(), (int) shape.getBounds2D().getY(), null); } else { BufferedImage image = document.getRealisticImage((int) shape.getBounds2D().getWidth(), (int) shape.getBounds2D().getHeight(), true); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(image, (int) shape.getBounds2D().getX(), (int) shape.getBounds2D().getY(), null); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); } }); } } catch (Exception exception) { } } } public class VmsMessageStorage { private List lMessage; private long currentMessageTimestamp = 0; private VmsGeneralStatusMessage currentMessage; public Optional getNextMessage(List currentMessages) { checkMessageList(currentMessages); Optional messageOpt = Optional.empty(); if (lMessage == null || lMessage.isEmpty()) { return messageOpt; } if (currentMessage == null) { messageOpt = Optional.of(lMessage.get(0)); currentMessageTimestamp = System.currentTimeMillis(); currentMessage = messageOpt.get(); } else { if ((System.currentTimeMillis() - currentMessageTimestamp) >= currentMessage.time * 1000) { currentMessageTimestamp = System.currentTimeMillis(); int messageIndex = lMessage.indexOf(currentMessage); int nextIndex = messageIndex >= lMessage.size() - 1 ? 0 : messageIndex + 1; currentMessage = lMessage.get(nextIndex); } messageOpt = Optional.of(currentMessage); } return messageOpt; } private void checkMessageList(List currentMessages) { try { if (!Serialization.equals(currentMessages, lMessage)) { lMessage = currentMessages; currentMessage = null; } } catch (Exception ex) { } } } }