Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminals and Icons: Graphical Representation #138

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
78 changes: 78 additions & 0 deletions Test/FMI3/fmi3_import_terminals_and_icons_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ TEST_CASE("Test parse terminals and icons") {
REQUIRE(xml != nullptr);
REQUIRE(fmi3_import_get_has_terminals_and_icons(xml) != 0);

SECTION("Testing graphicalRepresentation") {
// TODO: FMI2
// TODO
;
SECTION("Testing coordinateSystem") {
// TODO:
;
}
SECTION("Testing Icon") {
// TODO:
;
}
}

SECTION("Testing getting terminal by name") {
fmi_import_terminal_t* term;

Expand Down Expand Up @@ -148,3 +162,67 @@ TEST_CASE("Test clearing of attribute buffer with invalid elements") {
REQUIRE(fmi3_testutil_get_num_problems(tfmu) == 3);
fmi3_testutil_import_free(tfmu);
}

TEST_CASE("Empty graphical representation: Takes default") {
const char* xmldir = FMI3_TEST_XML_DIR "/terminals_and_icons/valid/empty_graphicalRepresentation";
fmi3_testutil_import_t* tfmu = fmi3_testutil_parse_xml_with_log(xmldir);
fmi3_import_t* fmu = tfmu->fmu;
REQUIRE(fmu != nullptr); // successful parse of modelDescription
REQUIRE(fmi3_import_get_has_terminals_and_icons(fmu) == 1);

// TODO: Verify default coordinate system + scaling + no icon

REQUIRE(fmi3_testutil_get_num_problems(tfmu) == 0);
fmi3_testutil_import_free(tfmu);
}

TEST_CASE("Incomplete graphicaRepresentation->coordinateSystem: Takes default") {
const char* xmldir = FMI3_TEST_XML_DIR "/terminals_and_icons/invalid/incomplete_coordinateSystem";
fmi3_testutil_import_t* tfmu = fmi3_testutil_parse_xml_with_log(xmldir);
fmi3_import_t* fmu = tfmu->fmu;
REQUIRE(fmu != nullptr); // successful parse of modelDescription
REQUIRE(fmi3_import_get_has_terminals_and_icons(fmu) == 1);

REQUIRE(fmi3_testutil_log_contains(tfmu, "Parsing XML element 'CoordinateSystem': required attribute 'x2' not found"));
REQUIRE(fmi3_testutil_log_contains(tfmu, "Parsing XML element 'CoordinateSystem': required attribute 'y2' not found"));

REQUIRE(fmi3_testutil_log_contains(tfmu, "Failed to parse complete CoordinateSystem, using default system (-100, -100), (100, 100)."));

// TODO: Verify default coordinate system + no icon

REQUIRE(fmi3_testutil_get_num_problems(tfmu) == 3);
fmi3_testutil_import_free(tfmu);
}

TEST_CASE("Not well-defined graphicaRepresentation->coordinateSystem") {
const char* xmldir = FMI3_TEST_XML_DIR "/terminals_and_icons/invalid/flipped_coordinateSystem";
fmi3_testutil_import_t* tfmu = fmi3_testutil_parse_xml_with_log(xmldir);
fmi3_import_t* fmu = tfmu->fmu;
REQUIRE(fmu != nullptr); // successful parse of modelDescription
REQUIRE(fmi3_import_get_has_terminals_and_icons(fmu) == 1);

REQUIRE(fmi3_testutil_log_contains(tfmu, "'CoordinateSystem' not well-defined, requires x1 = 100.000000 < x2 = -100.000000."));
REQUIRE(fmi3_testutil_log_contains(tfmu, "'CoordinateSystem' not well-defined, requires y1 = 100.000000 < y2 = -100.000000."));

// TODO: Verify coordinates are stored anyways

REQUIRE(fmi3_testutil_get_num_problems(tfmu) == 2);
fmi3_testutil_import_free(tfmu);
}

TEST_CASE("Incomplete graphicalRepresentation->Icon") {
const char* xmldir = FMI3_TEST_XML_DIR "/terminals_and_icons/invalid/incomplete_icon";
fmi3_testutil_import_t* tfmu = fmi3_testutil_parse_xml_with_log(xmldir);
fmi3_import_t* fmu = tfmu->fmu;
REQUIRE(fmu != nullptr); // successful parse of modelDescription
REQUIRE(fmi3_import_get_has_terminals_and_icons(fmu) == 1);

REQUIRE(fmi3_testutil_log_contains(tfmu, "Parsing XML element 'Icon': required attribute 'x2' not found"));
REQUIRE(fmi3_testutil_log_contains(tfmu, "Parsing XML element 'Icon': required attribute 'y2' not found"));
REQUIRE(fmi3_testutil_log_contains(tfmu, "Failed to parse complete Icon."));

// TODO: Verify there is no icon

REQUIRE(fmi3_testutil_get_num_problems(tfmu) == 3);
fmi3_testutil_import_free(tfmu);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription fmiVersion="3.0-alpha" modelName="terminalsAndIcons_testing" instantiationToken="">
<ModelExchange modelIdentifier="id"/>

<ModelVariables>
<Float64 name="f64_var" valueReference="1"/>
</ModelVariables>

<ModelStructure/>
</fmiModelDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiTerminalsAndIcons fmiVersion="3.0-alpha">
<GraphicalRepresentation>
<!-- coordinate system does not fulfill x1 < x2, y1 < y2 -->
<CoordinateSystem x1="100" y1="100" x2="-100" y2="-100" suggestedScalingFactorTo_mm="0.1"/>
</GraphicalRepresentation>
</fmiTerminalsAndIcons>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription fmiVersion="3.0-alpha" modelName="terminalsAndIcons_testing" instantiationToken="">
<ModelExchange modelIdentifier="id"/>

<ModelVariables>
<Float64 name="f64_var" valueReference="1"/>
</ModelVariables>

<ModelStructure/>
</fmiModelDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiTerminalsAndIcons fmiVersion="3.0-alpha">
<GraphicalRepresentation>
<CoordinateSystem x1="200" y1="300" suggestedScalingFactorTo_mm="0.2"/>
</GraphicalRepresentation>
</fmiTerminalsAndIcons>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription fmiVersion="3.0-alpha" modelName="terminalsAndIcons_testing" instantiationToken="">
<ModelExchange modelIdentifier="id"/>

<ModelVariables>
<Float64 name="f64_var" valueReference="1"/>
</ModelVariables>

<ModelStructure/>
</fmiModelDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiTerminalsAndIcons fmiVersion="3.0-alpha">
<GraphicalRepresentation>
<!-- Incomplete set of attributes -->
<Icon x1="200" y1="300"/>
</GraphicalRepresentation>
</fmiTerminalsAndIcons>
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiTerminalsAndIcons fmiVersion="3.0-alpha">
<GraphicalRepresentation>
<CoordinateSystem x1="0.1" y1="2.3" x2="4.5" y2="6.7" suggestedScalingFactorTo_mm="0.2"/>
<Icon x1="-0.1" y1="-2.3" x2="-4.5" y2="-6.7"/> <!-- flipped: OK-->
</GraphicalRepresentation>
<Terminals>
<Terminal name="terminalA" matchingRule="bus" description="some description" terminalKind="abc">
<!-- These are all dummys for now -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription fmiVersion="3.0-alpha" modelName="terminalsAndIcons_testing" instantiationToken="">
<ModelExchange modelIdentifier="id"/>

<ModelVariables>
<Float64 name="f64_var" valueReference="1"/>
</ModelVariables>

<ModelStructure/>
</fmiModelDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiTerminalsAndIcons fmiVersion="3.0-alpha">
<GraphicalRepresentation>
<!-- takes default coordinate system -->
</GraphicalRepresentation>
</fmiTerminalsAndIcons>
21 changes: 21 additions & 0 deletions src/XML/include/FMI/fmi_xml_terminals_and_icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ extern "C" {

/* Structure encapsulating terminals and icons information */
typedef struct fmi_xml_terminals_and_icons_t fmi_xml_terminals_and_icons_t;
/* Structure encapsulating graphicalRepresentation information */
typedef struct fmi_xml_graphicalRepresentation_t fmi_xml_graphicalRepresentation_t;
/* Structure encapsulating coordinateSystem information */
typedef struct fmi_xml_coordinateSystem_t fmi_xml_coordinateSystem_t;
/* Structure encapsulating icon information */
typedef struct fmi_xml_icon_t fmi_xml_icon_t;
/* Structure encapsulating terminal information */
typedef struct fmi_xml_terminal_t fmi_xml_terminal_t;

Expand All @@ -62,7 +68,22 @@ int fmi2_xml_terminals_and_icons_set_model_description(fmi_xml_terminals_and_ico
int fmi3_xml_terminals_and_icons_set_model_description(fmi_xml_terminals_and_icons_t* termIcon,
fmi3_xml_model_description_t* md);

/* Top level */
int fmi_xml_get_has_terminals_and_icons(fmi_xml_terminals_and_icons_t* termIcon);

/* Graphical Representation */
int fmi_xml_get_has_graphical_representation(fmi_xml_terminals_and_icons_t* termIcon);
/* coordinateSystem*/
int fmi_xml_get_graphical_representation_system_coordinates(fmi_xml_graphicalRepresentation_t* graphRepr,
double* x1, double* y1, double* x2, double* y2);
int fmi_xml_get_graphical_representation_suggested_scaling(fmi_xml_graphicalRepresentation_t* graphRepr,
double* suggested_scaling);
/* icon */
int fmi_xml_get_graphical_representation_has_icon(fmi_xml_graphicalRepresentation_t* graphRepr);
int fmi_xml_get_graphical_representation_icon_coordinates(fmi_xml_graphicalRepresentation_t* graphRepr,
double* x1, double* y1, double* x2, double* y2);

/* Terminals */
fmi_xml_terminal_t* fmi_xml_get_terminal_by_name(fmi_xml_terminals_and_icons_t* termIcon, const char* name);
const char* fmi_xml_get_terminal_name(fmi_xml_terminal_t* term);

Expand Down
31 changes: 22 additions & 9 deletions src/XML/include/FMI/fmi_xml_terminals_and_icons_scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ extern "C" {
#define FMI_XML_ATTRLIST_TERM_ICON(EXPAND_XML_ATTRNAME) \
EXPAND_XML_ATTRNAME(fmiVersion) \
EXPAND_XML_ATTRNAME(name) \
EXPAND_XML_ATTRNAME(description)
EXPAND_XML_ATTRNAME(description) \
EXPAND_XML_ATTRNAME(x1) \
EXPAND_XML_ATTRNAME(y1) \
EXPAND_XML_ATTRNAME(x2) \
EXPAND_XML_ATTRNAME(y2) \
EXPAND_XML_ATTRNAME(suggestedScalingFactorTo_mm)


/* Element names found in terminalsAndIcons.xml */
#define FMI_XML_ELMLIST_TERM_ICON(EXPAND_XML_ELMNAME) \
EXPAND_XML_ELMNAME(fmiTerminalsAndIcons) \
EXPAND_XML_ELMNAME(GraphicalRepresentation) \
EXPAND_XML_ELMNAME(CoordinateSystem) \
EXPAND_XML_ELMNAME(Icon) \
EXPAND_XML_ELMNAME(Terminals) \
EXPAND_XML_ELMNAME(Terminal) \
EXPAND_XML_ELMNAME(TerminalMemberVariable) \
Expand All @@ -48,14 +57,18 @@ extern "C" {
@multi_elem:
if the parent can have multiple elements of this type
*/
/* scheme_ID, super_type, parent_ID, sib_idx, multi_elem */
#define fmi_xml_scheme_termIcon_fmiTerminalsAndIcons {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_none, 0, 0}

#define fmi_xml_scheme_termIcon_Terminals {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_fmiTerminalsAndIcons, 1, 0}
#define fmi_xml_scheme_termIcon_Terminal {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminals, 0, 1}
#define fmi_xml_scheme_termIcon_TerminalMemberVariable {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 0, 1}
#define fmi_xml_scheme_termIcon_TerminalStreamMemberVariable {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 1, 1}
#define fmi_xml_scheme_termIcon_TerminalGraphicalRepresentation {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 3, 0}
/* scheme_ID, super_type, parent_ID, sib_idx, multi_elem */
#define fmi_xml_scheme_termIcon_fmiTerminalsAndIcons {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_none, 0, 0}

#define fmi_xml_scheme_termIcon_GraphicalRepresentation {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_fmiTerminalsAndIcons, 0, 0}
#define fmi_xml_scheme_termIcon_CoordinateSystem {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_GraphicalRepresentation, 0, 0}
#define fmi_xml_scheme_termIcon_Icon {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_GraphicalRepresentation, 1, 0}

#define fmi_xml_scheme_termIcon_Terminals {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_fmiTerminalsAndIcons, 1, 0}
#define fmi_xml_scheme_termIcon_Terminal {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminals, 0, 1}
#define fmi_xml_scheme_termIcon_TerminalMemberVariable {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 0, 1}
#define fmi_xml_scheme_termIcon_TerminalStreamMemberVariable {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 1, 1}
#define fmi_xml_scheme_termIcon_TerminalGraphicalRepresentation {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 3, 0}

// Attribute enum
#define FMI_TERMICON_XML_ATTR_ID(attr) fmi_termIcon_attr_id_##attr,
Expand Down
Loading