Skip to content

Commit

Permalink
enum scoring type
Browse files Browse the repository at this point in the history
  • Loading branch information
jagodek committed Dec 30, 2024
1 parent a84d373 commit 2cfe73d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 34 deletions.
21 changes: 12 additions & 9 deletions src/ThreeEditor/Simulation/Scoring/ScoringOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SimulationElementManager } from '../Base/SimulationManager';
import { SimulationZone } from '../Base/SimulationZone';
import { Detector } from '../Detectors/Detector';
import { ScoringFilter } from './ScoringFilter';
import { SCORING_TYPE, SCORING_TYPE_ENUM } from './ScoringOutputTypes';
import { ScoringQuantity, ScoringQuantityJSON } from './ScoringQuantity';

export type ScoringOutputJSON = Omit<
Expand Down Expand Up @@ -67,7 +68,7 @@ export class ScoringOutput

private _zone?: string;

private _scoringType?: string;
private _scoringType?: SCORING_TYPE;

//TODO: Issue#320
private _trace: [boolean, string | null];
Expand Down Expand Up @@ -122,15 +123,18 @@ export class ScoringOutput
this.signals.objectSelected.dispatch(this);
}

get scoringType(): string {
return this._scoringType ?? 'detector';
get scoringType(): SCORING_TYPE {
return this._scoringType ?? SCORING_TYPE_ENUM.DETECTOR;
}

set scoringType(scoringType: string) {
set scoringType(scoringType: SCORING_TYPE_ENUM) {
this._scoringType = scoringType;

if (scoringType === 'detector') this._zone = undefined;
else if (scoringType === 'zone') this._detector = undefined;
if (scoringType === SCORING_TYPE_ENUM.DETECTOR) {
this._zone = undefined;
} else if (scoringType === SCORING_TYPE_ENUM.ZONE) {
this._detector = undefined;
}
}

constructor(editor: YaptideEditor) {
Expand Down Expand Up @@ -200,13 +204,12 @@ export class ScoringOutput
this._trace = [json.trace, json.traceFilter ?? null];
this.quantityContainer.fromJSON(json.quantities);

this._scoringType = json.scoringType;
this.detector = json.detectorUuid
? this.editor.detectorManager.getDetectorByUuid(json.detectorUuid)
: null;
this.zone = json.zoneUuid ? this.editor.zoneManager.getZoneByUuid(json.zoneUuid) : null;

this._scoringType = json.scoringType ? json.scoringType : 'detector';
this._scoringType = (json.scoringType as SCORING_TYPE) ?? SCORING_TYPE_ENUM.DETECTOR;

return this;
}
Expand All @@ -224,7 +227,7 @@ export class ScoringOutput
duplicated.quantityContainer = this.quantityContainer.duplicate();
duplicated.add(duplicated.quantityContainer);

duplicated._scoringType = this._scoringType ? this._scoringType : 'detector';
duplicated._scoringType = this._scoringType ?? SCORING_TYPE_ENUM.DETECTOR;

return duplicated;
}
Expand Down
7 changes: 7 additions & 0 deletions src/ThreeEditor/Simulation/Scoring/ScoringOutputTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,10 @@ export const MEDIUM_KEYWORD_OPTIONS = Object.keys(MEDIUM_KEYWORDS).reduce(
},
{} as Record<MEDIUM, MEDIUM>
);

export type SCORING_TYPE = keyof typeof SCORING_TYPE_ENUM;

export enum SCORING_TYPE_ENUM {
DETECTOR = 'DETECTOR',
ZONE = 'ZONE'
}
17 changes: 9 additions & 8 deletions src/ThreeEditor/components/Dialog/ChangeScoringTypeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button } from '@mui/material';

import { StoreContext } from '../../../services/StoreService';
import { ScoringOutput } from '../../Simulation/Scoring/ScoringOutput';
import { SCORING_TYPE, SCORING_TYPE_ENUM } from '../../Simulation/Scoring/ScoringOutputTypes';
import { ConcreteDialogProps, CustomDialog } from './CustomDialog';

