Commit Graph

300 Commits (a4e7dea9e3bf5e054782529a30f26cfa9c24f1c2)

Author SHA1 Message Date
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
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
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
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 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
whitequark 02c30e6f87 Rewrite ttf2c to use GNU Unifont and merge with pngchar2c.pl.
After this change, SolveSpace does not contain nonfree assets.
Additionally, Perl is not required for the build.

Note that in the US, case law suggests that copyright does
not apply to bitmap fonts:
  http://www.renpy.org/wiki/renpy/misc/Bitmap_Fonts_and_Copyright

Nevertheless, it was prudent to replace the asset with something
that is unambiguously free.
2015-12-29 11:15:50 +08:00
whitequark f76f76ff60 Rewrite png2c.pl in C++.
This allows us to always generate icons during build,
and in the future remove a Perl dependency.
2015-12-29 11:15:50 +08:00
ruevs b23336b589 Add a new length-difference constraint.
This constraint requires the lengths of two line segments to
differ by a constant.
It can be useful to define the tolerances when making joints.
2015-12-28 21:37:07 +08:00
whitequark 8c2e94a01a Add a shortcut for drawing construction line segments.
Almost all construction requests are lines, and allowing to
draw them as construction obviates the need to select them one
by one afterwards to convert them. Also, it removes the "not closed
contour" error message, which is a nice usability improvement.
2015-12-28 21:37:07 +08:00
whitequark e40929afca Add a shortcut for adding a reference dimension or angle.
This is equivalent to adding a constraint, then making it a reference.
The benefits are that:
 * it's quicker;
 * it avoids having an over-constrained system, with an associated
   angry red flash and a regeneration delay.
The latter in particular is a very substantial usability improvement.

The reference distance command is useful most of the time,
but the reference angle one is also added for consistency.
2015-12-28 21:37:07 +08:00
William D. Jones 4b02bf1e81 Implement Three.js export. 2015-12-28 21:37:07 +08:00
EvilSpirit 3c917ebac9 Use relative tolerance for axis-parallel autoconstrainter.
This works better than absolute tolerance in display pixels
for small lines.
2015-12-28 21:37:07 +08:00
whitequark c6194d439c Allow using the constant "pi" in expressions. 2015-12-28 21:37:07 +08:00
EvilSpirit ef3ee55d42 Optimize Expr::From(double) by statically allocating common constants. 2015-12-28 21:37:07 +08:00
ruevs 922a6260d7 Allow building with MinGW on Windows. 2015-12-28 21:37:06 +08:00
whitequark 28166e6200 Use C++ std::{min,max,swap} instead of custom ones.
The main benefit is that std::swap will ensure that the type
of arguments is copy-constructible and move-constructible.
It is more concise as well.

When min and max are defined as macros, they will conflict
with STL header files included by other C++ libraries;
in this case STL will #undef any other definition.
2015-12-28 21:37:06 +08:00
whitequark 063dfc4f98 Require cmake 3.1.0 and C++11.
We plan to use C++11 features in the future. Moreover, recent gtkmm
has a hard requirement on C++11.
2015-12-28 21:37:06 +08:00
whitequark 1b6cd0d632 Make in-tree zlib more robust. 2015-12-28 21:37:06 +08:00
EvilSpirit 4d5a92e9b2 Make faces selectable again after undo. 2015-12-28 21:37:06 +08:00
whitequark fdc39edfd8 Fix AllocTemporary on *nix. 2015-12-28 21:37:06 +08:00
whitequark 06be0d1157 Fix read of uninitialized memory. 2015-12-28 21:37:06 +08:00
whitequark 1422d3abd2 Fix initialization order issue. 2015-12-28 21:37:06 +08:00
whitequark 0159a87a8a Add support for cross-compiling from Linux.
As a side effect, zlib and libpng are now git submodules,
based on their respective official git repositories.
This is necessary, because MinGW has a different ABI and
it cannot use the prebuilt binaries built by MSVC.

