Merge pull request #212 from enderw88/master
Mass Object Symbols and Section mass in component tree tooltips.
This commit is contained in:
commit
c85fe63ed8
@ -921,6 +921,7 @@ MassComponentCfg.tab.ttip.Radialpos = Radial position configuration
|
||||
MassComponentCfg.lbl.Radialdistance = Radial distance:
|
||||
MassComponentCfg.lbl.Radialdirection = Radial direction:
|
||||
MassComponentCfg.but.Reset = Reset
|
||||
MassComponentCfg.lbl.type = Mass type
|
||||
|
||||
! MotorConfig
|
||||
MotorCfg.checkbox.compmotormount = This component is a motor mount
|
||||
@ -1327,7 +1328,14 @@ TrapezoidFinSet.TrapezoidFinSet = Trapezoidal fin set
|
||||
! FreeformFinSet
|
||||
FreeformFinSet.FreeformFinSet = Freeform fin set
|
||||
!MassComponent
|
||||
MassComponent.MassComponent = Mass component
|
||||
MassComponent.MassComponent = Unspecified
|
||||
MassComponent.Altimeter = Altimeter
|
||||
MassComponent.FlightComputer = Flight computer
|
||||
MassComponent.DeploymentCharge = Deployment charge
|
||||
MassComponent.Tracker = Tracker
|
||||
MassComponent.Payload = Payload
|
||||
MassComponent.RecoveryHardware = Recovery hardware
|
||||
MassComponent.Battery = Battery
|
||||
! Parachute
|
||||
Parachute.Parachute = Parachute
|
||||
! ShockCord
|
||||
|
||||
@ -314,6 +314,14 @@ class DocumentConfig {
|
||||
// MassComponent
|
||||
setters.put("MassComponent:mass", new DoubleSetter(
|
||||
Reflection.findMethod(MassComponent.class, "setComponentMass", double.class)));
|
||||
/*setters.put("MassComponent:masscomponenttype", new DoubleSetter(
|
||||
Reflection.findMethod(MassComponent.class, "setMassComponentType", double.class)));*/
|
||||
setters.put("MassComponent:masscomponenttype", new EnumSetter<MassComponent.MassComponentType>(
|
||||
Reflection.findMethod(MassComponent.class, "setMassComponentType", MassComponent.MassComponentType.class),
|
||||
MassComponent.MassComponentType.class));
|
||||
/* setters.put("Transition:shape", new EnumSetter<Transition.Shape>(
|
||||
Reflection.findMethod(Transition.class, "setType", Transition.Shape.class),
|
||||
Transition.Shape.class));*/
|
||||
|
||||
// ShockCord
|
||||
setters.put("ShockCord:cordlength", new DoubleSetter(
|
||||
|
||||
@ -2,31 +2,36 @@ package net.sf.openrocket.file.openrocket.savers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.MassComponent;
|
||||
import net.sf.openrocket.rocketcomponent.MassComponent.MassComponentType;
|
||||
|
||||
|
||||
public class MassComponentSaver extends MassObjectSaver {
|
||||
|
||||
|
||||
private static final MassComponentSaver instance = new MassComponentSaver();
|
||||
|
||||
|
||||
public static List<String> getElements(net.sf.openrocket.rocketcomponent.RocketComponent c) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
|
||||
list.add("<masscomponent>");
|
||||
instance.addParams(c, list);
|
||||
list.add("</masscomponent>");
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void addParams(net.sf.openrocket.rocketcomponent.RocketComponent c, List<String> elements) {
|
||||
super.addParams(c, elements);
|
||||
|
||||
|
||||
MassComponent mass = (MassComponent) c;
|
||||
|
||||
|
||||
elements.add("<mass>" + mass.getMass() + "</mass>");
|
||||
|
||||
MassComponentType type = mass.getMassComponentType();
|
||||
elements.add("<masscomponenttype>" + type.name().toLowerCase(Locale.ENGLISH) + "</masscomponenttype>");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -15,6 +15,29 @@ public class MassComponent extends MassObject {
|
||||
|
||||
private double mass = 0;
|
||||
|
||||
public static enum MassComponentType {
|
||||
MASSCOMPONENT(Application.getTranslator().get("MassComponent.MassComponent")),
|
||||
ALTIMETER(Application.getTranslator().get("MassComponent.Altimeter")),
|
||||
FLIGHTCOMPUTER(Application.getTranslator().get("MassComponent.FlightComputer")),
|
||||
DEPLOYMENTCHARGE(Application.getTranslator().get("MassComponent.DeploymentCharge")),
|
||||
TRACKER(Application.getTranslator().get("MassComponent.Tracker")),
|
||||
PAYLOAD(Application.getTranslator().get("MassComponent.Payload")),
|
||||
RECOVERYHARDWARE(Application.getTranslator().get("MassComponent.RecoveryHardware")),
|
||||
BATTERY(Application.getTranslator().get("MassComponent.Battery"));
|
||||
|
||||
private String title;
|
||||
|
||||
MassComponentType(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
||||
private MassComponentType massComponentType = MassComponentType.MASSCOMPONENT;
|
||||
|
||||
public MassComponent() {
|
||||
super();
|
||||
@ -67,6 +90,21 @@ public class MassComponent extends MassObject {
|
||||
return trans.get("MassComponent.MassComponent");
|
||||
}
|
||||
|
||||
public final MassComponent.MassComponentType getMassComponentType() {
|
||||
mutex.verify();
|
||||
return this.massComponentType;
|
||||
}
|
||||
|
||||
public void setMassComponentType(MassComponent.MassComponentType compType) {
|
||||
mutex.verify();
|
||||
if (this.massComponentType == compType) {
|
||||
return;
|
||||
}
|
||||
checkState();
|
||||
this.massComponentType = compType;
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsChildren() {
|
||||
return false;
|
||||
|
||||
@ -1121,6 +1121,19 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
||||
return getComponentMass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the mass of this component and all of its subcomponents.
|
||||
*/
|
||||
public final double getSectionMass() {
|
||||
Double massSubtotal = getMass();
|
||||
mutex.verify();
|
||||
for (RocketComponent rc : children) {
|
||||
massSubtotal += rc.getSectionMass();
|
||||
}
|
||||
|
||||
return massSubtotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the (possibly overridden) center of gravity and mass.
|
||||
*
|
||||
|
||||
@ -32,7 +32,22 @@ public class MassComponentConfig extends RocketComponentConfig {
|
||||
|
||||
JPanel panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::]", ""));
|
||||
|
||||
//// Mass component type
|
||||
panel.add(new JLabel(trans.get("MassComponentCfg.lbl.type")));
|
||||
@SuppressWarnings("unchecked")
|
||||
JComboBox typecombo = new JComboBox(
|
||||
new EnumModel<MassComponent.MassComponentType>(component, "MassComponentType",
|
||||
new MassComponent.MassComponentType[] {
|
||||
MassComponent.MassComponentType.MASSCOMPONENT,
|
||||
MassComponent.MassComponentType.ALTIMETER,
|
||||
MassComponent.MassComponentType.FLIGHTCOMPUTER,
|
||||
MassComponent.MassComponentType.DEPLOYMENTCHARGE,
|
||||
MassComponent.MassComponentType.TRACKER,
|
||||
MassComponent.MassComponentType.PAYLOAD,
|
||||
MassComponent.MassComponentType.RECOVERYHARDWARE,
|
||||
MassComponent.MassComponentType.BATTERY}));
|
||||
|
||||
panel.add(typecombo, "spanx, growx, wrap");
|
||||
|
||||
//// Mass
|
||||
panel.add(new JLabel(trans.get("MassComponentCfg.lbl.Mass")));
|
||||
@ -116,6 +131,7 @@ public class MassComponentConfig extends RocketComponentConfig {
|
||||
new DoubleModel(component.getParent(), "Length"))),
|
||||
"w 100lp, wrap");
|
||||
|
||||
|
||||
//// General and General properties
|
||||
tabbedPane.insertTab(trans.get("MassComponentCfg.tab.General"), null, panel,
|
||||
trans.get("MassComponentCfg.tab.ttip.General"), 0);
|
||||
|
||||
@ -69,7 +69,15 @@ public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
|
||||
|
||||
sb.append("<b>").append(c.getName()).append("</b>");
|
||||
if (c.isMassive() || c.isMassOverridden() ) {
|
||||
sb.append(" (").append(UnitGroup.UNITS_MASS.toStringUnit(c.getMass())).append(")");
|
||||
sb.append(" (").append(UnitGroup.UNITS_MASS.toStringUnit(c.getMass()));
|
||||
if(c.getChildCount()>0){
|
||||
sb.append(" of ").append(UnitGroup.UNITS_MASS.toStringUnit(c.getSectionMass())).append( " total");
|
||||
}
|
||||
sb.append(")");
|
||||
} else {
|
||||
if((c.getChildCount()>0) && (c.getSectionMass()>0)){
|
||||
sb.append(" (").append(UnitGroup.UNITS_MASS.toStringUnit(c.getSectionMass())).append( " total)");
|
||||
}
|
||||
}
|
||||
|
||||
if ( c.isMassOverridden() ) {
|
||||
|
||||
@ -0,0 +1,237 @@
|
||||
package net.sf.openrocket.gui.rocketfigure;
|
||||
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Arc2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import java.util.Random;
|
||||
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
import net.sf.openrocket.util.MathUtil;
|
||||
import net.sf.openrocket.util.Transformation;
|
||||
|
||||
|
||||
public class MassComponentShapes extends RocketComponentShapes {
|
||||
|
||||
public static Shape[] getShapesSide(net.sf.openrocket.rocketcomponent.RocketComponent component,
|
||||
Transformation transformation) {
|
||||
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
|
||||
|
||||
net.sf.openrocket.rocketcomponent.MassComponent.MassComponentType type = ((net.sf.openrocket.rocketcomponent.MassComponent)component).getMassComponentType();
|
||||
|
||||
double length = tube.getLength();
|
||||
double radius = tube.getRadius();
|
||||
double arc = Math.min(length, 2*radius) * 0.7;
|
||||
Coordinate[] start = transformation.transform(tube.toAbsolute(new Coordinate(0,0,0)));
|
||||
|
||||
Shape[] s = new Shape[start.length];
|
||||
for (int i=0; i < start.length; i++) {
|
||||
s[i] = new RoundRectangle2D.Double(start[i].x*S,(start[i].y-radius)*S,
|
||||
length*S,2*radius*S,arc*S,arc*S);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case ALTIMETER:
|
||||
s = addAltimeterSymbol(s);
|
||||
break;
|
||||
case FLIGHTCOMPUTER:
|
||||
s = addFlightComputerSymbol(s);
|
||||
break;
|
||||
case DEPLOYMENTCHARGE:
|
||||
s = addDeploymentChargeSymbol(s);
|
||||
break;
|
||||
case RECOVERYHARDWARE:
|
||||
s = addRecoveryHardwareSymbol(s);
|
||||
break;
|
||||
case PAYLOAD:
|
||||
s = addPayloadSymbol(s);
|
||||
break;
|
||||
case TRACKER:
|
||||
s = addTrackerSymbol(s);
|
||||
break;
|
||||
case BATTERY:
|
||||
s = addBatterySymbol(s);
|
||||
break;
|
||||
case MASSCOMPONENT:
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
public static Shape[] getShapesBack(net.sf.openrocket.rocketcomponent.RocketComponent component,
|
||||
Transformation transformation) {
|
||||
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
|
||||
|
||||
double or = tube.getRadius();
|
||||
|
||||
Coordinate[] start = transformation.transform(tube.toAbsolute(new Coordinate(0,0,0)));
|
||||
|
||||
Shape[] s = new Shape[start.length];
|
||||
for (int i=0; i < start.length; i++) {
|
||||
s[i] = new Ellipse2D.Double((start[i].z-or)*S,(start[i].y-or)*S,2*or*S,2*or*S);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static Shape[] addAltimeterSymbol(Shape[] baseShape){
|
||||
int offset=baseShape.length;
|
||||
Shape[] newShape = new Shape[baseShape.length+1];
|
||||
System.arraycopy(baseShape, 0, newShape, 0, baseShape.length);
|
||||
|
||||
Rectangle2D bounds = baseShape[0].getBounds2D();
|
||||
Double vMargin = bounds.getHeight()/8.0;
|
||||
Double hMargin = bounds.getWidth()/2.25;
|
||||
Double halfArrowWidth=MathUtil.min(hMargin, vMargin);
|
||||
|
||||
Path2D.Double symbol = new Path2D.Double();
|
||||
symbol.moveTo(bounds.getCenterX(), bounds.getY()+vMargin);
|
||||
symbol.lineTo(bounds.getCenterX(), bounds.getY()+7*vMargin);
|
||||
symbol.lineTo(bounds.getCenterX()-halfArrowWidth, bounds.getY()+6*vMargin);
|
||||
symbol.lineTo(bounds.getCenterX()+halfArrowWidth, bounds.getY()+6*vMargin);
|
||||
symbol.lineTo(bounds.getCenterX(), bounds.getY()+7*vMargin);
|
||||
|
||||
newShape[offset]= symbol;
|
||||
return newShape;
|
||||
}
|
||||
|
||||
private static Shape[] addFlightComputerSymbol(Shape[] baseShape){
|
||||
int pins=12;
|
||||
int offset=baseShape.length;
|
||||
Shape[] newShape = new Shape[baseShape.length+1+pins];
|
||||
System.arraycopy(baseShape, 0, newShape, 0, baseShape.length);
|
||||
|
||||
Rectangle2D bounds = baseShape[0].getBounds2D();
|
||||
|
||||
|
||||
Double vMargin = bounds.getHeight()/8.0;
|
||||
Double hMargin = bounds.getWidth()/6.0;
|
||||
Double pinHeight=vMargin;
|
||||
Double pinSpacing=(bounds.getWidth()-2*hMargin)/(pins+1);
|
||||
Double pinWidth=pinSpacing/2;
|
||||
newShape[offset]=new Rectangle2D.Double(bounds.getX()+hMargin, bounds.getY()+2*vMargin, 4*hMargin,4*vMargin);
|
||||
for(int i=0; i<(pins/2); i++){
|
||||
newShape[i+1+offset]=new Rectangle2D.Double(bounds.getX()+hMargin+2*i*pinSpacing+pinSpacing, bounds.getY()+6*vMargin, pinWidth, pinHeight);
|
||||
newShape[i+pins/2+1+offset]=new Rectangle2D.Double(bounds.getX()+hMargin+2*i*pinSpacing+pinSpacing, bounds.getY()+vMargin, pinWidth, pinHeight);
|
||||
}
|
||||
//newShape[1]=symbol;
|
||||
return newShape;
|
||||
}
|
||||
|
||||
private static Shape[] addTrackerSymbol(Shape[] baseShape){
|
||||
Shape[] newShape = new Shape[baseShape.length+7];
|
||||
int offset=baseShape.length;
|
||||
System.arraycopy(baseShape, 0, newShape, 0, baseShape.length);
|
||||
|
||||
Rectangle2D bounds = baseShape[0].getBounds2D();
|
||||
Double vMargin=bounds.getWidth()/10;
|
||||
|
||||
Double xCenter=bounds.getCenterX();
|
||||
Double yCenter=bounds.getCenterY();
|
||||
|
||||
Double arcExtent = 60.0;
|
||||
Double arcStart1 = 360-arcExtent/2;
|
||||
Double arcStart2 = 180-arcExtent/2;
|
||||
|
||||
if(3*vMargin*Math.sin(Math.toRadians(arcExtent/2))>0.9*bounds.getHeight()/2){
|
||||
vMargin=0.9*bounds.getHeight()/(6*Math.sin(Math.toRadians(arcExtent/2)));
|
||||
}
|
||||
newShape[offset]= new Ellipse2D.Double(xCenter-vMargin/2, yCenter-vMargin/2,vMargin,vMargin);
|
||||
for(int i=1; i<4; i++){
|
||||
newShape[i+offset]= new Arc2D.Double(xCenter-i*vMargin, yCenter-i*vMargin, 2*i*vMargin, 2*i*vMargin, arcStart1,arcExtent,Arc2D.OPEN);
|
||||
newShape[i+3+offset]= new Arc2D.Double(xCenter-i*vMargin, yCenter-i*vMargin, 2*i*vMargin, 2*i*vMargin, arcStart2,arcExtent,Arc2D.OPEN);
|
||||
}
|
||||
return newShape;
|
||||
}
|
||||
private static Shape[] addPayloadSymbol(Shape[] baseShape){
|
||||
Shape[] newShape = new Shape[baseShape.length+1];
|
||||
int offset=baseShape.length;
|
||||
System.arraycopy(baseShape, 0, newShape, 0, baseShape.length);
|
||||
|
||||
Rectangle2D bounds = baseShape[0].getBounds2D();
|
||||
Double vMargin=bounds.getHeight()/10;
|
||||
Double hMargin=bounds.getWidth()/10;
|
||||
|
||||
|
||||
newShape[offset]= new Ellipse2D.Double(bounds.getX()+hMargin, bounds.getY()+vMargin,bounds.getWidth()-2*hMargin,bounds.getHeight()-2*vMargin);
|
||||
|
||||
return newShape;
|
||||
}
|
||||
private static Shape[] addRecoveryHardwareSymbol(Shape[] baseShape){
|
||||
Shape[] newShape = new Shape[baseShape.length+3];
|
||||
int offset=baseShape.length;
|
||||
System.arraycopy(baseShape, 0, newShape, 0, baseShape.length);
|
||||
Rectangle2D bounds = baseShape[0].getBounds2D();
|
||||
Double vMargin=bounds.getHeight()/8;
|
||||
Double hMargin=bounds.getWidth()/8;
|
||||
|
||||
|
||||
newShape[offset]= new RoundRectangle2D.Double(bounds.getX()+hMargin, bounds.getY()+vMargin,bounds.getWidth()-2*hMargin,bounds.getHeight()-2*vMargin, 15, 5);
|
||||
newShape[offset+1]= new RoundRectangle2D.Double(bounds.getX()+hMargin+vMargin, bounds.getY()+2*vMargin,bounds.getWidth()-2*hMargin-2*vMargin,bounds.getHeight()-4*vMargin, 15, 5);
|
||||
newShape[offset+2]= new Rectangle2D.Double(bounds.getCenterX()-1.5*hMargin, bounds.getCenterY()+1.5*vMargin, 3*hMargin, 2*vMargin);
|
||||
return newShape;
|
||||
}
|
||||
|
||||
private static Shape[] addDeploymentChargeSymbol(Shape[] baseShape){
|
||||
int rays=15;
|
||||
Shape[] newShape = new Shape[baseShape.length+2];
|
||||
int offset=baseShape.length;
|
||||
System.arraycopy(baseShape, 0, newShape, 0, baseShape.length);
|
||||
|
||||
Rectangle2D bounds = baseShape[0].getBounds2D();
|
||||
|
||||
Double vMargin=bounds.getWidth()/10;
|
||||
Double xCenter=bounds.getCenterX();
|
||||
Double yCenter=bounds.getCenterY();
|
||||
Random rand = new Random();
|
||||
|
||||
newShape[offset]= new Arc2D.Double(xCenter-2*vMargin, yCenter-2*vMargin,4*vMargin,4*vMargin, 55.0, 180.0, Arc2D.CHORD);
|
||||
|
||||
Path2D.Double explosion = new Path2D.Double();
|
||||
newShape[offset+1]=explosion;
|
||||
|
||||
for(int i=1; i<rays; i++){
|
||||
Double rx = rand.nextDouble()*3.0;
|
||||
Double ry = rand.nextDouble()*2.0;
|
||||
explosion.moveTo(xCenter, yCenter);
|
||||
explosion.lineTo(xCenter+rx*vMargin, yCenter+ry*vMargin);
|
||||
}
|
||||
return newShape;
|
||||
}
|
||||
|
||||
private static Shape[] addBatterySymbol(Shape[] baseShape){
|
||||
Shape[] newShape = new Shape[baseShape.length+1];
|
||||
Rectangle2D bounds = baseShape[0].getBounds2D();
|
||||
int offset=baseShape.length;
|
||||
System.arraycopy(baseShape, 0, newShape, 0, baseShape.length);
|
||||
|
||||
|
||||
Double vMargin = bounds.getHeight()/8.0;
|
||||
Double hMargin = bounds.getWidth()/3.0;
|
||||
Double cellWidth=hMargin/3.0;
|
||||
Double cellTop=bounds.getY()+7*vMargin;
|
||||
Double cellBottom=bounds.getY()+vMargin;
|
||||
|
||||
|
||||
Path2D.Double symbol = new Path2D.Double();
|
||||
symbol.moveTo(bounds.getX()+hMargin, bounds.getCenterY());
|
||||
symbol.lineTo(bounds.getX()+2*hMargin/3, bounds.getCenterY());
|
||||
for(Double x=bounds.getX()+hMargin; x<bounds.getX()+2*hMargin; x+=cellWidth){
|
||||
symbol.moveTo(x,cellTop);
|
||||
symbol.lineTo(x, cellBottom);
|
||||
symbol.moveTo(x+cellWidth/2.0, cellBottom+vMargin);
|
||||
symbol.lineTo(x+cellWidth/2.0, cellTop-vMargin);
|
||||
|
||||
}
|
||||
symbol.moveTo(bounds.getX()+bounds.getWidth()-2*hMargin/3-cellWidth/2, bounds.getCenterY());
|
||||
symbol.lineTo(bounds.getX()+2*hMargin-cellWidth/2, bounds.getCenterY());
|
||||
|
||||
newShape[offset]= symbol;
|
||||
return newShape;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -13,7 +13,7 @@ public class MassObjectShapes extends RocketComponentShapes {
|
||||
public static Shape[] getShapesSide(net.sf.openrocket.rocketcomponent.RocketComponent component,
|
||||
Transformation transformation) {
|
||||
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
|
||||
|
||||
|
||||
double length = tube.getLength();
|
||||
double radius = tube.getRadius();
|
||||
double arc = Math.min(length, 2*radius) * 0.7;
|
||||
@ -24,6 +24,7 @@ public class MassObjectShapes extends RocketComponentShapes {
|
||||
s[i] = new RoundRectangle2D.Double(start[i].x*S,(start[i].y-radius)*S,
|
||||
length*S,2*radius*S,arc*S,arc*S);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -42,6 +43,5 @@ public class MassObjectShapes extends RocketComponentShapes {
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
package net.sf.openrocket.gui.rocketfigure;
|
||||
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
import net.sf.openrocket.util.Transformation;
|
||||
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Arc2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
public class ParachuteShapes extends RocketComponentShapes {
|
||||
|
||||
public static Shape[] getShapesSide(net.sf.openrocket.rocketcomponent.RocketComponent component,
|
||||
Transformation transformation) {
|
||||
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
|
||||
|
||||
double length = tube.getLength();
|
||||
double radius = tube.getRadius();
|
||||
double arc = Math.min(length, 2*radius) * 0.7;
|
||||
Coordinate[] start = transformation.transform(tube.toAbsolute(new Coordinate(0,0,0)));
|
||||
|
||||
Shape[] s = new Shape[start.length];
|
||||
for (int i=0; i < start.length; i++) {
|
||||
s[i] = new RoundRectangle2D.Double(start[i].x*S,(start[i].y-radius)*S,
|
||||
length*S,2*radius*S,arc*S,arc*S);
|
||||
}
|
||||
return addSymbol(s);
|
||||
}
|
||||
|
||||
|
||||
public static Shape[] getShapesBack(net.sf.openrocket.rocketcomponent.RocketComponent component,
|
||||
Transformation transformation) {
|
||||
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
|
||||
|
||||
double or = tube.getRadius();
|
||||
|
||||
Coordinate[] start = transformation.transform(tube.toAbsolute(new Coordinate(0,0,0)));
|
||||
|
||||
Shape[] s = new Shape[start.length];
|
||||
for (int i=0; i < start.length; i++) {
|
||||
s[i] = new Ellipse2D.Double((start[i].z-or)*S,(start[i].y-or)*S,2*or*S,2*or*S);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static Shape[] addSymbol(Shape[] baseShape){
|
||||
int offset=baseShape.length;
|
||||
Shape[] newShape = new Shape[baseShape.length+2];
|
||||
System.arraycopy(baseShape, 0, newShape, 0, baseShape.length);
|
||||
|
||||
Rectangle2D bounds = baseShape[0].getBounds2D();
|
||||
|
||||
Double chuteDiameter = bounds.getHeight()/2;
|
||||
if(chuteDiameter>0.75*bounds.getWidth())
|
||||
chuteDiameter=0.75*bounds.getWidth();
|
||||
|
||||
newShape[offset]=new Arc2D.Double(bounds.getCenterX()-chuteDiameter/2, bounds.getCenterY()-chuteDiameter/4,
|
||||
chuteDiameter,chuteDiameter,180.0,180.0,Arc2D.PIE);
|
||||
Path2D.Double shrouds = new Path2D.Double();
|
||||
shrouds.moveTo(bounds.getCenterX()-chuteDiameter/2, bounds.getCenterY()+chuteDiameter/4);
|
||||
shrouds.lineTo(bounds.getCenterX(), bounds.getCenterY()-3*chuteDiameter/4);
|
||||
shrouds.lineTo(bounds.getCenterX()+chuteDiameter/2, bounds.getCenterY()+chuteDiameter/4);
|
||||
|
||||
shrouds.moveTo(bounds.getCenterX()-chuteDiameter/4, bounds.getCenterY()+chuteDiameter/4);
|
||||
shrouds.lineTo(bounds.getCenterX(), bounds.getCenterY()-3*chuteDiameter/4);
|
||||
shrouds.lineTo(bounds.getCenterX()+chuteDiameter/4, bounds.getCenterY()+chuteDiameter/4);
|
||||
|
||||
shrouds.moveTo(bounds.getCenterX(), bounds.getCenterY()+chuteDiameter/4);
|
||||
shrouds.lineTo(bounds.getCenterX(), bounds.getCenterY()-3*chuteDiameter/4);
|
||||
|
||||
newShape[offset+1]=shrouds;
|
||||
return newShape;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package net.sf.openrocket.gui.rocketfigure;
|
||||
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
import net.sf.openrocket.util.Transformation;
|
||||
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
public class ShockCordShapes extends RocketComponentShapes {
|
||||
|
||||
public static Shape[] getShapesSide(net.sf.openrocket.rocketcomponent.RocketComponent component,
|
||||
Transformation transformation) {
|
||||
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
|
||||
|
||||
double length = tube.getLength();
|
||||
double radius = tube.getRadius();
|
||||
double arc = Math.min(length, 2*radius) * 0.7;
|
||||
Coordinate[] start = transformation.transform(tube.toAbsolute(new Coordinate(0,0,0)));
|
||||
|
||||
Shape[] s = new Shape[start.length];
|
||||
for (int i=0; i < start.length; i++) {
|
||||
s[i] = new RoundRectangle2D.Double(start[i].x*S,(start[i].y-radius)*S,
|
||||
length*S,2*radius*S,arc*S,arc*S);
|
||||
}
|
||||
return addSymbol(s);
|
||||
}
|
||||
|
||||
|
||||
public static Shape[] getShapesBack(net.sf.openrocket.rocketcomponent.RocketComponent component,
|
||||
Transformation transformation) {
|
||||
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
|
||||
|
||||
double or = tube.getRadius();
|
||||
|
||||
Coordinate[] start = transformation.transform(tube.toAbsolute(new Coordinate(0,0,0)));
|
||||
|
||||
Shape[] s = new Shape[start.length];
|
||||
for (int i=0; i < start.length; i++) {
|
||||
s[i] = new Ellipse2D.Double((start[i].z-or)*S,(start[i].y-or)*S,2*or*S,2*or*S);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static Shape[] addSymbol(Shape[] baseShape){
|
||||
int offset=baseShape.length;
|
||||
Shape[] newShape = new Shape[baseShape.length+1];
|
||||
System.arraycopy(baseShape, 0, newShape, 0, baseShape.length);
|
||||
|
||||
Rectangle2D bounds = baseShape[0].getBounds2D();
|
||||
|
||||
Double left=bounds.getX()+bounds.getWidth()/4;
|
||||
Double cordWidth=bounds.getWidth()/2;
|
||||
Double top=bounds.getCenterY();
|
||||
Double flutterHeight=bounds.getHeight()/4;
|
||||
Double flutterWidth=cordWidth/4;
|
||||
|
||||
Path2D.Double streamer= new Path2D.Double();
|
||||
streamer.moveTo(left, bounds.getCenterY());
|
||||
|
||||
for(int i=0; i<4; i++){
|
||||
streamer.curveTo(left+(4*i+1)*flutterWidth/4, top+flutterHeight, left+(4*i+1)*flutterWidth/4, top+flutterHeight, left+(4*i+2)*flutterWidth/4, top);
|
||||
streamer.curveTo(left+(4*i+3)*flutterWidth/4, top-flutterHeight, left+(4*i+3)*flutterWidth/4, top-flutterHeight, left+(4*i+4)*flutterWidth/4, top);
|
||||
}
|
||||
|
||||
newShape[offset]=streamer;
|
||||
return newShape;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
package net.sf.openrocket.gui.rocketfigure;
|
||||
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
import net.sf.openrocket.util.Transformation;
|
||||
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
public class StreamerShapes extends RocketComponentShapes {
|
||||
|
||||
public static Shape[] getShapesSide(net.sf.openrocket.rocketcomponent.RocketComponent component,
|
||||
Transformation transformation) {
|
||||
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
|
||||
|
||||
double length = tube.getLength();
|
||||
double radius = tube.getRadius();
|
||||
double arc = Math.min(length, 2*radius) * 0.7;
|
||||
Coordinate[] start = transformation.transform(tube.toAbsolute(new Coordinate(0,0,0)));
|
||||
|
||||
Shape[] s = new Shape[start.length];
|
||||
for (int i=0; i < start.length; i++) {
|
||||
s[i] = new RoundRectangle2D.Double(start[i].x*S,(start[i].y-radius)*S,
|
||||
length*S,2*radius*S,arc*S,arc*S);
|
||||
}
|
||||
return addSymbol(s);
|
||||
}
|
||||
|
||||
|
||||
public static Shape[] getShapesBack(net.sf.openrocket.rocketcomponent.RocketComponent component,
|
||||
Transformation transformation) {
|
||||
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
|
||||
|
||||
double or = tube.getRadius();
|
||||
|
||||
Coordinate[] start = transformation.transform(tube.toAbsolute(new Coordinate(0,0,0)));
|
||||
|
||||
Shape[] s = new Shape[start.length];
|
||||
for (int i=0; i < start.length; i++) {
|
||||
s[i] = new Ellipse2D.Double((start[i].z-or)*S,(start[i].y-or)*S,2*or*S,2*or*S);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static Shape[] addSymbol(Shape[] baseShape){
|
||||
int offset=baseShape.length;
|
||||
Shape[] newShape = new Shape[baseShape.length+1];
|
||||
System.arraycopy(baseShape, 0, newShape, 0, baseShape.length);
|
||||
|
||||
Rectangle2D bounds = baseShape[0].getBounds2D();
|
||||
|
||||
Double left=bounds.getX()+bounds.getWidth()/4;
|
||||
Double streamerWidth=bounds.getWidth()/2;
|
||||
Double streamerHeight=bounds.getHeight()/2;
|
||||
Double top=bounds.getCenterY()+streamerHeight/2;
|
||||
Double bottom=bounds.getCenterY()-streamerHeight/2;
|
||||
Double flutterHeight=bounds.getHeight()/16;
|
||||
Double flutterWidth=streamerWidth/4;
|
||||
|
||||
Path2D.Double streamer= new Path2D.Double();
|
||||
streamer.moveTo(left, bottom); //bottom left
|
||||
streamer.lineTo(left, top); //upper left
|
||||
for(int i=0; i<4; i++){
|
||||
streamer.curveTo(left+(4*i+1)*flutterWidth/4, top+flutterHeight, left+(4*i+1)*flutterWidth/4, top+flutterHeight, left+(4*i+2)*flutterWidth/4, top);
|
||||
streamer.curveTo(left+(4*i+3)*flutterWidth/4, top-flutterHeight, left+(4*i+3)*flutterWidth/4, top-flutterHeight, left+(4*i+4)*flutterWidth/4, top);
|
||||
}
|
||||
streamer.lineTo(left+streamerWidth, bottom);
|
||||
streamer.moveTo(left, bottom); //bottom left
|
||||
for(int i=0; i<4; i++){
|
||||
streamer.curveTo(left+(4*i+1)*flutterWidth/4, bottom+flutterHeight, left+(4*i+1)*flutterWidth/4, bottom+flutterHeight, left+(4*i+2)*flutterWidth/4, bottom);
|
||||
streamer.curveTo(left+(4*i+3)*flutterWidth/4, bottom-flutterHeight, left+(4*i+3)*flutterWidth/4, bottom-flutterHeight, left+(4*i+4)*flutterWidth/4, bottom);
|
||||
}
|
||||
|
||||
newShape[offset]=streamer;
|
||||
return newShape;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user