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

Added set active tree action by name to api and cross origin api #4317

Merged
merged 4 commits into from
Nov 14, 2019
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
[Commits](https://github.com/scalableminds/webknossos/compare/19.11.0...HEAD)

### Added
-
- Added an API to set a tree active by name. [#4317](https://github.com/scalableminds/webknossos/pull/4317)

### Changed
-
Expand Down
13 changes: 13 additions & 0 deletions frontend/javascripts/oxalis/api/api_latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
setNodeRadiusAction,
setTreeNameAction,
setActiveTreeAction,
setActiveTreeByNameAction,
setTreeColorIndexAction,
setTreeVisibilityAction,
setTreeGroupAction,
Expand Down Expand Up @@ -286,6 +287,18 @@ class TracingApi {
Store.dispatch(setActiveTreeAction(treeId));
}

/**
* Makes the tree specified by name active. Within the tree, the node with the highest ID will be activated.
*
* @example
* api.tracing.setActiveTree("tree_1");
*/
setActiveTreeByName(treeName: string) {
const { tracing } = Store.getState();
assertSkeleton(tracing);
Store.dispatch(setActiveTreeByNameAction(treeName));
}

/**
* Changes the color of the referenced tree. Internally, a pre-defined array of colors is used which is
* why this function uses a colorIndex (between 0 and 500) instead of a proper color.
Expand Down
9 changes: 9 additions & 0 deletions frontend/javascripts/oxalis/api/cross_origin_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ const onMessage = event => {
api.tracing.resetSkeletonTracing();
break;
}
case "setActiveTreeByName": {
const treeName = args[0];
if (_.isString(treeName)) {
api.tracing.setActiveTreeByName(treeName);
} else {
console.warn("The first argument needs to be the name of the tree.");
}
break;
}
case "importNml": {
const nmlAsString = args[0];
if (_.isString(nmlAsString)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type AddTreesAndGroupsAction = {
type DeleteTreeAction = { type: "DELETE_TREE", treeId?: number, timestamp: number };
type ResetSkeletonTracingAction = { type: "RESET_SKELETON_TRACING" };
type SetActiveTreeAction = { type: "SET_ACTIVE_TREE", treeId: number };
type SetActiveTreeByNameAction = { type: "SET_ACTIVE_TREE_BY_NAME", treeName: string };
type DeselectActiveTreeAction = { type: "DESELECT_ACTIVE_TREE" };
type SetActiveGroupAction = { type: "SET_ACTIVE_GROUP", groupId: number };
type DeselectActiveGroupAction = { type: "DESELECT_ACTIVE_GROUP" };
Expand Down Expand Up @@ -124,6 +125,7 @@ export type SkeletonTracingAction =
| DeleteTreeAction
| ResetSkeletonTracingAction
| SetActiveTreeAction
| SetActiveTreeByNameAction
| DeselectActiveTreeAction
| MergeTreesAction
| SetTreeNameAction
Expand Down Expand Up @@ -157,6 +159,7 @@ export const SkeletonTracingSaveRelevantActions = [
"ADD_TREES_AND_GROUPS",
"DELETE_TREE",
"SET_ACTIVE_TREE",
"SET_ACTIVE_TREE_BY_NAME",
"SET_TREE_NAME",
"MERGE_TREES",
"SELECT_NEXT_TREE",
Expand Down Expand Up @@ -330,6 +333,11 @@ export const setActiveTreeAction = (treeId: number): SetActiveTreeAction => ({
treeId,
});

export const setActiveTreeByNameAction = (treeName: string): SetActiveTreeByNameAction => ({
type: "SET_ACTIVE_TREE_BY_NAME",
treeName,
});

export const deselectActiveTreeAction = (): DeselectActiveTreeAction => ({
type: "DESELECT_ACTIVE_TREE",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,25 @@ function SkeletonTracingReducer(state: OxalisState, action: Action): OxalisState
})
.getOrElse(state);
}
case "SET_ACTIVE_TREE_BY_NAME": {
const { treeName } = action;
const { trees } = skeletonTracing;
const treeWithMatchingName = _.values(trees).find(tree => tree.name === treeName);
if (!treeWithMatchingName) {
return state;
}
const newActiveNodeId = _.max(treeWithMatchingName.nodes.map(el => el.id)) || null;

return update(state, {
tracing: {
skeleton: {
activeNodeId: { $set: newActiveNodeId },
activeTreeId: { $set: treeWithMatchingName.treeId },
activeGroupId: { $set: null },
},
},
});
}

case "DESELECT_ACTIVE_TREE": {
return update(state, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export function* watchSkeletonTracingAsync(): Saga<void> {
yield _takeEvery(
[
"SET_ACTIVE_TREE",
"SET_ACTIVE_TREE_BY_NAME",
"SET_ACTIVE_NODE",
"DELETE_NODE",
"DELETE_BRANCHPOINT",
Expand Down