##  Hip_Roof_Geometry.py Version 1.00

##  Copyright (c) 2007 Bruce Vaughan, BV Detailing & Design, Inc.

##  All rights reserved.

##  NOT FOR SALE. The software is provided "as is" without any warranty.

########################################################################

"""

Calculate and display angles L1 through L10 as defined in "Hip and Valley Design"

by H. L. McKibben and L. E. Gray published in 1912

Developed in SDS/2 6.323, Python 2.2.1 (11/18/03)

Tested in SDS/2 7.002 (8/14/04)

Version 1.00 (11/18/07)

 

For comments, questions, or suggestions call Bruce Vaughan at (615) 646-9239,

email at bvdet@comcast.net, or post to the Detailing Forum

 

Definitions:

    The RAFTER is the hip or valley beam

    The PURLIN frames into the RAFTER, and is normal to the ROOF SLOPE

    L1 = Bevel on PURLIN WEB PLANE made by intersection of RAFTER WEB PLANE

    L2 = Bevel on ROOF PLANE made by intersection of RAFTER WEB PLANE

    L3 = Bevel on RAFTER WEB PLANE made by intersection of PURLIN WEB PLANE

    L4 = Bevel on RAFTER FLANGE PLANE made by intersection of PURLIN WEB PLANE

    L5 = Complement of angle between PURLIN WEB PLANE and RAFTER WEB PLANE (sum = 90)

    L6 = Complement of angle between PURLIN WEB PLANE and RAFTER FLANGE PLANE (sum = 90)

    L7 = Bevel on PURLIN WEB PLANE made by RAFTER FLANGE PLANE

    L8 = Angle between PURLIN WEB PLANE and a plane perpendicular to both

         RAFTER FLANGE PLANE and RAFTER WEB PLANE

    L9 = Bevel on a plane perpendicular to both RAFTER WEB PLANE and

         RAFTER FLANGE PLANE made by intersection of PURLIN WEB PLANE

    L10 = Angle between ROOF PLANE and RAFTER FLANGE PLANE (hip or valley angle)

    L11 = Bevel on RAFTER FLANGE PLANE made by a vertical section plane

          parallel to the ROOF SLOPE

 

"""

from param import *

from math import *

Units("feet")

 

import os

from job import JobName

from macrolib.FileDefaults import import_data, export_data

from macrolib.angle import rtod, dtor

 

