Skip to content
Snippets Groups Projects
Commit 330c488b authored by Jack Reed's avatar Jack Reed
Browse files

Add cursor tool and enable multi-polygon annos

parent 6e46543f
No related branches found
No related tags found
No related merge requests found
...@@ -13,19 +13,22 @@ import FormatColorFillIcon from '@material-ui/icons/FormatColorFill'; ...@@ -13,19 +13,22 @@ import FormatColorFillIcon from '@material-ui/icons/FormatColorFill';
import StrokeColorIcon from '@material-ui/icons/BorderColor'; import StrokeColorIcon from '@material-ui/icons/BorderColor';
import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
import Popover from '@material-ui/core/Popover'; import Popover from '@material-ui/core/Popover';
import Divider from '@material-ui/core/Divider';
import { SketchPicker } from 'react-color'; import { SketchPicker } from 'react-color';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import { withStyles } from '@material-ui/core/styles'; import { withStyles } from '@material-ui/core/styles';
import AnnotationDrawing from './AnnotationDrawing'; import AnnotationDrawing from './AnnotationDrawing';
import TextEditor from './TextEditor'; import TextEditor from './TextEditor';
import WebAnnotation from './WebAnnotation'; import WebAnnotation from './WebAnnotation';
import CursorIcon from './icons/Cursor';
/** */ /** */
class AnnotationCreation extends Component { class AnnotationCreation extends Component {
/** */ /** */
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
activeTool: null, activeTool: 'cursor',
annoBody: '', annoBody: '',
colorPopoverOpen: false, colorPopoverOpen: false,
currentColorType: false, currentColorType: false,
...@@ -123,7 +126,6 @@ class AnnotationCreation extends Component { ...@@ -123,7 +126,6 @@ class AnnotationCreation extends Component {
} = this.state; } = this.state;
return ( return (
<Paper className={classes.root}> <Paper className={classes.root}>
{ activeTool && (
<AnnotationDrawing <AnnotationDrawing
activeTool={activeTool} activeTool={activeTool}
fillColor={fillColor} fillColor={fillColor}
...@@ -131,7 +133,6 @@ class AnnotationCreation extends Component { ...@@ -131,7 +133,6 @@ class AnnotationCreation extends Component {
updateGeometry={this.updateGeometry} updateGeometry={this.updateGeometry}
windowId={windowId} windowId={windowId}
/> />
)}
<form onSubmit={this.submitForm}> <form onSubmit={this.submitForm}>
<Grid container> <Grid container>
<Grid item xs={12}> <Grid item xs={12}>
...@@ -140,7 +141,22 @@ class AnnotationCreation extends Component { ...@@ -140,7 +141,22 @@ class AnnotationCreation extends Component {
</Typography> </Typography>
</Grid> </Grid>
<Grid item xs={12}> <Grid item xs={12}>
<Paper elevation={0} className={classes.paper}>
<ToggleButtonGroup
className={classes.grouped}
value={activeTool}
exclusive
onChange={this.changeTool}
aria-label="tool selection"
size="small"
>
<ToggleButton value="cursor" aria-label="select cursor">
<CursorIcon />
</ToggleButton>
</ToggleButtonGroup>
<Divider flexItem orientation="vertical" className={classes.divider} />
<ToggleButtonGroup <ToggleButtonGroup
className={classes.grouped}
value={activeTool} value={activeTool}
exclusive exclusive
onChange={this.changeTool} onChange={this.changeTool}
...@@ -157,6 +173,7 @@ class AnnotationCreation extends Component { ...@@ -157,6 +173,7 @@ class AnnotationCreation extends Component {
<PolygonIcon /> <PolygonIcon />
</ToggleButton> </ToggleButton>
</ToggleButtonGroup> </ToggleButtonGroup>
</Paper>
</Grid> </Grid>
</Grid> </Grid>
<Grid container> <Grid container>
...@@ -226,6 +243,23 @@ class AnnotationCreation extends Component { ...@@ -226,6 +243,23 @@ class AnnotationCreation extends Component {
/** */ /** */
const styles = (theme) => ({ const styles = (theme) => ({
divider: {
margin: theme.spacing(1, 0.5),
},
grouped: {
'&:first-child': {
borderRadius: theme.shape.borderRadius,
},
'&:not(:first-child)': {
borderRadius: theme.shape.borderRadius,
},
border: 'none',
margin: theme.spacing(0.5),
},
paper: {
display: 'flex',
flexWrap: 'wrap',
},
root: { root: {
padding: theme.spacing(1), padding: theme.spacing(1),
}, },
...@@ -235,9 +269,7 @@ AnnotationCreation.propTypes = { ...@@ -235,9 +269,7 @@ AnnotationCreation.propTypes = {
canvases: PropTypes.arrayOf( canvases: PropTypes.arrayOf(
PropTypes.shape({ id: PropTypes.string, index: PropTypes.number }), PropTypes.shape({ id: PropTypes.string, index: PropTypes.number }),
), ),
classes: PropTypes.shape({ classes: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
root: PropTypes.string,
}).isRequired,
config: PropTypes.shape({ config: PropTypes.shape({
annotation: PropTypes.shape({ annotation: PropTypes.shape({
adapter: PropTypes.func, adapter: PropTypes.func,
......
...@@ -24,17 +24,16 @@ class AnnotationDrawing extends Component { ...@@ -24,17 +24,16 @@ class AnnotationDrawing extends Component {
/** */ /** */
addPath(path) { addPath(path) {
const { strokeWidth, updateGeometry } = this.props; const { strokeWidth, updateGeometry } = this.props;
// TODO: Compute xywh of bounding container of layers
const { bounds } = path; const { bounds } = path;
const { const {
x, y, width, height, x, y, width, height,
} = bounds; } = bounds;
// Reset strokeWidth for persistence // Reset strokeWidth for persistence
const pathClone = path.clone(); path.strokeWidth = strokeWidth; // eslint-disable-line no-param-reassign
pathClone.strokeWidth = strokeWidth; // eslint-disable-line no-param-reassign
updateGeometry({ updateGeometry({
svg: pathClone.exportSVG({ svg: path.project.exportSVG({
asString: true, asString: true,
}), }),
xywh: [ xywh: [
...@@ -52,7 +51,7 @@ class AnnotationDrawing extends Component { ...@@ -52,7 +51,7 @@ class AnnotationDrawing extends Component {
const { const {
activeTool, fillColor, strokeColor, strokeWidth, activeTool, fillColor, strokeColor, strokeWidth,
} = this.props; } = this.props;
if (!activeTool) return null; if (!activeTool || activeTool === 'cursor') return null;
// Setup Paper View to have the same center and zoom as the OSD Viewport // Setup Paper View to have the same center and zoom as the OSD Viewport
const viewportZoom = this.OSDReference.viewer.viewport.getZoom(true); const viewportZoom = this.OSDReference.viewer.viewport.getZoom(true);
const image1 = this.OSDReference.viewer.world.getItemAt(0); const image1 = this.OSDReference.viewer.world.getItemAt(0);
......
import React from 'react';
import SvgIcon from '@material-ui/core/SvgIcon';
/**
* CursorIcon ~
*/
export default function CursorIcon(props) {
return (
// eslint-disable-next-line react/jsx-props-no-spreading
<SvgIcon {...props}>
<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
x="0px"
y="0px"
viewBox="1064.7701 445.5539 419.8101 717.0565"
enableBackground="new 1064.7701 445.5539 419.8101 717.0565"
xmlSpace="preserve"
>
<polygon fill="#231F20" points="1283.1857,1127.3097 1406.1421,1077.6322 1314.2406,850.1678 1463.913,852.7823 1093.4828,480.8547 1085.4374,1005.6964 1191.2842,899.8454 " />
</svg>
</SvgIcon>
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment