Skip to content

Commit

Permalink
feat: improves some methods
Browse files Browse the repository at this point in the history
* core: recieves optional name in FragmentsManager.load()
* front: moves excluded fragmentIdMap from Highlighter.highlight to highlighter.highlighById
  • Loading branch information
HoyosJuan committed Jun 2, 2024
1 parent 5f6a241 commit 55b802a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
5 changes: 4 additions & 1 deletion packages/core/src/fragments/FragmentsManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ export class FragmentsManager extends Component implements Disposable {
data: Uint8Array,
config?: Partial<{
coordinate: boolean;
name: string;
properties: FRAGS.IfcProperties;
relationsMap: RelationsMap;
}>,
) {
const defaultConfig: {
coordinate: boolean;
name?: string;
properties?: FRAGS.IfcProperties;
relationsMap?: RelationsMap;
} = { coordinate: true };
const _config = { ...defaultConfig, ...config };
const { coordinate, properties, relationsMap } = _config;
const { coordinate, name, properties, relationsMap } = _config;
const model = this._loader.import(data);
if (name) model.name = name;
for (const fragment of model.items) {
fragment.group = model;
this.list.set(fragment.id, fragment);
Expand Down
47 changes: 27 additions & 20 deletions packages/front/src/fragments/Highlighter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,32 +155,23 @@ export class Highlighter

const found = group.getFragmentMap([itemID]);

const filtered: FragmentIdMap = {};

for (const fragID in found) {
const ids = found[fragID];
const excludeFrag = exclude[fragID];

for (const id of ids) {
if (!excludeFrag || !excludeFrag.has(id)) {
if (!filtered[fragID]) {
filtered[fragID] = new Set();
}
filtered[fragID].add(id);
}
}
}

await this.highlightByID(name, filtered, removePrevious, zoomToSelection);
await this.highlightByID(
name,
found,
removePrevious,
zoomToSelection,
exclude,
);

return { id: itemID, fragments: found };
}

async highlightByID(
name: string,
ids: FragmentIdMap,
fragmentIdMap: FragmentIdMap,
removePrevious = true,
zoomToSelection = this.zoomToSelection,
exclude: FragmentIdMap = {},
) {
if (!this.enabled) return;

Expand All @@ -195,15 +186,31 @@ export class Highlighter
throw new Error("Color for selection not found!");
}

for (const fragID in ids) {
const filtered: FragmentIdMap = {};

for (const fragID in fragmentIdMap) {
const ids = fragmentIdMap[fragID];
const excludeFrag = exclude[fragID];

for (const id of ids) {
if (!excludeFrag || !excludeFrag.has(id)) {
if (!filtered[fragID]) {
filtered[fragID] = new Set();
}
filtered[fragID].add(id);
}
}
}

for (const fragID in filtered) {
const fragment = fragments.list.get(fragID);
if (!fragment) {
continue;
}
if (!this.selection[name][fragID]) {
this.selection[name][fragID] = new Set<number>();
}
const itemIDs = ids[fragID];
const itemIDs = fragmentIdMap[fragID];
for (const itemID of itemIDs) {
this.selection[name][fragID].add(itemID);
fragment.setColor(color, [itemID]);
Expand Down

0 comments on commit 55b802a

Please sign in to comment.