Planning to do some work on Sketch solver

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Planning to do some work on Sketch solver

Post by ulrich1a »

Something missing in the Sketcher is the support for ellipses. ;)

With the recent work from abdullah at the sketcher (thanks for this!), I was thinking expessions for solver constraints should now working with the help of the spreadsheet module.
I tried it, and it looked, as everything was ready. The property controller of the spreadsheet allowed to select constraints as controlled property. But it did not work. :(
I could change the properties of a cube but not the properties of the sketch with the spreadsheet.
At pressing the "compute-button" in the spreadsheet-window, the cube get updated but not the sketch.
Did I do something wrong, or is it just not working?
Here is my test.

Ulrich

OS: Debian GNU/Linux testing (jessie)
Word size: 64-bit
Version: 0.15.3915 (Git)
Branch: master
Hash: 539e2d2f3326dc0f9532f05eca8fb7015a6d2987
Python version: 2.7.8
Qt version: 4.8.6
Coin version: 4.0.0a
SoQt version: 1.6.0a
OCC version: 6.7.1
Attachments
Sketch_spreadsheet.fcstd
Test of changing Sketcher properties with a spreadsheet
(4.7 KiB) Downloaded 55 times
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: Planning to do some work on Sketch solver

Post by ian.rees »

DevJohan wrote: Ian: I don't believe in the idea of linking the sketcher variables to some python variables. However, I do think they should be exposed through a python interface to allow python code to change the variables.
No worries. I've got a couple other things going at the moment anyway, so wasn't going to start on that idea for some time. -Ian-
User avatar
saso
Veteran
Posts: 1924
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Planning to do some work on Sketch solver

Post by saso »

I am sorry, maybe I even don't understand how it would all work together in the end, but just from what I can see and understand now I don't think this should be solved with spreadsheets. It is good that spreadsheet (or python) can tap in, to read and even edit the values, but it should not be the central "on-compute" driver behind all of it. IMO the formula functionality has to be in the core of sketcher (and other modules that can make use of it) so the user has to be able to set such formulas directly there and it has to stay synchronized between the different inputs (task, properties, spreadsheet, python,...).

With this spreadsheet approach, what happens if the spreadsheet is deleted (the formula based relations are lost)? And what happens if the user changes the value directly in the sketch / property (the relation with spreadsheet is unsynchronized)? IMO this just calls for problems. I don't believe one would want that the value that we have now in the property would stay unchanged if the value is changed directly inside the sketch and for the same reason I don't think this should be the case with spreadsheets.

Using the spreadsheets like suggested, makes them in a way similar to a macro, where something is done to the model when executing \ running it. I cannot agree that this is how they should be used. Spreadsheets should IMO represent the state of the model and always be in sync with it, same as properties :roll:
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Planning to do some work on Sketch solver

Post by abdullah »

I am sorry, maybe I even don't understand how it would all work together in the end, but just from what I can see and understand now I don't think this should be solved with spreadsheets. It is good that spreadsheet (or python) can tap in, to read and even edit the values, but it should not be the central "on-compute" driver behind all of it. IMO the formula functionality has to be in the core of sketcher (and other modules that can make use of it) so the user has to be able to set such formulas directly there and it has to stay synchronized between the different inputs (task, properties, spreadsheet, python,...).
Ok, so you kindda agree with the direction of my second thought.

All the values we set are properties (or stored within properties). I think that the task is not doable, or at least not in an elegant way, by directly limiting it to the sketcher. IMHO, the change should be made in the properties. So that a Quantity, for example does not embed just a double, but a double and an expression (new type). Quantity is used overall, including the PropertyUnitItem, that is also overall. This PropertyUnitItem then should be upgraded to handle this new type (to allow the edition of the expression), while representing the double.

A word on expressions: I was thinking that solving changes like this can become a nightmare. For example, updating an expression can mean subsequently changing a plurality of values of other depending expressions. This shall be done in order (and optimized when possible) to avoid breaking not-that-simple designs. A solution I have been thinking of is that this new type, adds itself to a "newtype managing system" (another class, like a container of this new type). This "managing system" could have a tree structure, the nodes set into different levels depending on their dependence on the values of other types, something like:

Variable, Function of, expression/value
L, , 32 mm
...K, L, L/2
....N, K, K^2
......Z, M L, M/L
M, , 20 mm
....Z, M L, M/L

note that Z is in both branches. This should allow to see how the sketch are to be applied.

I would set initial limitations to the system: expressions can not be recursive, depend on themselves (not even circularly).

I would really like to use an existing proven engine for symbolic math (like GAP), both none seems to be under LGPL (GAP is GPL), and I think we can not afford another licensing nightmare.

Ok, those are my 2 cents. No intention to insert more noise, as I have not read yet the other tasks tanderson provided, and probably I am either presenting similar problems or similar non-working solutions... ;)
mrlukeparry
Posts: 655
Joined: Fri Jul 22, 2011 8:37 pm
Contact:

Re: Planning to do some work on Sketch solver

Post by mrlukeparry »

One approach could be using a symbolic library like http://viennamath.sourceforge.net/viennamath-about.html or parser (muParser) to build up the equations - so it's just a string that is stored. References to spreadsheet or other could inspected prior to parsing the expression using a symbol e.g. $# etc/an re-evaluated using the values in the spreadsheet.

One of the challenges when I looked is that the equations whether it be 'distance to point' or arc have to be derived in terms of simpler parameters so an error function can be created. I struggled to get my head around it.

In general there is alot of scope of improvement as the original dev is busy. We also have the benefit that sketchsolve is now opensource to give some ideas.
User avatar
saso
Veteran
Posts: 1924
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Planning to do some work on Sketch solver

Post by saso »

abdullah wrote:Ok, so you kindda agree with the direction of my second thought.
Yes, I agree and support this idea. However, while I am able to sort of follow your thinking on how to implement it in the code I am unfortunately not able to help you on that level.

But I would like to link here my post in another topic that links to my post above viewtopic.php?f=10&t=7299&p=60471#p60471
Post Reply