"""
Copyright (c) 2020, CodeLV.
Distributed under the terms of the GPL v3 License.
The full license is in the file LICENSE, distributed with this software.
Created on March 25, 2020
@author: jrm
"""
from typing import TYPE_CHECKING, Any
from atom.api import Bool, Coerced, Float, ForwardTyped, List, Str, Typed, observe
from enaml.colors import Color, ColorMember
from enaml.core.declarative import d_
from enaml.widgets.control import ProxyControl
from enaml.widgets.toolkit_object import ToolkitObject
from .shape import Direction, coerce_direction
if TYPE_CHECKING:
from OCCT.AIS import AIS_Dimension
class ProxyDimension(ProxyControl):
#: A reference to the Shape declaration.
declaration = ForwardTyped(lambda: Dimension)
def set_shapes(self, shapes: list):
raise NotImplementedError
def set_display(self, display: bool):
raise NotImplementedError
def set_color(self, color: Color):
raise NotImplementedError
def set_direction(self, direction: Direction):
raise NotImplementedError
def set_flyout(self, flyout: float):
raise NotImplementedError
def set_extension_size(self, size: float):
raise NotImplementedError
def set_arrow_tail_size(self, size: float):
raise NotImplementedError
def set_arrow_size(self, size: float):
raise NotImplementedError
def set_arrow_angle(self, angle: float):
raise NotImplementedError
def set_show_units(self, show_units: bool):
raise NotImplementedError
def set_units(self, units: str):
raise NotImplementedError
class ProxyAngleDimension(ProxyControl):
#: A reference to the Shape declaration.
declaration = ForwardTyped(lambda: AngleDimension)
class ProxyLengthDimension(ProxyControl):
#: A reference to the Shape declaration.
declaration = ForwardTyped(lambda: LengthDimension)
class ProxyDiameterDimension(ProxyControl):
#: A reference to the Shape declaration.
declaration = ForwardTyped(lambda: DiameterDimension)
class ProxyRadiusDimension(ProxyControl):
#: A reference to the Shape declaration.
declaration = ForwardTyped(lambda: RadiusDimension)
class Dimension(ToolkitObject):
"""Basic dimension"""
#: Reference to the implementation control
proxy = Typed(ProxyDimension)
#: Whether the dimension should be displayed
display = d_(Bool(True))
#: A string representing the color of the shape.
color = d_(ColorMember()).tag(view=True, group="Display")
#: Show unbits
show_units = d_(Bool(False))
#: Units
units = d_(Str())
def _default_color(self) -> Color:
return Color(0, 0, 0)
#: A tuple or list of the (x, y, z) direction of this shape. This is
#: coerced into a Point. The direction is relative to the dimensions axis.
direction = d_(Coerced(Direction, coercer=coerce_direction))
def _default_direction(self) -> Direction:
return Direction(10, 10, 10)
#: Set the flyout distance.
flyout = d_(Float(0.0, strict=False))
#: Set the extension length (distance from arrow to text).
extension_size = d_(Float(1, strict=False))
#: Set the arrow tail length.
arrow_tail_size = d_(Float(1, strict=False))
#: Set the arrow length.
arrow_size = d_(Float(1, strict=False))
#: Set the arrow angle (in degrees).
arrow_angle = d_(Float(30, strict=False))
#: List of shapes to create the dimension
shapes = d_(List())
@observe(
"display",
"shapes",
"color",
"direction",
"flyout",
"extension_size",
"arrow_tail_size",
"arrow_size",
"arrow_angle",
"show_units",
"units",
)
def _update_proxy(self, change: dict[str, Any]):
super(Dimension, self)._update_proxy(change)
def show(self) -> "AIS_Dimension":
"""Generates the dimension
Returns
-------
dimension: AIS_Dimension
The dimension generated by this declaration.
"""
if not self.is_initialized:
self.initialize()
if not self.proxy_is_active:
self.activate_proxy()
return self.proxy.dimension
[docs]
class AngleDimension(Dimension):
#: Reference to the implementation control
proxy = Typed(ProxyAngleDimension)
[docs]
class LengthDimension(Dimension):
"""A LengthDimension can be created from the following shapes
- An edge
- Two verticies
- Parallel edges
- Parallel faces
"""
#: Reference to the implementation control
proxy = Typed(ProxyLengthDimension)
[docs]
class RadiusDimension(Dimension):
#: Reference to the implementation control
proxy = Typed(ProxyRadiusDimension)
[docs]
class DiameterDimension(Dimension):
#: Reference to the implementation control
proxy = Typed(ProxyDiameterDimension)