From c741079fd605c11dc1d236a596ba93c1b07bf719 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sun, 14 Dec 2014 10:27:24 -0700 Subject: [PATCH 1/2] Restructuring and adding symbols to all MassObjects. --- .../gui/rocketfigure/MassComponentShapes.java | 237 ++++++++++++++++++ .../gui/rocketfigure/MassObjectShapes.java | 190 -------------- .../gui/rocketfigure/ParachuteShapes.java | 76 ++++++ 3 files changed, 313 insertions(+), 190 deletions(-) create mode 100644 swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java create mode 100644 swing/src/net/sf/openrocket/gui/rocketfigure/ParachuteShapes.java diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java new file mode 100644 index 000000000..20730e33d --- /dev/null +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java @@ -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; i0.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; i0.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; + } +} From 8a8bb51f488ae2bc17976ef943ce4c8e9e0cf83f Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sun, 14 Dec 2014 12:03:25 -0700 Subject: [PATCH 2/2] Added Stream and Shock cord symbology. --- .../gui/rocketfigure/ShockCordShapes.java | 71 +++++++++++++++++ .../gui/rocketfigure/StreamerShapes.java | 79 +++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 swing/src/net/sf/openrocket/gui/rocketfigure/ShockCordShapes.java create mode 100644 swing/src/net/sf/openrocket/gui/rocketfigure/StreamerShapes.java diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/ShockCordShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/ShockCordShapes.java new file mode 100644 index 000000000..79ffdb89c --- /dev/null +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/ShockCordShapes.java @@ -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; + } +} diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/StreamerShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/StreamerShapes.java new file mode 100644 index 000000000..7a5f41bd9 --- /dev/null +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/StreamerShapes.java @@ -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; + } +}