Skip to content

New datamodels#50

Open
josemmo wants to merge 19 commits into
mainfrom
feat/new-datamodels
Open

New datamodels#50
josemmo wants to merge 19 commits into
mainfrom
feat/new-datamodels

Conversation

@josemmo

@josemmo josemmo commented May 26, 2026

Copy link
Copy Markdown
Contributor

Introduces new datamodels to represent Cadwork elements and the currently project, namely:

  • compas_cadwork.Project (new class)
  • compas_cadwork.elements.Element (deprecates compas_cadwork.datamodel.Element)

It also creates the compas_cadwork.IfcUUID helper class to represent IFC GUID, adds unit tests that mock the Cadwork API, and deprecates legacy classes and functions.

@josemmo josemmo added T: Feature Type: New feature or enhancement O: Requires rebasing Other: Must be rebased on main before it can be merged labels May 26, 2026
@josemmo josemmo added this to the v1.0.0 milestone May 26, 2026
@josemmo josemmo force-pushed the feat/new-datamodels branch from 0cc33eb to aec1ae5 Compare May 27, 2026 13:27
@gonzalocasas

Copy link
Copy Markdown
Member

@josemmo maybe you can set the base of this PR to be feat/switch-to-uv, so that the diff is correct. Once the first one is merged, github will automatically reassign the base to main

@josemmo

josemmo commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@gonzalocasas Neat! I was waiting to merge that first one, but this is better.

@josemmo josemmo changed the base branch from main to feat/switch-to-uv June 1, 2026 13:56
@josemmo josemmo requested a review from Copilot June 2, 2026 07:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Introduces new datamodels (Project, elements.Element) along with a generic KeyValueStorage abstraction, an IfcUUID helper, Cadwork↔COMPAS converter helpers, and a comprehensive pytest suite that mocks the Cadwork API. Existing datamodel/scene/storage/conversion APIs are marked with @deprecated to steer consumers to the new modules.

Changes:

  • New compas_cadwork.Project and compas_cadwork.elements.Element classes built on a generic KeyValueStorage/IterableKeyValueStorage for attributes/data, plus a new IfcUUID helper for Base64-compressed IFC GUIDs.
  • New unit tests with a CadworkMocks fixture in tests/conftest.py that injects mocked Cadwork modules into sys.modules.
  • Legacy APIs (datamodel, scene, storage, conversions) annotated with @deprecated from typing_extensions.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/compas_cadwork/init.py Re-exports Project.
src/compas_cadwork/project.py New Project datamodel with attribute/data accessors.
src/compas_cadwork/elements/init.py Re-exports Element.
src/compas_cadwork/elements/element.py New Element class wrapping Cadwork element APIs.
src/compas_cadwork/utils/init.py Re-exports IfcUUID.
src/compas_cadwork/utils/ifc_uuid.py IfcUUID with Base64-compressed encoding.
src/compas_cadwork/utils/storage.py Generic KeyValueStorage / IterableKeyValueStorage mixins.
src/compas_cadwork/utils/converters.py New point/vector ↔ Cadwork converters.
src/compas_cadwork/conversions/primitives.py Existing converters marked @deprecated.
src/compas_cadwork/datamodel/element.py Element, ElementGroup, ElementGroupingType marked @deprecated.
src/compas_cadwork/datamodel/dimension.py AnchorPoint, Dimension marked @deprecated.
src/compas_cadwork/scene/{scene,beamobject,camera,instructionobject}.py Scene objects/types marked @deprecated.
src/compas_cadwork/storage.py Storage classes marked @deprecated.
src/compas_cadwork/utilities/{events,ifc_export}.py Helpers marked @deprecated.
tests/conftest.py Adds CadworkMocks fixture stubbing Cadwork modules.
tests/compas_cadwork/test_project.py Unit tests for Project.
tests/compas_cadwork/elements/test_element.py Unit tests for Element.
tests/compas_cadwork/utils/test_ifc_uuid.py Tests for IFC Base64 encoding.
tests/compas_cadwork/utils/test_storage.py Tests for storage abstractions.
tests/test_placeholder.py Removed placeholder test.
CHANGELOG.md Records the new classes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/compas_cadwork/elements/element.py

@gonzalocasas gonzalocasas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can't comment much on the cadwork data model change itself, but I think we should reconsider the drift from conventions like the conversions stuff and maybe also scene

from typing_extensions import deprecated


@deprecated("Use compas_cadwork.utils.converters.compas_to_cwpoint instead")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wait... this goes against the convention in compas that all conversions are under conversions and are in the form of [element_or_class_name]_to_[target_environment_or_compas] so point_to_cadwork matches point_to_rhino and conversely, there would be a. point_to_compas inside cadwork that defines the cadwork to compas conversion.

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.

Ahh, I see. In that case, we should put the conversions in compas_cadwork.conversions.

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.

Addressed in 79c4b05.

@@ -0,0 +1,130 @@
from abc import abstractmethod

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should be more top-level, not a 3-level nested utility

@josemmo josemmo Jun 10, 2026

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.

The compas_cadwork.utils.storage is an internal helper module that provides the functionality needed for the Element.attributes, Element.attribute_names, Element.data, Project.attributes, Project.attribute_names, and Project.data properties. It is not meant to be used by end-users. In fact, we don't export it in "src/compas_cadwork/utils/__init__.py".

We can move it to "src/compas_cadwork/internal/storage.py" or to a different namespace if that helps.

Comment thread src/compas_cadwork/utils/__init__.py Outdated
@@ -0,0 +1,6 @@
from .ifc_uuid import IfcUUID

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I generally don't like to have utils or utilities packages, because they tend to degrade into trash containers for everything that has not a better place in the library. In this case, we would be keeping two of them (one being 100% deprecated), why not keep at least the utilities container instead of creating utils?

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.

Fair point. I put the new modules in compas_cadwork.utils to make it clear for library users to know which modules are being deprecated, and because "utils" is fairly more common than "utilities" for Python projects.

Another option related to the previous comment would be to ditch the "utils" module and just put the class at compas_cadwork.ifc_uuid. Would that work?

@josemmo josemmo Jun 24, 2026

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.

Addressed in 3cd093a.

Comment on lines +8 to +9
_K = TypeVar("_K")
_V = TypeVar("_V")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Neat generics-like syntax!

from compas_cadwork.utils.converters import cwpoint_to_point
from compas_cadwork.utils.converters import cwpoint_to_vector
from compas_cadwork.utils.ifc_uuid import IfcUUID
from compas_cadwork.utils.storage import KeyValueStorage

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since the data model is based on this, why not make it more prominent and move to compas_cadwork.storage import ... or similar?

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.

This one I didn't understand, sorry 😅
Could you elaborate?

@josemmo josemmo force-pushed the feat/new-datamodels branch from 82329ea to 6316a12 Compare June 24, 2026 07:37
@josemmo josemmo force-pushed the feat/new-datamodels branch from 3cd093a to fad004c Compare June 24, 2026 11:37
@josemmo josemmo changed the base branch from feat/switch-to-uv to main June 24, 2026 11:38
@josemmo josemmo removed the O: Requires rebasing Other: Must be rebased on main before it can be merged label Jun 24, 2026
@josemmo josemmo marked this pull request as ready for review June 24, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T: Feature Type: New feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants