-
Notifications
You must be signed in to change notification settings - Fork 9
/
CameraBeamBrick.py
256 lines (210 loc) · 8.91 KB
/
CameraBeamBrick.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
"""
Camera Beam Brick
[Description]
This brick displays and save for different zoom value a beam position.
[Properties]
zoom - string - MultiplePositions hardware object which reference the different
zoom position and allows to save beam position for each of them
[Signals]
ChangeBeamPosition - (xpos,ypos) - emitted when beam position change for a
given zoom value.
The client must get the zoom hardware
object to know the current zoom position.
[Slots]
getBeamPosition - position["ybeam"] - When a client want to know the current
position["zbeam"] beam position, it can connect a signal
to this slot. At return of its emit call
the dictionnary passed as argument will
be filled with the current beam position
beamPositionChanged - ybeam, zbeam - slot which should be connected to all
client able to change beam position.
Display numerically and save the new
beam positions.
setBrickEnabled - isEnabled - slot to call to disable the brick (expert mode for example).
[Comments]
"""
import qt
import sys
import qttable
from BlissFramework.BaseComponents import BlissWidget
from Qub.Objects.QubDrawingManager import QubPointDrawingMgr
from Qub.Objects.QubDrawingEvent import QubMoveNPressed1Point
from Qub.Objects.QubDrawingCanvasTools import QubCanvasTarget
__category__ = "Camera"
#############################################################################
########## ##########
########## BRICK ##########
########## ##########
#############################################################################
class CameraBeamBrick(BlissWidget):
def __init__(self, parent, name):
BlissWidget.__init__(self, parent, name)
"""
variables
"""
self.YBeam = None
self.ZBeam = None
"""
property
"""
self.addProperty("zoom", "string", "")
self.hwZoom = None
"""
signals
"""
self.defineSignal("ChangeBeamPosition", ())
"""
slots
"""
self.defineSlot("getBeamPosition", ())
self.defineSlot("beamPositionChanged", ())
self.defineSlot("setBrickEnabled", ())
self.buildInterface()
def buildInterface(self):
vlayout = qt.QVBoxLayout(self)
title = qt.QLabel("<B>Beam Position<B>", self)
title.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Expanding,
qt.QSizePolicy.Fixed))
vlayout.addWidget(title)
self.calibFrame = qt.QFrame(self)
self.calibFrame.setFrameShape(qt.QFrame.Box)
self.calibFrame.setFrameShadow(qt.QFrame.Sunken)
vlayout.addWidget(self.calibFrame)
vlayout1 = qt.QVBoxLayout(self.calibFrame)
vlayout1.setMargin(10)
self.table = qttable.QTable(0,3, self.calibFrame)
self.table.setFocusPolicy(qt.QWidget.NoFocus)
self.table.setSelectionMode(qttable.QTable.NoSelection)
self.table.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Minimum,
qt.QSizePolicy.Minimum))
self.table.verticalHeader().hide()
self.table.setLeftMargin(0)
self.table.setReadOnly(True)
header = self.table.horizontalHeader()
header.setLabel(0, "Zoom")
header.setLabel(1, "Y Beam (pix.)")
header.setLabel(2, "Z Beam (pix.)")
self.table.clearSelection(True)
vlayout1.addWidget(self.table)
vlayout1.addSpacing(10)
f1 = qt.QFrame(self.calibFrame)
f1.setFrameShape(qt.QFrame.HLine)
f1.setFrameShadow(qt.QFrame.Sunken)
vlayout1.addWidget(f1)
vlayout1.addSpacing(10)
self.saveButton = qt.QPushButton("Save Current Beam Pos.",
self.calibFrame)
self.connect(self.saveButton, qt.SIGNAL("clicked()"),
self.saveCalibration)
vlayout1.addWidget(self.saveButton)
vlayout1.addStretch(1)
def propertyChanged(self, prop, oldValue, newValue):
if prop == "zoom":
if self.hwZoom is not None:
self.disconnect(self.hwZoom, qt.PYSIGNAL("positionReached"),
self.zoomChanged)
self.disconnect(self.hwZoom, qt.PYSIGNAL("noPosition"),
self.zoomChanged)
self.hwZoom = self.getHardwareObject(newValue)
if self.hwZoom is not None:
self.connect(self.hwZoom, qt.PYSIGNAL("positionReached"),
self.zoomChanged)
self.connect(self.hwZoom, qt.PYSIGNAL("noPosition"),
self.zoomChanged)
self.initInterface()
self.zoomChanged()
def run(self):
self.zoomChanged()
def initInterface(self):
if self.hwZoom is not None:
pos = self.hwZoom.positionsIndex
self.table.setNumRows(len(pos))
for i in range(len(pos)):
aux = self.hwZoom.getPositionKeyValue(pos[i], "beamx")
if aux is None:
aux = "0"
beamy = float(aux)
aux = self.hwZoom.getPositionKeyValue(pos[i], "beamy")
if aux is None:
aux = "0"
beamz = float(aux)
self.table.setText(i, 0, pos[i])
if beamy is not None:
self.table.setText(i, 1, str(beamy))
else:
self.table.setText(i, 1, "Not Defined")
if beamz is not None:
self.table.setText(i, 2, str(beamz))
else:
self.table.setText(i, 2, "Not Defined")
self.table.adjustColumn(0)
self.table.adjustColumn(1)
self.table.adjustColumn(2)
def getZoomIndex(self, position):
positions = self.hwZoom.positionsIndex
for i in range(len(positions)):
if position == positions[i]:
return(i)
return(-1)
def zoomChanged(self):
if self.hwZoom is not None:
currentPos = self.hwZoom.getPosition()
self.currIdx = self.getZoomIndex(currentPos)
if self.table.numSelections() != -1:
self.table.clearSelection(True)
if self.currIdx != -1:
aux = self.hwZoom.getPositionKeyValue(currentPos,"beamx")
if aux is None:
aux = "0"
beamy = float(aux)
aux = self.hwZoom.getPositionKeyValue(currentPos,"beamy")
if aux is None:
aux = "0"
beamz = float(aux)
self.YBeam = beamy
self.ZBeam = beamz
self.table.selectRow(self.currIdx)
if beamy is not None:
self.table.setText(self.currIdx, 1, str(beamy))
else:
self.table.setText(self.currIdx, 1, "Not Defined")
if beamz is not None:
self.table.setText(self.currIdx, 2, str(beamz))
else:
self.table.setText(self.currIdx, 2, "Not Defined")
else:
# self.YBeam = None
# self.ZBeam = None
print "CameraBeamBrick.py--zoomChanged--zerouillage"
self.YBeam = 0
self.ZBeam = 0
else:
# self.YBeam = None
# self.ZBeam = None
print "CameraBeamBrick.py--zoomChanged--zerouying"
self.YBeam = 0
self.ZBeam = 0
self.emit(qt.PYSIGNAL("ChangeBeamPosition"),
(self.YBeam, self.ZBeam))
def saveCalibration(self):
currentPos = self.hwZoom.getPosition()
self.hwZoom.setPositionKeyValue(currentPos, "beamx", str(self.YBeam))
self.hwZoom.setPositionKeyValue(currentPos, "beamy", str(self.ZBeam))
"""
SLOTS
"""
def getBeamPosition(self, position):
position["ybeam"] = self.YBeam
position["zbeam"] = self.ZBeam
def beamPositionChanged(self, beamy, beamz):
self.YBeam = beamy
self.ZBeam = beamz
self.table.setText(self.currIdx, 1, str(beamy))
self.table.setText(self.currIdx, 2, str(beamz))
def setBrickEnabled(self, value):
if value:
# print "Someone ask to enable CameraBeamBrick."
self.setEnabled(True)
else:
# print "Someone ask to disable CameraBeamBrick."
self.setEnabled(False)