Tag Archives: TODO

Logarithms: Better than bad, they’re good!

Yesterday’s work was focused on two different TO-DO items:

1) I did a little bit of work on the position dialog box, as requested on the forum a few days back. The position dialog has two modes, incremental and not-incremental (I’ve been calling that one absolute), where the position indicated to the dialog is either applied against an object’s current position (incremental), or against the origin of the coordinate space (absolute). That mode is selected by a checkbox, the requested feature was to make the state of that checkbox persist between uses.

Screen Shot 2015-04-24 at 2.13.25 pm

In addition to making the checkbox state persistent, I ended up also changing around the transitions between the two modes a little bit, so now that part works a little more intuitively. Now, when incremental mode is entered, the GUI widgets are initialised to reflect the equivalent incremental placement to the change in absolute position that had been in the GUI before.

I suppose a video clip would’ve been a clearer way to convey the original problem and my changes…

2) The auto-scale in Drawing had a few problems, so I’ve re-worked two areas to resolve those.

First, there’s a little function (Attributed to David Eppstein, whose blog led me off to reading about the Harriss spiral – neat stuff) that takes a scale value and computes a ratio of two integers that closely approximates that scale. The problem was that the function wasn’t really setup for handing big or small scales, so I wrapped it up with a little math to essentially deal with adding 0s onto either the numerator or denominator depending on the scale.

Second, the algorithm for calculating the initial scale to use didn’t handle small scales very well. The re-work there was a little more involved, but fortunately a lot of my earlier work on the placement of orthographic views was useful.

So, now it’s easy to use the drawing workbench for bigger or smaller things than it used to be, though there are still a couple issues. One of them is that there’s a hard-coded level of detail parameter somewhere, which I intend to do something about. So, right now if I try to draw a sphere the size of Earth, then it gets computed to some absurdly high resolution, 0.01mm or something along those lines. There’s a similar problem in the regular 3D view part of FreeCAD too, for instance at the default settings a circle drawn in Sketcher looks like a 30-something sided polygon, so maybe that issue requires a bit more thought.

Tax Day summary

Mainly this morning was devoted to things outside of FreeCAD, but I made a bit of progress on a couple bugs too.

It took a while to get started, as some other changes to FreeCAD broke the new Drawing module. I’ve been trying to keep the new Drawing module up-to-date with the rest of FreeCAD, to avoid a giant merge headache at the end, so this morning was one of the temporary smaller headaches that are a consequence of that decision.

Bug hunting/fixing involved implementing a small change I figured out yesterday (to fix the dragging bug), and re-working of some code for handling B-Splines (to prevent some exceptions that I think are related to problems in other areas). More to come, but not today!

little things, and The Process

While I was playing around with FreeCAD today, I felt a little twinge of frustration and decided to do something about it. Perhaps my loyal reader will find the process of identifying issues, fixing them, and publishing fixes interesting?property viewer

There’s a widget, the “Property Viewer”, which is one of a few key GUI components in FreeCAD. It contains two lists of properties (dimensions, positions, colour, etc.) for the thing you’re working on, and allows them to be changed. There are other ways to change most properties too, but the Property Viewer has everything in one place and is usually accessible.

The Property Viewer has two tabs; Data and View, so you can either work on Data properties or View properties at any particular time*. The issue is that I manipulate Data properties much more frequently than View properties, but FreeCAD always starts up with the View tab in front. So, I usually have an extra click to get Property Viewer in the right mode for changing the properties I’m interested in.

To fix this, I added ~20 lines of code to save the last tab that was selected, and to select that tab next time FreeCAD opens. Then, I “pushed” that modification to github, and made a brief post to the FreeCAD forum to ask people to try it out and comment. Assuming that my change doesn’t cause any problems and people like it, in a few days I’ll submit a “pull request” and one of the core developers will bring the code in to the main FreeCAD codebase (unless they notice a problem in the new code). Not all changes justify asking for popular opinion and testing, but that’s a judgement call. This particular change affects a core GUI component of FreeCAD so I felt like it was worth asking.

Every now-and-then, a “release” is made of FreeCAD (incidentally, we just made a release today!), next time that happens, any changes incorporated to that point will be included. Releases happen every few-to-several months, so in the meantime people can only get the new changes by building from the latest source code, which is what some of the early posts on here, for instance the one about building on OS X, are about.

