Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #284 from vimaec/sroberge/0_3_16
Browse files Browse the repository at this point in the history
Sroberge/0 3 16
  • Loading branch information
vim-sroberge authored Oct 28, 2024
2 parents 3aad12f + 9a1ceac commit 9fc31c7
Show file tree
Hide file tree
Showing 10 changed files with 451 additions and 177 deletions.
34 changes: 17 additions & 17 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vim-webgl-component",
"version": "0.3.15",
"version": "0.3.17",
"description": "A demonstration app built on top of the vim-webgl-viewer",
"files": [
"dist"
Expand Down Expand Up @@ -61,7 +61,7 @@
"react-tooltip": "^4.2.21",
"stats-js": "^1.0.1",
"tailwindcss-scoped-preflight": "^3.2.8",
"vim-webgl-viewer": "2.0.9"
"vim-webgl-viewer": "2.0.10"
},
"peerDependencies": {
"react": "^18.2.0",
Expand Down
13 changes: 10 additions & 3 deletions src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as VIM from 'vim-webgl-viewer/'
import { AxesPanelMemo } from './panels/axesPanel'
import { ControlBar, ControlBarCustomization } from './controlbar/controlBar'
import { RestOfScreen } from './controlbar/restOfScreen'
import { LoadingBoxMemo, MsgInfo, ComponentLoader } from './panels/loading'
import { LoadingBoxMemo, MsgInfo } from './panels/loading'
import { OptionalBimPanel } from './bim/bimPanel'
import {
ContextMenuCustomization,
Expand Down Expand Up @@ -40,13 +40,15 @@ import { VimComponentRef } from './vimComponentRef'
import { createBimInfoState } from './bim/bimInfoData'
import { whenTrue } from './helpers/utils'
import { DeferredPromise } from './helpers/deferredPromise'
import { ComponentLoader } from './helpers/loading'

export * as VIM from 'vim-webgl-viewer/'
export const THREE = VIM.THREE
export * as ContextMenu from './panels/contextMenu'
export * as BimInfo from './bim/bimInfoData'
export * as ControlBar from './controlbar/controlBar'
export * as Icons from './panels/icons'
export * from './helpers/loadRequest'
export * from './vimComponentRef'
export { getLocalComponentSettings as getLocalSettings } from './settings/settingsStorage'
export { type ComponentSettings as Settings, type PartialComponentSettings as PartialSettings, defaultSettings } from './settings/settings'
Expand Down Expand Up @@ -127,7 +129,7 @@ export function VimComponent (props: {

const help = useHelp()
const viewerState = useViewerState(props.viewer)
const [msg, setMsg] = useState<MsgInfo>()
const [msg, setMsg] = useState<MsgInfo | undefined>()
const treeRef = useRef<TreeActionRef>()
const performanceRef = useRef<HTMLDivElement>(null)

Expand All @@ -154,6 +156,11 @@ export function VimComponent (props: {
const subContext =
props.viewer.inputs.onContextMenu.subscribe(showContextMenu)

// Patch load
loader.current.onProgress.sub(p => setMsg({ progress: p.loaded }))
loader.current.onError.sub((e) => setMsg({ progress: e }))
loader.current.onDone.sub(() => setMsg(undefined))

props.onMount({
container: props.container,
viewer: props.viewer,
Expand Down Expand Up @@ -206,7 +213,7 @@ export function VimComponent (props: {
<div className="vim-performance-div" ref={performanceRef}></div>
<Overlay viewer={props.viewer} side={side}></Overlay>
<MenuHelpMemo help={help} settings={settings.value} side={side} />
{whenTrue(settings.value.ui.loadingBox, <LoadingBoxMemo loader={loader.current} content={msg} />)}
{whenTrue(settings.value.ui.loadingBox, <LoadingBoxMemo content={msg} />)}
<SidePanelMemo
container={props.container}
viewer={props.viewer}
Expand Down
2 changes: 1 addition & 1 deletion src/controlbar/sectionBoxState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export function getSectionBoxState (viewer: VIM.Viewer) {

// On First Render
useEffect(() => {
sectionGizmo.clip = true
const subSection = sectionGizmo.onStateChanged.subscribe(() =>
setSection({
clip: sectionGizmo.clip,
Expand All @@ -45,6 +44,7 @@ export function getSectionBoxState (viewer: VIM.Viewer) {
sectionGizmo.visible = next

if (next && first.current) {
sectionGizmo.clip = true
sectionGizmo.fitBox(viewer.renderer.getBoundingBox())
first.current = false
}
Expand Down
81 changes: 81 additions & 0 deletions src/helpers/loadRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as VIM from 'vim-webgl-viewer/'
import { DeferredPromise } from './deferredPromise'

type RequestCallbacks = {
onProgress: (p: VIM.IProgressLogs) => void
onError: (e: string) => void
onDone: () => void
}

/**
* Class to handle loading a request.
*/
export class LoadRequest {
private _callbacks : RequestCallbacks
private _request: VIM.VimRequest

private _progress: VIM.IProgressLogs = { loaded: 0, total: 0, all: new Map() }
private _progressPromise = new DeferredPromise<void>()

private _isDone: boolean = false
private _completionPromise = new DeferredPromise<void>()

constructor (callbacks: RequestCallbacks, source: VIM.RequestSource, settings: VIM.VimPartialSettings) {
this._callbacks = callbacks

this.startRequest(source, settings)
}

private async startRequest (source: VIM.RequestSource, settings: VIM.VimPartialSettings) {
this._request = await VIM.request(source, settings)
for await (const progress of this._request.getProgress()) {
this.onProgress(progress)
}
const result = await this._request.getResult()
if (result.isError()) {
this.onError(result.error)
} else {
this.onSuccess()
}
}

private onProgress (progress: VIM.IProgressLogs) {
this._callbacks.onProgress(progress)
this._progress = progress
this._progressPromise.resolve()
this._progressPromise = new DeferredPromise<void>()
}

private onSuccess () {
this._callbacks.onDone()
this.end()
}

private onError (error: string) {
this._callbacks.onError(error)
this.end()
}

private end () {
this._isDone = true
this._progressPromise.resolve()
this._completionPromise.resolve()
}

async * getProgress () : AsyncGenerator<VIM.IProgressLogs, void, void> {
while (!this._isDone) {
await this._progressPromise
yield this._progress
}
}

async getResult () {
await this._completionPromise
return this._request.getResult()
}

abort () {
this._request.abort()
this.onError('Request aborted')
}
}
Loading

0 comments on commit 9fc31c7

Please sign in to comment.