Fixed Load/Save Issues for Boosters and Pods
Fixed hiearchy / naming issues, mostly
    mv StageSaver.java => AxialStageSaver.java
    populate ComponentAssemblySaver.java
    fixed method class refs in DocumentConfig.java
			
			
This commit is contained in:
		
							parent
							
								
									ea8066f63c
								
							
						
					
					
						commit
						a6be346c8d
					
				
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 269 B After Width: | Height: | Size: 269 B | 
| @ -15,6 +15,7 @@ import net.sf.openrocket.document.OpenRocketDocument; | ||||
| import net.sf.openrocket.document.Simulation; | ||||
| import net.sf.openrocket.document.StorageOptions; | ||||
| import net.sf.openrocket.file.RocketSaver; | ||||
| import net.sf.openrocket.rocketcomponent.AxialStage; | ||||
| import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent; | ||||
| import net.sf.openrocket.rocketcomponent.FinSet; | ||||
| import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent; | ||||
| @ -22,7 +23,6 @@ import net.sf.openrocket.rocketcomponent.MotorMount; | ||||
| import net.sf.openrocket.rocketcomponent.RecoveryDevice; | ||||
| import net.sf.openrocket.rocketcomponent.Rocket; | ||||
| import net.sf.openrocket.rocketcomponent.RocketComponent; | ||||
| import net.sf.openrocket.rocketcomponent.AxialStage; | ||||
| import net.sf.openrocket.rocketcomponent.TubeCoupler; | ||||
| import net.sf.openrocket.rocketcomponent.TubeFinSet; | ||||
| import net.sf.openrocket.simulation.FlightData; | ||||
| @ -384,18 +384,46 @@ public class OpenRocketSaver extends RocketSaver { | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Finds a getElements method somewhere in the *saver class hiearchy corresponding to the given component.  | ||||
| 	 */ | ||||
| 	private static Reflection.Method findGetElementsMethod(RocketComponent component) { | ||||
| 		String currentclassname; | ||||
| 		Class<?> currentclass; | ||||
| 		String saverclassname; | ||||
| 		Class<?> saverClass; | ||||
| 		 | ||||
| 		Reflection.Method mtr = null; // method-to-return | ||||
| 		 | ||||
| 		currentclass = component.getClass(); | ||||
| 		while ((currentclass != null) && (currentclass != Object.class)) { | ||||
| 			currentclassname = currentclass.getSimpleName(); | ||||
| 			saverclassname = METHOD_PACKAGE + "." + currentclassname + METHOD_SUFFIX; | ||||
| 			 | ||||
| 			try { | ||||
| 				saverClass = Class.forName(saverclassname); | ||||
| 				 | ||||
| 				// if class exists | ||||
| 				java.lang.reflect.Method m = saverClass.getMethod("getElements", RocketComponent.class); | ||||
| 				mtr = new Reflection.Method(m); | ||||
| 				 | ||||
| 				return mtr; | ||||
| 			} catch (Exception ignore) { | ||||
| 			} | ||||
| 			 | ||||
| 			currentclass = currentclass.getSuperclass(); | ||||
| 		} | ||||
| 		 | ||||
| 		// if( null == mtr ){ | ||||
| 		throw new BugException("Unable to find saving class for component " + | ||||
| 				METHOD_PACKAGE + "." + component.getClass().getSimpleName() + " ... " + METHOD_SUFFIX); | ||||
| 	} | ||||
| 	 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	private void saveComponent(RocketComponent component) throws IOException { | ||||
| 		 | ||||
| 		log.debug("Saving component " + component.getComponentName()); | ||||
| 		 | ||||
| 		Reflection.Method m = Reflection.findMethod(METHOD_PACKAGE, component, METHOD_SUFFIX, | ||||
| 				"getElements", RocketComponent.class); | ||||
| 		if (m == null) { | ||||
| 			throw new BugException("Unable to find saving class for component " + | ||||
| 					component.getComponentName()); | ||||
| 		} | ||||
| 		Reflection.Method m = findGetElementsMethod(component); | ||||
| 		 | ||||
| 		// Get the strings to save | ||||
| 		List<String> list = (List<String>) m.invokeStatic(component); | ||||
|  | ||||
| @ -403,28 +403,17 @@ class DocumentConfig { | ||||
| 				Reflection.findMethod(Rocket.class, "setRevision", String.class))); | ||||
| 		 | ||||
| 		// Stage | ||||
| 		setters.put("Stage:separationevent", new EnumSetter<StageSeparationConfiguration.SeparationEvent>( | ||||
| 		setters.put("AxialStage:separationevent", new EnumSetter<StageSeparationConfiguration.SeparationEvent>( | ||||
| 				Reflection.findMethod(AxialStage.class, "getStageSeparationConfiguration"), | ||||
| 				Reflection.findMethod(StageSeparationConfiguration.class, "setSeparationEvent", StageSeparationConfiguration.SeparationEvent.class), | ||||
| 				StageSeparationConfiguration.SeparationEvent.class)); | ||||
| 		setters.put("Stage:separationdelay", new DoubleSetter( | ||||
| 		setters.put("AxialStage:separationdelay", new DoubleSetter( | ||||
| 				Reflection.findMethod(AxialStage.class, "getStageSeparationConfiguration"), | ||||
| 				Reflection.findMethod(StageSeparationConfiguration.class, "setSeparationDelay", double.class))); | ||||
| 		 | ||||
| 		//		// Stage | ||||
| 		//		setters.put("Stage:separationevent", new EnumSetter<StageSeparationConfiguration.SeparationEvent>( | ||||
| 		//				Reflection.findMethod(AxialStage.class, "getStageSeparationConfiguration"), | ||||
| 		//				Reflection.findMethod(StageSeparationConfiguration.class, "setSeparationEvent", StageSeparationConfiguration.SeparationEvent.class), | ||||
| 		//				StageSeparationConfiguration.SeparationEvent.class)); | ||||
| 		//		setters.put("Stage:separationdelay", new DoubleSetter( | ||||
| 		//				Reflection.findMethod(AxialStage.class, "getStageSeparationConfiguration"), | ||||
| 		//				Reflection.findMethod(StageSeparationConfiguration.class, "setSeparationDelay", double.class))); | ||||
| 		//				 | ||||
| 		//		setters.put("Stage:outside", new BooleanSetter(Reflection.findMethod(AxialStage.class, "setOutside", boolean.class))); | ||||
| 		//		setters.put("Stage:relativeto", new IntSetter(Reflection.findMethod(AxialStage.class, "setRelativeToStage", int.class))); | ||||
| 		//		setters.put("Stage:instancecount", new IntSetter(Reflection.findMethod(AxialStage.class, "setInstanceCount", int.class))); | ||||
| 		//		setters.put("Stage:radialoffset", new DoubleSetter(Reflection.findMethod(AxialStage.class, "setRadialOffset", double.class))); | ||||
| 		//		setters.put("Stage:angleoffset", new DoubleSetter(Reflection.findMethod(AxialStage.class, "setAngularOffset", double.class))); | ||||
| 		setters.put("ComponentAssembly:instancecount", new IntSetter(Reflection.findMethod(AxialStage.class, "setInstanceCount", int.class))); | ||||
| 		setters.put("ComponentAssembly:radialoffset", new DoubleSetter(Reflection.findMethod(AxialStage.class, "setRadialOffset", double.class))); | ||||
| 		setters.put("ComponentAssembly:angleoffset", new DoubleSetter(Reflection.findMethod(AxialStage.class, "setAngularOffset", double.class))); | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
|  | ||||
| @ -1,7 +1,6 @@ | ||||
| package net.sf.openrocket.file.openrocket.savers; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.List; | ||||
| import java.util.Locale; | ||||
| 
 | ||||
| @ -11,16 +10,28 @@ import net.sf.openrocket.rocketcomponent.Rocket; | ||||
| import net.sf.openrocket.rocketcomponent.RocketComponent; | ||||
| import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration; | ||||
| 
 | ||||
| public class StageSaver extends ComponentAssemblySaver { | ||||
| public class AxialStageSaver extends ComponentAssemblySaver { | ||||
| 	 | ||||
| 	private static final StageSaver instance = new StageSaver(); | ||||
| 	private static final AxialStageSaver instance = new AxialStageSaver(); | ||||
| 	 | ||||
| 	public static ArrayList<String> getElements(net.sf.openrocket.rocketcomponent.RocketComponent c) { | ||||
| 		ArrayList<String> list = new ArrayList<String>(); | ||||
| 		 | ||||
| 		list.add("<stage>"); | ||||
| 		instance.addParams(c, list); | ||||
| 		list.add("</stage>"); | ||||
| 		if (c.isCenterline()) { | ||||
| 			// yes, this test is redundant.  I'm merely paranoid, and attempting to future-proof it | ||||
| 			if (c.getClass().equals(AxialStage.class)) { | ||||
| 				// kept as simply 'stage' for backward compatability | ||||
| 				list.add("<stage>"); | ||||
| 				instance.addParams(c, list); | ||||
| 				list.add("</stage>"); | ||||
| 			} | ||||
| 		} else { | ||||
| 			if (c instanceof BoosterSet) { | ||||
| 				list.add("<boosterset>"); | ||||
| 				instance.addParams(c, list); | ||||
| 				list.add("</boosterset>"); | ||||
| 			} | ||||
| 		} | ||||
| 		 | ||||
| 		return list; | ||||
| 	} | ||||
| @ -30,11 +41,6 @@ public class StageSaver extends ComponentAssemblySaver { | ||||
| 		super.addParams(c, elements); | ||||
| 		AxialStage stage = (AxialStage) c; | ||||
| 		 | ||||
| 		if (stage instanceof BoosterSet) { | ||||
| 			BoosterSet booster = (BoosterSet) stage; | ||||
| 			elements.addAll(this.addStageReplicationParams(booster)); | ||||
| 		} | ||||
| 		 | ||||
| 		if (stage.getStageNumber() > 0) { | ||||
| 			// NOTE:  Default config must be BEFORE overridden config for proper backward compatibility later on | ||||
| 			elements.addAll(separationConfig(stage.getStageSeparationConfiguration().getDefault(), false)); | ||||
| @ -62,25 +68,6 @@ public class StageSaver extends ComponentAssemblySaver { | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	private Collection<? extends String> addStageReplicationParams(final BoosterSet currentStage) { | ||||
| 		List<String> elementsToReturn = new ArrayList<String>(); | ||||
| 		final String instCt_tag = "instancecount"; | ||||
| 		final String radoffs_tag = "radialoffset"; | ||||
| 		final String startangle_tag = "angleoffset"; | ||||
| 		 | ||||
| 		 | ||||
| 		if (null != currentStage) { | ||||
| 			int instanceCount = currentStage.getInstanceCount(); | ||||
| 			elementsToReturn.add("<" + instCt_tag + ">" + instanceCount + "</" + instCt_tag + ">"); | ||||
| 			double radialOffset = currentStage.getRadialOffset(); | ||||
| 			elementsToReturn.add("<" + radoffs_tag + ">" + radialOffset + "</" + radoffs_tag + ">"); | ||||
| 			double angularOffset = currentStage.getAngularOffset(); | ||||
| 			elementsToReturn.add("<" + startangle_tag + ">" + angularOffset + "</" + startangle_tag + ">"); | ||||
| 		} | ||||
| 		 | ||||
| 		return elementsToReturn; | ||||
| 	} | ||||
| 	 | ||||
| 	private List<String> separationConfig(StageSeparationConfiguration config, boolean indent) { | ||||
| 		List<String> elements = new ArrayList<String>(2); | ||||
| 		elements.add((indent ? "    " : "") + "<separationevent>" | ||||
| @ -1,7 +1,65 @@ | ||||
| package net.sf.openrocket.file.openrocket.savers; | ||||
| 
 | ||||
| public class ComponentAssemblySaver extends RocketComponentSaver { | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.List; | ||||
| 
 | ||||
| 	// No-op | ||||
| import net.sf.openrocket.rocketcomponent.BoosterSet; | ||||
| import net.sf.openrocket.rocketcomponent.ComponentAssembly; | ||||
| import net.sf.openrocket.rocketcomponent.PodSet; | ||||
| import net.sf.openrocket.rocketcomponent.RocketComponent; | ||||
| 
 | ||||
| public class ComponentAssemblySaver extends RocketComponentSaver { | ||||
| 	 | ||||
| } | ||||
| 	 | ||||
| 	private static final ComponentAssemblySaver instance = new ComponentAssemblySaver(); | ||||
| 	 | ||||
| 	public static ArrayList<String> getElements(net.sf.openrocket.rocketcomponent.RocketComponent c) { | ||||
| 		ArrayList<String> list = new ArrayList<String>(); | ||||
| 		 | ||||
| 		if (!c.isCenterline()) { | ||||
| 			if (c instanceof PodSet) { | ||||
| 				list.add("<podset>"); | ||||
| 				instance.addParams(c, list); | ||||
| 				list.add("</podset>"); | ||||
| 			} else if (c instanceof BoosterSet) { | ||||
| 				list.add("<booster>"); | ||||
| 				instance.addParams(c, list); | ||||
| 				list.add("</booster>"); | ||||
| 			} | ||||
| 		} | ||||
| 		 | ||||
| 		return list; | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| 	protected void addParams(RocketComponent c, List<String> elements) { | ||||
| 		super.addParams(c, elements); | ||||
| 		ComponentAssembly ca = (ComponentAssembly) c; | ||||
| 		 | ||||
| 		if (!ca.isCenterline()) { | ||||
| 			elements.addAll(this.addAssemblyInstanceParams(ca)); | ||||
| 		} | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
| 	protected Collection<? extends String> addAssemblyInstanceParams(final ComponentAssembly currentStage) { | ||||
| 		List<String> elementsToReturn = new ArrayList<String>(); | ||||
| 		final String instCt_tag = "instancecount"; | ||||
| 		final String radoffs_tag = "radialoffset"; | ||||
| 		final String startangle_tag = "angleoffset"; | ||||
| 		 | ||||
| 		 | ||||
| 		if (null != currentStage) { | ||||
| 			int instanceCount = currentStage.getInstanceCount(); | ||||
| 			elementsToReturn.add("<" + instCt_tag + ">" + instanceCount + "</" + instCt_tag + ">"); | ||||
| 			double radialOffset = currentStage.getRadialOffset(); | ||||
| 			elementsToReturn.add("<" + radoffs_tag + ">" + radialOffset + "</" + radoffs_tag + ">"); | ||||
| 			double angularOffset = currentStage.getAngularOffset(); | ||||
| 			elementsToReturn.add("<" + startangle_tag + ">" + angularOffset + "</" + startangle_tag + ">"); | ||||
| 		} | ||||
| 		 | ||||
| 		return elementsToReturn; | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
| @ -72,9 +72,6 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC | ||||
| 			return true; | ||||
| 		} else if (PodSet.class.isAssignableFrom(type)) { | ||||
| 			return true; | ||||
| 			// DEBUG ONLY.  Remove this clause before production. | ||||
| 		} else if (AxialStage.class.isAssignableFrom(type)) { | ||||
| 			return true; | ||||
| 		} | ||||
| 		 | ||||
| 		return BodyComponent.class.isAssignableFrom(type); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user