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

Handle child cells in registerCellsAddedHandler #140

Closed
wants to merge 3 commits into from

Conversation

cauebs
Copy link
Contributor

@cauebs cauebs commented Sep 19, 2022

Needed for ASIM-4848. Main PR in https://github.com/ESSS/alfasim/pull/38/.

When cells are copied by ctrl+dragging, a callback is executed as the new cells are added, but decorations weren't passed along with nodes and edges (and perhaps tables).

The callback implementation for when cells are removed included some logic for recursing down into child cells, and it seems that was also required for when they're added. This PR factors that logic out from registerCellsRemovedHandler so it can be reused in registerCellsAddedHandler.

Props to @prusse-martin for basically co-authoring this.

@cauebs cauebs changed the title Handle children cells in registerCellsAddedHandler Handle child cells in registerCellsAddedHandler Sep 19, 2022
@cauebs cauebs force-pushed the fb-ASIM-4848-clone-network-elements branch 2 times, most recently from dcfaf1e to 97f80ce Compare September 20, 2022 14:27
@cauebs cauebs force-pushed the fb-ASIM-4848-clone-network-elements branch 2 times, most recently from 8d44d36 to b3afed3 Compare September 21, 2022 15:57
@cauebs cauebs force-pushed the fb-ASIM-4848-clone-network-elements branch from e8ddd07 to 52cffb8 Compare November 14, 2022 16:12
@cauebs cauebs force-pushed the fb-ASIM-4848-clone-network-elements branch from bf7498e to 52cffb8 Compare November 21, 2022 18:28
@cauebs cauebs force-pushed the fb-ASIM-4848-clone-network-elements branch from f61329d to 2f786c7 Compare December 16, 2022 19:03
* @param {number[]} cellIds Ids of cells to be cloned.
* @param {boolean} ignoreMissingCells Ids of non existent cells are ignored instead of
* raising an error.
* @param {boolean} allowInvalidEdges Specifies if invalid edges should be cloned.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate what are "invalid edges"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confess I'm not quite sure. I'm just surfacing the underlying mxGraph API. But since I'm already changing the behaviour by implicitly adding the cells to the graph on cloneCells (which mxGraph doesn't do), then maybe I could just ommit that parameter since it's not useful to us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: reading the mxGraph's source code just now, it seems that "invalid edges" is all about the edges' terminal nodes. It checks for dangling edges, loops, edges missing both terminal nodes, etc.

raising an error.
:param allow_invalid_edges: Specifies if invalid edges should be cloned.
"""
with wait_signals_called(self._events_bridge.on_cells_added):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that if cell_ids is empty this will hang.
Given this scenario also affects other code around I think we can ignore this for now.

tests/test_js_graph.py Show resolved Hide resolved
Comment on lines +671 to +707
assert added_handler.call_args_list == [
mocker.call(cell_id) for cell_id in (cell_ids + new_cell_ids)
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure.
Does this causes the add event to be called one time for each cell?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't, you're right. In the current implementation cellsAdded is only called once for each call to cloneCells.

The thing is I haven't run the tests yet, because I'm having trouble building this project's conda environment, and the CI is still broken.

"""
graph = graph_cases('2v_1e')

vertices = graph.get_vertices()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also often do this:

Suggested change
vertices = graph.get_vertices()
vert1, vert2 = graph.get_vertices()

@cauebs cauebs force-pushed the fb-ASIM-4848-clone-network-elements branch from 60dfff4 to f65e168 Compare December 22, 2022 19:51
Replace spread operator with more supported apply method
@cauebs cauebs force-pushed the fb-ASIM-4848-clone-network-elements branch from d767d30 to bf0d5b1 Compare February 20, 2023 16:10
var graph = this._graphEditor.graph;

// Creates a dictionary for fast lookups
var dict = new mxDictionary();
var tmp = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabs for indentation?

Better check your IDE XP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from mxgraph. I will convert it to spaces 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-commit.ci already did that.

@cauebs cauebs marked this pull request as draft July 28, 2023 16:17
@cauebs cauebs closed this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants