Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contributed_definitions/NXiv_temp.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
There should also be a field with an array of rank equal to the number of different temperature setpoints and each child's dimension
equal to the number of voltage setpoints.
</doc>
<field name="temperature" type="NX_NUMBER"/>
<field name="voltage" type="NX_NUMBER"/>
<field name="current" type="NX_NUMBER">
<field name="temperature" type="NX_NUMBER" extends="/NXdata/AXISNAME"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to specify @temperature_indices and @voltage_indices to signify their corresponding fields are AXISNAME instances

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@signal="current" may be too restrictive for an app def!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to specify @temperature_indices and @voltage_indices to signify their corresponding fields are AXISNAME instances

That works for AXISNAME, but how about DATA? Would be nice to have a consistent way of assigning fields to one or the other.

@signal="current" may be too restrictive for an app def!

Exactly my point 👍

<field name="voltage" type="NX_NUMBER" extends="/NXdata/AXISNAME"/>
<field name="current" type="NX_NUMBER" extends="/NXdata/DATA">
<dimensions rank="2">
<dim index="1" value="n_different_temperatures"/>
<dim index="2" value="n_different_voltages"/>
Expand Down
8 changes: 8 additions & 0 deletions dev_tools/docs/nxdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,12 @@ def _print_attribute(self, ns, kind, node, optional, indent, parent_path):
)
self._print_doc_enum(indent, ns, node)

def _get_extends_text(self, node):
extends = node.get("extends", None)
if extends:
return f"(:ref:`{extends.split("/")[-1]} <{extends}-field>`) "
return ""

def _print_if_deprecated(self, ns, node, indent):
deprecated = node.get("deprecated", None)
if deprecated is not None:
Expand All @@ -630,11 +636,13 @@ def _print_full_tree(self, ns, parent, name, indent, parent_path):
dims = self._analyze_dimensions(ns, node)

optional_text = self._get_required_or_optional_text(node)
extends_test = self._get_extends_text(node)
self._print(f"{indent}{self._hyperlink_target(parent_path, name, 'field')}")
self._print(f"{indent}.. index:: {index_name} (field)\n")
self._print(
f"{indent}{formatted_name}: "
f"{optional_text}"
f"{extends_test}"
f"{self._format_type(node)}"
f"{dims}"
f"{self._format_units(node)}"
Expand Down
38 changes: 38 additions & 0 deletions nxdl.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,44 @@ https://stackoverflow.com/a/48980995/1046449 -->
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="extends" use="optional">
<xs:annotation>
<xs:documentation>
The ``extends`` attribute allows to specify which field
in the inheritance hierarchy this field is derived from.

This attribute is to be used in cases where there is an ambiguity
in the inheritance. At the moment, this is only the case for the
``AXISNAME`` and ``DATA`` fields in ``NXdata``, which are both of
type ``NX_NUMBER``. Thus, when specializing ``NXdata`` in an application
definition, the ``extends`` attribute allows to specify whether a field
in the specialized ``NXdata`` is an ``AXISNAME`` and ``DATA``.

For example, consider the following NXDL snippet::

&lt;definition xmlns=&quot;http://definition.nexusformat.org/nxdl/3.1&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; category=&quot;application&quot; name=&quot;NXexample&quot; extends=&quot;NXobject&quot; type=&quot;group&quot; xsi:schemaLocation=&quot;http://definition.nexusformat.org/nxdl/3.1 ../nxdl.xsd&quot;&gt;
&lt;doc&gt;Example application definition.&lt;/doc&gt;
&lt;group type=&quot;NXentry&quot;&gt;
&lt;group type=&quot;NXdata&quot;&gt;
&lt;doc&gt;
This NXdata contains multiple fields. ``temperature`` and ``voltage``specialize ``AXISNAME``, whereas ``current`` specializes ``DATA``.
&lt;/doc&gt;
&lt;field name=&quot;temperature&quot; type=&quot;NX_NUMBER&quot; extends=&quot;/NXdata/AXISNAME&quot;/&gt;
&lt;field name=&quot;voltage&quot; type=&quot;NX_NUMBER&quot; extends=&quot;/NXdata/AXISNAME&quot;/&gt;
&lt;field name=&quot;current&quot; type=&quot;NX_NUMBER&quot; extends=&quot;/NXdata/DATA&quot;/&gt;
&lt;/group&gt;
&lt;/group&gt;
&lt;/definition&gt;

Here, the ``extends`` attribute is used to specify that the ``temperature`` and ``voltage`` fields are specializations
of the ``AXISNAME`` field, whereas the ``current`` field is a specialization of the ``DATA`` field.

Note that the ``extends`` keyword shall only be used in cases where there is an ambiguity in the inheritance, such as
the example above. The ``extends`` attribute must not be used when such ambiguity does not exist. Especially, it is
not alllowed to specify the ``extends`` attribute for fields that are not part of the inheritance hierarchy.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attributeGroup ref="nx:nameTypeAttributeGroup"/>
</xs:extension>
</xs:complexContent>
Expand Down