Skip to content

Commit 6f77538

Browse files
committed
qtvcp -offsetview: add rotational column
All user coordinates have rotational offsets. Now one can set them all
1 parent 67ea71a commit 6f77538

1 file changed

Lines changed: 97 additions & 76 deletions

File tree

lib/python/qtvcp/widgets/origin_offsetview.py

Lines changed: 97 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#LOCALEDIR = os.path.join(BASE, "share", "locale")
3131
#locale.setlocale(locale.LC_ALL, '')
3232

33-
# Instiniate the libraries with global reference
33+
# Instantiate the libraries with global reference
3434
# STATUS gives us status messages from linuxcnc
3535
# INI holds ini details
3636
# ACTION gives commands to linuxcnc
@@ -84,30 +84,30 @@ def _hal_init(self):
8484

8585
# If there is a preference file object use it to load the hi/low toggle points
8686
if self.PREFS_:
87-
self.tabledata[4][9] = self.PREFS_.getpref(self.HAL_NAME_+'-G54', 'User System 1', str, 'ORIGINOFFSET_SYSTEM_NAMES')
88-
self.tabledata[5][9] = self.PREFS_.getpref(self.HAL_NAME_+'-G55', 'User System 2', str, 'ORIGINOFFSET_SYSTEM_NAMES')
89-
self.tabledata[6][9] = self.PREFS_.getpref(self.HAL_NAME_+'-G56', 'User System 3', str, 'ORIGINOFFSET_SYSTEM_NAMES')
90-
self.tabledata[7][9] = self.PREFS_.getpref(self.HAL_NAME_+'-G57', 'User System 4', str, 'ORIGINOFFSET_SYSTEM_NAMES')
91-
self.tabledata[8][9] = self.PREFS_.getpref(self.HAL_NAME_+'-G58', 'User System 5', str, 'ORIGINOFFSET_SYSTEM_NAMES')
92-
self.tabledata[9][9] = self.PREFS_.getpref(self.HAL_NAME_+'-G59', 'User System 6', str, 'ORIGINOFFSET_SYSTEM_NAMES')
93-
self.tabledata[10][9] = self.PREFS_.getpref(self.HAL_NAME_+'-G59.1', 'User System 7', str, 'ORIGINOFFSET_SYSTEM_NAMES')
94-
self.tabledata[11][9] = self.PREFS_.getpref(self.HAL_NAME_+'-G59.2', 'User System 8', str, 'ORIGINOFFSET_SYSTEM_NAMES')
95-
self.tabledata[12][9] = self.PREFS_.getpref(self.HAL_NAME_+'-G59.3', 'User System 9', str, 'ORIGINOFFSET_SYSTEM_NAMES')
87+
self.tabledata[4][10] = self.PREFS_.getpref(self.HAL_NAME_+'-G54', 'User System 1', str, 'ORIGINOFFSET_SYSTEM_NAMES')
88+
self.tabledata[5][10] = self.PREFS_.getpref(self.HAL_NAME_+'-G55', 'User System 2', str, 'ORIGINOFFSET_SYSTEM_NAMES')
89+
self.tabledata[6][10] = self.PREFS_.getpref(self.HAL_NAME_+'-G56', 'User System 3', str, 'ORIGINOFFSET_SYSTEM_NAMES')
90+
self.tabledata[7][10] = self.PREFS_.getpref(self.HAL_NAME_+'-G57', 'User System 4', str, 'ORIGINOFFSET_SYSTEM_NAMES')
91+
self.tabledata[8][10] = self.PREFS_.getpref(self.HAL_NAME_+'-G58', 'User System 5', str, 'ORIGINOFFSET_SYSTEM_NAMES')
92+
self.tabledata[9][10] = self.PREFS_.getpref(self.HAL_NAME_+'-G59', 'User System 6', str, 'ORIGINOFFSET_SYSTEM_NAMES')
93+
self.tabledata[10][10] = self.PREFS_.getpref(self.HAL_NAME_+'-G59.1', 'User System 7', str, 'ORIGINOFFSET_SYSTEM_NAMES')
94+
self.tabledata[11][10] = self.PREFS_.getpref(self.HAL_NAME_+'-G59.2', 'User System 8', str, 'ORIGINOFFSET_SYSTEM_NAMES')
95+
self.tabledata[12][10] = self.PREFS_.getpref(self.HAL_NAME_+'-G59.3', 'User System 9', str, 'ORIGINOFFSET_SYSTEM_NAMES')
9696
self.tablemodel.layoutChanged.emit()
9797

9898
# when qtvcp closes this gets called
9999
def _hal_cleanup(self):
100100
if self.PREFS_:
101101
LOG.debug('Saving {} data to file.'.format(self.HAL_NAME_))
102-
self.PREFS_.putpref(self.HAL_NAME_+'-G54', self.tabledata[4][9], str, 'ORIGINOFFSET_SYSTEM_NAMES')
103-
self.PREFS_.putpref(self.HAL_NAME_+'-G55', self.tabledata[5][9], str, 'ORIGINOFFSET_SYSTEM_NAMES')
104-
self.PREFS_.putpref(self.HAL_NAME_+'-G56', self.tabledata[6][9], str, 'ORIGINOFFSET_SYSTEM_NAMES')
105-
self.PREFS_.putpref(self.HAL_NAME_+'-G57', self.tabledata[7][9], str, 'ORIGINOFFSET_SYSTEM_NAMES')
106-
self.PREFS_.putpref(self.HAL_NAME_+'-G58', self.tabledata[8][9], str, 'ORIGINOFFSET_SYSTEM_NAMES')
107-
self.PREFS_.putpref(self.HAL_NAME_+'-G59', self.tabledata[9][9], str, 'ORIGINOFFSET_SYSTEM_NAMES')
108-
self.PREFS_.putpref(self.HAL_NAME_+'-G59.1', self.tabledata[10][9], str, 'ORIGINOFFSET_SYSTEM_NAMES')
109-
self.PREFS_.putpref(self.HAL_NAME_+'-G59.2', self.tabledata[11][9], str, 'ORIGINOFFSET_SYSTEM_NAMES')
110-
self.PREFS_.putpref(self.HAL_NAME_+'-G59.3', self.tabledata[12][9], str, 'ORIGINOFFSET_SYSTEM_NAMES')
102+
self.PREFS_.putpref(self.HAL_NAME_+'-G54', self.tabledata[4][10], str, 'ORIGINOFFSET_SYSTEM_NAMES')
103+
self.PREFS_.putpref(self.HAL_NAME_+'-G55', self.tabledata[5][10], str, 'ORIGINOFFSET_SYSTEM_NAMES')
104+
self.PREFS_.putpref(self.HAL_NAME_+'-G56', self.tabledata[6][10], str, 'ORIGINOFFSET_SYSTEM_NAMES')
105+
self.PREFS_.putpref(self.HAL_NAME_+'-G57', self.tabledata[7][10], str, 'ORIGINOFFSET_SYSTEM_NAMES')
106+
self.PREFS_.putpref(self.HAL_NAME_+'-G58', self.tabledata[8][10], str, 'ORIGINOFFSET_SYSTEM_NAMES')
107+
self.PREFS_.putpref(self.HAL_NAME_+'-G59', self.tabledata[9][10], str, 'ORIGINOFFSET_SYSTEM_NAMES')
108+
self.PREFS_.putpref(self.HAL_NAME_+'-G59.1', self.tabledata[10][10], str, 'ORIGINOFFSET_SYSTEM_NAMES')
109+
self.PREFS_.putpref(self.HAL_NAME_+'-G59.2', self.tabledata[11][10], str, 'ORIGINOFFSET_SYSTEM_NAMES')
110+
self.PREFS_.putpref(self.HAL_NAME_+'-G59.3', self.tabledata[12][10], str, 'ORIGINOFFSET_SYSTEM_NAMES')
111111

112112
def _convert_system(self, w, data):
113113
convert = ("None", "G54", "G55", "G56", "G57", "G58", "G59", "G59.1", "G59.2", "G59.3")
@@ -121,25 +121,25 @@ def metricMode(self, state):
121121

