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 String name;
|
||||||
private final double density;
|
private double density;
|
||||||
private final boolean userDefined;
|
private boolean userDefined;
|
||||||
private boolean documentMaterial;
|
private boolean documentMaterial;
|
||||||
private final MaterialGroup group;
|
private MaterialGroup group;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -306,11 +306,23 @@ public abstract class Material implements Comparable<Material>, Groupable<Materi
|
|||||||
public static Material newMaterial(Type type, String name, double density, boolean userDefined) {
|
public static Material newMaterial(Type type, String name, double density, boolean userDefined) {
|
||||||
return newMaterial(type, name, density, null, userDefined);
|
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() {
|
public String toStorableString() {
|
||||||
return getType().name() + "|" + name.replace('|', ' ') + '|' + density + '|' + group.getDatabaseString();
|
return getType().name() + "|" + name.replace('|', ' ') + '|' + density + '|' + group.getDatabaseString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a material defined by the provided string.
|
* Return a material defined by the provided string.
|
||||||
|
@ -277,7 +277,7 @@ matedtpan.but.ttip.delete = Delete a user-defined material
|
|||||||
matedtpan.but.ttip.revertall = Delete all user-defined materials
|
matedtpan.but.ttip.revertall = Delete all user-defined materials
|
||||||
matedtpan.title.Deletealluser-defined = Delete all user-defined materials?
|
matedtpan.title.Deletealluser-defined = Delete all user-defined materials?
|
||||||
matedtpan.title.Revertall = Revert all?
|
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.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.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
|
matedtpan.dlg.RemoveUsedMaterial.Document.title = Cannot remove material
|
||||||
|
@ -184,8 +184,7 @@ public class MaterialEditPanel extends JPanel {
|
|||||||
return;
|
return;
|
||||||
sel = table.convertRowIndexToModel(sel);
|
sel = table.convertRowIndexToModel(sel);
|
||||||
Material m = getMaterial(sel);
|
Material m = getMaterial(sel);
|
||||||
boolean isDocumentMaterialPrior = m.isDocumentMaterial();
|
|
||||||
|
|
||||||
CustomMaterialDialog dialog;
|
CustomMaterialDialog dialog;
|
||||||
if (m.isUserDefined()) {
|
if (m.isUserDefined()) {
|
||||||
dialog = new CustomMaterialDialog(
|
dialog = new CustomMaterialDialog(
|
||||||
@ -206,13 +205,36 @@ public class MaterialEditPanel extends JPanel {
|
|||||||
if (!dialog.getOkClicked()) {
|
if (!dialog.getOkClicked()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Remove the original material
|
// Remove the original material from the database
|
||||||
removeMaterial(m, false);
|
removeMaterial(m, false);
|
||||||
|
|
||||||
// Add the edited material
|
// Get the edited material
|
||||||
Material mat = dialog.getMaterial();
|
Material mat = dialog.getMaterial();
|
||||||
mat.setDocumentMaterial(!dialog.isAddSelected());
|
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();
|
model.fireTableDataChanged();
|
||||||
setButtonStates();
|
setButtonStates();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user