mhk5.py :  » Business-Application » ThanCad » thancad-0.0.9 » p_gmhk » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » ThanCad 
ThanCad » thancad 0.0.9 » p_gmhk » mhk5.py
# -*- coding: iso-8859-7 -*-

import sys
from math import pi
from p_ggen import path,prg
from p_gfil import openFile1,opFile1e,Datlin
from p_gdxf import ThanDxfPlot
import com


def dedm():
      "Read data of ground line, grade lines, and horizontal curves."
      fr = com.frw["mhk"]
      fr.datCom("")
      com.mhk = fr.datCurline().partition(":")[2].rstrip()
      if com.mhk[:1] == " ": com.mhk = com.mhk[1:]  # Avoid first blank but allow :
      deded()  #  
      deder()  #    
      dedlep() #  
      dedka()  #   

def deded():
      "Read data of ground lines."
      fr = com.frw["mhk"]
      fr.datCom(' ')
      j1 = (com.ned+1)*10+1
      j2 = j1 + 8
      j3 = j2 + 2
      com.lasted=-1
      while True:
          if not fr.datLin(failoneof=False):
        com.telmhk = True
        break
          if fr.datComC(' ', fail=False):             return
          if fr.datComC(' ', fail=False):    return
          if fr.datComC('  ', fail=False): return
          if fr.datComC('', fail=False):                     return
#          read (ibuf, iform, iostat=ierr)xth,(yee[i],i=1,ned),onp,katara
    xth = fr.datFloat()
    yee = [fr.datFloat() for j in xrange(com.ned)]
    dl = fr.datCurline()
    onp = dl[j1:j2].rstrip()
    katara = dl[j2:j3]
    if wrongYps(yee): continue     # Heights of ground lines are invalid; ignore them
          com.lasted += 1
          yer = 1.0e30
          if katara=='': yer = 0.0
          com.uTed.writerec(rec=com.lasted, data=(xth,yee,onp,yer))

def wrongYps(yee):
    "Check if the height of the ground lines is ok."
    for yee1 in yee:
        if yee1 == -10000.0:
            fr.wafile1(['   -10000 : %s'%onp])
            return True
    return False

def deder():
      "Read data for grade lines."      
      fr = com.frw["mhk"]
      com.icod   = [0]*len(com.icod1)
      com.laster = [0]*len(com.icod1)
      com.linery = [0]*len(com.icod1)
      com.oxienl = [False] * len(com.icod1)
      com.xther1 = [0.0] * len(com.icod1)
      com.yer1   = [0.0] * len(com.icod1)
      com.r1     = [0.0] * len(com.icod1)
      com.xther2 = [0.0] * len(com.icod1)
      com.yer2   = [0.0] * len(com.icod1)
      com.r2     = [0.0] * len(com.icod1)
      com.xther3 = [0.0] * len(com.icod1)
      com.yer3   = [0.0] * len(com.icod1)
      com.r3     = [0.0] * len(com.icod1)
      com.ai1    = [0.0] * len(com.icod1)
      com.t      = [0.0] * len(com.icod1)
      com.ai2    = [0.0] * len(com.icod1)
      com.yee    = [0.0] * len(com.icod1)
      com.yeep   = [0.0] * len(com.icod1)
      liner = -1
      while not com.telmhk:
          fr.datLinbac()
          fr.datLin()
          if fr.datComC(' ', fail=False):    return
          if fr.datComC('  ', fail=False): return
          if fr.datComC('', fail=False):                     return
          if not fr.datComC(' ', fail=False):
               fr.er(":  ,   ,\n"\
               " ,  ")
          ieryth = fr.datIntR(1, com.nyee) - 1
          com.iseira.append(ieryth)

          com.icod[ieryth]=com.icod1[ieryth]
#c       call dedgr (keimen+metomi+idiagr,i,rv,dv,ibuf,ierr)  # This commented out code may ..
#c       i=istrstr(ibuf,'')                                 # ..change icod of a grade/line for..
#c       if (i>0) icod(ieryth)=1+(icod(ieryth)/4)*4           # ..an individual section
#c       i=istrstr(ibuf,'')
#c       if (i>0) icod(ieryth)=2+(icod(ieryth)/4)*4

          i = com.icod[ieryth] % 4
          if   i == 1: liner = dederOdop(liner, ieryth) #  
          elif i == 2: liner = dederApox(liner, ieryth) #  
          elif i == 3: dederEx(ieryth)                  #  
          else: fr.er('H  %d   !' % ieryth)

