Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setCustomFavoritePropertiesManager();
// __PUBLISH_EXTRACT_START__ Presentation.Frontend.Initialization
Presentation.initialize({
// specify `clientId` so Presentation framework can share caches
// between sessions for the same clients
clientId: MyAppFrontend.getClientId(),
// specify locale for localizing presentation data
activeLocale: IModelApp.i18n.languageList()[0],
});
// __PUBLISH_EXTRACT_END__
// __PUBLISH_EXTRACT_START__ Presentation.Frontend.SetSelectionScope
Presentation.selection.scopes.activeScope = "top-assembly";
// __PUBLISH_EXTRACT_END__
readyPromises.push(UiCore.initialize(IModelApp.i18n));
readyPromises.push(UiComponents.initialize(IModelApp.i18n));
this._ready = Promise.all(readyPromises).then(() => { });
}
public static setActiveSelectionScope(selectionScopeId: string): void {
// istanbul ignore else
if (UiFramework.frameworkState) {
const foundIndex = UiFramework.frameworkState.sessionState.availableSelectionScopes.findIndex((selectionScope: PresentationSelectionScope) => selectionScope.id === selectionScopeId);
if (-1 !== foundIndex) {
const scope = UiFramework.frameworkState.sessionState.availableSelectionScopes[foundIndex];
UiFramework.dispatchActionToStore(SessionStateActionId.SetSelectionScope, scope.id);
Presentation.selection.scopes.activeScope = scope.id;
}
}
}
(iModelConnection.iModelToken && iModelConnection.iModelToken.iModelId) ? UiFramework.setActiveIModelId(iModelConnection.iModelToken.iModelId) : "";
if (SyncUiEventDispatcher._unregisterListenerFunc)
SyncUiEventDispatcher._unregisterListenerFunc();
// listen for changes from presentation rules selection manager (this is done once an iModelConnection is available to ensure Presentation.selection is valid)
SyncUiEventDispatcher._unregisterListenerFunc = Presentation.selection.selectionChange.addListener((args: SelectionChangeEventArgs, provider: ISelectionProvider) => {
if (args.level !== 0) {
// don't need to handle sub-selections
return;
}
const selection = provider.getSelection(args.imodel, args.level);
const numSelected = getInstancesCount(selection);
UiFramework.dispatchActionToStore(SessionStateActionId.SetNumItemsSelected, numSelected);
});
Presentation.selection.scopes.getSelectionScopes(iModelConnection).then((availableScopes: SelectionScope[]) => { // tslint:disable-line:no-floating-promises
// istanbul ignore else
if (availableScopes) {
const presentationScopes: PresentationSelectionScope[] = [];
availableScopes.map((scope) => presentationScopes.push(scope));
UiFramework.dispatchActionToStore(SessionStateActionId.SetAvailableSelectionScopes, presentationScopes);
}
});
const activeSelectionScope = Presentation.selection.scopes.activeScope;
if (activeSelectionScope) {
if (typeof (activeSelectionScope) === "object") {
UiFramework.dispatchActionToStore(SessionStateActionId.SetSelectionScope, (activeSelectionScope as SelectionScope).id);
} else {
UiFramework.dispatchActionToStore(SessionStateActionId.SetSelectionScope, activeSelectionScope);
}
}
public componentWillUnmount() {
Presentation.selection.selectionChange.removeListener(this._selectionListener);
}
private onRulesetSelected = (rulesetId: string | undefined) => {
if (this.state.imodel)
Presentation.selection.clearSelection("onRulesetChanged", this.state.imodel, 0);
this.tryPreloadHierarchy(this.state.imodel, rulesetId);
this.setState({ currentRulesetId: rulesetId });
}
private _selectAllInstances = async (provider: IPresentationTableDataProvider) => {
const size = await provider.getRowsCount();
const rowPromises = [];
for (let i = 0; i < size; ++i)
rowPromises.push(provider.getRow(i));
const rows = await Promise.all(rowPromises);
const keys = rows.map((r) => provider.getRowKey(r!));
Presentation.selection.addToSelection("app", provider.imodel, keys);
}
await using(this._asyncsTracker.trackAsyncTask(), async (_r) => {
const ids = await Presentation.selection.getHiliteSet(this._imodel);
using(Presentation.selection.suspendIModelToolSelectionSync(this._imodel), (_) => {
imodel.hilited.clear();
let shouldClearSelectionSet = true;
if (ids.models && ids.models.length) {
imodel.hilited.models.addIds(ids.models);
}
if (ids.subCategories && ids.subCategories.length) {
imodel.hilited.subcategories.addIds(ids.subCategories);
}
if (ids.elements && ids.elements.length) {
imodel.hilited.elements.addIds(ids.elements);
imodel.selectionSet.replace(ids.elements);
shouldClearSelectionSet = false;
}
if (shouldClearSelectionSet)
imodel.selectionSet.emptyAll();
private static _checkClassSelected(className: string) {
if (!UiFramework.getIModelConnection())
throw new Error("NavigatorCommands: Undefined iModelConnection");
const selection = Presentation.selection.getSelection(UiFramework.getIModelConnection()!);
return selection.size === 1 && selection.instanceKeys.has(className);
}