/* OCP.STEPControl — STEP read and write. The reader inherits its transfer surface from XSControl_Reader; what is added here is the unit handling the app needs (FileUnits reports what the file declares, SetSystemLengthUnit rescales the transfer) and ReadStream, which takes a Python file-like. ReadStream reuses the slurp bridge from occt_stream.h rather than wrapping a streambuf that calls back into Python — same reasoning as BinTools, and the same one extra copy. The GIL stays held throughout, per the note in mod_XSControl.cpp: XSTEP is built on process-global state and the app serialises imports anyway. The wheel ships none of OCCT's share/ resources; STEP still resolves units in a container with no CSF_* environment, which tests/test_inc3_io.py pins. */ #include "../common/occt_module.h" #include "../common/occt_policies.h" #include "../common/occt_stream.h" #include #include #include #include #include #include #include #include void register_STEPControl(nb::module_ &root) { nb::module_ m = ocp_submodule(root, "STEPControl"); nb::enum_(m, "STEPControl_StepModelType", nb::is_arithmetic()) .value("STEPControl_AsIs", STEPControl_AsIs) .value("STEPControl_ManifoldSolidBrep", STEPControl_ManifoldSolidBrep) .value("STEPControl_BrepWithVoids", STEPControl_BrepWithVoids) .value("STEPControl_FacetedBrep", STEPControl_FacetedBrep) .value("STEPControl_FacetedBrepAndBrepWithVoids", STEPControl_FacetedBrepAndBrepWithVoids) .value("STEPControl_ShellBasedSurfaceModel", STEPControl_ShellBasedSurfaceModel) .value("STEPControl_GeometricCurveSet", STEPControl_GeometricCurveSet) .value("STEPControl_Hybrid", STEPControl_Hybrid) .export_values(); nb::class_ controller(m, "STEPControl_Controller"); OCP_DEF_S( controller, "Init", []() { return STEPControl_Controller::Init(); }); nb::class_(m, "STEPControl_Reader") .def(nb::init<>()) .def( "ReadStream", [](STEPControl_Reader &self, const char *name, nb::handle stream) { std::istringstream buffer(ocp_slurp(stream)); return self.ReadStream(name, buffer); }, "theName"_a, "theIStream"_a) .def("FileUnits", &STEPControl_Reader::FileUnits, "theLengthUnits"_a, "theAngleUnits"_a, "theSolidAngleUnits"_a) .def("SetSystemLengthUnit", &STEPControl_Reader::SetSystemLengthUnit, "theLengthUnit"_a) .def("SystemLengthUnit", &STEPControl_Reader::SystemLengthUnit); nb::class_(m, "STEPControl_Writer") .def(nb::init<>()) .def( "Transfer", [](STEPControl_Writer &self, const TopoDS_Shape &sh, const STEPControl_StepModelType mode, const Standard_Boolean compgraph) { return self.Transfer(sh, mode, compgraph); }, "sh"_a, "mode"_a, "compgraph"_a = Standard_True) .def( "Write", [](STEPControl_Writer &self, const Standard_CString filename) { return self.Write(filename); }, "filename"_a); }