Skip to content

Commit 37e2c96

Browse files
committed
Naming parameters in the python wrapper
1 parent b98c810 commit 37e2c96

File tree

1 file changed

+124
-62
lines changed

1 file changed

+124
-62
lines changed

python/src/formo.cpp

Lines changed: 124 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ PYBIND11_MODULE(formo, m)
4848
// clang-format off
4949
py::class_<Color>(m, "Color")
5050
.def(py::init<>())
51-
.def(py::init<int, int, int>())
51+
.def(py::init<int, int, int>(),
52+
py::arg("red"), py::arg("green"), py::arg("blue"))
5253
.def("red", &Color::red)
5354
.def("redF", &Color::redF)
5455
.def("green", &Color::green)
@@ -147,26 +148,33 @@ PYBIND11_MODULE(formo, m)
147148
//
148149

149150
py::class_<Point>(m, "Point")
150-
.def(py::init<double, double, double>())
151+
.def(py::init<double, double, double>(),
152+
py::arg("x"), py::arg("y"), py::arg("z"))
151153
.def("x", &Point::x)
152154
.def("y", &Point::y)
153155
.def("z", &Point::z)
154-
.def("is_equal", &Point::is_equal)
155-
.def("distance", &Point::distance)
156+
.def("is_equal", &Point::is_equal,
157+
py::arg("other"), py::arg("tol"))
158+
.def("distance", &Point::distance,
159+
py::arg("pt"))
156160
;
157161

158162
py::class_<Direction>(m, "Direction")
159-
.def(py::init<double, double, double>())
163+
.def(py::init<double, double, double>(),
164+
py::arg("x"), py::arg("y"), py::arg("z"))
160165
.def(py::init<const Vector &>())
161166
.def("x", &Direction::x)
162167
.def("y", &Direction::y)
163168
.def("z", &Direction::z)
164169
;
165170

166171
py::class_<Vector>(m, "Vector")
167-
.def(py::init<double, double, double>())
168-
.def(py::init<const Direction &>())
169-
.def(py::init<const Point &, const Point &>())
172+
.def(py::init<double, double, double>(),
173+
py::arg("x"), py::arg("y"), py::arg("z"))
174+
.def(py::init<const Direction &>(),
175+
py::arg("direction"))
176+
.def(py::init<const Point &, const Point &>(),
177+
py::arg("pt1"), py::arg("pt2"))
170178
.def("x", &Vector::x)
171179
.def("y", &Vector::y)
172180
.def("z", &Vector::z)
@@ -183,18 +191,21 @@ PYBIND11_MODULE(formo, m)
183191
;
184192

185193
py::class_<Plane>(m, "Plane")
186-
.def(py::init<const Point &, const Direction &>())
194+
.def(py::init<const Point &, const Direction &>(),
195+
py::arg("point"), py::arg("normal"))
187196
.def("location", &Plane::location)
188197
;
189198

190199
py::class_<Axis1>(m, "Axis1")
191-
.def(py::init<const Point &, const Direction &>())
200+
.def(py::init<const Point &, const Direction &>(),
201+
py::arg("point"), py::arg("direction"))
192202
.def("location", &Axis1::location)
193203
.def("direction", &Axis1::direction)
194204
;
195205

196206
py::class_<Axis2>(m, "Axis2")
197-
.def(py::init<const Point &, const Direction &>())
207+
.def(py::init<const Point &, const Direction &>(),
208+
py::arg("point"), py::arg("direction"))
198209
.def("location", &Axis2::location)
199210
.def("direction", &Axis2::direction)
200211
;
@@ -203,147 +214,198 @@ PYBIND11_MODULE(formo, m)
203214

204215
py::class_<Shape>(m, "Shape")
205216
.def(py::init<>())
206-
.def(py::init<const TopoDS_Shape &>())
217+
.def(py::init<const TopoDS_Shape &>(),
218+
py::arg("shape"))
207219
.def("name", &Shape::name)
208-
.def("set_name", &Shape::set_name)
220+
.def("set_name", &Shape::set_name,
221+
py::arg("name"))
209222
.def("color", &Shape::color)
210-
.def("set_color", &Shape::set_color)
223+
.def("set_color", &Shape::set_color,
224+
py::arg("color"))
211225
;
212226

