From acc20ee772598b3707f4fab3e659b7fe8a3a2bed Mon Sep 17 00:00:00 2001 From: SiboVG Date: Tue, 21 Mar 2023 23:46:28 +0100 Subject: [PATCH 1/8] Small cleanups --- .../net/sf/openrocket/database/Databases.java | 2 +- .../sf/openrocket/preset/xml/MaterialDTO.java | 34 +++++++++---------- .../preset/xml/MaterialTypeDTO.java | 3 +- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/core/src/net/sf/openrocket/database/Databases.java b/core/src/net/sf/openrocket/database/Databases.java index a2e9fb744..339315795 100644 --- a/core/src/net/sf/openrocket/database/Databases.java +++ b/core/src/net/sf/openrocket/database/Databases.java @@ -222,7 +222,7 @@ public class Databases { * the provided name if unable to do so. * * @param type the material type. - * @param baseName the base name of the material. + * @param baseName the base name of the material. * @param density the density of the material. * @return the material object from the database or a new material. */ diff --git a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java index f7499ff9c..8eeea3d94 100644 --- a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java +++ b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java @@ -18,7 +18,7 @@ import net.sf.openrocket.util.Chars; @XmlRootElement(name = "Material") @XmlAccessorType(XmlAccessType.FIELD) public class MaterialDTO { - + @XmlElement(name = "Name") private String name; @XmlElement(name = "Density") @@ -27,65 +27,65 @@ public class MaterialDTO { private MaterialTypeDTO type; @XmlAttribute(name = "UnitsOfMeasure") private String uom; - + /** * Default constructor. */ public MaterialDTO() { } - + public MaterialDTO(final Material theMaterial) { this(theMaterial.getName(), theMaterial.getDensity(), MaterialTypeDTO.asDTO(theMaterial.getType()), theMaterial.getType().getUnitGroup().getDefaultUnit().toString()); } - + public MaterialDTO(final String theName, final double theDensity, final MaterialTypeDTO theType, final String theUom) { name = theName; density = theDensity; type = theType; uom = theUom; } - + public String getName() { return name; } - + public void setName(final String theName) { name = theName; } - + public double getDensity() { return density; } - + public void setDensity(final double theDensity) { density = theDensity; } - + public MaterialTypeDTO getType() { return type; } - + public void setType(final MaterialTypeDTO theType) { type = theType; } - + public String getUom() { return uom; } - + public void setUom(final String theUom) { uom = theUom; } - + Material asMaterial() { return Databases.findMaterial(type.getORMaterialType(), name, density); } - - + + /** * Special directive to the JAXB system. After the object is parsed from xml, - * we replace the '2' with Chars.SQUARED, and '3' with Chars.CUBED. Just the + * we replace the '2' with Chars.SQUARED, and '3' with Chars.CUBED. Just the * opposite transformation as done in beforeMarshal. * @param unmarshaller * @param parent @@ -97,7 +97,7 @@ public class MaterialDTO { uom = uom.replace('3', Chars.CUBED); } } - + /** * Special directive to the JAXB system. Before the object is serialized into xml, * we strip out the special unicode characters for cubed and squared so they appear diff --git a/core/src/net/sf/openrocket/preset/xml/MaterialTypeDTO.java b/core/src/net/sf/openrocket/preset/xml/MaterialTypeDTO.java index acc23d31f..8af0ab35c 100644 --- a/core/src/net/sf/openrocket/preset/xml/MaterialTypeDTO.java +++ b/core/src/net/sf/openrocket/preset/xml/MaterialTypeDTO.java @@ -20,8 +20,7 @@ public enum MaterialTypeDTO { public static MaterialTypeDTO asDTO(Material.Type targetType) { MaterialTypeDTO[] values = values(); - for (int i = 0; i < values.length; i++) { - MaterialTypeDTO value = values[i]; + for (MaterialTypeDTO value : values) { if (value.corollary.equals(targetType)) { return value; } From 16ee787f6658b6bd67f1a97db81f32c8d79533dd Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 22 Mar 2023 11:45:20 +0100 Subject: [PATCH 2/8] WIP --- core/src/net/sf/openrocket/preset/xml/MaterialDTO.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java index 8eeea3d94..6694dbb7d 100644 --- a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java +++ b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java @@ -44,6 +44,7 @@ public class MaterialDTO { density = theDensity; type = theType; uom = theUom; + type.getORMaterialType().getUnitGroup().setDefaultUnit(getUom()); } public String getName() { @@ -68,6 +69,7 @@ public class MaterialDTO { public void setType(final MaterialTypeDTO theType) { type = theType; + type.getORMaterialType().getUnitGroup().setDefaultUnit(getUom()); } public String getUom() { @@ -76,6 +78,7 @@ public class MaterialDTO { public void setUom(final String theUom) { uom = theUom; + type.getORMaterialType().getUnitGroup().setDefaultUnit(theUom); } Material asMaterial() { From 242345856f6b89a17534625681abd3f42df9e3c0 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 8 Apr 2023 00:24:28 +0200 Subject: [PATCH 3/8] Fix density in rail button database --- .../datafiles/components-openrocket/RailButton_Database.orc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swing/resources-src/datafiles/components-openrocket/RailButton_Database.orc b/swing/resources-src/datafiles/components-openrocket/RailButton_Database.orc index fcc33ea21..90fd9e0ba 100644 --- a/swing/resources-src/datafiles/components-openrocket/RailButton_Database.orc +++ b/swing/resources-src/datafiles/components-openrocket/RailButton_Database.orc @@ -6,13 +6,13 @@ - + Delrin 1420 BULK - + Nylon 1150 BULK From 731cd76ba06b092374e4fa0ef33a976ddd6effb1 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 8 Apr 2023 00:36:49 +0200 Subject: [PATCH 4/8] Add additional units in density units --- core/src/net/sf/openrocket/unit/UnitGroup.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/net/sf/openrocket/unit/UnitGroup.java b/core/src/net/sf/openrocket/unit/UnitGroup.java index c5e10cfdd..654410d70 100644 --- a/core/src/net/sf/openrocket/unit/UnitGroup.java +++ b/core/src/net/sf/openrocket/unit/UnitGroup.java @@ -212,6 +212,7 @@ public class UnitGroup { UNITS_DENSITY_BULK = new UnitGroup(); UNITS_DENSITY_BULK.addUnit(new GeneralUnit(1000, "g/cm" + CUBED)); + UNITS_DENSITY_BULK.addUnit(new GeneralUnit(1000999, "kg/cm" + CUBED)); UNITS_DENSITY_BULK.addUnit(new GeneralUnit(1000, "kg/dm" + CUBED)); UNITS_DENSITY_BULK.addUnit(new GeneralUnit(1, "kg/m" + CUBED)); UNITS_DENSITY_BULK.addUnit(new GeneralUnit(1729.99404, "oz/in" + CUBED)); @@ -220,13 +221,18 @@ public class UnitGroup { UNITS_DENSITY_SURFACE = new UnitGroup(); UNITS_DENSITY_SURFACE.addUnit(new GeneralUnit(10, "g/cm" + SQUARED)); UNITS_DENSITY_SURFACE.addUnit(new GeneralUnit(0.001, "g/m" + SQUARED)); + UNITS_DENSITY_SURFACE.addUnit(new GeneralUnit(10000, "kg/cm" + SQUARED)); + UNITS_DENSITY_SURFACE.addUnit(new GeneralUnit(100, "kg/dm" + SQUARED)); UNITS_DENSITY_SURFACE.addUnit(new GeneralUnit(1, "kg/m" + SQUARED)); UNITS_DENSITY_SURFACE.addUnit(new GeneralUnit(43.9418487, "oz/in" + SQUARED)); UNITS_DENSITY_SURFACE.addUnit(new GeneralUnit(0.305151727, "oz/ft" + SQUARED)); UNITS_DENSITY_SURFACE.addUnit(new GeneralUnit(4.88242764, "lb/ft" + SQUARED)); UNITS_DENSITY_LINE = new UnitGroup(); + UNITS_DENSITY_LINE.addUnit(new GeneralUnit(0.1, "g/cm")); UNITS_DENSITY_LINE.addUnit(new GeneralUnit(0.001, "g/m")); + UNITS_DENSITY_LINE.addUnit(new GeneralUnit(100, "kg/cm")); + UNITS_DENSITY_LINE.addUnit(new GeneralUnit(10, "kg/dm")); UNITS_DENSITY_LINE.addUnit(new GeneralUnit(1, "kg/m")); UNITS_DENSITY_LINE.addUnit(new GeneralUnit(0.0930102465, "oz/ft")); @@ -428,7 +434,7 @@ public class UnitGroup { UNITS_ANGLE.setDefaultUnit(0); UNITS_DENSITY_BULK.setDefaultUnit(0); UNITS_DENSITY_SURFACE.setDefaultUnit(1); - UNITS_DENSITY_LINE.setDefaultUnit(0); + UNITS_DENSITY_LINE.setDefaultUnit(1); UNITS_FORCE.setDefaultUnit(0); UNITS_IMPULSE.setDefaultUnit(0); UNITS_TIME_STEP.setDefaultUnit(1); From e47d6481b26e0dfff28ada029b9d4b665a8e313d Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 10 Apr 2023 23:44:12 +0200 Subject: [PATCH 5/8] [#2083] Account for uom in material database loader --- core/src/net/sf/openrocket/preset/xml/MaterialDTO.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java index 6694dbb7d..7ce9c468d 100644 --- a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java +++ b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java @@ -10,6 +10,7 @@ import javax.xml.bind.annotation.XmlRootElement; import net.sf.openrocket.database.Databases; import net.sf.openrocket.material.Material; +import net.sf.openrocket.unit.Unit; import net.sf.openrocket.util.Chars; /** @@ -98,6 +99,13 @@ public class MaterialDTO { if (uom != null) { uom = uom.replace('2', Chars.SQUARED); uom = uom.replace('3', Chars.CUBED); + if (type != null) { + // The density value is stored in the XML file in the units of measure, but OR expects the density to be + // in SI units, so we need to convert it to SI units + Unit uomUnit = type.getORMaterialType().getUnitGroup().getUnit(getUom()); + density = uomUnit.fromUnit(density); + //type.getORMaterialType().getUnitGroup().setDefaultUnit(uomUnit); + } } } From dab6ec3642544020fcc03eb04ddde097078d24a8 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 10 Apr 2023 23:46:32 +0200 Subject: [PATCH 6/8] Update dbcook database --- swing/resources-src/datafiles/components-dbcook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swing/resources-src/datafiles/components-dbcook b/swing/resources-src/datafiles/components-dbcook index 1aa03bb4a..827509c8e 160000 --- a/swing/resources-src/datafiles/components-dbcook +++ b/swing/resources-src/datafiles/components-dbcook @@ -1 +1 @@ -Subproject commit 1aa03bb4a44a145f459939f487159a202dbf0f9f +Subproject commit 827509c8eaa27e456095ffe57009c53aa6ee4f28 From b57ad3d39393c592073c623df9a7896b8a2c8445 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 10 Apr 2023 23:52:47 +0200 Subject: [PATCH 7/8] Undo WIP --- core/src/net/sf/openrocket/preset/xml/MaterialDTO.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java index 7ce9c468d..745dd8acb 100644 --- a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java +++ b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java @@ -45,7 +45,6 @@ public class MaterialDTO { density = theDensity; type = theType; uom = theUom; - type.getORMaterialType().getUnitGroup().setDefaultUnit(getUom()); } public String getName() { @@ -70,7 +69,6 @@ public class MaterialDTO { public void setType(final MaterialTypeDTO theType) { type = theType; - type.getORMaterialType().getUnitGroup().setDefaultUnit(getUom()); } public String getUom() { @@ -79,7 +77,6 @@ public class MaterialDTO { public void setUom(final String theUom) { uom = theUom; - type.getORMaterialType().getUnitGroup().setDefaultUnit(theUom); } Material asMaterial() { @@ -104,7 +101,6 @@ public class MaterialDTO { // in SI units, so we need to convert it to SI units Unit uomUnit = type.getORMaterialType().getUnitGroup().getUnit(getUom()); density = uomUnit.fromUnit(density); - //type.getORMaterialType().getUnitGroup().setDefaultUnit(uomUnit); } } } From 09a586374e264b975ea30bd2c943d36d58a61969 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 13 Apr 2023 10:09:18 +0200 Subject: [PATCH 8/8] Update component database --- swing/resources-src/datafiles/components-dbcook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swing/resources-src/datafiles/components-dbcook b/swing/resources-src/datafiles/components-dbcook index 827509c8e..9da5f4e25 160000 --- a/swing/resources-src/datafiles/components-dbcook +++ b/swing/resources-src/datafiles/components-dbcook @@ -1 +1 @@ -Subproject commit 827509c8eaa27e456095ffe57009c53aa6ee4f28 +Subproject commit 9da5f4e25f57e8ec476ea38cd91c78edff06003f