Skip to content

Commit

Permalink
Changing Scene ComboBox for Checkbox #54
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Jan 8, 2025
1 parent a3c09d4 commit 701b5f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 42 deletions.
21 changes: 9 additions & 12 deletions js/bloch-sphere/model/BlochSphereModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import EnumerationIO from '../../../../tandem/js/types/EnumerationIO.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import { BlochSphereScene } from './BlochSphereScene.js';
import ComplexBlochSphere from './ComplexBlochSphere.js';
import { MeasurementBasis } from './MeasurementBasis.js';
import { StateDirection } from './StateDirection.js';
Expand All @@ -29,7 +28,7 @@ type QuantumMeasurementModelOptions = SelfOptions & PickRequired<PhetioObjectOpt

export default class BlochSphereModel implements TModel {

public readonly selectedSceneProperty: Property<BlochSphereScene>;
public readonly showMagneticFieldProperty: BooleanProperty;

// Bloch Spheres shown in the screen
public readonly preparationBlochSphere: ComplexBlochSphere;
Expand Down Expand Up @@ -70,10 +69,8 @@ export default class BlochSphereModel implements TModel {

public constructor( providedOptions: QuantumMeasurementModelOptions ) {

this.selectedSceneProperty = new Property( BlochSphereScene.MEASUREMENT, {
tandem: providedOptions.tandem.createTandem( 'selectedSceneProperty' ),
phetioReadOnly: true,
phetioValueType: EnumerationIO( BlochSphereScene ),
this.showMagneticFieldProperty = new BooleanProperty( false, {
tandem: providedOptions.tandem.createTandem( 'showMagneticFieldProperty' ),
phetioFeatured: true
} );

Expand Down Expand Up @@ -182,13 +179,13 @@ export default class BlochSphereModel implements TModel {

// Set the precession rate of the Bloch sphere based on the magnetic field strength and the selected scene.
Multilink.multilink(
[ this.magneticFieldStrengthProperty, this.selectedSceneProperty ],
( magneticFieldStrength, selectedScene ) => {
this.singleMeasurementBlochSphere.rotatingSpeedProperty.value = selectedScene === BlochSphereScene.PRECESSION ?
[ this.magneticFieldStrengthProperty, this.showMagneticFieldProperty ],
( magneticFieldStrength, showMagneticField ) => {
this.singleMeasurementBlochSphere.rotatingSpeedProperty.value = showMagneticField ?
magneticFieldStrength :
0;
this.multiMeasurementBlochSpheres.forEach( blochSphere => {
blochSphere.rotatingSpeedProperty.value = selectedScene === BlochSphereScene.PRECESSION ?
blochSphere.rotatingSpeedProperty.value = showMagneticField ?
magneticFieldStrength :
0;
} );
Expand Down Expand Up @@ -268,7 +265,7 @@ export default class BlochSphereModel implements TModel {
public reset(): void {
this.resetCounts();
this.preparationBlochSphere.reset();
this.selectedSceneProperty.reset();
this.showMagneticFieldProperty.reset();
this.readyToObserveProperty.reset();
this.magneticFieldStrengthProperty.reset();
this.measurementBasisProperty.reset();
Expand All @@ -285,7 +282,7 @@ export default class BlochSphereModel implements TModel {
this.multiMeasurementBlochSpheres.forEach( blochSphere => {
blochSphere.step( dt );
} );
if ( this.selectedSceneProperty.value === BlochSphereScene.PRECESSION ) {
if ( this.showMagneticFieldProperty.value ) {
this.measurementTimeProperty.value += dt;
this.measurementTimeProperty.value %= 2;
}
Expand Down
7 changes: 3 additions & 4 deletions js/bloch-sphere/view/BlochSphereMeasurementArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import QuantumMeasurementHistogram from '../../common/view/QuantumMeasurementHis
import quantumMeasurement from '../../quantumMeasurement.js';
import QuantumMeasurementStrings from '../../QuantumMeasurementStrings.js';
import BlochSphereModel from '../model/BlochSphereModel.js';
import { BlochSphereScene } from '../model/BlochSphereScene.js';
import { MeasurementBasis } from '../model/MeasurementBasis.js';
import BlochSphereNumericalEquationNode from './BlochSphereNumericalEquationNode.js';
import MagneticFieldControl from './MagneticFieldControl.js';
Expand All @@ -46,7 +45,7 @@ export default class BlochSphereMeasurementArea extends Node {
} );

const magneticFieldNode = new MagneticFieldNode( model.magneticFieldStrengthProperty, {
visibleProperty: DerivedProperty.valueEqualsConstant( model.selectedSceneProperty, BlochSphereScene.PRECESSION )
visibleProperty: model.showMagneticFieldProperty
} );

const singleMeasurementBlochSphereNode = new BlochSphereNode( model.singleMeasurementBlochSphere, {
Expand Down Expand Up @@ -143,7 +142,7 @@ export default class BlochSphereMeasurementArea extends Node {

const measurementTimerControl = new MeasurementTimerControl( model.timeToMeasurementProperty, model.measurementTimeProperty, {
tandem: providedOptions.tandem.createTandem( 'measurementTimerControl' ),
visibleProperty: DerivedProperty.valueEqualsConstant( model.selectedSceneProperty, BlochSphereScene.PRECESSION )
visibleProperty: model.showMagneticFieldProperty
} );

const measurementControlPanel = new Panel( new VBox( {
Expand Down Expand Up @@ -201,7 +200,7 @@ export default class BlochSphereMeasurementArea extends Node {
const magneticFieldControl = new MagneticFieldControl( model.magneticFieldStrengthProperty, {
centerX: singleMeasurementBlochSphereNode.centerX,
top: magneticFieldNode.bottom + 10,
visibleProperty: DerivedProperty.valueEqualsConstant( model.selectedSceneProperty, BlochSphereScene.PRECESSION ),
visibleProperty: model.showMagneticFieldProperty,
tandem: providedOptions.tandem.createTandem( 'magneticFieldControl' )
} );

Expand Down
40 changes: 14 additions & 26 deletions js/bloch-sphere/view/BlochSphereScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

import BlochSphereModel from 'model/BlochSphereModel.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { Color, Line, Text, VBox } from '../../../../scenery/js/imports.js';
import ComboBox, { ComboBoxItem } from '../../../../sun/js/ComboBox.js';
import { Color, Line, Text } from '../../../../scenery/js/imports.js';
import Checkbox from '../../../../sun/js/Checkbox.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import QuantumMeasurementScreenView from '../../common/view/QuantumMeasurementScreenView.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import { BlochSphereScene } from '../model/BlochSphereScene.js';
import BlochSphereMeasurementArea from './BlochSphereMeasurementArea.js';
import BlochSpherePreparationArea from './BlochSpherePreparationArea.js';

Expand Down Expand Up @@ -43,39 +42,28 @@ export default class BlochSphereScreenView extends QuantumMeasurementScreenView
} );
this.addChild( dividingLine );

const comboBoxItems: ComboBoxItem<BlochSphereScene>[] = BlochSphereScene.enumeration.values.map( scene => {
return {
value: scene,
createNode: () => new Text( scene.description, { font: new PhetFont( 16 ) } )
};
} );

const sceneSelectionComboBox = new ComboBox( model.selectedSceneProperty, comboBoxItems, this, {
tandem: tandem.createTandem( 'sceneSelectionComboBox' )
} );

const measurementAreaTitleAndComboBox = new VBox( {
children: [
new Text( 'Spin Measurement', { font: new PhetFont( { size: 20, weight: 'bolder' } ) } ),
sceneSelectionComboBox
],
spacing: 10,
centerX: this.layoutBounds.centerX + 150,
top: this.layoutBounds.top + 20
} );
this.addChild( measurementAreaTitleAndComboBox );
const showMagneticFieldCheckbox = new Checkbox(
model.showMagneticFieldProperty,
new Text( 'Show Magnetic Field', { font: new PhetFont( { size: 16 } ) } ),
{
tandem: tandem.createTandem( 'showMagneticFieldCheckbox' ),
spacing: 10,
centerX: this.layoutBounds.centerX + 150,
top: this.layoutBounds.top + 20
} );
this.addChild( showMagneticFieldCheckbox );


const measurementArea = new BlochSphereMeasurementArea( model, {
tandem: tandem.createTandem( 'measurementArea' ),
left: dividingLineX + 20,
top: measurementAreaTitleAndComboBox.bottom + 20
top: showMagneticFieldCheckbox.bottom + 20
} );
this.addChild( measurementArea );

this.pdomPlayAreaNode.pdomOrder = [
preparationArea,
measurementAreaTitleAndComboBox,
showMagneticFieldCheckbox,
measurementArea
];

Expand Down

0 comments on commit 701b5f0

Please sign in to comment.