def dederOdop(liner, ieryth):
       "Read data for highway grade line."
       fr = com.frw["mhk"]
       while True:
           if not fr.datLin(failoneof=False):
         com.telmhk = True
         return liner
           if fr.datComC(' ', fail=False):             return liner
           if fr.datComC(' ', fail=False):    return liner
           if fr.datComC('  ', fail=False): return liner
           if fr.datComC('', fail=False):                     return liner
           xth = fr.datFloat()
     yer = fr.datFloat()
     r = fr.datFloat()
           liner += 1
           com.uTer.writerec(rec=liner, data=(xth,yer,r))
           com.laster[ieryth] = liner

def dederApox(liner, ieryth):
      "Read data for sewage grade line."
      fr = com.frw["mhk"]
      while True:
          if not fr.datLin(failoneof=False):
        com.telmhk = True
        return liner
          if fr.datComC(' ', fail=False):             return liner
          if fr.datComC(' ', fail=False):    return liner
          if fr.datComC('  ', fail=False): return liner
          if fr.datComC('', fail=False):                     return liner
    xth = fr.datFloat()
    yer = fr.datFloat()
    if fr.eol(): r = yer
    else:        r = fr.datFloat()
          if r == 0.0: r = yer
          liner += 1
          com.uTer.writerec(rec=liner, data=(xth,yer,r))
          com.laster[ieryth]=liner

def dederEx(ieryth):
      "Read data for slave grade line."
      fr = com.frw["mhk"]
      fr.datCom(" ")
      com.r1[ieryth] = fr.datInt() - 1
      fr.datCom(" ")
      com.yer1[ieryth] = fr.datFloat()
      if not fr.datLin(failoneof=False):
          com.telmhk = True

def dedka():
      "Read data for horizontal curves."
      fr = com.frw["mhk"]
      if com.telmhk:
          com.oxikam = True
    return
      fr.datLinbac()
      fr.datLin()
      if fr.datComC('', fail=False): 
          com.oxikam = True
    return
      if not fr.datComC('  ', fail=False):
           fr.er(":   ")
      lastka = 0
      while True:
          if not fr.datLin(failoneof=False):
        com.telmhk = True
        break
          if fr.datComC('', fail=False): break
    dl = fr.datCurline()
    fr.datLinSet("'"+dl[:8]+"'"+dl[8:])
    onp = fr.datStr().rstrip()
    v = fr.datFloat()
    xth = fr.datFloat()
    r = fr.datFloat()
    dr = fr.datFloat()
    e = fr.datFloat()
    d = fr.datFloat()
          com.uTeo.writerec(data=(onp,v,xth,r,dr,e,d))
          lastka+=1
      if lastka==0: com.oxikam = True

def dedlep():
      "Read data for drawing details."
#     com.linlep = is initialized to zero in com.py
      fr = com.frw["mhk"]
      linlp = 0
      while not com.telmhk:
          fr.datLinbac()
          fr.datLin()
          if fr.datComC('  ', fail=False): return
          if fr.datComC('', fail=False):                     return
          if not fr.datComC(' ', fail=False):
              fr.er(":   ,\n"\
              " ,  ")

          ieryth = fr.datInt()
    if ieryth == 1: dedlepFreat(linlp)  # 
    else: fr.er('      %d' % ieryth)

def dedlepFreat(linlp):
      "Read data for drawing details: freatia."
      fr = com.frw["mhk"]
      linlep[ieryth]=linlp+1      # This is the first line in the temporary file for detail ieryth
      fr.datLin()
      yer = fr.datFloat()
      fr.datLin()
      r = fr.datFloat()
      com.uTef.writerec(data=(ieryth,))
      com.uTef.writerec(data=(yer,r))
      linlp+=1

      while True:
          if not fr.datLin(failoneol=False):
        com.telmhk = True
        return
    xth = fr.datFloat()
          com.uTef.writerec(data=(xth,))
          linlp+=1

#==============================================================

