From a32a574e0780f9a2a2f1f04c8bfce4f59aa19f2a Mon Sep 17 00:00:00 2001 From: Mark Wickens Date: Thu, 15 Aug 2024 18:35:45 +0100 Subject: [PATCH 1/2] - enabled colour by band with some changes --- pom.xml | 2 +- .../adifproc/adif3/args/CommandLineArgs.java | 2 +- .../adif3/control/TransformControl.java | 3 +- .../m0nom/adifproc/kml/KmlBandLineStyles.java | 127 ++++++++++++------ .../uk/m0nom/adifproc/kml/KmlLineStyle.java | 6 +- .../adifproc/kml/comms/KmlCommsService.java | 29 ++-- .../adifproc/FileProcessorApplication.java | 10 +- .../uk/m0nom/adifproc/adif3/BadGridTest.java | 36 ++--- 8 files changed, 131 insertions(+), 84 deletions(-) diff --git a/pom.xml b/pom.xml index 1c22c6ad..c7923576 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ uk.m0nom adif-processor - 1.4.13 + 1.4.14-SNAPSHOT ADIF Processor https://github.com/urbancamo/adif-processor diff --git a/src/main/java/uk/m0nom/adifproc/adif3/args/CommandLineArgs.java b/src/main/java/uk/m0nom/adifproc/adif3/args/CommandLineArgs.java index 21661391..130c4c50 100644 --- a/src/main/java/uk/m0nom/adifproc/adif3/args/CommandLineArgs.java +++ b/src/main/java/uk/m0nom/adifproc/adif3/args/CommandLineArgs.java @@ -129,7 +129,7 @@ public TransformControl parseArgs(String[] args) { } control.setKmlContactTransparency(100-ns.getInt("kml_contact_transparency")); control.setKmlContactWidth(ns.getInt("kml_contact_width")); - control.setKmlContactColourByBand(ns.getBoolean("kml_contact_colour_band")); + control.setColourContactsByBand(ns.getBoolean("kml_contact_colour_band")); control.setFormattedOutput(ns.getBoolean("markdown")); control.setQslLabels(ns.getBoolean("qsl_labels")); diff --git a/src/main/java/uk/m0nom/adifproc/adif3/control/TransformControl.java b/src/main/java/uk/m0nom/adifproc/adif3/control/TransformControl.java index 351790a2..d0348ab2 100644 --- a/src/main/java/uk/m0nom/adifproc/adif3/control/TransformControl.java +++ b/src/main/java/uk/m0nom/adifproc/adif3/control/TransformControl.java @@ -99,7 +99,6 @@ public class TransformControl { private Boolean generateKml; private Integer kmlContactWidth; private Integer kmlContactTransparency; - private boolean kmlContactColourByBand; private boolean kmlS2s; private String kmlS2sContactLineStyle; private String kmlInternetContactLineStyle; @@ -135,6 +134,8 @@ public class TransformControl { private String portableIcon; + private boolean colourContactsByBand; + public String getActivityRef(ActivityType type) { return activityRefs.get(type); } diff --git a/src/main/java/uk/m0nom/adifproc/kml/KmlBandLineStyles.java b/src/main/java/uk/m0nom/adifproc/kml/KmlBandLineStyles.java index f1313bc7..505499e3 100644 --- a/src/main/java/uk/m0nom/adifproc/kml/KmlBandLineStyles.java +++ b/src/main/java/uk/m0nom/adifproc/kml/KmlBandLineStyles.java @@ -1,58 +1,107 @@ package uk.m0nom.adifproc.kml; -import static org.marsik.ham.adif.enums.Band.*; import org.marsik.ham.adif.enums.Band; import java.util.HashMap; import java.util.Map; +import static org.marsik.ham.adif.enums.Band.*; + public class KmlBandLineStyles { private final Map bandLineStyles; - + public KmlBandLineStyles(int width, int transparency) { bandLineStyles = new HashMap<>(); - bandLineStyles.put(BAND_2190m, getKmlLineStyle(250, 0, 0, transparency, width)); - bandLineStyles.put(BAND_630m, getKmlLineStyle(246, 48, 0, transparency, width)); - bandLineStyles.put(BAND_560m, getKmlLineStyle(240, 69, 0, transparency, width)); - bandLineStyles.put(BAND_160m, getKmlLineStyle(235, 86, 0, transparency, width)); - bandLineStyles.put(BAND_80m, getKmlLineStyle(228, 100, 0, transparency, width)); - bandLineStyles.put(BAND_60m, getKmlLineStyle(222, 112, 0, transparency, width)); - bandLineStyles.put(BAND_40m, getKmlLineStyle(214, 123, 0, transparency, width)); - bandLineStyles.put(BAND_30m, getKmlLineStyle(207, 133, 0, transparency, width)); - bandLineStyles.put(BAND_20m, getKmlLineStyle(199, 143, 0, transparency, width)); - bandLineStyles.put(BAND_17m, getKmlLineStyle(191, 151, 0, transparency, width)); - bandLineStyles.put(BAND_15m, getKmlLineStyle(183, 160, 0, transparency, width)); - bandLineStyles.put(BAND_12m, getKmlLineStyle(175, 167, 0, transparency, width)); - bandLineStyles.put(BAND_10m, getKmlLineStyle(166, 174, 0, transparency, width)); - bandLineStyles.put(BAND_6m, getKmlLineStyle(158, 181, 0, transparency, width)); - bandLineStyles.put(BAND_4m, getKmlLineStyle(149, 188, 15, transparency, width)); - bandLineStyles.put(BAND_2m, getKmlLineStyle(140, 194, 42, transparency, width)); - bandLineStyles.put(BAND_1_25m, getKmlLineStyle(130, 200, 61, transparency, width)); - bandLineStyles.put(BAND_70cm, getKmlLineStyle(121, 205, 78, transparency, width)); - bandLineStyles.put(BAND_33cm, getKmlLineStyle(110, 210, 95, transparency, width)); - bandLineStyles.put(BAND_23cm, getKmlLineStyle(100, 216, 111, transparency, width)); - bandLineStyles.put(BAND_13cm, getKmlLineStyle(88, 220, 127, transparency, width)); - bandLineStyles.put(BAND_9cm, getKmlLineStyle(75, 225, 143, transparency, width)); - bandLineStyles.put(BAND_6cm, getKmlLineStyle(61, 230, 158, transparency, width)); - bandLineStyles.put(BAND_3cm, getKmlLineStyle(45, 234, 173, transparency, width)); - bandLineStyles.put(BAND_1_25cm, getKmlLineStyle(22, 238, 188, transparency, width)); - bandLineStyles.put(BAND_6mm, getKmlLineStyle(0, 242, 203, transparency, width)); - bandLineStyles.put(BAND_4mm, getKmlLineStyle(0, 245, 217, transparency, width)); - bandLineStyles.put(BAND_2_5mm, getKmlLineStyle(0, 249, 230, transparency, width)); - bandLineStyles.put(BAND_2mm, getKmlLineStyle(0, 252, 243, transparency, width)); - bandLineStyles.put(BAND_1mm, getKmlLineStyle(0, 255, 255, transparency, width)); - } - - private KmlLineStyle getKmlLineStyle(int r, int g, int b, int transparency, int width) { - String name = getRgbColourName(r, g, b); +// "FEEAFA", +// "FFF3B0", +// "8E9AAF", +// "CBF3F0", +// "540B0E", +// "00AFB9", +// "E0FBFC", +// "6D597A", +// "9E2A2B", +// "4361EE", +// "B56576", +// "F4978E", +// "F8AD9D", +// "F07167", +// "0077B6", +// "293241", +// "EE6C4D", +// "E09F3E", +// "2EC4B6", +// "FFDAB9", +// "FDFCDC", +// "FF9F1C", +// "F08080", +// "D6DAC8", +// "3A0CA3", +// "0081A7", +// "D6CCC2", +// "CBC0D3", +// "EAAC8B", +// "CAF0F8", +// "011627", +// "FDFFFC", +// "2EC4B6", +// "E71D36", +// "FF9F1C", +// "000814", +// "001D3D", +// "003566", +// "FFC300", +// "FFD60A", +// "463F3A", +// "8A817C", +// "BCB8B1", +// "F4F3EE", +// "E0AFA0", +// "5F0F40", +// "9A031E", +// "FB8B24", +// "0F4C5C", - return new KmlLineStyle(name, r, g, b, transparency, width); + bandLineStyles.put(BAND_2190m, getKmlLineStyle(BAND_2190m, "FCF6BD", transparency, width)); + bandLineStyles.put(BAND_630m, getKmlLineStyle(BAND_630m, "FCF6BD", transparency, width)); + bandLineStyles.put(BAND_560m, getKmlLineStyle(BAND_560m, "A9DEF9", transparency, width)); + bandLineStyles.put(BAND_160m, getKmlLineStyle(BAND_160m, "E4C1F9", transparency, width)); + bandLineStyles.put(BAND_80m, getKmlLineStyle(BAND_80m, "780000", transparency, width)); + bandLineStyles.put(BAND_60m, getKmlLineStyle(BAND_60m, "C1121F", transparency, width)); + bandLineStyles.put(BAND_40m, getKmlLineStyle(BAND_40m, "FDF0D5", transparency, width)); + bandLineStyles.put(BAND_30m, getKmlLineStyle(BAND_30m, "003049", transparency, width)); + bandLineStyles.put(BAND_20m, getKmlLineStyle(BAND_20m, "669BBC", transparency, width)); + bandLineStyles.put(BAND_17m, getKmlLineStyle(BAND_17m, "9A031E", transparency, width)); + bandLineStyles.put(BAND_15m, getKmlLineStyle(BAND_15m, "3C6E71", transparency, width)); + bandLineStyles.put(BAND_12m, getKmlLineStyle(BAND_12m, "FF99C8", transparency, width)); + bandLineStyles.put(BAND_10m, getKmlLineStyle(BAND_10m, "D9D9D9", transparency, width)); + bandLineStyles.put(BAND_6m, getKmlLineStyle(BAND_6m, "284B63", transparency, width)); + bandLineStyles.put(BAND_4m, getKmlLineStyle(BAND_4m, "05668D", transparency, width)); + bandLineStyles.put(BAND_2m, getKmlLineStyle(BAND_2m, "028090", transparency, width)); + bandLineStyles.put(BAND_1_25m, getKmlLineStyle(BAND_1_25m, "00A896", transparency, width)); + bandLineStyles.put(BAND_70cm, getKmlLineStyle(BAND_70cm, "02C39A", transparency, width)); + bandLineStyles.put(BAND_33cm, getKmlLineStyle(BAND_33cm, "F0F3BD", transparency, width)); + bandLineStyles.put(BAND_23cm, getKmlLineStyle(BAND_23cm, "9B5DE5", transparency, width)); + bandLineStyles.put(BAND_13cm, getKmlLineStyle(BAND_13cm, "F15BB5", transparency, width)); + bandLineStyles.put(BAND_9cm, getKmlLineStyle(BAND_9cm, "FEE440", transparency, width)); + bandLineStyles.put(BAND_6cm, getKmlLineStyle(BAND_6cm, "00BBF9", transparency, width)); + bandLineStyles.put(BAND_3cm, getKmlLineStyle(BAND_3cm, "00F5D4", transparency, width)); + bandLineStyles.put(BAND_1_25cm, getKmlLineStyle(BAND_1_25cm, "386641", transparency, width)); + bandLineStyles.put(BAND_6mm, getKmlLineStyle(BAND_6mm, "6A994E", transparency, width)); + bandLineStyles.put(BAND_4mm, getKmlLineStyle(BAND_4mm, "A7C957", transparency, width)); + bandLineStyles.put(BAND_2_5mm, getKmlLineStyle(BAND_2_5mm, "F2E8CF", transparency, width)); + bandLineStyles.put(BAND_2mm, getKmlLineStyle(BAND_2mm, "BC4749", transparency, width)); + bandLineStyles.put(BAND_1mm, getKmlLineStyle(BAND_1mm, "E36414", transparency, width)); } - public String getRgbColourName(int red, int green, int blue) { - return String.format("%02X%02X%02X", red, green, blue); + private KmlLineStyle getKmlLineStyle(Band band, String colour, int transparency, int width) { + int red = Integer.parseInt(colour.substring(0, 2), 16); + int green = Integer.parseInt(colour.substring(2, 4), 16); + int blue = Integer.parseInt(colour.substring(4, 6), 16); + + return new KmlLineStyle(band.name(), red, green, blue, transparency, width); } public KmlLineStyle getLineStyle(Band band) { diff --git a/src/main/java/uk/m0nom/adifproc/kml/KmlLineStyle.java b/src/main/java/uk/m0nom/adifproc/kml/KmlLineStyle.java index 5f11e342..f68e97e0 100644 --- a/src/main/java/uk/m0nom/adifproc/kml/KmlLineStyle.java +++ b/src/main/java/uk/m0nom/adifproc/kml/KmlLineStyle.java @@ -10,7 +10,7 @@ public class KmlLineStyle extends KmlColour { private Integer width; public KmlLineStyle(String name, int red, int green, int blue, int transparency, int width) { - super(name, red, green, blue, transparency); + super(name, name, getHtmlColor(red, green, blue), red, green, blue, transparency); this.width = width; } @@ -22,4 +22,8 @@ public KmlLineStyle(KmlColour colour, int width) { setTransparency(colour.getTransparency()); setWidth(width); } + + private static String getHtmlColor(int red, int green, int blue) { + return String.format("ff%02X%02X%02X", red, green, blue); + } } diff --git a/src/main/java/uk/m0nom/adifproc/kml/comms/KmlCommsService.java b/src/main/java/uk/m0nom/adifproc/kml/comms/KmlCommsService.java index b3b606f3..bec2d757 100644 --- a/src/main/java/uk/m0nom/adifproc/kml/comms/KmlCommsService.java +++ b/src/main/java/uk/m0nom/adifproc/kml/comms/KmlCommsService.java @@ -27,7 +27,6 @@ public class KmlCommsService { public final static String SHADOW_LINE = "shadow"; private final CommsVisualizationService commsVisualizationService; - private KmlBandLineStyles bandLineStyles; public KmlCommsService(CommsVisualizationService commsVisualizationService) { this.commsVisualizationService = commsVisualizationService; @@ -57,7 +56,10 @@ public static String getCommsLinkShadowId(Qso qso) { public CommsLinkResult createCommsLink(Document document, Folder folder, Map commsStyleMap, Qso qso, TransformControl control, KmlStationUtils stationUtils) { boolean internet = qso.getRecord().getPropMode() == Propagation.INTERNET; - bandLineStyles = new KmlBandLineStyles(control.getKmlContactWidth(), control.getKmlContactTransparency());String commsLinkId = getCommsLinkId(qso); + + KmlBandLineStyles bandLineStyles = new KmlBandLineStyles(control.getKmlContactWidth(), control.getKmlContactTransparency()); + + String commsLinkId = getCommsLinkId(qso); String commsLinkName = getCommsLinkName(qso); String commsLinkShadowId = getCommsLinkShadowId(qso); @@ -69,15 +71,19 @@ public CommsLinkResult createCommsLink(Document document, Folder folder, Map commsStyleMap) { + private void addStyleIfUsed(Document document, TransformControl control, Qso qso, Map commsStyleMap, KmlBandLineStyles bandLineStyles) { if (control.isKmlS2s() && qso.doingSameActivity()) { if (!commsStyleMap.containsKey(S2S_LINE)) { KmlLineStyle styling = KmlStyling.getKmlLineStyle(control.getKmlS2sContactLineStyle()); @@ -190,13 +196,13 @@ private void addStyleIfUsed(Document document, TransformControl control, Qso qso style.createAndSetLineStyle().withColor(styling.getStringSpecifier()).withWidth(styling.getWidth()); commsStyleMap.put(INTERNET_LINE, KmlUtils.getStyleUrl(INTERNET_LINE)); } - } else if (control.isKmlContactColourByBand()) { + } else if (control.isColourContactsByBand()) { KmlLineStyle styling = bandLineStyles.getLineStyle(qso.getRecord().getBand()); - String styleId = styling.getStringSpecifier(); + String styleId = styling.getName(); if (!commsStyleMap.containsKey(styling.getStringSpecifier())) { Style style = document.createAndAddStyle() .withId(KmlUtils.getStyleId(styleId)); - style.createAndSetLineStyle().withColor(styling.getStringSpecifier()).withWidth(styling.getWidth()); + style.createAndSetLineStyle().withColor(styling.getHtmlColor()).withWidth(styling.getWidth()); commsStyleMap.put(styling.getStringSpecifier(), KmlUtils.getStyleUrl(styling.getStringSpecifier())); } } else { @@ -209,7 +215,6 @@ private void addStyleIfUsed(Document document, TransformControl control, Qso qso commsStyleMap.put(COMM_LINE, KmlUtils.getStyleUrl(COMM_LINE)); } } - if (control.isKmlContactShadow()) { if (!commsStyleMap.containsKey(SHADOW_LINE)) { Style style = document.createAndAddStyle() diff --git a/src/test/java/uk/m0nom/adifproc/FileProcessorApplication.java b/src/test/java/uk/m0nom/adifproc/FileProcessorApplication.java index b5719fac..c52c0533 100644 --- a/src/test/java/uk/m0nom/adifproc/FileProcessorApplication.java +++ b/src/test/java/uk/m0nom/adifproc/FileProcessorApplication.java @@ -1,5 +1,6 @@ package uk.m0nom.adifproc; +import lombok.Setter; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -42,6 +43,9 @@ public class FileProcessorApplication implements CommandLineRunner, ProgressFeed private static final Logger logger = Logger.getLogger(FileProcessorApplication.class.getName()); + @Setter + private String[] args; + private final CommandLineArgs cli; private final Adif3Transformer transformer; private final Adif3FileReader reader; @@ -96,7 +100,11 @@ public static void main(String[] args) { @Override public void run(String... args) { logger.info("EXECUTING : command line runner"); + this.args = args; + internalRun(); + } + public void internalRun() { TransformResults results = new TransformResults(); TransformControl control = cli.parseArgs(args); qrzXmlService.setCredentials(control.getQrzUsername(), control.getQrzPassword()); @@ -194,6 +202,6 @@ public void run(String... args) { @Override public void sendProgressUpdate(String sessionId, String message) { - System.out.println(message); + logger.info(message); } } diff --git a/src/test/java/uk/m0nom/adifproc/adif3/BadGridTest.java b/src/test/java/uk/m0nom/adifproc/adif3/BadGridTest.java index 2d0ab07c..646f0f0a 100644 --- a/src/test/java/uk/m0nom/adifproc/adif3/BadGridTest.java +++ b/src/test/java/uk/m0nom/adifproc/adif3/BadGridTest.java @@ -1,51 +1,31 @@ package uk.m0nom.adifproc.adif3; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import uk.m0nom.adifproc.FileProcessorApplication; -import uk.m0nom.adifproc.activity.ActivityDatabaseService; -import uk.m0nom.adifproc.adif3.io.Adif3FileReader; -import uk.m0nom.adifproc.adif3.io.Adif3FileWriter; -import uk.m0nom.adifproc.adif3.print.Adif3PrintFormatter; -import uk.m0nom.adifproc.kml.KmlWriter; -import uk.m0nom.adifproc.qrz.CachingQrzXmlService; @SpringBootTest @ActiveProfiles("test") public class BadGridTest { @Autowired - Adif3Transformer transformer; + private FileProcessorApplication app; - @Autowired - Adif3FileReader reader; - - @Autowired - Adif3FileWriter writer; - - @Autowired - ActivityDatabaseService summits; - - @Autowired - Adif3PrintFormatter formatter; - - @Autowired - KmlWriter kmlWriter; + private static final String[] args = ("-k --encoding windows-1251 -md -o ../ ./target/test-classes/adif/2021-08-23-ADIF-with-bad-gridsquare.adi").split(" "); - @Autowired - CachingQrzXmlService qrzXmlService; + @BeforeEach + public void setup() { + app.setArgs(args); + } @Test public void testApp() { try { - String cli = "-k --encoding windows-1251 -md -o ../ ./target/test-classes/adif/2021-08-23-ADIF-with-bad-gridsquare.adi"; - String[] args = cli.split(" "); - - FileProcessorApplication app = new FileProcessorApplication(transformer, reader, writer, summits, formatter, kmlWriter, qrzXmlService); - app.run(args); + app.internalRun(); } catch (Exception e) { Assertions.fail("testData() threw exception while setting up the test. ", e); } From 5e939274c22da47e1d640e4c69397cccef930655 Mon Sep 17 00:00:00 2001 From: Mark Wickens Date: Sat, 24 Aug 2024 13:19:11 +0100 Subject: [PATCH 2/2] - enabled colour by band with some changes - release 1.4.14 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c7923576..a3cce10c 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ uk.m0nom adif-processor - 1.4.14-SNAPSHOT + 1.4.14 ADIF Processor https://github.com/urbancamo/adif-processor