Skip to content

Commit

Permalink
WIP: Actually read the params file
Browse files Browse the repository at this point in the history
  • Loading branch information
TurBoss committed Oct 1, 2019
1 parent 3bb6380 commit 3b811fd
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 87 deletions.
89 changes: 51 additions & 38 deletions qtpyvcp/plugins/offset_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ def merge(a, b):


DEFAULT_OFFSET = {
'A': 0.0,
'B': 0.0,
'C': 0.0,
'U': 0.0,
'V': 0.0,
'W': 0.0,
'X': 0.0,
'Y': 0.0,
'Z': 0.0,
}

0: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
4: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
5: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
6: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
7: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
8: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
9: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}
NO_TOOL = merge(DEFAULT_OFFSET, {'T': 0, 'R': 'No Tool Loaded'})

# FILE_HEADER = """
Expand All @@ -80,10 +80,10 @@ def merge(a, b):
'X': 'X',
'Y': 'Y',
'Z': 'Z',
'R': 'R'
}

ROW_LABELS = {
'P0': 'G53',
'P1': 'G54',
'P2': 'G55',
'P3': 'G56',
Expand All @@ -110,21 +110,26 @@ class OffsetTable(DataPlugin):

offset_table_changed = Signal(dict)

def __init__(self, columns='ABCUVWXYZ', file_header_template=None):
def __init__(self, columns='ABCUVWXYZR', file_header_template=None):
super(OffsetTable, self).__init__()

self.inifile = os.getenv("INI_FILE_NAME")
self.ini = linuxcnc.ini(self.inifile)
self.config_dir = os.path.dirname(self.inifile)

param_file = self.ini.find("RS274NGC", "PARAMETER_FILE")
self.parameter_file = os.path.join(self.config_dir, param_file)

self.status = STATUS

self.columns = self.validateColumns(columns) or [c for c in 'ABCUVWXYZ']
self.columns = self.validateColumns(columns) or [c for c in 'ABCUVWXYZR']

self.setCurrentToolNumber(0)

self.g5x_offset = None
self.g5x_offset_table = DEFAULT_OFFSET.copy()

self.loadOffsetTable()

self.current_tool.setValue(self.OFFSET_TABLE[STATUS.tool_in_spindle.getValue()])

# update signals
# STATUS.tool_in_spindle.notify(self.setCurrentToolNumber)
self.status.tool_table.notify(lambda *args: self.loadOffsetTable())
Expand All @@ -135,15 +140,15 @@ def current_tool(self, chan, item=None):
Available items:
* X -- x offset
* Y -- y offset
* Z -- z offset
* A -- a offset
* B -- b offset
* C -- c offset
* U -- u offset
* V -- v offset
* W -- w offset
* X -- x offset
* Y -- y offset
* Z -- z offset
Rules channel syntax::
Expand Down Expand Up @@ -182,7 +187,7 @@ def validateColumns(columns):
return

return [col for col in [col.strip().upper() for col in columns]
if col in 'TPXYZABCUVWDIJQR' and not col == '']
if col in 'ABCUVWXYZR' and not col == '']

def newOffset(self, tnum=None):
"""Get a dict of default tool values for a new tool."""
Expand Down Expand Up @@ -219,29 +224,37 @@ def iterTools(self, tool_table=None, columns=None):

def loadOffsetTable(self):

self.g5x_offset = self.status.stat.g5x_offset

header = "XYZABCUVW"

table = {0: NO_TOOL, }
offset = DEFAULT_OFFSET.copy()

for index, axis_offset in enumerate(self.g5x_offset):
print(index, axis_offset)
offset[header[index]] = axis_offset

table[0] = offset
with open(self.parameter_file, 'r') as fh:
for line in fh:
param, data = int(line.split()[0]), float(line.split()[1])

if 5230 >= param >= 5221:
self.g5x_offset_table.get(0)[param - 5221] = data
elif 5250 >= param >= 5241:
self.g5x_offset_table.get(2)[param - 5241] = data
elif 5270 >= param >= 5261:
self.g5x_offset_table.get(3)[param - 5261] = data
elif 5290 >= param >= 5281:
self.g5x_offset_table.get(4)[param - 5281] = data
elif 5310 >= param >= 5301:
self.g5x_offset_table.get(5)[param - 5301] = data
elif 5320 >= param >= 5321:
self.g5x_offset_table.get(6)[param - 5321] = data
elif 5350 >= param >= 5341:
self.g5x_offset_table.get(7)[param - 5341] = data
elif 5370 >= param >= 5361:
self.g5x_offset_table.get(8)[param - 5361] = data
elif 5390 >= param >= 5381:
self.g5x_offset_table.get(9)[param - 5381] = data

# update tooltable
self.__class__.OFFSET_TABLE = table

self.current_tool.setValue(self.OFFSET_TABLE[STATUS.tool_in_spindle.getValue()])
self.__class__.OFFSET_TABLE = self.g5x_offset_table

# import json
# print json.dumps(table, sort_keys=True, indent=4)

self.offset_table_changed.emit(table)
return table.copy()
self.offset_table_changed.emit(self.g5x_offset_table)
return self.g5x_offset_table.copy()

def getOffsetTable(self):
return self.OFFSET_TABLE.copy()
Expand Down
90 changes: 41 additions & 49 deletions qtpyvcp/widgets/input_widgets/offset_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with QtPyVCP. If not, see <http://www.gnu.org/licenses/>.


from qtpy.QtCore import Qt, Slot, Property, QModelIndex, QSortFilterProxyModel
from qtpy.QtGui import QStandardItemModel, QColor, QBrush
from qtpy.QtWidgets import QTableView, QStyledItemDelegate, QDoubleSpinBox, QSpinBox, QLineEdit, QMessageBox
Expand Down Expand Up @@ -48,26 +49,7 @@ def createEditor(self, parent, option, index):
# ToDo: set dec placed for IN and MM machines
col = self._columns[index.column()]

if col == 'R':
editor = QLineEdit(parent)
editor.setFrame(False)
margins = editor.textMargins()
padding = editor.fontMetrics().width(self._padding) + 1
margins.setLeft(margins.left() + padding)
editor.setTextMargins(margins)
return editor

elif col in 'TPQ':
editor = QSpinBox(parent)
editor.setFrame(False)
editor.setAlignment(Qt.AlignCenter)
if col == 'Q':
editor.setMaximum(9)
else:
editor.setMaximum(99999)
return editor

elif col in 'XYZABCUVWD':
if col in 'ABCUVWXYZR':
editor = QDoubleSpinBox(parent)
editor.setFrame(False)
editor.setAlignment(Qt.AlignCenter)
Expand All @@ -77,24 +59,38 @@ def createEditor(self, parent, option, index):
editor.setRange(-1000, 1000)
return editor

elif col in 'IJ':
editor = QDoubleSpinBox(parent)
editor.setFrame(False)
editor.setAlignment(Qt.AlignCenter)
editor.setDecimals(2)
# editor.setStepType(QSpinBox.AdaptiveDecimalStepType)
editor.setProperty('stepType', 1) # stepType was added in 5.12
return editor

return None


class OffsetModel(QStandardItemModel):
def __init__(self, parent=None):
super(OffsetModel, self).__init__(parent)

self.status = getPlugin('status')
self.stat = self.status.stat
self.column_labels = {
'A': 0,
'B': 1,
'C': 2,
'U': 3,
'V': 4,
'W': 5,
'X': 6,
'Y': 7,
'Z': 8,
'R': 9
}

self.row_labels = [
'G54',
'G55',
'G56',
'G57',
'G58',
'G59',
'G59.1',
'G59.2',
'G59.3'
]

self.ot = getPlugin('offsettable')

self.current_row_color = QColor(Qt.darkGreen)
Expand Down Expand Up @@ -142,32 +138,28 @@ def flags(self, index):

def data(self, index, role=Qt.DisplayRole):
if role == Qt.DisplayRole or role == Qt.EditRole:

key = self._columns[index.column()]
tnum = sorted(self._offset_table)[index.row() + 1]
return self._offset_table[tnum][key]

elif role == Qt.TextAlignmentRole:
col = self._columns[index.column()]
if col == 'R': # Remark
return Qt.AlignVCenter | Qt.AlignLeft
elif col in 'TPQ': # Integers (Tool, Pocket, Orient)
return Qt.AlignVCenter | Qt.AlignCenter
else: # All the other floats
return Qt.AlignVCenter | Qt.AlignRight
key_index = self.column_labels[key]

offset_num = sorted(self._offset_table)[index.row() + 1]

return self._offset_table[offset_num][key_index]

elif role == Qt.TextColorRole:
tnum = sorted(self._offset_table)[index.row() + 1]
if self.stat.tool_in_spindle == tnum:
return QBrush(self.current_row_color)
else:
return QStandardItemModel.data(self, index, role)
return QStandardItemModel.data(self, index, role)

return QStandardItemModel.data(self, index, role)

def setData(self, index, value, role):

key = self._columns[index.column()]
key_index = self.column_labels[key]

tnum = sorted(self._offset_table)[index.row() + 1]
self._offset_table[tnum][key] = value
offset_index = self.row_labels[tnum]

self._offset_table[offset_index][key_index] = value
return True

def removeOffset(self, row):
Expand Down Expand Up @@ -237,7 +229,7 @@ def __init__(self, parent=None):
self._current_row_color = QColor('sage')

# Appearance/Behaviour settings
self.setSortingEnabled(True)
self.setSortingEnabled(False)
# self.verticalHeader().hide()
self.setAlternatingRowColors(True)
self.setSelectionBehavior(QTableView.SelectRows)
Expand Down

0 comments on commit 3b811fd

Please # to comment.