Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 89f4c75cc9 | |||
| d20f7ea82a | |||
| 2e44a891e8 | |||
| edce76491f | |||
| ecbd0eab09 | |||
| b17423b282 | |||
| 166b0f5e87 | |||
| cac34120a9 | |||
| 55c4c68cf3 | |||
| be850d5ea9 | |||
| c9a5badac1 | |||
| 118fa07e37 | |||
| d71b616e2b | |||
| 35750f12c5 | |||
| 5730cdcb43 | |||
| 82b6dbbe78 | |||
| 883be4b27b | |||
| 37e2711a76 | |||
| 8dcc67fb31 | |||
| ed84820995 | |||
| 5c3dcb7bc0 | |||
| 92732e3c76 | |||
| 903951547d | |||
| 82c3dc9ffb | |||
| a0e10aae99 | |||
| bbea2a0d76 | |||
| a05ac3479b | |||
| 0bd972945e | |||
| f200544065 | |||
| 68ce9823ae | |||
| a920352407 | |||
| 24bfb6718e | |||
| e63f4b8636 | |||
| 47c6bd89af |
@@ -2,7 +2,7 @@ repos:
|
|||||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
rev: v0.1.6
|
rev: v0.8.2
|
||||||
|
|
||||||
- repo: https://github.com/commitizen-tools/commitizen
|
- repo: https://github.com/commitizen-tools/commitizen
|
||||||
hooks:
|
hooks:
|
||||||
@@ -13,12 +13,12 @@ repos:
|
|||||||
rev: v3.13.0
|
rev: v3.13.0
|
||||||
|
|
||||||
- repo: https://github.com/pycqa/isort
|
- repo: https://github.com/pycqa/isort
|
||||||
rev: 5.12.0
|
rev: 5.13.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: isort
|
- id: isort
|
||||||
|
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 23.11.0
|
rev: 24.10.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
# It is recommended to specify the latest version of Python
|
# It is recommended to specify the latest version of Python
|
||||||
|
|||||||
Vendored
+3
-5
@@ -4,11 +4,9 @@
|
|||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Python: Current File",
|
"name": "Python: Current File",
|
||||||
"type": "python",
|
"type": "debugpy",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${file}",
|
"program": "${file}",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
@@ -16,9 +14,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Pytest",
|
"name": "Pytest",
|
||||||
"type": "python",
|
"type": "debugpy",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "pytest",
|
"module": "pytest",
|
||||||
"args": [],
|
"args": [],
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"justMyCode": true
|
"justMyCode": true
|
||||||
|
|||||||
Generated
+745
-710
File diff suppressed because it is too large
Load Diff
+8
-8
@@ -15,7 +15,7 @@ packages = [
|
|||||||
|
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = ">=3.8.0, <4.0"
|
python = ">=3.10.0, <4.0"
|
||||||
pydantic = "^2.5"
|
pydantic = "^2.5"
|
||||||
appdirs = "^1.4.4"
|
appdirs = "^1.4.4"
|
||||||
gql = { extras = ["requests", "websockets"], version = "^3.3.0" }
|
gql = { extras = ["requests", "websockets"], version = "^3.3.0" }
|
||||||
@@ -24,21 +24,22 @@ Deprecated = "^1.2.13"
|
|||||||
stringcase = "^1.2.0"
|
stringcase = "^1.2.0"
|
||||||
attrs = "^23.1.0"
|
attrs = "^23.1.0"
|
||||||
httpx = "^0.25.0"
|
httpx = "^0.25.0"
|
||||||
|
pydantic-settings = "^2.6.1"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
black = "23.11.0"
|
black = "24.10.0"
|
||||||
isort = "^5.7.0"
|
isort = "^5.13.2"
|
||||||
pytest = "^7.1.3"
|
pytest = "^7.1.3"
|
||||||
pytest-asyncio = "^0.23.0"
|
pytest-asyncio = "^0.23.0"
|
||||||
pytest-ordering = "^0.6"
|
pytest-ordering = "^0.6"
|
||||||
pytest-cov = "^3.0.0"
|
pytest-cov = "^3.0.0"
|
||||||
devtools = "^0.8.0"
|
devtools = "^0.8.0"
|
||||||
pylint = "^2.14.4"
|
pylint = "^3.3.2"
|
||||||
pydantic-settings = "^2.3.0"
|
pydantic-settings = "^2.3.0"
|
||||||
mypy = "^0.982"
|
mypy = "^0.982"
|
||||||
pre-commit = "^2.20.0"
|
pre-commit = "^2.20.0"
|
||||||
commitizen = "^2.38.0"
|
commitizen = "^3.13.0"
|
||||||
ruff = "^0.4.4"
|
ruff = "^0.8.2"
|
||||||
types-deprecated = "^1.2.9"
|
types-deprecated = "^1.2.9"
|
||||||
types-ujson = "^5.6.0.0"
|
types-ujson = "^5.6.0.0"
|
||||||
types-requests = "^2.28.11.5"
|
types-requests = "^2.28.11.5"
|
||||||
@@ -60,8 +61,7 @@ exclude = '''
|
|||||||
'''
|
'''
|
||||||
include = '\.pyi?$'
|
include = '\.pyi?$'
|
||||||
line-length = 88
|
line-length = 88
|
||||||
target-version = ["py37", "py38", "py39", "py310", "py311"]
|
target-version = ["py39", "py310", "py311", "py312", "py313"]
|
||||||
|
|
||||||
|
|
||||||
[tool.commitizen]
|
[tool.commitizen]
|
||||||
name = "cz_conventional_commits"
|
name = "cz_conventional_commits"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Some useful helpers for working with automation data."""
|
"""Some useful helpers for working with automation data."""
|
||||||
|
|
||||||
import secrets
|
import secrets
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
|||||||
@@ -61,15 +61,13 @@ def _parse_input_data(
|
|||||||
def execute_automate_function(
|
def execute_automate_function(
|
||||||
automate_function: AutomateFunction[T],
|
automate_function: AutomateFunction[T],
|
||||||
input_schema: type[T],
|
input_schema: type[T],
|
||||||
) -> None:
|
) -> None: ...
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def execute_automate_function(
|
def execute_automate_function(
|
||||||
automate_function: AutomateFunctionWithoutInputs,
|
automate_function: AutomateFunctionWithoutInputs,
|
||||||
) -> None:
|
) -> None: ...
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
class AutomateGenerateJsonSchema(GenerateJsonSchema):
|
class AutomateGenerateJsonSchema(GenerateJsonSchema):
|
||||||
@@ -146,16 +144,14 @@ def run_function(
|
|||||||
automation_context: AutomationContext,
|
automation_context: AutomationContext,
|
||||||
automate_function: AutomateFunction[T],
|
automate_function: AutomateFunction[T],
|
||||||
inputs: T,
|
inputs: T,
|
||||||
) -> AutomationContext:
|
) -> AutomationContext: ...
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def run_function(
|
def run_function(
|
||||||
automation_context: AutomationContext,
|
automation_context: AutomationContext,
|
||||||
automate_function: AutomateFunctionWithoutInputs,
|
automate_function: AutomateFunctionWithoutInputs,
|
||||||
) -> AutomationContext:
|
) -> AutomationContext: ...
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
def run_function(
|
def run_function(
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
from specklepy import objects
|
# from specklepy import objects
|
||||||
|
|
||||||
__all__ = ["objects"]
|
# __all__ = ["objects"]
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ from specklepy.api.resources import (
|
|||||||
OtherUserResource,
|
OtherUserResource,
|
||||||
ProjectInviteResource,
|
ProjectInviteResource,
|
||||||
ProjectResource,
|
ProjectResource,
|
||||||
|
ServerResource,
|
||||||
SubscriptionResource,
|
SubscriptionResource,
|
||||||
VersionResource,
|
VersionResource,
|
||||||
branch,
|
branch,
|
||||||
commit,
|
commit,
|
||||||
object,
|
object,
|
||||||
server,
|
|
||||||
stream,
|
stream,
|
||||||
subscriptions,
|
subscriptions,
|
||||||
user,
|
user,
|
||||||
@@ -69,7 +69,7 @@ class SpeckleClient(CoreSpeckleClient):
|
|||||||
self.account = Account()
|
self.account = Account()
|
||||||
|
|
||||||
def _init_resources(self) -> None:
|
def _init_resources(self) -> None:
|
||||||
self.server = server.Resource(
|
self.server = ServerResource(
|
||||||
account=self.account, basepath=self.url, client=self.httpclient
|
account=self.account, basepath=self.url, client=self.httpclient
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ from typing import List, Optional, overload
|
|||||||
|
|
||||||
from deprecated import deprecated
|
from deprecated import deprecated
|
||||||
|
|
||||||
from specklepy.core.api.inputs.project_inputs import UserProjectsFilter
|
from specklepy.core.api.inputs.user_inputs import UserProjectsFilter, UserUpdateInput
|
||||||
from specklepy.core.api.inputs.user_inputs import UserUpdateInput
|
|
||||||
from specklepy.core.api.models import (
|
from specklepy.core.api.models import (
|
||||||
PendingStreamCollaborator,
|
PendingStreamCollaborator,
|
||||||
Project,
|
Project,
|
||||||
@@ -44,12 +43,10 @@ class ActiveUserResource(CoreResource):
|
|||||||
company: Optional[str] = None,
|
company: Optional[str] = None,
|
||||||
bio: Optional[str] = None,
|
bio: Optional[str] = None,
|
||||||
avatar: Optional[str] = None,
|
avatar: Optional[str] = None,
|
||||||
) -> User:
|
) -> User: ...
|
||||||
...
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def update(self, *, input: UserUpdateInput) -> User:
|
def update(self, *, input: UserUpdateInput) -> User: ...
|
||||||
...
|
|
||||||
|
|
||||||
def update(
|
def update(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ from specklepy.api.resources import ServerResource
|
|||||||
from specklepy.core.api.models.deprecated import FE1_DEPRECATION_VERSION
|
from specklepy.core.api.models.deprecated import FE1_DEPRECATION_VERSION
|
||||||
|
|
||||||
|
|
||||||
@deprecated(reason="Renamed to ActiveUserResource", version=FE1_DEPRECATION_VERSION)
|
@deprecated(reason="Renamed to ServerResource", version=FE1_DEPRECATION_VERSION)
|
||||||
class Resource(ServerResource):
|
class Resource(ServerResource):
|
||||||
"""Renamed to ServerResource"""
|
"""Renamed to ServerResource"""
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
from specklepy.core.api.inputs.model_inputs import (
|
||||||
|
CreateModelInput,
|
||||||
|
DeleteModelInput,
|
||||||
|
ModelVersionsFilter,
|
||||||
|
UpdateModelInput,
|
||||||
|
)
|
||||||
|
from specklepy.core.api.inputs.project_inputs import (
|
||||||
|
ProjectCreateInput,
|
||||||
|
ProjectInviteCreateInput,
|
||||||
|
ProjectInviteUseInput,
|
||||||
|
ProjectModelsFilter,
|
||||||
|
ProjectUpdateInput,
|
||||||
|
ProjectUpdateRoleInput,
|
||||||
|
)
|
||||||
|
from specklepy.core.api.inputs.user_inputs import UserProjectsFilter, UserUpdateInput
|
||||||
|
from specklepy.core.api.inputs.version_inputs import (
|
||||||
|
CreateVersionInput,
|
||||||
|
DeleteVersionsInput,
|
||||||
|
MarkReceivedVersionInput,
|
||||||
|
MoveVersionsInput,
|
||||||
|
UpdateVersionInput,
|
||||||
|
)
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"CreateModelInput",
|
||||||
|
"DeleteModelInput",
|
||||||
|
"UpdateModelInput",
|
||||||
|
"ModelVersionsFilter",
|
||||||
|
"ProjectCreateInput",
|
||||||
|
"ProjectInviteCreateInput",
|
||||||
|
"ProjectInviteUseInput",
|
||||||
|
"ProjectModelsFilter",
|
||||||
|
"ProjectUpdateInput",
|
||||||
|
"ProjectUpdateRoleInput",
|
||||||
|
"UserProjectsFilter",
|
||||||
|
"UserUpdateInput",
|
||||||
|
"UpdateVersionInput",
|
||||||
|
"MoveVersionsInput",
|
||||||
|
"DeleteVersionsInput",
|
||||||
|
"CreateVersionInput",
|
||||||
|
"MarkReceivedVersionInput",
|
||||||
|
]
|
||||||
@@ -45,8 +45,3 @@ class ProjectUpdateRoleInput(BaseModel):
|
|||||||
userId: str
|
userId: str
|
||||||
projectId: str
|
projectId: str
|
||||||
role: Optional[str]
|
role: Optional[str]
|
||||||
|
|
||||||
|
|
||||||
class UserProjectsFilter(BaseModel):
|
|
||||||
search: str
|
|
||||||
onlyWithRole: Optional[Sequence[str]] = None
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Optional
|
from typing import Optional, Sequence
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
@@ -8,3 +8,8 @@ class UserUpdateInput(BaseModel):
|
|||||||
bio: Optional[str] = None
|
bio: Optional[str] = None
|
||||||
company: Optional[str] = None
|
company: Optional[str] = None
|
||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class UserProjectsFilter(BaseModel):
|
||||||
|
search: str
|
||||||
|
onlyWithRoles: Optional[Sequence[str]] = None
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ from specklepy.core.api.models.deprecated import (
|
|||||||
Stream,
|
Stream,
|
||||||
Streams,
|
Streams,
|
||||||
)
|
)
|
||||||
from specklepy.core.api.models.instances import InstanceDefinitionProxy, InstanceProxy
|
|
||||||
from specklepy.core.api.models.proxies import ColorProxy, GroupProxy
|
|
||||||
from specklepy.core.api.models.subscription_messages import (
|
from specklepy.core.api.models.subscription_messages import (
|
||||||
ProjectModelsUpdatedMessage,
|
ProjectModelsUpdatedMessage,
|
||||||
ProjectUpdatedMessage,
|
ProjectUpdatedMessage,
|
||||||
@@ -70,8 +68,4 @@ __all__ = [
|
|||||||
"Streams",
|
"Streams",
|
||||||
"Activity",
|
"Activity",
|
||||||
"ActivityCollection",
|
"ActivityCollection",
|
||||||
"InstanceProxy",
|
|
||||||
"InstanceDefinitionProxy",
|
|
||||||
"ColorProxy",
|
|
||||||
"GroupProxy",
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
from specklepy.objects.base import Base
|
|
||||||
|
|
||||||
|
|
||||||
class InstanceProxy(
|
|
||||||
Base,
|
|
||||||
speckle_type="Speckle.Core.Models.Instances.InstanceProxy",
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
A proxy class for an instance (e.g, a rhino block, or an autocad block reference).
|
|
||||||
"""
|
|
||||||
|
|
||||||
definitionId: str
|
|
||||||
transform: list[float]
|
|
||||||
units: str
|
|
||||||
maxDepth: int
|
|
||||||
|
|
||||||
|
|
||||||
class InstanceDefinitionProxy(
|
|
||||||
Base,
|
|
||||||
speckle_type="Speckle.Core.Models.Instances.InstanceDefinitionProxy",
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
A proxy class for an instance definition.
|
|
||||||
"""
|
|
||||||
|
|
||||||
objects: list[str]
|
|
||||||
maxDepth: int
|
|
||||||
name: str
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
from specklepy.objects.base import Base
|
|
||||||
|
|
||||||
|
|
||||||
class ColorProxy(
|
|
||||||
Base,
|
|
||||||
speckle_type="Speckle.Core.Models.Proxies.ColorProxy",
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Represents a color that is found on objects and collections in a root collection.
|
|
||||||
"""
|
|
||||||
|
|
||||||
objects: list[str]
|
|
||||||
value: int
|
|
||||||
name: str | None # nullable but required
|
|
||||||
|
|
||||||
|
|
||||||
class GroupProxy(
|
|
||||||
Base,
|
|
||||||
speckle_type="Speckle.Core.Models.Proxies.GroupProxy",
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Grouped objects with a meaningful way for host application so use this proxy if you want to group object references for any purpose.
|
|
||||||
i.e. in rhino -> creating group make objects selectable/moveable/editable together.
|
|
||||||
"""
|
|
||||||
|
|
||||||
objects: list[str]
|
|
||||||
name: str
|
|
||||||
@@ -4,8 +4,7 @@ from typing import List, Optional, overload
|
|||||||
from deprecated import deprecated
|
from deprecated import deprecated
|
||||||
from gql import gql
|
from gql import gql
|
||||||
|
|
||||||
from specklepy.core.api.inputs.project_inputs import UserProjectsFilter
|
from specklepy.core.api.inputs.user_inputs import UserProjectsFilter, UserUpdateInput
|
||||||
from specklepy.core.api.inputs.user_inputs import UserUpdateInput
|
|
||||||
from specklepy.core.api.models import (
|
from specklepy.core.api.models import (
|
||||||
ActivityCollection,
|
ActivityCollection,
|
||||||
PendingStreamCollaborator,
|
PendingStreamCollaborator,
|
||||||
@@ -100,12 +99,10 @@ class ActiveUserResource(ResourceBase):
|
|||||||
company: Optional[str] = None,
|
company: Optional[str] = None,
|
||||||
bio: Optional[str] = None,
|
bio: Optional[str] = None,
|
||||||
avatar: Optional[str] = None,
|
avatar: Optional[str] = None,
|
||||||
) -> User:
|
) -> User: ...
|
||||||
...
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def update(self, *, input: UserUpdateInput) -> User:
|
def update(self, *, input: UserUpdateInput) -> User: ...
|
||||||
...
|
|
||||||
|
|
||||||
def update(
|
def update(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -127,9 +127,11 @@ class ModelResource(ResourceBase):
|
|||||||
"modelId": model_id,
|
"modelId": model_id,
|
||||||
"versionsLimit": versions_limit,
|
"versionsLimit": versions_limit,
|
||||||
"versionsCursor": versions_cursor,
|
"versionsCursor": versions_cursor,
|
||||||
"versionsFilter": versions_filter.model_dump(warnings="error")
|
"versionsFilter": (
|
||||||
if versions_filter
|
versions_filter.model_dump(warnings="error")
|
||||||
else None,
|
if versions_filter
|
||||||
|
else None
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.make_request_and_parse_response(
|
return self.make_request_and_parse_response(
|
||||||
@@ -179,9 +181,9 @@ class ModelResource(ResourceBase):
|
|||||||
"projectId": project_id,
|
"projectId": project_id,
|
||||||
"modelsLimit": models_limit,
|
"modelsLimit": models_limit,
|
||||||
"modelsCursor": models_cursor,
|
"modelsCursor": models_cursor,
|
||||||
"modelsFilter": models_filter.model_dump(warnings="error")
|
"modelsFilter": (
|
||||||
if models_filter
|
models_filter.model_dump(warnings="error") if models_filter else None
|
||||||
else None,
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.make_request_and_parse_response(
|
return self.make_request_and_parse_response(
|
||||||
|
|||||||
@@ -108,9 +108,9 @@ class ProjectResource(ResourceBase):
|
|||||||
"projectId": project_id,
|
"projectId": project_id,
|
||||||
"modelsLimit": models_limit,
|
"modelsLimit": models_limit,
|
||||||
"modelsCursor": models_cursor,
|
"modelsCursor": models_cursor,
|
||||||
"modelsFilter": models_filter.model_dump(warnings="error")
|
"modelsFilter": (
|
||||||
if models_filter
|
models_filter.model_dump(warnings="error") if models_filter else None
|
||||||
else None,
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.make_request_and_parse_response(
|
return self.make_request_and_parse_response(
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class Resource(ResourceBase):
|
|||||||
query = gql(
|
query = gql(
|
||||||
"""
|
"""
|
||||||
query User($stream_limit: Int!) {
|
query User($stream_limit: Int!) {
|
||||||
user {
|
activeUser {
|
||||||
id
|
id
|
||||||
bio
|
bio
|
||||||
name
|
name
|
||||||
@@ -149,7 +149,7 @@ class Resource(ResourceBase):
|
|||||||
params = {"stream_limit": stream_limit}
|
params = {"stream_limit": stream_limit}
|
||||||
|
|
||||||
return self.make_request(
|
return self.make_request(
|
||||||
query=query, params=params, return_type=["user", "streams", "items"]
|
query=query, params=params, return_type=["activeUser", "streams", "items"]
|
||||||
)
|
)
|
||||||
|
|
||||||
@deprecated(reason=FE1_DEPRECATION_REASON, version=FE1_DEPRECATION_VERSION)
|
@deprecated(reason=FE1_DEPRECATION_REASON, version=FE1_DEPRECATION_VERSION)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Provides uniform and consistent path helpers for `specklepy`
|
Provides uniform and consistent path helpers for `specklepy`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
"""Builtin Speckle object kit."""
|
|
||||||
|
|
||||||
from specklepy.objects import encoding, geometry, other, primitive, units
|
|
||||||
from specklepy.objects.base import Base
|
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
"Base",
|
|
||||||
"encoding",
|
|
||||||
"geometry",
|
|
||||||
"other",
|
|
||||||
"units",
|
|
||||||
"primitive",
|
|
||||||
]
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
|
from dataclasses import dataclass, field
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from inspect import isclass
|
from inspect import isclass
|
||||||
from typing import (
|
from typing import (
|
||||||
@@ -18,8 +19,7 @@ from warnings import warn
|
|||||||
|
|
||||||
from stringcase import pascalcase
|
from stringcase import pascalcase
|
||||||
|
|
||||||
from specklepy.logging.exceptions import SpeckleException, SpeckleInvalidUnitException
|
from specklepy.logging.exceptions import SpeckleException
|
||||||
from specklepy.objects.units import Units
|
|
||||||
from specklepy.transports.memory import MemoryTransport
|
from specklepy.transports.memory import MemoryTransport
|
||||||
|
|
||||||
PRIMITIVES = (int, float, str, bool)
|
PRIMITIVES = (int, float, str, bool)
|
||||||
@@ -65,7 +65,6 @@ REMOVE_FROM_DIR = {
|
|||||||
"_handle_object_count",
|
"_handle_object_count",
|
||||||
"_type_check",
|
"_type_check",
|
||||||
"_type_registry",
|
"_type_registry",
|
||||||
"_units",
|
|
||||||
"add_chunkable_attrs",
|
"add_chunkable_attrs",
|
||||||
"add_detachable_attrs",
|
"add_detachable_attrs",
|
||||||
"get_children_count",
|
"get_children_count",
|
||||||
@@ -116,7 +115,7 @@ class _RegisteringBase:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _determine_speckle_type(cls) -> str:
|
def _determine_speckle_type(cls) -> str:
|
||||||
"""
|
"""
|
||||||
This method brings the speckle_type construction in par with peckle-sharp/Core.
|
This method brings the speckle_type construction in par with Speckle-sharp/Core.
|
||||||
|
|
||||||
The implementation differs, because in Core the basis of the speckle_type if
|
The implementation differs, because in Core the basis of the speckle_type if
|
||||||
type.FullName, which includes the dotnet namespace name too.
|
type.FullName, which includes the dotnet namespace name too.
|
||||||
@@ -168,8 +167,11 @@ class _RegisteringBase:
|
|||||||
initialization. This is reused to register each subclassing type into a class
|
initialization. This is reused to register each subclassing type into a class
|
||||||
level dictionary.
|
level dictionary.
|
||||||
"""
|
"""
|
||||||
|
# if not speckle_type:
|
||||||
|
# raise Exception("no type")
|
||||||
cls._speckle_type_override = speckle_type
|
cls._speckle_type_override = speckle_type
|
||||||
cls.speckle_type = cls._determine_speckle_type()
|
cls.speckle_type = cls._determine_speckle_type()
|
||||||
|
# cls.speckle_type = speckle_type
|
||||||
if cls._full_name() in cls._type_registry:
|
if cls._full_name() in cls._type_registry:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"The speckle_type: {speckle_type} is already registered for type: "
|
f"The speckle_type: {speckle_type} is already registered for type: "
|
||||||
@@ -319,22 +321,17 @@ def _validate_type(t: Optional[type], value: Any) -> Tuple[bool, Any]:
|
|||||||
return False, value
|
return False, value
|
||||||
|
|
||||||
|
|
||||||
class Base(_RegisteringBase):
|
@dataclass(kw_only=True)
|
||||||
|
class Base(_RegisteringBase, speckle_type="Base"):
|
||||||
id: Union[str, None] = None
|
id: Union[str, None] = None
|
||||||
totalChildrenCount: Union[int, None] = None
|
# totalChildrenCount: Union[int, None] = None
|
||||||
applicationId: Union[str, None] = None
|
applicationId: Union[str, None] = None
|
||||||
_units: Union[None, str] = None
|
|
||||||
|
|
||||||
def __init__(self, **kwargs) -> None:
|
|
||||||
super().__init__()
|
|
||||||
for k, v in kwargs.items():
|
|
||||||
self.__setattr__(k, v)
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return (
|
return (
|
||||||
f"{self.__class__.__name__}(id: {self.id}, "
|
f"{self.__class__.__name__}(id: {self.id}, "
|
||||||
f"speckle_type: {self.speckle_type}, "
|
f"speckle_type: {self.speckle_type}, "
|
||||||
f"totalChildrenCount: {self.totalChildrenCount})"
|
# f"totalChildrenCount: {self.totalChildrenCount})"
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
@@ -462,21 +459,21 @@ class Base(_RegisteringBase):
|
|||||||
"""
|
"""
|
||||||
self._detachable = self._detachable.union(names)
|
self._detachable = self._detachable.union(names)
|
||||||
|
|
||||||
@property
|
# @property
|
||||||
def units(self) -> Union[str, None]:
|
# def units(self) -> Union[str, None]:
|
||||||
return self._units
|
# return self._units
|
||||||
|
|
||||||
@units.setter
|
# @units.setter
|
||||||
def units(self, value: Union[str, Units, None]):
|
# def units(self, value: Union[str, Units, None]):
|
||||||
"""While this property accepts any string value, geometry expects units to be specific strings (see Units enum)"""
|
# """While this property accepts any string value, geometry expects units to be specific strings (see Units enum)"""
|
||||||
if isinstance(value, str) or value is None:
|
# if isinstance(value, str) or value is None:
|
||||||
self._units = value
|
# self._units = value
|
||||||
elif isinstance(value, Units):
|
# elif isinstance(value, Units):
|
||||||
self._units = value.value
|
# self._units = value.value
|
||||||
else:
|
# else:
|
||||||
raise SpeckleInvalidUnitException(
|
# raise SpeckleInvalidUnitException(
|
||||||
f"Unknown type {type(value)} received for units"
|
# f"Unknown type {type(value)} received for units"
|
||||||
)
|
# )
|
||||||
|
|
||||||
def get_member_names(self) -> List[str]:
|
def get_member_names(self) -> List[str]:
|
||||||
"""Get all of the property names on this object, dynamic or not"""
|
"""Get all of the property names on this object, dynamic or not"""
|
||||||
@@ -568,9 +565,6 @@ class Base(_RegisteringBase):
|
|||||||
Base.update_forward_refs()
|
Base.update_forward_refs()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
class DataChunk(Base, speckle_type="Speckle.Core.Models.DataChunk"):
|
class DataChunk(Base, speckle_type="Speckle.Core.Models.DataChunk"):
|
||||||
data: Union[List[Any], None] = None
|
data: List[Any] = field(default_factory=list)
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
super().__init__()
|
|
||||||
self.data = []
|
|
||||||
|
|||||||
+231
-905
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,110 @@
|
|||||||
|
from abc import ABCMeta, abstractmethod
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import Generic, List, TypeVar
|
||||||
|
|
||||||
|
from specklepy.logging.exceptions import SpeckleInvalidUnitException
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
from specklepy.objects.models.units import Units
|
||||||
|
from specklepy.objects.primitive import Interval
|
||||||
|
|
||||||
|
T = TypeVar("T") # define type variable for generic type
|
||||||
|
|
||||||
|
|
||||||
|
# generic interfaces
|
||||||
|
class ICurve(metaclass=ABCMeta):
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def length(self) -> float:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def _domain(self) -> Interval:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def units(self) -> str:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class IDisplayValue(Generic[T], metaclass=ABCMeta):
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def display_value(self) -> T:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
|
class IHasUnits(metaclass=ABCMeta):
|
||||||
|
units: str | Units
|
||||||
|
_units: str = field(repr=False, init=False)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def units(self) -> str:
|
||||||
|
return self._units
|
||||||
|
|
||||||
|
@units.setter
|
||||||
|
def units(self, value: str | Units):
|
||||||
|
if isinstance(value, str):
|
||||||
|
self._units = value
|
||||||
|
elif isinstance(value, Units):
|
||||||
|
self._units = value.value
|
||||||
|
else:
|
||||||
|
raise SpeckleInvalidUnitException(
|
||||||
|
f"Unknown type {type(value)} received for units"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
|
class IHasArea(metaclass=ABCMeta):
|
||||||
|
area: float
|
||||||
|
_area: float = field(init=False, repr=False)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def area(self) -> float:
|
||||||
|
return self._area
|
||||||
|
|
||||||
|
@area.setter
|
||||||
|
def area(self, value: float):
|
||||||
|
if not isinstance(value, (int, float)):
|
||||||
|
raise ValueError(f"Area must be a number, got {type(value)}")
|
||||||
|
self._area = float(value)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
|
class IHasVolume(metaclass=ABCMeta):
|
||||||
|
volume: float
|
||||||
|
_volume: float = field(init=False, repr=False)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def volume(self) -> float:
|
||||||
|
return self._volume
|
||||||
|
|
||||||
|
@volume.setter
|
||||||
|
def volume(self, value: float):
|
||||||
|
if not isinstance(value, (int, float)):
|
||||||
|
raise ValueError(f"Volume must be a number, got {type(value)}")
|
||||||
|
self._volume = float(value)
|
||||||
|
|
||||||
|
|
||||||
|
# data object interfaces
|
||||||
|
class IProperties(metaclass=ABCMeta):
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def properties(self) -> dict[str, object]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class IDataObject(IProperties, IDisplayValue[List[Base]], metaclass=ABCMeta):
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def name(self) -> str:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class IBlenderObject(IDataObject, metaclass=ABCMeta):
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def type(self) -> str:
|
||||||
|
pass
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
|
class Collection(
|
||||||
|
Base,
|
||||||
|
# TODO: add deprecated speckle_types
|
||||||
|
speckle_type="Speckle.Core.Models.Collections.Collection",
|
||||||
|
detachable={"elements"},
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
A simple container for organising objects within a model and preserving object hierarchy.
|
||||||
|
|
||||||
|
A container is defined by a human-readable name a unique applicationId and its list of contained elements.
|
||||||
|
The elements can include an unrestricted number of Base objects including additional nested Collections.
|
||||||
|
|
||||||
|
Note:
|
||||||
|
A Collection can be for example a Layer in Rhino/AutoCad, a collection in Blender, or a Category in Revit.
|
||||||
|
The location of each collection in the hierarchy of collections in a commit will be retrieved through commit traversal.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
name: The human-readable name of the Collection. This name is not necessarily unique within a commit. Set the applicationId for a unique identifier.
|
||||||
|
elements: The elements contained in this Collection. This may include additional nested Collections
|
||||||
|
"""
|
||||||
|
|
||||||
|
name: str
|
||||||
|
elements: List[Base] = field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
c = Collection(name="asfd")
|
||||||
|
print(c)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class ISpeckleObject(speckle_type="ISpeckleObjects", metaclass=ABCMeta):
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def id(self) -> str | None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def application_id(self) -> str | None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def speckle_type(self) -> str:
|
||||||
|
pass
|
||||||
@@ -1,25 +1,28 @@
|
|||||||
from typing import Any, List
|
from dataclasses import dataclass
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from specklepy.objects.base import Base
|
from specklepy.objects.base import Base
|
||||||
|
|
||||||
NAMESPACE = "Objects.Primitive"
|
|
||||||
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
|
class Interval(Base, speckle_type="Objects.Primitive.Interval"):
|
||||||
|
start: float = 0.0 # Added default
|
||||||
|
end: float = 0.0 # Added default
|
||||||
|
|
||||||
class Interval(Base, speckle_type=f"{NAMESPACE}.Interval"):
|
@property
|
||||||
start: float = 0.0
|
def length(self) -> float:
|
||||||
end: float = 0.0
|
return abs(self.end - self.start)
|
||||||
|
|
||||||
def length(self):
|
def __str__(self) -> str:
|
||||||
return abs(self.start - self.end)
|
return f"{super().__str__()}[{self.start}, {self.end}]"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_list(cls, args: List[Any]) -> "Interval":
|
def unit_interval(cls) -> "Interval":
|
||||||
return cls(start=args[0], end=args[1])
|
return cls(start=0, end=1)
|
||||||
|
|
||||||
def to_list(self) -> List[Any]:
|
def to_list(self) -> List[float]:
|
||||||
return [self.start, self.end]
|
return [self.start, self.end]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
class Interval2d(Base, speckle_type=f"{NAMESPACE}.Interval2d"):
|
def from_list(cls, args: List[float]) -> "Interval":
|
||||||
u: Interval
|
return cls(start=args[0], end=args[1])
|
||||||
v: Interval
|
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
from specklepy.objects.interfaces import IHasUnits
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
|
class ColorProxy(
|
||||||
|
Base,
|
||||||
|
speckle_type="Models.Proxies.ColorProxy",
|
||||||
|
detachable={"objects"},
|
||||||
|
):
|
||||||
|
objects: List[str] = field(default_factory=list)
|
||||||
|
value: int
|
||||||
|
name: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
|
class GroupProxy(
|
||||||
|
Base,
|
||||||
|
speckle_type="Models.Proxies.GroupProxy",
|
||||||
|
detachable={"objects"},
|
||||||
|
):
|
||||||
|
objects: List[str] = field(default_factory=list)
|
||||||
|
name: str = field(default="Unnamed Group")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
|
class InstanceProxy(
|
||||||
|
Base,
|
||||||
|
IHasUnits,
|
||||||
|
speckle_type="Models.Proxies.InstanceProxy",
|
||||||
|
):
|
||||||
|
definition_id: str
|
||||||
|
transform: List[float] = field(default_factory=list)
|
||||||
|
max_depth: int = 50
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
|
class InstanceDefinitionProxy(
|
||||||
|
Base,
|
||||||
|
speckle_type="Models.Proxies.InstanceDefinitionProxy",
|
||||||
|
detachable={"objects"},
|
||||||
|
):
|
||||||
|
objects: List[str] = field(default_factory=list)
|
||||||
|
max_depth: int = 50
|
||||||
|
name: str = field(default="Unnamed Instance")
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
from devtools import debug
|
||||||
|
|
||||||
|
from specklepy.api.operations import deserialize, serialize
|
||||||
|
from specklepy.objects.geometry import Line, Point
|
||||||
|
from specklepy.objects.models.units import Units
|
||||||
|
from specklepy.objects.primitive import Interval
|
||||||
|
|
||||||
|
# points
|
||||||
|
p1 = Point(x=1.0, y=2.0, z=3.0, units=Units.m)
|
||||||
|
p2 = Point(x=4.0, y=6.0, z=8.0, units=Units.m, applicationId="asdf")
|
||||||
|
|
||||||
|
|
||||||
|
# test Line
|
||||||
|
line = Line(start=p1, end=p2, units=Units.m, domain=Interval(start=0.0, end=1.0))
|
||||||
|
|
||||||
|
print(f"\nLine length: {line.length}")
|
||||||
|
|
||||||
|
ser_line = serialize(line)
|
||||||
|
line_again = deserialize(ser_line)
|
||||||
|
|
||||||
|
print("\nOriginal line:")
|
||||||
|
debug(line)
|
||||||
|
print("\nSerialized line:")
|
||||||
|
debug(ser_line)
|
||||||
|
print("\nDeserialized line:")
|
||||||
|
debug(line_again)
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
from devtools import debug
|
||||||
|
|
||||||
|
from specklepy.api.operations import deserialize, serialize
|
||||||
|
from specklepy.objects.geometry import Mesh
|
||||||
|
|
||||||
|
# create a speckle cube mesh (but more colorful)
|
||||||
|
vertices = [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
]
|
||||||
|
|
||||||
|
# define faces (triangles)
|
||||||
|
faces = [
|
||||||
|
3,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
7,
|
||||||
|
3,
|
||||||
|
0,
|
||||||
|
4,
|
||||||
|
7,
|
||||||
|
3,
|
||||||
|
0,
|
||||||
|
7,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
6,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
6,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
6,
|
||||||
|
7,
|
||||||
|
3,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
3,
|
||||||
|
0,
|
||||||
|
5,
|
||||||
|
4,
|
||||||
|
]
|
||||||
|
|
||||||
|
# create colors (one per vertex)
|
||||||
|
colors = [
|
||||||
|
255,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
255,
|
||||||
|
0,
|
||||||
|
255,
|
||||||
|
0,
|
||||||
|
255,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
0,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
0,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
0,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
255,
|
||||||
|
]
|
||||||
|
|
||||||
|
texture_coordinates = [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
]
|
||||||
|
|
||||||
|
# create the mesh
|
||||||
|
cube_mesh = Mesh(
|
||||||
|
vertices=vertices,
|
||||||
|
faces=faces,
|
||||||
|
colors=colors,
|
||||||
|
textureCoordinates=texture_coordinates,
|
||||||
|
units="mm",
|
||||||
|
area=0.0,
|
||||||
|
volume=0.0,
|
||||||
|
)
|
||||||
|
|
||||||
|
print("\nMesh Details:")
|
||||||
|
print(f"Number of vertices: {cube_mesh.vertices_count}")
|
||||||
|
print(f"Number of texture coordinates: {cube_mesh.texture_coordinates_count}")
|
||||||
|
|
||||||
|
print("\nSome vertex points:")
|
||||||
|
for i in range(4):
|
||||||
|
point = cube_mesh.get_point(i)
|
||||||
|
print(f"Vertex {i}: ({point.x}, {point.y}, {point.z})")
|
||||||
|
|
||||||
|
print("\nSome texture coordinates:")
|
||||||
|
for i in range(4):
|
||||||
|
u, v = cube_mesh.get_texture_coordinate(i)
|
||||||
|
print(f"Texture coordinate {i}: ({u}, {v})")
|
||||||
|
|
||||||
|
print("\nTesting serialization...")
|
||||||
|
ser_mesh = serialize(cube_mesh)
|
||||||
|
mesh_again = deserialize(ser_mesh)
|
||||||
|
|
||||||
|
print("\nOriginal mesh:")
|
||||||
|
debug(cube_mesh)
|
||||||
|
print("\nDeserialized mesh:")
|
||||||
|
debug(mesh_again)
|
||||||
|
|
||||||
|
print("\nTesting vertex-texture coordinate alignment...")
|
||||||
|
cube_mesh.align_vertices_with_texcoords_by_index()
|
||||||
|
print("Alignment complete.")
|
||||||
|
|
||||||
|
print(f"Vertices count after alignment: {cube_mesh.vertices_count}")
|
||||||
|
print(
|
||||||
|
f"Texture coordinates count after alignment: {cube_mesh.texture_coordinates_count}"
|
||||||
|
)
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
from devtools import debug
|
||||||
|
|
||||||
|
from specklepy.api.operations import deserialize, serialize
|
||||||
|
from specklepy.objects.geometry import Point
|
||||||
|
from specklepy.objects.models.units import Units
|
||||||
|
|
||||||
|
# test points
|
||||||
|
p1 = Point(x=1.0, y=2.0, z=3.0, units=Units.m)
|
||||||
|
p2 = Point(x=4.0, y=6.0, z=8.0, units=Units.m, applicationId="asdf")
|
||||||
|
|
||||||
|
print("Distance between points:", p1.distance_to(p2))
|
||||||
|
|
||||||
|
ser_p1 = serialize(p1)
|
||||||
|
p1_again = deserialize(ser_p1)
|
||||||
|
|
||||||
|
print("\nOriginal point:")
|
||||||
|
debug(p1)
|
||||||
|
print("\nSerialized point:")
|
||||||
|
debug(ser_p1)
|
||||||
|
print("\nDeserialized point:")
|
||||||
|
debug(p1_again)
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
from devtools import debug
|
||||||
|
|
||||||
|
from specklepy.api.operations import deserialize, serialize
|
||||||
|
from specklepy.objects.geometry import Polyline
|
||||||
|
from specklepy.objects.models.units import Units
|
||||||
|
from specklepy.objects.primitive import Interval
|
||||||
|
|
||||||
|
# create points for first polyline - not closed, in meters
|
||||||
|
points1_coords = [1.0, 1.0, 0.0, 2.0, 1.0, 0.0, 2.0, 2.0, 0.0, 1.0, 2.0, 0.0]
|
||||||
|
|
||||||
|
# Create points for second polyline - closed, in ft
|
||||||
|
points2_coords = [0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 3.0, 3.0, 0.0, 0.0, 3.0, 0.0]
|
||||||
|
|
||||||
|
# create polylines
|
||||||
|
polyline1 = Polyline(
|
||||||
|
value=points1_coords,
|
||||||
|
closed=False,
|
||||||
|
units=Units.m,
|
||||||
|
domain=Interval(start=0.0, end=1.0),
|
||||||
|
)
|
||||||
|
|
||||||
|
polyline2 = Polyline(
|
||||||
|
value=points2_coords,
|
||||||
|
closed=True,
|
||||||
|
units=Units.feet,
|
||||||
|
domain=Interval(start=0.0, end=1.0),
|
||||||
|
applicationId="polyllllineeee",
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Polyline 1 length (meters):", polyline1.length)
|
||||||
|
print("Polyline 2 length (feet):", polyline2.length)
|
||||||
|
|
||||||
|
ser_poly1 = serialize(polyline1)
|
||||||
|
poly1_again = deserialize(ser_poly1)
|
||||||
|
|
||||||
|
print("\nOriginal polyline 1:")
|
||||||
|
debug(polyline1)
|
||||||
|
print("\nSerialized polyline 1:")
|
||||||
|
debug(ser_poly1)
|
||||||
|
print("\nDeserialized polyline 1:")
|
||||||
|
debug(poly1_again)
|
||||||
|
|
||||||
|
ser_poly2 = serialize(polyline2)
|
||||||
|
poly2_again = deserialize(ser_poly2)
|
||||||
|
|
||||||
|
print("\nOriginal polyline 2:")
|
||||||
|
debug(polyline2)
|
||||||
|
print("\nSerialized polyline 2:")
|
||||||
|
debug(ser_poly2)
|
||||||
|
print("\nDeserialized polyline 2:")
|
||||||
|
debug(poly2_again)
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
|
||||||
|
|
||||||
|
class CRS(Base, speckle_type="Objects.GIS.CRS"):
|
||||||
|
"""A Coordinate Reference System stored in wkt format"""
|
||||||
|
|
||||||
|
name: Optional[str] = None
|
||||||
|
authority_id: Optional[str] = None
|
||||||
|
wkt: Optional[str] = None
|
||||||
|
units_native: Optional[str] = None
|
||||||
|
offset_x: Optional[float] = None
|
||||||
|
offset_y: Optional[float] = None
|
||||||
|
rotation: Optional[float] = None
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
"""Builtin Speckle object kit."""
|
||||||
|
|
||||||
|
from specklepy.objects.GIS.CRS import CRS
|
||||||
|
from specklepy.objects.GIS.geometry import (
|
||||||
|
GisLineElement,
|
||||||
|
GisPointElement,
|
||||||
|
GisPolygonElement,
|
||||||
|
GisPolygonGeometry,
|
||||||
|
GisRasterElement,
|
||||||
|
PolygonGeometry,
|
||||||
|
)
|
||||||
|
from specklepy.objects.GIS.layers import RasterLayer, VectorLayer
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"VectorLayer",
|
||||||
|
"RasterLayer",
|
||||||
|
"GisPolygonGeometry",
|
||||||
|
"PolygonGeometry",
|
||||||
|
"GisPolygonElement",
|
||||||
|
"GisLineElement",
|
||||||
|
"GisPointElement",
|
||||||
|
"GisRasterElement",
|
||||||
|
"CRS",
|
||||||
|
]
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
from specklepy.objects.geometry import (
|
||||||
|
Arc,
|
||||||
|
Circle,
|
||||||
|
Line,
|
||||||
|
Mesh,
|
||||||
|
Point,
|
||||||
|
Polycurve,
|
||||||
|
Polyline,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PolygonGeometry(Base, speckle_type="Objects.GIS.PolygonGeometry"):
|
||||||
|
"""GIS Polygon Geometry"""
|
||||||
|
|
||||||
|
boundary: Optional[Polyline]
|
||||||
|
voids: Optional[List[Polyline]]
|
||||||
|
|
||||||
|
|
||||||
|
GisPolygonGeometry = PolygonGeometry
|
||||||
|
|
||||||
|
|
||||||
|
class GisPolygonElement(Base, speckle_type="Objects.GIS.PolygonElement"):
|
||||||
|
"""GIS Polygon element"""
|
||||||
|
|
||||||
|
geometry: Optional[List[GisPolygonGeometry]] = None
|
||||||
|
attributes: Optional[Base] = None
|
||||||
|
|
||||||
|
|
||||||
|
class GisLineElement(Base, speckle_type="Objects.GIS.LineElement"):
|
||||||
|
"""GIS Polyline element"""
|
||||||
|
|
||||||
|
geometry: Optional[List[Union[Polyline, Arc, Line, Circle, Polycurve]]] = None
|
||||||
|
attributes: Optional[Base] = None
|
||||||
|
|
||||||
|
|
||||||
|
class GisPointElement(Base, speckle_type="Objects.GIS.PointElement"):
|
||||||
|
"""GIS Point element"""
|
||||||
|
|
||||||
|
geometry: Optional[List[Point]] = None
|
||||||
|
attributes: Optional[Base] = None
|
||||||
|
|
||||||
|
|
||||||
|
class GisRasterElement(
|
||||||
|
Base, speckle_type="Objects.GIS.RasterElement", detachable={"displayValue"}
|
||||||
|
):
|
||||||
|
"""GIS Raster element"""
|
||||||
|
|
||||||
|
band_count: Optional[int] = None
|
||||||
|
band_names: Optional[List[str]] = None
|
||||||
|
x_origin: Optional[float] = None
|
||||||
|
y_origin: Optional[float] = None
|
||||||
|
x_size: Optional[int] = None
|
||||||
|
y_size: Optional[int] = None
|
||||||
|
x_resolution: Optional[float] = None
|
||||||
|
y_resolution: Optional[float] = None
|
||||||
|
noDataValue: Optional[List[float]] = None
|
||||||
|
displayValue: Optional[List[Mesh]] = None
|
||||||
|
|
||||||
|
|
||||||
|
class GisTopography(
|
||||||
|
GisRasterElement,
|
||||||
|
speckle_type="Objects.GIS.GisTopography",
|
||||||
|
detachable={"displayValue"},
|
||||||
|
):
|
||||||
|
"""GIS Raster element with 3d Topography representation"""
|
||||||
|
|
||||||
|
|
||||||
|
class GisNonGeometryElement(Base, speckle_type="Objects.GIS.NonGeometryElement"):
|
||||||
|
"""GIS Table feature"""
|
||||||
|
|
||||||
|
attributes: Optional[Base] = None
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
|
from deprecated import deprecated
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
from specklepy.objects.GIS.CRS import CRS
|
||||||
|
from specklepy.objects.other import Collection
|
||||||
|
|
||||||
|
|
||||||
|
@deprecated(version="2.15", reason="Use VectorLayer or RasterLayer instead")
|
||||||
|
class Layer(Base, detachable={"features"}):
|
||||||
|
"""A GIS Layer"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: Optional[str] = None,
|
||||||
|
crs: Optional[CRS] = None,
|
||||||
|
units: str = "m",
|
||||||
|
features: Optional[List[Base]] = None,
|
||||||
|
layerType: str = "None",
|
||||||
|
geomType: str = "None",
|
||||||
|
renderer: Optional[Dict[str, Any]] = None,
|
||||||
|
**kwargs,
|
||||||
|
) -> None:
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.name = name
|
||||||
|
self.crs = crs
|
||||||
|
self.units = units
|
||||||
|
self.type = layerType
|
||||||
|
self.features = features or []
|
||||||
|
self.geomType = geomType
|
||||||
|
self.renderer = renderer or {}
|
||||||
|
|
||||||
|
|
||||||
|
@deprecated(version="2.16", reason="Use VectorLayer or RasterLayer instead")
|
||||||
|
class VectorLayer(
|
||||||
|
Collection,
|
||||||
|
detachable={"elements"},
|
||||||
|
speckle_type="VectorLayer",
|
||||||
|
serialize_ignore={"features"},
|
||||||
|
):
|
||||||
|
"""GIS Vector Layer"""
|
||||||
|
|
||||||
|
name: Optional[str] = None
|
||||||
|
crs: Optional[Union[CRS, Base]] = None
|
||||||
|
units: Optional[str] = None
|
||||||
|
elements: Optional[List[Base]] = None
|
||||||
|
attributes: Optional[Base] = None
|
||||||
|
geomType: Optional[str] = "None"
|
||||||
|
renderer: Optional[Dict[str, Any]] = None
|
||||||
|
collectionType = "VectorLayer"
|
||||||
|
|
||||||
|
@property
|
||||||
|
@deprecated(version="2.14", reason="Use elements")
|
||||||
|
def features(self) -> Optional[List[Base]]:
|
||||||
|
return self.elements
|
||||||
|
|
||||||
|
@features.setter
|
||||||
|
def features(self, value: Optional[List[Base]]) -> None:
|
||||||
|
self.elements = value
|
||||||
|
|
||||||
|
|
||||||
|
@deprecated(version="2.16", reason="Use VectorLayer or RasterLayer instead")
|
||||||
|
class RasterLayer(
|
||||||
|
Collection,
|
||||||
|
detachable={"elements"},
|
||||||
|
speckle_type="RasterLayer",
|
||||||
|
serialize_ignore={"features"},
|
||||||
|
):
|
||||||
|
"""GIS Raster Layer"""
|
||||||
|
|
||||||
|
name: Optional[str] = None
|
||||||
|
crs: Optional[Union[CRS, Base]] = None
|
||||||
|
units: Optional[str] = None
|
||||||
|
rasterCrs: Optional[Union[CRS, Base]] = None
|
||||||
|
elements: Optional[List[Base]] = None
|
||||||
|
geomType: Optional[str] = "None"
|
||||||
|
renderer: Optional[Dict[str, Any]] = None
|
||||||
|
collectionType = "RasterLayer"
|
||||||
|
|
||||||
|
@property
|
||||||
|
@deprecated(version="2.14", reason="Use elements")
|
||||||
|
def features(self) -> Optional[List[Base]]:
|
||||||
|
return self.elements
|
||||||
|
|
||||||
|
@features.setter
|
||||||
|
def features(self, value: Optional[List[Base]]) -> None:
|
||||||
|
self.elements = value
|
||||||
|
|
||||||
|
|
||||||
|
class VectorLayer( # noqa: F811
|
||||||
|
Collection,
|
||||||
|
detachable={"elements"},
|
||||||
|
speckle_type="Objects.GIS.VectorLayer",
|
||||||
|
serialize_ignore={"features"},
|
||||||
|
):
|
||||||
|
"""GIS Vector Layer"""
|
||||||
|
|
||||||
|
name: Optional[str] = None
|
||||||
|
crs: Optional[Union[CRS, Base]] = None
|
||||||
|
units: Optional[str] = None
|
||||||
|
elements: Optional[List[Base]] = None
|
||||||
|
attributes: Optional[Base] = None
|
||||||
|
geomType: Optional[str] = "None"
|
||||||
|
renderer: Optional[Dict[str, Any]] = None
|
||||||
|
collectionType = "VectorLayer"
|
||||||
|
|
||||||
|
@property
|
||||||
|
@deprecated(version="2.14", reason="Use elements")
|
||||||
|
def features(self) -> Optional[List[Base]]:
|
||||||
|
return self.elements
|
||||||
|
|
||||||
|
@features.setter
|
||||||
|
def features(self, value: Optional[List[Base]]) -> None:
|
||||||
|
self.elements = value
|
||||||
|
|
||||||
|
|
||||||
|
class RasterLayer( # noqa: F811
|
||||||
|
Collection,
|
||||||
|
detachable={"elements"},
|
||||||
|
speckle_type="Objects.GIS.RasterLayer",
|
||||||
|
serialize_ignore={"features"},
|
||||||
|
):
|
||||||
|
"""GIS Raster Layer"""
|
||||||
|
|
||||||
|
name: Optional[str] = None
|
||||||
|
crs: Optional[Union[CRS, Base]] = None
|
||||||
|
units: Optional[str] = None
|
||||||
|
rasterCrs: Optional[Union[CRS, Base]] = None
|
||||||
|
elements: Optional[List[Base]] = None
|
||||||
|
geomType: Optional[str] = "None"
|
||||||
|
renderer: Optional[Dict[str, Any]] = None
|
||||||
|
collectionType = "RasterLayer"
|
||||||
|
|
||||||
|
@property
|
||||||
|
@deprecated(version="2.14", reason="Use elements")
|
||||||
|
def features(self) -> Optional[List[Base]]:
|
||||||
|
return self.elements
|
||||||
|
|
||||||
|
@features.setter
|
||||||
|
def features(self, value: Optional[List[Base]]) -> None:
|
||||||
|
self.elements = value
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
"""Builtin Speckle object kit."""
|
||||||
|
|
||||||
|
# from specklepy.objects import (
|
||||||
|
# GIS,
|
||||||
|
# encoding,
|
||||||
|
# geometry,
|
||||||
|
# other,
|
||||||
|
# primitive,
|
||||||
|
# structural,
|
||||||
|
# units,
|
||||||
|
# )
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"Base",
|
||||||
|
# "encoding",
|
||||||
|
# "geometry",
|
||||||
|
# "other",
|
||||||
|
# "units",
|
||||||
|
# "structural",
|
||||||
|
# "primitive",
|
||||||
|
# "GIS",
|
||||||
|
]
|
||||||
@@ -0,0 +1,588 @@
|
|||||||
|
import contextlib
|
||||||
|
from enum import Enum
|
||||||
|
from inspect import isclass
|
||||||
|
from typing import (
|
||||||
|
Any,
|
||||||
|
ClassVar,
|
||||||
|
Dict,
|
||||||
|
ForwardRef,
|
||||||
|
List,
|
||||||
|
Optional,
|
||||||
|
Set,
|
||||||
|
Tuple,
|
||||||
|
Type,
|
||||||
|
Union,
|
||||||
|
get_type_hints,
|
||||||
|
)
|
||||||
|
from warnings import warn
|
||||||
|
|
||||||
|
from stringcase import pascalcase
|
||||||
|
|
||||||
|
from specklepy.logging.exceptions import SpeckleException, SpeckleInvalidUnitException
|
||||||
|
from specklepy.objects.units import Units
|
||||||
|
from specklepy.transports.memory import MemoryTransport
|
||||||
|
|
||||||
|
PRIMITIVES = (int, float, str, bool)
|
||||||
|
|
||||||
|
# to remove from dir() when calling get_member_names()
|
||||||
|
REMOVE_FROM_DIR = {
|
||||||
|
"Config",
|
||||||
|
"_Base__dict_helper",
|
||||||
|
"__annotations__",
|
||||||
|
"__class__",
|
||||||
|
"__delattr__",
|
||||||
|
"__dict__",
|
||||||
|
"__dir__",
|
||||||
|
"__doc__",
|
||||||
|
"__eq__",
|
||||||
|
"__format__",
|
||||||
|
"__ge__",
|
||||||
|
"__getattribute__",
|
||||||
|
"__getitem__",
|
||||||
|
"__gt__",
|
||||||
|
"__hash__",
|
||||||
|
"__init__",
|
||||||
|
"__init_subclass__",
|
||||||
|
"__le__",
|
||||||
|
"__lt__",
|
||||||
|
"__module__",
|
||||||
|
"__ne__",
|
||||||
|
"__new__",
|
||||||
|
"__reduce__",
|
||||||
|
"__reduce_ex__",
|
||||||
|
"__repr__",
|
||||||
|
"__setattr__",
|
||||||
|
"__setitem__",
|
||||||
|
"__sizeof__",
|
||||||
|
"__str__",
|
||||||
|
"__subclasshook__",
|
||||||
|
"__weakref__",
|
||||||
|
"_chunk_size_default",
|
||||||
|
"_chunkable",
|
||||||
|
"_count_descendants",
|
||||||
|
"_attr_types",
|
||||||
|
"_detachable",
|
||||||
|
"_handle_object_count",
|
||||||
|
"_type_check",
|
||||||
|
"_type_registry",
|
||||||
|
"_units",
|
||||||
|
"add_chunkable_attrs",
|
||||||
|
"add_detachable_attrs",
|
||||||
|
"get_children_count",
|
||||||
|
"get_dynamic_member_names",
|
||||||
|
"get_id",
|
||||||
|
"get_member_names",
|
||||||
|
"get_registered_type",
|
||||||
|
"get_typed_member_names",
|
||||||
|
"to_dict",
|
||||||
|
"update_forward_refs",
|
||||||
|
"validate_prop_name",
|
||||||
|
"from_list",
|
||||||
|
"to_list",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class _RegisteringBase:
|
||||||
|
"""
|
||||||
|
Private Base model for Speckle types.
|
||||||
|
|
||||||
|
This is an implementation detail, please do not use this outside this module.
|
||||||
|
|
||||||
|
This class provides automatic registration of `speckle_type` into a global,
|
||||||
|
(class level) registry for each subclassing type.
|
||||||
|
The type registry is a base for accurate type based (de)serialization.
|
||||||
|
"""
|
||||||
|
|
||||||
|
speckle_type: ClassVar[str]
|
||||||
|
_speckle_type_override: ClassVar[Optional[str]] = None
|
||||||
|
_speckle_namespace: ClassVar[Optional[str]] = None
|
||||||
|
_type_registry: ClassVar[Dict[str, Type["Base"]]] = {}
|
||||||
|
_attr_types: ClassVar[Dict[str, Type]] = {}
|
||||||
|
# dict of chunkable props and their max chunk size
|
||||||
|
_chunkable: Dict[str, int] = {}
|
||||||
|
_chunk_size_default: int = 1000
|
||||||
|
_detachable: Set[str] = set() # list of defined detachable props
|
||||||
|
_serialize_ignore: Set[str] = set()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_registered_type(cls, speckle_type: str) -> Optional[Type["Base"]]:
|
||||||
|
"""Get the registered type from the protected mapping via the `speckle_type`"""
|
||||||
|
for full_name in reversed(speckle_type.split(":")):
|
||||||
|
maybe_type = cls._type_registry.get(full_name, None)
|
||||||
|
if maybe_type:
|
||||||
|
return maybe_type
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _determine_speckle_type(cls) -> str:
|
||||||
|
"""
|
||||||
|
This method brings the speckle_type construction in par with Speckle-sharp/Core.
|
||||||
|
|
||||||
|
The implementation differs, because in Core the basis of the speckle_type if
|
||||||
|
type.FullName, which includes the dotnet namespace name too.
|
||||||
|
Copying that behavior is hard in python, where the concept of namespaces
|
||||||
|
means something entirely different.
|
||||||
|
|
||||||
|
So we enabled a speckle_type override mechanism, that enables
|
||||||
|
"""
|
||||||
|
base_name = "Base"
|
||||||
|
if cls.__name__ == base_name:
|
||||||
|
return base_name
|
||||||
|
|
||||||
|
bases = [
|
||||||
|
b._full_name()
|
||||||
|
for b in reversed(cls.mro())
|
||||||
|
if issubclass(b, Base) and b.__name__ != base_name
|
||||||
|
]
|
||||||
|
return ":".join(bases)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _full_name(cls) -> str:
|
||||||
|
base_name = "Base"
|
||||||
|
if cls.__name__ == base_name:
|
||||||
|
return base_name
|
||||||
|
|
||||||
|
if cls._speckle_type_override:
|
||||||
|
return cls._speckle_type_override
|
||||||
|
|
||||||
|
# convert the module names to PascalCase to match c# namespace naming convention
|
||||||
|
# also drop specklepy from the beginning
|
||||||
|
namespace = ".".join(
|
||||||
|
pascalcase(m)
|
||||||
|
for m in filter(lambda name: name != "specklepy", cls.__module__.split("."))
|
||||||
|
)
|
||||||
|
return f"{namespace}.{cls.__name__}"
|
||||||
|
|
||||||
|
def __init_subclass__(
|
||||||
|
cls,
|
||||||
|
speckle_type: Optional[str] = None,
|
||||||
|
chunkable: Optional[Dict[str, int]] = None,
|
||||||
|
detachable: Optional[Set[str]] = None,
|
||||||
|
serialize_ignore: Optional[Set[str]] = None,
|
||||||
|
**kwargs: Dict[str, Any],
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Hook into subclass type creation.
|
||||||
|
|
||||||
|
This is provides a mechanism to hook into the event of the subclass type object
|
||||||
|
initialization. This is reused to register each subclassing type into a class
|
||||||
|
level dictionary.
|
||||||
|
"""
|
||||||
|
# if not speckle_type:
|
||||||
|
# raise Exception("no type")
|
||||||
|
cls._speckle_type_override = speckle_type
|
||||||
|
cls.speckle_type = cls._determine_speckle_type()
|
||||||
|
# cls.speckle_type = speckle_type
|
||||||
|
if cls._full_name() in cls._type_registry:
|
||||||
|
raise ValueError(
|
||||||
|
f"The speckle_type: {speckle_type} is already registered for type: "
|
||||||
|
f"{cls._type_registry[cls._full_name()].__name__}. "
|
||||||
|
"Please choose a different type name."
|
||||||
|
)
|
||||||
|
cls._type_registry[cls._full_name()] = cls # type: ignore
|
||||||
|
try:
|
||||||
|
cls._attr_types = get_type_hints(cls)
|
||||||
|
except Exception:
|
||||||
|
cls._attr_types = getattr(cls, "__annotations__", {})
|
||||||
|
if chunkable:
|
||||||
|
chunkable = {k: v for k, v in chunkable.items() if isinstance(v, int)}
|
||||||
|
cls._chunkable = dict(cls._chunkable, **chunkable)
|
||||||
|
if detachable:
|
||||||
|
cls._detachable = cls._detachable.union(detachable)
|
||||||
|
if serialize_ignore:
|
||||||
|
cls._serialize_ignore = cls._serialize_ignore.union(serialize_ignore)
|
||||||
|
# we know, that the super here is object, that takes no args on init subclass
|
||||||
|
return super().__init_subclass__()
|
||||||
|
|
||||||
|
|
||||||
|
# T = TypeVar("T")
|
||||||
|
|
||||||
|
# how i wish the code below would be correct, but we're also parsing into floats
|
||||||
|
# and converting into strings if the original type is string, but the value isn't
|
||||||
|
# def _validate_type(t: type, value: T) -> Tuple[bool, T]:
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_type(t: Optional[type], value: Any) -> Tuple[bool, Any]:
|
||||||
|
# this should be reworked. Its only ok to return null for Optionals...
|
||||||
|
# if t is None and value is None:
|
||||||
|
if value is None:
|
||||||
|
return True, value
|
||||||
|
|
||||||
|
# after fixing the None t above, this should be
|
||||||
|
# if t is Any:
|
||||||
|
# if t is None:
|
||||||
|
|
||||||
|
if t is None or t is Any:
|
||||||
|
return True, value
|
||||||
|
|
||||||
|
if isclass(t) and issubclass(t, Enum):
|
||||||
|
if isinstance(value, t):
|
||||||
|
return True, value
|
||||||
|
if value in t._value2member_map_:
|
||||||
|
return True, t(value)
|
||||||
|
|
||||||
|
if getattr(t, "__module__", None) == "typing":
|
||||||
|
if isinstance(t, ForwardRef):
|
||||||
|
return True, value
|
||||||
|
|
||||||
|
origin = getattr(t, "__origin__")
|
||||||
|
# below is what in nicer for >= py38
|
||||||
|
# origin = get_origin(t)
|
||||||
|
|
||||||
|
# recursive validation for Unions on both types preferring the fist type
|
||||||
|
if origin is Union:
|
||||||
|
# below is what in nicer for >= py38
|
||||||
|
# t_1, t_2 = get_args(t)
|
||||||
|
args = t.__args__ # type: ignore
|
||||||
|
for arg_t in args:
|
||||||
|
t_success, t_value = _validate_type(arg_t, value)
|
||||||
|
if t_success:
|
||||||
|
return True, t_value
|
||||||
|
return False, value
|
||||||
|
if origin is dict:
|
||||||
|
if not isinstance(value, dict):
|
||||||
|
return False, value
|
||||||
|
if value == {}:
|
||||||
|
return True, value
|
||||||
|
if not getattr(t, "__args__", None):
|
||||||
|
return True, value
|
||||||
|
t_key, t_value = t.__args__ # type: ignore
|
||||||
|
|
||||||
|
if (
|
||||||
|
getattr(t_key, "__name__", None),
|
||||||
|
getattr(t_value, "__name__", None),
|
||||||
|
) == ("KT", "VT"):
|
||||||
|
return True, value
|
||||||
|
# we're only checking the first item, but the for loop and return after
|
||||||
|
# evaluating the first item is the fastest way
|
||||||
|
for dict_key, dict_value in value.items():
|
||||||
|
valid_key, _ = _validate_type(t_key, dict_key)
|
||||||
|
valid_value, _ = _validate_type(t_value, dict_value)
|
||||||
|
|
||||||
|
if valid_key and valid_value:
|
||||||
|
return True, value
|
||||||
|
return False, value
|
||||||
|
|
||||||
|
if origin is list:
|
||||||
|
if not isinstance(value, list):
|
||||||
|
return False, value
|
||||||
|
if value == []:
|
||||||
|
return True, value
|
||||||
|
if not hasattr(t, "__args__"):
|
||||||
|
return True, value
|
||||||
|
t_items = t.__args__[0] # type: ignore
|
||||||
|
if getattr(t_items, "__name__", None) == "T":
|
||||||
|
return True, value
|
||||||
|
first_item_valid, _ = _validate_type(t_items, value[0])
|
||||||
|
if first_item_valid:
|
||||||
|
return True, value
|
||||||
|
return False, value
|
||||||
|
|
||||||
|
if origin is tuple:
|
||||||
|
if not isinstance(value, tuple):
|
||||||
|
return False, value
|
||||||
|
if not hasattr(t, "__args__"):
|
||||||
|
return True, value
|
||||||
|
args = t.__args__ # type: ignore
|
||||||
|
if args == tuple():
|
||||||
|
return True, value
|
||||||
|
# we're not checking for empty tuple, cause tuple lengths must match
|
||||||
|
if len(args) != len(value):
|
||||||
|
return False, value
|
||||||
|
values = []
|
||||||
|
for t_item, v_item in zip(args, value):
|
||||||
|
item_valid, item_value = _validate_type(t_item, v_item)
|
||||||
|
if not item_valid:
|
||||||
|
return False, value
|
||||||
|
values.append(item_value)
|
||||||
|
return True, tuple(values)
|
||||||
|
|
||||||
|
if origin is set:
|
||||||
|
if not isinstance(value, set):
|
||||||
|
return False, value
|
||||||
|
if not hasattr(t, "__args__"):
|
||||||
|
return True, value
|
||||||
|
t_items = t.__args__[0] # type: ignore
|
||||||
|
first_item_valid, _ = _validate_type(t_items, next(iter(value)))
|
||||||
|
if first_item_valid:
|
||||||
|
return True, value
|
||||||
|
return False, value
|
||||||
|
|
||||||
|
if isinstance(value, t):
|
||||||
|
return True, value
|
||||||
|
|
||||||
|
with contextlib.suppress(ValueError, TypeError):
|
||||||
|
if t is float and value is not None:
|
||||||
|
return True, float(value)
|
||||||
|
# TODO: dafuq, i had to add this not list check
|
||||||
|
# but it would also fail for objects and other complex values
|
||||||
|
if t is str and value and not isinstance(value, list):
|
||||||
|
return True, str(value)
|
||||||
|
|
||||||
|
return False, value
|
||||||
|
|
||||||
|
|
||||||
|
class Base(_RegisteringBase, speckle_type="Base"):
|
||||||
|
# id: Union[str, None] = None
|
||||||
|
# totalChildrenCount: Union[int, None] = None
|
||||||
|
# applicationId: Union[str, None] = None
|
||||||
|
_units: Union[None, str] = None
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
id: str | None = None,
|
||||||
|
# totalChildrenCount: Union[int, None] = None,
|
||||||
|
applicationId: str | None = None,
|
||||||
|
**kwargs,
|
||||||
|
) -> None:
|
||||||
|
self.id = id
|
||||||
|
# self.totalChildrenCount = totalChildrenCount
|
||||||
|
self.applicationId = applicationId
|
||||||
|
super().__init__()
|
||||||
|
for k, v in kwargs.items():
|
||||||
|
self.__setattr__(k, v)
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return (
|
||||||
|
f"{self.__class__.__name__}(id: {self.id}, "
|
||||||
|
f"speckle_type: {self.speckle_type}, "
|
||||||
|
# f"totalChildrenCount: {self.totalChildrenCount})"
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.__repr__()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def of_type(cls, speckle_type: str, **kwargs) -> "Base":
|
||||||
|
"""
|
||||||
|
Get a plain Base object with a specified speckle_type.
|
||||||
|
|
||||||
|
The speckle_type is protected and cannot be overwritten on a class instance.
|
||||||
|
This is to prevent problems with receiving in other platforms or connectors.
|
||||||
|
However, if you really need a base with a different type, here is a helper
|
||||||
|
to do that for you.
|
||||||
|
|
||||||
|
This is used in the deserialisation of unknown types so their speckle_type
|
||||||
|
can be preserved.
|
||||||
|
"""
|
||||||
|
b = cls(**kwargs)
|
||||||
|
b.__dict__.update(speckle_type=speckle_type)
|
||||||
|
return b
|
||||||
|
|
||||||
|
def __setitem__(self, name: str, value: Any) -> None:
|
||||||
|
self.validate_prop_name(name)
|
||||||
|
self.__dict__[name] = value
|
||||||
|
|
||||||
|
def __getitem__(self, name: str) -> Any:
|
||||||
|
return self.__dict__[name]
|
||||||
|
|
||||||
|
def __setattr__(self, name: str, value: Any) -> None:
|
||||||
|
"""
|
||||||
|
Type checking, guard attribute, and property set mechanism.
|
||||||
|
|
||||||
|
The `speckle_type` is a protected class attribute it must not be overridden.
|
||||||
|
|
||||||
|
This also performs a type check if the attribute is type hinted.
|
||||||
|
"""
|
||||||
|
if name == "speckle_type":
|
||||||
|
# not sure if we should raise an exception here??
|
||||||
|
# raise SpeckleException(
|
||||||
|
# "Cannot override the `speckle_type`. This is set manually by the class or on deserialisation"
|
||||||
|
# )
|
||||||
|
return
|
||||||
|
# if value is not None:
|
||||||
|
value = self._type_check(name, value)
|
||||||
|
attr = getattr(self.__class__, name, None)
|
||||||
|
if isinstance(attr, property):
|
||||||
|
try:
|
||||||
|
attr.__set__(self, value)
|
||||||
|
except AttributeError:
|
||||||
|
return # the prop probably doesn't have a setter
|
||||||
|
super().__setattr__(name, value)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def update_forward_refs(cls) -> None:
|
||||||
|
"""
|
||||||
|
Attempts to populate the internal defined types dict for type checking
|
||||||
|
sometime after defining the class.
|
||||||
|
This is already done when defining the class, but can be called
|
||||||
|
again if references to undefined types were
|
||||||
|
included.
|
||||||
|
|
||||||
|
See `objects.geometry` for an example of how this is used with
|
||||||
|
the Brep class definitions.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
cls._attr_types = get_type_hints(cls)
|
||||||
|
except Exception as e:
|
||||||
|
warn(f"Could not update forward refs for class {cls.__name__}: {e}")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def validate_prop_name(cls, name: str) -> None:
|
||||||
|
"""Validator for dynamic attribute names."""
|
||||||
|
if name in {"", "@"}:
|
||||||
|
raise ValueError("Invalid Name: Base member names cannot be empty strings")
|
||||||
|
if name.startswith("@@"):
|
||||||
|
raise ValueError(
|
||||||
|
"Invalid Name: Base member names cannot start with more than one '@'",
|
||||||
|
)
|
||||||
|
if "." in name or "/" in name:
|
||||||
|
raise ValueError(
|
||||||
|
"Invalid Name: Base member names cannot contain characters '.' or '/'",
|
||||||
|
)
|
||||||
|
|
||||||
|
def _type_check(self, name: str, value: Any) -> Any:
|
||||||
|
"""
|
||||||
|
Lightweight type checking of values before setting them
|
||||||
|
|
||||||
|
NOTE: Does not check subscripted types within generics as the performance hit
|
||||||
|
of checking each item within a given collection isn't worth it.
|
||||||
|
Eg if you have a type Dict[str, float],
|
||||||
|
we will only check if the value you're trying to set is a dict.
|
||||||
|
"""
|
||||||
|
types = getattr(self, "_attr_types", {})
|
||||||
|
t = types.get(name, None)
|
||||||
|
|
||||||
|
valid, checked_value = _validate_type(t, value)
|
||||||
|
|
||||||
|
if valid:
|
||||||
|
return checked_value
|
||||||
|
|
||||||
|
raise SpeckleException(
|
||||||
|
f"Cannot set '{self.__class__.__name__}.{name}':"
|
||||||
|
f"it expects type '{str(t)}',"
|
||||||
|
f"but received type '{type(value).__name__}'"
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_chunkable_attrs(self, **kwargs: int) -> None:
|
||||||
|
"""
|
||||||
|
Mark defined attributes as chunkable for serialisation
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
kwargs {int} -- the name of the attribute as the keyword
|
||||||
|
and the chunk size as the arg
|
||||||
|
"""
|
||||||
|
chunkable = {k: v for k, v in kwargs.items() if isinstance(v, int)}
|
||||||
|
self._chunkable = dict(self._chunkable, **chunkable)
|
||||||
|
|
||||||
|
def add_detachable_attrs(self, names: Set[str]) -> None:
|
||||||
|
"""
|
||||||
|
Mark defined attributes as detachable for serialisation
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
names {Set[str]} -- the names of the attributes to detach as a set of string
|
||||||
|
"""
|
||||||
|
self._detachable = self._detachable.union(names)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def units(self) -> Union[str, None]:
|
||||||
|
return self._units
|
||||||
|
|
||||||
|
@units.setter
|
||||||
|
def units(self, value: Union[str, Units, None]):
|
||||||
|
"""While this property accepts any string value, geometry expects units to be specific strings (see Units enum)"""
|
||||||
|
if isinstance(value, str) or value is None:
|
||||||
|
self._units = value
|
||||||
|
elif isinstance(value, Units):
|
||||||
|
self._units = value.value
|
||||||
|
else:
|
||||||
|
raise SpeckleInvalidUnitException(
|
||||||
|
f"Unknown type {type(value)} received for units"
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_member_names(self) -> List[str]:
|
||||||
|
"""Get all of the property names on this object, dynamic or not"""
|
||||||
|
attr_dir = list(set(dir(self)) - REMOVE_FROM_DIR)
|
||||||
|
return [
|
||||||
|
name
|
||||||
|
for name in attr_dir
|
||||||
|
if not name.startswith("_") and not callable(getattr(self, name))
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_serializable_attributes(self) -> List[str]:
|
||||||
|
"""Get the attributes that should be serialized"""
|
||||||
|
return sorted(list(set(self.get_member_names()) - self._serialize_ignore))
|
||||||
|
|
||||||
|
def get_typed_member_names(self) -> List[str]:
|
||||||
|
"""Get all of the names of the defined (typed) properties of this object"""
|
||||||
|
return list(self._attr_types.keys())
|
||||||
|
|
||||||
|
def get_dynamic_member_names(self) -> List[str]:
|
||||||
|
"""Get all of the names of the dynamic properties of this object"""
|
||||||
|
return list(set(self.__dict__.keys()) - set(self._attr_types.keys()))
|
||||||
|
|
||||||
|
def get_children_count(self) -> int:
|
||||||
|
"""Get the total count of children Base objects"""
|
||||||
|
parsed = []
|
||||||
|
return 1 + self._count_descendants(self, parsed)
|
||||||
|
|
||||||
|
def get_id(self, decompose: bool = False) -> str:
|
||||||
|
"""
|
||||||
|
Gets the id (a unique hash) of this object.
|
||||||
|
⚠️ This method fully serializes the object which,
|
||||||
|
in the case of large objects (with many sub-objects), has a tangible cost.
|
||||||
|
Avoid using it!
|
||||||
|
|
||||||
|
Note: the hash of a decomposed object differs from that of a
|
||||||
|
non-decomposed object
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
decompose {bool} -- if True, will decompose the object in
|
||||||
|
the process of hashing it
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str -- the hash (id) of the fully serialized object
|
||||||
|
"""
|
||||||
|
from specklepy.serialization.base_object_serializer import BaseObjectSerializer
|
||||||
|
|
||||||
|
serializer = BaseObjectSerializer()
|
||||||
|
if decompose:
|
||||||
|
serializer.write_transports = [MemoryTransport()]
|
||||||
|
return serializer.traverse_base(self)[0]
|
||||||
|
|
||||||
|
def _count_descendants(self, base: "Base", parsed: List) -> int:
|
||||||
|
if base in parsed:
|
||||||
|
return 0
|
||||||
|
parsed.append(base)
|
||||||
|
|
||||||
|
return sum(
|
||||||
|
self._handle_object_count(value, parsed)
|
||||||
|
for name, value in base.get_member_names()
|
||||||
|
if not name.startswith("@")
|
||||||
|
)
|
||||||
|
|
||||||
|
def _handle_object_count(self, obj: Any, parsed: List) -> int:
|
||||||
|
# pylint: disable=isinstance-second-argument-not-valid-type
|
||||||
|
count = 0
|
||||||
|
if obj is None:
|
||||||
|
return count
|
||||||
|
if isinstance(obj, "Base"):
|
||||||
|
count += 1
|
||||||
|
count += self._count_descendants(obj, parsed)
|
||||||
|
return count
|
||||||
|
elif isinstance(obj, list):
|
||||||
|
for item in obj:
|
||||||
|
if isinstance(item, "Base"):
|
||||||
|
count += 1
|
||||||
|
count += self._count_descendants(item, parsed)
|
||||||
|
else:
|
||||||
|
count += self._handle_object_count(item, parsed)
|
||||||
|
elif isinstance(obj, dict):
|
||||||
|
for _, value in obj.items():
|
||||||
|
if isinstance(value, "Base"):
|
||||||
|
count += 1
|
||||||
|
count += self._count_descendants(value, parsed)
|
||||||
|
else:
|
||||||
|
count += self._handle_object_count(value, parsed)
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
Base.update_forward_refs()
|
||||||
|
|
||||||
|
|
||||||
|
class DataChunk(Base, speckle_type="Speckle.Core.Models.DataChunk"):
|
||||||
|
data: Union[List[Any], None] = None
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.data = []
|
||||||
@@ -16,7 +16,9 @@ CHUNKABLE_PROPS = {
|
|||||||
DETACHABLE = {"detach_this", "origin", "detached_list"}
|
DETACHABLE = {"detach_this", "origin", "detached_list"}
|
||||||
|
|
||||||
|
|
||||||
class FakeGeo(Base, chunkable={"dots": 50}, detachable={"pointslist"}):
|
class FakeGeo(
|
||||||
|
Base, speckle_type="FakeGeo", chunkable={"dots": 50}, detachable={"pointslist"}
|
||||||
|
):
|
||||||
pointslist: Optional[List[Base]] = None
|
pointslist: Optional[List[Base]] = None
|
||||||
dots: Optional[List[int]] = None
|
dots: Optional[List[int]] = None
|
||||||
|
|
||||||
@@ -28,7 +30,9 @@ class FakeDirection(Enum):
|
|||||||
WEST = 4
|
WEST = 4
|
||||||
|
|
||||||
|
|
||||||
class FakeMesh(FakeGeo, chunkable=CHUNKABLE_PROPS, detachable=DETACHABLE):
|
class FakeMesh(
|
||||||
|
FakeGeo, speckle_type="FakeMesh", chunkable=CHUNKABLE_PROPS, detachable=DETACHABLE
|
||||||
|
):
|
||||||
vertices: Optional[List[float]] = None
|
vertices: Optional[List[float]] = None
|
||||||
faces: Optional[List[int]] = None
|
faces: Optional[List[int]] = None
|
||||||
colors: Optional[List[int]] = None
|
colors: Optional[List[int]] = None
|
||||||
@@ -0,0 +1,946 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
from specklepy.objects.encoding import CurveArray, CurveTypeEncoding, ObjectArray
|
||||||
|
from specklepy.objects.primitive import Interval
|
||||||
|
from specklepy.objects.units import get_encoding_from_units, get_units_from_encoding
|
||||||
|
|
||||||
|
GEOMETRY = "Objects.Geometry."
|
||||||
|
|
||||||
|
|
||||||
|
class Point(Base, speckle_type=GEOMETRY + "Point"):
|
||||||
|
x: float = 0.0
|
||||||
|
y: float = 0.0
|
||||||
|
z: float = 0.0
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return (
|
||||||
|
f"{self.__class__.__name__}(x: {self.x}, y: {self.y}, z: {self.z}, id:"
|
||||||
|
f" {self.id}, speckle_type: {self.speckle_type})"
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[float]) -> "Point":
|
||||||
|
"""
|
||||||
|
Create a new Point from a list of three floats
|
||||||
|
representing the x, y, and z coordinates
|
||||||
|
"""
|
||||||
|
return cls(x=args[0], y=args[1], z=args[2])
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [self.x, self.y, self.z]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_coords(cls, x: float = 0.0, y: float = 0.0, z: float = 0.0):
|
||||||
|
"""Create a new Point from x, y, and z values"""
|
||||||
|
pt = Point()
|
||||||
|
pt.x, pt.y, pt.z = x, y, z
|
||||||
|
return pt
|
||||||
|
|
||||||
|
|
||||||
|
class Pointcloud(
|
||||||
|
Base,
|
||||||
|
speckle_type=GEOMETRY + "Pointcloud",
|
||||||
|
chunkable={"points": 31250, "colors": 62500, "sizes": 62500},
|
||||||
|
):
|
||||||
|
points: Optional[List[float]] = None
|
||||||
|
colors: Optional[List[int]] = None
|
||||||
|
sizes: Optional[List[float]] = None
|
||||||
|
bbox: Optional["Box"] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Vector(Base, speckle_type=GEOMETRY + "Vector"):
|
||||||
|
x: float = 0.0
|
||||||
|
y: float = 0.0
|
||||||
|
z: float = 0.0
|
||||||
|
applicationId: Optional[str] = None
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return (
|
||||||
|
f"{self.__class__.__name__} "
|
||||||
|
"(x: {self.x}, y: {self.y}, z: {self.z}, id: {self.id}, "
|
||||||
|
"speckle_type: {self.speckle_type})"
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[float]) -> "Vector":
|
||||||
|
"""
|
||||||
|
Create from a list of three floats representing the x, y, and z coordinates.
|
||||||
|
"""
|
||||||
|
return cls(x=args[0], y=args[1], z=args[2])
|
||||||
|
|
||||||
|
def to_list(self) -> List[float]:
|
||||||
|
return [self.x, self.y, self.z]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_coords(cls, x: float = 0.0, y: float = 0.0, z: float = 0.0) -> "Vector":
|
||||||
|
"""Create a new Point from x, y, and z values"""
|
||||||
|
v = Vector()
|
||||||
|
v.x, v.y, v.z = x, y, z
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
class ControlPoint(Point, speckle_type=GEOMETRY + "ControlPoint"):
|
||||||
|
weight: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Plane(Base, speckle_type=GEOMETRY + "Plane"):
|
||||||
|
origin: Point = Point()
|
||||||
|
normal: Vector = Vector()
|
||||||
|
xdir: Vector = Vector()
|
||||||
|
ydir: Vector = Vector()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any]) -> "Plane":
|
||||||
|
return cls(
|
||||||
|
origin=Point.from_list(args[:3]),
|
||||||
|
normal=Vector.from_list(args[3:6]),
|
||||||
|
xdir=Vector.from_list(args[6:9]),
|
||||||
|
ydir=Vector.from_list(args[9:12]),
|
||||||
|
units=get_units_from_encoding(args[-1]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [
|
||||||
|
*self.origin.to_list(),
|
||||||
|
*self.normal.to_list(),
|
||||||
|
*self.xdir.to_list(),
|
||||||
|
*self.ydir.to_list(),
|
||||||
|
get_encoding_from_units(self._units),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Box(Base, speckle_type=GEOMETRY + "Box"):
|
||||||
|
basePlane: Plane = Plane()
|
||||||
|
xSize: Interval = Interval()
|
||||||
|
ySize: Interval = Interval()
|
||||||
|
zSize: Interval = Interval()
|
||||||
|
area: Optional[float] = None
|
||||||
|
volume: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Line(Base, speckle_type=GEOMETRY + "Line"):
|
||||||
|
start: Point = Point()
|
||||||
|
end: Optional[Point] = None
|
||||||
|
domain: Optional[Interval] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
length: Optional[float] = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any]) -> "Line":
|
||||||
|
return cls(
|
||||||
|
start=Point.from_list(args[1:4]),
|
||||||
|
end=Point.from_list(args[4:7]),
|
||||||
|
domain=Interval.from_list(args[7:10]),
|
||||||
|
units=get_units_from_encoding(args[-1]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
domain = self.domain.to_list() if self.domain else [0, 1]
|
||||||
|
return [
|
||||||
|
CurveTypeEncoding.Line.value,
|
||||||
|
*self.start.to_list(),
|
||||||
|
*self.end.to_list(),
|
||||||
|
*domain,
|
||||||
|
get_encoding_from_units(self._units),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Arc(Base, speckle_type=GEOMETRY + "Arc"):
|
||||||
|
radius: Optional[float] = None
|
||||||
|
startAngle: Optional[float] = None
|
||||||
|
endAngle: Optional[float] = None
|
||||||
|
angleRadians: Optional[float] = None
|
||||||
|
plane: Optional[Plane] = None
|
||||||
|
domain: Optional[Interval] = None
|
||||||
|
startPoint: Optional[Point] = None
|
||||||
|
midPoint: Optional[Point] = None
|
||||||
|
endPoint: Optional[Point] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
area: Optional[float] = None
|
||||||
|
length: Optional[float] = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any]) -> "Arc":
|
||||||
|
return cls(
|
||||||
|
radius=args[1],
|
||||||
|
startAngle=args[2],
|
||||||
|
endAngle=args[3],
|
||||||
|
angleRadians=args[4],
|
||||||
|
domain=Interval.from_list(args[5:7]),
|
||||||
|
plane=Plane.from_list(args[7:20]),
|
||||||
|
startPoint=Point.from_list(args[20:23]),
|
||||||
|
midPoint=Point.from_list(args[23:26]),
|
||||||
|
endPoint=Point.from_list(args[26:29]),
|
||||||
|
units=get_units_from_encoding(args[-1]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [
|
||||||
|
CurveTypeEncoding.Arc.value,
|
||||||
|
self.radius,
|
||||||
|
self.startAngle,
|
||||||
|
self.endAngle,
|
||||||
|
self.angleRadians,
|
||||||
|
*self.domain.to_list(),
|
||||||
|
*self.plane.to_list(),
|
||||||
|
*self.startPoint.to_list(),
|
||||||
|
*self.midPoint.to_list(),
|
||||||
|
*self.endPoint.to_list(),
|
||||||
|
get_encoding_from_units(self._units),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Circle(Base, speckle_type=GEOMETRY + "Circle"):
|
||||||
|
radius: Optional[float] = None
|
||||||
|
plane: Optional[Plane] = None
|
||||||
|
domain: Optional[Interval] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
area: Optional[float] = None
|
||||||
|
length: Optional[float] = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any]) -> "Circle":
|
||||||
|
return cls(
|
||||||
|
radius=args[1],
|
||||||
|
domain=Interval.from_list(args[2:4]),
|
||||||
|
plane=Plane.from_list(args[4:17]),
|
||||||
|
units=get_units_from_encoding(args[-1]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [
|
||||||
|
CurveTypeEncoding.Circle.value,
|
||||||
|
self.radius,
|
||||||
|
*self.domain.to_list(),
|
||||||
|
*self.plane.to_list(),
|
||||||
|
get_encoding_from_units(self._units),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Ellipse(Base, speckle_type=GEOMETRY + "Ellipse"):
|
||||||
|
firstRadius: Optional[float] = None
|
||||||
|
secondRadius: Optional[float] = None
|
||||||
|
plane: Optional[Plane] = None
|
||||||
|
domain: Optional[Interval] = None
|
||||||
|
trimDomain: Optional[Interval] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
area: Optional[float] = None
|
||||||
|
length: Optional[float] = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any]) -> "Ellipse":
|
||||||
|
return cls(
|
||||||
|
firstRadius=args[1],
|
||||||
|
secondRadius=args[2],
|
||||||
|
domain=Interval.from_list(args[3:5]),
|
||||||
|
plane=Plane.from_list(args[5:18]),
|
||||||
|
units=get_units_from_encoding(args[-1]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [
|
||||||
|
CurveTypeEncoding.Ellipse.value,
|
||||||
|
self.firstRadius,
|
||||||
|
self.secondRadius,
|
||||||
|
*self.domain.to_list(),
|
||||||
|
*self.plane.to_list(),
|
||||||
|
get_encoding_from_units(self._units),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Polyline(Base, speckle_type=GEOMETRY + "Polyline", chunkable={"value": 20000}):
|
||||||
|
value: Optional[List[float]] = None
|
||||||
|
closed: Optional[bool] = None
|
||||||
|
domain: Optional[Interval] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
area: Optional[float] = None
|
||||||
|
length: Optional[float] = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_points(cls, points: List[Point]):
|
||||||
|
"""Create a new Polyline from a list of Points"""
|
||||||
|
polyline = cls()
|
||||||
|
polyline.units = points[0].units
|
||||||
|
polyline.value = []
|
||||||
|
for point in points:
|
||||||
|
polyline.value.extend([point.x, point.y, point.z])
|
||||||
|
return polyline
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any]) -> "Polyline":
|
||||||
|
point_count = args[4]
|
||||||
|
return cls(
|
||||||
|
closed=bool(args[1]),
|
||||||
|
domain=Interval.from_list(args[2:4]),
|
||||||
|
value=args[5 : 5 + point_count],
|
||||||
|
units=get_units_from_encoding(args[-1]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [
|
||||||
|
CurveTypeEncoding.Polyline.value,
|
||||||
|
int(self.closed),
|
||||||
|
*self.domain.to_list(),
|
||||||
|
len(self.value),
|
||||||
|
*self.value,
|
||||||
|
get_encoding_from_units(self._units),
|
||||||
|
]
|
||||||
|
|
||||||
|
def as_points(self) -> List[Point]:
|
||||||
|
"""Converts the `value` attribute to a list of Points"""
|
||||||
|
if not self.value:
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(self.value) % 3:
|
||||||
|
raise ValueError("Points array malformed: length%3 != 0.")
|
||||||
|
|
||||||
|
values = iter(self.value)
|
||||||
|
return [
|
||||||
|
Point(x=v, y=next(values), z=next(values), units=self.units) for v in values
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class SpiralType(Enum):
|
||||||
|
Biquadratic = 0
|
||||||
|
BiquadraticParabola = 1
|
||||||
|
Bloss = 2
|
||||||
|
Clothoid = 3
|
||||||
|
Cosine = 4
|
||||||
|
Cubic = 5
|
||||||
|
CubicParabola = 6
|
||||||
|
Radioid = 7
|
||||||
|
Sinusoid = 8
|
||||||
|
Unknown = 9
|
||||||
|
|
||||||
|
|
||||||
|
class Spiral(Base, speckle_type=GEOMETRY + "Spiral", detachable={"displayValue"}):
|
||||||
|
startPoint: Optional[Point] = None
|
||||||
|
endPoint: Optional[Point]
|
||||||
|
plane: Optional[Plane]
|
||||||
|
turns: Optional[float]
|
||||||
|
pitchAxis: Optional[Vector] = Vector()
|
||||||
|
pitch: float = 0
|
||||||
|
spiralType: Optional[SpiralType] = None
|
||||||
|
displayValue: Optional[Polyline] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
length: Optional[float] = None
|
||||||
|
domain: Optional[Interval] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Curve(
|
||||||
|
Base,
|
||||||
|
speckle_type=GEOMETRY + "Curve",
|
||||||
|
chunkable={"points": 20000, "weights": 20000, "knots": 20000},
|
||||||
|
):
|
||||||
|
degree: Optional[int] = None
|
||||||
|
periodic: Optional[bool] = None
|
||||||
|
rational: Optional[bool] = None
|
||||||
|
points: Optional[List[float]] = None
|
||||||
|
weights: Optional[List[float]] = None
|
||||||
|
knots: Optional[List[float]] = None
|
||||||
|
domain: Optional[Interval] = None
|
||||||
|
displayValue: Optional[Polyline] = None
|
||||||
|
closed: Optional[bool] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
area: Optional[float] = None
|
||||||
|
length: Optional[float] = None
|
||||||
|
|
||||||
|
def as_points(self) -> List[Point]:
|
||||||
|
"""Converts the `value` attribute to a list of Points"""
|
||||||
|
if not self.points:
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(self.points) % 3:
|
||||||
|
raise ValueError("Points array malformed: length%3 != 0.")
|
||||||
|
|
||||||
|
values = iter(self.points)
|
||||||
|
return [
|
||||||
|
Point(x=v, y=next(values), z=next(values), units=self.units) for v in values
|
||||||
|
]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any]) -> "Curve":
|
||||||
|
point_count = int(args[7])
|
||||||
|
weights_count = int(args[8])
|
||||||
|
knots_count = int(args[9])
|
||||||
|
|
||||||
|
points_start = 10
|
||||||
|
weights_start = 10 + point_count
|
||||||
|
knots_start = weights_start + weights_count
|
||||||
|
knots_end = knots_start + knots_count
|
||||||
|
|
||||||
|
return cls(
|
||||||
|
degree=int(args[1]),
|
||||||
|
periodic=bool(args[2]),
|
||||||
|
rational=bool(args[3]),
|
||||||
|
closed=bool(args[4]),
|
||||||
|
domain=Interval.from_list(args[5:7]),
|
||||||
|
points=args[points_start:weights_start],
|
||||||
|
weights=args[weights_start:knots_start],
|
||||||
|
knots=args[knots_start:knots_end],
|
||||||
|
units=get_units_from_encoding(args[-1]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [
|
||||||
|
CurveTypeEncoding.Curve.value,
|
||||||
|
self.degree,
|
||||||
|
int(self.periodic),
|
||||||
|
int(self.rational),
|
||||||
|
int(self.closed),
|
||||||
|
*self.domain.to_list(),
|
||||||
|
len(self.points),
|
||||||
|
len(self.weights),
|
||||||
|
len(self.knots),
|
||||||
|
*self.points,
|
||||||
|
*self.weights,
|
||||||
|
*self.knots,
|
||||||
|
get_encoding_from_units(self._units),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Polycurve(Base, speckle_type=GEOMETRY + "Polycurve"):
|
||||||
|
segments: Optional[List[Base]] = None
|
||||||
|
domain: Optional[Interval] = None
|
||||||
|
closed: Optional[bool] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
area: Optional[float] = None
|
||||||
|
length: Optional[float] = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any]) -> "Polycurve":
|
||||||
|
curve_arrays = CurveArray(args[5:-1])
|
||||||
|
return cls(
|
||||||
|
closed=bool(args[1]),
|
||||||
|
domain=Interval.from_list(args[2:4]),
|
||||||
|
segments=curve_arrays.to_curves(),
|
||||||
|
units=get_units_from_encoding(args[-1]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
curve_array = CurveArray.from_curves(self.segments).data
|
||||||
|
return [
|
||||||
|
CurveTypeEncoding.Polycurve.value,
|
||||||
|
int(self.closed),
|
||||||
|
*self.domain.to_list(),
|
||||||
|
len(curve_array),
|
||||||
|
*curve_array,
|
||||||
|
get_encoding_from_units(self._units),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Extrusion(Base, speckle_type=GEOMETRY + "Extrusion"):
|
||||||
|
capped: Optional[bool] = None
|
||||||
|
profile: Optional[Base] = None
|
||||||
|
pathStart: Optional[Point] = None
|
||||||
|
pathEnd: Optional[Point] = None
|
||||||
|
pathCurve: Optional[Base] = None
|
||||||
|
pathTangent: Optional[Base] = None
|
||||||
|
profiles: Optional[List[Base]] = None
|
||||||
|
length: Optional[float] = None
|
||||||
|
area: Optional[float] = None
|
||||||
|
volume: Optional[float] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Mesh(
|
||||||
|
Base,
|
||||||
|
speckle_type=GEOMETRY + "Mesh",
|
||||||
|
chunkable={
|
||||||
|
"vertices": 2000,
|
||||||
|
"faces": 2000,
|
||||||
|
"colors": 2000,
|
||||||
|
"textureCoordinates": 2000,
|
||||||
|
},
|
||||||
|
):
|
||||||
|
vertices: Optional[List[float]] = None
|
||||||
|
faces: Optional[List[int]] = None
|
||||||
|
colors: Optional[List[int]] = None
|
||||||
|
textureCoordinates: Optional[List[float]] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
area: Optional[float] = None
|
||||||
|
volume: Optional[float] = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create(
|
||||||
|
cls,
|
||||||
|
vertices: List[float],
|
||||||
|
faces: List[int],
|
||||||
|
colors: Optional[List[int]] = None,
|
||||||
|
texture_coordinates: Optional[List[float]] = None,
|
||||||
|
) -> "Mesh":
|
||||||
|
"""
|
||||||
|
Create a new Mesh from lists representing its vertices, faces,
|
||||||
|
colors (optional), and texture coordinates (optional).
|
||||||
|
|
||||||
|
This will initialise empty lists for colors and texture coordinates
|
||||||
|
if you do not provide any.
|
||||||
|
"""
|
||||||
|
return cls(
|
||||||
|
vertices=vertices,
|
||||||
|
faces=faces,
|
||||||
|
colors=colors or [],
|
||||||
|
textureCoordinates=texture_coordinates or [],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Surface(Base, speckle_type=GEOMETRY + "Surface"):
|
||||||
|
degreeU: Optional[int] = None
|
||||||
|
degreeV: Optional[int] = None
|
||||||
|
rational: Optional[bool] = None
|
||||||
|
area: Optional[float] = None
|
||||||
|
pointData: Optional[List[float]] = None
|
||||||
|
countU: Optional[int] = None
|
||||||
|
countV: Optional[int] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
closedU: Optional[bool] = None
|
||||||
|
closedV: Optional[bool] = None
|
||||||
|
domainU: Optional[Interval] = None
|
||||||
|
domainV: Optional[Interval] = None
|
||||||
|
knotsU: Optional[List[float]] = None
|
||||||
|
knotsV: Optional[List[float]] = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any]) -> "Surface":
|
||||||
|
point_count = int(args[11])
|
||||||
|
knots_u_count = int(args[12])
|
||||||
|
knots_v_count = int(args[13])
|
||||||
|
|
||||||
|
start_point_data = 14
|
||||||
|
start_knots_u = start_point_data + point_count
|
||||||
|
start_knots_v = start_knots_u + knots_u_count
|
||||||
|
|
||||||
|
return cls(
|
||||||
|
degreeU=int(args[0]),
|
||||||
|
degreeV=int(args[1]),
|
||||||
|
countU=int(args[2]),
|
||||||
|
countV=int(args[3]),
|
||||||
|
rational=bool(args[4]),
|
||||||
|
closedU=bool(args[5]),
|
||||||
|
closedV=bool(args[6]),
|
||||||
|
domainU=Interval(start=args[7], end=args[8]),
|
||||||
|
domainV=Interval(start=args[9], end=args[10]),
|
||||||
|
pointData=args[start_point_data:start_knots_u],
|
||||||
|
knotsU=args[start_knots_u:start_knots_v],
|
||||||
|
knotsV=args[start_knots_v : start_knots_v + knots_v_count],
|
||||||
|
units=get_units_from_encoding(args[-1]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [
|
||||||
|
self.degreeU,
|
||||||
|
self.degreeV,
|
||||||
|
self.countU,
|
||||||
|
self.countV,
|
||||||
|
int(self.rational),
|
||||||
|
int(self.closedU),
|
||||||
|
int(self.closedV),
|
||||||
|
*self.domainU.to_list(),
|
||||||
|
*self.domainV.to_list(),
|
||||||
|
len(self.pointData),
|
||||||
|
len(self.knotsU),
|
||||||
|
len(self.knotsV),
|
||||||
|
*self.pointData,
|
||||||
|
*self.knotsU,
|
||||||
|
*self.knotsV,
|
||||||
|
get_encoding_from_units(self._units),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class BrepFace(Base, speckle_type=GEOMETRY + "BrepFace"):
|
||||||
|
_Brep: Optional["Brep"] = None
|
||||||
|
SurfaceIndex: Optional[int] = None
|
||||||
|
OuterLoopIndex: Optional[int] = None
|
||||||
|
OrientationReversed: Optional[bool] = None
|
||||||
|
LoopIndices: Optional[List[int]] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _outer_loop(self):
|
||||||
|
return self._Brep.Loops[self.OuterLoopIndex] # pylint: disable=no-member
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _surface(self):
|
||||||
|
return self._Brep.Surfaces[self.SurfaceIndex] # pylint: disable=no-member
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _loops(self):
|
||||||
|
if self.LoopIndices:
|
||||||
|
# pylint: disable=not-an-iterable, no-member
|
||||||
|
return [self._Brep.Loops[i] for i in self.LoopIndices]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any], brep: "Brep" = None) -> "BrepFace":
|
||||||
|
return cls(
|
||||||
|
_Brep=brep,
|
||||||
|
SurfaceIndex=args[0],
|
||||||
|
OuterLoopIndex=args[1],
|
||||||
|
OrientationReversed=bool(args[2]),
|
||||||
|
LoopIndices=args[3:],
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [
|
||||||
|
self.SurfaceIndex,
|
||||||
|
self.OuterLoopIndex,
|
||||||
|
int(self.OrientationReversed),
|
||||||
|
*self.LoopIndices,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class BrepEdge(Base, speckle_type=GEOMETRY + "BrepEdge"):
|
||||||
|
_Brep: Optional["Brep"] = None
|
||||||
|
Curve3dIndex: Optional[int] = None
|
||||||
|
TrimIndices: Optional[List[int]] = None
|
||||||
|
StartIndex: Optional[int] = None
|
||||||
|
EndIndex: Optional[int] = None
|
||||||
|
ProxyCurveIsReversed: Optional[bool] = None
|
||||||
|
Domain: Optional[Interval] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _start_vertex(self):
|
||||||
|
return self._Brep.Vertices[self.StartIndex]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _end_vertex(self):
|
||||||
|
return self._Brep.Vertices[self.EndIndex]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _trims(self):
|
||||||
|
if self.TrimIndices:
|
||||||
|
# pylint: disable=not-an-iterable
|
||||||
|
return [self._Brep.Trims[i] for i in self.TrimIndices]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _curve(self):
|
||||||
|
return self._Brep.Curve3D[self.Curve3dIndex]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any], brep: "Brep" = None) -> "BrepEdge":
|
||||||
|
domain_start = args[4]
|
||||||
|
domain_end = args[5]
|
||||||
|
domain = (
|
||||||
|
Interval(start=domain_start, end=domain_end)
|
||||||
|
if None not in (domain_start, domain_end)
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
return cls(
|
||||||
|
_Brep=brep,
|
||||||
|
Curve3dIndex=int(args[0]),
|
||||||
|
TrimIndices=[int(t) for t in args[6:]],
|
||||||
|
StartIndex=int(args[1]),
|
||||||
|
EndIndex=int(args[2]),
|
||||||
|
ProxyCurveIsReversed=bool(args[3]),
|
||||||
|
Domain=domain,
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [
|
||||||
|
self.Curve3dIndex,
|
||||||
|
self.StartIndex,
|
||||||
|
self.EndIndex,
|
||||||
|
int(self.ProxyCurveIsReversed),
|
||||||
|
self.Domain.start,
|
||||||
|
self.Domain.end,
|
||||||
|
*self.TrimIndices,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class BrepLoopType(int, Enum):
|
||||||
|
Unknown = 0
|
||||||
|
Outer = 1
|
||||||
|
Inner = 2
|
||||||
|
Slit = 3
|
||||||
|
CurveOnSurface = 4
|
||||||
|
PointOnSurface = 5
|
||||||
|
|
||||||
|
|
||||||
|
class BrepLoop(Base, speckle_type=GEOMETRY + "BrepLoop"):
|
||||||
|
_Brep: Optional["Brep"] = None
|
||||||
|
FaceIndex: Optional[Optional[int]] = None
|
||||||
|
TrimIndices: Optional[List[int]] = None
|
||||||
|
Type: Optional[BrepLoopType] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _face(self):
|
||||||
|
return self._Brep.Faces[self.FaceIndex]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _trims(self):
|
||||||
|
if self.TrimIndices:
|
||||||
|
# pylint: disable=not-an-iterable
|
||||||
|
return [self._Brep.Trims[i] for i in self.TrimIndices]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[any], brep: "Brep" = None):
|
||||||
|
return cls(
|
||||||
|
_Brep=brep,
|
||||||
|
FaceIndex=args[0],
|
||||||
|
Type=BrepLoopType(args[1]),
|
||||||
|
TrimIndices=args[2:],
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[int]:
|
||||||
|
return [
|
||||||
|
self.FaceIndex,
|
||||||
|
self.Type.value,
|
||||||
|
*self.TrimIndices,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class BrepTrimType(int, Enum):
|
||||||
|
Unknown = 0
|
||||||
|
Boundary = 1
|
||||||
|
Mated = 2
|
||||||
|
Seam = 3
|
||||||
|
Singular = 4
|
||||||
|
CurveOnSurface = 5
|
||||||
|
PointOnSurface = 6
|
||||||
|
Slit = 7
|
||||||
|
|
||||||
|
|
||||||
|
class BrepTrim(Base, speckle_type=GEOMETRY + "BrepTrim"):
|
||||||
|
_Brep: Optional["Brep"] = None
|
||||||
|
EdgeIndex: Optional[int] = None
|
||||||
|
StartIndex: Optional[int] = None
|
||||||
|
EndIndex: Optional[int] = None
|
||||||
|
FaceIndex: Optional[int] = None
|
||||||
|
LoopIndex: Optional[int] = None
|
||||||
|
CurveIndex: Optional[int] = None
|
||||||
|
IsoStatus: Optional[int] = None
|
||||||
|
TrimType: Optional[BrepTrimType] = None
|
||||||
|
IsReversed: Optional[bool] = None
|
||||||
|
Domain: Optional[Interval] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _face(self):
|
||||||
|
if self._Brep:
|
||||||
|
return self._Brep.Faces[self.FaceIndex] # pylint: disable=no-member
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _loop(self):
|
||||||
|
if self._Brep:
|
||||||
|
return self._Brep.Loops[self.LoopIndex] # pylint: disable=no-member
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _edge(self):
|
||||||
|
if self._Brep:
|
||||||
|
# pylint: disable=no-member
|
||||||
|
return self._Brep.Edges[self.EdgeIndex] if self.EdgeIndex != -1 else None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _curve_2d(self):
|
||||||
|
if self._Brep:
|
||||||
|
return self._Brep.Curve2D[self.CurveIndex] # pylint: disable=no-member
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any], brep: "Brep" = None) -> "BrepTrim":
|
||||||
|
return cls(
|
||||||
|
_Brep=brep,
|
||||||
|
EdgeIndex=args[0],
|
||||||
|
StartIndex=args[1],
|
||||||
|
EndIndex=args[2],
|
||||||
|
FaceIndex=args[3],
|
||||||
|
LoopIndex=args[4],
|
||||||
|
CurveIndex=args[5],
|
||||||
|
IsoStatus=args[6],
|
||||||
|
TrimType=BrepTrimType(args[7]),
|
||||||
|
IsReversed=bool(args[8]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [
|
||||||
|
self.EdgeIndex,
|
||||||
|
self.StartIndex,
|
||||||
|
self.EndIndex,
|
||||||
|
self.FaceIndex,
|
||||||
|
self.LoopIndex,
|
||||||
|
self.CurveIndex,
|
||||||
|
self.IsoStatus,
|
||||||
|
self.TrimType.value,
|
||||||
|
int(self.IsReversed),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Brep(
|
||||||
|
Base,
|
||||||
|
speckle_type=GEOMETRY + "Brep",
|
||||||
|
chunkable={
|
||||||
|
"SurfacesValue": 31250,
|
||||||
|
"Curve3DValues": 31250,
|
||||||
|
"Curve2DValues": 31250,
|
||||||
|
"VerticesValue": 31250,
|
||||||
|
"EdgesValue": 62500,
|
||||||
|
"LoopsValue": 62500,
|
||||||
|
"FacesValue": 62500,
|
||||||
|
"TrimsValue": 62500,
|
||||||
|
},
|
||||||
|
detachable={"displayValue"},
|
||||||
|
serialize_ignore={
|
||||||
|
"Surfaces",
|
||||||
|
"Curve3D",
|
||||||
|
"Curve2D",
|
||||||
|
"Vertices",
|
||||||
|
"Trims",
|
||||||
|
"Edges",
|
||||||
|
"Loops",
|
||||||
|
"Faces",
|
||||||
|
},
|
||||||
|
):
|
||||||
|
provenance: Optional[str] = None
|
||||||
|
bbox: Optional[Box] = None
|
||||||
|
area: Optional[float] = None
|
||||||
|
volume: Optional[float] = None
|
||||||
|
_displayValue: Optional[List[Mesh]] = None
|
||||||
|
Surfaces: Optional[List[Surface]] = None
|
||||||
|
Curve3D: Optional[List[Base]] = None
|
||||||
|
Curve2D: Optional[List[Base]] = None
|
||||||
|
Vertices: Optional[List[Point]] = None
|
||||||
|
Edges: Optional[List[BrepEdge]] = None
|
||||||
|
Loops: Optional[List[BrepLoop]] = None
|
||||||
|
Faces: Optional[List[BrepFace]] = None
|
||||||
|
Trims: Optional[List[BrepTrim]] = None
|
||||||
|
IsClosed: Optional[bool] = None
|
||||||
|
Orientation: Optional[int] = None
|
||||||
|
|
||||||
|
def _inject_self_into_children(self, children: Optional[List[Base]]) -> List[Base]:
|
||||||
|
if children is None:
|
||||||
|
return children
|
||||||
|
|
||||||
|
for child in children:
|
||||||
|
child._Brep = self # pylint: disable=protected-access
|
||||||
|
return children
|
||||||
|
|
||||||
|
# set as prop for now for backwards compatibility
|
||||||
|
@property
|
||||||
|
def displayValue(self) -> List[Mesh]:
|
||||||
|
return self._displayValue
|
||||||
|
|
||||||
|
@displayValue.setter
|
||||||
|
def displayValue(self, value):
|
||||||
|
if isinstance(value, Mesh):
|
||||||
|
self._displayValue = [value]
|
||||||
|
elif isinstance(value, list):
|
||||||
|
self._displayValue = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def EdgesValue(self) -> List[BrepEdge]:
|
||||||
|
return None if self.Edges is None else ObjectArray.from_objects(self.Edges).data
|
||||||
|
|
||||||
|
@EdgesValue.setter
|
||||||
|
def EdgesValue(self, value: List[float]):
|
||||||
|
if not value:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.Edges = ObjectArray.decode_data(value, BrepEdge.from_list, brep=self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def LoopsValue(self) -> List[BrepLoop]:
|
||||||
|
return None if self.Loops is None else ObjectArray.from_objects(self.Loops).data
|
||||||
|
|
||||||
|
@LoopsValue.setter
|
||||||
|
def LoopsValue(self, value: List[int]):
|
||||||
|
if not value:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.Loops = ObjectArray.decode_data(value, BrepLoop.from_list, brep=self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def FacesValue(self) -> List[int]:
|
||||||
|
return None if self.Faces is None else ObjectArray.from_objects(self.Faces).data
|
||||||
|
|
||||||
|
@FacesValue.setter
|
||||||
|
def FacesValue(self, value: List[int]):
|
||||||
|
if not value:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.Faces = ObjectArray.decode_data(value, BrepFace.from_list, brep=self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SurfacesValue(self) -> List[float]:
|
||||||
|
return (
|
||||||
|
None
|
||||||
|
if self.Surfaces is None
|
||||||
|
else ObjectArray.from_objects(self.Surfaces).data
|
||||||
|
)
|
||||||
|
|
||||||
|
@SurfacesValue.setter
|
||||||
|
def SurfacesValue(self, value: List[float]):
|
||||||
|
if not value:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.Surfaces = ObjectArray.decode_data(value, Surface.from_list)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def Curve3DValues(self) -> List[float]:
|
||||||
|
return (
|
||||||
|
None if self.Curve3D is None else CurveArray.from_curves(self.Curve3D).data
|
||||||
|
)
|
||||||
|
|
||||||
|
@Curve3DValues.setter
|
||||||
|
def Curve3DValues(self, value: List[float]):
|
||||||
|
crv_array = CurveArray(value)
|
||||||
|
self.Curve3D = crv_array.to_curves()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def Curve2DValues(self) -> List[Base]:
|
||||||
|
return (
|
||||||
|
None if self.Curve2D is None else CurveArray.from_curves(self.Curve2D).data
|
||||||
|
)
|
||||||
|
|
||||||
|
@Curve2DValues.setter
|
||||||
|
def Curve2DValues(self, value: List[float]):
|
||||||
|
crv_array = CurveArray(value)
|
||||||
|
self.Curve2D = crv_array.to_curves()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def VerticesValue(self) -> List[Point]:
|
||||||
|
if self.Vertices is None:
|
||||||
|
return None
|
||||||
|
encoded_unit = get_encoding_from_units(self.Vertices[0].units)
|
||||||
|
values = [encoded_unit]
|
||||||
|
for vertex in self.Vertices:
|
||||||
|
values.extend(vertex.to_list())
|
||||||
|
return values
|
||||||
|
|
||||||
|
@VerticesValue.setter
|
||||||
|
def VerticesValue(self, value: List[float]):
|
||||||
|
value = value.copy()
|
||||||
|
units = get_units_from_encoding(value.pop(0))
|
||||||
|
|
||||||
|
vertices = []
|
||||||
|
|
||||||
|
for i in range(0, len(value), 3):
|
||||||
|
vertex = Point.from_list(value[i : i + 3])
|
||||||
|
vertex.units = units
|
||||||
|
vertices.append(vertex)
|
||||||
|
|
||||||
|
self.Vertices = vertices
|
||||||
|
|
||||||
|
# TODO: can this be consistent with loops, edges, faces, curves, etc and prepend with the chunk list? needs to happen in sharp first
|
||||||
|
@property
|
||||||
|
def TrimsValue(self) -> List[float]:
|
||||||
|
# return None if self.Trims is None else ObjectArray.from_objects(self.Trims).data
|
||||||
|
if not self.Trims:
|
||||||
|
return
|
||||||
|
value = []
|
||||||
|
for trim in self.Trims:
|
||||||
|
value.extend(trim.to_list())
|
||||||
|
return value
|
||||||
|
|
||||||
|
@TrimsValue.setter
|
||||||
|
def TrimsValue(self, value: List[float]):
|
||||||
|
if not value:
|
||||||
|
return
|
||||||
|
|
||||||
|
# self.Trims = ObjectArray.decode_data(value, BrepTrim.from_list, brep=self)
|
||||||
|
self.Trims = [
|
||||||
|
BrepTrim.from_list(value[i : i + 9], self) for i in range(0, len(value), 9)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
BrepEdge.update_forward_refs()
|
||||||
|
BrepLoop.update_forward_refs()
|
||||||
|
BrepTrim.update_forward_refs()
|
||||||
|
BrepFace.update_forward_refs()
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
from typing import List, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from deprecated import deprecated
|
from deprecated import deprecated
|
||||||
|
|
||||||
from specklepy.objects.geometry import Point, Vector
|
from specklepy.objects.geometry import Plane, Point, Polyline, Vector
|
||||||
|
|
||||||
from .base import Base
|
from .base import Base
|
||||||
|
|
||||||
OTHER = "Objects.Other."
|
OTHER = "Objects.Other."
|
||||||
|
OTHER_REVIT = OTHER + "Revit."
|
||||||
|
|
||||||
IDENTITY_TRANSFORM = [
|
IDENTITY_TRANSFORM = [
|
||||||
1.0,
|
1.0,
|
||||||
@@ -28,6 +29,21 @@ IDENTITY_TRANSFORM = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Material(Base, speckle_type=OTHER + "Material"):
|
||||||
|
"""Generic class for materials containing generic parameters."""
|
||||||
|
|
||||||
|
name: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class RevitMaterial(Material, speckle_type="Objects.Other.Revit." + "RevitMaterial"):
|
||||||
|
materialCategory: Optional[str] = None
|
||||||
|
materialClass: Optional[str] = None
|
||||||
|
shininess: Optional[int] = None
|
||||||
|
smoothness: Optional[int] = None
|
||||||
|
transparency: Optional[int] = None
|
||||||
|
parameters: Optional[Base] = None
|
||||||
|
|
||||||
|
|
||||||
class RenderMaterial(Base, speckle_type=OTHER + "RenderMaterial"):
|
class RenderMaterial(Base, speckle_type=OTHER + "RenderMaterial"):
|
||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
opacity: float = 1
|
opacity: float = 1
|
||||||
@@ -37,16 +53,36 @@ class RenderMaterial(Base, speckle_type=OTHER + "RenderMaterial"):
|
|||||||
emissive: int = -16777216 # black arbg
|
emissive: int = -16777216 # black arbg
|
||||||
|
|
||||||
|
|
||||||
class RenderMaterialProxy(
|
class MaterialQuantity(Base, speckle_type=OTHER + "MaterialQuantity"):
|
||||||
Base,
|
material: Optional[Material] = None
|
||||||
speckle_type="Speckle.Core.Models.Proxies.RenderMaterialProxy",
|
volume: Optional[float] = None
|
||||||
):
|
area: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
|
class DisplayStyle(Base, speckle_type=OTHER + "DisplayStyle"):
|
||||||
"""
|
"""
|
||||||
Used to store render material to object relationships in root collections.
|
Minimal display style class.
|
||||||
|
Developed primarily for display styles in Rhino and AutoCAD.
|
||||||
|
Rhino object attributes uses OpenNURBS definition for linetypes and lineweights.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
objects: list[str]
|
name: Optional[str] = None
|
||||||
value: RenderMaterial
|
color: int = -2894893 # light gray arbg
|
||||||
|
linetype: Optional[str] = None
|
||||||
|
lineweight: float = 0
|
||||||
|
|
||||||
|
|
||||||
|
class Text(Base, speckle_type=OTHER + "Text"):
|
||||||
|
"""
|
||||||
|
Text object to render it on viewer.
|
||||||
|
"""
|
||||||
|
|
||||||
|
plane: Plane
|
||||||
|
value: str
|
||||||
|
height: float
|
||||||
|
rotation: float
|
||||||
|
displayValue: Optional[List[Polyline]] = None
|
||||||
|
richText: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class Transform(
|
class Transform(
|
||||||
@@ -217,10 +253,59 @@ class Transform(
|
|||||||
return cls(value=value)
|
return cls(value=value)
|
||||||
|
|
||||||
|
|
||||||
class Collection(
|
class BlockDefinition(
|
||||||
Base,
|
Base, speckle_type=OTHER + "BlockDefinition", detachable={"geometry"}
|
||||||
speckle_type="Speckle.Core.Models.Collections.Collection",
|
|
||||||
detachable={"elements"},
|
|
||||||
):
|
):
|
||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
|
basePoint: Optional[Point] = None
|
||||||
|
geometry: Optional[List[Base]] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Instance(Base, speckle_type=OTHER + "Instance", detachable={"definition"}):
|
||||||
|
transform: Optional[Transform] = None
|
||||||
|
definition: Optional[Base] = None
|
||||||
|
|
||||||
|
|
||||||
|
class BlockInstance(
|
||||||
|
Instance, speckle_type=OTHER + "BlockInstance", serialize_ignore={"blockDefinition"}
|
||||||
|
):
|
||||||
|
@property
|
||||||
|
@deprecated(version="2.13", reason="Use definition")
|
||||||
|
def blockDefinition(self) -> Optional[BlockDefinition]:
|
||||||
|
if isinstance(self.definition, BlockDefinition):
|
||||||
|
return self.definition
|
||||||
|
return None
|
||||||
|
|
||||||
|
@blockDefinition.setter
|
||||||
|
def blockDefinition(self, value: Optional[BlockDefinition]) -> None:
|
||||||
|
self.definition = value
|
||||||
|
|
||||||
|
|
||||||
|
class RevitInstance(Instance, speckle_type=OTHER_REVIT + "RevitInstance"):
|
||||||
|
level: Optional[Base] = None
|
||||||
|
facingFlipped: bool
|
||||||
|
handFlipped: bool
|
||||||
|
parameters: Optional[Base] = None
|
||||||
|
elementId: Optional[str]
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: prob move this into a built elements module, but just trialling this for now
|
||||||
|
class RevitParameter(Base, speckle_type="Objects.BuiltElements.Revit.Parameter"):
|
||||||
|
name: Optional[str] = None
|
||||||
|
value: Any = None
|
||||||
|
applicationUnitType: Optional[str] = None # eg UnitType UT_Length
|
||||||
|
applicationUnit: Optional[str] = None # DisplayUnitType eg DUT_MILLIMITERS
|
||||||
|
applicationInternalName: Optional[str] = (
|
||||||
|
None # BuiltInParameterName or GUID for shared parameter
|
||||||
|
)
|
||||||
|
isShared: bool = False
|
||||||
|
isReadOnly: bool = False
|
||||||
|
isTypeParameter: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
class Collection(
|
||||||
|
Base, speckle_type="Speckle.Core.Models.Collection", detachable={"elements"}
|
||||||
|
):
|
||||||
|
name: Optional[str] = None
|
||||||
|
collectionType: Optional[str] = None
|
||||||
elements: Optional[List[Base]] = None
|
elements: Optional[List[Base]] = None
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
from typing import Any, List
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
|
||||||
|
NAMESPACE = "Objects.Primitive"
|
||||||
|
|
||||||
|
|
||||||
|
class Interval(Base, speckle_type=f"{NAMESPACE}.Interval"):
|
||||||
|
start: float = 0.0
|
||||||
|
end: float = 0.0
|
||||||
|
|
||||||
|
def length(self):
|
||||||
|
return abs(self.start - self.end)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, args: List[Any]) -> "Interval":
|
||||||
|
return cls(start=args[0], end=args[1])
|
||||||
|
|
||||||
|
def to_list(self) -> List[Any]:
|
||||||
|
return [self.start, self.end]
|
||||||
|
|
||||||
|
|
||||||
|
class Interval2d(Base, speckle_type=f"{NAMESPACE}.Interval2d"):
|
||||||
|
u: Interval
|
||||||
|
v: Interval
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
"""Builtin Speckle object kit."""
|
||||||
|
|
||||||
|
from specklepy.objects.structural.analysis import (
|
||||||
|
Model,
|
||||||
|
ModelInfo,
|
||||||
|
ModelSettings,
|
||||||
|
ModelUnits,
|
||||||
|
)
|
||||||
|
from specklepy.objects.structural.axis import Axis, AxisType
|
||||||
|
from specklepy.objects.structural.geometry import (
|
||||||
|
Element1D,
|
||||||
|
Element2D,
|
||||||
|
Element3D,
|
||||||
|
ElementType1D,
|
||||||
|
ElementType2D,
|
||||||
|
ElementType3D,
|
||||||
|
Node,
|
||||||
|
Restraint,
|
||||||
|
)
|
||||||
|
from specklepy.objects.structural.loading import (
|
||||||
|
ActionType,
|
||||||
|
BeamLoadType,
|
||||||
|
CombinationType,
|
||||||
|
FaceLoadType,
|
||||||
|
Load,
|
||||||
|
LoadAxisType,
|
||||||
|
LoadBeam,
|
||||||
|
LoadCase,
|
||||||
|
LoadCombinations,
|
||||||
|
LoadDirection,
|
||||||
|
LoadDirection2D,
|
||||||
|
LoadFace,
|
||||||
|
LoadGravity,
|
||||||
|
LoadNode,
|
||||||
|
LoadType,
|
||||||
|
)
|
||||||
|
from specklepy.objects.structural.materials import (
|
||||||
|
Concrete,
|
||||||
|
MaterialType,
|
||||||
|
Steel,
|
||||||
|
StructuralMaterial,
|
||||||
|
Timber,
|
||||||
|
)
|
||||||
|
from specklepy.objects.structural.properties import (
|
||||||
|
BaseReferencePoint,
|
||||||
|
MemberType,
|
||||||
|
Property,
|
||||||
|
Property1D,
|
||||||
|
Property2D,
|
||||||
|
Property3D,
|
||||||
|
PropertyDamper,
|
||||||
|
PropertyMass,
|
||||||
|
PropertySpring,
|
||||||
|
PropertyType2D,
|
||||||
|
PropertyType3D,
|
||||||
|
PropertyTypeDamper,
|
||||||
|
PropertyTypeSpring,
|
||||||
|
ReferenceSurface,
|
||||||
|
ReferenceSurfaceEnum,
|
||||||
|
SectionProfile,
|
||||||
|
ShapeType,
|
||||||
|
shapeType,
|
||||||
|
)
|
||||||
|
from specklepy.objects.structural.results import (
|
||||||
|
Result,
|
||||||
|
Result1D,
|
||||||
|
Result2D,
|
||||||
|
Result3D,
|
||||||
|
ResultGlobal,
|
||||||
|
ResultNode,
|
||||||
|
ResultSet1D,
|
||||||
|
ResultSet2D,
|
||||||
|
ResultSet3D,
|
||||||
|
ResultSetAll,
|
||||||
|
ResultSetNode,
|
||||||
|
)
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"Element1D",
|
||||||
|
"Element2D",
|
||||||
|
"Element3D",
|
||||||
|
"ElementType1D",
|
||||||
|
"ElementType2D",
|
||||||
|
"ElementType3D",
|
||||||
|
"AxisType",
|
||||||
|
"Axis",
|
||||||
|
"Node",
|
||||||
|
"Restraint",
|
||||||
|
"Load",
|
||||||
|
"LoadType",
|
||||||
|
"ActionType",
|
||||||
|
"BeamLoadType",
|
||||||
|
"FaceLoadType",
|
||||||
|
"LoadDirection",
|
||||||
|
"LoadDirection2D",
|
||||||
|
"LoadAxisType",
|
||||||
|
"CombinationType",
|
||||||
|
"LoadBeam",
|
||||||
|
"LoadCase",
|
||||||
|
"LoadCombinations",
|
||||||
|
"LoadFace",
|
||||||
|
"LoadGravity",
|
||||||
|
"LoadNode",
|
||||||
|
"Model",
|
||||||
|
"ModelInfo",
|
||||||
|
"ModelSettings",
|
||||||
|
"ModelUnits",
|
||||||
|
"MaterialType",
|
||||||
|
"Concrete",
|
||||||
|
"StructuralMaterial",
|
||||||
|
"Steel",
|
||||||
|
"Timber",
|
||||||
|
"Property",
|
||||||
|
"Property1D",
|
||||||
|
"Property2D",
|
||||||
|
"Property3D",
|
||||||
|
"PropertyDamper",
|
||||||
|
"PropertyMass",
|
||||||
|
"PropertySpring",
|
||||||
|
"SectionProfile",
|
||||||
|
"MemberType",
|
||||||
|
"BaseReferencePoint",
|
||||||
|
"ReferenceSurface",
|
||||||
|
"PropertyType2D",
|
||||||
|
"PropertyType3D",
|
||||||
|
"ShapeType",
|
||||||
|
"PropertyTypeSpring",
|
||||||
|
"PropertyTypeDamper",
|
||||||
|
"ReferenceSurfaceEnum",
|
||||||
|
"shapeType",
|
||||||
|
"Result",
|
||||||
|
"Result1D",
|
||||||
|
"ResultSet1D",
|
||||||
|
"Result2D",
|
||||||
|
"ResultSet2D",
|
||||||
|
"Result3D",
|
||||||
|
"ResultSet3D",
|
||||||
|
"ResultGlobal",
|
||||||
|
"ResultSetNode",
|
||||||
|
"ResultNode",
|
||||||
|
"ResultSetAll",
|
||||||
|
]
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
|
||||||
|
STRUCTURAL_ANALYSIS = "Objects.Structural.Analysis."
|
||||||
|
|
||||||
|
|
||||||
|
class ModelUnits(Base, speckle_type=STRUCTURAL_ANALYSIS + "ModelUnits"):
|
||||||
|
length: Optional[str] = None
|
||||||
|
sections: Optional[str] = None
|
||||||
|
displacements: Optional[str] = None
|
||||||
|
stress: Optional[str] = None
|
||||||
|
force: Optional[str] = None
|
||||||
|
mass: Optional[str] = None
|
||||||
|
time: Optional[str] = None
|
||||||
|
temperature: Optional[str] = None
|
||||||
|
velocity: Optional[str] = None
|
||||||
|
acceleration: Optional[str] = None
|
||||||
|
energy: Optional[str] = None
|
||||||
|
angle: Optional[str] = None
|
||||||
|
strain: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class ModelSettings(Base, speckle_type=STRUCTURAL_ANALYSIS + "ModelSettings"):
|
||||||
|
modelUnits: Optional[ModelUnits] = None
|
||||||
|
steelCode: Optional[str] = None
|
||||||
|
concreteCode: Optional[str] = None
|
||||||
|
coincidenceTolerance: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
class ModelInfo(Base, speckle_type=STRUCTURAL_ANALYSIS + "ModelInfo"):
|
||||||
|
name: Optional[str] = None
|
||||||
|
description: Optional[str] = None
|
||||||
|
projectNumber: Optional[str] = None
|
||||||
|
projectName: Optional[str] = None
|
||||||
|
settings: Optional[ModelSettings] = None
|
||||||
|
initials: Optional[str] = None
|
||||||
|
application: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Model(Base, speckle_type=STRUCTURAL_ANALYSIS + "Model"):
|
||||||
|
specs: Optional[ModelInfo] = None
|
||||||
|
nodes: Optional[List] = None
|
||||||
|
elements: Optional[List] = None
|
||||||
|
loads: Optional[List] = None
|
||||||
|
restraints: Optional[List] = None
|
||||||
|
properties: Optional[List] = None
|
||||||
|
materials: Optional[List] = None
|
||||||
|
layerDescription: Optional[str] = None
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
from specklepy.objects.geometry import Plane
|
||||||
|
|
||||||
|
|
||||||
|
class AxisType(int, Enum):
|
||||||
|
Cartesian = 0
|
||||||
|
Cylindrical = 1
|
||||||
|
Spherical = 2
|
||||||
|
|
||||||
|
|
||||||
|
class Axis(Base, speckle_type="Objects.Structural.Geometry.Axis"):
|
||||||
|
name: Optional[str] = None
|
||||||
|
axisType: Optional[AxisType] = None
|
||||||
|
plane: Optional[Plane] = None
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
from specklepy.objects.geometry import Line, Mesh, Plane, Point, Vector
|
||||||
|
from specklepy.objects.structural.axis import Axis
|
||||||
|
from specklepy.objects.structural.properties import (
|
||||||
|
Property1D,
|
||||||
|
Property2D,
|
||||||
|
Property3D,
|
||||||
|
PropertyDamper,
|
||||||
|
PropertyMass,
|
||||||
|
PropertySpring,
|
||||||
|
)
|
||||||
|
|
||||||
|
STRUCTURAL_GEOMETRY = "Objects.Structural.Geometry"
|
||||||
|
|
||||||
|
|
||||||
|
class ElementType1D(int, Enum):
|
||||||
|
Beam = 0
|
||||||
|
Brace = 1
|
||||||
|
Bar = 2
|
||||||
|
Column = 3
|
||||||
|
Rod = 4
|
||||||
|
Spring = 5
|
||||||
|
Tie = 6
|
||||||
|
Strut = 7
|
||||||
|
Link = 8
|
||||||
|
Damper = 9
|
||||||
|
Cable = 10
|
||||||
|
Spacer = 11
|
||||||
|
Other = 12
|
||||||
|
Null = 13
|
||||||
|
|
||||||
|
|
||||||
|
class ElementType2D(int, Enum):
|
||||||
|
Quad4 = 0
|
||||||
|
Quad8 = 1
|
||||||
|
Triangle3 = 2
|
||||||
|
Triangle6 = 3
|
||||||
|
|
||||||
|
|
||||||
|
class ElementType3D(int, Enum):
|
||||||
|
Brick8 = 0
|
||||||
|
Wedge6 = 1
|
||||||
|
Pyramid5 = 2
|
||||||
|
Tetra4 = 3
|
||||||
|
|
||||||
|
|
||||||
|
class Restraint(Base, speckle_type=STRUCTURAL_GEOMETRY + ".Restraint"):
|
||||||
|
code: Optional[str] = None
|
||||||
|
stiffnessX: float = 0.0
|
||||||
|
stiffnessY: float = 0.0
|
||||||
|
stiffnessZ: float = 0.0
|
||||||
|
stiffnessXX: float = 0.0
|
||||||
|
stiffnessYY: float = 0.0
|
||||||
|
stiffnessZZ: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
class Node(Base, speckle_type=STRUCTURAL_GEOMETRY + ".Node"):
|
||||||
|
name: Optional[str] = None
|
||||||
|
basePoint: Optional[Point] = None
|
||||||
|
constraintAxis: Optional[Axis] = None
|
||||||
|
restraint: Optional[Restraint] = None
|
||||||
|
springProperty: Optional[PropertySpring] = None
|
||||||
|
massProperty: Optional[PropertyMass] = None
|
||||||
|
damperProperty: Optional[PropertyDamper] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Element1D(Base, speckle_type=STRUCTURAL_GEOMETRY + ".Element1D"):
|
||||||
|
name: Optional[str] = None
|
||||||
|
baseLine: Optional[Line] = None
|
||||||
|
property: Optional[Property1D] = None
|
||||||
|
type: Optional[ElementType1D] = None
|
||||||
|
end1Releases: Optional[Restraint] = None
|
||||||
|
end2Releases: Optional[Restraint] = None
|
||||||
|
end1Offset: Optional[Vector] = None
|
||||||
|
end2Offset: Optional[Vector] = None
|
||||||
|
orientationNode: Optional[Node] = None
|
||||||
|
orinetationAngle: float = 0.0
|
||||||
|
localAxis: Optional[Plane] = None
|
||||||
|
parent: Optional[Base] = None
|
||||||
|
end1Node: Optional[Node] = None
|
||||||
|
end2Node: Optional[Node] = None
|
||||||
|
topology: Optional[List] = None
|
||||||
|
displayMesh: Optional[Mesh] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Element2D(Base, speckle_type=STRUCTURAL_GEOMETRY + ".Element2D"):
|
||||||
|
name: Optional[str] = None
|
||||||
|
property: Optional[Property2D] = None
|
||||||
|
type: Optional[ElementType2D] = None
|
||||||
|
offset: float = 0.0
|
||||||
|
orientationAngle: float = 0.0
|
||||||
|
parent: Optional[Base] = None
|
||||||
|
topology: Optional[List] = None
|
||||||
|
displayMesh: Optional[Mesh] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Element3D(Base, speckle_type=STRUCTURAL_GEOMETRY + ".Element3D"):
|
||||||
|
name: Optional[str] = None
|
||||||
|
baseMesh: Optional[Mesh] = None
|
||||||
|
property: Optional[Property3D] = None
|
||||||
|
type: Optional[ElementType3D] = None
|
||||||
|
orientationAngle: float = 0.0
|
||||||
|
parent: Optional[Base] = None
|
||||||
|
topology: List
|
||||||
|
|
||||||
|
|
||||||
|
# class Storey needs ependency on built elements first
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
from specklepy.objects.geometry import Vector
|
||||||
|
from specklepy.objects.structural.axis import Axis
|
||||||
|
|
||||||
|
STRUCTURAL_LOADING = "Objects.Structural.Loading."
|
||||||
|
|
||||||
|
|
||||||
|
class LoadType(int, Enum):
|
||||||
|
none = 0
|
||||||
|
Dead = 1
|
||||||
|
SuperDead = 2
|
||||||
|
Soil = 3
|
||||||
|
Live = 4
|
||||||
|
LiveRoof = 5
|
||||||
|
ReducibleLive = 6
|
||||||
|
Wind = 7
|
||||||
|
Snow = 8
|
||||||
|
Rain = 9
|
||||||
|
Thermal = 10
|
||||||
|
Notional = 11
|
||||||
|
Prestress = 12
|
||||||
|
Equivalent = 13
|
||||||
|
Accidental = 14
|
||||||
|
SeismicRSA = 15
|
||||||
|
SeismicAccTorsion = 16
|
||||||
|
SeismicStatic = 17
|
||||||
|
Other = 18
|
||||||
|
|
||||||
|
|
||||||
|
class ActionType(int, Enum):
|
||||||
|
none = 0
|
||||||
|
Permanent = 1
|
||||||
|
Variable = 2
|
||||||
|
Accidental = 3
|
||||||
|
|
||||||
|
|
||||||
|
class BeamLoadType(int, Enum):
|
||||||
|
Point = 0
|
||||||
|
Uniform = 1
|
||||||
|
Linear = 2
|
||||||
|
Patch = 3
|
||||||
|
TriLinear = 4
|
||||||
|
|
||||||
|
|
||||||
|
class FaceLoadType(int, Enum):
|
||||||
|
Constant = 0
|
||||||
|
Variable = 1
|
||||||
|
Point = 2
|
||||||
|
|
||||||
|
|
||||||
|
class LoadDirection2D(int, Enum):
|
||||||
|
X = 0
|
||||||
|
Y = 1
|
||||||
|
Z = 2
|
||||||
|
|
||||||
|
|
||||||
|
class LoadDirection(int, Enum):
|
||||||
|
X = 0
|
||||||
|
Y = 1
|
||||||
|
Z = 2
|
||||||
|
XX = 3
|
||||||
|
YY = 4
|
||||||
|
ZZ = 5
|
||||||
|
|
||||||
|
|
||||||
|
class LoadAxisType(int, Enum):
|
||||||
|
Global = 0
|
||||||
|
Local = 1 # local element axes
|
||||||
|
DeformedLocal = (
|
||||||
|
2 # element local axis that is embedded in the element as it deforms
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CombinationType(int, Enum):
|
||||||
|
LinearAdd = 0
|
||||||
|
Envelope = 1
|
||||||
|
AbsoluteAdd = 2
|
||||||
|
SRSS = 3
|
||||||
|
RangeAdd = 4
|
||||||
|
|
||||||
|
|
||||||
|
class LoadCase(Base, speckle_type=STRUCTURAL_LOADING + "LoadCase"):
|
||||||
|
name: Optional[str] = None
|
||||||
|
loadType: Optional[LoadType] = None
|
||||||
|
group: Optional[str] = None
|
||||||
|
actionType: Optional[ActionType] = None
|
||||||
|
description: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Load(Base, speckle_type=STRUCTURAL_LOADING + "Load"):
|
||||||
|
name: Optional[str] = None
|
||||||
|
loadCase: Optional[LoadCase] = None
|
||||||
|
|
||||||
|
|
||||||
|
class LoadBeam(Load, speckle_type=STRUCTURAL_LOADING + "LoadBeam"):
|
||||||
|
elements: Optional[List] = None
|
||||||
|
loadType: Optional[BeamLoadType] = None
|
||||||
|
direction: Optional[LoadDirection] = None
|
||||||
|
loadAxis: Optional[Axis] = None
|
||||||
|
loadAxisType: Optional[LoadAxisType] = None
|
||||||
|
isProjected: Optional[bool] = None
|
||||||
|
values: Optional[List] = None
|
||||||
|
positions: Optional[List] = None
|
||||||
|
|
||||||
|
|
||||||
|
class LoadCombinations(Base, speckle_type=STRUCTURAL_LOADING + "LoadCombination"):
|
||||||
|
name: Optional[str] = None
|
||||||
|
loadCases: List
|
||||||
|
loadFactors: List
|
||||||
|
combinationType: CombinationType
|
||||||
|
|
||||||
|
|
||||||
|
class LoadFace(Load, speckle_type=STRUCTURAL_LOADING + "LoadFace"):
|
||||||
|
elements: Optional[List] = None
|
||||||
|
loadType: Optional[FaceLoadType] = None
|
||||||
|
direction: Optional[LoadDirection2D] = None
|
||||||
|
loadAxis: Optional[Axis] = None
|
||||||
|
loadAxisType: Optional[LoadAxisType] = None
|
||||||
|
isProjected: Optional[bool] = None
|
||||||
|
values: Optional[List] = None
|
||||||
|
positions: Optional[List] = None
|
||||||
|
|
||||||
|
|
||||||
|
class LoadGravity(Load, speckle_type=STRUCTURAL_LOADING + "LoadGravity"):
|
||||||
|
elements: Optional[List] = None
|
||||||
|
nodes: Optional[List] = None
|
||||||
|
gravityFactors: Optional[Vector] = None
|
||||||
|
|
||||||
|
|
||||||
|
class LoadNode(Load, speckle_type=STRUCTURAL_LOADING + "LoadNode"):
|
||||||
|
nodes: Optional[List] = None
|
||||||
|
loadAxis: Optional[Axis] = None
|
||||||
|
direction: Optional[LoadDirection] = None
|
||||||
|
value: float = 0.0
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
|
||||||
|
STRUCTURAL_MATERIALS = "Objects.Structural.Materials"
|
||||||
|
|
||||||
|
|
||||||
|
class MaterialType(int, Enum):
|
||||||
|
Concrete = 0
|
||||||
|
Steel = 1
|
||||||
|
Timber = 2
|
||||||
|
Aluminium = 3
|
||||||
|
Masonry = 4
|
||||||
|
FRP = 5
|
||||||
|
Glass = 6
|
||||||
|
Fabric = 7
|
||||||
|
Rebar = 8
|
||||||
|
Tendon = 9
|
||||||
|
ColdFormed = 10
|
||||||
|
Other = 11
|
||||||
|
|
||||||
|
|
||||||
|
class StructuralMaterial(
|
||||||
|
Base, speckle_type=STRUCTURAL_MATERIALS + ".StructuralMaterial"
|
||||||
|
):
|
||||||
|
name: Optional[str] = None
|
||||||
|
grade: Optional[str] = None
|
||||||
|
materialType: Optional[MaterialType] = None
|
||||||
|
designCode: Optional[str] = None
|
||||||
|
codeYear: Optional[str] = None
|
||||||
|
strength: float = 0.0
|
||||||
|
elasticModulus: float = 0.0
|
||||||
|
poissonsRatio: float = 0.0
|
||||||
|
shearModulus: float = 0.0
|
||||||
|
density: float = 0.0
|
||||||
|
thermalExpansivity: float = 0.0
|
||||||
|
dampingRatio: float = 0.0
|
||||||
|
cost: float = 0.0
|
||||||
|
materialSafetyFactor: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
class Concrete(StructuralMaterial):
|
||||||
|
compressiveStrength: float = 0.0
|
||||||
|
tensileStrength: float = 0.0
|
||||||
|
flexuralStrength: float = 0.0
|
||||||
|
maxCompressiveStrain: float = 0.0
|
||||||
|
maxTensileStrain: float = 0.0
|
||||||
|
maxAggregateSize: float = 0.0
|
||||||
|
lightweight: Optional[bool] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Steel(StructuralMaterial, speckle_type=STRUCTURAL_MATERIALS + ".Steel"):
|
||||||
|
yieldStrength: float = 0.0
|
||||||
|
ultimateStrength: float = 0.0
|
||||||
|
maxStrain: float = 0.0
|
||||||
|
strainHardeningModulus: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
class Timber(StructuralMaterial, speckle_type=STRUCTURAL_MATERIALS + ".Timber"):
|
||||||
|
species: Optional[str] = None
|
||||||
@@ -0,0 +1,212 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
from specklepy.objects.structural.axis import Axis
|
||||||
|
from specklepy.objects.structural.materials import StructuralMaterial
|
||||||
|
|
||||||
|
STRUCTURAL_PROPERTY = "Objects.Structural.Properties"
|
||||||
|
|
||||||
|
|
||||||
|
class MemberType(int, Enum):
|
||||||
|
Beam = 0
|
||||||
|
Column = 1
|
||||||
|
Generic1D = 2
|
||||||
|
Slab = 3
|
||||||
|
Wall = 4
|
||||||
|
Generic2D = 5
|
||||||
|
VoidCutter1D = 6
|
||||||
|
VoidCutter2D = 7
|
||||||
|
|
||||||
|
|
||||||
|
class BaseReferencePoint(int, Enum):
|
||||||
|
Centroid = 0
|
||||||
|
TopLeft = 1
|
||||||
|
TopCentre = 2
|
||||||
|
TopRight = 3
|
||||||
|
MidLeft = 4
|
||||||
|
MidRight = 5
|
||||||
|
BotLeft = 6
|
||||||
|
BotCentre = 7
|
||||||
|
BotRight = 8
|
||||||
|
|
||||||
|
|
||||||
|
class ReferenceSurface(int, Enum):
|
||||||
|
Top = 0
|
||||||
|
Middle = 1
|
||||||
|
Bottom = 2
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyType2D(int, Enum):
|
||||||
|
Stress = 0
|
||||||
|
Fabric = 1
|
||||||
|
Plate = 2
|
||||||
|
Shell = 3
|
||||||
|
Curved = 4
|
||||||
|
Wall = 5
|
||||||
|
Strain = 6
|
||||||
|
Axi = 7
|
||||||
|
Load = 8
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyType3D(int, Enum):
|
||||||
|
Solid = 0
|
||||||
|
Infinite = 1
|
||||||
|
|
||||||
|
|
||||||
|
class ShapeType(int, Enum):
|
||||||
|
Rectangular = 0
|
||||||
|
Circular = 1
|
||||||
|
I = 2 # noqa: E741
|
||||||
|
Tee = 3
|
||||||
|
Angle = 4
|
||||||
|
Channel = 5
|
||||||
|
Perimeter = 6
|
||||||
|
Box = 7
|
||||||
|
Catalogue = 8
|
||||||
|
Explicit = 9
|
||||||
|
Undefined = 10
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyTypeSpring(int, Enum):
|
||||||
|
Axial = 0
|
||||||
|
Torsional = 1
|
||||||
|
General = 2
|
||||||
|
Matrix = 3
|
||||||
|
TensionOnly = 4
|
||||||
|
CompressionOnly = 5
|
||||||
|
Connector = 6
|
||||||
|
LockUp = 7
|
||||||
|
Gap = 8
|
||||||
|
Friction = 9
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyTypeDamper(int, Enum):
|
||||||
|
Axial = 0
|
||||||
|
Torsional = 1
|
||||||
|
General = 2
|
||||||
|
|
||||||
|
|
||||||
|
class Property(Base, speckle_type=STRUCTURAL_PROPERTY):
|
||||||
|
name: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class SectionProfile(
|
||||||
|
Base, speckle_type=STRUCTURAL_PROPERTY + ".Profiles.SectionProfile"
|
||||||
|
):
|
||||||
|
name: Optional[str] = None
|
||||||
|
shapeType: Optional[ShapeType] = None
|
||||||
|
area: float = 0.0
|
||||||
|
Iyy: float = 0.0
|
||||||
|
Izz: float = 0.0
|
||||||
|
J: float = 0.0
|
||||||
|
Ky: float = 0.0
|
||||||
|
weight: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
class Property1D(Property, speckle_type=STRUCTURAL_PROPERTY + ".Property1D"):
|
||||||
|
memberType: Optional[MemberType] = None
|
||||||
|
material: Optional[StructuralMaterial] = None
|
||||||
|
profile: Optional[SectionProfile] = None
|
||||||
|
referencePoint: Optional[BaseReferencePoint] = None
|
||||||
|
offsetY: float = 0.0
|
||||||
|
offsetZ: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
class Property2D(Property, speckle_type=STRUCTURAL_PROPERTY + ".Property2D"):
|
||||||
|
type: Optional[PropertyType2D] = None
|
||||||
|
thickness: float = 0.0
|
||||||
|
material: Optional[StructuralMaterial] = None
|
||||||
|
orientationAxis: Optional[Axis] = None
|
||||||
|
refSurface: Optional[ReferenceSurface] = None
|
||||||
|
zOffset: float = 0.0
|
||||||
|
modifierInPlane: float = 0.0
|
||||||
|
modifierBending: float = 0.0
|
||||||
|
modifierShear: float = 0.0
|
||||||
|
modifierVolume: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
class Property3D(Property, speckle_type=STRUCTURAL_PROPERTY + ".Property3D"):
|
||||||
|
type: Optional[PropertyType3D] = None
|
||||||
|
material: Optional[StructuralMaterial] = None
|
||||||
|
orientationAxis: Optional[Axis] = None
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyDamper(Property, speckle_type=STRUCTURAL_PROPERTY + ".PropertyDamper"):
|
||||||
|
damperType: Optional[PropertyTypeDamper] = None
|
||||||
|
dampingX: float = 0.0
|
||||||
|
dampingY: float = 0.0
|
||||||
|
dampingZ: float = 0.0
|
||||||
|
dampingXX: float = 0.0
|
||||||
|
dampingYY: float = 0.0
|
||||||
|
dampingZZ: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyMass(Property, speckle_type=STRUCTURAL_PROPERTY + ".PropertyMass"):
|
||||||
|
mass: float = 0.0
|
||||||
|
inertiaXX: float = 0.0
|
||||||
|
inertiaYY: float = 0.0
|
||||||
|
inertiaZZ: float = 0.0
|
||||||
|
inertiaXY: float = 0.0
|
||||||
|
inertiaYZ: float = 0.0
|
||||||
|
inertiaZX: float = 0.0
|
||||||
|
massModified: Optional[bool] = None
|
||||||
|
massModifierX: float = 0.0
|
||||||
|
massModifierY: float = 0.0
|
||||||
|
massModifierZ: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
class PropertySpring(Property, speckle_type=STRUCTURAL_PROPERTY + ".PropertySpring"):
|
||||||
|
springType: Optional[PropertyTypeSpring] = None
|
||||||
|
springCurveX: float = 0.0
|
||||||
|
stiffnessX: float = 0.0
|
||||||
|
springCurveY: float = 0.0
|
||||||
|
stiffnessY: float = 0.0
|
||||||
|
springCurveZ: float = 0.0
|
||||||
|
stiffnessZ: float = 0.0
|
||||||
|
springCurveXX: float = 0.0
|
||||||
|
stiffnessXX: float = 0.0
|
||||||
|
springCurveYY: float = 0.0
|
||||||
|
stiffnessYY: float = 0.0
|
||||||
|
springCurveZZ: float = 0.0
|
||||||
|
stiffnessZZ: float = 0.0
|
||||||
|
dampingRatio: float = 0.0
|
||||||
|
dampingX: float = 0.0
|
||||||
|
dampingY: float = 0.0
|
||||||
|
dampingZ: float = 0.0
|
||||||
|
dampingXX: float = 0.0
|
||||||
|
dampingYY: float = 0.0
|
||||||
|
dampingZZ: float = 0.0
|
||||||
|
matrix: float = 0.0
|
||||||
|
postiveLockup: float = 0.0
|
||||||
|
frictionCoefficient: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
class ReferenceSurfaceEnum(int, Enum):
|
||||||
|
Concrete = 0
|
||||||
|
Steel = 1
|
||||||
|
Timber = 2
|
||||||
|
Aluminium = 3
|
||||||
|
Masonry = 4
|
||||||
|
FRP = 5
|
||||||
|
Glass = 6
|
||||||
|
Fabric = 7
|
||||||
|
Rebar = 8
|
||||||
|
Tendon = 9
|
||||||
|
ColdFormed = 10
|
||||||
|
Other = 11
|
||||||
|
|
||||||
|
|
||||||
|
class shapeType(int, Enum):
|
||||||
|
Concrete = 0
|
||||||
|
Steel = 1
|
||||||
|
Timber = 2
|
||||||
|
Aluminium = 3
|
||||||
|
Masonry = 4
|
||||||
|
FRP = 5
|
||||||
|
Glass = 6
|
||||||
|
Fabric = 7
|
||||||
|
Rebar = 8
|
||||||
|
Tendon = 9
|
||||||
|
ColdFormed = 10
|
||||||
|
Other = 11
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from specklepy.objects.base import Base
|
||||||
|
from specklepy.objects.structural.analysis import Model
|
||||||
|
from specklepy.objects.structural.geometry import Element1D, Element2D, Element3D, Node
|
||||||
|
|
||||||
|
STRUCTURAL_RESULTS = "Objects.Structural.Results."
|
||||||
|
|
||||||
|
|
||||||
|
class Result(Base, speckle_type=STRUCTURAL_RESULTS + "Result"):
|
||||||
|
resultCase: Optional[Base] = None
|
||||||
|
permutation: Optional[str] = None
|
||||||
|
description: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class ResultSet1D(Result, speckle_type=STRUCTURAL_RESULTS + "ResultSet1D"):
|
||||||
|
results1D: List
|
||||||
|
|
||||||
|
|
||||||
|
class Result1D(Result, speckle_type=STRUCTURAL_RESULTS + "Result1D"):
|
||||||
|
element: Optional[Element1D] = None
|
||||||
|
position: Optional[float] = None
|
||||||
|
dispX: Optional[float] = None
|
||||||
|
dispY: Optional[float] = None
|
||||||
|
dispZ: Optional[float] = None
|
||||||
|
rotXX: Optional[float] = None
|
||||||
|
rotYY: Optional[float] = None
|
||||||
|
rotZZ: Optional[float] = None
|
||||||
|
forceX: Optional[float] = None
|
||||||
|
forceY: Optional[float] = None
|
||||||
|
forceZ: Optional[float] = None
|
||||||
|
momentXX: Optional[float] = None
|
||||||
|
momentYY: Optional[float] = None
|
||||||
|
momentZZ: Optional[float] = None
|
||||||
|
axialStress: Optional[float] = None
|
||||||
|
shearStressY: Optional[float] = None
|
||||||
|
shearStressZ: Optional[float] = None
|
||||||
|
bendingStressYPos: Optional[float] = None
|
||||||
|
bendingStressYNeg: Optional[float] = None
|
||||||
|
bendingStressZPos: Optional[float] = None
|
||||||
|
bendingStressZNeg: Optional[float] = None
|
||||||
|
combinedStressMax: Optional[float] = None
|
||||||
|
combinedStressMin: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
|
class ResultSet2D(Result, speckle_type=STRUCTURAL_RESULTS + "ResultSet2D"):
|
||||||
|
results2D: List
|
||||||
|
|
||||||
|
|
||||||
|
class Result2D(Result, speckle_type=STRUCTURAL_RESULTS + "Result2D"):
|
||||||
|
element: Optional[Element2D] = None
|
||||||
|
position: List
|
||||||
|
dispX: Optional[float] = None
|
||||||
|
dispY: Optional[float] = None
|
||||||
|
dispZ: Optional[float] = None
|
||||||
|
forceXX: Optional[float] = None
|
||||||
|
forceYY: Optional[float] = None
|
||||||
|
forceXY: Optional[float] = None
|
||||||
|
momentXX: Optional[float] = None
|
||||||
|
momentYY: Optional[float] = None
|
||||||
|
momentXY: Optional[float] = None
|
||||||
|
shearX: Optional[float] = None
|
||||||
|
shearY: Optional[float] = None
|
||||||
|
stressTopXX: Optional[float] = None
|
||||||
|
stressTopYY: Optional[float] = None
|
||||||
|
stressTopZZ: Optional[float] = None
|
||||||
|
stressTopXY: Optional[float] = None
|
||||||
|
stressTopYZ: Optional[float] = None
|
||||||
|
stressTopZX: Optional[float] = None
|
||||||
|
stressMidXX: Optional[float] = None
|
||||||
|
stressMidYY: Optional[float] = None
|
||||||
|
stressMidZZ: Optional[float] = None
|
||||||
|
stressMidXY: Optional[float] = None
|
||||||
|
stressMidYZ: Optional[float] = None
|
||||||
|
stressMidZX: Optional[float] = None
|
||||||
|
stressBotXX: Optional[float] = None
|
||||||
|
stressBotYY: Optional[float] = None
|
||||||
|
stressBotZZ: Optional[float] = None
|
||||||
|
stressBotXY: Optional[float] = None
|
||||||
|
stressBotYZ: Optional[float] = None
|
||||||
|
stressBotZX: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
|
class ResultSet3D(Result, speckle_type=STRUCTURAL_RESULTS + "ResultSet3D"):
|
||||||
|
results3D: List
|
||||||
|
|
||||||
|
|
||||||
|
class Result3D(Result, speckle_type=STRUCTURAL_RESULTS + "Result3D"):
|
||||||
|
element: Optional[Element3D] = None
|
||||||
|
position: List
|
||||||
|
dispX: Optional[float] = None
|
||||||
|
dispY: Optional[float] = None
|
||||||
|
dispZ: Optional[float] = None
|
||||||
|
stressXX: Optional[float] = None
|
||||||
|
stressYY: Optional[float] = None
|
||||||
|
stressZZ: Optional[float] = None
|
||||||
|
stressXY: Optional[float] = None
|
||||||
|
stressYZ: Optional[float] = None
|
||||||
|
stressZX: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
|
class ResultGlobal(Result, speckle_type=STRUCTURAL_RESULTS + "ResultGlobal"):
|
||||||
|
model: Optional[Model] = None
|
||||||
|
loadX: Optional[float] = None
|
||||||
|
loadY: Optional[float] = None
|
||||||
|
loadZ: Optional[float] = None
|
||||||
|
loadXX: Optional[float] = None
|
||||||
|
loadYY: Optional[float] = None
|
||||||
|
loadZZ: Optional[float] = None
|
||||||
|
reactionX: Optional[float] = None
|
||||||
|
reactionY: Optional[float] = None
|
||||||
|
reactionZ: Optional[float] = None
|
||||||
|
reactionXX: Optional[float] = None
|
||||||
|
reactionYY: Optional[float] = None
|
||||||
|
reactionZZ: Optional[float] = None
|
||||||
|
mode: Optional[float] = None
|
||||||
|
frequency: Optional[float] = None
|
||||||
|
loadFactor: Optional[float] = None
|
||||||
|
modalStiffness: Optional[float] = None
|
||||||
|
modalGeoStiffness: Optional[float] = None
|
||||||
|
effMassX: Optional[float] = None
|
||||||
|
effMassY: Optional[float] = None
|
||||||
|
effMassZ: Optional[float] = None
|
||||||
|
effMassXX: Optional[float] = None
|
||||||
|
effMassYY: Optional[float] = None
|
||||||
|
effMassZZ: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
|
class ResultSetNode(Result, speckle_type=STRUCTURAL_RESULTS + "ResultSetNode"):
|
||||||
|
resultsNode: List
|
||||||
|
|
||||||
|
|
||||||
|
class ResultNode(Result, speckle_type=STRUCTURAL_RESULTS + " ResultNode"):
|
||||||
|
node: Optional[Node] = None
|
||||||
|
dispX: Optional[float] = None
|
||||||
|
dispY: Optional[float] = None
|
||||||
|
dispZ: Optional[float] = None
|
||||||
|
rotXX: Optional[float] = None
|
||||||
|
rotYY: Optional[float] = None
|
||||||
|
rotZZ: Optional[float] = None
|
||||||
|
reactionX: Optional[float] = None
|
||||||
|
reactionY: Optional[float] = None
|
||||||
|
reactionZ: Optional[float] = None
|
||||||
|
reactionXX: Optional[float] = None
|
||||||
|
reactionYY: Optional[float] = None
|
||||||
|
reactionZZ: Optional[float] = None
|
||||||
|
constraintX: Optional[float] = None
|
||||||
|
constraintY: Optional[float] = None
|
||||||
|
constraintZ: Optional[float] = None
|
||||||
|
constraintXX: Optional[float] = None
|
||||||
|
constraintYY: Optional[float] = None
|
||||||
|
constraintZZ: Optional[float] = None
|
||||||
|
velX: Optional[float] = None
|
||||||
|
velY: Optional[float] = None
|
||||||
|
velZ: Optional[float] = None
|
||||||
|
velXX: Optional[float] = None
|
||||||
|
velYY: Optional[float] = None
|
||||||
|
velZZ: Optional[float] = None
|
||||||
|
accX: Optional[float] = None
|
||||||
|
accY: Optional[float] = None
|
||||||
|
accZ: Optional[float] = None
|
||||||
|
accXX: Optional[float] = None
|
||||||
|
accYY: Optional[float] = None
|
||||||
|
accZZ: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
|
class ResultSetAll(Base, speckle_type=None):
|
||||||
|
resultSet1D: Optional[ResultSet1D] = None
|
||||||
|
resultSet2D: Optional[ResultSet2D] = None
|
||||||
|
resultSet3D: Optional[ResultSet3D] = None
|
||||||
|
resultsGlobal: Optional[ResultGlobal] = None
|
||||||
|
resultsNode: Optional[ResultSetNode] = None
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from specklepy.logging.exceptions import SpeckleException, SpeckleInvalidUnitException
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"Units",
|
||||||
|
"get_encoding_from_units",
|
||||||
|
"get_units_from_encoding",
|
||||||
|
"get_units_from_string",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Units(Enum):
|
||||||
|
mm = "mm"
|
||||||
|
cm = "cm"
|
||||||
|
m = "m"
|
||||||
|
km = "km"
|
||||||
|
inches = "in"
|
||||||
|
feet = "ft"
|
||||||
|
yards = "yd"
|
||||||
|
miles = "mi"
|
||||||
|
none = "none"
|
||||||
|
|
||||||
|
|
||||||
|
UNITS_STRINGS = {
|
||||||
|
Units.mm: ["mm", "mil", "millimeters", "millimetres"],
|
||||||
|
Units.cm: ["cm", "centimetre", "centimeter", "centimetres", "centimeters"],
|
||||||
|
Units.m: ["m", "meter", "meters", "metre", "metres"],
|
||||||
|
Units.km: ["km", "kilometer", "kilometre", "kilometers", "kilometres"],
|
||||||
|
Units.inches: ["in", "inch", "inches"],
|
||||||
|
Units.feet: ["ft", "foot", "feet"],
|
||||||
|
Units.yards: ["yd", "yard", "yards"],
|
||||||
|
Units.miles: ["mi", "mile", "miles"],
|
||||||
|
Units.none: ["none", "null"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UNITS_ENCODINGS = {
|
||||||
|
Units.none: 0,
|
||||||
|
None: 0,
|
||||||
|
Units.mm: 1,
|
||||||
|
Units.cm: 2,
|
||||||
|
Units.m: 3,
|
||||||
|
Units.km: 4,
|
||||||
|
Units.inches: 5,
|
||||||
|
Units.feet: 6,
|
||||||
|
Units.yards: 7,
|
||||||
|
Units.miles: 8,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UNIT_SCALE = {
|
||||||
|
Units.none: 1,
|
||||||
|
Units.mm: 0.001,
|
||||||
|
Units.cm: 0.01,
|
||||||
|
Units.m: 1.0,
|
||||||
|
Units.km: 1000.0,
|
||||||
|
Units.inches: 0.0254,
|
||||||
|
Units.feet: 0.3048,
|
||||||
|
Units.yards: 0.9144,
|
||||||
|
Units.miles: 1609.340,
|
||||||
|
}
|
||||||
|
"""Unit scaling factor to meters"""
|
||||||
|
|
||||||
|
|
||||||
|
def get_units_from_string(unit: str) -> Units:
|
||||||
|
if not isinstance(unit, str):
|
||||||
|
raise SpeckleInvalidUnitException(unit)
|
||||||
|
unit = str.lower(unit)
|
||||||
|
for name, alternates in UNITS_STRINGS.items():
|
||||||
|
if unit in alternates:
|
||||||
|
return name
|
||||||
|
raise SpeckleInvalidUnitException(unit)
|
||||||
|
|
||||||
|
|
||||||
|
def get_units_from_encoding(unit: int) -> Units:
|
||||||
|
for name, encoding in UNITS_ENCODINGS.items():
|
||||||
|
if unit == encoding:
|
||||||
|
return name or Units.none
|
||||||
|
|
||||||
|
raise SpeckleException(
|
||||||
|
message=(
|
||||||
|
f"Could not understand what unit {unit} is referring to."
|
||||||
|
f"Please enter a valid unit encoding (eg {UNITS_ENCODINGS})."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_encoding_from_units(unit: Union[Units, str, None]):
|
||||||
|
maybe_sanitized_unit = unit
|
||||||
|
if isinstance(unit, str):
|
||||||
|
for unit_enum, aliases in UNITS_STRINGS.items():
|
||||||
|
if unit in aliases:
|
||||||
|
maybe_sanitized_unit = unit_enum
|
||||||
|
try:
|
||||||
|
return UNITS_ENCODINGS[maybe_sanitized_unit]
|
||||||
|
except KeyError as e:
|
||||||
|
raise SpeckleException(
|
||||||
|
message=(
|
||||||
|
f"No encoding exists for unit {maybe_sanitized_unit}."
|
||||||
|
f"Please enter a valid unit to encode (eg {UNITS_ENCODINGS})."
|
||||||
|
)
|
||||||
|
) from e
|
||||||
|
|
||||||
|
|
||||||
|
def get_scale_factor_from_string(fromUnits: str, toUnits: str) -> float:
|
||||||
|
"""Returns a scalar to convert distance values from one unit system to another"""
|
||||||
|
return get_scale_factor(
|
||||||
|
get_units_from_string(fromUnits), get_units_from_string(toUnits)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_scale_factor(fromUnits: Units, toUnits: Units) -> float:
|
||||||
|
"""Returns a scalar to convert distance values from one unit system to another"""
|
||||||
|
return get_scale_factor_to_meters(fromUnits) / get_scale_factor_to_meters(toUnits)
|
||||||
|
|
||||||
|
|
||||||
|
def get_scale_factor_to_meters(fromUnits: Units) -> float:
|
||||||
|
"""Returns a scalar to convert distance values from one unit system to meters"""
|
||||||
|
if fromUnits not in UNIT_SCALE:
|
||||||
|
raise ValueError(f"Invalid units provided: {fromUnits}")
|
||||||
|
|
||||||
|
return UNIT_SCALE[fromUnits]
|
||||||
@@ -342,7 +342,11 @@ class BaseObjectSerializer:
|
|||||||
object_type = Base.get_registered_type(speckle_type)
|
object_type = Base.get_registered_type(speckle_type)
|
||||||
|
|
||||||
# initialise the base object using `speckle_type` fall back to base if needed
|
# initialise the base object using `speckle_type` fall back to base if needed
|
||||||
base = object_type() if object_type else Base.of_type(speckle_type=speckle_type)
|
base = (
|
||||||
|
object_type.__new__(object_type)
|
||||||
|
if object_type
|
||||||
|
else Base.of_type(speckle_type=speckle_type)
|
||||||
|
)
|
||||||
# get total children count
|
# get total children count
|
||||||
if "__closure" in obj:
|
if "__closure" in obj:
|
||||||
if not self.read_transport:
|
if not self.read_transport:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import pytest
|
|||||||
|
|
||||||
from specklepy.api.client import SpeckleClient
|
from specklepy.api.client import SpeckleClient
|
||||||
from specklepy.core.api.inputs.project_inputs import ProjectCreateInput
|
from specklepy.core.api.inputs.project_inputs import ProjectCreateInput
|
||||||
from specklepy.core.api.inputs.user_inputs import UserUpdateInput
|
from specklepy.core.api.inputs.user_inputs import UserProjectsFilter, UserUpdateInput
|
||||||
from specklepy.core.api.models import ResourceCollection, User
|
from specklepy.core.api.models import ResourceCollection, User
|
||||||
|
|
||||||
|
|
||||||
@@ -42,3 +42,21 @@ class TestActiveUserResource:
|
|||||||
assert len(res.items) == len(existing.items) + 2
|
assert len(res.items) == len(existing.items) + 2
|
||||||
assert any(project.id == p1.id for project in res.items)
|
assert any(project.id == p1.id for project in res.items)
|
||||||
assert any(project.id == p2.id for project in res.items)
|
assert any(project.id == p2.id for project in res.items)
|
||||||
|
|
||||||
|
def test_active_user_get_projects_with_filter(self, client: SpeckleClient):
|
||||||
|
# Since the client may be reused for other tests,
|
||||||
|
# this test does rely on no other test creating a project with "Search for me" in its name
|
||||||
|
p1 = client.project.create(
|
||||||
|
ProjectCreateInput(name="Search for me!", description=None, visibility=None)
|
||||||
|
)
|
||||||
|
_ = client.project.create(
|
||||||
|
ProjectCreateInput(name="But not me!", description=None, visibility=None)
|
||||||
|
)
|
||||||
|
filter = UserProjectsFilter(search="Search for me")
|
||||||
|
|
||||||
|
res = client.active_user.get_projects(filter=filter)
|
||||||
|
|
||||||
|
assert isinstance(res, ResourceCollection)
|
||||||
|
assert len(res.items) == 1
|
||||||
|
assert res.totalCount == 1
|
||||||
|
assert res.items[0].id == p1.id
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ from specklepy.core.api.inputs.model_inputs import (
|
|||||||
DeleteModelInput,
|
DeleteModelInput,
|
||||||
UpdateModelInput,
|
UpdateModelInput,
|
||||||
)
|
)
|
||||||
from specklepy.core.api.inputs.project_inputs import ProjectCreateInput
|
from specklepy.core.api.inputs.project_inputs import (
|
||||||
|
ProjectCreateInput,
|
||||||
|
ProjectModelsFilter,
|
||||||
|
)
|
||||||
from specklepy.core.api.models.current import (
|
from specklepy.core.api.models.current import (
|
||||||
Model,
|
Model,
|
||||||
Project,
|
Project,
|
||||||
@@ -65,6 +68,18 @@ class TestModelResource:
|
|||||||
assert result.createdAt == test_model.createdAt
|
assert result.createdAt == test_model.createdAt
|
||||||
assert result.updatedAt == test_model.updatedAt
|
assert result.updatedAt == test_model.updatedAt
|
||||||
|
|
||||||
|
def test_models_get_with_filter(
|
||||||
|
self, client: SpeckleClient, test_model: Model, test_project: Project
|
||||||
|
):
|
||||||
|
filter = ProjectModelsFilter(search=test_model.name)
|
||||||
|
|
||||||
|
result = client.model.get_models(test_project.id, models_filter=filter)
|
||||||
|
|
||||||
|
assert isinstance(result, ResourceCollection)
|
||||||
|
assert len(result.items) == 1
|
||||||
|
assert result.totalCount == 1
|
||||||
|
assert result.items[0].id == test_model.id
|
||||||
|
|
||||||
def test_get_models(
|
def test_get_models(
|
||||||
self, client: SpeckleClient, test_project: Project, test_model: Model
|
self, client: SpeckleClient, test_project: Project, test_model: Model
|
||||||
):
|
):
|
||||||
@@ -82,6 +97,20 @@ class TestModelResource:
|
|||||||
|
|
||||||
assert isinstance(result, ProjectWithModels)
|
assert isinstance(result, ProjectWithModels)
|
||||||
assert result.id == test_project.id
|
assert result.id == test_project.id
|
||||||
|
assert isinstance(result.models, ResourceCollection)
|
||||||
|
assert len(result.models.items) == 1
|
||||||
|
assert result.models.totalCount == 1
|
||||||
|
assert result.models.items[0].id == test_model.id
|
||||||
|
|
||||||
|
def test_project_get_models_with_filter(
|
||||||
|
self, client: SpeckleClient, test_project: Project, test_model: Model
|
||||||
|
):
|
||||||
|
filter = ProjectModelsFilter(search=test_model.name)
|
||||||
|
result = client.project.get_with_models(test_project.id, models_filter=filter)
|
||||||
|
|
||||||
|
assert isinstance(result, ProjectWithModels)
|
||||||
|
assert result.id == test_project.id
|
||||||
|
assert isinstance(result.models, ResourceCollection)
|
||||||
assert len(result.models.items) == 1
|
assert len(result.models.items) == 1
|
||||||
assert result.models.totalCount == 1
|
assert result.models.totalCount == 1
|
||||||
assert result.models.items[0].id == test_model.id
|
assert result.models.items[0].id == test_model.id
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from specklepy.api.client import SpeckleClient
|
from specklepy.api.client import SpeckleClient
|
||||||
from specklepy.core.api.inputs.model_inputs import CreateModelInput
|
from specklepy.core.api.inputs.model_inputs import CreateModelInput, ModelVersionsFilter
|
||||||
from specklepy.core.api.inputs.project_inputs import ProjectCreateInput
|
from specklepy.core.api.inputs.project_inputs import ProjectCreateInput
|
||||||
from specklepy.core.api.inputs.version_inputs import (
|
from specklepy.core.api.inputs.version_inputs import (
|
||||||
DeleteVersionsInput,
|
DeleteVersionsInput,
|
||||||
@@ -76,6 +76,26 @@ class TestVersionResource:
|
|||||||
assert result.totalCount == 1
|
assert result.totalCount == 1
|
||||||
assert result.items[0].id == test_version.id
|
assert result.items[0].id == test_version.id
|
||||||
|
|
||||||
|
def test_versions_get_with_filter(
|
||||||
|
self,
|
||||||
|
client: SpeckleClient,
|
||||||
|
test_model_1: Model,
|
||||||
|
test_project: Project,
|
||||||
|
test_version: Version,
|
||||||
|
):
|
||||||
|
filter = ModelVersionsFilter(
|
||||||
|
priorityIds=[test_version.id], priorityIdsOnly=True
|
||||||
|
)
|
||||||
|
|
||||||
|
result = client.version.get_versions(
|
||||||
|
test_model_1.id, test_project.id, filter=filter
|
||||||
|
)
|
||||||
|
|
||||||
|
assert isinstance(result, ResourceCollection)
|
||||||
|
assert len(result.items) == 1
|
||||||
|
assert result.totalCount == 1
|
||||||
|
assert result.items[0].id == test_version.id
|
||||||
|
|
||||||
def test_version_received(
|
def test_version_received(
|
||||||
self, client: SpeckleClient, test_version: Version, test_project: Project
|
self, client: SpeckleClient, test_version: Version, test_project: Project
|
||||||
):
|
):
|
||||||
@@ -103,6 +123,27 @@ class TestVersionResource:
|
|||||||
assert result.versions.totalCount == 1
|
assert result.versions.totalCount == 1
|
||||||
assert result.versions.items[0].id == test_version.id
|
assert result.versions.items[0].id == test_version.id
|
||||||
|
|
||||||
|
def test_model_get_with_versions_with_filter(
|
||||||
|
self,
|
||||||
|
client: SpeckleClient,
|
||||||
|
test_model_1: Model,
|
||||||
|
test_project: Project,
|
||||||
|
test_version: Version,
|
||||||
|
):
|
||||||
|
filter = ModelVersionsFilter(
|
||||||
|
priorityIds=[test_version.id], priorityIdsOnly=True
|
||||||
|
)
|
||||||
|
|
||||||
|
result = client.model.get_with_versions(
|
||||||
|
test_model_1.id, test_project.id, versions_filter=filter
|
||||||
|
)
|
||||||
|
|
||||||
|
assert isinstance(result, ModelWithVersions)
|
||||||
|
assert len(result.versions.items) == 1
|
||||||
|
assert result.versions.totalCount == 1
|
||||||
|
assert isinstance(result.versions, ResourceCollection)
|
||||||
|
assert result.versions.items[0].id == test_version.id
|
||||||
|
|
||||||
def test_version_update(
|
def test_version_update(
|
||||||
self, client: SpeckleClient, test_version: Version, test_project: Project
|
self, client: SpeckleClient, test_version: Version, test_project: Project
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Run integration tests with a speckle server."""
|
"""Run integration tests with a speckle server."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ def line(point, interval):
|
|||||||
start=point,
|
start=point,
|
||||||
end=point,
|
end=point,
|
||||||
domain=interval,
|
domain=interval,
|
||||||
units="none"
|
units="none",
|
||||||
# These attributes are not handled in C#
|
# These attributes are not handled in C#
|
||||||
# bbox=None,
|
# bbox=None,
|
||||||
# length=None
|
# length=None
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
# pylint: disable=redefined-outer-name
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from specklepy.core.api.models.instances import InstanceDefinitionProxy, InstanceProxy
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def instance_proxy():
|
|
||||||
return InstanceProxy(
|
|
||||||
definitionId="definitionId", transform=[1, 23.5], units="unit", maxDepth=3
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def instance_definition_proxy():
|
|
||||||
return InstanceDefinitionProxy(
|
|
||||||
objects=["app_id_1", "app_id_2"], maxDepth=2, name="group_proxy_name"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_instance_proxy():
|
|
||||||
try:
|
|
||||||
InstanceProxy(definitionId="", transform="", units="", maxDepth=1) # wrong type
|
|
||||||
assert False
|
|
||||||
except TypeError:
|
|
||||||
assert True
|
|
||||||
except:
|
|
||||||
assert False
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_instance_definition_proxy():
|
|
||||||
try:
|
|
||||||
InstanceDefinitionProxy(objects="", maxDepth=1, name="") # wrong type
|
|
||||||
assert False
|
|
||||||
except TypeError:
|
|
||||||
assert True
|
|
||||||
except:
|
|
||||||
assert False
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
# pylint: disable=redefined-outer-name
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from specklepy.core.api.models.proxies import ColorProxy, GroupProxy
|
|
||||||
from specklepy.objects.other import RenderMaterial, RenderMaterialProxy
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def color_proxy():
|
|
||||||
return ColorProxy(
|
|
||||||
objects=["app_id_1", "app_id_2"], value=11111, name="color_proxy_name"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def group_proxy():
|
|
||||||
return GroupProxy(objects=["app_id_1", "app_id_2"], name="group_proxy_name")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def material():
|
|
||||||
return RenderMaterial(
|
|
||||||
name="name", opacity=0.3, metalness=0, roughness=0, diffuse=1, emissive=1
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def material_proxy():
|
|
||||||
return RenderMaterialProxy(objects=["app_id_1", "app_id_2"], value=material())
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_color_proxy():
|
|
||||||
try:
|
|
||||||
ColorProxy(objects="", value=2, name="") # wrong type
|
|
||||||
assert False
|
|
||||||
except TypeError:
|
|
||||||
assert True
|
|
||||||
except:
|
|
||||||
assert False
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_group_proxy():
|
|
||||||
try:
|
|
||||||
GroupProxy(objects="", name="") # wrong type
|
|
||||||
assert False
|
|
||||||
except TypeError:
|
|
||||||
assert True
|
|
||||||
except:
|
|
||||||
assert False
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_material_proxy():
|
|
||||||
try:
|
|
||||||
RenderMaterialProxy(objects="", name="") # wrong type
|
|
||||||
assert False
|
|
||||||
except TypeError:
|
|
||||||
assert True
|
|
||||||
except:
|
|
||||||
assert False
|
|
||||||
@@ -3,7 +3,7 @@ from typing import Type
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from specklepy.objects.base import Base
|
from specklepy.objects.base import Base
|
||||||
from specklepy.objects.geometry import Line
|
from specklepy.objects.structural import Concrete
|
||||||
|
|
||||||
|
|
||||||
class Foo(Base):
|
class Foo(Base):
|
||||||
@@ -29,8 +29,8 @@ class Baz(Bar):
|
|||||||
"Tests.Unit.TestRegisteringBase.Foo:Custom.Bar:Tests.Unit.TestRegisteringBase.Baz",
|
"Tests.Unit.TestRegisteringBase.Foo:Custom.Bar:Tests.Unit.TestRegisteringBase.Baz",
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Line,
|
Concrete,
|
||||||
"Objects.Geometry.Line",
|
"Objects.Structural.Materials.StructuralMaterial:Objects.Structural.Materials.Concrete",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -43,7 +43,7 @@ def test_determine_speckle_type(klass: Type[Base], speckle_type: str):
|
|||||||
[
|
[
|
||||||
(Base, "Base"),
|
(Base, "Base"),
|
||||||
(Foo, "Tests.Unit.TestRegisteringBase.Foo"),
|
(Foo, "Tests.Unit.TestRegisteringBase.Foo"),
|
||||||
(Line, "Objects.Geometry.Line"),
|
(Concrete, "Objects.Structural.Materials.Concrete"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_full_name(klass: Type[Base], fully_qualified_name: str):
|
def test_full_name(klass: Type[Base], fully_qualified_name: str):
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from specklepy.objects.geometry import Line, Mesh, Point, Vector
|
||||||
|
from specklepy.objects.structural.analysis import Model
|
||||||
|
from specklepy.objects.structural.geometry import (
|
||||||
|
Element1D,
|
||||||
|
Element2D,
|
||||||
|
ElementType1D,
|
||||||
|
ElementType2D,
|
||||||
|
Node,
|
||||||
|
Restraint,
|
||||||
|
)
|
||||||
|
from specklepy.objects.structural.loading import LoadGravity
|
||||||
|
from specklepy.objects.structural.materials import StructuralMaterial
|
||||||
|
from specklepy.objects.structural.properties import (
|
||||||
|
MemberType,
|
||||||
|
Property1D,
|
||||||
|
Property2D,
|
||||||
|
SectionProfile,
|
||||||
|
ShapeType,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def point():
|
||||||
|
return Point(x=1, y=10, z=0)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def vector():
|
||||||
|
return Vector(x=0, y=0, z=-1)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def line(point, interval):
|
||||||
|
return Line(
|
||||||
|
start=point,
|
||||||
|
end=point,
|
||||||
|
domain=interval,
|
||||||
|
# These attributes are not handled in C#
|
||||||
|
# bbox=None,
|
||||||
|
# length=None
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def mesh(box):
|
||||||
|
return Mesh(
|
||||||
|
vertices=[2, 1, 2, 4, 77.3, 5, 33, 4, 2],
|
||||||
|
faces=[1, 2, 3, 4, 5, 6, 7],
|
||||||
|
colors=[111, 222, 333, 444, 555, 666, 777],
|
||||||
|
bbox=box,
|
||||||
|
area=233,
|
||||||
|
volume=232.2,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def restraint():
|
||||||
|
return Restraint(code="FFFFFF")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def node(restraint, point):
|
||||||
|
return Node(basePoint=point, restraint=restraint, name="node1")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def material():
|
||||||
|
return StructuralMaterial(name="TestMaterial")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def memberType():
|
||||||
|
return MemberType(0)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def shapeType():
|
||||||
|
return ShapeType(8)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def sectionProfile(shapeType):
|
||||||
|
return SectionProfile(name="Test", shapeType=shapeType)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def property1D(memberType, sectionProfile, material):
|
||||||
|
return Property1D(
|
||||||
|
Material=material,
|
||||||
|
SectionProfile=sectionProfile,
|
||||||
|
memberType=memberType,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def elementType1D():
|
||||||
|
return ElementType1D(0)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def element1D(line, restraint, elementType1D, property1D):
|
||||||
|
return Element1D(
|
||||||
|
baseLine=line,
|
||||||
|
end1Releases=restraint,
|
||||||
|
end2Releases=restraint,
|
||||||
|
type=elementType1D,
|
||||||
|
property=property1D,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def property2D(material):
|
||||||
|
return Property2D(Material=material)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def elementType2D():
|
||||||
|
return ElementType2D(0)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def element2D(point, elementType2D):
|
||||||
|
return Element2D(
|
||||||
|
topology=[point],
|
||||||
|
type=elementType2D,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def loadGravity(element1D, element2D, vector):
|
||||||
|
return LoadGravity(elements=[element1D, element2D], gravityFactors=vector)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def model(loadGravity, element1D, element2D, material, property1D, property2D):
|
||||||
|
return Model(
|
||||||
|
loads=[loadGravity],
|
||||||
|
elements=[element1D, element2D],
|
||||||
|
materials=[material],
|
||||||
|
properties=[property1D, property2D],
|
||||||
|
)
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Provides uniform and consistent path helpers for `specklepy`
|
Provides uniform and consistent path helpers for `specklepy`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from importlib import import_module, invalidate_caches
|
from importlib import import_module, invalidate_caches
|
||||||
|
|||||||
Reference in New Issue
Block a user