122122
def createTable(self):
123123
# create blank taple array
124-
self.tabledata = [[0, 0, 1, 0, 0, 0, 0, 0, 0, 'Absolute Position'],
125-
[None, None, 2, None, None, None, None, None, None, 'Rotational Offsets'],
126-
[0, 0, 3, 0, 0, 0, 0, 0, 0, 'G92 Offsets'],
127-
[0, 0, 0, 0, 0, 0, 0, 0, 0, 'Current Tool'],
128-
[0, 0, 4, 0, 0, 0, 0, 0, 0, 'System 1'],
129-
[0, 0, 5, 0, 0, 0, 0, 0, 0, 'System 2'],
130-
[0, 0, 6, 0, 0, 0, 0, 0, 0, 'System 3'],
131-
[0, 0, 7, 0, 0, 0, 0, 0, 0, 'System 4'],
132-
[0, 0, 8, 0, 0, 0, 0, 0, 0, 'System 5'],
133-
[0, 0, 9, 0, 0, 0, 0, 0, 0, 'System 6'],
134-
[0, 0, 10, 0, 0, 0, 0, 0, 0, 'System 7'],
135-
[0, 0, 11, 0, 0, 0, 0, 0, 0, 'System 8'],
136-
[0, 0, 12, 0, 0, 0, 0, 0, 0, 'System 9']]
124+
self.tabledata = [[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 'Absolute Position'],
125+
[None, None, 2, None, None, None, None, None, None, None, 'Rotational Offsets'],
126+
[0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 'G92 Offsets'],
127+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Current Tool'],
128+
[0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 'System 1'],
129+
[0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 'System 2'],
130+
[0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 'System 3'],
131+
[0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 'System 4'],
132+
[0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 'System 5'],
133+
[0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 'System 6'],
134+
[0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 'System 7'],
135+
[0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 'System 8'],
136+
[0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 'System 9']]
137137

138138
# create the view
139139
self.setSelectionMode(QAbstractItemView.SingleSelection)
140140

141141
# set the table model
142-
header = ['X', 'Y', 'Z', 'A', 'B', 'C', 'U', 'V', 'W', 'Name']
142+
header = ['X', 'Y', 'Z', 'A', 'B', 'C', 'U', 'V', 'W', 'Rot', 'Name']
143143
vheader = ['ABS', 'Rot', 'G92', 'Tool', 'G54', 'G55', 'G56', 'G57', 'G58', 'G59', 'G59.1', 'G59.2', 'G59.3']
144144
self.tablemodel = MyTableModel(self.tabledata, header, vheader, self)
145145
self.setModel(self.tablemodel)
@@ -172,19 +172,21 @@ def showSelection(self, item):
172172
# display in title bar for convenience
173173
self.setWindowTitle(sf)
174174
# row 0 is not editable (absolute position)
175-
# row has limited entries (rotational)
176-
# column 9 is the descriptive text column
177-
if item.column() == 9:
175+
# row 1 has limited entries (rotational)
176+
# column 10 is the descriptive text column
177+
if item.column() == 10:
178178
self.callTextDialog(text,item)
179179
elif item.row() == 1:
180180
if item.column() == 2:
181181
self.callDialog(text,item)
182+
elif item.row() in (2,3) and item.column() == 9:
183+
pass
182184
elif item.row() > 1:
183185
self.callDialog(text,item)
184186

