Skip to content

Commit

Permalink
adding data object and QgisObjects and interface (#372)
Browse files Browse the repository at this point in the history
* adding data object and QgisObjects and interface

* new classes

* python 3.9 typing

* rename file
  • Loading branch information
KatKatKateryna authored Jan 24, 2025
1 parent 826dadc commit 0fbfff5
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 6 deletions.
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

0 comments on commit 0fbfff5

Please sign in to comment.