From e5ca3d930e3e17c0259b085358fa6314825f62b4 Mon Sep 17 00:00:00 2001 From: Bill Kuker Date: Sun, 12 Apr 2009 17:31:52 +0000 Subject: [PATCH] Added new grain type, bound properties on compound grain --- .../motorsim/grain/CompoundGrain.java | 16 +++- .../motorsim/grain/RodAndTubeGrain.java | 82 +++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java diff --git a/src/com/billkuker/rocketry/motorsim/grain/CompoundGrain.java b/src/com/billkuker/rocketry/motorsim/grain/CompoundGrain.java index 2eb5fb5..ee1ac61 100644 --- a/src/com/billkuker/rocketry/motorsim/grain/CompoundGrain.java +++ b/src/com/billkuker/rocketry/motorsim/grain/CompoundGrain.java @@ -1,6 +1,7 @@ package com.billkuker.rocketry.motorsim.grain; import java.awt.geom.Area; +import java.beans.PropertyChangeListener; import java.util.HashSet; import java.util.Set; @@ -11,8 +12,9 @@ import javax.measure.unit.SI; import org.jscience.physics.amount.Amount; import com.billkuker.rocketry.motorsim.Grain; +import com.billkuker.rocketry.motorsim.MotorPart; -public class CompoundGrain implements Grain { +public class CompoundGrain extends MotorPart implements Grain { private Set grains = new HashSet(); @@ -23,6 +25,18 @@ public class CompoundGrain implements Grain { public void add( Grain g ){ grains.add(g); } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + for ( Grain g : grains ) + if ( g instanceof MotorPart ) + ((MotorPart)g).addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + for ( Grain g : grains ) + if ( g instanceof MotorPart ) + ((MotorPart)g).removePropertyChangeListener(listener); + } public Area getCrossSection(Amount regression) { Area a = new Area(); diff --git a/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java b/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java new file mode 100644 index 0000000..2ae00f4 --- /dev/null +++ b/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java @@ -0,0 +1,82 @@ +package com.billkuker.rocketry.motorsim.grain; + +import java.beans.PropertyVetoException; + +import javax.measure.quantity.Length; +import javax.measure.unit.SI; + +import org.jscience.physics.amount.Amount; + +import com.billkuker.rocketry.motorsim.Grain; + +public class RodAndTubeGrain extends CompoundGrain { + CoredCylindricalGrain rod, tube; + + public RodAndTubeGrain() { + try{ + rod = new CoredCylindricalGrain(); + rod.setInnerSurfaceInhibited(true); + rod.setID(Amount.valueOf(0, SI.MILLIMETER)); + rod.setOD(Amount.valueOf(10, SI.MILLIMETER)); + rod.setOuterSurfaceInhibited(false); + rod.setEndSurfaceInhibited(true); + + tube = new CoredCylindricalGrain(); + tube.setInnerSurfaceInhibited(false); + tube.setID(Amount.valueOf(20, SI.MILLIMETER)); + tube.setOD(Amount.valueOf(30, SI.MILLIMETER)); + tube.setOuterSurfaceInhibited(true); + tube.setEndSurfaceInhibited(true); + } catch ( PropertyVetoException v ){ + v.printStackTrace(); + //I know these values are OK + } + + add(rod); + add(tube); + } + + public Amount getRodDiameter() { + return rod.getOD(); + } + + public void setRodDiameter(Amount od) throws PropertyVetoException { + rod.setOD(od); + } + + public Amount getTubeID() { + return tube.getID(); + } + + public void setTubeID(Amount id) throws PropertyVetoException { + tube.setID(id); + } + + public Amount getOd() { + return tube.getOD(); + } + + public void setOd(Amount od) throws PropertyVetoException { + tube.setOD(od); + } + + public boolean isEndSurfaceInhibited() { + return rod.isEndSurfaceInhibited(); + } + + public void setEndSurfaceInhibited(boolean endSurfaceInhibited) + throws PropertyVetoException { + rod.setEndSurfaceInhibited(endSurfaceInhibited); + tube.setEndSurfaceInhibited(endSurfaceInhibited); + } + + public Amount getLength() { + return rod.getLength(); + } + + public void setLength(Amount length) throws PropertyVetoException { + rod.setLength(length); + tube.setLength(length); + } + +} -- 2.47.2