OHIF with Cornerstone3D 2.0 (#4347)
This commit is contained in:
1 parent
8981a61b8c
commit
7ce7127d7c
803 files changed
+32760
-15893
No files matched your search
@@ -93,6 +93,9 @@ export default function CineProvider({ children, service }) {
|
||||
setIsCineEnabled: isCineEnabled => service.setIsCineEnabled(isCineEnabled),
|
||||
playClip: (element, playClipOptions) => service.playClip(element, playClipOptions),
|
||||
stopClip: (element, stopClipOptions) => service.stopClip(element, stopClipOptions),
|
||||
setViewportCineClosed: viewportId => service.setViewportCineClosed(viewportId),
|
||||
clearViewportCineClosed: viewportId => service.clearViewportCineClosed(viewportId),
|
||||
isViewportCineClosed: viewportId => service.isViewportCineClosed(viewportId),
|
||||
};
|
||||
|
||||
return <CineContext.Provider value={[state, api]}>{children}</CineContext.Provider>;
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import React, { useState, createContext, useContext, useCallback, useEffect, useRef } from 'react';
|
||||
import React, {
|
||||
useState,
|
||||
createContext,
|
||||
useContext,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useMemo,
|
||||
} from 'react';
|
||||
|
||||
import PropTypes from 'prop-types';
|
||||
import Draggable from 'react-draggable';
|
||||
@@ -268,8 +276,13 @@ const DialogProvider = ({ children, service = null }) => {
|
||||
|
||||
const validCallback = callback => callback && typeof callback === 'function';
|
||||
|
||||
const contextValue = useMemo(
|
||||
() => ({ create, dismiss, dismissAll, isEmpty }),
|
||||
[create, dismiss, dismissAll, isEmpty]
|
||||
);
|
||||
|
||||
return (
|
||||
<DialogContext.Provider value={{ create, dismiss, dismissAll, isEmpty }}>
|
||||
<DialogContext.Provider value={contextValue}>
|
||||
{!isEmpty() && (
|
||||
<div
|
||||
className="absolute h-full w-full"
|
||||
|
||||
@@ -2,7 +2,6 @@ export function toolboxReducer(state, action) {
|
||||
let newState = { ...state };
|
||||
|
||||
const { payload } = action;
|
||||
const { stateSyncService, buttonSectionId } = payload || {};
|
||||
|
||||
switch (action.type) {
|
||||
case 'SET_ACTIVE_TOOL':
|
||||
@@ -49,18 +48,5 @@ export function toolboxReducer(state, action) {
|
||||
break;
|
||||
}
|
||||
|
||||
// store the state in the stateSyncService
|
||||
if (payload?.stateSyncService) {
|
||||
const prevState = stateSyncService.getState()?.['uiStateStore']?.[buttonSectionId];
|
||||
stateSyncService.store({
|
||||
uiStateStore: {
|
||||
...stateSyncService.getState()?.['uiStateStore'],
|
||||
[buttonSectionId]: {
|
||||
...prevState,
|
||||
...newState,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
return newState;
|
||||
}
|
||||
@@ -1,38 +1,18 @@
|
||||
import React, { createContext, useCallback, useContext, useEffect, useReducer } from 'react';
|
||||
import React, {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useReducer,
|
||||
ReactNode,
|
||||
} from 'react';
|
||||
import merge from 'lodash.merge';
|
||||
|
||||
import PropTypes from 'prop-types';
|
||||
import { ViewportGridService, utils } from '@ohif/core';
|
||||
import viewportLabels from '../utils/viewportLabels';
|
||||
|
||||
interface Viewport {
|
||||
viewportId: string;
|
||||
displaySetInstanceUIDs: string[];
|
||||
viewportOptions: any;
|
||||
displaySetSelectors: any[];
|
||||
displaySetOptions: any[];
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
viewportLabel: any;
|
||||
isReady: boolean;
|
||||
}
|
||||
|
||||
interface Layout {
|
||||
numRows: number;
|
||||
numCols: number;
|
||||
layoutType: string;
|
||||
}
|
||||
|
||||
interface DefaultState {
|
||||
activeViewportId: string | null;
|
||||
layout: Layout;
|
||||
isHangingProtocolLayout: boolean;
|
||||
viewports: Map<string, Viewport>;
|
||||
}
|
||||
|
||||
const DEFAULT_STATE: DefaultState = {
|
||||
const DEFAULT_STATE: AppTypes.ViewportGrid.State = {
|
||||
activeViewportId: null,
|
||||
layout: {
|
||||
numRows: 0,
|
||||
@@ -78,7 +58,10 @@ const getViewportLabel = (viewports, viewportId) => {
|
||||
return viewportLabels[viewportIds.indexOf(viewportId)];
|
||||
};
|
||||
|
||||
const determineActiveViewportId = (state: DefaultState, newViewports: Map) => {
|
||||
const determineActiveViewportId = (
|
||||
state: AppTypes.ViewportGrid.State,
|
||||
newViewports: Map<string, AppTypes.ViewportGrid.Viewport>
|
||||
) => {
|
||||
const { activeViewportId } = state;
|
||||
const currentActiveViewport = state.viewports.get(activeViewportId);
|
||||
|
||||
@@ -132,10 +115,37 @@ const determineActiveViewportId = (state: DefaultState, newViewports: Map) => {
|
||||
return sortedViewports[0].viewportId;
|
||||
};
|
||||
|
||||
export const ViewportGridContext = createContext(DEFAULT_STATE);
|
||||
// Define the API interface
|
||||
interface ViewportGridApi {
|
||||
getState: () => AppTypes.ViewportGrid.State;
|
||||
setActiveViewportId: (index: string) => void;
|
||||
setDisplaySetsForViewport: (props: any) => void;
|
||||
setDisplaySetsForViewports: (props: any[]) => void;
|
||||
setLayout: (layout: AppTypes.ViewportGrid.Layout) => void;
|
||||
reset: () => void;
|
||||
set: (gridLayoutState: Partial<AppTypes.ViewportGrid.State>) => void;
|
||||
getNumViewportPanes: () => number;
|
||||
setViewportIsReady: (viewportId: string, isReady: boolean) => void;
|
||||
getGridViewportsReady: () => boolean;
|
||||
getActiveViewportOptionByKey: (key: string) => any;
|
||||
setViewportGridSizeChanged: (props: any) => void;
|
||||
publishViewportsReady: () => void;
|
||||
}
|
||||
|
||||
export function ViewportGridProvider({ children, service }) {
|
||||
const viewportGridReducer = (state: DefaultState, action) => {
|
||||
// Update the context type
|
||||
export const ViewportGridContext = createContext<[AppTypes.ViewportGrid.State, ViewportGridApi]>([
|
||||
DEFAULT_STATE,
|
||||
{} as ViewportGridApi,
|
||||
]);
|
||||
|
||||
// Update the provider props type
|
||||
interface ViewportGridProviderProps {
|
||||
children: ReactNode;
|
||||
service: ViewportGridService;
|
||||
}
|
||||
|
||||
export function ViewportGridProvider({ children, service }: ViewportGridProviderProps) {
|
||||
const viewportGridReducer = (state: AppTypes.ViewportGrid.State, action) => {
|
||||
switch (action.type) {
|
||||
case 'SET_ACTIVE_VIEWPORT_ID': {
|
||||
return { ...state, ...{ activeViewportId: action.payload } };
|
||||
@@ -207,10 +217,10 @@ export function ViewportGridProvider({ children, service }) {
|
||||
// viewportLabel: getViewportLabel(viewports, viewportId),
|
||||
};
|
||||
|
||||
viewportOptions.presentationIds = ViewportGridService.getPresentationIds(
|
||||
newViewport,
|
||||
viewports
|
||||
);
|
||||
viewportOptions.presentationIds = service.getPresentationIds({
|
||||
viewport: newViewport,
|
||||
viewports,
|
||||
});
|
||||
|
||||
viewports.set(viewportId, {
|
||||
...viewports.get(viewportId),
|
||||
@@ -233,7 +243,7 @@ export function ViewportGridProvider({ children, service }) {
|
||||
|
||||
// If empty viewportOptions, we use numRow and numCols to calculate number of viewports
|
||||
const hasOptions = layoutOptions?.length;
|
||||
const viewports = new Map<string, Viewport>();
|
||||
const viewports = new Map<string, AppTypes.ViewportGrid.Viewport>();
|
||||
// Options is a temporary state store which can be used by the
|
||||
// findOrCreate to store state about already found viewports. Typically,
|
||||
// it will be used to store the display set UID's which are already
|
||||
@@ -298,10 +308,11 @@ export function ViewportGridProvider({ children, service }) {
|
||||
viewport.isReady = false;
|
||||
|
||||
if (!viewport.viewportOptions.presentationIds) {
|
||||
viewport.viewportOptions.presentationIds = ViewportGridService.getPresentationIds(
|
||||
const presentationIds = service.getPresentationIds({
|
||||
viewport,
|
||||
viewports
|
||||
);
|
||||
viewports,
|
||||
});
|
||||
viewport.viewportOptions.presentationIds = presentationIds;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -513,4 +524,6 @@ ViewportGridProvider.propTypes = {
|
||||
service: PropTypes.instanceOf(ViewportGridService).isRequired,
|
||||
};
|
||||
|
||||
export const useViewportGrid = () => useContext(ViewportGridContext);
|
||||
// Update the useViewportGrid hook
|
||||
export const useViewportGrid = (): [AppTypes.ViewportGrid.State, ViewportGridApi] =>
|
||||
useContext(ViewportGridContext);
|
||||
Reference in new issue
Block a user