diff --git a/js/photons/model/Laser.ts b/js/photons/model/Laser.ts index 5c87c5c..a428a2b 100644 --- a/js/photons/model/Laser.ts +++ b/js/photons/model/Laser.ts @@ -14,8 +14,9 @@ import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js'; import dotRandom from '../../../../dot/js/dotRandom.js'; import Range from '../../../../dot/js/Range.js'; import Vector2 from '../../../../dot/js/Vector2.js'; -import PickRequired from '../../../../phet-core/js/types/PickRequired.js'; -import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js'; +import optionize from '../../../../phet-core/js/optionize.js'; +import WithRequired from '../../../../phet-core/js/types/WithRequired.js'; +import PhetioObject, { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js'; import Tandem from '../../../../tandem/js/Tandem.js'; import StringUnionIO from '../../../../tandem/js/types/StringUnionIO.js'; import quantumMeasurement from '../../quantumMeasurement.js'; @@ -27,7 +28,7 @@ export type PhotonEmissionMode = 'singlePhoton' | 'manyPhotons'; type SelfOptions = { emissionMode: PhotonEmissionMode; }; -type LaserOptions = SelfOptions & PickRequired; +type LaserOptions = SelfOptions & WithRequired; const PolarizationPresetValues = [ 'vertical', 'horizontal', 'fortyFiveDegrees', 'unpolarized', 'custom' ] as const; export type PolarizationPresets = ( typeof PolarizationPresetValues )[number]; @@ -46,7 +47,7 @@ const MAP_OF_PRESET_POLARIZATION_ANGLES = new Map( ] ); -class Laser { +class Laser extends PhetioObject { // The position of the detector in two-dimensional space. Units are in meters. public readonly position: Vector2; @@ -84,6 +85,12 @@ class Laser { public constructor( position: Vector2, photonCollection: PhotonCollection, providedOptions: LaserOptions ) { + const options = optionize()( { + phetioState: false + }, providedOptions ); + + super( options ); + this.position = position; this.photonCollection = photonCollection; this.emissionMode = providedOptions.emissionMode; diff --git a/js/photons/model/PhotonDetector.ts b/js/photons/model/PhotonDetector.ts index c4e3a6b..db5a49e 100644 --- a/js/photons/model/PhotonDetector.ts +++ b/js/photons/model/PhotonDetector.ts @@ -11,9 +11,9 @@ import NumberProperty from '../../../../axon/js/NumberProperty.js'; import Range from '../../../../dot/js/Range.js'; import Vector2 from '../../../../dot/js/Vector2.js'; import { Line } from '../../../../kite/js/imports.js'; -import { combineOptions } from '../../../../phet-core/js/optionize.js'; -import PickRequired from '../../../../phet-core/js/types/PickRequired.js'; -import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js'; +import optionize from '../../../../phet-core/js/optionize.js'; +import WithRequired from '../../../../phet-core/js/types/WithRequired.js'; +import PhetioObject, { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js'; import Tandem from '../../../../tandem/js/Tandem.js'; import AveragingCounterNumberProperty from '../../common/model/AveragingCounterNumberProperty.js'; import quantumMeasurement from '../../quantumMeasurement.js'; @@ -26,7 +26,7 @@ import { TPhotonInteraction } from './TPhotonInteraction.js'; type SelfOptions = { displayMode?: DisplayMode; }; -type PhotonDetectorOptions = SelfOptions & PickRequired; +type PhotonDetectorOptions = SelfOptions & WithRequired; // Define a type for the direction in which the detector is looking for photons. export type DetectionDirection = ( [ 'up', 'down' ] )[number]; @@ -38,7 +38,7 @@ export type DisplayMode = ( [ 'count', 'rate' ] )[number]; export const COUNT_RANGE = new Range( 0, 999 ); export const RATE_RANGE = new Range( 0, 999 ); // in events per second -class PhotonDetector implements TPhotonInteraction { +class PhotonDetector extends PhetioObject implements TPhotonInteraction { // The position of the detector in two-dimensional space. Units are in meters. public readonly position: Vector2; @@ -71,10 +71,13 @@ class PhotonDetector implements TPhotonInteraction { public constructor( position: Vector2, detectionDirection: DetectionDirection, providedOptions: PhotonDetectorOptions ) { - const options = combineOptions( { - displayMode: 'count' + const options = optionize()( { + displayMode: 'count', + phetioState: false }, providedOptions ); + super( options ); + this.position = position; this.detectionDirection = detectionDirection; this.displayMode = options.displayMode!; diff --git a/js/photons/view/LaserNode.ts b/js/photons/view/LaserNode.ts index ff19aca..03f2313 100644 --- a/js/photons/view/LaserNode.ts +++ b/js/photons/view/LaserNode.ts @@ -109,6 +109,8 @@ export default class LaserNode extends Node { }, providedOptions ); super( options ); + + this.addLinkedElement( model ); } } diff --git a/js/photons/view/PhotonDetectorNode.ts b/js/photons/view/PhotonDetectorNode.ts index f6647d0..09ee634 100644 --- a/js/photons/view/PhotonDetectorNode.ts +++ b/js/photons/view/PhotonDetectorNode.ts @@ -39,7 +39,7 @@ export default class PhotonDetectorNode extends Node { public constructor( model: PhotonDetector, modelViewTransform: ModelViewTransform2, - providedOptions?: PhotonDetectorNodeOptions ) { + providedOptions: PhotonDetectorNodeOptions ) { // Create the detection aperture. This is essentially the anchor point for reset of the layout, meaning that the // other nodes are positioned relative to this. @@ -148,6 +148,8 @@ export default class PhotonDetectorNode extends Node { ); super( options ); + + this.addLinkedElement( model ); } } diff --git a/js/photons/view/PhotonTestingArea.ts b/js/photons/view/PhotonTestingArea.ts index 756654c..1e0da8a 100644 --- a/js/photons/view/PhotonTestingArea.ts +++ b/js/photons/view/PhotonTestingArea.ts @@ -82,11 +82,15 @@ class PhotonTestingArea extends Node { const verticalPolarizationDetector = new PhotonDetectorNode( model.verticalPolarizationDetector, - photonTestingAreaModelViewTransform + photonTestingAreaModelViewTransform, { + tandem: providedOptions.tandem.createTandem( 'verticalPolarizationDetector' ) + } ); const horizontalPolarizationDetector = new PhotonDetectorNode( model.horizontalPolarizationDetector, - photonTestingAreaModelViewTransform + photonTestingAreaModelViewTransform, { + tandem: providedOptions.tandem.createTandem( 'horizontalPolarizationDetector' ) + } ); const polarizingBeamSplitterNode = new PolarizingBeamSplitterNode(