Skip to content

Commit a5e01e2

Browse files
author
Gaël Écorchard
committed
Improve the XSD export
Add a special type for blackboard variables and use it for output ports to coerce the use of braces.
1 parent 1c402dd commit a5e01e2

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/xml_parsing.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ namespace
4949
std::string
5050
xsdAttributeType(const BT::PortInfo& port_info)
5151
{
52+
if (port_info.direction() == BT::PortDirection::OUTPUT)
53+
{
54+
return "blackboardType";
55+
}
5256
const auto& type_info = port_info.type();
5357
if ((type_info == typeid(int)) or (type_info == typeid(unsigned int)))
5458
{
@@ -60,11 +64,11 @@ xsdAttributeType(const BT::PortInfo& port_info)
6064
}
6165
else if (type_info == typeid(bool))
6266
{
63-
return "xs:boolean";
67+
return "booleanOrBlackboardType";
6468
}
6569
else if (type_info == typeid(std::string))
6670
{
67-
return "xs:string";
71+
return "stringOrBlackboardType";
6872
}
6973

7074
return std::string();
@@ -1201,17 +1205,22 @@ std::string writeTreeXSD(const BehaviorTreeFactory& factory)
12011205

12021206
// TODO: add <xs:whiteSpace value="preserve"/> for `inputPortType` and `outputPortType`.
12031207
parse_and_insert(schema_element, R"(
1204-
<xs:simpleType name="decimalOrBlackboardType">
1208+
<xs:simpleType name="blackboardType">
12051209
<xs:restriction base="xs:string">
1206-
<xs:pattern value="[+-]?[0-9]*(\.[0-9]+)?"/>
1207-
<xs:pattern value="\{[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)*\}"/>
1210+
<xs:pattern value="\{.*\}"/>
12081211
</xs:restriction>
12091212
</xs:simpleType>
1213+
<xs:simpleType name="booleanOrBlackboardType">
1214+
<xs:union memberTypes="xs:boolean blackboardType"/>
1215+
</xs:simpleType>
12101216
<xs:simpleType name="integerOrBlackboardType">
1211-
<xs:restriction base="xs:string">
1212-
<xs:pattern value="[+-]?[0-9]+"/>
1213-
<xs:pattern value="\{[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)*\}"/>
1214-
</xs:restriction>
1217+
<xs:union memberTypes="xs:integer blackboardType"/>
1218+
</xs:simpleType>
1219+
<xs:simpleType name="decimalOrBlackboardType">
1220+
<xs:union memberTypes="xs:decimal blackboardType"/>
1221+
</xs:simpleType>
1222+
<xs:simpleType name="stringOrBlackboardType">
1223+
<xs:union memberTypes="xs:string blackboardType"/>
12151224
</xs:simpleType>
12161225
<xs:simpleType name="descriptionType">
12171226
<xs:restriction base="xs:string">
@@ -1295,7 +1304,7 @@ std::string writeTreeXSD(const BehaviorTreeFactory& factory)
12951304
<xs:element ref="TreeNodesModel" minOccurs="0" maxOccurs="1"/>
12961305
</xs:sequence>
12971306
<xs:attribute name="BTCPP_format" type="xs:string" use="required"/>
1298-
<xs:attribute name="main_tree_to_execute" type="xs:string" use="required"/>
1307+
<xs:attribute name="main_tree_to_execute" type="xs:string" use="optional"/>
12991308
</xs:complexType>
13001309
</xs:element>
13011310
)";

0 commit comments

Comments
 (0)