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

Fix/htj2k and keymodifier #313

Merged
merged 4 commits into from
Dec 1, 2022
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
16 changes: 15 additions & 1 deletion common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2606,9 +2606,23 @@ enum KeyboardBindings {
// (undocumented)
Alt = 18,
// (undocumented)
AltMeta = 1891,
// (undocumented)
Ctrl = 17,
// (undocumented)
Shift = 16
CtrlAlt = 1718,
// (undocumented)
CtrlMeta = 1791,
// (undocumented)
Meta = 91,
// (undocumented)
Shift = 16,
// (undocumented)
ShiftAlt = 1618,
// (undocumented)
ShiftCtrl = 1617,
// (undocumented)
ShiftMeta = 1691
}

// @public (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ function getTransferSyntaxForContentType(contentType: string): string {
'image/x-jls': '1.2.840.10008.1.2.4.80',
'image/jp2': '1.2.840.10008.1.2.4.90',
'image/jpx': '1.2.840.10008.1.2.4.92',
'image/jphc': '3.2.840.10008.1.2.4.96',
'image/jls': '1.2.840.10008.1.2.4.80',
};

if (params['transfer-syntax']) {
Expand Down
7 changes: 7 additions & 0 deletions packages/tools/src/enums/ToolBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ enum KeyboardBindings {
Shift = 16,
Ctrl = 17,
Alt = 18,
Meta = 91,
ShiftCtrl = 1617,
ShiftAlt = 1618,
ShiftMeta = 1691,
CtrlAlt = 1718,
CtrlMeta = 1791,
AltMeta = 1891,
}

export { MouseBindings, KeyboardBindings };
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ToolGroupManager } from '../../store';
import { MouseBindings, ToolModes } from '../../enums';
import { keyEventListener } from '../../eventListeners';
import { EventTypes } from '../../types';
import getMouseModifier from './getMouseModifier';

const { Active } = ToolModes;

Expand All @@ -22,7 +23,9 @@ export default function getActiveToolForMouseEvent(
const mouseEvent = evt.detail.event;

// If any keyboard modifier key is also pressed
const modifierKey = keyEventListener.getModifierKey();
// Use the actual key if set, otherwise get the key from the mouse event.
const modifierKey =
keyEventListener.getModifierKey() || getMouseModifier(mouseEvent);

const toolGroup = ToolGroupManager.getToolGroupForViewport(
viewportId,
Expand Down
30 changes: 30 additions & 0 deletions packages/tools/src/eventDispatchers/shared/getMouseModifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { KeyboardBindings as kb } from '../../enums';

/**
* Gets the mouse modifier key from a mouse event.
* Supports Shift, Ctrl, Alt, in singly and in combinations of 2
* Supports Meta singly.
*/
const getMouseModifierKey = (evt) => {
// The logic is a hard coded key mapping
if (evt.shiftKey) {
if (evt.ctrlKey) return kb.ShiftCtrl;
if (evt.altKey) return kb.ShiftAlt;
if (evt.metaKey) return kb.ShiftMeta;
return kb.Shift;
}
if (evt.ctrlKey) {
if (evt.altKey) return kb.CtrlAlt;
if (evt.metaKey) return kb.CtrlMeta;
return kb.Ctrl;
}
if (evt.altKey) {
return (evt.metaKey && kb.AltMeta) || kb.Alt;
}
if (evt.metaKey) {
kb.Meta;
}
return undefined;
};

export default getMouseModifierKey;
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ class SegmentationRenderingEngine {
const segmentationDisplayToolInstance = toolGroup.getToolInstance(
SegmentationDisplayTool.toolName
) as SegmentationDisplayTool;
if (!segmentationDisplayToolInstance) {
console.warn('No segmentation tool found inside', toolGroupId);
return;
}

function onSegmentationRender(evt: Types.EventTypes.ImageRenderedEvent) {
const { element, viewportId, renderingEngineId } = evt.detail;
Expand Down