Commit Graph

68 Commits (028b613f1036d141fc8c534c115bf0612f04c020)

Author SHA1 Message Date
ruevs f6a774d7bf Fix some trivial warnings found by MSVC. NFC.
Found with /W4 by MSVC 2019 (Microsoft (R) C/C++ Optimizing Compiler Version 19.24.28314)

A bunch of implicit casts 'double' to 'float' and one 'int64_t' to 'unsigned'.

.\src\platform\guiwin.cpp(1237): warning C4701: potentially uninitialized local variable 'cursorName' used
.\src\platform\guiwin.cpp(1237): warning C4703: potentially uninitialized local pointer variable 'cursorName' used

.\src\solvespace.cpp(805,30): warning C4456: declaration of 'gs' hides previous local declaration
.\src\solvespace.cpp(715,17): message : see declaration of 'gs'

.\src\solvespace.cpp(849,47): warning C4456: declaration of 'e' hides previous local declaration
.\src\solvespace.cpp(847,29): message : see declaration of 'e'

.\src\render\render.h(288,51): warning C4458: declaration of 'camera' hides class member
.\src\render\render.h(271,17): message : see declaration of 'SolveSpace::SurfaceRenderer::camera'

.\src\render\render.h(289,57): warning C4458: declaration of 'lighting' hides class member
.\src\render\render.h(272,17): message : see declaration of 'SolveSpace::SurfaceRenderer::lighting'
2020-02-20 14:03:31 +00:00
Ryan Pavlik 15838dc5a1 For loop cleanup. NFC. 2019-09-10 04:21:57 +00:00
Ryan Pavlik 0bfbbe2bf3 Improve implementation hiding in IdList/List. NFC.
Allows distancing users from the internal "elem" member.

Add Get() and operator[].
Replace direct references to elem.
Make elem and elemsAllocated private in IdList/List.
2019-08-20 15:57:11 +00:00
Ryan Pavlik 3ea077b70f Reduce scopes and placate clang-tidy. NFC.
Pointing out one potential issue with an assert.
2019-08-20 15:57:11 +00:00
Ryan Pavlik 86f20cc7e5 Convert many loops to range-for or std algorithms. NFC.
Also add comments about indexing and when we don't use range-for.
2019-08-20 15:57:11 +00:00
nabijaczleweli d9081b0b08 VRML: add support for transparency. 2019-08-09 23:32:24 +00:00
nabijaczleweli 837628ea3e Add VRML (WRL) triangle mesh export.
Transparency is not supported.
2019-08-09 21:30:33 +00:00
Ryan Pavlik 5efb09e6d4 Use the new equality/inequality operators of handles to reduce references to .v. NFC. 2019-07-10 15:40:21 +00:00
whitequark 359697990a Update q3d submodule. 2019-05-31 23:07:04 +00:00
Bauke Conijn 7d181f0d0f Include custom styled entities in the same plane when exporting section. 2019-05-13 14:34:22 +00:00
Sergiusz Bazanski 3a3a2755bf Implement Q3DO export.
We plan to use flatbuffers in the future for the next generation of
the .slvs file format, so flatbuffers are built unconditionally; and
the Q3DO exporter itself is tiny.
2019-03-28 08:53:37 +00:00
whitequark f324477dd0 Implement a platform abstraction for windows.
This commit removes a large amount of code partially duplicated
between the text and the graphics windows, and opens the path to
having more than one model window on screen at any given time,
as well as simplifies platform work.

This commit also adds complete support for High-DPI device pixel
ratio. It adds support for font scale factor (a fractional factor
on top of integral device pixel ratio) on the platform side, but not
on the application side.

This commit also adds error checking to all Windows API calls
(within the abstracted code) and fixes a significant number of
misuses and non-future-proof uses of Windows API.

This commit also makes uses of Windows API idiomatic, e.g. using
the built-in vertical scroll bar, native tooltips, control
subclassing instead of hooks in the global dispatch loop, and so on.

It reinstates tooltip support and removes menu-related hacks.
2018-07-17 13:31:17 +00:00
whitequark e2e74762f4 Rework path and file operations to be more robust.
This commit updates a *lot* of rather questionable path handling
logic to be robust. Specifically:
  * All path operations go through Platform::Path.
  * All ad-hoc path handling functions are removed, together with
    PATH_SEP. This removes code that was in platform-independent
    parts, but had platform-dependent behavior.
  * Group::linkFileRel is removed; only an absolute path is stored
    in Group::linkFile. However, only Group::linkFileRel is saved,
    with the relative path calculated on the fly, from the filename
    passed into SaveToFile. This eliminates dependence on global
    state, and makes it unnecessary to have separare code paths
    for saved and not yet saved files.
  * In a departure from previous practice, functions with
    platform-independent code but platform-dependent behavior
    are all grouped under platform/. This makes it easy to grep
    for functions with platform-dependent behavior.
  * Similarly, new (GUI-independent) code for all platforms is added
    in the same platform.cpp file, guarded with #ifs. It turns out
    that implementations for different platforms had a lot of shared
    code that tended to go out of sync.
2017-03-11 18:58:53 +00:00
whitequark dbf66639aa Replace ad-hoc implementations of Basename with calls to it. 2017-03-08 19:25:45 +00:00
whitequark ff0af6fdba Fix a typo in 495a7ac. 2017-01-23 11:15:37 +00:00
whitequark 495a7ac166 Refactor the "File → Export Image" command.
The existing code is horrible and needlessly platform-dependent.
Even worse, it causes a freeze on GTK. Instead of propping that up
with a few more crutches, just fix the root cause.
2017-01-23 00:24:18 +00:00
whitequark 984f74d271 Internationalize all messages without substitutions. 2017-01-07 06:47:40 +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 c7277521f3 Fix error message shown when exporting mesh with wrong extension. 2016-11-17 06:52:44 +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
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
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
EvilSpirit f4e85127d6 Wavefront OBJ: export mesh color as well. 2016-10-11 14:54:19 +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 b9d375652c Recognize .ngc as a valid G-Code export extension. 2016-08-25 02:57:29 +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 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 8bf55b3c62 Fix multiple memory leaks found with LeakSanitizer. 2016-08-07 19:33:42 +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 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 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 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
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
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 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 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 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 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 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 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 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 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 94cba11f2a PDF, EPS: export stippled lines. 2016-04-08 11:32:16 +00:00
EvilSpirit 46b67d5457 Three.js: apply export scale factor to edges. 2016-04-08 10:19:55 +00:00