6
6
import { createContext , useContext , useState } from "react" ;
7
7
import { StatusBarSection } from "@itwin/appui-react" ;
8
8
import { SvgSelection , SvgVisibilityShow } from "@itwin/itwinui-icons-react" ;
9
- import { IconButton } from "@itwin/itwinui-react" ;
9
+ import { IconButton , Select } from "@itwin/itwinui-react" ;
10
+ import { Presentation } from "@itwin/presentation-frontend" ;
10
11
12
+ import type { SelectionScopesManager } from "@itwin/presentation-frontend" ;
11
13
import type { PropsWithChildren } from "react" ;
12
14
import type { UiItemsProvider } from "@itwin/appui-react" ;
13
15
@@ -57,6 +59,12 @@ export const statusBarActionsProvider: UiItemsProvider = {
57
59
itemPriority : 2 ,
58
60
section : StatusBarSection . Left ,
59
61
} ,
62
+ {
63
+ id : `selectionScopeSelectorButton` ,
64
+ content : < SelectionScopeSelectorButton /> ,
65
+ itemPriority : 3 ,
66
+ section : StatusBarSection . Left ,
67
+ } ,
60
68
] ,
61
69
} ;
62
70
@@ -77,3 +85,61 @@ function ToggleTreeNodesSelectionButton() {
77
85
</ IconButton >
78
86
) ;
79
87
}
88
+
89
+ function SelectionScopeSelectorButton ( ) {
90
+ const [ activeScope , setActiveScope ] = useState ( getScopeId ( Presentation . selection . scopes . activeScope ) ) ;
91
+ return (
92
+ < Select
93
+ options = { Object . entries ( scopes ) . map ( ( [ key , { label } ] ) => ( {
94
+ value : key ,
95
+ label,
96
+ } ) ) }
97
+ value = { activeScope }
98
+ onChange = { ( value ) => {
99
+ const scopeId = value as keyof typeof scopes ;
100
+ setActiveScope ( scopeId ) ;
101
+ // TODO: Viewer should allow specifying the active selection scope without using `Presentation.selection`
102
+ Presentation . selection . scopes . activeScope = scopes [ scopeId ] . props ;
103
+ } }
104
+ />
105
+ ) ;
106
+ }
107
+ function getScopeId ( scopeArg : SelectionScopesManager [ "activeScope" ] ) : keyof typeof scopes {
108
+ if ( ! scopeArg ) {
109
+ return "element" ;
110
+ }
111
+ if ( typeof scopeArg === "string" ) {
112
+ return scopeArg as keyof typeof scopes ;
113
+ }
114
+ if ( scopeArg . id === "element" && "ancestorLevel" in scopeArg ) {
115
+ if ( scopeArg . ancestorLevel === 1 ) {
116
+ return "assembly" ;
117
+ }
118
+ if ( scopeArg . ancestorLevel === 2 ) {
119
+ return "top-assembly" ;
120
+ }
121
+ }
122
+ return scopeArg . id as keyof typeof scopes ;
123
+ }
124
+ const scopes = {
125
+ element : {
126
+ props : { id : "element" } ,
127
+ label : "Element" ,
128
+ } ,
129
+ assembly : {
130
+ props : { id : "element" , ancestorLevel : 1 } ,
131
+ label : "Assembly" ,
132
+ } ,
133
+ "top-assembly" : {
134
+ props : { id : "element" , ancestorLevel : 2 } ,
135
+ label : "Top assembly" ,
136
+ } ,
137
+ model : {
138
+ props : { id : "model" } ,
139
+ label : "Model" ,
140
+ } ,
141
+ category : {
142
+ props : { id : "category" } ,
143
+ label : "Category" ,
144
+ } ,
145
+ } ;
0 commit comments