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

Add sad parameter #753 #888

Merged
merged 6 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChangeEvent } from 'react';
import { Object3D } from 'three';
import { SetValueCommand } from '../../../../js/commands/SetValueCommand';
import { Editor } from '../../../../js/Editor';
import { Beam, BEAM_SOURCE_TYPE, isBeam, SigmaType, SIGMA_TYPE } from '../../../../util/Beam';
import { Beam, BEAM_SOURCE_TYPE, isBeam, SadType, SAD_TYPE, SigmaType, SIGMA_TYPE } from '../../../../util/Beam';
import { useSmartWatchEditorState } from '../../../../util/hooks/signals';
import { PARTICLE_TYPES } from '../../../../util/particles';
import { IParticleType, ParticleSelect } from '../../../Select/ParticlesSelect';
Expand Down Expand Up @@ -131,6 +131,68 @@ function BeamSigmaField(props: { beam: Beam; onChange: (value: Beam['sigma']) =>
);
}


function BeamSadField(props: { beam: Beam; onChange: (value: Beam['sad']) => void }) {
const configuration = {
[SAD_TYPE.Rectangular]: {
X: {
text: 'sad in X'
grzanka marked this conversation as resolved.
Show resolved Hide resolved
},
Y: {
text: 'sad in Y'
grzanka marked this conversation as resolved.
Show resolved Hide resolved
}
},
[SAD_TYPE.Square]: {
Y: {
text: 'value'
}
},
[SAD_TYPE.None]: {

},

};

const selectedConfiguration = configuration[props.beam.sad.type];

return (
<>
<SelectPropertyField
label='Sad type'
grzanka marked this conversation as resolved.
Show resolved Hide resolved
value={props.beam.sad.type}
onChange={value =>
props.onChange({ ...props.beam.sad, type: value as SadType })
}
options={Object.keys(SAD_TYPE)}
/>
{props.beam.sad.type !== SAD_TYPE.None && (
<>
{'X' in selectedConfiguration && (
<NumberPropertyField
label={selectedConfiguration.X.text}
value={props.beam.sad.x}
onChange={value => props.onChange({ ...props.beam.sad, x: value })}
min={0}
unit='cm'
/>
)}

{'Y' in selectedConfiguration && (
<NumberPropertyField
label={selectedConfiguration.Y.text}
value={props.beam.sad.y}
onChange={value => props.onChange({ ...props.beam.sad, y: value })}
min={0}
unit='cm'
/>
)}
</>
)}
</>
);
}


function BeamConfigurationFields(props: { editor: Editor; object: Beam }) {
const { object, editor } = props;

Expand Down Expand Up @@ -258,6 +320,14 @@ function BeamConfigurationFields(props: { editor: Editor; object: Beam }) {

{watchedObject.beamSourceType === BEAM_SOURCE_TYPE.file && (
<>
{/* TODO */}
<BeamSadField
beam={watchedObject}
onChange={v => {
setValueCommand(v, 'sad');
}}
/>

<PropertyField children={<Divider />} />

<BeamDefinitionField
Expand Down
32 changes: 31 additions & 1 deletion src/ThreeEditor/util/Beam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ export const SIGMA_TYPE = {
'Flat square': 'Flat square',
'Flat circular': 'Flat circular'
} as const;
export type SigmaType = keyof typeof SIGMA_TYPE;
export type SigmaType = keyof typeof SIGMA_TYPE

export const SAD_TYPE = {
'None' : 'None',
'Rectangular': 'Rectangular',
'Square': 'Square'
grzanka marked this conversation as resolved.
Show resolved Hide resolved
} as const;
export type SadType = keyof typeof SAD_TYPE

export const BEAM_SOURCE_TYPE = {
'simple': 'simple',
Expand Down Expand Up @@ -44,6 +51,13 @@ export interface BeamJSON {
x: number;
y: number;
};

sad: {
type: SadType;
x: number;
y: number;
};

colorHex: number;
numberOfParticles: number;
beamSourceFile: BeamSourceFile;
Expand Down Expand Up @@ -72,6 +86,12 @@ const _default = {
x: 0,
y: 0
},
sad: {
type: SAD_TYPE.None,
x: 0,
y: 0
},

numberOfParticles: 10000,

beamSourceFile: {
Expand Down Expand Up @@ -126,6 +146,12 @@ export class Beam extends SimulationObject3D {
y: number;
};

sad: {
type: SadType;
x: number;
y: number;
};

numberOfParticles: number;

particleData: {
Expand Down Expand Up @@ -164,6 +190,8 @@ export class Beam extends SimulationObject3D {

this.sigma = { ..._default.sigma };

this.sad = { ..._default.sad };

this.particleData = _default.particle;

this.numberOfParticles = _default.numberOfParticles;
Expand Down Expand Up @@ -268,6 +296,7 @@ export class Beam extends SimulationObject3D {
energyLowCutoff: this.energyLowCutoff,
energyHighCutoff: this.energyHighCutoff,
sigma: this.sigma,
sad: this.sad,
divergence: this.divergence,
particle: this.particleData,
colorHex: this.material.color.getHex(),
Expand All @@ -293,6 +322,7 @@ export class Beam extends SimulationObject3D {
this.numberOfParticles = loadedData.numberOfParticles;
this.beamSourceFile = loadedData.beamSourceFile;
this.sigma = loadedData.sigma;
this.sad = loadedData.sad;
this.beamSourceType = loadedData.beamSourceType;
return this;
}
Expand Down