Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1196 add dose to medium and let to medium #1233

Merged
merged 17 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions package-lock.json

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

17 changes: 9 additions & 8 deletions src/ThreeEditor/Simulation/Base/SimulationZone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { SimulationElement, SimulationElementJSON } from './SimulationElement';

export type SimulationZoneJSON = Omit<
SimulationElementJSON & {
materialUuid: string;
materialPropertiesOverrides: Partial<MaterialOverridable>;
materialUuid?: string;
materialPropertiesOverrides?: Partial<MaterialOverridable>;
customMaterial?: SimulationMaterialJSON & {
originalMaterialUuid: string;
};
Expand Down Expand Up @@ -100,12 +100,13 @@ export abstract class SimulationZone

private reconstructMaterialFromJSON(json: SimulationZoneJSON) {
const { materialUuid, customMaterial } = json;
const simulationMaterial =
this.editor.materialManager.getMaterialByUuid(
customMaterial && materialUuid === customMaterial.uuid
? customMaterial.originalMaterialUuid
: materialUuid
) ?? this.editor.materialManager.defaultMaterial;
const simulationMaterial = materialUuid
? this.editor.materialManager.getMaterialByUuid(
customMaterial && materialUuid === customMaterial.uuid
? customMaterial.originalMaterialUuid
: materialUuid
)
: this.editor.materialManager.defaultMaterial;

if (simulationMaterial === undefined) throw new Error('SimulationMaterial not found');
this.simulationMaterial = simulationMaterial;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const addCustomStoppingPowerTableToEditorJSON = async (editorJson: Editor
const zone = editorJson.zoneManager.zones[key];
console.log(zone);

if (zone.materialPropertiesOverrides.customStoppingPower && zone.customMaterial) {
if (zone.materialPropertiesOverrides?.customStoppingPower && zone.customMaterial) {
usedStoppingPowerTables.add(zone.customMaterial.icru);
}
}
Expand Down
19 changes: 12 additions & 7 deletions src/ThreeEditor/Simulation/Detectors/DetectorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Signal } from 'signals';
import * as THREE from 'three';

import { SimulationPropertiesType } from '../../../types/SimulationProperties';
import { YaptideEditor } from '../../js/YaptideEditor';
import { JSON_VERSION, YaptideEditor } from '../../js/YaptideEditor';
import { SimulationSceneContainer } from '../Base/SimulationContainer';
import { SimulationElementJSON } from '../Base/SimulationElement';
import { SimulationElementManager } from '../Base/SimulationManager';
Expand Down Expand Up @@ -40,9 +40,11 @@ export class DetectorManager
{
/****************************Private****************************/
private readonly metadata = {
version: `0.10`, //update this to current YaptideEditor version when format changes
version: `0.11`,
type: 'Manager',
generator: 'DetectorManager.toJSON'
} as {
version: typeof JSON_VERSION;
} satisfies Record<string, string | number>;

private editor: YaptideEditor;
Expand Down Expand Up @@ -133,11 +135,14 @@ export class DetectorManager
return this.editor.zoneManager.getZoneByUuid(geometryData.zoneUuid) !== undefined;
})
.filter(additionalPredicate || (() => true))
.reduce((acc, geometry) => {
acc[geometry.uuid] = `${geometry.name} [${geometry.id}]`;

return acc;
}, {} as Record<string, string>);
.reduce(
(acc, geometry) => {
acc[geometry.uuid] = `${geometry.name} [${geometry.id}]`;

return acc;
},
{} as Record<string, string>
);

return options;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ThreeEditor/Simulation/Figures/FigureManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class FigureManager
{
/****************************Private****************************/
private readonly metadata = {
version: `0.10`, //update this to current YaptideEditor version when format changes
version: `0.11`, //update this to current YaptideEditor version when format changes
type: 'Manager',
generator: 'FigureManager.toJSON'
} satisfies Record<string, string | number>;
Expand Down
13 changes: 9 additions & 4 deletions src/ThreeEditor/Simulation/Materials/MaterialManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as THREE from 'three';

import { SimulationPropertiesType } from '../../../types/SimulationProperties';
import { CounterMap } from '../../../util/CounterMap/CounterMap';
import { YaptideEditor } from '../../js/YaptideEditor.js';
import { JSON_VERSION, YaptideEditor } from '../../js/YaptideEditor.js';
import { SimulationElementJSON } from '../Base/SimulationElement';
import { DEFAULT_MATERIAL_ICRU, MATERIALS } from './materials';
import SimulationMaterial, {
Expand All @@ -25,9 +25,11 @@ export type Icru = number;
export class MaterialManager extends THREE.Object3D implements SimulationPropertiesType {
/****************************Private****************************/
private readonly metadata = {
version: `0.10`, //update this to current YaptideEditor version when format changes
version: `0.11`,
type: 'Manager',
generator: 'MaterialManager.toJSON'
} as {
version: typeof JSON_VERSION;
} satisfies Record<string, string | number>;

private editor: YaptideEditor;
Expand All @@ -43,10 +45,13 @@ export class MaterialManager extends THREE.Object3D implements SimulationPropert
private createMaterialPrefabs = () => {
const { editor } = this;
const editorMaterials = MATERIALS.reduce(
([prevMaterials, prevOptions], { name, icru, density }) => [
(
[prevMaterials, prevOptions],
{ name, sanitized_name: sanitizedName, icru, density }
) => [
{
...prevMaterials,
[icru]: new SimulationMaterial(editor, name, icru, density)
[icru]: new SimulationMaterial(editor, name, sanitizedName, icru, density)
},
{
...prevOptions,
Expand Down
11 changes: 7 additions & 4 deletions src/ThreeEditor/Simulation/Materials/SimulationMaterial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ test('constructor default', () => {
});

test('constructor params', () => {
const material = new SimulationMaterial(editor, 'test', 1, 2);
const material = new SimulationMaterial(editor, 'test', 'test', 1, 2);
expect(material).toBeInstanceOf(SimulationMaterial);
expect(material.icru).toBe(1);
expect(material.density).toBe(2);
expect(material.name).toBe('test');
});

test('toJSON', () => {
const material = new SimulationMaterial(editor, 'test', 1, 2);
const material = new SimulationMaterial(editor, 'test', 'test', 1, 2);
expect(material.toJSON()).toEqual({
uuid: material.uuid,
name: 'test',
sanitizedName: 'test',
icru: 1,
density: 2
});
Expand All @@ -42,6 +43,7 @@ test('fromJSON', () => {
const material = SimulationMaterial.fromJSON(editor, {
uuid: 'testUuid',
name: 'test',
sanitizedName: 'test',
icru: 1,
density: 2
});
Expand All @@ -55,6 +57,7 @@ test('fromJSON', () => {
const material2 = SimulationMaterial.fromJSON(editor, {
uuid: 'testUuid',
name: 'test',
sanitizedName: 'test',
icru: 1,
density: 2,
customStoppingPower: true
Expand All @@ -69,7 +72,7 @@ test('fromJSON', () => {
});

test('clone', () => {
const material = new SimulationMaterial(editor, 'test', 1, 2);
const material = new SimulationMaterial(editor, 'test', 'test', 1, 2);
material.customStoppingPower = true;
const clone = material.clone();
expect(clone).toBeInstanceOf(SimulationMaterial);
Expand All @@ -81,7 +84,7 @@ test('clone', () => {
});

test('copy', () => {
const material = new SimulationMaterial(editor, 'test', 1, 2);
const material = new SimulationMaterial(editor, 'test', 'test', 1, 2);
material.customStoppingPower = true;
const copy = new SimulationMaterial(editor);
copy.copy(material);
Expand Down
28 changes: 23 additions & 5 deletions src/ThreeEditor/Simulation/Materials/SimulationMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import { Icru } from './MaterialManager';
import {
DEFAULT_MATERIAL_DENSITY,
DEFAULT_MATERIAL_ICRU,
DEFAULT_MATERIAL_NAME
DEFAULT_MATERIAL_NAME,
DEFAULT_SANITIZED_MATERIAL_NAME
} from './materials';

export type RenderProps = Omit<SimulationMaterialJSON, 'uuid' | 'name' | 'icru' | 'density'>;
export type RenderProps = Omit<
SimulationMaterialJSON,
'uuid' | 'name' | 'icru' | 'density' | 'sanitizedName'
>;

export type SimulationMaterialJSON = {
uuid: string;
name: string;
sanitizedName: string;
icru: Icru;
density: number;
customStoppingPower?: boolean;
Expand All @@ -28,6 +33,7 @@ export default class SimulationMaterial extends THREE.MeshPhongMaterial {
private editor: YaptideEditor;
private colorProxy: THREE.Color;
icru: Icru;
sanitizedName: string;
density: number;
customStoppingPower: boolean = false;
renderProps: RenderProps;
Expand Down Expand Up @@ -73,6 +79,7 @@ export default class SimulationMaterial extends THREE.MeshPhongMaterial {
constructor(
editor: YaptideEditor,
name: string = DEFAULT_MATERIAL_NAME,
sanitizedName: string = DEFAULT_SANITIZED_MATERIAL_NAME,
icru: number = DEFAULT_MATERIAL_ICRU,
density: number = DEFAULT_MATERIAL_DENSITY
) {
Expand All @@ -83,6 +90,7 @@ export default class SimulationMaterial extends THREE.MeshPhongMaterial {
transparent: false,
color: new THREE.Color(0xff3d3d)
});
this.sanitizedName = sanitizedName;
this.colorProxy = new Proxy(new THREE.Color(0xff3d3d), this.materialColorHandler);
this.editor = editor;
this.icru = icru;
Expand All @@ -101,10 +109,11 @@ export default class SimulationMaterial extends THREE.MeshPhongMaterial {
}

toJSON(): SimulationMaterialJSON {
const { uuid, name, icru, density, renderProps, customStoppingPower } = this;
const { uuid, name, sanitizedName, icru, density, renderProps, customStoppingPower } = this;

return {
uuid,
sanitizedName,
name,
icru,
density,
Expand All @@ -115,9 +124,17 @@ export default class SimulationMaterial extends THREE.MeshPhongMaterial {

static fromJSON(
editor: YaptideEditor,
{ uuid, name, icru, density, customStoppingPower, ...renderProps }: SimulationMaterialJSON
{
uuid,
name,
sanitizedName,
icru,
density,
customStoppingPower,
...renderProps
}: SimulationMaterialJSON
): SimulationMaterial {
const material = new SimulationMaterial(editor, name, icru, density);
const material = new SimulationMaterial(editor, name, sanitizedName, icru, density);
material.uuid = uuid;
material.customStoppingPower = customStoppingPower ?? false;
material.renderProps = renderProps;
Expand All @@ -138,6 +155,7 @@ export default class SimulationMaterial extends THREE.MeshPhongMaterial {

copy(source: SimulationMaterial): this {
const result = super.copy(source);
result.sanitizedName = source.sanitizedName;
result.renderProps = { ...source.renderProps };
result.density = source.density;
result.icru = source.icru;
Expand Down
Loading
Loading