question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to disable a tool when another gets activated?

See original GitHub issue

Prerequisites

  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

Description

We’re trying to add a new custom tool PanZoom which allows panning and zooming. We’re aware that these controls are already available standalone and can be used simultaneously. However, the fact that they can be used simultaneously is not discoverable - hence having a tool to do so explicitly.

Here’s what I have so far:

/* eslint-disable */
import BaseTool from './base/BaseTool.js';
import { setToolActive, setToolDisabled } from '../store/setToolMode.js';

/**
 * @public
 * @class PanZoomWheelTool
 * @memberof Tools
 *
 * @classdesc Tool that combines Pan and ZoomWheel behavior.
 * @extends Tools.Base.BaseTool
 */

export default class PanZoomWheelTool extends BaseTool {
  constructor(props = {}) {
    const defaultProps = {
      name: 'PanZoomWheel',
      supportedInteractionTypes: ['Mouse'],
    };

    super(props, defaultProps);

    this.referencedToolNames = {
      pan: 'Pan',
      stackScroll: 'StackScrollMouseWheel',
      zoomWheel: 'ZoomMouseWheel',
    };

    this.activeCallback = this.activate.bind(this);
    this.disabledCallback = this.deactivate.bind(this);
  }

  activate() {
    setToolDisabled(this.referencedToolNames.stackScroll);
    setToolActive(this.referencedToolNames.pan, { mouseButtonMask: 1 });
    setToolActive(this.referencedToolNames.zoomWheel, { mouseButtonMask: 4 });
  }

  deactivate() {
    setToolActive(this.referencedToolNames.stackScroll);
    setToolDisabled(this.referencedToolNames.pan);
    setToolDisabled(this.referencedToolNames.zoomWheel);
  }
}

The tool activates and the panning and zoom work as expected. However, I can’t seem to get deactivate fired in disabledCallback. What happens then is that I the zoomWheel continues to be active in the mouse wheel.

For reference, here’s how we achieved the desired behavior this in cornerstoneTools v2:

activate(element) {
  cornerstoneTools.pan.activate(element, 1);
  cornerstoneTools.stackScrollWheel.deactivate(element);
  cornerstoneTools.zoomWheel.activate(element);
}

deactivate(element) {
   cornerstoneTools.pan.deactivate(element, 1);
   cornerstoneTools.zoomWheel.deactivate(element);
   cornerstoneTools.stackScrollWheel.activate(element);
}

What is the appropriate API/approach to achieve this in V3? Is there a hook available from within this tool to tear down the tools that I activated when any other tool is activated?

Steps to Reproduce

N/A

Expected behavior: N/A

Actual behavior: [What actually happened] N/A

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
dannyrbcommented, Jul 22, 2019

@Ggpsv, they’re named “inputResolvers” which really just means that we try to resolve input conflicts when activating a new tool. You can find some of the logic here: https://github.com/cornerstonejs/cornerstoneTools/blob/master/src/store/setToolMode.js#L312-L355

When we activate a tool, we…

  1. Find tools with the same supported interaction types (mouse, touch, wheel, etc)
  2. Find and call the appropriate inputResolver for that interaction type
    • This clears/removes options/settings that would be conflicting after the new tool is activated
  3. Find tools that are active for the same element
  4. Iterate over each active tool w/ the same supported interaction type
  5. If all of their bindings/options were removed by the inputResolver, we call setToolPassiveForElement on them

https://github.com/cornerstonejs/cornerstoneTools/blob/master/src/store/setToolMode.js#L352

1reaction
Ggpsvcommented, Aug 2, 2019

Yeah I understand that now. That wasn’t entirely clear 10 days ago. I’ll be closing this issue now, thanks for all the feedback!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way of disabling other tools while one is currently ...
You can make it so when you equip the tool, and grab the player, your able to scan the other player's equipped tool...
Read more >
Enable and disable Auto-activation feature in Windows Vista
To disable the Auto-activation feature, follow these steps: Click Start, type regedit in the Start Search box, and then click regedit.exe in the...
Read more >
Activate and deactivate Adobe apps
Deactivation disconnects your app from your computer. You can then activate the apps on another computer or later reactivate them on the same ......
Read more >
Disable and suppress inspections | IntelliJ IDEA Documentation
In the Inspection Results tool window (after running code analysis), right-click the inspection you want to disable and select Disable ...
Read more >
Turn Restricted Mode on or off on YouTube - Google Support
Troubleshoot problems with turning off Restricted Mode ... The tool will assess whether an administrator set up these restrictions, or if they are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found