Skip to content

Commit

Permalink
Merge pull request #81 from ESSS/fb-ASIM-3658-annulus-ports-support
Browse files Browse the repository at this point in the history
Add function to identify if port exists in a cell
  • Loading branch information
Mauricio Oliveira committed Jun 3, 2020
2 parents 1a9acf2 + 929d980 commit 1ce6905
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions qmxgraph/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ def has_cell(self, cell_id):
"""
return self.call_api('hasCell', cell_id)

def has_port(self, cell_id, port_name):
"""
Indicates if the port exists.
:param str cell_id: Id of a cell in graph.
:param str port_name: Name of the expected port.
:rtype: bool
:return: True if the port exists.
"""
return self.call_api('hasPort', cell_id, port_name)

def get_cell_type(self, cell_id):
"""
:param str cell_id: Id of a cell in graph.
Expand Down
14 changes: 14 additions & 0 deletions qmxgraph/page/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,20 @@ graphs.Api.prototype._findPort = function _findPort (model, cellId, portName, al
return port;
};

/**
* @param {number} cellId Id of a cell in graph.
* @param {string} portName The name of the port.
* @returns {boolean} True if the port exists.
*/
graphs.Api.prototype.hasPort = function hasPort (cellId, portName) {
"use strict";

var graph = this._graphEditor.graph;
var portId = mxCell.createPortId(cellId, portName);
var port = graph.getModel().getCell(portId);
return !!port;
};

/**
*
* @param {number} cellId
Expand Down
2 changes: 2 additions & 0 deletions tests/test_qt_js_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def test_events_bridge(graph, qtbot, mocker):
bar_id = graph.api.insert_vertex(40, 140, 20, 20, 'bar')
edge_id = graph.api.insert_edge(vertex_id, foo_id, 'edge')
bar_port_name = 'a-port'
assert not graph.api.has_port(bar_id, bar_port_name)
graph.api.insert_port(bar_id, bar_port_name, 0, 0, 5, 5)
assert graph.api.has_port(bar_id, bar_port_name)

graph.api.set_edge_terminal(
edge_id, QmxGraphApi.TARGET_TERMINAL_CELL, bar_id, bar_port_name)
Expand Down

0 comments on commit 1ce6905

Please sign in to comment.