The submodules are also used for Windows, for several reasons:
  * to allow 64-bit builds;
  * to allow using newer MSVC, which doesn't like the prebuilt
    libraries;
  * to keep the libraries updated.
2015-07-10 15:59:12 +03:00
whitequark 5e7c7fce7e Rename RgbColor to RgbaColor. 2015-07-10 15:59:12 +03:00
whitequark 75a3936b64 Add support for transparent solids.
Some extra code is necessary to determine that the back faces
should not be drawn in red for transparent solids. It is expected
that the user will first ensure that the shell is watertight
and then set the opacity; back faces are still drawn if
the opacity is exactly 1.

The savefile format is changed backwards-compatibly by stashing
the alpha value in uppermost byte of 4-byte hex color value
in Surface and Triangle clauses. The existing files have 00
in the high byte, so RgbColor::FromPackedInt treats that
as "opaque".
2015-07-10 15:59:12 +03:00
whitequark 1b69032d99 Allow displaying and editing diameter constraints as radius.
The savefile format is not changed; the display option is
stored in Constraint::other.
2015-07-10 15:59:12 +03:00
whitequark f62e95d7b6 Replace \ with / slashes in assembly relative paths on *nix.
This is done specifically targeting the case where an assembly
initially made on Windows is transported to an *nix machine.
On *nix, the paths will be already saved with /, and correctly
read on Windows. On Windows however / is not a first-class separator,
in particular it cannot be used in UNC-style paths \\?\ (which
are the only paths that work with Unicode).

