-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1673 from theogutt/main
McStas3D
- Loading branch information
Showing
32 changed files
with
889 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
# Dependency directories | ||
node_modules/ | ||
|
||
# Build directories | ||
dist/ | ||
|
||
# Project specific | ||
instrument.json | ||
particles.json | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
tools/Python/mcdisplay/webgl/Contexts/ComponentsContext.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
tools/Python/mcdisplay/webgl/Contexts/InstrumentContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { | ||
ReactNode, | ||
createContext, | ||
useContext, | ||
useState, | ||
useEffect, | ||
} from "react"; | ||
import { fetchJSON } from "../utils/fetch"; | ||
import { initializeInstrument } from "../data-utils/initInstrument"; | ||
import { Instrument } from "../model/Instrument"; | ||
|
||
type InstrumentContextType = { | ||
instrument: Instrument; | ||
setInstrument: React.Dispatch<React.SetStateAction<Instrument>>; | ||
}; | ||
|
||
const InstrumentContext = createContext<InstrumentContextType>({ | ||
instrument: { | ||
name: "", | ||
abspath: "", | ||
params: [], | ||
params_defaults: [], | ||
params_values: [], | ||
cmd: "", | ||
components: [], | ||
}, | ||
setInstrument: () => {}, | ||
}); | ||
|
||
interface InstrumentProviderProps { | ||
children: ReactNode; | ||
} | ||
|
||
export const InstrumentProvider: React.FC<InstrumentProviderProps> = ({ | ||
children, | ||
}) => { | ||
const [instrument, _setInstrument] = useState<Instrument>({ | ||
name: "", | ||
abspath: "", | ||
params: [], | ||
params_defaults: [], | ||
params_values: [], | ||
cmd: "", | ||
components: [], | ||
}); | ||
|
||
useEffect(() => { | ||
fetchJSON("../instrument.json").then((data) => { | ||
if (data) { | ||
const instrument = initializeInstrument(data); | ||
_setInstrument(instrument); | ||
} else { | ||
console.warn("Instrument data is missing"); | ||
} | ||
}); | ||
}, []); | ||
|
||
const setInstrument = (newInstrument: React.SetStateAction<Instrument>) => { | ||
_setInstrument(newInstrument); | ||
}; | ||
|
||
return ( | ||
<InstrumentContext.Provider value={{ instrument, setInstrument }}> | ||
{children} | ||
</InstrumentContext.Provider> | ||
); | ||
}; | ||
|
||
export const useInstrumentContext = () => useContext(InstrumentContext); |
57 changes: 57 additions & 0 deletions
57
tools/Python/mcdisplay/webgl/Contexts/PlotRangeContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { createContext, useContext, ReactNode, useState } from "react"; | ||
|
||
type AxisRange = [number, number]; | ||
|
||
type PlotRangeContextType = { | ||
plotlyRanges: { | ||
[key: string]: { | ||
xaxis: AxisRange; | ||
yaxis: AxisRange; | ||
}; | ||
}; | ||
updatePlotlyRanges: ( | ||
view: string, | ||
newRanges: { xaxis: AxisRange; yaxis: AxisRange } | ||
) => void; | ||
}; | ||
|
||
const PlotRangeContext = createContext<PlotRangeContextType>({ | ||
plotlyRanges: { | ||
Top: { xaxis: [0, 100], yaxis: [-50, 50] }, | ||
Side: { xaxis: [0, 100], yaxis: [-50, 50] }, | ||
End: { xaxis: [0, 100], yaxis: [-50, 50] }, | ||
}, | ||
updatePlotlyRanges: () => {}, | ||
}); | ||
|
||
interface PlotRangeProviderProps { | ||
children: ReactNode; | ||
} | ||
|
||
export const PlotRangeProvider: React.FC<PlotRangeProviderProps> = ({ | ||
children, | ||
}) => { | ||
const [plotlyRanges, setPlotlyRanges] = useState({ | ||
Top: { xaxis: [0, 100] as AxisRange, yaxis: [-50, 50] as AxisRange }, | ||
Side: { xaxis: [0, 100] as AxisRange, yaxis: [-50, 50] as AxisRange }, | ||
End: { xaxis: [0, 100] as AxisRange, yaxis: [-50, 50] as AxisRange }, | ||
}); | ||
|
||
const updatePlotlyRanges = ( | ||
view: string, | ||
newRanges: { xaxis: AxisRange; yaxis: AxisRange } | ||
) => { | ||
setPlotlyRanges((prevRanges) => ({ | ||
...prevRanges, | ||
[view]: newRanges, | ||
})); | ||
}; | ||
|
||
return ( | ||
<PlotRangeContext.Provider value={{ plotlyRanges, updatePlotlyRanges }}> | ||
{children} | ||
</PlotRangeContext.Provider> | ||
); | ||
}; | ||
|
||
export const usePlotRangeContext = () => useContext(PlotRangeContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { createContext, useContext, ReactNode, useRef } from "react"; | ||
import * as THREE from "three"; | ||
import { initializeScene } from "../components/scene/initializeScene"; | ||
|
||
type SceneContextType = { | ||
gridsRef: React.MutableRefObject<any>; | ||
axesRef: React.MutableRefObject<any>; | ||
containerRef: React.MutableRefObject<any>; | ||
primaryCameraRef: React.MutableRefObject<any>; | ||
primaryControlsRef: React.MutableRefObject<any>; | ||
primaryViewRef: React.MutableRefObject<any>; | ||
TopView2DRef: React.MutableRefObject<any>; | ||
SideView2DRef: React.MutableRefObject<any>; | ||
BackView2DRef: React.MutableRefObject<any>; | ||
rendererRef: React.MutableRefObject<any>; | ||
sceneRef: React.MutableRefObject<any>; | ||
}; | ||
|
||
const SceneContext = createContext<SceneContextType>({ | ||
gridsRef: { current: null }, | ||
axesRef: { current: null }, | ||
containerRef: { current: null }, | ||
primaryCameraRef: { current: null }, | ||
primaryControlsRef: { current: null }, | ||
primaryViewRef: { current: null }, | ||
TopView2DRef: { current: null }, | ||
SideView2DRef: { current: null }, | ||
BackView2DRef: { current: null }, | ||
rendererRef: { current: null }, | ||
sceneRef: { current: null }, | ||
}); | ||
|
||
interface SceneProviderProps { | ||
children: ReactNode; | ||
} | ||
|
||
export const SceneProvider: React.FC<SceneProviderProps> = ({ children }) => { | ||
const gridsRef = useRef({ gridXY: null, gridXZ: null, gridYZ: null }); | ||
const axesRef = useRef({ x_axis: null, y_axis: null, z_axis: null }); | ||
const containerRef = useRef(null); | ||
const primaryCameraRef = useRef(null); | ||
const primaryControlsRef = useRef(null); | ||
const primaryViewRef = useRef(null); | ||
const TopView2DRef = useRef(null); | ||
const SideView2DRef = useRef(null); | ||
const BackView2DRef = useRef(null); | ||
const rendererRef = useRef(null); | ||
const sceneRef = useRef(initializeScene()); | ||
|
||
return ( | ||
<SceneContext.Provider | ||
value={{ | ||
gridsRef, | ||
axesRef, | ||
containerRef, | ||
primaryCameraRef, | ||
primaryControlsRef, | ||
primaryViewRef, | ||
TopView2DRef, | ||
SideView2DRef, | ||
BackView2DRef, | ||
rendererRef, | ||
sceneRef, | ||
}} | ||
> | ||
{children} | ||
</SceneContext.Provider> | ||
); | ||
}; | ||
|
||
export const useSceneContext = () => useContext(SceneContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.