export function ChangeScoringTypeDialog({
Expand All @@ -12,8 +13,8 @@ export function ChangeScoringTypeDialog({
setScoringType
}: ConcreteDialogProps<
Required<Pick<StoreContext, 'yaptideEditor'>> & { scoringOutput: ScoringOutput } & {
newAlignment: string | null;
} & { setScoringType: (scoringType: string) => void }
newAlignment: SCORING_TYPE;
} & { setScoringType: (scoringType: SCORING_TYPE) => void }
>) {
return (
<CustomDialog
Expand All @@ -33,12 +34,12 @@ export function ChangeScoringTypeDialog({
if (scoringOutput && yaptideEditor) {
scoringOutput.removeAllQuantities();

if (newAlignment === 'zone') {
setScoringType('zone');
scoringOutput.scoringType = 'zone';
} else if (newAlignment === 'detector') {
setScoringType('detector');
scoringOutput.scoringType = 'detector';
if (newAlignment === SCORING_TYPE_ENUM.ZONE) {
setScoringType(SCORING_TYPE_ENUM.ZONE);
scoringOutput.scoringType = SCORING_TYPE_ENUM.ZONE;
} else if (newAlignment === SCORING_TYPE_ENUM.DETECTOR) {
setScoringType(SCORING_TYPE_ENUM.DETECTOR);
scoringOutput.scoringType = SCORING_TYPE_ENUM.DETECTOR;
}
}
}}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Grid, ToggleButton, ToggleButtonGroup } from '@mui/material';
import { useCallback, useEffect,useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { Object3D } from 'three';

import { useDialog } from '../../../../../services/DialogService';
Expand All @@ -9,6 +9,7 @@ import { AddQuantityCommand } from '../../../../js/commands/AddQuantityCommand';
import { SetOutputSettingsCommand } from '../../../../js/commands/SetOutputSettingsCommand';
import { YaptideEditor } from '../../../../js/YaptideEditor';
import { isOutput, ScoringOutput } from '../../../../Simulation/Scoring/ScoringOutput';
import { SCORING_TYPE, SCORING_TYPE_ENUM } from '../../../../Simulation/Scoring/ScoringOutputTypes';
import {
ObjectSelectOptionType,
ObjectSelectPropertyField
Expand All @@ -24,11 +25,14 @@ export function OutputConfiguration(props: { editor: YaptideEditor; object: Obje
editor,
object as unknown as ScoringOutput
);
const [scoringType, setScoringType] = useState(watchedObject.scoringType ?? 'detector');

const [scoringType, setScoringType] = useState(
watchedObject.scoringType ?? SCORING_TYPE_ENUM.DETECTOR
);

useEffect(() => {
// needed to properly set the scoring type, useState above is not enough
setScoringType(watchedObject.scoringType ?? 'detector');
setScoringType(watchedObject.scoringType ?? SCORING_TYPE_ENUM.DETECTOR);
}, [watchedObject.scoringType]);

const handleChangedDetector = useCallback(
Expand All @@ -37,7 +41,7 @@ export function OutputConfiguration(props: { editor: YaptideEditor; object: Obje
new SetOutputSettingsCommand(
editor,
watchedObject.object,
'detector',
SCORING_TYPE_ENUM.DETECTOR,
editor.detectorManager.getDetectorByUuid(v.uuid)
)
);
Expand All @@ -51,7 +55,7 @@ export function OutputConfiguration(props: { editor: YaptideEditor; object: Obje
new SetOutputSettingsCommand(
editor,
watchedObject.object,
'zone',
SCORING_TYPE_ENUM.ZONE,
editor.zoneManager.getZoneByUuid(v.uuid)
)
);
Expand All @@ -61,7 +65,7 @@ export function OutputConfiguration(props: { editor: YaptideEditor; object: Obje

const handleChangeOutputType = (
event: React.MouseEvent<HTMLElement>,
newAlignment: string | null
newAlignment: SCORING_TYPE
) => {
changeScoringType({
yaptideEditor: editor,
Expand All @@ -81,7 +85,7 @@ export function OutputConfiguration(props: { editor: YaptideEditor; object: Obje
visible={visibleFlag}>
{visibleFlag && (
<>
{simulatorType == SimulatorType.FLUKA && (
{simulatorType === SimulatorType.FLUKA && (
<PropertyField
label='Scoring Type'
disabled={false}>
Expand All @@ -92,23 +96,23 @@ export function OutputConfiguration(props: { editor: YaptideEditor; object: Obje
aria-label='text alignment'
size='small'>
<ToggleButton
value='detector'
disabled={scoringType === 'detector'}
value={SCORING_TYPE_ENUM.DETECTOR}
disabled={scoringType === SCORING_TYPE_ENUM.DETECTOR}
aria-label='left aligned'>
Detector
</ToggleButton>

<ToggleButton
value='zone'
disabled={scoringType === 'zone'}
value={SCORING_TYPE_ENUM.ZONE}
disabled={scoringType === SCORING_TYPE_ENUM.ZONE}
aria-label='left aligned'>
Zone
</ToggleButton>
</ToggleButtonGroup>
</PropertyField>
)}

{scoringType === 'detector' && (
{scoringType === SCORING_TYPE_ENUM.DETECTOR && (
<ObjectSelectPropertyField
label='Detector'
value={watchedObject.detector?.uuid ?? ''}
Expand All @@ -124,7 +128,7 @@ export function OutputConfiguration(props: { editor: YaptideEditor; object: Obje
/>
)}

{scoringType === 'zone' && (
{scoringType === SCORING_TYPE_ENUM.ZONE && (
<ObjectSelectPropertyField
label='Zone'
value={watchedObject.zone?.uuid ?? ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
DETECTOR_KEYWORD_OPTIONS,
FLUKA_DETECTOR_KEYWORD_OPTIONS,
FLUKA_ZONE_KEYWORD_OPTIONS,
MEDIUM_KEYWORD_OPTIONS
MEDIUM_KEYWORD_OPTIONS,
SCORING_TYPE_ENUM
} from '../../../../Simulation/Scoring/ScoringOutputTypes';
import { isScoringQuantity, ScoringQuantity } from '../../../../Simulation/Scoring/ScoringQuantity';
import { ObjectSelectPropertyField } from '../fields/ObjectSelectPropertyField';
Expand Down Expand Up @@ -50,7 +51,7 @@ export function QuantityConfiguration(props: { editor: YaptideEditor; object: Ob
options={
editor.contextManager.currentSimulator === SimulatorType.SHIELDHIT
? DETECTOR_KEYWORD_OPTIONS
: scoringType === 'detector'
: scoringType === SCORING_TYPE_ENUM.DETECTOR
? FLUKA_DETECTOR_KEYWORD_OPTIONS
: FLUKA_ZONE_KEYWORD_OPTIONS
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { SetQuantityValueCommand } from '../../../../js/commands/SetQuantityValu
import { YaptideEditor } from '../../../../js/YaptideEditor';
import {
DETECTOR_MODIFIERS,
DETECTOR_MODIFIERS_OPTIONS
DETECTOR_MODIFIERS_OPTIONS,
FLUKA_ZONE_MODIFIERS_OPTIONS
} from '../../../../Simulation/Scoring/ScoringOutputTypes';
import { DifferentialModifier } from '../../../../Simulation/Scoring/ScoringQtyModifiers';
import { isScoringQuantity, ScoringQuantity } from '../../../../Simulation/Scoring/ScoringQuantity';
Expand Down Expand Up @@ -88,7 +89,11 @@ export function QuantityDifferentialScoring(props: { editor: YaptideEditor; obje
upperLimit={watchedObject.selectedModifier.upperLimit}
binsNumber={watchedObject.selectedModifier.binsNumber}
logCheckbox={watchedObject.selectedModifier.isLog}
options={DETECTOR_MODIFIERS_OPTIONS}
options={
simulatorType === SimulatorType.SHIELDHIT
? DETECTOR_MODIFIERS_OPTIONS
: FLUKA_ZONE_MODIFIERS_OPTIONS
}
onChange={v => {
editor.execute(
new AddDifferentialModifierCommand(
Expand Down

0 comments on commit 2cfe73d

Please sign in to comment.