Commit Graph

654 Commits (34a5d87011748dcf07943f29726a73cc04fbfaaf)

Author SHA1 Message Date
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
whitequark 54d8957bfe Only advise to Edit -> Undo if undo stack is not empty. 2016-01-13 06:45:17 +00:00
whitequark 86315b2b1f Allow exporting Three.js either as bare mesh or mesh with viewer.
Most people just want a single self-contained .html file, but more
advanced usage will involve embedding in a webpage, where the default
viewer would be copied and customized, and fed with bare mesh export.
2016-01-13 06:45:17 +00:00
whitequark 750842610c Simplify file saving code.
There is no need to record default file format choice, as
the first one is selected when an empty string is passed.
2016-01-13 06:45:17 +00:00
whitequark 259d8e0d38 Remember last used file type for all export dialogs. 2016-01-13 06:45:17 +00:00
whitequark 310fa9a817 Export vertex normals, not just face normals, for Three.js.
This causes NURBS models to render smoothly, like they do
in SolveSpace itself.
2016-01-13 06:45:17 +00:00
whitequark 1160b5d335 Fix OS X build. 2016-01-13 06:45:17 +00:00
EvilSpirit 6dced8052b Generate primitives for lathe groups.
The primitives that are generated are circles from points and
faces from axis-perpendicular line segments.
2016-01-13 06:45:17 +00:00
EvilSpirit 9c4d1cb9b0 Remove unused Expr operations ENTITY and POINT.
These weren't even used in any code, only defined.
2016-01-13 06:45:17 +00:00
EvilSpirit c5082f73a4 Remove unused field Expr::marker. 2016-01-13 06:45:17 +00:00
EvilSpirit 84a6511cfc Simplify layout of Expr.
Make the union anonymous so that its elements can be addressed
directly. Then, move the Expr *b field into the union, as it
already is never used at the same time as any of the union members.
2016-01-13 06:45:17 +00:00
EvilSpirit 158c66b1b4 Do not pass objects to Printf.
This seems to have worked by accident everywhere.
Interestingly, clang -Wall did not warn about this, but MSVC did.
2016-01-13 06:45:17 +00:00
whitequark 818436c57d Copy any constraints that only refer to entities in the clipboard. 2016-01-13 06:45:17 +00:00
whitequark 869404a8ec Fix GTK3 build. 2016-01-13 06:45:17 +00:00
whitequark b8e8da0c0b Add Unicode support to TTF renderer.
It works. Mostly. Sort of. Only on Windows fonts. Sometimes it
randomly refuses to render glyphs (try `х`, that's not a latin ex).
I'm not really sure why, the logic seems right.

Why do we have a homegrown TTF parser anyway? It's kind of awful.
It breaks on any slightly unusual input. It plows through UTF-16BE
font names like a nuclear-powered steamroller. It outright ignores
composite glyphs (is that why it's broken this time?). The kerning
is seizure-inducing. It ignores any characters outside BMP by design.

Maybe we should just replace it with freetype.
2016-01-13 06:45:17 +00:00
whitequark 11f29b1231 Replace NameStr with std::string.
This removes the arbitrary 64 byte restriction (which effectively
limits us to as little as 16 Unicode characters with CJK encodings),
makes classes smaller, and is easier to use.

As a consequence of making the length of all ex-NameStr fields
unbounded, all functions that returned a buffer derived from those
were changed to return std::string. Then, functions that are
contextually similar to the ones described above were changed
to return std::string. Then, functions that now happened to mostly
take an std::string argument converted to a C string were changed
to accept std::string.

This has produced a bit of churn, but is probably for the better.
2016-01-13 06:45:17 +00:00
whitequark 86f0439521 Work around an MSVC2013 value-initialization bug.
See https://connect.microsoft.com/VisualStudio/feedback/details/793506.
2016-01-13 06:45:17 +00:00
whitequark 9d2a035a71 Rasterize non-ASCII glyphs in the UI.
Now it is possible to give non-ASCII names to groups
as well as see non-ASCII filenames of imported files.
In the future this makes localization possible.

This works for LTR languages, such as European and CJK,
but not RTL such as Arabic. Does Arabic even exist in
monospaced form? I have no idea.
2016-01-13 06:45:16 +00:00
whitequark 31fd64af0a Remove platform checks for UTF-8 characters in the source. 2016-01-13 06:45:16 +00:00
whitequark ba10a75a7d Use Unicode-aware fopen and remove on Windows.
After this commit, SolveSpace can robustly handle non-ASCII filenames
on every OS. Additionally, on Windows, filenames longer than 260
characeters can be used, and files on network shares can be opened
directly, without mounting them as a network drive.
2016-01-13 06:45:16 +00:00
whitequark 97a9b4743e Make sure only *W functions from Win32 API are called.
After this commit, SolveSpace always uses UTF-8 strings internally
(represented as char* and std::string) on every OS, for everything:
UI labels, paths and user input. OS X always uses UTF-8; on Windows,
strings are converted at boundary; and on Linux/BSD/etc SolveSpace
refuses to start unless the current locale is UTF-8. This will
negatively affect literally no one.

This commit does not bring forth any user-visible improvement yet;
in order to correctly handle Unicode in filenames, it is still
necessary to change the fopen calls to _wfopen on Windows.
2016-01-13 06:45:16 +00:00
whitequark 5c9c32cfc7 Rigorously treat paths on every platform.
After this commit, SolveSpace deals with paths as follows:

  * Paths are generally treated as opaque platform-specific strings.
    This helps on Linux, because paths on Linux don't have any
    specific encoding and it helps to avoid any operations on them.

  * The UI in some places wants to get a basename. In this case,
    the newly introduced PATH_SEP is used. This allows to treat
    backslash as a regular character, which it is on Linux and OS X.

  * The only place where any nontrivial operations on paths are
    performed is the g->impFile/impFileRel logic.

    Specifically, when saved, g->impFile always contains an absolute
    path with separators of the current platform, and g->impFileRel
    always contains a relative path with UNIX separators. This allows
    to treat backslash as a regular character.

    Old files will contain g->impFileRel with Windows separators;
    these are detected by looking for a drive letter in g->impFile
    and in that case mapping Windows separators to UNIX ones.

There is no need to treat UNIX separators (forward slashes) in
any special way on Windows because there is no way on Windows,
not even via UNC paths, to create or address a directory entry
with a forward slash in its name.
2016-01-13 06:45:16 +00:00
whitequark 32383d22bf Rewrite all path handling with std::string.
What do we gain from this? Several things.

 * First, usage of PATH_MAX (the POSIX constant) is eliminated.
   PATH_MAX is actually a lie; Linux and OS X (and probably other BSDs
   too) do not have an actual path length limit. Linux claims 4096,
   OS X claims 1024, but it is trivial to construct paths that are
   longer.

 * Second, while Windows does enforce a limit of MAX_PATH (the Win32
   constant) for its ASCII functions, the Unicode variants, when
   used with UNC paths, do not have this restriction.
   The capability to use UNC paths is useful by itself, as it allows
   to access files on network shares directly.

 * Third, representing paths as std::string will make it easier to
   interoperate with *W WinAPI functions later.
2016-01-13 06:45:16 +00:00
whitequark 3ffbac38c6 Refactor Cnf* functions.
On Windows, freeze.{cpp,h} was factored into w32main.cpp.
The old implementation was too redundant and leaked registry
key handles.

On all platforms, Cnf* functions now use std::string.
This simplifies code everywhere, but will be particularly useful
when the Windows port switches to the *W WinAPI functions.
2016-01-13 06:45:16 +00:00
whitequark c84a3b6de3 Call constructors and destructors in List and IdList.
This is necessary to store non-POD classes in these containers.

Note that List and IdList do not use MemRealloc anymore;
this is necessarily (slightly) less efficient, but is the right
semantics, as you cannot just move non-POD types, e.g. std::string,
around in memory. All STL containers provide the same guarantees
and share the performance hit.

The slowdown is mostly mitigated by moving the contained objects,
so that no additional heap allocations or copies occur beyond
that of the object itself.
2016-01-13 06:45:16 +00:00
whitequark 97fa6355cc Fix memory leaks in IdList::{MoveSelfInto,DeepCopyInto}.
Note that this requires IdLists to be zero-initialized
to work correctly.
2016-01-13 06:45:16 +00:00
whitequark 45f056c852 Replace all ZERO and memset with C++11 brace-initialization.
This will allow us to use non-POD classes inside these objects
in future and is otherwise functionally equivalent, as well
as more concise.

Note that there are some subtleties with handling of
brace-initialization. Specifically:

On aggregates (e.g. simple C-style structures) using an empty
brace-initializer zero-initializes the aggregate, i.e. it makes
all members zero.

On non-aggregates an empty brace-initializer calls the default
constructor. And if the constructor doesn't explicitly initialize
the members (which the auto-generated constructor doesn't) then
the members will be constructed but otherwise uninitialized.

So, what is an aggregate class? To quote the C++ standard
(C++03 8.5.1 §1):

An aggregate is an array or a class (clause 9) with no
user-declared constructors (12.1), no private or protected
non-static data members (clause 11), no base classes (clause 10),
and no virtual functions (10.3).

In SolveSpace, we only have to handle the case of base classes;
Constraint and Entity have those. Thus, they had to gain a default
constructor that does nothing but initializes the members to zero.
2016-01-13 06:45:16 +00:00