Skip to content

Commit

Permalink
Merge pull request #8 from CASL/core_maps_read
Browse files Browse the repository at this point in the history
Core maps read/write
  • Loading branch information
aronhelser authored Apr 19, 2018
2 parents 55ab2de + 92a8dd6 commit 674a353
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 109 deletions.
5 changes: 4 additions & 1 deletion Documentation/content/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ ul#intro-feature-list(style="position:relative;margin-top:0;padding-top:0;")
VeraInView is a standalone Web application that visualizes the geometry from VERAin simulation input files. The 
a(href="users_guide/").link user's guide
span.
 can get you started.
 can get you started. Sample files can be found in the 
a(href="https://github.com/CASL/VERAin/tree/master/verain/Progression_Problems/GOLD") VERAin testing
span.
 folder.

li.intro-feature-wrap
.intro-feature
Expand Down
120 changes: 68 additions & 52 deletions src/EditView.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ const TEMPLATES = {
};

const GROUP_TYPES = [
{ label: 'Assembly', group: 'assemblies' },
{ label: 'Insert', group: 'inserts' },
{ label: 'Control', group: 'controls' },
{ label: 'Detector', group: 'detectors' },
{ label: 'Assembly', group: 'assemblies', coremap: 'assm_map' },
{ label: 'Insert', group: 'inserts', coremap: 'insert_map' },
{ label: 'Control', group: 'controls', coremap: 'crd_map' },
{ label: 'Detector', group: 'detectors', coremap: 'det_map' },
];

