Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated instances to match sharp 2.13 changes #263

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions src/specklepy/objects/other.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Any, List, Optional
from deprecated import deprecated

from specklepy.objects.geometry import Point, Vector

from .base import Base

OTHER = "Objects.Other."
OTHER_REVIT = OTHER + "Revit."

IDENTITY_TRANSFORM = [
1.0,
Expand Down Expand Up @@ -72,7 +74,7 @@ class DisplayStyle(Base, speckle_type=OTHER + "DisplayStyle"):
class Transform(
Base,
speckle_type=OTHER + "Transform",
serialize_ignore={"translation", "scaling", "is_identity"},
serialize_ignore={"translation", "scaling", "is_identity", "value"},
):
"""The 4x4 transformation matrix

Expand All @@ -84,12 +86,21 @@ class Transform(
_value: Optional[List[float]] = None

@property
@deprecated(version="2.12", reason="Use matrix")
def value(self) -> List[float]:
"""The transform matrix represented as a flat list of 16 floats"""
return self._value

@value.setter
def value(self, value: List[float]) -> None:
self.matrix = value

@property
def matrix(self) -> List[float]:
"""The transform matrix represented as a flat list of 16 floats"""
return self._value

@matrix.setter
def matrix(self, value: List[float]) -> None:
try:
value = [float(x) for x in value]
except (ValueError, TypeError) as error:
Expand Down Expand Up @@ -118,7 +129,7 @@ def scaling(self) -> List[float]:

@property
def is_identity(self) -> bool:
return self.value == IDENTITY_TRANSFORM
return self._value == IDENTITY_TRANSFORM

def apply_to_point(self, point: Point) -> Point:
"""Transform a single speckle Point
Expand Down Expand Up @@ -236,15 +247,38 @@ class BlockDefinition(
geometry: Optional[List[Base]] = None


class BlockInstance(
Base, speckle_type=OTHER + "BlockInstance", detachable={"blockDefinition"}
class Instance(
Base, speckle_type=OTHER + "Instance", detachable={"definition"}
):
blockDefinition: Optional[BlockDefinition] = None
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"):
class RevitParameter(
Base, speckle_type="Objects.BuiltElements.Revit.Parameter"
):
name: Optional[str] = None
value: Any = None
applicationUnitType: Optional[str] = None # eg UnitType UT_Length
Expand All @@ -254,4 +288,4 @@ class RevitParameter(Base, speckle_type="Objects.BuiltElements.Revit.Parameter")
] = None # BuiltInParameterName or GUID for shared parameter
isShared: bool = False
isReadOnly: bool = False
isTypeParameter: bool = False
isTypeParameter: bool = False