diff --git a/Packages/ohif-core/client/lib/cornerstone.js b/Packages/ohif-core/client/lib/cornerstone.js index dfba6b81c..216af4ad6 100644 --- a/Packages/ohif-core/client/lib/cornerstone.js +++ b/Packages/ohif-core/client/lib/cornerstone.js @@ -36,9 +36,16 @@ OHIF.cornerstone.repositionTextBox = (eventData, measurementData) => { const element = eventData.element; const enabledElement = cornerstone.getEnabledElement(element); - const $element = $(element); const image = enabledElement.image; + const allowedBorders = OHIF.uiSettings.autoPositionMeasurementsTextCallOuts; + const allow = { + T: !allowedBorders || _.contains(allowedBorders, 'T'), + R: !allowedBorders || _.contains(allowedBorders, 'R'), + B: !allowedBorders || _.contains(allowedBorders, 'B'), + L: !allowedBorders || _.contains(allowedBorders, 'L') + }; + const getAvailableBlankAreas = (enabledElement, labelWidth, labelHeight) => { const { element, canvas, image } = enabledElement; @@ -57,10 +64,10 @@ OHIF.cornerstone.repositionTextBox = (eventData, measurementData) => { const canvasHeight = $canvas.outerHeight(); const result = {}; - result['x-1'] = topLeft.x > labelWidth; - result['y-1'] = topLeft.y > labelHeight; - result.x1 = canvasWidth - bottomRight.x > labelWidth; - result.y1 = canvasHeight - bottomRight.y > labelHeight; + result['x-1'] = allow.L && (topLeft.x > labelWidth); + result['y-1'] = allow.T && (topLeft.y > labelHeight); + result.x1 = allow.R && (canvasWidth - bottomRight.x > labelWidth); + result.y1 = allow.B && (canvasHeight - bottomRight.y > labelHeight); return result; }; @@ -76,7 +83,25 @@ OHIF.cornerstone.repositionTextBox = (eventData, measurementData) => { const diffX = directions.x < 0 ? tool.x : limits.x - tool.x; const diffY = directions.y < 0 ? tool.y : limits.y - tool.y; - const cornerAxis = diffY < diffX ? 'y' : 'x'; + let cornerAxis = diffY < diffX ? 'y' : 'x'; + + const map = { + 'x-1': 'L', + 'y-1': 'T', + x1: 'R', + y1: 'B' + }; + + let current = 0; + while (current < 4 && !allow[map[cornerAxis + directions[cornerAxis]]]) { + // Invert the direction for the next iteration + directions[cornerAxis] *= -1; + + // Invert the tempCornerAxis + cornerAxis = cornerAxis === 'x' ? 'y' : 'x'; + + current++; + } return { directions, diff --git a/Packages/ohif-study-list/both/schema/servers.js b/Packages/ohif-study-list/both/schema/servers.js index bc503bd22..bc4bd2111 100644 --- a/Packages/ohif-study-list/both/schema/servers.js +++ b/Packages/ohif-study-list/both/schema/servers.js @@ -153,6 +153,11 @@ export const UISettings = new SimpleSchema({ type: Boolean, label: 'Enable cine dialog enhancements for multiframe images.', defaultValue: false + }, + autoPositionMeasurementsTextCallOuts: { + type: String, + label: 'Auto position text call-outs for measurements when creating them.', + defaultValue: 'TRBL' } }); diff --git a/config/orthancDICOMWeb.json b/config/orthancDICOMWeb.json index d112feea1..2f564a6ce 100644 --- a/config/orthancDICOMWeb.json +++ b/config/orthancDICOMWeb.json @@ -24,7 +24,8 @@ "studyListFunctionsEnabled": true, "leftSidebarOpen": false, "displaySetNavigationLoopOverSeries": false, - "displaySetNavigationMultipleViewports": true + "displaySetNavigationMultipleViewports": true, + "autoPositionMeasurementsTextCallOuts": "TRLB" } } }