Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async computeSelection(imodel: IModelConnection, ids: Id64Arg, scope: SelectionScope | string): Promise {
const scopeId = getScopeId(scope);
// convert ids input to array
if (typeof ids === "string")
ids = [ids];
else if (ids instanceof Set)
ids = [...ids];
// compute selection in batches to avoid HTTP 413
const keys = new KeySet();
const batchSize = DEFAULT_KEYS_BATCH_SIZE;
const batchesCount = Math.ceil(ids.length / batchSize);
const batchKeyPromises = [];
for (let batchIndex = 0; batchIndex < batchesCount; ++batchIndex) {
const batchStart = batchSize * batchIndex;
const batchEnd = (batchStart + batchSize > ids.length) ? ids.length : (batchStart + batchSize);
const batchIds = (0 === batchIndex && ids.length <= batchEnd) ? ids : ids.slice(batchStart, batchEnd);
batchKeyPromises.push(this._rpcRequestsHandler.computeSelection({ imodel: imodel.iModelToken }, batchIds, scopeId));
}
const batchKeys = (await Promise.all(batchKeyPromises)).map(KeySet.fromJSON);
batchKeys.forEach((bk) => keys.add(bk));
return keys;
}
}
private async doCreateContent(rulesetId: string, instanceKeys: InstanceKey[], displayType: string): Promise {
const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider(this._iModel, rulesetId, displayType);
dataProvider.keys = new KeySet(instanceKeys);
const content = await dataProvider.getContent();
if (!content)
return [];
const records: PropertyRecord[] = [];
const sortedFields = content.descriptor.fields.sort((f1, f2) => {
if (f1.name > f2.name)
return -1;
if (f1.name < f2.name)
return 1;
return 0;
});
for (const field of sortedFields) {
private computeCategorySelection(requestOptions: SelectionScopeRequestOptions, ids: Id64String[]) {
const categoryKeys = new KeySet();
ids.forEach(skipTransients((id) => {
const el = requestOptions.imodel.elements.getElement(id);
if (el instanceof GeometricElement) {
const category = requestOptions.imodel.elements.getElementProps(el.category);
categoryKeys.add({ className: category.classFullName, id: category.id! });
}
}));
return categoryKeys;
}
private getSelectedKeys(selectionLevel?: number): KeySet | undefined {
if (undefined === selectionLevel) {
const availableLevels = this._selectionHandler!.getSelectionLevels();
if (0 === availableLevels.length)
return undefined;
selectionLevel = availableLevels[availableLevels.length - 1];
}
for (let i = selectionLevel; i >= 0; i--) {
const selection = this._selectionHandler!.getSelection(i);
if (!selection.isEmpty)
return new KeySet(selection);
}
return new KeySet();
}
private computeElementSelection(requestOptions: SelectionScopeRequestOptions, ids: Id64String[]) {
const keys = new KeySet();
ids.forEach(skipTransients((id) => {
const key = this.getElementKey(requestOptions.imodel, id);
if (key)
keys.add(key);
}));
return keys;
}
public clearSelection(source: string, imodel: IModelConnection, level: number = 0, rulesetId?: string): void {
const evt: SelectionChangeEventArgs = {
source,
level,
imodel,
changeType: SelectionChangeType.Clear,
keys: new KeySet(),
timestamp: new Date(),
rulesetId,
};
this.handleEvent(evt);
}
private getKeysForContentRequest(imodel: IModelDb, keys: KeySet): KeySet {
const elementClassName = "BisCore:Element";
const instanceKeys = keys.instanceKeys;
if (!instanceKeys.has(elementClassName))
return keys;
const elementIds = instanceKeys.get(elementClassName)!;
const keyset = new KeySet();
keyset.add(keys);
elementIds.forEach((elementId) => {
const concreteKey = this.getElementKey(imodel, elementId);
if (concreteKey) {
keyset.delete({ className: elementClassName, id: elementId });
keyset.add(concreteKey);
}
});
return keyset;
}
}
private async computeFunctionalElementSelection(requestOptions: SelectionScopeRequestOptions, ids: Id64String[]) {
const keys = new KeySet();
const nonTransientIds = new Array();
ids.forEach(skipTransients((id) => {
nonTransientIds.push(id);
}));
const query = `
SELECT e.ECClassId, e.ECInstanceId elId, funcSchemaDef.Name || '.' || funcClassDef.Name funcElClassName, fe.ECInstanceId funcElId
FROM bis.Element e
LEFT JOIN func.PhysicalElementFulfillsFunction rel1 ON rel1.SourceECInstanceId = e.ECInstanceId
LEFT JOIN func.DrawingGraphicRepresentsFunctionalElement rel2 ON rel2.SourceECInstanceId = e.ECInstanceId
LEFT JOIN func.FunctionalElement fe ON fe.ECInstanceId IN (rel1.TargetECInstanceId, rel2.TargetECInstanceId)
LEFT JOIN meta.ECClassDef funcClassDef ON funcClassDef.ECInstanceId = fe.ECClassId
LEFT JOIN meta.ECSchemaDef funcSchemaDef ON funcSchemaDef.ECInstanceId = funcClassDef.Schema.Id
WHERE e.ECInstanceId IN (${nonTransientIds.map(() => "?").join(",")})
`;
const iter = requestOptions.imodel.query(query, nonTransientIds);
for await (const row of iter) {