From ff8b5f95a1b3025b288bde304045a16faa474eb8 Mon Sep 17 00:00:00 2001 From: plaa Date: Sat, 25 Aug 2012 20:10:58 +0000 Subject: [PATCH] Material localization support git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@1001 180e2498-e6e9-4542-8430-84ac67f01cd8 --- core/resources/l10n/messages.properties | 90 +- core/resources/l10n/messages_cs.properties | 90 +- core/resources/l10n/messages_de.properties | 90 +- core/resources/l10n/messages_es.properties | 90 +- core/resources/l10n/messages_fr.properties | 90 +- core/resources/l10n/messages_it.properties | 90 +- core/resources/l10n/messages_pl.properties | 90 +- core/resources/l10n/messages_ru.properties | 90 +- core/resources/l10n/rename.sh | 16 + .../net/sf/openrocket/database/Databases.java | 206 ++--- .../openrocket/importt/OpenRocketLoader.java | 846 +++++++++--------- .../savers/RocketComponentSaver.java | 81 +- .../file/rocksim/importt/BaseHandler.java | 539 ++++++----- .../gui/dialogs/CustomMaterialDialog.java | 92 +- .../openrocket/gui/util/SwingPreferences.java | 84 +- .../openrocket/l10n/ClassBasedTranslator.java | 24 +- .../sf/openrocket/l10n/DebugTranslator.java | 20 +- .../l10n/ExceptionSuppressingTranslator.java | 17 +- core/src/net/sf/openrocket/l10n/L10N.java | 26 + .../l10n/ResourceBundleTranslator.java | 26 + .../net/sf/openrocket/l10n/Translator.java | 29 + .../net/sf/openrocket/material/Material.java | 140 +-- .../preset/ComponentPresetFactory.java | 241 ++--- .../loader/LineMaterialColumnParser.java | 21 +- .../preset/loader/MaterialColumnParser.java | 17 +- .../preset/loader/MaterialHolder.java | 96 +- .../preset/loader/MaterialLoader.java | 57 +- .../loader/SurfaceMaterialColumnParser.java | 19 +- .../preset/xml/BaseComponentDTO.java | 253 +++--- .../sf/openrocket/preset/xml/MaterialDTO.java | 188 ++-- .../sf/openrocket/startup/Preferences.java | 96 +- .../net/sf/openrocket/util/TestRockets.java | 91 +- .../openrocket/l10n/TestDebugTranslator.java | 24 + .../test/net/sf/openrocket/l10n/TestL10N.java | 30 + .../l10n/TestResourceBundleTranslator.java | 41 +- .../preset/BodyTubeComponentTests.java | 84 +- .../preset/BodyTubePresetTests.java | 268 +++--- .../preset/BulkHeadComponentTests.java | 57 +- .../preset/BulkHeadPresetTests.java | 158 ++-- .../preset/CenteringRingComponentTests.java | 67 +- .../preset/CenteringRingPresetTests.java | 268 +++--- .../preset/EngineBlockComponentTests.java | 67 +- .../preset/EngineBlockPresetTests.java | 258 +++--- .../preset/LaunchLugComponentTests.java | 70 +- .../preset/LaunchLugPresetTests.java | 258 +++--- .../preset/NoseConeComponentTests.java | 118 +-- .../preset/NoseConePresetTests.java | 212 ++--- .../preset/ParachuterComponentTests.java | 78 +- .../preset/StreamerComponentTests.java | 52 +- .../preset/TransitionComponentTests.java | 148 ++- .../preset/TransitionPresetTests.java | 242 ++--- .../preset/TubeCouplerComponentTests.java | 64 +- .../preset/TubeCouplerPresetTests.java | 258 +++--- .../rocketcomponent/FinSetTest.java | 14 +- .../SymmetricComponentVolumeTest.java | 330 +++---- 55 files changed, 3637 insertions(+), 3474 deletions(-) create mode 100755 core/resources/l10n/rename.sh create mode 100644 core/test/net/sf/openrocket/l10n/TestDebugTranslator.java create mode 100644 core/test/net/sf/openrocket/l10n/TestL10N.java diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 7ade8093..88f2c019 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1126,53 +1126,53 @@ Databases.materials.types.Line = Line Databases.materials.types.Surface = Surface ! BULK_MATERIAL -Databases.materials.Acrylic = Acrylic -Databases.materials.Aluminum = Aluminum -Databases.materials.Balsa = Balsa -Databases.materials.Basswood = Basswood -Databases.materials.Birch = Birch -Databases.materials.Brass = Brass -Databases.materials.Cardboard = Cardboard -Databases.materials.Carbonfiber = Carbon fiber -Databases.materials.Cork = Cork -Databases.materials.DepronXPS = Depron (XPS) -Databases.materials.Fiberglass = Fiberglass -Databases.materials.Kraftphenolic = Kraft phenolic -Databases.materials.Maple = Maple -Databases.materials.Paperoffice = Paper (office) -Databases.materials.Pine = Pine -Databases.materials.Plywoodbirch = Plywood (birch) -Databases.materials.PolycarbonateLexan = Polycarbonate (Lexan) -Databases.materials.Polystyrene = Polystyrene -Databases.materials.PVC = PVC -Databases.materials.Spruce = Spruce -Databases.materials.Steel = Steel -Databases.materials.StyrofoamgenericEPS = Styrofoam (generic EPS) -Databases.materials.StyrofoamBluefoamXPS = Styrofoam \"Blue foam\" (XPS) -Databases.materials.Titanium = Titanium -Databases.materials.Quantumtubing = Quantum tubing -Databases.materials.BlueTube = Blue tube +material.acrylic = Acrylic +material.aluminum = Aluminum +material.balsa = Balsa +material.basswood = Basswood +material.birch = Birch +material.brass = Brass +material.cardboard = Cardboard +material.carbon_fiber = Carbon fiber +material.cork = Cork +material.depron_xps = Depron (XPS) +material.fiberglass = Fiberglass +material.kraft_phenolic = Kraft phenolic +material.maple = Maple +material.paper_office = Paper (office) +material.pine = Pine +material.plywood_birch = Plywood (birch) +material.polycarbonate_lexan = Polycarbonate (Lexan) +material.polystyrene = Polystyrene +material.pvc = PVC +material.spruce = Spruce +material.steel = Steel +material.styrofoam_generic_eps = Styrofoam (generic EPS) +material.styrofoam_blue_foam_xps = Styrofoam \"Blue foam\" (XPS) +material.titanium = Titanium +material.quantum_tubing = Quantum tubing +material.blue_tube = Blue tube !SURFACE_MATERIAL -Databases.materials.Ripstopnylon = Ripstop nylon -Databases.materials.Mylar = Mylar -Databases.materials.Polyethylenethin = Polyethylene (thin) -Databases.materials.Polyethyleneheavy = Polyethylene (heavy) -Databases.materials.Silk = Silk -Databases.materials.Paperoffice = Paper (office) -Databases.materials.Cellophane = Cellophane -Databases.materials.Crepepaper = Cr\u00eape paper +material.ripstop_nylon = Ripstop nylon +material.mylar = Mylar +material.polyethylene_thin = Polyethylene (thin) +material.polyethylene_heavy = Polyethylene (heavy) +material.silk = Silk +material.paper_office = Paper (office) +material.cellophane = Cellophane +material.crepe_paper = Cr\u00eape paper ! LINE_MATERIAL -Databases.materials.Threadheavy-duty = Thread (heavy-duty) -Databases.materials.Elasticcordround2mm = Elastic cord (round 2mm, 1/16 in) -Databases.materials.Elasticcordflat6mm = Elastic cord (flat 6mm, 1/4 in) -Databases.materials.Elasticcordflat12mm = Elastic cord (flat 12mm, 1/2 in) -Databases.materials.Elasticcordflat19mm = Elastic cord (flat 19mm, 3/4 in) -Databases.materials.Elasticcordflat25mm = Elastic cord (flat 25mm, 1 in) -Databases.materials.Braidednylon2mm = Braided nylon (2 mm, 1/16 in) -Databases.materials.Braidednylon3mm = Braided nylon (3 mm, 1/8 in) -Databases.materials.Tubularnylon11mm = Tubular nylon (11 mm, 7/16 in) -Databases.materials.Tubularnylon14mm = Tubular nylon (14 mm, 9/16 in) -Databases.materials.Tubularnylon25mm = Tubular nylon (25 mm, 1 in) +material.thread_heavy_duty = Thread (heavy-duty) +material.elastic_cord_round_2_mm_1_16_in = Elastic cord (round 2 mm, 1/16 in) +material.elastic_cord_flat_6_mm_1_4_in = Elastic cord (flat 6 mm, 1/4 in) +material.elastic_cord_flat_12_mm_1_2_in = Elastic cord (flat 12 mm, 1/2 in) +material.elastic_cord_flat_19_mm_3_4_in = Elastic cord (flat 19 mm, 3/4 in) +material.elastic_cord_flat_25_mm_1_in = Elastic cord (flat 25 mm, 1 in) +material.braided_nylon_2_mm_1_16_in = Braided nylon (2 mm, 1/16 in) +material.braided_nylon_3_mm_1_8_in = Braided nylon (3 mm, 1/8 in) +material.tubular_nylon_11_mm_7_16_in = Tubular nylon (11 mm, 7/16 in) +material.tubular_nylon_14_mm_9_16_in = Tubular nylon (14 mm, 9/16 in) +material.tubular_nylon_25_mm_1_in = Tubular nylon (25 mm, 1 in) ! ExternalComponent ExternalComponent.Rough = Rough diff --git a/core/resources/l10n/messages_cs.properties b/core/resources/l10n/messages_cs.properties index 587fa86b..c8a913db 100644 --- a/core/resources/l10n/messages_cs.properties +++ b/core/resources/l10n/messages_cs.properties @@ -1033,53 +1033,53 @@ main.menu.debug.createtestrocket = Udelej test rakety ! Material database ! BULK_MATERIAL -Databases.materials.Acrylic = Akryl -Databases.materials.Aluminum = Hliník -Databases.materials.Balsa = Balza -Databases.materials.Basswood = Lípa -Databases.materials.Birch = Bríza -Databases.materials.Brass = Mosaz -Databases.materials.Cardboard = Kartón -Databases.materials.Carbonfiber = Vystu\u017Eený kartón -Databases.materials.Cork = Korek -Databases.materials.DepronXPS = Depron (XPS) -Databases.materials.Fiberglass = Skelné vlákno -Databases.materials.Kraftphenolic = Kraft phenolic -Databases.materials.Maple = Javor -Databases.materials.Paperoffice = Papír (kancelárský) -Databases.materials.Pine = Borovice -Databases.materials.Plywoodbirch = Prekli\u017Eka (briza) -Databases.materials.PolycarbonateLexan = Polykarbonát (Lexan) -Databases.materials.Polystyrene = Polystyrén -Databases.materials.PVC = PVC -Databases.materials.Spruce = Smrk -Databases.materials.Steel = Ocel -Databases.materials.StyrofoamgenericEPS = Styrofoam (obecný EPS) -Databases.materials.StyrofoamBluefoamXPS = Styrofoam \"modrá pena\" (XPS) -Databases.materials.Titanium = Titan -Databases.materials.Quantumtubing = Quantum tubing -Databases.materials.BlueTube = Blue tube +material.acrylic = Akryl +material.aluminum = Hliník +material.balsa = Balza +material.basswood = Lípa +material.birch = Bríza +material.brass = Mosaz +material.cardboard = Kartón +material.carbon_fiber = Vystu\u017Eený kartón +material.cork = Korek +material.depron_xps = Depron (XPS) +material.fiberglass = Skelné vlákno +material.kraft_phenolic = Kraft phenolic +material.maple = Javor +material.paper_office = Papír (kancelárský) +material.pine = Borovice +material.plywood_birch = Prekli\u017Eka (briza) +material.polycarbonate_lexan = Polykarbonát (Lexan) +material.polystyrene = Polystyrén +material.pvc = PVC +material.spruce = Smrk +material.steel = Ocel +material.styrofoam_generic_eps = Styrofoam (obecný EPS) +material.styrofoam_blue_foam_xps = Styrofoam \"modrá pena\" (XPS) +material.titanium = Titan +material.quantum_tubing = Quantum tubing +material.blue_tube = Blue tube !SURFACE_MATERIAL -Databases.materials.Ripstopnylon = Ripstoponový nylon -Databases.materials.Mylar = Mylar -Databases.materials.Polyethylenethin = Polyethylén (tenký) -Databases.materials.Polyethyleneheavy = Polyethylén (te\u017Eký) -Databases.materials.Silk = Hedvábí -Databases.materials.Paperoffice = Papír (kancelárský) -Databases.materials.Cellophane = Celofán -Databases.materials.Crepepaper = Celulární papír +material.ripstop_nylon = Ripstoponový nylon +material.mylar = Mylar +material.polyethylene_thin = Polyethylén (tenký) +material.polyethylene_heavy = Polyethylén (te\u017Eký) +material.silk = Hedvábí +material.paper_office = Papír (kancelárský) +material.cellophane = Celofán +material.crepe_paper = Celulární papír ! LINE_MATERIAL -Databases.materials.Threadheavy-duty = Vlákno (vysoce odolné) -Databases.materials.Elasticcordround2mm = Elastická \u0161nura (round 2mm, 1/16 in) -Databases.materials.Elasticcordflat6mm = Elastická \u0161nura (flat 6mm, 1/4 in) -Databases.materials.Elasticcordflat12mm = Elastická \u0161nura (flat 12mm, 1/2 in) -Databases.materials.Elasticcordflat19mm = Elastická \u0161nura (flat 19mm, 3/4 in) -Databases.materials.Elasticcordflat25mm = Elastická \u0161nura (flat 25mm, 1 in) -Databases.materials.Braidednylon2mm = Spletený nylon (2 mm, 1/16 in) -Databases.materials.Braidednylon3mm = Spletený nylon (3 mm, 1/8 in) -Databases.materials.Tubularnylon11mm = Trubkovitý nylon (11 mm, 7/16 in) -Databases.materials.Tubularnylon14mm = Trubkovitý nylon (14 mm, 9/16 in) -Databases.materials.Tubularnylon25mm = Trubkovitý nylon (25 mm, 1 in) +material.thread_heavy_duty = Vlákno (vysoce odolné) +material.elastic_cord_round_2_mm_1_16_in = Elastická \u0161nura (round 2mm, 1/16 in) +material.elastic_cord_flat_6_mm_1_4_in = Elastická \u0161nura (flat 6mm, 1/4 in) +material.elastic_cord_flat_12_mm_1_2_in = Elastická \u0161nura (flat 12mm, 1/2 in) +material.elastic_cord_flat_19_mm_3_4_in = Elastická \u0161nura (flat 19mm, 3/4 in) +material.elastic_cord_flat_25_mm_1_in = Elastická \u0161nura (flat 25mm, 1 in) +material.braided_nylon_2_mm_1_16_in = Spletený nylon (2 mm, 1/16 in) +material.braided_nylon_3_mm_1_8_in = Spletený nylon (3 mm, 1/8 in) +material.tubular_nylon_11_mm_7_16_in = Trubkovitý nylon (11 mm, 7/16 in) +material.tubular_nylon_14_mm_9_16_in = Trubkovitý nylon (14 mm, 9/16 in) +material.tubular_nylon_25_mm_1_in = Trubkovitý nylon (25 mm, 1 in) ! ExternalComponent ExternalComponent.Rough = drsný diff --git a/core/resources/l10n/messages_de.properties b/core/resources/l10n/messages_de.properties index ad6c5649..38133ab9 100644 --- a/core/resources/l10n/messages_de.properties +++ b/core/resources/l10n/messages_de.properties @@ -1090,53 +1090,53 @@ main.menu.debug.createtestrocket = Eine Testrakete erstellen ! Material database ! BULK_MATERIAL -Databases.materials.Acrylic = Acryl -Databases.materials.Aluminum = Aluminum -Databases.materials.Balsa = Balsa -Databases.materials.Basswood = Linde -Databases.materials.Birch = Birke -Databases.materials.Brass = Messing -Databases.materials.Cardboard = Karton -Databases.materials.Carbonfiber = Kohlefaser -Databases.materials.Cork = Kork -Databases.materials.DepronXPS = Depron (XPS) -Databases.materials.Fiberglass = Glasfaser -Databases.materials.Kraftphenolic = Pertinax -Databases.materials.Maple = Ahorn -Databases.materials.Paperoffice = Papier (Büro) -Databases.materials.Pine = Kiefer -Databases.materials.Plywoodbirch = Sperrholz (Birke) -Databases.materials.PolycarbonateLexan = Polycarbonat (Lexan) -Databases.materials.Polystyrene = Polystyrène -Databases.materials.PVC = PVC -Databases.materials.Spruce = Fichte -Databases.materials.Steel = Stahl -Databases.materials.StyrofoamgenericEPS = Styropor (EPS) -Databases.materials.StyrofoamBluefoamXPS = Styrodur (XPS) -Databases.materials.Titanium = Titan -Databases.materials.Quantumtubing = Quantum-Röhren -Databases.materials.BlueTube = 'Blue tube'-Röhren +material.acrylic = Acryl +material.aluminum = Aluminum +material.balsa = Balsa +material.basswood = Linde +material.birch = Birke +material.brass = Messing +material.cardboard = Karton +material.carbon_fiber = Kohlefaser +material.cork = Kork +material.depron_xps = Depron (XPS) +material.fiberglass = Glasfaser +material.kraft_phenolic = Pertinax +material.maple = Ahorn +material.paper_office = Papier (Büro) +material.pine = Kiefer +material.plywood_birch = Sperrholz (Birke) +material.polycarbonate_lexan = Polycarbonat (Lexan) +material.polystyrene = Polystyrène +material.pvc = PVC +material.spruce = Fichte +material.steel = Stahl +material.styrofoam_generic_eps = Styropor (EPS) +material.styrofoam_blue_foam_xps = Styrodur (XPS) +material.titanium = Titan +material.quantum_tubing = Quantum-Röhren +material.blue_tube = 'Blue tube'-Röhren !SURFACE_MATERIAL -Databases.materials.Ripstopnylon = Ripstop Nylon -Databases.materials.Mylar = Mylar -Databases.materials.Polyethylenethin = Polyethylen (dünn) -Databases.materials.Polyethyleneheavy = Polyethylen (schwer) -Databases.materials.Silk = Seide -Databases.materials.Paperoffice = Papier (Büro) -Databases.materials.Cellophane = Zellophan -Databases.materials.Crepepaper = Krepppapier +material.ripstop_nylon = Ripstop Nylon +material.mylar = Mylar +material.polyethylene_thin = Polyethylen (dünn) +material.polyethylene_heavy = Polyethylen (schwer) +material.silk = Seide +material.paper_office = Papier (Büro) +material.cellophane = Zellophan +material.crepe_paper = Krepppapier ! LINE_MATERIAL -Databases.materials.Threadheavy-duty = Faden (stark) -Databases.materials.Elasticcordround2mm = Elastikband (rund, 2mm, 1/16 in) -Databases.materials.Elasticcordflat6mm = Elastikband (flach, 6mm, 1/4 in) -Databases.materials.Elasticcordflat12mm = Elastikband (flach, 12mm, 1/2 in) -Databases.materials.Elasticcordflat19mm = Elastikband (flach, 19mm, 3/4 in) -Databases.materials.Elasticcordflat25mm = Elastikband (flach, 25mm, 1 in) -Databases.materials.Braidednylon2mm = Nylonflachband (2 mm, 1/16 in) -Databases.materials.Braidednylon3mm = Nylonflachband (3 mm, 1/8 in) -Databases.materials.Tubularnylon11mm = Tubular Nylon (11 mm, 7/16 in) -Databases.materials.Tubularnylon14mm = Tubular Nylon (14 mm, 9/16 in) -Databases.materials.Tubularnylon25mm = Tubular Nylon (25 mm, 1 in) +material.thread_heavy_duty = Faden (stark) +material.elastic_cord_round_2_mm_1_16_in = Elastikband (rund, 2mm, 1/16 in) +material.elastic_cord_flat_6_mm_1_4_in = Elastikband (flach, 6mm, 1/4 in) +material.elastic_cord_flat_12_mm_1_2_in = Elastikband (flach, 12mm, 1/2 in) +material.elastic_cord_flat_19_mm_3_4_in = Elastikband (flach, 19mm, 3/4 in) +material.elastic_cord_flat_25_mm_1_in = Elastikband (flach, 25mm, 1 in) +material.braided_nylon_2_mm_1_16_in = Nylonflachband (2 mm, 1/16 in) +material.braided_nylon_3_mm_1_8_in = Nylonflachband (3 mm, 1/8 in) +material.tubular_nylon_11_mm_7_16_in = Tubular Nylon (11 mm, 7/16 in) +material.tubular_nylon_14_mm_9_16_in = Tubular Nylon (14 mm, 9/16 in) +material.tubular_nylon_25_mm_1_in = Tubular Nylon (25 mm, 1 in) ! ExternalComponent ExternalComponent.Rough = Rau diff --git a/core/resources/l10n/messages_es.properties b/core/resources/l10n/messages_es.properties index 7e4d0aaa..36ea24e5 100644 --- a/core/resources/l10n/messages_es.properties +++ b/core/resources/l10n/messages_es.properties @@ -1101,53 +1101,53 @@ main.menu.debug.createtestrocket = Crear una prueba de modelo ! Material database ! BULK_MATERIAL -Databases.materials.Acrylic = Acrílico -Databases.materials.Aluminum = Aluminio -Databases.materials.Balsa = Balsa -Databases.materials.Basswood = Tilo -Databases.materials.Birch = Abedul -Databases.materials.Brass = Latón -Databases.materials.Cardboard = Cartón -Databases.materials.Carbonfiber = Fibra de Carbono -Databases.materials.Cork = Corcho -Databases.materials.DepronXPS = Depron (XPS) -Databases.materials.Fiberglass = Fibra de vidrio -Databases.materials.Kraftphenolic = Cartón fenólico -Databases.materials.Maple = Arce -Databases.materials.Paperoffice = Papel (oficina) -Databases.materials.Pine = Pino -Databases.materials.Plywoodbirch = Contrachapado -Databases.materials.PolycarbonateLexan = Policarbonato (Lexan) -Databases.materials.Polystyrene = Poliestireno -Databases.materials.PVC = PVC -Databases.materials.Spruce = Pícea (Abeto común) -Databases.materials.Steel = Acero -Databases.materials.StyrofoamgenericEPS = Porex (generico EPS) -Databases.materials.StyrofoamBluefoamXPS = Porex \"Foam azul\" (XPS) -Databases.materials.Titanium = Titanio -Databases.materials.Quantumtubing = Quantum tubing -Databases.materials.BlueTube = Tubo azul (PML) +material.acrylic = Acrílico +material.aluminum = Aluminio +material.balsa = Balsa +material.basswood = Tilo +material.birch = Abedul +material.brass = Latón +material.cardboard = Cartón +material.carbon_fiber = Fibra de Carbono +material.cork = Corcho +material.depron_xps = Depron (XPS) +material.fiberglass = Fibra de vidrio +material.kraft_phenolic = Cartón fenólico +material.maple = Arce +material.paper_office = Papel (oficina) +material.pine = Pino +material.plywood_birch = Contrachapado +material.polycarbonate_lexan = Policarbonato (Lexan) +material.polystyrene = Poliestireno +material.pvc = PVC +material.spruce = Pícea (Abeto común) +material.steel = Acero +material.styrofoam_generic_eps = Porex (generico EPS) +material.styrofoam_blue_foam_xps = Porex \"Foam azul\" (XPS) +material.titanium = Titanio +material.quantum_tubing = Quantum tubing +material.blue_tube = Tubo azul (PML) !SURFACE_MATERIAL -Databases.materials.Ripstopnylon = Ripstop nylon -Databases.materials.Mylar = Mylar -Databases.materials.Polyethylenethin = Polietileno (delgado) -Databases.materials.Polyethyleneheavy = Polietileno (grueso) -Databases.materials.Silk = Seda -Databases.materials.Paperoffice = Papel (oficina) -Databases.materials.Cellophane = Celofán -Databases.materials.Crepepaper = Crespón de papel +material.ripstop_nylon = Ripstop nylon +material.mylar = Mylar +material.polyethylene_thin = Polietileno (delgado) +material.polyethylene_heavy = Polietileno (grueso) +material.silk = Seda +material.paper_office = Papel (oficina) +material.cellophane = Celofán +material.crepe_paper = Crespón de papel ! LINE_MATERIAL -Databases.materials.Threadheavy-duty = Trenzado (Alta resistencia) -Databases.materials.Elasticcordround2mm = Cordón elástico (aprox. 2mm, 1/16 in) -Databases.materials.Elasticcordflat6mm = Cordón elástico plano (6mm, 1/4 in) -Databases.materials.Elasticcordflat12mm = Cordón elástico plano (12mm, 1/2 in) -Databases.materials.Elasticcordflat19mm = Cordón elástico plano (19mm, 3/4 in) -Databases.materials.Elasticcordflat25mm = Cordón elástico plano (25mm, 1 in) -Databases.materials.Braidednylon2mm = Nylon trenzado (2 mm, 1/16 in) -Databases.materials.Braidednylon3mm = Nylon trenzado (3 mm, 1/8 in) -Databases.materials.Tubularnylon11mm = Nylon tubular (11 mm, 7/16 in) -Databases.materials.Tubularnylon14mm = Nylon tubular (14 mm, 9/16 in) -Databases.materials.Tubularnylon25mm = Nylon tubular (25 mm, 1 in) +material.thread_heavy_duty = Trenzado (Alta resistencia) +material.elastic_cord_round_2_mm_1_16_in = Cordón elástico (aprox. 2mm, 1/16 in) +material.elastic_cord_flat_6_mm_1_4_in = Cordón elástico plano (6mm, 1/4 in) +material.elastic_cord_flat_12_mm_1_2_in = Cordón elástico plano (12mm, 1/2 in) +material.elastic_cord_flat_19_mm_3_4_in = Cordón elástico plano (19mm, 3/4 in) +material.elastic_cord_flat_25_mm_1_in = Cordón elástico plano (25mm, 1 in) +material.braided_nylon_2_mm_1_16_in = Nylon trenzado (2 mm, 1/16 in) +material.braided_nylon_3_mm_1_8_in = Nylon trenzado (3 mm, 1/8 in) +material.tubular_nylon_11_mm_7_16_in = Nylon tubular (11 mm, 7/16 in) +material.tubular_nylon_14_mm_9_16_in = Nylon tubular (14 mm, 9/16 in) +material.tubular_nylon_25_mm_1_in = Nylon tubular (25 mm, 1 in) ! ExternalComponent ExternalComponent.Rough = Rugoso diff --git a/core/resources/l10n/messages_fr.properties b/core/resources/l10n/messages_fr.properties index fc8f00ff..a4b68a85 100644 --- a/core/resources/l10n/messages_fr.properties +++ b/core/resources/l10n/messages_fr.properties @@ -1122,53 +1122,53 @@ Databases.materials.types.Line = Ligne Databases.materials.types.Surface = Surface ! BULK_MATERIAL -Databases.materials.Acrylic = Acrylique -Databases.materials.Aluminum = Aluminum -Databases.materials.Balsa = Balsa -Databases.materials.Basswood = Tilleul -Databases.materials.Birch = Bouleau -Databases.materials.Brass = Laiton -Databases.materials.Cardboard = Carton -Databases.materials.Carbonfiber = Fibre de carbone -Databases.materials.Cork = Liège -Databases.materials.DepronXPS = Depron (XPS) -Databases.materials.Fiberglass = Fibre de verre -Databases.materials.Kraftphenolic = Kraft phénolique -Databases.materials.Maple = Érable -Databases.materials.Paperoffice = Papier (bureau) -Databases.materials.Pine = Pin -Databases.materials.Plywoodbirch = Contre-plaqué (bouleau) -Databases.materials.PolycarbonateLexan = Polycarbonate (Lexan) -Databases.materials.Polystyrene = Polystyrène -Databases.materials.PVC = PVC -Databases.materials.Spruce = Sapin -Databases.materials.Steel = Acier -Databases.materials.StyrofoamgenericEPS = Polystyrène (générique EPS) -Databases.materials.StyrofoamBluefoamXPS = \"Mousse Bleue\" de polystyrène (XPS) -Databases.materials.Titanium = Titane -Databases.materials.Quantumtubing = Tube Quantum -Databases.materials.BlueTube = Blue tube +material.acrylic = Acrylique +material.aluminum = Aluminum +material.balsa = Balsa +material.basswood = Tilleul +material.birch = Bouleau +material.brass = Laiton +material.cardboard = Carton +material.carbon_fiber = Fibre de carbone +material.cork = Liège +material.depron_xps = Depron (XPS) +material.fiberglass = Fibre de verre +material.kraft_phenolic = Kraft phénolique +material.maple = Érable +material.paper_office = Papier (bureau) +material.pine = Pin +material.plywood_birch = Contre-plaqué (bouleau) +material.polycarbonate_lexan = Polycarbonate (Lexan) +material.polystyrene = Polystyrène +material.pvc = PVC +material.spruce = Sapin +material.steel = Acier +material.styrofoam_generic_eps = Polystyrène (générique EPS) +material.styrofoam_blue_foam_xps = \"Mousse Bleue\" de polystyrène (XPS) +material.titanium = Titane +material.quantum_tubing = Tube Quantum +material.blue_tube = Blue tube !SURFACE_MATERIAL -Databases.materials.Ripstopnylon = Ripstop nylon -Databases.materials.Mylar = Mylar -Databases.materials.Polyethylenethin = Polyéthylène (fin) -Databases.materials.Polyethyleneheavy = Polyéthylène (lourd) -Databases.materials.Silk = Soie -Databases.materials.Paperoffice = Papier (bureau) -Databases.materials.Cellophane = Cellophane -Databases.materials.Crepepaper = Papier crépon +material.ripstop_nylon = Ripstop nylon +material.mylar = Mylar +material.polyethylene_thin = Polyéthylène (fin) +material.polyethylene_heavy = Polyéthylène (lourd) +material.silk = Soie +material.paper_office = Papier (bureau) +material.cellophane = Cellophane +material.crepe_paper = Papier crépon ! LINE_MATERIAL -Databases.materials.Threadheavy-duty = Fil(haute résistance) -Databases.materials.Elasticcordround2mm = Corde Elastique (ronde 2mm, 1/16 in) -Databases.materials.Elasticcordflat6mm = Corde Elastique (plate 6mm, 1/4 in) -Databases.materials.Elasticcordflat12mm = Corde Elastique (plate 12mm, 1/2 in) -Databases.materials.Elasticcordflat19mm = Corde Elastique (plate 19mm, 3/4 in) -Databases.materials.Elasticcordflat25mm = Corde Elastique (plate 25mm, 1 in) -Databases.materials.Braidednylon2mm = Nylon tressé (2 mm, 1/16 in) -Databases.materials.Braidednylon3mm = Nylon tressé (3 mm, 1/8 in) -Databases.materials.Tubularnylon11mm = Nylon tubulaire (11 mm, 7/16 in) -Databases.materials.Tubularnylon14mm = Nylon tubulaire (14 mm, 9/16 in) -Databases.materials.Tubularnylon25mm = Nylon tubulaire (25 mm, 1 in) +material.thread_heavy_duty = Fil(haute résistance) +material.elastic_cord_round_2_mm_1_16_in = Corde Elastique (ronde 2mm, 1/16 in) +material.elastic_cord_flat_6_mm_1_4_in = Corde Elastique (plate 6mm, 1/4 in) +material.elastic_cord_flat_12_mm_1_2_in = Corde Elastique (plate 12mm, 1/2 in) +material.elastic_cord_flat_19_mm_3_4_in = Corde Elastique (plate 19mm, 3/4 in) +material.elastic_cord_flat_25_mm_1_in = Corde Elastique (plate 25mm, 1 in) +material.braided_nylon_2_mm_1_16_in = Nylon tressé (2 mm, 1/16 in) +material.braided_nylon_3_mm_1_8_in = Nylon tressé (3 mm, 1/8 in) +material.tubular_nylon_11_mm_7_16_in = Nylon tubulaire (11 mm, 7/16 in) +material.tubular_nylon_14_mm_9_16_in = Nylon tubulaire (14 mm, 9/16 in) +material.tubular_nylon_25_mm_1_in = Nylon tubulaire (25 mm, 1 in) ! ExternalComponent ExternalComponent.Rough = Rugueuse diff --git a/core/resources/l10n/messages_it.properties b/core/resources/l10n/messages_it.properties index f0f1653c..1d2c0366 100644 --- a/core/resources/l10n/messages_it.properties +++ b/core/resources/l10n/messages_it.properties @@ -1094,53 +1094,53 @@ main.menu.debug.createtestrocket = Crea un test del razzo ! Material database ! BULK_MATERIAL -Databases.materials.Acrylic = Acrilico -Databases.materials.Aluminum = Aluminum -Databases.materials.Balsa = Balsa -Databases.materials.Basswood = Basswood -Databases.materials.Birch = Betulla -Databases.materials.Brass = Brass -Databases.materials.Cardboard = Cartoncino -Databases.materials.Carbonfiber = Fibra di carbonio -Databases.materials.Cork = Sughero -Databases.materials.DepronXPS = Depron (XPS) -Databases.materials.Fiberglass = Fibra di vetro -Databases.materials.Kraftphenolic = Kraft phenolic -Databases.materials.Maple = Acero -Databases.materials.Paperoffice = Carta (ufficio) -Databases.materials.Pine = Pino -Databases.materials.Plywoodbirch = Compensato (betulla) -Databases.materials.PolycarbonateLexan = Policarbonato (Lexan) -Databases.materials.Polystyrene = Polistirene -Databases.materials.PVC = PVC -Databases.materials.Spruce = Abete rosso -Databases.materials.Steel = Steel -Databases.materials.StyrofoamgenericEPS = polistirolo (generic EPS) -Databases.materials.StyrofoamBluefoamXPS = polistirolo \"Blue foam\" (XPS) -Databases.materials.Titanium = Titanium -Databases.materials.Quantumtubing = Quantum tubing -Databases.materials.BlueTube = Blue tube +material.acrylic = Acrilico +material.aluminum = Aluminum +material.balsa = Balsa +material.basswood = Basswood +material.birch = Betulla +material.brass = Brass +material.cardboard = Cartoncino +material.carbon_fiber = Fibra di carbonio +material.cork = Sughero +material.depron_xps = Depron (XPS) +material.fiberglass = Fibra di vetro +material.kraft_phenolic = Kraft phenolic +material.maple = Acero +material.paper_office = Carta (ufficio) +material.pine = Pino +material.plywood_birch = Compensato (betulla) +material.polycarbonate_lexan = Policarbonato (Lexan) +material.polystyrene = Polistirene +material.pvc = PVC +material.spruce = Abete rosso +material.steel = Steel +material.styrofoam_generic_eps = polistirolo (generic EPS) +material.styrofoam_blue_foam_xps = polistirolo \"Blue foam\" (XPS) +material.titanium = Titanium +material.quantum_tubing = Quantum tubing +material.blue_tube = Blue tube !SURFACE_MATERIAL -Databases.materials.Ripstopnylon = Ripstop nylon -Databases.materials.Mylar = Mylar -Databases.materials.Polyethylenethin = Polyethylene (thin) -Databases.materials.Polyethyleneheavy = Polyethylene (heavy) -Databases.materials.Silk = Seta -Databases.materials.Paperoffice = Carta (ufficio) -Databases.materials.Cellophane = Cellophane -Databases.materials.Crepepaper = Cr\u00eape carta +material.ripstop_nylon = Ripstop nylon +material.mylar = Mylar +material.polyethylene_thin = Polyethylene (thin) +material.polyethylene_heavy = Polyethylene (heavy) +material.silk = Seta +material.paper_office = Carta (ufficio) +material.cellophane = Cellophane +material.crepe_paper = Cr\u00eape carta ! LINE_MATERIAL -Databases.materials.Threadheavy-duty = Thread (heavy-duty) -Databases.materials.Elasticcordround2mm = Elastic cord (round 2mm, 1/16 in) -Databases.materials.Elasticcordflat6mm = Elastic cord (flat 6mm, 1/4 in) -Databases.materials.Elasticcordflat12mm = Elastic cord (flat 12mm, 1/2 in) -Databases.materials.Elasticcordflat19mm = Elastic cord (flat 19mm, 3/4 in) -Databases.materials.Elasticcordflat25mm = Elastic cord (flat 25mm, 1 in) -Databases.materials.Braidednylon2mm = Braided nylon (2 mm, 1/16 in) -Databases.materials.Braidednylon3mm = Braided nylon (3 mm, 1/8 in) -Databases.materials.Tubularnylon11mm = Tubular nylon (11 mm, 7/16 in) -Databases.materials.Tubularnylon14mm = Tubular nylon (14 mm, 9/16 in) -Databases.materials.Tubularnylon25mm = Tubular nylon (25 mm, 1 in) +material.thread_heavy_duty = Thread (heavy-duty) +material.elastic_cord_round_2_mm_1_16_in = Elastic cord (round 2mm, 1/16 in) +material.elastic_cord_flat_6_mm_1_4_in = Elastic cord (flat 6mm, 1/4 in) +material.elastic_cord_flat_12_mm_1_2_in = Elastic cord (flat 12mm, 1/2 in) +material.elastic_cord_flat_19_mm_3_4_in = Elastic cord (flat 19mm, 3/4 in) +material.elastic_cord_flat_25_mm_1_in = Elastic cord (flat 25mm, 1 in) +material.braided_nylon_2_mm_1_16_in = Braided nylon (2 mm, 1/16 in) +material.braided_nylon_3_mm_1_8_in = Braided nylon (3 mm, 1/8 in) +material.tubular_nylon_11_mm_7_16_in = Tubular nylon (11 mm, 7/16 in) +material.tubular_nylon_14_mm_9_16_in = Tubular nylon (14 mm, 9/16 in) +material.tubular_nylon_25_mm_1_in = Tubular nylon (25 mm, 1 in) ! ExternalComponent ExternalComponent.Rough = Ruvido diff --git a/core/resources/l10n/messages_pl.properties b/core/resources/l10n/messages_pl.properties index 0b67b8b9..a25fecd6 100644 --- a/core/resources/l10n/messages_pl.properties +++ b/core/resources/l10n/messages_pl.properties @@ -1035,53 +1035,53 @@ ! Material database ! BULK_MATERIAL - Databases.materials.Acrylic = Akryl - Databases.materials.Aluminum = Aluminium - Databases.materials.Balsa = Balsa - Databases.materials.Basswood = Lipa - Databases.materials.Birch = Brzoza - Databases.materials.Brass = Mosi\u0105dz - Databases.materials.Cardboard = Karton - Databases.materials.Carbonfiber = W\u0142ókno w\u0119glowe - Databases.materials.Cork = Korek - Databases.materials.DepronXPS = Depron (XPS) - Databases.materials.Fiberglass = W\u0142ókno szklane - Databases.materials.Kraftphenolic = Kraft fenolowy - Databases.materials.Maple = Klon - Databases.materials.Paperoffice = Papier (biurowy) - Databases.materials.Pine = Sosna - Databases.materials.Plywoodbirch = Sklejka (brzoza) - Databases.materials.PolycarbonateLexan = Poliw\u0119glan (Lexan) - Databases.materials.Polystyrene = Polistyren - Databases.materials.PVC = PVC - Databases.materials.Spruce = \u015Awierk - Databases.materials.Steel = Stal - Databases.materials.StyrofoamgenericEPS = Styropian (zwyk\u0142y EPS) - Databases.materials.StyrofoamBluefoamXPS = Styropian \"kolorowy\" (XPS) - Databases.materials.Titanium = Tytan - Databases.materials.Quantumtubing = Tuby kwantowe - Databases.materials.BlueTube = Blue tube + material.acrylic = Akryl + material.aluminum = Aluminium + material.balsa = Balsa + material.basswood = Lipa + material.birch = Brzoza + material.brass = Mosi\u0105dz + material.cardboard = Karton + material.carbon_fiber = W\u0142ókno w\u0119glowe + material.cork = Korek + material.depron_xps = Depron (XPS) + material.fiberglass = W\u0142ókno szklane + material.kraft_phenolic = Kraft fenolowy + material.maple = Klon + material.paper_office = Papier (biurowy) + material.pine = Sosna + material.plywood_birch = Sklejka (brzoza) + material.polycarbonate_lexan = Poliw\u0119glan (Lexan) + material.polystyrene = Polistyren + material.pvc = PVC + material.spruce = \u015Awierk + material.steel = Stal + material.styrofoam_generic_eps = Styropian (zwyk\u0142y EPS) + material.styrofoam_blue_foam_xps = Styropian \"kolorowy\" (XPS) + material.titanium = Tytan + material.quantum_tubing = Tuby kwantowe + material.blue_tube = Blue tube !SURFACE_MATERIAL - Databases.materials.Ripstopnylon = Nylon Rip-stop - Databases.materials.Mylar = Mylar - Databases.materials.Polyethylenethin = Polietylen (cienki) - Databases.materials.Polyethyleneheavy = Polietylen (ci\u0119\u017Cki) - Databases.materials.Silk = Jedwab - Databases.materials.Paperoffice = Papier (biurowy) - Databases.materials.Cellophane = Celofan - Databases.materials.Crepepaper = Papier marszczony, krepina + material.ripstop_nylon = Nylon Rip-stop + material.mylar = Mylar + material.polyethylene_thin = Polietylen (cienki) + material.polyethylene_heavy = Polietylen (ci\u0119\u017Cki) + material.silk = Jedwab + material.paper_office = Papier (biurowy) + material.cellophane = Celofan + material.crepe_paper = Papier marszczony, krepina ! LINE_MATERIAL - Databases.materials.Threadheavy-duty = Ni\u0107 (wytrzyma\u0142a) - Databases.materials.Elasticcordround2mm = Przewód elastyczny (okr\u0105g\u0142y 2mm) - Databases.materials.Elasticcordflat6mm = Przewód elastyczny (p\u0142aski 6mm) - Databases.materials.Elasticcordflat12mm = Przewód elastyczny (p\u0142aski 12 mm) - Databases.materials.Elasticcordflat19mm = Przewód elastyczny (p\u0142aski 19 mm) - Databases.materials.Elasticcordflat25mm = Przewód elastyczny (p\u0142aski 25mm) - Databases.materials.Braidednylon2mm = Nylon spleciony (2 mm) - Databases.materials.Braidednylon3mm = Nylon spleciony (3 mm) - Databases.materials.Tubularnylon11mm = Nylon rurkowy (11 mm) - Databases.materials.Tubularnylon14mm = Nylon rurkowy (14 mm) - Databases.materials.Tubularnylon25mm = Nylon rurkowy (25 mm) + material.thread_heavy_duty = Ni\u0107 (wytrzyma\u0142a) + material.elastic_cord_round_2_mm_1_16_in = Przewód elastyczny (okr\u0105g\u0142y 2mm) + material.elastic_cord_flat_6_mm_1_4_in = Przewód elastyczny (p\u0142aski 6mm) + material.elastic_cord_flat_12_mm_1_2_in = Przewód elastyczny (p\u0142aski 12 mm) + material.elastic_cord_flat_19_mm_3_4_in = Przewód elastyczny (p\u0142aski 19 mm) + material.elastic_cord_flat_25_mm_1_in = Przewód elastyczny (p\u0142aski 25mm) + material.braided_nylon_2_mm_1_16_in = Nylon spleciony (2 mm) + material.braided_nylon_3_mm_1_8_in = Nylon spleciony (3 mm) + material.tubular_nylon_11_mm_7_16_in = Nylon rurkowy (11 mm) + material.tubular_nylon_14_mm_9_16_in = Nylon rurkowy (14 mm) + material.tubular_nylon_25_mm_1_in = Nylon rurkowy (25 mm) ! ExternalComponent ExternalComponent.Rough = Chropowate diff --git a/core/resources/l10n/messages_ru.properties b/core/resources/l10n/messages_ru.properties index 9873357f..6527dee9 100644 --- a/core/resources/l10n/messages_ru.properties +++ b/core/resources/l10n/messages_ru.properties @@ -1121,53 +1121,53 @@ Databases.materials.types.Bulk = \u041e\u0431\u044a\u0435\u043c\u043d\u044b\u043 Databases.materials.types.Line = \u041b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 Databases.materials.types.Surface = \u041f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u044b\u0439 ! BULK_MATERIAL -Databases.materials.Acrylic = \u0410\u043a\u0440\u0438\u043b -Databases.materials.Aluminum = \u0410\u043b\u044e\u043c\u0438\u043d\u0438\u0439 -Databases.materials.Balsa = \u0411\u0430\u043b\u044c\u0441\u0430 -Databases.materials.Basswood = \u0410\u043c\u0435\u0440\u0438\u043a\u0430\u043d\u0441\u043a\u0430\u044f \u043b\u0438\u043f\u0430 -Databases.materials.Birch = \u0411\u0435\u0440\u0435\u0437\u0430 -Databases.materials.Brass = \u041b\u0430\u0442\u0443\u043d\u044c -Databases.materials.Cardboard = \u041a\u0430\u0440\u0442\u043e\u043d -Databases.materials.Carbonfiber = \u0423\u0433\u043b\u0435\u0432\u043e\u043b\u043e\u043a\u043d\u043e -Databases.materials.Cork = \u041f\u0440\u043e\u0431\u043a\u0430 -Databases.materials.DepronXPS = \u0414\u0435\u043f\u0440\u043e\u043d (XPS) -Databases.materials.Fiberglass = \u0421\u0442\u0435\u043a\u043b\u043e\u0432\u043e\u043b\u043e\u043a\u043d\u043e -Databases.materials.Kraftphenolic = \u041f\u0440\u043e\u043f\u0438\u0442\u0430\u043d\u043d\u0430\u044f \u043a\u0440\u0430\u0444\u0442-\u0431\u0443\u043c\u0430\u0433\u0430 -Databases.materials.Maple = \u041a\u043b\u0451\u043d -Databases.materials.Paperoffice = \u0411\u0443\u043c\u0430\u0433\u0430 (\u043e\u0444\u0438\u0441\u043d\u0430\u044f) -Databases.materials.Pine = \u0421\u043e\u0441\u043d\u0430 -Databases.materials.Plywoodbirch = \u0424\u0430\u043d\u0435\u0440\u0430 (\u0431\u0435\u0440\u0435\u0437\u043e\u0432\u0430\u044f) -Databases.materials.PolycarbonateLexan = \u041f\u043e\u043b\u0438\u043a\u0430\u0440\u0431\u043e\u043d\u0430\u0442 (\u041b\u0435\u043a\u0441\u0430\u043d) -Databases.materials.Polystyrene = \u041f\u043e\u043b\u0438\u0441\u0442\u0438\u0440\u043e\u043b -Databases.materials.PVC = \u041f\u0412\u0425 -Databases.materials.Spruce = \u0415\u043b\u044c -Databases.materials.Steel = \u0421\u0442\u0430\u043b\u044c -Databases.materials.StyrofoamgenericEPS = \u041f\u0435\u043d\u043e\u043f\u043b\u0430\u0441\u0442 (\u043e\u0431\u044b\u0447\u043d\u044b\u0439 EPS) -Databases.materials.StyrofoamBluefoamXPS = \u041f\u0435\u043d\u043e\u043f\u043b\u0430\u0441\u0442 "Blue foam" (XPS) -Databases.materials.Titanium = \u0422\u0438\u0442\u0430\u043d -Databases.materials.Quantumtubing = Quantum tubing -Databases.materials.BlueTube = Blue tube +material.acrylic = \u0410\u043a\u0440\u0438\u043b +material.aluminum = \u0410\u043b\u044e\u043c\u0438\u043d\u0438\u0439 +material.balsa = \u0411\u0430\u043b\u044c\u0441\u0430 +material.basswood = \u0410\u043c\u0435\u0440\u0438\u043a\u0430\u043d\u0441\u043a\u0430\u044f \u043b\u0438\u043f\u0430 +material.birch = \u0411\u0435\u0440\u0435\u0437\u0430 +material.brass = \u041b\u0430\u0442\u0443\u043d\u044c +material.cardboard = \u041a\u0430\u0440\u0442\u043e\u043d +material.carbon_fiber = \u0423\u0433\u043b\u0435\u0432\u043e\u043b\u043e\u043a\u043d\u043e +material.cork = \u041f\u0440\u043e\u0431\u043a\u0430 +material.depron_xps = \u0414\u0435\u043f\u0440\u043e\u043d (XPS) +material.fiberglass = \u0421\u0442\u0435\u043a\u043b\u043e\u0432\u043e\u043b\u043e\u043a\u043d\u043e +material.kraft_phenolic = \u041f\u0440\u043e\u043f\u0438\u0442\u0430\u043d\u043d\u0430\u044f \u043a\u0440\u0430\u0444\u0442-\u0431\u0443\u043c\u0430\u0433\u0430 +material.maple = \u041a\u043b\u0451\u043d +material.paper_office = \u0411\u0443\u043c\u0430\u0433\u0430 (\u043e\u0444\u0438\u0441\u043d\u0430\u044f) +material.pine = \u0421\u043e\u0441\u043d\u0430 +material.plywood_birch = \u0424\u0430\u043d\u0435\u0440\u0430 (\u0431\u0435\u0440\u0435\u0437\u043e\u0432\u0430\u044f) +material.polycarbonate_lexan = \u041f\u043e\u043b\u0438\u043a\u0430\u0440\u0431\u043e\u043d\u0430\u0442 (\u041b\u0435\u043a\u0441\u0430\u043d) +material.polystyrene = \u041f\u043e\u043b\u0438\u0441\u0442\u0438\u0440\u043e\u043b +material.pvc = \u041f\u0412\u0425 +material.spruce = \u0415\u043b\u044c +material.steel = \u0421\u0442\u0430\u043b\u044c +material.styrofoam_generic_eps = \u041f\u0435\u043d\u043e\u043f\u043b\u0430\u0441\u0442 (\u043e\u0431\u044b\u0447\u043d\u044b\u0439 EPS) +material.styrofoam_blue_foam_xps = \u041f\u0435\u043d\u043e\u043f\u043b\u0430\u0441\u0442 "Blue foam" (XPS) +material.titanium = \u0422\u0438\u0442\u0430\u043d +material.quantum_tubing = Quantum tubing +material.blue_tube = Blue tube !SURFACE_MATERIAL -Databases.materials.Ripstopnylon = \u041d\u0435\u0439\u043b\u043e\u043d\u043e\u0432\u044b\u0439 \u0440\u0438\u043f\u0441\u0442\u043e\u043f -Databases.materials.Mylar = \u041c\u0430\u0439\u043b\u0430\u0440 -Databases.materials.Polyethylenethin = \u041f\u043e\u043b\u0438\u044d\u0442\u0438\u043b\u0435\u043d (\u0442\u043e\u043d\u043a\u0438\u0439) -Databases.materials.Polyethyleneheavy = \u041f\u043e\u043b\u0438\u044d\u0442\u0438\u043b\u0435\u043d (\u043f\u043b\u043e\u0442\u043d\u044b\u0439) -Databases.materials.Silk = \u0428\u0435\u043b\u043a -Databases.materials.Paperoffice = \u0411\u0443\u043c\u0430\u0433\u0430 (\u043e\u0444\u0438\u0441\u043d\u0430\u044f) -Databases.materials.Cellophane = \u0426\u0435\u043b\u043b\u043e\u0444\u0430\u043d -Databases.materials.Crepepaper = Cr\u00eape paper +material.ripstop_nylon = \u041d\u0435\u0439\u043b\u043e\u043d\u043e\u0432\u044b\u0439 \u0440\u0438\u043f\u0441\u0442\u043e\u043f +material.mylar = \u041c\u0430\u0439\u043b\u0430\u0440 +material.polyethylene_thin = \u041f\u043e\u043b\u0438\u044d\u0442\u0438\u043b\u0435\u043d (\u0442\u043e\u043d\u043a\u0438\u0439) +material.polyethylene_heavy = \u041f\u043e\u043b\u0438\u044d\u0442\u0438\u043b\u0435\u043d (\u043f\u043b\u043e\u0442\u043d\u044b\u0439) +material.silk = \u0428\u0435\u043b\u043a +material.paper_office = \u0411\u0443\u043c\u0430\u0433\u0430 (\u043e\u0444\u0438\u0441\u043d\u0430\u044f) +material.cellophane = \u0426\u0435\u043b\u043b\u043e\u0444\u0430\u043d +material.crepe_paper = Cr\u00eape paper ! LINE_MATERIAL -Databases.materials.Threadheavy-duty = \u0421\u0443\u0440\u043e\u0432\u0430\u044f \u043d\u0438\u0442\u044c -Databases.materials.Elasticcordround2mm = \u042d\u043b\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u043d\u0443\u0440 (\u043a\u0440\u0443\u0433\u043b\u044b\u0439 2mm, 1/16 in) -Databases.materials.Elasticcordflat6mm = \u042d\u043b\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u043d\u0443\u0440 (\u043f\u043b\u043e\u0441\u043a\u0438\u0439 6mm, 1/4 in) -Databases.materials.Elasticcordflat12mm = \u042d\u043b\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u043d\u0443\u0440 (\u043f\u043b\u043e\u0441\u043a\u0438\u0439 12mm, 1/2 in) -Databases.materials.Elasticcordflat19mm = \u042d\u043b\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u043d\u0443\u0440 (\u043f\u043b\u043e\u0441\u043a\u0438\u0439 19mm, 3/4 in) -Databases.materials.Elasticcordflat25mm = \u042d\u043b\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u043d\u0443\u0440 (\u043f\u043b\u043e\u0441\u043a\u0438\u0439 25mm, 1 in) -Databases.materials.Braidednylon2mm = \u041f\u043b\u0435\u0442\u0435\u043d\u044b\u0439 \u043d\u0435\u0439\u043b\u043e\u043d (2 mm, 1/16 in) -Databases.materials.Braidednylon3mm = \u041f\u043b\u0435\u0442\u0435\u043d\u044b\u0439 \u043d\u0435\u0439\u043b\u043e\u043d (3 mm, 1/8 in) -Databases.materials.Tubularnylon11mm = \u0422\u0440\u0443\u0431\u0447\u0430\u0442\u044b\u0439 \u043d\u0435\u0439\u043b\u043e\u043d (11 mm, 7/16 in) -Databases.materials.Tubularnylon14mm = \u0422\u0440\u0443\u0431\u0447\u0430\u0442\u044b\u0439 \u043d\u0435\u0439\u043b\u043e\u043d (14 mm, 9/16 in) -Databases.materials.Tubularnylon25mm = \u0422\u0440\u0443\u0431\u0447\u0430\u0442\u044b\u0439 \u043d\u0435\u0439\u043b\u043e\u043d (25 mm, 1 in) +material.thread_heavy_duty = \u0421\u0443\u0440\u043e\u0432\u0430\u044f \u043d\u0438\u0442\u044c +material.elastic_cord_round_2_mm_1_16_in = \u042d\u043b\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u043d\u0443\u0440 (\u043a\u0440\u0443\u0433\u043b\u044b\u0439 2mm, 1/16 in) +material.elastic_cord_flat_6_mm_1_4_in = \u042d\u043b\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u043d\u0443\u0440 (\u043f\u043b\u043e\u0441\u043a\u0438\u0439 6mm, 1/4 in) +material.elastic_cord_flat_12_mm_1_2_in = \u042d\u043b\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u043d\u0443\u0440 (\u043f\u043b\u043e\u0441\u043a\u0438\u0439 12mm, 1/2 in) +material.elastic_cord_flat_19_mm_3_4_in = \u042d\u043b\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u043d\u0443\u0440 (\u043f\u043b\u043e\u0441\u043a\u0438\u0439 19mm, 3/4 in) +material.elastic_cord_flat_25_mm_1_in = \u042d\u043b\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u043d\u0443\u0440 (\u043f\u043b\u043e\u0441\u043a\u0438\u0439 25mm, 1 in) +material.braided_nylon_2_mm_1_16_in = \u041f\u043b\u0435\u0442\u0435\u043d\u044b\u0439 \u043d\u0435\u0439\u043b\u043e\u043d (2 mm, 1/16 in) +material.braided_nylon_3_mm_1_8_in = \u041f\u043b\u0435\u0442\u0435\u043d\u044b\u0439 \u043d\u0435\u0439\u043b\u043e\u043d (3 mm, 1/8 in) +material.tubular_nylon_11_mm_7_16_in = \u0422\u0440\u0443\u0431\u0447\u0430\u0442\u044b\u0439 \u043d\u0435\u0439\u043b\u043e\u043d (11 mm, 7/16 in) +material.tubular_nylon_14_mm_9_16_in = \u0422\u0440\u0443\u0431\u0447\u0430\u0442\u044b\u0439 \u043d\u0435\u0439\u043b\u043e\u043d (14 mm, 9/16 in) +material.tubular_nylon_25_mm_1_in = \u0422\u0440\u0443\u0431\u0447\u0430\u0442\u044b\u0439 \u043d\u0435\u0439\u043b\u043e\u043d (25 mm, 1 in) ! ExternalComponent ExternalComponent.Rough = \u0427\u0435\u0440\u043d\u043e\u0432\u0430\u044f diff --git a/core/resources/l10n/rename.sh b/core/resources/l10n/rename.sh new file mode 100755 index 00000000..c21c1f64 --- /dev/null +++ b/core/resources/l10n/rename.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Usage: +# ./rename + +RENAME="$1" +shift + +cat "$RENAME" | while read line ; do + + FROM=`echo $line | awk '{print $1}'` + TO=`echo $line | awk '{print $2}'` + + sed -i "s/$FROM/$TO/g" "$@" + +done diff --git a/core/src/net/sf/openrocket/database/Databases.java b/core/src/net/sf/openrocket/database/Databases.java index 28b50dcb..853790bf 100644 --- a/core/src/net/sf/openrocket/database/Databases.java +++ b/core/src/net/sf/openrocket/database/Databases.java @@ -1,7 +1,9 @@ package net.sf.openrocket.database; +import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.logging.LogHelper; import net.sf.openrocket.material.Material; +import net.sf.openrocket.material.Material.Type; import net.sf.openrocket.material.MaterialStorage; import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.MathUtil; @@ -14,9 +16,11 @@ import net.sf.openrocket.util.MathUtil; */ public class Databases { private static final LogHelper log = Application.getLogger(); - + private static final Translator trans = Application.getTranslator(); + + /* Static implementations of specific databases: */ - + /** * A database of bulk materials (with bulk densities). */ @@ -29,118 +33,116 @@ public class Databases { * A database of linear material (with length densities). */ public static final Database LINE_MATERIAL = new Database(); - - - + + + static { - + // Add default materials - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Acrylic", 1190)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Aluminum", 2700)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Balsa", 170)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Basswood", 500)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Birch", 670)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Brass", 8600)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Cardboard", 680)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Carbonfiber", 1780)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Cork", 240)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"DepronXPS", 40)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Fiberglass", 1850)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Kraftphenolic", 950)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Maple", 755)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Paperoffice", 820)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Pine", 530)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Plywoodbirch", 630)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"PolycarbonateLexan", 1200)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Polystyrene", 1050)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"PVC", 1390)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Spruce", 450)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Steel", 7850)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"StyrofoamgenericEPS", 20)); - // BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Styrofoam (Blue foam, XPS)", 32)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"StyrofoamBluefoamXPS", 32)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Titanium", 4500)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Quantumtubing", 1050)); - BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"BlueTube", 1300)); - - SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Ripstopnylon", 0.067)); - SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Mylar", 0.021)); - SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Polyethylenethin", 0.015)); - SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Polyethyleneheavy", 0.040)); - SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Silk", 0.060)); - SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Paperoffice", 0.080)); - SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Cellophane", 0.018)); - SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Crepepaper", 0.025)); - - //// Thread (heavy-duty) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Threadheavy-duty", 0.0003)); - //// Elastic cord (round 2mm, 1/16 in) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordround2mm", 0.0018)); - //// Elastic cord (flat 6mm, 1/4 in) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat6mm", 0.0043)); - //// Elastic cord (flat 12mm, 1/2 in) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat12mm", 0.008)); - //// Elastic cord (flat 19mm, 3/4 in) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat19mm", 0.0012)); - //// Elastic cord (flat 25mm, 1 in) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat25mm", 0.0016)); - //// Braided nylon (2 mm, 1/16 in) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Braidednylon2mm", 0.001)); - //// Braided nylon (3 mm, 1/8 in) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Braidednylon3mm", 0.0035)); - //// Tubular nylon (11 mm, 7/16 in) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Tubularnylon11mm", 0.013)); - //// Tubular nylon (14 mm, 9/16 in) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Tubularnylon14mm", 0.016)); - //// Tubular nylon (25 mm, 1 in) - LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Tubularnylon25mm", 0.029)); - - + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Acrylic", 1190)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Aluminum", 2700)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Balsa", 170)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Basswood", 500)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Birch", 670)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Brass", 8600)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Cardboard", 680)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Carbon fiber", 1780)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Cork", 240)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Depron (XPS)", 40)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Fiberglass", 1850)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Kraft phenolic", 950)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Maple", 755)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Paper (office)", 820)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Pine", 530)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Plywood (birch)", 630)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Polycarbonate (Lexan)", 1200)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Polystyrene", 1050)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "PVC", 1390)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Spruce", 450)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Steel", 7850)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Styrofoam (generic EPS)", 20)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Styrofoam \"Blue foam\" (XPS)", 32)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Titanium", 4500)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Quantum tubing", 1050)); + BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Blue tube", 1300)); + + SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Ripstop nylon", 0.067)); + SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Mylar", 0.021)); + SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Polyethylene (thin)", 0.015)); + SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Polyethylene (heavy)", 0.040)); + SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Silk", 0.060)); + SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Paper (office)", 0.080)); + SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Cellophane", 0.018)); + SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Cr\u00eape paper", 0.025)); + + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Thread (heavy-duty)", 0.0003)); + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Elastic cord (round 2 mm, 1/16 in)", 0.0018)); + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Elastic cord (flat 6 mm, 1/4 in)", 0.0043)); + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Elastic cord (flat 12 mm, 1/2 in)", 0.008)); + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Elastic cord (flat 19 mm, 3/4 in)", 0.0012)); + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Elastic cord (flat 25 mm, 1 in)", 0.0016)); + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Braided nylon (2 mm, 1/16 in)", 0.001)); + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Braided nylon (3 mm, 1/8 in)", 0.0035)); + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Tubular nylon (11 mm, 7/16 in)", 0.013)); + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Tubular nylon (14 mm, 9/16 in)", 0.016)); + LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Tubular nylon (25 mm, 1 in)", 0.029)); + + // Add user-defined materials for (Material m : Application.getPreferences().getUserMaterials()) { switch (m.getType()) { case LINE: LINE_MATERIAL.add(m); break; - + case SURFACE: SURFACE_MATERIAL.add(m); break; - + case BULK: BULK_MATERIAL.add(m); break; - + default: log.warn("ERROR: Unknown material type " + m); } } - + // Add database storage listener MaterialStorage listener = new MaterialStorage(); LINE_MATERIAL.addDatabaseListener(listener); SURFACE_MATERIAL.addDatabaseListener(listener); BULK_MATERIAL.addDatabaseListener(listener); } - - + + + private static Material newMaterial(Type type, String baseName, double density) { + String name = trans.get("material", baseName); + return Material.newMaterial(type, name, density, false); + } + + + + /* * Used just for ensuring initialization of the class. */ public static void fakeMethod() { - + } - - + /** * Find a material from the database with the specified type and name. Returns * null if the specified material could not be found. + *

