From 08c4d083933a0f1b0e35257ca82959ec0bea6d71 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Fri, 18 Aug 2023 03:59:57 +0200 Subject: [PATCH] Fix issue of export children pref --- .../openrocket/document/OpenRocketDocument.java | 7 +++++++ .../file/wavefrontobj/OBJOptionChooser.java | 10 ++++++++-- .../net/sf/openrocket/gui/main/BasicFrame.java | 16 +++++++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/core/src/net/sf/openrocket/document/OpenRocketDocument.java b/core/src/net/sf/openrocket/document/OpenRocketDocument.java index 0b3332818..1b36a0175 100644 --- a/core/src/net/sf/openrocket/document/OpenRocketDocument.java +++ b/core/src/net/sf/openrocket/document/OpenRocketDocument.java @@ -3,6 +3,7 @@ package net.sf.openrocket.document; import java.io.File; import java.util.*; +import net.sf.openrocket.file.wavefrontobj.export.OBJExportOptions; import net.sf.openrocket.rocketcomponent.*; import net.sf.openrocket.startup.Preferences; import net.sf.openrocket.util.StateChangeListener; @@ -93,6 +94,7 @@ public class OpenRocketDocument implements ComponentChangeListener, StateChangeL private int savedID = -1; private final StorageOptions storageOptions = new StorageOptions(); + private final OBJExportOptions objOptions; private final DecalRegistry decalRegistry = new DecalRegistry(); @@ -105,6 +107,7 @@ public class OpenRocketDocument implements ComponentChangeListener, StateChangeL */ OpenRocketDocument(Rocket rocket) { this.rocket = rocket; + this.objOptions = prefs.loadOBJExportOptions(rocket); rocket.enableEvents(); init(); } @@ -250,6 +253,10 @@ public class OpenRocketDocument implements ComponentChangeListener, StateChangeL public StorageOptions getDefaultStorageOptions() { return storageOptions; } + + public OBJExportOptions getDefaultOBJOptions() { + return objOptions; + } /** diff --git a/swing/src/net/sf/openrocket/file/wavefrontobj/OBJOptionChooser.java b/swing/src/net/sf/openrocket/file/wavefrontobj/OBJOptionChooser.java index e62b1cf41..048af06e1 100644 --- a/swing/src/net/sf/openrocket/file/wavefrontobj/OBJOptionChooser.java +++ b/swing/src/net/sf/openrocket/file/wavefrontobj/OBJOptionChooser.java @@ -128,10 +128,16 @@ public class OBJOptionChooser extends JPanel { this.LOD.setSelectedItem(opts.getLOD()); } - public void storeOptions(OBJExportOptions opts) { + /** + * Store the options from this GUI in the given {@link OBJExportOptions} object. + * @param opts The options to store the options in + * @param alwaysStoreExportChildren if true, store the export children option even. If false, only store it if the + * checkbox was not disabled. + */ + public void storeOptions(OBJExportOptions opts, boolean alwaysStoreExportChildren) { boolean onlyComponentAssemblies = isOnlyComponentAssembliesSelected(selectedComponents); // Don't save the state when the checkbox is set automatically due to component assemblies - if (!onlyComponentAssemblies) { + if (alwaysStoreExportChildren || !onlyComponentAssemblies) { opts.setExportChildren(exportChildren.isSelected()); } opts.setExportAppearance(exportAppearance.isSelected()); diff --git a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java index 8ba7cc37c..057d07d5c 100644 --- a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java +++ b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java @@ -1405,10 +1405,16 @@ public class BasicFrame extends JFrame { return null; } + // Store the OBJ options if (objChooser != null) { - OBJExportOptions selectedOptions = new OBJExportOptions(rocket); - objChooser.storeOptions(selectedOptions); - prefs.saveOBJExportOptions(selectedOptions); + objChooser.storeOptions(document.getDefaultOBJOptions(), true); + + // We need to separately store the preference options, because the export children option can be + // automatically selected based on whether only component assemblies are selected. We don't want to + // store that state in the preferences. + OBJExportOptions prefOptions = new OBJExportOptions(rocket); + objChooser.storeOptions(prefOptions, false); + prefs.saveOBJExportOptions(prefOptions); } File file = chooser.getSelectedFile(); @@ -1642,7 +1648,7 @@ public class BasicFrame extends JFrame { } file = FileHelper.forceExtension(file, "obj"); - OBJExportOptions options = prefs.loadOBJExportOptions(rocket); + OBJExportOptions options = document.getDefaultOBJOptions(); boolean isExportAsSeparateFiles = options.isExportAsSeparateFiles(); if (isExportAsSeparateFiles || FileHelper.confirmWrite(file, BasicFrame.this)) { // No overwrite warning for separate files return saveAsWavefrontOBJ(file); @@ -1651,7 +1657,7 @@ public class BasicFrame extends JFrame { } private boolean saveAsWavefrontOBJ(File file) { - OBJExportOptions options = prefs.loadOBJExportOptions(rocket); + OBJExportOptions options = document.getDefaultOBJOptions(); return saveWavefrontOBJFile(file, options); }