See also:
http://msdn.microsoft.com/en-us/library/aa365247.aspx
2015-07-10 15:59:12 +03:00
whitequark 69c509064c Automatically add horz/vert constraints to lines if close enough. 2015-07-10 15:59:12 +03:00
whitequark f89020ad26 Highlight pending operation on toolbar, even if started via keyboard. 2015-07-10 15:59:12 +03:00
whitequark 46db5378dc Add Travis CI and Appveyor CI configurations. 2015-07-10 15:59:12 +03:00
whitequark 71b7ad7f99 Add an autosave timer.
Original patch by Marc Britten <marc.britten@gmail.com>.
2015-07-10 15:59:12 +03:00
whitequark 22d43d5b83 Remember the last format used to export 2D Views.
This helps a lot when exporting a lot of views, e.g.
for shop drawings.
2015-07-10 15:59:12 +03:00
whitequark d585f0d1ff Make "Align view onto workplane" switch to locked workplane, if any.
Original patch by yugami
(http://solvespace.com/forum.pl?action=viewthread&parent=508).
2015-07-10 15:59:12 +03:00
whitequark d0c0a7ae5a Remove FLTK port.
It provides no value over the native GTK and Cocoa ports.
2015-07-10 15:59:12 +03:00
whitequark bbe4999033 Make sure all DrawOrGetDistance style code only draws in Paint();
Otherwise, GL reports errors when used with FBOs, as well as
creates visual artifacts, especially when UI is also drawn
with OpenGL.
2015-07-10 15:59:12 +03:00
whitequark 4b86fb89f8 Make "Show Menu Bar" and "Full Screen" use Ctrl/Cmd+Fn.
On OS X F11 and F12 are system-global shortcuts. I could switch
them only on Apple platforms, but for consistency I decided not to.
Anyway, neither of those appeared in an official release.
2015-07-10 15:59:12 +03:00
whitequark d76d59ea64 Build Mac OS X dmg installation image. 2015-07-10 15:59:12 +03:00
whitequark 95ab80d0ee Implement OS X port. 2015-07-10 15:59:12 +03:00
whitequark 5d7a5bf3a7 Pack everything into `namespace SolveSpace`.
This is required to avoid name conflicts with the Cocoa libraries
on OS X.

I renamed the `class SolveSpace` to `class SolveSpaceUI`, because
that's what it does, and because otherwise the namespace would
have to be called something else than `namespace SolveSpace`.
2015-07-10 15:59:12 +03:00
whitequark 0807c2fdfe Add a native Debian package. 2015-07-10 15:59:12 +03:00
whitequark d3dbf23725 Add a desktop file in the format understandable by Ubuntu. 2015-07-10 15:59:12 +03:00
whitequark 2ce12155bf Add bug compatibility with Chromium GL (VirtualBox).
I question the life choices that led me here.
2015-07-10 15:59:12 +03:00
whitequark 88e4163970 Use the extension version of FBO extension instead of core.
This will allow solvespace to run on pre-OpenGL 3.0 implementations,
such as VirtualBox (and possibly others).

However, VirtualBox's handling of framebuffer objects is buggy;
it tries to draw over our X window and fails to do either.

I hate OpenGL.
2015-07-10 15:59:12 +03:00
whitequark e27c6b56c3 Implement offscreen rendering using GL framebuffer objects.
Apparently pbuffers are also a deprecated and unportable
way of offscreen rendering. They're not supported by
Chromium OpenGL implementation, which is what 3D-accelerated
VirtualBox uses.

This would also help a future OS X port.
2015-07-10 15:59:12 +03:00
whitequark 622c9efadb Use GL pbuffers instead of GLX pixmaps.
Apparently GLX pixmaps are an antiquated and unsupported method
for offscreen rendering in OpenGL. Specifically this broke
software and VirtualBox accelerated rendering in Ubuntu trusty
and who knows which other systems.

This commit switches the rendering to use pbuffers instead,
while retaining all other logic. The pbuffers are fixed-size,
because reallocating pbuffers during a resize sometimes results
in segfaults in glXMakeCurrent despite apparently correct
API usage.
2015-07-10 15:59:12 +03:00
whitequark 2c39f259db Add a GTK2/3 port.
In principle, GTK3 is the way forward, and GTK2 is officially
deprecated, though still maintained. In practice however, GTK3
is often unbearably buggy; e.g. on my system, combo boxes
don't ever roll up in GTK3 windows. So I have added support
for both.

This required a few minor changes to the core, namely:
  * GTK wants to know beforehand whether a menu item is a check
    menu item or a regular one.
  * GTK doesn't give us an easy way to execute something after
    any event is processed, so an explicit idle timer is added.
    This is a no-op on Win32.
  * A few function signatures were const'ed, since GTK expects
    immutable strings when converting to Glib::ustring.
2015-07-10 15:59:12 +03:00
whitequark b68631ee56 Make fltkutil.cpp independent of FLTK and rename it to unixutil.cpp.
fltkutil.cpp should be independent of FLTK so that it can be linked
into libslvs while neither requiring every user of the library to
reimplement these support routines nor requiring linking in FLTK.
2015-07-10 15:59:11 +03:00
whitequark 5db5f1e152 Add a CMake buildsystem.
Additionally, update build tools so that no stdio redirection
is necessary.
2015-07-10 15:59:11 +03:00
whitequark c5364fe7a8 Trim trailing whitespace. 2015-07-10 15:59:11 +03:00
whitequark 7c7ac17e4b Remove all legacy buildsystems. 2015-07-10 15:59:11 +03:00
whitequark 3a42a8d8cb catc 2015-07-10 15:59:11 +03:00
whitequark 62af550c0b Fix try..catch clauses dealing with C strings.
On *nix, a thrown string literal cannot be caught using
catch(char*), resulting in crashes.
2015-07-10 15:58:56 +03:00
whitequark 024a26bf57 Explicitly request a 24-bit depth buffer in FLTK port.
See http://solvespace.com/forum.pl?action=viewthread&parent=417.
2015-07-05 06:20:25 +03:00
whitequark 14690e6e42 Work around poor line rendering with Intel Mesa-based drivers.
However, don't use ssglLineWidth for UI drawing operations.
These only draw horizontal or vertical lines that don't need to
be antialiased, and thus don't require the workaround. In fact
the workaround would make them thicker than needed.
2015-07-05 06:20:25 +03:00
whitequark 13afcb310e Fix fontconfig detection code in FLTK.
Either clang is stricter than the compiler the authors of that
code used, or fontconfig detection never worked.
2015-07-05 06:20:25 +03:00
whitequark 80046672ef Use Command instead of Control key for shortcuts on OS X.
It is the OS X convention.
2015-07-05 06:20:25 +03:00
whitequark 84f2a59993 Use the degree symbol on non-Windows.
The Windows code uses a degree symbol in Latin-1, which
crashes FLTK on OS X.
2015-07-05 06:20:25 +03:00
whitequark ffd2df9494 Fix dbg() not writing a newline.
puts() appends a newline, but fputs() does not.
Who needs consistency when you have undefined behavior? Oh, wait.
2015-07-05 06:20:25 +03:00
whitequark 1bbf61b8a2 Fix accidental glibc dependency.
fltkmain accidentally used optind instead of optndx. optind is
defined as an extern int in glibc but not on BSD systems.
This also broke passing a filename on command line.
2015-07-05 06:20:25 +03:00
whitequark 604c4bbea3 Fix oops() to not have UB.
Writing to NULL is undefined behavior and it is legal for the
compiler to simply remove it; clang will do so. abort()
or __builtin_trap() would produce the desirable result.
abort() is used as it is more portable.
2015-07-05 06:20:25 +03:00
whitequark 1cd2e2be2f Add Apple-specific OpenGL include statements. 2015-07-05 06:20:25 +03:00
whitequark 5894efcfe5 Fix unresolved symbols in src/constraint.cpp when building libslvs. 2015-07-05 06:20:25 +03:00
Jonathan Westhues ba8202d54a Don't falsely detect inconsistent systems with small angle constraints. 2015-06-08 11:19:29 -07:00
Jonathan Westhues 403d3c04d2 Improve relative paths for file import.
Don't break on case-sensitive filesystems, and don't require an explicit
regen after initial save of the assembly.
2015-05-21 05:26:29 -07:00
Jonathan Westhues 044a4ea8fc Don't offset SVG width and height by one. 2015-04-12 14:24:55 -07:00
Jonathan Westhues 9c9a0d8c28 Merge commit 'refs/merge-requests/16' of https://gitorious.org/solvespace/solvespace 2015-03-10 22:50:31 -07:00
Marc Britten 3b587d022a Updated Freeze to be multi monitor friendly 2015-03-10 22:05:29 -05:00
Roland Lutz 48880f6fe9 Apply automake option `subdir-objects' globally 2015-03-02 21:46:11 +01:00
Roland Lutz 9b68bf8f7b Move library source to src/ directory 2015-03-02 21:46:11 +01:00
Roland Lutz ae37fb783e Control libslvs compilation from src/Makefile.am 2015-03-02 21:46:11 +01:00
Andrew Downing 6cfa884406 fix GraphicsEditControlWindow placement, and fix error due to cmath being included instead of math.h 2015-02-26 12:22:42 -05:00
Andrew Downing 252f4128b7 add includes to dsc.h to fix errors in it's own context (not real errors since dsc.h isnt compiled by itself, just screws up the code model in QtCreator without them) 2015-02-26 09:19:15 -05:00
Andrew Downing 023f404475 add LDFLAGS for FLTK to exposed/Makefile.am and src/Makefile.am 2015-02-25 22:47:35 -05:00
Andrew Downing ce77197dac display GraphicsEditControl in its own tooltip window avoiding the need to hack FLTKs internals 2015-02-25 12:43:01 -05:00
Andrew Downing 396b1c63a4 fix fltk code 2015-02-24 16:07:32 -05:00
Andrew Downing 1bfba0df5f fix fltk code 2015-02-24 15:54:27 -05:00
Marc Britten 0f334cc040 Added updated header information for surfaces 2015-02-08 10:43:19 -06:00
Petteri Aimonen 12a29ddce0 FLTK: Don't oops() when unknown mouse button is pressed.
For example forward/backward buttons are present on many mouses
but are not used by solvespace. This oops() caused solvespace to
crash whenever those buttons were (accidentally) pressed.
2014-12-29 22:33:19 +02:00
Petteri Aimonen 8996833989 Fix crash on Ubuntu when opening assembly files.
Ubuntu enables GCC's buffer overflow checks by default. In SAVEDptr
union, the path was declared as 'char', even though MAX_PATH memory
was actually allocated. The buffer overflow check mistakenly thought
that the buffer size was only 1 and aborted the program whenever it
tried to read a path from a file.
2014-12-29 22:16:21 +02:00
Jonathan Westhues e587d0ebee Fix GUI bugs in FLTK port, per Xavier Thomas's forum post:
"There was some small but annoying bugs with the FLTK port:
-cursor disappear sometimes
-not all the area of the windows (graphic and text windows) is accessible
by the mouse after a re-size
-input widget for editing constraints value are not correctly placed"
2014-05-11 15:43:03 -07:00
Ilya Novoselov f5297093c0 Fix automake "option 'subdir-objects' is disabled" warning 2014-04-10 23:05:17 +06:00
Ilya Novoselov 01213bcafb Rest of code assumes that allocated memory is filled with zeroes 2014-04-08 07:56:57 +06:00
Jonathan Westhues f4916f9ee4 Compare ((char *)p)[0] against '\0', not (char *)p.
Also make the library example compile again under MSVC, and make the
perl scripts to build the image tables work.
2013-12-08 00:32:50 -08:00
Daniel Richard G 1bc73c4a75 Renamed the RGB() macro to RGBi() to avoid collisions with Microsoft
Microsoft defines an RGB() macro that at one point was compatible with our
version (returning a packed integer containing 8-bit red, green and blue
channels), but is no longer, and the incompatibility led to an awkward
situation in w32main.cpp where we had to restore Microsoft's form of the
macro in order for the commctrl.h header to compile. By renaming the macro
to RGBi()---analogous to the RGBf() macro we already define---we avoid the
hassle entirely.
2013-12-02 04:27:34 -05:00
Daniel Richard G f9f321ca84 Warning fixes 2013-12-02 04:27:33 -05:00
Daniel Richard G fd9dc19a34 Added the exposed/ library and demo program to the Autotools build
The libslvs library and CDemo program can now be built by Autotools. A few
code changes were needed for this: C++ comments in C code had to be
converted, constraint.cpp required some massaging, and fltkutil.cpp needed
a stub for InitHeaps().
2013-12-02 04:27:33 -05:00
Daniel Richard G 6c68294249 Improved handling of generated files
Place a pre-built copy of generated source files in src/built/, so that
users building SolveSpace from Git without the tools or setup necessary to
generate these can still complete the process.

Makefile.msvc: Use slashes consistently, and added rules to copy files from
src/built/ if needed

configure.ac: Check for presence of src/built/ at configure time

src/Makefile.am: Handle the generated *.table.h files together with
icon*.h; updated the source-generation rules so that the files are created
in builddir, not srcdir; added rules to copy files from src/built/ if
needed
2013-11-20 01:25:48 -05:00
Daniel Richard G 174ed76ef9 Added libspnav configure option and support to the Autotools build system 2013-11-19 18:17:55 -05:00
Daniel Richard G bb3e5e9bb1 Minor follow-up changes
solvespace.h: Need to #define MAX_PATH on POSIX systems

resource.rc: icon.ico now lives in the same directory as this file
2013-11-19 18:17:55 -05:00
Daniel Richard G 0a24cf40f0 Moved most of the source into a src/ subdirectory
The SolveSpace top-level directory was getting a bit cluttered, so
following the example of numerous other free-software projects, we move the
main application source into a subdirectory and adjust the build systems
accordingly.

Also, got rid of the obj/ directory in favor of creating it on the fly in
Makefile.msvc.
2013-11-19 18:17:32 -05:00