+ * This method will attempt to localize the material name to the current locale, or use + * the provided name if unable to do so. * - * @param type the material type. - * @param name the material name in the database. - * @return the material, or null if not found. + * @param type the material type. + * @param baseName the material base name in the database. + * @return the material, or null if not found. */ - public static Material findMaterial(Material.Type type, String name) { + public static Material findMaterial(Material.Type type, String baseName) { Database db; switch (type) { case BULK: @@ -155,7 +157,9 @@ public class Databases { default: throw new IllegalArgumentException("Illegal material type: " + type); } - + + String name = trans.get("material", baseName); + for (Material m : db) { if (m.getName().equalsIgnoreCase(name)) { return m; @@ -163,18 +167,21 @@ public class Databases { } return null; } - - + + /** * Find a material from the database or return a new user defined material if the specified * material with the specified density is not found. + *

+ * This method will attempt to localize the material name to the current locale, or use + * the provided name if unable to do so. * * @param type the material type. - * @param name the material name. + * @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. */ - public static Material findMaterial(Material.Type type, String key, String name, double density) { + public static Material findMaterial(Material.Type type, String baseName, double density) { Database db; switch (type) { case BULK: @@ -189,32 +196,15 @@ public class Databases { default: throw new IllegalArgumentException("Illegal material type: " + type); } - - Material bestMatch = null; - - // Alter the search mechanism to handle older specifications. - // If a key is specified, then we match on key, if one is found. - // Otherwise we return the material which matches on name. - // this requires us to loop through the entire db at least once to look for the key. + + String name = trans.get("material", baseName); + for (Material m : db) { - // perfect match based on key. - if ( key != null && m.getKey().equals(key) ) { - // Exact match - if ( MathUtil.equals(m.getDensity(), density) ) { - return m; - } - // Custom material with standard name - return Material.newUserMaterialWithKey(type, key, m.getName(), density); - } if (m.getName().equalsIgnoreCase(name) && MathUtil.equals(m.getDensity(), density)) { - bestMatch = m; + return m; } } - if ( bestMatch != null ) { - return bestMatch; - } - return Material.newUserMaterial(type, name, density); + return Material.newMaterial(type, name, density, true); } - - + } diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java index 39845c7f..f4c615a1 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java @@ -67,13 +67,13 @@ import net.sf.openrocket.rocketcomponent.ThicknessRingComponent; import net.sf.openrocket.rocketcomponent.Transition; import net.sf.openrocket.rocketcomponent.TrapezoidFinSet; import net.sf.openrocket.rocketcomponent.TubeCoupler; -import net.sf.openrocket.simulation.customexpression.CustomExpression; import net.sf.openrocket.simulation.FlightData; import net.sf.openrocket.simulation.FlightDataBranch; import net.sf.openrocket.simulation.FlightDataType; import net.sf.openrocket.simulation.FlightEvent; import net.sf.openrocket.simulation.FlightEvent.Type; import net.sf.openrocket.simulation.SimulationOptions; +import net.sf.openrocket.simulation.customexpression.CustomExpression; import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.util.BugException; @@ -99,30 +99,30 @@ import org.xml.sax.SAXException; */ public class OpenRocketLoader extends AbstractRocketLoader { private static final LogHelper log = Application.getLogger(); - - + + @Override public OpenRocketDocument loadFromStream(InputStream source, MotorFinder motorFinder) throws RocketLoadException, - IOException { + IOException { log.info("Loading .ork file"); DocumentLoadingContext context = new DocumentLoadingContext(); context.setMotorFinder(motorFinder); - + InputSource xmlSource = new InputSource(source); OpenRocketHandler handler = new OpenRocketHandler(context); - - + + try { SimpleSAX.readXML(xmlSource, handler, warnings); } catch (SAXException e) { log.warn("Malformed XML in input"); throw new RocketLoadException("Malformed XML in input.", e); } - - + + OpenRocketDocument doc = handler.getDocument(); doc.getDefaultConfiguration().setAllStages(); - + // Deduce suitable time skip double timeSkip = StorageOptions.SIMULATION_DATA_NONE; for (Simulation s : doc.getSimulations()) { @@ -139,7 +139,7 @@ public class OpenRocketLoader extends AbstractRocketLoader { List list = branch.get(FlightDataType.TYPE_TIME); if (list == null) continue; - + double previousTime = Double.NaN; for (double time : list) { if (time - previousTime < timeSkip) @@ -149,33 +149,33 @@ public class OpenRocketLoader extends AbstractRocketLoader { } // Round value timeSkip = Math.rint(timeSkip * 100) / 100; - + doc.getDefaultStorageOptions().setSimulationTimeSkip(timeSkip); doc.getDefaultStorageOptions().setCompressionEnabled(false); // Set by caller if compressed doc.getDefaultStorageOptions().setExplicitlySet(false); - + doc.clearUndo(); log.info("Loading done"); return doc; } - + } class DocumentConfig { - + /* Remember to update OpenRocketSaver as well! */ public static final String[] SUPPORTED_VERSIONS = { "1.0", "1.1", "1.2", "1.3", "1.4", "1.5" }; - + /** * Divisor used in converting an integer version to the point-represented version. * The integer version divided by this value is the major version and the remainder is * the minor version. For example 101 corresponds to file version "1.1". */ public static final int FILE_VERSION_DIVISOR = 100; - - + + //////// Component constructors static final HashMap> constructors = new HashMap>(); static { @@ -188,29 +188,29 @@ class DocumentConfig { constructors.put("ellipticalfinset", EllipticalFinSet.class.getConstructor(new Class[0])); constructors.put("freeformfinset", FreeformFinSet.class.getConstructor(new Class[0])); constructors.put("launchlug", LaunchLug.class.getConstructor(new Class[0])); - + // Internal components constructors.put("engineblock", EngineBlock.class.getConstructor(new Class[0])); constructors.put("innertube", InnerTube.class.getConstructor(new Class[0])); constructors.put("tubecoupler", TubeCoupler.class.getConstructor(new Class[0])); constructors.put("bulkhead", Bulkhead.class.getConstructor(new Class[0])); constructors.put("centeringring", CenteringRing.class.getConstructor(new Class[0])); - + constructors.put("masscomponent", MassComponent.class.getConstructor(new Class[0])); constructors.put("shockcord", ShockCord.class.getConstructor(new Class[0])); constructors.put("parachute", Parachute.class.getConstructor(new Class[0])); constructors.put("streamer", Streamer.class.getConstructor(new Class[0])); - + // Other constructors.put("stage", Stage.class.getConstructor(new Class[0])); - + } catch (NoSuchMethodException e) { throw new BugException( "Error in constructing the 'constructors' HashMap."); } } - - + + //////// Parameter setters /* * The keys are of the form Class:param, where Class is the class name and param @@ -240,7 +240,7 @@ class DocumentConfig { Reflection.findMethod(RocketComponent.class, "setComment", String.class))); setters.put("RocketComponent:preset", new ComponentPresetSetter( Reflection.findMethod(RocketComponent.class, "loadPreset", ComponentPreset.class))); - + // ExternalComponent setters.put("ExternalComponent:finish", new EnumSetter( Reflection.findMethod(ExternalComponent.class, "setFinish", Finish.class), @@ -248,23 +248,23 @@ class DocumentConfig { setters.put("ExternalComponent:material", new MaterialSetter( Reflection.findMethod(ExternalComponent.class, "setMaterial", Material.class), Material.Type.BULK)); - + // BodyComponent setters.put("BodyComponent:length", new DoubleSetter( Reflection.findMethod(BodyComponent.class, "setLength", double.class))); - + // SymmetricComponent setters.put("SymmetricComponent:thickness", new DoubleSetter( Reflection.findMethod(SymmetricComponent.class, "setThickness", double.class), "filled", Reflection.findMethod(SymmetricComponent.class, "setFilled", boolean.class))); - + // BodyTube setters.put("BodyTube:radius", new DoubleSetter( Reflection.findMethod(BodyTube.class, "setOuterRadius", double.class), "auto", Reflection.findMethod(BodyTube.class, "setOuterRadiusAutomatic", boolean.class))); - + // Transition setters.put("Transition:shape", new EnumSetter( Reflection.findMethod(Transition.class, "setType", Transition.Shape.class), @@ -273,7 +273,7 @@ class DocumentConfig { Reflection.findMethod(Transition.class, "setClipped", boolean.class))); setters.put("Transition:shapeparameter", new DoubleSetter( Reflection.findMethod(Transition.class, "setShapeParameter", double.class))); - + setters.put("Transition:foreradius", new DoubleSetter( Reflection.findMethod(Transition.class, "setForeRadius", double.class), "auto", @@ -282,7 +282,7 @@ class DocumentConfig { Reflection.findMethod(Transition.class, "setAftRadius", double.class), "auto", Reflection.findMethod(Transition.class, "setAftRadiusAutomatic", boolean.class))); - + setters.put("Transition:foreshoulderradius", new DoubleSetter( Reflection.findMethod(Transition.class, "setForeShoulderRadius", double.class))); setters.put("Transition:foreshoulderlength", new DoubleSetter( @@ -291,7 +291,7 @@ class DocumentConfig { Reflection.findMethod(Transition.class, "setForeShoulderThickness", double.class))); setters.put("Transition:foreshouldercapped", new BooleanSetter( Reflection.findMethod(Transition.class, "setForeShoulderCapped", boolean.class))); - + setters.put("Transition:aftshoulderradius", new DoubleSetter( Reflection.findMethod(Transition.class, "setAftShoulderRadius", double.class))); setters.put("Transition:aftshoulderlength", new DoubleSetter( @@ -300,14 +300,14 @@ class DocumentConfig { Reflection.findMethod(Transition.class, "setAftShoulderThickness", double.class))); setters.put("Transition:aftshouldercapped", new BooleanSetter( Reflection.findMethod(Transition.class, "setAftShoulderCapped", boolean.class))); - + // NoseCone - disable disallowed elements setters.put("NoseCone:foreradius", null); setters.put("NoseCone:foreshoulderradius", null); setters.put("NoseCone:foreshoulderlength", null); setters.put("NoseCone:foreshoulderthickness", null); setters.put("NoseCone:foreshouldercapped", null); - + // FinSet setters.put("FinSet:fincount", new IntSetter( Reflection.findMethod(FinSet.class, "setFinCount", int.class))); @@ -325,7 +325,7 @@ class DocumentConfig { setters.put("FinSet:tablength", new DoubleSetter( Reflection.findMethod(FinSet.class, "setTabLength", double.class))); setters.put("FinSet:tabposition", new FinTabPositionSetter()); - + // TrapezoidFinSet setters.put("TrapezoidFinSet:rootchord", new DoubleSetter( Reflection.findMethod(TrapezoidFinSet.class, "setRootChord", double.class))); @@ -335,15 +335,15 @@ class DocumentConfig { Reflection.findMethod(TrapezoidFinSet.class, "setSweep", double.class))); setters.put("TrapezoidFinSet:height", new DoubleSetter( Reflection.findMethod(TrapezoidFinSet.class, "setHeight", double.class))); - + // EllipticalFinSet setters.put("EllipticalFinSet:rootchord", new DoubleSetter( Reflection.findMethod(EllipticalFinSet.class, "setLength", double.class))); setters.put("EllipticalFinSet:height", new DoubleSetter( Reflection.findMethod(EllipticalFinSet.class, "setHeight", double.class))); - + // FreeformFinSet points handled as a special handler - + // LaunchLug setters.put("LaunchLug:radius", new DoubleSetter( Reflection.findMethod(LaunchLug.class, "setOuterRadius", double.class))); @@ -354,14 +354,14 @@ class DocumentConfig { setters.put("LaunchLug:radialdirection", new DoubleSetter( Reflection.findMethod(LaunchLug.class, "setRadialDirection", double.class), Math.PI / 180.0)); - + // InternalComponent - nothing - + // StructuralComponent setters.put("StructuralComponent:material", new MaterialSetter( Reflection.findMethod(StructuralComponent.class, "setMaterial", Material.class), Material.Type.BULK)); - + // RingComponent setters.put("RingComponent:length", new DoubleSetter( Reflection.findMethod(RingComponent.class, "setLength", double.class))); @@ -370,23 +370,23 @@ class DocumentConfig { setters.put("RingComponent:radialdirection", new DoubleSetter( Reflection.findMethod(RingComponent.class, "setRadialDirection", double.class), Math.PI / 180.0)); - + // ThicknessRingComponent - radius on separate components due to differing automatics setters.put("ThicknessRingComponent:thickness", new DoubleSetter( Reflection.findMethod(ThicknessRingComponent.class, "setThickness", double.class))); - + // EngineBlock setters.put("EngineBlock:outerradius", new DoubleSetter( Reflection.findMethod(EngineBlock.class, "setOuterRadius", double.class), "auto", Reflection.findMethod(EngineBlock.class, "setOuterRadiusAutomatic", boolean.class))); - + // TubeCoupler setters.put("TubeCoupler:outerradius", new DoubleSetter( Reflection.findMethod(TubeCoupler.class, "setOuterRadius", double.class), "auto", Reflection.findMethod(TubeCoupler.class, "setOuterRadiusAutomatic", boolean.class))); - + // InnerTube setters.put("InnerTube:outerradius", new DoubleSetter( Reflection.findMethod(InnerTube.class, "setOuterRadius", double.class))); @@ -396,9 +396,9 @@ class DocumentConfig { setters.put("InnerTube:clusterrotation", new DoubleSetter( Reflection.findMethod(InnerTube.class, "setClusterRotation", double.class), Math.PI / 180.0)); - + // RadiusRingComponent - + // Bulkhead setters.put("RadiusRingComponent:innerradius", new DoubleSetter( Reflection.findMethod(RadiusRingComponent.class, "setInnerRadius", double.class))); @@ -406,7 +406,7 @@ class DocumentConfig { Reflection.findMethod(Bulkhead.class, "setOuterRadius", double.class), "auto", Reflection.findMethod(Bulkhead.class, "setOuterRadiusAutomatic", boolean.class))); - + // CenteringRing setters.put("CenteringRing:innerradius", new DoubleSetter( Reflection.findMethod(CenteringRing.class, "setInnerRadius", double.class), @@ -416,8 +416,8 @@ class DocumentConfig { Reflection.findMethod(CenteringRing.class, "setOuterRadius", double.class), "auto", Reflection.findMethod(CenteringRing.class, "setOuterRadiusAutomatic", boolean.class))); - - + + // MassObject setters.put("MassObject:packedlength", new DoubleSetter( Reflection.findMethod(MassObject.class, "setLength", double.class))); @@ -428,18 +428,18 @@ class DocumentConfig { setters.put("MassObject:radialdirection", new DoubleSetter( Reflection.findMethod(MassObject.class, "setRadialDirection", double.class), Math.PI / 180.0)); - + // MassComponent setters.put("MassComponent:mass", new DoubleSetter( Reflection.findMethod(MassComponent.class, "setComponentMass", double.class))); - + // ShockCord setters.put("ShockCord:cordlength", new DoubleSetter( Reflection.findMethod(ShockCord.class, "setCordLength", double.class))); setters.put("ShockCord:material", new MaterialSetter( Reflection.findMethod(ShockCord.class, "setMaterial", Material.class), Material.Type.LINE)); - + // RecoveryDevice setters.put("RecoveryDevice:cd", new DoubleSetter( Reflection.findMethod(RecoveryDevice.class, "setCD", double.class), @@ -455,7 +455,7 @@ class DocumentConfig { setters.put("RecoveryDevice:material", new MaterialSetter( Reflection.findMethod(RecoveryDevice.class, "setMaterial", Material.class), Material.Type.SURFACE)); - + // Parachute setters.put("Parachute:diameter", new DoubleSetter( Reflection.findMethod(Parachute.class, "setDiameter", double.class))); @@ -466,13 +466,13 @@ class DocumentConfig { setters.put("Parachute:linematerial", new MaterialSetter( Reflection.findMethod(Parachute.class, "setLineMaterial", Material.class), Material.Type.LINE)); - + // Streamer setters.put("Streamer:striplength", new DoubleSetter( Reflection.findMethod(Streamer.class, "setStripLength", double.class))); setters.put("Streamer:stripwidth", new DoubleSetter( Reflection.findMethod(Streamer.class, "setStripWidth", double.class))); - + // Rocket // handled by separate handler setters.put("Rocket:referencetype", new EnumSetter( @@ -484,17 +484,17 @@ class DocumentConfig { Reflection.findMethod(Rocket.class, "setDesigner", String.class))); setters.put("Rocket:revision", new StringSetter( Reflection.findMethod(Rocket.class, "setRevision", String.class))); - + // Stage setters.put("Stage:separationevent", new EnumSetter( Reflection.findMethod(Stage.class, "setSeparationEvent", Stage.SeparationEvent.class), Stage.SeparationEvent.class)); setters.put("Stage:separationdelay", new DoubleSetter( Reflection.findMethod(Stage.class, "setSeparationDelay", double.class))); - + } - - + + /** * Search for a enum value that has the corresponding name as an XML value. The current * conversion from enum name to XML value is to lowercase the name and strip out all @@ -508,7 +508,7 @@ class DocumentConfig { */ public static > Enum findEnum(String name, Class> enumClass) { - + if (name == null) return null; name = name.trim(); @@ -519,8 +519,8 @@ class DocumentConfig { } return null; } - - + + /** * Convert a string to a double including formatting specifications of the OpenRocket * file format. This accepts all formatting that is valid for @@ -554,11 +554,11 @@ class DocumentConfig { class OpenRocketHandler extends AbstractElementHandler { private final DocumentLoadingContext context; private OpenRocketContentHandler handler = null; - + public OpenRocketHandler(DocumentLoadingContext context) { this.context = context; } - + /** * Return the OpenRocketDocument read from the file, or null if a document * has not been read yet. @@ -568,24 +568,24 @@ class OpenRocketHandler extends AbstractElementHandler { public OpenRocketDocument getDocument() { return handler.getDocument(); } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - + // Check for unknown elements if (!element.equals("openrocket")) { warnings.add(Warning.fromString("Unknown element " + element + ", ignoring.")); return null; } - + // Check for first call if (handler != null) { warnings.add(Warning.fromString("Multiple document elements found, ignoring later " + "ones.")); return null; } - + // Check version number String version = null; String creator = attributes.remove("creator"); @@ -605,18 +605,18 @@ class OpenRocketHandler extends AbstractElementHandler { str += ", attempting to read file anyway."; warnings.add(str); } - + context.setFileVersion(parseVersion(docVersion)); - + handler = new OpenRocketContentHandler(context); return handler; } - - + + private int parseVersion(String docVersion) { if (docVersion == null) return 0; - + Matcher m = Pattern.compile("^([0-9]+)\\.([0-9]+)$").matcher(docVersion); if (m.matches()) { int major = Integer.parseInt(m.group(1)); @@ -626,7 +626,7 @@ class OpenRocketHandler extends AbstractElementHandler { return 0; } } - + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { @@ -634,8 +634,8 @@ class OpenRocketHandler extends AbstractElementHandler { attributes.remove("creator"); super.closeElement(element, attributes, content, warnings); } - - + + } @@ -646,27 +646,27 @@ class OpenRocketContentHandler extends AbstractElementHandler { private final DocumentLoadingContext context; private final OpenRocketDocument doc; private final Rocket rocket; - + private boolean rocketDefined = false; private boolean simulationsDefined = false; private boolean datatypesDefined = false; - + public OpenRocketContentHandler(DocumentLoadingContext context) { this.context = context; this.rocket = new Rocket(); this.doc = new OpenRocketDocument(rocket); } - + public OpenRocketDocument getDocument() { if (!rocketDefined) return null; return doc; } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - + if (element.equals("rocket")) { if (rocketDefined) { warnings.add(Warning @@ -678,7 +678,7 @@ class OpenRocketContentHandler extends AbstractElementHandler { return new ComponentParameterHandler(rocket, context); } - if (element.equals("datatypes")){ + if (element.equals("datatypes")) { if (datatypesDefined) { warnings.add(Warning.fromString("Multiple datatype blocks. Ignoring later ones.")); return null; @@ -686,7 +686,7 @@ class OpenRocketContentHandler extends AbstractElementHandler { datatypesDefined = true; return new DatatypeHandler(this, context); } - + if (element.equals("simulations")) { if (simulationsDefined) { warnings.add(Warning @@ -697,9 +697,9 @@ class OpenRocketContentHandler extends AbstractElementHandler { simulationsDefined = true; return new SimulationsHandler(doc, context); } - + warnings.add(Warning.fromString("Unknown element " + element + ", ignoring.")); - + return null; } } @@ -721,7 +721,7 @@ class DatatypeHandler extends AbstractElementHandler { HashMap attributes, WarningSet warnings) throws SAXException { - if (element.equals("type") && attributes.get("source").equals("customexpression") ){ + if (element.equals("type") && attributes.get("source").equals("customexpression")) { customExpressionHandler = new CustomExpressionHandler(contentHandler, context); return customExpressionHandler; } @@ -737,7 +737,7 @@ class DatatypeHandler extends AbstractElementHandler { attributes.remove("source"); super.closeElement(element, attributes, content, warnings); - if (customExpressionHandler != null){ + if (customExpressionHandler != null) { contentHandler.getDocument().addCustomExpression(customExpressionHandler.currentExpression); } @@ -745,7 +745,7 @@ class DatatypeHandler extends AbstractElementHandler { } -class CustomExpressionHandler extends AbstractElementHandler{ +class CustomExpressionHandler extends AbstractElementHandler { private final DocumentLoadingContext context; private final OpenRocketContentHandler contentHandler; public CustomExpression currentExpression; @@ -754,29 +754,29 @@ class CustomExpressionHandler extends AbstractElementHandler{ this.context = context; this.contentHandler = contentHandler; currentExpression = new CustomExpression(contentHandler.getDocument()); - + } @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) throws SAXException { - + return this; } @Override public void closeElement(String element, HashMap attributes, - String content, WarningSet warnings) throws SAXException { - + String content, WarningSet warnings) throws SAXException { + if (element.equals("type")) { contentHandler.getDocument().addCustomExpression(currentExpression); } - + if (element.equals("name")) { currentExpression.setName(content); } - + if (element.equals("symbol")) { currentExpression.setSymbol(content); } @@ -785,10 +785,10 @@ class CustomExpressionHandler extends AbstractElementHandler{ currentExpression.setUnit(content); } - if (element.equals("expression")){ + if (element.equals("expression")) { currentExpression.setExpression(content); } - } + } } /** @@ -798,16 +798,16 @@ class CustomExpressionHandler extends AbstractElementHandler{ class ComponentHandler extends AbstractElementHandler { private final DocumentLoadingContext context; private final RocketComponent parent; - + public ComponentHandler(RocketComponent parent, DocumentLoadingContext context) { this.parent = parent; this.context = context; } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - + // Attempt to construct new component Constructor constructor = DocumentConfig.constructors .get(element); @@ -815,7 +815,7 @@ class ComponentHandler extends AbstractElementHandler { warnings.add(Warning.fromString("Unknown element " + element + ", ignoring.")); return null; } - + RocketComponent c; try { c = constructor.newInstance(); @@ -826,9 +826,9 @@ class ComponentHandler extends AbstractElementHandler { } catch (InvocationTargetException e) { throw Reflection.handleWrappedException(e); } - + parent.addChild(c); - + return new ComponentParameterHandler(c, context); } } @@ -842,16 +842,16 @@ class ComponentHandler extends AbstractElementHandler { class ComponentParameterHandler extends AbstractElementHandler { private final DocumentLoadingContext context; private final RocketComponent component; - + public ComponentParameterHandler(RocketComponent c, DocumentLoadingContext context) { this.component = c; this.context = context; } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - + // Check for specific elements that contain other elements if (element.equals("subcomponents")) { return new ComponentHandler(component, context); @@ -877,22 +877,22 @@ class ComponentParameterHandler extends AbstractElementHandler { } return new MotorConfigurationHandler((Rocket) component, context); } - - + + return PlainTextHandler.INSTANCE; } - + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) { - + if (element.equals("subcomponents") || element.equals("motormount") || element.equals("finpoints") || element.equals("motorconfiguration")) { return; } - + // Search for the correct setter class - + Class c; for (c = component.getClass(); c != null; c = c.getSuperclass()) { String setterKey = c.getSimpleName() + ":" + element; @@ -925,23 +925,23 @@ class FinSetPointHandler extends AbstractElementHandler { private final DocumentLoadingContext context; private final FreeformFinSet finset; private final ArrayList coordinates = new ArrayList(); - + public FinSetPointHandler(FreeformFinSet finset, DocumentLoadingContext context) { this.finset = finset; this.context = context; } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { return PlainTextHandler.INSTANCE; } - - + + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { - + String strx = attributes.remove("x"); String stry = attributes.remove("y"); if (strx == null || stry == null) { @@ -956,10 +956,10 @@ class FinSetPointHandler extends AbstractElementHandler { warnings.add(Warning.fromString("Illegal fin points specification, ignoring.")); return; } - + super.closeElement(element, attributes, content, warnings); } - + @Override public void endHandler(String element, HashMap attributes, String content, WarningSet warnings) { @@ -976,51 +976,51 @@ class MotorMountHandler extends AbstractElementHandler { private final DocumentLoadingContext context; private final MotorMount mount; private MotorHandler motorHandler; - + public MotorMountHandler(MotorMount mount, DocumentLoadingContext context) { this.mount = mount; this.context = context; mount.setMotorMount(true); } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - + if (element.equals("motor")) { motorHandler = new MotorHandler(context); return motorHandler; } - + if (element.equals("ignitionevent") || element.equals("ignitiondelay") || element.equals("overhang")) { return PlainTextHandler.INSTANCE; } - + warnings.add(Warning.fromString("Unknown element '" + element + "' encountered, ignoring.")); return null; } - - - + + + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { - + if (element.equals("motor")) { String id = attributes.get("configid"); if (id == null || id.equals("")) { warnings.add(Warning.fromString("Illegal motor specification, ignoring.")); return; } - + Motor motor = motorHandler.getMotor(warnings); mount.setMotor(id, motor); mount.setMotorDelay(id, motorHandler.getDelay(warnings)); return; } - + if (element.equals("ignitionevent")) { MotorMount.IgnitionEvent event = null; for (MotorMount.IgnitionEvent e : MotorMount.IgnitionEvent.values()) { @@ -1036,7 +1036,7 @@ class MotorMountHandler extends AbstractElementHandler { mount.setIgnitionEvent(event); return; } - + if (element.equals("ignitiondelay")) { double d; try { @@ -1048,7 +1048,7 @@ class MotorMountHandler extends AbstractElementHandler { mount.setIgnitionDelay(d); return; } - + if (element.equals("overhang")) { double d; try { @@ -1060,7 +1060,7 @@ class MotorMountHandler extends AbstractElementHandler { mount.setMotorOverhang(d); return; } - + super.closeElement(element, attributes, content, warnings); } } @@ -1074,54 +1074,54 @@ class MotorConfigurationHandler extends AbstractElementHandler { private final Rocket rocket; private String name = null; private boolean inNameElement = false; - + public MotorConfigurationHandler(Rocket rocket, DocumentLoadingContext context) { this.rocket = rocket; this.context = context; } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - + if (inNameElement || !element.equals("name")) { warnings.add(Warning.FILE_INVALID_PARAMETER); return null; } inNameElement = true; - + return PlainTextHandler.INSTANCE; } - + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) { name = content; } - + @Override public void endHandler(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { - + String configid = attributes.remove("configid"); if (configid == null || configid.equals("")) { warnings.add(Warning.FILE_INVALID_PARAMETER); return; } - + if (!rocket.addMotorConfigurationID(configid)) { warnings.add("Duplicate motor configuration ID used."); return; } - + if (name != null && name.trim().length() > 0) { rocket.setMotorConfigurationName(configid, name); } - + if ("true".equals(attributes.remove("default"))) { rocket.getDefaultConfiguration().setMotorConfigurationID(configid); } - + super.closeElement(element, attributes, content, warnings); } } @@ -1130,7 +1130,7 @@ class MotorConfigurationHandler extends AbstractElementHandler { class MotorHandler extends AbstractElementHandler { /** File version where latest digest format was introduced */ private static final int MOTOR_DIGEST_VERSION = 104; - + private final DocumentLoadingContext context; private Motor.Type type = null; private String manufacturer = null; @@ -1139,26 +1139,26 @@ class MotorHandler extends AbstractElementHandler { private double diameter = Double.NaN; private double length = Double.NaN; private double delay = Double.NaN; - + public MotorHandler(DocumentLoadingContext context) { this.context = context; } - - + + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { return PlainTextHandler.INSTANCE; } - - + + /** * Return the motor to use, or null. */ public Motor getMotor(WarningSet warnings) { return context.getMotorFinder().findMotor(type, manufacturer, designation, diameter, length, digest, warnings); } - + /** * Return the delay to use for the motor. */ @@ -1169,16 +1169,16 @@ class MotorHandler extends AbstractElementHandler { } return delay; } - - + + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { - + content = content.trim(); - + if (element.equals("type")) { - + // Motor type type = null; for (Motor.Type t : Motor.Type.values()) { @@ -1190,26 +1190,26 @@ class MotorHandler extends AbstractElementHandler { if (type == null) { warnings.add(Warning.fromString("Unknown motor type '" + content + "', ignoring.")); } - + } else if (element.equals("manufacturer")) { - + // Manufacturer manufacturer = content.trim(); - + } else if (element.equals("designation")) { - + // Designation designation = content.trim(); - + } else if (element.equals("digest")) { - + // Digest is used only for file versions saved using the same digest algorithm if (context.getFileVersion() >= MOTOR_DIGEST_VERSION) { digest = content.trim(); } - + } else if (element.equals("diameter")) { - + // Diameter diameter = Double.NaN; try { @@ -1220,22 +1220,22 @@ class MotorHandler extends AbstractElementHandler { if (Double.isNaN(diameter)) { warnings.add(Warning.fromString("Illegal motor diameter specified, ignoring.")); } - + } else if (element.equals("length")) { - + // Length length = Double.NaN; try { length = Double.parseDouble(content.trim()); } catch (NumberFormatException ignore) { } - + if (Double.isNaN(length)) { warnings.add(Warning.fromString("Illegal motor diameter specified, ignoring.")); } - + } else if (element.equals("delay")) { - + // Delay delay = Double.NaN; if (content.equals("none")) { @@ -1245,18 +1245,18 @@ class MotorHandler extends AbstractElementHandler { delay = Double.parseDouble(content.trim()); } catch (NumberFormatException ignore) { } - + if (Double.isNaN(delay)) { warnings.add(Warning.fromString("Illegal motor delay specified, ignoring.")); } - + } - + } else { super.closeElement(element, attributes, content, warnings); } } - + } @@ -1265,61 +1265,61 @@ class SimulationsHandler extends AbstractElementHandler { private final DocumentLoadingContext context; private final OpenRocketDocument doc; private SingleSimulationHandler handler; - + public SimulationsHandler(OpenRocketDocument doc, DocumentLoadingContext context) { this.doc = doc; this.context = context; } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - + if (!element.equals("simulation")) { warnings.add("Unknown element '" + element + "', ignoring."); return null; } - + handler = new SingleSimulationHandler(doc, context); return handler; } - + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { attributes.remove("status"); super.closeElement(element, attributes, content, warnings); } - - + + } class SingleSimulationHandler extends AbstractElementHandler { - + private final DocumentLoadingContext context; - + private final OpenRocketDocument doc; - + private String name; - + private SimulationConditionsHandler conditionHandler; private FlightDataHandler dataHandler; private final List listeners = new ArrayList(); - + public SingleSimulationHandler(OpenRocketDocument doc, DocumentLoadingContext context) { this.doc = doc; this.context = context; } - - public OpenRocketDocument getDocument(){ + + public OpenRocketDocument getDocument() { return doc; } @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - + if (element.equals("name") || element.equals("simulator") || element.equals("calculator") || element.equals("listener")) { return PlainTextHandler.INSTANCE; @@ -1334,11 +1334,11 @@ class SingleSimulationHandler extends AbstractElementHandler { return null; } } - + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) { - + if (element.equals("name")) { name = content; } else if (element.equals("simulator")) { @@ -1352,20 +1352,20 @@ class SingleSimulationHandler extends AbstractElementHandler { } else if (element.equals("listener") && content.trim().length() > 0) { listeners.add(content.trim()); } - + } - + @Override public void endHandler(String element, HashMap attributes, String content, WarningSet warnings) { - + String s = attributes.get("status"); Simulation.Status status = (Status) DocumentConfig.findEnum(s, Simulation.Status.class); if (status == null) { warnings.add("Simulation status unknown, assuming outdated."); status = Simulation.Status.OUTDATED; } - + SimulationOptions conditions; if (conditionHandler != null) { conditions = conditionHandler.getConditions(); @@ -1373,39 +1373,39 @@ class SingleSimulationHandler extends AbstractElementHandler { warnings.add("Simulation conditions not defined, using defaults."); conditions = new SimulationOptions(doc.getRocket()); } - + if (name == null) name = "Simulation"; - + FlightData data; if (dataHandler == null) data = null; else data = dataHandler.getFlightData(); - + Simulation simulation = new Simulation(doc.getRocket(), status, name, conditions, listeners, data); - + doc.addSimulation(simulation); } } - + class SimulationConditionsHandler extends AbstractElementHandler { private final DocumentLoadingContext context; private SimulationOptions conditions; private AtmosphereHandler atmosphereHandler; - + public SimulationConditionsHandler(Rocket rocket, DocumentLoadingContext context) { this.context = context; conditions = new SimulationOptions(rocket); // Set up default loading settings (which may differ from the new defaults) conditions.setGeodeticComputation(GeodeticComputationStrategy.FLAT); } - + public SimulationOptions getConditions() { return conditions; } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { @@ -1415,18 +1415,18 @@ class SimulationConditionsHandler extends AbstractElementHandler { } return PlainTextHandler.INSTANCE; } - + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) { - + double d = Double.NaN; try { d = Double.parseDouble(content); } catch (NumberFormatException ignore) { } - - + + if (element.equals("configid")) { if (content.equals("")) { conditions.setMotorConfigurationID(null); @@ -1508,28 +1508,28 @@ class AtmosphereHandler extends AbstractElementHandler { private final String model; private double temperature = Double.NaN; private double pressure = Double.NaN; - + public AtmosphereHandler(String model, DocumentLoadingContext context) { this.model = model; this.context = context; } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { return PlainTextHandler.INSTANCE; } - + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { - + double d = Double.NaN; try { d = Double.parseDouble(content); } catch (NumberFormatException ignore) { } - + if (element.equals("basetemperature")) { if (Double.isNaN(d)) { warnings.add("Illegal base temperature specified, ignoring."); @@ -1544,8 +1544,8 @@ class AtmosphereHandler extends AbstractElementHandler { super.closeElement(element, attributes, content, warnings); } } - - + + public void storeSettings(SimulationOptions cond, WarningSet warnings) { if (!Double.isNaN(pressure)) { cond.setLaunchPressure(pressure); @@ -1553,7 +1553,7 @@ class AtmosphereHandler extends AbstractElementHandler { if (!Double.isNaN(temperature)) { cond.setLaunchTemperature(temperature); } - + if ("isa".equals(model)) { cond.setISAAtmosphere(true); } else if ("extendedisa".equals(model)) { @@ -1563,34 +1563,34 @@ class AtmosphereHandler extends AbstractElementHandler { warnings.add("Unknown atmospheric model, using ISA."); } } - + } class FlightDataHandler extends AbstractElementHandler { private final DocumentLoadingContext context; - + private FlightDataBranchHandler dataHandler; private WarningSet warningSet = new WarningSet(); private List branches = new ArrayList(); private SingleSimulationHandler simHandler; private FlightData data; - - + + public FlightDataHandler(SingleSimulationHandler simHandler, DocumentLoadingContext context) { this.context = context; this.simHandler = simHandler; } - + public FlightData getFlightData() { return data; } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - + if (element.equals("warning")) { return PlainTextHandler.INSTANCE; } @@ -1599,21 +1599,21 @@ class FlightDataHandler extends AbstractElementHandler { warnings.add("Illegal flight data definition, ignoring."); return null; } - dataHandler = new FlightDataBranchHandler( attributes.get("name"), - attributes.get("types"), - simHandler, context); + dataHandler = new FlightDataBranchHandler(attributes.get("name"), + attributes.get("types"), + simHandler, context); return dataHandler; } - + warnings.add("Unknown element '" + element + "' encountered, ignoring."); return null; } - - + + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) { - + if (element.equals("databranch")) { FlightDataBranch branch = dataHandler.getBranch(); if (branch.getLength() > 0) { @@ -1623,12 +1623,12 @@ class FlightDataHandler extends AbstractElementHandler { warningSet.add(Warning.fromString(content)); } } - - + + @Override public void endHandler(String element, HashMap attributes, String content, WarningSet warnings) { - + if (branches.size() > 0) { data = new FlightData(branches.toArray(new FlightDataBranch[0])); } else { @@ -1641,7 +1641,7 @@ class FlightDataHandler extends AbstractElementHandler { double groundHitVelocity = Double.NaN; double launchRodVelocity = Double.NaN; double deploymentVelocity = Double.NaN; - + try { maxAltitude = DocumentConfig.stringToDouble(attributes.get("maxaltitude")); } catch (NumberFormatException ignore) { @@ -1679,16 +1679,16 @@ class FlightDataHandler extends AbstractElementHandler { deploymentVelocity = DocumentConfig.stringToDouble(attributes.get("deploymentvelocity")); } catch (NumberFormatException ignore) { } - + data = new FlightData(maxAltitude, maxVelocity, maxAcceleration, maxMach, timeToApogee, flightTime, groundHitVelocity, launchRodVelocity, deploymentVelocity); } - + data.getWarningSet().addAll(warningSet); data.immute(); } - - + + } @@ -1712,7 +1712,7 @@ class FlightDataBranchHandler extends AbstractElementHandler { types[i] = matching; //types[i] = FlightDataType.getType(typeName, matching.getSymbol(), matching.getUnitGroup()); } - + // TODO: LOW: May throw an IllegalArgumentException branch = new FlightDataBranch(name, types); } @@ -1720,9 +1720,9 @@ class FlightDataBranchHandler extends AbstractElementHandler { // Find the full flight data type given name only // Note: this way of doing it requires that custom expressions always come before flight data in the file, // not the nicest but this is always the case anyway. - private FlightDataType findFlightDataType(String name){ + private FlightDataType findFlightDataType(String name) { - // Kevins version with lookup by key. Not using right now + // Kevins version with lookup by key. Not using right now /* if ( key != null ) { for (FlightDataType t : FlightDataType.ALL_TYPES){ @@ -1732,84 +1732,84 @@ class FlightDataBranchHandler extends AbstractElementHandler { } } */ - + // Look in built in types - for (FlightDataType t : FlightDataType.ALL_TYPES){ - if (t.getName().equals(name) ){ + for (FlightDataType t : FlightDataType.ALL_TYPES) { + if (t.getName().equals(name)) { return t; } } // Look in custom expressions - for (CustomExpression exp : simHandler.getDocument().getCustomExpressions()){ - if (exp.getName().equals(name) ){ + for (CustomExpression exp : simHandler.getDocument().getCustomExpressions()) { + if (exp.getName().equals(name)) { return exp.getType(); } } - log.warn("Could not find the flight data type '"+name+"' used in the XML file. Substituted type with unknown symbol and units."); + log.warn("Could not find the flight data type '" + name + "' used in the XML file. Substituted type with unknown symbol and units."); return FlightDataType.getType(name, "Unknown", UnitGroup.UNITS_NONE); } - + public FlightDataBranch getBranch() { branch.immute(); return branch; } - + @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - + if (element.equals("datapoint")) return PlainTextHandler.INSTANCE; if (element.equals("event")) return PlainTextHandler.INSTANCE; - + warnings.add("Unknown element '" + element + "' encountered, ignoring."); return null; } - - + + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) { - + if (element.equals("event")) { double time; FlightEvent.Type type; - + try { time = DocumentConfig.stringToDouble(attributes.get("time")); } catch (NumberFormatException e) { warnings.add("Illegal event specification, ignoring."); return; } - + type = (Type) DocumentConfig.findEnum(attributes.get("type"), FlightEvent.Type.class); if (type == null) { warnings.add("Illegal event specification, ignoring."); return; } - + branch.addEvent(new FlightEvent(type, time)); return; } - + if (!element.equals("datapoint")) { warnings.add("Unknown element '" + element + "' encountered, ignoring."); return; } - + // element == "datapoint" - - + + // Check line format String[] split = content.split(","); if (split.length != types.length) { warnings.add("Data point did not contain correct amount of values, ignoring point."); return; } - + // Parse the doubles double[] values = new double[split.length]; for (int i = 0; i < values.length; i++) { @@ -1820,7 +1820,7 @@ class FlightDataBranchHandler extends AbstractElementHandler { return; } } - + // Add point to branch branch.addPoint(); for (int i = 0; i < types.length; i++) { @@ -1854,11 +1854,11 @@ interface Setter { //// StringSetter - sets the value to the contained String class StringSetter implements Setter { private final Reflection.Method setMethod; - + public StringSetter(Reflection.Method set) { setMethod = set; } - + @Override public void set(RocketComponent c, String s, HashMap attributes, WarningSet warnings) { @@ -1869,11 +1869,11 @@ class StringSetter implements Setter { //// IntSetter - set an integer value class IntSetter implements Setter { private final Reflection.Method setMethod; - + public IntSetter(Reflection.Method set) { setMethod = set; } - + @Override public void set(RocketComponent c, String s, HashMap attributes, WarningSet warnings) { @@ -1890,15 +1890,15 @@ class IntSetter implements Setter { //// BooleanSetter - set a boolean value class BooleanSetter implements Setter { private final Reflection.Method setMethod; - + public BooleanSetter(Reflection.Method set) { setMethod = set; } - + @Override public void set(RocketComponent c, String s, HashMap attributes, WarningSet warnings) { - + s = s.trim(); if (s.equalsIgnoreCase("true")) { setMethod.invoke(c, true); @@ -1919,7 +1919,7 @@ class DoubleSetter implements Setter { private final String specialString; private final Reflection.Method specialMethod; private final double multiplier; - + /** * Set only the double value. * @param set set method for the double value. @@ -1930,7 +1930,7 @@ class DoubleSetter implements Setter { this.specialMethod = null; this.multiplier = 1.0; } - + /** * Multiply with the given multiplier and set the double value. * @param set set method for the double value. @@ -1942,7 +1942,7 @@ class DoubleSetter implements Setter { this.specialMethod = null; this.multiplier = mul; } - + /** * Set the double value, or if the value equals the special string, use the * special setter and set it to true. @@ -1958,20 +1958,20 @@ class DoubleSetter implements Setter { this.specialMethod = specialMethod; this.multiplier = 1.0; } - - + + @Override public void set(RocketComponent c, String s, HashMap attributes, WarningSet warnings) { - + s = s.trim(); - + // Check for special case if (specialMethod != null && s.equalsIgnoreCase(specialString)) { specialMethod.invoke(c, true); return; } - + // Normal case try { double d = Double.parseDouble(s); @@ -1986,16 +1986,16 @@ class DoubleSetter implements Setter { class OverrideSetter implements Setter { private final Reflection.Method setMethod; private final Reflection.Method enabledMethod; - + public OverrideSetter(Reflection.Method set, Reflection.Method enabledMethod) { this.setMethod = set; this.enabledMethod = enabledMethod; } - + @Override public void set(RocketComponent c, String s, HashMap attributes, WarningSet warnings) { - + try { double d = Double.parseDouble(s); setMethod.invoke(c, d); @@ -2010,22 +2010,22 @@ class OverrideSetter implements Setter { class EnumSetter> implements Setter { private final Reflection.Method setter; private final Class enumClass; - + public EnumSetter(Reflection.Method set, Class enumClass) { this.setter = set; this.enumClass = enumClass; } - + @Override public void set(RocketComponent c, String name, HashMap attributes, WarningSet warnings) { - + Enum setEnum = DocumentConfig.findEnum(name, enumClass); if (setEnum == null) { warnings.add(Warning.FILE_INVALID_PARAMETER); return; } - + setter.invoke(c, setEnum); } } @@ -2034,24 +2034,24 @@ class EnumSetter> implements Setter { //// ColorSetter - sets a Color value class ColorSetter implements Setter { private final Reflection.Method setMethod; - + public ColorSetter(Reflection.Method set) { setMethod = set; } - + @Override public void set(RocketComponent c, String s, HashMap attributes, WarningSet warnings) { - + String red = attributes.get("red"); String green = attributes.get("green"); String blue = attributes.get("blue"); - + if (red == null || green == null || blue == null) { warnings.add(Warning.FILE_INVALID_PARAMETER); return; } - + int r, g, b; try { r = Integer.parseInt(red); @@ -2061,15 +2061,15 @@ class ColorSetter implements Setter { warnings.add(Warning.FILE_INVALID_PARAMETER); return; } - + if (r < 0 || g < 0 || b < 0 || r > 255 || g > 255 || b > 255) { warnings.add(Warning.FILE_INVALID_PARAMETER); return; } - + Color color = new Color(r, g, b); setMethod.invoke(c, color); - + if (!s.trim().equals("")) { warnings.add(Warning.FILE_INVALID_PARAMETER); } @@ -2078,130 +2078,128 @@ class ColorSetter implements Setter { ////ComponentPresetSetter - sets a ComponentPreset value class ComponentPresetSetter implements Setter { -private final Reflection.Method setMethod; - -public ComponentPresetSetter(Reflection.Method set) { - this.setMethod = set; -} - -@Override -public void set(RocketComponent c, String name, HashMap attributes, - WarningSet warnings) { - String manufacturerName = attributes.get("manufacturer"); - if ( manufacturerName == null ) { - warnings.add(Warning.fromString("Invalid ComponentPreset for component " + c.getName() + ", no manufacturer specified. Ignored")); - return; - } - - String productNo = attributes.get("partno"); - if ( productNo == null ) { - warnings.add(Warning.fromString("Invalid ComponentPreset for component " + c.getName() + ", no partno specified. Ignored")); - return; - } - - String digest = attributes.get("digest"); - if ( digest == null ) { - warnings.add(Warning.fromString("Invalid ComponentPreset for component " + c.getName() + ", no digest specified.")); - } - - String type = attributes.get("type"); - if ( type == null ) { - warnings.add(Warning.fromString("Invalid ComponentPreset for component " + c.getName() + ", no type specified.")); + private final Reflection.Method setMethod; + + public ComponentPresetSetter(Reflection.Method set) { + this.setMethod = set; } - - List presets = Application.getComponentPresetDao().find( manufacturerName, productNo ); - - ComponentPreset matchingPreset = null; - - for( ComponentPreset preset: presets ) { - if ( digest != null && preset.getDigest().equals(digest) ) { - // Found one with matching digest. Take it. - matchingPreset = preset; - break; + + @Override + public void set(RocketComponent c, String name, HashMap attributes, + WarningSet warnings) { + String manufacturerName = attributes.get("manufacturer"); + if (manufacturerName == null) { + warnings.add(Warning.fromString("Invalid ComponentPreset for component " + c.getName() + ", no manufacturer specified. Ignored")); + return; } - if ( type != null && preset.getType().name().equals(type) && matchingPreset != null) { - // Found the first one with matching type. - matchingPreset = preset; + + String productNo = attributes.get("partno"); + if (productNo == null) { + warnings.add(Warning.fromString("Invalid ComponentPreset for component " + c.getName() + ", no partno specified. Ignored")); + return; } + + String digest = attributes.get("digest"); + if (digest == null) { + warnings.add(Warning.fromString("Invalid ComponentPreset for component " + c.getName() + ", no digest specified.")); + } + + String type = attributes.get("type"); + if (type == null) { + warnings.add(Warning.fromString("Invalid ComponentPreset for component " + c.getName() + ", no type specified.")); + } + + List presets = Application.getComponentPresetDao().find(manufacturerName, productNo); + + ComponentPreset matchingPreset = null; + + for (ComponentPreset preset : presets) { + if (digest != null && preset.getDigest().equals(digest)) { + // Found one with matching digest. Take it. + matchingPreset = preset; + break; + } + if (type != null && preset.getType().name().equals(type) && matchingPreset != null) { + // Found the first one with matching type. + matchingPreset = preset; + } + } + + // Was any found? + if (matchingPreset == null) { + warnings.add(Warning.fromString("No matching ComponentPreset for component " + c.getName() + " found matching " + manufacturerName + " " + productNo)); + return; + } + + if (digest != null && !matchingPreset.getDigest().equals(digest)) { + warnings.add(Warning.fromString("ComponentPreset for component " + c.getName() + " has wrong digest")); + } + + setMethod.invoke(c, matchingPreset); } - - // Was any found? - if ( matchingPreset == null ) { - warnings.add(Warning.fromString("No matching ComponentPreset for component " + c.getName() + " found matching " + manufacturerName + " " + productNo)); - return; - } - - if ( digest != null && !matchingPreset.getDigest().equals(digest) ) { - warnings.add(Warning.fromString("ComponentPreset for component " + c.getName() + " has wrong digest")); - } - - setMethod.invoke(c, matchingPreset); -} } ////MaterialSetter - sets a Material value class MaterialSetter implements Setter { -private final Reflection.Method setMethod; -private final Material.Type type; - -public MaterialSetter(Reflection.Method set, Material.Type type) { - this.setMethod = set; - this.type = type; -} - -@Override -public void set(RocketComponent c, String name, HashMap attributes, - WarningSet warnings) { - - Material mat; - - // Check name != "" - name = name.trim(); - if (name.equals("")) { - warnings.add(Warning.fromString("Illegal material specification, ignoring.")); - return; - } - - // Parse density - double density; - String str; - str = attributes.remove("density"); - if (str == null) { - warnings.add(Warning.fromString("Illegal material specification, ignoring.")); - return; - } - try { - density = Double.parseDouble(str); - } catch (NumberFormatException e) { - warnings.add(Warning.fromString("Illegal material specification, ignoring.")); - return; + private final Reflection.Method setMethod; + private final Material.Type type; + + public MaterialSetter(Reflection.Method set, Material.Type type) { + this.setMethod = set; + this.type = type; } - - // Parse thickness - // double thickness = 0; - // str = attributes.remove("thickness"); - // try { - // if (str != null) - // thickness = Double.parseDouble(str); - // } catch (NumberFormatException e){ - // warnings.add(Warning.fromString("Illegal material specification, ignoring.")); - // return; - // } - - // Check type if specified - str = attributes.remove("type"); - if (str != null && !type.name().toLowerCase(Locale.ENGLISH).equals(str)) { - warnings.add(Warning.fromString("Illegal material type specified, ignoring.")); - return; + + @Override + public void set(RocketComponent c, String name, HashMap attributes, + WarningSet warnings) { + + Material mat; + + // Check name != "" + name = name.trim(); + if (name.equals("")) { + warnings.add(Warning.fromString("Illegal material specification, ignoring.")); + return; + } + + // Parse density + double density; + String str; + str = attributes.remove("density"); + if (str == null) { + warnings.add(Warning.fromString("Illegal material specification, ignoring.")); + return; + } + try { + density = Double.parseDouble(str); + } catch (NumberFormatException e) { + warnings.add(Warning.fromString("Illegal material specification, ignoring.")); + return; + } + + // Parse thickness + // double thickness = 0; + // str = attributes.remove("thickness"); + // try { + // if (str != null) + // thickness = Double.parseDouble(str); + // } catch (NumberFormatException e){ + // warnings.add(Warning.fromString("Illegal material specification, ignoring.")); + // return; + // } + + // Check type if specified + str = attributes.remove("type"); + if (str != null && !type.name().toLowerCase(Locale.ENGLISH).equals(str)) { + warnings.add(Warning.fromString("Illegal material type specified, ignoring.")); + return; + } + + mat = Databases.findMaterial(type, name, density); + + setMethod.invoke(c, mat); } - - String key = attributes.remove("key"); - - mat = Databases.findMaterial(type, key, name, density); - - setMethod.invoke(c, mat); -} } @@ -2209,18 +2207,18 @@ public void set(RocketComponent c, String name, HashMap attribut class PositionSetter implements Setter { - + @Override public void set(RocketComponent c, String value, HashMap attributes, WarningSet warnings) { - + RocketComponent.Position type = (Position) DocumentConfig.findEnum(attributes.get("type"), RocketComponent.Position.class); if (type == null) { warnings.add(Warning.FILE_INVALID_PARAMETER); return; } - + double pos; try { pos = Double.parseDouble(value); @@ -2228,7 +2226,7 @@ class PositionSetter implements Setter { warnings.add(Warning.FILE_INVALID_PARAMETER); return; } - + if (c instanceof FinSet) { ((FinSet) c).setRelativePosition(type); c.setPositionValue(pos); @@ -2241,34 +2239,34 @@ class PositionSetter implements Setter { } else { warnings.add(Warning.FILE_INVALID_PARAMETER); } - + } } class FinTabPositionSetter extends DoubleSetter { - + public FinTabPositionSetter() { super(Reflection.findMethod(FinSet.class, "setTabShift", double.class)); } - + @Override public void set(RocketComponent c, String s, HashMap attributes, WarningSet warnings) { - + if (!(c instanceof FinSet)) { throw new IllegalStateException("FinTabPositionSetter called for component " + c); } - + String relative = attributes.get("relativeto"); FinSet.TabRelativePosition position = (TabRelativePosition) DocumentConfig.findEnum(relative, FinSet.TabRelativePosition.class); - + if (position != null) { - + ((FinSet) c).setTabRelativePosition(position); - + } else { if (relative == null) { warnings.add("Required attribute 'relativeto' not found for fin tab position."); @@ -2276,25 +2274,25 @@ class FinTabPositionSetter extends DoubleSetter { warnings.add("Illegal attribute value '" + relative + "' encountered."); } } - + super.set(c, s, attributes, warnings); } - - + + } class ClusterConfigurationSetter implements Setter { - + @Override public void set(RocketComponent component, String value, HashMap attributes, WarningSet warnings) { - + if (!(component instanceof Clusterable)) { warnings.add("Illegal component defined as cluster."); return; } - + ClusterConfiguration config = null; for (ClusterConfiguration c : ClusterConfiguration.CONFIGURATIONS) { if (c.getXMLName().equals(value)) { @@ -2302,12 +2300,12 @@ class ClusterConfigurationSetter implements Setter { break; } } - + if (config == null) { warnings.add("Illegal cluster configuration specified."); return; } - + ((Clusterable) component).setClusterConfiguration(config); } } diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java index 0380eedc..a4892902 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Locale; import net.sf.openrocket.file.RocketSaver; +import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.ThrustCurveMotor; @@ -14,28 +15,30 @@ import net.sf.openrocket.rocketcomponent.ComponentAssembly; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; +import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.Color; import net.sf.openrocket.util.LineStyle; public class RocketComponentSaver { - + private static final Translator trans = Application.getTranslator(); + protected RocketComponentSaver() { // Prevent instantiation from outside the package } - + protected void addParams(net.sf.openrocket.rocketcomponent.RocketComponent c, List elements) { elements.add("" + RocketSaver.escapeXML(c.getName()) + ""); - + ComponentPreset preset = c.getPresetComponent(); - if ( preset != null ) { + if (preset != null) { elements.add(""); + "\" partno=\"" + preset.getPartNo() + "\" digest=\"" + preset.getDigest() + "\"/>"); } - - + + // Save color and line style if significant if (!(c instanceof Rocket || c instanceof ComponentAssembly)) { Color color = c.getColor(); @@ -43,23 +46,23 @@ public class RocketComponentSaver { elements.add(""); } - + LineStyle style = c.getLineStyle(); if (style != null) { // Type names currently equivalent to the enum names except for case. elements.add("" + style.name().toLowerCase(Locale.ENGLISH) + ""); } } - - + + // Save position unless "AFTER" if (c.getRelativePosition() != RocketComponent.Position.AFTER) { // The type names are currently equivalent to the enum names except for case. String type = c.getRelativePosition().name().toLowerCase(Locale.ENGLISH); elements.add("" + c.getPositionValue() + ""); } - - + + // Overrides boolean overridden = false; if (c.isMassOverridden()) { @@ -74,26 +77,26 @@ public class RocketComponentSaver { elements.add("" + c.getOverrideSubcomponents() + ""); } - - + + // Comment if (c.getComment().length() > 0) { elements.add("" + RocketSaver.escapeXML(c.getComment()) + ""); } - + } - - - - + + + + protected final String materialParam(Material mat) { return materialParam("material", mat); } - - + + protected final String materialParam(String tag, Material mat) { String str = "<" + tag; - + switch (mat.getType()) { case LINE: str += " type=\"line\""; @@ -107,27 +110,29 @@ public class RocketComponentSaver { default: throw new BugException("Unknown material type: " + mat.getType()); } - - return str + " density=\"" + mat.getDensity() + "\" key=\"" + RocketSaver.escapeXML(mat.getKey()) + "\">" + RocketSaver.escapeXML(mat.getName()) + ""; + + String baseName = trans.getBaseText("material", mat.getName()); + + return str + " density=\"" + mat.getDensity() + "\">" + RocketSaver.escapeXML(baseName) + ""; } - - + + protected final List motorMountParams(MotorMount mount) { if (!mount.isMotorMount()) return Collections.emptyList(); - + String[] motorConfigIDs = ((RocketComponent) mount).getRocket().getMotorConfigurationIDs(); List elements = new ArrayList(); - + elements.add(""); - + for (String id : motorConfigIDs) { Motor motor = mount.getMotor(id); - + // Nothing is stored if no motor loaded if (motor == null) continue; - + elements.add(" "); if (motor.getMotorType() != Motor.Type.UNKNOWN) { elements.add(" " + motor.getMotorType().name().toLowerCase(Locale.ENGLISH) + ""); @@ -141,27 +146,27 @@ public class RocketComponentSaver { elements.add(" " + RocketSaver.escapeXML(motor.getDesignation()) + ""); elements.add(" " + motor.getDiameter() + ""); elements.add(" " + motor.getLength() + ""); - + // Motor delay if (mount.getMotorDelay(id) == Motor.PLUGGED) { elements.add(" none"); } else { elements.add(" " + mount.getMotorDelay(id) + ""); } - + elements.add(" "); } - + elements.add(" " + mount.getIgnitionEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + ""); - + elements.add(" " + mount.getIgnitionDelay() + ""); elements.add(" " + mount.getMotorOverhang() + ""); - + elements.add(""); - + return elements; } - + } diff --git a/core/src/net/sf/openrocket/file/rocksim/importt/BaseHandler.java b/core/src/net/sf/openrocket/file/rocksim/importt/BaseHandler.java index b87664a8..35296d41 100644 --- a/core/src/net/sf/openrocket/file/rocksim/importt/BaseHandler.java +++ b/core/src/net/sf/openrocket/file/rocksim/importt/BaseHandler.java @@ -3,17 +3,19 @@ */ package net.sf.openrocket.file.rocksim.importt; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; + import net.sf.openrocket.aerodynamics.WarningSet; +import net.sf.openrocket.database.Databases; import net.sf.openrocket.file.rocksim.RocksimCommonConstants; import net.sf.openrocket.file.rocksim.RocksimDensityType; import net.sf.openrocket.file.simplesax.AbstractElementHandler; import net.sf.openrocket.material.Material; import net.sf.openrocket.rocketcomponent.RocketComponent; -import org.xml.sax.SAXException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; +import org.xml.sax.SAXException; /** * An abstract base class that handles common parsing. All Rocksim component handlers are subclassed from here. @@ -21,271 +23,266 @@ import java.util.HashMap; * @param the specific RocketComponent subtype for which the concrete handler can create */ public abstract class BaseHandler extends AbstractElementHandler { - - /** - * Prepend rocksim materials. - */ - public static final String ROCKSIM_MATERIAL_PREFIX = "RS: "; - /** - * The overridden mass. - */ - private Double mass = 0d; - /** - * The overridden Cg. - */ - private Double cg = 0d; - /** - * The density of the material in the component. - */ - private Double density = 0d; - /** - * The internal Rocksim density type. - */ - private RocksimDensityType densityType = RocksimDensityType.ROCKSIM_BULK; - - /** - * The material name. - */ - private String materialName = ""; - - /** - * The SAX method called when the closing element tag is reached. - * - * @param element the element name. - * @param attributes attributes of the element. - * @param content the textual content of the element. - * @param warnings the warning set to store warnings in. - * - * @throws SAXException - */ - - @Override - public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) - throws SAXException { - final C component = getComponent(); - try { - if (RocksimCommonConstants.NAME.equals(element)) { - component.setName(content); - } - if (RocksimCommonConstants.KNOWN_MASS.equals(element)) { - mass = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS); - } - if (RocksimCommonConstants.DENSITY.equals(element)) { - density = Math.max(0d, Double.parseDouble(content)); - } - if (RocksimCommonConstants.KNOWN_CG.equals(element)) { - cg = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - } - if (RocksimCommonConstants.USE_KNOWN_CG.equals(element)) { //Rocksim sets UseKnownCG to true to control the override of both cg and mass - boolean override = "1".equals(content); - setOverride(component, override, mass, cg); - } - if (RocksimCommonConstants.DENSITY_TYPE.equals(element)) { - densityType = RocksimDensityType.fromCode(Integer.parseInt(content)); - } - } - catch (NumberFormatException nfe) { - warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number."); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void endHandler(String element, HashMap attributes, String content, WarningSet warnings) - throws SAXException { - /* Because of the order of XML elements in Rocksim, not all information is known at the time it really needs - to be acted upon. So we keep temporary instance variables to be used here at the end of the parsing. - */ - density = computeDensity(densityType, density); - RocketComponent component = getComponent(); - updateComponentMaterial(component, materialName, getMaterialType(), density); - } - - /** - * Compute the density. Rocksim does strange things with densities. For some streamer material it's in cubic, - * rather than square, units. In those cases it needs to be converted to an appropriate SURFACE material density. - * Some G10 fiberglass materials are in cubic units, other G10 fiberglass is in square units. And due to a Rocksim - * bug, some densities are 0 when they clearly should not be. - *

- * This may be overridden for specific component density computations. - * - * @param type the rocksim density - * @param rawDensity the density as specified in the Rocksim design file - * - * @return a value in OpenRocket SURFACE density units - */ - protected double computeDensity(RocksimDensityType type, double rawDensity) { - return rawDensity / type.asOpenRocket(); - } - - /** - * If the Rocksim component does not override the mass, then create a Material based upon the density defined for - * that component. This *should* result in a consistent representation of Cg between Rocksim and OpenRocket. - * - * @param component the component - * @param type the type of the material - * @param density the density in g/cm^3 - * @param definedMaterial the material that is currently defined on the component; used only to get the name as it - * appears in Rocksim - */ - public static void updateComponentMaterial(RocketComponent component, String definedMaterial, Material.Type type, - double density) { - if (definedMaterial != null) { - Material custom = createCustomMaterial(type, definedMaterial, density); - setMaterial(component, custom); - } - } - - /** - * Override the mass and Cg of the component. - * - * @param component the component - * @param override true if any override should happen - * @param mass the override mass - * @param cg the override cg - */ - public static void setOverride(RocketComponent component, boolean override, double mass, double cg) { - if (override) { - component.setCGOverridden(override); - component.setMassOverridden(override); - component.setOverrideSubcomponents(false); //Rocksim does not support this type of override - component.setOverrideMass(mass); - component.setOverrideCGX(cg); - } - } - - /** - * Get the component this handler is working upon. - * - * @return a component - */ - protected abstract C getComponent(); - - /** - * Get the required type of material for this component. - * - * @return the required material type - */ - protected abstract Material.Type getMaterialType(); - - /** - * Some CG positions in Rocksim do not correspond to the CG position reference in OpenRocket. - * - * @param theCG the CG value to really use when overriding CG on the OpenRocket component - */ - protected void setCG(double theCG) { - cg = theCG; - } - - /** - * Set the material name as specified in the Rocksim design file. - * - * @param content the material name - */ - protected void setMaterialName(String content) { - materialName = content; - } - - /** - * Get the Rocksim enum of the component's density type. - * - * @return a Rocksim density type - */ - protected RocksimDensityType getDensityType() { - return densityType; - } - - /** - * Add child to parent only if the child is compatible. Otherwise add to warning set. - * - * @param parent the parent component - * @param child the child component - * @param warnings the warning set - * - * @return true if the child is compatible with parent - */ - protected static boolean isCompatible(RocketComponent parent, Class child, WarningSet warnings) { - return isCompatible(parent, child, warnings, false); - } - - /** - * Add child to parent only if the child is compatible. Otherwise add to warning set. - * - * @param parent the parent component - * @param child the child component - * @param warnings the warning set - * @param suppressWarnings suppress warnings, just return the boolean - * - * @return true if the child is compatible with parent - */ - protected static boolean isCompatible(RocketComponent parent, Class child, - WarningSet warnings, - boolean suppressWarnings) { - if (!parent.isCompatible(child)) { - if (!suppressWarnings) { - warnings.add(child.getName() + " can not be attached to " - + parent.getComponentName() + ", ignoring component."); - } - return false; - } - else { - return true; - } - } - - /** - * Create a custom material based on the density. The name of the material is prepended with 'RS: ' to indicate it - * came from a RockSim material. - * - * @param type the type of the material - * @param name the name of the component - * @param density the density - * - * @return a Material instance - */ - public static Material createCustomMaterial(Material.Type type, String name, double density) { - return Material.newUserMaterial(type, ROCKSIM_MATERIAL_PREFIX + name, density); - } - - /** - * Set the material onto an instance of RocketComponent. This is done because only some subtypes of RocketComponent - * have the setMaterial method. Unfortunately the supertype cannot be used. - * - * @param component the component who's material is to be set - * @param material the material to be set on the component (defined by getComponent()) - */ - private static void setMaterial(RocketComponent component, Material material) { - try { - final Method method = getMethod(component, "setMaterial", new Class[]{Material.class}); - if (method != null) { - method.invoke(component, material); - } - } - catch (IllegalAccessException ignored) { - } - catch (InvocationTargetException ignored) { - } - } - - /** - * Find a method by name and argument list. - * - * @param component the component who's material is to be set - * @param name the method name - * @param args the class types of the parameters - * - * @return the Method instance, or null - */ - private static Method getMethod(RocketComponent component, String name, Class[] args) { - Method method = null; - try { - method = component.getClass().getMethod(name, args); - } - catch (NoSuchMethodException ignored) { - } - return method; - } - + + /** + * Prepend rocksim materials. + */ + public static final String ROCKSIM_MATERIAL_PREFIX = "RS: "; + /** + * The overridden mass. + */ + private Double mass = 0d; + /** + * The overridden Cg. + */ + private Double cg = 0d; + /** + * The density of the material in the component. + */ + private Double density = 0d; + /** + * The internal Rocksim density type. + */ + private RocksimDensityType densityType = RocksimDensityType.ROCKSIM_BULK; + + /** + * The material name. + */ + private String materialName = ""; + + /** + * The SAX method called when the closing element tag is reached. + * + * @param element the element name. + * @param attributes attributes of the element. + * @param content the textual content of the element. + * @param warnings the warning set to store warnings in. + * + * @throws SAXException + */ + + @Override + public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) + throws SAXException { + final C component = getComponent(); + try { + if (RocksimCommonConstants.NAME.equals(element)) { + component.setName(content); + } + if (RocksimCommonConstants.KNOWN_MASS.equals(element)) { + mass = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS); + } + if (RocksimCommonConstants.DENSITY.equals(element)) { + density = Math.max(0d, Double.parseDouble(content)); + } + if (RocksimCommonConstants.KNOWN_CG.equals(element)) { + cg = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + } + if (RocksimCommonConstants.USE_KNOWN_CG.equals(element)) { //Rocksim sets UseKnownCG to true to control the override of both cg and mass + boolean override = "1".equals(content); + setOverride(component, override, mass, cg); + } + if (RocksimCommonConstants.DENSITY_TYPE.equals(element)) { + densityType = RocksimDensityType.fromCode(Integer.parseInt(content)); + } + } catch (NumberFormatException nfe) { + warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number."); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endHandler(String element, HashMap attributes, String content, WarningSet warnings) + throws SAXException { + /* Because of the order of XML elements in Rocksim, not all information is known at the time it really needs + to be acted upon. So we keep temporary instance variables to be used here at the end of the parsing. + */ + density = computeDensity(densityType, density); + RocketComponent component = getComponent(); + updateComponentMaterial(component, materialName, getMaterialType(), density); + } + + /** + * Compute the density. Rocksim does strange things with densities. For some streamer material it's in cubic, + * rather than square, units. In those cases it needs to be converted to an appropriate SURFACE material density. + * Some G10 fiberglass materials are in cubic units, other G10 fiberglass is in square units. And due to a Rocksim + * bug, some densities are 0 when they clearly should not be. + *

+ * This may be overridden for specific component density computations. + * + * @param type the rocksim density + * @param rawDensity the density as specified in the Rocksim design file + * + * @return a value in OpenRocket SURFACE density units + */ + protected double computeDensity(RocksimDensityType type, double rawDensity) { + return rawDensity / type.asOpenRocket(); + } + + /** + * If the Rocksim component does not override the mass, then create a Material based upon the density defined for + * that component. This *should* result in a consistent representation of Cg between Rocksim and OpenRocket. + * + * @param component the component + * @param type the type of the material + * @param density the density in g/cm^3 + * @param definedMaterial the material that is currently defined on the component; used only to get the name as it + * appears in Rocksim + */ + public static void updateComponentMaterial(RocketComponent component, String definedMaterial, Material.Type type, + double density) { + if (definedMaterial != null) { + Material custom = createCustomMaterial(type, definedMaterial, density); + setMaterial(component, custom); + } + } + + /** + * Override the mass and Cg of the component. + * + * @param component the component + * @param override true if any override should happen + * @param mass the override mass + * @param cg the override cg + */ + public static void setOverride(RocketComponent component, boolean override, double mass, double cg) { + if (override) { + component.setCGOverridden(override); + component.setMassOverridden(override); + component.setOverrideSubcomponents(false); //Rocksim does not support this type of override + component.setOverrideMass(mass); + component.setOverrideCGX(cg); + } + } + + /** + * Get the component this handler is working upon. + * + * @return a component + */ + protected abstract C getComponent(); + + /** + * Get the required type of material for this component. + * + * @return the required material type + */ + protected abstract Material.Type getMaterialType(); + + /** + * Some CG positions in Rocksim do not correspond to the CG position reference in OpenRocket. + * + * @param theCG the CG value to really use when overriding CG on the OpenRocket component + */ + protected void setCG(double theCG) { + cg = theCG; + } + + /** + * Set the material name as specified in the Rocksim design file. + * + * @param content the material name + */ + protected void setMaterialName(String content) { + materialName = content; + } + + /** + * Get the Rocksim enum of the component's density type. + * + * @return a Rocksim density type + */ + protected RocksimDensityType getDensityType() { + return densityType; + } + + /** + * Add child to parent only if the child is compatible. Otherwise add to warning set. + * + * @param parent the parent component + * @param child the child component + * @param warnings the warning set + * + * @return true if the child is compatible with parent + */ + protected static boolean isCompatible(RocketComponent parent, Class child, WarningSet warnings) { + return isCompatible(parent, child, warnings, false); + } + + /** + * Add child to parent only if the child is compatible. Otherwise add to warning set. + * + * @param parent the parent component + * @param child the child component + * @param warnings the warning set + * @param suppressWarnings suppress warnings, just return the boolean + * + * @return true if the child is compatible with parent + */ + protected static boolean isCompatible(RocketComponent parent, Class child, + WarningSet warnings, + boolean suppressWarnings) { + if (!parent.isCompatible(child)) { + if (!suppressWarnings) { + warnings.add(child.getName() + " can not be attached to " + + parent.getComponentName() + ", ignoring component."); + } + return false; + } + else { + return true; + } + } + + /** + * Create a custom material based on the density. + * + * @param type the type of the material + * @param name the name of the component + * @param density the density + * + * @return a Material instance + */ + public static Material createCustomMaterial(Material.Type type, String name, double density) { + return Databases.findMaterial(type, name, density); + } + + /** + * Set the material onto an instance of RocketComponent. This is done because only some subtypes of RocketComponent + * have the setMaterial method. Unfortunately the supertype cannot be used. + * + * @param component the component who's material is to be set + * @param material the material to be set on the component (defined by getComponent()) + */ + private static void setMaterial(RocketComponent component, Material material) { + try { + final Method method = getMethod(component, "setMaterial", new Class[] { Material.class }); + if (method != null) { + method.invoke(component, material); + } + } catch (IllegalAccessException ignored) { + } catch (InvocationTargetException ignored) { + } + } + + /** + * Find a method by name and argument list. + * + * @param component the component who's material is to be set + * @param name the method name + * @param args the class types of the parameters + * + * @return the Method instance, or null + */ + private static Method getMethod(RocketComponent component, String name, Class[] args) { + Method method = null; + try { + method = component.getClass().getMethod(name, args); + } catch (NoSuchMethodException ignored) { + } + return method; + } + } diff --git a/core/src/net/sf/openrocket/gui/dialogs/CustomMaterialDialog.java b/core/src/net/sf/openrocket/gui/dialogs/CustomMaterialDialog.java index ed1d97cf..9ef95a9b 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/CustomMaterialDialog.java +++ b/core/src/net/sf/openrocket/gui/dialogs/CustomMaterialDialog.java @@ -15,6 +15,7 @@ import javax.swing.JSpinner; import javax.swing.JTextField; import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.database.Databases; import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.UnitSelector; @@ -24,9 +25,10 @@ import net.sf.openrocket.material.Material; import net.sf.openrocket.startup.Application; public class CustomMaterialDialog extends JDialog { - + private static final Translator trans = Application.getTranslator(); + private final Material originalMaterial; - + private boolean okClicked = false; private JComboBox typeBox; private JTextField nameField; @@ -34,34 +36,33 @@ public class CustomMaterialDialog extends JDialog { private JSpinner densitySpinner; private UnitSelector densityUnit; private JCheckBox addBox; - private static final Translator trans = Application.getTranslator(); - + public CustomMaterialDialog(Window parent, Material material, boolean saveOption, String title) { this(parent, material, saveOption, title, null); } - - + + public CustomMaterialDialog(Window parent, Material material, boolean saveOption, String title, String note) { //// Custom material super(parent, trans.get("custmatdlg.title.Custommaterial"), Dialog.ModalityType.APPLICATION_MODAL); - + this.originalMaterial = material; - + JPanel panel = new JPanel(new MigLayout("fill, gap rel unrel")); - - + + // Add title and note if (title != null) { - panel.add(new JLabel("" + title + ":"), - "gapleft para, span, wrap" + (note == null ? " para":"")); + panel.add(new JLabel("" + title + ":"), + "gapleft para, span, wrap" + (note == null ? " para" : "")); } if (note != null) { panel.add(new StyledLabel(note, -1), "span, wrap para"); } - - + + //// Material name panel.add(new JLabel(trans.get("custmatdlg.lbl.Materialname"))); nameField = new JTextField(15); @@ -69,8 +70,8 @@ public class CustomMaterialDialog extends JDialog { nameField.setText(material.getName()); } panel.add(nameField, "span, growx, wrap"); - - + + // Material type (if not known) panel.add(new JLabel(trans.get("custmatdlg.lbl.Materialtype"))); if (material == null) { @@ -87,28 +88,28 @@ public class CustomMaterialDialog extends JDialog { } else { panel.add(new JLabel(material.getType().toString()), "span, growx, wrap"); } - - + + // Material density: panel.add(new JLabel(trans.get("custmatdlg.lbl.Materialdensity"))); densitySpinner = new JSpinner(); panel.add(densitySpinner, "w 70lp"); - densityUnit = new UnitSelector((DoubleModel)null); + densityUnit = new UnitSelector((DoubleModel) null); panel.add(densityUnit, "w 30lp"); panel.add(new JPanel(), "growx, wrap"); updateDensityModel(); - - + + // Save option if (saveOption) { //// Add material to database addBox = new JCheckBox(trans.get("custmatdlg.checkbox.Addmaterial")); - panel.add(addBox,"span, wrap"); + panel.add(addBox, "span, wrap"); } - + //// OK button JButton okButton = new JButton(trans.get("dlg.but.ok")); - + okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -116,8 +117,8 @@ public class CustomMaterialDialog extends JDialog { CustomMaterialDialog.this.setVisible(false); } }); - panel.add(okButton,"span, split, tag ok"); - + panel.add(okButton, "span, split, tag ok"); + //// Cancel JButton closeButton = new JButton(trans.get("dlg.but.cancel")); closeButton.addActionListener(new ActionListener() { @@ -127,49 +128,44 @@ public class CustomMaterialDialog extends JDialog { CustomMaterialDialog.this.setVisible(false); } }); - panel.add(closeButton,"tag cancel"); - + panel.add(closeButton, "tag cancel"); + this.setContentPane(panel); this.pack(); this.setLocationByPlatform(true); GUIUtil.setDisposableDialogOptions(this, okButton); } - - + + public boolean getOkClicked() { return okClicked; } - - + + public boolean isAddSelected() { return addBox.isSelected(); } - - + + public Material getMaterial() { Material.Type type; String name; - double density; - + double materialDensity; + if (typeBox != null) { type = (Material.Type) typeBox.getSelectedItem(); } else { type = originalMaterial.getType(); } - + name = nameField.getText().trim(); - - density = this.density.getValue(); - - // If the name has not changed from the original name and we started with a system material. - if ( name.equals( originalMaterial.getName()) ) { - return Material.newUserMaterialWithKey(type, originalMaterial.getKey(), originalMaterial.getName(), density); - } else { - return Material.newUserMaterial(type, name, density); - } + + materialDensity = this.density.getValue(); + + return Databases.findMaterial(type, name, materialDensity); } - - + + private void updateDensityModel() { if (originalMaterial != null) { if (density == null) { diff --git a/core/src/net/sf/openrocket/gui/util/SwingPreferences.java b/core/src/net/sf/openrocket/gui/util/SwingPreferences.java index 55aed616..61e6be85 100644 --- a/core/src/net/sf/openrocket/gui/util/SwingPreferences.java +++ b/core/src/net/sf/openrocket/gui/util/SwingPreferences.java @@ -34,17 +34,17 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { private static final String SPLIT_CHARACTER = "|"; - + private static final List SUPPORTED_LOCALES; static { List list = new ArrayList(); - for (String lang : new String[] { "en", "de", "es", "fr", "it", "ru","cs","pl" }) { + for (String lang : new String[] { "en", "de", "es", "fr", "it", "ru", "cs", "pl" }) { list.add(new Locale(lang)); } SUPPORTED_LOCALES = Collections.unmodifiableList(list); } - + /** * Whether to use the debug-node instead of the normal node. */ @@ -64,9 +64,9 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { */ private static final String NODENAME = (DEBUG ? "OpenRocket-debug" : "OpenRocket"); - private final Preferences PREFNODE; + private final Preferences PREFNODE; + - public SwingPreferences() { Preferences root = Preferences.userRoot(); if (DEBUG && CLEARPREFS) { @@ -81,13 +81,13 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { PREFNODE = root.node(NODENAME); } - - + + ////////////////////// - - + + /** * Store the current OpenRocket version into the preferences to allow for preferences migration. */ @@ -108,9 +108,9 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { } @Override - public String getString( String directory, String key, String defaultValue ) { + public String getString(String directory, String key, String defaultValue) { Preferences p = PREFNODE.node(directory); - return p.get(key,defaultValue); + return p.get(key, defaultValue); } /** @@ -130,12 +130,12 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { } @Override - public void putString(String directory, String key, String value ) { + public void putString(String directory, String key, String value) { Preferences p = PREFNODE.node(directory); - if ( value == null ) { + if (value == null) { p.remove(key); } else { - p.put(key,value); + p.put(key, value); } storeVersion(); } @@ -165,29 +165,29 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { } @Override - public int getInt( String key, int defaultValue ) { + public int getInt(String key, int defaultValue) { return PREFNODE.getInt(key, defaultValue); } @Override - public void putInt( String key , int value ) { - PREFNODE.putInt(key, value ); + public void putInt(String key, int value) { + PREFNODE.putInt(key, value); storeVersion(); } @Override public double getDouble(String key, double defaultValue) { - return PREFNODE.getDouble(key, defaultValue ); + return PREFNODE.getDouble(key, defaultValue); } - + @Override public void putDouble(String key, double value) { - PREFNODE.putDouble(key,value); + PREFNODE.putDouble(key, value); storeVersion(); } - - - + + + /** * Return a preferences object for the specified node name. * @@ -201,7 +201,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { ////////////////// - + public static List getSupportedLocales() { return SUPPORTED_LOCALES; } @@ -330,8 +330,8 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { } - - + + public Dimension getWindowSize(Class c) { int x, y; String pref = PREFNODE.node("windows").get("size." + c.getCanonicalName(), null); @@ -372,9 +372,9 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { * you can pass (java.awt.Color) null to the second argument to * disambiguate */ - public Color getColor( String key, Color defaultValue ) { + public Color getColor(String key, Color defaultValue) { net.sf.openrocket.util.Color c = super.getColor(key, (net.sf.openrocket.util.Color) null); - if ( c == null ) { + if (c == null) { return defaultValue; } return ColorConversion.toAwtColor(c); @@ -383,9 +383,9 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { /** * */ - public void putColor( String key, Color value ) { + public void putColor(String key, Color value) { net.sf.openrocket.util.Color c = ColorConversion.fromAwtColor(value); - super.putColor(key, c); + super.putColor(key, c); } //// Printing @@ -409,7 +409,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { } - + ///////// Export variables public boolean isExportSelected(FlightDataType type) { @@ -423,7 +423,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { } - + ///////// Default unit storage public void loadDefaultUnits() { @@ -459,10 +459,10 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { } - + //// Material storage - + /** * Add a user-defined material to the preferences. The preferences are * first checked for an existing material matching the provided one using @@ -474,7 +474,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { public void addUserMaterial(Material m) { Preferences prefs = PREFNODE.node("userMaterials"); - + // Check whether material already exists if (getUserMaterials().contains(m)) { return; @@ -509,7 +509,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { String value = prefs.get(key, null); try { - Material existing = Material.fromStorableString(value); + Material existing = Material.fromStorableString(value, true); if (existing.equals(m)) { prefs.remove(key); } @@ -542,7 +542,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { String value = prefs.get(key, null); try { - Material m = Material.fromStorableString(value); + Material m = Material.fromStorableString(value, true); materials.add(m); } catch (IllegalArgumentException e) { @@ -559,9 +559,9 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { } @Override - public void setComponentFavorite( ComponentPreset preset, ComponentPreset.Type type, boolean favorite ) { + public void setComponentFavorite(ComponentPreset preset, ComponentPreset.Type type, boolean favorite) { Preferences prefs = PREFNODE.node("favoritePresets").node(type.name()); - if ( favorite ) { + if (favorite) { prefs.putBoolean(preset.preferenceKey(), true); } else { prefs.remove(preset.preferenceKey()); @@ -569,12 +569,12 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences { } @Override - public Set getComponentFavorites( ComponentPreset.Type type) { + public Set getComponentFavorites(ComponentPreset.Type type) { Preferences prefs = PREFNODE.node("favoritePresets").node(type.name()); Set collection = new HashSet(); try { - collection.addAll( Arrays.asList(prefs.keys())); - } catch ( BackingStoreException bex ) { + collection.addAll(Arrays.asList(prefs.keys())); + } catch (BackingStoreException bex) { } return collection; diff --git a/core/src/net/sf/openrocket/l10n/ClassBasedTranslator.java b/core/src/net/sf/openrocket/l10n/ClassBasedTranslator.java index b4212dc9..6281b6e8 100644 --- a/core/src/net/sf/openrocket/l10n/ClassBasedTranslator.java +++ b/core/src/net/sf/openrocket/l10n/ClassBasedTranslator.java @@ -15,7 +15,7 @@ import net.sf.openrocket.util.BugException; */ public class ClassBasedTranslator implements Translator { - + private final Translator translator; private final String className; @@ -41,7 +41,7 @@ public class ClassBasedTranslator implements Translator { } - + @Override public String get(String key) { String classKey = className + "." + key; @@ -63,7 +63,20 @@ public class ClassBasedTranslator implements Translator { } - + + @Override + public String get(String base, String text) { + return translator.get(base, text); + } + + @Override + public String getBaseText(String base, String translation) { + return translator.getBaseText(base, translation); + } + + + + private static String getStackClass(int levels) { TraceException trace = new TraceException(); StackTraceElement stack[] = trace.getStackTrace(); @@ -82,11 +95,10 @@ public class ClassBasedTranslator implements Translator { } - - + + // For unit testing purposes String getClassName() { return className; } - } diff --git a/core/src/net/sf/openrocket/l10n/DebugTranslator.java b/core/src/net/sf/openrocket/l10n/DebugTranslator.java index 5a2bf592..ccf72e58 100644 --- a/core/src/net/sf/openrocket/l10n/DebugTranslator.java +++ b/core/src/net/sf/openrocket/l10n/DebugTranslator.java @@ -22,7 +22,7 @@ public class DebugTranslator implements Translator { } - + @Override public String get(String key) { if (translator != null) { @@ -31,4 +31,22 @@ public class DebugTranslator implements Translator { return "[" + key + "]"; } + + + @Override + public String get(String base, String text) { + return "[" + base + ":" + text + "]"; + } + + + + @Override + public String getBaseText(String base, String translation) { + if (translation.startsWith("[" + base + ":") && translation.endsWith("]")) { + return translation.substring(base.length() + 2, translation.length() - 1); + } + return translation; + } + + } diff --git a/core/src/net/sf/openrocket/l10n/ExceptionSuppressingTranslator.java b/core/src/net/sf/openrocket/l10n/ExceptionSuppressingTranslator.java index dd916b6c..1287822c 100644 --- a/core/src/net/sf/openrocket/l10n/ExceptionSuppressingTranslator.java +++ b/core/src/net/sf/openrocket/l10n/ExceptionSuppressingTranslator.java @@ -29,7 +29,7 @@ public class ExceptionSuppressingTranslator implements Translator { } - + @Override public String get(String key) { try { @@ -42,7 +42,18 @@ public class ExceptionSuppressingTranslator implements Translator { } - + @Override + public String get(String base, String text) { + return translator.get(base, text); + } + + + @Override + public String getBaseText(String base, String translation) { + return translator.getBaseText(base, translation); + } + + private static synchronized void handleError(String key, MissingResourceException e) { if (!errorReported) { errorReported = true; @@ -50,4 +61,6 @@ public class ExceptionSuppressingTranslator implements Translator { } } + + } diff --git a/core/src/net/sf/openrocket/l10n/L10N.java b/core/src/net/sf/openrocket/l10n/L10N.java index 878b3c41..351873be 100644 --- a/core/src/net/sf/openrocket/l10n/L10N.java +++ b/core/src/net/sf/openrocket/l10n/L10N.java @@ -1,8 +1,11 @@ package net.sf.openrocket.l10n; +import java.text.Normalizer; import java.util.Locale; import java.util.regex.Pattern; +import net.sf.openrocket.util.Chars; + /** * Helper methods for localization needs. * @@ -54,4 +57,27 @@ public final class L10N { return l; } + + public static String normalize(String text) { + text = Normalizer.normalize(text, Normalizer.Form.NFKD); + text = text.toLowerCase(); + text = text.replaceAll("\\s+", " "); + text = text.trim(); + + StringBuilder sb = new StringBuilder(text.length()); + for (char c : text.toCharArray()) { + if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) { + sb.append(c); + } else if (c == ' ' || c == '/' || c == Chars.FRACTION) { + sb.append('_'); + } + } + text = sb.toString(); + + text = text.replaceAll("^_+", ""); + text = text.replaceAll("_+$", ""); + + return text; + } + } diff --git a/core/src/net/sf/openrocket/l10n/ResourceBundleTranslator.java b/core/src/net/sf/openrocket/l10n/ResourceBundleTranslator.java index 241ecefc..d210e01e 100644 --- a/core/src/net/sf/openrocket/l10n/ResourceBundleTranslator.java +++ b/core/src/net/sf/openrocket/l10n/ResourceBundleTranslator.java @@ -1,6 +1,7 @@ package net.sf.openrocket.l10n; import java.util.Locale; +import java.util.MissingResourceException; import java.util.ResourceBundle; /** @@ -11,6 +12,7 @@ import java.util.ResourceBundle; public class ResourceBundleTranslator implements Translator { private final ResourceBundle bundle; + private final ResourceBundle english; /** * Create a ResourceBundleTranslator using the default Locale. @@ -29,6 +31,7 @@ public class ResourceBundleTranslator implements Translator { */ public ResourceBundleTranslator(String baseName, Locale locale) { this.bundle = ResourceBundle.getBundle(baseName, locale); + this.english = ResourceBundle.getBundle(baseName, Locale.ROOT); } @@ -40,4 +43,27 @@ public class ResourceBundleTranslator implements Translator { return bundle.getString(key); } + @Override + public synchronized String get(String base, String text) { + String key = base + "." + L10N.normalize(text); + try { + return bundle.getString(key); + } catch (MissingResourceException e) { + return text; + } + } + + @Override + public synchronized String getBaseText(String base, String translation) { + String prefix = base + "."; + for (String key : bundle.keySet()) { + if (key.startsWith(prefix)) { + String value = bundle.getString(key); + if (value.equals(translation)) { + return english.getString(key); + } + } + } + return translation; + } } diff --git a/core/src/net/sf/openrocket/l10n/Translator.java b/core/src/net/sf/openrocket/l10n/Translator.java index 9eed2cdf..5211ed73 100644 --- a/core/src/net/sf/openrocket/l10n/Translator.java +++ b/core/src/net/sf/openrocket/l10n/Translator.java @@ -22,4 +22,33 @@ public interface Translator { */ public String get(String key); + + /** + * Retrieve a translated string based on a base key and base (English) version of the text. + * The base text is normalized before using as a key. + *

+ * This is meant to be used in very specific cases where the English name is + * used as a key for translation and storage. If a translation is not found, + * the base text is used instead. + * + * @param base the base for the logical key + * @param text the base (English) text to translate + * @return the translated string, or "text" if not found + */ + public String get(String base, String text); + + + /** + * Find the base (English) version of a translated text. + *

+ * This is the opposite operation of {@link #get(String, String)}, and + * meant for use in very specific cases when storing the values of + * translated texts. + * + * @param base the base for the logical key + * @param translation the translated string + * @return the base text, or the translation if not found. + */ + public String getBaseText(String base, String translation); + } diff --git a/core/src/net/sf/openrocket/material/Material.java b/core/src/net/sf/openrocket/material/Material.java index f8fe76a8..055fc336 100644 --- a/core/src/net/sf/openrocket/material/Material.java +++ b/core/src/net/sf/openrocket/material/Material.java @@ -1,6 +1,5 @@ package net.sf.openrocket.material; -import net.sf.openrocket.database.Databases; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.Unit; @@ -20,17 +19,17 @@ import net.sf.openrocket.util.MathUtil; public abstract class Material implements Comparable { private static final Translator trans = Application.getTranslator(); - + public enum Type { - LINE("Line", UnitGroup.UNITS_DENSITY_LINE), - SURFACE("Surface", UnitGroup.UNITS_DENSITY_SURFACE), - BULK("Bulk", UnitGroup.UNITS_DENSITY_BULK); + LINE("Databases.materials.types.Line", UnitGroup.UNITS_DENSITY_LINE), + SURFACE("Databases.materials.types.Surface", UnitGroup.UNITS_DENSITY_SURFACE), + BULK("Databases.materials.types.Bulk", UnitGroup.UNITS_DENSITY_BULK); private final String name; private final UnitGroup units; - private Type(String name, UnitGroup units) { - this.name = trans.get ("Databases.materials.types." + name); + private Type(String nameKey, UnitGroup units) { + this.name = trans.get(nameKey); this.units = units; } @@ -48,10 +47,10 @@ public abstract class Material implements Comparable { ///// Definitions of different material types ///// public static class Line extends Material { - Line(String name, String key, double density, boolean userDefined) { - super(name, key, density, userDefined); + Line(String name, double density, boolean userDefined) { + super(name, density, userDefined); } - + @Override public Type getType() { return Type.LINE; @@ -60,10 +59,10 @@ public abstract class Material implements Comparable { public static class Surface extends Material { - Surface(String name, String key, double density, boolean userDefined) { - super(name, key, density, userDefined); + Surface(String name, double density, boolean userDefined) { + super(name, density, userDefined); } - + @Override public Type getType() { return Type.SURFACE; @@ -76,10 +75,10 @@ public abstract class Material implements Comparable { } public static class Bulk extends Material { - Bulk(String name, String key, double density, boolean userDefined) { - super(name, key, density, userDefined); + Bulk(String name, double density, boolean userDefined) { + super(name, density, userDefined); } - + @Override public Type getType() { return Type.BULK; @@ -87,9 +86,8 @@ public abstract class Material implements Comparable { } - + private final String name; - private final String key; private final double density; private final boolean userDefined; @@ -102,21 +100,11 @@ public abstract class Material implements Comparable { * @param density * @param userDefined true if this is a user defined material, false if it is a system material. */ - private Material(String name, String key, double density, boolean userDefined) { - if ( userDefined ) { - this.key = "UserDefined."+name; - this.name = name; - } else { - this.key = key; - this.name = trans.get("Databases.materials." + key); - } + private Material(String name, double density, boolean userDefined) { + this.name = name; this.userDefined = userDefined; this.density = density; } - - public String getKey() { - return key; - } public double getDensity() { return density; @@ -180,64 +168,33 @@ public abstract class Material implements Comparable { } - public static Material newSystemMaterial(Type type, String key, double density ) { - switch (type) { - case LINE: - return new Material.Line(null, key, density, false); - - case SURFACE: - return new Material.Surface(null,key, density, false); - - case BULK: - return new Material.Bulk(null, key, density, false); - - default: - throw new IllegalArgumentException("Unknown material type: " + type); - } - } - /** - * Return a new user defined material of the specified type. - */ - public static Material newUserMaterial(Type type, String name, double density) { - switch (type) { - case LINE: - return new Material.Line(name, null, density, true); - - case SURFACE: - return new Material.Surface(name, null, density, true); - - case BULK: - return new Material.Bulk(name, null, density, true); - - default: - throw new IllegalArgumentException("Unknown material type: " + type); - } - } - - /** - * Return a new user defined material of the specified type and localizable key. + * Return a new material. The name is used as-is, without any translation. + * + * @param type the material type + * @param name the material name + * @param density the material density + * @param userDefined whether the material is user-defined or not + * @return the new material */ - public static Material newUserMaterialWithKey(Type type, String key, String name, double density) { + public static Material newMaterial(Type type, String name, double density, boolean userDefined) { switch (type) { case LINE: - return new Material.Line(name, key, density, true); + return new Material.Line(name, density, userDefined); case SURFACE: - return new Material.Surface(name, key, density, true); + return new Material.Surface(name, density, userDefined); case BULK: - return new Material.Bulk(name, key, density, true); + return new Material.Bulk(name, density, userDefined); default: throw new IllegalArgumentException("Unknown material type: " + type); } } - - public String toStorableString() { - return getType().name() + "|" + key + "|" + name.replace('|', ' ') + '|' + density; + return getType().name() + "|" + name.replace('|', ' ') + '|' + density; } @@ -249,18 +206,17 @@ public abstract class Material implements Comparable { * @return a new Material object. * @throws IllegalArgumentException if str is invalid or null. */ - public static Material fromStorableString(String str) { + public static Material fromStorableString(String str, boolean userDefined) { if (str == null) throw new IllegalArgumentException("Material string is null"); - String[] split = str.split("\\|"); + String[] split = str.split("\\|", 3); if (split.length < 3) throw new IllegalArgumentException("Illegal material string: " + str); Type type = null; - String name = null; - String key= null; - String densityString; + String name; + double density; try { type = Type.valueOf(split[0]); @@ -268,25 +224,27 @@ public abstract class Material implements Comparable { throw new IllegalArgumentException("Illegal material string: " + str, e); } - if ( split.length == 3 ) { - name = split[1]; - densityString =split[2]; - } else { - key = split[1]; - name = split[2]; - densityString=split[3]; - } - + name = split[1]; - double density; - try { - density = Double.parseDouble(densityString); + density = Double.parseDouble(split[2]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Illegal material string: " + str, e); } - return Databases.findMaterial(type, key, name, density); + switch (type) { + case BULK: + return new Material.Bulk(name, density, userDefined); + + case SURFACE: + return new Material.Surface(name, density, userDefined); + + case LINE: + return new Material.Line(name, density, userDefined); + + default: + throw new IllegalArgumentException("Illegal material string: " + str); + } } } diff --git a/core/src/net/sf/openrocket/preset/ComponentPresetFactory.java b/core/src/net/sf/openrocket/preset/ComponentPresetFactory.java index 7c4b2b9a..7d2677b3 100644 --- a/core/src/net/sf/openrocket/preset/ComponentPresetFactory.java +++ b/core/src/net/sf/openrocket/preset/ComponentPresetFactory.java @@ -1,251 +1,252 @@ package net.sf.openrocket.preset; import static net.sf.openrocket.preset.ComponentPreset.*; +import net.sf.openrocket.database.Databases; import net.sf.openrocket.material.Material; import net.sf.openrocket.preset.ComponentPreset.Type; import net.sf.openrocket.rocketcomponent.NoseCone; import net.sf.openrocket.rocketcomponent.Transition; public abstract class ComponentPresetFactory { - - public static ComponentPreset create( TypedPropertyMap props ) throws InvalidComponentPresetException { - + + public static ComponentPreset create(TypedPropertyMap props) throws InvalidComponentPresetException { + InvalidComponentPresetException exceptions = new InvalidComponentPresetException("Invalid preset specification."); ComponentPreset preset = new ComponentPreset(); // First do validation. if (!props.containsKey(MANUFACTURER)) { - exceptions.addInvalidParameter(MANUFACTURER, "No Manufacturer specified"); + exceptions.addInvalidParameter(MANUFACTURER, "No Manufacturer specified"); } if (!props.containsKey(PARTNO)) { - exceptions.addInvalidParameter(PARTNO,"No PartNo specified"); + exceptions.addInvalidParameter(PARTNO, "No PartNo specified"); } - if ( !props.containsKey(TYPE)) { - exceptions.addInvalidParameter(TYPE, "No Type specified" ); + if (!props.containsKey(TYPE)) { + exceptions.addInvalidParameter(TYPE, "No Type specified"); // We can't do anything else without TYPE so throw immediately. throw exceptions; } - - + + preset.putAll(props); - + // Should check for various bits of each of the types. Type t = props.get(TYPE); - switch ( t ) { + switch (t) { case BODY_TUBE: { - makeBodyTube(exceptions,preset); + makeBodyTube(exceptions, preset); break; } case NOSE_CONE: { - makeNoseCone(exceptions,preset); + makeNoseCone(exceptions, preset); break; } case TRANSITION: { - makeTransition(exceptions,preset); + makeTransition(exceptions, preset); break; } case BULK_HEAD: { - makeBulkHead(exceptions,preset); + makeBulkHead(exceptions, preset); break; } case TUBE_COUPLER: { // For now TUBE_COUPLER is the same as BODY_TUBE - makeBodyTube(exceptions,preset); + makeBodyTube(exceptions, preset); break; } case CENTERING_RING: { - makeCenteringRing(exceptions,preset); + makeCenteringRing(exceptions, preset); break; } case ENGINE_BLOCK: { - makeEngineBlock(exceptions,preset); + makeEngineBlock(exceptions, preset); break; } case LAUNCH_LUG: { // Same processing as BODY_TUBE - makeBodyTube(exceptions,preset); + makeBodyTube(exceptions, preset); break; } case STREAMER: { - makeStreamer(exceptions,preset); + makeStreamer(exceptions, preset); break; } case PARACHUTE: { - makeParachute(exceptions,preset); + makeParachute(exceptions, preset); break; } } - - if ( exceptions.hasProblems() ) { + + if (exceptions.hasProblems()) { throw exceptions; } preset.computeDigest(); - + return preset; - + } - - private static void makeBodyTube( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException { + + private static void makeBodyTube(InvalidComponentPresetException exceptions, ComponentPreset preset) throws InvalidComponentPresetException { + + checkRequiredFields(exceptions, preset, LENGTH); - checkRequiredFields( exceptions, preset, LENGTH ); - checkDiametersAndThickness(exceptions, preset); - double volume = computeVolumeOfTube( preset ); + double volume = computeVolumeOfTube(preset); // Need to translate Mass to Density. - if ( preset.has(MASS) ) { + if (preset.has(MASS)) { String materialName = "TubeCustom"; - if ( preset.has(MATERIAL) ) { + if (preset.has(MATERIAL)) { materialName = preset.get(MATERIAL).getName(); } - Material m = Material.newUserMaterial(Material.Type.BULK, materialName, preset.get(MASS)/volume); + Material m = Databases.findMaterial(Material.Type.BULK, materialName, preset.get(MASS) / volume); preset.put(MATERIAL, m); } - - + + } - - private static void makeNoseCone( InvalidComponentPresetException exceptions, ComponentPreset preset ) { - - checkRequiredFields( exceptions, preset, LENGTH, SHAPE, AFT_OUTER_DIAMETER ); - - if ( preset.has(MASS) ) { + + private static void makeNoseCone(InvalidComponentPresetException exceptions, ComponentPreset preset) { + + checkRequiredFields(exceptions, preset, LENGTH, SHAPE, AFT_OUTER_DIAMETER); + + if (preset.has(MASS)) { // compute a density for this component double mass = preset.get(MASS); NoseCone nc = new NoseCone(); nc.loadPreset(preset); double density = mass / nc.getComponentVolume(); - + String materialName = "NoseConeCustom"; - if ( preset.has(MATERIAL) ) { + if (preset.has(MATERIAL)) { materialName = preset.get(MATERIAL).getName(); } - - Material m = Material.newUserMaterial(Material.Type.BULK, materialName,density); + + Material m = Databases.findMaterial(Material.Type.BULK, materialName, density); preset.put(MATERIAL, m); - + } - + } - - private static void makeTransition( InvalidComponentPresetException exceptions, ComponentPreset preset ) { + + private static void makeTransition(InvalidComponentPresetException exceptions, ComponentPreset preset) { checkRequiredFields(exceptions, preset, LENGTH, AFT_OUTER_DIAMETER, FORE_OUTER_DIAMETER); - - if ( preset.has(MASS) ) { + + if (preset.has(MASS)) { // compute a density for this component double mass = preset.get(MASS); Transition tr = new Transition(); tr.loadPreset(preset); double density = mass / tr.getComponentVolume(); - + String materialName = "TransitionCustom"; - if ( preset.has(MATERIAL) ) { + if (preset.has(MATERIAL)) { materialName = preset.get(MATERIAL).getName(); } - - Material m = Material.newUserMaterial(Material.Type.BULK, materialName,density); + + Material m = Databases.findMaterial(Material.Type.BULK, materialName, density); preset.put(MATERIAL, m); - + } - + } - - private static void makeBulkHead( InvalidComponentPresetException exceptions, ComponentPreset preset ) { - checkRequiredFields(exceptions, preset, LENGTH, OUTER_DIAMETER ); - - if ( preset.has(MASS) ) { + + private static void makeBulkHead(InvalidComponentPresetException exceptions, ComponentPreset preset) { + checkRequiredFields(exceptions, preset, LENGTH, OUTER_DIAMETER); + + if (preset.has(MASS)) { // compute a density for this component double mass = preset.get(MASS); - + double volume = computeVolumeOfTube(preset); double density = mass / volume; - + String materialName = "BulkHeadCustom"; - if ( preset.has(MATERIAL) ) { + if (preset.has(MATERIAL)) { materialName = preset.get(MATERIAL).getName(); } - - Material m = Material.newUserMaterial(Material.Type.BULK, materialName,density); + + Material m = Databases.findMaterial(Material.Type.BULK, materialName, density); preset.put(MATERIAL, m); - + } - + } - - private static void makeCenteringRing( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException { - checkRequiredFields( exceptions, preset, LENGTH ); - - checkDiametersAndThickness( exceptions, preset ); - - double volume = computeVolumeOfTube( preset ); - + + private static void makeCenteringRing(InvalidComponentPresetException exceptions, ComponentPreset preset) throws InvalidComponentPresetException { + checkRequiredFields(exceptions, preset, LENGTH); + + checkDiametersAndThickness(exceptions, preset); + + double volume = computeVolumeOfTube(preset); + // Need to translate Mass to Density. - if ( preset.has(MASS) ) { + if (preset.has(MASS)) { String materialName = "CenteringRingCustom"; - if ( preset.has(MATERIAL) ) { + if (preset.has(MATERIAL)) { materialName = preset.get(MATERIAL).getName(); } - Material m = Material.newUserMaterial(Material.Type.BULK, materialName, preset.get(MASS)/volume); + Material m = Databases.findMaterial(Material.Type.BULK, materialName, preset.get(MASS) / volume); preset.put(MATERIAL, m); } - + } - private static void makeEngineBlock( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException { - checkRequiredFields( exceptions, preset, LENGTH ); - - checkDiametersAndThickness( exceptions, preset ); - - double volume = computeVolumeOfTube( preset ); - + private static void makeEngineBlock(InvalidComponentPresetException exceptions, ComponentPreset preset) throws InvalidComponentPresetException { + checkRequiredFields(exceptions, preset, LENGTH); + + checkDiametersAndThickness(exceptions, preset); + + double volume = computeVolumeOfTube(preset); + // Need to translate Mass to Density. - if ( preset.has(MASS) ) { + if (preset.has(MASS)) { String materialName = "EngineBlockCustom"; - if ( preset.has(MATERIAL) ) { + if (preset.has(MATERIAL)) { materialName = preset.get(MATERIAL).getName(); } - Material m = Material.newUserMaterial(Material.Type.BULK, materialName, preset.get(MASS)/volume); + Material m = Databases.findMaterial(Material.Type.BULK, materialName, preset.get(MASS) / volume); preset.put(MATERIAL, m); } - + } - private static void makeStreamer( InvalidComponentPresetException exceptions, ComponentPreset preset ) { - checkRequiredFields( exceptions, preset, LENGTH, WIDTH ); + private static void makeStreamer(InvalidComponentPresetException exceptions, ComponentPreset preset) { + checkRequiredFields(exceptions, preset, LENGTH, WIDTH); } - - private static void makeParachute( InvalidComponentPresetException exceptions, ComponentPreset preset ) { - checkRequiredFields( exceptions, preset, DIAMETER, LINE_COUNT, LINE_LENGTH ); + + private static void makeParachute(InvalidComponentPresetException exceptions, ComponentPreset preset) { + checkRequiredFields(exceptions, preset, DIAMETER, LINE_COUNT, LINE_LENGTH); } - - private static void checkRequiredFields( InvalidComponentPresetException exceptions, ComponentPreset preset, TypedKey ... keys ) { - for( TypedKey key: keys ) { - if (! preset.has(key) ) { + + private static void checkRequiredFields(InvalidComponentPresetException exceptions, ComponentPreset preset, TypedKey... keys) { + for (TypedKey key : keys) { + if (!preset.has(key)) { exceptions.addInvalidParameter(key, "No " + key.getName() + " specified"); } } } - - private static void checkDiametersAndThickness( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException { + + private static void checkDiametersAndThickness(InvalidComponentPresetException exceptions, ComponentPreset preset) throws InvalidComponentPresetException { // Need to verify contains 2 of OD, thickness, ID. Compute the third. boolean hasOd = preset.has(OUTER_DIAMETER); boolean hasId = preset.has(INNER_DIAMETER); boolean hasThickness = preset.has(THICKNESS); - + double outerRadius; double innerRadius; double thickness; - if ( hasOd ) { - outerRadius = preset.get(OUTER_DIAMETER)/2.0; + if (hasOd) { + outerRadius = preset.get(OUTER_DIAMETER) / 2.0; thickness = 0; - if ( hasId ) { - innerRadius = preset.get(INNER_DIAMETER)/2.0; + if (hasId) { + innerRadius = preset.get(INNER_DIAMETER) / 2.0; thickness = outerRadius - innerRadius; - } else if ( hasThickness ) { + } else if (hasThickness) { thickness = preset.get(THICKNESS); innerRadius = outerRadius - thickness; } else { @@ -253,27 +254,27 @@ public abstract class ComponentPresetFactory { throw exceptions; } } else { - if ( ! hasId || ! hasThickness ) { + if (!hasId || !hasThickness) { exceptions.addMessage("Preset dimensions underspecified"); throw exceptions; } - innerRadius = preset.get(INNER_DIAMETER)/2.0; + innerRadius = preset.get(INNER_DIAMETER) / 2.0; thickness = preset.get(THICKNESS); outerRadius = innerRadius + thickness; } - - preset.put(OUTER_DIAMETER, outerRadius *2.0); - preset.put(INNER_DIAMETER, innerRadius *2.0); - preset.put(THICKNESS, thickness ); - + + preset.put(OUTER_DIAMETER, outerRadius * 2.0); + preset.put(INNER_DIAMETER, innerRadius * 2.0); + preset.put(THICKNESS, thickness); + } private static double computeVolumeOfTube(ComponentPreset preset) { - double or = preset.get(OUTER_DIAMETER)/2.0; - double ir = preset.has(INNER_DIAMETER) ? preset.get(INNER_DIAMETER)/2.0 : 0.0; + double or = preset.get(OUTER_DIAMETER) / 2.0; + double ir = preset.has(INNER_DIAMETER) ? preset.get(INNER_DIAMETER) / 2.0 : 0.0; double l = preset.get(LENGTH); - return Math.PI * (or*or - ir*ir) * l; + return Math.PI * (or * or - ir * ir) * l; } - + } diff --git a/core/src/net/sf/openrocket/preset/loader/LineMaterialColumnParser.java b/core/src/net/sf/openrocket/preset/loader/LineMaterialColumnParser.java index eace7f3f..42a79722 100644 --- a/core/src/net/sf/openrocket/preset/loader/LineMaterialColumnParser.java +++ b/core/src/net/sf/openrocket/preset/loader/LineMaterialColumnParser.java @@ -1,13 +1,14 @@ package net.sf.openrocket.preset.loader; +import net.sf.openrocket.database.Databases; import net.sf.openrocket.material.Material; import net.sf.openrocket.preset.TypedKey; import net.sf.openrocket.preset.TypedPropertyMap; public class LineMaterialColumnParser extends BaseColumnParser { - + private final MaterialHolder materialMap; - + private final TypedKey param; public LineMaterialColumnParser(MaterialHolder materialMap, String columnName, TypedKey param) { @@ -16,19 +17,19 @@ public class LineMaterialColumnParser extends BaseColumnParser { this.materialMap = materialMap; } - + @Override protected void doParse(String columnData, String[] data, TypedPropertyMap props) { - - if ( columnData == null || "".equals(columnData.trim())) { + + if (columnData == null || "".equals(columnData.trim())) { return; } - Material.Line myMaterial = (Material.Line) Material.newUserMaterial(Material.Type.LINE, columnData, 0.0); - + Material.Line myMaterial = (Material.Line) Databases.findMaterial(Material.Type.LINE, columnData, 0.0); + Material.Line m = materialMap.getLineMaterial(myMaterial); - props.put(param, m!=null? m : myMaterial); - + props.put(param, m != null ? m : myMaterial); + } - + } diff --git a/core/src/net/sf/openrocket/preset/loader/MaterialColumnParser.java b/core/src/net/sf/openrocket/preset/loader/MaterialColumnParser.java index 415c11f1..2d559bb7 100644 --- a/core/src/net/sf/openrocket/preset/loader/MaterialColumnParser.java +++ b/core/src/net/sf/openrocket/preset/loader/MaterialColumnParser.java @@ -1,14 +1,15 @@ package net.sf.openrocket.preset.loader; +import net.sf.openrocket.database.Databases; import net.sf.openrocket.material.Material; import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.preset.TypedKey; import net.sf.openrocket.preset.TypedPropertyMap; public class MaterialColumnParser extends BaseColumnParser { - + private final MaterialHolder materialMap; - + private final TypedKey param; public MaterialColumnParser(MaterialHolder materialMap, String columnName, TypedKey param) { @@ -21,18 +22,18 @@ public class MaterialColumnParser extends BaseColumnParser { this(materialMap, "Material", ComponentPreset.MATERIAL); } - + @Override protected void doParse(String columnData, String[] data, TypedPropertyMap props) { - - if ( columnData == null || "".equals(columnData.trim())) { + + if (columnData == null || "".equals(columnData.trim())) { return; } - Material.Bulk tmpMaterial = (Material.Bulk) Material.newUserMaterial( Material.Type.BULK,columnData, 0.0); + Material.Bulk tmpMaterial = (Material.Bulk) Databases.findMaterial(Material.Type.BULK, columnData, 0.0); Material.Bulk m = materialMap.getBulkMaterial(tmpMaterial); - props.put(param, m!= null ? m : tmpMaterial); + props.put(param, m != null ? m : tmpMaterial); } - + } diff --git a/core/src/net/sf/openrocket/preset/loader/MaterialHolder.java b/core/src/net/sf/openrocket/preset/loader/MaterialHolder.java index 3a8dbfaa..7ab176b8 100644 --- a/core/src/net/sf/openrocket/preset/loader/MaterialHolder.java +++ b/core/src/net/sf/openrocket/preset/loader/MaterialHolder.java @@ -7,20 +7,22 @@ import java.util.List; import java.util.Map; import net.sf.openrocket.database.Database; +import net.sf.openrocket.database.Databases; import net.sf.openrocket.material.Material; import net.sf.openrocket.unit.UnitGroup; public class MaterialHolder { - - private final Map bulkMaterials = new HashMap(); - - private final Map surfaceMaterials = new HashMap(); - - private final Map lineMaterials = new HashMap(); - - public MaterialHolder() {} - public MaterialHolder( List materials ) { + private final Map bulkMaterials = new HashMap(); + + private final Map surfaceMaterials = new HashMap(); + + private final Map lineMaterials = new HashMap(); + + public MaterialHolder() { + } + + public MaterialHolder(List materials) { if (materials == null) { return; } @@ -29,8 +31,8 @@ public class MaterialHolder { } } - public void put( Material material ) { - switch ( material.getType() ) { + public void put(Material material) { + switch (material.getType()) { case BULK: bulkMaterials.put(material.getName(), (Material.Bulk) material); break; @@ -42,78 +44,78 @@ public class MaterialHolder { break; } } - - public Material getMaterial ( Material material ) { - switch ( material.getType() ) { + + public Material getMaterial(Material material) { + switch (material.getType()) { case BULK: - return getBulkMaterial( (Material.Bulk)material ); + return getBulkMaterial((Material.Bulk) material); case SURFACE: - return getSurfaceMaterial( (Material.Surface) material, null ); + return getSurfaceMaterial((Material.Surface) material, null); case LINE: - return getLineMaterial( (Material.Line) material ); + return getLineMaterial((Material.Line) material); default: return null; } } - - public Material.Bulk getBulkMaterial( Material.Bulk material ) { - Material.Bulk m = bulkMaterials.get( material.getName() ); + + public Material.Bulk getBulkMaterial(Material.Bulk material) { + Material.Bulk m = bulkMaterials.get(material.getName()); return m; } - - public Material.Surface getSurfaceMaterial( Material.Surface material, Double thickness ) { - Material.Surface m = surfaceMaterials.get(material.getName() ); - if ( m != null ) { + + public Material.Surface getSurfaceMaterial(Material.Surface material, Double thickness) { + Material.Surface m = surfaceMaterials.get(material.getName()); + if (m != null) { return m; } // Try to see if we can convert a bulk material. - if ( thickness == null ) { + if (thickness == null) { // if we have no thickness, there is nothing we can do return null; } String thicknessName = UnitGroup.UNITS_LENGTH.getUnit("mm").toString(thickness); String convertedMaterialName = material.getName() + "(" + thicknessName + ")"; m = surfaceMaterials.get(convertedMaterialName); - if ( m != null ) { + if (m != null) { return m; } - Material.Bulk bulk = bulkMaterials.get(material.getName() ); - - if ( bulk == null ) { + Material.Bulk bulk = bulkMaterials.get(material.getName()); + + if (bulk == null) { return null; } - + // Ok, now we have a thickness and a bulk material of the correct name, // we can make our own surface material. - - Material.Surface surface = (Material.Surface) Material.newUserMaterial(Material.Type.SURFACE, convertedMaterialName, bulk.getDensity() * thickness); - + + Material.Surface surface = (Material.Surface) Databases.findMaterial(Material.Type.SURFACE, convertedMaterialName, bulk.getDensity() * thickness); + this.put(surface); - + return surface; - + } - - public Material.Line getLineMaterial( Material.Line material ) { - Material.Line m = lineMaterials.get( material.getName() ); + + public Material.Line getLineMaterial(Material.Line material) { + Material.Line m = lineMaterials.get(material.getName()); return m; } - + public int size() { return bulkMaterials.size() + surfaceMaterials.size() + lineMaterials.size(); } - + public Collection values() { - + HashSet allMats = new HashSet(); - allMats.addAll( bulkMaterials.values() ); - allMats.addAll( surfaceMaterials.values() ); - allMats.addAll( lineMaterials.values() ); - + allMats.addAll(bulkMaterials.values()); + allMats.addAll(surfaceMaterials.values()); + allMats.addAll(lineMaterials.values()); + return allMats; - + } - + public Database asDatabase(Material.Type theType) { Database result = new Database(); switch (theType) { diff --git a/core/src/net/sf/openrocket/preset/loader/MaterialLoader.java b/core/src/net/sf/openrocket/preset/loader/MaterialLoader.java index 39468280..b7ef55b4 100644 --- a/core/src/net/sf/openrocket/preset/loader/MaterialLoader.java +++ b/core/src/net/sf/openrocket/preset/loader/MaterialLoader.java @@ -1,61 +1,62 @@ package net.sf.openrocket.preset.loader; +import java.io.File; + +import net.sf.openrocket.database.Databases; import net.sf.openrocket.material.Material; import net.sf.openrocket.preset.TypedKey; import net.sf.openrocket.preset.TypedPropertyMap; import net.sf.openrocket.util.BugException; -import java.io.File; - public class MaterialLoader extends RocksimComponentFileLoader { - + private MaterialHolder materialMap = new MaterialHolder(); - + private final static TypedKey MATERIALNAME = new TypedKey("MaterialName", String.class); private final static TypedKey UNITS = new TypedKey("Units", String.class); private final static TypedKey DENSITY = new TypedKey("Density", Double.class); - + public MaterialLoader(File theBasePathToLoadFrom) { super(theBasePathToLoadFrom); - fileColumns.add( new StringColumnParser("Material Name", MATERIALNAME) ); - fileColumns.add( new StringColumnParser("Units", UNITS)); - fileColumns.add( new DoubleColumnParser("Density", DENSITY)); + fileColumns.add(new StringColumnParser("Material Name", MATERIALNAME)); + fileColumns.add(new StringColumnParser("Units", UNITS)); + fileColumns.add(new DoubleColumnParser("Density", DENSITY)); } - + @Override protected RocksimComponentFileType getFileType() { return RocksimComponentFileType.MATERIAL; } - + public MaterialHolder getMaterialMap() { return materialMap; } - + @Override protected void postProcess(TypedPropertyMap props) { String name = props.get(MATERIALNAME); String unit = props.get(UNITS); double density = props.get(DENSITY); - + String cleanedMaterialName = stripAll(name, '"').trim(); - - if ( "g/cm".equals( unit ) ) { - materialMap.put( Material.newUserMaterial(Material.Type.LINE,cleanedMaterialName, 0.1d * density)); - } else if ( "g/cm2".equals(unit) ) { - materialMap.put( Material.newUserMaterial(Material.Type.SURFACE,cleanedMaterialName, 10.0d * density)); - } else if ( "g/cm3".equals(unit) ) { - materialMap.put( Material.newUserMaterial(Material.Type.BULK,cleanedMaterialName, 1000.0d * density)); - } else if ( "kg/m3".equals(unit) ) { - materialMap.put( Material.newUserMaterial(Material.Type.BULK,cleanedMaterialName, density)); - } else if ( "lb/ft3".equals(unit) ) { - materialMap.put( Material.newUserMaterial(Material.Type.BULK,cleanedMaterialName, 16.0184634d * density)); - } else if ( "oz/in".equals(unit) ) { - materialMap.put( Material.newUserMaterial(Material.Type.LINE,cleanedMaterialName, 1.11612296d * density)); - } else if ( "oz/in2".equals(unit ) ) { - materialMap.put( Material.newUserMaterial(Material.Type.SURFACE,cleanedMaterialName, 43.94184876d * density)); + + if ("g/cm".equals(unit)) { + materialMap.put(Databases.findMaterial(Material.Type.LINE, cleanedMaterialName, 0.1d * density)); + } else if ("g/cm2".equals(unit)) { + materialMap.put(Databases.findMaterial(Material.Type.SURFACE, cleanedMaterialName, 10.0d * density)); + } else if ("g/cm3".equals(unit)) { + materialMap.put(Databases.findMaterial(Material.Type.BULK, cleanedMaterialName, 1000.0d * density)); + } else if ("kg/m3".equals(unit)) { + materialMap.put(Databases.findMaterial(Material.Type.BULK, cleanedMaterialName, density)); + } else if ("lb/ft3".equals(unit)) { + materialMap.put(Databases.findMaterial(Material.Type.BULK, cleanedMaterialName, 16.0184634d * density)); + } else if ("oz/in".equals(unit)) { + materialMap.put(Databases.findMaterial(Material.Type.LINE, cleanedMaterialName, 1.11612296d * density)); + } else if ("oz/in2".equals(unit)) { + materialMap.put(Databases.findMaterial(Material.Type.SURFACE, cleanedMaterialName, 43.94184876d * density)); } else { throw new BugException("Unknown unit in Materials file: " + unit); } } - + } \ No newline at end of file diff --git a/core/src/net/sf/openrocket/preset/loader/SurfaceMaterialColumnParser.java b/core/src/net/sf/openrocket/preset/loader/SurfaceMaterialColumnParser.java index 80eaae5f..703d128c 100644 --- a/core/src/net/sf/openrocket/preset/loader/SurfaceMaterialColumnParser.java +++ b/core/src/net/sf/openrocket/preset/loader/SurfaceMaterialColumnParser.java @@ -1,13 +1,14 @@ package net.sf.openrocket.preset.loader; +import net.sf.openrocket.database.Databases; import net.sf.openrocket.material.Material; import net.sf.openrocket.preset.TypedKey; import net.sf.openrocket.preset.TypedPropertyMap; public class SurfaceMaterialColumnParser extends BaseColumnParser { - + private final MaterialHolder materialMap; - + private final TypedKey param; public SurfaceMaterialColumnParser(MaterialHolder materialMap, String columnName, TypedKey param) { @@ -16,18 +17,18 @@ public class SurfaceMaterialColumnParser extends BaseColumnParser { this.materialMap = materialMap; } - + @Override protected void doParse(String columnData, String[] data, TypedPropertyMap props) { - - if ( columnData == null || "".equals(columnData.trim())) { + + if (columnData == null || "".equals(columnData.trim())) { return; } - Material.Surface myMaterial = (Material.Surface) Material.newUserMaterial(Material.Type.SURFACE,columnData, 0.0); + Material.Surface myMaterial = (Material.Surface) Databases.findMaterial(Material.Type.SURFACE, columnData, 0.0); Material.Surface m = materialMap.getSurfaceMaterial(myMaterial, null); - props.put(param, m!=null ? m : myMaterial); - + props.put(param, m != null ? m : myMaterial); + } - + } diff --git a/core/src/net/sf/openrocket/preset/xml/BaseComponentDTO.java b/core/src/net/sf/openrocket/preset/xml/BaseComponentDTO.java index b39bc23e..ca8c18fd 100644 --- a/core/src/net/sf/openrocket/preset/xml/BaseComponentDTO.java +++ b/core/src/net/sf/openrocket/preset/xml/BaseComponentDTO.java @@ -1,13 +1,10 @@ - package net.sf.openrocket.preset.xml; -import net.sf.openrocket.database.Databases; -import net.sf.openrocket.material.Material; -import net.sf.openrocket.motor.Manufacturer; -import net.sf.openrocket.preset.ComponentPreset; -import net.sf.openrocket.preset.InvalidComponentPresetException; -import net.sf.openrocket.preset.TypedPropertyMap; -import net.sf.openrocket.unit.UnitGroup; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.List; import javax.imageio.ImageIO; import javax.xml.bind.DatatypeConverter; @@ -19,18 +16,21 @@ import javax.xml.bind.annotation.XmlInlineBinaryData; import javax.xml.bind.annotation.XmlValue; import javax.xml.bind.annotation.adapters.XmlAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.List; + +import net.sf.openrocket.database.Databases; +import net.sf.openrocket.material.Material; +import net.sf.openrocket.motor.Manufacturer; +import net.sf.openrocket.preset.ComponentPreset; +import net.sf.openrocket.preset.InvalidComponentPresetException; +import net.sf.openrocket.preset.TypedPropertyMap; +import net.sf.openrocket.unit.UnitGroup; /** * Base class for the external representation of all component presets. */ @XmlAccessorType(XmlAccessType.FIELD) public abstract class BaseComponentDTO { - + @XmlElement(name = "Manufacturer") private String manufacturer; @XmlElement(name = "PartNumber") @@ -41,19 +41,19 @@ public abstract class BaseComponentDTO { private AnnotatedMaterialDTO material; @XmlElement(name = "Mass") private AnnotatedMassDTO mass; - @XmlElement(name="Filled") + @XmlElement(name = "Filled") private Boolean filled; - @XmlInlineBinaryData - @XmlJavaTypeAdapter(Base64Adapter.class) - @XmlElement(name = "Thumbnail") - private byte[] image; - + @XmlInlineBinaryData + @XmlJavaTypeAdapter(Base64Adapter.class) + @XmlElement(name = "Thumbnail") + private byte[] image; + /** * Default constructor. */ protected BaseComponentDTO() { } - + /** * Constructor. * @@ -64,216 +64,219 @@ public abstract class BaseComponentDTO { protected BaseComponentDTO(final ComponentPreset preset) { setManufacturer(preset.getManufacturer().getSimpleName()); setPartNo(preset.getPartNo()); - if ( preset.has(ComponentPreset.DESCRIPTION )) { + if (preset.has(ComponentPreset.DESCRIPTION)) { setDescription(preset.get(ComponentPreset.DESCRIPTION)); } - if ( preset.has(ComponentPreset.MATERIAL)) { + if (preset.has(ComponentPreset.MATERIAL)) { setMaterial(new AnnotatedMaterialDTO(preset.get(ComponentPreset.MATERIAL))); } if (preset.has(ComponentPreset.MASS)) { setMass(preset.get(ComponentPreset.MASS)); } - if ( preset.has(ComponentPreset.FILLED) ) { - setFilled( preset.get(ComponentPreset.FILLED)); + if (preset.has(ComponentPreset.FILLED)) { + setFilled(preset.get(ComponentPreset.FILLED)); + } + if (preset.has(ComponentPreset.IMAGE)) { + setImageData(preset.get(ComponentPreset.IMAGE)); } - if (preset.has(ComponentPreset.IMAGE) ) { - setImageData(preset.get(ComponentPreset.IMAGE)); - } } - + public String getManufacturer() { return manufacturer; } - + public void setManufacturer(final String theManufacturer) { manufacturer = theManufacturer; } - + public String getPartNo() { return partNo; } - + public void setPartNo(final String thePartNo) { partNo = thePartNo; } - + public String getDescription() { return description; } - + public void setDescription(final String theDescription) { description = theDescription; } - + public AnnotatedMaterialDTO getMaterial() { return material; } - + public void setMaterial(final AnnotatedMaterialDTO theMaterial) { material = theMaterial; } - + public double getMass() { return mass.getValue(); } - + public void setMass(final AnnotatedMassDTO theMass) { mass = theMass; } - + public void setMass(final double theMass) { mass = new AnnotatedMassDTO(theMass); } - + public Boolean getFilled() { return filled; } - + public void setFilled(Boolean filled) { this.filled = filled; } - - public byte[] getImageData() { - return image; - } - - public void setImageData(final byte[] theImage) { - image = theImage; - } - - public BufferedImage getImage() throws IOException { - if (image != null) { - return ImageIO.read(new ByteArrayInputStream(image)); - } - return null; - } - - public void setImage(BufferedImage theImage) throws IOException { - if (theImage != null) { - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - ImageIO.write(theImage, "png", byteArrayOutputStream); - image = byteArrayOutputStream.toByteArray(); - } - } - - public abstract ComponentPreset asComponentPreset(List materials) throws InvalidComponentPresetException; - + + public byte[] getImageData() { + return image; + } + + public void setImageData(final byte[] theImage) { + image = theImage; + } + + public BufferedImage getImage() throws IOException { + if (image != null) { + return ImageIO.read(new ByteArrayInputStream(image)); + } + return null; + } + + public void setImage(BufferedImage theImage) throws IOException { + if (theImage != null) { + final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ImageIO.write(theImage, "png", byteArrayOutputStream); + image = byteArrayOutputStream.toByteArray(); + } + } + + public abstract ComponentPreset asComponentPreset(List materials) throws InvalidComponentPresetException; + void addProps(TypedPropertyMap props, List materialList) { props.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer(manufacturer)); props.put(ComponentPreset.PARTNO, partNo); - if ( description != null ) { + if (description != null) { props.put(ComponentPreset.DESCRIPTION, description); } Material m = find(materialList, material); - if ( m != null ) { + if (m != null) { props.put(ComponentPreset.MATERIAL, find(materialList, material)); } - if ( mass != null ) { + if (mass != null) { props.put(ComponentPreset.MASS, getMass()); } - if ( filled != null ) { + if (filled != null) { props.put(ComponentPreset.FILLED, getFilled()); } - if (image != null) { - props.put(ComponentPreset.IMAGE, image); - } + if (image != null) { + props.put(ComponentPreset.IMAGE, image); + } } - + protected Material find(List materialList, AnnotatedMaterialDTO dto) { - if ( dto == null ) { + if (dto == null) { return null; } for (int i = 0; i < materialList.size(); i++) { - MaterialDTO materialDTO = materialList.get(i); + MaterialDTO materialDTO = materialList.get(i); if (materialDTO.getType().name().equals(dto.type) && materialDTO.getName().equals(dto.material)) { return materialDTO.asMaterial(); } } - + // Don't have one, first check OR's database - Material m = Databases.findMaterial(dto.getORMaterialType(), dto.material); - if ( m != null ) { - return m; - } - - return Material.newUserMaterial(dto.getORMaterialType(), dto.material, 0.0); - + Material m = Databases.findMaterial(dto.getORMaterialType(), dto.material); + if (m != null) { + return m; + } + + return Databases.findMaterial(dto.getORMaterialType(), dto.material, 0.0); + } - + static class AnnotatedMaterialDTO { @XmlAttribute(name = "Type") private String type; @XmlValue private String material; - - AnnotatedMaterialDTO() {} - + + AnnotatedMaterialDTO() { + } + AnnotatedMaterialDTO(Material theMaterial) { type = theMaterial.getType().name(); material = theMaterial.getName(); } public Material.Type getORMaterialType() { - if ( "BULK".equals(type) ) { + if ("BULK".equals(type)) { return Material.Type.BULK; - } else if ( "SURFACE".equals(type) ) { + } else if ("SURFACE".equals(type)) { return Material.Type.SURFACE; - } else if ( "LINE".equals(type) ) { + } else if ("LINE".equals(type)) { return Material.Type.LINE; } - throw new IllegalArgumentException( "Inavlid material type " + type +" specified for Component" ); + throw new IllegalArgumentException("Inavlid material type " + type + " specified for Component"); } } - + static class AnnotatedLengthDTO { - @XmlAttribute(name="Unit", required=false) + @XmlAttribute(name = "Unit", required = false) private String unitName = "m"; @XmlValue private double length; - - AnnotatedLengthDTO() {} - - AnnotatedLengthDTO( double length ) { + + AnnotatedLengthDTO() { + } + + AnnotatedLengthDTO(double length) { this.length = length; } - + public double getValue() { return UnitGroup.UNITS_LENGTH.getUnit(unitName).fromUnit(length); } } - + static class AnnotatedMassDTO { - @XmlAttribute(name="Unit", required=false) + @XmlAttribute(name = "Unit", required = false) private String unitName = "kg"; @XmlValue private double mass; - - AnnotatedMassDTO() {} - - AnnotatedMassDTO( double mass ) { + + AnnotatedMassDTO() { + } + + AnnotatedMassDTO(double mass) { this.mass = mass; } - + public double getValue() { return UnitGroup.UNITS_MASS.getUnit(unitName).fromUnit(mass); } } - - static class Base64Adapter extends XmlAdapter { - @Override - public byte[] unmarshal(String s) { - if (s == null) { - return null; - } - return DatatypeConverter.parseBase64Binary(s); - } - - @Override - public String marshal(byte[] bytes) { - if (bytes == null) { - return null; - } - return DatatypeConverter.printBase64Binary(bytes); - } - } + + static class Base64Adapter extends XmlAdapter { + @Override + public byte[] unmarshal(String s) { + if (s == null) { + return null; + } + return DatatypeConverter.parseBase64Binary(s); + } + + @Override + public String marshal(byte[] bytes) { + if (bytes == null) { + return null; + } + return DatatypeConverter.printBase64Binary(bytes); + } + } } diff --git a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java index 405596a4..abcebda7 100644 --- a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java +++ b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java @@ -1,4 +1,3 @@ - package net.sf.openrocket.preset.xml; import javax.xml.bind.Marshaller; @@ -9,6 +8,7 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import net.sf.openrocket.database.Databases; import net.sf.openrocket.material.Material; import net.sf.openrocket.util.Chars; @@ -18,97 +18,97 @@ import net.sf.openrocket.util.Chars; @XmlRootElement(name = "Material") @XmlAccessorType(XmlAccessType.FIELD) public class MaterialDTO { - - @XmlElement(name = "Name") - private String name; - @XmlElement(name = "Density") - private double density; - @XmlElement(name = "Type") - 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 Material.newUserMaterial(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 - * opposite transformation as doen in beforeMarshal. - * @param unmarshaller - * @param parent - */ - @SuppressWarnings("unused") - private void afterUnmarshal( Unmarshaller unmarshaller, Object parent ) { - if (uom != null) { - uom = uom.replace('2', Chars.SQUARED); - 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 - * as simple "3" and "2" chars. The reverse transformation is done in afterUnmarshal. - * @param marshaller - */ - @SuppressWarnings("unused") - private void beforeMarshal( Marshaller marshaller ) { - if (uom != null ) { - uom = uom.replace(Chars.SQUARED, '2'); - uom = uom.replace(Chars.CUBED, '3'); - } - } + + @XmlElement(name = "Name") + private String name; + @XmlElement(name = "Density") + private double density; + @XmlElement(name = "Type") + 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 + * opposite transformation as doen in beforeMarshal. + * @param unmarshaller + * @param parent + */ + @SuppressWarnings("unused") + private void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { + if (uom != null) { + uom = uom.replace('2', Chars.SQUARED); + 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 + * as simple "3" and "2" chars. The reverse transformation is done in afterUnmarshal. + * @param marshaller + */ + @SuppressWarnings("unused") + private void beforeMarshal(Marshaller marshaller) { + if (uom != null) { + uom = uom.replace(Chars.SQUARED, '2'); + uom = uom.replace(Chars.CUBED, '3'); + } + } } diff --git a/core/src/net/sf/openrocket/startup/Preferences.java b/core/src/net/sf/openrocket/startup/Preferences.java index ca82aa3f..73a29cc2 100644 --- a/core/src/net/sf/openrocket/startup/Preferences.java +++ b/core/src/net/sf/openrocket/startup/Preferences.java @@ -5,7 +5,6 @@ import java.util.Map; import java.util.Set; import net.sf.openrocket.database.Databases; -import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.material.Material; import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.rocketcomponent.BodyComponent; @@ -23,7 +22,7 @@ import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.UniqueID; public abstract class Preferences { - + /* * Well known string keys to preferences. * There are other strings out there in the source as well. @@ -46,26 +45,30 @@ public abstract class Preferences { public static final String MOTOR_DIAMETER_FILTER = "MotorDiameterMatch"; public static final String MOTOR_HIDE_SIMILAR = "MotorHideSimilar"; - + // Node names public static final String PREFERRED_THRUST_CURVE_MOTOR_NODE = "preferredThrustCurveMotors"; - + /* * ****************************************************************************************** * * Abstract methods which must be implemented by any derived class. */ - public abstract boolean getBoolean( String key, boolean defaultValue ); - public abstract void putBoolean( String key, boolean value ); - - public abstract int getInt( String key, int defaultValue); - public abstract void putInt( String key, int value ); - - public abstract double getDouble( String key, double defaultValue ); - public abstract void putDouble( String key, double value ); - - public abstract String getString( String key, String defaultValue ); - public abstract void putString( String key, String value ); + public abstract boolean getBoolean(String key, boolean defaultValue); + + public abstract void putBoolean(String key, boolean value); + + public abstract int getInt(String key, int defaultValue); + + public abstract void putInt(String key, int value); + + public abstract double getDouble(String key, double defaultValue); + + public abstract void putDouble(String key, double value); + + public abstract String getString(String key, String defaultValue); + + public abstract void putString(String key, String value); /** * Directory represents a way to collect multiple keys together. Implementors may @@ -75,10 +78,10 @@ public abstract class Preferences { * @param defaultValue * @return */ - public abstract String getString( String directory, String key, String defaultValue); - - public abstract void putString( String directory, String key, String value ); - + public abstract String getString(String directory, String key, String defaultValue); + + public abstract void putString(String directory, String key, String value); + /* * ****************************************************************************************** */ @@ -174,7 +177,7 @@ public abstract class Preferences { putString(key, value.name()); } } - + public Color getDefaultColor(Class c) { String color = get("componentColors", c, DEFAULT_COLORS); if (color == null) @@ -193,8 +196,8 @@ public abstract class Preferences { return; putString("componentColors", c.getSimpleName(), stringifyColor(color)); } - - + + /** * Retrieve a Line style for the given component. * @param c @@ -234,7 +237,7 @@ public abstract class Preferences { String material = get("componentMaterials", componentClass, null); if (material != null) { try { - Material m = Material.fromStorableString(material); + Material m = Material.fromStorableString(material, false); if (m.getType() == type) return m; } catch (IllegalArgumentException ignore) { @@ -263,16 +266,16 @@ public abstract class Preferences { putString("componentMaterials", componentClass.getSimpleName(), material == null ? null : material.toStorableString()); } - + /** * get a net.sf.openrocket.util.Color object for the given key. * @param key * @param defaultValue * @return */ - public final Color getColor( String key, Color defaultValue ) { - Color c = parseColor( getString(key,null) ); - if ( c == null ) { + public final Color getColor(String key, Color defaultValue) { + Color c = parseColor(getString(key, null)); + if (c == null) { return defaultValue; } return c; @@ -283,10 +286,10 @@ public abstract class Preferences { * @param key * @param value */ - public final void putColor( String key, Color value ) { - putString( key, stringifyColor(value) ); + public final void putColor(String key, Color value) { + putString(key, stringifyColor(value)); } - + /** * Helper function to convert a string representation into a net.sf.openrocket.util.Color object. * @param color @@ -320,7 +323,7 @@ public abstract class Preferences { String string = color.getRed() + "," + color.getGreen() + "," + color.getBlue(); return string; } - + /** * Special helper function which allows for a map of default values. * @@ -359,14 +362,17 @@ public abstract class Preferences { return null; } - + public abstract void addUserMaterial(Material m); + public abstract Set getUserMaterials(); + public abstract void removeUserMaterial(Material m); - - public abstract void setComponentFavorite( ComponentPreset preset, ComponentPreset.Type type, boolean favorite ); - public abstract Set getComponentFavorites( ComponentPreset.Type type ); - + + public abstract void setComponentFavorite(ComponentPreset preset, ComponentPreset.Type type, boolean favorite); + + public abstract Set getComponentFavorites(ComponentPreset.Type type); + /* * Map of default line styles */ @@ -381,17 +387,9 @@ public abstract class Preferences { * Within a holder class so they will load only when needed. */ private static class DefaultMaterialHolder { - private static final Translator trans = Application.getTranslator(); - - //// Elastic cord (round 2mm, 1/16 in) - private static final Material DEFAULT_LINE_MATERIAL = - Databases.findMaterial(Material.Type.LINE, "Elasticcordround2mm", trans.get("Databases.materials.Elasticcordround2mm"),0.0018); - //// Ripstop nylon - private static final Material DEFAULT_SURFACE_MATERIAL = - Databases.findMaterial(Material.Type.SURFACE, "Ripstopnylon", trans.get("Databases.materials.Ripstopnylon"), 0.067); - //// Cardboard - private static final Material DEFAULT_BULK_MATERIAL = - Databases.findMaterial(Material.Type.BULK, "Cardboard", trans.get("Databases.materials.Cardboard"), 680); + private static final Material DEFAULT_LINE_MATERIAL = Databases.findMaterial(Material.Type.LINE, "Elastic cord (round 2 mm, 1/16 in)"); + private static final Material DEFAULT_SURFACE_MATERIAL = Databases.findMaterial(Material.Type.SURFACE, "Ripstop nylon"); + private static final Material DEFAULT_BULK_MATERIAL = Databases.findMaterial(Material.Type.BULK, "Cardboard"); } private static final HashMap, String> DEFAULT_COLORS = @@ -405,6 +403,6 @@ public abstract class Preferences { DEFAULT_COLORS.put(RecoveryDevice.class, "255,0,0"); } - - + + } diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index 6d3c7e59..7a670e16 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -2,6 +2,7 @@ package net.sf.openrocket.util; import java.util.Random; +import net.sf.openrocket.database.Databases; import net.sf.openrocket.material.Material; import net.sf.openrocket.material.Material.Type; import net.sf.openrocket.motor.Motor; @@ -81,12 +82,12 @@ public class TestRockets { rocket.setRevision("Rocket revision " + key); rocket.setName(key); - + Stage stage = new Stage(); setBasics(stage); rocket.addChild(stage); - + NoseCone nose = new NoseCone(); setBasics(stage); nose.setAftRadius(rnd(0.03)); @@ -104,7 +105,7 @@ public class TestRockets { nose.setType((Shape) randomEnum(Shape.class)); stage.addChild(nose); - + Transition shoulder = new Transition(); setBasics(shoulder); shoulder.setAftRadius(rnd(0.06)); @@ -128,7 +129,7 @@ public class TestRockets { shoulder.setType((Shape) randomEnum(Shape.class)); stage.addChild(shoulder); - + BodyTube body = new BodyTube(); setBasics(body); body.setThickness(rnd(0.002)); @@ -142,7 +143,7 @@ public class TestRockets { body.setOuterRadiusAutomatic(rnd.nextBoolean()); stage.addChild(body); - + Transition boattail = new Transition(); setBasics(boattail); boattail.setAftRadius(rnd(0.03)); @@ -166,7 +167,7 @@ public class TestRockets { boattail.setType((Shape) randomEnum(Shape.class)); stage.addChild(boattail); - + MassComponent mass = new MassComponent(); setBasics(mass); mass.setComponentMass(rnd(0.05)); @@ -176,9 +177,9 @@ public class TestRockets { mass.setRadius(rnd(0.05)); nose.addChild(mass); - - - + + + return rocket; } @@ -203,7 +204,7 @@ public class TestRockets { ExternalComponent e = (ExternalComponent) c; e.setFinish((Finish) randomEnum(Finish.class)); double d = rnd(100); - e.setMaterial(Material.newUserMaterial(Type.BULK, "Testmat " + d, d)); + e.setMaterial(Databases.findMaterial(Type.BULK, "Testmat " + d, d)); } if (c instanceof InternalComponent) { @@ -214,7 +215,7 @@ public class TestRockets { } - + private double rnd(double scale) { return (rnd.nextDouble() * 0.2 + 0.9) * scale; } @@ -232,9 +233,9 @@ public class TestRockets { } - - - + + + public Rocket makeSmallFlyable() { double noseconeLength = 0.10, noseconeRadius = 0.01; double bodytubeLength = 0.20, bodytubeRadius = 0.01, bodytubeThickness = 0.001; @@ -242,7 +243,7 @@ public class TestRockets { int finCount = 3; double finRootChord = 0.04, finTipChord = 0.05, finSweep = 0.01, finThickness = 0.003, finHeight = 0.03; - + Rocket rocket; Stage stage; NoseCone nosecone; @@ -258,11 +259,11 @@ public class TestRockets { finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight); - + // Stage construction rocket.addChild(stage); - + // Component construction stage.addChild(nosecone); stage.addChild(bodytube); @@ -284,7 +285,7 @@ public class TestRockets { rocket.getDefaultConfiguration().setAllStages(); - + return rocket; } @@ -331,7 +332,7 @@ public class TestRockets { rocket.addChild(stage); rocket.setPerfectFinish(false); - + // Component construction stage.addChild(nosecone); stage.addChild(bodytube); @@ -355,12 +356,12 @@ public class TestRockets { rocket.getDefaultConfiguration().setAllStages(); - + return rocket; } - + public static Rocket makeIsoHaisu() { Rocket rocket; Stage stage; @@ -397,7 +398,7 @@ public class TestRockets { tube3.setOverrideMass(0.730); stage.addChild(tube3); - + LaunchLug lug = new LaunchLug(); tube1.addChild(lug); @@ -411,7 +412,7 @@ public class TestRockets { coupler.setPositionValue(-0.14); tube1.addChild(coupler); - + // Parachute MassComponent mass = new MassComponent(0.05, 0.05, 0.280); mass.setRelativePosition(Position.TOP); @@ -430,7 +431,7 @@ public class TestRockets { mass.setPositionValue(0.25); tube1.addChild(mass); - + auxfinset = new TrapezoidFinSet(); auxfinset.setName("CONTROL"); auxfinset.setFinCount(2); @@ -445,9 +446,9 @@ public class TestRockets { auxfinset.setBaseRotation(Math.PI / 2); tube1.addChild(auxfinset); - - - + + + coupler = new TubeCoupler(); coupler.setOuterRadiusAutomatic(true); coupler.setLength(0.28); @@ -457,8 +458,8 @@ public class TestRockets { coupler.setOverrideMass(0.360); tube2.addChild(coupler); - - + + // Parachute mass = new MassComponent(0.1, 0.05, 0.028); mass.setRelativePosition(Position.TOP); @@ -479,8 +480,8 @@ public class TestRockets { mass.setPositionValue(0.19); tube2.addChild(mass); - - + + InnerTube inner = new InnerTube(); inner.setOuterRadius(0.08 / 2); inner.setInnerRadius(0.0762 / 2); @@ -489,7 +490,7 @@ public class TestRockets { inner.setOverrideMass(0.388); tube3.addChild(inner); - + CenteringRing center = new CenteringRing(); center.setInnerRadiusAutomatic(true); center.setOuterRadiusAutomatic(true); @@ -500,7 +501,7 @@ public class TestRockets { center.setPositionValue(0); tube3.addChild(center); - + center = new CenteringRing(); center.setInnerRadiusAutomatic(true); center.setOuterRadiusAutomatic(true); @@ -511,7 +512,7 @@ public class TestRockets { center.setPositionValue(0.28); tube3.addChild(center); - + center = new CenteringRing(); center.setInnerRadiusAutomatic(true); center.setOuterRadiusAutomatic(true); @@ -522,10 +523,10 @@ public class TestRockets { center.setPositionValue(0.83); tube3.addChild(center); - - - - + + + + finset = new TrapezoidFinSet(); finset.setRootChord(0.495); finset.setTipChord(0.1); @@ -537,17 +538,17 @@ public class TestRockets { finset.setBaseRotation(Math.PI / 2); tube3.addChild(finset); - + finset.setCantAngle(0 * Math.PI / 180); System.err.println("Fin cant angle: " + (finset.getCantAngle() * 180 / Math.PI)); - + // Stage construction rocket.addChild(stage); rocket.setPerfectFinish(false); - - + + String id = rocket.newMotorConfigurationID(); tube3.setMotorMount(true); @@ -560,10 +561,10 @@ public class TestRockets { rocket.getDefaultConfiguration().setAllStages(); - + return rocket; } - - + + } diff --git a/core/test/net/sf/openrocket/l10n/TestDebugTranslator.java b/core/test/net/sf/openrocket/l10n/TestDebugTranslator.java new file mode 100644 index 00000000..698094f9 --- /dev/null +++ b/core/test/net/sf/openrocket/l10n/TestDebugTranslator.java @@ -0,0 +1,24 @@ +package net.sf.openrocket.l10n; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class TestDebugTranslator { + + @Test + public void testGetEnglish() { + DebugTranslator trans = new DebugTranslator(null); + assertEquals("[material:Paper (office)]", trans.get("material", "Paper (office)")); + } + + + @Test + public void testGetBase() { + DebugTranslator trans = new DebugTranslator(null); + assertEquals("Paper (office)", trans.getBaseText("material", "[material:Paper (office)]")); + assertEquals("Papier (toilet)", trans.getBaseText("material", "Papier (toilet)")); + } + + +} diff --git a/core/test/net/sf/openrocket/l10n/TestL10N.java b/core/test/net/sf/openrocket/l10n/TestL10N.java new file mode 100644 index 00000000..abe53113 --- /dev/null +++ b/core/test/net/sf/openrocket/l10n/TestL10N.java @@ -0,0 +1,30 @@ +package net.sf.openrocket.l10n; + +import static org.junit.Assert.assertEquals; +import net.sf.openrocket.util.Chars; + +import org.junit.Test; + +public class TestL10N { + + @Test + public void testNormalize() { + assertEquals("hello", L10N.normalize("hello")); + assertEquals("hello", L10N.normalize("Hello")); + assertEquals("hello", L10N.normalize(" \t Hello \n ")); + assertEquals("hello", L10N.normalize("H\u00eall\u00d6")); + assertEquals("hello_world", L10N.normalize("Hello World!")); + assertEquals("hello_world", L10N.normalize("? Hello\nWorld !")); + assertEquals("hello_123", L10N.normalize("Hello 123!")); + assertEquals("hello_123", L10N.normalize("Hello/123?")); + + assertEquals("plywood_birch", L10N.normalize("Plywood (birch)")); + assertEquals("styrofoam_blue_foam_xps", L10N.normalize("Styrofoam \"Blue foam\" (XPS)")); + assertEquals("tubular_nylon_11_mm_7_16_in", L10N.normalize("Tubular nylon (11 mm, 7/16 in)")); + + assertEquals("m2", L10N.normalize("m" + Chars.SQUARED)); + assertEquals("a_b", L10N.normalize("a" + Chars.NBSP + "b")); + assertEquals("1_2a", L10N.normalize(Chars.FRAC12 + "A")); + + } +} diff --git a/core/test/net/sf/openrocket/l10n/TestResourceBundleTranslator.java b/core/test/net/sf/openrocket/l10n/TestResourceBundleTranslator.java index db7dbfc7..992bcc2c 100644 --- a/core/test/net/sf/openrocket/l10n/TestResourceBundleTranslator.java +++ b/core/test/net/sf/openrocket/l10n/TestResourceBundleTranslator.java @@ -5,18 +5,35 @@ import static org.junit.Assert.*; import java.util.Locale; import java.util.MissingResourceException; +import org.junit.After; +import org.junit.Before; import org.junit.Test; public class TestResourceBundleTranslator { + private Locale originalDefaultLocale; + + @Before + public void setup() { + // Default locale affects resource bundles, so set something non-English + this.originalDefaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.GERMAN); + } + + @After + public void teardown() { + Locale.setDefault(originalDefaultLocale); + } + + @Test - public void testSuccessfulUS() { - ResourceBundleTranslator trans = new ResourceBundleTranslator("l10n.messages", Locale.US); - assertEquals("messages.properties", trans.get("debug.currentFile")); + public void testSuccessfulDefault() { + ResourceBundleTranslator trans = new ResourceBundleTranslator("l10n.messages"); + assertEquals("messages_de.properties", trans.get("debug.currentFile")); } @Test - public void testSuccessfulFR() { + public void testSuccessfulNonDefault() { ResourceBundleTranslator trans = new ResourceBundleTranslator("l10n.messages", Locale.FRENCH); assertEquals("messages_fr.properties", trans.get("debug.currentFile")); } @@ -31,4 +48,20 @@ public class TestResourceBundleTranslator { } } + @Test + public void testGetEnglish() { + ResourceBundleTranslator trans = new ResourceBundleTranslator("l10n.messages", Locale.FRENCH); + assertEquals("Papier (bureau)", trans.get("material", "Paper (office)")); + assertEquals("Paper (toilet)", trans.get("material", "Paper (toilet)")); + } + + + @Test + public void testGetBase() { + ResourceBundleTranslator trans = new ResourceBundleTranslator("l10n.messages", Locale.FRENCH); + assertEquals("Paper (office)", trans.getBaseText("material", "Papier (bureau)")); + assertEquals("Papier (toilet)", trans.getBaseText("material", "Papier (toilet)")); + } + + } diff --git a/core/test/net/sf/openrocket/preset/BodyTubeComponentTests.java b/core/test/net/sf/openrocket/preset/BodyTubeComponentTests.java index bb70a6eb..891d9ed3 100644 --- a/core/test/net/sf/openrocket/preset/BodyTubeComponentTests.java +++ b/core/test/net/sf/openrocket/preset/BodyTubeComponentTests.java @@ -20,27 +20,27 @@ import org.junit.Test; * */ public class BodyTubeComponentTests extends BaseTestCase { - + ComponentPreset preset; @Before public void createPreset() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); preset = ComponentPresetFactory.create(presetspec); } - + @Test public void testComponentType() { BodyTube bt = new BodyTube(); - assertSame( ComponentPreset.Type.BODY_TUBE, bt.getPresetType() ); + assertSame(ComponentPreset.Type.BODY_TUBE, bt.getPresetType()); } @Test @@ -49,18 +49,18 @@ public class BodyTubeComponentTests extends BaseTestCase { bt.loadPreset(preset); - assertEquals( 2.0, bt.getLength(), 0.0 ); - assertEquals( 1.0, bt.getOuterRadius(), 0.0 ); - assertEquals( 1.0, bt.getAftRadius(), 0.0 ); - assertEquals( 0.5, bt.getInnerRadius(), 0.0 ); + assertEquals(2.0, bt.getLength(), 0.0); + assertEquals(1.0, bt.getOuterRadius(), 0.0); + assertEquals(1.0, bt.getAftRadius(), 0.0); + assertEquals(0.5, bt.getInnerRadius(), 0.0); - assertFalse( bt.isAftRadiusAutomatic() ); - assertFalse( bt.isFilled() ); - assertFalse( bt.isForeRadiusAutomatic() ); - assertFalse( bt.isOuterRadiusAutomatic() ); + assertFalse(bt.isAftRadiusAutomatic()); + assertFalse(bt.isFilled()); + assertFalse(bt.isForeRadiusAutomatic()); + assertFalse(bt.isOuterRadiusAutomatic()); - assertSame( preset.get( ComponentPreset.MATERIAL), bt.getMaterial() ); - assertEquals( 100.0, bt.getMass(), 0.05); + assertSame(preset.get(ComponentPreset.MATERIAL), bt.getMaterial()); + assertEquals(100.0, bt.getMass(), 0.05); } @Test @@ -68,75 +68,75 @@ public class BodyTubeComponentTests extends BaseTestCase { BodyTube bt = new BodyTube(); bt.loadPreset(preset); - + bt.setLength(1.0); - assertSame( preset, bt.getPresetComponent() ); + assertSame(preset, bt.getPresetComponent()); } - + @Test public void changeODClearsPreset() { BodyTube bt = new BodyTube(); bt.loadPreset(preset); - + bt.setOuterRadius(2.0); - assertNull( bt.getPresetComponent() ); + assertNull(bt.getPresetComponent()); } - + @Test public void changeIDClearsPreset() { BodyTube bt = new BodyTube(); bt.loadPreset(preset); - + bt.setInnerRadius(0.75); - assertNull( bt.getPresetComponent() ); + assertNull(bt.getPresetComponent()); } - + @Test public void changeThicknessClearsPreset() { BodyTube bt = new BodyTube(); bt.loadPreset(preset); - + bt.setThickness(0.1); - assertNull( bt.getPresetComponent() ); + assertNull(bt.getPresetComponent()); } - + @Test public void changeMaterialClearsPreset() { BodyTube bt = new BodyTube(); bt.loadPreset(preset); - - bt.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0)); - assertNull( bt.getPresetComponent() ); + bt.setMaterial(Material.newMaterial(Material.Type.BULK, "new", 1.0, true)); + + assertNull(bt.getPresetComponent()); } - + @Test public void changeFinishLeavesPreset() { BodyTube bt = new BodyTube(); bt.loadPreset(preset); - - bt.setFinish( Finish.POLISHED ); - assertSame( preset, bt.getPresetComponent() ); + bt.setFinish(Finish.POLISHED); + + assertSame(preset, bt.getPresetComponent()); } - + @Test public void changeFillClearsPreset() { BodyTube bt = new BodyTube(); bt.loadPreset(preset); - - bt.setFilled( true ); - assertNull( bt.getPresetComponent() ); + bt.setFilled(true); + + assertNull(bt.getPresetComponent()); } } diff --git a/core/test/net/sf/openrocket/preset/BodyTubePresetTests.java b/core/test/net/sf/openrocket/preset/BodyTubePresetTests.java index 182605f5..33d75293 100644 --- a/core/test/net/sf/openrocket/preset/BodyTubePresetTests.java +++ b/core/test/net/sf/openrocket/preset/BodyTubePresetTests.java @@ -16,256 +16,256 @@ import org.junit.Test; * */ public class BodyTubePresetTests { - + @Test public void testManufacturerRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.MANUFACTURER, - ComponentPreset.PARTNO, - ComponentPreset.LENGTH - }, - new String[] { - "No Manufacturer specified", - "No PartNo specified", - "No Length specified", - "Preset dimensions underspecified" - } + ComponentPreset.MANUFACTURER, + ComponentPreset.PARTNO, + ComponentPreset.LENGTH + }, + new String[] { + "No Manufacturer specified", + "No PartNo specified", + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testPartNoRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.PARTNO, - ComponentPreset.LENGTH - }, - new String[] { - "No PartNo specified", - "No Length specified", - "Preset dimensions underspecified" - } + ComponentPreset.PARTNO, + ComponentPreset.LENGTH + }, + new String[] { + "No PartNo specified", + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testLengthRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { ComponentPreset.LENGTH - }, - new String[] { - "No Length specified", - "Preset dimensions underspecified" - } + }, + new String[] { + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testOnlyOuterDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testOnlyInnerDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testOnlyThicknessDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.THICKNESS, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.THICKNESS, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testComputeInnerDiameter() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.THICKNESS, 0.5); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.THICKNESS, 0.5); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(1.0,preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(),0.0); + + assertEquals(1.0, preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(), 0.0); } - + @Test public void testComputeOuterDiameter() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.THICKNESS, 0.5); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.THICKNESS, 0.5); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(2.0,preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(),0.0); + + assertEquals(2.0, preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(), 0.0); } - + @Test public void testComputeThickness() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0); + + assertEquals(0.5, preset.get(ComponentPreset.THICKNESS).doubleValue(), 0.0); } - + @Test public void testComputeThicknessLooses() throws Exception { // If all OUTER_DIAMETER, INNER_DIAMETER and THICKNESS are // specified, THICKNESS is recomputed. TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.THICKNESS, 15.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.THICKNESS, 15.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0); + + assertEquals(0.5, preset.get(ComponentPreset.THICKNESS).doubleValue(), 0.0); } - + @Test public void testComputeDensityNoMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); + double volume = /*outer area*/(Math.PI * 1.0) - /* inner area */(Math.PI * .25); volume *= 2.0; /* times length */ - + double density = 100.0 / volume; - - assertEquals("TubeCustom",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + + assertEquals("TubeCustom", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); - + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(2.0, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); + } - + @Test public void testComputeDensityWithMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); + double volume = /*outer area*/(Math.PI * 1.0) - /* inner area */(Math.PI * .25); volume *= 2.0; /* times length */ - + double density = 100.0 / volume; - - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + } diff --git a/core/test/net/sf/openrocket/preset/BulkHeadComponentTests.java b/core/test/net/sf/openrocket/preset/BulkHeadComponentTests.java index 4d9734c8..6a1c8463 100644 --- a/core/test/net/sf/openrocket/preset/BulkHeadComponentTests.java +++ b/core/test/net/sf/openrocket/preset/BulkHeadComponentTests.java @@ -1,9 +1,6 @@ package net.sf.openrocket.preset; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.rocketcomponent.Bulkhead; @@ -22,26 +19,26 @@ import org.junit.Test; * */ public class BulkHeadComponentTests extends BaseTestCase { - + ComponentPreset preset; @Before public void createPreset() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MASS, 100.0); preset = ComponentPresetFactory.create(presetspec); } - + @Test public void testComponentType() { Bulkhead bt = new Bulkhead(); - assertSame( ComponentPreset.Type.BULK_HEAD, bt.getPresetType() ); + assertSame(ComponentPreset.Type.BULK_HEAD, bt.getPresetType()); } @Test @@ -50,13 +47,13 @@ public class BulkHeadComponentTests extends BaseTestCase { bt.loadPreset(preset); - assertEquals( 2.0, bt.getLength(), 0.0 ); - assertEquals( 1.0, bt.getOuterRadius(), 0.0 ); + assertEquals(2.0, bt.getLength(), 0.0); + assertEquals(1.0, bt.getOuterRadius(), 0.0); - assertFalse( bt.isOuterRadiusAutomatic() ); + assertFalse(bt.isOuterRadiusAutomatic()); - assertSame( preset.get( ComponentPreset.MATERIAL), bt.getMaterial() ); - assertEquals( 100.0, bt.getMass(), 0.05); + assertSame(preset.get(ComponentPreset.MATERIAL), bt.getMaterial()); + assertEquals(100.0, bt.getMass(), 0.05); } @Test @@ -64,23 +61,23 @@ public class BulkHeadComponentTests extends BaseTestCase { Bulkhead bt = new Bulkhead(); bt.loadPreset(preset); - + bt.setLength(1.0); - assertSame( preset, bt.getPresetComponent() ); + assertSame(preset, bt.getPresetComponent()); } - + @Test public void changeODClearsPreset() { Bulkhead bt = new Bulkhead(); bt.loadPreset(preset); - + bt.setOuterRadius(2.0); - assertNull( bt.getPresetComponent() ); + assertNull(bt.getPresetComponent()); } - + @Test public void changeODAutomaticClearsPreset() { Bulkhead bt = new Bulkhead(); @@ -88,19 +85,19 @@ public class BulkHeadComponentTests extends BaseTestCase { bt.loadPreset(preset); bt.setOuterRadiusAutomatic(true); - - assertNull( bt.getPresetComponent() ); + + assertNull(bt.getPresetComponent()); } - + @Test public void changeMaterialClearsPreset() { Bulkhead bt = new Bulkhead(); bt.loadPreset(preset); - - bt.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0)); - assertNull( bt.getPresetComponent() ); + bt.setMaterial(Material.newMaterial(Material.Type.BULK, "new", 1.0, true)); + + assertNull(bt.getPresetComponent()); } - + } diff --git a/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java b/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java index 9f54ae95..2f393bac 100644 --- a/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java +++ b/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java @@ -16,158 +16,158 @@ import org.junit.Test; * */ public class BulkHeadPresetTests { - + @Test public void testManufacturerRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.MANUFACTURER, - ComponentPreset.PARTNO, - ComponentPreset.LENGTH, - ComponentPreset.OUTER_DIAMETER - }, - new String[] { - "No Manufacturer specified", - "No PartNo specified", - "No Length specified", - "No OuterDiameter specified" - } + ComponentPreset.MANUFACTURER, + ComponentPreset.PARTNO, + ComponentPreset.LENGTH, + ComponentPreset.OUTER_DIAMETER + }, + new String[] { + "No Manufacturer specified", + "No PartNo specified", + "No Length specified", + "No OuterDiameter specified" + } ); } } - + @Test public void testPartNoRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.PARTNO, - ComponentPreset.LENGTH, - ComponentPreset.OUTER_DIAMETER - }, - new String[] { - "No PartNo specified", - "No Length specified", - "No OuterDiameter specified" - } + ComponentPreset.PARTNO, + ComponentPreset.LENGTH, + ComponentPreset.OUTER_DIAMETER + }, + new String[] { + "No PartNo specified", + "No Length specified", + "No OuterDiameter specified" + } ); } } - + @Test public void testLengthRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.LENGTH, - ComponentPreset.OUTER_DIAMETER - }, - new String[] { - "No Length specified", - "No OuterDiameter specified" - } + ComponentPreset.LENGTH, + ComponentPreset.OUTER_DIAMETER + }, + new String[] { + "No Length specified", + "No OuterDiameter specified" + } ); } } - + @Test public void testOuterDiameterRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { ComponentPreset.OUTER_DIAMETER - }, - new String[] { + }, + new String[] { "No OuterDiameter specified" - } + } ); } } - + @Test public void testComputeDensityNoMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MASS, 100.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0); + double volume = /*outer area*/(Math.PI * 1.0); volume *= 2.0; /* times length */ double density = 100.0 / volume; - assertEquals("BulkHeadCustom",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + assertEquals("BulkHeadCustom", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(2.0, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testComputeDensityWithMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.MASS, 100.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0); + double volume = /*outer area*/(Math.PI * 1.0); volume *= 2.0; /* times length */ double density = 100.0 / volume; - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + } diff --git a/core/test/net/sf/openrocket/preset/CenteringRingComponentTests.java b/core/test/net/sf/openrocket/preset/CenteringRingComponentTests.java index 2b638655..dac3f8fd 100644 --- a/core/test/net/sf/openrocket/preset/CenteringRingComponentTests.java +++ b/core/test/net/sf/openrocket/preset/CenteringRingComponentTests.java @@ -1,9 +1,6 @@ package net.sf.openrocket.preset; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.rocketcomponent.CenteringRing; @@ -22,27 +19,27 @@ import org.junit.Test; * */ public class CenteringRingComponentTests extends BaseTestCase { - + ComponentPreset preset; @Before public void createPreset() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); preset = ComponentPresetFactory.create(presetspec); } - + @Test public void testComponentType() { CenteringRing cr = new CenteringRing(); - assertSame( ComponentPreset.Type.CENTERING_RING, cr.getPresetType() ); + assertSame(ComponentPreset.Type.CENTERING_RING, cr.getPresetType()); } @Test @@ -51,14 +48,14 @@ public class CenteringRingComponentTests extends BaseTestCase { cr.loadPreset(preset); - assertEquals( 2.0, cr.getLength(), 0.0 ); - assertEquals( 1.0, cr.getOuterRadius(), 0.0 ); - assertEquals( 0.5, cr.getInnerRadius(), 0.0 ); + assertEquals(2.0, cr.getLength(), 0.0); + assertEquals(1.0, cr.getOuterRadius(), 0.0); + assertEquals(0.5, cr.getInnerRadius(), 0.0); - assertFalse( cr.isOuterRadiusAutomatic() ); + assertFalse(cr.isOuterRadiusAutomatic()); - assertSame( preset.get( ComponentPreset.MATERIAL), cr.getMaterial() ); - assertEquals( 100.0, cr.getMass(), 0.05); + assertSame(preset.get(ComponentPreset.MATERIAL), cr.getMaterial()); + assertEquals(100.0, cr.getMass(), 0.05); } @Test @@ -66,54 +63,54 @@ public class CenteringRingComponentTests extends BaseTestCase { CenteringRing cr = new CenteringRing(); cr.loadPreset(preset); - + cr.setLength(1.0); - assertSame( preset, cr.getPresetComponent() ); + assertSame(preset, cr.getPresetComponent()); } - + @Test public void changeODClearsPreset() { CenteringRing cr = new CenteringRing(); cr.loadPreset(preset); - + cr.setOuterRadius(2.0); - assertNull( cr.getPresetComponent() ); + assertNull(cr.getPresetComponent()); } - + @Test public void changeIDClearsPreset() { CenteringRing cr = new CenteringRing(); cr.loadPreset(preset); - + cr.setInnerRadius(0.75); - assertNull( cr.getPresetComponent() ); + assertNull(cr.getPresetComponent()); } - + @Test public void changeThicknessClearsPreset() { CenteringRing cr = new CenteringRing(); cr.loadPreset(preset); - + cr.setThickness(0.1); - assertNull( cr.getPresetComponent() ); + assertNull(cr.getPresetComponent()); } - + @Test public void changeMaterialClearsPreset() { CenteringRing cr = new CenteringRing(); cr.loadPreset(preset); - - cr.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0)); - assertNull( cr.getPresetComponent() ); + cr.setMaterial(Material.newMaterial(Material.Type.BULK, "new", 1.0, true)); + + assertNull(cr.getPresetComponent()); } - + } diff --git a/core/test/net/sf/openrocket/preset/CenteringRingPresetTests.java b/core/test/net/sf/openrocket/preset/CenteringRingPresetTests.java index d106fefd..718e4be5 100644 --- a/core/test/net/sf/openrocket/preset/CenteringRingPresetTests.java +++ b/core/test/net/sf/openrocket/preset/CenteringRingPresetTests.java @@ -16,256 +16,256 @@ import org.junit.Test; * */ public class CenteringRingPresetTests { - + @Test public void testManufacturerRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.MANUFACTURER, - ComponentPreset.PARTNO, - ComponentPreset.LENGTH - }, - new String[] { - "No Manufacturer specified", - "No PartNo specified", - "No Length specified", - "Preset dimensions underspecified" - } + ComponentPreset.MANUFACTURER, + ComponentPreset.PARTNO, + ComponentPreset.LENGTH + }, + new String[] { + "No Manufacturer specified", + "No PartNo specified", + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testPartNoRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.PARTNO, - ComponentPreset.LENGTH - }, - new String[] { - "No PartNo specified", - "No Length specified", - "Preset dimensions underspecified" - } + ComponentPreset.PARTNO, + ComponentPreset.LENGTH + }, + new String[] { + "No PartNo specified", + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testLengthRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { ComponentPreset.LENGTH - }, - new String[] { - "No Length specified", - "Preset dimensions underspecified" - } + }, + new String[] { + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testOnlyOuterDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testOnlyInnerDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testOnlyThicknessDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.THICKNESS, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.THICKNESS, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testComputeInnerDiameter() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.THICKNESS, 0.5); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.THICKNESS, 0.5); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(1.0,preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(),0.0); + + assertEquals(1.0, preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(), 0.0); } - + @Test public void testComputeOuterDiameter() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.THICKNESS, 0.5); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.THICKNESS, 0.5); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(2.0,preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(),0.0); + + assertEquals(2.0, preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(), 0.0); } - + @Test public void testComputeThickness() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0); + + assertEquals(0.5, preset.get(ComponentPreset.THICKNESS).doubleValue(), 0.0); } - + @Test public void testComputeThicknessLooses() throws Exception { // If all OUTER_DIAMETER, INNER_DIAMETER and THICKNESS are // specified, THICKNESS is recomputed. TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.THICKNESS, 15.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.THICKNESS, 15.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0); + + assertEquals(0.5, preset.get(ComponentPreset.THICKNESS).doubleValue(), 0.0); } - + @Test public void testComputeDensityNoMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); + double volume = /*outer area*/(Math.PI * 1.0) - /* inner area */(Math.PI * .25); volume *= 2.0; /* times length */ - + double density = 100.0 / volume; - - assertEquals("CenteringRingCustom",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + + assertEquals("CenteringRingCustom", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); - + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(2.0, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); + } - + @Test public void testComputeDensityWithMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); + double volume = /*outer area*/(Math.PI * 1.0) - /* inner area */(Math.PI * .25); volume *= 2.0; /* times length */ - + double density = 100.0 / volume; - - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + } diff --git a/core/test/net/sf/openrocket/preset/EngineBlockComponentTests.java b/core/test/net/sf/openrocket/preset/EngineBlockComponentTests.java index 07f45a51..759a3b7b 100644 --- a/core/test/net/sf/openrocket/preset/EngineBlockComponentTests.java +++ b/core/test/net/sf/openrocket/preset/EngineBlockComponentTests.java @@ -1,9 +1,6 @@ package net.sf.openrocket.preset; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.rocketcomponent.EngineBlock; @@ -22,27 +19,27 @@ import org.junit.Test; * */ public class EngineBlockComponentTests extends BaseTestCase { - + ComponentPreset preset; @Before public void createPreset() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); preset = ComponentPresetFactory.create(presetspec); } - + @Test public void testComponentType() { EngineBlock eb = new EngineBlock(); - assertSame( ComponentPreset.Type.ENGINE_BLOCK, eb.getPresetType() ); + assertSame(ComponentPreset.Type.ENGINE_BLOCK, eb.getPresetType()); } @Test @@ -51,14 +48,14 @@ public class EngineBlockComponentTests extends BaseTestCase { eb.loadPreset(preset); - assertEquals( 2.0, eb.getLength(), 0.0 ); - assertEquals( 1.0, eb.getOuterRadius(), 0.0 ); - assertEquals( 0.5, eb.getInnerRadius(), 0.0 ); + assertEquals(2.0, eb.getLength(), 0.0); + assertEquals(1.0, eb.getOuterRadius(), 0.0); + assertEquals(0.5, eb.getInnerRadius(), 0.0); - assertFalse( eb.isOuterRadiusAutomatic() ); + assertFalse(eb.isOuterRadiusAutomatic()); - assertSame( preset.get( ComponentPreset.MATERIAL), eb.getMaterial() ); - assertEquals( 100.0, eb.getMass(), 0.05); + assertSame(preset.get(ComponentPreset.MATERIAL), eb.getMaterial()); + assertEquals(100.0, eb.getMass(), 0.05); } @Test @@ -66,54 +63,54 @@ public class EngineBlockComponentTests extends BaseTestCase { EngineBlock eb = new EngineBlock(); eb.loadPreset(preset); - + eb.setLength(1.0); - assertSame( preset, eb.getPresetComponent() ); + assertSame(preset, eb.getPresetComponent()); } - + @Test public void changeODClearsPreset() { EngineBlock eb = new EngineBlock(); eb.loadPreset(preset); - + eb.setOuterRadius(2.0); - assertNull( eb.getPresetComponent() ); + assertNull(eb.getPresetComponent()); } - + @Test public void changeIDClearsPreset() { EngineBlock eb = new EngineBlock(); eb.loadPreset(preset); - + eb.setInnerRadius(0.75); - assertNull( eb.getPresetComponent() ); + assertNull(eb.getPresetComponent()); } - + @Test public void changeThicknessClearsPreset() { EngineBlock eb = new EngineBlock(); eb.loadPreset(preset); - + eb.setThickness(0.1); - assertNull( eb.getPresetComponent() ); + assertNull(eb.getPresetComponent()); } - + @Test public void changeMaterialClearsPreset() { EngineBlock eb = new EngineBlock(); eb.loadPreset(preset); - - eb.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0)); - assertNull( eb.getPresetComponent() ); + eb.setMaterial(Material.newMaterial(Material.Type.BULK, "new", 1.0, true)); + + assertNull(eb.getPresetComponent()); } - + } diff --git a/core/test/net/sf/openrocket/preset/EngineBlockPresetTests.java b/core/test/net/sf/openrocket/preset/EngineBlockPresetTests.java index 9e62ee50..d032b513 100644 --- a/core/test/net/sf/openrocket/preset/EngineBlockPresetTests.java +++ b/core/test/net/sf/openrocket/preset/EngineBlockPresetTests.java @@ -16,256 +16,256 @@ import org.junit.Test; * */ public class EngineBlockPresetTests { - + @Test public void testManufacturerRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.MANUFACTURER, - ComponentPreset.PARTNO, - ComponentPreset.LENGTH - }, - new String[] { - "No Manufacturer specified", - "No PartNo specified", - "No Length specified", - "Preset dimensions underspecified" - } + ComponentPreset.MANUFACTURER, + ComponentPreset.PARTNO, + ComponentPreset.LENGTH + }, + new String[] { + "No Manufacturer specified", + "No PartNo specified", + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testPartNoRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.PARTNO, - ComponentPreset.LENGTH - }, - new String[] { - "No PartNo specified", - "No Length specified", - "Preset dimensions underspecified" - } + ComponentPreset.PARTNO, + ComponentPreset.LENGTH + }, + new String[] { + "No PartNo specified", + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testLengthRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { ComponentPreset.LENGTH - }, - new String[] { - "No Length specified", - "Preset dimensions underspecified" - } + }, + new String[] { + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testOnlyOuterDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testOnlyInnerDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testOnlyThicknessDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.THICKNESS, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.THICKNESS, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testComputeInnerDiameter() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.THICKNESS, 0.5); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.THICKNESS, 0.5); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(1.0,preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(),0.0); + + assertEquals(1.0, preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(), 0.0); } - + @Test public void testComputeOuterDiameter() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.THICKNESS, 0.5); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.THICKNESS, 0.5); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(2.0,preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(),0.0); + + assertEquals(2.0, preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(), 0.0); } - + @Test public void testComputeThickness() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0); + + assertEquals(0.5, preset.get(ComponentPreset.THICKNESS).doubleValue(), 0.0); } - + @Test public void testComputeThicknessLooses() throws Exception { // If all OUTER_DIAMETER, INNER_DIAMETER and THICKNESS are // specified, THICKNESS is recomputed. TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.THICKNESS, 15.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.THICKNESS, 15.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0); + + assertEquals(0.5, preset.get(ComponentPreset.THICKNESS).doubleValue(), 0.0); } - + @Test public void testComputeDensityNoMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); + double volume = /*outer area*/(Math.PI * 1.0) - /* inner area */(Math.PI * .25); volume *= 2.0; /* times length */ double density = 100.0 / volume; - assertEquals("EngineBlockCustom",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + assertEquals("EngineBlockCustom", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(2.0, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testComputeDensityWithMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); + double volume = /*outer area*/(Math.PI * 1.0) - /* inner area */(Math.PI * .25); volume *= 2.0; /* times length */ double density = 100.0 / volume; - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + } diff --git a/core/test/net/sf/openrocket/preset/LaunchLugComponentTests.java b/core/test/net/sf/openrocket/preset/LaunchLugComponentTests.java index 3af93859..e232aa62 100644 --- a/core/test/net/sf/openrocket/preset/LaunchLugComponentTests.java +++ b/core/test/net/sf/openrocket/preset/LaunchLugComponentTests.java @@ -3,8 +3,8 @@ package net.sf.openrocket.preset; import static org.junit.Assert.*; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Manufacturer; -import net.sf.openrocket.rocketcomponent.LaunchLug; import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish; +import net.sf.openrocket.rocketcomponent.LaunchLug; import net.sf.openrocket.util.BaseTestCase.BaseTestCase; import org.junit.Before; @@ -20,27 +20,27 @@ import org.junit.Test; * */ public class LaunchLugComponentTests extends BaseTestCase { - + ComponentPreset preset; @Before public void createPreset() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); preset = ComponentPresetFactory.create(presetspec); } - + @Test public void testComponentType() { LaunchLug bt = new LaunchLug(); - assertSame( ComponentPreset.Type.LAUNCH_LUG, bt.getPresetType() ); + assertSame(ComponentPreset.Type.LAUNCH_LUG, bt.getPresetType()); } @Test @@ -49,12 +49,12 @@ public class LaunchLugComponentTests extends BaseTestCase { bt.loadPreset(preset); - assertEquals( 2.0, bt.getLength(), 0.0 ); - assertEquals( 1.0, bt.getOuterRadius(), 0.0 ); - assertEquals( 0.5, bt.getInnerRadius(), 0.0 ); + assertEquals(2.0, bt.getLength(), 0.0); + assertEquals(1.0, bt.getOuterRadius(), 0.0); + assertEquals(0.5, bt.getInnerRadius(), 0.0); - assertSame( preset.get( ComponentPreset.MATERIAL), bt.getMaterial() ); - assertEquals( 100.0, bt.getMass(), 0.05); + assertSame(preset.get(ComponentPreset.MATERIAL), bt.getMaterial()); + assertEquals(100.0, bt.getMass(), 0.05); } @Test @@ -62,65 +62,65 @@ public class LaunchLugComponentTests extends BaseTestCase { LaunchLug bt = new LaunchLug(); bt.loadPreset(preset); - + bt.setLength(1.0); - assertSame( preset, bt.getPresetComponent() ); + assertSame(preset, bt.getPresetComponent()); } - + @Test public void changeODClearsPreset() { LaunchLug bt = new LaunchLug(); bt.loadPreset(preset); - + bt.setOuterRadius(2.0); - assertNull( bt.getPresetComponent() ); + assertNull(bt.getPresetComponent()); } - + @Test public void changeIDClearsPreset() { LaunchLug bt = new LaunchLug(); bt.loadPreset(preset); - + bt.setInnerRadius(0.75); - assertNull( bt.getPresetComponent() ); + assertNull(bt.getPresetComponent()); } - + @Test public void changeThicknessClearsPreset() { LaunchLug bt = new LaunchLug(); bt.loadPreset(preset); - + bt.setThickness(0.1); - assertNull( bt.getPresetComponent() ); + assertNull(bt.getPresetComponent()); } - + @Test public void changeMaterialClearsPreset() { LaunchLug bt = new LaunchLug(); bt.loadPreset(preset); - - bt.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0)); - assertNull( bt.getPresetComponent() ); + bt.setMaterial(Material.newMaterial(Material.Type.BULK, "new", 1.0, true)); + + assertNull(bt.getPresetComponent()); } - + @Test public void changeFinishLeavesPreset() { LaunchLug bt = new LaunchLug(); bt.loadPreset(preset); - - bt.setFinish( Finish.POLISHED ); - assertSame( preset, bt.getPresetComponent() ); + bt.setFinish(Finish.POLISHED); + + assertSame(preset, bt.getPresetComponent()); } - + } diff --git a/core/test/net/sf/openrocket/preset/LaunchLugPresetTests.java b/core/test/net/sf/openrocket/preset/LaunchLugPresetTests.java index 2297e20c..207931d3 100644 --- a/core/test/net/sf/openrocket/preset/LaunchLugPresetTests.java +++ b/core/test/net/sf/openrocket/preset/LaunchLugPresetTests.java @@ -16,256 +16,256 @@ import org.junit.Test; * */ public class LaunchLugPresetTests { - + @Test public void testManufacturerRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.MANUFACTURER, - ComponentPreset.PARTNO, - ComponentPreset.LENGTH - }, - new String[] { - "No Manufacturer specified", - "No PartNo specified", - "No Length specified", - "Preset dimensions underspecified" - } + ComponentPreset.MANUFACTURER, + ComponentPreset.PARTNO, + ComponentPreset.LENGTH + }, + new String[] { + "No Manufacturer specified", + "No PartNo specified", + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testPartNoRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.PARTNO, - ComponentPreset.LENGTH - }, - new String[] { - "No PartNo specified", - "No Length specified", - "Preset dimensions underspecified" - } + ComponentPreset.PARTNO, + ComponentPreset.LENGTH + }, + new String[] { + "No PartNo specified", + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testLengthRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { ComponentPreset.LENGTH - }, - new String[] { - "No Length specified", - "Preset dimensions underspecified" - } + }, + new String[] { + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testOnlyOuterDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testOnlyInnerDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testOnlyThicknessDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.THICKNESS, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.THICKNESS, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testComputeInnerDiameter() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.THICKNESS, 0.5); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.THICKNESS, 0.5); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(1.0,preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(),0.0); + + assertEquals(1.0, preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(), 0.0); } - + @Test public void testComputeOuterDiameter() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.THICKNESS, 0.5); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.THICKNESS, 0.5); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(2.0,preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(),0.0); + + assertEquals(2.0, preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(), 0.0); } - + @Test public void testComputeThickness() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0); + + assertEquals(0.5, preset.get(ComponentPreset.THICKNESS).doubleValue(), 0.0); } - + @Test public void testComputeThicknessLooses() throws Exception { // If all OUTER_DIAMETER, INNER_DIAMETER and THICKNESS are // specified, THICKNESS is recomputed. TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.THICKNESS, 15.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.THICKNESS, 15.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0); + + assertEquals(0.5, preset.get(ComponentPreset.THICKNESS).doubleValue(), 0.0); } - + @Test public void testComputeDensityNoMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); + double volume = /*outer area*/(Math.PI * 1.0) - /* inner area */(Math.PI * .25); volume *= 2.0; /* times length */ double density = 100.0 / volume; - assertEquals("TubeCustom",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + assertEquals("TubeCustom", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(2.0, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testComputeDensityWithMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); + double volume = /*outer area*/(Math.PI * 1.0) - /* inner area */(Math.PI * .25); volume *= 2.0; /* times length */ double density = 100.0 / volume; - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + } diff --git a/core/test/net/sf/openrocket/preset/NoseConeComponentTests.java b/core/test/net/sf/openrocket/preset/NoseConeComponentTests.java index e4a954e6..37f7dd4e 100644 --- a/core/test/net/sf/openrocket/preset/NoseConeComponentTests.java +++ b/core/test/net/sf/openrocket/preset/NoseConeComponentTests.java @@ -3,9 +3,9 @@ package net.sf.openrocket.preset; import static org.junit.Assert.*; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Manufacturer; +import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish; import net.sf.openrocket.rocketcomponent.NoseCone; import net.sf.openrocket.rocketcomponent.Transition; -import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish; import net.sf.openrocket.util.BaseTestCase.BaseTestCase; import org.junit.Before; @@ -21,31 +21,31 @@ import org.junit.Test; * */ public class NoseConeComponentTests extends BaseTestCase { - + ComponentPreset preset; @Before public void createPreset() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); - presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.AFT_SHOULDER_LENGTH, 1.0); - presetspec.put( ComponentPreset.AFT_SHOULDER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.FILLED, true); - presetspec.put( ComponentPreset.MASS, 100.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.AFT_SHOULDER_LENGTH, 1.0); + presetspec.put(ComponentPreset.AFT_SHOULDER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.FILLED, true); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); preset = ComponentPresetFactory.create(presetspec); } - + @Test public void testComponentType() { NoseCone nc = new NoseCone(); - assertSame( ComponentPreset.Type.NOSE_CONE, nc.getPresetType() ); + assertSame(ComponentPreset.Type.NOSE_CONE, nc.getPresetType()); } @Test @@ -54,21 +54,21 @@ public class NoseConeComponentTests extends BaseTestCase { nc.loadPreset(preset); - assertEquals( 2.0, nc.getLength(), 0.0 ); - assertSame( Transition.Shape.CONICAL, nc.getType() ); - assertEquals( 1.0, nc.getAftRadius(), 0.0 ); - assertEquals( 0.0, nc.getForeShoulderLength(), 0.0 ); - assertEquals( 0.0, nc.getForeShoulderRadius(), 0.0 ); - assertEquals( 1.0, nc.getAftShoulderLength(), 0.0 ); - assertEquals( 0.5, nc.getAftShoulderRadius(), 0.0 ); - assertEquals( 0.5, nc.getAftShoulderThickness(), 0.0 ); - - assertFalse( nc.isForeRadiusAutomatic() ); - assertFalse( nc.isAftRadiusAutomatic() ); - assertTrue( nc.isFilled() ); - - assertSame( preset.get( ComponentPreset.MATERIAL), nc.getMaterial() ); - assertEquals( 100.0, nc.getMass(), 0.05); + assertEquals(2.0, nc.getLength(), 0.0); + assertSame(Transition.Shape.CONICAL, nc.getType()); + assertEquals(1.0, nc.getAftRadius(), 0.0); + assertEquals(0.0, nc.getForeShoulderLength(), 0.0); + assertEquals(0.0, nc.getForeShoulderRadius(), 0.0); + assertEquals(1.0, nc.getAftShoulderLength(), 0.0); + assertEquals(0.5, nc.getAftShoulderRadius(), 0.0); + assertEquals(0.5, nc.getAftShoulderThickness(), 0.0); + + assertFalse(nc.isForeRadiusAutomatic()); + assertFalse(nc.isAftRadiusAutomatic()); + assertTrue(nc.isFilled()); + + assertSame(preset.get(ComponentPreset.MATERIAL), nc.getMaterial()); + assertEquals(100.0, nc.getMass(), 0.05); } @Test @@ -76,99 +76,99 @@ public class NoseConeComponentTests extends BaseTestCase { NoseCone nc = new NoseCone(); nc.loadPreset(preset); - + nc.setLength(1.0); - assertNull( nc.getPresetComponent() ); + assertNull(nc.getPresetComponent()); } - + @Test public void changeAftRadiusClearsPreset() { NoseCone nc = new NoseCone(); nc.loadPreset(preset); - + nc.setAftRadius(2.0); - assertNull( nc.getPresetComponent() ); + assertNull(nc.getPresetComponent()); } - + @Test public void changeAftRadiusAutomaticClearsPreset() { NoseCone nc = new NoseCone(); nc.loadPreset(preset); - + nc.setAftRadiusAutomatic(true); - assertNull( nc.getPresetComponent() ); + assertNull(nc.getPresetComponent()); } - + @Test public void changeAftShoulderRadiusClearsPreset() { NoseCone nc = new NoseCone(); nc.loadPreset(preset); - + nc.setAftShoulderRadius(2.0); - assertNull( nc.getPresetComponent() ); + assertNull(nc.getPresetComponent()); } - + @Test public void changeAftSholderLengthLeavesPreset() { NoseCone nc = new NoseCone(); nc.loadPreset(preset); - + nc.setAftShoulderLength(2.0); - assertSame( preset, nc.getPresetComponent() ); + assertSame(preset, nc.getPresetComponent()); } - + @Test public void changeThicknessClearsPreset() { NoseCone nc = new NoseCone(); nc.loadPreset(preset); - + nc.setThickness(0.1); - assertNull( nc.getPresetComponent() ); + assertNull(nc.getPresetComponent()); } - - + + @Test public void changeFilledClearsPreset() { NoseCone nc = new NoseCone(); nc.loadPreset(preset); - + nc.setFilled(false); - assertNull( nc.getPresetComponent() ); + assertNull(nc.getPresetComponent()); } - + @Test public void changeMaterialClearsPreset() { NoseCone nc = new NoseCone(); nc.loadPreset(preset); - - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0)); - assertNull( nc.getPresetComponent() ); + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "new", 1.0, true)); + + assertNull(nc.getPresetComponent()); } - + @Test public void changeFinishLeavesPreset() { NoseCone nc = new NoseCone(); nc.loadPreset(preset); - - nc.setFinish( Finish.POLISHED ); - assertSame( preset, nc.getPresetComponent() ); + nc.setFinish(Finish.POLISHED); + + assertSame(preset, nc.getPresetComponent()); } - + } diff --git a/core/test/net/sf/openrocket/preset/NoseConePresetTests.java b/core/test/net/sf/openrocket/preset/NoseConePresetTests.java index 36743672..56e849c5 100644 --- a/core/test/net/sf/openrocket/preset/NoseConePresetTests.java +++ b/core/test/net/sf/openrocket/preset/NoseConePresetTests.java @@ -18,191 +18,191 @@ import org.junit.Test; * */ public class NoseConePresetTests extends BaseTestCase { - + @Test public void testManufacturerRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.MANUFACTURER, - ComponentPreset.PARTNO, - ComponentPreset.LENGTH, - ComponentPreset.AFT_OUTER_DIAMETER, - ComponentPreset.SHAPE - }, - new String[] { - "No Manufacturer specified", - "No PartNo specified", - "No Length specified", - "No AftOuterDiameter specified", - "No Shape specified" - } + ComponentPreset.MANUFACTURER, + ComponentPreset.PARTNO, + ComponentPreset.LENGTH, + ComponentPreset.AFT_OUTER_DIAMETER, + ComponentPreset.SHAPE + }, + new String[] { + "No Manufacturer specified", + "No PartNo specified", + "No Length specified", + "No AftOuterDiameter specified", + "No Shape specified" + } ); } } - + @Test public void testPartNoRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.PARTNO, - ComponentPreset.LENGTH, - ComponentPreset.AFT_OUTER_DIAMETER, - ComponentPreset.SHAPE - }, - new String[] { - "No PartNo specified", - "No Length specified", - "No AftOuterDiameter specified", - "No Shape specified" - } + ComponentPreset.PARTNO, + ComponentPreset.LENGTH, + ComponentPreset.AFT_OUTER_DIAMETER, + ComponentPreset.SHAPE + }, + new String[] { + "No PartNo specified", + "No Length specified", + "No AftOuterDiameter specified", + "No Shape specified" + } ); } } - + @Test public void testLengthRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.LENGTH, - ComponentPreset.AFT_OUTER_DIAMETER, - ComponentPreset.SHAPE - }, - new String[] { - "No Length specified", - "No AftOuterDiameter specified", - "No Shape specified" - } + ComponentPreset.LENGTH, + ComponentPreset.AFT_OUTER_DIAMETER, + ComponentPreset.SHAPE + }, + new String[] { + "No Length specified", + "No AftOuterDiameter specified", + "No Shape specified" + } ); } } - + @Test public void testShapeRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.AFT_OUTER_DIAMETER, - ComponentPreset.SHAPE - }, - new String[] { - "No AftOuterDiameter specified", - "No Shape specified" - } + ComponentPreset.AFT_OUTER_DIAMETER, + ComponentPreset.SHAPE + }, + new String[] { + "No AftOuterDiameter specified", + "No Shape specified" + } ); } } - + @Test public void testAftOuterDiameterRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { ComponentPreset.AFT_OUTER_DIAMETER - }, - new String[] { + }, + new String[] { "No AftOuterDiameter specified" - } + } ); } } - + @Test public void testComputeDensityNoMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); - presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.FILLED, true); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.FILLED, true); + presetspec.put(ComponentPreset.MASS, 100.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // constants put into the presetspec above. - double volume = /*base area*/ Math.PI; - volume *= 2.0 /* times height */ / 3.0; /* one third */ + double volume = /*base area*/Math.PI; + volume *= 2.0 /* times height *// 3.0; /* one third */ double density = 100.0 / volume; - assertEquals("NoseConeCustom",preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals("NoseConeCustom", preset.get(ComponentPreset.MATERIAL).getName()); // note - epsilon is 1% of the simple computation of density - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.01*density); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.01 * density); } - + @Test public void testMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); - presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(2.0, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testComputeDensityWithMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); - presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.FILLED, true); - presetspec.put( ComponentPreset.MASS, 100.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.FILLED, true); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // constants put into the presetspec above. - double volume = /*base area*/ Math.PI; - volume *= 2.0 /* times height */ / 3.0; /* one third */ + double volume = /*base area*/Math.PI; + volume *= 2.0 /* times height *// 3.0; /* one third */ double density = 100.0 / volume; - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); // note - epsilon is 1% of the simple computation of density - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.01*density); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.01 * density); } - + } diff --git a/core/test/net/sf/openrocket/preset/ParachuterComponentTests.java b/core/test/net/sf/openrocket/preset/ParachuterComponentTests.java index 6263957d..e2489960 100644 --- a/core/test/net/sf/openrocket/preset/ParachuterComponentTests.java +++ b/core/test/net/sf/openrocket/preset/ParachuterComponentTests.java @@ -1,8 +1,6 @@ package net.sf.openrocket.preset; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.rocketcomponent.Parachute; @@ -21,30 +19,30 @@ import org.junit.Test; * */ public class ParachuterComponentTests extends BaseTestCase { - + ComponentPreset preset; @Before public void createPreset() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.PARACHUTE); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.DIAMETER, 20.0); - presetspec.put( ComponentPreset.LINE_COUNT, 8); - presetspec.put( ComponentPreset.LINE_LENGTH, 12.0); - Material m = Material.newUserMaterial(Material.Type.SURFACE,"testMaterial", 2.0); - presetspec.put( ComponentPreset.MATERIAL, m); - m = Material.newUserMaterial(Material.Type.LINE,"testLineMaterial", 3); - presetspec.put( ComponentPreset.LINE_MATERIAL, m); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.DIAMETER, 20.0); + presetspec.put(ComponentPreset.LINE_COUNT, 8); + presetspec.put(ComponentPreset.LINE_LENGTH, 12.0); + Material m = Material.newMaterial(Material.Type.SURFACE, "testMaterial", 2.0, true); + presetspec.put(ComponentPreset.MATERIAL, m); + m = Material.newMaterial(Material.Type.LINE, "testLineMaterial", 3, true); + presetspec.put(ComponentPreset.LINE_MATERIAL, m); preset = ComponentPresetFactory.create(presetspec); } - + @Test public void testComponentType() { Parachute cr = new Parachute(); - assertSame( ComponentPreset.Type.PARACHUTE, cr.getPresetType() ); + assertSame(ComponentPreset.Type.PARACHUTE, cr.getPresetType()); } @Test @@ -53,12 +51,12 @@ public class ParachuterComponentTests extends BaseTestCase { cr.loadPreset(preset); - assertEquals( 20.0, cr.getDiameter(), 0.0 ); - assertEquals( 8, cr.getLineCount(), 0.0 ); - assertEquals( 12.0, cr.getLineLength(), 0.0 ); + assertEquals(20.0, cr.getDiameter(), 0.0); + assertEquals(8, cr.getLineCount(), 0.0); + assertEquals(12.0, cr.getLineLength(), 0.0); - assertSame( preset.get( ComponentPreset.MATERIAL), cr.getMaterial() ); - assertSame( preset.get( ComponentPreset.LINE_MATERIAL), cr.getLineMaterial() ); + assertSame(preset.get(ComponentPreset.MATERIAL), cr.getMaterial()); + assertSame(preset.get(ComponentPreset.LINE_MATERIAL), cr.getLineMaterial()); } @Test @@ -66,65 +64,65 @@ public class ParachuterComponentTests extends BaseTestCase { Parachute cr = new Parachute(); cr.loadPreset(preset); - + cr.setDiameter(1.0); - assertNull( cr.getPresetComponent() ); + assertNull(cr.getPresetComponent()); } - + @Test public void changeAreaClearsPreset() { Parachute cr = new Parachute(); cr.loadPreset(preset); - + cr.setArea(1.0); - assertNull( cr.getPresetComponent() ); + assertNull(cr.getPresetComponent()); } - + @Test public void changeLineCountClearsPreset() { Parachute cr = new Parachute(); cr.loadPreset(preset); - + cr.setLineCount(12); - assertNull( cr.getPresetComponent() ); + assertNull(cr.getPresetComponent()); } - + @Test public void changeLineLengthLeavesPreset() { Parachute cr = new Parachute(); cr.loadPreset(preset); - + cr.setLineLength(24); - assertSame( preset, cr.getPresetComponent() ); + assertSame(preset, cr.getPresetComponent()); } - + @Test public void changeMaterialClearsPreset() { Parachute cr = new Parachute(); cr.loadPreset(preset); - - cr.setMaterial( Material.newUserMaterial(Material.Type.SURFACE,"new", 1.0)); - assertNull( cr.getPresetComponent() ); + cr.setMaterial(Material.newMaterial(Material.Type.SURFACE, "new", 1.0, true)); + + assertNull(cr.getPresetComponent()); } - + @Test public void changeLineMaterialLeavesPreset() { Parachute cr = new Parachute(); cr.loadPreset(preset); - - cr.setLineMaterial( Material.newUserMaterial(Material.Type.LINE,"new", 1.0)); - assertSame( preset, cr.getPresetComponent() ); + cr.setLineMaterial(Material.newMaterial(Material.Type.LINE, "new", 1.0, true)); + + assertSame(preset, cr.getPresetComponent()); } - + } diff --git a/core/test/net/sf/openrocket/preset/StreamerComponentTests.java b/core/test/net/sf/openrocket/preset/StreamerComponentTests.java index b36ada19..099a8d54 100644 --- a/core/test/net/sf/openrocket/preset/StreamerComponentTests.java +++ b/core/test/net/sf/openrocket/preset/StreamerComponentTests.java @@ -1,8 +1,6 @@ package net.sf.openrocket.preset; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.rocketcomponent.Streamer; @@ -21,27 +19,27 @@ import org.junit.Test; * */ public class StreamerComponentTests extends BaseTestCase { - + ComponentPreset preset; @Before public void createPreset() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.STREAMER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 20.0); - presetspec.put( ComponentPreset.WIDTH, 2.0); - Material m = Material.newUserMaterial(Material.Type.SURFACE,"testMaterial", 2.0); - presetspec.put( ComponentPreset.MATERIAL, m); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 20.0); + presetspec.put(ComponentPreset.WIDTH, 2.0); + Material m = Material.newMaterial(Material.Type.SURFACE, "testMaterial", 2.0, true); + presetspec.put(ComponentPreset.MATERIAL, m); preset = ComponentPresetFactory.create(presetspec); } - + @Test public void testComponentType() { Streamer cr = new Streamer(); - assertSame( ComponentPreset.Type.STREAMER, cr.getPresetType() ); + assertSame(ComponentPreset.Type.STREAMER, cr.getPresetType()); } @Test @@ -50,12 +48,12 @@ public class StreamerComponentTests extends BaseTestCase { cr.loadPreset(preset); - assertEquals( 20.0, cr.getStripLength(), 0.0 ); - assertEquals( 2.0, cr.getStripWidth(), 0.0 ); - assertEquals( 2.0, cr.getLength(), 0.0 ); + assertEquals(20.0, cr.getStripLength(), 0.0); + assertEquals(2.0, cr.getStripWidth(), 0.0); + assertEquals(2.0, cr.getLength(), 0.0); - assertSame( preset.get( ComponentPreset.MATERIAL), cr.getMaterial() ); - assertEquals( 80.0, cr.getMass(), 0.05); + assertSame(preset.get(ComponentPreset.MATERIAL), cr.getMaterial()); + assertEquals(80.0, cr.getMass(), 0.05); } @Test @@ -63,32 +61,32 @@ public class StreamerComponentTests extends BaseTestCase { Streamer cr = new Streamer(); cr.loadPreset(preset); - + cr.setStripLength(1.0); - assertNull( cr.getPresetComponent() ); + assertNull(cr.getPresetComponent()); } - + @Test public void changeWidthClearsPreset() { Streamer cr = new Streamer(); cr.loadPreset(preset); - + cr.setStripWidth(1.0); - assertNull( cr.getPresetComponent() ); + assertNull(cr.getPresetComponent()); } - + @Test public void changeMaterialClearsPreset() { Streamer cr = new Streamer(); cr.loadPreset(preset); - - cr.setMaterial( Material.newUserMaterial(Material.Type.SURFACE,"new", 1.0)); - assertNull( cr.getPresetComponent() ); + cr.setMaterial(Material.newMaterial(Material.Type.SURFACE, "new", 1.0, true)); + + assertNull(cr.getPresetComponent()); } - + } diff --git a/core/test/net/sf/openrocket/preset/TransitionComponentTests.java b/core/test/net/sf/openrocket/preset/TransitionComponentTests.java index 3cc5f9ff..9826613c 100644 --- a/core/test/net/sf/openrocket/preset/TransitionComponentTests.java +++ b/core/test/net/sf/openrocket/preset/TransitionComponentTests.java @@ -1,10 +1,6 @@ package net.sf.openrocket.preset; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish; @@ -24,34 +20,34 @@ import org.junit.Test; * */ public class TransitionComponentTests extends BaseTestCase { - + ComponentPreset preset; @Before public void createPreset() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); - presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.FORE_OUTER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.AFT_SHOULDER_LENGTH, 1.0); - presetspec.put( ComponentPreset.AFT_SHOULDER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.FORE_SHOULDER_LENGTH, 1.0); - presetspec.put( ComponentPreset.FORE_SHOULDER_DIAMETER, 0.5); - presetspec.put( ComponentPreset.FILLED, true); - presetspec.put( ComponentPreset.MASS, 100.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.FORE_OUTER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.AFT_SHOULDER_LENGTH, 1.0); + presetspec.put(ComponentPreset.AFT_SHOULDER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.FORE_SHOULDER_LENGTH, 1.0); + presetspec.put(ComponentPreset.FORE_SHOULDER_DIAMETER, 0.5); + presetspec.put(ComponentPreset.FILLED, true); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); preset = ComponentPresetFactory.create(presetspec); } - + @Test public void testComponentType() { Transition tr = new Transition(); - assertSame( ComponentPreset.Type.TRANSITION, tr.getPresetType() ); + assertSame(ComponentPreset.Type.TRANSITION, tr.getPresetType()); } @Test @@ -60,22 +56,22 @@ public class TransitionComponentTests extends BaseTestCase { tr.loadPreset(preset); - assertEquals( 2.0, tr.getLength(), 0.0 ); - assertSame( Transition.Shape.CONICAL, tr.getType() ); - assertEquals( 1.0, tr.getAftRadius(), 0.0 ); - assertEquals( 1.0, tr.getForeShoulderLength(), 0.0 ); - assertEquals( 0.25, tr.getForeShoulderRadius(), 0.0 ); - assertEquals( 0.25, tr.getForeShoulderThickness(), 0.0 ); - assertEquals( 1.0, tr.getAftShoulderLength(), 0.0 ); - assertEquals( 0.5, tr.getAftShoulderRadius(), 0.0 ); - assertEquals( 0.5, tr.getAftShoulderThickness(), 0.0 ); - - assertFalse( tr.isForeRadiusAutomatic() ); - assertFalse( tr.isAftRadiusAutomatic() ); - assertTrue( tr.isFilled() ); - - assertSame( preset.get( ComponentPreset.MATERIAL), tr.getMaterial() ); - assertEquals( 100.0, tr.getMass(), 1.0); + assertEquals(2.0, tr.getLength(), 0.0); + assertSame(Transition.Shape.CONICAL, tr.getType()); + assertEquals(1.0, tr.getAftRadius(), 0.0); + assertEquals(1.0, tr.getForeShoulderLength(), 0.0); + assertEquals(0.25, tr.getForeShoulderRadius(), 0.0); + assertEquals(0.25, tr.getForeShoulderThickness(), 0.0); + assertEquals(1.0, tr.getAftShoulderLength(), 0.0); + assertEquals(0.5, tr.getAftShoulderRadius(), 0.0); + assertEquals(0.5, tr.getAftShoulderThickness(), 0.0); + + assertFalse(tr.isForeRadiusAutomatic()); + assertFalse(tr.isAftRadiusAutomatic()); + assertTrue(tr.isFilled()); + + assertSame(preset.get(ComponentPreset.MATERIAL), tr.getMaterial()); + assertEquals(100.0, tr.getMass(), 1.0); } @Test @@ -83,132 +79,132 @@ public class TransitionComponentTests extends BaseTestCase { Transition tr = new Transition(); tr.loadPreset(preset); - + tr.setLength(1.0); - assertNull( tr.getPresetComponent() ); + assertNull(tr.getPresetComponent()); } - + @Test public void changeAftRadiusClearsPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - + tr.setAftRadius(2.0); - assertNull( tr.getPresetComponent() ); + assertNull(tr.getPresetComponent()); } - + @Test public void changeAftRadiusAutomaticClearsPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - + tr.setAftRadiusAutomatic(true); - assertNull( tr.getPresetComponent() ); + assertNull(tr.getPresetComponent()); } - + @Test public void changeForeRadiusClearsPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - + tr.setForeRadius(2.0); - assertNull( tr.getPresetComponent() ); + assertNull(tr.getPresetComponent()); } - + @Test public void changeForeRadiusAutomaticClearsPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - + tr.setForeRadiusAutomatic(true); - assertNull( tr.getPresetComponent() ); + assertNull(tr.getPresetComponent()); } - + @Test public void changeForeShoulderRadiusClearsPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - + tr.setForeShoulderRadius(2.0); - assertNull( tr.getPresetComponent() ); + assertNull(tr.getPresetComponent()); } - + @Test public void changeAftShoulderRadiusClearsPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - + tr.setAftShoulderRadius(2.0); - assertNull( tr.getPresetComponent() ); + assertNull(tr.getPresetComponent()); } - + @Test public void changeAftSholderLengthLeavesPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - + tr.setAftShoulderLength(2.0); - assertSame( preset, tr.getPresetComponent() ); + assertSame(preset, tr.getPresetComponent()); } - + @Test public void changeThicknessClearsPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - + tr.setThickness(0.1); - assertNull( tr.getPresetComponent() ); + assertNull(tr.getPresetComponent()); } - - + + @Test public void changeFilledClearsPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - + tr.setFilled(false); - assertNull( tr.getPresetComponent() ); + assertNull(tr.getPresetComponent()); } - + @Test public void changeMaterialClearsPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - - tr.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0)); - assertNull( tr.getPresetComponent() ); + tr.setMaterial(Material.newMaterial(Material.Type.BULK, "new", 1.0, true)); + + assertNull(tr.getPresetComponent()); } - + @Test public void changeFinishLeavesPreset() { Transition tr = new Transition(); tr.loadPreset(preset); - - tr.setFinish( Finish.POLISHED ); - assertSame( preset, tr.getPresetComponent() ); + tr.setFinish(Finish.POLISHED); + + assertSame(preset, tr.getPresetComponent()); } - + } diff --git a/core/test/net/sf/openrocket/preset/TransitionPresetTests.java b/core/test/net/sf/openrocket/preset/TransitionPresetTests.java index a2752eb3..26593dd8 100644 --- a/core/test/net/sf/openrocket/preset/TransitionPresetTests.java +++ b/core/test/net/sf/openrocket/preset/TransitionPresetTests.java @@ -18,205 +18,205 @@ import org.junit.Test; * */ public class TransitionPresetTests extends BaseTestCase { - + @Test public void testManufacturerRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.MANUFACTURER, - ComponentPreset.PARTNO, - ComponentPreset.LENGTH, - ComponentPreset.AFT_OUTER_DIAMETER, - ComponentPreset.FORE_OUTER_DIAMETER - }, - new String[] { - "No Manufacturer specified", - "No PartNo specified", - "No Length specified", - "No AftOuterDiameter specified", - "No ForeOuterDiameter specified" - } + ComponentPreset.MANUFACTURER, + ComponentPreset.PARTNO, + ComponentPreset.LENGTH, + ComponentPreset.AFT_OUTER_DIAMETER, + ComponentPreset.FORE_OUTER_DIAMETER + }, + new String[] { + "No Manufacturer specified", + "No PartNo specified", + "No Length specified", + "No AftOuterDiameter specified", + "No ForeOuterDiameter specified" + } ); } } - + @Test public void testPartNoRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.PARTNO, - ComponentPreset.LENGTH, - ComponentPreset.AFT_OUTER_DIAMETER, - ComponentPreset.FORE_OUTER_DIAMETER - }, - new String[] { - "No PartNo specified", - "No Length specified", - "No AftOuterDiameter specified", - "No ForeOuterDiameter specified" - } + ComponentPreset.PARTNO, + ComponentPreset.LENGTH, + ComponentPreset.AFT_OUTER_DIAMETER, + ComponentPreset.FORE_OUTER_DIAMETER + }, + new String[] { + "No PartNo specified", + "No Length specified", + "No AftOuterDiameter specified", + "No ForeOuterDiameter specified" + } ); } } - + @Test public void testLengthRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.LENGTH, - ComponentPreset.AFT_OUTER_DIAMETER, - ComponentPreset.FORE_OUTER_DIAMETER - }, - new String[] { - "No Length specified", - "No AftOuterDiameter specified", - "No ForeOuterDiameter specified" - } + ComponentPreset.LENGTH, + ComponentPreset.AFT_OUTER_DIAMETER, + ComponentPreset.FORE_OUTER_DIAMETER + }, + new String[] { + "No Length specified", + "No AftOuterDiameter specified", + "No ForeOuterDiameter specified" + } ); } } - + @Test public void testAftOuterDiameterRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.AFT_OUTER_DIAMETER, - ComponentPreset.FORE_OUTER_DIAMETER - }, - new String[] { - "No AftOuterDiameter specified", - "No ForeOuterDiameter specified" - } + ComponentPreset.AFT_OUTER_DIAMETER, + ComponentPreset.FORE_OUTER_DIAMETER + }, + new String[] { + "No AftOuterDiameter specified", + "No ForeOuterDiameter specified" + } ); } } - - + + @Test public void testForeOuterDiameterRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); - presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { ComponentPreset.FORE_OUTER_DIAMETER - }, - new String[] { + }, + new String[] { "No ForeOuterDiameter specified" - } + } ); } } - + @Test public void testComputeDensityNoMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); - presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.FORE_OUTER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.FILLED, true); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.FORE_OUTER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.FILLED, true); + presetspec.put(ComponentPreset.MASS, 100.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // constants put into the presetspec above. - double volume = /*base area*/ Math.PI * ( 1.0 * 1.0 + 1.0 * 0.5 + 0.5 * 0.5); + double volume = /*base area*/Math.PI * (1.0 * 1.0 + 1.0 * 0.5 + 0.5 * 0.5); + + volume *= 2.0 /* times height *// 3.0; /* one third */ - volume *= 2.0 /* times height */ / 3.0; /* one third */ - double density = 100.0 / volume; - assertEquals("TransitionCustom",preset.get(ComponentPreset.MATERIAL).getName()); - - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.01*density); + assertEquals("TransitionCustom", preset.get(ComponentPreset.MATERIAL).getName()); + + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.01 * density); } - + @Test public void testMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); - presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.FORE_OUTER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.FILLED, true); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.FORE_OUTER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.FILLED, true); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(2.0, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testComputeDensityWithMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); - presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.FORE_OUTER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.FILLED, true); - presetspec.put( ComponentPreset.MASS, 100.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL); + presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.FORE_OUTER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.FILLED, true); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // constants put into the presetspec above. - double totvolume = /*base area*/ Math.PI; + double totvolume = /*base area*/Math.PI; - totvolume *= 4.0 /* times height */ / 3.0; /* one third */ - - double uppervolume = /*fore area*/ Math.PI * 0.5 * 0.5; - uppervolume *= 2.0 /* times height */ / 3.0; /* one third */ + totvolume *= 4.0 /* times height *// 3.0; /* one third */ + + double uppervolume = /*fore area*/Math.PI * 0.5 * 0.5; + uppervolume *= 2.0 /* times height *// 3.0; /* one third */ + + double volume = totvolume - uppervolume; - double volume = totvolume-uppervolume; - double density = 100.0 / volume; - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.01*density); + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.01 * density); } - + } diff --git a/core/test/net/sf/openrocket/preset/TubeCouplerComponentTests.java b/core/test/net/sf/openrocket/preset/TubeCouplerComponentTests.java index 280affec..829f664f 100644 --- a/core/test/net/sf/openrocket/preset/TubeCouplerComponentTests.java +++ b/core/test/net/sf/openrocket/preset/TubeCouplerComponentTests.java @@ -19,27 +19,27 @@ import org.junit.Test; * */ public class TubeCouplerComponentTests extends BaseTestCase { - + ComponentPreset preset; @Before public void createPreset() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); preset = ComponentPresetFactory.create(presetspec); } - + @Test public void testComponentType() { TubeCoupler tc = new TubeCoupler(); - assertSame( ComponentPreset.Type.TUBE_COUPLER, tc.getPresetType() ); + assertSame(ComponentPreset.Type.TUBE_COUPLER, tc.getPresetType()); } @Test @@ -48,15 +48,15 @@ public class TubeCouplerComponentTests extends BaseTestCase { tc.loadPreset(preset); - assertEquals( 2.0, tc.getLength(), 0.0 ); - assertEquals( 1.0, tc.getOuterRadius(), 0.0 ); - assertEquals( 0.5, tc.getInnerRadius(), 0.0 ); + assertEquals(2.0, tc.getLength(), 0.0); + assertEquals(1.0, tc.getOuterRadius(), 0.0); + assertEquals(0.5, tc.getInnerRadius(), 0.0); - assertFalse( tc.isInnerRadiusAutomatic() ); - assertFalse( tc.isOuterRadiusAutomatic() ); + assertFalse(tc.isInnerRadiusAutomatic()); + assertFalse(tc.isOuterRadiusAutomatic()); - assertSame( preset.get( ComponentPreset.MATERIAL), tc.getMaterial() ); - assertEquals( 100.0, tc.getMass(), 0.05); + assertSame(preset.get(ComponentPreset.MATERIAL), tc.getMaterial()); + assertEquals(100.0, tc.getMass(), 0.05); } @Test @@ -64,54 +64,54 @@ public class TubeCouplerComponentTests extends BaseTestCase { TubeCoupler tc = new TubeCoupler(); tc.loadPreset(preset); - + tc.setLength(1.0); - assertSame( preset, tc.getPresetComponent() ); + assertSame(preset, tc.getPresetComponent()); } - + @Test public void changeODClearsPreset() { TubeCoupler tc = new TubeCoupler(); tc.loadPreset(preset); - + tc.setOuterRadius(2.0); - assertNull( tc.getPresetComponent() ); + assertNull(tc.getPresetComponent()); } - + @Test public void changeIDClearsPreset() { TubeCoupler tc = new TubeCoupler(); tc.loadPreset(preset); - + tc.setInnerRadius(0.75); - assertNull( tc.getPresetComponent() ); + assertNull(tc.getPresetComponent()); } - + @Test public void changeThicknessClearsPreset() { TubeCoupler tc = new TubeCoupler(); tc.loadPreset(preset); - + tc.setThickness(0.1); - assertNull( tc.getPresetComponent() ); + assertNull(tc.getPresetComponent()); } - + @Test public void changeMaterialClearsPreset() { TubeCoupler tc = new TubeCoupler(); tc.loadPreset(preset); - - tc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0)); - assertNull( tc.getPresetComponent() ); + tc.setMaterial(Material.newMaterial(Material.Type.BULK, "new", 1.0, true)); + + assertNull(tc.getPresetComponent()); } - + } diff --git a/core/test/net/sf/openrocket/preset/TubeCouplerPresetTests.java b/core/test/net/sf/openrocket/preset/TubeCouplerPresetTests.java index 95e0c976..7ef16ede 100644 --- a/core/test/net/sf/openrocket/preset/TubeCouplerPresetTests.java +++ b/core/test/net/sf/openrocket/preset/TubeCouplerPresetTests.java @@ -16,256 +16,256 @@ import org.junit.Test; * */ public class TubeCouplerPresetTests { - + @Test public void testManufacturerRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.MANUFACTURER, - ComponentPreset.PARTNO, - ComponentPreset.LENGTH - }, - new String[] { - "No Manufacturer specified", - "No PartNo specified", - "No Length specified", - "Preset dimensions underspecified" - } + ComponentPreset.MANUFACTURER, + ComponentPreset.PARTNO, + ComponentPreset.LENGTH + }, + new String[] { + "No Manufacturer specified", + "No PartNo specified", + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testPartNoRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { - ComponentPreset.PARTNO, - ComponentPreset.LENGTH - }, - new String[] { - "No PartNo specified", - "No Length specified", - "Preset dimensions underspecified" - } + ComponentPreset.PARTNO, + ComponentPreset.LENGTH + }, + new String[] { + "No PartNo specified", + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testLengthRequired() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, new TypedKey[] { ComponentPreset.LENGTH - }, - new String[] { - "No Length specified", - "Preset dimensions underspecified" - } + }, + new String[] { + "No Length specified", + "Preset dimensions underspecified" + } ); } } - + @Test public void testOnlyOuterDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testOnlyInnerDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testOnlyThicknessDiameter() { try { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.THICKNESS, 2.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.THICKNESS, 2.0); ComponentPresetFactory.create(presetspec); - } catch ( InvalidComponentPresetException ex ) { - PresetAssertHelper.assertInvalidPresetException( ex, + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, null, - new String[] { + new String[] { "Preset dimensions underspecified" - } + } ); } } - + @Test public void testComputeInnerDiameter() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.THICKNESS, 0.5); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.THICKNESS, 0.5); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(1.0,preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(),0.0); + + assertEquals(1.0, preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(), 0.0); } - + @Test public void testComputeOuterDiameter() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.THICKNESS, 0.5); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.THICKNESS, 0.5); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(2.0,preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(),0.0); + + assertEquals(2.0, preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(), 0.0); } - + @Test public void testComputeThickness() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0); + + assertEquals(0.5, preset.get(ComponentPreset.THICKNESS).doubleValue(), 0.0); } - + @Test public void testComputeThicknessLooses() throws Exception { // If all OUTER_DIAMETER, INNER_DIAMETER and THICKNESS are // specified, THICKNESS is recomputed. TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.THICKNESS, 15.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.THICKNESS, 15.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0); + + assertEquals(0.5, preset.get(ComponentPreset.THICKNESS).doubleValue(), 0.0); } - + @Test public void testComputeDensityNoMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); + double volume = /*outer area*/(Math.PI * 1.0) - /* inner area */(Math.PI * .25); volume *= 2.0; /* times length */ double density = 100.0 / volume; - assertEquals("TubeCustom",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + assertEquals("TubeCustom", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(2.0, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + @Test public void testComputeDensityWithMaterial() throws Exception { TypedPropertyMap presetspec = new TypedPropertyMap(); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); - presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); - presetspec.put( ComponentPreset.PARTNO, "partno"); - presetspec.put( ComponentPreset.LENGTH, 2.0); - presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); - presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0); - presetspec.put( ComponentPreset.MASS, 100.0); - presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0)); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); ComponentPreset preset = ComponentPresetFactory.create(presetspec); - + // Compute the volume by hand here using a slightly different formula from // the real implementation. The magic numbers are based on the // constants put into the presetspec above. - double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); + double volume = /*outer area*/(Math.PI * 1.0) - /* inner area */(Math.PI * .25); volume *= 2.0; /* times length */ double density = 100.0 / volume; - assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); - assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); } - + } diff --git a/core/test/net/sf/openrocket/rocketcomponent/FinSetTest.java b/core/test/net/sf/openrocket/rocketcomponent/FinSetTest.java index 61d63d4a..321efbe8 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/FinSetTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/FinSetTest.java @@ -1,8 +1,6 @@ package net.sf.openrocket.rocketcomponent; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.awt.Color; @@ -20,7 +18,7 @@ import org.junit.Test; public class FinSetTest extends BaseTestCase { - + @Test public void testFreeformConvert() { testFreeformConvert(new TrapezoidFinSet()); @@ -31,7 +29,7 @@ public class FinSetTest extends BaseTestCase { private void testFreeformConvert(FinSet fin) { FreeformFinSet converted; - Material mat = Material.newUserMaterial(Type.BULK, "foo", 0.1); + Material mat = Material.newMaterial(Type.BULK, "foo", 0.1, true); fin.setBaseRotation(1.1); fin.setCantAngle(0.001); @@ -55,14 +53,14 @@ public class FinSetTest extends BaseTestCase { fin.setTabShift(0.015); fin.setThickness(0.005); - + converted = FreeformFinSet.convertFinSet((FinSet) fin.copy()); ComponentCompare.assertSimilarity(fin, converted, true); assertEquals(converted.getComponentName(), converted.getName()); - + // Create test rocket Rocket rocket = new Rocket(); Stage stage = new Stage(); @@ -79,7 +77,7 @@ public class FinSetTest extends BaseTestCase { assertTrue(l1.changed); assertEquals(ComponentChangeEvent.NONFUNCTIONAL_CHANGE, l1.changetype); - + // Create copy RocketComponent rocketcopy = rocket.copy(); diff --git a/core/test/net/sf/openrocket/rocketcomponent/SymmetricComponentVolumeTest.java b/core/test/net/sf/openrocket/rocketcomponent/SymmetricComponentVolumeTest.java index 5b1e5ecb..9d554d72 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/SymmetricComponentVolumeTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/SymmetricComponentVolumeTest.java @@ -8,7 +8,7 @@ import net.sf.openrocket.util.BaseTestCase.BaseTestCase; import org.junit.Test; public class SymmetricComponentVolumeTest extends BaseTestCase { - + @Test public void simpleConeFilled() { NoseCone nc = new NoseCone(); @@ -18,63 +18,63 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { nc.setLength(1.0); nc.setFilled(true); - nc.setType( Transition.Shape.CONICAL ); + nc.setType(Transition.Shape.CONICAL); nc.setAftRadius(1.0); - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"test",density)); - + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "test", density, true)); + Coordinate cg = nc.getCG(); - - System.out.println( nc.getComponentVolume() + "\t" + nc.getMass()); - System.out.println( cg ); + + System.out.println(nc.getComponentVolume() + "\t" + nc.getMass()); + System.out.println(cg); double volume = Math.PI / 3.0; double mass = density * volume; - System.out.println( volume ); + System.out.println(volume); - assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume); - assertEquals( mass, nc.getMass(), epsilonPercent * mass ); + assertEquals(volume, nc.getComponentVolume(), epsilonPercent * volume); + assertEquals(mass, nc.getMass(), epsilonPercent * mass); - assertEquals( 0.75, cg.x, epsilonPercent * 0.75 ); - assertEquals( mass, cg.weight, epsilonPercent * mass); + assertEquals(0.75, cg.x, epsilonPercent * 0.75); + assertEquals(mass, cg.weight, epsilonPercent * mass); } - + @Test public void simpleConeWithShoulderFilled() { NoseCone nc = new NoseCone(); final double epsilonPercent = 0.001; final double density = 2.0; - + nc.setLength(1.0); nc.setFilled(true); - nc.setType( Transition.Shape.CONICAL ); + nc.setType(Transition.Shape.CONICAL); nc.setAftRadius(1.0); nc.setAftShoulderRadius(1.0); nc.setAftShoulderLength(1.0); nc.setAftShoulderThickness(1.0); - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"test",density)); - + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "test", density, true)); + Coordinate cg = nc.getCG(); - - System.out.println( nc.getComponentVolume() + "\t" + nc.getMass()); - System.out.println( cg ); - + + System.out.println(nc.getComponentVolume() + "\t" + nc.getMass()); + System.out.println(cg); + double volume = Math.PI / 3.0; volume += Math.PI; - + double mass = density * volume; - - System.out.println( volume + "\t" + mass ); - - assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume); - assertEquals( mass, nc.getMass(), epsilonPercent * mass ); - assertEquals( 1.312, cg.x, epsilonPercent * 1.071 ); - assertEquals( mass, cg.weight, epsilonPercent * mass); + System.out.println(volume + "\t" + mass); + + assertEquals(volume, nc.getComponentVolume(), epsilonPercent * volume); + assertEquals(mass, nc.getMass(), epsilonPercent * mass); + + assertEquals(1.312, cg.x, epsilonPercent * 1.071); + assertEquals(mass, cg.weight, epsilonPercent * mass); } - + @Test public void simpleConeHollow() { NoseCone nc = new NoseCone(); @@ -85,15 +85,15 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { nc.setLength(1.0); nc.setAftRadius(1.0); nc.setThickness(0.5); - nc.setType( Transition.Shape.CONICAL ); - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"test",density)); + nc.setType(Transition.Shape.CONICAL); + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "test", density, true)); Coordinate cg = nc.getCG(); - - System.out.println( nc.getComponentVolume() + "\t" + nc.getMass()); - System.out.println( cg ); - - double volume = Math.PI / 3.0; // outer volume + + System.out.println(nc.getComponentVolume() + "\t" + nc.getMass()); + System.out.println(cg); + + double volume = Math.PI / 3.0; // outer volume // manually projected Thickness of 0.5 on to radius to determine // the innerConeDimen. Since the outer cone is "square" (height = radius), @@ -102,41 +102,41 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { double innerConeDimen = 1.0 - Math.sqrt(2.0) / 2.0; double innerVolume = Math.PI / 3.0 * innerConeDimen * innerConeDimen * innerConeDimen; volume -= innerVolume; - + double mass = density * volume; - - System.out.println( volume ); - assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume); - assertEquals( mass, nc.getMass(), epsilonPercent * mass ); + System.out.println(volume); - assertEquals( 0.7454, cg.x, epsilonPercent * 0.7454 ); - assertEquals( mass, cg.weight, epsilonPercent * mass); + assertEquals(volume, nc.getComponentVolume(), epsilonPercent * volume); + assertEquals(mass, nc.getMass(), epsilonPercent * mass); + + assertEquals(0.7454, cg.x, epsilonPercent * 0.7454); + assertEquals(mass, cg.weight, epsilonPercent * mass); } - + @Test public void simpleConeWithShoulderHollow() { NoseCone nc = new NoseCone(); final double epsilonPercent = 0.001; final double density = 2.0; - + nc.setLength(1.0); - nc.setType( Transition.Shape.CONICAL ); + nc.setType(Transition.Shape.CONICAL); nc.setAftRadius(1.0); nc.setThickness(0.5); nc.setAftShoulderRadius(1.0); nc.setAftShoulderLength(1.0); nc.setAftShoulderThickness(0.5); - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"test",density)); - + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "test", density, true)); + Coordinate cg = nc.getCG(); - - System.out.println( nc.getComponentVolume() + "\t" + nc.getMass()); - System.out.println( cg ); - - double volume = Math.PI / 3.0; // outer volume - + + System.out.println(nc.getComponentVolume() + "\t" + nc.getMass()); + System.out.println(cg); + + double volume = Math.PI / 3.0; // outer volume + // manually projected Thickness of 0.5 on to radius to determine // the innerConeDimen. Since the outer cone is "square" (height = radius), // we only need to compute this one dimension in order to compute the @@ -144,63 +144,63 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { double innerConeDimen = 1.0 - Math.sqrt(2.0) / 2.0; double innerVolume = Math.PI / 3.0 * innerConeDimen * innerConeDimen * innerConeDimen; volume -= innerVolume; - - volume += Math.PI - Math.PI * 0.5 * 0.5; - + + volume += Math.PI - Math.PI * 0.5 * 0.5; + double mass = density * volume; - - System.out.println( volume ); - assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume); - assertEquals( mass, nc.getMass(), epsilonPercent * mass ); + System.out.println(volume); + + assertEquals(volume, nc.getComponentVolume(), epsilonPercent * volume); + assertEquals(mass, nc.getMass(), epsilonPercent * mass); - assertEquals( 1.2719, cg.x, epsilonPercent * 1.2719 ); - assertEquals( mass, cg.weight, epsilonPercent * mass); + assertEquals(1.2719, cg.x, epsilonPercent * 1.2719); + assertEquals(mass, cg.weight, epsilonPercent * mass); } - + @Test public void simpleTransitionFilled() { Transition nc = new Transition(); final double epsilonPercent = 0.001; final double density = 2.0; - + nc.setLength(4.0); nc.setFilled(true); - nc.setType( Transition.Shape.CONICAL ); + nc.setType(Transition.Shape.CONICAL); nc.setForeRadius(1.0); nc.setAftRadius(2.0); - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"test",density)); + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "test", density, true)); Coordinate cg = nc.getCG(); - - System.out.println( nc.getComponentVolume() + "\t" + nc.getMass()); - System.out.println( cg ); - - double volume = Math.PI / 3.0 * (2.0*2.0 + 2.0 * 1.0 + 1.0 * 1.0) * 4.0; - double mass = density * volume; + System.out.println(nc.getComponentVolume() + "\t" + nc.getMass()); + System.out.println(cg); - System.out.println( volume ); + double volume = Math.PI / 3.0 * (2.0 * 2.0 + 2.0 * 1.0 + 1.0 * 1.0) * 4.0; - assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume); - assertEquals( mass, nc.getMass(), epsilonPercent * mass ); + double mass = density * volume; - assertEquals( 2.4285, cg.x, epsilonPercent * 2.4285 ); - assertEquals( mass, cg.weight, epsilonPercent * mass); + System.out.println(volume); + + assertEquals(volume, nc.getComponentVolume(), epsilonPercent * volume); + assertEquals(mass, nc.getMass(), epsilonPercent * mass); + + assertEquals(2.4285, cg.x, epsilonPercent * 2.4285); + assertEquals(mass, cg.weight, epsilonPercent * mass); } - + @Test public void simpleTransitionWithShouldersFilled() { Transition nc = new Transition(); final double epsilonPercent = 0.001; final double density = 2.0; - + nc.setLength(4.0); nc.setFilled(true); - nc.setType( Transition.Shape.CONICAL ); + nc.setType(Transition.Shape.CONICAL); nc.setForeRadius(1.0); nc.setAftRadius(2.0); nc.setAftShoulderLength(1.0); @@ -209,52 +209,52 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { nc.setForeShoulderLength(1.0); nc.setForeShoulderRadius(1.0); nc.setForeShoulderThickness(1.0); - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"test",density)); + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "test", density, true)); Coordinate cg = nc.getCG(); - - System.out.println( nc.getComponentVolume() + "\t" + nc.getMass()); - System.out.println( cg ); - - double volume = Math.PI / 3.0 * (2.0*2.0 + 2.0 * 1.0 + 1.0 * 1.0) * 4.0; + + System.out.println(nc.getComponentVolume() + "\t" + nc.getMass()); + System.out.println(cg); + + double volume = Math.PI / 3.0 * (2.0 * 2.0 + 2.0 * 1.0 + 1.0 * 1.0) * 4.0; // plus aft shoulder: volume += Math.PI * 1.0 * 2.0 * 2.0; // plus fore shoulder: volume += Math.PI * 1.0 * 1.0 * 1.0; - double mass = density * volume; + double mass = density * volume; - System.out.println( volume ); + System.out.println(volume); - assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume); - assertEquals( mass, nc.getMass(), epsilonPercent * mass ); + assertEquals(volume, nc.getComponentVolume(), epsilonPercent * volume); + assertEquals(mass, nc.getMass(), epsilonPercent * mass); - assertEquals( 2.8023, cg.x, epsilonPercent * 2.8023 ); - assertEquals( mass, cg.weight, epsilonPercent * mass); + assertEquals(2.8023, cg.x, epsilonPercent * 2.8023); + assertEquals(mass, cg.weight, epsilonPercent * mass); } - + @Test public void simpleTransitionHollow1() { Transition nc = new Transition(); final double epsilonPercent = 0.001; final double density = 2.0; - + nc.setLength(1.0); - nc.setType( Transition.Shape.CONICAL ); + nc.setType(Transition.Shape.CONICAL); nc.setForeRadius(0.5); nc.setAftRadius(1.0); nc.setThickness(0.5); - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"test",density)); + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "test", density, true)); Coordinate cg = nc.getCG(); - - System.out.println( nc.getComponentVolume() + "\t" + nc.getMass()); - System.out.println( cg ); - + + System.out.println(nc.getComponentVolume() + "\t" + nc.getMass()); + System.out.println(cg); + // Volume of filled transition = - double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0; - + double filledVolume = Math.PI / 3.0 * (1.0 * 1.0 + 1.0 * 0.5 + 0.5 * 0.5) * 1.0; + // magic 2D cad drawing... // // Since the thickness >= fore radius, the @@ -265,30 +265,30 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { double innerConeRadius = 0.441; double innerConeLength = 0.882; - double innerVolume = Math.PI /3.0 * innerConeLength * innerConeRadius * innerConeRadius; + double innerVolume = Math.PI / 3.0 * innerConeLength * innerConeRadius * innerConeRadius; double volume = filledVolume - innerVolume; - double mass = density * volume; + double mass = density * volume; - System.out.println( volume ); + System.out.println(volume); - assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume); - assertEquals( mass, nc.getMass(), epsilonPercent * mass ); + assertEquals(volume, nc.getComponentVolume(), epsilonPercent * volume); + assertEquals(mass, nc.getMass(), epsilonPercent * mass); - assertEquals( 0.5884, cg.x, epsilonPercent * 0.5884 ); - assertEquals( mass, cg.weight, epsilonPercent * mass); + assertEquals(0.5884, cg.x, epsilonPercent * 0.5884); + assertEquals(mass, cg.weight, epsilonPercent * mass); } - + @Test public void simpleTransitionWithShouldersHollow1() { Transition nc = new Transition(); final double epsilonPercent = 0.001; final double density = 2.0; - + nc.setLength(1.0); - nc.setType( Transition.Shape.CONICAL ); + nc.setType(Transition.Shape.CONICAL); nc.setForeRadius(0.5); nc.setAftRadius(1.0); nc.setThickness(0.5); @@ -297,17 +297,17 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { nc.setAftShoulderThickness(0.5); nc.setForeShoulderLength(1.0); nc.setForeShoulderRadius(0.5); - nc.setForeShoulderThickness(0.5); // note this means fore shoulder is filled. - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"test",density)); + nc.setForeShoulderThickness(0.5); // note this means fore shoulder is filled. + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "test", density, true)); Coordinate cg = nc.getCG(); - - System.out.println( nc.getComponentVolume() + "\t" + nc.getMass()); - System.out.println( cg ); - + + System.out.println(nc.getComponentVolume() + "\t" + nc.getMass()); + System.out.println(cg); + // Volume of filled transition = - double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0; - + double filledVolume = Math.PI / 3.0 * (1.0 * 1.0 + 1.0 * 0.5 + 0.5 * 0.5) * 1.0; + // magic 2D cad drawing... // // Since the thickness >= fore radius, the @@ -318,7 +318,7 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { double innerConeRadius = 0.441; double innerConeLength = 0.882; - double innerVolume = Math.PI /3.0 * innerConeLength * innerConeRadius * innerConeRadius; + double innerVolume = Math.PI / 3.0 * innerConeLength * innerConeRadius * innerConeRadius; double volume = filledVolume - innerVolume; @@ -327,39 +327,39 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { // Now add fore shoulder volume += Math.PI * 1.0 * 0.5 * 0.5; - double mass = density * volume; + double mass = density * volume; - System.out.println( volume ); + System.out.println(volume); - assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume); - assertEquals( mass, nc.getMass(), epsilonPercent * mass ); + assertEquals(volume, nc.getComponentVolume(), epsilonPercent * volume); + assertEquals(mass, nc.getMass(), epsilonPercent * mass); - assertEquals( 0.8581, cg.x, epsilonPercent * 0.8581 ); - assertEquals( mass, cg.weight, epsilonPercent * mass); + assertEquals(0.8581, cg.x, epsilonPercent * 0.8581); + assertEquals(mass, cg.weight, epsilonPercent * mass); } - + @Test public void simpleTransitionHollow2() { Transition nc = new Transition(); final double epsilonPercent = 0.001; final double density = 2.0; - + nc.setLength(1.0); - nc.setType( Transition.Shape.CONICAL ); + nc.setType(Transition.Shape.CONICAL); nc.setForeRadius(0.5); nc.setAftRadius(1.0); nc.setThickness(0.25); - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"test",density)); + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "test", density, true)); Coordinate cg = nc.getCG(); - - System.out.println( nc.getComponentVolume() + "\t" + nc.getMass()); - System.out.println( cg ); - + + System.out.println(nc.getComponentVolume() + "\t" + nc.getMass()); + System.out.println(cg); + // Volume of filled transition = - double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0; - + double filledVolume = Math.PI / 3.0 * (1.0 * 1.0 + 1.0 * 0.5 + 0.5 * 0.5) * 1.0; + // magic 2D cad drawing... // // Since the thickness < fore radius, the @@ -370,30 +370,31 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { double innerTransitionAftRadius = 0.7205; double innerTransitionForeRadius = 0.2205; - double innerVolume = Math.PI /3.0 * ( innerTransitionAftRadius * innerTransitionAftRadius + innerTransitionAftRadius * innerTransitionForeRadius + innerTransitionForeRadius * innerTransitionForeRadius); + double innerVolume = Math.PI / 3.0 + * (innerTransitionAftRadius * innerTransitionAftRadius + innerTransitionAftRadius * innerTransitionForeRadius + innerTransitionForeRadius * innerTransitionForeRadius); double volume = filledVolume - innerVolume; - double mass = density * volume; + double mass = density * volume; - System.out.println( volume ); + System.out.println(volume); - assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume); - assertEquals( mass, nc.getMass(), epsilonPercent * mass ); + assertEquals(volume, nc.getComponentVolume(), epsilonPercent * volume); + assertEquals(mass, nc.getMass(), epsilonPercent * mass); - assertEquals( 0.56827, cg.x, epsilonPercent * 0.56827 ); - assertEquals( mass, cg.weight, epsilonPercent * mass); + assertEquals(0.56827, cg.x, epsilonPercent * 0.56827); + assertEquals(mass, cg.weight, epsilonPercent * mass); } - + @Test public void simpleTransitionWithShouldersHollow2() { Transition nc = new Transition(); final double epsilonPercent = 0.001; final double density = 2.0; - + nc.setLength(1.0); - nc.setType( Transition.Shape.CONICAL ); + nc.setType(Transition.Shape.CONICAL); nc.setForeRadius(0.5); nc.setAftRadius(1.0); nc.setThickness(0.25); @@ -404,16 +405,16 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { nc.setForeShoulderRadius(0.5); nc.setForeShoulderThickness(0.25); - nc.setMaterial( Material.newUserMaterial(Material.Type.BULK,"test",density)); + nc.setMaterial(Material.newMaterial(Material.Type.BULK, "test", density, true)); Coordinate cg = nc.getCG(); - - System.out.println( nc.getComponentVolume() + "\t" + nc.getMass()); - System.out.println( cg ); - + + System.out.println(nc.getComponentVolume() + "\t" + nc.getMass()); + System.out.println(cg); + // Volume of filled transition = - double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0; - + double filledVolume = Math.PI / 3.0 * (1.0 * 1.0 + 1.0 * 0.5 + 0.5 * 0.5) * 1.0; + // magic 2D cad drawing... // // Since the thickness < fore radius, the @@ -424,7 +425,8 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { double innerTransitionAftRadius = 0.7205; double innerTransitionForeRadius = 0.2205; - double innerVolume = Math.PI /3.0 * ( innerTransitionAftRadius * innerTransitionAftRadius + innerTransitionAftRadius * innerTransitionForeRadius + innerTransitionForeRadius * innerTransitionForeRadius); + double innerVolume = Math.PI / 3.0 + * (innerTransitionAftRadius * innerTransitionAftRadius + innerTransitionAftRadius * innerTransitionForeRadius + innerTransitionForeRadius * innerTransitionForeRadius); double volume = filledVolume - innerVolume; @@ -434,15 +436,15 @@ public class SymmetricComponentVolumeTest extends BaseTestCase { volume += Math.PI * 1.0 * 0.5 * 0.5 - Math.PI * 1.0 * 0.25 * 0.25; - double mass = density * volume; + double mass = density * volume; - System.out.println( volume ); + System.out.println(volume); - assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume); - assertEquals( mass, nc.getMass(), epsilonPercent * mass ); + assertEquals(volume, nc.getComponentVolume(), epsilonPercent * volume); + assertEquals(mass, nc.getMass(), epsilonPercent * mass); - assertEquals( 0.7829, cg.x, epsilonPercent * 0.7829 ); - assertEquals( mass, cg.weight, epsilonPercent * mass); + assertEquals(0.7829, cg.x, epsilonPercent * 0.7829); + assertEquals(mass, cg.weight, epsilonPercent * mass); } - + } -- 2.30.2