def run_script():

    #####################################################################

    ## Variables section

    # system path for defaults file

    default_file_path = os.path.join(os.getcwd(), "macro", "Defaults")

 

    # defaults file name

    def_file = "Col_BntPLConn.txt"

 

    # Path to image files and file names

    image_path = os.path.join(os.getcwd(), "macro", "Images")

    image_name = os.path.join(image_path, "Hip_Roof_Geometry.gif")

    image_name1 = os.path.join(image_path, "Hip_Roof_L1.gif")

    image_name2 = os.path.join(image_path, "Hip_Roof_L2.gif")

    image_name3 = os.path.join(image_path, "Hip_Roof_L3.gif")

    image_name4 = os.path.join(image_path, "Hip_Roof_L4.gif")

    image_name5 = os.path.join(image_path, "Hip_Roof_L5.gif")

    image_name6 = os.path.join(image_path, "Hip_Roof_L6.gif")

    image_name7 = os.path.join(image_path, "Hip_Roof_L7.gif")

    image_name8 = os.path.join(image_path, "Hip_Roof_L8.gif")

    image_name9 = os.path.join(image_path, "Hip_Roof_L9.gif")

    image_name10 = os.path.join(image_path, "Hip_Roof_L10.gif")

    ########################################################################

    ## Defaults section

    roof_slope = 4

    hip_angle = 45.0

    roof_slope_angle = 0.0

    # ["Save to disc", "Print to screen"]

    save_or_print = "Save to disc"

    ########################################################################

 

    ## MAIN PROGRAM LOOP

    # Import default variables

    dd0 = import_data(os.path.join(default_file_path, def_file))

    if dd0:

        for key, value in dd0.items():

            exec "%s = %s" % (key, repr(value)) in None

       

    while True:

        dlg1 = Dialog("Calculate hip/valley roof plane angles")

        dlg1.menu("print_doc", ("Yes", "No"), "No", "Print documentation only")

        dlg1.tabset_begin()

       

        dlg1.tab("Input")

        dlg1.group_title("Roof Slope 'A' - SLOPE/12, Plan Angle 'B'")

        dlg1.line("RAFTER - hip or valley beam")

        dlg1.line("PURLIN - frames into the RAFTER - is normal to the ROOF SLOPE")

        dlg1.entry("roof_slope", dim_print(roof_slope), "Rise of roof with respect to 12                              ")

        dlg1.entry("hip_angle", hip_angle,              "Angle 'B' in degrees between roof slope and hip/valley rafter")

       

        dlg1.group_title("Roof Slope 'A' - DEGREES")

        dlg1.line("Calculate from rise entry above if 0 is entered")

        dlg1.entry("roof_slope_angle", roof_slope_angle, "Roof slope angle in degrees")

 

        dlg1.group_title("Data options")       

        dlg1.menu("save_or_print", ["Save to disc", "Print to screen"], save_or_print, "Print or save")

        dlg1.group_title("File name - Save to disc")

        dlg1.file_save('export_file', os.path.join(os.getcwd(), "jobs", JobName(), "macro", "RoofGeometry.txt"), "Enter file name or browse       ")

        dlg1.menu('write_or_append', ["Write", "Append"], "Append", "If file is existing, over'Write' or 'Append'")

       

        dlg1.tab("Graphic")

        dlg1.image(image_name)

        dlg1.tab("L1")

        dlg1.image(image_name1)

        dlg1.tab("L2")

        dlg1.image(image_name2)

        dlg1.tab("L3")

        dlg1.image(image_name3)

        dlg1.tab("L4")

        dlg1.image(image_name4)

        dlg1.tab("L5")

        dlg1.image(image_name5)

        dlg1.tab("L6")

        dlg1.image(image_name6)

        dlg1.tab("L7")

        dlg1.image(image_name7)

        dlg1.tab("L8")

        dlg1.image(image_name8)

        dlg1.tab("L9")

        dlg1.image(image_name9)

        dlg1.tab("L10")

        dlg1.image(image_name10)

       

 

        dlg1.tabset_end()       

        try:

            dd1 = dlg1.done()

        except ResponseNotOK:

            break

        for key, value in dd1.items():

            exec "%s = %s" % (key, repr(value)) in None

        ###############################################################

        ## END DIALOG BOX 1 ------------------------------------------#

        ###############################################################

        export_data(os.path.join(default_file_path, def_file), dd1)       

           

        if print_doc == "Yes":

            print __doc__

            break      

       

        if roof_slope_angle == 0:

            roof_slope_angle = rtod(atan(roof_slope/12.0))

           

        rafter_slp = atan(tan(dtor(roof_slope_angle)) * cos(dtor(hip_angle)))

        L1 = atan(sin(dtor(roof_slope_angle)) * tan(dtor(hip_angle)))

        L2 = atan(tan(dtor(hip_angle)) * cos(dtor(roof_slope_angle)))

        L3 = atan(sin(dtor(roof_slope_angle)) * cos(dtor(roof_slope_angle)) * sin(dtor(hip_angle)) * tan(dtor(hip_angle)))

        L4 = atan(cos(dtor(roof_slope_angle))**2 * tan(dtor(hip_angle)) / cos(rafter_slp))

        L5 = atan(cos(L3) * tan(L4))

        L6 = atan(tan(L3) * cos(L4))

        L7 = atan(tan(dtor(hip_angle)) * sin(rafter_slp) * cos(L2))

        L8 = atan(tan(dtor(hip_angle)) * cos(dtor(roof_slope_angle)))

        L9 = atan(tan(dtor(hip_angle)) * sin(rafter_slp))

        L10 = atan(tan(dtor(hip_angle)) * sin(rafter_slp))

        L11 = atan(tan(dtor(hip_angle)) / cos(rafter_slp))

        ### L12 (atan (/ (* (tan rafter_slp) (sin hip_angle)) (tan hip_angle)))

        str1List = ["The RAFTER is the hip or valley beam",\

                    "The PURLIN frames into the RAFTER, and is normal to the ROOF SLOPE",\

                    "L1 = Bevel on PURLIN WEB PLANE made by intersection of RAFTER WEB PLANE",\

                    "L2 = Bevel on ROOF PLANE made by intersection of RAFTER WEB PLANE",\

                    "L3 = Bevel on RAFTER WEB PLANE made by intersection of PURLIN WEB PLANE",\

                    "L4 = Bevel on RAFTER FLANGE PLANE made by intersection of PURLIN WEB PLANE",\

                    "L5 = Complement of angle between PURLIN WEB PLANE and RAFTER WEB PLANE (sum = 90)",\

                    "L6 = Complement of angle between PURLIN WEB PLANE and RAFTER FLANGE PLANE (sum = 90)",\

                    "L7 = Bevel on PURLIN WEB PLANE made by RAFTER FLANGE PLANE",\

                    "L8 = Angle between PURLIN WEB PLANE and a plane perpendicular to both RAFTER FLANGE PLANE and RAFTER WEB PLANE",\

                    "L9 = Bevel on a plane perpendicular to both RAFTER WEB PLANE and RAFTER FLANGE PLANE made by intersection of PURLIN WEB PLANE",\

                    "L10 = Angle between ROOF PLANE and RAFTER FLANGE PLANE (hip or valley angle)",\

                    "L11 = Bevel on RAFTER FLANGE PLANE made by a vertical section plane parallel to the ROOF SLOPE"

                    ]

       

        str2List =  ["Roof slope       = %0.8f" % roof_slope_angle, "Hip/Valley angle = %0.8f" % hip_angle,\

                    "Rafter slope     = %0.8f" % rtod(rafter_slp), "L1               = %0.8f" % rtod(L1), \

                    "L2               = %0.8f" % rtod(L2), "L3               = %0.8f" % rtod(L3), \

                    "L4               = %0.8f" % rtod(L4), "L5               = %0.8f" % rtod(L5), \

                    "L6               = %0.8f" % rtod(L6), "L7               = %0.8f" % rtod(L7), \

                    "L8               = %0.8f" % rtod(L8), "L9               = %0.8f" % rtod(L9), \

                    "L10              = %0.8f" % rtod(L10), "L11              = %0.8f" % rtod(L11)

                    ]

        if save_or_print == "Print to screen":

            print '%s\n%s' % ('\n'.join(str1List), '\n'.join(str2List))

        else:

            try:

                f = open(export_file, {"Write": 'w', "Append": 'a'}[write_or_append])

                f.write('%s\n%s\n\n' % ('\n'.join(str1List), '\n'.join(str2List)))

                f.close()

            except:

                Warning('File export failed')

           

        if not yes_or_no("Run again"):

            break

## END run_script() #######################################

if __name__ == '__main__':

    try:

        run_script()

    finally:

        del run_script