Fix component material not being updated after editing it in the preferences
This commit is contained in:
parent
370e6bffd7
commit
cee3cb04ae
@ -134,11 +134,11 @@ public abstract class Material implements Comparable<Material>, Groupable<Materi
|
||||
|
||||
|
||||
|
||||
private final String name;
|
||||
private final double density;
|
||||
private final boolean userDefined;
|
||||
private String name;
|
||||
private double density;
|
||||
private boolean userDefined;
|
||||
private boolean documentMaterial;
|
||||
private final MaterialGroup group;
|
||||
private MaterialGroup group;
|
||||
|
||||
|
||||
/**
|
||||
@ -307,6 +307,18 @@ public abstract class Material implements Comparable<Material>, Groupable<Materi
|
||||
return newMaterial(type, name, density, null, userDefined);
|
||||
}
|
||||
|
||||
public void loadFrom(Material m) {
|
||||
if (m == null)
|
||||
throw new IllegalArgumentException("Material is null");
|
||||
if (this.getClass() != m.getClass())
|
||||
throw new IllegalArgumentException("Material type mismatch");
|
||||
name = m.name;
|
||||
density = m.density;
|
||||
group = m.group;
|
||||
userDefined = m.userDefined;
|
||||
documentMaterial = m.documentMaterial;
|
||||
}
|
||||
|
||||
public String toStorableString() {
|
||||
return getType().name() + "|" + name.replace('|', ' ') + '|' + density + '|' + group.getDatabaseString();
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ matedtpan.but.ttip.delete = Delete a user-defined material
|
||||
matedtpan.but.ttip.revertall = Delete all user-defined materials
|
||||
matedtpan.title.Deletealluser-defined = Delete all user-defined materials?
|
||||
matedtpan.title.Revertall = Revert all?
|
||||
matedtpan.lbl.edtmaterials = Editing materials will not affect existing rocket designs.
|
||||
matedtpan.lbl.edtmaterials = <html>Editing application materials will not affect existing rocket designs.<br>Editing document materials <b>does</b> affect the rocket design using the material.</html>
|
||||
matedtpan.dlg.RemoveUsedMaterial.Application.title = Material used by component(s)
|
||||
matedtpan.dlg.RemoveUsedMaterial.Application.msg = <html>The material is currently used in the following designs and components:<br>%s<br>The material will be converted from an Application material to a Document material.</html>
|
||||
matedtpan.dlg.RemoveUsedMaterial.Document.title = Cannot remove material
|
||||
|
@ -184,7 +184,6 @@ public class MaterialEditPanel extends JPanel {
|
||||
return;
|
||||
sel = table.convertRowIndexToModel(sel);
|
||||
Material m = getMaterial(sel);
|
||||
boolean isDocumentMaterialPrior = m.isDocumentMaterial();
|
||||
|
||||
CustomMaterialDialog dialog;
|
||||
if (m.isUserDefined()) {
|
||||
@ -206,13 +205,36 @@ public class MaterialEditPanel extends JPanel {
|
||||
if (!dialog.getOkClicked()) {
|
||||
return;
|
||||
}
|
||||
// Remove the original material
|
||||
// Remove the original material from the database
|
||||
removeMaterial(m, false);
|
||||
|
||||
// Add the edited material
|
||||
// Get the edited material
|
||||
Material mat = dialog.getMaterial();
|
||||
mat.setDocumentMaterial(!dialog.isAddSelected());
|
||||
addMaterial(mat);
|
||||
|
||||
// Document materials can be edited no strings attached
|
||||
if (m.isDocumentMaterial()) {
|
||||
// Load the old material with the new values, so that we don't mess up the references in the components
|
||||
// that used the old component.
|
||||
m.loadFrom(mat);
|
||||
|
||||
// Add the "new" material to the database (this could be another database type as before, so we had to
|
||||
// first remove the old one and then re-add it)
|
||||
addMaterial(m);
|
||||
}
|
||||
// Editing application materials will not affect existing rocket designs
|
||||
else {
|
||||
// If the application material was already in use, add the old application material as a document material
|
||||
Map<OpenRocketDocument, List<RocketComponent>> components = getComponentsThatUseMaterial(m);
|
||||
if (!components.isEmpty()) {
|
||||
for (OpenRocketDocument doc: components.keySet()) {
|
||||
doc.getDocumentPreferences().addMaterial(m);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the new material to the database
|
||||
addMaterial(mat);
|
||||
}
|
||||
|
||||
model.fireTableDataChanged();
|
||||
setButtonStates();
|
||||
|
Loading…
x
Reference in New Issue
Block a user