[Refactor] Rocket inherits from ComponentAssembly instead of RocketComponent
- conceptually, a rocket *IS A* ComponentAssembly. - reduces code duplication: 7 redundant functions - rocket still inherits all the RocketComponent methods - Also: changed Coordinate.NUL -> Coordinate.ZERO to better reflect our intent. -- Nitpick: Coordinate.NUL is *not* null. It's zero. These are different! -- Null is an error condition. -- Zero is a valid coordinate. Zero means something is located at the origin. Like the rocket, and the nosecone.
This commit is contained in:
parent
05d439bd1e
commit
445e6caac3
@ -31,6 +31,11 @@ public abstract class ComponentAssembly extends RocketComponent {
|
|||||||
super(RocketComponent.Position.AFTER);
|
super(RocketComponent.Position.AFTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowsChildren(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getAxialOffset() {
|
public double getAxialOffset() {
|
||||||
return super.asPositionValue(this.relativePosition);
|
return super.asPositionValue(this.relativePosition);
|
||||||
@ -49,7 +54,7 @@ public abstract class ComponentAssembly extends RocketComponent {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Coordinate getComponentCG() {
|
public Coordinate getComponentCG() {
|
||||||
return Coordinate.NUL;
|
return Coordinate.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,10 +127,7 @@ public abstract class ComponentAssembly extends RocketComponent {
|
|||||||
@Override
|
@Override
|
||||||
public void setAxialOffset(final double _pos) {
|
public void setAxialOffset(final double _pos) {
|
||||||
this.updateBounds();
|
this.updateBounds();
|
||||||
// System.err.println("updating axial position for boosters: " + this.getName() + " ( " + this.getComponentName() + ")");
|
|
||||||
// System.err.println(" requesting offset: " + _pos + " via: " + this.relativePosition.name());
|
|
||||||
super.setAxialOffset(this.relativePosition, _pos);
|
super.setAxialOffset(this.relativePosition, _pos);
|
||||||
// System.err.println(" resultant offset: " + this.position.x + " via: " + this.relativePosition.name());
|
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.sf.openrocket.rocketcomponent;
|
package net.sf.openrocket.rocketcomponent;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.EventListener;
|
import java.util.EventListener;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -14,7 +13,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.util.ArrayList;
|
import net.sf.openrocket.util.ArrayList;
|
||||||
import net.sf.openrocket.util.Coordinate;
|
|
||||||
import net.sf.openrocket.util.MathUtil;
|
import net.sf.openrocket.util.MathUtil;
|
||||||
import net.sf.openrocket.util.StateChangeListener;
|
import net.sf.openrocket.util.StateChangeListener;
|
||||||
import net.sf.openrocket.util.UniqueID;
|
import net.sf.openrocket.util.UniqueID;
|
||||||
@ -30,7 +28,7 @@ import net.sf.openrocket.util.UniqueID;
|
|||||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class Rocket extends RocketComponent {
|
public class Rocket extends ComponentAssembly {
|
||||||
private static final Logger log = LoggerFactory.getLogger(Rocket.class);
|
private static final Logger log = LoggerFactory.getLogger(Rocket.class);
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
@ -76,7 +74,6 @@ public class Rocket extends RocketComponent {
|
|||||||
///////////// Constructor /////////////
|
///////////// Constructor /////////////
|
||||||
|
|
||||||
public Rocket() {
|
public Rocket() {
|
||||||
super(RocketComponent.Position.AFTER);
|
|
||||||
modID = UniqueID.next();
|
modID = UniqueID.next();
|
||||||
massModID = modID;
|
massModID = modID;
|
||||||
aeroModID = modID;
|
aeroModID = modID;
|
||||||
@ -765,45 +762,7 @@ public class Rocket extends RocketComponent {
|
|||||||
return trans.get("Rocket.compname.Rocket");
|
return trans.get("Rocket.compname.Rocket");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Coordinate getComponentCG() {
|
|
||||||
return new Coordinate(0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getComponentMass() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getLongitudinalUnitInertia() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getRotationalUnitInertia() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Coordinate> getComponentBounds() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAerodynamic() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isMassive() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean allowsChildren() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows only <code>AxialStage</code> components to be added to the type Rocket.
|
* Allows only <code>AxialStage</code> components to be added to the type Rocket.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user