185187
# alphanumerical
186188
def callTextDialog(self, text,item):
187-
text = self.tablemodel.arraydata[item.row()][9]
189+
text = self.tablemodel.arraydata[item.row()][10]
188190
system = self.tablemodel.Vheaderdata[item.row()]
189191
mess = {'NAME':self.text_dialog_code,'ID':'%s__' % self.objectName(),
190192
'PRELOAD':text, 'TITLE':'{} System Description Entry'.format(system),
@@ -225,7 +227,7 @@ def return_value(self, w, message):
225227

226228
newobj = self.currentIndex()
227229
# if we selected the text column, move back
228-
if newobj.column() == 9:
230+
if newobj.column() == 10:
229231
self.left()
230232
newobj = self.currentIndex()
231233
cellContent = newobj.data()
@@ -265,8 +267,10 @@ def reload_offsets(self):
265267
# overwrite with motion's version of the current system offset
266268
# this should be more up to date
267269
STATUS.stat.poll()
268-
temp[STATUS.stat.g5x_index-1] = STATUS.stat.g5x_offset
269-
270+
temp[STATUS.stat.g5x_index-1] = list(STATUS.stat.g5x_offset)
271+
# inject the current rotation into the list
272+
temp[STATUS.stat.g5x_index-1].append(STATUS.stat.rotation_xy)
273+
270274
g54, g55, g56, g57, g58, g59, g59_1, g59_2, g59_3 = temp
271275
if g54 is None: return
272276

@@ -284,18 +288,18 @@ def reload_offsets(self):
284288
rot = STATUS.stat.rotation_xy
285289

286290
if self.metric_display != INFO.MACHINE_IS_METRIC:
287-
ap = INFO.convert_units_9(ap)
288-
tool = INFO.convert_units_9(tool)
289-
g92 = INFO.convert_units_9(g92)
290-
g54 = INFO.convert_units_9(g54)
291-
g55 = INFO.convert_units_9(g55)
292-
g56 = INFO.convert_units_9(g56)
293-
g57 = INFO.convert_units_9(g57)
294-
g58 = INFO.convert_units_9(g58)
295-
g59 = INFO.convert_units_9(g59)
296-
g59_1 = INFO.convert_units_9(g59_1)
297-
g59_2 = INFO.convert_units_9(g59_2)
298-
g59_3 = INFO.convert_units_9(g59_3)
291+
ap = INFO.convert_units_10(ap)
292+
tool = INFO.convert_units_10(tool)
293+
g92 = INFO.convert_units_10(g92)
294+
g54 = INFO.convert_units_10(g54)
295+
g55 = INFO.convert_units_10(g55)
296+
g56 = INFO.convert_units_10(g56)
297+
g57 = INFO.convert_units_10(g57)
298+
g58 = INFO.convert_units_10(g58)
299+
g59 = INFO.convert_units_10(g59)
300+
g59_1 = INFO.convert_units_10(g59_1)
301+
g59_2 = INFO.convert_units_10(g59_2)
302+
g59_3 = INFO.convert_units_10(g59_3)
299303

300304
# set the text style based on unit type
301305
if self.metric_display:
@@ -307,30 +311,40 @@ def reload_offsets(self):
307311

308312
# fill each row of the liststore from the offsets arrays
309313
for row, i in enumerate([ap, rot, g92, tool, g54, g55, g56, g57, g58, g59, g59_1, g59_2, g59_3]):
310-
for column in range(0, 9):
314+
for column in range(0, 10):
315+
316+
# current rotational
311317
if row == 1:
312318
if column == 2:
313319
self.tabledata[row][column] = locale.format_string(degree_tmpl, rot)
314320
else:
315321
self.tabledata[row][column] = " "
322+
323+
# rotational column not available in row 0,2,3
324+
elif row in (0,2,3) and column == 9:
325+
self.tabledata[row][column] = " "
326+
327+
elif column == 9:
328+
self.tabledata[row][column] = locale.format_string(degree_tmpl, i[column])
316329
else:
317330
self.tabledata[row][column] = locale.format_string(tmpl, i[column])
331+
318332
self.tablemodel.layoutChanged.emit()
319333

320334
# We read the var file directly
321335
# and pull out the info we need
322336
# if anything goes wrong we set all the info to 0
323337
def read_file(self):
324338
try:
325-
g54 = [0, 0, 0, 0, 0, 0, 0, 0, 0]
326-
g55 = [0, 0, 0, 0, 0, 0, 0, 0, 0]
327-
g56 = [0, 0, 0, 0, 0, 0, 0, 0, 0]
328-
g57 = [0, 0, 0, 0, 0, 0, 0, 0, 0]
329-
g58 = [0, 0, 0, 0, 0, 0, 0, 0, 0]
330-
g59 = [0, 0, 0, 0, 0, 0, 0, 0, 0]
331-
g59_1 = [0, 0, 0, 0, 0, 0, 0, 0, 0]
332-
g59_2 = [0, 0, 0, 0, 0, 0, 0, 0, 0]
333-
g59_3 = [0, 0, 0, 0, 0, 0, 0, 0, 0]
339+
g54 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
340+
g55 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
341+
g56 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
342+
g57 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
343+
g58 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
344+
g59 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
345+
g59_1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
346+
g59_2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
347+
g59_3 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
334348
if self.filename is None:
335349
return g54, g55, g56, g57, g58, g59, g59_1, g59_2, g59_3
336350
if not os.path.exists(self.filename):
@@ -342,23 +356,23 @@ def read_file(self):
342356
param = int(temp[0])
343357
data = float(temp[1])
344358

345-
if 5229 >= param >= 5221:
359+
if 5230 >= param >= 5221:
346360
g54[param - 5221] = data
347-
elif 5249 >= param >= 5241:
361+
elif 5250 >= param >= 5241:
348362
g55[param - 5241] = data
349-
elif 5269 >= param >= 5261:
363+
elif 5270 >= param >= 5261:
350364
g56[param - 5261] = data
351-
elif 5289 >= param >= 5281:
365+
elif 5290 >= param >= 5281:
352366
g57[param - 5281] = data
353-
elif 5309 >= param >= 5301:
367+
elif 5310 >= param >= 5301:
354368
g58[param - 5301] = data
355-
elif 5329 >= param >= 5321:
369+
elif 5330 >= param >= 5321:
356370
g59[param - 5321] = data
357-
elif 5349 >= param >= 5341:
371+
elif 5350 >= param >= 5341:
358372
g59_1[param - 5341] = data
359-
elif 5369 >= param >= 5361:
373+
elif 5370 >= param >= 5361:
360374
g59_2[param - 5361] = data
361-
elif 5389 >= param >= 5381:
375+
elif 5390 >= param >= 5381:
362376
g59_3[param - 5381] = data
363377
return [g54, g55, g56, g57, g58, g59, g59_1, g59_2, g59_3]
364378
except:
@@ -370,11 +384,14 @@ def dataChanged(self, new, old, x):
370384
data = self.tabledata[row][col]
371385

372386
if row == 0: return
387+
373388
# Hack to not edit any rotational offset but Z axis
374389
if row == 1 and not col == 2: return
375390

376-
# dont evaluate text column
377-
if col == 9 :return
391+
if row in(2,3) and col == 9: return
392+
393+
# don't evaluate text column
394+
if col == 10 :return
378395

379396
# make sure we switch to correct units for machine and rotational, row 2, does not get converted
380397
try:
@@ -388,7 +405,7 @@ def dataChanged(self, new, old, x):
388405
ACTION.RECORD_CURRENT_MODE()
389406
if row == 0: # current Origin
390407
ACTION.CALL_MDI("G10 L2 P0 %s %10.4f" % (self.axisletters[col], qualified))
391-
elif row == 1: # rotational
408+
elif row == 1: # current rotational
392409
if col == 2: # Z axis only
393410
ACTION.CALL_MDI("G10 L2 P0 R %10.4f" % (qualified))
394411
elif row == 2: # G92 offset
@@ -397,6 +414,8 @@ def dataChanged(self, new, old, x):
397414
if not self.current_tool == 0:
398415
ACTION.CALL_MDI("G10 L1 P%d %s %10.4f" % (self.current_tool, self.axisletters[col], qualified))
399416
ACTION.CALL_MDI('g43')
417+
elif col == 9: # rotational
418+
ACTION.CALL_MDI("G10 L2 P%d R %10.4f" % (row-3, qualified))
400419
else:
401420
ACTION.CALL_MDI("G10 L2 P%d %s %10.4f" % (row-3, self.axisletters[col], qualified))
402421

@@ -525,12 +544,14 @@ def flags(self, index):
525544
if not index.isValid():
526545
return None
527546
# print(">>> flags() index.column() = ", index.column())
528-
if index.column() == 9 and index.row() in(0, 1, 2, 3):
547+
if index.column() == 10 and index.row() in(0, 1, 2, 3):
529548
return Qt.ItemIsEnabled
530549
elif index.row() == 0:
531550
return Qt.ItemIsEnabled
532551
elif index.row() == 1 and not index.column() == 2:
533552
return Qt.NoItemFlags
553+
elif index.row() in(2, 3) and index.column() == 9:
554+
return Qt.NoItemFlags
534555
else:
535556
return Qt.ItemIsEditable | Qt.ItemIsEnabled | Qt.ItemIsSelectable
536557

@@ -542,7 +563,7 @@ def setData(self, index, value, role):
542563
LOG.debug(">>> setData() index.column() = {}".format(index.column()))
543564
if index.row() == 0: return False
544565
try:
545-
if index.column() == 9:
566+
if index.column() == 10:
546567
v = str(value)
547568
else:
548569
v = float(value)

0 commit comments

Comments
 (0)