[fixes #697] Added Photo Studio settings saving
This commit is contained in:
parent
074b7a842a
commit
85213cdd89
@ -1,13 +1,7 @@
|
||||
package net.sf.openrocket.document;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.*;
|
||||
import org.slf4j.Logger;
|
||||
@ -61,7 +55,8 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
private final ArrayList<Simulation> simulations = new ArrayList<Simulation>();
|
||||
private ArrayList<CustomExpression> customExpressions = new ArrayList<CustomExpression>();
|
||||
|
||||
private PhotoSettings photoSettings = new PhotoSettings();
|
||||
// The Photo Settings will be saved in the core module as a map of key values with corresponding content
|
||||
private Map<String, String> photoSettings = new HashMap<>();
|
||||
|
||||
/*
|
||||
* The undo/redo variables and mechanism are documented in doc/undo-redo-flow.*
|
||||
@ -834,11 +829,11 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
public PhotoSettings getPhotoSettings() {
|
||||
public Map<String, String> getPhotoSettings() {
|
||||
return photoSettings;
|
||||
}
|
||||
|
||||
public void setPhotoSettings(PhotoSettings photoSettings) {
|
||||
public void setPhotoSettings(Map<String, String> photoSettings) {
|
||||
this.photoSettings = photoSettings;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,12 +5,8 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.*;
|
||||
|
||||
import net.sf.openrocket.document.PhotoSettings;
|
||||
import net.sf.openrocket.file.openrocket.savers.PhotoStudioSaver;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -427,7 +423,7 @@ public class OpenRocketSaver extends RocketSaver {
|
||||
|
||||
}
|
||||
|
||||
private void savePhotoSettings(PhotoSettings p) throws IOException {
|
||||
private void savePhotoSettings(Map<String, String> p) throws IOException {
|
||||
log.debug("Saving Photo Settings");
|
||||
for (String s : PhotoStudioSaver.getElements(p))
|
||||
writeln(s);
|
||||
|
||||
@ -19,7 +19,7 @@ import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
* The starting point of the handlers. Accepts a single <openrocket> element and hands
|
||||
* the contents to be read by a OpenRocketContentsHandler.
|
||||
*/
|
||||
class OpenRocketHandler extends AbstractElementHandler {
|
||||
public class OpenRocketHandler extends AbstractElementHandler {
|
||||
private final DocumentLoadingContext context;
|
||||
private OpenRocketContentHandler handler = null;
|
||||
|
||||
|
||||
@ -1,32 +1,30 @@
|
||||
package net.sf.openrocket.file.openrocket.importt;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.PhotoSettings;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
import net.sf.openrocket.gui.figure3d.TextureCache;
|
||||
import net.sf.openrocket.gui.figure3d.photo.sky.Sky;
|
||||
import net.sf.openrocket.gui.figure3d.photo.sky.SkyBox;
|
||||
import net.sf.openrocket.gui.figure3d.photo.sky.builtin.*;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.Color;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* File import handler for PhotoSettings
|
||||
* This class will parse the photostudio xml parameters from the OpenRocketDocument and
|
||||
* save it as a parameter map. This map can then later be used in the swing module for getting
|
||||
* or setting the PhotoSetting. (this cumbersome solution is done because of dependency reasons
|
||||
* between files of the core and swing module; trying to just use PhotoSettings objects in the
|
||||
* core module would have caused circular dependencies)
|
||||
*
|
||||
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
||||
*/
|
||||
public class PhotoStudioHandler extends AbstractElementHandler {
|
||||
private PhotoSettings p;
|
||||
// The Photo Settings will be saved in the core module as a map of key values with corresponding content
|
||||
private Map<String, String> p;
|
||||
private static final Logger log = LoggerFactory.getLogger(OpenRocketHandler.class);
|
||||
|
||||
public PhotoStudioHandler(PhotoSettings p) {
|
||||
public PhotoStudioHandler(Map<String, String> p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
@ -37,176 +35,23 @@ public class PhotoStudioHandler extends AbstractElementHandler {
|
||||
|
||||
@Override
|
||||
public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings) throws SAXException {
|
||||
if ("roll".equals(element)) {
|
||||
double roll = Double.parseDouble(content);
|
||||
p.setRoll(roll);
|
||||
String[] params = new String[] {"roll", "yaw", "pitch", "advance", "viewAlt", "viewAz", "viewDistance", "fov",
|
||||
"lightAlt", "lightAz", "ambiance", "ambiance", "motionBlurred", "flame", "smoke", "smokeOpacity", "sparks",
|
||||
"exhaustScale", "flameAspectRatio", "sparkConcentration", "sparkWeight", "sky"};
|
||||
if (Arrays.asList(params).contains(element)) {
|
||||
p.put(element, content);
|
||||
return;
|
||||
}
|
||||
if ("yaw".equals(element)) {
|
||||
double yaw = Double.parseDouble(content);
|
||||
p.setYaw(yaw);
|
||||
return;
|
||||
}
|
||||
if ("pitch".equals(element)) {
|
||||
double pitch = Double.parseDouble(content);
|
||||
p.setPitch(pitch);
|
||||
return;
|
||||
}
|
||||
if ("advance".equals(element)) {
|
||||
double advance = Double.parseDouble(content);
|
||||
p.setAdvance(advance);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("viewAlt".equals(element)) {
|
||||
double viewAlt = Double.parseDouble(content);
|
||||
p.setViewAlt(viewAlt);
|
||||
return;
|
||||
}
|
||||
if ("viewAz".equals(element)) {
|
||||
double viewAz = Double.parseDouble(content);
|
||||
p.setViewAz(viewAz);
|
||||
return;
|
||||
}
|
||||
if ("viewDistance".equals(element)) {
|
||||
double viewDistance = Double.parseDouble(content);
|
||||
p.setViewDistance(viewDistance);
|
||||
return;
|
||||
}
|
||||
if ("fov".equals(element)) {
|
||||
double fov = Double.parseDouble(content);
|
||||
p.setFov(fov);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("lightAlt".equals(element)) {
|
||||
double lightAlt = Double.parseDouble(content);
|
||||
p.setLightAlt(lightAlt);
|
||||
return;
|
||||
}
|
||||
if ("lightAz".equals(element)) {
|
||||
double lightAz = Double.parseDouble(content);
|
||||
p.setLightAz(lightAz);
|
||||
return;
|
||||
}
|
||||
if ("sunlight".equals(element)) {
|
||||
Color sunlight = getColor(attributes);
|
||||
p.setSunlight(sunlight);
|
||||
return;
|
||||
}
|
||||
if ("ambiance".equals(element)) {
|
||||
double ambiance = Double.parseDouble(content);
|
||||
p.setAmbiance(ambiance);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("skyColor".equals(element)) {
|
||||
Color skyColor = getColor(attributes);
|
||||
p.setSkyColor(skyColor);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("motionBlurred".equals(element)) {
|
||||
boolean motionBlurred = Boolean.parseBoolean(content);
|
||||
p.setMotionBlurred(motionBlurred);
|
||||
return;
|
||||
}
|
||||
if ("flame".equals(element)) {
|
||||
boolean flame = Boolean.parseBoolean(content);
|
||||
p.setFlame(flame);
|
||||
return;
|
||||
}
|
||||
if ("flameColor".equals(element)) {
|
||||
Color flameColor = getColor(attributes);
|
||||
p.setFlameColor(flameColor);
|
||||
return;
|
||||
}
|
||||
if ("smoke".equals(element)) {
|
||||
boolean smoke = Boolean.parseBoolean(content);
|
||||
p.setSmoke(smoke);
|
||||
return;
|
||||
}
|
||||
if ("smokeColor".equals(element)) {
|
||||
Color smokeColor = getColor(attributes);
|
||||
p.setSmokeColor(smokeColor);
|
||||
return;
|
||||
}
|
||||
if ("smokeOpacity".equals(element)) {
|
||||
double smokeOpacity = Double.parseDouble(content);
|
||||
p.setSmokeOpacity(smokeOpacity);
|
||||
return;
|
||||
}
|
||||
if ("sparks".equals(element)) {
|
||||
boolean sparks = Boolean.parseBoolean(content);
|
||||
p.setSparks(sparks);
|
||||
return;
|
||||
}
|
||||
if ("exhaustScale".equals(element)) {
|
||||
double exhaustScale = Double.parseDouble(content);
|
||||
p.setExhaustScale(exhaustScale);
|
||||
return;
|
||||
}
|
||||
if ("flameAspectRatio".equals(element)) {
|
||||
double flameAspectRatio = Double.parseDouble(content);
|
||||
p.setFlameAspectRatio(flameAspectRatio);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("sparkConcentration".equals(element)) {
|
||||
double sparkConcentration = Double.parseDouble(content);
|
||||
p.setSparkConcentration(sparkConcentration);
|
||||
return;
|
||||
}
|
||||
if ("sparkWeight".equals(element)) {
|
||||
double sparkWeight = Double.parseDouble(content);
|
||||
p.setSparkWeight(sparkWeight);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("sky".equals(element)) {
|
||||
if (content.equals("")) { // Case where sky is null
|
||||
p.setSky(null);
|
||||
return;
|
||||
}
|
||||
Sky s = null;
|
||||
try {
|
||||
Class<?> cl = Class.forName(content);
|
||||
if (Mountains.class.isAssignableFrom(cl))
|
||||
s = Mountains.instance;
|
||||
else if (Lake.class.isAssignableFrom(cl))
|
||||
s = Lake.instance;
|
||||
else if (Meadow.class.isAssignableFrom(cl))
|
||||
s = Meadow.instance;
|
||||
else if (Miramar.class.isAssignableFrom(cl))
|
||||
s = Miramar.instance;
|
||||
else if (Orbit.class.isAssignableFrom(cl))
|
||||
s = Orbit.instance;
|
||||
else if (Storm.class.isAssignableFrom(cl))
|
||||
s = Storm.instance;
|
||||
else {
|
||||
// Case where sky is a dummy sky, displaying <none>
|
||||
s = new Sky() {
|
||||
@Override
|
||||
public void draw(com.jogamp.opengl.GL2 gl, TextureCache cache) { }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Application.getTranslator().get("DecalModel.lbl.select");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
log.info("Could not load sky class '" + content + "'.");
|
||||
}
|
||||
p.setSky(s);
|
||||
String[] colors = new String[] {"sunlight", "skyColor", "flameColor", "smokeColor"};
|
||||
if (Arrays.asList(colors).contains(element)) {
|
||||
p.put(element, getColor(attributes));
|
||||
return;
|
||||
}
|
||||
|
||||
super.closeElement(element, attributes, content, warnings);
|
||||
}
|
||||
|
||||
private Color getColor(HashMap<String, String> attributes) {
|
||||
private String getColor(HashMap<String, String> attributes) {
|
||||
int red = Integer.parseInt(attributes.get("red"));
|
||||
int green = Integer.parseInt(attributes.get("green"));
|
||||
int blue = Integer.parseInt(attributes.get("blue"));
|
||||
@ -217,6 +62,6 @@ public class PhotoStudioHandler extends AbstractElementHandler {
|
||||
// "alpha" string was present so load the value
|
||||
alpha = Integer.parseInt(a);
|
||||
}
|
||||
return new Color(red, green, blue, alpha);
|
||||
return red + " " + green + " " + blue + " " + alpha;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,61 +1,84 @@
|
||||
package net.sf.openrocket.file.openrocket.savers;
|
||||
import
|
||||
|
||||
import net.sf.openrocket.util.Color;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class takes in the photo settings map from the swing module and converts it into the xml format
|
||||
* needed to save it in the OpenRocketDocument.
|
||||
* (this cumbersome solution is done because of dependency reasons
|
||||
* between files of the core and swing module; trying to just use PhotoSettings objects in the
|
||||
* core module would have caused circular dependencies)
|
||||
*
|
||||
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
||||
*/
|
||||
public class PhotoStudioSaver {
|
||||
public static List<String> getElements(PhotoSettings p) {
|
||||
public static List<String> getElements(Map<String, String> photoSettings) {
|
||||
List<String> elements = new ArrayList<String>();
|
||||
|
||||
if (photoSettings == null || photoSettings.size() == 0) return elements;
|
||||
|
||||
elements.add("<photostudio>");
|
||||
|
||||
elements.add("<roll>" + p.getRoll() + "</roll>");
|
||||
elements.add("<yaw>" + p.getYaw() + "</yaw>");
|
||||
elements.add("<pitch>" + p.getPitch() + "</pitch>");
|
||||
elements.add("<advance>" + p.getAdvance() + "</advance>");
|
||||
elements.add("<roll>" + photoSettings.get("roll") + "</roll>");
|
||||
elements.add("<yaw>" + photoSettings.get("yaw") + "</yaw>");
|
||||
elements.add("<pitch>" + photoSettings.get("pitch") + "</pitch>");
|
||||
elements.add("<advance>" + photoSettings.get("advance") + "</advance>");
|
||||
|
||||
elements.add("<viewAlt>" + p.getViewAlt() + "</viewAlt>");
|
||||
elements.add("<viewAz>" + p.getViewAz() + "</viewAz>");
|
||||
elements.add("<viewDistance>" + p.getViewDistance() + "</viewDistance>");
|
||||
elements.add("<fov>" + p.getFov() + "</fov>");
|
||||
elements.add("<viewAlt>" + photoSettings.get("viewAlt") + "</viewAlt>");
|
||||
elements.add("<viewAz>" + photoSettings.get("viewAz") + "</viewAz>");
|
||||
elements.add("<viewDistance>" + photoSettings.get("viewDistance") + "</viewDistance>");
|
||||
elements.add("<fov>" + photoSettings.get("fov") + "</fov>");
|
||||
|
||||
elements.add("<lightAlt>" + p.getLightAlt() + "</lightAlt>");
|
||||
elements.add("<lightAz>" + p.getLightAz() + "</lightAz>");
|
||||
emitColor("sunlight", elements, p.getSunlight());
|
||||
elements.add("<ambiance>" + p.getAmbiance() + "</ambiance>");
|
||||
elements.add("<lightAlt>" + photoSettings.get("lightAlt") + "</lightAlt>");
|
||||
elements.add("<lightAz>" + photoSettings.get("lightAz") + "</lightAz>");
|
||||
emitColor("sunlight", elements, photoSettings.get("sunlight"));
|
||||
elements.add("<ambiance>" + photoSettings.get("ambiance") + "</ambiance>");
|
||||
|
||||
emitColor("skyColor", elements, p.getSkyColor());
|
||||
emitColor("skyColor", elements, photoSettings.get("skyColor"));
|
||||
|
||||
elements.add("<motionBlurred>" + p.isMotionBlurred() + "</motionBlurred>");
|
||||
elements.add("<flame>" + p.isFlame() + "</flame>");
|
||||
emitColor("flameColor", elements, p.getFlameColor());
|
||||
elements.add("<smoke>" + p.isSmoke() + "</smoke>");
|
||||
emitColor("smokeColor", elements, p.getSmokeColor());
|
||||
elements.add("<smokeOpacity>" + p.getSmokeOpacity() + "</smokeOpacity>");
|
||||
elements.add("<sparks>" + p.isSparks() + "</sparks>");
|
||||
elements.add("<exhaustScale>" + p.getExhaustScale() + "</exhaustScale>");
|
||||
elements.add("<flameAspectRatio>" + p.getFlameAspectRatio() + "</flameAspectRatio>");
|
||||
elements.add("<motionBlurred>" + photoSettings.get("motionBlurred") + "</motionBlurred>");
|
||||
elements.add("<flame>" + photoSettings.get("flame") + "</flame>");
|
||||
emitColor("flameColor", elements, photoSettings.get("flameColor"));
|
||||
elements.add("<smoke>" + photoSettings.get("smoke") + "</smoke>");
|
||||
emitColor("smokeColor", elements, photoSettings.get("smokeColor"));
|
||||
elements.add("<smokeOpacity>" + photoSettings.get("smokeOpacity") + "</smokeOpacity>");
|
||||
elements.add("<sparks>" + photoSettings.get("sparks") + "</sparks>");
|
||||
elements.add("<exhaustScale>" + photoSettings.get("exhaustScale") + "</exhaustScale>");
|
||||
elements.add("<flameAspectRatio>" + photoSettings.get("flameAspectRatio") + "</flameAspectRatio>");
|
||||
|
||||
elements.add("<sparkConcentration>" + p.getSparkConcentration() + "</sparkConcentration>");
|
||||
elements.add("<sparkWeight>" + p.getSparkWeight() + "</sparkWeight>");
|
||||
elements.add("<sparkConcentration>" + photoSettings.get("sparkConcentration") + "</sparkConcentration>");
|
||||
elements.add("<sparkWeight>" + photoSettings.get("sparkWeight") + "</sparkWeight>");
|
||||
|
||||
if (p.getSky() != null) {
|
||||
elements.add("<sky>" + p.getSky().getClass().getName() + "</sky>");
|
||||
}
|
||||
else
|
||||
elements.add("<sky></sky>");
|
||||
elements.add("<sky>" + photoSettings.get("sky") + "</sky>");
|
||||
|
||||
elements.add("</photostudio>");
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
private final static void emitColor(String elementName, List<String> elements, Color color) {
|
||||
private static Color getColor(String content) {
|
||||
if (content == null) return null;
|
||||
String[] values = content.split(" ");
|
||||
if (values.length < 4) return null;
|
||||
|
||||
int red = Integer.parseInt(values[0]);
|
||||
int green = Integer.parseInt(values[1]);
|
||||
int blue = Integer.parseInt(values[2]);
|
||||
int alpha = Integer.parseInt(values[3]);
|
||||
return new Color(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
private static void emitColor(String elementName, List<String> elements, String content) {
|
||||
Color color = getColor(content);
|
||||
if (color != null) {
|
||||
elements.add("<" + elementName + " red=\"" + color.getRed() + "\" green=\"" + color.getGreen()
|
||||
+ "\" blue=\"" + color.getBlue() + "\" alpha=\"" + color.getAlpha() + "\"/>");
|
||||
}
|
||||
else
|
||||
elements.add(String.format("<%s></%s>", elementName));
|
||||
}
|
||||
}
|
||||
|
||||
220
swing/src/net/sf/openrocket/file/photo/PhotoStudioGetter.java
Normal file
220
swing/src/net/sf/openrocket/file/photo/PhotoStudioGetter.java
Normal file
@ -0,0 +1,220 @@
|
||||
package net.sf.openrocket.file.photo;
|
||||
|
||||
import net.sf.openrocket.file.openrocket.importt.OpenRocketHandler;
|
||||
import net.sf.openrocket.gui.figure3d.TextureCache;
|
||||
import net.sf.openrocket.gui.figure3d.photo.PhotoSettings;
|
||||
import net.sf.openrocket.gui.figure3d.photo.sky.Sky;
|
||||
import net.sf.openrocket.gui.figure3d.photo.sky.builtin.*;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.Color;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class takes in the PhotoSetting map from the core module and converts it
|
||||
* to a PhotoSettings object that can be used withing the swing module.
|
||||
* (this cumbersome solution is done because of dependency reasons
|
||||
* between files of the core and swing module; trying to just use PhotoSettings objects in the
|
||||
* core module would have caused circular dependencies)
|
||||
*
|
||||
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
||||
*/
|
||||
public class PhotoStudioGetter {
|
||||
private PhotoSettings p = null;
|
||||
private Map<String, String> parameters = null;
|
||||
private static final Logger log = LoggerFactory.getLogger(OpenRocketHandler.class);
|
||||
|
||||
public PhotoStudioGetter(Map<String, String> par) {
|
||||
this.parameters = par;
|
||||
p = new PhotoSettings();
|
||||
}
|
||||
|
||||
public PhotoSettings getPhotoSettings() {
|
||||
if (parameters != null) {
|
||||
for (String element : parameters.keySet()) {
|
||||
processElement(element, parameters.get(element));
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
private void processElement(String element, String content) {
|
||||
if ("roll".equals(element)) {
|
||||
double roll = Double.parseDouble(content);
|
||||
p.setRoll(roll);
|
||||
return;
|
||||
}
|
||||
if ("yaw".equals(element)) {
|
||||
double yaw = Double.parseDouble(content);
|
||||
p.setYaw(yaw);
|
||||
return;
|
||||
}
|
||||
if ("pitch".equals(element)) {
|
||||
double pitch = Double.parseDouble(content);
|
||||
p.setPitch(pitch);
|
||||
return;
|
||||
}
|
||||
if ("advance".equals(element)) {
|
||||
double advance = Double.parseDouble(content);
|
||||
p.setAdvance(advance);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("viewAlt".equals(element)) {
|
||||
double viewAlt = Double.parseDouble(content);
|
||||
p.setViewAlt(viewAlt);
|
||||
return;
|
||||
}
|
||||
if ("viewAz".equals(element)) {
|
||||
double viewAz = Double.parseDouble(content);
|
||||
p.setViewAz(viewAz);
|
||||
return;
|
||||
}
|
||||
if ("viewDistance".equals(element)) {
|
||||
double viewDistance = Double.parseDouble(content);
|
||||
p.setViewDistance(viewDistance);
|
||||
return;
|
||||
}
|
||||
if ("fov".equals(element)) {
|
||||
double fov = Double.parseDouble(content);
|
||||
p.setFov(fov);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("lightAlt".equals(element)) {
|
||||
double lightAlt = Double.parseDouble(content);
|
||||
p.setLightAlt(lightAlt);
|
||||
return;
|
||||
}
|
||||
if ("lightAz".equals(element)) {
|
||||
double lightAz = Double.parseDouble(content);
|
||||
p.setLightAz(lightAz);
|
||||
return;
|
||||
}
|
||||
if ("sunlight".equals(element)) {
|
||||
Color sunlight = getColor(content);
|
||||
p.setSunlight(sunlight);
|
||||
return;
|
||||
}
|
||||
if ("ambiance".equals(element)) {
|
||||
double ambiance = Double.parseDouble(content);
|
||||
p.setAmbiance(ambiance);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("skyColor".equals(element)) {
|
||||
Color skyColor = getColor(content);
|
||||
p.setSkyColor(skyColor);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("motionBlurred".equals(element)) {
|
||||
boolean motionBlurred = Boolean.parseBoolean(content);
|
||||
p.setMotionBlurred(motionBlurred);
|
||||
return;
|
||||
}
|
||||
if ("flame".equals(element)) {
|
||||
boolean flame = Boolean.parseBoolean(content);
|
||||
p.setFlame(flame);
|
||||
return;
|
||||
}
|
||||
if ("flameColor".equals(element)) {
|
||||
Color flameColor = getColor(content);
|
||||
p.setFlameColor(flameColor);
|
||||
return;
|
||||
}
|
||||
if ("smoke".equals(element)) {
|
||||
boolean smoke = Boolean.parseBoolean(content);
|
||||
p.setSmoke(smoke);
|
||||
return;
|
||||
}
|
||||
if ("smokeColor".equals(element)) {
|
||||
Color smokeColor = getColor(content);
|
||||
p.setSmokeColor(smokeColor);
|
||||
return;
|
||||
}
|
||||
if ("smokeOpacity".equals(element)) {
|
||||
double smokeOpacity = Double.parseDouble(content);
|
||||
p.setSmokeOpacity(smokeOpacity);
|
||||
return;
|
||||
}
|
||||
if ("sparks".equals(element)) {
|
||||
boolean sparks = Boolean.parseBoolean(content);
|
||||
p.setSparks(sparks);
|
||||
return;
|
||||
}
|
||||
if ("exhaustScale".equals(element)) {
|
||||
double exhaustScale = Double.parseDouble(content);
|
||||
p.setExhaustScale(exhaustScale);
|
||||
return;
|
||||
}
|
||||
if ("flameAspectRatio".equals(element)) {
|
||||
double flameAspectRatio = Double.parseDouble(content);
|
||||
p.setFlameAspectRatio(flameAspectRatio);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("sparkConcentration".equals(element)) {
|
||||
double sparkConcentration = Double.parseDouble(content);
|
||||
p.setSparkConcentration(sparkConcentration);
|
||||
return;
|
||||
}
|
||||
if ("sparkWeight".equals(element)) {
|
||||
double sparkWeight = Double.parseDouble(content);
|
||||
p.setSparkWeight(sparkWeight);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("sky".equals(element)) {
|
||||
if (content.equals("")) { // Case where sky is null
|
||||
p.setSky(null);
|
||||
return;
|
||||
}
|
||||
Sky s = null;
|
||||
try {
|
||||
Class<?> cl = Class.forName(content);
|
||||
if (Mountains.class.isAssignableFrom(cl))
|
||||
s = Mountains.instance;
|
||||
else if (Lake.class.isAssignableFrom(cl))
|
||||
s = Lake.instance;
|
||||
else if (Meadow.class.isAssignableFrom(cl))
|
||||
s = Meadow.instance;
|
||||
else if (Miramar.class.isAssignableFrom(cl))
|
||||
s = Miramar.instance;
|
||||
else if (Orbit.class.isAssignableFrom(cl))
|
||||
s = Orbit.instance;
|
||||
else if (Storm.class.isAssignableFrom(cl))
|
||||
s = Storm.instance;
|
||||
else {
|
||||
// Case where sky is a dummy sky, displaying <none>
|
||||
s = new Sky() {
|
||||
@Override
|
||||
public void draw(com.jogamp.opengl.GL2 gl, TextureCache cache) { }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Application.getTranslator().get("DecalModel.lbl.select");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
log.info("Could not load sky class '" + content + "'.");
|
||||
}
|
||||
p.setSky(s);
|
||||
}
|
||||
}
|
||||
|
||||
private Color getColor(String content) {
|
||||
String[] values = content.split(" ");
|
||||
if (values.length < 4) return null;
|
||||
|
||||
int red = Integer.parseInt(values[0]);
|
||||
int green = Integer.parseInt(values[1]);
|
||||
int blue = Integer.parseInt(values[2]);
|
||||
int alpha = Integer.parseInt(values[3]);
|
||||
return new Color(red, green, blue, alpha);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package net.sf.openrocket.file.photo;
|
||||
|
||||
import net.sf.openrocket.gui.figure3d.photo.PhotoSettings;
|
||||
import net.sf.openrocket.util.Color;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class converts the PhotoSettings to a Map that can be sent over to the core module for saving
|
||||
* into the OpenRocketDocument. The key of the map is the attribute name, the value is its content.
|
||||
* (this cumbersome solution is done because of dependency reasons
|
||||
* between files of the core and swing module; trying to just use PhotoSettings objects in the
|
||||
* core module would have caused circular dependencies)
|
||||
*
|
||||
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
||||
*/
|
||||
public class PhotoStudioSetter {
|
||||
public static Map<String, String> getPhotoSettings(PhotoSettings p) {
|
||||
Map<String, String> photoSettings = new HashMap<>();
|
||||
|
||||
photoSettings.put("roll", String.valueOf(p.getRoll()));
|
||||
photoSettings.put("yaw", String.valueOf(p.getYaw()));
|
||||
photoSettings.put("pitch", String.valueOf(p.getPitch()));
|
||||
photoSettings.put("advance", String.valueOf(p.getAdvance()));
|
||||
|
||||
photoSettings.put("viewAlt", String.valueOf(p.getViewAlt()));
|
||||
photoSettings.put("viewAz", String.valueOf(p.getViewAz()));
|
||||
photoSettings.put("viewDistance", String.valueOf(p.getViewDistance()));
|
||||
photoSettings.put("fov", String.valueOf(p.getFov()));
|
||||
|
||||
photoSettings.put("lightAlt", String.valueOf(p.getLightAlt()));
|
||||
photoSettings.put("lightAz", String.valueOf(p.getLightAz()));
|
||||
photoSettings.put("sunlight", getColor(p.getSunlight()));
|
||||
photoSettings.put("ambiance", String.valueOf(p.getAmbiance()));
|
||||
|
||||
photoSettings.put("skyColor", getColor(p.getSkyColor()));
|
||||
|
||||
photoSettings.put("motionBlurred", String.valueOf(p.isMotionBlurred()));
|
||||
photoSettings.put("flame", String.valueOf(p.isFlame()));
|
||||
photoSettings.put("flameColor", getColor(p.getFlameColor()));
|
||||
photoSettings.put("smoke", String.valueOf(p.isSmoke()));
|
||||
photoSettings.put("smokeColor", getColor(p.getSmokeColor()));
|
||||
photoSettings.put("smokeOpacity", String.valueOf(p.getSmokeOpacity()));
|
||||
photoSettings.put("sparks", String.valueOf(p.isSparks()));
|
||||
photoSettings.put("exhaustScale", String.valueOf(p.getExhaustScale()));
|
||||
photoSettings.put("flameAspectRatio", String.valueOf(p.getFlameAspectRatio()));
|
||||
|
||||
photoSettings.put("sparkConcentration", String.valueOf(p.getSparkConcentration()));
|
||||
photoSettings.put("sparkWeight", String.valueOf(p.getSparkWeight()));
|
||||
|
||||
if (p.getSky() != null)
|
||||
photoSettings.put("sky", p.getSky().getClass().getName());
|
||||
else
|
||||
photoSettings.put("sky", "");
|
||||
|
||||
return photoSettings;
|
||||
}
|
||||
|
||||
private static String getColor(Color color) {
|
||||
if (color == null) return "";
|
||||
return color.getRed() + " " + color.getGreen() + " " + color.getBlue() + " " + color.getAlpha();
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,8 @@ import java.awt.event.WindowEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.EventObject;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.AbstractAction;
|
||||
@ -32,6 +34,8 @@ import net.sf.openrocket.database.Databases;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.GeneralRocketLoader;
|
||||
import net.sf.openrocket.file.RocketLoadException;
|
||||
import net.sf.openrocket.file.photo.PhotoStudioGetter;
|
||||
import net.sf.openrocket.file.photo.PhotoStudioSetter;
|
||||
import net.sf.openrocket.gui.main.SwingExceptionHandler;
|
||||
import net.sf.openrocket.gui.util.FileHelper;
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
@ -45,6 +49,7 @@ import net.sf.openrocket.plugin.PluginModule;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.startup.GuiModule;
|
||||
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -67,9 +72,20 @@ public class PhotoFrame extends JFrame {
|
||||
}
|
||||
|
||||
public PhotoFrame(boolean app, OpenRocketDocument document) {
|
||||
PhotoSettings p = new PhotoStudioGetter(document.getPhotoSettings()).getPhotoSettings();
|
||||
|
||||
// Send the new PhotoSetting to the core module
|
||||
p.addChangeListener(new StateChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(EventObject e) {
|
||||
Map<String, String> par = PhotoStudioSetter.getPhotoSettings(p);
|
||||
document.setPhotoSettings(par);
|
||||
}
|
||||
});
|
||||
|
||||
setSize(1024, 768);
|
||||
this.setMinimumSize(new Dimension(160, 150));
|
||||
photoPanel = new PhotoPanel(document);
|
||||
photoPanel = new PhotoPanel(document, p);
|
||||
photoPanel.setDoc(document);
|
||||
setJMenuBar(getMenu(app));
|
||||
setContentPane(photoPanel);
|
||||
@ -92,7 +108,7 @@ public class PhotoFrame extends JFrame {
|
||||
|
||||
settings = new JDialog(this, trans.get("PhotoSettingsConfig.title")) {
|
||||
{
|
||||
setContentPane(new PhotoSettingsConfig(document.getPhotoSettings()));
|
||||
setContentPane(new PhotoSettingsConfig(p));
|
||||
pack();
|
||||
this.setLocationByPlatform(true);
|
||||
GUIUtil.rememberWindowSize(this);
|
||||
|
||||
@ -116,12 +116,11 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
||||
});
|
||||
}
|
||||
|
||||
PhotoPanel(OpenRocketDocument document) {
|
||||
PhotoPanel(OpenRocketDocument document, PhotoSettings p) {
|
||||
this.p = p;
|
||||
this.setLayout(new BorderLayout());
|
||||
PhotoPanel.this.configuration = document.getSelectedConfiguration();
|
||||
|
||||
p = document.getPhotoSettings();
|
||||
|
||||
// Fixes a linux / X bug: Splash must be closed before GL Init
|
||||
SplashScreen splash = Splash.getSplashScreen();
|
||||
if (splash != null && splash.isVisible())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user