-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpcblocator.py
executable file
·129 lines (94 loc) · 3.48 KB
/
pcblocator.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
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
#!/usr/bin/env python
from gimpfu import *
import re
# create an output function that redirects to gimp's Error Console
def gprint( text ):
pdb.gimp_message(text)
return
#set board layer location relative to main layer
def set_locationrel(boardlayer,mainlayer,cox,coy):
relposx , relposy = get_locationrel(boardlayer,mainlayer)
images = gimp.image_list()
g = gimp.pdb
g.gimp_layer_translate(boardlayer,relposx-cox,relposy-coy)
def get_locationrel(mainlayer,boardlayer):
images = gimp.image_list()
mainlayercox = mainlayer.offsets[0]
mainlayercoy = mainlayer.offsets[1]
boardlayercox = boardlayer.offsets[0]
boardlayercoy = boardlayer.offsets[1]
relposx = boardlayercox - mainlayercox
relposy = boardlayercoy - mainlayercoy
return relposx,relposy
# our script
def set_btaction(image, drawable, text) :
g = gimp.pdb
images = gimp.image_list()
gprint(text)
m = re.compile('\(([^)]*)\)').search(text)
if m:
print('Match found:' + str(m.group()) )
startsub = m.start()
endsub = m.end()
# Get bottom name layers #
bottomboardlayerName = text[startsub+1 : endsub-1].split(',')
bottommainlayerName = text[:startsub]
# Get bottom layer objects from name
bottommainlayer = get_layer_from_name(bottommainlayerName)
bottomboardlayer = []
for n in bottomboardlayerName:
print "**debug: "+str(get_layer_from_name(n))
bottomboardlayer.append(get_layer_from_name(n))
# Get names of top layers
topmainlayerName = get_the_top_name(bottommainlayerName)
topboardlayerName=[]
for n in bottomboardlayerName:
topboardlayerName.append(get_the_top_name(n))
# Get top layer objects from name.
topmainlayer = get_layer_from_name(topmainlayerName)
topboardlayer = []
for n in topboardlayerName:
topboardlayer.append(get_layer_from_name(n))
# sizes of top main layers.
wtopmainlayer = g.gimp_drawable_width(topmainlayer)
htopmainlayer = g.gimp_drawable_height(topmainlayer)
print("The layer variable names")
print(topmainlayer)
print(topboardlayer)
print(bottommainlayer)
print(bottomboardlayer)
for idx,n in enumerate(topboardlayer):
cox,coy = get_locationrel(bottomboardlayer[idx],bottommainlayer)
set_locationrel(n,topmainlayer, -(wtopmainlayer-(abs(cox)+g.gimp_drawable_width(topboardlayer[idx]) )) ,coy )
g.gimp_flip(topboardlayer[idx],0)
gprint("**"+str(cox)+"**"+str(coy))
else:
print('No match')
return
def get_the_top_name(boardname):
return re.sub('bottom','top', boardname)
def get_layer_from_name(name):
images = gimp.image_list()
flagname=0
for idx,nlayer in enumerate(images[0].layers):
if(nlayer.name == name):
flagname = idx
return(images[0].layers[flagname])
# This is the plugin registration function
register(
"locate_pcba",
"Locate pcba",
"Locates(and mirrors) the top side for double sided boards, in function of the position of the bottom ones",
"Miguel Jimenez",
"GPL licensed",
"August 2011",
"<Image>/PCB/PCBLocator",
"*",
[
(PF_STRING, 'some_text', 'Layers operator[mainbottom(subbottom,...)]', '...'),
#(PF_INT, 'some_integer', 'Some number input for our plugin', 2010)
],
[],
set_btaction,
)
main()