Skip to content

Commit

Permalink
Merge pull request openrocket#2693 from MiguelECL/AdditionalRocketPro…
Browse files Browse the repository at this point in the history
…perties

[openrocket#2664] Additional rocket properties
  • Loading branch information
SiboVG authored Feb 1, 2025
2 parents ea2ab87 + c53cb93 commit d4dbf49
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import info.openrocket.core.rocketcomponent.CenteringRing;
import info.openrocket.core.rocketcomponent.DeploymentConfiguration;
import info.openrocket.core.rocketcomponent.DeploymentConfiguration.DeployEvent;
import info.openrocket.core.rocketcomponent.DesignType;
import info.openrocket.core.rocketcomponent.EllipticalFinSet;
import info.openrocket.core.rocketcomponent.EngineBlock;
import info.openrocket.core.rocketcomponent.ExternalComponent;
Expand Down Expand Up @@ -488,7 +489,18 @@ class DocumentConfig {
Reflection.findMethod(Rocket.class, "setDesigner", String.class)));
setters.put("Rocket:revision", new StringSetter(
Reflection.findMethod(Rocket.class, "setRevision", String.class)));

setters.put("Rocket:designtype", new EnumSetter<>(
Reflection.findMethod(Rocket.class, "setDesignType", DesignType.class),
DesignType.class));
setters.put("Rocket:kitname", new StringSetter(
Reflection.findMethod(Rocket.class, "setKitName", String.class)));
// setters.put("Rocket:optimizationflight", new BooleanSetter(
// Reflection.findMethod(Rocket.class, "setOptimizationFlight", boolean.class)));
// setters.put("Rocket:optimizationappearance", new BooleanSetter(
// Reflection.findMethod(Rocket.class, "setOptimizationAppearance", boolean.class)));
// setters.put("Rocket:optimizationconstruction", new BooleanSetter(
// Reflection.findMethod(Rocket.class, "setOptimizationConstruction", boolean.class)));

