models.py
2.5 kB · python · 103 lines
1from copy import deepcopy2from typing import Dict, List, Optional, TYPE_CHECKING34if TYPE_CHECKING:5 from mrlypy.two.models import Cell2d67class Cell6d:89 def __init__(10 self,11 cell: "Cell2d",12 projection: str = "iso",13 orientation: str = "vertical",14 start: int = 1,15 ):16 self._cell = cell17 self.projection = projection18 self.orientation = orientation19 self.start = start2021 @property22 def cell(self) -> "Cell2d":23 return self._cell2425 @property26 def width(self) -> int:27 return self._cell.width2829 @property30 def height(self) -> int:31 return self._cell.height3233 @property34 def types(self):35 return self._cell.types3637 @types.setter38 def types(self, value):39 self._cell.types = value4041 @property42 def colors(self):43 return self._cell.colors4445 @colors.setter46 def colors(self, value):47 self._cell.colors = value4849 @property50 def tags(self):51 return self._cell.tags5253 @tags.setter54 def tags(self, value):55 self._cell.tags = value5657 @property58 def _types(self):59 return self._cell._types6061 @property62 def _colors(self):63 return self._cell._colors6465 @property66 def _tags(self):67 return self._cell._tags6869 def __repr__(self) -> str:70 return f"Cell6d(width={self.width}, height={self.height}, projection={self.projection})"7172 def copy(self) -> "Cell6d":73 return Cell6d(74 cell=deepcopy(self._cell),75 projection=self.projection,76 orientation=self.orientation,77 start=self.start,78 )7980 def anti(self) -> "Cell6d":81 import numpy as np82 from . import FILL, VOID83 types = self._cell.types84 swapped = types.copy()85 swapped[types == FILL] = VOID86 swapped[types == VOID] = FILL87 self._cell.types = swapped88 return self8990 def text(self, mapping: Optional[Dict[int, str]] = None) -> List[str]:91 return self._cell.text(mapping)9293 def paint(self, palette=None, mode=None) -> "Cell6d":94 from . import painter95 return painter.paint_6d(self, palette, mode)9697 def draw(self, scale: int = 1, outline=None, width: int = 1):98 from . import renderer99 return renderer.draw(self._cell, scale, self.orientation, self.start, outline, width)100101 def svg(self, scale: int = 1, outline=None, width: int = 1) -> str:102 from . import renderer103 return renderer.svg(self._cell, scale, self.orientation, self.start, outline, width)