Skip to content

Commit

Permalink
Revert "Convert ElectricPotentialLineIO to use PhetioObject.createIOT…
Browse files Browse the repository at this point in the history
…ype, see phetsims/tandem#188"

This reverts commit 27fded7
  • Loading branch information
samreid committed Sep 11, 2020
1 parent 240d6d4 commit 8130f6e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 37 deletions.
3 changes: 2 additions & 1 deletion js/charges-and-fields/model/ChargesAndFieldsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 )
} );

//----------------------------------------------------------------------------------------
Expand Down
38 changes: 2 additions & 36 deletions js/charges-and-fields/model/ElectricPotentialLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +34,7 @@ class ElectricPotentialLine extends PhetioObject {

super( {
tandem: tandem,
phetioType: ElectricPotentialLine.ElectricPotentialLineIO,
phetioType: ElectricPotentialLineIO,
phetioDynamicElement: true
} );

Expand Down Expand Up @@ -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;
45 changes: 45 additions & 0 deletions js/charges-and-fields/model/ElectricPotentialLineIO.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 8130f6e

Please sign in to comment.