Measures/m_5_example_5_computed_schedule/resources/util.rb
# Returns true if the material was assigned
Returns true if the material was assigned
Returns true if the material was assigned
def assign_material(constr, material, surface, remove_non_std_layers, runner)
            if not surface.respond_to?("surfaceType")
                remove_material(constr, material.name.to_s, runner)
                constr.insertLayer(constr.numLayers, material)
                return true
            end
            num_layers = constr.numLayers
            if surface.surfaceType.downcase == "wall" 
                target_positions_std = {Constants.MaterialWallExtFinish => 0, 
                                        Constants.MaterialWallRigidIns => 1,
                                        Constants.MaterialWallSheathing => 2, 
                                        Constants.MaterialWallMassOtherSide2 => 3,
                                        Constants.MaterialWallMassOtherSide => 4,
                                        Constants.MaterialWallMass => [num_layers,6].max,
                                        Constants.MaterialWallMass2 => [num_layers+1,7].max} 
                target_position_non_std = target_positions_std[Constants.MaterialWallMassOtherSide] + 1
            elsif surface.surfaceType.downcase == "roofceiling" and surface.outsideBoundaryCondition.downcase == "outdoors" 
                target_positions_std = {Constants.MaterialRoofMaterial => 0, 
                                        Constants.MaterialRoofRigidIns => 1,
                                        Constants.MaterialRoofSheathing => 2,
                                        Constants.MaterialRadiantBarrier => [num_layers,4].max,
                                        Constants.MaterialCeilingMass => [num_layers+1,5].max,
                                        Constants.MaterialCeilingMass2 => [num_layers+2,6].max} 
                target_position_non_std = target_positions_std[Constants.MaterialRoofSheathing] + 1
            elsif surface.surfaceType.downcase == "floor" 
                target_positions_std = {Constants.MaterialCeilingMass2 => 0, 
                                        Constants.MaterialCeilingMass => 1,
                                        Constants.MaterialFloorRigidIns => [num_layers,3].max,
                                        Constants.MaterialFloorSheathing => [num_layers+1,4].max,
                                        Constants.MaterialFloorMass => [num_layers+2,5].max,
                                        Constants.MaterialFloorCovering => [num_layers+3,6].max} 
                target_position_non_std = target_positions_std[Constants.MaterialCeilingMass] + 1
            elsif surface.surfaceType.downcase == "roofceiling" 
                target_positions_std = {Constants.MaterialFloorCovering => 0, 
                                        Constants.MaterialFloorMass => 1,
                                        Constants.MaterialFloorSheathing => 2,
                                        Constants.MaterialFloorRigidIns => 3,
                                        Constants.MaterialCeilingMass => [num_layers,5].max,
                                        Constants.MaterialCeilingMass2 => [num_layers+1,6].max} 
                target_position_non_std = target_positions_std[Constants.MaterialFloorRigidIns] + 1
            else
                runner.registeError("Unexpected surface type '#{surface.surfaceType.to_s}'.")
            end
            std_mat_positions = target_positions_std.clone
            std_mat_positions.each { |k, v| std_mat_positions[k] = nil } 
            max_non_std_position = nil
            constr.layers.each_with_index do |layer, index|
                layer_is_std = false
                std_mat_positions.keys.each do |layer_name|
                    if layer.name.to_s.start_with? layer_name
                        std_mat_positions[layer_name] = index
                        layer_is_std = true
                    end
                end
                if not layer_is_std
                    max_non_std_position = index
                end
            end
            standard_mat = nil
            target_positions_std.keys.each do |std_mat|
                if material.name.to_s.start_with? std_mat
                    standard_mat = std_mat
                end
            end
            if remove_non_std_layers and standard_mat.nil?
                constr.layers.reverse.each_with_index do |layer, index|
                    layer_index = num_layers - 1 - index
                    if not std_mat_positions.values.include? layer_index
                        constr.eraseLayer(layer_index)
                    end
                end
            end
            if not standard_mat.nil? and not std_mat_positions[standard_mat].nil?
                constr.setLayer(std_mat_positions[standard_mat], material)
            else
                if standard_mat.nil?
                    final_pos = target_position_non_std
                else
                    final_pos = target_positions_std[standard_mat]
                end
                insert_pos = 0
                for pos in (final_pos-1).downto(0)
                    mat = target_positions_std.key(pos)
                    next if not std_mat_positions.key? mat
                    if not std_mat_positions[mat].nil?
                        insert_pos = std_mat_positions[mat] + 1
                        if not standard_mat.nil? and not max_non_std_position.nil?
                            if target_positions_std[standard_mat] > target_position_non_std and insert_pos <= max_non_std_position
                                insert_pos = max_non_std_position + 1
                            end
                        end
                        break
                    end
                end
                if insert_pos > constr.numLayers
                    insert_pos = constr.numLayers
                end
                constr.insertLayer(insert_pos, material)
            end
            return true
        end
