* Filter segs and fetch correct metadata. * Initiate seg loading logic on series load into viewport. Need to write. * Automatic consumption of SEG functional. * Pull in master. * Fix issues after pulling in master. * Clean up old segmentation handlers. * WIP * WIP * Poppulate viewport with metadata. * Show hide/segmentation in react-vtkjs-viewport. * feat: 🎸 View segmentations in vtkjs viewport * Filter segs and fetch correct metadata. * Initiate seg loading logic on series load into viewport. Need to write. * Automatic consumption of SEG functional. * Pull in master. * Fix issues after pulling in master. * Clean up old segmentation handlers. * WIP * WIP * Poppulate viewport with metadata. * Show hide/segmentation in react-vtkjs-viewport. * feat: 🎸 View segmentations in vtkjs viewport * Rebase on master. * format format format * add basic extension parts * Updated yarn lock * Fetch derived/referenced displaysets in sidepanel * Add buttons, expose seriesDescription, write notes for Danny. * Add growcut tool extention. -> Move to a seperate repo. * Change some text fields. * expose dialog provider * hide draggable area * No pointer events for now; need to revisit * Don't filter seg from the outset for now * fiddling about * fix path to series data * fix logic to determine next available labelmapindex * Ability to swtich between labelmaps * Return a promise so we can make sure our labelmap is loaded before pulling metadata * Better UI to toggle labelmaps * Fix accidental untoggle of active labelmap for ui * Remove brush tool from cornerstone extension * Add cstools in preInit for seg extension * Add buttons for seg magic * Hide the measurements panel for now * Slightly better seg/scissor icons * Add eraser * ability to switch segments * seg color / switcher * Fix vtk labelmap cache. * sidepanel should scroll if there's overflow * Use a fancier range slider * Slightly prettier buttons * Push in progress * A bit more reactive; handle no-meta * Update to vtk.js 11.14.0 and react-vtkjs-viewport 0.6.0 * chore: kickstart preview * Fix conflict issues * Refactor panel * Isolate increment functions * Wip segment table * Hide selector and add scroll to segmentation * Increase width of segment description * Hide not used items * Add new select for segmentations * Align ui * Fix default segmentation * Fix broken import test * Get measurements panel back and add spacing to grouped buttons * Hide brush and selector and refresh when switching segmentations * Add pointer events back and fix broken tests for measurement table * Update segment list when switching humbnails * CR Update: Minor UI adjustments * CR Update: Set active segment * Move components to components folder * Add new settings ui * Integrate configuration * Improve styles * Float numbers * Improve css * Refresh settings menu if side panel changed * Fix settings rendering logic and remove comments * Extract components * Remove not used tools * Remove non used extension * Use style variables and remove comments * Remove non used dep from lock * Remove tools * Remove segmentation from toolbar * Add todo and brushradius from config * Fix packagejson growcut import * Remove webpack config already defined in parent * Update package json description * Change component name to british english to us * Improve prop types * Rename cornerstone label map event * Scope css * Extract and add doc to helper * Update jsdocs for getDerivedDatasets * Add proptypes and cr updates * Update tablistitem proptypes * config is readonly, rollback destructuring * Remove event for side panel * Add jsdocs for util * Extract getimageid to studymetada * Use ohif log instead of console * Remove specific style from side panel * Fix default props for brush radius * Descructure configuration props from settings component to avoid invalid props * Update proptypes to be required (settings) * Update readme * Remove commandsmodule * Get configuration module inside the component * Set selected segment * Rename extension and use modality to filter * Fix for failing tests (#1423) * hello world * Finish rebase for Igor. * Re-fix cornerstoneTools version that got messed up in merge. * Fix reactivity of isDisabled, write implementation for the SEG panel. * Nuke yarn.lock to stack CST to 4.12.0 * Remove debugger statements. * fix: bump cornerstone-tools version to address toFixed issue * test: force tests for MISTER^MR to navigate to study directly * test: remove eraser tool test * test: count is off by one * test: don't save SR state for the time being * test: disable more tests Co-authored-by: James A. Petts <jamesapetts@gmail.com> Co-authored-by: dannyrb <danny.ri.brown@gmail.com> Co-authored-by: igoroctaviano] <igoroctaviano@users.noreply.github.com> Co-authored-by: Mirna Silva <mirna.silva@radicalimaging.com>
366 lines
10 KiB
JavaScript
366 lines
10 KiB
JavaScript
import React, { Component } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { withTranslation } from 'react-i18next';
|
|
|
|
import { MODULE_TYPES } from '@ohif/core';
|
|
import {
|
|
ExpandableToolMenu,
|
|
RoundedButtonGroup,
|
|
ToolbarButton,
|
|
withModal,
|
|
withDialog,
|
|
} from '@ohif/ui';
|
|
|
|
import './ToolbarRow.css';
|
|
import { commandsManager, extensionManager } from './../App.js';
|
|
|
|
import ConnectedCineDialog from './ConnectedCineDialog';
|
|
import ConnectedLayoutButton from './ConnectedLayoutButton';
|
|
|
|
class ToolbarRow extends Component {
|
|
// TODO: Simplify these? isOpen can be computed if we say "any" value for selected,
|
|
// closed if selected is null/undefined
|
|
static propTypes = {
|
|
isLeftSidePanelOpen: PropTypes.bool.isRequired,
|
|
isRightSidePanelOpen: PropTypes.bool.isRequired,
|
|
selectedLeftSidePanel: PropTypes.string.isRequired,
|
|
selectedRightSidePanel: PropTypes.string.isRequired,
|
|
handleSidePanelChange: PropTypes.func.isRequired,
|
|
activeContexts: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
studies: PropTypes.array,
|
|
t: PropTypes.func.isRequired,
|
|
// NOTE: withDialog, withModal HOCs
|
|
dialog: PropTypes.any,
|
|
modal: PropTypes.any,
|
|
};
|
|
|
|
static defaultProps = {
|
|
studies: [],
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
const toolbarButtonDefinitions = _getVisibleToolbarButtons.call(this);
|
|
// TODO:
|
|
// If it's a tool that can be active... Mark it as active?
|
|
// - Tools that are on/off?
|
|
// - Tools that can be bound to multiple buttons?
|
|
|
|
// Normal ToolbarButtons...
|
|
// Just how high do we need to hoist this state?
|
|
// Why ToolbarRow instead of just Toolbar? Do we have any others?
|
|
this.state = {
|
|
toolbarButtons: toolbarButtonDefinitions,
|
|
activeButtons: [],
|
|
};
|
|
|
|
this.seriesPerStudyCount = [];
|
|
|
|
this._handleBuiltIn = _handleBuiltIn.bind(this);
|
|
|
|
this.updateButtonGroups();
|
|
}
|
|
|
|
updateButtonGroups() {
|
|
const panelModules = extensionManager.modules[MODULE_TYPES.PANEL];
|
|
|
|
this.buttonGroups = {
|
|
left: [],
|
|
right: [],
|
|
};
|
|
|
|
// ~ FIND MENU OPTIONS
|
|
panelModules.forEach(panelExtension => {
|
|
const panelModule = panelExtension.module;
|
|
const defaultContexts = Array.from(panelModule.defaultContext);
|
|
|
|
panelModule.menuOptions.forEach(menuOption => {
|
|
const contexts = Array.from(menuOption.context || defaultContexts);
|
|
const hasActiveContext = this.props.activeContexts.some(actx =>
|
|
contexts.includes(actx)
|
|
);
|
|
|
|
// It's a bit beefy to pass studies; probably only need to be reactive on `studyInstanceUIDs` and activeViewport?
|
|
// Note: This does not cleanly handle `studies` prop updating with panel open
|
|
const isDisabled =
|
|
typeof menuOption.isDisabled === 'function' &&
|
|
menuOption.isDisabled(this.props.studies);
|
|
|
|
if (hasActiveContext && !isDisabled) {
|
|
const menuOptionEntry = {
|
|
value: menuOption.target,
|
|
icon: menuOption.icon,
|
|
bottomLabel: menuOption.label,
|
|
};
|
|
const from = menuOption.from || 'right';
|
|
|
|
this.buttonGroups[from].push(menuOptionEntry);
|
|
}
|
|
});
|
|
});
|
|
|
|
// TODO: This should come from extensions, instead of being baked in
|
|
this.buttonGroups.left.unshift({
|
|
value: 'studies',
|
|
icon: 'th-large',
|
|
bottomLabel: this.props.t('Series'),
|
|
});
|
|
}
|
|
|
|
componentDidUpdate(prevProps) {
|
|
const activeContextsChanged =
|
|
prevProps.activeContexts !== this.props.activeContexts;
|
|
|
|
const prevStudies = prevProps.studies;
|
|
const studies = this.props.studies;
|
|
const seriesPerStudyCount = this.seriesPerStudyCount;
|
|
|
|
let studiesUpdated = false;
|
|
|
|
if (prevStudies.length !== studies.length) {
|
|
studiesUpdated = true;
|
|
} else {
|
|
for (let i = 0; i < studies.length; i++) {
|
|
if (studies[i].series.length !== seriesPerStudyCount[i]) {
|
|
seriesPerStudyCount[i] = studies[i].series.length;
|
|
|
|
studiesUpdated = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (studiesUpdated) {
|
|
this.updateButtonGroups();
|
|
}
|
|
|
|
if (activeContextsChanged) {
|
|
this.setState({
|
|
toolbarButtons: _getVisibleToolbarButtons.call(this),
|
|
});
|
|
}
|
|
}
|
|
|
|
render() {
|
|
const buttonComponents = _getButtonComponents.call(
|
|
this,
|
|
this.state.toolbarButtons,
|
|
this.state.activeButtons
|
|
);
|
|
|
|
const onPress = (side, value) => {
|
|
this.props.handleSidePanelChange(side, value);
|
|
};
|
|
const onPressLeft = onPress.bind(this, 'left');
|
|
const onPressRight = onPress.bind(this, 'right');
|
|
|
|
return (
|
|
<>
|
|
<div className="ToolbarRow">
|
|
<div className="pull-left m-t-1 p-y-1" style={{ padding: '10px' }}>
|
|
<RoundedButtonGroup
|
|
options={this.buttonGroups.left}
|
|
value={this.props.selectedLeftSidePanel || ''}
|
|
onValueChanged={onPressLeft}
|
|
/>
|
|
</div>
|
|
{buttonComponents}
|
|
<ConnectedLayoutButton />
|
|
<div
|
|
className="pull-right m-t-1 rm-x-1"
|
|
style={{ marginLeft: 'auto' }}
|
|
>
|
|
{this.buttonGroups.right.length && (
|
|
<RoundedButtonGroup
|
|
options={this.buttonGroups.right}
|
|
value={this.props.selectedRightSidePanel || ''}
|
|
onValueChanged={onPressRight}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
}
|
|
|
|
function _getCustomButtonComponent(button, activeButtons) {
|
|
const CustomComponent = button.CustomComponent;
|
|
const isValidComponent = typeof CustomComponent === 'function';
|
|
|
|
// Check if its a valid customComponent. Later on an CustomToolbarComponent interface could be implemented.
|
|
if (isValidComponent) {
|
|
const parentContext = this;
|
|
const activeButtonsIds = activeButtons.map(button => button.id);
|
|
const isActive = activeButtonsIds.includes(button.id);
|
|
|
|
return (
|
|
<CustomComponent
|
|
parentContext={parentContext}
|
|
toolbarClickCallback={_handleToolbarButtonClick.bind(this)}
|
|
button={button}
|
|
key={button.id}
|
|
activeButtons={activeButtonsIds}
|
|
isActive={isActive}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
function _getExpandableButtonComponent(button, activeButtons) {
|
|
// Iterate over button definitions and update `onClick` behavior
|
|
let activeCommand;
|
|
const childButtons = button.buttons.map(childButton => {
|
|
childButton.onClick = _handleToolbarButtonClick.bind(this, childButton);
|
|
|
|
if (activeButtons.map(button => button.id).indexOf(childButton.id) > -1) {
|
|
activeCommand = childButton.id;
|
|
}
|
|
|
|
return childButton;
|
|
});
|
|
|
|
return (
|
|
<ExpandableToolMenu
|
|
key={button.id}
|
|
label={button.label}
|
|
icon={button.icon}
|
|
buttons={childButtons}
|
|
activeCommand={activeCommand}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function _getDefaultButtonComponent(button, activeButtons) {
|
|
return (
|
|
<ToolbarButton
|
|
key={button.id}
|
|
label={button.label}
|
|
icon={button.icon}
|
|
onClick={_handleToolbarButtonClick.bind(this, button)}
|
|
isActive={activeButtons.map(button => button.id).includes(button.id)}
|
|
/>
|
|
);
|
|
}
|
|
/**
|
|
* Determine which extension buttons should be showing, if they're
|
|
* active, and what their onClick behavior should be.
|
|
*/
|
|
function _getButtonComponents(toolbarButtons, activeButtons) {
|
|
const _this = this;
|
|
return toolbarButtons.map(button => {
|
|
const hasCustomComponent = button.CustomComponent;
|
|
const hasNestedButtonDefinitions = button.buttons && button.buttons.length;
|
|
|
|
if (hasCustomComponent) {
|
|
return _getCustomButtonComponent.call(_this, button, activeButtons);
|
|
}
|
|
|
|
if (hasNestedButtonDefinitions) {
|
|
return _getExpandableButtonComponent.call(_this, button, activeButtons);
|
|
}
|
|
|
|
return _getDefaultButtonComponent.call(_this, button, activeButtons);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* TODO: DEPRECATE
|
|
* This is used exclusively in `extensions/cornerstone/src`
|
|
* We have better ways with new UI Services to trigger "builtin" behaviors
|
|
*
|
|
* A handy way for us to handle different button types. IE. firing commands for
|
|
* buttons, or initiation built in behavior.
|
|
*
|
|
* @param {*} button
|
|
* @param {*} evt
|
|
* @param {*} props
|
|
*/
|
|
function _handleToolbarButtonClick(button, evt, props) {
|
|
const { activeButtons } = this.state;
|
|
|
|
if (button.commandName) {
|
|
const options = Object.assign({ evt }, button.commandOptions);
|
|
commandsManager.runCommand(button.commandName, options);
|
|
}
|
|
|
|
// TODO: Use Types ENUM
|
|
// TODO: We can update this to be a `getter` on the extension to query
|
|
// For the active tools after we apply our updates?
|
|
if (button.type === 'setToolActive') {
|
|
const toggables = activeButtons.filter(
|
|
({ options }) => options && !options.togglable
|
|
);
|
|
this.setState({ activeButtons: [...toggables, button] });
|
|
} else if (button.type === 'builtIn') {
|
|
this._handleBuiltIn(button);
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
function _getVisibleToolbarButtons() {
|
|
const toolbarModules = extensionManager.modules[MODULE_TYPES.TOOLBAR];
|
|
const toolbarButtonDefinitions = [];
|
|
|
|
toolbarModules.forEach(extension => {
|
|
const { definitions, defaultContext } = extension.module;
|
|
definitions.forEach(definition => {
|
|
const context = definition.context || defaultContext;
|
|
|
|
if (this.props.activeContexts.includes(context)) {
|
|
toolbarButtonDefinitions.push(definition);
|
|
}
|
|
});
|
|
});
|
|
|
|
return toolbarButtonDefinitions;
|
|
}
|
|
|
|
function _handleBuiltIn(button) {
|
|
/* TODO: Keep cine button active until its unselected. */
|
|
const { dialog, t } = this.props;
|
|
const { dialogId } = this.state;
|
|
const { id, options } = button;
|
|
|
|
if (options.behavior === 'CINE') {
|
|
if (dialogId) {
|
|
dialog.dismiss({ id: dialogId });
|
|
this.setState(state => ({
|
|
dialogId: null,
|
|
activeButtons: [
|
|
...state.activeButtons.filter(button => button.id !== id),
|
|
],
|
|
}));
|
|
} else {
|
|
const spacing = 20;
|
|
const { x, y } = document
|
|
.querySelector(`.ViewerMain`)
|
|
.getBoundingClientRect();
|
|
const newDialogId = dialog.create({
|
|
content: ConnectedCineDialog,
|
|
defaultPosition: {
|
|
x: x + spacing || 0,
|
|
y: y + spacing || 0,
|
|
},
|
|
});
|
|
this.setState(state => ({
|
|
dialogId: newDialogId,
|
|
activeButtons: [...state.activeButtons, button],
|
|
}));
|
|
}
|
|
}
|
|
|
|
if (options.behavior === 'DOWNLOAD_SCREEN_SHOT') {
|
|
commandsManager.runCommand('showDownloadViewportModal', {
|
|
title: t('Download High Quality Image'),
|
|
});
|
|
}
|
|
}
|
|
|
|
export default withTranslation(['Common', 'ViewportDownloadForm'])(
|
|
withModal(withDialog(ToolbarRow))
|
|
);
|