Skip to content

Commit 4c7ee76

Browse files
OCP 7.9 multiple fixes and QoL improvements (#194)
* OCP 7.9 multiple fixes and QoL improvements * Add cast_pyobject * Add overloads with explicit converters * Make strings implicitly convertible * TCollection conf fix Removed duplicate include_body_post and added new implicit conversions. * Add fmt to deps * Link against fmt * Switch to fmt * typo fix * Another typo * typo fix * Correct cast_pyobject return type * Simplify iostram casters * Add RWMesh * Extra include for RWMesh * Update version to 7.9.3.1
1 parent 5b151ff commit 4c7ee76

File tree

5 files changed

+86
-489
lines changed

5 files changed

+86
-489
lines changed

OCP_specific.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <Standard_Handle.hxx>
33
#include <type_traits>
44
#include <memory>
5+
#include <fmt/format.h>
56

67
namespace py = pybind11;
78

@@ -46,6 +47,13 @@ inline void copy_if_copy_constructible(T& t1, T& t2){
4647

4748
};
4849

50+
template <typename T> inline opencascade::handle<T> cast_pyobject(const py::object &arg){
51+
if(py::isinstance(arg, py::type::of<T>()))
52+
return opencascade::handle(py::cast<T*>(arg));
53+
else
54+
throw py::value_error(fmt::format("Cannot convert the argument to the required type {}", typeid(T).name()));
55+
};
56+
4957
template<typename T, template<typename> typename Deleter = std::default_delete>
5058
struct shared_ptr : public std::shared_ptr<T>{
5159
explicit shared_ptr(T* t = nullptr) : std::shared_ptr<T>(t, Deleter<T>()) {};

environment.devenv.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies:
2626
{% else %}
2727
- cxx-compiler
2828
- tbb-devel # [win]
29+
- fmt
2930
- pip:
3031
- git+https://github.com/CadQuery/pybind11-stubgen.git
3132
{% endif %}

ocp.toml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ modules = [
3030
"Quantity",
3131
"Storage",
3232
"FSD",
33-
"MMgt",
3433
"TCollection",
3534
"TColStd",
3635
"Message",
@@ -269,6 +268,7 @@ modules = [
269268
"RWStepGeom",
270269
"RWStepRepr",
271270
"RWStepShape",
271+
"RWMesh",
272272
"StepBasic",
273273
"StepGeom",
274274
"StepRepr",
@@ -424,7 +424,7 @@ class Adaptor3d_Surface;
424424

425425
[Attributes]
426426

427-
__version__ = "7.9.3.0"
427+
__version__ = "7.9.3.1"
428428

429429
[Modules]
430430

@@ -493,6 +493,20 @@ void register_template_NCollection_Vector(py::object &m, const char *name){
493493
[Modules.TCollection]
494494

495495
exclude_methods = ["TCollection_ExtendedString::ToUTF8CString"]
496+
include_body_post = """py::implicitly_convertible<std::string, TCollection_HAsciiString>();
497+
py::implicitly_convertible<std::string, TCollection_AsciiString>();"""
498+
499+
[[Modules.TCollection.Classes.TCollection_HAsciiString.additional_constructors]]
500+
501+
body = "[](const std::string &s){ return TCollection_HAsciiString(s.c_str()); }"
502+
help = "std::strings based constructor"
503+
arguments = ["aString"]
504+
505+
[[Modules.TCollection.Classes.TCollection_AsciiString.additional_constructors]]
506+
507+
body = "[](const std::string &s){ return TCollection_AsciiString(s.c_str()); }"
508+
help = "std::strings based constructor"
509+
arguments = ["aString"]
496510

497511
[Modules.TColStd]
498512

@@ -1090,6 +1104,12 @@ struct __GLXFBConfigRec {};"""
10901104

10911105
exclude_classes = ["StepData_EnumTool"]
10921106

1107+
[Modules.StepData.Classes.StepData_SelectType.additional_methods.SetValue]
1108+
1109+
body = "[](StepData_SelectType &self , py::object& ent){self.SetValue(cast_pyobject<Standard_Transient>(ent));}"
1110+
help = "SetValue supporting python objects"
1111+
arguments = ["ent"]
1112+
10931113
[Modules.LDOM]
10941114

10951115
exclude_classes = ["LDOMString","LDOM_MemManager","LDOM_BasicText"]
@@ -1279,6 +1299,18 @@ using rapidjson::BasicOStreamWrapper;"""
12791299

12801300
"Interface_ValueInterpret.hxx" = "#include <Interface_TypedValue.hxx>"
12811301

1302+
[Modules.Interface.Classes.Interface_InterfaceModel.additional_methods.AddEntity]
1303+
1304+
body = "[](Interface_InterfaceModel &self , py::object& ent){self.AddEntity(cast_pyobject<Standard_Transient>(ent));}"
1305+
help = "AddEntity supporting python objects"
1306+
arguments = ["anent"]
1307+
1308+
[Modules.Interface.Classes.Interface_InterfaceModel.additional_methods.AddWithRefs]
1309+
1310+
body = "[](Interface_InterfaceModel &self , py::object& ent){self.AddWithRefs(cast_pyobject<Standard_Transient>(ent));}"
1311+
help = "AddWithRefs supporting python objects"
1312+
arguments = ["anent"]
1313+
12821314
[Modules.IVtkVTK]
12831315

12841316
include_header_pre = """#include <vtkRenderer.h>
@@ -1495,3 +1527,7 @@ using rapidjson::BasicOStreamWrapper;"""
14951527
[Modules.StepAP214]
14961528

14971529
include_header_pre = "#include <Interface_InterfaceModel.hxx>"
1530+
1531+
[Modules.RWMesh]
1532+
1533+
include_header_pre = "#include <OSD_FileSystem.hxx>"

0 commit comments

Comments
 (0)