def assign_material ( constr , material , surface , remove_non_std_layers , runner ) if not surface . respond_to? ( "surfaceType" ) remove_material ( constr , material . name . to_s , runner ) constr . insertLayer ( constr . numLayers , material ) return true end num_layers = constr . numLayers if surface . surfaceType . downcase == "wall" target_positions_std = { Constants . MaterialWallExtFinish => 0 , Constants . MaterialWallRigidIns => 1 , Constants . MaterialWallSheathing => 2 , Constants . MaterialWallMassOtherSide2 => 3 , Constants . MaterialWallMassOtherSide => 4 , Constants . MaterialWallMass => [ num_layers , 6 ] . max , Constants . MaterialWallMass2 => [ num_layers + 1 , 7 ] . max } target_position_non_std = target_positions_std [ Constants . MaterialWallMassOtherSide ] + 1 elsif surface . surfaceType . downcase == "roofceiling" and surface . outsideBoundaryCondition . downcase == "outdoors" target_positions_std = { Constants . MaterialRoofMaterial => 0 , Constants . MaterialRoofRigidIns => 1 , Constants . MaterialRoofSheathing => 2 , Constants . MaterialRadiantBarrier => [ num_layers , 4 ] . max , Constants . MaterialCeilingMass => [ num_layers + 1 , 5 ] . max , Constants . MaterialCeilingMass2 => [ num_layers + 2 , 6 ] . max } target_position_non_std = target_positions_std [ Constants . MaterialRoofSheathing ] + 1 elsif surface . surfaceType . downcase == "floor" target_positions_std = { Constants . MaterialCeilingMass2 => 0 , Constants . MaterialCeilingMass => 1 , Constants . MaterialFloorRigidIns => [ num_layers , 3 ] . max , Constants . MaterialFloorSheathing => [ num_layers + 1 , 4 ] . max , Constants . MaterialFloorMass => [ num_layers + 2 , 5 ] . max , Constants . MaterialFloorCovering => [ num_layers + 3 , 6 ] . max } target_position_non_std = target_positions_std [ Constants . MaterialCeilingMass ] + 1 elsif surface . surfaceType . downcase == "roofceiling" target_positions_std = { Constants . MaterialFloorCovering => 0 , Constants . MaterialFloorMass => 1 , Constants . MaterialFloorSheathing => 2 , Constants . MaterialFloorRigidIns => 3 , Constants . MaterialCeilingMass => [ num_layers , 5 ] . max , Constants . MaterialCeilingMass2 => [ num_layers + 1 , 6 ] . max } target_position_non_std = target_positions_std [ Constants . MaterialFloorRigidIns ] + 1 else runner . registeError ( "Unexpected surface type '#{surface.surfaceType.to_s}'." ) end std_mat_positions = target_positions_std . clone std_mat_positions . each { | k , v | std_mat_positions [ k ] = nil } max_non_std_position = nil constr . layers . each_with_index do | layer , index | layer_is_std = false std_mat_positions . keys . each do | layer_name | if layer . name . to_s . start_with? layer_name std_mat_positions [ layer_name ] = index layer_is_std = true end end if not layer_is_std max_non_std_position = index end end standard_mat = nil target_positions_std . keys . each do | std_mat | if material . name . to_s . start_with? std_mat standard_mat = std_mat end end if remove_non_std_layers and standard_mat . nil? constr . layers . reverse . each_with_index do | layer , index | layer_index = num_layers - 1 - index if not std_mat_positions . values . include? layer_index constr . eraseLayer ( layer_index ) end end end if not standard_mat . nil? and not std_mat_positions [ standard_mat ] . nil? constr . setLayer ( std_mat_positions [ standard_mat ] , material ) else if standard_mat . nil? final_pos = target_position_non_std else final_pos = target_positions_std [ standard_mat ] end insert_pos = 0 for pos in ( final_pos - 1 ) . downto ( 0 ) mat = target_positions_std . key ( pos ) next if not std_mat_positions . key? mat if not std_mat_positions [ mat ] . nil? insert_pos = std_mat_positions [ mat ] + 1 if not standard_mat . nil? and not max_non_std_position . nil? if target_positions_std [ standard_mat ] > target_position_non_std and insert_pos <= max_non_std_position insert_pos = max_non_std_position + 1 end end break end end if insert_pos > constr . numLayers insert_pos = constr . numLayers end constr . insertLayer ( insert_pos , material ) end return true end
Returns true if the material was assigned
Returns true if the material was assigned
# Note: We determine types of layers (exterior finish, etc.) by name. # The code below defines the target layer positions for the materials when the  # construction is complete. # TODO: This is all a huge hack until we can use StandardsInfo to classify layers. # Wall # outside # non-std middle layer(s) => 5... # inside # Roof # outside # non-std middle layer(s) => 3... # inside # Floor # outside # non-std middle layer(s) => 2... # inside # Ceiling (must be reverse of floor) # outside # non-std middle layer(s) => 4... # inside # Determine current positions of any standard materials # Also, determine max position of any non-standard materials #re-init # Is the current material a standard material? # Remove any layers other than standard materials # Standard layer already exists, replace it # Add at appropriate position # Ensure we put std layer after non-std layer in this situation
constr
<not_specific>
material
<not_specific>
surface
<not_specific>
remove_non_std_layers
<not_specific>
runner
<not_specific>