| 1 |
# (C) Copyright 2007-2025 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
|
| 11 |
# Enthought library imports. |
| 12 |
from traits.api import ( |
| 13 |
Array, |
| 14 |
cached_property, |
| 15 |
DelegatesTo, |
| 16 |
HasTraits, |
| 17 |
Instance, |
| 18 |
Interface, |
| 19 |
Property, |
| 20 |
Str, |
| 21 |
Trait, |
| 22 |
) |
| 23 |
from traitsui.api import Group, Item, View |
| 24 |
|
| 25 |
|
| 26 |
class IModel3d(Interface): |
| 27 |
"""A model object that produces an array of 3D points.""" |
| 28 |
|
| 29 |
# The user-visible name of the model. |
| 30 |
name = Str |
| 31 |
|
| 32 |
# An n-by-3 array. |
| 33 |
points = Array |
| 34 |
|
| 35 |
|
| 36 |
class IModel3dIPlottable2dMixin(HasTraits): |
| 37 |
""" |
| 38 |
Mixin class to facilitate defining a IModel3d -> IPlottable2D adapter. |
| 39 |
""" |
| 40 |
|
| 41 |
#### 'Adapter' interface ################################################## |
| 42 |
|
| 43 |
adaptee = Instance(IModel3d) |
| 44 |
|
| 45 |
#### 'IPlottable2D' interface ############################################# |
| 46 |
|
| 47 |
name = DelegatesTo("adaptee") |
| 48 |
|
| 49 |
x_data = Property(Array, observe="adaptee.points, x_label") |
| 50 |
y_data = Property(Array, observe="adaptee.points, y_label") |
| 51 |
|
| 52 |
x_label = Trait("x", {"x": 0, "y": 1, "z": 2}) |
| 53 |
y_label = Trait("y", {"x": 0, "y": 1, "z": 2}) |
| 54 |
|
| 55 |
view = View( |
| 56 |
Group( |
| 57 |
Group( |
| 58 |
Item("adaptee", style="custom", show_label=False), |
| 59 |
label="Model", |
| 60 |
), |
| 61 |
Group( |
| 62 |
Item("x_label", label="X axis"), |
| 63 |
Item("y_label", label="Y axis"), |
| 64 |
label="Plot", |
| 65 |
), |
| 66 |
) |
| 67 |
) |
| 68 |
|
| 69 |
########################################################################### |
| 70 |
# Protected interface. |
| 71 |
########################################################################### |
| 72 |
|
| 73 |
@cached_property |
| 74 |
def _get_x_data(self): |
| 75 |
return self.adaptee.points[:, self.x_label_] |
| 76 |
|
| 77 |
@cached_property |
| 78 |
def _get_y_data(self): |
| 79 |
return self.adaptee.points[:, self.y_label_] |