Fix bug radius offset not updating with radius method

This commit is contained in:
SiboVG 2022-06-11 01:19:04 +02:00
parent bd3770ddc3
commit 7ec703964c
5 changed files with 94 additions and 26 deletions

View File

@ -424,7 +424,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
this.stages.clear(); this.stages.clear();
for (AxialStage curStage : this.rocket.getStageList()) { for (AxialStage curStage : this.rocket.getStageList()) {
if (curStage == null) continue;
StageFlags flagsToAdd = new StageFlags( curStage.getStageNumber(), true); StageFlags flagsToAdd = new StageFlags( curStage.getStageNumber(), true);
this.stages.put(curStage.getStageNumber(), flagsToAdd); this.stages.put(curStage.getStageNumber(), flagsToAdd);
} }

View File

@ -204,7 +204,14 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
} }
} }
setRadius( radiusMethod, radius_m ); if (radius_m == this.radiusOffset_m) return;
if (this.radiusMethod.clampToZero() ) {
this.radiusOffset_m = 0.0;
} else {
this.radiusOffset_m = radius_m;
}
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }
@Override @Override
@ -230,15 +237,14 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
mutex.verify(); mutex.verify();
RadiusMethod newMethod = requestedMethod;
double newRadius = requestedRadius; double newRadius = requestedRadius;
if( newMethod.clampToZero() ) { if( requestedMethod.clampToZero() ) {
newRadius = 0.; newRadius = 0.;
} }
this.radiusMethod = newMethod; this.radiusMethod = requestedMethod;
this.radiusOffset_m = newRadius; this.radiusOffset_m = this.radiusMethod.getAsOffset(getParent(), this, newRadius);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }
@ -267,14 +273,18 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
} }
@Override @Override
public void setRadiusMethod(RadiusMethod newRadiusMethod) { public void setRadiusMethod(RadiusMethod newMethod) {
for (RocketComponent listener : configListeners) { for (RocketComponent listener : configListeners) {
if (listener instanceof ParallelStage) { if (listener instanceof ParallelStage) {
((ParallelStage) listener).setRadiusMethod(newRadiusMethod); ((ParallelStage) listener).setRadiusMethod(newMethod);
} }
} }
setRadius( newRadiusMethod, this.radiusOffset_m ); if (newMethod == this.radiusMethod) return;
mutex.verify();
double radius = this.radiusMethod.getRadius(getParent(), this, this.radiusOffset_m); // Radius from the parent's center
setRadius(newMethod, radius);
} }

View File

@ -225,9 +225,12 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
} }
mutex.verify(); mutex.verify();
if( this.radiusMethod.clampToZero() ) {
if (radius_m == this.radiusOffset_m) return;
if (this.radiusMethod.clampToZero()) {
this.radiusOffset_m = 0.0; this.radiusOffset_m = 0.0;
}else { } else {
this.radiusOffset_m = radius_m; this.radiusOffset_m = radius_m;
} }
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
@ -246,9 +249,11 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
} }
} }
if (newMethod == this.radiusMethod) return;
mutex.verify(); mutex.verify();
this.radiusMethod = newMethod; double radius = this.radiusMethod.getRadius(getParent(), this, this.radiusOffset_m); // Radius from the parent's center
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); setRadius(newMethod, radius);
} }
@Override @Override
@ -261,15 +266,14 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
mutex.verify(); mutex.verify();
RadiusMethod newMethod = requestMethod;
double newRadius = requestRadius; double newRadius = requestRadius;
if( this.radiusMethod.clampToZero() ) { if( this.radiusMethod.clampToZero() ) {
newRadius = 0.; newRadius = 0.;
} }
this.radiusMethod = newMethod; this.radiusMethod = requestMethod;
this.radiusOffset_m = newRadius; this.radiusOffset_m = this.radiusMethod.getAsOffset(getParent(), this, newRadius);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }

View File

@ -16,6 +16,11 @@ public enum RadiusMethod implements DistanceMethod {
public double getRadius( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ){ public double getRadius( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ){
return 0.; return 0.;
} }
@Override
public double getAsOffset(final RocketComponent parentComponent, final RocketComponent thisComponent, double radius) {
return 0;
}
}, },
FREE(Application.getTranslator().get("RocketComponent.Position.Method.Radius.FREE") ){ FREE(Application.getTranslator().get("RocketComponent.Position.Method.Radius.FREE") ){
@ -26,6 +31,11 @@ public enum RadiusMethod implements DistanceMethod {
public double getRadius( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ){ public double getRadius( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ){
return requestedOffset; return requestedOffset;
} }
@Override
public double getAsOffset(final RocketComponent parentComponent, final RocketComponent thisComponent, double radius) {
return radius;
}
}, },
RELATIVE ( Application.getTranslator().get("RocketComponent.Position.Method.Radius.RELATIVE") ){ RELATIVE ( Application.getTranslator().get("RocketComponent.Position.Method.Radius.RELATIVE") ){
@ -43,6 +53,18 @@ public enum RadiusMethod implements DistanceMethod {
} }
return radius; return radius;
} }
@Override
public double getAsOffset(final RocketComponent parentComponent, final RocketComponent thisComponent, double radius) {
double offset = radius;
if (parentComponent instanceof BodyTube) {
offset -= ((BodyTube)parentComponent).getOuterRadius();
}
if (thisComponent instanceof RadiusPositionable) {
offset -= ((RadiusPositionable)thisComponent).getBoundingRadius();
}
return offset;
}
}, },
// Defines placement relative to the outside of the target component // Defines placement relative to the outside of the target component
@ -60,6 +82,11 @@ public enum RadiusMethod implements DistanceMethod {
} }
return radius; return radius;
} }
@Override
public double getAsOffset(RocketComponent parentComponent, RocketComponent thisComponent, double radius) {
return 0;
}
}; };
public static final RadiusMethod[] choices(){ public static final RadiusMethod[] choices(){
@ -82,5 +109,15 @@ public enum RadiusMethod implements DistanceMethod {
@Override @Override
public boolean clampToZero() { return true; } public boolean clampToZero() { return true; }
public abstract double getRadius( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ); public abstract double getRadius(final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset );
/**
* Returns the radius offset argument (starting from the center of its parent) as an offset value for this
* RadiusMethod.
* @param parentComponent parent of this component
* @param thisComponent the component for which the offset is requested
* @param radius the radius offset argument
* @return the offset value of this RadiusMethod that yields the given radius
*/
public abstract double getAsOffset(final RocketComponent parentComponent, final RocketComponent thisComponent, final double radius);
} }

View File

@ -208,6 +208,19 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
quad2 = quad1 = quad0 = 0; // Not used quad2 = quad1 = quad0 = 0; // Not used
} }
public ValueSliderModel(double min, DoubleModel max) {
this.islinear = true;
linearPosition = 1.0;
this.min = new DoubleModel(min);
this.mid = max; // Never use exponential scale
this.max = max;
max.addChangeListener(this);
quad2 = quad1 = quad0 = 0; // Not used
}
/** /**
@ -427,6 +440,10 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
return new ValueSliderModel(min, max); return new ValueSliderModel(min, max);
} }
public BoundedRangeModel getSliderModel(double min, DoubleModel max) {
return new ValueSliderModel(min, max);
}
public BoundedRangeModel getSliderModel(double min, double mid, double max) { public BoundedRangeModel getSliderModel(double min, double mid, double max) {
return new ValueSliderModel(min, mid, max); return new ValueSliderModel(min, mid, max);
} }