Set current configuration before creating simulation
createSimulationForConfiguration() assumed addConfiguration() and copyConfiguration() would set the new configuration as selected, but they didn't resulting in simulation based on old configuration, not new one. Fixed. addConfiguration() and copyConfiguration() had enough common code that consolidating them and createSimulationForConfiguration() seemed like a good idea. Let FlightConfiguration.copy() create new ID for consistency with constructor.
This commit is contained in:
parent
aa300709f5
commit
09123dd0ce
@ -463,10 +463,11 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
* @return the new configuration
|
* @return the new configuration
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FlightConfiguration copy( final FlightConfigurationId copyId ) {
|
public FlightConfiguration copy( final FlightConfigurationId newId ) {
|
||||||
// Note the stages are updated in the constructor call.
|
// Note the stages are updated in the constructor call.
|
||||||
FlightConfiguration copy= new FlightConfiguration( this.rocket, copyId );
|
FlightConfiguration copy= new FlightConfiguration( this.rocket, newId );
|
||||||
|
final FlightConfigurationId copyId = copy.getId();
|
||||||
|
|
||||||
// copy motor instances.
|
// copy motor instances.
|
||||||
for( final MotorConfiguration sourceMotor: motors.values() ){
|
for( final MotorConfiguration sourceMotor: motors.values() ){
|
||||||
MotorConfiguration cloneMotor = sourceMotor.copy( copyId);
|
MotorConfiguration cloneMotor = sourceMotor.copy( copyId);
|
||||||
|
@ -64,6 +64,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
|||||||
//// Motor tabs
|
//// Motor tabs
|
||||||
motorConfigurationPanel = new MotorConfigurationPanel(this, rocket);
|
motorConfigurationPanel = new MotorConfigurationPanel(this, rocket);
|
||||||
tabs.add(trans.get("edtmotorconfdlg.lbl.Motortab"), motorConfigurationPanel);
|
tabs.add(trans.get("edtmotorconfdlg.lbl.Motortab"), motorConfigurationPanel);
|
||||||
|
|
||||||
//// Recovery tab
|
//// Recovery tab
|
||||||
recoveryConfigurationPanel = new RecoveryConfigurationPanel(this, rocket);
|
recoveryConfigurationPanel = new RecoveryConfigurationPanel(this, rocket);
|
||||||
tabs.add(trans.get("edtmotorconfdlg.lbl.Recoverytab"), recoveryConfigurationPanel);
|
tabs.add(trans.get("edtmotorconfdlg.lbl.Recoverytab"), recoveryConfigurationPanel);
|
||||||
@ -76,7 +77,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
|||||||
newConfButton.addActionListener(new ActionListener() {
|
newConfButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
addConfiguration();
|
addOrCopyConfiguration(false);
|
||||||
configurationChanged();
|
configurationChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +109,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
|||||||
copyConfButton.addActionListener(new ActionListener() {
|
copyConfButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
copyConfiguration();
|
addOrCopyConfiguration(true);
|
||||||
configurationChanged();
|
configurationChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -118,37 +119,46 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
|||||||
|
|
||||||
this.add(tabs, "spanx, grow, wrap rel");
|
this.add(tabs, "spanx, grow, wrap rel");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addConfiguration() {
|
|
||||||
FlightConfigurationId newId = new FlightConfigurationId();
|
|
||||||
FlightConfiguration newConfig = new FlightConfiguration( rocket, newId );
|
|
||||||
rocket.setFlightConfiguration( newId, newConfig);
|
|
||||||
|
|
||||||
// Create a new simulation for this configuration.
|
/**
|
||||||
createSimulationForNewConfiguration( newId );
|
* either create or copy configuration
|
||||||
|
* set new configuration as current
|
||||||
configurationChanged();
|
* create simulation for new configuration
|
||||||
}
|
*/
|
||||||
|
private void addOrCopyConfiguration(boolean copy) {
|
||||||
private void copyConfiguration() {
|
FlightConfiguration newConfig;
|
||||||
FlightConfigurationId oldId = this.motorConfigurationPanel.getSelectedConfigurationId();
|
FlightConfigurationId newId;
|
||||||
FlightConfiguration oldConfig = rocket.getFlightConfiguration(oldId);
|
|
||||||
|
|
||||||
FlightConfigurationId newId = new FlightConfigurationId();
|
// create or copy configuration
|
||||||
FlightConfiguration newConfig = oldConfig.copy( newId);
|
if (copy) {
|
||||||
|
FlightConfigurationId oldId = this.motorConfigurationPanel.getSelectedConfigurationId();
|
||||||
|
FlightConfiguration oldConfig = rocket.getFlightConfiguration(oldId);
|
||||||
|
|
||||||
for (RocketComponent c : rocket) {
|
newConfig = oldConfig.copy(null);
|
||||||
if (c instanceof FlightConfigurableComponent) {
|
newId = newConfig.getId();
|
||||||
((FlightConfigurableComponent) c).copyFlightConfiguration(oldId, newId);
|
|
||||||
|
for (RocketComponent c : rocket) {
|
||||||
|
if (c instanceof FlightConfigurableComponent) {
|
||||||
|
((FlightConfigurableComponent) c).copyFlightConfiguration(oldId, newId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
newConfig = new FlightConfiguration(rocket, null);
|
||||||
|
newId = newConfig.getId();
|
||||||
}
|
}
|
||||||
rocket.setFlightConfiguration( newId, newConfig);
|
|
||||||
|
|
||||||
|
// associate configuration with Id and select it
|
||||||
|
rocket.setFlightConfiguration(newId, newConfig);
|
||||||
|
rocket.setSelectedConfiguration(newId);
|
||||||
|
|
||||||
// Create a new simulation for this configuration.
|
// create simulation for configuration
|
||||||
createSimulationForNewConfiguration( newId);
|
Simulation newSim = new Simulation(rocket);
|
||||||
|
|
||||||
configurationChanged();
|
OpenRocketDocument doc = BasicFrame.findDocument(rocket);
|
||||||
|
if (doc != null) {
|
||||||
|
newSim.setName(doc.getNextSimulationName());
|
||||||
|
doc.addSimulation(newSim);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renameConfiguration() {
|
private void renameConfiguration() {
|
||||||
@ -164,18 +174,6 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
|||||||
configurationChanged();
|
configurationChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* prereq - assumes that the new configuration has been set as the default configuration.
|
|
||||||
*/
|
|
||||||
private void createSimulationForNewConfiguration( final FlightConfigurationId fcid ) {
|
|
||||||
Simulation newSim = new Simulation(rocket);
|
|
||||||
OpenRocketDocument doc = BasicFrame.findDocument(rocket);
|
|
||||||
if (doc != null) {
|
|
||||||
newSim.setName(doc.getNextSimulationName());
|
|
||||||
doc.addSimulation(newSim);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void configurationChanged() {
|
private void configurationChanged() {
|
||||||
motorConfigurationPanel.fireTableDataChanged();
|
motorConfigurationPanel.fireTableDataChanged();
|
||||||
recoveryConfigurationPanel.fireTableDataChanged();
|
recoveryConfigurationPanel.fireTableDataChanged();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user