Sha256: 7c4ca6d532b1a648fa7f3e20fa309472659cd5e09722c4ae10b1e9bfceea3e03

Contents?: true

Size: 1.8 KB

Versions: 4

Compression:

Stored size: 1.8 KB

Contents

# *******************************************************************************
# OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
# See also https://openstudio.net/license
# *******************************************************************************

class OpenStudio::Model::ModelObject
  # Convert object to a concrete class if possible
  # @return [Object, nil] returns nil if the object was already
  # of its concrete class, returns the object casted to its concrete
  # class if it was casted successfully.
  def cast_to_concrete_type
    # puts "Casting '#{name}' to concrete type from #{caller_locations(1,1)[0].label}"
    # Get the class type and the IDD object type
    comp_class = self.class.name.to_s.gsub('OpenStudio::Model::', '')
    comp_type = iddObject.type.valueDescription.gsub('OS:', '').delete(':')
    case comp_type
    when 'CoilCoolingLowTemperatureRadiantVariableFlow'
      comp_type = 'CoilCoolingLowTempRadiantVarFlow'
    when 'CoilHeatingLowTemperatureRadiantVariableFlow'
      comp_type = 'CoilHeatingLowTempRadiantVarFlow'
    when 'ZoneHVACLowTemperatureRadiantVariableFlow'
      comp_type = 'ZoneHVACLowTempRadiantVarFlow'
    end
    # If the class type and the IDD object type are identical,
    # this means that the object is already of the concrete class.
    if comp_class == comp_type
      # puts "INFO: #{name} of type #{comp_type} is already concrete"
      return nil
    end
    # Cast the object to its concrete class type
    cast_method = "to_#{comp_type}"
    if respond_to?(cast_method)
      return public_send(cast_method).get
    else
      puts "ERROR: #{name} of type #{comp_type} cannot be made concrete using #{cast_method}"
      # raise "ERROR: #{name} of type #{comp_type} cannot be made concrete using #{cast_method}"
      return nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
openstudio-common-measures-0.11.0 lib/measures/openstudio_results/resources/Siz.ModelObject.rb
openstudio-common-measures-0.10.0 lib/measures/openstudio_results/resources/Siz.ModelObject.rb
openstudio-common-measures-0.9.0 lib/measures/openstudio_results/resources/Siz.ModelObject.rb
openstudio-common-measures-0.8.0 lib/measures/openstudio_results/resources/Siz.ModelObject.rb