diff --git a/js/charges-and-fields/model/ChargesAndFieldsModel.js b/js/charges-and-fields/model/ChargesAndFieldsModel.js index dec996d8..2c7dde9a 100644 --- a/js/charges-and-fields/model/ChargesAndFieldsModel.js +++ b/js/charges-and-fields/model/ChargesAndFieldsModel.js @@ -23,6 +23,7 @@ import ChargesAndFieldsConstants from '../ChargesAndFieldsConstants.js'; import ChargedParticle from './ChargedParticle.js'; import ElectricFieldSensor from './ElectricFieldSensor.js'; import ElectricPotentialLine from './ElectricPotentialLine.js'; +import ElectricPotentialLineIO from './ElectricPotentialLineIO.js'; import ElectricPotentialSensor from './ElectricPotentialSensor.js'; import MeasuringTape from './MeasuringTape.js'; import ModelElement from './ModelElement.js'; @@ -176,7 +177,7 @@ class ChargesAndFieldsModel extends PhetioObject { return new ElectricPotentialLine( this, position, tandem ); }, [ this.electricPotentialSensor.positionProperty.get() ], { tandem: tandem.createTandem( 'electricPotentialLineGroup' ), - phetioType: PhetioGroupIO( ElectricPotentialLine.ElectricPotentialLineIO ) + phetioType: PhetioGroupIO( ElectricPotentialLineIO ) } ); //---------------------------------------------------------------------------------------- diff --git a/js/charges-and-fields/model/ElectricPotentialLine.js b/js/charges-and-fields/model/ElectricPotentialLine.js index 69e804c3..86281638 100644 --- a/js/charges-and-fields/model/ElectricPotentialLine.js +++ b/js/charges-and-fields/model/ElectricPotentialLine.js @@ -9,13 +9,12 @@ import Emitter from '../../../../axon/js/Emitter.js'; import dot from '../../../../dot/js/dot.js'; import Vector2 from '../../../../dot/js/Vector2.js'; -import Vector2IO from '../../../../dot/js/Vector2IO.js'; import Vector2Property from '../../../../dot/js/Vector2Property.js'; import Shape from '../../../../kite/js/Shape.js'; import merge from '../../../../phet-core/js/merge.js'; import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import chargesAndFields from '../../chargesAndFields.js'; -import ModelElement from './ModelElement.js'; +import ElectricPotentialLineIO from './ElectricPotentialLineIO.js'; // constants // see getEquipotentialPositionArray to find how these are used @@ -35,7 +34,7 @@ class ElectricPotentialLine extends PhetioObject { super( { tandem: tandem, - phetioType: ElectricPotentialLine.ElectricPotentialLineIO, + phetioType: ElectricPotentialLineIO, phetioDynamicElement: true } ); @@ -416,40 +415,7 @@ class ElectricPotentialLine extends PhetioObject { } return shape; } - - /** - * @public - * @returns {Object} - * @override - */ - toStateObject() { - return { position: Vector2IO.toStateObject( this.position ) }; - } - - // @private: just used for applyState - static fromStateObject( stateObject ) { - return { position: Vector2IO.fromStateObject( stateObject.position ) }; - } - - // @public - applyState( stateObject ) { - this.position = ElectricPotentialLine.fromStateObject( stateObject ).position; - } - - /** - * @public - * @override - * @param {Object} stateObject - * @returns {Array.<*>} - */ - static stateToArgsForConstructor( stateObject ) { - return [ Vector2IO.fromStateObject( stateObject.position ) ]; - } } -ElectricPotentialLine.ElectricPotentialLineIO = PhetioObject.createIOType( ElectricPotentialLine, 'ElectricPotentialLineIO', ModelElement.ModelElementIO, { - documentation: 'The vector that shows the charge strength and direction.' -} ); - chargesAndFields.register( 'ElectricPotentialLine', ElectricPotentialLine ); export default ElectricPotentialLine; diff --git a/js/charges-and-fields/model/ElectricPotentialLineIO.js b/js/charges-and-fields/model/ElectricPotentialLineIO.js new file mode 100644 index 00000000..b7a80bb6 --- /dev/null +++ b/js/charges-and-fields/model/ElectricPotentialLineIO.js @@ -0,0 +1,45 @@ +// Copyright 2017-2020, University of Colorado Boulder + +/** + * IO type for ElectricPotentialLine + * + * @author Sam Reid (PhET Interactive Simulations) + */ + +import validate from '../../../../axon/js/validate.js'; +import Vector2IO from '../../../../dot/js/Vector2IO.js'; +import ObjectIO from '../../../../tandem/js/types/ObjectIO.js'; +import chargesAndFields from '../../chargesAndFields.js'; +import ModelElement from './ModelElement.js'; + +class ElectricPotentialLineIO extends ModelElement.ModelElementIO { + + /** + * @public + * @param {ElectricPotentialLine} electricPotentialLine + * @returns {Object} + * @override + */ + static toStateObject( electricPotentialLine ) { + validate( electricPotentialLine, this.validator ); + return { position: Vector2IO.toStateObject( electricPotentialLine.position ) }; + } + + /** + * @public + * @override + * @param {Object} stateObject + * @returns {Array.<*>} + */ + static stateToArgsForConstructor( stateObject ) { + return [ Vector2IO.fromStateObject( stateObject.position ) ]; + } +} + +ElectricPotentialLineIO.documentation = 'The vector that shows the charge strength and direction.'; +ElectricPotentialLineIO.validator = { isValidValue: v => v instanceof phet.chargesAndFields.ElectricPotentialLine }; +ElectricPotentialLineIO.typeName = 'ElectricPotentialLineIO'; +ObjectIO.validateSubtype( ElectricPotentialLineIO ); + +chargesAndFields.register( 'ElectricPotentialLineIO', ElectricPotentialLineIO ); +export default ElectricPotentialLineIO; \ No newline at end of file