summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice/DeviceModel.py
blob: 6fd2b6639df4a4276becb0a0b03d0777daff9e8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from PyQt4 import QtGui

import TrackWidget


class DeviceModel(QtGui.QWidget):
    """
    This class creates Device Library  Tab in KicadtoNgspice Window
    It dynamically creates the widget for device like diode,mosfet,transistor and jfet.
    """
    
    def __init__(self,schematicInfo):
        QtGui.QWidget.__init__(self)
        #print "Starting Device Modeling"
              
        #Creating track widget object
        self.obj_trac = TrackWidget.TrackWidget()
        
        #Row and column count
        self.row = 0
        self.count = 1  #Entry count
        self.entry_var = {}
                
        #For MOSFET
        self.widthLabel = {}
        self.lengthLabel = {}
        self.multifactorLable = {}
              
        
        #List to hold information about device
        self.deviceDetail = {}
                
        #Set Layout
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        
        for eachline in schematicInfo:
            words = eachline.split()
            if eachline[0] == 'q':
                print "Words ",words[0]
                self.label = QtGui.QLabel("Add library for Transistor "+words[0]+" : "+words[4])
                self.grid.addWidget(self.label,self.row,0)
                self.entry_var[self.count] = QtGui.QLineEdit()
                self.entry_var[self.count].setText("")
                self.grid.addWidget(self.entry_var[self.count],self.row,1)
                self.addbtn = QtGui.QPushButton("Add")
                self.addbtn.setObjectName("%d" %self.count)
                self.addbtn.clicked.connect(self.trackLibrary)
                self.grid.addWidget(self.addbtn,self.row,2)
                
                #Adding Device Details
                self.deviceDetail[self.count] = words[0]
                                
                #Increment row and widget count
                self.row = self.row+1
                self.count = self.count+1
                
            elif eachline[0] == 'd':
                print "Words",words[0]
                self.label = QtGui.QLabel("Add library for Diode "+words[0]+" : "+words[3])
                self.grid.addWidget(self.label,self.row,0)
                self.entry_var[self.count] = QtGui.QLineEdit()
                self.entry_var[self.count].setText("")
                self.grid.addWidget(self.entry_var[self.count],self.row,1)
                self.addbtn = QtGui.QPushButton("Add")
                self.addbtn.setObjectName("%d" %self.count)
                self.addbtn.clicked.connect(self.trackLibrary)
                self.grid.addWidget(self.addbtn,self.row,2)
                
                #Adding Device Details
                self.deviceDetail[self.count] = words[0]
                                
                #Increment row and widget count
                self.row = self.row+1
                self.count = self.count+1
                
            elif eachline[0] == 'j':
                print "Words",words[0]
                self.label = QtGui.QLabel("Add library for JFET "+words[0]+" : "+words[4])
                self.grid.addWidget(self.label,self.row,0)
                self.entry_var[self.count] = QtGui.QLineEdit()
                self.entry_var[self.count].setText("")
                self.grid.addWidget(self.entry_var[self.count],self.row,1)
                self.addbtn = QtGui.QPushButton("Add")
                self.addbtn.setObjectName("%d" %self.count)
                self.addbtn.clicked.connect(self.trackLibrary)
                self.grid.addWidget(self.addbtn,self.row,2)
                
                #Adding Device Details
                self.deviceDetail[self.count] = words[0]
                                
                #Increment row and widget count
                self.row = self.row+1
                self.count = self.count+1
                
                       
                
            elif eachline[0] == 'm':
                self.label = QtGui.QLabel("Add library for MOSFET "+words[0]+" : "+words[5])
                self.grid.addWidget(self.label,self.row,0)
                self.entry_var[self.count] =QtGui.QLineEdit()
                self.entry_var[self.count].setText("")
                self.grid.addWidget(self.entry_var[self.count],self.row,1)
                self.addbtn = QtGui.QPushButton("Add")
                self.addbtn.setObjectName("%d" %self.count)
                self.addbtn.clicked.connect(self.trackLibrary)
                self.grid.addWidget(self.addbtn,self.row,2)
                
                #Adding Device Details
                self.deviceDetail[self.count] = words[0]
                                
                #Increment row and widget count
                self.row = self.row+1
                self.count = self.count+1
                
                #Adding to get MOSFET dimension                
                self.widthLabel[self.count] = QtGui.QLabel("Enter width of MOSFET "+words[0]+"(default=100u):")
                self.grid.addWidget(self.widthLabel[self.count],self.row,0)
                self.entry_var[self.count] = QtGui.QLineEdit()
                self.entry_var[self.count].setText("")
                self.entry_var[self.count].setMaximumWidth(150)
                self.grid.addWidget(self.entry_var[self.count],self.row,1)
                self.row = self.row + 1
                self.count = self.count+1
                
                self.lengthLabel[self.count] = QtGui.QLabel("Enter length of MOSFET "+words[0]+"(default=100u):")
                self.grid.addWidget(self.lengthLabel[self.count],self.row,0)
                self.entry_var[self.count] = QtGui.QLineEdit()
                self.entry_var[self.count].setText("")
                self.entry_var[self.count].setMaximumWidth(150)
                self.grid.addWidget(self.entry_var[self.count],self.row,1)
                self.row = self.row + 1
                self.count = self.count+1
                
                
                self.multifactorLable[self.count] = QtGui.QLabel("Enter multiplicative factor of MOSFET "+words[0]+"(default=1):")
                self.grid.addWidget(self.multifactorLable[self.count],self.row,0)
                self.entry_var[self.count] = QtGui.QLineEdit()
                self.entry_var[self.count].setText("")
                self.entry_var[self.count].setMaximumWidth(150)
                self.grid.addWidget(self.entry_var[self.count],self.row,1)
                self.row = self.row + 1
                self.count = self.count+1
                
                   
            self.show()
        
                  
    def trackLibrary(self):
        """
        This function is use to keep track of all Device Model widget
        """
        print "Calling Track Library funtion"
        sending_btn = self.sender()
        #print "Object Called is ",sending_btn.objectName()
        self.widgetObjCount = int(sending_btn.objectName())
        
        self.libfile = str(QtGui.QFileDialog.getOpenFileName(self,"Open Library Directory","../deviceModelLibrary"))
        #print "Selected Library File :",self.libfile
        
        #Setting Library to Text Edit Line
        self.entry_var[self.widgetObjCount].setText(self.libfile)
        self.deviceName = self.deviceDetail[self.widgetObjCount]
        
        #Storing to track it during conversion
        
        
        if self.deviceName[0] == 'm':
            width = str(self.entry_var[self.widgetObjCount+1].text())
            length = str(self.entry_var[self.widgetObjCount+2].text())
            multifactor = str(self.entry_var[self.widgetObjCount+3].text())
            if width == "" : width="100u"
            if length == "": length="100u"
            if multifactor == "": multifactor="1"
                
            self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile+":"+"W="+width+" L="+length+" M="+multifactor
            
        else:
            self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile