Skip to content

Commit

Permalink
update circuit
Browse files Browse the repository at this point in the history
Signed-off-by: Masaya Kataoka <[email protected]>
  • Loading branch information
hakuturu583 committed Dec 1, 2024
1 parent 81663c6 commit 32180c6
Show file tree
Hide file tree
Showing 25 changed files with 24,467 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
try:
from .plugin import PCBGOGOPlugin
plugin = PCBGOGOPlugin()
plugin.register()
except Exception as e:
import logging
root = logging.getLogger()
root.debug(repr(e))
21 changes: 21 additions & 0 deletions circuits/3rdparty/plugins/PCBGOGO-JP-Plug-in-for-Kicad/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pcbnew

#baseUrl = 'http://www.pcbgogo.jp'
baseUrl = 'https://www.pcbgogo.jp'
netlistFilename = 'PCBGOGO_netlist.ipc'
componentsFilename = 'PCBGOGO_components.json'
plotPlan = [
("F.Cu", pcbnew.F_Cu, "Top Layer"),
("B.Cu", pcbnew.B_Cu, "Bottom Layer"),
("In1.Cu", pcbnew.In1_Cu, "Internal plane 1"),
("In2.Cu", pcbnew.In2_Cu, "Internal plane 2"),
("In3.Cu", pcbnew.In3_Cu, "Internal plane 3"),
("In4.Cu", pcbnew.In4_Cu, "Internal plane 4"),
("F.SilkS", pcbnew.F_SilkS, "Top Silkscreen"),
("B.SilkS", pcbnew.B_SilkS, "Bottom Silkscreen"),
("F.Mask", pcbnew.F_Mask, "Top Soldermask"),
("B.Mask", pcbnew.B_Mask, "Bottom Soldermask"),
("F.Paste", pcbnew.F_Paste, "Top Paste (Stencil)"),
("B.Paste", pcbnew.B_Paste, "Bottom Paste (Stencil)"),
("Edge.Cuts", pcbnew.Edge_Cuts, "Board Outline")
]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions circuits/3rdparty/plugins/PCBGOGO-JP-Plug-in-for-Kicad/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import wx
import pcbnew

from .thread import *
from .result_event import *


class KiCadToPCBGOGOForm(wx.Frame):
def __init__(self):
wx.Dialog.__init__(
self,
None,
id=wx.ID_ANY,
title=u"PCBGOGO is processing...",
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=wx.DEFAULT_DIALOG_STYLE)

self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)

bSizer1 = wx.BoxSizer(wx.VERTICAL)

self.m_gaugeStatus = wx.Gauge(
self, wx.ID_ANY, 100, wx.DefaultPosition, wx.Size(
300, 20), wx.GA_HORIZONTAL)
self.m_gaugeStatus.SetValue(0)
bSizer1.Add(self.m_gaugeStatus, 0, wx.ALL, 5)

self.SetSizer(bSizer1)
self.Layout()
bSizer1.Fit(self)

self.Centre(wx.BOTH)

EVT_RESULT(self, self.updateDisplay)
PCBGOGOThread(self)

def updateDisplay(self, status):
if status.data == -1:
pcbnew.Refresh()
self.Destroy()
else:
self.m_gaugeStatus.SetValue(status.data)


class PCBGOGOPlugin(pcbnew.ActionPlugin):
def __init__(self):
self.name = "PCBGOGO JP Plug-in for KiCad" # 插件名称
self.category = "Manufacturing" # 描述性类别名称
self.description = "Start prototype and assembly by sending files to PCBGOGO with just one click." # 对插件及其功能的描述
self.pcbnew_icon_support = hasattr(self, "show_toolbar_button")
self.show_toolbar_button = True # 可选,默认为 False
self.icon_file_name = os.path.join(
os.path.dirname(__file__), 'icon.png') # 可选,默认为 ""
self.dark_icon_file_name = os.path.join(
os.path.dirname(__file__), 'icon.png')

def Run(self):
# 在用户操作时执行的插件的入口函数
KiCadToPCBGOGOForm().Show()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import wx

EVT_RESULT_ID = wx.NewId()


def EVT_RESULT(win, func):
win.Connect(-1, -1, EVT_RESULT_ID, func)


class ResultEvent(wx.PyEvent):
def __init__(self, data):
wx.PyEvent.__init__(self)
self.SetEventType(EVT_RESULT_ID)
self.data = data
173 changes: 173 additions & 0 deletions circuits/3rdparty/plugins/PCBGOGO-JP-Plug-in-for-Kicad/thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#copyright Aisler and licensed under the MIT license.
#https://opensource.org/licenses/MIT

import os
import webbrowser
import shutil
import json
import requests
import wx
import tempfile
from threading import Thread
from .result_event import *
from .config import *


class PCBGOGOThread(Thread):
def __init__(self, wxObject):
Thread.__init__(self)
self.wxObject = wxObject
self.start()

def run(self):

temp_dir = tempfile.mkdtemp()
_, temp_file = tempfile.mkstemp()
board = pcbnew.GetBoard()
title_block = board.GetTitleBlock()
p_name = board.GetFileName()

self.report(5)

settings = board.GetDesignSettings()
settings.m_SolderMaskMargin = 0
settings.m_SolderMaskMinWidth = 0

pctl = pcbnew.PLOT_CONTROLLER(board)

