Skip to content

Commit

Permalink
Added plc:gvl directive
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoRoos committed Aug 20, 2024
1 parent 73905e6 commit acd8102
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Documentation Status](https://readthedocs.org/projects/plc-doc/badge/?version=latest)](https://plc-doc.readthedocs.io/latest/?badge=latest)
[![Unit tests](https://github.com/DEMCON/plcdoc/actions/workflows/tests.yml/badge.svg)](https://github.com/DEMCON/plcdoc/actions)
[![codecov](https://codecov.io/github/DEMCON/plcdoc/graph/badge.svg?token=LS0LECRP58)](https://codecov.io/DEMCON/plcdoc)
[![codecov](https://codecov.io/gh/DEMCON/plcdoc/graph/badge.svg?token=xMg0U6mX2r)](https://codecov.io/gh/DEMCON/plcdoc)

This is a work-in-progress of a tool to get documentation with Sphinx from TwinCAT PLC.
The focus is on PLC code made with Structured Text (ST), i.e. the IEC 61131-3 standard.
Expand Down
32 changes: 32 additions & 0 deletions docs/src/directives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ The same options from `function <#function>`_ are available.
:var_input LREAL myInput:
:var_output LREAL myOutput:
Description of my function block.
.. functionblock:: MyFunctionBlock
:noindex:

:var_input LREAL myInput:
:var_output LREAL myOutput:

Description of my function block.

You can also nest e.g. methods and properties:

.. code-block:: rst
Expand Down Expand Up @@ -197,6 +201,34 @@ struct
.. member:: Second : LREAL
:noindex:

gvl
---

.. code-block:: rst
.. gvl:: <name>
<variables>
**Examples:**

.. code-block:: rst
.. gvl:: GVL_Main
:var LREAL var_double: Some precision decimal variable
:var BOOL my_flag: Another variable, of boolean type
Main variables list.
.. gvl:: GVL_Main
:noindex:

:var LREAL var_double: Some precision decimal variable
:var BOOL my_flag: Another variable, of boolean type

Main variables list.

folder
------

Expand Down
17 changes: 17 additions & 0 deletions src/plcdoc/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,23 @@ class PlcMemberDescription(PlcObjectDescription):
object_display_type = False


class PlcVariableListDescription(PlcObjectDescription):
"""Directive specifically to show a GVL."""

# fmt: off
doc_field_types = [
TypedField(
"var",
label="VAR",
names=("var", "param", "parameter", "arg", "argument"),
typerolename="type",
typenames=("paramtype", "type", "var_type"),
can_collapse=False,
),
]
# fmt: on


class PlcFolderDescription(PlcObjectDescription):
"""Directive specifically for a folder and contents."""

Expand Down
2 changes: 2 additions & 0 deletions src/plcdoc/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
PlcEnumeratorDescription,
PlcMemberDescription,
PlcFolderDescription,
PlcVariableListDescription,
)
from .roles import PlcXRefRole

Expand Down Expand Up @@ -61,6 +62,7 @@ class StructuredTextDomain(Domain):
"struct": PlcObjectDescription,
"member": PlcMemberDescription,
"property": PlcObjectDescription,
"gvl": PlcVariableListDescription,
"folder": PlcFolderDescription,
}

Expand Down
8 changes: 8 additions & 0 deletions tests/roots/test-domain-plc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@
.. plc:property:: \
FaceUp
FaceDown


.. GVL -----------------------------
.. plc:gvl:: GVL_MyList
:var LREAL my_double: Some double-type variable
:var USINT some_int: My short integer
1 change: 1 addition & 0 deletions tests/test_domain_plc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ def test_domain_plc_objects(app, status, warning):
assert objects["Orientation"][2] == "enum"
assert objects["ST_MyStruct"][2] == "struct"
assert objects["ST_MyStruct2"][2] == "struct"
assert objects["GVL_MyList"][2] == "gvl"

0 comments on commit acd8102

Please sign in to comment.