diff --git a/utils/examples/tragesym/at91rm9200-qu-002.src b/utils/examples/tragesym/at91rm9200-qu-002.src new file mode 100644 index 0000000..123f0be --- /dev/null +++ b/utils/examples/tragesym/at91rm9200-qu-002.src @@ -0,0 +1,293 @@ +# This is the template file for creating symbols with tragesym +# every line starting with '#' is a comment line. + +[options] +# wordswap swaps labels if the pin is on the right side an looks like this: +# "PB1 (CLK)". That's useful for micro controller port labels +# rotate_labels rotates the pintext of top and bottom pins +# this is useful for large symbols like FPGAs with more than 100 pins +# sort_labels will sort the pins by it's labels +# useful for address ports, busses, ... + +wordswap = yes +sort_labels = no +generate_pinseq = yes + +component_name_position = auto +refdes_position = auto +attribute_position = auto + +base_x = 100 +base_y = 100 + +pin_dist_horizontal = 300 +pin_dist_vertical = 300 +pin_length = 300 + +space_on_left = 2000 +space_on_bottom = 2000 +space_on_right = 2000 +space_on_top = 2000 + +just_on_left = middle +just_on_bottom = middle +just_on_right = middle +just_on_top = middle + +order_on_left = topbottom +order_on_bottom = leftright +order_on_right = bottomtop +order_on_top = rightleft + +dir_on_top = vertical +dir_on_bottom = vertical + +[geda_attr] +# name will be printed in the top of the symbol +# name is only some graphical text, not an attribute +# version specifies a gschem version. +# if you have a device with slots, you'll have to use slot= and slotdef= +# use comment= if there are special information you want to add +version=20060113 1 +name=AT91RM9200-QU-002 +device=AT91RM9200-QU-002 +refdes=U? +footprint=TQFP208_28 +description=ARM controller +documentation=http://www.atmel.com/dyn/resources/prod_documents/doc1768.pdf +author=sza2 +dist-license=GPL +use-license=GPL +numslots=0 +#slot=1 +#slotdef=1: +#slotdef=2: +#slotdef=3: +#slotdef=4: +#comment= +#comment= +#comment= + +[pins] +# tabseparated list of pin descriptions +# ---------------------------------------- +# pinnr is the physical number of the pin +# seq is the pinseq= attribute, leave it blank if it doesn't matter +# type can be (in, out, io, oc, oe, pas, tp, tri, clk, pwr) +# style can be (line,dot,clk,dotclk,none). none if only want to add a net +# posit. can be (l,r,t,b) or empty for nets +# net specifies the name of the net. Vcc or GND for example. +# label represents the pinlabel. +# negation lines can be added with "\_" example: \_enable\_ +# if you want to write a "\" use "\\" as escape sequence +#----------------------------------------------------- +#pinnr seq type style posit. net label +#----------------------------------------------------- +1 1 io line b PC24 D24 +2 1 io line b PC25 D25 +3 1 io line b PC26 D26 +4 1 io line b PC27 D27 +5 1 io line b PC28 D28 +6 1 io line b PC29 D29 +7 1 pwr line b VDDIOM +8 1 pwr line b GND +9 1 io line b PC30 D30 +10 1 io line b PC31 D31 +11 1 io line b PC10 NCS4/CFCS NCS4 +12 1 io line b PC11 NCS5/CFCE1 NCS5 +13 1 io line b PC12 NCS6/CFCE2 NCS6 +14 1 io line b PC13 NCS7 NCS7 +15 1 io line b PC14 +16 1 io line b PC15 +17 1 io line b PC0 BFCK +18 1 io line b PC1 BFRDY/SMOE +19 1 pwr line b VDDCORE +20 1 pwr line b GND +21 1 io line b PC2 BFAVD +22 1 io line b PC3 BFBAA/SMMWE +23 1 io line b PC4 BFOE +24 1 io line b PC5 BFWE +25 1 io line b PC6 NWAIT +26 1 pwr line b VDDIOM +27 1 pwr line b GND +28 1 pwr line b VDDPLL +29 1 in line b PLLRCA +30 1 pwr line b GNDPLL +31 1 out line b XOUT +32 1 in line b XIN +33 1 pwr line b VDDOSC +34 1 pwr line b GNDOSC +35 1 out line b XOUT32 +36 1 in line b XIN32 +37 1 pwr line b VDDPLL +38 1 in line b PLLRCB +39 1 pwr line b GNDPLL +40 1 pwr line b VDDIOP +41 1 pwr line b GND +42 1 io line b PA0 MISO PCK3 +43 1 io line b PA1 MOSI PCK0 +44 1 io line b PA2 SPCK IRQ4 +45 1 io line b PA3 NPCS0 IRQ5 +46 1 io line b PA4 NPCS1 PCK1 +47 1 io line b PA5 NPCS2 TXD3 +48 1 io line b PA6 NPCS3 RXD3 +49 1 io line b PA7 ETXCK/EREFCK PCK2 +50 1 io line b PA8 ETXEN MCCDB +51 1 io line b PA9 ETX0 MCDB0 +52 1 io line b PA10 ETX1 MCDB1 +53 1 io line r PA11 ECRS/ECRSDV MCDB2 +54 1 io line r PA12 ERX0 MCDB3 +55 1 io line r PA13 ERX1 TCLK0 +56 1 pwr line r VDDIOP +57 1 pwr line r GND +58 1 io line r PA14 ERXER TCLK1 +59 1 io line r PA15 EMDC TCLK2 +60 1 io line r PA16 EMDIO IRQ6 +61 1 io line r PA17 TXD0 TIOA0 +62 1 pwr line r VDDCORE +63 1 pwr line r GND +64 1 io line r PA18 RXD0 TIOB0 +65 1 io line r PA19 SCK0 TIOA1 +66 1 io line r PA20 CTS0 TIOB1 +67 1 io line r PA21 RTS0 TIOA2 +68 1 io line r PA22 RXD2 TIOB2 +69 1 io line r PA23 TXD2 IRQ3 +70 1 io line r PA24 SCK2 PCK1 +71 1 io line r PA25 TWD IRQ2 +72 1 io line r PA26 TWCK IRQ1 +73 1 io line r PA27 MCCK TCLK3 +74 1 io line r PA28 MCCDA TCLK4 +75 1 pwr line r VDDIOP +76 1 pwr line r GND +77 1 io line r PA29 MCDA0 TCLK5 +78 1 io line r PA30 DRXD CTS2 +79 1 io line r PA31/BMS DTXD RTS2 +80 1 io line r PB0 TF0 RTS3 +81 1 io line r PB1 TK0 CTS3 +82 1 io line r PB2 TD0 SCK3 +83 1 io line r PB3 RD0 MCDA1 +84 1 io line r PB4 RK0 MCDA2 +85 1 io line r PB5 RF0 MCDA3 +86 1 io line r PB6 TF1 TIOA3 +87 1 io line r PB7 TK1 TIOB3 +88 1 io line r PB8 TD1 TIOA4 +89 1 io line r PB9 RD1 TIOB4 +90 1 io line r PB10 RK1 TIOA5 +91 1 io line r PB11 RF1 TIOB5 +92 1 io line r PB12 TF2 ETX2 +93 1 pwr line r VDDIOP +94 1 pwr line r GND +95 1 io line r PB13 TK2 ETX3 +96 1 io line r PB14 TD2 ETXER +97 1 io line r PB15 RD2 ERX2 +98 1 io line r PB16 RK2 ERX3 +99 1 io line r PB17 RF2 ERXDV +100 1 io line r PB18 RI1 ECOL +101 1 io line r PB19 DTR1 ERXCK +102 1 io line r PB20 TXD1 +103 1 io line r PB21 RXD1 +104 1 io line r PB22 SCK1 +105 1 in line t JTAGSEL +106 1 in line t TDI +107 1 out line t TDO +108 1 in line t TCK +109 1 in line t TMS +110 1 in line t NTRST +111 1 pwr line t VDDIOP +112 1 pwr line t GND +113 1 in line t TST0 +114 1 in line t TST1 +115 1 in line t NRST +116 1 pwr line t VDDCORE +117 1 pwr line t GND +118 1 io line t PB23 DCD1 +119 1 io line t PB24 CTS1 +120 1 io line t PB25 DSR1 EF100 +121 1 io line t PB26 RTS1 +122 1 io line t PB27 PCK0 +123 1 io line t PB28 FIQ +124 1 io line t PB29 IRQ0 +125 1 io line t HDMA +126 1 io line t HDPA +127 1 io line t DDM +128 1 io line t DDP +129 1 pwr line t VDDIOP +130 1 pwr line t GND +131 1 pwr line t VDDIOM +132 1 pwr line t GND +133 1 out line t A0/NBS0 +134 1 out line t A1/NBS2/NWR2 +135 1 out line t A2 +136 1 out line t A3 +137 1 out line t A4 +138 1 out line t A5 +139 1 out line t A6 +140 1 out line t A7 +141 1 out line t A8 +142 1 out line t A9 +143 1 out line t A10 +144 1 out line t SDA10 +145 1 out line t A11 +146 1 pwr line t VDDIOM +147 1 pwr line t GND +148 1 out line t A12 +149 1 out line t A13 +150 1 out line t A14 +151 1 out line t A15 +152 1 pwr line t VDDCORE +153 1 pwr line t GND +154 1 out line t A16/BA0 +155 1 out line t A17/BA1 +156 1 out line t A18 +157 1 out line l A19 +158 1 out line l A20 +159 1 out line l A21 +160 1 out line l A22 +161 1 io line l PC7 A23 A23 +162 1 io line l PC8 A24 A24 +163 1 io line l PC9 A25/CFRNW A25 +164 1 pwr line l VDDIOM +165 1 pwr line l GND +166 1 out line l NCS0/BFCS +167 1 out line l NCS1/SDCS +168 1 out line l NCS2 +169 1 out line l NCS3/SMCS +170 1 out line l NRD/NOE/CFOE +171 1 out line l NWR0/NWE/CFWE +172 1 out line l NWR1/NBS1/CFIOR +173 1 out line l NWR3/NBS3/CFIOW +174 1 out line l SDCK +175 1 out line l SDCKE +176 1 out line l RAS +177 1 out line l CAS +178 1 out line l SDWE +179 1 io line l D0 +180 1 io line l D1 +181 1 io line l D2 +182 1 io line l D3 +183 1 pwr line l VDDIOM +184 1 pwr line l GND +185 1 io line l D4 +186 1 io line l D5 +187 1 io line l D6 +188 1 pwr line l VDDCORE +189 1 pwr line l GND +190 1 io line l D7 +191 1 io line l D8 +192 1 io line l D9 +193 1 io line l D10 +194 1 io line l D11 +195 1 io line l D12 +196 1 io line l D13 +197 1 io line l D14 +198 1 io line l D15 +199 1 pwr line l VDDIOM +200 1 pwr line l GND +201 1 io line l PC16 D16 +202 1 io line l PC17 D17 +203 1 io line l PC18 D18 +204 1 io line l PC19 D19 +205 1 io line l PC20 D20 +206 1 io line l PC21 D21 +207 1 io line l PC22 D22 +208 1 io line l PC23 D23 diff --git a/utils/examples/tragesym/k9f1g08u0a-pcbt.src b/utils/examples/tragesym/k9f1g08u0a-pcbt.src new file mode 100644 index 0000000..362aa72 --- /dev/null +++ b/utils/examples/tragesym/k9f1g08u0a-pcbt.src @@ -0,0 +1,104 @@ +# This is the template file for creating symbols with tragesym +# every line starting with '#' is a comment line. + +[options] +# wordswap swaps labels if the pin is on the right side an looks like this: +# "PB1 (CLK)". That's useful for micro controller port labels +# rotate_labels rotates the pintext of top and bottom pins +# this is useful for large symbols like FPGAs with more than 100 pins +# sort_labels will sort the pins by it's labels +# useful for address ports, busses, ... + +wordswap = yes +sort_labels = no +generate_pinseq = yes + +component_name_position = auto +refdes_position = auto +attribute_position = auto + +base_x = 100 +base_y = 100 + +pin_dist_horizontal = 400 +pin_dist_vertical = 400 +pin_length = 300 + +space_on_left = 1200 +space_on_bottom = 400 +space_on_right = 1200 +space_on_top = 400 + +just_on_left = top +just_on_bottom = middle +just_on_right = top +just_on_top = middle + +order_on_left = topbottom +order_on_bottom = leftright +order_on_right = topbottom +order_on_top = leftright + +dir_on_top = horizontal +dir_on_bottom = horizontal + +[geda_attr] +# name will be printed in the top of the symbol +# name is only some graphical text, not an attribute +# version specifies a gschem version. +# if you have a device with slots, you'll have to use slot= and slotdef= +# use comment= if there are special information you want to add +version=20060113 1 +name=K9F1G08U0A +device=K9F1G08U0A +refdes=U? +footprint=TSSOP48 +description=128MX8Bit NAND Flash Memory +documentation=http://pdf1.alldatasheet.com/datasheet-pdf/view/84340/SAMSUNG/K9F1G08U0A/datasheet.pdf +author=sza2 +dist-license=GPL +use-license=GPL +numslots=0 +#slot=1 +#slotdef=1: +#slotdef=2: +#slotdef=3: +#slotdef=4: +#comment= +#comment= +#comment= + +[pins] +# tabseparated list of pin descriptions +# ---------------------------------------- +# pinnr is the physical number of the pin +# seq is the pinseq= attribute, leave it blank if it doesn't matter +# type can be (in, out, io, oc, oe, pas, tp, tri, clk, pwr) +# style can be (line,dot,clk,dotclk,none). none if only want to add a net +# posit. can be (l,r,t,b) or empty for nets +# net specifies the name of the net. Vcc or GND for example. +# label represents the pinlabel. +# negation lines can be added with "\_" example: \_enable\_ +# if you want to write a "\" use "\\" as escape sequence +#----------------------------------------------------- +#pinnr seq type style posit. net label +#----------------------------------------------------- +12 1 pwr line t VCC +37 1 pwr line t VCC +13 1 pwr line b VSS +36 1 pwr line b VSS +7 1 out line l R/\_B\_ +8 1 in line l \_RE\_ +9 1 in line l \_CE\_ +16 1 in line l CLE +17 1 in line l ALE +18 1 in line l \_WE\_ +19 1 in line l \_WP\_ +29 1 io line r IO0 +30 1 io line r IO1 +31 1 io line r IO2 +32 1 io line r IO3 +41 1 io line r IO4 +42 1 io line r IO5 +43 1 io line r IO6 +44 1 io line r IO7 diff --git a/utils/scripts/tragesym b/utils/scripts/tragesym index 9becd83..ffd383d 100755 --- a/utils/scripts/tragesym +++ b/utils/scripts/tragesym @@ -5,6 +5,39 @@ # begin : 2001-10-20 # copyright : (C) 2001,2002,2003,2004,2006,2007 by Werner Hoch # email : werner.ho@gmx.de +# +############################################################################ +# modified (rewritten) by: Tamas Szabo +# email : huszabot _@_ freemail . hu +# +# Major modifications (as of 2007/10/11) +# +# - making possible to create ICs with round pin numbering +# - new / modified options for fine tune +# - option names changed to represent the meaning (maybe) more clearly +# - some code beautifying ( TABs -> spaces, etc) +# - NOT compatible with the original +# +# Options: +# +# - wordswap, sort_labels, generate_pinseq as original +# - component_name_position, refdes_position: [ auto | top | center ] +# - attribute_position: [ auto | left | right ] +# - base_x, base_y: x / y offset for the symbol +# - pin_dist_XXX: distance between pins +# - pin_length: length of bin +# - space_on_XXX: space between the given edge of the box and first pin +# - just_on_XXX: justification if pin number on the opposite side greater +# left, right: [ middle | top | bottom ] +# bottom, top: [ middle | left| right ] +# - order_on_XXX: pin ordering on the selected side +# left, right: [ topbottom | bottomtop ] +# bottom, top: [ leftright | rightleft ] +# - dir_on_XXX: select the direction of text of pin on top and bottom +# [ horizontal | vertical ] +# notice: horizontal can be unsuitable for long names / multiple +# function pins +# ############################################################################ # # # This program is free software; you can redistribute it and/or modify # @@ -20,9 +53,6 @@ # - swap words of the pinlabels # - negation lines if label is in "_","\" is for escape # - rotate top and bottom pinlabels if wished -# - if the symbol's width specified is 0, then tragesym calculates the -# symbol width based on the greater number of pins at the top or at the -# bottom of the symbol # TODO: # - make a nicer comandline interface including stdin /stdout @@ -31,49 +61,87 @@ import sys, string ##################### GLOBALS ############################################ -VERSION="0.0.11" - -CHARHIGH=26 -preset_options = {"wordswap":"yes", - "rotate_labels":"no", - "sort_labels":"yes", - "generate_pinseq":"yes", - "sym_width":"1400", - "pinwidthvertikal":"400", - "pinwidthvertical":"400", - "pinwidthhorizontal":"400"} -allowed_attr = ["version", "name", "device", "refdes", "footprint", "numslots", - "slot", "slotdef","description", "comment", "author", - "documentation","value","dist-license", "use-license"] -single_attr_warning = ["device", "footprint", "author", "documentation", - "description", "numslots","dist-license", "use-license"] +VERSION = "0.0.11" + +P_NR, P_SEQ, P_TYPE, P_STYLE, P_DIR, P_NET, P_LABEL = 0, 1, 2, 3, 4, 5, 6 + +preset_options = { + "wordswap" : "yes", + "sort_labels" : "no", + "generate_pinseq" : "yes", + + "component_name_position" : "auto", + "refdes_position" : "auto", + "attribute_position" : "auto", + + "base_x" : "100", + "base_y" : "100", + + "pin_dist_horizontal" : "400", + "pin_dist_vertical" : "400", + "pin_length" : "300", + + "space_on_left" : "1500", + "space_on_bottom" : "300", + "space_on_right" : "1500", + "space_on_top" : "300", + + "just_on_left" : "middle", + "just_on_bottom" : "middle", + "just_on_right" : "middle", + "just_on_top" : "middle", + + "order_on_left" : "topbottom", + "order_on_bottom" : "leftright", + "order_on_right" : "topbottom", + "order_on_top" : "leftright", + + "dir_on_bottom" : "horizontal", + "dir_on_top" : "horizontal" +} + +allowed_attr = [ + "version", "name", "device", "refdes", "footprint", "numslots", + "slot", "slotdef", "description", "comment", "author", + "documentation", "value", "dist-license", "use-license"] + +single_attr_warning = [ + "device", "footprint", "author", "documentation", + "description", "numslots", "dist-license", "use-license" +] + single_attr = ["slot"] + multiple_attr = ["slotdef", "comment"] -stylelist = ["line","dot","clk","dotclk","none"] -poslist = ["l","r","t","b",""] -typelist = ["in","out","io","oc","oe","pas","tp","tri","clk","pwr"] -P_NR, P_SEQ, P_TYPE, P_STYLE, P_POS, P_NET, P_LABEL = 0,1,2,3,4,5,6 + +stylelist = ["line", "dot", "clk", "dotclk", "none"] + +poslist = ["l", "r", "t", "b", ""] + +typelist = ["in", "out", "io", "oc", "oe", "pas", "tp", "tri", "clk", "pwr"] + +P_NR, P_SEQ, P_TYPE, P_STYLE, P_DIR, P_NET, P_LABEL = 0, 1, 2, 3, 4, 5, 6 ################################# FUNCTIONS ############################## def parselabel(str): '''returns a stripped label without overbar markers "\_"''' - slash, neg= 0, 0 - textout="" + slash, neg = 0, 0 + textout = "" for letter in str: if letter == '\\' and slash == 0: - slash=1 + slash = 1 elif slash == 1 and letter == '_': if neg == 0: neg = 1 else: neg = 0 - slash = 0 + slash = 0 else: - textout=textout+letter + textout = textout + letter slash = 0 - + if slash == 1 or neg == 1: print '''unbalanced overbars or escapesequence: ''', str print '''the overbar starts and ends with "\_" example: \"\_enable\_''' @@ -82,33 +150,33 @@ def parselabel(str): return textout ## round *unsigned* integer x to closest r -def round_closest(x,r): - return x-(x+r/2)%r+r/2 +def round_closest(x, r): + return x - (x + r / 2) % r + r / 2 -## returns the words in reverse order -def swapwords(str): - list=string.split(str," ") - back=list[0] +## returns the words in reverse order +def swapwords(str): + list = string.split(str, " ") + back = list[0] for i in list[1:]: - back=i+" "+back + back = i + " " + back return back ## make the parser more tolerant to the input file def type_translate(str): if str == "i/o": - str="io" + str = "io" elif str == "i": - str="in" + str = "in" elif str == "o": - str="out" + str = "out" elif str == "p": - str="pas" + str = "pas" return str ## split a string at the first tab or equal char -def split_tab_equal(str,n=1): - list_tab=string.split(str,'\t',n) - list_equal=string.split(str,'=',n) +def split_tab_equal(str, n = 1): + list_tab = string.split(str, '\t', n) + list_equal = string.split(str, '=', n) if len(list_tab[0]) < len(list_equal[0]): return list_tab else: @@ -116,38 +184,38 @@ def split_tab_equal(str,n=1): ## returns 2 dicts: (options, attr) and 2 arrays: (devices, pins) def readsrc(filename): - geda_attr={} - options={} - pins=[] - f = open(filename,"r") - content= f.readlines() - section="" - linenr=0 + geda_attr = {} + options = {} + pins = [] + f = open(filename, "r") + content = f.readlines() + section = "" + linenr = 0 for line in content: - linenr=linenr+1 - if line[0]=="[": # find a section - section=string.split(line[1:],"]")[0] + linenr = linenr + 1 + if line[0] == "[": # find a section + section = string.split(line[1:], "]")[0] continue - elif section=="" or line[0]=="#" \ - or len(string.strip(line)) == 0: # comment, empty line or no section + elif section == "" or line[0] == "#" \ + or len(string.strip(line)) == 0: # comment, empty line or no section continue - if section=="options": - element=split_tab_equal(line,1) + if section == "options": + element = split_tab_equal(line, 1) if len(element) > 1: - options[string.strip(element[0])]=string.strip(element[1]) - elif section=="geda_attr": - element=split_tab_equal(line,1) - nr=1 - while geda_attr.has_key((element[0],nr)): - nr=nr+1 - geda_attr[(string.strip(element[0]),nr)]=string.strip(element[1]) - elif section=="pins": - element=string.split(line,"\t") + options[string.strip(element[0])] = string.strip(element[1]) + elif section == "geda_attr": + element = split_tab_equal(line, 1) + nr = 1 + while geda_attr.has_key((element[0], nr)): + nr += 1 + geda_attr[(string.strip(element[0]), nr)] = string.strip(element[1]) + elif section == "pins": + element = string.split(line,"\t") if len(element) > 2: for j in xrange(len(element)): - element[j]=string.strip(element[j]) - if j in [P_TYPE,P_POS,P_STYLE]: - element[j]= string.lower(element[j]) + element[j] = string.strip(element[j]) + if j in [P_TYPE, P_DIR, P_STYLE]: + element[j] = string.lower(element[j]) if j == P_TYPE: element[j] = type_translate(element[j]) while len(element) < 7: @@ -160,19 +228,18 @@ def readsrc(filename): def checkpins(pinlist): for pin in pinlist: - if (pin[P_STYLE]=="spacer"): - if (pin[P_POS] == ""): - print "There must be a position with a spacer.\n" - sys.exit() - if pin[P_POS] not in poslist: - print "Position is not allowed: \n", pin - sys.exit() - continue + if (pin[P_STYLE] == "spacer"): + if (pin[P_DIR] == ""): + print "There must be a position with a spacer.\n" + sys.exit() + if pin[P_DIR] not in poslist: + print "Position is not allowed: \n", pin + sys.exit() if pin[P_STYLE] != "none": if pin[P_SEQ].isdigit(): string.atoi(pin[P_SEQ]) else: - print "pinseq needs to be a number: \n", pin + print "Pinseq needs to be a number: \n", pin sys.exit() if pin[P_TYPE] not in typelist: print "Pintype not allowed: \n", pin @@ -180,40 +247,40 @@ def checkpins(pinlist): if pin[P_STYLE] not in stylelist: print "Style is not allowed: \n", pin sys.exit() - if pin[P_POS] not in poslist: + if pin[P_DIR] not in poslist: print "Position is not allowed: \n", pin sys.exit() - if pin[P_POS] == "" and pin[P_NET] == "": + if pin[P_DIR] == "" and pin[P_NET] == "": print "There must be either position or a netlabel: \n", pin sys.exit() def checkattr(attr): - for attr,value in attr.items(): - attr,nr=attr + for attr, value in attr.items(): + attr, nr = attr if attr not in allowed_attr: - print "this attribute is not allowed: ", attr, value + print "This attribute is not allowed: ", attr, value sys.exit() ## makes a list out of a string: "3abc345x?" --> ["","3","abc","345","x?"] def splitspecial(str): - isletter=1 - list=[""] + isletter = 1 + list = [""] for letter in str: if letter not in string.digits: if isletter == 1: - list[-1]=list[-1] + letter + list[-1] = list[-1] + letter else: list.append(letter) - isletter=1 + isletter = 1 else: if isletter == 0: - list[-1]=list[-1] + letter + list[-1] = list[-1] + letter else: list.append(letter) - isletter=0 + isletter = 0 return list - -def pinsort(pin1,pin2): + +def pinsort(pin1, pin2): ## rules: nets first, positions second, labels last ## net if pin1[P_NET] != "" and pin2[P_NET] != "": @@ -223,9 +290,9 @@ def pinsort(pin1,pin2): elif pin1[P_NET] != "": return -1 ## position - if pin1[P_POS] > pin2[P_POS]: + if pin1[P_DIR] > pin2[P_DIR]: return -1 - elif pin1[P_POS] < pin2[P_POS]: + elif pin1[P_DIR] < pin2[P_DIR]: return 1 ## pinlabel label1 = parselabel(pin1[P_LABEL]) @@ -237,295 +304,305 @@ def pinsort(pin1,pin2): minlen = len(l2) for i in xrange(minlen): if i % 2 == 1: - ret= sort(string.atoi(l1[i]),string.atoi(l2[i])) + ret = sort(string.atoi(l1[i]), string.atoi(l2[i])) else: - ret= sort(l1[i],l2[i]) + ret = sort(l1[i], l2[i]) if ret != 0: return ret - ret=sort(len(l1),len(l2)) + ret = sort(len(l1), len(l2)) return ret -def sort(item1,item2): +def sort(item1, item2): if item1 < item2: return -1 elif item1 > item2: return 1 return 0 -def writesym(filename,options,attr,pins): - o_symwidth=string.atoi(options["sym_width"]) - o_hdist=string.atoi(options["pinwidthhorizontal"]) - - # If pinwidthvertikal was defined, use it, else use pinwidthvertical - # This keeps compatibility with older versions, while fixing the spell - # bug - if options["pinwidthvertikal"] != preset_options["pinwidthvertikal"]: - o_vdist=string.atoi(options["pinwidthvertikal"]) +def writesym_pin_terminal(symfile, pos_x, pos_y, direction, + type, length): + if type == "dot" or type == "dotclk": + offs = 100 else: - o_vdist=string.atoi(options["pinwidthvertical"]) - - o_wordswap=options["wordswap"] - o_rotate=options["rotate_labels"] - o_sort=options["sort_labels"] - - pinlength = 300 - -### Count the number of pins in each side - - numpleft=0 - numpright=0 - numpbottom=0 - numptop = 0 - for pin in pins: - if pin[P_POS] == "l": # left pin - numpleft=numpleft+1 - elif pin[P_POS] == "r": #right pin - numpright=numpright+1 - elif pin[P_POS] == "b": #right pin - numpbottom=numpbottom+1 - elif pin[P_POS] == "t": #right pin - numptop=numptop+1 - - # Calculate the position of the pins in the left and right side. - plefty, prighty = 0, 0 - if numpleft > numpright: - plefty=plefty+(numpleft-1)*o_vdist - prighty = plefty - else : - prighty=prighty+(numpright-1)*o_vdist - plefty = prighty - - # Calculate the bottom left of the box - bottomleftx, bottomlefty = pinlength + 100, 100 ## bottom left of the box - if numpbottom > 0: - bottomlefty += pinlength - - # Calculate the minimum symwidth and increase it if necessary - calculated_top_symwidth=(numptop-1)*o_hdist+2*o_hdist - calculated_bottom_symwidth=(numpbottom-1)*o_hdist+2*o_hdist - - calcutated_symwidth = max(calculated_bottom_symwidth, - calculated_top_symwidth) + offs = 0 + if direction == "l": + x0, y0, x1, y1 = pos_x - length, pos_y, pos_x - offs, pos_y + elif direction == "r": + x0, y0, x1, y1 = pos_x + length, pos_y, pos_x + offs, pos_y + elif direction == "b": + x0, y0, x1, y1 = pos_x, pos_y - length, pos_x, pos_y - offs + elif direction == "t": + x0, y0, x1, y1 = pos_x, pos_y + length, pos_x, pos_y + offs + else: + print "error: pin direction should be l, r, b or t\n" + sys.exit() + symfile.write("P %i" %x0 + " %i" %y0 + " %i" %x1 + " %i" %y1 + " 1 0 0\n") + symfile.write("{\n") + return 0 - if (numptop + numpbottom > 0): - print "note: use sym_width to adjust symbol width if texts overlap." +def writesym_pin_number(symfile, pos_x, pos_y, direction, + orientation, pinnumber): + if direction == "l": + x, y, o, i = pos_x - 100, pos_y + 50, 0, 6 + elif direction == "r": + x, y, o, i = pos_x + 100, pos_y + 50, 0, 0 + elif direction == "b": + if orientation == "horizontal": + x, y, o, i = pos_x - 50, pos_y - 100, 0, 8 + elif orientation == "vertical": + x, y, o, i = pos_x - 50, pos_y - 100, 90, 6 + else: + print "error: pinnumber orientation should be " \ + "horizontal or vertical\n" + elif direction == "t": + if orientation == "horizontal": + x, y, o, i = pos_x - 50, pos_y + 100, 0, 6 + elif orientation == "vertical": + x, y, o, i = pos_x - 50, pos_y + 100, 90, 0 + else: + print "error: pinnumber orientation should be " \ + "horizontal or vertical\n" + else: + print "error: pinnumber direction should be l, r, b or t\n" + sys.exit() + symfile.write("T %i" %x + " %i" %y + " 5 8 1 1 %i" %o + " %i" %i + " 1\n") + symfile.write("pinnumber=" + pinnumber + "\n") + return 0 - if o_symwidth == 0: - o_symwidth = calculated_symwidth +def writesym_pin_label(symfile, pos_x, pos_y, direction, + type, orientation, label, wordswap): + if type == "clk" or type == "dotclk": + offs = 100 + else: + offs = 0 + if direction == "l": + x, y, o, i = pos_x + 100 + offs, pos_y, 0, 1 + elif direction == "r": + if wordswap == "yes": + label = swapwords(label) + x, y, o, i = pos_x - 100 - offs, pos_y, 0, 7 + elif direction == "b": + if orientation == "horizontal": + x, y, o, i = pos_x, pos_y + 100 + offs, 0, 3 + elif orientation == "vertical": + x, y, o, i = pos_x, pos_y + 100 + offs, 90, 1 + else: + print "error: pin label orientation should be " \ + "horizontal or vertical\n" + elif direction == "t": + if wordswap == "yes": + label = swapwords(label) + if orientation == "horizontal": + x, y, o, i = pos_x, pos_y - 100 - offs, 0, 5 + elif orientation == "vertical": + x, y, o, i = pos_x, pos_y - 100 - offs, 90, 7 + else: + print "error: pin label orientation should be " \ + "horizontal or vertical\n" + else: + print "error: pinnumber direction should be l, r, b or t\n" + sys.exit() + symfile.write("T %i" %x + " %i" %y + " 9 8 1 1 %i" %o + " %i" %i + " 1\n") + symfile.write("pinlabel=" + label + "\n") + return 0 - # Calculate the symbol's high - if numpleft < numpright: - high=(numpright+1)*o_vdist +def writesym_pin_type(symfile, pos_x, pos_y, direction, + type, orientation, label): + if type == "clk" or type == "dotclk": + offs = 100 else: - high=(numpleft+1)*o_vdist - topy = bottomlefty + high + offs = 0 + if direction == "l": + x, y, o, i = pos_x + 100 + offs, pos_y + 150, 0, 1 + elif direction == "r": + x, y, o, i = pos_x - 100 - offs, pos_y + 150, 0, 7 + elif direction == "b": + if orientation == "horizontal": + x, y, o, i = pos_x, pos_y + 250 + offs, 0, 3 + elif orientation == "vertical": + x, y, o, i = pos_x - 150, pos_y + 100 + offs, 90, 1 + else: + print "error: pin label orientation should be " \ + "horizontal or vertical\n" + elif direction == "t": + if orientation == "horizontal": + x, y, o, i = pos_x, pos_y - 250 - offs, 0, 5 + elif orientation == "vertical": + x, y, o, i = pos_x + 150, pos_y - 100 - offs, 90, 7 + else: + print "error: pin label orientation should be " \ + "horizontal or vertical\n" + else: + print "error: pinnumber direction should be l, r, b or t\n" + sys.exit() + symfile.write("T %i" %x + " %i" %y + " 5 8 0 1 %i" %o + " %i" %i + " 1\n") + symfile.write("pintype=" + label + "\n") + return 0 - # Calculate the position of several items. - prightx, prighty= bottomleftx + pinlength + o_symwidth, prighty + bottomlefty + o_vdist - pleftx, plefty= bottomleftx - pinlength, plefty + bottomlefty + o_vdist - ptopx, ptopy= bottomleftx + o_hdist, bottomlefty + high + pinlength - pbottomx, pbottomy = bottomleftx + o_hdist, bottomlefty - pinlength +def writesym_pin_seq(symfile, pos_x, pos_y, direction, + type, orientation, label): + if type == "clk" or type == "dotclk": + offs = 100 + else: + offs = 0 + if direction == "l": + x, y, o, i = pos_x + 100 + offs, pos_y - 125, 0, 1 + elif direction == "r": + x, y, o, i = pos_x - 100 - offs, pos_y - 125, 0, 7 + elif direction == "b": + if orientation == "horizontal": + x, y, o, i = pos_x, pos_y + 400 + offs, 0, 3 + elif orientation == "vertical": + x, y, o, i = pos_x + 125, pos_y + 100 + offs, 90, 1 + else: + print "error: pin label orientation should be " \ + "horizontal or vertical\n" + elif direction == "t": + if orientation == "horizontal": + x, y, o, i = pos_x, pos_y - 400 - offs, 0, 5 + elif orientation == "vertical": + x, y, o, i = pos_x - 125, pos_y - 100 - offs, 90, 7 + else: + print "error: pin label orientation should be " \ + "horizontal or vertical\n" + else: + print "error: pinnumber direction should be l, r, b or t\n" + sys.exit() + symfile.write("T %i" %x + " %i" %y + " 5 8 0 1 %i" %o + " %i" %i + " 1\n") + symfile.write("pinseq=" + label + "\n") + return 0 - # Lets add some pad if sym_width was defined - ptopx = ptopx + (o_symwidth - calculated_top_symwidth) / 2 - pbottomx = pbottomx + (o_symwidth - calculated_bottom_symwidth) / 2 +def writesym_pin_negation(symfile, pos_x, pos_y, direction, + type): + if type != "dot" and type != "dotclk": + return 0 + if direction == "l": + x, y = pos_x - 50, pos_y + elif direction == "r": + x, y = pos_x + 50, pos_y + elif direction == "b": + x, y = pos_x, pos_y - 50 + elif direction == "t": + x, y = pos_x, pos_y + 50 + else: + print "error: negation bubble direction should be l, r, b or t\n" + sys.exit() + symfile.write("V %i" %x + " %i" %y + " 50 6 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n") + return 0 - ptopx = round_closest(ptopx, 100) - pbottomx = round_closest(pbottomx, 100) +def writesym_pin_clocksign(symfile, pos_x, pos_y, direction, type): + if type != "clk" and type != "dotclk": + return 0 - f = open(filename, "w") - -### Draw the symbol version - if attr.has_key(("version",1)): - value=attr[("version",1)] - f.write("v " + value + " 1\n") + if direction == "l": + xa0, ya0, xa1, ya1 = pos_x, pos_y + 75, pos_x + 100, pos_y + xb0, yb0, xb1, yb1 = pos_x, pos_y - 75, pos_x + 100, pos_y + elif direction == "r": + xa0, ya0, xa1, ya1 = pos_x, pos_y + 75, pos_x - 100, pos_y + xb0, yb0, xb1, yb1 = pos_x, pos_y - 75, pos_x - 100, pos_y + elif direction == "b": + xa0, ya0, xa1, ya1 = pos_x + 75, pos_y, pos_x, pos_y + 100 + xb0, yb0, xb1, yb1 = pos_x - 75, pos_y, pos_x, pos_y + 100 + elif direction == "t": + xa0, ya0, xa1, ya1 = pos_x + 75, pos_y, pos_x, pos_y - 100 + xb0, yb0, xb1, yb1 = pos_x - 75, pos_y, pos_x, pos_y - 100 else: - print "error: version attribut missing" + print "error: clocksign direction should be l, r, b or t\n" sys.exit() - - if o_sort == "yes": - pins.sort(pinsort) + symfile.write("L %i" %xa0 + " %i" %ya0 + " %i" %xa1 + " %i" %ya1 + + " 3 0 0 0 -1 -1\n") + symfile.write("L %i" %xb0 + " %i" %yb0 + " %i" %xb1 + " %i" %yb1 + + " 3 0 0 0 -1 -1\n") + return 0 - for pin in pins: - if pin[P_STYLE] == "none": # - continue -### decide which pindirection to use - ## TODO: put all constants into a dictionary - if pin[P_POS] == "l": #left pin - basex, basey= pleftx, plefty #where to draw this pin - xf, yf= 1, 0 # orientation factors - pint=(200,50,6,0) # dx, dy, alignment, angle - pinl=(350,0,0,0) # """" - pina=(350,0,2,0) # """" - pinq=(200,-50,8,0) # """" - negl=(0, CHARHIGH*4+20,0,0) # dx,dy,vert,rotate (base is label) - swap=0 # swap words in label ? - plefty=plefty - o_vdist #where to draw the _next_ pin - elif pin[P_POS] == "r": #right pin - basex, basey = prightx, prighty - xf, yf= -1, 0 - pint=(-200,50,0,0) - pinl=(-350,0,6,0) - pina=(-350,0,8,0) - pinq=(-200,-50,2,0) - negl=(0, CHARHIGH*4+20,2,0) - swap=1 - prighty=prighty - o_vdist - elif pin[P_POS] == "b": # bottom pin - basex, basey=pbottomx, pbottomy - xf, yf= 0, 1 - if o_rotate == "yes": # bottom pin with 90° text - pint=(-50,200,6,90) - pinl=(0,350,0,90) - pina=(0,350,2,90) - pinq=(50,200,8,90) - negl=(CHARHIGH*4+20,0,0,1) - else: - pint=(50,100,0,0) - pinl=(0,350,3,0) - pina=(0,500,3,0) - pinq=(50,100,2,0) - negl=(0,CHARHIGH*4+20,1,0) - swap=0 - pbottomx=pbottomx + o_hdist - elif pin[P_POS] == "t": # top pin - basex, basey=ptopx, ptopy - xf, yf= 0, -1 - if o_rotate == "yes": # with 90° text - pint=(-50,-200,0,90) - pinl=(0,-350,6,90) - pina=(0,-350,8,90) - pinq=(50,-200,2,90) - negl=(CHARHIGH*4+20,0,2,1) - swap=1 - else: - pint=(50,-200,0,0) - pinl=(0,-350,5,0) - pina=(0,-500,5,0) - pinq=(50,-200,2,0) - negl=(0,20,1,0) - swap=0 - ptopx=ptopx + o_hdist - if (pin[P_STYLE]=="spacer"): - continue -### draw the pin - if (pin[P_STYLE]=="dot" or #short pin and dot? - pin[P_STYLE]=="dotclk"): - x=basex + xf*200 - y=basey + yf*200 - else: - x=basex + xf*300 - y=basey + yf*300 - f.write("P %i"%basex+" %i"%basey+" %i"%x + " %i"%y+ " 1 0 0\n") - f.write("{\n") -### draw pinnumber - pintx, pinty, pinta, pintr=pint - x=basex+pintx - y=basey+pinty - if pin[P_POS] == "t": # top pin - y += 50 - f.write("T %i"%x+" %i"%y+" 5 8 1 1 %i"%pintr+" %i 1\n"%pinta) - f.write("pinnumber="+pin[P_NR]+"\n") -### draw pinseq - pintx, pinty, pinta, pintr=pinq - x=basex+pintx - y=basey+pinty - if pin[P_POS] == "t": # top pin - y += 50 - f.write("T %i"%x+" %i"%y+" 5 8 0 1 %i"%pintr+" %i 1\n"%pinta) - f.write("pinseq="+pin[P_SEQ]+"\n") -### draw pinlabel and pintype - pinlx, pinly, pinla, pinlr=pinl - pinax, pinay, pinaa, pinar=pina - if (pin[P_STYLE]=="clk" or #move label if clocksign - pin[P_STYLE]=="dotclk"): - pinlx=pinlx + xf*75 - pinly=pinly + yf*75 - pinax=pinax + xf*75 - pinay=pinay + yf*75 - pinlx=pinlx + basex - pinly=pinly + basey - pinax=pinax + basex - pinay=pinay + basey - if o_wordswap=="yes" and swap==1: - label=swapwords(pin[P_LABEL]) - else: - label=pin[P_LABEL] - f.write("T %i"%pinlx+" %i"%pinly+" 9 8 1 1 %i"%pinlr+" %i 1\n"%pinla) - f.write("pinlabel="+label+"\n") - f.write("T %i"%pinax+" %i"%pinay+" 5 8 0 1 %i"%pinar+" %i 1\n"%pinaa) - f.write("pintype="+pin[P_TYPE]+"\n") - f.write("}\n") -### draw the negation bubble - if (pin[P_STYLE]=="dot" or pin[P_STYLE]=="dotclk"): - x=basex + xf*250 - y=basey + yf*250 - f.write("V %i"%x+" %i"%y +" 50 6 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n") -### draw the clocksign - if (pin[P_STYLE]=="clk" or - pin[P_STYLE]=="dotclk"): - x1=basex+ xf*400 - y1=basey+ yf*400 - x2=x1- xf*100 +yf*75 - y2=y1- yf*100 +xf*75 - x3=x1- xf*100 -yf*75 - y3=y1- yf*100 -xf*75 - f.write("L %i"%x1+" %i"%y1+" %i"%x2+" %i"%y2 + " 3 0 0 0 -1 -1\n") - f.write("L %i"%x1+" %i"%y1+" %i"%x3+" %i"%y3 + " 3 0 0 0 -1 -1\n") -### draw a box - f.write("B %i"%bottomleftx+" %i"%bottomlefty+" %i"%o_symwidth+" %i"%high+ - " 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n") +def writesym_pin_finish(symfile): + symfile.write("}\n") + +def writesym_pin(symfile, pos_x, pos_y, direction, + orientation, length, number, label, type, seq, wordswap): + if type == "none" or type == "spacer": + return + writesym_pin_terminal(symfile, pos_x, pos_y, direction, type, length) + writesym_pin_number(symfile, pos_x, pos_y, direction, orientation, number) + writesym_pin_label(symfile, pos_x, pos_y, direction, type, orientation, + label, wordswap) + writesym_pin_type(symfile, pos_x, pos_y, direction, type, orientation, type) + writesym_pin_seq(symfile, pos_x, pos_y, direction, type, orientation, seq) + writesym_pin_negation(symfile, pos_x, pos_y, direction, type) + writesym_pin_clocksign(symfile, pos_x, pos_y, direction, type) + writesym_pin_finish(symfile) + return 0 +def write_attributes(symfile, box_left, box_bottom, box_right, box_top, + pin_num_top, pos_name, pos_refdes, pos_others, pins): ### draw the attributes - urefx, urefy = bottomleftx+o_symwidth, bottomlefty + high + 100 - - # Center name if we have top/bottom pins - if numptop + numpbottom > 0: - namex, namey = (bottomleftx + o_symwidth) / 2, (bottomlefty + high) / 2 + 100 + if attr.has_key(("name", 1)): + if (pos_name == "auto" and pin_num_top > 0) or pos_name == "center": + text_x = (box_right + box_left) / 2 + text_y = (box_top + box_bottom) / 2 - 50 + symfile.write("T %i" %text_x + " %i" %text_y + " 9 10 1 0 0 5 1\n") + symfile.write(attr[("name", 1)] + "\n") + elif (pos_name == "auto" and pin_num_top == 0) or pos_name == "top": + text_x = box_left + text_y = box_top + 100 + symfile.write("T %i" %text_x + " %i" %text_y + " 9 10 1 0 0 0 1\n") + symfile.write(attr[("name", 1)] + "\n") + else: + print "error: name position should be top, center, auto\n" + else: + print "warning: name attribute missing" + + if attr.has_key(("refdes", 1)): + if (pos_refdes == "auto" and pin_num_top > 0) or pos_refdes == "center": + text_x = (box_right + box_left) / 2 + text_y = (box_top + box_bottom) / 2 + 50 + symfile.write("T %i" %text_x + " %i" %text_y + " 8 10 1 1 0 3 1\n") + symfile.write("refdes=" + attr[("refdes", 1)] + "\n") + elif (pos_name == "auto" and pin_num_top == 0) or pos_name == "top": + text_x = box_right + text_y = box_top + 100 + symfile.write("T %i" %text_x + " %i" %text_y + " 8 10 1 1 0 6 1\n") + symfile.write("refdes=" + attr[("refdes", 1)] + "\n") + else: + print "error: refdes position should be top, center, auto\n" else: - namex, namey = bottomleftx, bottomlefty+high+100 + print "warning: refdes attribute missing" - textx = namex - texty = namey + 200 - if numptop > 0: - texty += 100 - ## special attribute format - if attr.has_key(("refdes",1)): - f.write("T %i"% urefx +" %i"% urefy +" 8 10 1 1 0 6 1\n") - f.write("refdes=" + attr[("refdes",1)] + "\n") + ## attributes with same format and warnings + if (pos_name == "auto" and pin_num_top > 0) or pos_name == "center": + text_y = box_top + 100 else: - print "warning: refdes attribut missing" + text_y += 200 - if attr.has_key(("name",1)): - f.write("T %i" %namex + " %i"% namey + " 9 10 1 0 0 0 1\n") - f.write(attr[("name",1)] + "\n") + if (pos_others == "auto" and pin_num_top > 0) or pos_others == "right": + text_x = box_right + elif (pos_others == "auto" and pin_num_top == 0) or pos_others == "left": + text_x = box_left else: - print "warning: name attribut missing" - - ## attributes with same format and warnings + print "error: attribute position should be left, right, auto\n" for a in single_attr_warning: - if attr.has_key((a,1)): - f.write("T %i" %textx + " %i"% texty + " 5 10 0 0 0 0 1\n") - f.write(a + "=" + attr[(a,1)] + "\n") - texty=texty+200 + if attr.has_key((a, 1)): + symfile.write("T %i" %text_x + " %i" %text_y + " 5 10 0 1 0 0 1\n") + symfile.write(a + "=" + attr[(a, 1)] + "\n") + text_y += 200 else: - print "warning: " + a + " attribut missing" + print "warning: " + a + " attribute missing" ## attributes without warning for a in single_attr: - if attr.has_key((a,1)): - f.write("T %i" %textx + " %i"% texty + " 5 10 0 0 0 0 1\n") - f.write(a + "=" + attr[(a,1)] + "\n") - texty=texty+200 + if attr.has_key((a, 1)): + symfile.write("T %i" %textx + " %i" %texty + " 5 10 0 1 0 0 1\n") + symfile.write(a + "=" + attr[(a, 1)] + "\n") + text_y += 200 ## attributes with more than one equal name for a in multiple_attr: i = 1 - while attr.has_key((a,i)): - f.write("T %i" %textx + " %i"% texty + " 5 10 0 0 0 0 1\n") - f.write(a + "=" + attr[(a,i)] + "\n") - texty=texty+200 + while attr.has_key((a, i)): + symfile.write("T %i" %textx + " %i" %texty + " 5 10 0 1 0 0 1\n") + symfile.write(a + "=" + attr[(a, i)] + "\n") + text_y += 200 i = i + 1 nets={} @@ -534,29 +611,215 @@ def writesym(filename,options,attr,pins): if not nets.has_key(pin[P_NET]): nets[pin[P_NET]] = pin[P_NR] else: - nets[pin[P_NET]] = nets[pin[P_NET]] + ","+ pin[P_NR] + nets[pin[P_NET]] = nets[pin[P_NET]] + "," + pin[P_NR] for key,value in nets.items(): - f.write("T %i" %textx + " %i"% texty + " 5 10 0 0 0 0 1\n") - f.write("net=" + key + ":" + value + "\n") - texty=texty+200 - + symfile.write("T %i" %text_x + " %i" %text_y + " 5 10 0 1 0 0 1\n") + symfile.write("net=" + key + ":" + value + "\n") + text_y += 200 + return 0 + +def pin_nums(pins): + pin_num_left, pin_num_right, pin_num_bottom, pin_num_top = 0, 0, 0, 0 + for pin in pins: + if pin[P_DIR] == "l": # left pin + pin_num_left += 1 + elif pin[P_DIR] == "b": # bottom pin + pin_num_bottom += 1 + elif pin[P_DIR] == "r": # right pin + pin_num_right += 1 + elif pin[P_DIR] == "t": # top pin + pin_num_top += 1 + return pin_num_left, pin_num_bottom, pin_num_right, pin_num_top + +def writesym(filename, options, attr, pins): + wordswap = options["wordswap"] + sort = options["sort_labels"] + + base_x = string.atoi(options["base_x"]) + base_y = string.atoi(options["base_y"]) + + component_name_position = options["component_name_position"] + refdes_position = options["refdes_position"] + attribute_position = options["attribute_position"] + + pin_dist_horizontal = string.atoi(options["pin_dist_horizontal"]) + pin_dist_vertical = string.atoi(options["pin_dist_vertical"]) + pin_length = string.atoi(options["pin_length"]) + + space_on_top = string.atoi(options["space_on_top"]) + space_on_bottom = string.atoi(options["space_on_bottom"]) + space_on_left = string.atoi(options["space_on_left"]) + space_on_right = string.atoi(options["space_on_right"]) + + just_on_top = options["just_on_top"] + just_on_bottom = options["just_on_bottom"] + just_on_left = options["just_on_left"] + just_on_right = options["just_on_right"] + + order_on_top = options["order_on_top"] + order_on_bottom = options["order_on_bottom"] + order_on_left = options["order_on_left"] + order_on_right = options["order_on_right"] + + dir_on_top = options["dir_on_top"] + dir_on_bottom = options["dir_on_bottom"] + + symfile = open(filename, "w") + +### Count the number of pins in each side + + pin_num_left, pin_num_bottom, pin_num_right, pin_num_top = pin_nums(pins) + + if pin_num_left > 0: + pin_offs_x = pin_length + else: + pin_offs_x = 0 + + if pin_num_bottom > 0: + pin_offs_y = pin_length + else: + pin_offs_y = 0 + + box_bottom = base_y + pin_offs_y + box_left = base_x + pin_offs_x + box_top = box_bottom + space_on_bottom + space_on_top + \ + (max(pin_num_left, pin_num_right) - 1) * pin_dist_vertical + box_right = box_left + space_on_left + space_on_right + \ + (max(pin_num_bottom, pin_num_top) - 1) * pin_dist_horizontal + box_height = box_top - box_bottom + box_width = box_right - box_left + + symfile.write("B %i" %box_left + " %i" %box_bottom + " %i" %box_width + + " %i" %box_height + " 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n") + +### Draw the symbol version + if attr.has_key(("version", 1)): + value = attr[("version", 1)] + symfile.write("v " + value + " 1\n") + else: + print "error: version attribute missing" + sys.exit() + + if sort == "yes": + pins.sort(pinsort) + + if order_on_left == "topbottom": + pin_counter_left, dir_counter_left = pin_num_left - 1, -1 + else: + pin_counter_left, dir_counter_left = 0, 1 + + if order_on_right == "topbottom": + pin_counter_right, dir_counter_right = pin_num_right - 1, -1 + else: + pin_counter_right, dir_counter_right = 0, 1 + + if order_on_top == "rightleft": + pin_counter_top, dir_counter_top = pin_num_top - 1, -1 + else: + pin_counter_top, dir_counter_top = 0, 1 + + if order_on_bottom == "rightleft": + pin_counter_bottom, dir_counter_bottom = pin_num_bottom - 1, -1 + else: + pin_counter_bottom, dir_counter_bottom = 0, 1 + + if just_on_left == "bottom": + just_offs_left = space_on_bottom + elif just_on_left == "middle": + just_offs_left = (box_top - box_bottom) / 2 - (pin_num_left - 1) * \ + pin_dist_vertical / 2 + elif just_on_left == "top": + just_offs_left = box_top - box_bottom - space_on_top - \ + (pin_num_left - 1) * pin_dist_vertical + else: + print "error: justification shoud be top, middle or bottom" + sys.exit() + + if just_on_right == "bottom": + just_offs_right = space_on_bottom + elif just_on_right == "middle": + just_offs_right = (box_top - box_bottom) / 2 - (pin_num_right - 1) * \ + pin_dist_vertical / 2 + elif just_on_right == "top": + just_offs_right = box_top - box_bottom - space_on_top - \ + (pin_num_right - 1) * pin_dist_vertical + else: + print "error: justification shoud be top, middle or bottom" + sys.exit() + + if just_on_bottom == "left": + just_offs_bottom = space_on_left + elif just_on_bottom == "middle": + just_offs_bottom = (box_right - box_left) / 2 - (pin_num_bottom - 1) \ + * pin_dist_horizontal / 2 + elif just_on_bottom == "right": + just_offs_bottom = box_right - box_left - space_on_right - \ + (pin_num_bottom - 1) * pin_dist_horizontal + else: + print "error: justification shoud be left, middle or right" + sys.exit() + + if just_on_top == "left": + just_offs_top = space_on_left + elif just_on_top == "middle": + just_offs_top = (box_right - box_left) / 2 - (pin_num_top - 1) * \ + pin_dist_horizontal / 2 + elif just_on_top == "right": + just_offs_top = box_right - box_left - space_on_right - \ + (pin_num_top - 1) * pin_dist_horizontal + else: + print "error: justification shoud be left, middle or right" + sys.exit() + + for pin in pins: + if pin[P_DIR] == "l": + pin_x = box_left + pin_y = box_bottom + just_offs_left + pin_counter_left * \ + pin_dist_vertical + orientation = "horizontal" + pin_counter_left += dir_counter_left + if pin[P_DIR] == "r": + pin_x = box_right + pin_y = box_bottom + just_offs_right + pin_counter_right * \ + pin_dist_vertical + orientation = "horizontal" + pin_counter_right += dir_counter_right + if pin[P_DIR] == "b": + pin_x = box_left + just_offs_bottom + pin_counter_bottom * \ + pin_dist_horizontal + pin_y = box_bottom + orientation = dir_on_bottom + pin_counter_bottom += dir_counter_bottom + if pin[P_DIR] == "t": + pin_x = box_left + just_offs_top + pin_counter_top * \ + pin_dist_horizontal + pin_y = box_top + orientation = dir_on_top + pin_counter_top += dir_counter_top + writesym_pin(symfile, pin_x, pin_y, pin[P_DIR], orientation, + pin_length, pin[P_NR], pin[P_LABEL], pin[P_TYPE], + pin[P_SEQ], wordswap) + + write_attributes(symfile, box_left, box_bottom, box_right, box_top, + pin_num_top, component_name_position, refdes_position, + attribute_position, pins) return 0 -def mergeoptions(source_opt,pre_opt): - ret=pre_opt +def mergeoptions(source_opt, pre_opt): + ret = pre_opt for item in source_opt.keys(): if ret.has_key(item): - ret[item]=source_opt[item] + ret[item] = source_opt[item] else: - print "This option is not allowed:", item + print "this option is not allowed:", item sys.exit() return ret def generate_pinseq(pins): - seq=1 + seq = 1 for nr in xrange(len(pins)): if pins[nr][P_STYLE] != "none": - pins[nr][P_SEQ] = "%i"%seq + pins[nr][P_SEQ] = "%i" %seq seq = seq + 1 return pins @@ -564,23 +827,22 @@ def generate_pinseq(pins): ## TODO: use getopt try: - file_in=sys.argv[1] - file_out=sys.argv[2] + file_in = sys.argv[1] + file_out = sys.argv[2] except: print "tragesym version " + VERSION - print "Bad arguments, usage is: ", sys.argv[0] ,"infile outfile" + print "Bad arguments, usage is: ", sys.argv[0], "infile outfile" sys.exit() - + ## read sourcefile -opts,attr,pins=readsrc(file_in) +opts, attr, pins = readsrc(file_in) -options=mergeoptions(opts,preset_options) +options = mergeoptions(opts, preset_options) if options["generate_pinseq"] == "yes": - pins=generate_pinseq(pins) + pins = generate_pinseq(pins) checkpins(pins) checkattr(attr) -writesym(file_out,options,attr,pins) - +writesym(file_out, options, attr, pins)