summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/maker/Appconfig.py37
-rwxr-xr-xsrc/maker/ModelGeneration.py2
-rw-r--r--src/maker/createkicad.py153
-rw-r--r--src/projManagement/Kicad.py20
-rw-r--r--src/projManagement/newProject.py3
5 files changed, 116 insertions, 99 deletions
diff --git a/src/maker/Appconfig.py b/src/maker/Appconfig.py
index 9d373d5e..315ecff8 100755
--- a/src/maker/Appconfig.py
+++ b/src/maker/Appconfig.py
@@ -24,18 +24,29 @@ class Appconfig:
# parser_ngveri.read(os.path.join(home,
# os.path.join('.ngveri', 'config.ini')))
- # KiCad V6 Library Template
+ # KiCad v6 Library Template
kicad_sym_template = {
- "start_def": "(symbol \"comp_name\" (pin_names (offset 1.016)) (in_bom yes) (on_board yes)",
- "U_field":"(property \"Reference\" \"U\" (id 0) (at 12 15 0)(effects (font (size 1.524 1.524))))",
- "comp_name_field":"(property \"Value\" \"comp_name\" (id 1) (at 12 18 0)(effects (font (size 1.524 1.524))))",
- "blank_field": [
- "(property \"Footprint\" blank_quotes (id 2) (at 72.39 49.53 0)(effects (font (size 1.524 1.524))))",
- "(property \"Datasheet\" blank_quotes (id 3) (at 72.39 49.53 0)(effects (font (size 1.524 1.524))))"
- ],
- "draw_pos": "(symbol \"comp_name\"(rectangle (start 0 0 ) (end 25.40 3.6 )(stroke (width 0) (type default) (color 0 0 0 0))(fill (type none))))",
- "start_draw":"(symbol",
- "input_port":"(pin input line(at -5.15 0.54 0 )(length 5.08 )(name \"in\" (effects(font(size 1.27 1.27))))(number \"1\" (effects (font (size 1.27 1.27)))))",
- "output_port": "(pin output line(at 30.52 0.54 180 )(length 5.08 )(name \"out\" (effects(font(size 1.27 1.27))))(number \"2\" (effects (font (size 1.27 1.27)))))",
- "end_draw":"))"
+ "start_def": "(symbol \"comp_name\" (pin_names (offset 1.016)) " +
+ "(in_bom yes) (on_board yes)",
+ "U_field": "(property \"Reference\" \"U\" (id 0) (at 12 15 0)" +
+ "(effects (font (size 1.524 1.524))))",
+ "comp_name_field": "(property \"Value\" \"comp_name\" (id 1) " +
+ "(at 12 18 0)(effects (font (size 1.524 1.524))))",
+ "blank_field": [
+ "(property \"Footprint\" blank_quotes (id 2) " +
+ "(at 72.39 49.53 0)(effects (font (size 1.524 1.524))))",
+ "(property \"Datasheet\" blank_quotes (id 3) " +
+ "(at 72.39 49.53 0)(effects (font (size 1.524 1.524))))"
+ ],
+ "draw_pos": "(symbol \"comp_name\"(rectangle (start 0 0 ) " +
+ "(end 25.40 3.6 )(stroke (width 0) (type default) " +
+ "(color 0 0 0 0))(fill (type none))))",
+ "start_draw": "(symbol",
+ "input_port": "(pin input line(at -5.15 0.54 0 )(length 5.08 )" +
+ "(name \"in\" (effects(font(size 1.27 1.27))))" +
+ "(number \"1\" (effects (font (size 1.27 1.27)))))",
+ "output_port": "(pin output line(at 30.52 0.54 180 )(length 5.08 )" +
+ "(name \"out\" (effects(font(size 1.27 1.27))))" +
+ "(number \"2\" (effects (font (size 1.27 1.27)))))",
+ "end_draw": "))"
}
diff --git a/src/maker/ModelGeneration.py b/src/maker/ModelGeneration.py
index 42ebd285..2591b26b 100755
--- a/src/maker/ModelGeneration.py
+++ b/src/maker/ModelGeneration.py
@@ -216,7 +216,7 @@ class ModelGeneration(QtWidgets.QWidget):
modelname = str(m.name)
schematicLib = createkicad.AutoSchematic()
schematicLib.init(modelname, self.modelpath)
- error = schematicLib.createkicad()
+ error = schematicLib.createKicadSymbol()
if error == "Error":
return "Error"
return "No Error"
diff --git a/src/maker/createkicad.py b/src/maker/createkicad.py
index 8e4faa1b..0ce239a0 100644
--- a/src/maker/createkicad.py
+++ b/src/maker/createkicad.py
@@ -1,4 +1,4 @@
-# =========================================================================
+# ==============================================================================
# FILE: createkicad.py
#
# USAGE: ---
@@ -24,22 +24,17 @@
# Partha Singha Roy, Kalyani Government Engineering College
# ORGANIZATION: eSim Team at FOSSEE, IIT Bombay
# CREATED: Monday 29, November 2021
-# REVISION: Friday 16 , June 2023
-# =========================================================================
+# REVISION: Friday 16, June 2023
+# ==============================================================================
-# importing the files and libraries
from . import Appconfig
import re
import os
import xml.etree.cElementTree as ET
from PyQt5 import QtWidgets
-# beginning the AutoSchematic Class
-
class AutoSchematic:
-
- # initialising the variables here
def init(self, modelname, modelpath):
self.App_obj = Appconfig.Appconfig()
self.modelname = modelname.split('.')[0]
@@ -50,19 +45,17 @@ class AutoSchematic:
if os.name == 'nt':
eSim_src = self.App_obj.src_home
inst_dir = eSim_src.replace('\\eSim', '')
- self.kicad_ngveri_lib = \
+ self.kicad_ngveri_sym = \
inst_dir + '/KiCad/share/kicad/symbols/eSim_Ngveri.kicad_sym'
else:
- self.kicad_ngveri_lib = '/usr/share/kicad/symbols/eSim_Ngveri.kicad_sym'
+ self.kicad_ngveri_sym = \
+ '/usr/share/kicad/symbols/eSim_Ngveri.kicad_sym'
# self.parser = self.App_obj.parser_ngveri
- # creating KiCAD library using this function
- def createkicad(self):
-
- xmlFound = None
- # read_file = open(self.modelpath+'connection_info.txt', 'r')
- # data = read_file.readlines()
- # print(data)
+ def createKicadSymbol(self):
+ '''
+ creating KiCad library using this function
+ '''
xmlFound = None
for root, dirs, files in os.walk(self.xml_loc):
if (str(self.modelname) + '.xml') in files:
@@ -73,7 +66,7 @@ class AutoSchematic:
if xmlFound is None:
self.getPortInformation()
self.createXML()
- self.createLib()
+ self.createSym()
elif (xmlFound == os.path.join(self.xml_loc, 'Ngveri')):
print('Library already exists...')
@@ -89,8 +82,8 @@ class AutoSchematic:
print("Overwriting existing libraries")
self.getPortInformation()
self.createXML()
- self.removeOldLibrary() # Removes the existng library
- self.createLib()
+ self.removeOldLibrary() # Removes the existing library
+ self.createSym()
else:
print("Library Creation Cancelled")
return "Error"
@@ -104,16 +97,20 @@ class AutoSchematic:
QtWidgets.QMessageBox.Ok
)
- # getting the port information here
def getPortInformation(self):
+ '''
+ getting the port information here
+ '''
portInformation = PortInfo(self, self.modelpath)
portInformation.getPortInfo()
self.portInfo = portInformation.bit_list
self.input_length = portInformation.input_len
self.portName = portInformation.port_name
- # creating the XML files in eSim-2.2/library/modelParamXML/Ngveri
def createXML(self):
+ '''
+ creating the XML files at `library/modelParamXML/Ngveri`
+ '''
cwd = os.getcwd()
xmlDestination = os.path.join(self.xml_loc, 'Ngveri')
self.splitText = ""
@@ -146,8 +143,10 @@ class AutoSchematic:
print("Leaving the directory ", xmlDestination)
os.chdir(cwd)
- # Calculates the maximum between input and output ports
def findBlockSize(self):
+ '''
+ Calculates the maximum between input and output ports
+ '''
ind = self.input_length
return max(
self.char_sum(self.portInfo[:ind]),
@@ -157,14 +156,16 @@ class AutoSchematic:
def char_sum(self, ls):
return sum([int(x) for x in ls])
- # removing the old library
def removeOldLibrary(self):
+ '''
+ removing the old library
+ '''
cwd = os.getcwd()
os.chdir(self.lib_loc)
print("Changing directory to ", self.lib_loc)
- f = open(self.kicad_ngveri_lib)
- lines = f.readlines()
- f.close()
+ sym_file = open(self.kicad_ngveri_sym)
+ lines = sym_file.readlines()
+ sym_file.close()
output = []
line_reading_flag = False
@@ -178,41 +179,49 @@ class AutoSchematic:
if line.startswith("))"): # Eeschema Template end
line_reading_flag = False
- f = open(self.kicad_ngveri_lib, 'w')
+ sym_file = open(self.kicad_ngveri_sym, 'w')
for line in output:
- f.write(line)
+ sym_file.write(line)
os.chdir(cwd)
print("Leaving directory, ", self.lib_loc)
- # creating the library
- def createLib(self):
- self.dist_port = 2.54 # Distance between two ports(mil)
- self.inc_size = 2.54 # Increment size of a block(mil)
+ def createSym(self):
+ '''
+ creating the symbol
+ '''
+ self.dist_port = 2.54 # Distance between two ports (mil)
+ self.inc_size = 2.54 # Increment size of a block (mil)
cwd = os.getcwd()
os.chdir(self.lib_loc)
print("Changing directory to ", self.lib_loc)
- # Removeing ")" from "eSim_Ngveri.kicad_sym"
- file = open(self.kicad_ngveri_lib,"r")
+ # Removing ")" from "eSim_Ngveri.kicad_sym"
+ file = open(self.kicad_ngveri_sym, "r")
content_file = file.read()
- new_content_file=content_file[:-1]
+ new_content_file = content_file[:-1]
file.close()
- file = open(self.kicad_ngveri_lib,"w")
+ file = open(self.kicad_ngveri_sym, "w")
file.write(new_content_file)
file.close()
- # Appending New Schematic
- lib_file = open(self.kicad_ngveri_lib, "a")
+ # Appending new schematic block
+ sym_file = open(self.kicad_ngveri_sym, "a")
line1 = self.template["start_def"]
line1 = line1.split()
line1 = [w.replace('comp_name', self.modelname) for w in line1]
self.template["start_def"] = ' '.join(line1)
- if os.stat(self.kicad_ngveri_lib).st_size == 0:
- lib_file.write("(kicad_symbol_lib (version 20211014) (generator kicad_symbol_editor)" + "\n\n") # Eeschema startar code
- # lib_file.write("#encoding utf-8"+ "\n"+ "#"+ "\n" +
+
+ if os.stat(self.kicad_ngveri_sym).st_size == 0:
+ sym_file.write(
+ "(kicad_symbol_lib (version 20211014) " +
+ "(generator kicad_symbol_editor)" +
+ "\n\n"
+ ) # Eeschema starter code
+
+ # sym_file.write("#encoding utf-8"+ "\n"+ "#"+ "\n" +
# "#test_compo" + "\n"+ "#"+ "\n")
- lib_file.write(
+ sym_file.write(
self.template["start_def"] + "\n" + self.template["U_field"] + "\n"
)
@@ -221,7 +230,7 @@ class AutoSchematic:
line3 = [w.replace('comp_name', self.modelname) for w in line3]
self.template["comp_name_field"] = ' '.join(line3)
- lib_file.write(self.template["comp_name_field"] + "\n")
+ sym_file.write(self.template["comp_name_field"] + "\n")
line4 = self.template["blank_field"]
line4_1 = line4[0]
@@ -234,20 +243,22 @@ class AutoSchematic:
line4[1] = ' '.join(line4_2)
self.template["blank_qoutes"] = line4
- lib_file.write(line4[0] + "\n" + line4[1] + "\n")
+ sym_file.write(line4[0] + "\n" + line4[1] + "\n")
draw_pos = self.template["draw_pos"]
draw_pos = draw_pos.split()
- draw_pos= [w.replace('comp_name', f"{self.modelname}_0_1") for w in draw_pos]
- draw_pos[8] = str(float(draw_pos[8]) + float(self.findBlockSize() * self.inc_size)) ##previously it is (-)
- draw_pos_rec= draw_pos[8]
-
+ draw_pos = \
+ [w.replace('comp_name', f"{self.modelname}_0_1") for w in draw_pos]
+ draw_pos[8] = str(float(draw_pos[8]) + # previously it is (-)
+ float(self.findBlockSize() * self.inc_size))
+ draw_pos_rec = draw_pos[8]
+
self.template["draw_pos"] = ' '.join(draw_pos)
- lib_file.write(
- self.template["draw_pos"] + "\n"+
- self.template["start_draw"] + " \""+ f"{self.modelname}_1_1\""+ "\n"
+ sym_file.write(
+ self.template["draw_pos"] + "\n" + self.template["start_draw"] +
+ " \"" + f"{self.modelname}_1_1\"" + "\n"
)
input_port = self.template["input_port"]
@@ -270,12 +281,6 @@ class AutoSchematic:
self.portName[i] +
str(int(outputs[i - self.input_length]) - j - 1))
- # print("INPUTS AND OUTPUTS ")
- # print("INPUTS:"+inputName)
- # print("OUTPUTS:"outputName)
- # print(inputs)
- # print(outputs)
-
inputs = self.char_sum(inputs)
outputs = self.char_sum(outputs)
@@ -283,16 +288,17 @@ class AutoSchematic:
port_list = []
- # Set input & output port
- input_port[4] = draw_pos_rec
- output_port[4] =draw_pos_rec
+ # Set input & output port
+ input_port[4] = draw_pos_rec
+ output_port[4] = draw_pos_rec
j = 0
for i in range(total):
if (i < inputs):
input_port[9] = f"\"{inputName[i]}\""
input_port[13] = f"\"{str(i + 1)}\""
- input_port[4] = str(float(input_port[4]) - float(self.dist_port))
+ input_port[4] = \
+ str(float(input_port[4]) - float(self.dist_port))
input_list = ' '.join(input_port)
port_list.append(input_list)
j = j + 1
@@ -300,33 +306,35 @@ class AutoSchematic:
else:
output_port[9] = f"\"{outputName[i - inputs]}\""
output_port[13] = f"\"{str(i + 1)}\""
- output_port[4] = str(float(output_port[4]) - float(self.dist_port))
+ output_port[4] = \
+ str(float(output_port[4]) - float(self.dist_port))
output_list = ' '.join(output_port)
port_list.append(output_list)
for ports in port_list:
- lib_file.write(ports + "\n")
- lib_file.write(
+ sym_file.write(ports + "\n")
+ sym_file.write(
self.template["end_draw"] + "\n\n\n"+")"
)
- lib_file.close()
+ sym_file.close()
os.chdir(cwd)
-# beginning the PortInfo Class containing Port Information
class PortInfo:
-
- # initialising the variables
+ '''
+ The class contains port information
+ '''
def __init__(self, model, modelpath):
self.modelname = model.modelname
- # self.model_loc = model.parser.get('NGVERI', 'DIGITAL_MODEL')
self.bit_list = []
self.port_name = []
self.input_len = 0
self.modelpath = modelpath
- # getting the port information from connection_info.txt
def getPortInfo(self):
+ '''
+ getting the port information from `connection_info.txt`
+ '''
input_list = []
output_list = []
read_file = open(self.modelpath + 'connection_info.txt', 'r')
@@ -354,8 +362,7 @@ class PortInfo:
input_list.append(line.split())
if out_items:
output_list.append(line.split())
- # print(input_list)
- # print(output_list)
+
for in_list in input_list:
self.bit_list.append(in_list[2])
self.port_name.append(in_list[0])
diff --git a/src/projManagement/Kicad.py b/src/projManagement/Kicad.py
index 16569d80..833f075e 100644
--- a/src/projManagement/Kicad.py
+++ b/src/projManagement/Kicad.py
@@ -10,10 +10,10 @@
# BUGS: ---
# NOTES: ---
# AUTHOR: Fahim Khan, fahim.elex@gmail.com
-# MODIFIED: Rahul Paknikar, rahulp@iitb.ac.in
+# MODIFIED: Rahul Paknikar, Partha Singh Roy
# ORGANIZATION: eSim Team at FOSSEE, IIT Bombay
# CREATED: Tuesday 17 February 2015
-# REVISION: Sunday 26 July 2020
+# REVISION: Thursday 29 Jun 2023
# =========================================================================
import os
@@ -25,7 +25,7 @@ from PyQt5 import QtWidgets
class Kicad:
"""
- This class called the Kicad Schematic,KicadtoNgspice Converter,Layout
+ This class called the Kicad Schematic, KicadtoNgspice Converter, Layout
editor and Footprint Editor
Initialise validation, appconfig and dockarea
@@ -79,19 +79,17 @@ class Kicad:
'Kicad Schematic is called for project ' + self.projDir)
except BaseException:
pass
- # Validating if current project is available or not
+ # Validating if current project is available or not
if self.obj_validation.validateKicad(self.projDir):
self.projName = os.path.basename(self.projDir)
self.project = os.path.join(self.projDir, self.projName)
- # Creating a command to run
- if os.path.exists(self.project + ".kicad_sch"):
- self.cmd = "eeschema " + self.project + ".kicad_sch" #kicad v6 file
- elif os.path.exists(self.project + ".sch"):
- self.cmd = "eeschema " + self.project + ".sch" #kicad v4 file
- else:
- self.cmd = "eeschema " + self.project + ".kicad_sch"
+ # creating a command to open schematic
+ self.cmd = "eeschema " + self.project + ".kicad_sch" # kicad6 file
+ if not os.path.exists(self.project + ".kicad_sch") \
+ and os.path.exists(self.project + ".sch"):
+ self.cmd = "eeschema " + self.project + ".sch" # kicad4 file
self.obj_workThread.args = self.cmd
self.obj_workThread.start()
diff --git a/src/projManagement/newProject.py b/src/projManagement/newProject.py
index 8b305964..10fb0cb5 100644
--- a/src/projManagement/newProject.py
+++ b/src/projManagement/newProject.py
@@ -94,7 +94,8 @@ class NewProjectInfo(QtWidgets.QWidget):
)
self.msg.exec_()
- f.write("schematicFile " + self.projName + ".kicad_sch\n") #New KiCad V6 file extension
+ # New KiCad v6 file extension
+ f.write("schematicFile " + self.projName + ".kicad_sch\n")
f.close()
# Now Change the current working project