Skip to content

Commit

Permalink
fix: htj2k and keymodifier (#313)
Browse files Browse the repository at this point in the history
* fix(htj2k):Support htj2k in the streaming volume loader

* fix(decodeImage):Fix htj2k image decode and mouse key modifiers

* Update for PR

* update ci build
  • Loading branch information
wayfarer3130 authored Dec 1, 2022
1 parent e68f064 commit 48bd8a1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
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

0 comments on commit 48bd8a1

Please sign in to comment.