All that said, the process for the Drawing module, which is where I’ve been doing most of my work lately, is a bit different. At this point there are only a couple people working on that module, and we’re working on a fairly significant re-write that involves breaking the existing Drawing module. So, rather than asking for comments and incorporating changes into the main FreeCAD, we [even more] informally push and pull our work to/from github to keep the latest and greatest moving forward. Eventually, when there’s some consensus that the module is ready to go, we’ll go through a testing phase with the wider FreeCAD community, and hopefully the whole thing will eventually be a part of the main codebase.

* Of course, as I type this, I realise that it might make sense to just get rid of the tabs altogether and just put all properties in one widget…

More about file opening

Today, I spent a couple hours trying to understand, and possibly re-work some of the FreeCAD bits involved in opening documents following yesterday’s diversion.

In the end, it looks like “fixing” this would take a bit more effort than I want to put into it, for a rather small gain compared to some other areas. So, if anyone else is interested in a project, there’s a branch here https://github.com/ianrrees/FreeCAD_tinkering/tree/read-unordered-zips that has some of the work done, but I think the proper solution will involve getting rid of the current istream-oriented approach in favour of something that’s file/database/XML-oriented. Basically, I’d start with removing the current Base::Reader’s inheritance from istream, then replace the getStream() with something more like getStream(specific_filename). Right now, Base::Reader has an awkward “is-a and has-a” relationship with istream, which in my opinion needs to go away. The combination of the XML parser, and only maintaining stream handles (versus handles to the original input file) is why we have the requirement for files to be stored in a specific order inside the FCStd file.

Have put also some time into updating the wiki, making some notes, doing some testing, and putting together a small patch that improves the error handling and reporting around improperly formatted input files.

Another TO-DO too: When a file fails to open properly, it should either not leave an open partially-loaded document in the GUI, or it should prompt before saving over the original document. As things are, it’s really easy to “shoot yourself in the foot” if FreeCAD fails to open a file, because hitting “save” will overwrite the entire original file with only the bits that FreeCAD managed to open successfully…

FCStd Format

I went on a bit of a tangent this afternoon – the plan was to continue with some work around projections in the Drawing module, but I got distracted by working with the text in the bottom-right corner of the page…

That led to me wanting to modify a Drawing’s SVG template inside an existing FreeCAD document, which I don’t believe the Drawing module can do yet. I knew that the FCStd file format that FreeCAD uses is just a Zip container, so unzipped the file, made some changes, zipped it back up, and watched FreeCAD crash on attempting to open the file…

I discovered an old post on the forum that points out FreeCAD’s expectation that the files in a FCStd container are stored in a particular order. FreeCAD also provides a “Project tool” to handle exactly this situation, but that tool doesn’t seem to work as I expect it to, and the wiki pages for FCStd don’t mention the file storage order requirement.

So, the TODO item here is to, at a minimum, update the wiki pages that relate to FCStd, figure out the “Project tool”, and maybe get rid of the file ordering requirement if it’s not too much work.

Slow startup fixed, more TODO items!

The slow startup of Drawing was being caused by a “broken” regular expression, which was causing the text search it was used in to try using up too much of one resource or another (eg: stack space) and throw an exception (after ~20 seconds on my machine). There was a try/catch around that particular chunk of code, which essentially just kept the program quietly running.

Anyways, to get it going again I changed:

"<text.*?font-size:(.*?)px.*?x=\"(.*?)\".*?y=\"(.*?)\".*?freecad:editable=\"(.*?)\".*?<tspan.*?>"

into:

// Regex e1 attempts to find:
// [0] - A text tag that contains "freecad:editable=", and it's matching tspan tag
// [1] - positive integer font size in px
// [2] - pos/neg float x coordinate
// [3] - pos/neg float y coordinate
// [4] - one or more character Perl "word" for freecad:editable value
...
"<text.*?font-size:([\\d]+)px.*?x=\"([\\d.-]+)\".*?y=\"([\\d.-]+)\".*?freecad:editable=\"(\\w+)\".*?>.*?<tspan.*?"

Now, we get a much faster load, and the beginnings of another working feature! Now, we’ve got editable text boxes for the title, author, scale, etc. as encoded in the drawing templates. Of course, all this will require a fair bit more work before it’s ready to go…

Screen Shot 2015-04-05 at 11.05.12 am

From http://doc.qt.io/qt-4.8/QGLWidget.html we can discover the root cause of the floating 3D view in Drawing from a couple posts ago:

On Mac OS X, when Qt is built with Cocoa support, a QGLWidget can’t have any sibling widgets placed ontop of itself. This is due to limitations in the Cocoa API and is not supported by Apple.

Cocoa support is essentially required on modern MacOS, so there will need to be some sort of workaround or FreeCAD will need to move to Qt5 to fix that issue…