Skip to content

Commit

Permalink
Merge pull request #109 from urbancamo/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
urbancamo authored Aug 24, 2024
2 parents d4bd8eb + 5e93927 commit c93ffee
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 84 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>uk.m0nom</groupId>
<artifactId>adif-processor</artifactId>
<version>1.4.13</version>
<version>1.4.14</version>

<name>ADIF Processor</name>
<url>https://github.com/urbancamo/adif-processor</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,6 +134,8 @@ public class TransformControl {

private String portableIcon;

private boolean colourContactsByBand;

public String getActivityRef(ActivityType type) {
return activityRefs.get(type);
}
Expand Down
127 changes: 88 additions & 39 deletions src/main/java/uk/m0nom/adifproc/kml/KmlBandLineStyles.java
Original file line number Diff line number Diff line change
@@ -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<Band, KmlLineStyle> 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) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/uk/m0nom/adifproc/kml/KmlLineStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
}
29 changes: 17 additions & 12 deletions src/main/java/uk/m0nom/adifproc/kml/comms/KmlCommsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,7 +56,10 @@ public static String getCommsLinkShadowId(Qso qso) {

public CommsLinkResult createCommsLink(Document document, Folder folder, Map<String, String> 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);

Expand All @@ -69,15 +71,19 @@ public CommsLinkResult createCommsLink(Document document, Folder folder, Map<Str
qso.getFrom().getCallsign()));
}

addStyleIfUsed(document, control, qso, commsStyleMap);
addStyleIfUsed(document, control, qso, commsStyleMap, bandLineStyles);
String id = getStyleForQso(control, qso, bandLineStyles);
String lineStyleId = commsStyleMap.get(id);

String id = getStyleForQso(control, qso);
if (control.isColourContactsByBand()) {
lineStyleId = bandLineStyles.getLineStyle(rec.getBand()).getName();
}

Placemark placemark = folder.createAndAddPlacemark();
// use the style for each line type
placemark.withName(commsLinkName)
.withId(commsLinkId)
.withStyleUrl(commsStyleMap.get(id));
.withStyleUrl(KmlUtils.getStyleUrl(lineStyleId));

LineString commsLine = placemark.createAndSetLineString();

Expand Down Expand Up @@ -151,12 +157,12 @@ public CommsLinkResult createCommsLink(Document document, Folder folder, Map<Str
}


private String getStyleForQso(TransformControl control, Qso qso) {
private String getStyleForQso(TransformControl control, Qso qso, KmlBandLineStyles bandLineStyles) {
if (control.isKmlS2s() && qso.doingSameActivity()) {
return S2S_LINE;
} else if (qso.getRecord().getPropMode() == Propagation.INTERNET) {
return INTERNET_LINE;
} else if (control.isKmlContactColourByBand()) {
} else if (control.isColourContactsByBand()) {
KmlLineStyle styling = bandLineStyles.getLineStyle(qso.getRecord().getBand());
return styling.getStringSpecifier();
}
Expand All @@ -171,7 +177,7 @@ private String getStyleForQso(TransformControl control, Qso qso) {
* @param qso QSO to add appropriate style
* @param control Controls the rendering of line styles
*/
private void addStyleIfUsed(Document document, TransformControl control, Qso qso, Map<String, String> commsStyleMap) {
private void addStyleIfUsed(Document document, TransformControl control, Qso qso, Map<String, String> commsStyleMap, KmlBandLineStyles bandLineStyles) {
if (control.isKmlS2s() && qso.doingSameActivity()) {
if (!commsStyleMap.containsKey(S2S_LINE)) {
KmlLineStyle styling = KmlStyling.getKmlLineStyle(control.getKmlS2sContactLineStyle());
Expand All @@ -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 {
Expand All @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/uk/m0nom/adifproc/FileProcessorApplication.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -194,6 +202,6 @@ public void run(String... args) {

@Override
public void sendProgressUpdate(String sessionId, String message) {
System.out.println(message);
logger.info(message);
}
}
36 changes: 8 additions & 28 deletions src/test/java/uk/m0nom/adifproc/adif3/BadGridTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down

0 comments on commit c93ffee

Please sign in to comment.