// todo get from vtk-js
Expand Down Expand Up @@ -211,13 +211,15 @@ export default class EditView extends React.Component {

onMenuNew(type, group) {
// create a new item based on the currently selected one.
// state.content holds the current item.
// state.content holds the current item. Might be null for coremaps.
const base =
capitalize(type) !== this.state.path[0]
? TEMPLATES[type]
: this.state.content;
: this.state.content || TEMPLATES[type];
const newItem = EDITORS[capitalize(type)].createNew(base);
newItem.group = group;
// need to override ID for coremaps so they are selectable in the menu
if (type === 'coremaps') newItem.id = `${newItem.group}-1`;
if (newItem.label !== undefined) {
newItem.label = uniqueLabel(newItem.label, this.state[type]);
if (newItem.labelToUse !== undefined) {
Expand Down Expand Up @@ -385,9 +387,15 @@ export default class EditView extends React.Component {
labelMap[assembly.id] = assembly;
});

let foundSomething = false;
groupList.forEach((group) => {
if (newState[group]) {
newState[group].forEach((assembly) => {
// inserts only set num_pins, not ppitch
if (assembly.num_pins && assembly.ppitch) {
params.numPins = Math.max(params.numPins, assembly.num_pins);
params.pinPitch = Math.max(params.pinPitch, assembly.ppitch);
}
let count = assembly.layout.length;
while (count--) {
const layout = assembly.layout[count];
Expand All @@ -396,42 +404,55 @@ export default class EditView extends React.Component {
const numPins = assembly.num_pins;
layout.numPins = numPins;
layout.group = group;
const map = [];
for (let i = 0; i < numPins; ++i) {
map.push(
layout.cell_map
.slice(i * numPins, (i + 1) * numPins)
.join(' ')
);
}
layout.cellMap = map.join('\n');
InpHelper.setSymmetry(layout, params);
newLayout.unshift(layout);
foundSomething = true;
labelMap[layout.id] = layout;
}
}
assembly.id = `assembly-${group}-${assembly.label}`;
if (!labelMap[assembly.id]) {
assembly.group = group;
newAssemblies.unshift(assembly);
foundSomething = true;
labelMap[assembly.id] = assembly;
}
// inserts only set num_pins, not ppitch
if (assembly.num_pins && assembly.ppitch) {
params.numPins = Math.max(params.numPins, assembly.num_pins);
params.pinPitch = Math.max(params.pinPitch, assembly.ppitch);
}
});
if (newState.core) {
params.numAssemblies = newState.core.numAssemblies;
params.assemblyPitch = newState.core.assemblyPitch;
}
this.setState({
rodmaps: newLayout,
assemblies: newAssemblies,
params,
});
}
});
if (foundSomething) {
this.setState({
rodmaps: newLayout,
assemblies: newAssemblies,
params,
});
}
if (newState.core) {
params.numAssemblies = newState.core.numAssemblies;
params.assemblyPitch = newState.core.assemblyPitch;
params.coreShapeMap = newState.core.shape;
const coremaps = [];
GROUP_TYPES.forEach((info) => {
const coremap = newState.core[info.coremap];
if (coremap) {
const newMap = {
id: `${info.group}-1`,
type: 'coremaps',
label: info.label,
cell_map: coremap,
group: info.group,
};
InpHelper.setSymmetry(newMap, params);
console.log(newMap);
coremaps.push(newMap);
}
});

this.setState({
params,
coremaps,
});
}
console.log('editor', newState);
});
return false;
Expand Down Expand Up @@ -540,30 +561,25 @@ export default class EditView extends React.Component {
const coremaps = this.state.coremaps.filter(
(a) => a.group === info.group
);
// menu item key must match ID of the single coremap per type.
return (
<Menu.ItemGroup
key={`${info.label}Coremaps`}
title={
<GroupTitle
title={`${info.label} Map`}
icon="global"
onClick={
coremaps.length
? null
: () => this.onMenuNew('coremaps', info.group)
}
/>
}
>
{coremaps.map((a) => (
<Menu.Item key={`coremaps:${a.id}`}>
<span className={style.itemWithSmallIcon}>
<Icon type="global" />
{a.labelToUse || a.label}
</span>
</Menu.Item>
))}
</Menu.ItemGroup>
<Menu.Item key={`coremaps:${info.group}-1`}>
<span className={style.itemWithSmallIcon}>
<Icon type="global" />
{`${info.label} Map`}
<span style={{ flex: 1 }} />
{coremaps.length === 0 && (
<Button
shape="circle"
icon="plus"
className={style.menuAddNew}
onClick={() =>
this.onMenuNew('coremaps', info.group)
}
/>
)}
</span>
</Menu.Item>
);
}
return null;
Expand Down
9 changes: 3 additions & 6 deletions src/MainView.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import macro from 'vtk.js/Sources/macro';
import Color from './widgets/Color';
import ImageRenderer from './widgets/ImageRenderer';
import VTKRenderer from './widgets/VTKRenderer';
import CellTip from './widgets/CellTip';
import ModelHelper from './utils/ModelHelper';
import ImageGenerator from './utils/ImageGenerator';

Expand Down Expand Up @@ -172,15 +173,11 @@ export default class MainView extends React.Component {
const { item } = this.getSelectionByKey(this.state.lastKey);
if (this.state.has3D && this.state.has3D.type === 'layout') {
const { cell } = ImageGenerator.getLayoutCell(item, posx, posy);
return cell;
return `Cell: ${cell}`;
}
if (this.state.has3D && this.state.has3D.type === 'cell') {
const mat = ImageGenerator.getCellMaterial(item, posx, posy);
return mat ? (
<span>
{mat.radius} cm <br /> {mat.mat}
</span>
) : null;
return mat ? <CellTip mat={mat} /> : null;
}
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion src/utils/ColorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ function createColorManager(palette = PALETTE) {
// if all have been used.
let minLengthSeen = 1000;
Object.keys(colorInfo).forEach((infoRGBA) => {
if (!rgba || colorInfo[infoRGBA].names.length < minLengthSeen) {
// avoid assigning colors with a '0' alpha
if (
colorInfo[infoRGBA].color[3] > 0 &&
(!rgba || colorInfo[infoRGBA].names.length < minLengthSeen)
) {
rgba = infoRGBA;
minLengthSeen = colorInfo[infoRGBA].names.length;
}
Expand Down
52 changes: 34 additions & 18 deletions src/utils/ImageGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,11 @@ function updateItemWithLayoutImages(
}

// ----------------------------------------------------------------------------
// key will be "ASSEMBLIES;1:" if not present at this elevation,
// return will be "ASSEMBLIES;1:" if not present at this elevation,
// or "ASSEMBLIES;1:PLEN" if present.
function getElevationKey(map, key, elevation) {
function getElevationKey(map, itemMap, itemMapkey, elevation) {
if (!itemMap) return ':';
const key = itemMap[itemMapkey];
const layoutItem = map[key];
if (!layoutItem) {
return `${map.__category};${key}:`.replace(/-/g, '');
Expand Down Expand Up @@ -668,9 +670,9 @@ function computeCoreColorsAt(elevation, core) {
const lastColorManager = colorManagerByElevation[lastElevation];
lastElevation = elevation;

assemMap.forEach((tag) => {
assemMap.forEach((tag, i) => {
const assemKey = assemMap
? getElevationKey(LAYOUT_MAP.ASSEMBLIES, tag, elevation)
? getElevationKey(LAYOUT_MAP.ASSEMBLIES, assemMap, i, elevation)
: ':';
// assign a color only if there's a tag for a cellmap.
if (assemKey.split(':')[1].length) {
Expand All @@ -695,8 +697,10 @@ function computeCoreColorsAt(elevation, core) {
];
processingList.forEach((entry) => {
const [container, keyMap] = entry;
keyMap.forEach((tag) => {
const key = keyMap ? getElevationKey(container, tag, elevation) : ':';
keyMap.forEach((tag, i) => {
const key = keyMap
? getElevationKey(container, keyMap, i, elevation)
: ':';
if (key.split(':')[1].length) {
let prevColor = null;
if (lastColorManager) {
Expand Down Expand Up @@ -814,31 +818,43 @@ function computeCore2ImageAt(elevation, core, size = 1500, edge = 250) {
if (coreShape[i + j * coreSize]) {
// if the coremap has an assembly at this location, tag comes before the ':'
// if the assembly has a cellmap at this elevation, tag comes after ':'
const assemKey = assemMap
? getElevationKey(LAYOUT_MAP.ASSEMBLIES, assemMap[pidx], elevation)
: ':';
const assemKey = getElevationKey(
LAYOUT_MAP.ASSEMBLIES,
assemMap,
pidx,
elevation
);
// assign a color only if there's a tag for a cellmap.
const assemColor = assemKey.split(':')[1].length
? localColorManager.getColorRGBA(assemKey)
: null;

const ctrKey = ctrlMap
? getElevationKey(LAYOUT_MAP.CONTROLS, ctrlMap[pidx], elevation)
: ':';
const ctrKey = getElevationKey(
LAYOUT_MAP.CONTROLS,
ctrlMap,
pidx,
elevation
);
const ctrColor = ctrKey.split(':')[1].length
? localColorManager.getColorRGBA(ctrKey)
: null;

const detKey = detMap
? getElevationKey(LAYOUT_MAP.DETECTORS, detMap[pidx], elevation)
: ':';
const detKey = getElevationKey(
LAYOUT_MAP.DETECTORS,
detMap,
pidx,
elevation
);
const detColor = detKey.split(':')[1].length
? localColorManager.getColorRGBA(detKey)
: null;

const insKey = insMap
? getElevationKey(LAYOUT_MAP.INSERTS, insMap[pidx], elevation)
: ':';
const insKey = getElevationKey(
LAYOUT_MAP.INSERTS,
insMap,
pidx,
elevation
);
const insColor = insKey.split(':')[1].length
? localColorManager.getColorRGBA(insKey)
: null;
Expand Down
Loading

0 comments on commit 674a353

Please sign in to comment.