From bfcd31c7c14519d29cf5b2c813899fc63bc5cf32 Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Tue, 25 Jun 2019 15:38:20 +0530 Subject: Uploading Subcircuit feature added --- src/ngspiceSimulation/NgspiceWidget.py | 4 +- src/ngspiceSimulation/pythonPlotting.py | 4 +- src/projManagement/Validation.py | 45 ++++++++++++++++ src/subcircuit/uploadSub.py | 94 +++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 src/subcircuit/uploadSub.py diff --git a/src/ngspiceSimulation/NgspiceWidget.py b/src/ngspiceSimulation/NgspiceWidget.py index 1d5c974f..a963c51f 100644 --- a/src/ngspiceSimulation/NgspiceWidget.py +++ b/src/ngspiceSimulation/NgspiceWidget.py @@ -9,8 +9,8 @@ class NgspiceWidget(QtGui.QWidget): def __init__(self, command, projPath): """ - 1)Creates constructor for NgspiceWidget class. - 2)Checks whether OS is linux or windows + - Creates constructor for NgspiceWidget class. + - Checks whether OS is linux or windows and creates NgSpice window accordingly. """ QtGui.QWidget.__init__(self) diff --git a/src/ngspiceSimulation/pythonPlotting.py b/src/ngspiceSimulation/pythonPlotting.py index b9474403..22f2100a 100644 --- a/src/ngspiceSimulation/pythonPlotting.py +++ b/src/ngspiceSimulation/pythonPlotting.py @@ -14,10 +14,10 @@ import numpy as np # This class creates Python Plotting window class plotWindow(QtGui.QMainWindow): - ''' + """ This class defines python plotting window, its features, buttons, colors, AC and DC analysis, plotting etc. - ''' + """ def __init__(self, fpath, projectName): """This create constructor for plotWindow class.""" diff --git a/src/projManagement/Validation.py b/src/projManagement/Validation.py index 65103282..a3b12ecd 100644 --- a/src/projManagement/Validation.py +++ b/src/projManagement/Validation.py @@ -186,3 +186,48 @@ class Validation: Example, nghdl, eeschema... """ return distutils.spawn.find_executable(toolName) is not None + + def validateSubcir(self, projDir): + """ + This function checks for valid format of .sub file. + Correct format of file is: + - File should start with **.subckt ** + - End with **.ends ** + Function is passed with the file of path it checks the + file line by line untill it get .subckt as its first word + and then check for second word is it or not. + + Then it checks for second last line if it is ".ends + " it return True if conditions satisfy else + return False. + + """ + projName = os.path.basename(str(projDir)) + fileName = projName[:-4] + req_line = ".ends" + " " + str(fileName) + f = open(projDir, 'r') + + flag1 = False + flag2 = False + + for line in f: + word = line.split(' ') + if word[0] == "*": + continue + if word[0] == ".subckt": + break + + if word[1] == fileName: + flag1 = True + + with open(projDir, 'r') as m: + lines = m.read().splitlines() + last_line = lines[-2] + + if req_line == last_line: + flag2 = True + + if flag1 == True and flag2 == True: + return "True" + else: + return "False" diff --git a/src/subcircuit/uploadSub.py b/src/subcircuit/uploadSub.py new file mode 100644 index 00000000..940e13c8 --- /dev/null +++ b/src/subcircuit/uploadSub.py @@ -0,0 +1,94 @@ +from PyQt4 import QtGui +from configuration.Appconfig import Appconfig +from projManagement.Validation import Validation +import os +import shutil + + +class UploadSub(QtGui.QWidget): + """This class contain function for """ + + def __init__(self): + super(UploadSub, self).__init__() + self.obj_validation = Validation() + self.obj_appconfig = Appconfig() + + def upload(self): + """ + This method opens a dialogue box when Upload subcircuit button is + clicked and after entering folder name, it opens directory system + to chose file for folder, it only shows file with extension .sub + and with the name of project entered earlier as folder name. + + It then validates file if it is in proper format or not, for it + the file is passed to the function **validateSub** and it returns + true if file has valid format or else it shows an error message. + """ + text, ok = QtGui.QInputDialog.getText( + self, 'Subcircuit Info', 'Enter Subcircuit Name:') + + if ok: + projname = (str(text)) + create_subcircuit = projname + subcircuit_path = (os.path.join(os.path.abspath('..'), 'SubcircuitLibrary', create_subcircuit)) + + if subcircuit_path == "": + self.reply = "NONE" + else: + self.reply = self.obj_validation.validateNewproj(str(subcircuit_path)) + + if self.reply == "VALID": + print("Validated: Creating subcircuit directory") + os.mkdir(subcircuit_path) + editfile = str( + QtGui.QFileDialog.getOpenFileName( + None, "Upload File", os.path.expanduser("~"), (projname + ".sub"))) + + upload = os.path.basename(editfile) + print("===================") + print("Current path of subcircuit file is " + editfile) + print("===================") + print("Selected file is " + upload) + print("===================") + self.valid = self.obj_validation.validateSubcir(str(editfile)) + print("===================") + + if self.valid is True: + print("Right file format!!!") + print("===================") + subcircuit = (os.path.join(subcircuit_path, upload)) + print("Final path of file is " + subcircuit) + print("===================") + print("Copying file from " + editfile + " to " + subcircuit) + print("===================") + shutil.copy(editfile, subcircuit) + else: + self.msg = QtGui.QErrorMessage(self) + self.msg.showMessage( + "Content of file does not meet the required format.\ + Please make sure file starts with * .subckt \ + " + upload + "** and ends with **.ends \ + " + upload + "**") + self.msg.setWindowTitle("Error Message") + print("Invalid file format") + print("===================") + print("Removing directory " + subcircuit_path) + print("===================") + os.rmdir(subcircuit_path) + + elif self.reply == "CHECKEXIST": + print("Project name already exists.") + print("==========================") + msg = QtGui.QErrorMessage(self) + msg.showMessage( + "The project already exist. Please select \ + the different name or delete existing project") + msg.setWindowTitle("Error Message") + + elif self.reply == "CHECKNAME": + print("Name can not contain space between them") + print("===========================") + msg = QtGui.QErrorMessage(self) + msg.showMessage( + 'The project name should not contain space between them') + msg.setWindowTitle("Error Message") -- cgit