Skip to content

Commit

Permalink
phet-io for rulers, #263
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Dec 7, 2021
1 parent 9cfaa0a commit c03f178
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
6 changes: 4 additions & 2 deletions js/common/model/GeometricOpticsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ class GeometricOpticsModel {

this.horizontalRuler = new GeometricOpticsRuler( {
orientation: 'horizontal',
length: GeometricOpticsConstants.HORIZONTAL_RULER_LENGTH
length: GeometricOpticsConstants.HORIZONTAL_RULER_LENGTH,
tandem: options.tandem.createTandem( 'horizontalRuler' )
} );

this.verticalRuler = new GeometricOpticsRuler( {
orientation: 'vertical',
length: GeometricOpticsConstants.VERTICAL_RULER_LENGTH
length: GeometricOpticsConstants.VERTICAL_RULER_LENGTH,
tandem: options.tandem.createTandem( 'verticalRuler' )
} );
}

Expand Down
14 changes: 11 additions & 3 deletions js/common/model/GeometricOpticsRuler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Property from '../../../../axon/js/Property.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import Vector2Property from '../../../../dot/js/Vector2Property.js';
import merge from '../../../../phet-core/js/merge.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import geometricOptics from '../../geometricOptics.js';

type RulerOrientation = 'horizontal' | 'vertical';
Expand Down Expand Up @@ -40,7 +41,10 @@ class GeometricOpticsRuler {

options = merge( {
orientation: 'horizontal',
length: 100
length: 100,

// phet-io options
tandem: Tandem.REQUIRED
}, options );

assert && assert( isFinite( options.length ) && options.length > 0 );
Expand All @@ -50,12 +54,16 @@ class GeometricOpticsRuler {

// The initial value of position really does not matter, because position will be set when the ruler is
// removed from the toolbox.
this.positionProperty = new Vector2Property( Vector2.ZERO );
this.positionProperty = new Vector2Property( Vector2.ZERO, {
tandem: options.tandem.createTandem( 'positionProperty' )
} );

this.length = options.length;
this.nominalLength = options.length;

this.visibleProperty = new BooleanProperty( false );
this.visibleProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'visibleProperty' )
} );
}

public reset(): void {
Expand Down
9 changes: 7 additions & 2 deletions js/common/view/GeometricOpticsRulerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import geometricOpticsStrings from '../../geometricOpticsStrings.js';
import GeometricOpticsConstants from '../GeometricOpticsConstants.js';
import GeometricOpticsRuler from '../model/GeometricOpticsRuler.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import Tandem from '../../../../tandem/js/Tandem.js';

// constants
const MINIMUM_VISIBLE_LENGTH = GeometricOpticsConstants.RULER_MINIMUM_VISIBLE_LENGTH;
Expand Down Expand Up @@ -58,7 +59,10 @@ class GeometricOpticsRulerNode extends Node {

// Node options
rotation: ruler.isVertical ? -Math.PI / 2 : 0,
visibleProperty: ruler.visibleProperty
visibleProperty: ruler.visibleProperty,

// phet-io options
tandem: Tandem.REQUIRED

}, options );
assert && assert( !options.children, 'this Node calls removeAllChildren' );
Expand Down Expand Up @@ -129,7 +133,8 @@ class GeometricOpticsRulerNode extends Node {
if ( this.toolboxBounds.containsPoint( this.globalToParentPoint( event.pointer.point as Vector2 ) ) ) {
ruler.visibleProperty.value = false;
}
}
},
tandem: options.tandem.createTandem( 'dragListener' )
} );
this.addInputListener( this.dragListener );
}
Expand Down
20 changes: 12 additions & 8 deletions js/common/view/GeometricOpticsScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ class GeometricOpticsScreenView extends ScreenView {

// create Rulers
const horizontalRulerNode = new GeometricOpticsRulerNode( model.horizontalRuler,
zoomTransformProperty, zoomScaleProperty, this.visibleBoundsProperty );
zoomTransformProperty, zoomScaleProperty, this.visibleBoundsProperty, {
tandem: config.tandem.createTandem( 'horizontalRulerNode' )
} );
const verticalRulerNode = new GeometricOpticsRulerNode( model.verticalRuler,
zoomTransformProperty, zoomScaleProperty, this.visibleBoundsProperty );
zoomTransformProperty, zoomScaleProperty, this.visibleBoundsProperty, {
tandem: config.tandem.createTandem( 'verticalRulerNode' )
} );

// create control panel at the bottom of the screen
const controlPanel = new GeometricOpticsControlPanel( model.representationProperty, model.optic,
Expand All @@ -141,14 +145,14 @@ class GeometricOpticsScreenView extends ScreenView {
} );

// create toolbox at the top right corner of the screen
const toolbox = new RulersToolbox( [ verticalRulerNode, horizontalRulerNode ], {
const rulersToolbox = new RulersToolbox( [ verticalRulerNode, horizontalRulerNode ], {
rightTop: erodedLayoutBounds.rightTop,
tandem: config.tandem.createTandem( 'toolbox' )
tandem: config.tandem.createTandem( 'rulersToolbox' )
} );

// Tell the rulers where the toolbox is.
horizontalRulerNode.setToolboxBounds( toolbox.bounds );
verticalRulerNode.setToolboxBounds( toolbox.bounds );
horizontalRulerNode.setToolboxBounds( rulersToolbox.bounds );
verticalRulerNode.setToolboxBounds( rulersToolbox.bounds );

// radio buttons for the shape of the optic
const opticShapeRadioButtonGroup = new OpticShapeRadioButtonGroup( model.optic, {
Expand Down Expand Up @@ -358,7 +362,7 @@ class GeometricOpticsScreenView extends ScreenView {
controlPanel,
showHideToggleButton,
resetAllButton,
toolbox,
rulersToolbox,
zoomButtonGroup,
representationComboBox,
rulersLayer,
Expand All @@ -375,7 +379,7 @@ class GeometricOpticsScreenView extends ScreenView {
};

// pdom -traversal order
//TODO https://github.com/phetsims/geometric-optics/issues/235 add Object, second point, light sources, toolbox, rulers
//TODO https://github.com/phetsims/geometric-optics/issues/235 add Object, second point, light sources, rulersToolbox, rulers
// @ts-ignore TYPESCRIPT Property 'pdomOrder' does not exist on type 'Node'.
screenViewRootNode.pdomOrder = [
representationComboBox,
Expand Down

0 comments on commit c03f178

Please sign in to comment.