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

adding data object and QgisObjects and interface #372

Merged
merged 6 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/specklepy/objects/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .data_objects import DataObject, QgisObject

__all__ = [
"DataObject",
"QgisObject",
]
81 changes: 81 additions & 0 deletions src/specklepy/objects/data_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from dataclasses import dataclass, field
from typing import Dict, List
from specklepy.objects.base import Base
from specklepy.objects.interfaces import IDataObject, IGisObject, IHasUnits
from specklepy.logging.exceptions import SpeckleException


@dataclass(kw_only=True)
class DataObject(
Base,
IDataObject,
speckle_type="Objects.Data.DataObject",
detachable={"displayValue"},
):

name: str
properties: Dict[str, object]
displayValue: List[Base]
_name: str = field(repr=False, init=False)
_properties: Dict[str, object] = field(repr=False, init=False)
_displayValue: List[Base] = field(repr=False, init=False)

@property
def name(self) -> str:
return self._name

@property
def properties(self) -> Dict[str, object]:
return self._properties

@property
def displayValue(self) -> List[Base]:
return self._displayValue

@name.setter
def name(self, value: str):
if isinstance(value, str):
self._name = value
else:
raise SpeckleException(
f"'name' value should be string, received {type(value)}"
)

@properties.setter
def properties(self, value: dict):
if isinstance(value, dict):
self._properties = value
else:
raise SpeckleException(
f"'properties' value should be Dict, received {type(value)}"
)

@displayValue.setter
def displayValue(self, value: list):
if isinstance(value, list):
self._displayValue = value
else:
raise SpeckleException(
f"'displayValue' value should be List, received {type(value)}"
)


@dataclass(kw_only=True)
class QgisObject(
DataObject, IGisObject, IHasUnits, speckle_type="Objects.Data.QgisObject"
):
type: str
_type: str = field(repr=False, init=False)

@property
def type(self) -> str:
return self._type

@type.setter
def type(self, value: str):
if isinstance(value, str):
self._type = value
else:
raise SpeckleException(
f"'type' value should be string, received {type(value)}"
)
17 changes: 11 additions & 6 deletions src/specklepy/objects/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABCMeta, abstractmethod
from dataclasses import dataclass, field
from typing import Generic, List, TypeVar
from typing import Dict, Generic, List, TypeVar

from specklepy.logging.exceptions import SpeckleInvalidUnitException
from specklepy.objects.base import Base
Expand All @@ -13,8 +13,7 @@
# generic interfaces
@dataclass(kw_only=True)
class ICurve(metaclass=ABCMeta):
_domain: Interval = field(
default_factory=Interval.unit_interval, init=False)
_domain: Interval = field(default_factory=Interval.unit_interval, init=False)

@property
@abstractmethod
Expand All @@ -35,11 +34,10 @@ def domain(self, value: Interval) -> None:
class IDisplayValue(Generic[T], metaclass=ABCMeta):
@property
@abstractmethod
def display_value(self) -> T:
def displayValue(self) -> T:
pass


# field interfaces
# field interfaces
@dataclass(kw_only=True)
class IHasUnits(metaclass=ABCMeta):
Expand Down Expand Up @@ -99,7 +97,7 @@ def volume(self, value: float):
class IProperties(metaclass=ABCMeta):
@property
@abstractmethod
def properties(self) -> dict[str, object]:
def properties(self) -> Dict[str, object]:
pass


Expand All @@ -115,3 +113,10 @@ class IBlenderObject(IDataObject, metaclass=ABCMeta):
@abstractmethod
def type(self) -> str:
pass


class IGisObject(IDataObject, metaclass=ABCMeta):
@property
@abstractmethod
def type(self) -> str:
pass