Commit Graph

815 Commits (b4e1ce44e8cd9a5220bb25d2b251ee769b7a1f68)

Author SHA1 Message Date
whitequark 41365c5f9f DXF: Fix export of wireframe as 3D DXF.
Before this commit, polylines got flattened but all other entities
got exported with the proper Z coordinate. After this commit, all
entities are exported with proper Z coordinate.

Also, instead of exporting LWPOLYLINE (2d only), POLYLINE (2d/3d)
is exported; as a bonus it is more compatible with 3rd party
software, since it is older.
2016-11-26 08:18:14 +00:00
EvilSpirit aaab8a09d4 Fix a crash when extruding TTF text. 2016-11-21 17:35:24 +00:00
EvilSpirit 37defcbc33 Unbreak Camera::UnProjectPoint3.
The handedness was wrong, and this resulted in weird glitches
while drawing anything that depends on AlignToPixelGrid, like
normals.
2016-11-19 09:50:00 +00:00
EvilSpirit 01ae452507 Unbreak drawing of DEPTH_ONLY meshes via OpenGL 2 batch canvas. 2016-11-19 09:04:47 +00:00
Elvira Khabirova 61f248899a Refactor expression parsing.
The new expression parser is significantly simpler, more robust
and easier to understand; it also doesn't use longjmp or pollutes
Expr::Op anymore.
2016-11-19 09:02:14 +00:00
whitequark 8dc60f61c1 Fix Windows build with -DOPENGL=1.
This is mostly useful when testing the Windows functionality
on Linux, as wine is currently unable to compile the shaders
that ANGLE outputs.
2016-11-19 05:14:06 +00:00
whitequark d3f2ac7513 Remove most dependencies on config.h.
The only thing we need it anymore is the package version and platform
configuration, so only include it for that. As a result, less files
are rebuilt when the git commit changes and config.h is regenerated.
2016-11-19 01:00:11 +00:00
whitequark 369b0a378c Optimize toggling visibility of normals, points, edges, outlines.
Before this commit, any visibility toggle would cause a regeneration.
After this commit, toggling visibility of normals and points never
causes a regeneration, and toggling visibility of edges and outlines
only causes a regeneration when they weren't already generated.
2016-11-18 15:26:01 +00:00
EvilSpirit 683ac78ca2 Optimize FromTransformationOf for performing identity transformation.
FromTransformationOf is called with an identity rotation or
translation for translation and rotation groups, and for every
group that doesn't produce a solid model. This commit omits any
calculations from it when the relevant part of transformation
would change nothing.

This commit results in a ~10% improvement on testcase
woodworking/big-big-big-woodworking-asm, and splitting the condition
into three parts results in a ~5% improvement on testcase
stress/rotate_groups_0.
2016-11-18 14:51:47 +00:00
whitequark 9a0f2c3601 Fix detection of transparent meshes.
SSurface::TriangulateInto first populates the mesh with triangles
that have no color, and then paints them, which confused the code
that detects if a mesh is transparent into thinking that all of them
are; and that broke the "draw back faces in red" feature, since it
is disabled for transparent meshes.
2016-11-18 11:38:45 +00:00
whitequark 73844f7202 Draw triangle back faces like the front, unless we draw them in red.
The configuration option "draw back faces in red" aids debugging,
in that it allows to visually identify a non-watertight mesh.
When it is disabled, or when the mesh is transparent, we used to not
draw them at all before this commit; after, they are drawn just like
the front faces.

This has two consequences:
  1. Inner surfaces of non-watertight meshes are not see-through
     anymore. That used to be the behavior in version 2.0, and it
     was accidentally broken in 2.1.
  2. Transparent meshes look *much* better.
  3. Solids made from a union of a non-transparent and a transparent
     one look sensibly at all.

This commit also updates the OpenGL 1 renderer to let it render
such meshes correctly.
2016-11-18 11:38:45 +00:00
whitequark c8ff17f4a2 Add OpenGL 2 support on Windows using ANGLE.
This commit performs two main changes:
  * Alters the shaders to use only strictly conformant GLSL 2.0.
  * Alters the Windows UI to use ANGLE via GL ES 2.0 and EGL 1.4.

This commit also drops official support for Windows XP, since ANGLE
requires a non-XP toolset to build. It is still possible to build
SolveSpace for Windows XP using:

  cmake -T v120_xp -DOPENGL=1
2016-11-18 11:38:45 +00:00
whitequark 9db50ed077 Refactor the renderer frame flush functionality.
This commit does three things:
  * Recognizes that BeginFrame()/EndFrame() are badly named, since
    BeginFrame() sets up framebuffer, and EndFrame() flushes a frame,
    and they do not have to be called in pairs; and so renames them
    to NewFrame()/FlushFrame().
  * Reduces the amount of frame flushes in GraphicsWindow::Paint()
    to two, which is the minimum since we use two different cameras
    for geometry and UI;
  * Changes the FPS measurement code to only take into account
    the time spent rendering our main geometry, and not the UI
    rendering or window system interaction time.
2016-11-18 04:05:12 +00:00
whitequark 156fe73bee Allow using z-index in UiCanvas, and use it for tooltips.
Before this commit, tooltips in the text window are drawn under
the red "X" indicating a disabled button. After this commit, they
are moved on top of that.

This commit also alters the OpenGL renderers' SetCamera() method
to clear the depth buffer, as that would interfere with drawing
the UI; the toolbar would get occluded by geometry.
2016-11-18 04:05:12 +00:00
EvilSpirit 92773a5770 Implement BatchCanvas for GL2. 2016-11-18 04:05:12 +00:00
EvilSpirit 52557ee979 Add an interface for view-independent rendering.
To actually achieve improved performance with the OpenGL 2 renderer,
we have to cache geometry that doesn't change when the viewport does
(note that the rendered pixels can change quite dramatically because
we can reconfigure shaders; e.g. stippling can be drawn in screen
coordinates).

This commit adds a BatchCanvas interface that can be implemented
by renderers, and uses it for drawing entities such as lines and
points.
2016-11-18 04:04:32 +00:00
EvilSpirit 6d2c2aecff Implement an OpenGL 2 renderer.
There are two main reasons to desire an OpenGL 2 renderer:
 1. Compatibility. The compatibility profile, ironically, does not
    offer a lot of compatibility, and our OpenGL 1 renderer will not
    run on Android, iOS, or WebGL.
 2. Performance. The immediate mode does not scale, and in fact
    becomes very slow with only a moderate amount of lines on screen,
    and only a somewhat large amount of triangles.

This commit implements a basic OpenGL 2 renderer that uses only
features from the (OpenGL 3.2) core profile. It is not yet faster
than the OpenGL 1 renderer, primarily because it uses a lot of small
draw calls.

This commit uses OpenGL 2 on Linux and Mac OS X directly (i.e. links
to the GL symbols from version 2+); on Windows this is impossible
with the default drivers, so for now OpenGL 1 is still used there.
2016-11-18 04:04:29 +00:00
EvilSpirit f8824e1fb2 Reimplement drawing of the mesh wireframe.
OpenGL 2 and newer do not have the glPolygonMode(..., GL_LINES) API,
so produce the wireframe on our side. It's somewhat slow, and draws
every line three times, but it is cached when the OpenGL 2 renderer
is used, and this should do for a debugging feature.
2016-11-18 02:40:43 +00:00
whitequark e56630e71d Fix creation of workplane based on a workplane.
This fixes functionality introduced by commit 3c45158, which did not
take into account reference groups.
2016-11-17 15:51:19 +00:00
whitequark c97ba6b928 Optimize IdList::MaximumId() from O(n) to O(1).
This specific implementation seems to have lingered from the days
before IdList was stored sorted. This commit has resulted in a ~5%
improvement in Generate::DIRTY time for modelisation.slvs on a GCC 6
release build.
2016-11-17 14:14:56 +00:00
whitequark ea0a1b743a Fix uninitialized variable warnings.
gcc 6 displays these when compiling in release mode; all of these
warnings except the rankOk one were benign because there would have
been an error about the incomplete switch statement.

The rankOk warning highlighted a real problem: bailing early to
didnt_converge would have branched on an uninitialized variable.
2016-11-17 13:59:51 +00:00
whitequark 802d092b13 When exporting files, initially fill in the basename of the sketch.
This is a common and convenient behavior; the basename is
pre-selected, so exporting multiple views requires just one keystroke
to put the cursor after the basename.
2016-11-17 12:54:02 +00:00
whitequark e681ba3218 Rephrase the error message for sketch in workplane creation.
The old message was confusing because it seemingly talked about
a point that was orthogonal to coordinate axes.
2016-11-17 10:07:33 +00:00
Elvira Khabirova 3c451586d7 Add an ability to create a workplane with another workplane.
This is useful in case one wants to create a workplane based on
one of the reference ones, to be explicit, or to avoid fishing out
again the line segments used to create a workplane at an angle.
2016-11-17 10:04:38 +00:00
whitequark c7277521f3 Fix error message shown when exporting mesh with wrong extension. 2016-11-17 06:52:44 +00:00
Elvira Khabirova 489ae66e96 Fix crash when trying to import not .dxf or .dwg files 2016-11-17 06:52:12 +00:00
Evil-Spirit fdd08cbead Warn if exporting a non-watertight mesh.
If a generated mesh is non-watertight, and this is not noticed for
some reason (e.g. the markers are dismissed), and the mesh is
exported for further processing, it could cause problems down
the line.
2016-11-17 00:53:28 +00:00
Evil-Spirit 3b241392d4 Fix rendering of horizontal/vertical constraint labels.
This was a regression from 2.2 to 3.0, caused by the Canvas
transition.
2016-11-17 00:48:47 +00:00
whitequark 1ec36fc657 Add missing newline in OutputDebugStringA invocation.
Before this commit, every debug message was correctly printed
to stdout, but they were all concatenated onto a single line in
the Visual Studio "Output" pane.
2016-11-16 05:57:06 +00:00
whitequark 9673225648 Fix a crash when adding a symmetric constraint on a line.
This is the same problem as in ffd9c62.
2016-11-16 02:25:21 +00:00
EvilSpirit a0d7f1dadb Optimize GroupsInOrder.
GroupsInOrder is an extremely hot function, especially during object
picking: before this commit, it was easy to get second plus latencies
on picking, and after this commit picking is almost real-time.
2016-11-15 08:56:43 +00:00
EvilSpirit 13d4a1bb6a Fix memory leak in RemoveTagged. 2016-11-15 08:56:40 +00:00
EvilSpirit 7b9d730a23 Hide OpenGL implementation details.
Abstract the exact details of the OpenGL renderer in the render.h
header; this allows us to use GL-specific types in the renderer
class and functions without including OpenGL (and Windows, where
applicable) headers in every source file.
2016-11-14 20:30:46 +00:00
whitequark afecbccb0f OS X: fix another out-of-bounds TW.META access.
See also f5a37ae.
2016-11-05 17:05:17 +00:00
whitequark 74cb1f589c Add two more points to the TTF text request.
These points can be used for constraining the width of the text
(or to the width of the text).

