Skip to content

Commit

Permalink
Fixed a typo error where an uninitialized variable was accessed
Browse files Browse the repository at this point in the history
  • Loading branch information
CKuhlmann committed May 5, 2017
1 parent 4945e95 commit f0a83de
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 16 deletions.
2 changes: 2 additions & 0 deletions compile.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
py -3.4 -m py2exe.build_exe lt2ti.py
pause
3 changes: 3 additions & 0 deletions dist/lt2ti.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[general]
symdir=\..\sym32a
includepreamble=true
2 changes: 2 additions & 0 deletions dist/lt2ti_Test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lt2ti.exe examples\Test.asc > Test.log
pause
53 changes: 42 additions & 11 deletions lt2ti.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,22 @@ def __init__(self):
self.lt2tscale = (1.0/48.0);
self.includepreamble = True;

self.scriptdir = (os.path.dirname(os.path.realpath(__file__)));
try:
approot2 = (os.path.dirname(os.path.realpath(__file__)));
approot = os.path.dirname(os.path.abspath(__file__))
except NameError: # We are the main py2exe script, not a module
import sys
approot = os.path.dirname(os.path.abspath(sys.argv[0]))

self.scriptdir = (approot);

self.symfilebasepath = 'sym'+os.sep;

configfileloc = self.scriptdir+os.sep+'lt2ti.ini'
print('lt2ti: Loading config at "'+configfileloc+'"')

self.config = configparser.RawConfigParser()
self.config.read(self.scriptdir+os.sep+'lt2ti.ini')
self.config.read(configfileloc)

if (self.config.has_option('general', 'symdir')):
self.symfilebasepath = self.config.get('general', 'symdir') + os.sep;
Expand All @@ -119,6 +129,8 @@ def __init__(self):
if (self.config.has_option('general', 'includepreamble')):
includepreamble = self.config.get('general', 'includepreamble');
self.includepreamble = ((str(includepreamble).lower() == 'true') or ((includepreamble) == '1'))

print('lt2ti ready for conversion.')



Expand All @@ -144,6 +156,7 @@ def symresetPin(self):
return;

def readASYFile(self, relfileandpath):
print('Loading Symbol file "'+relfileandpath+'"...')
# read symbol file
self.symlinecnt = 0;
aSymbol = None;
Expand Down Expand Up @@ -416,8 +429,8 @@ def _resetLast(self):
self.circDict.addText(self.lastText);
self.lastText = None;

def readASCFile(self, fielandpath):

def readASCFile(self, fileandpath):
print('Reading ASC file "'+fileandpath+'"...')
self.lastComponent = None;
self.lastSymbol = None;
self.lastAttributesDict = {};
Expand All @@ -430,9 +443,9 @@ def readASCFile(self, fielandpath):

self.linecnt = 0;
try :
fhs = open(fielandpath, mode='r', newline=None);
fhs = open(fileandpath, mode='r', newline=None);
except Exception as e:
print('could not open ASC file "'+fielandpath+'" (cwd="'+os.curdir+'")');
print('could not open ASC file "'+fileandpath+'" (cwd="'+os.curdir+'")');
return None;


Expand Down Expand Up @@ -779,6 +792,7 @@ def copyFileContentsToHandle(self,source,hdestination):
fhs.close();

def writeCircuiTikz(self, outfile):
print('Writing Tex commands to "'+outfile+'"...')
xscale = 1 * self.lt2tscale;
yscale = -1 * self.lt2tscale; # y is inverse for LTspice files
xoffset = 0;
Expand Down Expand Up @@ -1118,7 +1132,7 @@ def wiresToPolyWires(self):
for coord, dictWires in coordWireDictCpy.items():
isAtCompPin = (coord in self.coordCompPinDict);
if (isAtCompPin):
print("Wire position "+str(coord)+' is incident with a component pin. Conversion to polywire suppressed.');
print(" Wire position "+str(coord)+' is incident with a component pin. Conversion to polywire suppressed.');

if (len(dictWires) == 2) and (coord not in self.coordCompDict) and (not isAtCompPin): # two wires joined at this point and no component node there. convert to PolyWire
changes = True # we join two wires, thus change the set and must reprocess it
Expand Down Expand Up @@ -1147,6 +1161,7 @@ def wiresToPolyWires(self):
# if len(dictWires) == 2: # two wires joined at this point: convert them into a PolyWire

# no more changes
print("Joining operations completed.")
return cnt;

class Attribute:
Expand Down Expand Up @@ -1933,20 +1948,23 @@ def JoinWires(cls, Wire1, Wire2):

if (Wire1.getP1Tuple() == Wire2.getP1Tuple()):
# joined at P1 back to back Wire1 <-> Wire2
print(" Wire1 <-> Wire2")
x1_ = Wire1.x2
y1_ = Wire1.y2

if (type(Wire1) is PolyWire):
an = list(Wire1.xn); # copy so we can reverse it if necessary
an.reverse(); # turn the wire coordinate list 'around'
xn.extend(an);
xn_.extend(an);
an = list(Wire1.yn); # copy so we can reverse it if necessary
an.reverse(); # turn the wire coordinate list 'around'
yn.extend(an);
yn_.extend(an);

xn_.append(Wire1.x1)
yn_.append(Wire1.y1)

print(" (Wire1 complete..)")

if (type(Wire2) is PolyWire):
an = list(Wire2.xn); # copy so we can reverse it if necessary
#an.reverse(); # turn the wire coordinate list 'around'
Expand All @@ -1959,6 +1977,7 @@ def JoinWires(cls, Wire1, Wire2):
y2_ = Wire2.y2
elif (Wire1.getP2Tuple() == Wire2.getP2Tuple()):
# joined at P2 face to face Wire1 >-< Wire2
print(" Wire1 >-< Wire2")
x1_ = Wire1.x1
y1_ = Wire1.y1

Expand All @@ -1985,6 +2004,7 @@ def JoinWires(cls, Wire1, Wire2):
y2_ = Wire2.y1
elif (Wire1.getP2Tuple() == Wire2.getP1Tuple()):
# flow from Wire1 -> Wire2
print(" Wire1 -> Wire2")
x1_ = Wire1.x1
y1_ = Wire1.y1

Expand All @@ -2011,6 +2031,7 @@ def JoinWires(cls, Wire1, Wire2):
y2_ = Wire2.y2
elif (Wire1.getP1Tuple() == Wire2.getP2Tuple()):
# flow from Wire2 -> Wire1
print(" Wire2 -> Wire1")
x1_ = Wire2.x1
y1_ = Wire2.y1

Expand Down Expand Up @@ -2039,6 +2060,8 @@ def JoinWires(cls, Wire1, Wire2):
# unknown
print("Error: Unknown wire configuration for PolyWire:JoinWires")

print(" Constructing new wire object..")

pw = cls(name_, x1_, y1_, xn_, yn_, x2_, y2_)
return pw;

Expand Down Expand Up @@ -2397,5 +2420,13 @@ def main():
l2tobj.readASCFile(args.file);
l2tobj.writeCircuiTikz(args.file+'.tex');

if __name__ == '__main__':
main();

try:
approot = os.path.dirname(os.path.abspath(__file__))
if __name__ == '__main__':
main();
except NameError: # We are the main py2exe script, not a module
import sys
approot = os.path.dirname(os.path.abspath(sys.argv[0]))
main();

9 changes: 9 additions & 0 deletions lt2ti_Prj.wpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!wing
#!version=6.0
##################################################################
# Wing IDE project file #
##################################################################
[project attributes]
proj.file-list = [loc('lt2ti.py'),
loc('test_lt2ti.py')]
proj.file-type = 'shared'
2 changes: 1 addition & 1 deletion sym32a/latex_preamble.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% automatically generated document using lt2circuiTikz
\documentclass[tikz,margin={2pt 2pt 2pt 2pt}]{standalone}
\usepackage[compatibility,siunitx, americanvoltages, americancurrents, europeanresistors, europeaninductors, americanports,%
straightlabels, fetbodydiode]{circuitikz}
straightlabels, fetbodydiode, straightvoltages]{circuitikz}
\usepackage{tikz,amsmath, amssymb,bm,color,pgfkeys,siunitx,ifthen,ulem}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
Expand Down
3 changes: 1 addition & 2 deletions sym32a/voltage.asy2tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ BeginPinList
EndPinList
TexElementName *V
BeginTex
%\draw (#+:x1#, #+:y1#) to[#self.symbol.latexElementName#, l=#self.name#, a=#self.value#, ##mirror##, rotate=##rotate##,##options##] (#-:x1#,#-:y1#){};
\draw (#+:x1#, #+:y1#) to[#self.symbol.latexElementName#, l=#self.name#, a=#self.value#,##mirror##, #+:junction#-#-:junction#, ##options##] (#-:x1#,#-:y1#){};
\draw (#+:x1#, #+:y1#) to[#self.symbol.latexElementName#, l_=#self.name#, a^=#self.value#,##mirror##, #+:junction#-#-:junction#, ##options##] (#-:x1#,#-:y1#){};
EndTex
2 changes: 1 addition & 1 deletion sym32b/latex_preamble.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% automatically generated document using lt2circuiTikz
\documentclass[tikz,margin={2pt 2pt 2pt 2pt}]{standalone}
\usepackage[compatibility,siunitx, americanvoltages, americancurrents, europeanresistors, europeaninductors, americanports,%
straightlabels, fetbodydiode]{circuitikz}
straightlabels, fetbodydiode, straightvoltages]{circuitikz}
\usepackage{tikz,amsmath, amssymb,bm,color,pgfkeys,siunitx,ifthen,ulem}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
Expand Down
2 changes: 1 addition & 1 deletion sym48/latex_preamble.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% automatically generated document using lt2circuiTikz
\documentclass[tikz,margin={2pt 2pt 2pt 2pt}]{standalone}
\usepackage[compatibility,siunitx, americanvoltages, americancurrents, europeanresistors, europeaninductors, americanports,%
straightlabels, fetbodydiode]{circuitikz}
straightlabels, fetbodydiode, straightvoltages]{circuitikz}
\usepackage{tikz,amsmath, amssymb,bm,color,pgfkeys,siunitx,ifthen,ulem}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
Expand Down

0 comments on commit f0a83de

Please sign in to comment.