def dedgen():
      """Read general data.

            :  5000.
             :   500.
         : 
      : 
         : 
 .  : 
    : 
   : 
  (CM)     :  59.0
  (CM):   1.5
      :  1
      :  2
          :  2
      """
      fr = com.frw["mhk"]
      fr.datCom(" ")
      com.aklx = fr.datFloatR(1e-6, 1e6)
      com.pklx=100.0/com.aklx
      fr.datCom(" ")
      com.akly = fr.datFloatR(1e-6, 1e6)
      com.pkly=100.0/com.akly

      fr.datCom(" ")
      com.oxiery = not fr.datYesno()

      fr.datCom(" ")
      com.oxikam = not fr.datYesno()

      odopoi= True
      fr.datCom(" ")
      ibuf = fr.datMchoice(" ")
      com.odopoi = ibuf[:2] == ""

      fr.datCom(" . ")
      com.oxikak = not fr.datYesno()

      fr.datCom("   ")
      com.sxetit = fr.datYesno()

      fr.datCom("  ")
      com.drawguidelines = fr.datYesno()

      fr.datCom(" ")
      com.plaxar = fr.datFloatR(15.0, 1000.0)
      com.plxm=8.0*com.HS+2.5
      com.plaxar -= com.plxm
      if not com.drawguidelines: com.um = com.dm = 0.0
      com.paper = com.plaxar
      com.plaxar -= (com.um + com.dm)

      fr.datCom(" ")
      com.perype = fr.datFloatR(0.0, com.plaxar-15.0)

      fr.datCom("  ")
      com.kedaf = fr.datIntR(1, com.MYEE) - 1

      fr.datCom("  ")
      com.keryth = fr.datIntR(1, com.MYEE) - 1

      fr.datCom(" ")
      com.nyee = fr.datIntR(1, com.MYEE)

#----- 
#     1                               .00,  .00,  .00
#     2                     .00,  .00,  .00

      com.ned=0
      com.itit = []
      com.diak1 = []
      com.icod1 = []
      com.ied = []
      for i in xrange(com.MYEE):
          if fr.datCom('', fail=False): break
          dl = fr.datCurline()
    dl = dl[:10] + "'" + dl[10:32] + "' '" + dl[32:52] + "' " + dl[52:].replace(",", " ")
    fr.datLinSet(dl)

          j = fr.datInt()
          if j != i+1:
              fr.er('     / %d' % (i+1,))
    com.ititl.append(fr.datStr())
         
    com.icod1.append(0)
    ig = fr.datStr()
          if '' in ig:   com.ied.append(i)
          elif '' in ig: com.icod1[-1] += 1
          elif '' in ig: com.icod1[-1] += 2
          elif '' in ig:   com.icod1[-1] += 3
          else: fr.er('    :\n'\
                      '    "",  " \n'\
                      '    " ",  " "'
         )
   
    ip = fr.datMchoice(" ")
          if ip[:2]=='': com.icod1[i]+=4

    com.diak1.append([fr.datFloat() for j in xrange(3)])
      
#          read (ibuf,11,iostat=ierr) j, ititl[i], ig, ip,
#     &    diak1[i],diak2[i],diak3[i]
#11       format (i8, 2x, a22, a20, a7, 1x, 3(1x, f5.0))
#                 0  8   10   32   52  59 60  
      else:
          fr.er('    / : %d' % com.MYEE)
      com.telmhk = False
      fr.datLinbac()
      com.nyee = len(com.icod1)
      com.ned = len(com.ied)
      com.ner = com.nyee - com.ned
      
      if com.ner == 0 and not com.oxiery:
          wamhk("   .")
          com.oxiery = True
      if not 0 <= com.kedaf < com.nyee:
          ermhks(["    (%d)     %d  %d." %
                  (com.kedaf+1, 1, com.nyee)])
      if com.kedaf not in com.ied:
          wamhk(["    (%d)   !" % (com.kedaf+1,)]) 
      if not 0 <= com.keryth < com.nyee:
          if com.oxiery:
              com.keryth = 0     # keryth is unused, so set a failsafe value
          else:
              ermhks(["    (%d)     %d  %d." %
                      (com.keryth+1, 1, com.nyee)])
      if com.keryth in com.ied and not com.oxiery:
          wamhk(["    (%d)   !" % (com.keryth+1,)]) 
      freat()

#=======================================================================

def freat():
      "Read dimension of freatia."
      sxedfreat = False
      try:            fr = open('freatia', "r")
      except IOError: return

      try:                           
          com.pfr, com.hfr = map(float, fr.next().split())
      except (ValueError, IndexError):
          pass
      else:
          com.sxedfreat = True
      fr.close()

#==============================================================

