summaryrefslogtreecommitdiff
path: root/src/pspicetoKicad/ImportPspice.py
blob: 1b97efc047162310f230f442dbf0e4c913a51bb4 (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
from PyQt4 import QtGui,QtCore
from configuration.Appconfig import Appconfig
import os
import platform
import shutil
import glob

class ImportPspiceLibrary(QtGui.QWidget):
    """
    This is used to import the Pspice Library and convert it inot Kicad library
    """
    def __init__(self):
        super(ImportPspiceLibrary, self).__init__()
        self.obj_Appconfig = Appconfig()
        
    def imortLib(self):
        self.home = os.path.expanduser("~")
        self.worspace_loc = self.obj_Appconfig.default_workspace['workspace']
        #self.sourceLoc = os.path.join(str(os.getcwd()),"*.lib")
        self.destinationLoc = os.path.join(self.worspace_loc,"ConvertedLib")
        self.libLocation = QtGui.QFileDialog.getOpenFileNames(self,"open",self.home,"*.slb")
        self.tempList = [] #Hold library file in the form of string
        
        #print "Source---------->",self.sourceLoc
        print "Destination--------->",self.destinationLoc
        
        for item in self.libLocation:
            self.tempList.append(str(item))
        
        self.obj_Appconfig.print_info('File selected : '+str(self.tempList))
        self.arg = ' '.join(self.tempList)
                       
        #Create command to run
        if platform.system() == 'Linux':
            #Check for 32 or 64 bit
            if platform.architecture()[0] == '64bit':
                self.cmd = "../pspicetoKicad/libConverter64 "+self.arg
            else:
                self.cmd = "../pspicetoKicad/libConverter32 "+self.arg
        elif platform.system() == 'Windows':
            print "Needs to include for Windows"
           
        self.status =  os.system(str(self.cmd))
                       
        if self.status == 0:
            #Moving files to necessary location
            for libfile in glob.glob('*.lib'):
                shutil.move(libfile, self.worspace_loc)
            self.msg = QtGui.QMessageBox()
            self.msgContent = "Successfully imported and converted PSPICE library to Kicad library.<br/>"
            self.msg.setTextFormat(QtCore.Qt.RichText)
            self.msg.setText(self.msgContent)
            self.msg.setWindowTitle("Message")
            self.obj_Appconfig.print_info(self.msgContent)
            self.msg.exec_()
        else:
            self.msg = QtGui.QErrorMessage(None)
            self.msg.showMessage('Error while converting PSPICE library to Kicad library')
            self.obj_Appconfig.print_error('Error while converting PSPICE library to Kicad library')
            self.msg.setWindowTitle("Error Message")
            
        
        
    
class ConvertPspiceKicad(QtGui.QWidget):
    """
    This is used to convert Pspice schematic into Kicad schematic
    """
    def __init__(self):
        super(ConvertPspiceKicad, self).__init__()
        self.obj_Appconfig = Appconfig()
    
    def runConverter(self):
        self.obj_Appconfig.print_info('Running PSPICE to Kicad converter')
        self.home = os.path.expanduser("~")
        self.worspace_loc = self.obj_Appconfig.default_workspace['workspace']
        
        self.pspiceSchFileLoc = QtGui.QFileDialog.getOpenFileName(self,"open",self.home)
        self.pspiceSchFileName = os.path.basename(str(self.pspiceSchFileLoc))
        self.pspiceProjName = os.path.splitext(self.pspiceSchFileName)[0]
        self.outputDir = os.path.join(self.worspace_loc,self.pspiceProjName)       
        
        #Check if project is already exists
        if  os.path.isdir(self.outputDir):
            print "Already present"
            self.obj_Appconfig.print_info("Output Project "+self.outputDir+" is already present")
            reply = QtGui.QMessageBox.question(self, 'Message',"eSim project with same name is already exist. Do you want to delete it ?", \
                                               QtGui.QMessageBox.Yes |QtGui.QMessageBox.No, QtGui.QMessageBox.No)
            if reply == QtGui.QMessageBox.Yes:
                print "Deleting Project and creating new"
                self.obj_Appconfig.print_info("Deleting Project and creating new")
                shutil.rmtree(self.outputDir, ignore_errors=False, onerror=self.errorRemove)
                os.mkdir(self.outputDir)
                #Calling Function
                self.createProjectFile(self.pspiceSchFileLoc,self.outputDir)
            else:
                self.msg = QtGui.QMessageBox()
                self.msgContent = "PSPICE to Kicad schematic conversion aborted.<br/>\
                You can change the Pspice schematic file name and upload it again.<br/>"
                self.msg.setTextFormat(QtCore.Qt.RichText)
                self.msg.setText(self.msgContent)
                self.msg.setWindowTitle("Message")
                self.obj_Appconfig.print_info(self.msgContent)
                self.msg.exec_()
        else:
            os.mkdir(self.outputDir)
            #Calling Function
            self.createProjectFile(self.pspiceSchFileLoc,self.outputDir)
            
    def createProjectFile(self,pspiceSchFileLoc,outputDir):
        print "Create Project File is called"
        #Create command to be run
        if platform.system() == 'Linux':
            #Check for 32 or 64 bit
            if platform.architecture()[0] == '64bit':
                self.cmd = "../pspicetoKicad/schConverter64 "+pspiceSchFileLoc+" "+self.outputDir
            else:
                self.cmd = "../pspicetoKicad/schConverter32 "+pspiceSchFileLoc+" "+self.outputDir
        elif platform.system() == 'Windows':
            print "Needs to include for Windows"
               
        #Running command
        self.status =  os.system(str(self.cmd))
                    
        if self.status == 0:
            self.msg = QtGui.QMessageBox()
            self.msgContent = "Successfully converted PSPICE schematic to Kicad Schematic.<br/>\
            Project is available in eSim workspace at <b>"+self.outputDir+"</b>.<br/>\
            You can open the project from eSim workspace"
            self.msg.setTextFormat(QtCore.Qt.RichText)
            self.msg.setText(self.msgContent)
            self.msg.setWindowTitle("Message")
            self.obj_Appconfig.print_info(self.msgContent)
            self.msg.exec_()
            
        else:
            self.msg = QtGui.QErrorMessage(None)
            self.msg.showMessage('Error while converting PSPICE schematic to Kicad Schematic')
            self.obj_Appconfig.print_error('Error while converting PSPICE schematic to Kicad Schematic')
            self.msg.setWindowTitle("Error Message")
            
    def errorRemove(self,func, path, exc):
        self.msg = QtGui.QErrorMessage(None)
        self.msg.showMessage('Error while removing existing project. <br/> Please check whether directory is Read only.')
        self.obj_Appconfig.print_error('Error while removing existing project')
        self.msg.setWindowTitle("Error Message")