CAD_Sketcher icon indicating copy to clipboard operation
CAD_Sketcher copied to clipboard

Use official solvespace python package

Open hlorus opened this issue 9 months ago • 7 comments

This switches the solver from the inofficial binding to the official python binding of solvespace which has the benefit of being more uptodate as well as being stateful. There are currently some remaining issues:

  • The SolveResult's bad field is just a number, what does this represent? Is it the handle of the failed constraint? If so, can't there be more than one failed constraints?
  • What is the SolveResult's 'rank' field for?
  • SlvsArc and SlvsCircle take a 3d normal as input, shouldn't that be a 2d normal?
  • How is the 'distance_proj' ment to be used? Shouldn't it have an input to defone the direction of the projection?
  • The tangent constraint fails in some cases:
    • between a curve and a line if they are not connected
    • between two curves

hlorus avatar Mar 06 '25 17:03 hlorus

@vespakoen congrats on the progress on the python binding, this is a great improvement!

hlorus avatar Mar 06 '25 17:03 hlorus

This switches the solver from the inofficial binding to the official python binding of solvespace [...]

Note that you also need to update the following definition, as the errors that the solver returns have changed (in this PR you're using dev24, which just removed values 4 and 5, but dev28 added back REDUNDANT_OKAY, although with a value of 4 instead of 5):

https://github.com/hlorus/CAD_Sketcher/blob/3fb273c1d346450f7f6e458840ab3e3a6a1cefff/global_data.py#L39-L95

  • The SolveResult's bad field is just a number, what does this represent? Is it the handle of the failed constraint? If so, can't there be more than one failed constraints?

It represents the number of bad constraints. To get the list of bad constraint you'll need to use the system solve function rather than the sketch solve one, but this one unfortunately isn't exposed in the Python bindings (and for good reason, as for now building the system involves much more manual work compared to adding entities to the sketch which has a proper API).

  • What is the SolveResult's 'rank' field for?

I suppose it was originally meant for exposing the rank of the Jacobian matrix, so that it could be used to calulate DoF, but all of this is now internal to the solver, and the rank member is never actually set anyway, so it probably should be removed now.

iscgar avatar Mar 07 '25 12:03 iscgar

@iscgar Thanks alot for your help and the work on the bindings!

It represents the number of bad constraints. To get the list of bad constraint you'll need to use the system solve function rather than the sketch solve one, but this one unfortunately isn't exposed in the Python bindings (and for good reason, as for now building the system involves much more manual work compared to adding entities to the sketch which has a proper API).

That's indeed really unfortunate! Is it planned to be added to a later version of the python bindings? I'm afraid this is a showstopper since it's quite a big regression.

On a similar note: People often ask for DOF per entity, is this something that migth be added to the bindings as well?

hlorus avatar Mar 08 '25 16:03 hlorus

It represents the number of bad constraints. To get the list of bad constraint you'll need to use the system solve function rather than the sketch solve one, but this one unfortunately isn't exposed in the Python bindings (and for good reason, as for now building the system involves much more manual work compared to adding entities to the sketch which has a proper API).

That's indeed really unfortunate! Is it planned to be added to a later version of the python bindings? I'm afraid this is a showstopper since it's quite a big regression.

I've only recently started working on SolveSpace because I was interested in CAD Sketcher and started looking into the underlying solver, so @vespakoen is likely much more qualified than me to answer that, though I can think of a few ways this can be done, with minimal changes to the library (the easier way would probably be to add an optional out parameter to the sketch solve function that points to a list that could be populated with the bad constraints, if there are any).

On a similar note: People often ask for DOF per entity, is this something that migth be added to the bindings as well?

SolveSpace itself doesn't do DoF calculation per entity, only per group, so this requires some work on the solver to allow it to calculate DoF per entity (although that would likely slow things down).

iscgar avatar Mar 08 '25 17:03 iscgar

Related: https://github.com/solvespace/solvespace/issues/1546

hlorus avatar Mar 17 '25 07:03 hlorus

Any updates on this?

rcarmo avatar May 03 '25 20:05 rcarmo

Yes, there is an open PR waiting for review. It is linked in the issue https://github.com/solvespace/solvespace/issues/1546

hlorus avatar May 04 '25 15:05 hlorus

The PR is merged. The issue is closed.

ruevs avatar Jun 20 '25 17:06 ruevs

The PR is merged. The issue is closed.

Hey thanks a lot for your efforts, i've updated the PR. It currently uses 3.2.dev66 since that's the only version which i've found that has the new changes applied.

hlorus avatar Jul 01 '25 13:07 hlorus