2011-09-07 20:41:58 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* (C) Copyright 2009-2024, Arnaud Roques
|
2011-09-07 20:41:58 +00:00
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* Project Info: https://plantuml.com
|
2011-09-07 20:41:58 +00:00
|
|
|
*
|
2017-03-15 19:13:31 +00:00
|
|
|
* If you like this project or if you find it useful, you can support us at:
|
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* https://plantuml.com/patreon (only 1$ per month!)
|
|
|
|
* https://plantuml.com/paypal
|
2017-03-15 19:13:31 +00:00
|
|
|
*
|
2011-09-07 20:41:58 +00:00
|
|
|
* This file is part of PlantUML.
|
|
|
|
*
|
|
|
|
* PlantUML is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PlantUML distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
2013-12-10 19:36:50 +00:00
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
2011-09-07 20:41:58 +00:00
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml.acearth;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
2016-05-31 19:41:55 +00:00
|
|
|
import java.util.Locale;
|
2011-09-07 20:41:58 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.TimeZone;
|
|
|
|
|
2020-04-19 16:04:39 +00:00
|
|
|
import ext.plantuml.com.ctreber.acearth.ACearth;
|
|
|
|
import ext.plantuml.com.ctreber.acearth.ConfigurationACearth;
|
|
|
|
import ext.plantuml.com.ctreber.acearth.plugins.markers.Marker;
|
2011-09-07 20:41:58 +00:00
|
|
|
import net.sourceforge.plantuml.AbstractPSystem;
|
|
|
|
import net.sourceforge.plantuml.FileFormatOption;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.api.ImageDataSimple;
|
|
|
|
import net.sourceforge.plantuml.core.DiagramDescription;
|
|
|
|
import net.sourceforge.plantuml.core.ImageData;
|
2021-05-23 15:35:13 +00:00
|
|
|
import net.sourceforge.plantuml.core.UmlSource;
|
2011-09-07 20:41:58 +00:00
|
|
|
|
|
|
|
public class PSystemXearth extends AbstractPSystem {
|
2023-03-08 20:49:44 +00:00
|
|
|
// ::remove folder when __CORE__
|
2023-05-15 16:37:07 +00:00
|
|
|
// ::remove folder when __MIT__ or __EPL__ or __BSD__ or __ASL__ or __LGPL__
|
2011-09-07 20:41:58 +00:00
|
|
|
|
|
|
|
final private int width;
|
|
|
|
final private int height;
|
|
|
|
final private Map<String, String> config;
|
|
|
|
final private List<Marker> markers;
|
|
|
|
|
|
|
|
final private Collection<String> enums = Arrays.asList("viewPositionType");
|
|
|
|
final private Collection<String> doubles = Arrays.asList("sunPosRelLat", "sunPosRelLong", "orbitPeriod",
|
|
|
|
"orbitInclination", "viewPosLat", "viewPosLong", "starFrequency", "viewMagnification");
|
|
|
|
final private Collection<String> integers = Arrays.asList("daySideBrightness", "nightSideBrightness",
|
|
|
|
"terminatorDiscontinuity", "gridDivision", "gridPixelDivision", "bigStars");
|
|
|
|
final private Collection<String> booleans = Arrays.asList("shadeP", "gridP", "starsP");
|
|
|
|
|
2021-05-23 15:35:13 +00:00
|
|
|
public PSystemXearth(UmlSource source, int width, int height, Map<String, String> config, List<Marker> markers) {
|
|
|
|
super(source);
|
2011-09-07 20:41:58 +00:00
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
this.config = config;
|
|
|
|
this.markers = markers;
|
|
|
|
}
|
2016-12-01 20:29:25 +00:00
|
|
|
|
|
|
|
@Override
|
2021-03-23 13:06:33 +00:00
|
|
|
final protected ImageData exportDiagramNow(OutputStream os, int num, FileFormatOption fileFormat)
|
2016-12-01 20:29:25 +00:00
|
|
|
throws IOException {
|
2019-09-14 18:12:04 +00:00
|
|
|
synchronized (PSystemXearth.class) {
|
|
|
|
final ACearth earth = new ACearth(markers);
|
|
|
|
final ConfigurationACearth conf = earth.getConf();
|
|
|
|
conf.setInt("imageWidth", width);
|
|
|
|
conf.setInt("imageHeight", height);
|
2011-09-07 20:41:58 +00:00
|
|
|
|
2019-09-14 18:12:04 +00:00
|
|
|
for (Map.Entry<String, String> ent : config.entrySet()) {
|
|
|
|
final String key = ent.getKey();
|
|
|
|
final String value = ent.getValue();
|
|
|
|
if (key.equalsIgnoreCase("GMT")) {
|
|
|
|
final Date date = extractGmt(value);
|
|
|
|
conf.setInt("fixedTime", (int) (date.getTime() / 1000L));
|
|
|
|
} else if (enums.contains(key)) {
|
|
|
|
conf.getMOEnum(key).set(value);
|
|
|
|
} else if (doubles.contains(key)) {
|
|
|
|
conf.setDouble(key, Double.parseDouble(value));
|
|
|
|
} else if (integers.contains(key)) {
|
|
|
|
conf.setInt(key, Integer.parseInt(value));
|
|
|
|
} else if (booleans.contains(key)) {
|
|
|
|
conf.setBoolean(key, value.equalsIgnoreCase("true"));
|
|
|
|
} else {
|
|
|
|
throw new UnsupportedOperationException(key);
|
|
|
|
}
|
2011-09-07 20:41:58 +00:00
|
|
|
}
|
2019-09-14 18:12:04 +00:00
|
|
|
earth.exportPng(os);
|
|
|
|
return new ImageDataSimple(width, height);
|
2011-09-07 20:41:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Date extractGmt(String s) {
|
|
|
|
final SimpleDateFormat timeFormat;
|
|
|
|
if (s.matches("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2}")) {
|
2016-05-31 19:41:55 +00:00
|
|
|
timeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US);
|
2011-09-07 20:41:58 +00:00
|
|
|
} else if (s.matches("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}")) {
|
2016-05-31 19:41:55 +00:00
|
|
|
timeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.US);
|
2011-09-07 20:41:58 +00:00
|
|
|
} else {
|
|
|
|
throw new UnsupportedOperationException(s);
|
|
|
|
}
|
|
|
|
timeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
|
try {
|
|
|
|
return timeFormat.parse(s);
|
|
|
|
} catch (ParseException e) {
|
|
|
|
throw new UnsupportedOperationException(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public DiagramDescription getDescription() {
|
2017-03-12 17:22:02 +00:00
|
|
|
return new DiagramDescription("(XEarth)");
|
2011-09-07 20:41:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|