Commit ae3f61bb authored by Fabrice Salvaire's avatar Fabrice Salvaire

improved data

parent b313bb09
...@@ -30,7 +30,9 @@ __all__ = [ ...@@ -30,7 +30,9 @@ __all__ = [
'Letters', 'Letters',
'Gcode', 'Gcode',
'Gcodes', 'Gcodes',
'ModalGroup',
'ModalGroups', 'ModalGroups',
'ExecutionGroup',
'ExecutionOrder', 'ExecutionOrder',
] ]
...@@ -67,9 +69,14 @@ class RstMixin: ...@@ -67,9 +69,14 @@ class RstMixin:
############################################## ##############################################
def _make_rst(self, headers, columns=None, show_line_number=False, str_item=None): def _make_rst(self, headers, columns, **kwargs):
lengths = [] number_of_columns = len(headers)
if len(columns) != number_of_columns:
raise ValueError('Number of columns mismatch')
number_of_lines = len(self)
table = []
rule = '' rule = ''
line_format = '' line_format = ''
for c, title in enumerate(headers): for c, title in enumerate(headers):
...@@ -77,36 +84,28 @@ class RstMixin: ...@@ -77,36 +84,28 @@ class RstMixin:
rule += ' ' rule += ' '
line_format += ' ' line_format += ' '
length = len(title) length = len(title)
if columns is not None: column = columns[c]
column = columns[c] str_columns = []
if hasattr(self, 'sorted_iter'):
it = self.sorted_iter()
else: else:
column = None it = self
for line_number, item in enumerate(self): for line_number, item in enumerate(it):
if c == 0 and show_line_number: formater = kwargs.get('str_' + column, str)
text = str(line_number) field = getattr(item, column)
else: text = formater(field)
if column is not None:
text = str(getattr(item, column))
else:
text = str(item)
length = max(len(text), length) length = max(len(text), length)
str_columns.append(text)
rule += '='*length rule += '='*length
line_format += '{:' + str(length) + '}' line_format += '{:' + str(length) + '}'
lengths.append(length) table.append(str_columns)
rst = '' rst = ''
rst += rule + '\n' rst += rule + '\n'
rst += line_format.format(*headers) + '\n' rst += line_format.format(*headers) + '\n'
rst += rule + '\n' rst += rule + '\n'
for line_number, item in enumerate(self): for line_number in range(number_of_lines):
if columns is not None: fields = [table[c][line_number] for c in range(number_of_columns)]
fields = [getattr(item, column) for column in columns]
elif str_item:
fields = [str_item(item)]
else:
fields = [str(item)]
if show_line_number:
fields = [str(line_number)] + fields
rst += line_format.format(*fields) + '\n' rst += line_format.format(*fields) + '\n'
rst += rule + '\n' rst += rule + '\n'
...@@ -267,6 +266,13 @@ class Gcodes(YamlMixin, RstMixin): ...@@ -267,6 +266,13 @@ class Gcodes(YamlMixin, RstMixin):
def __getitem__(self, code): def __getitem__(self, code):
return self._gcodes[code] return self._gcodes[code]
##############################################
def sorted_iter(self):
items = list(self)
items.sort(key=lambda item: str(ord(item.code[0])*1000) + item.code[1:])
return items
############################################## ##############################################
...@@ -276,6 +282,27 @@ class Gcodes(YamlMixin, RstMixin): ...@@ -276,6 +282,27 @@ class Gcodes(YamlMixin, RstMixin):
headers=('G-code', 'Meaning'), headers=('G-code', 'Meaning'),
columns=('code', 'meaning'), columns=('code', 'meaning'),
) )
####################################################################################################
class ExecutionGroup(MeaningMixin):
##############################################
def __init__(self, index, gcodes, meaning):
MeaningMixin.__init__(self, meaning)
self._index = int(index)
self._gcodes = list(gcodes)
##############################################
@property
def index(self):
return self._index
@property
def gcodes(self):
return self._gcodes
#################################################################################################### ####################################################################################################
...@@ -288,13 +315,15 @@ class ExecutionOrder(YamlMixin, RstMixin): ...@@ -288,13 +315,15 @@ class ExecutionOrder(YamlMixin, RstMixin):
data = self._load_yaml(yaml_path) data = self._load_yaml(yaml_path)
self._order = [] self._order = []
count = 1 count = 1
for index, gcodes in data.items(): for index, d in data.items():
if index != count: if index != count:
raise ValueError('Unexpected index {} versus {}'.format(index, count)) raise ValueError('Unexpected index {} versus {}'.format(index, count))
count += 1 count += 1
gcodes = d['gcodes']
if not isinstance(gcodes, list): if not isinstance(gcodes, list):
gcodes = list(gcodes) gcodes = [gcodes]
self._order.append(gcodes) group = ExecutionGroup(index, gcodes, d['meaning'])
self._order.append(group)
############################################## ##############################################
...@@ -312,13 +341,35 @@ class ExecutionOrder(YamlMixin, RstMixin): ...@@ -312,13 +341,35 @@ class ExecutionOrder(YamlMixin, RstMixin):
def to_rst(self, path): def to_rst(self, path):
self._write_rst( self._write_rst(
path, path,
headers=('Order', 'G-codes'), headers=('Order', 'G-codes', 'Comment'),
show_line_number=True, columns=('index', 'gcodes', 'meaning'),
str_item=lambda item: '(' + ', '.join(item) + ')' str_gcodes=lambda item: ', '.join(item),
) )
#################################################################################################### ####################################################################################################
class ModalGroup(MeaningMixin):
##############################################
def __init__(self, index, gcodes, meaning):
MeaningMixin.__init__(self, meaning)
self._index = int(index)
self._gcodes = list(gcodes)
##############################################
@property
def index(self):
return self._index
@property
def gcodes(self):
return self._gcodes
####################################################################################################
class ModalGroups(YamlMixin, RstMixin): class ModalGroups(YamlMixin, RstMixin):
############################################## ##############################################
...@@ -327,8 +378,12 @@ class ModalGroups(YamlMixin, RstMixin): ...@@ -327,8 +378,12 @@ class ModalGroups(YamlMixin, RstMixin):
data = self._load_yaml(yaml_path) data = self._load_yaml(yaml_path)
self._groups = {} self._groups = {}
for index, gcodes in data.items(): for index, d in data.items():
self._groups[index] = list(gcodes) gcodes = d['gcodes']
if not isinstance(gcodes, list):
gcodes = [gcodes]
group = ExecutionGroup(index, gcodes, d['meaning'])
self._groups[index] = group
############################################## ##############################################
...@@ -339,16 +394,24 @@ class ModalGroups(YamlMixin, RstMixin): ...@@ -339,16 +394,24 @@ class ModalGroups(YamlMixin, RstMixin):
return iter(self._groups.values()) return iter(self._groups.values())
def __getitem__(self, index): def __getitem__(self, index):
return self._groups[index_] return self._groups[index]
##############################################
def sorted_iter(self):
items = list(self)
items.sort(key=lambda item: item.index)
return items
############################################## ##############################################
def to_rst(self, path): def to_rst(self, path):
self._write_rst( self._write_rst(
path, path,
headers=('Group', 'G-codes'), headers=('Group', 'G-codes', 'Comment'),
show_line_number=True, columns=('index', 'gcodes', 'meaning'),
str_item=lambda item: '(' + ', '.join(item) + ')' str_gcodes=lambda item: '(' + ', '.join(item) + ')',
) )
#################################################################################################### ####################################################################################################
......
# Table 8. Order of Execution # Table 8. Order of Execution
1: COMMENT # (includes message] 1:
2: [G93, G94] # set feed rate mode (inverse time or per minute] gcodes: COMMENT
3: F # set feed rate meaning: includes message
4: S # set spindle speed 2:
5: T # select tool gcodes: [G93, G94]
6: M6 # change tool meaning: set feed rate mode (inverse time or per minute)
7: [M3, M4, M5] # spindle on or off 3:
8: [M7, M8, M9] # coolant on or off gcodes: F
9: [M48, M49] # enable or disable overrides meaning: set feed rate
10: G4 # dwell 4:
11: [G17, G18, G19] # set active plane gcodes: S
12: [G20, G21] # set length units meaning: set spindle speed
13: [G40, G41, G42] # cutter radius compensation on or off 5:
14: [G43, G49] # cutter length compensation on or off gcodes: T
15: [G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3] # coordinate system selection meaning: select tool
16: [G61, G61.1, G64] # set path control mode 6:
17: [G90, G91] # set distance mode gcodes: M6
18: [G98, G99] # set retract mode meaning: change tool
19: [G28, G30, G10, G92, G92.1, G92.2, G94] # home or change coordinate system data or set axis offsets 7:
20: ['G0-G3', 'G80-G89', G53] # perform motion, as modified (possibly) by G53 gcodes: [M3, M4, M5]
21: [M0, M1, M2, M30, M60] # stop meaning: spindle on or off
8:
gcodes: [M7, M8, M9]
meaning: coolant on or off
9:
gcodes: [M48, M49]
meaning: enable or disable overrides
10:
gcodes: G4
meaning: dwell
11:
gcodes: [G17, G18, G19]
meaning: set active plane
12:
gcodes: [G20, G21]
meaning: set length units
13:
gcodes: [G40, G41, G42]
meaning: cutter radius compensation on or off
14:
gcodes: [G43, G49]
meaning: cutter length compensation on or off
15:
gcodes: [G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3]
meaning: coordinate system selection
16:
gcodes: [G61, G61.1, G64]
meaning: set path control mode
17:
gcodes: [G90, G91]
meaning: set distance mode
18:
gcodes: [G98, G99]
meaning: set retract mode
19:
gcodes: [G28, G30, G10, G92, G92.1, G92.2, G94]
meaning: home or change coordinate system data or set axis offsets
20:
gcodes: ['G0-G3', 'G80-G89', G53]
meaning: perform motion, as modified (possibly) by G53
21:
gcodes: [M0, M1, M2, M30, M60]
meaning: stop
# Table 4. Modal Groups # Table 4. Modal Groups
# The modal groups for G codes are # The modal groups for G codes are
1: [G0, G1, G2, G3, G38.2, G80, G81, G82, G83, G84, G85, G86, G87, G88, G89] 1:
2 : [G17, G18, G19] # plane selection gcodes: [G0, G1, G2, G3, G38.2, G80, G81, G82, G83, G84, G85, G86, G87, G88, G89]
3 : [G90, G91] # distance mode meaning:
5 : [G93, G94] # feed rate mode 2 :
6 : [G20, G21] # units gcodes: [G17, G18, G19]
7 : [G40, G41, G42] # cutter radius compensation meaning: plane selection
8 : [G43, G49] # tool length offset 3 :
10 : [G98, G99] # return mode in canned cycles gcodes: [G90, G91]
12 : [G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3] # coordinate system selection meaning: distance mode
13 : [G61, G61.1, G64] # path control mode 5 :
gcodes: [G93, G94]
meaning: feed rate mode
6 :
gcodes: [G20, G21]
meaning: units
7 :
gcodes: [G40, G41, G42]
meaning: cutter radius compensation
8 :
gcodes: [G43, G49]
meaning: tool length offset
10 :
gcodes: [G98, G99]
meaning: return mode in canned cycles
12 :
gcodes: [G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3]
meaning: coordinate system selection
13 :
gcodes: [G61, G61.1, G64]
meaning: path control mode
# The modal groups for M codes are # The modal groups for M codes are
4 : [M0, M1, M2, M30, M60] # stopping 4 :
6 : [M6] # tool change gcodes: [M0, M1, M2, M30, M60]
7 : [M3, M4, M5] # spindle turning meaning: stopping
8 : [M7, M8, M9] # coolant (special case: M7 and M8 may be active at the same time) 6 :
9 : [M48, M49] # enable/disable feed and speed override switches gcodes: [M6]
meaning: tool change
7 :
gcodes: [M3, M4, M5]
meaning: spindle turning
8 :
gcodes: [M7, M8, M9]
meaning: 'coolant (special case: M7 and M8 may be active at the same time)'
9 :
gcodes: [M48, M49]
meaning: enable/disable feed and speed override switches
# In addition to the above modal groups, there is a group for non-modal G codes # In addition to the above modal groups, there is a group for non-modal G codes
0 : [G4, G10, G28, G30, G53, G92, G92.1, G92.2, G92.3] 0 :
gcodes: [G4, G10, G28, G30, G53, G92, G92.1, G92.2, G92.3]
meaning: group for non-modal G codes
...@@ -299,6 +299,9 @@ millimeters. A machining center may be in many modes at the same time, with one ...@@ -299,6 +299,9 @@ millimeters. A machining center may be in many modes at the same time, with one
group being in effect. group being in effect.
.. The modal groups are shown in Table 4. .. The modal groups are shown in Table 4.
.. Table . Modal Groups
The modal groups are
.. include:: modal_groups.rst .. include:: modal_groups.rst
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment