import React from 'react'; import { PRECISION } from '../src/constants.js'; export default class SlicerViewer extends React.Component { state = { layer: 0, render: { renderIntersectionPoints: false, renderShape1: false, renderShape2: true, renderOuterLine: true, renderInnerLine: true, renderFill: true } }; changeSlider = (event) => { this.setState({ layer: parseInt(event.target.value) }); }; onControl = (event) => { const section = event.target.value; this.setState({ render: { ...this.state.render, [section]: !this.state.render[section] } }); }; render() { const { layer, render } = this.state; const { layerIntersectionPoints, settings, layerShapes, slices } = this.props; const numLayers = settings.dimensionsZ / settings.layerHeight; const intersectionPoints = layerIntersectionPoints[layer + 1]; const shape = layerShapes[layer]; const slice = slices[layer]; return (
{render.renderIntersectionPoints && intersectionPoints.map(({ x, y }, i) => ( ))} {render.renderShape1 && shape && shape.closedShapes.map((closedShape, i) => ( `${x} ${y}`).join(' ')} fill="rgba(255, 0, 0, 0.5)" /> ))} {slice && slice.parts.map((slicePart, i) => ( {render.renderShape2 && } {render.renderOuterLine && } {render.renderInnerLine && slicePart.innerLines.map((innerLine, i) => ( ))} {render.renderFill && } ))}

Layer: {layer}

); } } class ClipperShapeSVG extends React.Component { render() { const { shape, color = 'black', strokeWidth, scale, fill } = this.props; const data = shape.paths.map(path => { const pathData = path.map(({ X, Y }, i) => `${i === 0 ? 'M' : 'L '}${X * scale} ${Y * scale}`); if (shape.closed) pathData.push('Z'); return pathData.join(' '); }).join(' '); return ( ); } }