Skip to content
Closed
4 changes: 3 additions & 1 deletion py3dm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Geometry,
Layer,
LayerTable,
LayerView,
Line,
LineCurve,
ModelComponent,
Expand All @@ -12,8 +13,9 @@
OpenNURBSObject,
Model,
PlotColorSource,
PointGeometry,
Point,
PointTable,
PointView,
Point3d,
TextLog
)
Expand Down
230 changes: 212 additions & 18 deletions py3dm/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,32 @@ class CurveTable:
"""
...

def get_by_uuid_exclusive(self, object_uuid: UUID) -> LineCurve | None:
"""Returns the object with the given ``object_uuid`` or ``None`` if
``object_uuid`` is not found.
"""
...


class CurveView:
"""Tiny wrapper to read-only access `Curve` (``ON_Curve``) objects.
"""
def get_uuid(self) -> UUID:
"""Returns the object UUID.
"""
...

def is_closed(self) -> bool:
"""`True` if the curve is closed (either curve has clamped end knots
and euclidean location of start CV = euclidean location of end CV, or
curve is periodic.
"""
...

def is_linear(self) -> bool: ...

def is_Valid(self, text_log: TextLog) -> bool: ...


class Geometry(OpenNURBSObject):
"""Python bindings for the openNURBS ``ON_Geometry`` class.
Expand Down Expand Up @@ -130,9 +156,6 @@ class Layer(ModelComponent):
@color.setter
def color(self, color: tuple[int, int, int, int]) -> None: ...

@property
def full_path(self) -> str: ...

@property
def iges_level(self) -> int: ...
@iges_level.setter
Expand Down Expand Up @@ -242,9 +265,9 @@ class LayerTable:
``LayerTable`` does not own the underlying data; it operates on the
associated ``ONX_Model`` instance.
"""
def __getitem__(self, index: int) -> Layer: ...
def __getitem__(self, index: int) -> LayerView: ...

def __iter__(self) -> Iterator[Layer]: ...
def __iter__(self) -> Iterator[LayerView]: ...

def __len__(self) -> int: ...

Expand Down Expand Up @@ -290,9 +313,9 @@ class LayerTable:
"""
...

def get_by_index(self, layer_index: int) -> Layer | None:
"""Returns the ``Layer`` if the given ``index`` is found in the table,
``None`` otherwise.
def get_by_index(self, layer_index: int) -> LayerView | None:
"""Returns a view of the ``Layer`` if the given ``index`` is found in
the table, ``None`` otherwise.

Raises
------
Expand All @@ -301,13 +324,19 @@ class LayerTable:
"""
...

def get_by_name(self, full_name: str) -> Layer | None:
"""Returns the ``Layer`` if the given ``full_name`` is found in the
table, ``None`` otherwise.
def get_by_name(self, full_name: str) -> LayerView | None:
"""Returns a view of the ``Layer`` if the given ``full_name`` is found
in the table, ``None`` otherwise.
"""
...

def get_by_uuid(self, layer_uuid: UUID) -> Layer | None:
def get_by_uuid(self, layer_uuid: UUID) -> LayerView | None:
"""Returns a view of the ``Layer`` if the given ``layer_uuid`` is found
in the table, ``None`` otherwise.
"""
...

def get_by_uuid_exclusive(self, layer_uuid: UUID) -> Layer | None:
"""Returns the ``Layer`` if the given ``layer_uuid`` is found in the
table, ``None`` otherwise.
"""
Expand Down Expand Up @@ -338,6 +367,95 @@ class LayerTable:
...


class LayerView:
"""Tiny wrapper to read-only access `Layer` (``ON_Layer``) objects.
"""
# properties
@property
def color(self) -> tuple[int, int, int, int]: ...

@property
def iges_level(self) -> int: ...

@property
def is_expanded(self) -> bool: ...

@property
def is_locked(self) -> bool: ...

@property
def is_visible(self) -> bool: ...

@property
def layer_uuid(self) -> UUID: ...

@property
def line_type_index(self) -> int: ...

@property
def name(self) -> str: ...

@property
def parent_uuid(self) -> UUID: ...

@property
def parent_uuid_is_not_null(self) -> bool: ...

@property
def parent_uuid_is_null(self) -> bool: ...

@property
def path_separator(self) -> str: ...

@property
def plot_color(self) -> tuple[int, int, int, int]: ...

@property
def plot_weight(self) -> float: ...

@property
def render_material_index(self) -> int: ...

@overload
def index(self) -> int:
"""Value of the runtime model component index attribute.

Notes
-----
If the component is in a model, then the index is unique for all
components of identical type in the model and is locked. If the index
has not been set, ``ON_UNSET_INT_INDEX`` is returned. The
``index()`` value can change when saved in an archive (.3dm file).
Use the `get_uuid()` when you need to reference model components in an
archive.
"""
...

@overload
def index(self, unset_index_value: int) -> int:
"""Value of the runtime model component index attribute.

Parameters
----------
unset_index_value: int
Value to return if the index has not been set.
``ON_UNSET_INT_INDEX`` or indices of default components are often
used for this parameter.

Notes
-----
If the component is in a model, then the index is unique for all
components of identical type in the model and is locked. If the index
has not been set, ``unset_index_value`` is returned. The
``index()`` value can change when saved in an archive (.3dm file).
Use the `get_uuid()` when you need to reference model components in an
archive.
"""
...

def is_valid(self, text_log: TextLog | None = None) -> bool: ...


class Line:
"""Python bindings for the openNURBS ``ON_Line`` class.
"""
Expand Down Expand Up @@ -616,7 +734,7 @@ class ModelComponent(OpenNURBSObject):

Parameters
----------
index: int
unset_index_value: int
Value to return if the index has not been set.
``ON_UNSET_INT_INDEX`` or indices of default components are often
used for this parameter.
Expand All @@ -625,7 +743,7 @@ class ModelComponent(OpenNURBSObject):
-----
If the component is in a model, then the index is unique for all
components of identical type in the model and is locked. If the index
has not been set, ``ON_UNSET_INT_INDEX`` is returned. The
has not been set, ``unset_index_value`` is returned. The
``get_index()`` value can change when saved in an archive (.3dm file).
Use the `get_uuid()` when you need to reference model components in an
archive.
Expand Down Expand Up @@ -894,7 +1012,7 @@ class PlotColorSource(Enum):
from_parent = 3


class PointGeometry(Geometry):
class Point(Geometry):
"""Python bindings for the openNURBS ``ON_Point`` class.
"""
# read-write member variables
Expand Down Expand Up @@ -929,7 +1047,7 @@ class PointTable:
associated ``ONX_Model`` instance.
"""
# dunder methods
def __iter__(self) -> Iterator[PointGeometry]: ...
def __iter__(self) -> Iterator[PointView]: ...

def __len__(self) -> int: ...

Expand All @@ -951,7 +1069,7 @@ class PointTable:
@overload
def add(
self,
point: PointGeometry,
point: Point,
obj_attr: None | ObjectAttributes = None
) -> UUID:
"""Returns the ``UUID`` of the point in case of successful addition, or
Expand All @@ -978,9 +1096,79 @@ class PointTable:
"""
...

def get_by_uuid(self, object_uuid: UUID) -> PointGeometry | None:
def get_by_uuid(self, object_uuid: UUID) -> PointView | None:
"""Returns the object with the given ``object_uuid`` or ``None`` if
``object_uuid`` is not found.
"""
...

def get_by_uuid_exclusive(self, object_uuid: UUID) -> Point | None:
"""Returns the object with the given ``object_uuid`` or ``None`` if
``object_uuid`` is not found.

Notes
-----
From opennurbs documentation
(``ON_ModelGeometryComponent::ExclusiveGeometry()``):
Get a pointer to geometry that can be used to modify the geometry. The
returned pointer is not shared at the time it is returned and will not
be shared until a copy of this ``ON_ModelGeometryComponent`` is
created. If this ``ON_ModelGeometryComponent`` is the only reference to
the geometry, then a pointer to the geometry is returned. Otherwise,
``nullptr`` is returned.
"""
...


class PointView:
"""Tiny wrapper to read-only access `Point` (``ON_Point``) objects.
"""
# dunder methods
def __eq__(self, other: object) -> bool: ...

def __ne__(self, other: object) -> bool: ...

# properties
@property
def obj_uuid(self) -> UUID: ...

@property
def x(self) -> float: ...

@property
def y(self) -> float: ...

@property
def z(self) -> float: ...

# other methods
def distance_to(self, point: Point3d) -> float:
"""Returns the distance between the two points.
"""
...

def is_coincident(self, point: Point3d) -> bool:
"""In openNURBS points within ``ON_ZERO_TOLERANCE`` are generally
considered to be the same.

Returns
-------
is_coindent: bool
``True`` if for each coordinate pair
``|a - b| <= ON_ZERO_TOLERANCE`` or
``|a - b| <= (abs(a) + abs(b)) * ON_RELATIVE_TOLERANCE``.

Notes
-----
``ON_ZERO_TOLERANCE`` is set to 2.3283064365386962890625e-10

``ON_RELATIVE_TOLERANCE`` is set to 2.27373675443232059478759765625e-13
"""
...

def is_valid(self, text_log: TextLog | None = None) -> bool:
"""Returns ``False`` if any coordinate is infinite, a nan, or
``ON_UNSET_VALUE``.
"""
...

Expand Down Expand Up @@ -1033,6 +1221,12 @@ class Point3d:
``True`` if for each coordinate pair
``|a - b| <= ON_ZERO_TOLERANCE`` or
``|a - b| <= (abs(a) + abs(b)) * ON_RELATIVE_TOLERANCE``.

Notes
-----
``ON_ZERO_TOLERANCE`` is set to 2.3283064365386962890625e-10

``ON_RELATIVE_TOLERANCE`` is set to 2.27373675443232059478759765625e-13
"""
...

Expand Down
12 changes: 7 additions & 5 deletions src/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@
#include "geometry_bindings.h"
#include "layer_bindings.h"
#include "layer_table_bindings.h"
#include "layer_view_bindings.h"
#include "line_bindings.h"
#include "line_curve_bindings.h"
#include "model_bindings.h"
#include "model_component_bindings.h"
#include "object_attributes_bindings.h"
#include "object_bindings.h"
#include "point_geometry_bindings.h"
#include "point_bindings.h"
#include "point_table_bindings.h"
#include "point_view_bindings.h"
#include "point3d_bindings.h"
#include "text_log_bindings.h"


NB_MODULE(_py3dm, m) {
m.attr("__author__") = "StudioWEngineers";
m.attr("__email__") = "studio.w.engineers@gmail.com";
m.attr("__maintainer__") = "StudioWEngineers";
m.doc() = "Python bindings for openNURBS using nanobind.";

ON::Begin();
Expand All @@ -41,9 +40,12 @@ NB_MODULE(_py3dm, m) {
LayerTableBindings(m);
LineCurveBindings(m);
ModelBindings(m);
PointGeometryBindings(m);
PointBindings(m);
TextLogBindings(m);

LayerViewBindings(m);
PointViewBindings(m);

CurveTableBindings(m);
PointTableBindings(m);
}
Loading
Loading