def stoperr(ierr, s):
      "Prints error message and stops the program."
      if ierr == 0: return
      if ierr == 1: terr = '       %s  - %d' % (s, lepcount)
      elif ierr == 2: terr = '          %s  - %d' % (s, lepcount)
      elif ierr == 3: terr = '  '
      elif ierr == 4: terr = "   '%s'  ." % s
      elif ierr == 10: terr = '  $    %d' % lepcount
      elif ierr == 11: terr = '    %d' % lepcount
      elif ierr == 20: terr = '   '
      elif ierr == 21: terr = ' '
      elif ierr == 30: terr = ' ..      %s     -  %d' % (s, lepcount)
      else: assert False, "Uknown error code %d" % ierr
      ermhks([terr])

#====================================================================

def openFilesEkp():
      "Message for the student license."
      hhh1()
      terr = \
      [' ',
       '  . :   -  ',
       ' --------------------------------------------------------',
       ' ',
       '       ',
       ' .  ..',
       '        4 ',
       '       ,  ',
       '  ,    ',
       '        ',
       ' .',
       ' ',
       '       ',
       '  .',
       '    , , leasing   ',
       '        ',
       ' .',
       ' ',
       '        ',
       ' 4        ',
       '    ,    ',
       '  .',
       ' '
      ]
#     prg("\n".join(terr))
      pro = raw_input(' enter..')
      prg(9*"\n")
      openFiles()


def openFiles():
      "Opens the necessary files."
      openFile1(0, ' ', ' ', 0, ' ')
      openFile1(1, 'mhk', 'opt', 1, '')
      openFile1(1, 'med', 'opt', 1, ' ')
      openFile1(1, 'lep', 'opt', 1, '')
      openFile1(1, 'ini', 'opt', 1, '')
      openFile1(1, 'ery', ' ',   1, '')
      openFile1(1, 'oka', ' ',   1, ' ')
      openFile1(1, 'dxf', ' ',   1, ' thancad')
      com.frw = openFile1(999, ' ', ' ', 0, ' ')

      if com.frw["mhk"] != None:
    if com.frw["med"] != None:
              terr = [' file .med : %s' % com.frw["med"].name,
                '    file .mhk: %s' % com.frw["mhk"].name,
                '(  .med   ,   .mhk)'
         ]
        waFile1(terr)
      elif com.frw["med"] != None:
    fil = path(com.frw["ery"].name)
    fil = fil.basename()
    prg(' ')
    prg('  file .med  file .mhk')
          com.frw.update(opFile1e(1, "mhk", ' ', fil, ' '))
    med2mhk()
    com.frw["mhk"].close()
          com.frw.update(opFile1e(1, "mhk", "old", fil, 'old', ' '))
      else:
    prg("     .mhk   .med")
    sys.exit(1)

      com.drawtitle = com.frw["ini"] != None
      com.drawlep = com.frw["lep"] != None
      if com.drawlep:
          com.frw["lep"] = Datlin(com.frw["lep"], comment="*")
      
      
      com.frw["mhk"] = Datlin(com.frw["mhk"], comment="*")
      uDxf = ThanDxfPlot()
      uDxf.thanDxfPlots1(com.frw["dxf"])
      com.frw["dxf"] = uDxf

def openFilesTcad(fpath):
      "Opens the necessary files when the program is run within ThanCad."
      pro = fpath.parent / fpath.namebase
      com.frw.update(opFile1e(1, 'mhk', 'old', pro, ''))
      com.frw.update(opFile1e(1, 'lep', 'opt', pro, ''))
      com.frw.update(opFile1e(1, 'ini', 'opt', pro, ''))
      com.frw.update(opFile1e(1, 'ery', ' ',   pro, ''))
      com.frw.update(opFile1e(1, 'oka', ' ',   pro, ' '))

      com.drawtitle = com.frw["ini"] != None
      com.drawlep = com.frw["lep"] != None
      if com.drawlep:
          com.frw["lep"] = Datlin(com.frw["lep"], comment="*")

      com.frw["mhk"] = Datlin(com.frw["mhk"], comment="*")

#c====================================================================

def med2mhk():
      "Transform a .med file to a .mhk file."
      fw = com.frw["mhk"]
      fw.write("""\
            :  2000.
             :   200.
         : 
      : 
         : 
 .  : 
    : 
   : 
  (cm)     :  27.0
  (cm):   1.5
      :  1
      :  2
          :  1
*
*                                        
* ------  ---------------------  ------------------  ------  -------------------
     1                               .00,  .00,  .00
*     2                     .00,  .00,  .00
*
* ----------------------------------------------------------------------'
""")
      fr = com.frw["med"]
      while True:
          dline = fr.readline()
    if dline == "": return
          fw.write('*\n : %s\n*\n \n' % dline.strip("\n"))
          while True:
              dline = fr.readline()
        if dline == "": return
        if dline.strip() == '$': break
        fw.write(dline)

