# -*- coding: utf-8 -*-


VERSION = 201612


'''
DESCRIPTION
    This is a calculator for designing
    parallel square conductor transmission lines.
    The approximative expression was developed by Owen Duffy, VK1OD.
    See: http://owenduffy.net/calc/tstl.htm


USAGE
    See: http://hamwaves.com/zc.square/en/index.html


COPYRIGHT
    Copyright (C) 2015-2016  Serge Y. Stroobandt

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.


CONTACT
    xdg-open mailto:$(echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d)
'''


### IMPORTS ###

from browser import document
from math import exp


### FUNCTIONS ###

def calculate(event):
    
    try:
        Z_c = float(document['Z_c'].value)
        d = float(document['d'].value)
        
        D = d * (0.539774145266 + 0.404050444546 * exp(0.009504588299*Z_c))
        document['D'].value = '%.3f' % D
        
        s = D - d
        document['s'].value = '%.3f' % s
        
    except:
        outputs = ['D', 's']
        for i in range(len(outputs)):
            document[outputs[i]].value = ''


### MAIN ###

document['brython'].style.display = 'initial'
calculate(None)


### EVENT HANDLERS ###

document['Z_c'].bind('focus', calculate)
document['d'].bind('focus', calculate)

document['Z_c'].bind('input', calculate)
document['d'].bind('input', calculate)
