|
1 | 1 | #cython: language_level=3 |
2 | 2 | from enum import IntEnum, auto |
| 3 | +from libc.stdint cimport uint32_t |
| 4 | +from libc.stdlib cimport free |
3 | 5 |
|
4 | 6 | cdef extern from "slvs.h" nogil: |
5 | | - ctypedef int Slvs_hEntity |
6 | | - ctypedef int Slvs_hGroup |
7 | | - ctypedef int Slvs_hConstraint |
8 | | - ctypedef int Slvs_hParam |
| 7 | + ctypedef uint32_t Slvs_hEntity |
| 8 | + ctypedef uint32_t Slvs_hGroup |
| 9 | + ctypedef uint32_t Slvs_hConstraint |
| 10 | + ctypedef uint32_t Slvs_hParam |
9 | 11 |
|
10 | 12 | ctypedef struct Slvs_Entity: |
11 | 13 | Slvs_hEntity h |
@@ -35,7 +37,7 @@ cdef extern from "slvs.h" nogil: |
35 | 37 | ctypedef struct Slvs_SolveResult: |
36 | 38 | int result |
37 | 39 | int dof |
38 | | - int bad |
| 40 | + int nbad |
39 | 41 |
|
40 | 42 | void Slvs_QuaternionU(double qw, double qx, double qy, double qz, |
41 | 43 | double *x, double *y, double *z) |
@@ -84,7 +86,7 @@ cdef extern from "slvs.h" nogil: |
84 | 86 | Slvs_Constraint Slvs_LengthDiff(Slvs_hGroup grouph, Slvs_Entity entityA, Slvs_Entity entityB, double value, Slvs_Entity workplane) |
85 | 87 | Slvs_Constraint Slvs_Dragged(Slvs_hGroup grouph, Slvs_Entity ptA, Slvs_Entity workplane) |
86 | 88 |
|
87 | | - Slvs_SolveResult Slvs_SolveSketch(Slvs_hGroup hg, int calculateFaileds) nogil |
| 89 | + Slvs_SolveResult Slvs_SolveSketch(Slvs_hGroup hg, Slvs_hConstraint **bad) nogil |
88 | 90 | double Slvs_GetParamValue(int ph) |
89 | 91 | double Slvs_SetParamValue(int ph, double value) |
90 | 92 | void Slvs_ClearSketch() |
@@ -363,7 +365,17 @@ class EntityType(IntEnum): |
363 | 365 | ARC_OF_CIRCLE = _SLVS_E_ARC_OF_CIRCLE |
364 | 366 |
|
365 | 367 | def solve_sketch(grouph: int, calculateFaileds: bool): |
366 | | - return Slvs_SolveSketch(grouph, calculateFaileds) |
| 368 | + cdef Slvs_hConstraint *badp = NULL |
| 369 | + if not calculateFaileds: |
| 370 | + return Slvs_SolveSketch(grouph, NULL) |
| 371 | + else: |
| 372 | + result = Slvs_SolveSketch(grouph, &badp) |
| 373 | + bad = [] |
| 374 | + if badp != NULL: |
| 375 | + for i in range(0, result.nbad): |
| 376 | + bad.append(badp[i]) |
| 377 | + free(badp) |
| 378 | + return result, bad |
367 | 379 |
|
368 | 380 | def get_param_value(ph: int): |
369 | 381 | return Slvs_GetParamValue(ph) |
|
0 commit comments