213227
py::class_<Edge, Shape>(m, "Edge")
214228
.def(py::init<>())
215-
.def(py::init<const TopoDS_Edge &>())
229+
.def(py::init<const TopoDS_Edge &>(),
230+
py::arg("edge"))
216231
.def("length", &Edge::length)
217232
;
218233

219234
py::class_<Face, Shape>(m, "Face")
220-
.def(py::init<const Wire &>())
235+
.def(py::init<const Wire &>(),
236+
py::arg("wire"))
221237
.def("is_plane", &Face::is_plane)
222238
.def("plane", &Face::plane)
223239
;
224240

225241
py::class_<Wire, Shape>(m, "Wire")
226-
.def(py::init<const TopoDS_Wire &>())
227-
.def(py::init<const std::vector<Edge> &>())
242+
.def(py::init<const TopoDS_Wire &>(),
243+
py::arg("wire"))
244+
.def(py::init<const std::vector<Edge> &>(),
245+
py::arg("edges"))
228246
;
229247

230248
py::class_<Shell, Shape>(m, "Shell")
231-
.def(py::init<const TopoDS_Shell &>())
249+
.def(py::init<const TopoDS_Shell &>(),
250+
py::arg("shell"))
232251
;
233252

234253
py::class_<Solid, Shape>(m, "Solid")
235254
.def(py::init<>())
236-
.def(py::init<const TopoDS_Solid &>())
255+
.def(py::init<const TopoDS_Solid &>(),
256+
py::arg("solid"))
237257
.def("volume", &Solid::volume)
238258
;
239259

240260
//
241261

242262
py::class_<ArcOfCircle, Edge>(m, "ArcOfCircle")
243-
.def(py::init<const Point &, const Point &, const Point &>())
244-
.def(py::init<const Circle &, const Point &, const Point &, bool>())
245-
.def(py::init<const Point &, const Vector &, const Point &>())
263+
.def(py::init<const Point &, const Point &, const Point &>(),
264+
py::arg("pt1"), py::arg("pt2"), py::arg("pt3"))
265+
.def(py::init<const Circle &, const Point &, const Point &, bool>(),
266+
py::arg("circ"), py::arg("pt1"), py::arg("pt2"), py::arg("sense") = true)
267+
.def(py::init<const Point &, const Vector &, const Point &>(),
268+
py::arg("pt1"), py::arg("tangent"), py::arg("pt2"))
246269
.def("start_point", &ArcOfCircle::start_point)
247270
.def("end_point", &ArcOfCircle::end_point)
248271
;
249272

250273
py::class_<Line, Edge>(m, "Line")
251-
.def(py::init<const Point &, const Point &>())
274+
.def(py::init<const Point &, const Point &>(),
275+
py::arg("pt1"), py::arg("pt2"))
252276
;
253277

254278
py::class_<Circle, Edge>(m, "Circle")
255-
.def(py::init<const Point &, double, const Direction &>())
256-
.def(py::init<const Point &, const Point &, const Direction &>())
257-
.def(py::init<const Point &, const Point &, const Point &>())
279+
.def(py::init<const Point &, double, const Direction &>(),
280+
py::arg("center"), py::arg("radius"), py::arg("normal") = Direction(0., 0., 1.))
281+
.def(py::init<const Point &, const Point &, const Direction &>(),
282+
py::arg("center"), py::arg("point"), py::arg("normal") = Direction(0., 0., 1.))
283+
.def(py::init<const Point &, const Point &, const Point &>(),
284+
py::arg("pt1"), py::arg("pt2"), py::arg("pt3"))
258285
.def("area", &Circle::area)
259286
.def("radius", &Circle::radius)
260287
.def("location", &Circle::location)
261288
;
262289

263290
py::class_<Spline, Edge>(m, "Spline")
264-
.def(py::init<const std::vector<Point> &>())
265-
.def(py::init<const std::vector<Point> &, const Vector &, const Vector &>())
291+
.def(py::init<const std::vector<Point> &>(),
292+
py::arg("points"))
293+
.def(py::init<const std::vector<Point> &, const Vector &, const Vector &>(),
294+
py::arg("points"), py::arg("initial_tangent"), py::arg("final_tangent"))
266295
;
267296

