Commit Graph

730 Commits (d1a2eb6d187cd57ecb31f1c0f8ecb3428d116e41)

Author SHA1 Message Date
EvilSpirit e377eb8851 DXF: export color and line width. 2016-02-19 23:16:36 +00:00
EvilSpirit 3fdfca10f6 DXF: export non-rational beziers as splines instead of pwl. 2016-02-19 23:16:36 +00:00
EvilSpirit c469af6600 DXF: rewrite DxfFileWriter using libdxfrw. 2016-02-19 23:16:36 +00:00
whitequark 20a041e0ef DXF: initial libdxfrw import.
We had to fork libdxfrw since the upstream doesn't have a git
repository, a CMake buildsystem, and is quite buggy.

libdxfrw is also used in LibreCAD, but they just vendored
their version.
2016-02-19 23:16:36 +00:00
EvilSpirit a71d5894aa Draw extension lines from pt-line-distance to line ends.
Before this commit, if a pt-line-distance constraint is placed so
that the dimension line doesn't touch the line, no extension is
drawn. After this commit, an extension line will be drawn towards
the nearest end of the line.
2016-02-19 23:00:35 +00:00
whitequark b3fa8dca37 Allow removing active group.
This is an artificial restriction that serves no useful purpose.
Just switch to the previous group if asked to delete the current
one.

The ClearSuper() calls are reshuffled, since TW.ClearSuper() calls
TW.Show() and so has to be called while the sketch is still valid,
whereas GW.ClearSuper() also recreates the default group and thus
it should be called after the first RemoveById+GenerateAll pair,
or it'll recreate the default group before the entities on it have
a chance to be pruned.
2016-02-19 10:23:24 +00:00
whitequark 27d0dedbd1 Add new group after active group, not after all groups. 2016-02-19 10:23:24 +00:00
whitequark c9648805ea Allow generating groups in arbitrary order. 2016-02-19 10:23:24 +00:00
EvilSpirit df87ac6e6f Preserve entity visibility while switching active group.
Switching active group by itself is not an editing but a viewing
action; the active group is not recorded in the savefile. However,
the entity visibility status is, and this is annoying when source
control is used, because e.g. looking up dimensions in one of
the inner groups whose display was turned off ends up changing
the savefile.

When the display has to be turned on manually, this modification
of the file becomes explicit, so there's no longer any question
of what action modified the file.

This can also be convenient when inserting a group in the middle
of the stack, which will be implemented in the future.
2016-02-19 10:23:24 +00:00
whitequark d4ecf155f6 Include invisible entities when calculating BBox for chord tolerance.
Otherwise, loading a file with all entities invisible becomes
pathologically slow.
2016-02-19 10:23:24 +00:00
whitequark bdd02ac3a8 Fix usage of uninitialized BBox. 2016-02-19 10:23:24 +00:00
whitequark cd6d891100 Use U+FFFD instead of crashing when encountering unknown characters.
Also, use a nicer U+FFFD glyph in the builtin vector font.
2016-02-19 10:23:23 +00:00
whitequark 923374b305 Set the correct scale for vector font.
This was adjusted so that the height of "A" when exported to a vector
file would be 10mm in a style configured for 10mm font height.
2016-02-19 10:22:53 +00:00
whitequark 5c15cbf5f6 Remove extraneous instances of .c_str().
Most of these were just converting char* into std::string back and
forth; some more used ReadUTF8, which was converted to use nicer
STL-style iterators over UTF-8 text.

The remaining ones are:
  * arguments to Expr::From, which we'll change when refactoring
    the expression lexer;
  * arguments to varargs functions, which we'll change when adding
    localization (that requires custom printf-style functions to
    allow for changing argument order);
  * arguments where only string literals are ever passed, which
    are OK;
  * in platform-specific code, which is OK.
