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 #281 from vimaec/sroberge/0_3_13
Browse files Browse the repository at this point in the history
Sroberge/0 3 13
  • Loading branch information
vim-sroberge authored Oct 2, 2024
2 parents 30e6786 + 091de32 commit 615f13f
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 44 deletions.
18 changes: 9 additions & 9 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.11",
"version": "0.3.14",
"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.5"
"vim-webgl-viewer": "2.0.8"
},
"peerDependencies": {
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/bim/bimInfoData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type Data = {
* @data The data to customize.
* @source The VIM.Object or VIM.Vim from which the data was pulled.
*/
export type DataCustomization = (data: Data, source: VIM.Vim | VIM.Object) => Promise<Data>
export type DataCustomization = (data: Data, source: VIM.Vim | VIM.Object3D) => Promise<Data>

/**
* Rendering customization function for the BIM info panel.
Expand Down
4 changes: 2 additions & 2 deletions src/bim/bimInfoObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export declare type ElementParameter = {
isInstance: boolean;
};

export async function getObjectData (object: VIM.Object, elements: AugmentedElement[]) : Promise<BIM.Data> {
export async function getObjectData (object: VIM.Object3D, elements: AugmentedElement[]) : Promise<BIM.Data> {
const element = object
? elements.find((e) => e.index === object.element)
: undefined
Expand Down Expand Up @@ -62,7 +62,7 @@ export function getHeader (info: AugmentedElement | undefined): BIM.Entry[] | un
}

export async function getBody (
object: VIM.Object
object: VIM.Object3D
): Promise<BIM.Section[]> {
let parameters = await object?.getBimParameters()
if (!parameters) return null
Expand Down
7 changes: 4 additions & 3 deletions src/bim/bimInfoPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { AugmentedElement } from '../helpers/element'
import { Data, BimInfoPanelRef } from './bimInfoData'

export function BimInfoPanel (props : {
object: VIM.Object,
object: VIM.Object3D,
vim: VIM.Vim,
elements: AugmentedElement[],
full : boolean
bimInfoRef: BimInfoPanelRef
}
) {
const target = props.object?.type === 'Object3D' ? props.object : undefined
useEffect(() => {
ReactTooltip.rebuild()
})
Expand All @@ -28,8 +29,8 @@ export function BimInfoPanel (props : {
async function update () {
let data = props.object === undefined
? await getVimData(props.vim)
: await getObjectData(props.object, props.elements)
data = await props.bimInfoRef.onData(data, props.object ?? props.vim)
: await getObjectData(target, props.elements)
data = await props.bimInfoRef.onData(data, target ?? props.vim)
setData(data)
}
// UseEffect doesn't accept async functions so we need to wrap it
Expand Down
10 changes: 5 additions & 5 deletions src/bim/bimTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type TreeActionRef = {
showAll: () => void
hideAll: () => void
collapseAll: () => void
selectSiblings: (element: VIM.IObject) => void
selectSiblings: (element: VIM.Object3D) => void
}

/**
Expand All @@ -35,12 +35,12 @@ export function BimTree (props: {
actionRef: React.MutableRefObject<TreeActionRef>
viewer: VIM.Viewer
camera: CameraHelpers
objects: VIM.IObject[]
objects: VIM.Object3D[]
isolation: Isolation
treeData: BimTreeData
}) {
// Data state
const [objects, setObjects] = useState<VIM.IObject[]>([])
const [objects, setObjects] = useState<VIM.Object3D[]>([])

// Tree state
const [expandedItems, setExpandedItems] = useState<number[]>([])
Expand All @@ -62,7 +62,7 @@ export function BimTree (props: {
collapseAll: () => {
setExpandedItems([])
},
selectSiblings: (object: VIM.Object) => {
selectSiblings: (object: VIM.Object3D) => {
const element = object.element
const node = props.treeData.getNodeFromElement(element)
const siblings = props.treeData.getSiblings(node)
Expand Down Expand Up @@ -299,7 +299,7 @@ function updateViewerSelection (
nodes: number[],
operation: 'add' | 'remove' | 'set'
) {
const objects: VIM.Object[] = []
const objects: VIM.Object3D[] = []
nodes.forEach((n) => {
const item = tree.nodes[n]
const element = item.data.index
Expand Down
10 changes: 8 additions & 2 deletions src/helpers/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export class ComponentInputs implements VIM.InputScheme {
this._sideState = sideState
}

private _getSelection = () => {
return [...this._viewer.selection.objects].filter(
(o) => o.type === 'Object3D'
) as VIM.Object3D[]
}

onMainAction (hit: InputAction): void {
this._default.onMainAction(hit)
}
Expand Down Expand Up @@ -75,13 +81,13 @@ export class ComponentInputs implements VIM.InputScheme {
const visible = objs.findIndex((o) => o.visible) >= 0
if (visible) {
this._isolation.hide(
[...this._viewer.selection.objects],
this._getSelection(),
'keyboard'
)
this._viewer.selection.clear()
} else {
this._isolation.show(
[...this._viewer.selection.objects],
this._getSelection(),
'keyboard'
)
}
Expand Down
20 changes: 10 additions & 10 deletions src/helpers/isolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export class Isolation {
private _viewer: VIM.Viewer

private _settings: ComponentSettings
private _isolation: VIM.IObject[]
private _lastIsolation: VIM.IObject[]
private _isolation: VIM.Object3D[]
private _lastIsolation: VIM.Object3D[]

private _camera: ComponentCamera
private _references = new Map<VIM.Vim, Set<VIM.IObject> | 'always'>()
private _references = new Map<VIM.Vim, Set<VIM.Object3D> | 'always'>()

private _onChanged = new SimpleEventDispatcher<string>()
/** Signal dispatched when the isolation set changes. */
Expand Down Expand Up @@ -52,7 +52,7 @@ export class Isolation {
* @param vim The VIM for which reference objects are being set.
* @param reference An array of reference objects or the string 'always' to indicate permanent reference.
*/
setReference (vim: VIM.Vim, reference: VIM.Object[] | 'always') {
setReference (vim: VIM.Vim, reference: VIM.Object3D[] | 'always') {
const value = reference === 'always' ? reference : new Set(reference)
this._references.set(vim, value)
}
Expand Down Expand Up @@ -95,7 +95,7 @@ export class Isolation {
* @param source The source of isolation.
* @returns True if isolation occurs; otherwise, false.
*/
isolate (objects: VIM.IObject[], source: string) {
isolate (objects: VIM.Object3D[], source: string) {
if (!this._settings.isolation.enable) return

if (this._isolation) {
Expand All @@ -115,7 +115,7 @@ export class Isolation {
*/
toggleIsolation (source: string) {
if (!this._settings.isolation.enable) return
const selection = [...this._viewer.selection.objects]
const selection = [...this._viewer.selection.objects].filter(o => o.type === 'Object3D') as VIM.Object3D[]

if (this._isolation) {
this._lastIsolation = this._isolation
Expand Down Expand Up @@ -157,11 +157,11 @@ export class Isolation {
* @param objects An array of objects to be removed from isolation.
* @param source The source of the removal operation.
*/
hide (objects: VIM.IObject[], source: string) {
hide (objects: VIM.Object3D[], source: string) {
if (!this._settings.isolation.enable) return
const selection = new Set(objects)
const initial = this._isolation ?? this._viewer.vims[0].getObjects()
const result: VIM.IObject[] = []
const result: VIM.Object3D[] = []
for (const obj of initial) {
if (!selection.has(obj)) result.push(obj)
}
Expand All @@ -176,7 +176,7 @@ export class Isolation {
* @param objects An array of objects to be added to isolation.
* @param source The source of the addition operation.
*/
show (objects: VIM.IObject[], source: string) {
show (objects: VIM.Object3D[], source: string) {
if (!this._settings.isolation.enable) return
const isolation = this._isolation ?? []
objects.forEach((o) => isolation.push(o))
Expand Down Expand Up @@ -226,7 +226,7 @@ export class Isolation {
private _isolate (
viewer: VIM.Viewer,
settings: ComponentSettings,
objects: VIM.IObject[]
objects: VIM.Object3D[]
) {
let useIsolation = false
if (!objects) {
Expand Down
14 changes: 9 additions & 5 deletions src/panels/contextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ export function VimContextMenu (props: {
camera: ComponentCamera
help: HelpState
isolation: Isolation
selection: VIM.IObject[]
selection: VIM.Object3D[]
customization?: (e: ContextMenuElement[]) => ContextMenuElement[]
treeRef: React.MutableRefObject<TreeActionRef>
}) {
const getSelection = () => {
return [...props.viewer.selection.objects].filter(o => o.type === 'Object3D') as VIM.Object3D[]
}

const viewer = props.viewer
const camera = props.camera
const [section, setSection] = useState<{
Expand Down Expand Up @@ -158,26 +162,26 @@ export function VimContextMenu (props: {

const onSelectionIsolateBtn = (e: ClickCallback) => {
props.isolation.isolate(
[...viewer.selection.objects],
getSelection(),
'contextMenu'
)
props.viewer.selection.clear()
e.stopPropagation()
}

const onSelectSimilarBtn = (e: ClickCallback) => {
const o = [...viewer.selection.objects][0]
const o = getSelection()[0]
props.treeRef.current.selectSiblings(o)
e.stopPropagation()
}

const onSelectionHideBtn = (e: ClickCallback) => {
props.isolation.hide([...viewer.selection.objects], 'contextMenu')
props.isolation.hide(getSelection(), 'contextMenu')
e.stopPropagation()
}

const onSelectionShowBtn = (e: ClickCallback) => {
props.isolation.show([...viewer.selection.objects], 'contextMenu')
props.isolation.show(getSelection(), 'contextMenu')
e.stopPropagation()
}

Expand Down
12 changes: 7 additions & 5 deletions src/viewerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ import { AugmentedElement, getElements } from './helpers/element'

export type ViewerState = {
vim: VIM.Vim
selection: VIM.Object[]
selection: VIM.Object3D[]
elements: AugmentedElement[]
}

export function useViewerState (viewer: VIM.Viewer) {
const getVim = () => {
return viewer.selection.vim ?? viewer.vims[0]
}
const getSelection = () => {
return [...viewer.selection.objects].filter(o => o.type === 'Object3D') as VIM.Object3D[]
}

const [vim, setVim] = useState<VIM.Vim>(getVim())
const [selection, setSelection] = useState<VIM.IObject[]>([
...viewer.selection.objects
])
const [selection, setSelection] = useState<VIM.Object3D[]>(getSelection())
const [elements, setElements] = useState<AugmentedElement[]>([])
const vimConnection = useRef<() =>void>()

Expand All @@ -29,7 +30,8 @@ export function useViewerState (viewer: VIM.Viewer) {
const subLoad = viewer.onVimLoaded.subscribe(() => setVim(getVim()))
const subSelect = viewer.selection.onValueChanged.subscribe(() => {
setVim(getVim())
setSelection([...viewer.selection.objects])
// Only architectural objects are supported
setSelection(getSelection())
})

// Clean up
Expand Down

0 comments on commit 615f13f

Please sign in to comment.