From 268251f186ee77bc3eb9880878db0c8f23769b5e Mon Sep 17 00:00:00 2001 From: cherneyasp Date: Wed, 22 Jun 2022 14:16:20 -0500 Subject: [PATCH 1/4] Update minhdwy units and allow for double inputs from the UI. --- osmbin/units.csv | 2 ++ src/cc/ctrl/TrafCtrlEnums.java | 2 +- src/cc/ws/CtrlTiles.java | 13 ++++++------- src/cc/ws/GeoLanes.java | 7 ++++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/osmbin/units.csv b/osmbin/units.csv index b92048c1..cb4911f5 100644 --- a/osmbin/units.csv +++ b/osmbin/units.csv @@ -15,3 +15,5 @@ mm,cm,1,10,0 mph,kph,1.609344,1,0 ft,in,12,1,0 dm/s,mph,3600,16093.44,0 +m/s,dm/s,10,1,0 +ft,dm,3.048,1,0 diff --git a/src/cc/ctrl/TrafCtrlEnums.java b/src/cc/ctrl/TrafCtrlEnums.java index 469129f0..2f0ae625 100644 --- a/src/cc/ctrl/TrafCtrlEnums.java +++ b/src/cc/ctrl/TrafCtrlEnums.java @@ -51,7 +51,7 @@ public abstract class TrafCtrlEnums new String[0], //parking", "no", "parallel", "angled new String[]{"dm/s", "mph", "kph"}, //minspeed new String[]{"dm/s", "mph", "kph"}, //maxspeed - new String[]{"sec", "sec", "sec"}, //minhdwy + new String[]{"dm", "ft", "m"}, //minhdwy new String[]{"kg", "lb", "kg"}, //maxvehmass new String[]{"dm", "ft", "m"}, //maxvehheight new String[]{"dm", "ft", "m"}, //maxvehwidth diff --git a/src/cc/ws/CtrlTiles.java b/src/cc/ws/CtrlTiles.java index b07b0ed9..8ddc22ef 100644 --- a/src/cc/ws/CtrlTiles.java +++ b/src/cc/ws/CtrlTiles.java @@ -37,7 +37,6 @@ import cc.vector_tile.VectorTile; import java.awt.geom.Area; import java.io.BufferedInputStream; -import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.IOException; import java.io.PrintWriter; @@ -477,7 +476,11 @@ private void addControl(HttpServletRequest oReq, HttpServletResponse oRes) String sVal = oReq.getParameter("value"); if (sVal != null) { - nControlValue = Integer.parseInt(sVal); + double dVal = Double.parseDouble(sVal); + if (sUnits.length > 0) + nControlValue = (int)Math.round(Units.getInstance().convert(sUnits[1], sUnits[0], dVal)); + else + nControlValue = (int)dVal; } else { @@ -497,11 +500,7 @@ private void addControl(HttpServletRequest oReq, HttpServletResponse oRes) nControlValue = Integer.parseInt(sVal); } } - if (sUnits.length > 0) - { - double dVal = Units.getInstance().convert(sUnits[1], sUnits[0], nControlValue); - nControlValue = (int)Math.round(dVal); - } + String sId = oReq.getParameter("id"); int nStartIndex = Integer.parseInt(oReq.getParameter("s")) * 4 + 1; // add one since we use the growable arrays with the insertion index at position 0 int nEndIndex = Integer.parseInt(oReq.getParameter("e")) * 4 + 1; diff --git a/src/cc/ws/GeoLanes.java b/src/cc/ws/GeoLanes.java index c7edb6a9..8cfa6308 100644 --- a/src/cc/ws/GeoLanes.java +++ b/src/cc/ws/GeoLanes.java @@ -21,6 +21,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -196,13 +197,13 @@ protected void doPost(HttpServletRequest oRequest, HttpServletResponse oResponse sBuf.append("]"); if (TrafCtrlEnums.CTRLS[oCtrl.m_nControlType].length == 1) { - int nDisplay = Integer.parseInt(sVals.get(1)); + double dDisplay = Integer.parseInt(sVals.get(1)); String[] sUnits = TrafCtrlEnums.UNITS[oCtrl.m_nControlType]; if (sUnits.length > 0) { - nDisplay = (int)Math.round(Units.getInstance().convert(sUnits[0], sUnits[1], nDisplay)); + dDisplay = Units.getInstance().convert(sUnits[0], sUnits[1], dDisplay); } - sBuf.append(",\"display\":").append(nDisplay); + sBuf.append(",\"display\":").append(new DecimalFormat("#.##").format(dDisplay)); } sBuf.append("},"); } From 926bc20c5e73c1de94b1f393f5592e80fb6c42f6 Mon Sep 17 00:00:00 2001 From: cherneyasp Date: Thu, 30 Jun 2022 14:40:29 -0500 Subject: [PATCH 2/4] Changed parseInt to parseDouble --- src/cc/ws/GeoLanes.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/ws/GeoLanes.java b/src/cc/ws/GeoLanes.java index 8cfa6308..578fb1d6 100644 --- a/src/cc/ws/GeoLanes.java +++ b/src/cc/ws/GeoLanes.java @@ -30,7 +30,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; /** * @@ -197,7 +196,7 @@ protected void doPost(HttpServletRequest oRequest, HttpServletResponse oResponse sBuf.append("]"); if (TrafCtrlEnums.CTRLS[oCtrl.m_nControlType].length == 1) { - double dDisplay = Integer.parseInt(sVals.get(1)); + double dDisplay = Double.parseDouble(sVals.get(1)); String[] sUnits = TrafCtrlEnums.UNITS[oCtrl.m_nControlType]; if (sUnits.length > 0) { From cb2ede86078043f03cf54058cc4d982b12a47ed3 Mon Sep 17 00:00:00 2001 From: cherneyasp Date: Thu, 7 Jul 2022 15:06:26 -0500 Subject: [PATCH 3/4] Bug fix for controls with decimal numbers failing and updating the dialog with the new value. --- src/cc/ws/CtrlTiles.java | 26 +++++++++++++++++++------- web/script/map-edit.js | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/cc/ws/CtrlTiles.java b/src/cc/ws/CtrlTiles.java index 8ddc22ef..8dfe0112 100644 --- a/src/cc/ws/CtrlTiles.java +++ b/src/cc/ws/CtrlTiles.java @@ -43,6 +43,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -589,7 +590,12 @@ private void saveEdit(HttpServletRequest oReq, HttpServletResponse oRes) boolean bReg; bReg = !(sReg == null || sReg.compareTo("on") != 0); if (sVal != null) - nControlValue = Integer.parseInt(sVal); + { + double dVal = Double.parseDouble(sVal); + if (sUnits.length > 0) + dVal = Units.getInstance().convert(sUnits[1], sUnits[0], dVal); + nControlValue = (int)Math.round(dVal); + } else { sVal = oReq.getParameter("value1"); @@ -603,11 +609,7 @@ private void saveEdit(HttpServletRequest oReq, HttpServletResponse oRes) else nControlValue = Integer.parseInt(sVal); } - if (sUnits.length > 0) - { - double dVal = Units.getInstance().convert(sUnits[1], sUnits[0], nControlValue); - nControlValue = (int)Math.round(dVal); - } + String sId = oReq.getParameter("id"); String sFile = g_sCtrlDir + sId + ".bin"; TrafCtrl oOriginalCtrl; @@ -670,7 +672,17 @@ private void saveEdit(HttpServletRequest oReq, HttpServletResponse oRes) for (String sValue : sVals) sBuf.append("\"").append(sValue).append("\","); sBuf.setLength(sBuf.length() - 1); - sBuf.append("]}"); + sBuf.append("]"); + if (TrafCtrlEnums.CTRLS[oCtrlToWrite.m_nControlType].length == 1) + { + double dDisplay = Double.parseDouble(sVals.get(1)); + if (sUnits.length > 0) + { + dDisplay = Units.getInstance().convert(sUnits[0], sUnits[1], dDisplay); + } + sBuf.append(",\"display\":").append(new DecimalFormat("#.##").format(dDisplay)); + } + sBuf.append("}"); try (PrintWriter oOut = oRes.getWriter()) { oOut.append(sBuf); diff --git a/web/script/map-edit.js b/web/script/map-edit.js index 02d74537..7d3fd1fc 100644 --- a/web/script/map-edit.js +++ b/web/script/map-edit.js @@ -594,6 +594,7 @@ function doneSaveEdit(oData) oMapData.features[nSelectedId].properties.reg = oData.reg; oMapData.features[nSelectedId].properties.label = oData.label; oMapData.features[nSelectedId].properties.vtypes = oData.vtypes; + oMapData.features[nSelectedId].properties.display = oData.display; oSrc.setData(oMapData); console.log(oData.id);; refreshVectorTiles(); From 42104da6d4cc0e2efedef83364df8d50a1c140f9 Mon Sep 17 00:00:00 2001 From: cherneyasp Date: Thu, 7 Jul 2022 15:07:48 -0500 Subject: [PATCH 4/4] Fixed the rendered view of the control for minhdwy --- src/cc/ctrl/proc/ProcCtrl.java | 2 ++ src/cc/ctrl/proc/ProcHeadway.java | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cc/ctrl/proc/ProcCtrl.java b/src/cc/ctrl/proc/ProcCtrl.java index 1f819999..a6b2ce37 100644 --- a/src/cc/ctrl/proc/ProcCtrl.java +++ b/src/cc/ctrl/proc/ProcCtrl.java @@ -77,6 +77,8 @@ public abstract class ProcCtrl CHARS.put("X", new double[]{-0.1, -0.2, 0.1, 0.2, 0.0, 0.0, -0.1, 0.2, 0.1, -0.2}); CHARS.put("s", new double[]{0.1, 0.0, -0.1, 0.0, -0.1, -0.1, 0.1, -0.1, 0.1, -0.2, -0.1, -0.2}); CHARS.put(".", new double[]{0.1, -0.075, 0.1, -0.1, 0.075, -0.1, 0.075, -0.075, 0.1, -0.075}); + CHARS.put("t", new double[]{-0.1, 0, 0.1, 0, 0.0, 0.0, 0.0, 0.2, 0.0, -0.2, 0.1, -0.2}); + CHARS.put("f", new double[]{-0.1, 0, 0.1, 0, 0.0, 0.0, 0.0, -0.2, 0.0, 0.2, 0.1, 0.2}); } public String m_sLineArcDir; diff --git a/src/cc/ctrl/proc/ProcHeadway.java b/src/cc/ctrl/proc/ProcHeadway.java index f75f0937..65a6b29f 100644 --- a/src/cc/ctrl/proc/ProcHeadway.java +++ b/src/cc/ctrl/proc/ProcHeadway.java @@ -8,12 +8,14 @@ import cc.ctrl.CtrlGeo; import cc.ctrl.CtrlLineArcs; import cc.ctrl.TrafCtrl; +import cc.ctrl.TrafCtrlEnums; import cc.geosrv.Mercator; import cc.util.Arrays; import cc.util.FileUtil; import cc.util.Geo; import cc.util.MathUtil; import cc.util.TileUtil; +import cc.util.Units; import java.awt.geom.AffineTransform; import java.io.BufferedOutputStream; import java.io.DataOutputStream; @@ -73,7 +75,8 @@ public static void renderTiledData(ArrayList oCtrls, ArrayList dSymbol1[0] = dSymbol1.length; dSymbol2[0] = dSymbol2.length; int nSymbolPts = SYMBOL.length / 2; - + Units oUnits = Units.getInstance(); + String[] sUnits = TrafCtrlEnums.UNITS[TrafCtrlEnums.getCtrl("minhdwy")]; for (int[] nTile : nTiles) { int nX = nTile[0]; @@ -134,8 +137,8 @@ public static void renderTiledData(ArrayList oCtrls, ArrayList { oLayer.add(new TdFeature(dSymbol1, nTags, oCtrl)); oLayer.add(new TdFeature(dSymbol2, nTags, oCtrl)); - - String sVal = oDf.format(MathUtil.bytesToInt(oCtrl.m_yControlValue)) + "s"; + int nVal = (int)Math.round(oUnits.convert(sUnits[0], sUnits[1], MathUtil.bytesToInt(oCtrl.m_yControlValue))); + String sVal = oDf.format(nVal) + "ft"; int nLimit = sVal.length(); double dStep = -0.3; double dOffset = -0.45 + (nLimit * 0.3);