# -*- coding: iso-8859-7 -*-
import sys
from math import log10,fabs,hypot
from p_gfil import closeFiles1
from p_gmath import fsign
import com, mhk2, mhk4, mhk5
def thanMainTcad(fpath, dxf, prt):
"Main routine, if the program is run within ThanCad."
com.prt = prt
mhk5.openFilesTcad(fpath)
com.frw["dxf"] = dxf
mhkProgram()
del dxf, com.prt
closeFiles1()
def thanMain():
"Main routine for standalone program."
# openfilesekp()
mhk5.openFiles()
mhkProgram()
normalexit()
def mhkProgram():
"Main function of section program."
#================================================
com.um = com.UM1
com.dm = com.DM1
com.ipenl=1
com.ipenx=2
#----- files
mhk5.dedgen()
mhk5.onlaygram()
uDxf = com.frw["dxf"]
mhk5.defdxf()
# getgreekdxf()
uDxf.thanDxfSetLayer('TITLOS')
if com.drawtitle: title(0.0-com.TAS, 0.0, 100.0/com.pklx, 100.0/com.pkly, com.uIni, ' ')
uDxf.thanDxfSetLayer('TEXTL')
mhk4.titlos()
#===== =====================================================
while (True):
mhk5.dedm()
#c rewind 16
com.xthar, _, _, _ = com.uTed.readrec(rec=0) # read (16, rec=1) xthar
mhk4.ypkata()
#
#----------
#
uDxf.thanDxfSetLayer('TEXTX')
uDxf.thanDxfPlotSymbol(-0.7,com.platit+5.0,0.7, com.mhk, 90.0)
uDxf.thanDxfSetLayer('TEXTL')
if (not com.oxiery): com.frw["ery"].write("%s\n" % com.mhk)
#
#--------------
#
#c rewind 16
com.xthed, yeed, com.onp, com.akat = com.uTed.readrec(rec=0) # read (16,rec=1)xthed,(yee(ied(i)),i=1,ned),onp,akat
for i,yeed1 in enumerate(yeed): com.yee[com.ied[i]] = yeed1
#c kil = 0.0d0
#c ery = 0.0d0
#c edaf = 0.0d0
#c katar = 0.0d0
com.xthar=com.xthed
com.xkmhd=0.0
com.xnump=-1.0
com.xak=-59.0
com.yor=com.akat
uDxf.thanDxfPlot(0.0,0.0,3)
uDxf.thanDxfPlot(0.0,1.0,2)
mhk4.proker()
xx = mhk4.sxeakr()
uDxf.thanDxfSetLayer('noplot') #thanasis2007_06_07:aid dxf read of grade line
uDxf.thanDxfPlotPoint(0.0, com.platit)
uDxf.thanDxfSetLayer('TEXTL')
ypyer(False)
xilsh(True)
mhk4.sxenum(xx,True)
com.kil.append(com.xthed)
com.edaf.append(com.yee[com.kedaf])
com.ery.append(com.yee[com.keryth])
com.katar.append([com.xthed, com.yor])
#
#----------
#
for ip in xrange(1, com.lasted+1): #do 20 ip=2,lasted
com.yeep[:] = com.yee[:]
com.xthedp=com.xthed
com.xthed, yeed, com.onp, com.akat = com.uTed.readrec(rec=ip) # read ( 16,rec=ip)xthed,(yee(ied(i)),i=1,ned),onp,akat
for i,yeed1 in enumerate(yeed): com.yee[com.ied[i]] = yeed1
xx = mhk4.sxeakr()
ypyer(False)
xilsh(False)
mhk4.sxenum(xx,False)
mhk4.sxelin(xx)
com.kil.append(com.xthed)
com.edaf.append(com.yee[com.kedaf])
com.ery.append(com.yee[com.keryth])
if (com.yor != com.katar[-1][1]): #if (com.yor(2, katarcount)) then
com.katar.append([com.xthed, com.yor])
else:
com.katar[-1][0] = com.xthed
#20 continue
#-----------
#
if com.drawlep: mhk2.leptomeries()
uDxf.thanDxfPlot(xx,0.0,3)
uDxf.thanDxfPlot(xx,1.0,2)
mhk4.orkam(xx)
if (not com.oxiery): com.frw["ery"].write('$')
#
#----------
#
com.uTed.clear() #close (16,status='delete') #
com.uTer.clear() #close (7,status='delete') #
com.uTef.clear() #close (8,status='delete') #
com.uTeo.clear() #close (9,status='delete') #
if com.telmhk: break
if com.sxetit: mhk4.titlos()
# go to 10
#
#--------------
#
uDxf.thanDxfPlot(0.0, 0.0, 999)
#=======================================================================
ekatom = xiliom = 0.0
def xilsh (initialise):
"Plots the station (Xil.Thesi)."
global ekatom, xiliom
#-----
uDxf = com.frw["dxf"]
if (initialise):
n = int(log10(0.99*com.aklx))
com.ndxth = 4 - n
if (com.ndxth > 2): com.ndxth = 2
if (com.ndxth <= 0): com.ndxth = -1 # no dekadika
if (n < 3): n = 3
com.xthmod = 10.0**n
xiliom = int(com.xthed / com.xthmod)
if com.xthed % com.xthmod == 0.0: xiliom = xiliom - 1.0
ekatom = int((com.xthed % com.xthmod) / 100.0) + 0.0
if (com.xthed % 100.0 == 0.0): ekatom = ekatom - 1.0
#-----
if (com.onp[:1] == ''):
#c com.xkmhd = xthed
#c xiliom = 0.0d0
#c ekatom = 0.0d0
pass
xthed1 = com.xthed - com.xkmhd
x = int(xthed1 / com.xthmod)
while xiliom < x:
xiliom = xiliom + 1.0
xx = (xiliom*com.xthmod - com.xthar + com.xkmhd) * com.pklx
uDxf.thanDxfPlotSymbol(xx+0.07, 2.02, com.HS, '', 90.0)
uDxf.thanDxfPlotSymbol(xx, 2.1, com.HS, '.', 90.0)
x1 = xiliom*com.xthmod/1000.0
uDxf.thanDxfPlotNumber(xx, 2.25, com.HS, x1, 90.0, -1)
ekatom = 0.0
#-----
if (com.ndxth != 2): return
x = int((xthed1 % com.xthmod) / 100.0)
while ekatom < x:
ekatom = ekatom + 1.0
xx = (xiliom*com.xthmod + ekatom*100.0 - com.xthar + com.xkmhd) * com.pklx
uDxf.thanDxfPlotSymbol(xx, 2.1, com.HS, '.', 90.0)
uDxf.thanDxfPlotNumber(xx, 2.25, com.HS, ekatom, 90.0, -1)
#======================================================================
def shmaia (xshm, yshm, pr):
"Plots a flag at the start or end of a vertical curve."
#
#-----.. ,
#
xx=(xshm-com.xthar)*com.pklx
uDxf = com.frw["dxf"]
uDxf.thanDxfPlot(xx,0.0,3)
uDxf.thanDxfPlot(xx,1.0,2)
xs = xshm % com.xthmod
if com.ndxth == 2: xs = xshm % 100.0
uDxf.thanDxfPlotNumber(xx-com.HS*0.2, com.platit+com.HS*0.2, com.HS, xs, 90.0, com.ndxth)
uDxf.thanDxfPlotNumber(xx+com.HS*1.2, com.platit+com.HS*0.2, com.HS, yshm, 90.0, 2)
#
#-----
#
#c yy=(ysmax-yor)*pkly+platit+4.0d0
#c if (yy.gt.plaxar+plxm) yy=plaxar+plxm
yy=com.plaxar+com.plxm-8.0*com.HS
uDxf.thanDxfPlot(xx,com.platit,3)
uDxf.thanDxfPlot(xx,yy,2)
uDxf.thanDxfPlot(xx+pr*0.3,yy-0.4,2)
uDxf.thanDxfPlot(xx,yy-0.8,2)
uDxf.thanDxfPlot(xx+pr*0.3,yy-0.4,3)
uDxf.thanDxfPlot(xx,yy-0.4,2)
#==============================================================
def klish(ai,amhkos):
"Plots the slope of the grade line."
if com.oxikak: return
uDxf = com.frw["dxf"]
xx=(com.xkli-com.xthar)*com.pklx
if ai < 0.0:
#----------
uDxf.thanDxfPlot(xx,0.8,3)
uDxf.thanDxfPlot(xx+2.4,0.2,2)
uDxf.thanDxfPlotNumber(xx+0.9,0.7,com.HS,ai*100.0,-16.26,1)
px, py = uDxf.thanDxfWhere()
uDxf.thanDxfPlotSymbol(px,py,com.HS,'%',-16.26)
uDxf.thanDxfPlotNumber(xx+0.9,0.3,com.HS,amhkos,-16.26, 2)
else:
#----------
if ai == 0.00:
mhk5.wamhk(['.. = %.2: = 0.00 %' % xkli])
uDxf.thanDxfPlot(xx,0.2,3)
uDxf.thanDxfPlot(xx+2.4,0.8,2)
uDxf.thanDxfPlotNumber(xx+0.9,0.5,com.HS,ai*100.0,16.26,1)
px, py = uDxf.thanDxfWhere()
uDxf.thanDxfPlotSymbol(px,py,com.HS,'%',16.26)
uDxf.thanDxfPlotNumber(xx+0.9,0.1,com.HS,amhkos,16.26,2)
#
#=====================================================================
#
def katako(i):
"Plot rectangle with vertical curve information."
#
#------.. ,
#
uDxf = com.frw["dxf"]
xx = (com.xstk-com.xthar)*com.pklx
xs = com.xstk % com.xthmod
if (com.ndxth == 2): xs=com.xstk % 100.0
uDxf.thanDxfPlotNumber(xx-com.HS*0.3,com.platit+com.HS*0.2,com.HS,xs,90.0,com.ndxth)
dy=com.t[i]**2/2.0/com.r2[i]
yy=com.yer2[i]+fsign(dy, com.ai2[i]-com.ai1[i])
uDxf.thanDxfPlotNumber(xx+com.HS*1.3,com.platit+com.HS*0.2,com.HS,yy,90.0,2)
#
#-----
#
yy=com.plaxar+com.plxm
yy1=yy-8.0*com.HS
xx1=4.5*com.HS
uDxf.thanDxfPlot (xx,com.platit,3)
uDxf.thanDxfPlot (xx,yy1,2)
uDxf.thanDxfPlot (xx-xx1,yy1,2)
uDxf.thanDxfPlot (xx-xx1,yy,2)
uDxf.thanDxfPlot (xx+xx1,yy,2)
uDxf.thanDxfPlot (xx+xx1,yy1,2)
uDxf.thanDxfPlot (xx,yy1,2)
#
#-----
#
yy=com.plaxar+com.plxm-8.0*com.HS+0.5*com.HS
xx1 = xx-xx1+0.5*com.HS
xx2 = xx1+2.5*com.HS
uDxf.thanDxfPlotSymbol (xx1,yy,com.HS,'=',0.0)
uDxf.thanDxfPlotNumber (xx2,yy,com.HS,dy,0.0,2)
yy=yy+1.5*com.HS
uDxf.thanDxfPlotSymbol(xx1,yy,com.HS,'l=',0.0)
uDxf.thanDxfPlotNumber(xx2,yy,com.HS,2.0*com.t[i],0.0,2)
yy=yy+1.5*com.HS
uDxf.thanDxfPlotSymbol (xx1,yy,com.HS,'t=',0.0)
uDxf.thanDxfPlotNumber (xx2,yy,com.HS,com.t[i],0.0,2)
yy=yy+1.5*com.HS
uDxf.thanDxfPlotSymbol(xx1,yy,com.HS,'r=',0.0)
uDxf.thanDxfPlotNumber(xx2,yy,com.HS,com.r2[i],0.0,-1)
yy=yy+1.5*com.HS
uDxf.thanDxfPlotSymbol(xx1,yy,com.HS,'h=',0.0)
uDxf.thanDxfPlotNumber(xx2,yy,com.HS,com.yer2[i],0.0,2)
#
#======================================================================
#
def ypyer(oxisxe):
"Computation of height of grade lines."
if com.oxiery: return
for i in xrange(com.nyee): #do 1 i=1,nyee
oxi = oxisxe or i!=com.keryth
m = com.icod[i] % 4
if m == 0: pass #
elif m == 1: ypyerOdop(i, oxi) #
elif m == 2: ypyerApox(i, oxi) #
else: pass #
ypyerEx() # -
if oxisxe: return
com.dxom=com.yee[com.keryth]-com.yee[com.kedaf]
com.frw["ery"].write ("%-8s%10.2f%10.2f%10.2f\n" % (com.onp,com.xthed,com.yee[com.kedaf],com.yee[com.keryth]))
def ypyerEx():
"Compute the height of all the slave grade lines."
for k in xrange(com.nyee):
if com.icod[k]%4 != 3: continue
i = k
dy = 0.0
while True:
m = com.icod[i] % 4
if m != 3: break
dy += com.yer1[i]
i = int(com.r1[i])
com.yee[k] = com.yee[i] + dy
def ypyerApox(i, oxi):
"Compute the height of the sewage grade line."
uDxf = com.frw["dxf"]
while True:
if not oxi: # go to 40
if com.xthed >= com.xkli: # go to 40
klish(com.ai1[i], hypot(com.xther2[i]-com.xther1[i], com.yer2[i]-com.yer1[i]))
com.xkli=1.030
if com.xthed <= com.xther2[i]: break # go to 21
if not oxi: #go to 41
xx=(com.xther2[i]-com.xthar)*com.pklx
uDxf.thanDxfPlot (xx,0.0,3)
uDxf.thanDxfPlot (xx,1.0,2)
if (com.linery[i] >= com.laster[i]): # go to 22
terr = [' (..=%.2f) ' % com.xthed,
' %d (..=%.2f)' % (i, com.xther2[i]),
]
mhk5.ermhks(terr)
#----------
com.xther1[i] = com.xther2[i]
com.yer1[i] = com.yer2[i]
com.r1[i] = com.r2[i]
com.linery[i] = com.linery[i]+1
com.xther2[i],com.yer2[i],com.r2[i] = com.uTer.readrec(rec=com.linery[i]) # read(7,rec=linery(i))xther2(i),yer2(i),r2(i)
com.ai1[i]=(com.yer2[i]-com.r1[i])/(com.xther2[i]-com.xther1[i])
if not oxi: #go to 40
com.xkli=(com.xther1[i]+com.xther2[i])*0.5-1.25/com.pklx
#------
com.yee[i]=com.r1[i]+com.ai1[i]*(com.xthed-com.xther1[i])
xshm1p = yshm1 = yshm2 = ysmax = 0.0
def ypyerOdop(i, oxi):
"Compute the height of the highway grade line."
global xshm1p, yshm1, yshm2, ysmax
while True:
if not oxi: # go to 35
#--------------- ,, .
if com.xthed >= com.xkli: #) go to 31
xtemp=com.xshm1
if xtemp == 1.0e30: xtemp=com.xther2[i]
klish(com.ai1[i], xtemp-com.xshm2p)
com.xkli=1e30
if com.xthed >= com.xshm1: #go to 32
yshm1=com.yer1[i]+com.ai1[i]*(com.xshm1-com.xther1[i])
yshm2=com.yer2[i]+com.ai2[i]*(com.xshm2-com.xther2[i])
ysmax=max((yshm1,yshm2))
if com.r2[i] != 0.0: shmaia(com.xshm1,yshm1,1.0)
xshm1p=com.xshm1
com.xshm1=1.0e30
if com.xthed >= com.xstk: # go to 33
if com.r2[i] != 0.0: katako (i)
com.xstk=1.0e30
if com.xthed >= com.xshm2: # go to 35
if com.r2[i] != 0.0: shmaia (com.xshm2,yshm2,-1.0)
com.xshm2p=com.xshm2
com.xshm2=1.0e30
if com.oxienl[i]: break # go to 11
#-----------
com.xther1[i] = com.xther2[i]
com.yer1[i] = com.yer2[i]
com.ai1[i] = com.ai2[i]
com.xther2[i] = com.xther3[i]
com.yer2[i] = com.yer3[i]
com.r2[i] = com.r3[i]
com.oxienl[i] = True
if com.linery[i] < com.laster[i]: # go to 12
#---------------
com.linery[i] += 1
com.xther3[i], com.yer3[i], com.r3[i] = com.uTer.readrec(rec=com.linery[i]) # read (7, rec=linery(i))xther3(i),yer3(i),r3(i)
if com.linery[i] >= com.laster[i] and com.r3[i] != 0.0: # go to 100
mhk5.ermhks ([" %d = 0.00" % i])
com.ai2[i]=(com.yer3[i]-com.yer2[i])/(com.xther3[i]-com.xther2[i])
com.t[i]=com.r2[i]*fabs(com.ai2[i]-com.ai1[i])*0.5
if not oxi:
com.xshm1=com.xther2[i]-com.t[i]
com.xshm2=com.xther2[i]+com.t[i]
com.xstk=com.xther2[i]
com.xkli=(com.xshm2p+com.xshm1)*0.5-1.25/com.pklx
else:
#---------------
com.t[i]=0.0
if not oxi: com.xkli=(com.xshm2p+com.xther2[i])*0.5-1.25/com.pklx
if (com.xthed <= com.xther2[i]+0.01): continue #go to 10
terr = [' (..=%.2f) ' % com.xthed,
' %d (..=%.2f)' % (i, com.xther2[i]),
]
mhk5.ermhks(terr)
#-----
if com.xthed > com.xther2[i]+com.t[i]: com.oxienl[i]=False
if com.xthed <= com.xther2[i]: # go to 15
com.yee[i]=com.yer1[i]+com.ai1[i]*(com.xthed-com.xther1[i])
else:
com.yee[i]=com.yer2[i]+com.ai2[i]*(com.xthed-com.xther2[i])
dy=com.t[i]-fabs(com.xther2[i]-com.xthed)
if dy > 0.0:
dy=dy*dy/2.0/com.r2[i]
com.yee[i]=com.yee[i]+fsign(dy,com.ai2[i]-com.ai1[i])
#=============================================================================
def normalexit():
"Stop the program reporting success."
#c prg(' ')
closeFiles1()
sys.exit()
if __name__ == "__main__": thanMain()
|