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
|
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from random import randint
def get_comp(design, num):
try:
c = [x for x in design.complist if x.num == num][0]
except:
c = Component(design)
c.num = num
return c
class Component:
def __init__(self, design):
design.complist.append(self)
self.design = design
self.name = ""
self.num = 0
self.pins_in = []
self.pins_out = []
self.x = randint(0, design.width-150)
self.y = randint(0, design.height-200)
self.widget = None
self.redraw()
def redraw(self):
if self.widget:
self.widget.destroy()
self.widget = self.design.canvas.add_comp(self, self.x, self.y)
for pin in self.pins_in + self.pins_out:
pin.redraw()
def read_pos(self):
self.x = self.widget.get_property('x')
self.y = self.widget.get_property('y')
for pin in self.pins_in + self.pins_out:
pin.redraw()
def move(self, pos):
self.x, self.y = pos
self.redraw()
for pin in self.pins_in + self.pins_out:
pin.redraw()
def get_pin(component, name, dtype, perm, value):
try:
p = [x for x in component.pins_in + component.pins_out if x.name == name][0]
except:
p = Pin(component, name, dtype, perm, value)
return p
class Pin:
def __init__(self, component, name, dtype, perm, value):
self.component = component
self.design = component.design
self.name = name
self.dtype = dtype
self.perm = perm
self.value = value
self.signal = None
self.sigwid = None
self.x = 0
self.y = 0
def redraw(self):
if self.sigwid:
self.sigwid.destroy()
self.sigwid = None
if self.signal:
self.sigwid = self.design.canvas.add_sigline(self)
def get_sig(design, name, dtype):
try:
c = [x for x in design.siglist if x.name == name][0]
except:
c = Signal(design, name, dtype)
return c
class Signal:
def __init__(self, design, name, dtype):
self.design = design
self.name = name
self.dtype = dtype
self.pinlist = []
self.x = randint(0, design.width-150)
self.y = randint(0, design.height-200)
self.widget = None
design.siglist.append(self)
self.redraw()
def addpin(self, pin):
self.pinlist.append(pin)
pin.signal = self
def redraw(self):
if self.widget:
self.widget.destroy()
self.widget = self.design.canvas.add_sig(self, self.x, self.y)
def read_pos(self):
self.x = self.widget.get_property('x')
self.y = self.widget.get_property('y')
for pin in self.pinlist:
pin.redraw()
def move(self, pos):
self.x, self.y = pos
self.redraw()
for pin in self.pinlist:
pin.redraw()
|