Skip to content

Commit

Permalink
Add lab screen
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Oct 21, 2019
1 parent f5a981f commit bc98d64
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 8 deletions.
3 changes: 3 additions & 0 deletions circuit-construction-kit-ac-strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
},
"screen.rlc": {
"value": "RLC"
},
"screen.lab": {
"value": "Lab"
}
}
4 changes: 2 additions & 2 deletions js/ac-voltage/ACVoltageScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ define( require => {
'use strict';

// modules
const ACVoltageModel = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/ac-voltage/model/ACVoltageModel' );
const ACVoltageScreenView = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/ac-voltage/view/ACVoltageScreenView' );
const CCKCConstants = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/CCKCConstants' );
const circuitConstructionKitAc = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuitConstructionKitAc' );
const Image = require( 'SCENERY/nodes/Image' );
const ACVoltageModel = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/ac-voltage/model/ACVoltageModel' );
const ACVoltageScreenView = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/ac-voltage/view/ACVoltageScreenView' );
const Property = require( 'AXON/Property' );
const Rectangle = require( 'SCENERY/nodes/Rectangle' );
const Screen = require( 'JOIST/Screen' );
Expand Down
10 changes: 6 additions & 4 deletions js/circuit-construction-kit-ac-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ define( require => {

// modules
const ACVoltageScreen = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/ac-voltage/ACVoltageScreen' );
const capacitor = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuits/capacitor' );
const CCKACQueryParameters = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/CCKACQueryParameters' );
const LabScreen = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/lab/LabScreen' );
const RLCScreen = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/rlc/RLCScreen' );
const shortBattery = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuits/shortBattery' );
const shortBatterySideBulb = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuits/shortBatterySideBulb' );
const Sim = require( 'JOIST/Sim' );
const SimLauncher = require( 'JOIST/SimLauncher' );
const Tandem = require( 'TANDEM/Tandem' );
const capacitor = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuits/capacitor' );
const shortBattery = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuits/shortBattery' );
const shortBatterySideBulb = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuits/shortBatterySideBulb' );

// strings
const circuitConstructionKitAcTitleString = require( 'string!CIRCUIT_CONSTRUCTION_KIT_AC/circuit-construction-kit-ac.title' );
Expand All @@ -44,7 +45,8 @@ define( require => {
SimLauncher.launch( () => {
const sim = new Sim( circuitConstructionKitAcTitleString, [
new ACVoltageScreen( tandem.createTandem( 'acVoltageScreen' ) ),
new RLCScreen( tandem.createTandem( 'rlcScreen' ) )
new RLCScreen( tandem.createTandem( 'rlcScreen' ) ),
new LabScreen( tandem.createTandem( 'labScreen' ) )
], simOptions );

// For debugging, load the specified circuit, saved from PhET-iO state wrapper
Expand Down
72 changes: 72 additions & 0 deletions js/lab/LabScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2019, University of Colorado Boulder

/**
* The "Lab" screen.
*
* @author Sam Reid (PhET Interactive Simulations)
*/
define( require => {
'use strict';

// modules
const CCKCConstants = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/CCKCConstants' );
const circuitConstructionKitAc = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuitConstructionKitAc' );
const Image = require( 'SCENERY/nodes/Image' );
const LabModel = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/lab/model/LabModel' );
const LabScreenView = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/lab/view/LabScreenView' );
const Property = require( 'AXON/Property' );
const Rectangle = require( 'SCENERY/nodes/Rectangle' );
const Screen = require( 'JOIST/Screen' );

// strings
const screenLabString = require( 'string!CIRCUIT_CONSTRUCTION_KIT_AC/screen.lab' ); // eslint-disable-line

// images
const lightBulbImage = require( 'mipmap!CIRCUIT_CONSTRUCTION_KIT_COMMON/lightbulb-middle.png' );
const lightBulbImageIcon = require( 'mipmap!CIRCUIT_CONSTRUCTION_KIT_COMMON/lightbulb-middle-icon.png' );

class LabScreen extends Screen {

/**
* @param {Tandem} tandem
*/
constructor( tandem ) {

// Create the icon
const homeScreenIcon = Rectangle.dimension( Screen.MINIMUM_HOME_SCREEN_ICON_SIZE, {
fill: CCKCConstants.BACKGROUND_COLOR
} );
homeScreenIcon.addChild( new Image( lightBulbImage, {
scale: 0.95,
center: homeScreenIcon.center
} ) );

// Render a smaller icon for Edge because it is aliasing the image (even with mipmap on)
// see https://github.com/phetsims/circuit-construction-kit-dc/issues/120
const navigationBarIcon = Rectangle.dimension( Screen.MINIMUM_NAVBAR_ICON_SIZE, {
fill: CCKCConstants.BACKGROUND_COLOR
} );
navigationBarIcon.addChild( new Image( lightBulbImageIcon, {
scale: 1.05,
center: navigationBarIcon.center
} ) );

const options = {
name: screenLabString,
backgroundColorProperty: new Property( CCKCConstants.BACKGROUND_COLOR ),
homeScreenIcon: homeScreenIcon,
navigationBarIcon: navigationBarIcon,
tandem: tandem,
maxDT: CCKCConstants.MAX_DT
};

super(
() => new LabModel( tandem.createTandem( 'model' ) ),
model => new LabScreenView( model, tandem.createTandem( 'view' ) ),
options
);
}
}

return circuitConstructionKitAc.register( 'LabScreen', LabScreen );
} );
33 changes: 33 additions & 0 deletions js/lab/model/LabModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2019, University of Colorado Boulder

/**
* Model for the Lab Screen.
*
* @author Sam Reid (PhET Interactive Simulations)
*/
define( require => {
'use strict';

// modules
const BooleanProperty = require( 'AXON/BooleanProperty' );
const circuitConstructionKitAc = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuitConstructionKitAc' );
const CircuitConstructionKitModel = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/model/CircuitConstructionKitModel' );

class LabModel extends CircuitConstructionKitModel {

/**
* @param {Tandem} tandem
* @constructor
*/
constructor( tandem ) {
super( tandem );

// @public {Property.<boolean>} - true if the stopwatch should be shown in the play area
this.showStopwatchProperty = new BooleanProperty( false, {
tandem: tandem.createTandem( 'showStopwatchProperty' )
} );
}
}

return circuitConstructionKitAc.register( 'LabModel', LabModel );
} );
72 changes: 72 additions & 0 deletions js/lab/view/LabScreenView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2019, University of Colorado Boulder

/**
* The view for the Lab screen.
*
* @author Sam Reid (PhET Interactive Simulations)
*/
define( require => {
'use strict';

// modules
const BooleanProperty = require( 'AXON/BooleanProperty' );
const CCKCScreenView = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/view/CCKCScreenView' );
const circuitConstructionKitAc = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuitConstructionKitAc' );
const CircuitElementToolFactory = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/view/CircuitElementToolFactory' );
const NumberProperty = require( 'AXON/NumberProperty' );
const TimerNode = require( 'SCENERY_PHET/TimerNode' );

class LabScreenView extends CCKCScreenView {

/**
* @param {LabModel} model
* @param {Tandem} tandem
*/
constructor( model, tandem ) {
const circuitElementToolFactory = new CircuitElementToolFactory( model.circuit, model.showLabelsProperty, model.viewTypeProperty,
point => this.circuitLayerNode.globalToLocalPoint( point ) );

// Tool nodes that appear on every screen. Pagination for the carousel, each page should begin with wire node
const circuitElementToolNodes = [

// This page is duplicated in the Lab Screen View
circuitElementToolFactory.createWireToolNode( 25, tandem.createTandem( 'wireToolNode' ) ),
circuitElementToolFactory.createRightBatteryToolNode( 10, tandem.createTandem( 'rightBatteryToolNode' ) ),
circuitElementToolFactory.createACVoltageToolNode( 10, tandem.createTandem( 'rightBatteryToolNode' ) ),
circuitElementToolFactory.createLightBulbToolNode( 10, tandem.createTandem( 'lightBulbToolNode' ) ),
circuitElementToolFactory.createResistorToolNode( 10, tandem.createTandem( 'resistorToolNode' ) ),
circuitElementToolFactory.createCapacitorToolNode( 10, tandem.createTandem( 'capacitorToolNode' ) ),
circuitElementToolFactory.createInductorToolNode( 10, tandem.createTandem( 'inductorToolNode' ) ),
circuitElementToolFactory.createSwitchToolNode( 5, tandem.createTandem( 'switchToolNode' ) )
];

super( model, circuitElementToolNodes, tandem, {
toolboxOrientation: 'vertical', // The toolbox should be vertical
showResetAllButton: true, // The reset all button should be shown.
showResistivityControl: false,
showBatteryResistanceControl: false,
showCharts: true,
itemsPerPage: circuitElementToolNodes.length,
pageHeight: 400,
hideDisabledButtons: true
} );

// @public - the TimerNode
// TODO: consider generalizing Stopwatch and StopwatchNode from gas-properties
const timerNodeTandem = tandem.createTandem( 'timerNode' );
this.timerNode = new TimerNode( new NumberProperty( 0 ), new BooleanProperty( false, {
tandem: timerNodeTandem.createTandem( 'isRunningProperty' )
} ), {
tandem: timerNodeTandem
} );
this.addChild( this.timerNode );

// Show the TimerNode when the checkbox is checked
model.showStopwatchProperty.link( showStopwatch => {
this.timerNode.visible = showStopwatch;
} );
}
}

return circuitConstructionKitAc.register( 'LabScreenView', LabScreenView );
} );
4 changes: 2 additions & 2 deletions js/rlc/RLCScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ define( require => {
const CCKCConstants = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/CCKCConstants' );
const circuitConstructionKitAc = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/circuitConstructionKitAc' );
const Image = require( 'SCENERY/nodes/Image' );
const RLCModel = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/rlc/model/RLCModel' );
const RLCScreenView = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/rlc/view/RLCScreenView' );
const Property = require( 'AXON/Property' );
const Rectangle = require( 'SCENERY/nodes/Rectangle' );
const RLCModel = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/rlc/model/RLCModel' );
const RLCScreenView = require( 'CIRCUIT_CONSTRUCTION_KIT_AC/rlc/view/RLCScreenView' );
const Screen = require( 'JOIST/Screen' );

// strings
Expand Down

0 comments on commit bc98d64

Please sign in to comment.