Skip to content

Commit

Permalink
fix(CellEditor): Better radius/material UI, paired inputs
Browse files Browse the repository at this point in the history
With add and delete button for pairs.

Fix save of .inp when there are no coremaps.
  • Loading branch information
aronhelser committed Apr 19, 2018
1 parent 44fba35 commit 87010cd
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 52 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 31 additions & 28 deletions src/utils/InpHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,36 +176,39 @@ function writeToInp(state, GROUP_TYPES) {
if (cell !== '-') coreShapeMap[i] = 1;
});
});
const coreShape = {
type: 'coremaps',
symmetry: 'none',
cell_map: coreShapeMap,
};
const coreText = getTextMap(coreShape, state.params);
result.push('\n core_shape');
coreText.split('\n').forEach((line) => {
result.push(` ${line}`);
});

// get symmetry text maps for comparison with assemblies.
const coreMaps = {
none: coreText,
oct: (coreShape.symmetry = 'oct') && getTextMap(coreShape, state.params),
quad: (coreShape.symmetry = 'quad') && getTextMap(coreShape, state.params),
};
GROUP_TYPES.forEach((info) => {
const mapList = state.coremaps.filter((a) => a.group === info.group);
if (!mapList.length) return;
const assemMap = mapList[0];
result.push(`\n ${info.coremap}`);
setSymmetry(assemMap, state.params);
let textMap = getTextMap(assemMap, state.params);
// strips locations that are '0' in coreShape map.
textMap = stripCoreZeros(textMap, coreMaps[assemMap.symmetry]);
textMap.split('\n').forEach((line) => {
if (coreShapeMap) {
const coreShape = {
type: 'coremaps',
symmetry: 'none',
cell_map: coreShapeMap,
};
const coreText = getTextMap(coreShape, state.params);
result.push('\n core_shape');
coreText.split('\n').forEach((line) => {
result.push(` ${line}`);
});
});

// get symmetry text maps for comparison with assemblies.
const coreMaps = {
none: coreText,
oct: (coreShape.symmetry = 'oct') && getTextMap(coreShape, state.params),
quad:
(coreShape.symmetry = 'quad') && getTextMap(coreShape, state.params),
};
GROUP_TYPES.forEach((info) => {
const mapList = state.coremaps.filter((a) => a.group === info.group);
if (!mapList.length) return;
const assemMap = mapList[0];
result.push(`\n ${info.coremap}`);
setSymmetry(assemMap, state.params);
let textMap = getTextMap(assemMap, state.params);
// strips locations that are '0' in coreShape map.
textMap = stripCoreZeros(textMap, coreMaps[assemMap.symmetry]);
textMap.split('\n').forEach((line) => {
result.push(` ${line}`);
});
});
}

GROUP_TYPES.forEach((info) => {
const isAssembly = info.label === 'Assembly';
Expand Down
96 changes: 75 additions & 21 deletions src/widgets/CellEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
// import ReactCursorPosition from 'react-cursor-position';

import { Form, Input, Button, Select, Row, Col } from 'antd';
import { Form, Input, InputNumber, Button, Select, Row, Col } from 'antd';

// import macro from 'vtk.js/Sources/macro';
import DualRenderer from './DualRenderer';
Expand Down Expand Up @@ -56,7 +56,9 @@ export default class CellEditor extends React.Component {

this.onFieldUpdate = this.onFieldUpdate.bind(this);
this.addNew = this.addNew.bind(this);
this.onRadiiUpdate = this.onRadiiUpdate.bind(this);
// this.onRadiiUpdate = this.onRadiiUpdate.bind(this);
this.onRadiiAdd = this.onRadiiAdd.bind(this);
this.onRadiiDelete = this.onRadiiDelete.bind(this);
this.onMaterialUpdate = this.onMaterialUpdate.bind(this);
this.update3D = this.update3D.bind(this);
}
Expand All @@ -78,11 +80,17 @@ export default class CellEditor extends React.Component {
this.update3D();
}

onRadiiUpdate(e) {
const radii = e.target.value
.split(/[,\s]+/)
.map((s) => s.trim())
.map((s) => Number(s));
onRadiiUpdate(id, value) {
// const id = e.target.dataset.id;
// const newRadii = e.target.value
// .split(/[,\s]+/)
// .map((s) => s.trim())
// .map((s) => Number(s));
const radii = [].concat(this.props.content.radii);

// radii.splice(id, 1, ...newRadii);
radii[id] = value;
console.log(radii);
const numRings = radii.length;
const mats = [].concat(this.props.content.mats);
if (numRings > 0 && mats.length === 0) {
Expand All @@ -94,13 +102,32 @@ export default class CellEditor extends React.Component {
while (mats.length > numRings) {
mats.pop();
}
this.props.content.radiiStr = e.target.value;
// this.props.content.radiiStr = e.target.value;
this.props.content.radii = radii;
this.props.content.num_rings = numRings;
this.props.content.mats = mats;
this.update3D();
}

onRadiiAdd(e) {
const id = e.target.dataset.id;
this.props.content.radii.splice(id, 0, this.props.content.radii[id]);
console.log(id, this.props.content.radii);
this.props.content.mats.splice(id, 0, this.props.content.mats[id]);
this.props.content.num_rings += 1;
this.update3D();
}
onRadiiDelete(e) {
const id = e.target.dataset.id;
if (this.props.content.num_rings > 1) {
this.props.content.radii.splice(id, 1);
console.log(id, this.props.content.radii);
this.props.content.mats.splice(id, 1);
this.props.content.num_rings -= 1;
this.update3D();
}
}

onMaterialUpdate(value) {
const [idx, name] = value.split('::');
this.props.content.mats[Number(idx)] = name;
Expand Down Expand Up @@ -131,7 +158,7 @@ export default class CellEditor extends React.Component {
}

render() {
/* eslint-disable react/no-array-index-key */
/* eslint-disable react/no-array-index-key, react/jsx-no-bind */
return (
<div className={style.form}>
<Button
Expand All @@ -157,21 +184,48 @@ export default class CellEditor extends React.Component {
/>
</FormItem>
<FormItem
label="Radii"
labelCol={{ span: 4 }}
wrapperCol={{ span: 20 }}
>
<Input
defaultValue={this.props.content.radii}
data-id="radii"
onChange={this.onRadiiUpdate}
/>
</FormItem>
<FormItem
label="Materials"
label="Radii & Materials"
labelCol={{ span: 4 }}
wrapperCol={{ span: 20 }}
>
<Row>
{this.props.content.radii.map((m, idx) => (
<Col span={3} key={`rad-${idx.toString(16)}`}>
<InputNumber
value={this.props.content.radii[idx]}
step={0.02}
data-id={idx}
size="100%"
style={{ width: '100%' }}
onChange={this.onRadiiUpdate.bind(this, idx)}
/>
</Col>
))}
</Row>
<Row>
{this.props.content.mats.map((m, idx) => (
<Col span={3} key={`add-${idx.toString(16)}`}>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Button
shape="circle"
icon="plus"
data-id={idx}
className={style.cellNewRing}
onClick={this.onRadiiAdd}
/>
{this.props.content.num_rings > 1 && (
<Button
shape="circle"
icon="delete"
data-id={idx}
className={style.cellNewRing}
onClick={this.onRadiiDelete}
/>
)}
</div>
</Col>
))}
</Row>
<Row>
{this.props.content.mats.map((m, idx) => (
<Col span={3} key={`mat-${idx.toString(16)}`}>
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/ImageRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class ImageRenderer extends React.Component {
elementDimensions: { width = 0, height = 0 } = {},
position: { x = 0, y = 0 } = {},
} = this.props;
// console.log(x, y);

// pass position as 0 -> 1
const posx = (x - this.props.pad) / (width - 2 * this.props.pad);
Expand All @@ -48,6 +49,7 @@ export default class ImageRenderer extends React.Component {
delayShow={50}
scrollHide
getContent={this.getTooltip}
isCapture
ref={(c) => {
this.tooltipRef = c;
}}
Expand Down

0 comments on commit 87010cd

Please sign in to comment.