Commit b313bb09 authored by Fabrice Salvaire's avatar Fabrice Salvaire

rs-274 doc

parent 0deb75de
......@@ -63,6 +63,64 @@ class MeaningMixin:
####################################################################################################
class RstMixin:
##############################################
def _make_rst(self, headers, columns=None, show_line_number=False, str_item=None):
lengths = []
rule = ''
line_format = ''
for c, title in enumerate(headers):
if rule:
rule += ' '
line_format += ' '
length = len(title)
if columns is not None:
column = columns[c]
else:
column = None
for line_number, item in enumerate(self):
if c == 0 and show_line_number:
text = str(line_number)
else:
if column is not None:
text = str(getattr(item, column))
else:
text = str(item)
length = max(len(text), length)
rule += '='*length
line_format += '{:' + str(length) + '}'
lengths.append(length)
rst = ''
rst += rule + '\n'
rst += line_format.format(*headers) + '\n'
rst += rule + '\n'
for line_number, item in enumerate(self):
if columns is not None:
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 += rule + '\n'
return rst
##############################################
def _write_rst(self, path, *args, **kwargs):
print('Write {}'.format(path))
with open(path, 'w') as fh:
fh.write(self._make_rst(*args, **kwargs))
####################################################################################################
class Parameter(MeaningMixin):
##############################################
......@@ -85,7 +143,7 @@ class Parameter(MeaningMixin):
####################################################################################################
class Parameters(YamlMixin):
class Parameters(YamlMixin, RstMixin):
##############################################
......@@ -108,6 +166,15 @@ class Parameters(YamlMixin):
def __getitem__(self, index):
return self._parameters[index]
##############################################
def to_rst(self, path):
self._write_rst(
path,
headers=('Parameter Number', 'Parameter Value', 'Comment'),
columns=('index', 'default_value', 'meaning'),
)
####################################################################################################
class Letter(MeaningMixin):
......@@ -127,7 +194,7 @@ class Letter(MeaningMixin):
####################################################################################################
class Letters(YamlMixin):
class Letters(YamlMixin, RstMixin):
##############################################
......@@ -149,6 +216,15 @@ class Letters(YamlMixin):
def __getitem__(self, letter):
return self._letters[letter]
##############################################
def to_rst(self, path):
self._write_rst(
path,
headers=('Letter', 'Meaning'),
columns=('letter', 'meaning'),
)
####################################################################################################
class Gcode(MeaningMixin):
......@@ -168,7 +244,7 @@ class Gcode(MeaningMixin):
####################################################################################################
class Gcodes(YamlMixin):
class Gcodes(YamlMixin, RstMixin):
##############################################
......@@ -191,9 +267,19 @@ class Gcodes(YamlMixin):
def __getitem__(self, code):
return self._gcodes[code]
##############################################
def to_rst(self, path):
self._write_rst(
path,
headers=('G-code', 'Meaning'),
columns=('code', 'meaning'),
)
####################################################################################################
class ExecutionOrder(YamlMixin):
class ExecutionOrder(YamlMixin, RstMixin):
##############################################
......@@ -216,14 +302,24 @@ class ExecutionOrder(YamlMixin):
return len(self._order)
def __iter__(self):
return iter(self._order.values())
return iter(self._order)
def __getitem__(self, slice_):
return self._order[slice_]
##############################################
def to_rst(self, path):
self._write_rst(
path,
headers=('Order', 'G-codes'),
show_line_number=True,
str_item=lambda item: '(' + ', '.join(item) + ')'
)
####################################################################################################
class ModalGroups(YamlMixin):
class ModalGroups(YamlMixin, RstMixin):
##############################################
......@@ -245,6 +341,16 @@ class ModalGroups(YamlMixin):
def __getitem__(self, index):
return self._groups[index_]
##############################################
def to_rst(self, path):
self._write_rst(
path,
headers=('Group', 'G-codes'),
show_line_number=True,
str_item=lambda item: '(' + ', '.join(item) + ')'
)
####################################################################################################
class Config:
......
####################################################################################################
#
# PythonicGcodeMachine - @licence_header_description@
# Copyright (C) 2018 Fabrice Salvaire
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################
"""
"""
####################################################################################################
__all__ = [
'Config',
'Parameter',
'Parameters',
'Letters',
'Gcode',
'Gcodes',
'ModalGroups',
'ExecutionOrder',
]
####################################################################################################
####################################################################################################
class Config:
##############################################
def __init__(self,
execution_order,
gcodes,
letters,
modal_groups,
parameters,
):
self._execution_order = str(execution_order)
self._gcodes = str(gcodes)
self._letters = str(letters)
self._modal_groups = str(modal_groups)
self._parameters = str(parameters)
##############################################
@property
def execution_order(self):
if isinstance(self._execution_order, str):
self._execution_order = ExecutionOrder(self._execution_order)
return self._execution_order
@property
def gcodes(self):
if isinstance(self._gcodes, str):
self._gcodes = Gcodes(self._gcodes)
return self._gcodes
@property
def letters(self):
if isinstance(self._letters, str):
self._letters = Letters(self._letters)
return self._letters
@property
def modal_groups(self):
if isinstance(self._modal_groups, str):
self._modal_groups = ModalGroups(self._modal_groups)
return self._modal_groups
@property
def parameters(self):
if isinstance(self._parameters, str):
self._parameters = Parameters(self._parameters)
return self._parameters
#! /usr/bin/env python3
####################################################################################################
#
# PythonicGcodeMachine - @licence_header_description@
# Copyright (C) 2018 Fabrice Salvaire
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################
"""Script to generate rST files.
"""
####################################################################################################
import pathlib
from PythonicGcodeMachine.Gcode.Rs274 import config
####################################################################################################
source_path = pathlib.Path(__file__).absolute().parents[4]
print('Source:', source_path)
rst_path = source_path.joinpath('doc', 'sphinx', 'source', 'gcode-reference', 'rs-274')
print('rST:', rst_path)
config.execution_order.to_rst(rst_path.joinpath('execution_order.rst'))
config.gcodes.to_rst(rst_path.joinpath('gcodes.rst'))
config.letters.to_rst(rst_path.joinpath('letters.rst'))
config.modal_groups.to_rst(rst_path.joinpath('modal_groups.rst'))
config.parameters.to_rst(rst_path.joinpath('parameters.rst'))
#! /usr/bin/env python3
####################################################################################################
#
# PythonicGcodeMachine - @licence_header_description@
# Copyright (C) 2018 Fabrice Salvaire
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################
"""Script to generate YAML files from texts copied from the NIST PDF.
"""
####################################################################################################
import pathlib
......@@ -295,13 +319,13 @@ B-axis of machine
C-axis of machine
tool radius compensation number
feedrate
general function (see Table 5)
general function (See table G codes)
tool length offset index
X-axis offset for arcs / X offset in G87 canned cycle
Y-axis offset for arcs / Y offset in G87 canned cycle
Z-axis offset for arcs / Z offset in G87 canned cycle
number of repetitions in canned cycles / key used with G10
miscellaneous function (see Table 7)
miscellaneous function (see Table M codes)
line number
dwell time in canned cycles / dwell time with G4 / key used with G10
feed increment in G83 canned cycle
......
......@@ -9,7 +9,7 @@ D:
F:
meaning: feedrate
G:
meaning: general function (see Table 5)
meaning: general function (See table G codes)
H:
meaning: tool length offset index
I:
......@@ -21,7 +21,7 @@ K:
L:
meaning: number of repetitions in canned cycles / key used with G10
M:
meaning: miscellaneous function (see Table 7)
meaning: miscellaneous function (see Table M codes)
N:
meaning: line number
P:
......
.. include:: abbreviation.txt
.. _gcode-reference-page:
==================
G-code Reference
==================
.. toctree::
:maxdepth: 3
:numbered:
rs-274/index.rst
This diff is collapsed.
......@@ -146,6 +146,8 @@ If you want to donate to the project or need a more professional support.
roadmap.rst
installation.rst
faq.rst
examples/index.rst
gcode-reference/index.rst
design-notes.rst
reference-manual.rst
development.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