diff --git a/js/spin/model/MeasurementLine.ts b/js/spin/model/MeasurementLine.ts index 2b2a9cf..ac95bf0 100644 --- a/js/spin/model/MeasurementLine.ts +++ b/js/spin/model/MeasurementLine.ts @@ -53,7 +53,7 @@ export default class MeasurementLine { // Flag to indicate if the line is active public readonly isActiveProperty: Property; - public constructor( position: Vector2, providedOptions: MeasurementLineOptions ) { + public constructor( position: Vector2, originallyActive: boolean, providedOptions: MeasurementLineOptions ) { this.spinStateProperty = new Vector2Property( new Vector2( 0, 1 ), { tandem: providedOptions.tandem.createTandem( 'spinStateProperty' ) @@ -63,15 +63,17 @@ export default class MeasurementLine { this.measurementStateProperty.link( measurementState => { if ( measurementState === MeasurementState.MEASURING ) { + // TODO: How to interrupt this after a restart? https://github.com/phetsims/quantum-measurement/issues/53 + const measurementStateListener = () => { + this.measurementStateProperty.value = MeasurementState.MEASURED; + }; // Count some time and reset the hasMeasured flag - stepTimer.setTimeout( () => { - this.measurementStateProperty.value = MeasurementState.MEASURED; - }, MeasurementState.MEASURING_TIMEOUT_DURATION ); + stepTimer.setTimeout( measurementStateListener, MeasurementState.MEASURING_TIMEOUT_DURATION ); } } ); - this.isActiveProperty = new Property( false, { + this.isActiveProperty = new Property( originallyActive, { tandem: providedOptions.tandem.createTandem( 'isActiveProperty' ), phetioValueType: BooleanIO } ); diff --git a/js/spin/model/ParticleSourceModel.ts b/js/spin/model/ParticleSourceModel.ts index a3349a9..bf60faa 100644 --- a/js/spin/model/ParticleSourceModel.ts +++ b/js/spin/model/ParticleSourceModel.ts @@ -46,7 +46,7 @@ export default class ParticleSourceModel { public constructor( position: Vector2, tandem: Tandem ) { - this.sourceModeProperty = new Property( SourceMode.CONTINUOUS ); + this.sourceModeProperty = new Property( SourceMode.SINGLE ); this.isContinuousModeProperty = new DerivedProperty( [ this.sourceModeProperty ], sourceMode => sourceMode === SourceMode.CONTINUOUS ); @@ -84,6 +84,7 @@ export default class ParticleSourceModel { this.positionProperty.reset(); this.currentlyShootingParticlesProperty.reset(); this.particleAmountProperty.reset(); + this.spinStateProperty.reset(); } } diff --git a/js/spin/model/SpinModel.ts b/js/spin/model/SpinModel.ts index 1f15591..b91a32d 100644 --- a/js/spin/model/SpinModel.ts +++ b/js/spin/model/SpinModel.ts @@ -74,7 +74,7 @@ export default class SpinModel implements TModel { public constructor( providedOptions: QuantumMeasurementModelOptions ) { - this.currentExperimentProperty = new Property( SpinExperiment.CUSTOM ); + this.currentExperimentProperty = new Property( SpinExperiment.EXPERIMENT_1 ); this.isCustomExperimentProperty = new DerivedProperty( [ this.currentExperimentProperty ], ( experiment: SpinExperiment ) => experiment === SpinExperiment.CUSTOM @@ -112,15 +112,15 @@ export default class SpinModel implements TModel { this.measurementLines = [ new MeasurementLine( new Vector2( ( this.particleSourceModel.exitPositionProperty.value.x + this.sternGerlachs[ 0 ].entrancePositionProperty.value.x ) / 2, 1 ), - { tandem: measurementLinesTandem.createTandem( 'firstMeasurementLine' ) } + true, { tandem: measurementLinesTandem.createTandem( 'firstMeasurementLine' ) } ), new MeasurementLine( new Vector2( ( this.sternGerlachs[ 0 ].topExitPositionProperty.value.x + this.sternGerlachs[ 1 ].entrancePositionProperty.value.x ) / 2, 1 ), - { tandem: measurementLinesTandem.createTandem( 'secondMeasurementLine' ) } + true, { tandem: measurementLinesTandem.createTandem( 'secondMeasurementLine' ) } ), new MeasurementLine( new Vector2( ( this.sternGerlachs[ 1 ].topExitPositionProperty.value.x + this.sternGerlachs[ 1 ].topExitPositionProperty.value.plusXY( 1, 0 ).x ) / 2, 1 ), - { tandem: measurementLinesTandem.createTandem( 'thirdMeasurementLine' ) } + false, { tandem: measurementLinesTandem.createTandem( 'thirdMeasurementLine' ) } ) ]; @@ -266,11 +266,10 @@ export default class SpinModel implements TModel { * Resets the model. */ public reset(): void { + this.measurementLines.forEach( line => line.reset() ); this.sternGerlachs.forEach( sternGerlach => sternGerlach.reset() ); this.particleSystem.reset(); - this.measurementLines.forEach( line => line.reset() ); this.currentExperimentProperty.reset(); - this.particleSourceModel.spinStateProperty.reset(); this.particleSourceModel.reset(); }