268297
py::class_<Polygon, Shape>(m, "Polygon")
269-
.def(py::init<const std::vector<Point> &, bool>())
298+
.def(py::init<const std::vector<Point> &, bool>(),
299+
py::arg("points"), py::arg("closed") = true)
270300
.def("as_edge", &Polygon::as_edge)
271301
.def("as_wire", &Polygon::as_wire)
272302
;
273303

274304
//
275305

276306
py::class_<Box, Solid>(m, "Box")
277-
.def(py::init<const Point &, const Point &>())
307+
.def(py::init<const Point &, const Point &>(),
308+
py::arg("pt1"), py::arg("pt2"))
278309
;
279310

280311
py::class_<Sphere, Solid>(m, "Sphere")
281-
.def(py::init<const Point &, double>())
312+
.def(py::init<const Point &, double>(),
313+
py::arg("center"), py::arg("radius"))
282314
;
283315

284316
py::class_<Cone, Solid>(m, "Cone")
285-
.def(py::init<const Axis2 &, double, double, double>())
317+
.def(py::init<const Axis2 &, double, double, double>(),
318+
py::arg("axis"), py::arg("radius1"), py::arg("radius2"), py::arg("height"))
286319
;
287320

288321
py::class_<Cylinder, Solid>(m, "Cylinder")
289-
.def(py::init<const Axis2 &, double, double>())
322+
.def(py::init<const Axis2 &, double, double>(),
323+
py::arg("axis"), py::arg("radius"), py::arg("height"))
290324
;
291325

292326
py::class_<Prism, Shape>(m, "Prism")
293-
.def(py::init<const Shape &, const Vector &>())
327+
.def(py::init<const Shape &, const Vector &>(),
328+
py::arg("shape"), py::arg("vector"))
294329
;
295330

296331
//
297332

298333
py::class_<IO>(m, "IO")
299-
.def_static("write", &IO::write)
300-
.def_static("read", &IO::read)
334+
.def_static("write", &IO::write,
335+
py::arg("file_name"), py::arg("shapes"), py::arg("file_format") = "step")
336+
.def_static("read", &IO::read,
337+
py::arg("file_name"))
301338
;
302339

303340
py::class_<IGESFile>(m, "IGESFile")
304-
.def(py::init<const std::string &>())
341+
.def(py::init<const std::string &>(),
342+
py::arg("file_name"))
305343
.def("read", &IGESFile::read)
306-
.def("write", &IGESFile::write)
344+
.def("write", &IGESFile::write,
345+
py::arg("shapes"))
307346
;
308347

309348
py::class_<STEPFile>(m, "STEPFile")
310-
.def(py::init<const std::string &>())
349+
.def(py::init<const std::string &>(),
350+
py::arg("file_name"))
311351
.def("read", &STEPFile::read)
312-
.def("write", &STEPFile::write)
352+
.def("write", &STEPFile::write,
353+
py::arg("shapes"))
313354
;
314355

315-
m.def("translate", py::overload_cast<const Shape &, const Vector &>(&translate));
316-
m.def("translate", py::overload_cast<const Shape &, const Point &, const Point &>(&translate));
356+
m.def("translate", py::overload_cast<const Shape &, const Vector &>(&translate),
357+
py::arg("shape"), py::arg("vector"));
358+
m.def("translate", py::overload_cast<const Shape &, const Point &, const Point &>(&translate),
359+
py::arg("shape"), py::arg("pt1"), py::arg("pt2"));
317360

318-
m.def("scale", py::overload_cast<const Shape &, double>(&scale));
319-
m.def("scale", py::overload_cast<const Vector &, double>(&scale));
361+
m.def("scale", py::overload_cast<const Shape &, double>(&scale),
362+
py::arg("shape"), py::arg("scale_factor"));
363+
m.def("scale", py::overload_cast<const Vector &, double>(&scale),
364+
py::arg("vector"), py::arg("scale_factor"));
320365

