1
1
#!/usr/bin/env python3
2
2
# -*- coding: utf-8 -*-
3
3
#
4
- # Logic Circuits
4
+ # Logic Circuits - component.py
5
5
#
6
6
# Copyleft 2015 Chris Meyers <[email protected] > 2015.12.13
7
7
#
20
20
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
21
# Boston, MA 02110-1301, USA.
22
22
#
23
- #
24
23
25
24
from __future__ import print_function
26
25
from six .moves import input # use raw_input when I say input
36
35
__status__ = "Development" # "Prototype", "Development" or "Production"
37
36
__appname__ = "Logic Circuits"
38
37
39
- # component.py
40
- #
41
38
import settings as set
42
39
43
- class Component :
44
- def __init__ (self , parent , name , pos = (0 ,0 ), scale = 1 ) :
40
+
41
+ class Component :
42
+ def __init__ (self , parent , name , pos = (0 , 0 ), scale = 1 ):
45
43
self .parent = parent
46
44
self .kids = ()
47
45
self .name = name
@@ -50,65 +48,76 @@ def __init__(self, parent, name, pos=(0,0), scale=1) :
50
48
self .layer = 1
51
49
self .value = 1
52
50
self .banner = ""
53
- if parent :
51
+ if parent :
54
52
self .scale *= parent .scale
55
- self .layer = parent .layer + 1
53
+ self .layer = parent .layer + 1
56
54
parent .kids += (self ,)
57
55
self .setupGraphics ()
58
56
59
- def x (s , val = 0 ) : return s .pos [0 ]+ val * s .scale
60
- def y (s , val = 0 ) : return s .pos [1 ]+ val * s .scale
57
+ def x (s , val = 0 ):
58
+ return s .pos [0 ] + val * s .scale
59
+
60
+ def y (s , val = 0 ):
61
+ return s .pos [1 ] + val * s .scale
61
62
62
- def align (s ,myCon ,pivotCon , xoff , yoff ) :
63
+ def align (s , myCon , pivotCon , xoff , yoff ):
63
64
# Align so that seperation of 2 connectors is (xoff,yoff)
64
65
pivX , pivY = pivotCon .pos
65
66
oldX , oldY = myCon .pos
66
- xoff *= s .scale ; yoff *= s .scale
67
- newX = pivX + xoff ; newY = pivY + yoff
68
- xmov = newX - oldX ; ymov = newY - oldY
67
+ xoff *= s .scale
68
+ yoff *= s .scale
69
+ newX = pivX + xoff
70
+ newY = pivY + yoff
71
+ xmov = newX - oldX
72
+ ymov = newY - oldY
69
73
s .scootOver (xmov , ymov )
70
74
71
- def encapsulated (s ) :
75
+ def encapsulated (s ):
72
76
return s .layer == set .CmdEncapsuleLayer
73
77
74
- def hidden (s ) :
78
+ def hidden (s ):
75
79
return s .layer > set .CmdEncapsuleLayer
76
80
77
- def scaleM (self , * args ) : # scale multiple args
81
+ def scaleM (self , * args ): # scale multiple args
78
82
return map (self .scale1 , args )
79
83
80
- def scale1 (s , arg ) : # transform single point or scalar
81
- if type (arg ) == type (5 ) :
82
- return arg * s .scale
83
- elif type (arg ) == type ((4 ,)) or type (arg )== type ([4 ]) :
84
- return posAdd (s .pos ,posMult (arg ,s .scale ))
84
+ def scale1 (s , arg ): # transform single point or scalar
85
+ if type (arg ) == type (5 ):
86
+ return arg * s .scale
87
+ elif type (arg ) == type ((4 ,)) or type (arg )== type ([4 ]):
88
+ return posAdd (s .pos , posMult (arg , s .scale ))
85
89
86
- def sendOutput (self ) :
90
+ def sendOutput (self ):
87
91
self .output .sendOutput () # between connectors
88
92
89
- def checkClicked (self , clicked ) :
90
- if abs (clicked [0 ]- self .pos [0 ]) <= 15 :
91
- if abs (clicked [1 ]- self .pos [1 ]) <= 15 :
93
+ def checkClicked (self , clicked ):
94
+ if abs (clicked [0 ] - self .pos [0 ]) <= 15 :
95
+ if abs (clicked [1 ] - self .pos [1 ]) <= 15 :
92
96
self .takeClick ()
93
97
94
- def takeClick (self ) : # default action
95
- if set .Debug : print self .name , "was clicked"
98
+ def takeClick (self ): # default action
99
+ if set .Debug :
100
+ print ("{0} was clicked" .format (self .name ))
96
101
97
- def scootOver (self , xmov , ymov , nest = "" ) :
102
+ def scootOver (self , xmov , ymov , nest = "" ):
98
103
# not only yourself but everything inside too
99
- self .pos = posAdd (self .pos , (xmov ,ymov ))
100
- for kid in self .kids :
104
+ self .pos = posAdd (self .pos , (xmov , ymov ))
105
+ for kid in self .kids :
101
106
# kid is either an inner component or a connector
102
- kid .scootOver (xmov , ymov , nest + " " )
107
+ kid .scootOver (xmov , ymov , nest + " " )
103
108
104
- def __repr__ (s ) :
109
+ def __repr__ (s ):
105
110
par = s .parent
106
- if par : par = par .name
107
- return "<Comp: %s.%s %s %s>" % (par ,s .name ,s .pos ,s .layer )
111
+ if par :
112
+ par = par .name
113
+ return "<Comp: {0}.{1} {2} {3}>" .format (par , s .name , s .pos , s .layer )
114
+
108
115
109
- def posMult (pos ,factor ) : # position math
110
- return (pos [0 ]* factor ,pos [1 ]* factor )
116
+ def posMult (pos , factor ): # position math
117
+ return (pos [0 ] * factor ,
118
+ pos [1 ] * factor )
111
119
112
- def posAdd (pos1 , pos2 ) :
113
- return (pos1 [0 ]+ pos2 [0 ],pos1 [1 ]+ pos2 [1 ])
114
120
121
+ def posAdd (pos1 , pos2 ):
122
+ return (pos1 [0 ] + pos2 [0 ],
123
+ pos1 [1 ] + pos2 [1 ])
0 commit comments