bindings: one vocabulary for signature types (Renamed<T, Tag>, AnyOf<Tag> and the meanings built from them); every operation's parameters are typed
The three branches had each grown a helper header (Typed/Shown, Renamed/Named, TypedObject/Choice/...); they are one semantic_types.hpp now, with Length, Angle, Point3, Direction3, Vector3, Count, Choice and the plain-double/Vec3 variants as names over the two tools. test_catalog now requires that no parameter of any operation reads "object". Stubs and API pages regenerated. Full suite: 2494 passed, 63 skipped (the 7 collection errors are the untracked stale test files that predate this work). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
## API Definition
|
||||
|
||||
```python
|
||||
def make_cylindrical_surface_rface(radius, u_range, v_range, origin=[0.0, 0.0, 0.0], axis=[0.0, 0.0, 1.0], x_direction=None, *, tolerance=1e-07, tag_prefix=None)
|
||||
def make_cylindrical_surface_rface(radius, u_range, v_range, origin=(0.0, 0.0, 0.0), axis=(0.0, 0.0, 1.0), x_direction=None, *, tolerance=1e-07, tag_prefix=None)
|
||||
```
|
||||
|
||||
*Source: operators/geometry.py*
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
## API Definition
|
||||
|
||||
```python
|
||||
def render_screenshot_rpath(shapes: 'Any', output_path: 'str', highlight_tags: 'Optional[Sequence[str]]' = None, tag_labels: 'Optional[Dict[str, str]]' = None, image_size: 'Tuple[int, int]' = (1400, 900), view: 'Union[Tuple[float, float], str]' = 'auto', views: 'Optional[Sequence[Tuple[float, float, str]]]' = None, show_axes: 'bool' = True, show_legend: 'bool' = True, zoom: 'float' = 4.0, show_callouts: 'bool' = True, linear_deflection: 'Optional[float]' = None, angular_deflection: 'Optional[float]' = None, style: 'str' = 'studio', edge_width_scale: 'Optional[float]' = None, view_up: 'Optional[Sequence[float]]' = None, supersample: 'int' = 2, highlight_edges: 'Optional[Sequence[Any]]' = None, highlight_edge_width: 'float' = 4.5) -> 'str'
|
||||
def render_screenshot_rpath(shapes: 'Solid | Sequence[Solid]', output_path: 'str | PathLike[str]', highlight_tags: 'Sequence[str] | None' = None, tag_labels: 'dict[str, str] | None' = None, image_size: 'tuple[int, int]' = (1400, 900), view: "Literal['auto', 'iso', 'isometric', 'top', 'bottom', 'front', 'back', 'left', 'right', 'front_right', 'front_left', 'rear_right', 'rear_left'] | tuple[Angle, Angle] | None" = 'auto', views: 'Sequence[tuple[Angle, Angle, str]] | None' = None, show_axes: 'bool' = True, show_legend: 'bool' = True, zoom: 'float' = 4.0, show_callouts: 'bool' = True, linear_deflection: 'Length | None' = None, angular_deflection: 'float | None' = None, style: "Literal['studio', 'standard']" = 'studio', edge_width_scale: 'float | None' = None, view_up: 'Direction3 | None' = None, supersample: 'int' = 2, highlight_edges: 'Sequence[AnyShape] | None' = None, highlight_edge_width: 'float' = 4.5) -> 'str'
|
||||
```
|
||||
|
||||
*Source: operators/features.py*
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
## API Definition
|
||||
|
||||
```python
|
||||
def make_ball_bearing_rassembly(bore_diameter: float, outer_diameter: float, bearing_width: float, ball_diameter: float, ball_count: Optional[int] = None, raceway_clearance: float = 0.02, edge_chamfer: float = 0.0, assembly_id: str = 'ball_bearing', drive_angle_degrees: Optional[float] = None, fuse_rolling_elements: bool = False, rolling_element_fuse_overlap: float = 0.01, material: Optional[Material] = None) -> Assembly
|
||||
def make_ball_bearing_rassembly(bore_diameter: Length, outer_diameter: Length, bearing_width: Length, ball_diameter: Length, ball_count: Count | None = None, raceway_clearance: Length = 0.02, edge_chamfer: Length = 0.0, assembly_id: str = 'ball_bearing', drive_angle_degrees: Angle | None = None, fuse_rolling_elements: bool = False, rolling_element_fuse_overlap: Length = 0.01, material: Material | None = None) -> Assembly
|
||||
```
|
||||
|
||||
*Source: std/bearing.py*
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
// The GIL is released around the kernel work, except while a ql selector is being resolved
|
||||
// (a property resolver registered from Python is called back from there).
|
||||
#include "bindings.hpp"
|
||||
#include "typed_object.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -21,6 +20,7 @@ namespace {
|
||||
|
||||
using namespace scad;
|
||||
using scad::pybind::Angle;
|
||||
using scad::pybind::AnyOf;
|
||||
using scad::pybind::Choice;
|
||||
using scad::pybind::Count;
|
||||
using scad::pybind::Direction3;
|
||||
@@ -28,7 +28,6 @@ using scad::pybind::DirectionVec;
|
||||
using scad::pybind::Length;
|
||||
using scad::pybind::PlainQuantity;
|
||||
using scad::pybind::Point3;
|
||||
using scad::pybind::TypedObject;
|
||||
using scad::pybind::Vector3;
|
||||
|
||||
// ---- what the signatures say ------------------------------------------------------------------------------------
|
||||
@@ -63,12 +62,12 @@ SCAD_SIGNATURE_NAME(OffsetKindTag, "typing.Literal['ARC', 'INTERSECTION']");
|
||||
SCAD_SIGNATURE_NAME(SetOperationTag, "typing.Literal['cut', 'intersect', 'union']");
|
||||
#undef SCAD_SIGNATURE_NAME
|
||||
|
||||
using EdgesOrQuery = TypedObject<EdgesTag>;
|
||||
using FacesOrQuery = TypedObject<FacesTag>;
|
||||
using PointArg = TypedObject<scad::pybind::PointTag>; // checked by vector_arg
|
||||
using DirectionArg = TypedObject<scad::pybind::DirectionTag>; // checked by vector_arg
|
||||
using VectorArg = TypedObject<scad::pybind::VectorTag>; // checked by vector_arg
|
||||
using Policy = TypedObject<PolicyTag>;
|
||||
using EdgesOrQuery = AnyOf<EdgesTag>;
|
||||
using FacesOrQuery = AnyOf<FacesTag>;
|
||||
using PointArg = AnyOf<scad::pybind::PointTag>; // checked by vector_arg
|
||||
using DirectionArg = AnyOf<scad::pybind::DirectionTag>; // checked by vector_arg
|
||||
using VectorArg = AnyOf<scad::pybind::VectorTag>; // checked by vector_arg
|
||||
using Policy = AnyOf<PolicyTag>;
|
||||
using Handedness = Choice<HandednessTag>;
|
||||
|
||||
// ---- conversions ---------------------------------------------------------------------------------------------
|
||||
@@ -260,9 +259,9 @@ void bind_blends(py::module_& m) {
|
||||
void bind_sweeps(py::module_& m) {
|
||||
m.def(
|
||||
"loft_rsolid",
|
||||
[](const TypedObject<LoftSectionsTag>& profiles, bool ruled, const Policy& tracking_policy,
|
||||
OptionalString tag_prefix, OptionalString result_tag, OptionalString start_face_tag,
|
||||
OptionalString end_face_tag, OptionalString side_faces_tag) {
|
||||
[](const AnyOf<LoftSectionsTag>& profiles, bool ruled, const Policy& tracking_policy, OptionalString tag_prefix,
|
||||
OptionalString result_tag, OptionalString start_face_tag, OptionalString end_face_tag,
|
||||
OptionalString side_faces_tag) {
|
||||
const std::vector<Shape> sections =
|
||||
shape_list(profiles, "loft_rsolid sections must contain only Wire or Vertex objects");
|
||||
const LoftOptions options{policy_text(tracking_policy),
|
||||
@@ -318,8 +317,8 @@ void bind_sweeps(py::module_& m) {
|
||||
|
||||
m.def(
|
||||
"sweep_multisection_rsolid",
|
||||
[](const TypedObject<SweepSectionsTag>& profiles, const Wire& path, bool is_frenet,
|
||||
const TypedObject<BinormalTag>& binormal_arg) {
|
||||
[](const AnyOf<SweepSectionsTag>& profiles, const Wire& path, bool is_frenet,
|
||||
const AnyOf<BinormalTag>& binormal_arg) {
|
||||
const py::object& binormal = binormal_arg;
|
||||
const std::vector<Shape> sections = shape_list(profiles, "sections must be Face or Wire");
|
||||
std::optional<Binormal> aux;
|
||||
@@ -372,8 +371,8 @@ void bind_derived(py::module_& m) {
|
||||
|
||||
m.def(
|
||||
"extrude_until_rsolid",
|
||||
[](const Face& profile, const TypedObject<TargetTag>& target_arg, const DirectionArg& direction,
|
||||
const TypedObject<UntilTag>& until_arg) {
|
||||
[](const Face& profile, const AnyOf<TargetTag>& target_arg, const DirectionArg& direction,
|
||||
const AnyOf<UntilTag>& until_arg) {
|
||||
const py::object& target = target_arg;
|
||||
const py::object& until = until_arg;
|
||||
std::vector<Solid> targets;
|
||||
@@ -395,7 +394,7 @@ void bind_derived(py::module_& m) {
|
||||
|
||||
m.def(
|
||||
"scale_rsolid",
|
||||
[](const Solid& solid, const TypedObject<FactorsTag>& factors, const PointArg& center) {
|
||||
[](const Solid& solid, const AnyOf<FactorsTag>& factors, const PointArg& center) {
|
||||
const Scalar3 scale = vector_arg(factors, "factors"), about = vector_arg(center, "center");
|
||||
return unlocked(false, [&] { return scale_rsolid(solid, scale, about); });
|
||||
},
|
||||
@@ -529,7 +528,7 @@ void bind_diagnostics(py::module_& m) {
|
||||
|
||||
m.def(
|
||||
"raise_loft_failure_if_diagnosed",
|
||||
[](const TypedObject<ShapesTag>& sections, const std::string& operation) {
|
||||
[](const AnyOf<ShapesTag>& sections, const std::string& operation) {
|
||||
raise_loft_failure_if_diagnosed(shape_list(sections, "loft sections must be shapes"), operation);
|
||||
},
|
||||
py::arg("sections"), py::arg("operation"), "Explain a failed loft from its sections, when they do.");
|
||||
@@ -607,8 +606,7 @@ void bind_booleans(py::module_& m) {
|
||||
|
||||
m.def(
|
||||
"boolean_rsolidlist",
|
||||
[](const TypedObject<SolidsTag>& left, const TypedObject<SolidsTag>& right,
|
||||
const Choice<SetOperationTag>& operation_arg) {
|
||||
[](const AnyOf<SolidsTag>& left, const AnyOf<SolidsTag>& right, const Choice<SetOperationTag>& operation_arg) {
|
||||
const std::string& operation = operation_arg;
|
||||
if (operation != "cut" && operation != "intersect" && operation != "union") {
|
||||
throw ValueError("operation must be cut, intersect or union");
|
||||
@@ -623,7 +621,7 @@ void bind_booleans(py::module_& m) {
|
||||
const char* second, const char* doc) {
|
||||
m.def(
|
||||
name,
|
||||
[fn, name, first, second](const TypedObject<FaceOperandTag>& a_arg, const TypedObject<FaceOperandTag>& b_arg) {
|
||||
[fn, name, first, second](const AnyOf<FaceOperandTag>& a_arg, const AnyOf<FaceOperandTag>& b_arg) {
|
||||
const py::object& a = a_arg;
|
||||
const py::object& b = b_arg;
|
||||
if (!py::isinstance<Shape>(a))
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// simplecadapi/operators/geometry.py, under the Python names, argument names and
|
||||
// defaults (keyword-only where Python is keyword-only), plus the create_* aliases.
|
||||
#include "bindings.hpp"
|
||||
#include "typed_object.hpp"
|
||||
|
||||
#include "scad/core/tolerance.hpp"
|
||||
#include "scad/io/brep_region.hpp"
|
||||
@@ -21,11 +20,11 @@ namespace {
|
||||
|
||||
using namespace scad;
|
||||
using scad::pybind::Angle;
|
||||
using scad::pybind::AnyOf;
|
||||
using scad::pybind::Choice;
|
||||
using scad::pybind::Direction3;
|
||||
using scad::pybind::Length;
|
||||
using scad::pybind::Point3;
|
||||
using scad::pybind::TypedObject;
|
||||
using scad::pybind::Vector3;
|
||||
using namespace pybind11::literals;
|
||||
|
||||
@@ -62,7 +61,7 @@ double degree_of(const py::object& degree) {
|
||||
return degree.cast<double>();
|
||||
}
|
||||
|
||||
SplineSpec spline_spec(std::vector<ScalarPoint> control_points, const TypedObject<DegreeTag>& degree,
|
||||
SplineSpec spline_spec(std::vector<ScalarPoint> control_points, const AnyOf<DegreeTag>& degree,
|
||||
std::optional<ScalarList> knots, std::optional<std::vector<int>> multiplicities,
|
||||
std::optional<ScalarList> weights, bool periodic) {
|
||||
return {.control_points = std::move(control_points),
|
||||
@@ -195,12 +194,12 @@ void bind_arcs(py::module_& m) {
|
||||
|
||||
void bind_splines(py::module_& m) {
|
||||
const auto exact = [](auto fn) {
|
||||
return [fn](std::vector<ScalarPoint> control_points, const TypedObject<DegreeTag>& degree,
|
||||
std::optional<ScalarList> knots, std::optional<std::vector<int>> multiplicities,
|
||||
std::optional<ScalarList> weights, bool periodic) {
|
||||
return fn(spline_spec(std::move(control_points), degree, std::move(knots), std::move(multiplicities),
|
||||
std::move(weights), periodic));
|
||||
};
|
||||
return
|
||||
[fn](std::vector<ScalarPoint> control_points, const AnyOf<DegreeTag>& degree, std::optional<ScalarList> knots,
|
||||
std::optional<std::vector<int>> multiplicities, std::optional<ScalarList> weights, bool periodic) {
|
||||
return fn(spline_spec(std::move(control_points), degree, std::move(knots), std::move(multiplicities),
|
||||
std::move(weights), periodic));
|
||||
};
|
||||
};
|
||||
m.def("make_spline_redge", exact(&make_spline_redge), py::kw_only(), py::arg("control_points"), py::arg("degree") = 3,
|
||||
py::arg("knots") = py::none(), py::arg("multiplicities") = py::none(), py::arg("weights") = py::none(),
|
||||
@@ -364,7 +363,7 @@ void bind_primitives(py::module_& m) {
|
||||
void bind_brep_region(py::module_& m) {
|
||||
m.def(
|
||||
"load_brep_region_rsolid",
|
||||
[](const TypedObject<PathTag>& path, const std::string& sha256, const OptionalString& tag_prefix) {
|
||||
[](const AnyOf<PathTag>& path, const std::string& sha256, const OptionalString& tag_prefix) {
|
||||
return load_brep_region_rsolid(path_text(path), sha256, tag_prefix);
|
||||
},
|
||||
py::arg("path"), py::arg("sha256"), py::kw_only(), py::arg("tag_prefix") = py::none(),
|
||||
@@ -375,14 +374,14 @@ void bind_brep_region(py::module_& m) {
|
||||
"sidecar bytes.");
|
||||
m.def(
|
||||
"_brep_region_path",
|
||||
[](const TypedObject<PathTag>& path, bool for_graph) {
|
||||
[](const AnyOf<PathTag>& path, bool for_graph) {
|
||||
return scad::io::checked_region_path(path_text(path), for_graph);
|
||||
},
|
||||
py::arg("path"), py::kw_only(), py::arg("for_graph"),
|
||||
"The checks on a .scadbrep locator (graph replay: relative, no drive, no '..', '/' separators).");
|
||||
m.def(
|
||||
"load_brep_region_rshell",
|
||||
[](const TypedObject<PathTag>& path, const std::string& sha256, const OptionalString& tag_prefix) {
|
||||
[](const AnyOf<PathTag>& path, const std::string& sha256, const OptionalString& tag_prefix) {
|
||||
return load_brep_region_rshell(path_text(path), sha256, tag_prefix);
|
||||
},
|
||||
py::arg("path"), py::arg("sha256"), py::kw_only(), py::arg("tag_prefix") = py::none(),
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
// Every operator takes py::object for the arguments whose type Python checks inside its wrapped
|
||||
// body, and converts them inside guard_operation, so a wrong type is the operation's
|
||||
// SimpleCADError exactly as in Python (see bind_product_args.hpp). The py::object arrives as a
|
||||
// `Typed<Name>` (typed_args.hpp), so the signature still says what each argument is.
|
||||
// `AnyOf<Name>` (semantic_types.hpp), so the signature still says what each argument is.
|
||||
#include "bind_product_args.hpp"
|
||||
#include "typed_args.hpp"
|
||||
|
||||
#include "scad/reactive/registry.hpp"
|
||||
|
||||
@@ -52,35 +51,35 @@ SCAD_SIGNATURE_NAME(Ref, type_name<sp::ConnectorRef>());
|
||||
SCAD_SIGNATURE_NAME(Limit, type_name<sp::ScalarLimit>() + kOrNone);
|
||||
} // namespace names
|
||||
|
||||
using scad::pybind::Typed;
|
||||
using TextArg = Typed<names::Text>;
|
||||
using NameArg = Typed<names::TextOrNone>; // anything str() takes: a display name
|
||||
using TextOrNoneArg = Typed<names::TextOrNone>;
|
||||
using NumberArg = Typed<names::Number>;
|
||||
using NumberOrNoneArg = Typed<names::NumberOrNone>;
|
||||
using BoolArg = Typed<names::Bool>; // any object, read by its truth value
|
||||
using ColorArg = Typed<names::Color>;
|
||||
using LengthArg = Typed<names::Length>;
|
||||
using LengthOrNoneArg = Typed<names::LengthOrNone>;
|
||||
using AngleOrNoneArg = Typed<names::AngleOrNone>;
|
||||
using PointArg = Typed<names::Point>;
|
||||
using PointOrNoneArg = Typed<names::PointOrNone>;
|
||||
using DirectionArg = Typed<names::Direction>;
|
||||
using DirectionOrNoneArg = Typed<names::DirectionOrNone>;
|
||||
using DirectionsArg = Typed<names::Directions>;
|
||||
using WeightsArg = Typed<names::Weights>;
|
||||
using SolidArg = Typed<names::Solid>;
|
||||
using FaceArg = Typed<names::Face>;
|
||||
using EdgeArg = Typed<names::Edge>;
|
||||
using VertexArg = Typed<names::Vertex>;
|
||||
using PartArg = Typed<names::Part>;
|
||||
using AssemblyArg = Typed<names::Assembly>;
|
||||
using ItemArg = Typed<names::Item>;
|
||||
using PlacementArg = Typed<names::Placement>;
|
||||
using MaterialArg = Typed<names::Material>;
|
||||
using ConnectorArg = Typed<names::Connector>;
|
||||
using RefArg = Typed<names::Ref>;
|
||||
using LimitArg = Typed<names::Limit>;
|
||||
using scad::pybind::AnyOf;
|
||||
using TextArg = AnyOf<names::Text>;
|
||||
using NameArg = AnyOf<names::TextOrNone>; // anything str() takes: a display name
|
||||
using TextOrNoneArg = AnyOf<names::TextOrNone>;
|
||||
using NumberArg = AnyOf<names::Number>;
|
||||
using NumberOrNoneArg = AnyOf<names::NumberOrNone>;
|
||||
using BoolArg = AnyOf<names::Bool>; // any object, read by its truth value
|
||||
using ColorArg = AnyOf<names::Color>;
|
||||
using LengthArg = AnyOf<names::Length>;
|
||||
using LengthOrNoneArg = AnyOf<names::LengthOrNone>;
|
||||
using AngleOrNoneArg = AnyOf<names::AngleOrNone>;
|
||||
using PointArg = AnyOf<names::Point>;
|
||||
using PointOrNoneArg = AnyOf<names::PointOrNone>;
|
||||
using DirectionArg = AnyOf<names::Direction>;
|
||||
using DirectionOrNoneArg = AnyOf<names::DirectionOrNone>;
|
||||
using DirectionsArg = AnyOf<names::Directions>;
|
||||
using WeightsArg = AnyOf<names::Weights>;
|
||||
using SolidArg = AnyOf<names::Solid>;
|
||||
using FaceArg = AnyOf<names::Face>;
|
||||
using EdgeArg = AnyOf<names::Edge>;
|
||||
using VertexArg = AnyOf<names::Vertex>;
|
||||
using PartArg = AnyOf<names::Part>;
|
||||
using AssemblyArg = AnyOf<names::Assembly>;
|
||||
using ItemArg = AnyOf<names::Item>;
|
||||
using PlacementArg = AnyOf<names::Placement>;
|
||||
using MaterialArg = AnyOf<names::Material>;
|
||||
using ConnectorArg = AnyOf<names::Connector>;
|
||||
using RefArg = AnyOf<names::Ref>;
|
||||
using LimitArg = AnyOf<names::Limit>;
|
||||
|
||||
const sp::Assembly& assembly_arg(const py::object& value) {
|
||||
return typed<sp::Assembly>(value, "assembly must be an Assembly");
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
// the member or its string value ("local"), and returns members. The casters below are the only
|
||||
// ones for these types in the module.
|
||||
#include "bindings.hpp"
|
||||
#include "typed_args.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
@@ -651,9 +650,9 @@ void bind_operators(py::module_& m) {
|
||||
|
||||
m.def(
|
||||
"apply_tag_rselection",
|
||||
[](const Shape& scope, const scad::pybind::Typed<TagTargetsName>& targets, const std::string& tag,
|
||||
scad::pybind::Shown<TopologyPropagation, TopologyPropagationName> topology,
|
||||
scad::pybind::Shown<LineagePolicy, LineagePolicyName> lineage) {
|
||||
[](const Shape& scope, const scad::pybind::AnyOf<TagTargetsName>& targets, const std::string& tag,
|
||||
scad::pybind::Renamed<TopologyPropagation, TopologyPropagationName> topology,
|
||||
scad::pybind::Renamed<LineagePolicy, LineagePolicyName> lineage) {
|
||||
static const ErrorSpec spec{
|
||||
"apply_tag_rselection",
|
||||
"Failed to attach the tag to the selected shapes.",
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// the solver backend registry (duck-typed Python backends included) and the 42
|
||||
// operators, under the names and signatures of simplecadapi.
|
||||
#include "bindings.hpp"
|
||||
#include "semantic_names.hpp"
|
||||
#include "py_lifetime.hpp"
|
||||
|
||||
#include <mutex>
|
||||
@@ -129,9 +128,9 @@ using namespace scad;
|
||||
using pybind::value_from_python;
|
||||
using pybind::value_to_python;
|
||||
using scad::pybind::Angle;
|
||||
using scad::pybind::AnyOf;
|
||||
using scad::pybind::Choice;
|
||||
using scad::pybind::Length;
|
||||
using scad::pybind::Named;
|
||||
|
||||
// The names the signatures show.
|
||||
struct PlaneTag { // read by make_sketch_rsketch: a named plane or {"origin", "x_axis", "y_axis"}
|
||||
@@ -596,7 +595,7 @@ void bind_sketch_class(py::module_& m) {
|
||||
void bind_entity_operators(py::module_& m) {
|
||||
m.def(
|
||||
"make_sketch_rsketch",
|
||||
[](const std::optional<std::string>& name, const Named<PlaneTag>& plane,
|
||||
[](const std::optional<std::string>& name, const AnyOf<PlaneTag>& plane,
|
||||
const std::optional<std::string>& sketch_id) {
|
||||
return make_sketch_rsketch(name, value_from_python(plane.value), sketch_id);
|
||||
},
|
||||
@@ -646,7 +645,7 @@ void bind_entity_operators(py::module_& m) {
|
||||
py::arg("sketch"), py::arg("a"), py::arg("b"), py::arg("distance"));
|
||||
m.def(
|
||||
"project_rsketch",
|
||||
[](const Sketch& sketch, const Named<ProjectSourceTag>& source_arg,
|
||||
[](const Sketch& sketch, const AnyOf<ProjectSourceTag>& source_arg,
|
||||
const std::optional<std::vector<std::string>>& entities, bool construction) -> Sketch {
|
||||
const py::object& source = source_arg.value;
|
||||
if (py::isinstance<Sketch>(source))
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
// executor to register: a recorded gear replays through the operators it was made of.
|
||||
// `build_ball_bearing` (the durable-definition wrapper over the build layer) is not provided.
|
||||
#include "bindings.hpp"
|
||||
#include "typed_args.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -23,14 +22,12 @@ namespace {
|
||||
|
||||
using namespace scad;
|
||||
|
||||
// What the arguments mean, for the signature (typed_args.hpp): each converts exactly as the double / int / object it
|
||||
// wraps, so the factories take what they took before.
|
||||
struct CountTag {
|
||||
static constexpr auto name = py::detail::const_name("simplecadapi.types.Count");
|
||||
};
|
||||
using Length = scad::pybind::Shown<double, scad::pybind::LengthTag>;
|
||||
using Angle = scad::pybind::Shown<double, scad::pybind::AngleTag>;
|
||||
using Count = scad::pybind::Shown<int, CountTag>;
|
||||
// What the arguments mean, for the signature (semantic_types.hpp): each converts exactly as the double / int / object
|
||||
// it wraps, so the factories take what they took before.
|
||||
using CountTag = scad::pybind::CountTag;
|
||||
using Length = scad::pybind::PlainQuantity<scad::pybind::LengthTag>;
|
||||
using Angle = scad::pybind::PlainQuantity<scad::pybind::AngleTag>;
|
||||
using Count = scad::pybind::Count;
|
||||
|
||||
namespace names {
|
||||
using py::detail::const_name;
|
||||
@@ -47,16 +44,16 @@ SCAD_SIGNATURE_NAME(NutStyle, const_name("typing.Literal['hex', 'square', 'round
|
||||
SCAD_SIGNATURE_NAME(HoleStyle, const_name("typing.Literal['through', 'blind']"));
|
||||
} // namespace names
|
||||
|
||||
using CountArg = scad::pybind::Typed<CountTag>; // checked as a plain int by the factory
|
||||
using CountOrNoneArg = scad::pybind::Typed<names::CountOrNone>;
|
||||
using MaterialOrNoneArg = scad::pybind::Typed<names::MaterialOrNone>;
|
||||
using HeadStyleArg = scad::pybind::Typed<names::HeadStyle>;
|
||||
using ThreadStyleArg = scad::pybind::Typed<names::ThreadStyle>;
|
||||
using ThreadDetailArg = scad::pybind::Typed<names::ThreadDetail>;
|
||||
using ThreadFormArg = scad::pybind::Typed<names::ThreadForm>;
|
||||
using DriveStyleArg = scad::pybind::Typed<names::DriveStyle>;
|
||||
using NutStyleArg = scad::pybind::Typed<names::NutStyle>;
|
||||
using HoleStyleArg = scad::pybind::Typed<names::HoleStyle>;
|
||||
using CountArg = scad::pybind::AnyOf<CountTag>; // checked as a plain int by the factory
|
||||
using CountOrNoneArg = scad::pybind::AnyOf<names::CountOrNone>;
|
||||
using MaterialOrNoneArg = scad::pybind::AnyOf<names::MaterialOrNone>;
|
||||
using HeadStyleArg = scad::pybind::AnyOf<names::HeadStyle>;
|
||||
using ThreadStyleArg = scad::pybind::AnyOf<names::ThreadStyle>;
|
||||
using ThreadDetailArg = scad::pybind::AnyOf<names::ThreadDetail>;
|
||||
using ThreadFormArg = scad::pybind::AnyOf<names::ThreadForm>;
|
||||
using DriveStyleArg = scad::pybind::AnyOf<names::DriveStyle>;
|
||||
using NutStyleArg = scad::pybind::AnyOf<names::NutStyle>;
|
||||
using HoleStyleArg = scad::pybind::AnyOf<names::HoleStyle>;
|
||||
|
||||
// Runs `body` with the GIL released; an exception leaves with the GIL back.
|
||||
template <class F>
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
// the Python package. This is also where the units hook of the surface area is wired to the
|
||||
// reactive area's dimension inference.
|
||||
#include "bindings.hpp"
|
||||
#include "semantic_names.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <optional>
|
||||
@@ -37,10 +36,10 @@
|
||||
namespace {
|
||||
|
||||
using namespace scad;
|
||||
using scad::pybind::AnyOf;
|
||||
using scad::pybind::Choice;
|
||||
using scad::pybind::Direction3;
|
||||
using scad::pybind::Length;
|
||||
using scad::pybind::Named;
|
||||
using scad::pybind::Point3;
|
||||
using scad::pybind::PointVec3;
|
||||
|
||||
@@ -276,7 +275,7 @@ void bind_surface(py::module_& m) {
|
||||
|
||||
m.def(
|
||||
"loft_rshell",
|
||||
[](const std::vector<Named<LoftSectionTag>>& raw_sections, bool ruled, const TagPrefix& tag_prefix,
|
||||
[](const std::vector<AnyOf<LoftSectionTag>>& raw_sections, bool ruled, const TagPrefix& tag_prefix,
|
||||
const std::optional<std::string>& result_tag, const std::optional<std::string>& start_wire_tag,
|
||||
const std::optional<std::string>& end_wire_tag, const std::optional<std::string>& side_faces_tag) {
|
||||
std::vector<LoftSection> sections;
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
// More signature names for what a parameter means (see semantic_types.hpp), for the surface and sketch bindings.
|
||||
//
|
||||
// Renamed<T, Tag> a T, loaded and cast exactly as T is; the signature says Tag::name
|
||||
// PointVec3 a position (x, y, z) read exactly as scad::Vec3 is (a 3-sequence, or an object with x, y, z);
|
||||
// the signature says simplecadapi.types.Point3
|
||||
// Choice<Tag> text with fixed choices, read exactly as std::string is; the signature says Literal[...]
|
||||
// Named<Tag> any Python object (the binding checks it, as with a py::object parameter); the signature says the
|
||||
// types the binding accepts
|
||||
//
|
||||
// The sketch casters (bind_sketch.cpp) name a position in the sketch plane simplecadapi.types.Point2.
|
||||
#pragma once
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "scad/core/vec.hpp"
|
||||
#include "semantic_types.hpp"
|
||||
|
||||
namespace scad::pybind {
|
||||
|
||||
// A value loaded and cast exactly as T is, under another name in the signature.
|
||||
template <class T, class Tag>
|
||||
struct Renamed {
|
||||
T value;
|
||||
operator const T&() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
};
|
||||
|
||||
using PointVec3 = Renamed<Vec3, PointTag>;
|
||||
template <class Tag>
|
||||
using Choice = Renamed<std::string, Tag>;
|
||||
|
||||
template <class Tag>
|
||||
struct Named {
|
||||
pybind11::object value;
|
||||
};
|
||||
|
||||
} // namespace scad::pybind
|
||||
|
||||
namespace pybind11::detail {
|
||||
|
||||
template <class T, class Tag>
|
||||
struct type_caster<scad::pybind::Renamed<T, Tag>> {
|
||||
using Type = scad::pybind::Renamed<T, Tag>;
|
||||
PYBIND11_TYPE_CASTER(Type, Tag::name);
|
||||
|
||||
bool load(handle src, bool convert) {
|
||||
make_caster<T> inner;
|
||||
if (!inner.load(src, convert))
|
||||
return false;
|
||||
value.value = cast_op<T&&>(std::move(inner));
|
||||
return true;
|
||||
}
|
||||
static handle cast(const Type& r, return_value_policy policy, handle parent) {
|
||||
return make_caster<T>::cast(r.value, policy, parent);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tag>
|
||||
struct type_caster<scad::pybind::Named<Tag>> {
|
||||
PYBIND11_TYPE_CASTER(scad::pybind::Named<Tag>, Tag::name);
|
||||
|
||||
bool load(handle src, bool /*convert*/) {
|
||||
if (!src)
|
||||
return false;
|
||||
value.value = reinterpret_borrow<object>(src);
|
||||
return true;
|
||||
}
|
||||
static handle cast(const scad::pybind::Named<Tag>& n, return_value_policy, handle) { return n.value.inc_ref(); }
|
||||
};
|
||||
|
||||
} // namespace pybind11::detail
|
||||
@@ -1,39 +1,59 @@
|
||||
// What a parameter means, in the signature itself: the Python-facing types of the bound operations.
|
||||
//
|
||||
// A binding declares `const Length& radius` instead of `const Scalar& radius`; the value converts to the Scalar the
|
||||
// kernel takes (so the body of the binding does not change), and the signature pybind writes reads `radius: Length`.
|
||||
// The names are the typing aliases of `simplecadapi.types`, so the stubs, the API pages and the operation catalog
|
||||
// (`simplecadapi.catalog`) all read the meaning from the one place it is written: the binding.
|
||||
// A binding declares `const Length& radius` instead of `const Scalar& radius`; the value converts to what the kernel
|
||||
// takes (so the body of the binding does not change), and the signature pybind writes reads
|
||||
// `radius: simplecadapi.types.Length`. The names are the typing aliases of `simplecadapi.types`, so the stubs, the API
|
||||
// pages and the operation catalog (`simplecadapi.catalog`) all read the meaning from the one place it is written: here,
|
||||
// in the binding. There are two tools and the names built from them:
|
||||
//
|
||||
// Renamed<T, Tag> a T, loaded and cast exactly as T is (same conversions, same errors); the signature says
|
||||
// Tag::name. AnyOf<Tag> any Python object, passed on as the py::object the binding read before (the binding or
|
||||
// the
|
||||
// operation checks it, with the errors it always raised); the signature says the types it accepts.
|
||||
//
|
||||
// Length a distance (mm by default; a `scad.var` with a length unit) float | Expr
|
||||
// Angle an angle in degrees float | Expr
|
||||
// Point3 a position (x, y, z) 3 x (float | Expr)
|
||||
// Direction3 a direction or an axis (its length does not matter) 3 x (float | Expr)
|
||||
// Vector3 an offset (direction and length) 3 x (float | Expr)
|
||||
// PointVec3 / DirectionVec a position / a direction read as a plain Vec3 (no expressions)
|
||||
// PlainQuantity<Tag> a meaning above read as a plain double (no expressions)
|
||||
// Count a whole number of things
|
||||
// Choice<Tag> text with fixed choices; Tag::name is the Literal[...] that lists them
|
||||
//
|
||||
// Plain `Scalar` stays for numbers without a unit (a factor, a tolerance); plain `Scalar3` for anything else.
|
||||
// Plain `Scalar` stays for numbers without a unit (a factor, a tolerance); plain `Scalar3` for anything else. A tag is
|
||||
// a struct with `static constexpr auto name = <pybind descr>`; SCAD_SIGNATURE_NAME declares one, and type_name<T>() is
|
||||
// the descr pybind prints for a bound class.
|
||||
#pragma once
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "scad/core/scalar.hpp"
|
||||
#include "scad/core/vec.hpp"
|
||||
|
||||
namespace scad::pybind {
|
||||
|
||||
template <class Tag>
|
||||
struct Quantity {
|
||||
Scalar value;
|
||||
template <class T, class Tag>
|
||||
struct Renamed {
|
||||
T value;
|
||||
// The binding passes it on as is.
|
||||
operator const Scalar&() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
operator const T&() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
};
|
||||
|
||||
template <class Tag>
|
||||
struct Quantity3 {
|
||||
std::array<Scalar, 3> value;
|
||||
operator const std::array<Scalar, 3>&() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
struct AnyOf {
|
||||
pybind11::object value;
|
||||
operator const pybind11::object&() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
bool is_none() const { return value.is_none(); }
|
||||
template <class T>
|
||||
T cast() const {
|
||||
return value.cast<T>();
|
||||
}
|
||||
};
|
||||
|
||||
struct LengthTag {
|
||||
@@ -51,48 +71,70 @@ struct DirectionTag {
|
||||
struct VectorTag {
|
||||
static constexpr auto name = pybind11::detail::const_name("simplecadapi.types.Vector3");
|
||||
};
|
||||
struct CountTag {
|
||||
static constexpr auto name = pybind11::detail::const_name("simplecadapi.types.Count");
|
||||
};
|
||||
|
||||
using Length = Quantity<LengthTag>;
|
||||
using Angle = Quantity<AngleTag>;
|
||||
using Point3 = Quantity3<PointTag>;
|
||||
using Direction3 = Quantity3<DirectionTag>;
|
||||
using Vector3 = Quantity3<VectorTag>;
|
||||
using Length = Renamed<Scalar, LengthTag>;
|
||||
using Angle = Renamed<Scalar, AngleTag>;
|
||||
using Point3 = Renamed<std::array<Scalar, 3>, PointTag>;
|
||||
using Direction3 = Renamed<std::array<Scalar, 3>, DirectionTag>;
|
||||
using Vector3 = Renamed<std::array<Scalar, 3>, VectorTag>;
|
||||
using PointVec3 = Renamed<Vec3, PointTag>;
|
||||
using DirectionVec = Renamed<Vec3, DirectionTag>;
|
||||
template <class Tag>
|
||||
using PlainQuantity = Renamed<double, Tag>;
|
||||
using Count = Renamed<int, CountTag>;
|
||||
template <class Tag>
|
||||
using Choice = Renamed<std::string, Tag>;
|
||||
|
||||
// The descr pybind prints for a bound class.
|
||||
template <class T>
|
||||
constexpr auto type_name() {
|
||||
return pybind11::detail::make_caster<T>::name;
|
||||
}
|
||||
// Words for the names.
|
||||
inline constexpr auto kOr = pybind11::detail::const_name(" | ");
|
||||
inline constexpr auto kOrNone = pybind11::detail::const_name(" | None");
|
||||
|
||||
} // namespace scad::pybind
|
||||
|
||||
// Declares a tag: SCAD_SIGNATURE_NAME(PartName, type_name<sp::Part>());
|
||||
#define SCAD_SIGNATURE_NAME(Struct, ...) \
|
||||
struct Struct { \
|
||||
static constexpr auto name = (__VA_ARGS__); \
|
||||
}
|
||||
|
||||
namespace pybind11::detail {
|
||||
|
||||
// Loads and casts exactly as Scalar does; only the name in the signature differs.
|
||||
template <class Tag>
|
||||
struct type_caster<scad::pybind::Quantity<Tag>> {
|
||||
PYBIND11_TYPE_CASTER(scad::pybind::Quantity<Tag>, Tag::name);
|
||||
template <class T, class Tag>
|
||||
struct type_caster<scad::pybind::Renamed<T, Tag>> {
|
||||
using Type = scad::pybind::Renamed<T, Tag>; // the macro takes no comma
|
||||
PYBIND11_TYPE_CASTER(Type, Tag::name);
|
||||
|
||||
bool load(handle src, bool convert) {
|
||||
make_caster<scad::Scalar> inner;
|
||||
make_caster<T> inner;
|
||||
if (!inner.load(src, convert))
|
||||
return false;
|
||||
value.value = cast_op<scad::Scalar&&>(std::move(inner));
|
||||
value.value = cast_op<T&&>(std::move(inner));
|
||||
return true;
|
||||
}
|
||||
static handle cast(const scad::pybind::Quantity<Tag>& q, return_value_policy policy, handle parent) {
|
||||
return make_caster<scad::Scalar>::cast(q.value, policy, parent);
|
||||
static handle cast(const Type& renamed, return_value_policy policy, handle parent) {
|
||||
return make_caster<T>::cast(renamed.value, policy, parent);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tag>
|
||||
struct type_caster<scad::pybind::Quantity3<Tag>> {
|
||||
PYBIND11_TYPE_CASTER(scad::pybind::Quantity3<Tag>, Tag::name);
|
||||
struct type_caster<scad::pybind::AnyOf<Tag>> {
|
||||
PYBIND11_TYPE_CASTER(scad::pybind::AnyOf<Tag>, Tag::name);
|
||||
|
||||
bool load(handle src, bool convert) {
|
||||
make_caster<std::array<scad::Scalar, 3>> inner;
|
||||
if (!inner.load(src, convert))
|
||||
bool load(handle src, bool /*convert*/) {
|
||||
if (!src)
|
||||
return false;
|
||||
value.value = cast_op<std::array<scad::Scalar, 3>&&>(std::move(inner));
|
||||
value.value = reinterpret_borrow<object>(src);
|
||||
return true;
|
||||
}
|
||||
static handle cast(const scad::pybind::Quantity3<Tag>& q, return_value_policy policy, handle parent) {
|
||||
return make_caster<std::array<scad::Scalar, 3>>::cast(q.value, policy, parent);
|
||||
}
|
||||
static handle cast(const scad::pybind::AnyOf<Tag>& any, return_value_policy, handle) { return any.value.inc_ref(); }
|
||||
};
|
||||
|
||||
} // namespace pybind11::detail
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
// Signature types for bindings that convert their arguments themselves.
|
||||
//
|
||||
// Some operations take py::object and check the type inside the operation (the product operators, so a wrong type is
|
||||
// the operation's SimpleCADError, not a pybind overload error), or read a value the Python way (`str(value)`,
|
||||
// `int(value)`). Their signature would read `object`. `Typed<Name>` keeps the py::object (it accepts anything, as
|
||||
// before) and prints Name in the signature; `Shown<T, Name>` converts exactly as T does and prints Name. The body of
|
||||
// the binding does not change: both convert to what it took before.
|
||||
//
|
||||
// const Typed<PartName>& part part: simplecadapi._cpp._native.Part (any object reaches the body)
|
||||
// Shown<double, LengthTag> diameter diameter: simplecadapi.types.Length (loaded as a double)
|
||||
//
|
||||
// A name is a struct with `static constexpr auto name = <pybind descr>`; the class names come from the registered
|
||||
// types (`type_name<T>()`), so they print the way pybind prints the class itself.
|
||||
#pragma once
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "semantic_types.hpp"
|
||||
|
||||
namespace scad::pybind {
|
||||
|
||||
template <class Name>
|
||||
struct Typed {
|
||||
pybind11::object value;
|
||||
operator const pybind11::object&() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
bool is_none() const { return value.is_none(); }
|
||||
template <class T>
|
||||
T cast() const {
|
||||
return value.cast<T>();
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class Name>
|
||||
struct Shown {
|
||||
T value;
|
||||
operator const T&() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
};
|
||||
|
||||
// The descr pybind prints for a bound class.
|
||||
template <class T>
|
||||
constexpr auto type_name() {
|
||||
return pybind11::detail::make_caster<T>::name;
|
||||
}
|
||||
|
||||
// Words for the names.
|
||||
inline constexpr auto kOr = pybind11::detail::const_name(" | ");
|
||||
inline constexpr auto kOrNone = pybind11::detail::const_name(" | None");
|
||||
|
||||
} // namespace scad::pybind
|
||||
|
||||
// Declares a name struct: SCAD_SIGNATURE_NAME(PartName, type_name<sp::Part>());
|
||||
#define SCAD_SIGNATURE_NAME(Struct, ...) \
|
||||
struct Struct { \
|
||||
static constexpr auto name = (__VA_ARGS__); \
|
||||
}
|
||||
|
||||
namespace pybind11::detail {
|
||||
|
||||
template <class Name>
|
||||
struct type_caster<scad::pybind::Typed<Name>> {
|
||||
PYBIND11_TYPE_CASTER(scad::pybind::Typed<Name>, Name::name);
|
||||
|
||||
bool load(handle src, bool /*convert*/) {
|
||||
if (!src)
|
||||
return false;
|
||||
value.value = reinterpret_borrow<object>(src);
|
||||
return true;
|
||||
}
|
||||
static handle cast(const scad::pybind::Typed<Name>& v, return_value_policy, handle) { return v.value.inc_ref(); }
|
||||
};
|
||||
|
||||
template <class T, class Name>
|
||||
struct type_caster<scad::pybind::Shown<T, Name>> {
|
||||
using Self = scad::pybind::Shown<T, Name>; // the macro takes no comma
|
||||
PYBIND11_TYPE_CASTER(Self, Name::name);
|
||||
|
||||
bool load(handle src, bool convert) {
|
||||
make_caster<T> inner;
|
||||
if (!inner.load(src, convert))
|
||||
return false;
|
||||
value.value = cast_op<T&&>(std::move(inner));
|
||||
return true;
|
||||
}
|
||||
static handle cast(const scad::pybind::Shown<T, Name>& v, return_value_policy policy, handle parent) {
|
||||
return make_caster<T>::cast(v.value, policy, parent);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace pybind11::detail
|
||||
@@ -1,131 +0,0 @@
|
||||
// Parameter types that only change what the signature says, for the bound operations of ops_geometry/ops_features.
|
||||
//
|
||||
// TypedObject<Tag> any Python object, passed on as the py::object the binding read before; the signature prints
|
||||
// Tag::name (`Sequence[Edge] | ShapeSelector`, `simplecadapi.types.Point3`, ...). The binding
|
||||
// validates it itself, with the errors it raised before.
|
||||
// Choice<Tag> a str, loaded as std::string; the signature prints Tag::name (`Literal['Right', 'Left']`).
|
||||
// PlainQuantity<Tag> a float (no expression), loaded as double; prints a meaning of semantic_types.hpp.
|
||||
// DirectionVec a Vec3 (a 3-sequence or an object with x, y, z); prints simplecadapi.types.Direction3.
|
||||
// Count an int; prints simplecadapi.types.Count.
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "bindings.hpp"
|
||||
|
||||
namespace scad::pybind {
|
||||
|
||||
template <class Tag>
|
||||
struct TypedObject {
|
||||
pybind11::object value;
|
||||
operator const pybind11::object&() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
};
|
||||
|
||||
template <class Tag>
|
||||
struct Choice {
|
||||
std::string value;
|
||||
operator const std::string&() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
};
|
||||
|
||||
template <class Tag>
|
||||
struct PlainQuantity {
|
||||
double value;
|
||||
operator double() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
};
|
||||
|
||||
struct DirectionVec {
|
||||
Vec3 value;
|
||||
operator const Vec3&() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
};
|
||||
|
||||
struct Count {
|
||||
int value;
|
||||
operator int() const { return value; } // NOLINT(google-explicit-constructor)
|
||||
};
|
||||
|
||||
struct CountTag {
|
||||
static constexpr auto name = pybind11::detail::const_name("simplecadapi.types.Count");
|
||||
};
|
||||
|
||||
} // namespace scad::pybind
|
||||
|
||||
namespace pybind11::detail {
|
||||
|
||||
template <class Tag>
|
||||
struct type_caster<scad::pybind::TypedObject<Tag>> {
|
||||
PYBIND11_TYPE_CASTER(scad::pybind::TypedObject<Tag>, Tag::name);
|
||||
|
||||
bool load(handle src, bool) {
|
||||
if (!src)
|
||||
return false;
|
||||
value.value = reinterpret_borrow<object>(src);
|
||||
return true;
|
||||
}
|
||||
static handle cast(const scad::pybind::TypedObject<Tag>& o, return_value_policy, handle) { return o.value.inc_ref(); }
|
||||
};
|
||||
|
||||
template <class Tag>
|
||||
struct type_caster<scad::pybind::Choice<Tag>> {
|
||||
PYBIND11_TYPE_CASTER(scad::pybind::Choice<Tag>, Tag::name);
|
||||
|
||||
bool load(handle src, bool convert) {
|
||||
make_caster<std::string> inner;
|
||||
if (!inner.load(src, convert))
|
||||
return false;
|
||||
value.value = cast_op<std::string&&>(std::move(inner));
|
||||
return true;
|
||||
}
|
||||
static handle cast(const scad::pybind::Choice<Tag>& c, return_value_policy policy, handle parent) {
|
||||
return make_caster<std::string>::cast(c.value, policy, parent);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tag>
|
||||
struct type_caster<scad::pybind::PlainQuantity<Tag>> {
|
||||
PYBIND11_TYPE_CASTER(scad::pybind::PlainQuantity<Tag>, Tag::name);
|
||||
|
||||
bool load(handle src, bool convert) {
|
||||
make_caster<double> inner;
|
||||
if (!inner.load(src, convert))
|
||||
return false;
|
||||
value.value = cast_op<double>(inner);
|
||||
return true;
|
||||
}
|
||||
static handle cast(const scad::pybind::PlainQuantity<Tag>& q, return_value_policy policy, handle parent) {
|
||||
return make_caster<double>::cast(q.value, policy, parent);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct type_caster<scad::pybind::DirectionVec> {
|
||||
PYBIND11_TYPE_CASTER(scad::pybind::DirectionVec, scad::pybind::DirectionTag::name);
|
||||
|
||||
bool load(handle src, bool convert) {
|
||||
make_caster<scad::Vec3> inner;
|
||||
if (!inner.load(src, convert))
|
||||
return false;
|
||||
value.value = cast_op<scad::Vec3&&>(std::move(inner));
|
||||
return true;
|
||||
}
|
||||
static handle cast(const scad::pybind::DirectionVec& d, return_value_policy policy, handle parent) {
|
||||
return make_caster<scad::Vec3>::cast(d.value, policy, parent);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct type_caster<scad::pybind::Count> {
|
||||
PYBIND11_TYPE_CASTER(scad::pybind::Count, scad::pybind::CountTag::name);
|
||||
|
||||
bool load(handle src, bool convert) {
|
||||
make_caster<int> inner;
|
||||
if (!inner.load(src, convert))
|
||||
return false;
|
||||
value.value = cast_op<int>(inner);
|
||||
return true;
|
||||
}
|
||||
static handle cast(const scad::pybind::Count& c, return_value_policy policy, handle parent) {
|
||||
return make_caster<int>::cast(c.value, policy, parent);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace pybind11::detail
|
||||
@@ -717,7 +717,7 @@ class _TrackingPolicyScope:
|
||||
...
|
||||
def __exit__(self, *args) -> None:
|
||||
...
|
||||
def _brep_region_path(path: typing.Any, *, for_graph: bool) -> str:
|
||||
def _brep_region_path(path: str | os.PathLike[str], *, for_graph: bool) -> str:
|
||||
"""
|
||||
The checks on a .scadbrep locator (graph replay: relative, no drive, no '..', '/' separators).
|
||||
"""
|
||||
@@ -893,7 +893,7 @@ def tessellate_solid(shape: AnyShape, *, linear_deflection: typing.SupportsFloat
|
||||
"""
|
||||
(vertices Nx3 float64, triangles Mx3 int32): the shape's surface tessellated, vertices welded.
|
||||
"""
|
||||
def tracking_policy_scope(policy: typing.Any) -> _TrackingPolicyScope:
|
||||
def tracking_policy_scope(policy: typing.Literal['full', 'graph'] | simplecadapi._cpp.TrackingPolicy) -> _TrackingPolicyScope:
|
||||
"""
|
||||
Run a block with graph-only or full topology tracking.
|
||||
"""
|
||||
|
||||
+4
-69
@@ -7,71 +7,6 @@ import json
|
||||
import simplecadapi as scad
|
||||
from simplecadapi import catalog
|
||||
|
||||
# Operations whose signature still says ``object`` for some parameter: give them real types (simplecadapi.types, typed
|
||||
# sequences, Literal choices) and remove them here. The list only shrinks.
|
||||
PENDING_UNTYPED = {
|
||||
"add_belt_constraint_rassembly",
|
||||
"add_component_rassembly",
|
||||
"add_connector_rpart",
|
||||
"add_fixed_constraint_rassembly",
|
||||
"add_gear_constraint_rassembly",
|
||||
"add_prismatic_constraint_rassembly",
|
||||
"add_rack_pinion_constraint_rassembly",
|
||||
"add_revolute_constraint_rassembly",
|
||||
"apply_tag_rselection",
|
||||
"assign_material_rpart",
|
||||
"boolean_rsolidlist",
|
||||
"chamfer_rsolid",
|
||||
"cut_rsolid",
|
||||
"draft_rsolid",
|
||||
"explode_rassembly",
|
||||
"extrude_taper_rsolid",
|
||||
"extrude_until_rsolid",
|
||||
"fill_holes_rshell",
|
||||
"fillet_rsolid",
|
||||
"ground_component_rassembly",
|
||||
"inspect_assembly_constraints_rconstraintreport",
|
||||
"load_brep_region_rshell",
|
||||
"load_brep_region_rsolid",
|
||||
"loft_rshell",
|
||||
"loft_rsolid",
|
||||
"make_2d_cut_rface",
|
||||
"make_2d_intersect_rface",
|
||||
"make_2d_union_rface",
|
||||
"make_assembly_rassembly",
|
||||
"make_ball_bearing_rassembly",
|
||||
"make_bolt_rsolid",
|
||||
"make_compound_from_assembly_rcompound",
|
||||
"make_connector_ref_rconnectorref",
|
||||
"make_edge_connector_rconnector",
|
||||
"make_face_connector_rconnector",
|
||||
"make_face_from_sketch_rface",
|
||||
"make_material_rmaterial",
|
||||
"make_nut_rsolid",
|
||||
"make_part_rpart",
|
||||
"make_placement_connector_rconnector",
|
||||
"make_placement_rplacement",
|
||||
"make_roller_chain_sprocket_rsolid",
|
||||
"make_scalar_limit_rscalarlimit",
|
||||
"make_sketch_rsketch",
|
||||
"make_spline_redge",
|
||||
"make_spline_rwire",
|
||||
"make_surface_patch_rface",
|
||||
"make_vertex_connector_rconnector",
|
||||
"make_wire_from_sketch_rwire",
|
||||
"measure_constraint_residual_rconstraintresidual",
|
||||
"offset_rsolid",
|
||||
"place_component_rassembly",
|
||||
"project_rsketch",
|
||||
"render_screenshot_rpath",
|
||||
"scale_rsolid",
|
||||
"set_public_connector_rassembly",
|
||||
"shell_rsolid",
|
||||
"solve_assembly_constraints_rassembly",
|
||||
"sweep_multisection_rsolid",
|
||||
"unground_component_rassembly",
|
||||
"union_rsolid",
|
||||
}
|
||||
|
||||
|
||||
def test_every_public_operation_is_in_the_catalog_with_its_parameters():
|
||||
@@ -91,10 +26,10 @@ def test_the_meaning_comes_from_the_binding_types():
|
||||
assert next(p for p in cylinder.params if p.name == "start_face_tag").keyword_only
|
||||
|
||||
|
||||
def test_no_operation_beyond_the_pending_list_takes_an_untyped_parameter():
|
||||
untyped = {op.name for op in catalog.operations() for p in op.params if p.kind == "unknown"}
|
||||
assert untyped <= PENDING_UNTYPED, sorted(untyped - PENDING_UNTYPED)
|
||||
assert not (PENDING_UNTYPED - untyped), f"typed now, drop from PENDING_UNTYPED: {sorted(PENDING_UNTYPED - untyped)}"
|
||||
def test_every_parameter_of_every_operation_says_what_it_is():
|
||||
"""No signature reads ``object``: a new operation that does not type its parameters fails here, not in a GUI form."""
|
||||
untyped = sorted(f"{op.name}({p.name}: {p.type})" for op in catalog.operations() for p in op.params if p.kind == "unknown")
|
||||
assert not untyped, untyped
|
||||
|
||||
|
||||
def test_types_classify():
|
||||
|
||||
Reference in New Issue
Block a user