2016-02-19 10:22:53 +00:00
whitequark a1a624da12 Rigorously treat quoting in CMake.
CMake can properly quote inputs to custom commands itself; this is
governed by the VERBATIM flag. If we pass this flag, no quoting
needs to be done except for compiler/linker flags and diagnostic
messages, as CMake doesn't treat whitespace expanded from variables
the same way it treats whitespace that separates arguments.
2016-02-19 10:22:51 +00:00
whitequark 575146b975 Use GNUInstallDirs CMake module when installing files.
This should handle platform conventions more correctly, especially
on 64-bit or multiarch systems.
2016-02-17 06:23:01 +00:00
whitequark 7c2ec8f80e Always build in C++11 mode on GCC and Clang.
This will weed out compilers that are too old to build our code
(among others, recent gtkmm and glibmm have a hard dependency on
C++11, not even C++0x) and also properly communicate our wish to GCC
(Clang defaults to C++11 these days).
2016-02-15 20:08:46 +00:00
whitequark f20a044837 CI: Use Ubuntu Trusty for Travis builds.
Trusty has newer software and most importantly GCC with proper C++11
support, not just C++0x.
2016-02-15 19:58:14 +00:00
EvilSpirit cf38bdfebd Only consider selected entities, when any, when doing Zoom to Fit.
Scoped "Zoom to Fit" is convenient for working on large models.
I (whitequark) have considered a separate shortcut, but its
usefulness is unclear and in any case it can be easily added
if desired.
2016-02-14 14:29:47 +00:00
EvilSpirit dd5feb5724 Refactor Point2d to take advantage of const correctness. 2016-02-14 14:29:47 +00:00
whitequark 29ad1acdfe Enable and mollify -Wunused-variable.
In my (whitequark's) experience this warning tends to expose
copy-paste errors with a high SNR, so making a few fragments
slightly less symmetric is worth it.

Also mollify -Wlogical-op-parentheses while we're at it.
2016-02-14 14:29:47 +00:00
whitequark d43bd93060 Only consider groups until active when checking for solver failure.
After commit 2f734d9, inactive groups are no longer regenerated
for trivial changes, e.g. changing parameters, so it's possible to
switch to an earlier group and work on it without incurring
the computational (slowdown) and cognitive (annoyance by red
background) overhead of later groups failing to solve.

However, if a group--any group anywhere--was not solved OK,
the interface reacted accordingly, which diminished usefulness of
the change, especially given that, if we have groups A and B with
B depending on A, if B is broken by a change in A and we activate A
and fix it, B will not be regenerated.

After this commit, only active groups are considered when deciding
if generating the entire sketch would fail.
2016-02-14 14:09:36 +00:00
EvilSpirit 57fb3bf3dc Replace internal vector font with LibreCAD's GPLv2+ vector font.
This font is less complete than our bitmap font, Unifont: Unifont
has essentially complete Unicode coverage and LibreCAD's font only
has Latin, Cyrillic and Japanese, but it can be extended rather
easily, so this should be fine for now.

These embedded fonts fatten glhelper.o quite a bit:
bitmapfont.table.h is about 8M in gzip-compressed bitmaps and
vectorfont.table.h is about 2M in raw vector data.
In spite of that it takes just around five seconds to build
glhelper.c on my laptop, so it should be fine.

The final executable grows from about 2M to about 8M, but this
is a small price to pay for fairly extensive i18n support.

The new font has somewhat different metrics, so the rendering
code has been fudged to make it look good.
2016-02-14 14:09:36 +00:00
Peter Barfuss 784f3e5548 Rewrite TTF to Bezier conversion using Freetype.
Benefits:
  * Much simpler code.
  * Handles the entire TTF spec, not just a small subset that
    only really worked well on Windows fonts.
  * Handles all character sets as well as accented characters.
  * Much faster parsing, since Freetype lazily loads and
    caches glyphs.
  * Support for basically every kind of font that was invented,
    not just TTF.

Note that OpenType features, e.g. ligatures, are not yet supported.
This means that Arabic and Devanagari scripts, among others, will
not be rendered in their proper form.

RTL scripts are not supported either, neither in TTF nor in
the text window. Adding RTL support is comparatively easy, but
given that Arabic would not be legibly rendered anyway, this is not
done so far.
2016-02-13 21:08:18 +00:00
whitequark e5294eef9d Add freetype dependency.
We are going to use freetype instead of the old custom TTF parser,
since the old parser has many annoying bugs when handling non-Latin
fonts and fixing it is not really worth the time.

On Windows, Freetype is built from a submodule.
On Linux and OS X, Freetype is provided together with the desktop,
though development files have to be installed separately.
2016-02-13 21:08:18 +00:00
EvilSpirit f82767ae79 Break the dependency between an imported group and its parent.
Per correspondence with Jonathan the dependency serves no
useful purpose. It also prevents safely deleting groups preceding
imported groups.
2016-02-13 21:08:18 +00:00
EvilSpirit 34a5d87011 Use relative chord tolerance instead of absolute.
Commit 89eb208 has improved the overall situation with chord
tolerance, but it changed the display chord tolerance to use
an absolute value in millimeters as a stopgap measure.

This commit changes the display chord tolerance to be specified
in percents of entity bounding box instead of millimeters.
As a result, the linearized curves are both zoom level and sketch
scale independent.

In order to compute the bounding box, all entities are generated
twice. However, this shouldn't result in a noticeable slowdown,
since the bounding box calculation does not need the expensive
triangle mesh generation and the solver will converge immediately
on the second run.

Since the meaning of the preference has changed, a new name is
used (ChordTolerancePct instead of ChordTolerance), so that it
would be reset to the default value after updating SolveSpace.

The default value, 0.5%, was selected using trial and error by
judging whether cylinders of moderate dimensions were looking
aesthetically pleasing enough.

After this change, the only real function of the spacebar
shortcut is to reload imported groups, since manual regeneration
should not change anything anymore unless there is a bug.
2016-02-13 16:16:56 +00:00
EvilSpirit fc68804f65 Add BBox class for calculating entity bounding boxes. 2016-02-13 16:16:47 +00:00
EvilSpirit 89eb208660 Use a separate value of chord tolerance for exporting.
Before this commit, a single chord tolerance was used for both
displaying and exporting geometry. Moreover, this chord tolerance
was specified in screen pixels, and as such depended on zoom level.
This was inconvenient: exporting geometry with a required level of
precision required awkward manipulations of viewport. Moreover,
since some operations, e.g. mesh watertightness checking, were done
on triangle meshes which are generated differently depending on
the zoom level, these operations could report wildly different
and quite confusing results depending on zoom level.

The chord tolerance for display and export pursue completely distinct
goals: display chord tolerance should be set high enough to achieve
both fast regeneration and legible rendering, whereas export chord
tolerance should be set to match the dimension tolerance of
the fabrication process.

This commit introduces two distinct chord tolerances: a display
and an export one. Both chord tolerances are absolute and expressed
in millimeters; this is inappropriate for display purposes but
will be fixed in the next commits.

After exporting, the geometry is redrawn with the chord tolerance
configured for the export and an overlay message is displayed;
pressing Esc clears the message and returns the display back to
normal.
2016-02-13 16:16:47 +00:00
EvilSpirit 139dd80b48 Improve Bezier to piecewise linear conversion.
Instead of always using two points on every curve, with a hack for
some cubics edge case, use three points on the first iteration and
one point on every further iteration. This both faster and more
correct.
2016-02-13 16:16:47 +00:00
whitequark 1e2a899ba2 Avoid spurious double to float conversion.
MSVC (mostly rightly) complains about this, even if our particular
case is irrelevant.
2016-02-12 05:26:26 +00:00
whitequark 8c83a4a212 Use size_t for indexing where appropriate.
MSVC (rightly) complains about this.
2016-02-12 05:26:26 +00:00
whitequark 062344e40d Define _SCL_SECURE_NO_WARNINGS on Windows.
This is required to squash warnings about 'checked iterators'.
Regardless of their utility we can't use them on other platforms,
so we don't care.
2016-02-12 05:00:29 +00:00
whitequark f3b232238c Remove mention of Launchpad PPA from README.
I do not update it anymore and it's probably not the best solution
for distributing SolveSpace on Linux. In the meantime, the builds
from GitHub releases should be convenient enough.
2016-02-10 12:06:30 +00:00
whitequark 293eedc85e Add command-line Windows build instructions to README. 2016-02-10 10:48:42 +00:00
EvilSpirit b28fa34e4a Use an enum to select the mode of operation for GenerateAll. 2016-01-27 09:19:37 +00:00
EvilSpirit 2f734d9cfa When explicitly regenerating groups, only generate until active group.
Before this change, groups and their meshes were generated even past
the active group, which, in cause the mesh was broken, caused red
marks to appear for no apparent reason. Furthermore, it unnecessarily
slows down regeneration.
2016-01-27 09:14:00 +00:00
EvilSpirit 76d582720a Don't calculate halfRow for ShowEditControl manually.
Instead, grab it from hoveredRow, since almost always (with only one
exception) this is where the edit control has to be shown.

This makes it much easier to adjust views, e.g. add a new editable
field in the middle of configuration view, because it's not necessary
to manually change and test all the indexes below the row being
changed.

Additionally, it removes a lot of awkward and opaque row calculations.
2016-01-27 09:09:18 +00:00
EvilSpirit fd0b7fbc29 Update remaining sprintf calls with a stack buffer to use ssprintf.
The commit 11f29b123 has replaced most of the uses of sprintf,
but there were still many remaining in Screen* functions, and it
was annoyingly inconsistent. Moreover, while most usage of sprintf
there was fine, it is bad hygiene to leave stack overflow prone
code around.
2016-01-27 09:09:18 +00:00
EvilSpirit b7409b8ad6 Rework SAVEDptr to be a struct with accessors instead of an union.
It's not possible to put non-POD elements in a union, and a struct
with accessors is a more elegant solution than a union with POD
elements and explicit casts for the rest.
2016-01-27 09:09:18 +00:00
EvilSpirit 3af4e1c5b0 Define NOMINMAX for Windows builds.
Without #define NOMINMAX, <windows.h> defines min and max as macros,
which shadows the definitions from <algorithm> and makes them
unusable with multiple arguments.
2016-01-27 09:09:18 +00:00
whitequark 46ab541444 Add a setting that permits a group to include redundant constraints.
This setting is generally useful, but it especially shines when
assembling, since the "same orientation" and "parallel" constraints
remove three and two rotational degrees of freedom, which makes them
impossible to use with 3d "point on line" constraint that removes
two spatial and two rotational degrees of freedom.

The setting is not enabled for all imported groups by default
because it exhibits some edge case failures. For example:
  * draw two line segments sharing a point,
  * constrain lengths of line segments,
  * constrain line segments perpendicular,
  * constrain line segments to a 90° angle.

This is a truly degenerate case and so it is not considered very
important. However, we can fix this later by using Eigen::SparseQR.
2016-01-22 08:53:04 +00:00
EvilSpirit 2b388e7da4 Try to solve even very overconstrained systems.
Before this commit, overconstraining a system past a certain point
resulted in a wrong error message: instead of "redundant constraints",
"unsolvable constraints" was displayed.

To reproduce, place more six or more length constraints with the same
value onto the same line segment.
2016-01-22 07:41:30 +00:00
EvilSpirit 804761da88 Distinguish overconstrained and redundantly constrained sketches.
When a solver error arises after a change to the sketch, it should
be easy to understand exactly why it happened. Before this change,
two functionally distinct modes of failure were lumped into one:
the same "redundant constraints" message was displayed when all
degrees of freedom were exhausted and the had a solution, but also
when it had not.

To understand why this is problematic, let's examine several ways
in which we can end up with linearly dependent equations in our
system:
  0) create a triangle, then constrain two different pairs of edges
     to be perpendicular
  1) add two distinct distance constraints on the same segment
  2) add two identical distance constraints on the same segment
  3) create a triangle, then constrain edges to lengths a, b, and c
     so that a+b=c