321-
m.def("mirror", py::overload_cast<const Shape &, const Axis1 &>(&mirror));
322-
m.def("mirror", py::overload_cast<const Vector &, const Axis1 &>(&mirror));
323-
m.def("mirror", py::overload_cast<const Vector &, const Axis2 &>(&mirror));
324-
m.def("mirror", py::overload_cast<const Point &, const Axis1 &>(&mirror));
325-
m.def("mirror", py::overload_cast<const Point &, const Axis2 &>(&mirror));
366+
m.def("mirror", py::overload_cast<const Shape &, const Axis1 &>(&mirror),
367+
py::arg("shape"), py::arg("axis1"));
368+
m.def("mirror", py::overload_cast<const Vector &, const Axis1 &>(&mirror),
369+
py::arg("vector"), py::arg("axis1"));
370+
m.def("mirror", py::overload_cast<const Vector &, const Axis2 &>(&mirror),
371+
py::arg("vector"), py::arg("axis2"));
372+
m.def("mirror", py::overload_cast<const Point &, const Axis1 &>(&mirror),
373+
py::arg("point"), py::arg("axis1"));
374+
m.def("mirror", py::overload_cast<const Point &, const Axis2 &>(&mirror),
375+
py::arg("point"), py::arg("axis2"));
326376

327-
m.def("fuse", py::overload_cast<const Shape &, const Shape &>(&fuse));
377+
m.def("fuse", py::overload_cast<const Shape &, const Shape &>(&fuse),
378+
py::arg("shape"), py::arg("tool"));
328379

329-
m.def("cut", py::overload_cast<const Shape &, const Shape &>(&cut));
380+
m.def("cut", py::overload_cast<const Shape &, const Shape &>(&cut),
381+
py::arg("shape"), py::arg("tool"));
330382

331-
m.def("intersect", py::overload_cast<const Shape &, const Shape &>(&intersect));
383+
m.def("intersect", py::overload_cast<const Shape &, const Shape &>(&intersect),
384+
py::arg("shape"), py::arg("tool"));
332385

333-
m.def("fillet", py::overload_cast<const Shape &, const std::vector<Edge> &, double>(&fillet));
386+
m.def("fillet", py::overload_cast<const Shape &, const std::vector<Edge> &, double>(&fillet),
387+
py::arg("shape"), py::arg("edges"), py::arg("radius"));
334388

335-
m.def("hollow", py::overload_cast<const Shape &, const std::vector<Face> &, double, double>(&hollow));
389+
m.def("hollow", py::overload_cast<const Shape &, const std::vector<Face> &, double, double>(&hollow),
390+
py::arg("shape"), py::arg("faces_to_remove"), py::arg("thickness"), py::arg("tolerance"));
336391

337-
m.def("extrude", py::overload_cast<const Shape &, const Vector &>(&extrude));
392+
m.def("extrude", py::overload_cast<const Shape &, const Vector &>(&extrude),
393+
py::arg("shape"), py::arg("vector"));
338394

339-
m.def("revolve", py::overload_cast<const Shape &, const Axis1 &, double>(&revolve));
395+
m.def("revolve", py::overload_cast<const Shape &, const Axis1 &, double>(&revolve),
396+
py::arg("shape"), py::arg("axis1"), py::arg("angle") = 2. * M_PI);
340397

341-
m.def("rotate", py::overload_cast<const Point &, const Axis1 &, double>(&rotate));
342-
m.def("rotate", py::overload_cast<const Vector &, const Axis1 &, double>(&rotate));
398+
m.def("rotate", py::overload_cast<const Point &, const Axis1 &, double>(&rotate),
399+
py::arg("point"), py::arg("axis"), py::arg("angle"));
400+
m.def("rotate", py::overload_cast<const Vector &, const Axis1 &, double>(&rotate),
401+
py::arg("point"), py::arg("axis1"), py::arg("angle"));
343402

344-
m.def("section", py::overload_cast<const Shape &, const Plane &>(&section));
403+
m.def("section", py::overload_cast<const Shape &, const Plane &>(&section),
404+
py::arg("shape"), py::arg("plane"));
345405

346-
m.def("write", &IO::write);
347-
m.def("read", &IO::read);
406+
m.def("write", &IO::write,
407+
py::arg("file_name"), py::arg("shapes"), py::arg("file_format") = "step");
408+
m.def("read", &IO::read,
409+
py::arg("file_name"));
348410
// clang-format on
349411
}

0 commit comments

Comments
 (0)