// Axial Stage
setters.put("AxialStage:separationevent", new EnumSetter<>(
Reflection.findMethod(AxialStage.class, "getSeparationConfigurations"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ protected void addParams(info.openrocket.core.rocketcomponent.RocketComponent c,
+ info.openrocket.core.util.TextUtil.escapeXML(rocket.getDesigner())
+ "</designer>");
}
elements.add("<designtype>" + rocket.getDesignType().getStorableString() + "</designtype>");
if (rocket.getKitName().length() > 0){
elements.add("<kitname>"
+ info.openrocket.core.util.TextUtil.escapeXML(rocket.getKitName())
+ "</kitname>");
}
// if (rocket.isOptimizationFlight() != null){
// elements.add("<optimizationflight>"
// + rocket.isOptimizationFlight()
// + "</optimizationflight>");
// }
// if (rocket.isOptimizationAppearance() != null){
// elements.add("<optimizationappearance>"
// + rocket.isOptimizationAppearance()
// + "</optimizationappearance>");
// }
// if (rocket.isOptimizationConstruction() != null){
// elements.add("<optimizationconstruction>"
// + rocket.isOptimizationConstruction()
// + "</optimizationconstruction>");
// }
if (rocket.getRevision().length() > 0) {
elements.add("<revision>"
+ info.openrocket.core.util.TextUtil.escapeXML(rocket.getRevision())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package info.openrocket.core.rocketcomponent;

import info.openrocket.core.l10n.Translator;
import info.openrocket.core.startup.Application;

import java.util.Locale;

/**
* The type of design of a rocket, e.g. original design, clone kit, etc.
*/
public enum DesignType {
ORIGINAL("DesignType.Originaldesign"),
COMMERCIAL_KIT("DesignType.Commercialkit"),
CLONE_KIT("DesignType.Clonekit"),
UPSCALE_KIT("DesignType.Upscalekit"),
DOWNSCALE_KIT("DesignType.Downscalekit"),
MODIFIED_KIT("DesignType.Modificationkit"),
KIT_BASH("DesignType.Kitbashkit");

private static final Translator trans = Application.getTranslator();
private final String translationKey;

DesignType(String translationKey) {
this.translationKey = translationKey;
}

public String getName() {
return trans.get(translationKey);
}

/**
* Returns a string that can be used to store the design type in a file.
* The result is a lowercase string with underscores removed (for some historical reason, that's how OpenRocket
* does it)...
* @return the storable string
*/
public String getStorableString() {
return name().toLowerCase(Locale.ENGLISH).replace("_", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public class Rocket extends ComponentAssembly {

private String designer = "";
private String revision = "";
private DesignType designType = DesignType.ORIGINAL;
private String kitName = "";
// private boolean optimizationFlight = false;
// private boolean optimizationAppearance = false;
// private boolean optimizationConstruction = false;


// Flight configuration list
Expand Down Expand Up @@ -116,7 +121,78 @@ public void setDesigner(String s) {
designer = s;
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}


/**
* Get the design type of the rocket (e.g. is the current model a clone of a kit, an upscale of a kit, an original
* design...).
* @return the design type
*/
public DesignType getDesignType() {
checkState();
return designType;
}

/**
* Set the design type of the rocket.
* @param type the design type
*/
public void setDesignType(DesignType type) {
if (type == null) {
type = DesignType.ORIGINAL;
}
designType = type;
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}

/**
* Get the name of the kit that this rocket is based on.
* @return the kit name
*/
public String getKitName() {
checkState();
return kitName;
}

/**
* Set the name of the kit that this rocket is based on.
* @param s the kit name
*/
public void setKitName(String s) {
if (s == null)
s = "";
kitName = s;
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}

// public Boolean isOptimizationFlight(){
// checkState();
// return optimizationFlight;
// }
//
// public void setOptimizationFlight(boolean b){
// optimizationFlight = b;
// fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
// }
//
// public Boolean isOptimizationAppearance(){
// checkState();
// return optimizationAppearance;
// }
//
// public void setOptimizationAppearance(boolean b){
// optimizationAppearance = b;
// fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
// }
//
// public Boolean isOptimizationConstruction(){
// checkState();
// return optimizationConstruction;
// }
//
// public void setOptimizationConstruction(boolean b){
// optimizationConstruction = b;
// fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
// }

public String getRevision() {
checkState();
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/resources/l10n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1192,8 +1192,20 @@ RocketCfg.lbl.Designname = Design name:
RocketCfg.lbl.Designer = Designer:
RocketCfg.lbl.Comments = Comments:
RocketCfg.lbl.Revisionhistory = Revision history:
RocketCfg.lbl.Designtype = Design type:
RocketCfg.lbl.Kitname = Kit name:
RocketCfg.lbl.Optimization = Optimization:
RocketCfg.lbl.Material = Material:

! DesignType
DesignType.Originaldesign = Original Design/Other
DesignType.Commercialkit = Commercial Kit
DesignType.Clonekit = Clone of Commercial Kit
DesignType.Upscalekit = Upscale of Commercial Kit
DesignType.Downscalekit = Downscale of Commercial Kit
DesignType.Modificationkit = Modification of a Commercial Kit
DesignType.Kitbashkit = Kit Bash of Commercial Kits

! RocketComponentConfig
RocketCompCfg.lbl.Componentname = Component name:
RocketCompCfg.lbl.Componentname.ttip = The component name.
Expand Down
2 changes: 1 addition & 1 deletion fileformat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ The following file format versions exist:
Added wind model settings (<wind mode="{average or multilevel}">), and windmodeltype to simulation conditions.
Added warning flight events
Added <maxtime> attribute to simulation conditions.

Added <designtype> and <kitname> to <rocket> element.
Loading

0 comments on commit d4dbf49

Please sign in to comment.