The case (0) is our baseline case: the constraints in it make
the system unsolvable yet they do not remove more degrees of freedom
than the amount we started with. So the displayed error is
"unsolvable constraints".

The constraints in case (1) remove one too many degrees of freedom,
but otherwise are quite like the case (0): the cause of failure that
is useful to the user is that the constraints are mutually
incompatible.

The constraints in cases (2) and (3) however are not like the others:
there is a set of parameters that satisfies all of the constraints,
but the constraints still remove one degree of freedom too many.

It makes sense to display a different error message for cases (2)
and (3) because in practice, cases like this are likely to arise from
adjustment of constraint values on sketches corresponding to systems
that have a small amount of degenerate solutions, and this is very
different from systems arising in cases like (0) where no adjustment
of constraint values will ever result in a successful solution.
So the error message displayed is "redundant constraints".

At last, this commit makes cases (0) and (1) display a message
with only a minor difference in wording. This is deliberate.
The reason is that the facts "the system is unsolvable" and
"the system is unsolvable and also has linearly dependent equations"
present no meaningful, actionable difference to the user, and placing
emphasis on it would only cause confusion.

However, they are still distinguished, because in case (0) we
list all relevant constraints (and thus we say they are "mutually
incompatible") but in case (1) we only list the ones that constrain
the sketch further than some valid solution (and we say they are
"unsatisfied").
2016-01-21 14:15:05 +00:00
whitequark c011444045 Perform rank test after solving the system.
Before this change, it was possible to adjust constraints in a way
that removes a degree of freedom and makes the sketch unsolvable,
but rank test was performed before solving the system, and an error
was not displayed immediately. Instead, a solution would seemingly
be found, but it would be very unstable--unrelated changes to
the sketch would cause rank test to fail.

To reproduce the bug, do this:
  * Draw a triangle.
  * Create a length constraint for all sides.
  * Set side lengths to a, b, and c such that a + b = c.
  * Add a line segment.
2016-01-21 12:39:22 +00:00
whitequark 55cde18c5a Reword error messages that are displayed when a group fails to solve.
The current messages accurately reflect what happens to the system
of equations that represents the sketch, but can be quite confusing
to users that only think in terms of the constraints.

We use "unsolvable" and not "impossible" because while most of
the cases that result in this error message will indeed stem from
mutually exclusive sets of constraints, it is still possible that
there is some solution that our solver is unable to find using
numeric methods.
2016-01-21 12:39:18 +00:00
whitequark 30d9bb0479 Add lathe button to toolbar. 2016-01-18 05:31:31 +00:00
whitequark ef5db2132e Ignore text window scroll events if edit control is visible.
After commit 11f29b12, we no longer have a convenient way to indicate
that the edit control should be moved without changing its contents;
the old code trying to do this caused a crash, since constructing
an std::string from a NULL char* is invalid.

This went undetected during testing, since on Linux, recent
GTK versions will munge scroll events while the edit box has
a modal grab.

I could've fixed the feature, but opted to remove it, since being able
to scroll the edit box out of visible region is more likely to result
in confusion than ever be useful.
2016-01-13 11:55:45 +00:00
whitequark 5e5ef3be3e Build Debian packages with debug symbols. 2016-01-13 06:45:17 +00:00
whitequark 28a6e04f33 Ask the user to locate imported files if they cannot be loaded. 2016-01-13 06:45:17 +00:00