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
10 changes: 9 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ tox = "*"

[packages]
bpmn-python = {editable = true,path = "."}
six = "*"
pandas = "*"
networkx = "*"
matplotlib = "*"
pydotplus = "*"
pydot = "*"
pytest = "*"
tox = "*"

[requires]
python_version = "3.7"
python_version = "3.13"
74 changes: 37 additions & 37 deletions bpmn_python/bpmn_diagram_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def import_participant_element(diagram_graph, participants_dictionary, participa
process_ref = participant_element.getAttribute(consts.Consts.process_ref)
if participant_element.getAttribute(consts.Consts.process_ref) == '':
diagram_graph.add_node(participant_id)
diagram_graph.node[participant_id][consts.Consts.type] = consts.Consts.participant
diagram_graph.node[participant_id][consts.Consts.process] = participant_id
diagram_graph.nodes[participant_id][consts.Consts.type] = consts.Consts.participant
diagram_graph.nodes[participant_id][consts.Consts.process] = participant_id
participants_dictionary[participant_id] = {consts.Consts.name: name, consts.Consts.process_ref: process_ref}

@staticmethod
Expand Down Expand Up @@ -347,14 +347,14 @@ def import_flow_node_to_graph(bpmn_graph, process_id, process_attributes, flow_n
"""
element_id = flow_node_element.getAttribute(consts.Consts.id)
bpmn_graph.add_node(element_id)
bpmn_graph.node[element_id][consts.Consts.id] = element_id
bpmn_graph.node[element_id][consts.Consts.type] = \
bpmn_graph.nodes[element_id][consts.Consts.id] = element_id
bpmn_graph.nodes[element_id][consts.Consts.type] = \
utils.BpmnImportUtils.remove_namespace_from_tag_name(flow_node_element.tagName)
bpmn_graph.node[element_id][consts.Consts.node_name] = \
bpmn_graph.nodes[element_id][consts.Consts.node_name] = \
flow_node_element.getAttribute(consts.Consts.name) \
if flow_node_element.hasAttribute(consts.Consts.name) \
else ""
bpmn_graph.node[element_id][consts.Consts.process] = process_id
bpmn_graph.nodes[element_id][consts.Consts.process] = process_id
process_attributes[consts.Consts.node_ids].append(element_id)

# add incoming flow node list
Expand All @@ -365,7 +365,7 @@ def import_flow_node_to_graph(bpmn_graph, process_id, process_attributes, flow_n
if tag_name == consts.Consts.incoming_flow:
incoming_value = tmp_element.firstChild.nodeValue
incoming_list.append(incoming_value)
bpmn_graph.node[element_id][consts.Consts.incoming_flow] = incoming_list
bpmn_graph.nodes[element_id][consts.Consts.incoming_flow] = incoming_list

# add outgoing flow node list
outgoing_list = []
Expand All @@ -375,7 +375,7 @@ def import_flow_node_to_graph(bpmn_graph, process_id, process_attributes, flow_n
if tag_name == consts.Consts.outgoing_flow:
outgoing_value = tmp_element.firstChild.nodeValue
outgoing_list.append(outgoing_value)
bpmn_graph.node[element_id][consts.Consts.outgoing_flow] = outgoing_list
bpmn_graph.nodes[element_id][consts.Consts.outgoing_flow] = outgoing_list

@staticmethod
def import_task_to_graph(diagram_graph, process_id, process_attributes, task_element):
Expand Down Expand Up @@ -410,11 +410,11 @@ def import_subprocess_to_graph(diagram_graph, sequence_flows, process_id, proces
subprocess_element)

subprocess_id = subprocess_element.getAttribute(consts.Consts.id)
diagram_graph.node[subprocess_id][consts.Consts.triggered_by_event] = \
diagram_graph.nodes[subprocess_id][consts.Consts.triggered_by_event] = \
subprocess_element.getAttribute(consts.Consts.triggered_by_event) \
if subprocess_element.hasAttribute(consts.Consts.triggered_by_event) else "false"

subprocess_attributes = diagram_graph.node[subprocess_id]
subprocess_attributes = diagram_graph.nodes[subprocess_id]
subprocess_attributes[consts.Consts.node_ids] = []
for element in utils.BpmnImportUtils.iterate_elements(subprocess_element):
if element.nodeType != element.TEXT_NODE:
Expand Down Expand Up @@ -444,7 +444,7 @@ def import_data_object_to_graph(diagram_graph, process_id, process_attributes, d
BpmnDiagramGraphImport.import_flow_node_to_graph(diagram_graph, process_id, process_attributes,
data_object_element)
data_object_id = data_object_element.getAttribute(consts.Consts.id)
diagram_graph.node[data_object_id][consts.Consts.is_collection] = \
diagram_graph.nodes[data_object_id][consts.Consts.is_collection] = \
data_object_element.getAttribute(consts.Consts.is_collection) \
if data_object_element.hasAttribute(consts.Consts.is_collection) else "false"

Expand All @@ -464,7 +464,7 @@ def import_activity_to_graph(diagram_graph, process_id, process_attributes, elem
BpmnDiagramGraphImport.import_flow_node_to_graph(diagram_graph, process_id, process_attributes, element)

element_id = element.getAttribute(consts.Consts.id)
diagram_graph.node[element_id][consts.Consts.default] = element.getAttribute(consts.Consts.default) \
diagram_graph.nodes[element_id][consts.Consts.default] = element.getAttribute(consts.Consts.default) \
if element.hasAttribute(consts.Consts.default) else None

@staticmethod
Expand All @@ -482,7 +482,7 @@ def import_gateway_to_graph(diagram_graph, process_id, process_attributes, eleme
"""
element_id = element.getAttribute(consts.Consts.id)
BpmnDiagramGraphImport.import_flow_node_to_graph(diagram_graph, process_id, process_attributes, element)
diagram_graph.node[element_id][consts.Consts.gateway_direction] = \
diagram_graph.nodes[element_id][consts.Consts.gateway_direction] = \
element.getAttribute(consts.Consts.gateway_direction) \
if element.hasAttribute(consts.Consts.gateway_direction) else "Unspecified"

Expand All @@ -501,7 +501,7 @@ def import_complex_gateway_to_graph(diagram_graph, process_id, process_attribute
"""
element_id = element.getAttribute(consts.Consts.id)
BpmnDiagramGraphImport.import_gateway_to_graph(diagram_graph, process_id, process_attributes, element)
diagram_graph.node[element_id][consts.Consts.default] = element.getAttribute(consts.Consts.default) \
diagram_graph.nodes[element_id][consts.Consts.default] = element.getAttribute(consts.Consts.default) \
if element.hasAttribute(consts.Consts.default) else None
# TODO sequence of conditions
# Can't get any working example of Complex gateway, so I'm not sure how exactly those conditions are kept
Expand All @@ -522,9 +522,9 @@ def import_event_based_gateway_to_graph(diagram_graph, process_id, process_attri
"""
element_id = element.getAttribute(consts.Consts.id)
BpmnDiagramGraphImport.import_gateway_to_graph(diagram_graph, process_id, process_attributes, element)
diagram_graph.node[element_id][consts.Consts.instantiate] = element.getAttribute(consts.Consts.instantiate) \
diagram_graph.nodes[element_id][consts.Consts.instantiate] = element.getAttribute(consts.Consts.instantiate) \
if element.hasAttribute(consts.Consts.instantiate) else "false"
diagram_graph.node[element_id][consts.Consts.event_gateway_type] = \
diagram_graph.nodes[element_id][consts.Consts.event_gateway_type] = \
element.getAttribute(consts.Consts.event_gateway_type) \
if element.hasAttribute(consts.Consts.event_gateway_type) else "Exclusive"

Expand All @@ -543,7 +543,7 @@ def import_incl_or_excl_gateway_to_graph(diagram_graph, process_id, process_attr
"""
element_id = element.getAttribute(consts.Consts.id)
BpmnDiagramGraphImport.import_gateway_to_graph(diagram_graph, process_id, process_attributes, element)
diagram_graph.node[element_id][consts.Consts.default] = element.getAttribute(consts.Consts.default) \
diagram_graph.nodes[element_id][consts.Consts.default] = element.getAttribute(consts.Consts.default) \
if element.hasAttribute(consts.Consts.default) else None

@staticmethod
Expand Down Expand Up @@ -578,7 +578,7 @@ def import_event_definition_elements(diagram_graph, element, event_definitions):
event_def_tmp = {consts.Consts.id: event_def_xml[index].getAttribute(consts.Consts.id),
consts.Consts.definition_type: definition_type}
event_def_list.append(event_def_tmp)
diagram_graph.node[element_id][consts.Consts.event_definitions] = event_def_list
diagram_graph.nodes[element_id][consts.Consts.event_definitions] = event_def_list

@staticmethod
def import_start_event_to_graph(diagram_graph, process_id, process_attributes, element):
Expand All @@ -599,10 +599,10 @@ def import_start_event_to_graph(diagram_graph, process_id, process_attributes, e
start_event_definitions = {'messageEventDefinition', 'timerEventDefinition', 'conditionalEventDefinition',
'escalationEventDefinition', 'signalEventDefinition'}
BpmnDiagramGraphImport.import_flow_node_to_graph(diagram_graph, process_id, process_attributes, element)
diagram_graph.node[element_id][consts.Consts.parallel_multiple] = \
diagram_graph.nodes[element_id][consts.Consts.parallel_multiple] = \
element.getAttribute(consts.Consts.parallel_multiple) \
if element.hasAttribute(consts.Consts.parallel_multiple) else "false"
diagram_graph.node[element_id][consts.Consts.is_interrupting] = \
diagram_graph.nodes[element_id][consts.Consts.is_interrupting] = \
element.getAttribute(consts.Consts.is_interrupting) \
if element.hasAttribute(consts.Consts.is_interrupting) else "true"
BpmnDiagramGraphImport.import_event_definition_elements(diagram_graph, element, start_event_definitions)
Expand All @@ -627,7 +627,7 @@ def import_intermediate_catch_event_to_graph(diagram_graph, process_id, process_
'signalEventDefinition', 'conditionalEventDefinition',
'escalationEventDefinition'}
BpmnDiagramGraphImport.import_flow_node_to_graph(diagram_graph, process_id, process_attributes, element)
diagram_graph.node[element_id][consts.Consts.parallel_multiple] = \
diagram_graph.nodes[element_id][consts.Consts.parallel_multiple] = \
element.getAttribute(consts.Consts.parallel_multiple) \
if element.hasAttribute(consts.Consts.parallel_multiple) else "false"
BpmnDiagramGraphImport.import_event_definition_elements(diagram_graph, element,
Expand Down Expand Up @@ -691,13 +691,13 @@ def import_boundary_event_to_graph(diagram_graph, process_id, process_attributes
'conditionalEventDefinition', 'escalationEventDefinition', 'errorEventDefinition'}
BpmnDiagramGraphImport.import_flow_node_to_graph(diagram_graph, process_id, process_attributes, element)

diagram_graph.node[element_id][consts.Consts.parallel_multiple] = \
diagram_graph.nodes[element_id][consts.Consts.parallel_multiple] = \
element.getAttribute(consts.Consts.parallel_multiple) \
if element.hasAttribute(consts.Consts.parallel_multiple) else "false"
diagram_graph.node[element_id][consts.Consts.cancel_activity] = \
diagram_graph.nodes[element_id][consts.Consts.cancel_activity] = \
element.getAttribute(consts.Consts.cancel_activity) \
if element.hasAttribute(consts.Consts.cancel_activity) else "true"
diagram_graph.node[element_id][consts.Consts.attached_to_ref] = \
diagram_graph.nodes[element_id][consts.Consts.attached_to_ref] = \
element.getAttribute(consts.Consts.attached_to_ref)

BpmnDiagramGraphImport.import_event_definition_elements(diagram_graph, element,
Expand Down Expand Up @@ -749,15 +749,15 @@ def import_sequence_flow_to_graph(diagram_graph, sequence_flows, process_id, flo
added when processing nodes, but listing incoming / outgoing nodes under node element is optional - this way
we can make sure this info will be imported.
'''
if consts.Consts.outgoing_flow not in diagram_graph.node[source_ref]:
diagram_graph.node[source_ref][consts.Consts.outgoing_flow] = []
outgoing_list = diagram_graph.node[source_ref][consts.Consts.outgoing_flow]
if consts.Consts.outgoing_flow not in diagram_graph.nodes[source_ref]:
diagram_graph.nodes[source_ref][consts.Consts.outgoing_flow] = []
outgoing_list = diagram_graph.nodes[source_ref][consts.Consts.outgoing_flow]
if flow_id not in outgoing_list:
outgoing_list.append(flow_id)

if consts.Consts.incoming_flow not in diagram_graph.node[target_ref]:
diagram_graph.node[target_ref][consts.Consts.incoming_flow] = []
incoming_list = diagram_graph.node[target_ref][consts.Consts.incoming_flow]
if consts.Consts.incoming_flow not in diagram_graph.nodes[target_ref]:
diagram_graph.nodes[target_ref][consts.Consts.incoming_flow] = []
incoming_list = diagram_graph.nodes[target_ref][consts.Consts.incoming_flow]
if flow_id not in incoming_list:
incoming_list.append(flow_id)

Expand Down Expand Up @@ -797,15 +797,15 @@ def import_message_flow_to_graph(diagram_graph, message_flows, flow_element):
added when processing nodes, but listing incoming / outgoing nodes under node element is optional - this way
we can make sure this info will be imported.
'''
if consts.Consts.outgoing_flow not in diagram_graph.node[source_ref]:
diagram_graph.node[source_ref][consts.Consts.outgoing_flow] = []
outgoing_list = diagram_graph.node[source_ref][consts.Consts.outgoing_flow]
if consts.Consts.outgoing_flow not in diagram_graph.nodes[source_ref]:
diagram_graph.nodes[source_ref][consts.Consts.outgoing_flow] = []
outgoing_list = diagram_graph.nodes[source_ref][consts.Consts.outgoing_flow]
if flow_id not in outgoing_list:
outgoing_list.append(flow_id)

if consts.Consts.incoming_flow not in diagram_graph.node[target_ref]:
diagram_graph.node[target_ref][consts.Consts.incoming_flow] = []
incoming_list = diagram_graph.node[target_ref][consts.Consts.incoming_flow]
if consts.Consts.incoming_flow not in diagram_graph.nodes[target_ref]:
diagram_graph.nodes[target_ref][consts.Consts.incoming_flow] = []
incoming_list = diagram_graph.nodes[target_ref][consts.Consts.incoming_flow]
if flow_id not in incoming_list:
incoming_list.append(flow_id)

Expand All @@ -828,7 +828,7 @@ def import_shape_di(participants_dict, diagram_graph, shape_element):
element_id = shape_element.getAttribute(consts.Consts.bpmn_element)
bounds = shape_element.getElementsByTagNameNS("*", "Bounds")[0]
if diagram_graph.has_node(element_id):
node = diagram_graph.node[element_id]
node = diagram_graph.nodes[element_id]
node[consts.Consts.width] = bounds.getAttribute(consts.Consts.width)
node[consts.Consts.height] = bounds.getAttribute(consts.Consts.height)

Expand Down
2 changes: 1 addition & 1 deletion bpmn_python/bpmn_diagram_layouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def insert_into_grid(grid, row, col, node_id):
if occupied_cell:
for grid_cell in grid:
if grid_cell.row >= row:
grid_cell.row += consts.Consts.width
grid_cell.row += consts.Consts.grid_column_width
grid.append(cell_class.GridCell(row, col, node_id))


Expand Down
Loading