<commit_before>// Copyright 2014-2015, University of Colorado Boulder

/**
 * Scenery Node that is used to represent thermometers in the tool box and that
 * controls the initial movement of thermometers in and out of the tool
 * box.
 *
 * @author <NAME>
 */
define( function( require ) {
  'use strict';

  var EFACConstants = require( 'ENERGY_FORMS_AND_CHANGES/common/EFACConstants' );
  var inherit = require( 'PHET_CORE/inherit' );
  var ScreenView = require( 'JOIST/ScreenView' );
  var SimpleDragHandler = require( 'SCENERY/input/SimpleDragHandler' );
  var ThermometerNode = require( 'ENERGY_FORMS_AND_CHANGES/intro/view/ThermometerNode' );

  /**
   *
   * @param {ThermometerNode} thermometerNode
   * @param {ModelViewTransform2} modelViewTransform
   * @constructor
   */
  function ThermometerToolBoxNode( thermometerNode, modelViewTransform ) {
    ThermometerNode.call( this );
    var self = this;
    this.modelViewTransform = modelViewTransform;
    // getThermometer is defined in  sensing Thermometer Node
    var thermometer = thermometerNode.getThermometer();
    //var positioningOffset = modelViewTransform.viewToModelDelta( thermometerNode.getOffsetCenterShaftToTriangleTip() );
    this.setSensedTemperature( EFACConstants.ROOM_TEMPERATURE );
    this.setSensedColor( 'white' );
    // This node's visibility is the inverse of the thermometer's.

    thermometer.activeProperty.link( function( active ) {
      self.visible = !active;
    } );

    this.addInputListener( new SimpleDragHandler( {

      parentScreen: null, // needed for coordinate transforms
      // Allow moving a finger (touch) across a node to pick it up.
      allowTouchSnag: true,

      start: function( event, trail ) {
        thermometer.userControlled = true;
        thermometer.active = true;

        // Find the parent screen by moving up the scene graph.
        var testNode = self;
        while ( testNode !== null ) {
          if ( testNode instanceof ScreenView ) {
            this.parentScreen = testNode;
            break;
          }
          testNode = testNode.parents[ 0 ]; // Move up the scene graph by one level
        }

        // Determine the initial position of the new element as a function of the event position and this node's bounds.
        var triangleTipGlobal = self.parentToGlobalPoint( self.rightCenter.plus( thermometerNode.getOffsetCenterShaftToTriangleTip() ) );
        var initialPosition = this.parentScreen.globalToLocalPoint( triangleTipGlobal );

        thermometer.position = modelViewTransform.viewToModelPosition( initialPosition );

      },
      // Handler that moves the shape in model space.
      translate: function( translationParams ) {<commit_msg>implemented some suggested improvements to leveraged code that locates the parent screen view in creator nodes, see https://github.com/phetsims/scenery-phet/issues/214 and https://github.com/phetsims/area-builder/issues/83.<commit_after>// Copyright 2014-2015, University of Colorado Boulder

/**
 * Scenery Node that is used to represent thermometers in the tool box and that
 * controls the initial movement of thermometers in and out of the tool
 * box.
 *
 * @author <NAME>
 */
define( function( require ) {
  'use strict';

  var EFACConstants = require( 'ENERGY_FORMS_AND_CHANGES/common/EFACConstants' );
  var inherit = require( 'PHET_CORE/inherit' );
  var ScreenView = require( 'JOIST/ScreenView' );
  var SimpleDragHandler = require( 'SCENERY/input/SimpleDragHandler' );
  var ThermometerNode = require( 'ENERGY_FORMS_AND_CHANGES/intro/view/ThermometerNode' );

  /**
   *
   * @param {ThermometerNode} thermometerNode
   * @param {ModelViewTransform2} modelViewTransform
   * @constructor
   */
  function ThermometerToolBoxNode( thermometerNode, modelViewTransform ) {
    ThermometerNode.call( this );
    var self = this;
    this.modelViewTransform = modelViewTransform;
    // getThermometer is defined in  sensing Thermometer Node
    var thermometer = thermometerNode.getThermometer();
    //var positioningOffset = modelViewTransform.viewToModelDelta( thermometerNode.getOffsetCenterShaftToTriangleTip() );
    this.setSensedTemperature( EFACConstants.ROOM_TEMPERATURE );
    this.setSensedColor( 'white' );
    // This node's visibility is the inverse of the thermometer's.

    thermometer.activeProperty.link( function( active ) {
      self.visible = !active;
    } );

    this.addInputListener( new SimpleDragHandler( {

      parentScreenView: null, // needed for coordinate transforms

      // Allow moving a finger (touch) across a node to pick it up.
      allowTouchSnag: true,

      start: function( event, trail ) {
        thermometer.userControlled = true;
        thermometer.active = true;

        if ( !this.parentScreenView ) {

          // find the parent screen view by moving up the scene graph
          var testNode = self;
          while ( testNode !== null ) {
            if ( testNode instanceof ScreenView ) {
              this.parentScreenView = testNode;
              break;
            }
            testNode = testNode.parents[ 0 ]; // move up the scene graph by one level
          }
          assert && assert( this.parentScreenView, 'unable to find parent screen view' );
        }

        // Determine the initial position of the new element as a function of the event position and this node's bounds.
        var triangleTipGlobal = self.parentToGlobalPoint( self.rightCenter.plus( thermometerNode.getOffsetCenterShaftToTriangleTip() ) );
        var initialPosition = this.parentScreenView.globalToLocalPoint( triangleTipGlobal );

        thermometer.position = modelViewTransform.viewToModelPosition( initialPosition );
      },

      // Handler that moves the shape in model space.
      translate: function( translationParams ) {
{'fraction_non_alphanumeric': 0.08565531475748193, 'fraction_numerical': 0.004299965600275198, 'mean_word_length': 3.2321688500727803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1068850', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1558, 'n_words': 467}