#====================================================================

def hhh1():
      terr = \
      [' ',
       '  . :   -  ',
       ' --------------------------------------------------------',
       ' ',
       '       ',
       ' .  ..',
       '        4 ',
       '       ,  ',
       '  ,    ',
       '        ',
       ' .',
       ' ',
       '       ',
       '  .',
       '    , , leasing   ',
       '        ',
       ' .',
       ' ',
       '        ',
       ' 4        ',
       '    ,    ',
       '  .',
       ' '
      ]
      for dl in terr:
#          dl = gggg(dl)
          prg(dl)

#============================================================================

def gggg (dl):
      a = pi - int(pi)
      k = []
      for i in range(8):
          a = a * 10.0
          k.append(int(a))
          a -= int(a)

      cc = []
      for i,c in enumerate(dl):
          j = ord(c) - k[i % 8]
          cc.apend(chr(j))
      return "".join(cc)

#====================================================================

def onlaygram():
      "Makes a layer name for each ground/grade line."
      for i in xrange(com.nyee):
          ic = com.icod1[i] % 4
          if ic == 0: com.laygram.append('edaf%d' % i)
          else:       com.laygram.append('eryt%d' % i)    

#===========================================================================

def defdxf():
      "Define various dxf properties - layers, linetypes etc."
      uDxf = com.frw["dxf"]
      uDxf.thanDxfTableDef ('__INIT__', 0)
#-----line types---------------------------
      uDxf.thanDxfTableDef ('LTYPE', 3)
      uDxf.thanDxfCrLtype ('continuous', 'solid line', ())
      uDxf.thanDxfCrLtype ('dotr',    '.................', (0, -0.06))
      uDxf.thanDxfCrLtype ('dashed2', '- - - - - - - - -', (0.25, -0.125))
#-----text styles---------------------------
      uDxf.thanDxfTableDef ('STYLE', 1)
      uDxf.thanDxfCrTstyle('grstyle', 'arial.ttf')
#-----layers--------------------------------
      uDxf.thanDxfTableDef('LAYER', 10+com.nyee)
      uDxf.thanDxfCrLayer ('titlos',       7, 'continuous')
      uDxf.thanDxfCrLayer ('texnika',     13, 'continuous')
      uDxf.thanDxfCrLayer ('sxolia',       3, 'continuous')
      uDxf.thanDxfCrLayer ('sxolia1',     12, 'continuous')
      uDxf.thanDxfCrLayer ('sxolia_xth',   3, 'continuous')
      uDxf.thanDxfCrLayer ('sxolia1_xth', 12, 'continuous')
      uDxf.thanDxfCrLayer ('sxolia_or',    3, 'continuous')
      uDxf.thanDxfCrLayer ('sxolia1_or',  12, 'continuous')
      uDxf.thanDxfCrLayer ('TEXTL',        2, 'continuous')
      uDxf.thanDxfCrLayer ('TEXTX',        3, 'continuous')
      for i in xrange(com.nyee):
          if com.icod1[i] % 4 == 0: ic = 2
          else:                     ic = 11
          uDxf.thanDxfCrLayer (com.laygram[i], ic, 'continuous')

      uDxf.thanDxfTableDef ('ENTITIES', 1)

#=============================================================================

def ermhks(terr1):
      "Prints an error message (also saying the section name) and stops the program."
      terr1.insert(0, "   '%s':" % com.mhk)
      com.frw["mhk"].er("\n".join(terr1))

#=============================================================================

def wamhk (terr1):
      "Prints a warning (also saying the section name)."
      terr1.insert(0, '   %s' % com.mhk)
      com.frw["mhk"].wa("\n".join(terr1))

def xfrm(x, fs):
      "     ..   12+498.1  1+569  -9-522.22"
      MAXCHAR = 50
      try:    s = fs % x
      except: return '*' * MAXCHAR

      s = s.strip()
      n = int(x)
      if n < 1000: return s

      ch = '+'
      if x < 0.0: ch = '-'
      n = s.find('.')
      if n < 0: n = len(s)
      n -= 3
      return s[:n] + ch + s[n:]
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.