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.
User avatar
DevJohan
Posts: 41
Joined: Sun Jul 13, 2014 2:36 pm
Location: Stockholm, Sweden

Planning to do some work on Sketch solver

Postby DevJohan » Thu Aug 21, 2014 2:36 pm

Hi everyone.

I've been playing around a bit with the sketch solver lately and I'm planning to make some improvements. One of the things I want to do is implement variables and expression (http://www.freecadweb.org/tracker/view.php?id=800). Just want to know if someone else is working on the same thing or if there are some inputs from the rest of you.

Cheers,
Johan
wmayer
Site Admin
Posts: 14992
Joined: Thu Feb 19, 2009 10:32 am

Re: Planning to do some work on Sketch solver

Postby wmayer » Thu Aug 21, 2014 3:16 pm

Just want to know if someone else is working on the same thing or if there are some inputs from the rest of you
It doesn't seem so. Good luck!
User avatar
tanderson69
Posts: 1500
Joined: Thu Feb 18, 2010 1:07 am

Re: Planning to do some work on Sketch solver

Postby tanderson69 » Thu Aug 21, 2014 3:57 pm

Some relevant forum threads:
viewtopic.php?f=9&t=4359
viewtopic.php?f=10&t=6354

Some relevant mantis tickets:
http://www.freecadweb.org/tracker/view.php?id=1098
http://www.freecadweb.org/tracker/view.php?id=1437

Some relevant branches, with origin being sourceforge:

Code: Select all

origin/master-spreadsheet

Code: Select all

origin/tanderson-dev-expressions1
The sticking point on these ideas is how the expressions are stored in the document and related to features. Specific links to discussion beginnings:
viewtopic.php?f=9&t=4359&start=80#p50832
viewtopic.php?f=10&t=6354&start=30#p54546
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: Planning to do some work on Sketch solver

Postby ian.rees » Fri Aug 22, 2014 3:51 am

Hi Johan,

I've thought about doing some work that might work nicely with what you're proposing. Maybe we could sync up sometime, but I'm a bit busy with real (well, at least paying) work for at least the next few days.

Basically, what I was considering is allowing python variables to be used in many of the places where numbers are currently used. For instance, a person could use the GUI to set the rotation angle of a part to some python variable, say hourAngle, rather than a number, then if that number were changed in the python interpreter, the drawing would be updated appropriately. The hourAngle variable would be attached to the document object as an attribute, saved and loaded as appropriate, etc.

I've not done much more than think about how this would work from the user's perspective, but I assume that a first step would be to facilitate adding python attributes to Document objects. It's also entirely possible that the feature I'm imagining exists already and I just haven't looked hard enough for it. -Ian-
jmaustpc
Posts: 9566
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Planning to do some work on Sketch solver

Postby jmaustpc » Fri Aug 22, 2014 4:17 am

Hi all

Ian a couple of points that immediately spring to mind ...you have quite possibly already thought of these.

1) no Python code is saved into the fcstd file as deliberate design decision, as a security measure ....so no one can save the Python code for "please wipe my HDD" or some such thing, into the FreeCAD file where an expecting user could open the file and have the Python code automatically executed.

2) the input would have to not clash with the Units functionality.

Jim
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

Re: Planning to do some work on Sketch solver

Postby abdullah » Fri Aug 22, 2014 12:13 pm

Hi there!!

This is something that is also on my list. I share my thoughts with you.

Because of the way properties system works, my first thought was not try to embed the functionality into the existing Sketcher Module (Or any other module). I would do a separate module that sets the properties values based on formulas. This is the case of the Spreedsheet module, but you could use that or whatever else you might like, like an Octave module (similar to Matlab), or sage (NumPy, SciPy, matplotlib, Sympy, Maxima).

Problem with the first thought: The Sketchs, Pads, ... still show a numerical value, instead of a relationship (L/2).

My second thought is still in progress, and tackles the problem with the first thought. This implies making a new class (an new type) that has the interface of a double (internally I think all the units are doubles), but internally stores relationships (L,L/2,sqrt(L)). The object having an identity relationship has to define the value (L,32 mm). For that to happen, it is necessary to define new Property Editors, that can handle this kind of expressions. This Editors would only allow to edit the value of objects having an identity relationship (L, 32 mm). The editor would have to the right the option of calling an edit dialog (Like placement property has), This dialog would allow to edit either a identity relationship (L, 32 mm), or a relationship (L/2).

That solution should allow to work based only on magnitudes, with relationships, and should allow to load old files (backwards compatibility). A separate tool, integral part of FreeCAD, would allow to list all the objects of that class like a property view, and modify their values...

The inventor view will have two modes (value/relationship), and will show the actual value or the relationship depending on the mode selected.

Of course that is a though in progress...
User avatar
yorik
Site Admin
Posts: 11577
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Planning to do some work on Sketch solver

Postby yorik » Fri Aug 22, 2014 2:28 pm

Guys, since most of you "new coders" of FreeCAD are here, if any of you would like to be upgraded to developer on the bug tracker, so you can attribute bugs to yourself, or close bugs, or help with triaging, etc... just tell me, I'll gladly do it.
User avatar
DevJohan
Posts: 41
Joined: Sun Jul 13, 2014 2:36 pm
Location: Stockholm, Sweden

Re: Planning to do some work on Sketch solver

Postby DevJohan » Fri Aug 22, 2014 6:00 pm

Hi everyone.

There seems to be a fair amount of interest in working on this issue. I guess we should be able to collaborate at least to some extent. My main focus is to bring this functionality to the Sketcher and link it to the sketch solver. I guess extending the reach of the code may well be possible but I want to focus on a limited scope.

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.

Abdullah: Have you checked out what tanderson69 linked as related forum threads?

Tanderson69: Thanks for all the links and code references!

/Johan
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

Re: Planning to do some work on Sketch solver

Postby abdullah » Fri Aug 22, 2014 8:11 pm

 if any of you would like to be upgraded to developer on the bug tracker, so you can attribute bugs to yourself, or close bugs, or help with triaging, etc... just tell me, I'll gladly do it.
I am not that skillful, but I am looking in Mantis for jobs that seem doable by me, so why not... currently I am working in the utf support for the data properties and in bejant's bug/request to rotate symetric symbol to make it perpendicular to line of symmetry.
Abdullah: Have you checked out what tanderson69 linked as related forum threads? 
Not at all. I have just thrown what was in my mind.
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: Planning to do some work on Sketch solver

Postby ian.rees » Fri Aug 22, 2014 9:03 pm

Hi Jim,
jmaustpc wrote: 1) no Python code is saved into the fcstd file as deliberate design decision, as a security measure ....so no one can save the Python code for "please wipe my HDD" or some such thing, into the FreeCAD file where an expecting user could open the file and have the Python code automatically executed.
I do understand that's how things work at the moment, but haven't looked into the details. I'm mainly interested in adding the ability to access values that are already stored in the FreeCAD file, as Python variables, so on it's own this wouldn't really involve saving python code into the FreeCAD file.

Would be interested to know more about the "deliberate design decision", because it seems like a competing solution might have been to use a sandboxed Python interpreter in FreeCAD. As things stand now, the macro functionality in FreeCAD seems to allow the same sort of security hole you're describing.
jmaustpc wrote: 2) the input would have to not clash with the Units functionality.
Agreed, and I think this shouldn't be too much of a problem. -Ian-