update empty geometry handling
This commit is contained in:
@@ -3211,11 +3211,15 @@ static int cyberiada_process_decode_sm_document(CyberiadaDocument* cyb_doc, xmlD
|
||||
if (res == CYBERIADA_NO_ERROR) {
|
||||
if (flags & CYBERIADA_FLAG_SKIP_GEOMETRY) {
|
||||
cyberiada_clean_document_geometry(cyb_doc);
|
||||
} else {
|
||||
} else if (cyberiada_document_has_geometry(cyb_doc) ||
|
||||
flags & CYBERIADA_FLAG_RECONSTRUCT_GEOMETRY) {
|
||||
cyberiada_import_document_geometry(cyb_doc, flags, format);
|
||||
} else {
|
||||
/* document has no geometry */
|
||||
cyb_doc->geometry_format = cybCoordNone;
|
||||
cyb_doc->edge_geom_format = cybEdgeNone;
|
||||
}
|
||||
}
|
||||
|
||||
} while(0);
|
||||
|
||||
cyberiada_free_name_list(&nl);
|
||||
@@ -4437,12 +4441,12 @@ static int cyberiada_process_encode_sm_document(CyberiadaDocument* doc, xmlTextW
|
||||
}
|
||||
}
|
||||
|
||||
if (CYBERIADA_FLAG_ABSOLUTE_GEOMETRY |
|
||||
if (flags & (CYBERIADA_FLAG_ABSOLUTE_GEOMETRY |
|
||||
CYBERIADA_FLAG_LEFTTOP_LOCAL_GEOMETRY |
|
||||
CYBERIADA_FLAG_CENTER_LOCAL_GEOMETRY |
|
||||
CYBERIADA_FLAG_LEFTTOP_BORDER_EDGE_GEOMETRY |
|
||||
CYBERIADA_FLAG_CENTER_BORDER_EDGE_GEOMETRY |
|
||||
CYBERIADA_FLAG_CENTER_EDGE_GEOMETRY) {
|
||||
CYBERIADA_FLAG_CENTER_EDGE_GEOMETRY)) {
|
||||
|
||||
ERROR("Geometry flags (abs, left-top, center) & edge geometry flags are not allowed for export\n");
|
||||
return CYBERIADA_BAD_PARAMETER;
|
||||
|
||||
@@ -368,6 +368,9 @@ typedef enum {
|
||||
/* Free the SM polyline structure in memory */
|
||||
int cyberiada_destroy_polyline(CyberiadaPolyline* polyline);
|
||||
|
||||
/* Check the presence of the SM document geometry, return 1 if there is any geometry object available */
|
||||
int cyberiada_document_has_geometry(CyberiadaDocument* doc);
|
||||
|
||||
/* Change the SM document geometry format and convert the SMs geometry data */
|
||||
int cyberiada_convert_document_geometry(CyberiadaDocument* doc,
|
||||
CyberiadaGeometryCoordFormat new_format,
|
||||
|
||||
56
geometry.c
56
geometry.c
@@ -1188,6 +1188,8 @@ int cyberiada_export_document_geometry(CyberiadaDocument* doc,
|
||||
|
||||
if (flags & CYBERIADA_FLAG_RECONSTRUCT_GEOMETRY) {
|
||||
cyberiada_reconstruct_document_geometry(doc);
|
||||
} else if (!cyberiada_document_has_geometry(doc)) {
|
||||
return CYBERIADA_NO_ERROR;
|
||||
}
|
||||
|
||||
if (flags & CYBERIADA_FLAG_ROUND_GEOMETRY) {
|
||||
@@ -1195,8 +1197,10 @@ int cyberiada_export_document_geometry(CyberiadaDocument* doc,
|
||||
}
|
||||
|
||||
for (sm = doc->state_machines; sm; sm = sm->next) {
|
||||
if (sm->bounding_rect) {
|
||||
cyberiada_convert_node_geometry(sm->nodes, sm->bounding_rect,
|
||||
doc->geometry_format, to_format);
|
||||
}
|
||||
if (sm->edges) {
|
||||
cyberiada_convert_edge_geometry(sm->edges,
|
||||
doc->geometry_format, to_format,
|
||||
@@ -1207,3 +1211,55 @@ int cyberiada_export_document_geometry(CyberiadaDocument* doc,
|
||||
return CYBERIADA_NO_ERROR;
|
||||
}
|
||||
|
||||
static int cyberiada_node_has_geometry(CyberiadaNode* node)
|
||||
{
|
||||
while (node) {
|
||||
if (node->geometry_point) {
|
||||
return 1;
|
||||
}
|
||||
if (node->geometry_rect) {
|
||||
return 1;
|
||||
}
|
||||
if (node->children) {
|
||||
int found = cyberiada_node_has_geometry(node->children);
|
||||
if (found) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cyberiada_document_has_geometry(CyberiadaDocument* doc)
|
||||
{
|
||||
CyberiadaSM* sm;
|
||||
CyberiadaEdge* edge;
|
||||
|
||||
if (!doc) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (sm = doc->state_machines; sm; sm = sm->next) {
|
||||
if (cyberiada_node_has_geometry(sm->nodes)) {
|
||||
return 1;
|
||||
}
|
||||
edge = sm->edges;
|
||||
while (edge) {
|
||||
if (edge->geometry_polyline) {
|
||||
return 1;
|
||||
}
|
||||
if (edge->geometry_source_point) {
|
||||
return 1;
|
||||
}
|
||||
if (edge->geometry_target_point) {
|
||||
return 1;
|
||||
}
|
||||
if (edge->geometry_label_point) {
|
||||
return 1;
|
||||
}
|
||||
edge = edge->next;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ extern "C" {
|
||||
int flags, CyberiadaXMLFormat file_format);
|
||||
int cyberiada_export_document_geometry(CyberiadaDocument* doc,
|
||||
int flags, CyberiadaXMLFormat file_format);
|
||||
int cyberiada_document_has_geometry(CyberiadaDocument* doc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user