- public static ComponentPreset create( TypedPropertyMap props ) throws InvalidComponentPresetException {
-
- ComponentPreset preset = new ComponentPreset();
- // First do validation.
- if ( !props.containsKey(TYPE)) {
- throw new InvalidComponentPresetException("No Type specified " + props.toString() );
- }
-
- if (!props.containsKey(MANUFACTURER)) {
- throw new InvalidComponentPresetException("No Manufacturer specified " + props.toString() );
- }
-
- if (!props.containsKey(PARTNO)) {
- throw new InvalidComponentPresetException("No PartNo specified " + props.toString() );
- }
-
- preset.properties.putAll(props);
-
- // Should check for various bits of each of the types.
- Type t = props.get(TYPE);
- switch ( t ) {
- case BODY_TUBE: {
-
- if ( !props.containsKey(LENGTH) ) {
- throw new InvalidComponentPresetException( "No Length specified for body tube preset " + props.toString());
- }
-
- BodyTube bt = new BodyTube();
-
- bt.setLength(props.get(LENGTH));
-
- // Need to verify contains 2 of OD, thickness, ID. Compute the third.
- boolean hasOd = props.containsKey(OUTER_DIAMETER);
- boolean hasId = props.containsKey(INNER_DIAMETER);
- boolean hasThickness = props.containsKey(THICKNESS);
-
- if ( hasOd ) {
- double outerRadius = props.get(OUTER_DIAMETER)/2.0;
- double thickness = 0;
- bt.setOuterRadius( outerRadius );
- if ( hasId ) {
- thickness = outerRadius - props.get(INNER_DIAMETER)/2.0;
- } else if ( hasThickness ) {
- thickness = props.get(THICKNESS);
- } else {
- throw new InvalidComponentPresetException("Body tube preset underspecified " + props.toString());
- }
- bt.setThickness( thickness );
- } else {
- if ( ! hasId && ! hasThickness ) {
- throw new InvalidComponentPresetException("Body tube preset underspecified " + props.toString());
- }
- double innerRadius = props.get(INNER_DIAMETER)/2.0;
- double thickness = props.get(THICKNESS);
- bt.setOuterRadius(innerRadius + thickness);
- bt.setThickness(thickness);
- }
-
- preset.properties.put(OUTER_DIAMETER, bt.getOuterRadius() *2.0);
- preset.properties.put(INNER_DIAMETER, bt.getInnerRadius() *2.0);
- preset.properties.put(THICKNESS, bt.getThickness());
-
- // Need to translate Mass to Density.
- if ( props.containsKey(MASS) ) {
- String materialName = "TubeCustom";
- if ( props.containsKey(MATERIAL) ) {
- materialName = props.get(MATERIAL).getName();
- }
- Material m = Material.newMaterial(Material.Type.BULK, materialName, props.get(MASS)/bt.getComponentVolume(), false);
- preset.properties.put(MATERIAL, m);
- }
-
- break;
- }
- case NOSE_CONE: {
- break;
- }
- }
-
- preset.computeDigest();
-
- return preset;
-
- }
-
- // Private constructor to encourage use of factory.
- private ComponentPreset() {