popt = pctl.GetPlotOptions()
popt.SetOutputDirectory(temp_dir)
popt.SetPlotFrameRef(False)
popt.SetSketchPadLineWidth(pcbnew.FromMM(0.1))
popt.SetAutoScale(False)
popt.SetScale(1)
popt.SetMirror(False)
popt.SetUseGerberAttributes(True)
if hasattr(popt, "SetExcludeEdgeLayer"):
popt.SetExcludeEdgeLayer(True)
popt.SetUseGerberProtelExtensions(False)
popt.SetUseAuxOrigin(True)
popt.SetSubtractMaskFromSilk(False)
popt.SetDrillMarksType(0) # NO_DRILL_SHAPE

self.report(20)
for layer_info in plotPlan:
if board.IsLayerEnabled(layer_info[1]):
pctl.SetLayer(layer_info[1])
pctl.OpenPlotfile(
layer_info[0],
pcbnew.PLOT_FORMAT_GERBER,
layer_info[2])
pctl.PlotLayer()

pctl.ClosePlot()

self.report(25)
drlwriter = pcbnew.EXCELLON_WRITER(board)

drlwriter.SetOptions(
False,
True,
board.GetDesignSettings().GetAuxOrigin(),
False)
drlwriter.SetFormat(False)
drlwriter.CreateDrillandMapFilesSet(pctl.GetPlotDirName(), True, False)

self.report(30)
netlist_writer = pcbnew.IPC356D_WRITER(board)
netlist_writer.Write(os.path.join(temp_dir, netlistFilename))

self.report(35)
components = []
if hasattr(board, 'GetModules'):
footprints = list(board.GetModules())
else:
footprints = list(board.GetFootprints())

for i, f in enumerate(footprints):
try:
footprint_name = str(f.GetFPID().GetFootprintName())
except AttributeError:
footprint_name = str(f.GetFPID().GetLibItemName())

layer = {
pcbnew.F_Cu: 'top',
pcbnew.B_Cu: 'bottom',
}.get(f.GetLayer())

attrs = f.GetAttributes()
parsed_attrs = self.parse_attrs(attrs)

mount_type = 'smt' if parsed_attrs['smd'] else 'tht'
placed = not parsed_attrs['not_in_bom']

rotation = f.GetOrientation().AsDegrees() if hasattr(f.GetOrientation(), 'AsDegrees') else f.GetOrientation() / 10.0
designator = f.GetReference()

components.append({
'pos_x': (f.GetPosition()[0] - board.GetDesignSettings().GetAuxOrigin()[0]) / 1000000.0,
'pos_y': (f.GetPosition()[1] - board.GetDesignSettings().GetAuxOrigin()[1]) * -1.0 / 1000000.0,
'rotation': rotation,
'side': layer,
'designator': designator,
'mpn': self.getMpnFromFootprint(f),
'pack': footprint_name,
'value': f.GetValue(),
'mount_type': mount_type,
'place': placed
})

boardWidth = pcbnew.ToMM(board.GetBoardEdgesBoundingBox().GetWidth())
boardHeight = pcbnew.ToMM(board.GetBoardEdgesBoundingBox().GetHeight())
if hasattr(board, 'GetCopperLayerCount'):
boardLayer = board.GetCopperLayerCount()
with open((os.path.join(temp_dir, componentsFilename)), 'w') as outfile:
json.dump(components, outfile)

temp_file = shutil.make_archive(p_name, 'zip', temp_dir)
files = {'upload[file]': open(temp_file, 'rb')}

upload_url = baseUrl + '/Common/KiCadUpFile/'

self.report(45)

rsp = requests.post(
upload_url, files=files, data={'boardWidth':boardWidth,'boardHeight':boardHeight,'boardLayer':boardLayer})

urls = json.loads(rsp.content)

readsofar = 0
totalsize = os.path.getsize(temp_file)
with open(temp_file, 'rb') as file:
while True:
data = file.read(10)
if not data:
break
readsofar += len(data)
percent = readsofar * 1e2 / totalsize
self.report(45 + percent / 1.8)

webbrowser.open(urls['redirect'])
self.report(-1)

def report(self, status):
wx.PostEvent(self.wxObject, ResultEvent(status))

def getMpnFromFootprint(self, f):
keys = ['mpn', 'MPN', 'Mpn', 'PCBWay_MPN']
for key in keys:
if f.HasProperty(key):
return f.GetProperty(key)

def parse_attr_flag(self, attr, mask):
return mask == (attr & mask)

def parse_attrs(self, attrs):
return {} if not isinstance(attrs, int) else {
'tht': self.parse_attr_flag(attrs, pcbnew.FP_THROUGH_HOLE),
'smd': self.parse_attr_flag(attrs, pcbnew.FP_SMD),
'not_in_pos': self.parse_attr_flag(attrs, pcbnew.FP_EXCLUDE_FROM_POS_FILES),
'not_in_bom': self.parse_attr_flag(attrs, pcbnew.FP_EXCLUDE_FROM_BOM),
'not_in_plan': self.parse_attr_flag(attrs, pcbnew.FP_BOARD_ONLY)
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(kicad_symbol_lib
(version 20231120)
(generator "kicad_symbol_editor")
(generator_version "8.0")
(symbol "2MD1-T2-B4-M2-Q-N"
(exclude_from_sim no)
(in_bom yes)
(on_board yes)
(property "Reference" "U"
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Value" ""
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Footprint" ""
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(property "Datasheet" ""
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(property "Description" ""
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
)
)
Loading

0 comments on commit 32180c6

Please sign in to comment.