The main parts of the commit are:
  * TtfFont is restructured to be able to return the aspect ratio
    for a given string.
  * This aspect ratio is written to the savefile, such that even if
    the font is missing, the sketch would still be solved correctly.
  * The two additional points are constrained via perpendicularly
    to the two main points (which form a v vector).

The compatibility features are as follows:
  * When the font is missing in old files, 1:1 aspect ratio is used,
    which works for the replacement symbol anyhow.
  * When the two additional points are missing in old files, their
    would-be positions are calculated and they are moved there,
    avoiding 'jumping' of underconstrained sketches.
2016-11-02 09:22:18 +00:00
whitequark 23feb4cf8f TTF: use metrics of 'A' to determine cap height.
SolveSpace 2.0 used the height of 'A' (i.e. cap height) to determine
the reference height.
SolveSpace 2.1 completely broke that during transition to Freetype,
and used something more or less random, by using FT_Set_Char_Size
with units_per_EM.
SolveSpace 2.2 attempted to fix that, but also used something more
or less random, by using FT_Request_Size with "unit" values.

Turns out that Freetype actually doesn't have a concept of cap height
at all. It is possible to extract it from the TT_OS2 table that is
present in some TrueType fonts, but it is not present in Microsoft
fonts (the msttcorefonts ones), and for those Linux fonts in which
it is present it doesn't appear very reliable.

So instead, use the height of 'A' instead, like version 2.0 did.
This has the advantage that it is quite bulletproof, and also matches
exactly what the old files are measured against.

One downside is that fonts without an 'A' glyph would not render.
We can deal with that when it becomes a problem.
2016-11-02 08:59:33 +00:00
whitequark 7bd6adefd8 TTF: actually use CID as GID when CID-to-GID mapping is absent. 2016-11-02 08:47:02 +00:00
whitequark b8bec35a0c TTF: only call FT_Request_Size once after loading. 2016-11-02 08:46:36 +00:00
EvilSpirit 505f503cc3 Don't consider workplane origin point for bounding box calculation. 2016-11-02 02:43:45 +00:00
EvilSpirit 600c39db91 Don't consider arc center point for bounding box calculation. 2016-11-02 02:40:26 +00:00
whitequark f619a4b85e GTK: add a no-op glXSwapBuffers call for apitrace.
Apitrace uses swapping buffers to determine frame boundaries; before
this commit, everything solvespace renders gets put into a single
frame. Since we don't use double-buffered rendering, the call does
nothing (and is legal to perform), but apitrace output becomes
readable.
2016-10-22 07:47:13 +00:00
whitequark 345c982b3b OS X: don't crash in GetSaveFile() if default extension is invalid. 2016-10-21 20:18:45 +04:00
whitequark 90987d3ee4 Fix a rendering bug introduced in 9f97e9a. 2016-10-14 04:15:20 +00:00
EvilSpirit 3a585ea7c2 Try to re-solve groups that fail rank test.
Sometimes, after a large change in a sketch, constraints that are
geometrically fine may still cause the rank test to fail. One way
this can happen is VectorsParallel() pivoting wrong due to the big
move, converging anyways but ending up singular. It would then
re-pivot correctly on the new solution when you re-solve, making
this a transient error. This is visible when dragging the arm in
the jansen-asm.slvs example.

After this commit, if the rank test fails, equations are regenerated
the Jacobian is rewritten, and the rank test is retried, which
prevents these transient errors from interfering with dragging.

The problem described above was invisible before c011444, as rank
test was only performed before solving.
2016-10-14 00:27:38 +00:00
Evil-Spirit b2092eaea9 Write params if system is solved as REDUNDANT_OKAY.
A system solved as REDUNDANT_OKAY is still solved correctly,
even if the UI would consider this an error, in case that
g->allowRedundant==false. So there's no reason to discard this
solution; we might find it useful if a system loses a degree of
freedom while dragging, or to avoid regeneration after redundant
constraints are allowed.

This commit also reverts commit 3ff236c, as that is not necessary
anymore.
2016-10-14 00:10:41 +00:00
EvilSpirit b37aba00e2 Preserve stipple phase across separate piecewise linear segments.
This significantly increases visual clarity, especially for curves
with a low chord tolerance value.
2016-10-13 23:15:35 +00:00
whitequark 47288e9a4c Stitch outlines before display to preserve phase of stippling.
Before this commit, the outlines are generated in an arbitrary order
from the kd-tree. This worked just fine for continuous lines, but
for stippling, especially on curves, this meant that most of
the piecewise linear edges would have the stippling phase restart
from zero, leading to a very poor appearance.
2016-10-13 22:05:32 +00:00
EvilSpirit 186911a51a Factor out PolylineBuilder from DXF export code. 2016-10-13 22:05:29 +00:00
EvilSpirit d2c250324b Fix many rendering bugs introduced in df83ee4 and 9f97e9a. 2016-10-13 21:30:27 +00:00
whitequark ea52fcbce1 Remove unnecessary GenerateAll/ZoomToFit calls in AfterNewFile.
These were useful before because chord tolerance depended on the zoom
level; and so the first generation produced a crude mesh used to
set the zoom level, and the second actually did useful work.
Chord tolerance is now independent of the zoom level, so this code
is no longer useful.
2016-10-12 23:34:02 +00:00
whitequark 62f5f690c1 Print a debug message for generations that are taking a long time. 2016-10-12 23:15:24 +00:00
EvilSpirit 2ccf5954d4 Allow creating n-dimensional arrays with translate and rotate groups.
Before this commit, a translate group based on another translate
group would always use the "union" boolean operation, which does not
work at all if one wants an array with a difference operation, and
results in degraded performance if one wants an array with
an assemble operation.
2016-10-12 22:02:38 +00:00
EvilSpirit 6658b1fa2b Allow combining extrude, lathe, translate and rotate group as assemblies.
This significantly improves performance e.g. in case of a sketch
containing a multitude of wooden panels, as the meshes can be
merely transformed instead of being joined.
2016-10-12 22:02:38 +00:00
whitequark 5462fc6b3c OS X: map the backspace key to the "Delete" function.
Apple hardware does not have a discrete Delete key, so Backspace
is used for deleting stuff instead.
2016-10-12 23:42:41 +04:00
whitequark 90f10ccfa6 OS X: set scroller knob style to light.
On newer OS X versions the scrollbar is overlaid on the window
contents, so a black know is invisible.
2016-10-12 23:24:17 +04:00
whitequark b5f5e05336 OS X: don't remap OK in message boxes to Escape.
The platform convention is to use Return.
2016-10-12 18:56:31 +00:00
whitequark b0363802d8 OS X: revert "sort out window visibility and focus."
This reverts commit 1dba594949.

Turns out the old behavior was more appropriate for OS X.
2016-10-12 18:56:31 +00:00
whitequark 291e16e549 Fix a few compiler warnings. 2016-10-12 14:36:52 +00:00
EvilSpirit 363f5c1ab8 Fix BitmapFont to not lose texture updates.
Texture could also be updated by GetWidth(), which calls GetGlyph()
internally, and then the next LocateGlyph() call would return false.
2016-10-11 23:45:19 +00:00
whitequark af226b2437 Fix rendering of reference axes in bottom left corner. 2016-10-11 23:32:21 +00:00
EvilSpirit 9f97e9aad4 Allow selecting unit (px/mm) in Canvas::Stroke.
By directly specifying the desired end result to the renderer, we
can avoid regeneration of geometry.
2016-10-11 23:32:21 +00:00
whitequark a5c7fc6ad9 Disable closed contour check in the test harness.
The check was actually half-broken from the beginning and
until df83ee4; the thick red line was rendered properly but
the error text was rendered with width 0, which by chance worked
on some GL implementations. That commit has fixed the underlying
bug but left the text line width at 0 to avoid test breakage.

