-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModulePlacer.py
47 lines (40 loc) · 1.8 KB
/
ModulePlacer.py
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
from math import *
import pcbnew
import wx
import os
import re
class ModulePlacer(pcbnew.ActionPlugin):
def defaults(self):
self.name = "Module placer"
self.category = "Modify PCB"
self.description = "Place modules using coordinates file"
#self.icon_file_name = os.path.join(os.path.dirname(__file__), "./round_keepout_area.png")
#self.show_toolbar_button = True
def processFile(self,pathname):
with open(pathname, 'r') as f:
content = f.readlines()
content = [x.strip() for x in content]
for line in content:
mc = re.split("\s+",line)
if len(mc) >= 3:
module = self.pcb.FindFootprintByReference(mc[0])
if module != None:
if hasattr(pcbnew, 'EDA_RECT'):
module.SetPosition(pcbnew.wxPointMM(float(mc[1]),float(mc[2])))
else:
module.SetPosition(pcbnew.VECTOR2I_MM(float(mc[1]),float(mc[2])))
if len(mc) == 4:
module.SetOrientationDegrees(float(mc[3]))
else:
wx.LogError("|".join(mc))
def Run(self):
self.pcb = pcbnew.GetBoard()
projectdir = os.path.dirname(self.pcb.GetFileName())
with wx.FileDialog(None, "Open file", defaultDir = projectdir, wildcard="txt files (*.txt)|*.txt|all files (*)|*",
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return # the user changed their mind
# Proceed loading the file chosen by the user
pathname = fileDialog.GetPath()
self.processFile(pathname)
self.pcb.GetConnectivity().RecalculateRatsnest()