Skip to content

Commit

Permalink
Featuring a number of properties as well as phetio cleanup, #63
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Nov 28, 2024
1 parent 494d47f commit 4f0ea19
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
14 changes: 7 additions & 7 deletions js/spin/model/ParticleSourceModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,19 @@ export default class ParticleSourceModel {
this.sourceModeProperty = new Property<SourceMode>( SourceMode.SINGLE, {
tandem: tandem.createTandem( 'sourceModeProperty' ),
phetioValueType: EnumerationIO( SourceMode ),
validValues: SourceMode.enumeration.values
validValues: SourceMode.enumeration.values,
phetioFeatured: true
} );

this.isContinuousModeProperty = new DerivedProperty( [ this.sourceModeProperty ], sourceMode => sourceMode === SourceMode.CONTINUOUS );

this.particleAmountProperty = new NumberProperty( 0.1, {
tandem: tandem.createTandem( 'particleAmountProperty' ),
range: new Range( 0, 1 )
range: new Range( 0, 1 ),
phetioFeatured: true
} );

this.positionProperty = new Vector2Property( position, {
tandem: tandem.createTandem( 'positionProperty' ),
phetioReadOnly: true
} );
this.positionProperty = new Vector2Property( position );

this.exitLocalPosition = new Vector2( 0, 0 );

Expand All @@ -75,7 +74,8 @@ export default class ParticleSourceModel {
this.spinStateProperty = new Property<SpinDirection>( initialSpinState, {
tandem: tandem.createTandem( 'spinStateProperty' ),
phetioValueType: EnumerationIO( SpinDirection ),
validValues: SpinDirection.enumeration.values
validValues: SpinDirection.enumeration.values,
phetioFeatured: true
} );

this.customSpinStateProperty = new Vector2Property( SpinDirection.spinToVector( initialSpinState ) );
Expand Down
12 changes: 3 additions & 9 deletions js/spin/model/SpinModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export default class SpinModel implements TModel {
this.currentExperimentProperty = new Property<SpinExperiment>( SpinExperiment.EXPERIMENT_1, {
tandem: providedOptions.tandem.createTandem( 'currentExperimentProperty' ),
phetioValueType: EnumerationIO( SpinExperiment ),
validValues: SpinExperiment.enumeration.values
validValues: SpinExperiment.enumeration.values,
phetioFeatured: true
} );
this.isCustomExperimentProperty = new DerivedProperty(
[ this.currentExperimentProperty ],
Expand Down Expand Up @@ -114,7 +115,7 @@ export default class SpinModel implements TModel {
// This is needed for the number sliders to work properly.
this.downProbabilityProperty = new NumberProperty( 1 - this.upProbabilityProperty.value );

const sternGerlachsTandem = providedOptions.tandem.createTandem( 'SternGerlachs' );
const sternGerlachsTandem = providedOptions.tandem.createTandem( 'sternGerlachs' );
this.sternGerlachs = [
new SternGerlach( new Vector2( 0.8, 0 ), true, sternGerlachsTandem.createTandem( 'firstSternGerlach' ) ),
new SternGerlach( new Vector2( 2, 0.3 ), false, sternGerlachsTandem.createTandem( 'secondSternGerlach' ) ),
Expand Down Expand Up @@ -142,13 +143,6 @@ export default class SpinModel implements TModel {
)
];

// Find the first inactive single particle and activate it
this.particleSourceModel.currentlyShootingParticlesProperty.link( shooting => {
if ( shooting ) {
this.particleSystem.shootSingleParticle();
}
} );

this.expectedPercentageVisibleProperty = new BooleanProperty( false, {
tandem: providedOptions.tandem.createTandem( 'expectedPercentageVisibleProperty' )
} );
Expand Down
13 changes: 12 additions & 1 deletion js/spin/view/ParticleSourceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @author Agustín Vallejo
*/

import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import Dimension2 from '../../../../dot/js/Dimension2.js';
import { Shape } from '../../../../kite/js/imports.js';
Expand All @@ -21,6 +22,7 @@ import QuantumMeasurementColors from '../../common/QuantumMeasurementColors.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import QuantumMeasurementStrings from '../../QuantumMeasurementStrings.js';
import ParticleSourceModel from '../model/ParticleSourceModel.js';
import { ParticleSystem } from '../model/ParticleSystem.js';
import { SourceMode } from '../model/SourceMode.js';
import HBarOverTwoNode from './HBarOverTwoNode.js';

Expand All @@ -30,6 +32,7 @@ export default class ParticleSourceNode extends Node {

public constructor(
particleSourceModel: ParticleSourceModel,
particleSystem: ParticleSystem,
modelViewTransform: ModelViewTransform2,
tandem: Tandem ) {

Expand Down Expand Up @@ -65,16 +68,24 @@ export default class ParticleSourceNode extends Node {
particleSourceBarrel.rotateAround( particleSourceBarrel.center, Math.PI / 4 );
particleSourceBarrel.center.y = particleSourceRectangle.center.y;

const currentlyShootingParticlesProperty = new BooleanProperty( false );

// Button for 'single' mode
const shootParticleButton = new RoundMomentaryButton<boolean>(
particleSourceModel.currentlyShootingParticlesProperty, false, true, {
currentlyShootingParticlesProperty, false, true, {
scale: 0.7,
baseColor: QuantumMeasurementColors.downColorProperty,
visibleProperty: DerivedProperty.not( particleSourceModel.isContinuousModeProperty ),
center: particleSourceRectangle.center,
tandem: tandem.createTandem( 'shootParticleButton' )
} );

currentlyShootingParticlesProperty.link( shooting => {
if ( shooting ) {
particleSystem.shootSingleParticle();
}
} );

// Slider for 'continuous' mode
const sliderRange = particleSourceModel.particleAmountProperty.range;
const particleAmountSlider = new HSlider( particleSourceModel.particleAmountProperty, sliderRange, {
Expand Down
7 changes: 6 additions & 1 deletion js/spin/view/SpinMeasurementArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export default class SpinMeasurementArea extends VBox {
180 // empirically determined
);

const particleSourceNode = new ParticleSourceNode( model.particleSourceModel, modelViewTransform, tandem.createTandem( 'particleSourceNode' ) );
const particleSourceNode = new ParticleSourceNode(
model.particleSourceModel,
model.particleSystem,
modelViewTransform,
tandem.createTandem( 'particleSourceNode' )
);

const sternGerlachNodes = [
new SternGerlachNode(
Expand Down

0 comments on commit 4f0ea19

Please sign in to comment.