This commit fixes the bug, turns off the check completely, and
updates the tests to account for breakage.
2016-10-11 23:32:12 +00:00
EvilSpirit df83ee4c8f Factor out Style::Stroke. 2016-10-11 23:32:05 +00:00
Evil-Spirit 1108a6f37d Use Canvas::Stroke, not Canvas::Fill, for drawing a point.
Our points are more like fat lines than actual quads, in that they
are scale-invariant.
2016-10-11 23:32:05 +00:00
whitequark e80a3a0a71 Fix a buffer overrun in ssprintf. 2016-10-11 23:32:05 +00:00
Drew Gates ffa104602c Fix spelling error. 2016-10-11 16:47:23 +00:00
EvilSpirit f4e85127d6 Wavefront OBJ: export mesh color as well. 2016-10-11 14:54:19 +00:00
whitequark aa958504af GTK: use 3DConnexion button 0 instead of SI_APP_FIT_BUTTON.
The libspnav library doesn't even define SI_APP_FIT_BUTTON, which
appears to be Windows-specific functionality, perhaps a physical
button remapped with some logic. Just use 0 instead, since that
seems always safe.
2016-10-11 13:56:41 +00:00
whitequark b10e621fce Rephrase error messages that say "select a workplane".
This is confusing, as merely selecting one (and not activating it)
is not enough to satisfy any of the conditions leading to these
errors.
2016-10-11 13:46:05 +00:00
EvilSpirit 456c987218 Use transparent white fill color for drawing pixmaps, not black.
Textures can interact with selected color. This commit makes it
a no-op.
2016-10-11 10:53:57 +00:00
whitequark 66ed417d45 Fix a handle leak in TtfFontList::PlotString. 2016-10-10 21:16:22 +00:00
whitequark 476860acbb Normalize the string returned by Extension() to lowercase.
This would otherwise break code that branches on the extension,
such as that after 06a188cc.
2016-10-10 20:34:11 +00:00
whitequark 2371068d01 Don't regenerate the entire sketch in AddRequest().
This is unnecessary and leads to huge slowdowns on large sketches.
E.g. this speeds up import of a certain large DXF from ~60s to ~3s.
2016-10-10 20:33:02 +00:00
whitequark 0e66eafe5a OS X: correctly parse output of otool -D.
In the past this relied on otool -XD not printing the name of
the library itself, only the install name, but that doesn't work
anymore as of 10.12.
2016-10-10 23:31:15 +04:00
whitequark 3ff236c494 Mark group dirty when clicking "allow redundant constraints" link.
Otherwise, the now-valid constraint will not become satisfied.
2016-10-10 17:44:01 +00:00
whitequark 9bcba4b92c Fix incorrect rendering of XYZ axes in the bottom left corner. 2016-10-10 13:31:29 +00:00
whitequark a8e723381c Replace convenience #defines with const auto references.
These are nicer as they are scoped, and so it's clear where they
can be used.
2016-10-10 12:34:10 +00:00
whitequark f5a37ae2fd OS X: fix out-of-bounds TW.META access.
For some reason OS X can post pointer events far outside the window
rect, so be defensive here.
2016-10-10 12:25:10 +00:00
whitequark 21a4305ee1 Add "Zoom to Fit" to context menu. 2016-10-09 22:26:36 +00:00
whitequark 2f64f18095 Add "Select All" to context menu for no selection. 2016-10-09 22:26:25 +00:00
whitequark 2f4c6a6b0e Add "Toggle Construction" to context menu. 2016-10-09 22:13:01 +00:00
whitequark da2d035200 Remove exact numeric values from ContextCommand.
They carry no meaning, except for FIRST_STYLE.
2016-10-09 22:08:22 +00:00
whitequark c43a1988ae Win32: add proper Unicode support to message boxes.
Before this commit, for every non-ASCII character, a replacement
character was also printed.
2016-10-09 21:54:21 +00:00
whitequark fbd89a7e30 Update 819c4c5 for Wine compatibility.
For some reason glGetString(GL_VERSION) can return NULL at least
once even after we've started rendering.
2016-10-09 21:27:30 +00:00
whitequark 819c4c5742 GL1: work around lack of NPOT textures in Windows OpenGL renderer.
OpenGL 1.1 permits implementations to reject non-power-of-2 sized
textures. In practice this only affects the default Windows OpenGL
implementation, i.e. with no vendor drivers installed. This is still
important in case the application runs in a VM.
2016-10-09 20:24:49 +00:00
whitequark d12bf047b4 Update 58db06d8 to not even try to use std::fstream with Unicode paths.
Unfortunately there is no portable way to open an Unicode path with
std::fstream. On *nix, it is enough to call the const char*
constructor. On MSVC, it is enough to call a nonstandard
const wchar_t* constructor. However, on MinGW, there is no way at all
to construct an std::fstream with a wide path, not even using
undocumented APIs. (There used to be a const wchar_t* overload added
back in libstdc++ 4.7, but it got removed for a reason that I was not
able to find out.)
2016-10-09 20:00:02 +00:00
whitequark fb87431ba5 Fix a numeric conversion warning. 2016-10-09 15:26:05 +00:00
whitequark 58db06d845 DXF: update to use Unicode-aware file open routines on Windows. 2016-10-09 15:19:36 +00:00
whitequark fd54e5ac27 Make translate/rotate groups inherit the "suppress solid model" option. 2016-10-09 13:27:43 +00:00
whitequark 06a188cc62 GTK: show files with uppercase extensions in file open dialog.
The Windows dialog does that automatically, but the GTK one doesn't.
So this is useful for Windows interop.
2016-10-09 12:39:48 +00:00
whitequark e7edc39b34 Alias the "=" key to "+" key. 2016-10-09 10:57:25 +00:00
whitequark ffd9c6241a Fix a crash when adding a symmetric constraint on two points.
The crash was introduced in e2e91672; I have not noticed that some
of the code relies on past-the-size entities in GW.GS being empty.
2016-08-28 16:50:36 +00:00
whitequark b9d375652c Recognize .ngc as a valid G-Code export extension. 2016-08-25 02:57:29 +00:00
whitequark a1e18ae4a6 GlOffscreen: create color/depth renderbuffers separately.
This fixes a strange problem where GTK 2 (but not GTK 3) with NVidia
drivers would not have a depth buffer, but only during exporting
PNGs, despite the fact that normal rendering path and PNG rendering
path come through the same offscreen rendering code.
2016-08-21 19:58:45 +00:00
whitequark 991909d794 Show pt-ln distance projected onto workplane when one is active.
This avoids a pitfall where a point and a line are selected that are
not in the current workplane, but since the view is parallel to
the workplane, that's not visible, and incorrect measurement results.
2016-08-14 01:49:33 +00:00
whitequark f998293760 Allow displaying outlines without any other edges.
As usual, what's displayed is what's exported.
2016-08-14 01:00:10 +00:00
whitequark 4c30c09792 Correctly draw vector text for constraints free in 3d. 2016-08-13 10:51:14 +00:00
whitequark efd358d734 Unbreak PNG export.
Before this commit, on Win32 the toolbar was visible, and
the framebuffer was flipped, whereas on other platforms just a black
image was exported.
2016-08-13 09:55:37 +00:00
whitequark 6e860fb148 Make "Show/hide hidden lines" a tri-state button instead.
The states are:
  * Draw all lines (on top of shaded mesh).
  * Draw occluded (by shaded mesh) lines as stippled.
  * Do not draw occluded (by shaded mesh) lines.

As usual, the export output follows the screen output.
2016-08-13 09:44:08 +00:00
whitequark 8ce2922902 Refactor text window buttons to allow for more custom behavior. 2016-08-13 07:30:17 +00:00
whitequark e2e9167210 Get rid of the MAX_SELECTED restriction in GroupSelection(). 2016-08-13 05:20:43 +00:00
EvilSpirit e381c70842 DXF export: always declare layers before using them.
Before this commit, the #s001-active-grp layer was not declared,
and this broke some external software, such as Inkscape.
See https://bugs.launchpad.net/inkscape/+bug/1472429 for details.
2016-08-13 04:27:41 +00:00
whitequark 35a20ae260 GTK: fix an uninitialized variable. 2016-08-13 03:39:59 +00:00
EvilSpirit 065a0a8b00 Forcibly show the current group once we start a drawing operation. 2016-08-13 03:37:27 +00:00
EvilSpirit b2ab15c2e1 Do not clear selection during operations that don't need it.
Specifically, during "Align View onto Workplane" when we are locked
in workplane (in which case it always aligns onto that workplane).
2016-08-13 03:30:27 +00:00
whitequark 8bf55b3c62 Fix multiple memory leaks found with LeakSanitizer. 2016-08-07 19:33:42 +00:00
whitequark e462387fca Add tests to cover 95.3% of constrainteq.cpp branches. 2016-08-07 17:33:27 +00:00
whitequark 4b4944264b Align constraint lines to pixel grid.
This ensures that constraints always look crisp, no matter the camera
position.
2016-08-07 17:33:27 +00:00
whitequark f2633e4a57 Also consider constraints when zooming to fit.
Before this commit, when working on convex sketches, zooming to fit
was guaranteed to clip most or even all constraints, making it quite
useless.
2016-08-01 14:03:16 +00:00
whitequark 8e7d2eaa84 Implement "view → set to full scale" text window command. 2016-08-01 14:03:16 +00:00
whitequark ff23a4a471 Implement Analyze → Measure Perimeter. 2016-08-01 14:02:39 +00:00
whitequark 9a1ceaa5c8 Unbreak TTF metrics.
In 2.0, the distance between the points in the TTF request specified
cap height. In 2.1, that was accidentally changed to some arbitrary
value near cap height instead, due to a 72pt factor mess-up.
This commit restores the old behavior.
2016-08-01 12:31:00 +00:00
whitequark fd9ee94437 Add basic test coverage for curve sketching tools. 2016-08-01 11:31:38 +00:00
whitequark 4f49a8a9d4 Eliminate several memory leaks.
All leaks found with valgrind while running the test suite.
This commit also clears the Cairo cache to improve SNR of Valgrind
output.
2016-08-01 05:39:18 +00:00
whitequark 42d3ec9917 CMake: finish Clang sanitizer support.
This makes ENABLE_SANITIZERS a proper cached variable, removes some
spurious failures and configures asan/ubsan to die on an error.
2016-08-01 05:39:18 +00:00
whitequark 2fdbabc13c Add statement/condition coverage measurement for the test suite.
We're using gcov+lcov, since these tools appear to be the only
usable ones that use the SC/CC metric; and measuring just the line
coverage would be practically criminal negligence.

gcov only works with GCC and Clang, and MSVC's own coverage
measurement tools are not up to the task; so MSVC is out of luck.
2016-08-01 02:19:06 +00:00
whitequark 5e63d8301e Add a simple harness for automated, headless testing.
This commit alters the build system substantially; it adds another
platform, `headless`, that provides stubs in place of all GUI
functions, and provides a library `solvespace_headless` alongside
the main executable. To cut down build times, only the few files
that have #if defined(HEADLESS) are built twice for the executable
and the library; the rest is grouped into a new `solvespace_cad`
library. It is not usable on its own and just serves for grouping.

This commit also gates the tests behind a -DENABLE_TESTS=ON CMake
option, ON by default (but suggested as OFF in the README so that
people don't ever have to install cairo to build the executable.)

The tests introduced in this commit are (so far) rudimentary,
although functional, and they serve as a stepping point towards
introducing coverage analysis.
2016-08-01 00:48:37 +00:00
whitequark 977a0b8e6d Replace the last use of exceptions (in Expr) with setjmp/longjmp.
Without -fno-exceptions, the branch coverage information is
practically useless, as every call becomes a branch.

The functionality of Expr is retained as-is, although SjLj error
handling is a maintenance nightmare. However, the entire parser
probably should be eventually replaced, so for now it is not
a great concern.
2016-08-01 00:48:37 +00:00
whitequark 65e2cccde0 Add a Cairo rendering backend.
This backend will be used for reproducible offscreen rendering
in integration tests.
2016-08-01 00:48:37 +00:00
whitequark 6963c7e25b Add Cairo (and, transitively, Pixman) dependencies. 2016-08-01 00:48:37 +00:00
whitequark 8960ee365a Add a new renderer that prepares geometry for 2d backends.
SurfaceRenderer is a new renderer implementing the Canvas interface
running entirely on the CPU; it projects strokes and triangles
in the exact same way as OpenGL would, and it can be used for
rendering into raster or vector 2d surfaces.
2016-08-01 00:48:37 +00:00
whitequark 8af3a933cf Implement SPolygon::TriangulateInto. 2016-08-01 00:48:37 +00:00
whitequark 14cf0e09df Win32: emit dbp() output to stderr as well in Debug builds. 2016-08-01 00:48:37 +00:00
whitequark d0e32849b2 Fix a typo in Group::DrawFilledPaths. 2016-07-31 11:58:54 +00:00
whitequark 50b2b8adfd Unbreak background image display.
Before this commit, background image was drawn with alpha=0, which
caused it to be not drawn at all. This was an error introduced
during rebasing.
2016-07-31 11:57:46 +00:00
whitequark 613aa8c579 Reimplement 6846010 correctly.
The bug was actually not in ReadPng*, but in WritePng.
2016-07-31 11:57:17 +00:00
whitequark 803665404e Add support for BGR formats to Pixmap, and RGB conversion.
The Cairo image surface backend uses the BGR format for "RGB24"
for some reason, and we need to handle that.
2016-07-25 11:00:07 +00:00
whitequark 6d5d88f01e Fix off-by-one bug in Pixmap::WritePng. 2016-07-25 10:58:25 +00:00
whitequark 6846010416 Fix a flip bug in ReadPngIntoPixmap.
The only user of that was the background image, and it was flipped
again when it was rendered, so the two bugs masked out each other.
This adds a `bool flip` to ReadPng and FromPng, since that's cheap
to do when writing the PNG file, expensive on the pixel arrays,
and sometimes inconvenient in OpenGL due to offsets.
2016-07-25 10:58:03 +00:00
whitequark 0c90cd799d Align normals and workplanes to pixel grid.
They look much sharper and nicer this way, and more similar to 2.0.
2016-07-25 10:56:36 +00:00
whitequark 6607a48357 CMake: refactor inclusion of external libraries.
This commit makes common external packages always be included through
find_package to eliminate differences in variables set, wraps
find_package for vendored libraries on Windows to factor out common
code, and removes miscellaneous useless code elsewhere in dependency
handling.

This also fixes a problem where pkg-config would pick up `build`
libraries instead of `host` when cross-compiling.
2016-07-25 04:22:02 +00:00
whitequark 7265121b24 Refactor GlOffscreen; remove the GLEW dependency.
It was never really needed, since both Linux and OS X, where
GlOffscreen is used, guarantee that the API we need is present,
on all OS versions we're interested in.

Also, reorganize GlOffscreen consistently with the rest of our
codebase, and don't use RAII for OpenGL resource management because
of its requirement for an active context.
2016-07-25 04:21:55 +00:00
EvilSpirit 7f411d1593 Unify displayEdges and displayOutlines.
This has the following benefits:
  * Less geometry to generate; we can do both in one pass;
  * Less geometry to draw;
  * Eliminate overdraw of outlines on top of emphasized edges;
  * In future, being able to seamlessly stitch stippled lines.

The contour edges are now also drawn before emphasized edges;
this makes intersections of contour and emphasized edges look better
as the thinner emphasized edge doesn't clobber the depth buffer.
2016-07-23 22:41:16 +00:00
whitequark e7c8c1c8f2 Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
  * It is now possible to port SolveSpace to a later version of
    OpenGL, such as OpenGLES 2, so that it runs on platforms that
    only have that OpenGL version;
  * The majority of geometry is now rendered without references to
    the camera in C++ code, so a renderer can now submit it to
    the video card once and re-rasterize with a different projection
    matrix every time the projection is changed, avoiding expensive
    reuploads;
  * The DOGD (draw or get distance) interface is now
    a straightforward Canvas implementation;
  * There are no more direct references to SS.GW.(projection)
    in sketch rendering code, which allows rendering to multiple
    viewports;
  * There are no more unnecessary framebuffer flips on CPU on Cocoa
    and GTK;
  * The platform-dependent GL code is now confined to rendergl1.cpp.
  * The Microsoft and Apple headers required by it that are prone to
    identifier conflicts are no longer included globally;
  * The rendergl1.cpp implementation can now be omitted from
    compilation to run SolveSpace headless or with a different
    OpenGL version.

Note these implementation details of Canvas:
  * GetCamera currently always returns a reference to the field
    `Camera camera;`. This is so that a future renderer that caches
    geometry in the video memory can define it as asserting, which
    would provide assurance against code that could accidentally
    put something projection-dependent in the cache;
  * Line and triangle rendering is specified through a level of
    indirection, hStroke and hFill. This is so that a future renderer
    that batches geometry could cheaply group identical styles.
  * DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
    This is so that a future renderer into an output format that
    uses 2d transforms (e.g. SVG) could easily derive those.

Some additional internal changes were required to enable this:
  * Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
    This is so that the renderer could cache uploaded textures
    between API calls, which requires it to capture a (weak)
    reference.
  * The PlatformPathEqual function was properly extracted into
    platform-specific code. This is so that the <windows.h> header
    could be included only where needed (in platform/w32* as well
    as rendergl1.cpp).
  * The SBsp{2,3}::DebugDraw functions were removed. They can be
    rewritten using the Canvas API if they are ever needed.

While no visual changes were originally intended, some minor fixes
happened anyway:
  * The "emphasis" yellow line from top-left corner is now correctly
    rendered much wider.
  * The marquee rectangle is now pixel grid aligned.
  * The hidden entities now do not clobber the depth buffer, removing
    some minor artifacts.
  * The workplane "tab" now scales with the font used to render
    the workplane name.
  * The workplane name font is now taken from the normals style.
  * Workplane and constraint line stipple is insignificantly
    different. This is so that it can reuse the existing stipple
    codepaths; rendering of workplanes and constraints predates
    those.

Some debug functionality was added:
  * In graphics window, an fps counter that becomes red when
    rendering under 60fps is drawn.
2016-07-23 22:31:18 +00:00
whitequark bd2da7fe3f GTK3: fix color chooser.
On GTK2, even with a modal grab, mouse button events go through
to the text window. On GTK3 this is not the case.
2016-07-21 08:49:23 +00:00
whitequark 89da072427 GTK3: fix a broken type cast introduced in 66746d1. 2016-07-21 08:48:05 +00:00
whitequark b0d37c1e78 Replace platform-specific GetMilliseconds using std::chrono. 2016-07-21 06:07:46 +00:00
EvilSpirit a4a121694c Reimplement commit 0b999f4 correctly. 2016-07-21 05:45:12 +00:00
EvilSpirit 6e17780e01 Draw projection lines for point-line distance constraints.
This is only visible when the point and line lie within the workplane,
but the constraint label does not.
2016-07-20 07:52:05 +00:00
whitequark ad2371cfae Unix: compatibility with platforms where backtrace() is not in libc.
Also, don't depend on backtrace() when built as libslvs; it is not
the responsbility of the library to use it.
2016-07-19 15:40:52 +00:00
whitequark 8ccc9fe56c When snapping constraints to grid, snap the reference point. 2016-07-19 14:29:25 +00:00
whitequark 8747745a14 Multiply constraint values by scale when pasting with transformation. 2016-07-19 12:12:01 +00:00
whitequark 33e292a6bc Unix: prioritize local resource directory over installed one. 2016-07-19 09:31:58 +00:00
whitequark cbf84a9d2b Unix: don't use argv[0] when determining resource directory.
This makes invocations like this work:
  ~/solvespace/build$ src/solvespace
2016-07-19 09:30:34 +00:00
EvilSpirit 25575b14c7 Allow indexed access to triangle vertices and normals. 2016-06-30 16:40:40 +00:00
EvilSpirit 0b999f4165 Improved outline detection condition.
Before this commit, circles parallel to the camera plane caused
some edges to be randomly marked as outlines.
2016-06-30 16:39:42 +00:00
EvilSpirit 737ff51893 Skip edges with equal L/R normals when calculating outlines. 2016-06-30 16:39:42 +00:00
EvilSpirit 5a2eb9fb50 Allow changing stipple width for default styles.
We already allow changing stipple style, so it makes sense to do
the same for width.
2016-06-30 16:39:27 +00:00
EvilSpirit d0a0a0f8cf Use the same line width for hidden and shown edges, by default. 2016-06-30 16:21:55 +00:00
EvilSpirit 32a2a4dbd9 Fix the "Show degrees of freedom" command.
Before this commit, it never highlighted anything at all.
It was broken when chord tolerance calculation was overhauled.
2016-06-29 16:58:47 +00:00
whitequark da1fc3fd70 DXF: export freehand and zigzag lines as continuous, with a message.
Previously, this resulted in a crash even with no such lines present.
2016-06-29 16:47:23 +00:00
whitequark 21179c2e30 GTK: make Space Navigator actually work.
Before this commit, no events would actually be received.
2016-06-28 09:49:23 +00:00
whitequark ced5b78420 Don't crash when hovering one of the predefined workplanes. 2016-06-23 12:10:47 +00:00
whitequark a4e487d298 Don't crash when changing the autosave interval. 2016-06-23 11:56:13 +00:00
whitequark 51f4f27b2b Do not remove autosave after successfully opening file.
If SolveSpace crashes after the open, or hangs and is forcibly
killed, data would be lost. (I lost my data.) Instead, remove
autosave only in two cases: right after a successful save, or right
after a save is declined. This should be completely safe.
2016-06-23 03:00:50 +00:00
whitequark 85cd44df3c Show "Paste" context menu item even when only constraints are copied. 2016-06-20 13:47:14 +00:00
Thomas Buck fb62e0494b OS X: add 3Dconnexion device support. 2016-06-19 19:25:08 +00:00
whitequark 251948bdbd GTK: don't crash if argv[0]=="solvespace". 2016-06-16 03:05:45 +00:00
whitequark 1dba594949 OS X: sort out window visibility and focus. 2016-06-13 02:08:42 +04:00
whitequark afafa5ec2e Three.js: allow to configure projRight/projUp.
Also, use a more appealing isometric projection if none specified,
instead of orthographic.

Also, use the scale, offset and projection from the viewport at
the time of export.
2016-06-11 23:13:59 +00:00
whitequark de6be52293 Fix disabling of autoconstrainter via Ctrl. 2016-06-11 23:13:59 +00:00
whitequark 215b8e4537 Unbreak importing files in the same directory as current file.
This commit fixes a bug introduced in commit 0d7aa0a1.
2016-06-06 17:48:45 +00:00
whitequark 122920d3ee Cocoa: allow dismissing Message/Error NSAlerts using Escape key. 2016-06-03 00:07:30 +00:00
Twisted Pair in my Hair 66746d151f GTK: make some dubious implicit type conversions explicit. 2016-05-31 15:40:27 +00:00
whitequark 682bfa2732 Add STL begin()/end() functions to List and IdList.
This will allow us to use it in the C++11 foreach loop, as well
as simplify use of STL <algorithms>.
2016-05-29 14:14:38 +00:00
whitequark a4e7dea9e3 Remove "generating group 1/10" status message during generation.
It's broken. It expects a valid OpenGL context during generation
that immediately pushes changes to the screen. This is never true
on non-Windows as offscreen rendering is used, and also incompatible
with OpenGL core profile.

Further, right now it displays junk on Windows as well due to some
issue with the bitmap font texture loading.

We will restore it later, in a saner form.
2016-05-27 11:41:17 +00:00
whitequark faa84c61cf Add SHORT_DASH stipple pattern. 2016-05-27 11:41:17 +00:00
EvilSpirit 73d82a6347 Load actual factory default, not saved style, when requested. 2016-05-26 15:49:46 +00:00
EvilSpirit 5791310bb1 Annotate constants passed as boolean function arguments.
This is to ensure that:
  * it is clear, when looking at the point of usage, what is
    the purpose of "true" or "false";
  * when refactoring, a simple search will bring up any places that
    need to be changed.

Also, argument names were synchronized between declaration and
implementation.

As an exception, these are not annotated:
  * Printf(/*halfLine=*/), to avoid pointless churn.
2016-05-26 12:43:52 +00:00
whitequark 8aab0160d3 Refactor EntReqTable to not special-case last row.
Simplify it a bit while we're at it.
2016-05-26 12:43:52 +00:00
whitequark 3cd9c28ebc Refactor Toolbar to not special-case last row. 2016-05-26 12:43:52 +00:00
whitequark 1249f8496e Enable exhaustive switch coverage warnings as an error, and use them.
Specifically, this enables -Wswitch=error on GCC/Clang and its MSVC
equivalent; the exact way it is handled varies slightly, but what
they all have in common is that in a switch statement over an
enumeration, any enumerand that is not explicitly (via case:) or
implicitly (via default:) handled in the switch triggers an error.

Moreover, we also change the switch statements in three ways:

  * Switch statements that ought to be extended every time a new
    enumerand is added (e.g. Entity::DrawOrGetDistance(), are changed
    to explicitly list every single enumerand, and not have a
    default: branch.

    Note that the assertions are kept because it is legal for
    a enumeration to have a value unlike any of its defined
    enumerands, and we can e.g. read garbage from a file, or
    an uninitialized variable. This requires some rearranging if
    a default: branch is undesired.

  * Switch statements that ought to only ever see a few select
    enumerands, are changed to always assert in the default: branch.

  * Switch statements that do something meaningful for a few
    enumerands, and ignore everything else, are changed to do nothing
    in a default: branch, under the assumption that changing them
    every time an enumerand is added or removed would just result
    in noise and catch no bugs.

This commit also removes the {Request,Entity,Constraint}::UNKNOWN and
Entity::DATUM_POINT enumerands, as those were just fancy names for
zeroes. They mess up switch exhaustiveness checks and most of the time
were not the best way to implement what they did anyway.
2016-05-26 12:43:52 +00:00
EvilSpirit 4128a5d8d4 Convert GraphicsWindow::pending.operation to `enum class`.
This follows the previous commit. Unlike it, though, a small change
to control flow is made to separate the command and pending operation
enumerations.
2016-05-25 07:58:29 +00:00
EvilSpirit f33ddc94fb Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:

  class Foo {
    enum { X = 1, Y = 2 };
    int kind;
  }
  ... foo.kind = Foo::X; ...

and convert it to this:

  class Foo {
    enum class Kind : uint32_t { X = 1, Y = 2 };
    Kind kind;
  }
  ... foo.kind = Foo::Kind::X;

(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)

The benefits are as follows:
  * The type of the field gives a clear indication of intent, both
    to humans and tools (such as binding generators).
  * The compiler is able to automatically warn when a switch is not
    exhaustive; but this is currently suppressed by the
      default: ssassert(false, ...)
    idiom.
  * Integers and plain enums are weakly type checked: they implicitly
    convert into each other. This can hide bugs where type conversion
    is performed but not intended. Enum classes are strongly type
    checked.
  * Plain enums pollute parent namespaces; enum classes do not.
    Almost every defined enum we have already has a kind of ad-hoc
    namespacing via `NAMESPACE_`, which is now explicit.
  * Plain enums do not have a well-defined ABI size, which is
    important for bindings. Enum classes can have it, if specified.
    We specify the base type for all enums as uint32_t, which is
    a safe choice and allows us to not change the numeric values
    of any variants.

This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-25 07:17:14 +00:00
whitequark 3103728c15 Cocoa: fix warnings. 2016-05-25 07:17:13 +00:00
whitequark 7bda30aca4 Refactor SS.bgImage to use Pixmap. 2016-05-25 03:22:54 +00:00
whitequark 274233fe08 Eliminate Constraint::dogd.refp.
While we're at it, let's also emphasize both parts of a two-part
constraint to make it easier to find.
2016-05-25 03:22:54 +00:00
whitequark 23ff9fa8d1 Eliminate Entity::dogd.refp. 2016-05-25 03:22:54 +00:00
whitequark 8372154384 Remove unused includingConstruction argument of Entity::GenerateEdges. 2016-05-25 03:22:54 +00:00
whitequark 68c4d6f704 Use entity bounding boxes in SelectByMarquee.
Also, fix an insidious typo in BBox::GetOrigin that made BBox::Overlap
return nonsensical results.
2016-05-25 03:22:54 +00:00
whitequark e2916e3e4a Factor in SOutlineList::FillOutlineTags. 2016-05-25 03:22:54 +00:00
whitequark 20d87d93c5 Add const qualifiers to functions where trivially possible.
This will allow us in future to accept `const T &` anywhere it's
necessary to reduce the amount of copying.

This commit is quite conservative: it does not attempt very hard to
refactor code that performs incidental mutation. In particular
dogd and caches are not marked with the `mutable` keyword.
dogd will be eliminated later, opening up more opportunities to
add const qualifiers.

This commit also doesn't introduce any uses of the newly added const
qualifers. This will be done later.
2016-05-25 03:22:54 +00:00
whitequark 91e18eed73 GTK: clip any editors instead of resizing GraphicsWindow.
Such resizing may well get us past OpenGL's maximum texture size
and break rendering.
2016-05-25 03:22:54 +00:00
whitequark ddc0dd7194 Reimplement e129755d properly.
Before this commit, quitting through menu would bring up the dialog
twice when declining to save the file.
2016-05-25 03:22:54 +00:00
EvilSpirit def73ec118 Refactor Point2d::DistanceToLine. 2016-05-20 15:02:38 +00:00
whitequark bb0eef2b96 Allow copying and pasting constraints. 2016-05-20 14:19:50 +00:00
EvilSpirit 457ff78849 DXF, DWG: allow undoing an import. 2016-05-20 14:04:21 +00:00
EvilSpirit bbca4cc224 Rewrite declarations of form f(void) as f().
In C++ there is no difference and newly added functions are all
declared as f(), so this brings back consistency.
2016-05-20 12:43:20 +00:00
whitequark ad4a204edf Replace all oops() checks with ssassert()s.
This includes explanation and context for non-obvious cases and
shortens debug cycles when just-in-time debugging is not available
(like on Linux) by immediately printing description of the assert
as well as symbolized backtrace.
2016-05-20 12:38:30 +00:00
whitequark 4415f5bb91 Implement ssassert(), a replacement for oops(). 2016-05-20 12:38:29 +00:00
whitequark 1b52c46b81 Remove some dead code. 2016-05-18 23:00:34 +00:00
whitequark ab418b827e Use the `override` C++ keyword everywhere.
This helps to ensure that a base class that changes underneath us
would not leave any overridden functions hanging.

This already highlighted some questionable use of GTKMM's API,
which were also fixed in this commit.
2016-05-18 18:42:33 +00:00
whitequark 193477e2da GTK: set application icon. 2016-05-18 17:27:37 +00:00
whitequark 63398ef3ba Cocoa: fix massive memory leak. 2016-05-18 18:20:43 +04:00
whitequark 45514849e2 GTK: intercept the Tab key and run MNU_SHOW_TEXT_WND. 2016-05-18 12:15:17 +00:00
whitequark b55e096fef Rename "Browser" to "Property Browser".
Also, rename confusing "Show Text Window" menu item.
2016-05-18 12:13:59 +00:00
whitequark 432e7680a4 Three.js: put all resources into res/threejs/ and embed on export.
This means that our exported viewer is independent of internet
connection as well as any CDNs that will eventually die.
2016-05-18 11:44:32 +00:00
whitequark fbc5bfc27f Enable -Wfloat-conversion on Clang.
This is a high-SNR warning that's enabled by default on MSVC and
it has highlighted some bugs in glhelper.cpp (that are also fixed
in this commit).

Unfortunately GCC does not have an equivalent for that warning,
and -Wconversion is very noisy.
2016-05-18 11:24:24 +00:00
whitequark 69b8a3b3b3 In Pixmap and BitmapFont, use std::vector instead of std::unique_ptr.
MSVC 2013 keeps having aggravating bugs where its unique_ptr
implementation wants to use deleted functions.

In this case the worst that could happen is one copy per entity
once during initialization (which should in principle be elided
anyway because a return value is a prvalue... no idea if MSVC does
actually do that).
2016-05-18 11:24:24 +00:00
whitequark fc79642788 Move vector font to res/fonts/; remove lff2c.
This commit integrates the vector font in the resource system, so
that cross-compilation would be easier and a custom font could be
used without recompilation.

The font handling code was carefully written to lazily load glyphs;
as possible; in practice this means that startup is less than 15ms
slower after this commit, most of it spent in inflate().

This also reduces executable size and makes compilation of
glhelper.cpp much faster.
2016-05-18 11:24:24 +00:00
whitequark 645c2d90ac Move bitmap font to res/fonts/; remove unifont2c.
This commit integrates the bitmap font in the resource system, so
that cross-compilation would be easier.

The font handling code was carefully written to do glyph parsing
lazily; in practice this means that after this commit, startup
is less than 25ms slower, most of it spent in inflate().

This should also result in faster rendering, since there is no
rampant plane switching anymore; instead, all characters that are
actually used are stashed into same one texture.
2016-05-18 11:24:24 +00:00
whitequark a525f03371 Move icons to res/icons/; remove png2c.
This commit integrates icons in the resource system so that they
can be loaded (or reloaded, without restarting) in @2x mode, which
will be added in a future commit. png2c is no longer necessary.

png2c used to perform the following transformation:
  if(r + g + b < 11) r = g = b = 11;

This is now achieved by switching the icons to RGBA mode and adding
alpha channel with the following imagemagick invocation, which is
equivalent to the transformation above:
  for i in *.png; do
    convert -fuzz 4% -channel rgba -matte \
            -fill "rgba(255,255,255,0)" -opaque black \
            $i $i
  done

The Debian package solvespace now includes /usr/share/solvespace;
this should be split out into solvespace-data later.
2016-05-18 11:24:24 +00:00
whitequark fa546af28f Move all platform-specific code to src/platform/.
Without resources, it makes no sense anymore to keep these in
separate subdirectories: unixutil* is shared between Cocoa
and GTK ports, and gloffscreen* should be shared between all ports
(but it's still platform-specific).
2016-05-18 11:24:24 +00:00
whitequark 4c01461316 OS X: move resources to res/. 2016-05-18 11:24:23 +00:00
whitequark e36ee32def freedesktop: move resources to res/. 2016-05-18 11:24:23 +00:00
whitequark a6b6d98a94 Win32: move resources to res/. 2016-05-18 11:24:23 +00:00
whitequark f4c01f670c Implement a resource system.
Currently, icons, fonts, etc are converted to C structures at compile
time and are hardcoded to the binary. This presents several problems:

  * Cross-compilation is complicated. Right now, it is necessary
    to be able to run executables for the target platform; this
    happens to work with wine-binfmt installed, but is rather ugly.

  * Icons can only have one resolution. On OS X, modern software is
    expected to take advantage of high-DPI ("Retina") screens and
    use so-called @2x assets when ran in high-DPI mode.

  * Localization is complicated. Win32 and OS X provide built-in
    support for loading the resource appropriate for the user's
    locale.

  * Embedding strings can only be done as raw strings, using C++'s
    R"(...)" literals. This precludes embedding sizable strings,
    e.g. JavaScript libraries as used in Three.js export, and makes
    git history less useful. Not embedding the libraries means we
    have to rely on external CDNs, which requires an Internet
    connection and adds a glaring point of failure.

  * Linux distribution guidelines are violated. All architecture-
    independent data, especially large data such as fonts, is
    expected to be in /usr/share, not in the binary.

  * Customization is impossible without recompilation. Minor
    modifications like adding a few missing vector font characters
    or adjusting localization require a complete development
    environment, which is unreasonable to expect from users of
    a mechanical CAD.

As such, this commit adds a resource system that bundles (and
sometimes builds) resources with the executable. Where they go is
platform-dependent:

  * on Win32: into resources of the executable, which allows us to
    keep distributing one file;
  * on OS X: into the app bundle;
  * on other *nix: into /usr/share/solvespace/ or ../res/ (relative
    to the executable path), the latter allowing us to run freshly
    built executables without installation.

It also subsides the platform-specific resources that are in src/.

The resource system is not yet used for anything; this will be added
in later commits.
2016-05-18 11:24:23 +00:00
whitequark b2cdbe8c8d Properly fix workplane name overlapping workplane border.
A previous attempt to fix this was done in 0128b8679. However, it was
not rigorous. The added offset was dependent on font size and it
introduced an error into edit control positioning. Further, it is
irrelevant to non-workplanes.

After this commit, the workplane drawing code adds a fixed offset
instead. Also, the "tab" is enlarged to not overlap with #XY etc.
2016-05-18 11:24:23 +00:00
whitequark 0d7aa0a1a3 When opening imported files, first try relative path.
Without this, if we have e.g.:
  * a/x.slvs
  * a/y.slvs importing a/x.slvs
and copy a/ to b/, then loading b/y.slvs would load a/x.slvs, which
is rather surprising.
2016-05-17 14:44:33 +00:00
EvilSpirit ae60187322 DXF: export the right supplementary angle.
Before this commit, e.g. a 120° angle could be exported as its
supplementary 60° angle but it would still say 120° in the label.

After this commit, the right angle is selected in DXF-based software.
Similarly, it roundtrips through SolveSpace correctly.
2016-05-17 12:34:35 +00:00
EvilSpirit 11919bf0c1 DXF: import "actual measurement" for dimensions. 2016-05-17 12:34:35 +00:00
EvilSpirit 63abcc379d DXF: export "actual measurement" for dimensions.
The "actual measurement" DXF field contains the size of the dimension
as scaled on the drawing, as opposed to the size as written on
the label.
2016-05-17 12:34:35 +00:00
EvilSpirit 7b8e8b0b41 DXF: export color as indexed, not RGB.
The version of AutoCAD we advertise is unable to read RGB color, so
software attempting to be compatible with it ignores color attributes.
2016-05-17 11:47:49 +00:00
whitequark e129755d66 Offer to save file when closing if it is unsaved. 2016-05-11 07:43:04 +00:00
whitequark 005ff7e31b GTK: fix GTK3 build. 2016-05-10 13:10:41 +00:00
whitequark ab8fdcb273 GTK: don't set the "Keep above" hint on text window.
This hint is not recommended for direct use by applications, and for
a good reason: it's very annoying. Moreover, what we want is not
"keep above" but rather "keep on the same layer as graphics window",
which is already achieved by setting window type to "utility"
on GNOME and Unity WMs, and by setting the transient window hint
for the text window on KDE WM.
2016-05-10 01:21:36 +00:00
whitequark 4a8675c120 DXF: regenerate after importing.
Without this, some freshly imported entities appear with incorrect
styles.
2016-05-09 12:43:52 +00:00
whitequark 8f515f3b90 GTK: don't raise graphics window in HideTextEditControl().
This screws up window managers like fvwm, which don't respect
the ICCCM "Keep Above" flag. I don't remember why it's there and
it doesn't appear that removing it has any ill effect.
2016-05-08 00:02:21 +00:00
whitequark e969bc94ad Enable -Wall -Wextra -Wno-unused-parameter on GCC/Clang.
This is good practice and helps to catch bugs. Several changes
were made to accomodate the newly enabled warnings:
  * -Wunused-function:
    * in exposed/, static functions that were supposed to be inlined
      were explicitly marked as inline;
    * some actually unused functions were removed;
  * -Wsign-compare: explicit conversions were added, and in
    the future we should find a nicer way than aux* fields;
  * -Wmissing-field-initializers: added initializers;
  * -Wreorder: reordered properly;
  * -Wunused-but-set-variable: remove variable.

-Wunused-parameter was turned off as enabling it would result in
massive amount of churn in UI code. Despite that, we should enable
it at some point as it has a fairly high SNR otherwise.
2016-05-08 00:01:35 +00:00
whitequark ee30fa2b0d Work around an MSVC 2013 bug related to unique_ptr.
The following bug is tickled by calling emplace() on a map with
non-copyable but moveable values:
https://connect.microsoft.com/VisualStudio/feedbackdetail/view/960021

Fortunately, we don't actually need emplace() here as operator[]
will create values if they aren't there.
2016-05-07 22:36:41 +00:00
whitequark 12c9858d06 Only flip extrusion normal when transitioning between union and difference.
After commit a8465cbc8, extrusion normal would be adjusted when
switching between union and assembly groups, if ever implemented.
2016-05-07 06:36:30 +00:00
EvilSpirit a44a4665a8 In GenerateAll, accept explicitly permitted redundant sketches as OK.
Before this commit, they were considered unsolved and were re-solved
over and over unnecessarily.
2016-05-07 05:43:16 +00:00
whitequark febe0f5282 Rename the old "Import / Assemble" feature to "Link / Assemble".
This better reflects what it does and avoids clashes with the new
DXF import feature.
2016-05-07 05:27:54 +00:00
whitequark d05e9a938b DWG: implement import.
Before this commit, the file filter suggested that DWG was readable,
but it wasn't.

Also, report any failures while reading DWG and DXF files.
2016-05-07 05:17:23 +00:00
whitequark 7da5cfbaae Don't hold all existing system fonts open.
On Windows, this exhausts file descriptors and everything (e.g.
opening and saving files) breaks.
2016-05-07 04:20:06 +00:00
EvilSpirit a21a327a97 DXF: create certain constraints during import.
Specifically:
  * point-coincident, horizontal and vertical constraints (inferred);
  * point-point and point-line distance, angle, radius and diameter
    constraints (based on DXF dimensions).
2016-05-07 04:02:34 +00:00
EvilSpirit 70d84b30e8 DXF: implement import. 2016-05-07 04:02:34 +00:00
EvilSpirit a8465cbc8a Flip extrusion normal when switching between union and difference.
This is done because a meaningful union extrusion is almost never
a meaningful difference extrusion, and saves a bunch of common
manual work.

To avoid creating invalid sketches this isn't done when there are any
constraints.
2016-05-06 23:07:19 +00:00
whitequark affc88f342 Three.js: various control improvements.
Specifically:
  * touchscreen devices are now supported;
  * rotation is now more like what SolveSpace itself does.

The code is split in two parts because MSVC can't handle string
literals longer than 16Ki.
2016-05-06 17:42:01 +00:00
EvilSpirit e1f614101f Only generate split triangles when exporting if needed.
Before this commit, when exporting a vector file without the shaded
model shown, or similarly when using formats that we do not export
the mesh to, we still generate (and then discard) the mesh in paint
order. This is a waste of time.
2016-05-04 04:48:24 +00:00
EvilSpirit a75bf6e216 Fix incorrect condition ordering that causes a crash. 2016-05-04 04:34:03 +00:00
EvilSpirit f5d8b1dc6b Implement missing parts of 09f59ddb.
This caused no crashes, but some extrusions resulted in a wrong mesh.
2016-05-04 03:21:12 +00:00
whitequark ba4cb28251 Fix uninitialized variable access. 2016-05-04 03:21:12 +00:00
whitequark e61bac2797 Refactor file filters to not use preprocessor magic.
The immediate reason for refactoring this was that the GTK port broke
after 52af7256 since config.h is not included anymore, but it was
a fragile piece of code I will shed no tears for.

While we're at it, get rid of the mutable std::string &file to be
consistent with our conventions.
2016-05-04 03:21:12 +00:00
whitequark 52af725606 Only #include "config.h" when we need something from it.
config.h now includes the git hash and so, as long as it's included
in solvespace.h, any change of git HEAD will trigger a complete
recompilation, which makes bisecting especially annoying.

While we're at it, remove HAVE_STDINT_H from it, since we require
C++11 and all MSVC versions that include C++11 also include stdint.h.
2016-04-23 23:06:31 +00:00
whitequark 2fed0587ea Embed git commit hash in the "About" dialog.
Also, remove usage of __DATE__ and __TIME__ to make the build fully
deterministic. They are redundant once we have the commit hash,
anyway.
2016-04-23 22:53:21 +00:00
EvilSpirit 1c51205a11 DXF: reassemble piecewise linear fragments into polylines. 2016-04-23 19:39:39 +00:00
whitequark 04a79b4308 OS X: correctly make text window the key window.
This is a refactoring bug introduced in 23dc36d.
2016-04-23 19:39:39 +00:00
EvilSpirit dabd57847e MSVC: work around binary size explosion. 2016-04-23 19:39:39 +00:00
whitequark c17f1160dc Allow snapping constraint labels to grid.
This is pretty much the only way to get a sketch with tidily placed
dimensions.
2016-04-23 04:38:32 +00:00
whitequark 1142f85ff5 Fix edit control width calculation on GTK3.
Also, bring the GTK2 width calculation in line with the GTK3 one.
2016-04-23 04:38:32 +00:00
whitequark 6cb6a2cf27 Forcibly show text window on some context menu actions.
Specifically:
  * Group Info
  * Style Info
  * Assign to Style → Newly Created Custom Style...

These context actions are meaningless without viewing or manipulating
text window.
2016-04-23 04:38:32 +00:00
whitequark a61544ea9c Fix empty space at the end of the tooltips.
Also, bring MakeAcceleratorLabel to modernity.
2016-04-23 04:38:32 +00:00
EvilSpirit accd73fe02 Improve rendering of workplane stipple lines.
After this commit, a workplane perpendicular to the camera is
rendered with all dashes aligned, making it look more tidy.
2016-04-17 03:11:19 +00:00
whitequark efb9fa3d69 Actually display the "zero-length edge!" polygon error.
Before this commit, the initial state allCoplanar=false took
precedence over allNonZeroLen=false, since detecting a zero-length
edge short-circuits AssembleLoops.
2016-04-17 01:33:15 +00:00
whitequark b3df595769 Don't crash after right-clicking on derived entities. 2016-04-17 01:16:47 +00:00
EvilSpirit a4a353f01b Reverse arrows on an angle constraint when the label is outside. 2016-04-16 12:05:10 +00:00
EvilSpirit 3b7e7289c8 Continue an extension arc towards angle constraint label. 2016-04-16 09:05:21 +00:00
EvilSpirit 92f5bd450c Display angle in the middle of its dimension line, not adjacent.
Less visual clutter and more consistency with distance constraints.
2016-04-16 09:05:21 +00:00
EvilSpirit 07f3ab95e4 Draw extension lines for angle constraints between line segments. 2016-04-16 09:05:21 +00:00
whitequark 1098e598ae Quit export mode after new file. 2016-04-16 09:05:21 +00:00
whitequark 6b123f2d34 Refactor Style::LoadFactoryDefaults.
This also fixes a bug where the hidden-edge style would be reset
to continuous when factory defaults are loaded.
2016-04-16 05:49:37 +00:00
whitequark a7f4d0fffc Fully reinitialize graphics window in AfterNewFile().
Before this commit it was possible to cause a crash by e.g. selecting
a face and pressing Ctrl+N, or numerous other glitches.
2016-04-16 04:19:14 +00:00
EvilSpirit e74ccb3010 Perform grid fitting on the builtin vector font.
Grid fitting is performed only on glyph boundaries, since glyphs
include curves converted to pwl, which would be mangled by per-point
grid fitting.

Grid fitting is only performed when the plane in which text is
laid out is parallel to the viewing plane.

Grid fitting is only performed when rendering for display; there
are no devices with dpi low enough for grid fitting to become
profitable, and in any case we cannot predict what the dpi would
be anyway.
2016-04-16 04:19:14 +00:00
EvilSpirit bd6c4c0cbd Use 16-bit integers to store builtin vector font data.
This significantly increases font legibility, since curves are
represented more precisely. The file size is increased by mere ~1M
(from 7M).
2016-04-16 03:10:56 +00:00
whitequark 0128b86796 Improve builtin vector font positioning.
First, a larger origin offset is applied in ssglWriteText. This moves
the text so that it doesn't overlap the workplane boundary.

Second, a different offset is applied in ssglWriteTextRefCenter.
After this, the middle stroke of "E" is vertically aligned with
the reference point, and the overall label is horizontally aligned
with the reference point more precisely.
2016-04-16 03:10:56 +00:00
whitequark bcb484e941 Do not display trailing zeroes for integer angles.
Angles that aren't an integral number of degrees are extremely
rare, and the label is often in a tight space, which warrants
special-casing this.
2016-04-16 03:10:56 +00:00
whitequark 7a01c840d3 Display and edit length difference constraints as lengths.
Before this commit, they worked sort of like length ratio
constraints, leading to wildly incorrect results in inch mode.
2016-04-16 03:10:56 +00:00
whitequark bd51a9edac Use the Unicode diameter symbol ⌀ in diameter constraints.
Before this commit, the diameter symbol was drawn using custom code,
which is not necessary anymore.
2016-04-16 03:10:56 +00:00
whitequark 23dc36da9b Make graphics window edit control width fit the content.
Before this commit, the graphics window edit control always had
a width of 30 average character widths.

After this commit, the edit control has a width of 5 average
character widths (for numeric constraints) or 30 average character
widths (for comment constraints), or just enough to display
the entire value being edited, whichever is greater.

This makes the edit control overlap the sketch less in case of
editing numeric constraints (since in most cases, the numbers being
edited are short), and removes annoying scrolling in case of editing
long comments.
2016-04-16 03:10:56 +00:00
whitequark d17771064a Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:

The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.

The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.

Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.

On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.

Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-15 21:53:08 +00:00
whitequark 0f304b4c64 Rigorously treat font scale factors.
The old values were chosen without a good understanding of font
metrics.
2016-04-15 21:53:08 +00:00
whitequark e7057418df When there's a shell, always render solids using sharp edges solids.
Before this commit, solids in the viewport were rendered with
"emphasized edges", with the intention to highlight selectable faces.
However, selectable faces are already surrounded by entities, and
so rendering emphasized edges adds little value.

After this commit, solids in the viewport are always rendered with
"sharp edges", like they are exported.
2016-04-15 21:53:08 +00:00
EvilSpirit 24fc65a71c Allow rendering solid outlines using a distinct style.
A new button is added, "Show/hide outline of solid model".

When the outline is hidden, it is rendered using the "solid edge"
style. When the outline is shown, it is rendered using the "outline"
style.

In SolveSpace's true WYSIWYG tradition, the 2d view export follows
the rendered view exactly.

Moreover, shell edges are not rendered anymore, since there is not
much need in them anymore and not drawing them lessens the overlap
between various kinds of lines, which already includes entities,
solid edges and outlines.
2016-04-15 21:53:08 +00:00
EvilSpirit d1a2eb6d18 Allow rendering hidden solid edges using a distinct style.
Before this change, the two buttons "Show/hide shaded model" (S) and
"Show/hide hidden lines" (H) resulted in drawing the following
elements in the following styles:

  Button | Non-occluded | Non-occluded |  Occluded   |   Occluded
  state  | solid edges  |   entities   | solid edges |   entities
 --------+--------------+--------------+-------------+--------------
  !S !H  |              |              | solid-edge  | entity style
 --------+              |              +-------------+--------------
   S !H  |              |              |         invisible
 --------+  solid-edge  | entity style +-------------+--------------
  !S  H  |              |              |             |
 --------+              |              | solid-edge  | entity style
   S  H  |              |              |             |
 --------+--------------+--------------+-------------+--------------

After this change, they are drawn as follows:

  Button | Non-occluded | Non-occluded |  Occluded   |   Occluded
  state  | solid edges  |   entities   | solid edges |   entities
 --------+--------------+--------------+-------------+--------------
  !S !H  |              |              | solid-edge  | entity style
 --------+              |              +-------------+--------------
   S !H  |              |              |         invisible
 --------+  solid-edge  | entity style +-------------+--------------
  !S  H  |              |              |             |
 --------+              |              | hidden-edge |  stippled¹
   S  H  |              |              |             |
 --------+--------------+--------------+-------------+--------------

  ¹ entity style, but the stipple parameters taken from hidden-edge

In SolveSpace's true WYSIWYG tradition, the 2d view export follows
the rendered view exactly.

Also, it is now possible to edit the stipple parameters of built-in
styles, so that by changing the hidden-edge style to non-stippled
it is possible to regain the old behavior.
2016-04-15 21:53:08 +00:00
EvilSpirit d55300232f Don't generate each edge twice in MakeCertainEdgesInto.
This messes up edges when they are rendered stippled, and
unnecessarily makes exported files bigger.
2016-04-15 21:53:08 +00:00
EvilSpirit 1bf7777815 Only export sharp edges of the triangle mesh.
Before this commit, "emphasized edges" were displayed as well as
exported. An "emphasized edge" is an edge between triangles that
come from different faces. They are helpful in the rendered
display because they hint at the locations of faces, but not
in the 2d export since they just clutter the drawing.

After this commit, "emphasized edges" are displayed but "sharp
edges" are exported. A "sharp edge" is an edge between triangles
where the two matching vertexes have different normals, indicating
a discontiguity in the surface. "Sharp edges" are also displayed
while post-viewing the exported geometry.
2016-04-15 21:53:08 +00:00
EvilSpirit 7e6a11c958 Refactor SKdNode::FindEdgeOn.
Extract output parameters into a separate structure.
2016-04-15 21:53:08 +00:00
EvilSpirit 7c60be8203 Remove overlapping line segments when exporting a 2d view.
This adds a new style attribute, "Z-index", which is not currently
displayed and cannot be modified. It may be exposed in the UI later.
2016-04-15 21:53:08 +00:00
EvilSpirit 16ea824456 Allow adding spline points. 2016-04-15 06:11:03 +00:00
EvilSpirit 77d8291216 Allow removing spline points. 2016-04-15 06:11:03 +00:00
whitequark 2d25bdb51f When choosing color for a new group, consider active, not last, group. 2016-04-15 06:11:03 +00:00
EvilSpirit 98e0a30a98 Consider plane faces when zooming to fit. 2016-04-15 06:11:03 +00:00
whitequark 83f5b60228 Fix a macro redefinition warning.
Including windows.h defines "IN".
2016-04-15 06:11:03 +00:00
EvilSpirit 09f59ddbc0 Get rid of if(!this).
According to the C++ standard, "this" is never NULL, so checks
of the form "if(!this)" can be legally optimized out. This
breaks SolveSpace on GCC 6, and probably on other compilers and
configurations.
2016-04-15 06:11:03 +00:00
whitequark 11565e081d Refactor export code to pass around hStyle, not uint32_t. 2016-04-14 18:54:09 +00:00
EvilSpirit 27b403faf5 DXF: refactor. 2016-04-14 18:54:09 +00:00
EvilSpirit f88cb1195b DXF: split entities by layers according to their line styles. 2016-04-14 18:54:09 +00:00
EvilSpirit d88149e705 SVG: export stippled lines.
Also, factor out styles in the exported file, making it much
smaller.
2016-04-14 18:54:09 +00:00
EvilSpirit 94cba11f2a PDF, EPS: export stippled lines. 2016-04-08 11:32:16 +00:00
EvilSpirit a6f7200092 Display point-circle or point-arc distance, when selected. 2016-04-08 11:21:51 +00:00
EvilSpirit 55e3162a05 When creating a new group, use the color of last requested solid. 2016-04-08 11:21:40 +00:00
EvilSpirit 29296447a9 Add the Ukrainian letters [ЄІЇєіїҐґ] to builtin vector font. 2016-04-08 11:01:29 +00:00
EvilSpirit d72b250a64 Don't draw zero-length lines.
Causes "Vector::WithMagnitude(...) of zero vector!"
2016-04-08 10:55:31 +00:00
EvilSpirit e19a2f4f35 Accept maybeFat in ssglStippledLine. 2016-04-08 10:55:11 +00:00
whitequark 1e0fcf1e6c OS X: bundle Freetype.
I erroneously believed that Freetype was shipped with OS X, whereas
it is not, and so we need to ship it ourselves.
2016-04-08 10:47:25 +00:00
EvilSpirit 46b67d5457 Three.js: apply export scale factor to edges. 2016-04-08 10:19:55 +00:00
EvilSpirit e17a24814b DXF: only export visible constraints. 2016-04-08 10:15:29 +00:00
EvilSpirit 73f28b9731 Make normals and workplanes non-stylable.
This does not seem to have any useful application, and it can
result in odd misrenderings with some styles.
2016-04-08 10:12:28 +00:00
EvilSpirit 614902ebdd Don't create multiple undo steps when pasting. 2016-04-08 09:54:46 +00:00
EvilSpirit 3d334d153d Disable autoconstrainer while Ctrl is held. 2016-04-08 09:51:10 +00:00
whitequark 6f67ec2d48 GTK: make the file filter hack more robust. 2016-03-25 11:08:04 +00:00
whitequark fb0aee91ea Add a degree symbol to angle constraints. 2016-03-23 14:16:17 +00:00
whitequark c061fb9416 Restore sensible order of group creation toolicons.
They now have a similar function within each row.
2016-03-19 13:24:52 +00:00
whitequark 762af7d2ad Regenerate the sketch after allowing redundant constraints. 2016-03-18 20:46:46 +00:00
Adam Jaremko b76d7026e0 OS X: Fix iconutil build error.
Fix iconutil build errors: “Iconset contains no image resources.”,
followed by “Failed to generate ICNS.”

The error is produced by iconutil because the AppIcon.iconset contains
only symbolic links to the icon resources which aren’t followed.

Replace the symbolic links with duplicates of the original resources,
as well as conform to the “High Resolution Guidelines for OS X” by
adding additional sizes and dpi.
2016-03-17 00:31:32 -04:00
whitequark e87e787d3f Add "Paste Transformed..." to context menu, when applicable. 2016-03-15 12:11:00 +00:00
whitequark 6e56b00b9a Don't perform hit testing if we haven't painted the graphics window.
This change is quite subtle. The goal is to improve responsiveness
of highlighting even further. To understand this change you need
to keep in mind that Windows and Gtk have dramatically different
behavior for paint (WM_PAINT in Windows, expose in Gtk) and
mouse move events.

In Windows, WM_PAINT and WM_MOUSEMOVE, unless sent explicitly,
are synthesized: WM_MOUSEMOVE is delivered when there are no other
messages and the current cursor position doesn't match the remembered
one, and WM_PAINT is delivered when there are no other messages,
even WM_MOUSEMOVE. This is pretty clever because it doesn't swamp
programs that are slow to process either of those events with even
more of them, ensuring they remain responsive.

In Gtk, expose events are delivered at the end of the frame whenever
there is an invalid view, and every single mouse move that happened
will result in a separate event.

If mouse move events are handled quickly, then the behavior is
identical in either case:
  * process mouse move event
    * perform hit testing
    * invalidate view
  * no more events to process!
    * there are invalid views
      * repaint

If, however, mouse move events are handled slower, then the behavior
diverges. With Gtk:
  * process mouse move event
    * perform hit testing (slow)
      * while this happens, ten more mouse move events are added
    * invalidate view
  * end of frame!
    * there are invalid views
      * repaint
  * process mouse move event...
As a result, the Gtk-hosted UI hopelessly lags behind user input.
This is very irritating.

With Windows:
  * process mouse move event
    * perform hit testing (slow)
      * while this happens, mouse was moved
    * invalidate view
  * process mouse move event...
As a result, the Windows-hosted UI never repaints while the mouse
is moved. This is also very irritating.

Commit HEAD^ has fixed the problems with Gtk-based UI by making
hit testing so fast that mouse move events never quite overflow
the queue. There's still a barely noticeable lag but it's better.

However, the problems with Windows remained because while the queue
doesn't *overflow* with the faster hit testing code, it doesn't go
*empty* either! Thus we still don't repaint.

This commit builds on top of HEAD^ and makes it so that we don't
actually hit test anything if we haven't painted the result of
the previous hit test already. This fixes the problem on Windows
but also helps Gtk a little bit.

Curiously, the Cocoa-based UI never suffered from any of these
problems. To my understanding (it's somewhat underdocumented), it
processes mouse moves like Windows, but paints like Gtk.
2016-03-07 16:03:20 +00:00
whitequark bda2835e9f Cache bounding boxes.
This results in massive performance improvements for hit testing.
Files with very large amounts of entities (e.g. [1]) inflict
a delay of several seconds between moving the pointer and
highlighting an entity in commit HEAD^^^, whereas in this commit
the delay is barely perceptible.

[1]: http://solvespace.com/forum.pl?action=viewthread&parent=872
2016-03-05 16:48:56 +00:00
EvilSpirit e99eedd7a3 Check entity bounding box before hit testing edges. 2016-03-05 16:48:56 +00:00
EvilSpirit b054b9682a Cache generated bezier curves and edges in Entity. 2016-03-05 16:48:16 +00:00
EvilSpirit a0576e2a50 Allow changing text size for default styles.
This is especially useful for High-DPI displays on non-OS X.
2016-03-05 12:02:13 +00:00
EvilSpirit 96344c85a6 Eliminate DEFAULT_TEXT_HEIGHT from drawing code.
Instead, query the text height for constraint style.
2016-03-05 12:02:13 +00:00
EvilSpirit 1f0649d1bb Remove merge artifact. 2016-03-05 12:02:13 +00:00
EvilSpirit 1814cf3c0f DXF: export stippled line styles. 2016-03-05 12:02:13 +00:00
EvilSpirit 1170a91875 Implement stippled line styles from ISO 128.
Now it's possible to use a styled line to indicate e.g.
a centerline.
2016-03-05 12:02:13 +00:00
EvilSpirit 171f208cfb Extract Style::FillDefaultStyle. 2016-03-04 15:13:09 +00:00
whitequark c9a2092b9c Fix image export on *nix.
Before this commit, trying to export image on *nix platforms yielded
a black rectangle, since since there is nowhere to render to
when we're not in a GUI toolkit draw callback.

On Windows, nothing changes: we do a repaint without the toolbar,
glReadPixels, export. On *nix, we create another offscreen rendering
context, render into it, then destroy it. As a bonus this avoids
some minor flickering that would happen if we reused the regular
rendering path.
2016-03-04 15:11:14 +00:00
EvilSpirit a886746e71 DXF: export entities, dimensions and comments on separate layers. 2016-02-19 23:16:36 +00:00
EvilSpirit df0a1d64e4 DXF: include compatible AutoCAD version in format selector. 2016-02-19 23:16:36 +00:00
EvilSpirit f87152e8c0 DXF: export constraints with labels as DXF constraints, not pwl.
Specifically, the following constraint types:
  * pt-pt-distance
  * pt-line-distance
  * diameter
  * angle
  * comment
2016-02-19 23:16:36 +00:00
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
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