Skip to content

Commit

Permalink
partial instrumentation, #92
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jan 30, 2020
1 parent 1da0342 commit a8b8e50
Show file tree
Hide file tree
Showing 7 changed files with 554 additions and 29 deletions.
47 changes: 40 additions & 7 deletions js/common/model/Dropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ define( require => {
const NumberProperty = require( 'AXON/NumberProperty' );
const phScale = require( 'PH_SCALE/phScale' );
const Property = require( 'AXON/Property' );
const Tandem = require( 'TANDEM/Tandem' );

class Dropper extends Movable {

Expand All @@ -32,18 +33,50 @@ define( require => {
dispensing: false, // is the dropper dispensing solute?
enabled: true,
empty: false,
visible: true
visible: true,

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

super( position, dragBounds );

// @public
this.soluteProperty = new Property( solute );
this.visibleProperty = new BooleanProperty( options.visible );
this.dispensingProperty = new BooleanProperty( options.dispensing );
this.enabledProperty = new BooleanProperty( options.enabled );
this.emptyProperty = new BooleanProperty( options.empty );
this.flowRateProperty = new NumberProperty( options.flowRate ); // L/sec
this.soluteProperty = new Property( solute, {
//TODO #92 tandem
} );

// @public
//TODO #92 this should interruptSubtreeInput
this.visibleProperty = new BooleanProperty( options.visible, {
tandem: options.tandem.createTandem( 'visibleProperty' )
} );

// @public
this.dispensingProperty = new BooleanProperty( options.dispensing, {
tandem: options.tandem.createTandem( 'dispensingProperty' ),
phetioReadOnly: true
} );

// @public
this.enabledProperty = new BooleanProperty( options.enabled, {
tandem: options.tandem.createTandem( 'enabledProperty' ),
phetioReadOnly: true
} );

// @public
this.emptyProperty = new BooleanProperty( options.empty, {
tandem: options.tandem.createTandem( 'emptyProperty' ),
phetioReadOnly: true
} );

// @public
this.flowRateProperty = new NumberProperty( options.flowRate, {
//TODO #93 this is exceeded by MacroModel.startAutoFill range: new Range( 0, options.maxFlowRate ),
units: 'L/s',
tandem: options.tandem.createTandem( 'flowRateProperty' ),
phetioReadOnly: true
} ); // L/sec

// Turn off the dropper when it's disabled.
this.enabledProperty.link( enabled => {
Expand Down
23 changes: 20 additions & 3 deletions js/common/model/Faucet.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ define( require => {
const merge = require( 'PHET_CORE/merge' );
const NumberProperty = require( 'AXON/NumberProperty' );
const phScale = require( 'PH_SCALE/phScale' );
const Range = require( 'DOT/Range' );
const Tandem = require( 'TANDEM/Tandem' );

class Faucet {

Expand All @@ -29,16 +31,31 @@ define( require => {
spoutWidth: 45, // pixels
maxFlowRate: 0.25, // L/sec
flowRate: 0,
enabled: true
enabled: true,

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

// @public
this.position = position;
this.pipeMinX = pipeMinX;
this.spoutWidth = options.spoutWidth;
this.maxFlowRate = options.maxFlowRate;
this.flowRateProperty = new NumberProperty( options.flowRate );
this.enabledProperty = new BooleanProperty( options.enabled );

// @public
this.flowRateProperty = new NumberProperty( options.flowRate, {
range: new Range( 0, options.maxFlowRate ),
units: 'L/s',
tandem: options.tandem.createTandem( 'flowRateProperty' ),
phetioReadOnly: true
} );

// @public
this.enabledProperty = new BooleanProperty( options.enabled, {
tandem: options.tandem.createTandem( 'enabledProperty' ),
phetioReadOnly: true
} );

// when disabled, turn off the faucet.
this.enabledProperty.link( enabled => {
Expand Down
19 changes: 16 additions & 3 deletions js/common/model/Movable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,32 @@ define( require => {
'use strict';

// modules
const merge = require( 'PHET_CORE/merge' );
const phScale = require( 'PH_SCALE/phScale' );
const Property = require( 'AXON/Property' );
const Tandem = require( 'TANDEM/Tandem' );
const Vector2Property = require( 'DOT/Vector2Property' );

class Movable {

/**
* @param {Vector2} position
* @param {Bounds2} dragBounds optional, undefined if not provided
* @param {Object} [options]
*/
constructor( position, dragBounds ) {
constructor( position, dragBounds, options ) {

options = merge( {

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

// @public
this.positionProperty = new Vector2Property( position, {
tandem: options.tandem.createTandem( 'positionProperty' )
} );

// @public
this.positionProperty = new Property( position );
this.dragBounds = dragBounds;
}

Expand Down
40 changes: 28 additions & 12 deletions js/macro/model/MacroModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,57 @@ define( require => {
];

// @public Beaker, everything else is positioned relative to it. Offset constants were set by visual inspection.
//TODO #92 is there any reason to instrument the Beaker model?
this.beaker = new Beaker( new Vector2( 750, 580 ), new Dimension2( 450, 300 ) );

// Dropper above the beaker
const yDropper = this.beaker.position.y - this.beaker.size.height - 15;
// @public
this.dropper = new Dropper( Solute.WATER,
new Vector2( this.beaker.position.x - 50, yDropper ),
new Bounds2( this.beaker.left + 40, yDropper, this.beaker.right - 200, yDropper ) );
new Bounds2( this.beaker.left + 40, yDropper, this.beaker.right - 200, yDropper ), {
tandem: tandem.createTandem( 'dropper' )
} );

// @public Solution in the beaker
this.solution = new Solution( this.dropper.soluteProperty, 0, 0, this.beaker.volume );

// @public Water faucet at the beaker's top-right
this.waterFaucet = new Faucet( new Vector2( this.beaker.right - 50, this.beaker.position.y - this.beaker.size.height - 45 ),
this.beaker.right + 400,
{ enabled: this.solution.volumeProperty.get() < this.beaker.volume } );
this.waterFaucet = new Faucet(
new Vector2( this.beaker.right - 50, this.beaker.position.y - this.beaker.size.height - 45 ),
this.beaker.right + 400, {
enabled: this.solution.volumeProperty.get() < this.beaker.volume,
tandem: tandem.createTandem( 'waterFaucet' )
} );

// @public Drain faucet at the beaker's bottom-left.
this.drainFaucet = new Faucet( new Vector2( this.beaker.left - 75, this.beaker.position.y + 43 ), this.beaker.left,
{ enabled: this.solution.volumeProperty.get() > 0 } );

// pH meter to the left of the drain faucet
this.drainFaucet = new Faucet(
new Vector2( this.beaker.left - 75, this.beaker.position.y + 43 ),
this.beaker.left, {
enabled: this.solution.volumeProperty.get() > 0,
tandem: tandem.createTandem( 'drainFaucet' )
} );

// @public pH meter to the left of the drain faucet
const pHMeterPosition = new Vector2( this.drainFaucet.position.x - 300, 75 );
this.pHMeter = new PHMeter( pHMeterPosition, new Vector2( pHMeterPosition.x + 150, this.beaker.position.y ),
PHScaleConstants.SCREEN_VIEW_OPTIONS.layoutBounds );
this.pHMeter = new PHMeter(
pHMeterPosition,
new Vector2( pHMeterPosition.x + 150, this.beaker.position.y ),
PHScaleConstants.SCREEN_VIEW_OPTIONS.layoutBounds, {
tandem: tandem.createTandem( 'pHMeter' )
} );

// auto-fill when the solute changes
this.autoFillVolume = options.autoFillVolume; // @private
// @private auto-fill when the solute changes
this.autoFillVolume = options.autoFillVolume;

// @public (read-only)
//TODO #92 any reason to instrument this?
this.isAutoFillingProperty = new BooleanProperty( false );

this.dropper.soluteProperty.link( () => {

// disable the faucets to cancel any multi-touch interaction that may be in progress, see issue #28
//TODO #92 this might be handled better via interruptSubtreeInput
this.waterFaucet.enabledProperty.set( false );
this.drainFaucet.enabledProperty.set( false );

Expand Down
32 changes: 28 additions & 4 deletions js/macro/model/PHMeter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,45 @@ define( require => {
'use strict';

// modules
const merge = require( 'PHET_CORE/merge' );
const Movable = require( 'PH_SCALE/common/model/Movable' );
const NullableIO = require( 'TANDEM/types/NullableIO' );
const NumberIO = require( 'TANDEM/types/NumberIO' );
const phScale = require( 'PH_SCALE/phScale' );
const Property = require( 'AXON/Property' );
const PropertyIO = require( 'AXON/PropertyIO' );
const Tandem = require( 'TANDEM/Tandem' );

class PHMeter {

/**
* @param {Vector2} bodyPosition
* @param {Vector2} probePosition
* @param {Bounds2} probeDragBounds
* @param {Object} [options]
*/
constructor( bodyPosition, probePosition, probeDragBounds ) {
this.valueProperty = new Property( null ); // @public null if the meter is not reading a value
this.bodyPosition = bodyPosition; // @public
this.probe = new Movable( probePosition, probeDragBounds ); // @public
constructor( bodyPosition, probePosition, probeDragBounds, options ) {

options = merge( {

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

// @public null if the meter is not reading a value
this.valueProperty = new Property( null, {
tandem: options.tandem.createTandem( 'valueProperty' ),
phetioType: PropertyIO( NullableIO( NumberIO ) ),
phetioReadOnly: true
} );

// @public
this.bodyPosition = bodyPosition;

// @public
this.probe = new Movable( probePosition, probeDragBounds, {
tandem: options.tandem.createTandem( 'probe' )
} );
}

/**
Expand Down
Loading

0 comments on commit a8b8e50

Please sign in to comment.