-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding data object and QgisObjects and interface (#372)
* adding data object and QgisObjects and interface * new classes * python 3.9 typing * rename file
- Loading branch information
1 parent
826dadc
commit 0fbfff5
Showing
3 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .data_objects import DataObject, QgisObject | ||
|
||
__all__ = [ | ||
"DataObject", | ||
"QgisObject", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters