Skip to content

fix(SingleThreadedFragmentsModel): apply common fragments model interface#227

Open
ShaMan123 wants to merge 9 commits into
ThatOpen:mainfrom
ShaMan123:feat/model-interface
Open

fix(SingleThreadedFragmentsModel): apply common fragments model interface#227
ShaMan123 wants to merge 9 commits into
ThatOpen:mainfrom
ShaMan123:feat/model-interface

Conversation

@ShaMan123

@ShaMan123 ShaMan123 commented May 30, 2026

Copy link
Copy Markdown
Contributor

Description

closes #216

  • drop redundant async directives
  • BREAKING: rename SingleThreadedFragmentsModel#getItemsWithGeometry to getItemsIdsWithGeometry for compat with FragmentsModel exposed getItemsIdsWithGeometry and deprecated getItemsWithGeometry
  • exposed getItemsVolume

Additional context

Misalignments — methods present in one class but absent (or internal) in the other

  • In FragmentsModel only (missing from SingleThreadedFragmentsModel):
    • getGuids() — VirtualFragmentsModel exposes this but SingleThreaded does not.
    • getItemsWithGeometryCategories() — same situation.
    • getItemsIdsWithGeometry() — FragmentsModel only.
    • getCoordinationMatrix() — FragmentsModel only.
    • getMergedBox() / getBoxes() — FragmentsModel only.
    • getAlignments() / getHorizontalAlignments() / getVerticalAlignments() / getAlignmentStyles() — FragmentsModel only.
    • getGrids() / getGridMaterial() / setGridMaterial() / getGridLabelMaterial() / setGridLabelMaterial() — FragmentsModel only.
    • useCamera() / setLodMode() — FragmentsModel only.
    • raycast() / raycastAll() / raycastWithSnapping() / rectangleRaycast() — FragmentsModel only.
    • setVisible() / toggleVisible() / resetVisible() / getVisible() / getItemsByVisibility() — FragmentsModel only.
    • highlight() / setColor() / resetColor() / setOpacity() / resetOpacity() — FragmentsModel only.
    • getHighlight() / resetHighlight() / getHighlightItemIds() — FragmentsModel only.
    • getItemsMaterialDefinition() — FragmentsModel only.
    • getAttributesUniqueValues() — FragmentsModel only.
    • getEditedElements() — FragmentsModel only.
    • getItemsVolume() — FragmentsModel only.
    • getAttributeNames() / getAttributeValues() / getAttributeTypes() / getRelationNames() — FragmentsModel only.
    • getGeometries() — FragmentsModel only.
    • getItem() — FragmentsModel only.
  • In SingleThreadedFragmentsModel only (absent or internal in FragmentsModel):
    • edit() — public in SingleThreaded; FragmentsModel exposes _edit() (internal) and routes edits through the Editor class.
    • reset() / save() — same; _reset() / _save() are internal in FragmentsModel.
    • undo() / redo() — SingleThreaded only; no equivalent in FragmentsModel.
    • getRequests() / setRequests() / selectRequest() — SingleThreaded only; _getRequests() etc. are internal in FragmentsModel.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following:

  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Follow the Conventional Commits v1.0.0 standard for PR naming (e.g. feat(examples): add hello-world example).
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@ShaMan123

Copy link
Copy Markdown
Contributor Author

Methods that can be added to SingleThreadedFragmentsModel

  getGuids() {
    return this._virtualModel.getGuids();
  }

  getItemsWithGeometryCategories() {
    return this._virtualModel.getItemsWithGeometryCategories();
  }

  getItemsVolume(localIds: number[]) {
    return this._virtualModel.getItemsVolume(localIds);
  }

  getAttributeNames() {
    return this._virtualModel.getAttributeNames();
  }

  getAttributeValues() {
    return this._virtualModel.getAttributeValues();
  }

  getAttributeTypes() {
    return this._virtualModel.getAttributeTypes();
  }

  getRelationNames() {
    return this._virtualModel.getRelationNames();
  }

  getAttributesUniqueValues(params: AttributesUniqueValuesParams[]) {
    return this._virtualModel.getAttributesUniqueValues(params);
  }

  getItemsMaterialDefinition(localIds: number[]) {
    return this._virtualModel.getItemsMaterialDefinition(localIds);
  }

  getMergedBox(localIds: number[]) {
    return this._virtualModel.getBBoxes(localIds);
  }

  getBoxes(localIds?: number[]) {
    const ids = localIds ?? (this._virtualModel.getLocalIds() as number[]);
    return ids.map((id) => this._virtualModel.getBBoxes([id]));
  }

  setLodMode(lodMode: LodMode) {
    this._virtualModel.setLodMode(lodMode);
  }

@ShaMan123 ShaMan123 force-pushed the feat/model-interface branch from 9e82a89 to 40961c6 Compare May 30, 2026 09:13
@ShaMan123 ShaMan123 force-pushed the feat/model-interface branch from c99c6db to c428f5a Compare May 30, 2026 09:28

@ShaMan123 ShaMan123 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • drop redundant async directives
  • BREAKING: rename SingleThreadedFragmentsModel#getItemsWithGeometry to getItemsWithGeometry for compat with FragmentsModel
  • exposed getItemsVolume

* @param localIds - The local IDs of the items to look up.
*/
getPositions(localIds: number[]) {
getPositions(localIds?: number[]) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed signature, non breaking

@ShaMan123 ShaMan123 changed the title fix(): apply common fragments model interface fix()!: apply common fragments model interface May 30, 2026
@ShaMan123 ShaMan123 changed the title fix()!: apply common fragments model interface fix(SingleThreadedFragmentsModel)!: apply common fragments model interface May 30, 2026
@ShaMan123 ShaMan123 marked this pull request as ready for review May 30, 2026 09:36

@ShaMan123 ShaMan123 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for review
Regarding file/interface naming please suggest to desired pattern so I can align with standards.

@ShaMan123

Copy link
Copy Markdown
Contributor Author

Should IModelSerializer methods return Uint8Array only?

@ShaMan123 ShaMan123 changed the title fix(SingleThreadedFragmentsModel)!: apply common fragments model interface fix!(SingleThreadedFragmentsModel): apply common fragments model interface Jun 1, 2026
@agviegas

agviegas commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for pushing this through, the Promisify<T, Async> split is clean and it's exactly the shared contract we discussed in #220. I want to land it, with one constraint: we don't ship breaking changes outside of a planned major with explicit sign-off. The good news is every breaking bit here has an additive equivalent, so we can get the same interface in as a feature now.

Two things to reshape:

getItemsWithGeometry rename. You're right that the current method returns ids, so getItemsIdsWithGeometry is the honest name. But renaming it outright breaks anyone calling it today. Instead of renaming, let's keep getItemsWithGeometry in place, tag it @deprecated pointing at the new name, and add getItemsIdsWithGeometry alongside it with the same body. Both work, the old one nudges people to migrate, and we drop it in the next major.

getCoordinates return type. Let's not re-type the existing method. A 9-tuple is assignable to number[] so most reads keep compiling, but it's still a visible signature change and it can break reassignment cases, so I'd rather hold the line. Keep getCoordinates(): number[] as is (type it as number[] in the interface too). If you want the strict Matrix3Tuple, add it as a separate method.

Everything else is good to go:

  • The delegation methods you listed (getGuids, getItemsWithGeometryCategories, getItemsVolume, getAttributeNames/Values/Types, getRelationNames, getAttributesUniqueValues, getItemsMaterialDefinition, getMergedBox, getBoxes, setLodMode) are all additive, please add them to close the misalignments.
  • Dropping async off the delegating methods is fine; they still return promises through the managers.
  • The applyChangesToIds rewrite is fine. It's internal, and the guard you removed was dead code since requests is always an array.

On your question: should IModelSerializer return Uint8Array only? Today getBuffer returns an ArrayBuffer when raw is true and a Uint8Array (from pako.deflate) when false, so the union type is accurate to what actually comes back. Standardizing on Uint8Array would mean wrapping the raw path, which changes the return shape for current raw consumers, so it's a breaking change. I'd keep the union here and queue the Uint8Array normalization for the next major, where we can also drop the deprecated method above.

@ShaMan123 ShaMan123 changed the title fix!(SingleThreadedFragmentsModel): apply common fragments model interface fix(SingleThreadedFragmentsModel): apply common fragments model interface Jun 9, 2026
@ShaMan123

ShaMan123 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

See the last commit with requested changes.
I prefer not to add anything to this PR, merge it and open a follow up with the added methods. Who knows? Maybe there will be some discussion about what should or shouldn't be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate FragmentsModel / SingleThreadedFragmentsModel return types

2 participants