Refactor doc material loading to OpenRocketDocument
This commit is contained in:
parent
65116fcb58
commit
0d5952cfa3
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import info.openrocket.core.file.wavefrontobj.export.OBJExportOptions;
|
||||
import info.openrocket.core.material.Material;
|
||||
import info.openrocket.core.preferences.ApplicationPreferences;
|
||||
import info.openrocket.core.preferences.DocumentPreferences;
|
||||
import info.openrocket.core.rocketcomponent.*;
|
||||
@ -881,4 +882,21 @@ public class OpenRocketDocument implements ComponentChangeListener, StateChangeL
|
||||
public DocumentPreferences getDocumentPreferences() {
|
||||
return docPrefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all materials that are user-defined and document materials to the document material database.
|
||||
*/
|
||||
public void reloadDocumentMaterials() {
|
||||
for (RocketComponent c : getRocket()) {
|
||||
List<Material> materials = c.getAllMaterials();
|
||||
if (materials == null) {
|
||||
continue;
|
||||
}
|
||||
for (Material m : materials) {
|
||||
if (m.isUserDefined() && m.isDocumentMaterial()) {
|
||||
getDocumentPreferences().addMaterial(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -246,23 +246,6 @@ public class GeneralRocketLoader {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all materials that are user-defined and document materials to the document material database.
|
||||
*/
|
||||
private void loadMaterialsToDocument() {
|
||||
for (RocketComponent c : doc.getRocket()) {
|
||||
List<Material> materials = c.getAllMaterials();
|
||||
if (materials == null) {
|
||||
continue;
|
||||
}
|
||||
for (Material m : materials) {
|
||||
if (m.isUserDefined() && m.isDocumentMaterial()) {
|
||||
doc.getDocumentPreferences().addMaterial(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadUsing(RocketLoader loader, InputStream source, String fileName) throws RocketLoadException {
|
||||
warnings.clear();
|
||||
DocumentLoadingContext context = new DocumentLoadingContext();
|
||||
@ -273,6 +256,6 @@ public class GeneralRocketLoader {
|
||||
warnings.addAll(loader.getWarnings());
|
||||
|
||||
// Check for custom materials that need to be added to the document material database
|
||||
loadMaterialsToDocument();
|
||||
doc.reloadDocumentMaterials();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user