diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 43dca9b4c..be9630a1d 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1504,6 +1504,8 @@ OBJOptionChooser.checkbox.exportChildren = Export children OBJOptionChooser.checkbox.exportChildren.ttip = If true, export children of the selected components as well. OBJOptionChooser.checkbox.exportChildren.assemblies.ttip = Component assemblies always export their children. OBJOptionChooser.checkbox.exportChildren.noChildren.ttip = Selected components don't have children. +OBJOptionChooser.checkbox.exportMotors = Export motors +OBJOptionChooser.checkbox.exportMotors.ttip = If true, export the motors of the rocket. OBJOptionChooser.checkbox.exportAppearance = Export appearance OBJOptionChooser.checkbox.exportAppearance.ttip = If true, export the component appearances to an MTL file. OBJOptionChooser.checkbox.exportAsSeparateFiles = Export as separate files diff --git a/core/src/net/sf/openrocket/file/wavefrontobj/export/OBJExportOptions.java b/core/src/net/sf/openrocket/file/wavefrontobj/export/OBJExportOptions.java index ab283f718..e89b108c2 100644 --- a/core/src/net/sf/openrocket/file/wavefrontobj/export/OBJExportOptions.java +++ b/core/src/net/sf/openrocket/file/wavefrontobj/export/OBJExportOptions.java @@ -6,10 +6,16 @@ import net.sf.openrocket.file.wavefrontobj.ObjUtils; import net.sf.openrocket.rocketcomponent.Rocket; public class OBJExportOptions { + // ! Update Preferences when adding new options ! + /** * If true, export all children of the components as well */ private boolean exportChildren; + /** + * If true, export the motors of the components as well. + */ + private boolean exportMotors; /** * If true, export the appearance of the components to an MTL file. */ @@ -64,6 +70,14 @@ public class OBJExportOptions { this.exportChildren = exportChildren; } + public boolean isExportMotors() { + return exportMotors; + } + + public void setExportMotors(boolean exportMotors) { + this.exportMotors = exportMotors; + } + public boolean isRemoveOffset() { return removeOffset; } diff --git a/core/src/net/sf/openrocket/file/wavefrontobj/export/OBJExporterFactory.java b/core/src/net/sf/openrocket/file/wavefrontobj/export/OBJExporterFactory.java index a71739583..b9e6f52b3 100644 --- a/core/src/net/sf/openrocket/file/wavefrontobj/export/OBJExporterFactory.java +++ b/core/src/net/sf/openrocket/file/wavefrontobj/export/OBJExporterFactory.java @@ -262,7 +262,7 @@ public class OBJExporterFactory { exporter.addToObj(); // Export motor - if (component instanceof MotorMount) { + if (component instanceof MotorMount && options.isExportMotors()) { // Get the motor MotorConfiguration motoConfig = ((MotorMount) component).getMotorConfig(config.getId()); Motor motor = motoConfig.getMotor(); diff --git a/core/src/net/sf/openrocket/startup/Preferences.java b/core/src/net/sf/openrocket/startup/Preferences.java index 2bcb8d885..7f46a85a5 100644 --- a/core/src/net/sf/openrocket/startup/Preferences.java +++ b/core/src/net/sf/openrocket/startup/Preferences.java @@ -122,6 +122,7 @@ public abstract class Preferences implements ChangeSource { // OBJ Export options private static final String OBJ_EXPORT_OPTIONS_NODE = "OBJExportOptions"; private static final String OBJ_EXPORT_CHILDREN = "ExportChildren"; + private static final String OBJ_EXPORT_MOTORS = "ExportMotors"; private static final String OBJ_EXPORT_APPEARANCE = "ExportAppearance"; private static final String OBJ_EXPORT_AS_SEPARATE_FILES = "ExportAsSeparateFiles"; private static final String OBJ_REMOVE_OFFSET = "RemoveOffset"; @@ -1040,6 +1041,7 @@ public abstract class Preferences implements ChangeSource { java.util.prefs.Preferences objExportOptionsNode = preferences.node(OBJ_EXPORT_OPTIONS_NODE); objExportOptionsNode.putBoolean(OBJ_EXPORT_CHILDREN, options.isExportChildren()); + objExportOptionsNode.putBoolean(OBJ_EXPORT_MOTORS, options.isExportMotors()); objExportOptionsNode.putBoolean(OBJ_EXPORT_APPEARANCE, options.isExportAppearance()); objExportOptionsNode.putBoolean(OBJ_EXPORT_AS_SEPARATE_FILES, options.isExportAsSeparateFiles()); objExportOptionsNode.putBoolean(OBJ_REMOVE_OFFSET, options.isRemoveOffset()); @@ -1069,6 +1071,7 @@ public abstract class Preferences implements ChangeSource { // By default, we will use options optimized for 3D printing (most-used case) OBJExportOptions options = new OBJExportOptions(rocket); options.setExportChildren(objExportOptionsNode.getBoolean(OBJ_EXPORT_CHILDREN, false)); + options.setExportMotors(objExportOptionsNode.getBoolean(OBJ_EXPORT_MOTORS, false)); options.setExportAppearance(objExportOptionsNode.getBoolean(OBJ_EXPORT_APPEARANCE, false)); options.setExportAsSeparateFiles(objExportOptionsNode.getBoolean(OBJ_EXPORT_AS_SEPARATE_FILES, false)); options.setRemoveOffset(objExportOptionsNode.getBoolean(OBJ_REMOVE_OFFSET, true)); diff --git a/swing/src/net/sf/openrocket/file/wavefrontobj/OBJOptionChooser.java b/swing/src/net/sf/openrocket/file/wavefrontobj/OBJOptionChooser.java index 0767e01d6..d23149313 100644 --- a/swing/src/net/sf/openrocket/file/wavefrontobj/OBJOptionChooser.java +++ b/swing/src/net/sf/openrocket/file/wavefrontobj/OBJOptionChooser.java @@ -46,6 +46,7 @@ public class OBJOptionChooser extends JPanel { private final JButton optRend; private final JLabel componentsLabel; private final JCheckBox exportChildren; + private final JCheckBox exportMotors; private final JCheckBox exportAppearance; private final JCheckBox exportAsSeparateFiles; private final JCheckBox removeOffset; @@ -146,6 +147,13 @@ public class OBJOptionChooser extends JPanel { destroyTheMagic(exportChildren); this.add(exportChildren, "spanx, wrap"); + //// Export motors + this.exportMotors = new JCheckBox(trans.get("OBJOptionChooser.checkbox.exportMotors")); + this.exportMotors.setToolTipText(trans.get("OBJOptionChooser.checkbox.exportMotors.ttip")); + destroyTheMagic(exportMotors); + addOptimizationListener(exportMotors); + this.add(exportMotors, "spanx, wrap"); + //// Remove origin offset this.removeOffset = new JCheckBox(trans.get("OBJOptionChooser.checkbox.removeOffset")); this.removeOffset.setToolTipText(trans.get("OBJOptionChooser.checkbox.removeOffset.ttip")); @@ -360,6 +368,7 @@ public class OBJOptionChooser extends JPanel { exportChildren.setToolTipText(trans.get("OBJOptionChooser.checkbox.exportChildren.ttip")); } + this.exportMotors.setSelected(opts.isExportMotors()); this.exportAppearance.setSelected(opts.isExportAppearance()); this.exportAsSeparateFiles.setSelected(opts.isExportAsSeparateFiles()); this.removeOffset.setSelected(opts.isRemoveOffset()); @@ -391,6 +400,7 @@ public class OBJOptionChooser extends JPanel { if (alwaysStoreExportChildren || !onlyComponentAssemblies) { opts.setExportChildren(exportChildren.isSelected()); } + opts.setExportMotors(exportMotors.isSelected()); opts.setExportAppearance(exportAppearance.isSelected()); opts.setExportAsSeparateFiles(exportAsSeparateFiles.isSelected()); opts.setRemoveOffset(removeOffset.isSelected()); @@ -409,6 +419,7 @@ public class OBJOptionChooser extends JPanel { OBJExportOptions options = new OBJExportOptions(rocket); storeOptions(options, true); + options.setExportMotors(false); options.setExportAppearance(false); options.setRemoveOffset(true); options.setScaling(1000); @@ -424,14 +435,15 @@ public class OBJOptionChooser extends JPanel { * @return True if the settings are optimized for 3D printing, false otherwise */ private boolean isOptimizedFor3DPrinting(OBJExportOptions options) { - return !options.isExportAppearance() && options.isTriangulate() && options.getLOD() == ObjUtils.LevelOfDetail.HIGH_QUALITY && - options.isRemoveOffset() && options.getScaling() == 1000; + return !options.isExportMotors() && !options.isExportAppearance() && options.isTriangulate() && + options.getLOD() == ObjUtils.LevelOfDetail.HIGH_QUALITY && options.isRemoveOffset() && options.getScaling() == 1000; } private void optimizeSettingsForRendering() { OBJExportOptions options = new OBJExportOptions(rocket); storeOptions(options, true); + options.setExportMotors(true); options.setExportAppearance(true); options.setScaling(20); // Idk, pretty arbitrary options.setTriangulate(false); @@ -446,8 +458,8 @@ public class OBJOptionChooser extends JPanel { * @return True if the settings are optimized for rendering, false otherwise */ private boolean isOptimizedForRendering(OBJExportOptions options) { - return options.isExportAppearance() && !options.isTriangulate() && options.getLOD() == ObjUtils.LevelOfDetail.NORMAL_QUALITY && - options.getScaling() == 20; + return options.isExportMotors() && options.isExportAppearance() && !options.isTriangulate() && + options.getLOD() == ObjUtils.LevelOfDetail.NORMAL_QUALITY && options.getScaling() == 20; } private static boolean isOnlyComponentAssembliesSelected(List selectedComponents) {