2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// All declarations not grouped specially elsewhere.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-03-25 10:02:13 +00:00
|
|
|
|
|
|
|
#ifndef __SOLVESPACE_H
|
|
|
|
#define __SOLVESPACE_H
|
|
|
|
|
2016-04-23 23:00:16 +00:00
|
|
|
#include <stdint.h>
|
2013-10-25 05:04:16 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2015-03-23 17:49:04 +00:00
|
|
|
#include <stddef.h>
|
2013-10-25 05:04:16 +00:00
|
|
|
#include <stdarg.h>
|
2016-07-25 22:09:58 +00:00
|
|
|
#include <setjmp.h>
|
2013-10-25 05:04:16 +00:00
|
|
|
#include <math.h>
|
2016-07-25 21:46:35 +00:00
|
|
|
#include <setjmp.h>
|
2013-10-25 05:04:16 +00:00
|
|
|
#include <limits.h>
|
2015-03-27 15:43:28 +00:00
|
|
|
#include <algorithm>
|
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-05-31 00:55:13 +00:00
|
|
|
#include <functional>
|
2016-03-03 09:53:10 +00:00
|
|
|
#include <memory>
|
2015-12-26 15:54:26 +00:00
|
|
|
#include <string>
|
2016-04-13 08:43:06 +00:00
|
|
|
#include <locale>
|
2015-12-27 06:35:46 +00:00
|
|
|
#include <vector>
|
2016-03-21 11:11:41 +00:00
|
|
|
#include <unordered_map>
|
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-05-31 00:55:13 +00:00
|
|
|
#include <unordered_set>
|
2016-01-11 12:18:18 +00:00
|
|
|
#include <map>
|
2016-03-14 16:14:24 +00:00
|
|
|
#include <set>
|
2016-07-20 07:50:05 +00:00
|
|
|
#include <chrono>
|
2016-10-09 19:58:44 +00:00
|
|
|
#include <sstream>
|
2013-10-25 05:04:16 +00:00
|
|
|
|
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-01-30 01:42:44 +00:00
|
|
|
// We declare these in advance instead of simply using FT_Library
|
|
|
|
// (defined as typedef FT_LibraryRec_* FT_Library) because including
|
|
|
|
// freetype.h invokes indescribable horrors and we would like to avoid
|
|
|
|
// doing that every time we include solvespace.h.
|
|
|
|
struct FT_LibraryRec_;
|
|
|
|
struct FT_FaceRec_;
|
|
|
|
|
2016-07-24 13:17:52 +00:00
|
|
|
typedef struct _cairo cairo_t;
|
|
|
|
|
2013-10-21 21:29:25 +00:00
|
|
|
// The few floating-point equality comparisons in SolveSpace have been
|
|
|
|
// carefully considered, so we disable the -Wfloat-equal warning for them
|
|
|
|
#ifdef __clang__
|
|
|
|
# define EXACT(expr) \
|
|
|
|
(_Pragma("clang diagnostic push") \
|
|
|
|
_Pragma("clang diagnostic ignored \"-Wfloat-equal\"") \
|
|
|
|
(expr) \
|
|
|
|
_Pragma("clang diagnostic pop"))
|
|
|
|
#else
|
|
|
|
# define EXACT(expr) (expr)
|
|
|
|
#endif
|
|
|
|
|
2008-03-28 10:00:37 +00:00
|
|
|
// Debugging functions
|
2016-05-18 19:38:17 +00:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
#define ssassert(condition, message) \
|
|
|
|
do { \
|
|
|
|
if(__builtin_expect((condition), true) == false) { \
|
|
|
|
SolveSpace::assert_failure(__FILE__, __LINE__, __func__, #condition, message); \
|
|
|
|
__builtin_unreachable(); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2015-03-17 16:17:51 +00:00
|
|
|
#else
|
2016-05-18 19:38:17 +00:00
|
|
|
#define ssassert(condition, message) \
|
|
|
|
do { \
|
|
|
|
if((condition) == false) { \
|
|
|
|
SolveSpace::assert_failure(__FILE__, __LINE__, __func__, #condition, message); \
|
|
|
|
abort(); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2015-03-17 16:17:51 +00:00
|
|
|
#endif
|
2013-10-25 05:04:16 +00:00
|
|
|
|
2013-10-19 05:36:45 +00:00
|
|
|
#ifndef isnan
|
|
|
|
# define isnan(x) (((x) != (x)) || (x > 1e11) || (x < -1e11))
|
|
|
|
#endif
|
2008-06-03 18:28:41 +00:00
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
namespace SolveSpace {
|
|
|
|
|
2015-03-27 15:43:28 +00:00
|
|
|
using std::min;
|
|
|
|
using std::max;
|
|
|
|
using std::swap;
|
|
|
|
|
2016-05-18 19:38:17 +00:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
__attribute__((noreturn))
|
|
|
|
#endif
|
|
|
|
void assert_failure(const char *file, unsigned line, const char *function,
|
|
|
|
const char *condition, const char *message);
|
|
|
|
|
2015-11-06 08:40:12 +00:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
__attribute__((__format__ (__printf__, 1, 2)))
|
|
|
|
#endif
|
|
|
|
std::string ssprintf(const char *fmt, ...);
|
|
|
|
|
2008-05-26 03:39:45 +00:00
|
|
|
inline int WRAP(int v, int n) {
|
2009-01-03 12:27:33 +00:00
|
|
|
// Clamp it to the range [0, n)
|
2008-05-26 03:39:45 +00:00
|
|
|
while(v >= n) v -= n;
|
|
|
|
while(v < 0) v += n;
|
|
|
|
return v;
|
|
|
|
}
|
2009-01-03 12:27:33 +00:00
|
|
|
inline double WRAP_NOT_0(double v, double n) {
|
|
|
|
// Clamp it to the range (0, n]
|
|
|
|
while(v > n) v -= n;
|
|
|
|
while(v <= 0) v += n;
|
|
|
|
return v;
|
|
|
|
}
|
2009-03-19 17:40:11 +00:00
|
|
|
inline double WRAP_SYMMETRIC(double v, double n) {
|
|
|
|
// Clamp it to the range (-n/2, n/2]
|
|
|
|
while(v > n/2) v -= n;
|
|
|
|
while(v <= -n/2) v += n;
|
|
|
|
return v;
|
|
|
|
}
|
2009-01-03 12:27:33 +00:00
|
|
|
|
2009-10-21 04:46:01 +00:00
|
|
|
// Why is this faster than the library function?
|
|
|
|
inline double ffabs(double v) { return (v > 0) ? v : (-v); }
|
|
|
|
|
2008-05-22 10:28:28 +00:00
|
|
|
#define CO(v) (v).x, (v).y, (v).z
|
|
|
|
|
2015-10-31 08:22:26 +00:00
|
|
|
#define ANGLE_COS_EPS (1e-6)
|
2009-03-08 10:59:57 +00:00
|
|
|
#define LENGTH_EPS (1e-6)
|
2009-01-27 05:48:40 +00:00
|
|
|
#define VERY_POSITIVE (1e10)
|
|
|
|
#define VERY_NEGATIVE (-1e10)
|
2008-05-11 10:40:37 +00:00
|
|
|
|
2008-04-17 06:42:32 +00:00
|
|
|
#define isforname(c) (isalnum(c) || (c) == '_' || (c) == '-' || (c) == '#')
|
|
|
|
|
2015-12-27 07:51:28 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
std::string Narrow(const wchar_t *s);
|
|
|
|
std::wstring Widen(const char *s);
|
|
|
|
std::string Narrow(const std::wstring &s);
|
|
|
|
std::wstring Widen(const std::string &s);
|
|
|
|
#endif
|
|
|
|
|
2009-02-09 12:40:48 +00:00
|
|
|
inline double Random(double vmax) {
|
|
|
|
return (vmax*rand()) / RAND_MAX;
|
|
|
|
}
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
class Expr;
|
2008-04-22 13:14:15 +00:00
|
|
|
class ExprVector;
|
2008-05-05 06:18:01 +00:00
|
|
|
class ExprQuaternion;
|
2015-07-10 11:54:39 +00:00
|
|
|
class RgbaColor;
|
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-20 08:31:20 +00:00
|
|
|
enum class Command : uint32_t;
|
|
|
|
enum class ContextCommand : uint32_t;
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2008-06-30 09:09:17 +00:00
|
|
|
//================
|
2008-04-14 10:28:32 +00:00
|
|
|
// From the platform-specific code.
|
2015-12-27 06:35:46 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
#define PATH_SEP "\\"
|
|
|
|
#else
|
|
|
|
#define PATH_SEP "/"
|
|
|
|
#endif
|
|
|
|
|
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-05-31 00:55:13 +00:00
|
|
|
extern const bool FLIP_FRAMEBUFFER;
|
|
|
|
|
|
|
|
bool PathEqual(const std::string &a, const std::string &b);
|
2016-07-25 19:37:48 +00:00
|
|
|
std::string PathSepPlatformToUnix(const std::string &filename);
|
|
|
|
std::string PathSepUnixToPlatform(const std::string &filename);
|
2015-12-27 08:09:00 +00:00
|
|
|
FILE *ssfopen(const std::string &filename, const char *mode);
|
2016-10-09 14:58:07 +00:00
|
|
|
std::fstream ssfstream(const std::string &filename, std::ios_base::openmode mode);
|
2015-12-27 08:09:00 +00:00
|
|
|
void ssremove(const std::string &filename);
|
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
const size_t MAX_RECENT = 8;
|
2015-12-27 01:03:24 +00:00
|
|
|
extern std::string RecentFile[MAX_RECENT];
|
2016-05-05 05:54:05 +00:00
|
|
|
void RefreshRecentMenus();
|
2008-05-28 10:10:31 +00:00
|
|
|
|
2016-01-11 12:18:18 +00:00
|
|
|
enum DialogChoice { DIALOG_YES = 1, DIALOG_NO = -1, DIALOG_CANCEL = 0 };
|
2016-05-05 05:54:05 +00:00
|
|
|
DialogChoice SaveFileYesNoCancel();
|
|
|
|
DialogChoice LoadAutosaveYesNo();
|
2016-01-11 12:18:18 +00:00
|
|
|
DialogChoice LocateImportedFileYesNoCancel(const std::string &filename,
|
|
|
|
bool canCancel);
|
2015-03-29 04:46:57 +00:00
|
|
|
|
|
|
|
#define AUTOSAVE_SUFFIX "~"
|
2013-09-18 20:49:32 +00:00
|
|
|
|
2016-05-04 03:12:06 +00:00
|
|
|
struct FileFilter {
|
|
|
|
const char *name;
|
|
|
|
const char *patterns[3];
|
|
|
|
};
|
2013-10-25 05:04:16 +00:00
|
|
|
|
2009-10-12 10:40:48 +00:00
|
|
|
// SolveSpace native file format
|
2016-05-04 03:12:06 +00:00
|
|
|
const FileFilter SlvsFileFilter[] = {
|
|
|
|
{ "SolveSpace models", { "slvs" } },
|
2016-05-07 23:34:21 +00:00
|
|
|
{ NULL, {} }
|
2016-05-04 03:12:06 +00:00
|
|
|
};
|
2009-10-12 10:40:48 +00:00
|
|
|
// PNG format bitmap
|
2016-05-04 03:12:06 +00:00
|
|
|
const FileFilter PngFileFilter[] = {
|
|
|
|
{ "PNG", { "png" } },
|
2016-05-07 23:34:21 +00:00
|
|
|
{ NULL, {} }
|
2016-05-04 03:12:06 +00:00
|
|
|
};
|
2009-10-12 10:40:48 +00:00
|
|
|
// Triangle mesh
|
2016-05-04 03:12:06 +00:00
|
|
|
const FileFilter MeshFileFilter[] = {
|
|
|
|
{ "STL mesh", { "stl" } },
|
|
|
|
{ "Wavefront OBJ mesh", { "obj" } },
|
|
|
|
{ "Three.js-compatible mesh, with viewer", { "html" } },
|
|
|
|
{ "Three.js-compatible mesh, mesh only", { "js" } },
|
2016-05-07 23:34:21 +00:00
|
|
|
{ NULL, {} }
|
2016-05-04 03:12:06 +00:00
|
|
|
};
|
2009-10-12 10:40:48 +00:00
|
|
|
// NURBS surfaces
|
2016-05-04 03:12:06 +00:00
|
|
|
const FileFilter SurfaceFileFilter[] = {
|
|
|
|
{ "STEP file", { "step", "stp" } },
|
2016-05-07 23:34:21 +00:00
|
|
|
{ NULL, {} }
|
2016-05-04 03:12:06 +00:00
|
|
|
};
|
2009-10-12 10:40:48 +00:00
|
|
|
// 2d vector (lines and curves) format
|
2016-05-04 03:12:06 +00:00
|
|
|
const FileFilter VectorFileFilter[] = {
|
|
|
|
{ "PDF file", { "pdf" } },
|
|
|
|
{ "Encapsulated PostScript", { "eps", "ps" } },
|
|
|
|
{ "Scalable Vector Graphics", { "svg" } },
|
|
|
|
{ "STEP file", { "step", "stp" } },
|
|
|
|
{ "DXF file (AutoCAD 2007)", { "dxf" } },
|
|
|
|
{ "HPGL file", { "plt", "hpgl" } },
|
|
|
|
{ "G Code", { "ngc", "txt" } },
|
2016-05-07 23:34:21 +00:00
|
|
|
{ NULL, {} }
|
2016-05-04 03:12:06 +00:00
|
|
|
};
|
2009-10-12 10:40:48 +00:00
|
|
|
// 3d vector (wireframe lines and curves) format
|
2016-05-04 03:12:06 +00:00
|
|
|
const FileFilter Vector3dFileFilter[] = {
|
|
|
|
{ "STEP file", { "step", "stp" } },
|
|
|
|
{ "DXF file (AutoCAD 2007)", { "dxf" } },
|
2016-05-07 23:34:21 +00:00
|
|
|
{ NULL, {} }
|
2016-05-04 03:12:06 +00:00
|
|
|
};
|
2016-04-13 08:43:06 +00:00
|
|
|
// All Importable formats
|
|
|
|
const FileFilter ImportableFileFilter[] = {
|
|
|
|
{ "AutoCAD DXF and DWG files", { "dxf", "dwg" } },
|
2016-05-07 23:34:21 +00:00
|
|
|
{ NULL, {} }
|
2016-04-13 08:43:06 +00:00
|
|
|
};
|
2009-10-12 10:40:48 +00:00
|
|
|
// Comma-separated value, like a spreadsheet would use
|
2016-05-04 03:12:06 +00:00
|
|
|
const FileFilter CsvFileFilter[] = {
|
|
|
|
{ "CSV", { "csv" } },
|
2016-05-07 23:34:21 +00:00
|
|
|
{ NULL, {} }
|
2016-05-04 03:12:06 +00:00
|
|
|
};
|
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
enum class Unit : uint32_t {
|
|
|
|
MM = 0,
|
|
|
|
INCHES
|
|
|
|
};
|
|
|
|
|
2016-05-04 03:12:06 +00:00
|
|
|
bool GetSaveFile(std::string *filename, const std::string &defExtension,
|
|
|
|
const FileFilter filters[]);
|
|
|
|
bool GetOpenFile(std::string *filename, const std::string &defExtension,
|
|
|
|
const FileFilter filters[]);
|
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-01-30 01:42:44 +00:00
|
|
|
std::vector<std::string> GetFontFiles();
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2013-08-26 18:58:35 +00:00
|
|
|
void OpenWebsite(const char *url);
|
2008-02-09 13:52:01 +00:00
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
void CheckMenuByCmd(Command id, bool checked);
|
|
|
|
void RadioMenuByCmd(Command id, bool selected);
|
|
|
|
void EnableMenuByCmd(Command id, bool enabled);
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2016-04-16 00:10:32 +00:00
|
|
|
void ShowGraphicsEditControl(int x, int y, int fontHeight, int minWidthChars,
|
|
|
|
const std::string &str);
|
2016-05-05 05:54:05 +00:00
|
|
|
void HideGraphicsEditControl();
|
|
|
|
bool GraphicsEditControlIsVisible();
|
2015-11-06 08:40:12 +00:00
|
|
|
void ShowTextEditControl(int x, int y, const std::string &str);
|
2016-05-05 05:54:05 +00:00
|
|
|
void HideTextEditControl();
|
|
|
|
bool TextEditControlIsVisible();
|
2010-04-26 07:52:49 +00:00
|
|
|
void MoveTextScrollbarTo(int pos, int maxPos, int page);
|
2008-04-21 10:12:04 +00:00
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
void AddContextMenuItem(const char *legend, ContextCommand id);
|
2016-05-05 05:54:05 +00:00
|
|
|
void CreateContextSubmenu();
|
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-20 08:31:20 +00:00
|
|
|
ContextCommand ShowContextMenu();
|
2009-09-23 10:59:59 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void ToggleMenuBar();
|
|
|
|
bool MenuBarIsVisible();
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
void ShowTextWindow(bool visible);
|
2016-05-05 05:54:05 +00:00
|
|
|
void InvalidateText();
|
|
|
|
void InvalidateGraphics();
|
|
|
|
void PaintGraphics();
|
|
|
|
void ToggleFullScreen();
|
|
|
|
bool FullScreenIsActive();
|
2008-06-12 07:31:41 +00:00
|
|
|
void GetGraphicsWindowSize(int *w, int *h);
|
2010-05-03 05:04:42 +00:00
|
|
|
void GetTextWindowSize(int *w, int *h);
|
2016-08-01 13:44:38 +00:00
|
|
|
double GetScreenDpi();
|
2016-05-05 05:54:05 +00:00
|
|
|
int64_t GetMilliseconds();
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2013-08-26 18:58:35 +00:00
|
|
|
void dbp(const char *str, ...);
|
2008-05-30 07:32:30 +00:00
|
|
|
#define DBPTRI(tri) \
|
|
|
|
dbp("tri: (%.3f %.3f %.3f) (%.3f %.3f %.3f) (%.3f %.3f %.3f)", \
|
|
|
|
CO((tri).a), CO((tri).b), CO((tri).c))
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
void SetCurrentFilename(const std::string &filename);
|
2010-04-26 07:52:49 +00:00
|
|
|
void SetMousePointerToHand(bool yes);
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
void DoMessageBox(const char *str, int rows, int cols, bool error);
|
2009-01-02 10:38:36 +00:00
|
|
|
void SetTimerFor(int milliseconds);
|
2015-03-29 04:46:57 +00:00
|
|
|
void SetAutosaveTimerFor(int minutes);
|
2015-03-18 17:02:11 +00:00
|
|
|
void ScheduleLater();
|
2016-05-05 05:54:05 +00:00
|
|
|
void ExitNow();
|
2008-07-08 08:02:22 +00:00
|
|
|
|
2015-12-26 15:54:26 +00:00
|
|
|
void CnfFreezeInt(uint32_t val, const std::string &name);
|
|
|
|
void CnfFreezeFloat(float val, const std::string &name);
|
|
|
|
void CnfFreezeString(const std::string &val, const std::string &name);
|
|
|
|
std::string CnfThawString(const std::string &val, const std::string &name);
|
|
|
|
uint32_t CnfThawInt(uint32_t val, const std::string &name);
|
|
|
|
float CnfThawFloat(float val, const std::string &name);
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2013-08-26 20:40:25 +00:00
|
|
|
void *AllocTemporary(size_t n);
|
2008-07-13 12:58:52 +00:00
|
|
|
void FreeTemporary(void *p);
|
2016-05-05 05:54:05 +00:00
|
|
|
void FreeAllTemporary();
|
2013-08-26 20:40:25 +00:00
|
|
|
void *MemAlloc(size_t n);
|
2008-04-18 07:06:37 +00:00
|
|
|
void MemFree(void *p);
|
2016-05-05 05:54:05 +00:00
|
|
|
void InitHeaps();
|
|
|
|
void vl(); // debug function to validate heaps
|
2008-06-30 09:09:17 +00:00
|
|
|
|
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-04-21 15:54:18 +00:00
|
|
|
#include "resource.h"
|
|
|
|
|
2008-06-30 09:09:17 +00:00
|
|
|
// End of platform-specific functions
|
|
|
|
//================
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2016-07-21 20:27:53 +00:00
|
|
|
template<class T>
|
|
|
|
struct CompareHandle {
|
|
|
|
bool operator()(T lhs, T rhs) const { return lhs.v < rhs.v; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class Key, class T>
|
|
|
|
using handle_map = std::map<Key, T, CompareHandle<Key>>;
|
|
|
|
|
2009-05-24 11:37:07 +00:00
|
|
|
class Group;
|
2009-02-27 14:05:08 +00:00
|
|
|
class SSurface;
|
2008-03-25 10:02:13 +00:00
|
|
|
#include "dsc.h"
|
2008-04-23 07:29:19 +00:00
|
|
|
#include "polygon.h"
|
2009-01-15 03:55:42 +00:00
|
|
|
#include "srf/surface.h"
|
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-05-31 00:55:13 +00:00
|
|
|
#include "render/render.h"
|
2008-05-29 10:10:12 +00:00
|
|
|
|
|
|
|
class Entity;
|
|
|
|
class hEntity;
|
2008-06-23 08:25:17 +00:00
|
|
|
class Param;
|
|
|
|
class hParam;
|
2008-05-29 10:10:12 +00:00
|
|
|
typedef IdList<Entity,hEntity> EntityList;
|
2008-06-23 08:25:17 +00:00
|
|
|
typedef IdList<Param,hParam> ParamList;
|
2008-05-29 10:10:12 +00:00
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
enum class SolveResult : uint32_t {
|
|
|
|
OKAY = 0,
|
|
|
|
DIDNT_CONVERGE = 10,
|
|
|
|
REDUNDANT_OKAY = 11,
|
|
|
|
REDUNDANT_DIDNT_CONVERGE = 12,
|
|
|
|
TOO_MANY_UNKNOWNS = 20
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-26 09:18:12 +00:00
|
|
|
#include "sketch.h"
|
2008-04-12 14:12:26 +00:00
|
|
|
#include "ui.h"
|
2008-04-08 12:54:53 +00:00
|
|
|
#include "expr.h"
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2008-03-27 09:53:51 +00:00
|
|
|
|
2008-04-11 11:13:47 +00:00
|
|
|
// Utility functions that are provided in the platform-independent code.
|
2016-02-14 20:13:40 +00:00
|
|
|
class utf8_iterator : std::iterator<std::forward_iterator_tag, char32_t> {
|
|
|
|
const char *p, *n;
|
|
|
|
public:
|
|
|
|
utf8_iterator(const char *p) : p(p), n(NULL) {}
|
|
|
|
bool operator==(const utf8_iterator &i) const { return p==i.p; }
|
|
|
|
bool operator!=(const utf8_iterator &i) const { return p!=i.p; }
|
|
|
|
ptrdiff_t operator- (const utf8_iterator &i) const { return p -i.p; }
|
|
|
|
utf8_iterator& operator++() { **this; p=n; n=NULL; return *this; }
|
|
|
|
utf8_iterator operator++(int) { utf8_iterator t(*this); operator++(); return t; }
|
|
|
|
char32_t operator*();
|
|
|
|
};
|
|
|
|
class ReadUTF8 {
|
|
|
|
const std::string &str;
|
|
|
|
public:
|
|
|
|
ReadUTF8(const std::string &str) : str(str) {}
|
|
|
|
utf8_iterator begin() const { return utf8_iterator(&str[0]); }
|
|
|
|
utf8_iterator end() const { return utf8_iterator(&str[str.length()]); }
|
|
|
|
};
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2008-03-26 09:18:12 +00:00
|
|
|
#define arraylen(x) (sizeof((x))/sizeof((x)[0]))
|
2008-03-27 09:53:51 +00:00
|
|
|
#define PI (3.1415926535897931)
|
|
|
|
void MakeMatrix(double *mat, double a11, double a12, double a13, double a14,
|
|
|
|
double a21, double a22, double a23, double a24,
|
|
|
|
double a31, double a32, double a33, double a34,
|
|
|
|
double a41, double a42, double a43, double a44);
|
2016-04-17 10:01:44 +00:00
|
|
|
std::string MakeAcceleratorLabel(int accel);
|
2015-12-27 01:03:24 +00:00
|
|
|
bool FilenameHasExtension(const std::string &str, const char *ext);
|
2016-10-09 19:58:44 +00:00
|
|
|
bool ReadFile(const std::string &filename, std::string *data);
|
|
|
|
bool WriteFile(const std::string &filename, const std::string &data);
|
2013-08-26 18:58:35 +00:00
|
|
|
void Message(const char *str, ...);
|
|
|
|
void Error(const char *str, ...);
|
2015-12-26 15:54:26 +00:00
|
|
|
void CnfFreezeBool(bool v, const std::string &name);
|
|
|
|
void CnfFreezeColor(RgbaColor v, const std::string &name);
|
|
|
|
bool CnfThawBool(bool v, const std::string &name);
|
|
|
|
RgbaColor CnfThawColor(RgbaColor v, const std::string &name);
|
2008-03-27 09:53:51 +00:00
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
class System {
|
|
|
|
public:
|
2013-09-09 19:50:32 +00:00
|
|
|
enum { MAX_UNKNOWNS = 1024 };
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-06-23 08:25:17 +00:00
|
|
|
EntityList entity;
|
|
|
|
ParamList param;
|
2008-04-20 11:35:10 +00:00
|
|
|
IdList<Equation,hEquation> eq;
|
|
|
|
|
2009-04-20 07:30:09 +00:00
|
|
|
// A list of parameters that are being dragged; these are the ones that
|
|
|
|
// we should put as close as possible to their initial positions.
|
2009-11-03 18:54:49 +00:00
|
|
|
List<hParam> dragged;
|
2009-04-20 07:30:09 +00:00
|
|
|
|
2013-09-09 19:50:32 +00:00
|
|
|
enum {
|
|
|
|
// In general, the tag indicates the subsys that a variable/equation
|
|
|
|
// has been assigned to; these are exceptions for variables:
|
|
|
|
VAR_SUBSTITUTED = 10000,
|
|
|
|
VAR_DOF_TEST = 10001,
|
|
|
|
// and for equations:
|
|
|
|
EQ_SUBSTITUTED = 20000
|
|
|
|
};
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-04-21 01:26:36 +00:00
|
|
|
// The system Jacobian matrix
|
2008-04-20 11:35:10 +00:00
|
|
|
struct {
|
2008-04-21 01:26:36 +00:00
|
|
|
// The corresponding equation for each row
|
|
|
|
hEquation eq[MAX_UNKNOWNS];
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-04-21 01:26:36 +00:00
|
|
|
// The corresponding parameter for each column
|
|
|
|
hParam param[MAX_UNKNOWNS];
|
2008-05-01 06:25:38 +00:00
|
|
|
|
2008-04-21 01:26:36 +00:00
|
|
|
// We're solving AX = B
|
2008-04-20 11:35:10 +00:00
|
|
|
int m, n;
|
2008-04-21 01:26:36 +00:00
|
|
|
struct {
|
|
|
|
Expr *sym[MAX_UNKNOWNS][MAX_UNKNOWNS];
|
|
|
|
double num[MAX_UNKNOWNS][MAX_UNKNOWNS];
|
|
|
|
} A;
|
2008-05-01 06:25:38 +00:00
|
|
|
|
2008-05-13 02:35:31 +00:00
|
|
|
double scale[MAX_UNKNOWNS];
|
|
|
|
|
2008-05-12 07:29:50 +00:00
|
|
|
// Some helpers for the least squares solve
|
|
|
|
double AAt[MAX_UNKNOWNS][MAX_UNKNOWNS];
|
|
|
|
double Z[MAX_UNKNOWNS];
|
|
|
|
|
2008-04-21 01:26:36 +00:00
|
|
|
double X[MAX_UNKNOWNS];
|
2008-05-01 06:25:38 +00:00
|
|
|
|
2008-04-21 01:26:36 +00:00
|
|
|
struct {
|
|
|
|
Expr *sym[MAX_UNKNOWNS];
|
|
|
|
double num[MAX_UNKNOWNS];
|
|
|
|
} B;
|
|
|
|
} mat;
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-09-05 11:25:53 +00:00
|
|
|
static const double RANK_MAG_TOLERANCE, CONVERGE_TOLERANCE;
|
2016-05-05 05:54:05 +00:00
|
|
|
int CalculateRank();
|
|
|
|
bool TestRank();
|
2008-05-12 07:29:50 +00:00
|
|
|
static bool SolveLinearSystem(double X[], double A[][MAX_UNKNOWNS],
|
|
|
|
double B[], int N);
|
2016-05-05 05:54:05 +00:00
|
|
|
bool SolveLeastSquares();
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2009-04-19 20:37:51 +00:00
|
|
|
bool WriteJacobian(int tag);
|
2016-05-05 05:54:05 +00:00
|
|
|
void EvalJacobian();
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2009-04-20 07:30:09 +00:00
|
|
|
void WriteEquationsExceptFor(hConstraint hc, Group *g);
|
|
|
|
void FindWhichToRemoveToFixJacobian(Group *g, List<hConstraint> *bad);
|
2016-05-05 05:54:05 +00:00
|
|
|
void SolveBySubstitution();
|
2008-05-07 07:10:20 +00:00
|
|
|
|
2009-04-20 07:30:09 +00:00
|
|
|
bool IsDragged(hParam p);
|
2008-05-01 06:25:38 +00:00
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
bool NewtonSolve(int tag);
|
2009-04-20 07:30:09 +00:00
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
SolveResult Solve(Group *g, int *dof, List<hConstraint> *bad,
|
2009-04-21 07:56:17 +00:00
|
|
|
bool andFindBad, bool andFindFree);
|
2013-09-19 04:33:12 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void Clear();
|
2008-04-20 11:35:10 +00:00
|
|
|
};
|
|
|
|
|
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-01-30 01:42:44 +00:00
|
|
|
#include "ttf.h"
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2009-06-11 05:57:23 +00:00
|
|
|
class StepFileWriter {
|
|
|
|
public:
|
2015-12-27 01:03:24 +00:00
|
|
|
void ExportSurfacesTo(const std::string &filename);
|
2016-05-05 05:54:05 +00:00
|
|
|
void WriteHeader();
|
|
|
|
void WriteProductHeader();
|
2009-06-11 05:57:23 +00:00
|
|
|
int ExportCurve(SBezier *sb);
|
|
|
|
int ExportCurveLoop(SBezierLoop *loop, bool inner);
|
2009-10-12 09:28:34 +00:00
|
|
|
void ExportSurface(SSurface *ss, SBezierList *sbl);
|
2016-05-05 05:54:05 +00:00
|
|
|
void WriteWireframe();
|
|
|
|
void WriteFooter();
|
2009-06-11 05:57:23 +00:00
|
|
|
|
|
|
|
List<int> curves;
|
|
|
|
List<int> advancedFaces;
|
|
|
|
FILE *f;
|
|
|
|
int id;
|
|
|
|
};
|
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
class VectorFileWriter {
|
2016-01-06 12:40:17 +00:00
|
|
|
protected:
|
|
|
|
Vector u, v, n, origin;
|
|
|
|
double cameraTan, scale;
|
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
public:
|
|
|
|
FILE *f;
|
2015-12-25 08:29:08 +00:00
|
|
|
std::string filename;
|
2009-01-27 05:48:40 +00:00
|
|
|
Vector ptMin, ptMax;
|
2009-07-03 20:55:57 +00:00
|
|
|
|
2009-04-15 06:50:06 +00:00
|
|
|
static double MmToPts(double mm);
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
static VectorFileWriter *ForFile(const std::string &filename);
|
2009-01-14 05:10:42 +00:00
|
|
|
|
2016-01-06 12:40:17 +00:00
|
|
|
void SetModelviewProjection(const Vector &u, const Vector &v, const Vector &n,
|
|
|
|
const Vector &origin, double cameraTan, double scale);
|
|
|
|
Vector Transform(Vector &pos) const;
|
|
|
|
|
|
|
|
void OutputLinesAndMesh(SBezierLoopSetSet *sblss, SMesh *sm);
|
2009-01-27 05:48:40 +00:00
|
|
|
|
2009-10-30 10:38:34 +00:00
|
|
|
void BezierAsPwl(SBezier *sb);
|
|
|
|
void BezierAsNonrationalCubic(SBezier *sb, int depth=0);
|
2009-09-22 05:46:30 +00:00
|
|
|
|
2016-05-21 05:18:00 +00:00
|
|
|
virtual void StartPath(RgbaColor strokeRgb, double lineWidth,
|
2016-04-12 23:57:49 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) = 0;
|
2015-07-10 11:54:39 +00:00
|
|
|
virtual void FinishPath(RgbaColor strokeRgb, double lineWidth,
|
2016-04-12 23:57:49 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) = 0;
|
2009-10-30 10:38:34 +00:00
|
|
|
virtual void Bezier(SBezier *sb) = 0;
|
2009-03-17 16:33:46 +00:00
|
|
|
virtual void Triangle(STriangle *tr) = 0;
|
2016-05-18 18:42:33 +00:00
|
|
|
virtual bool OutputConstraints(IdList<Constraint,hConstraint> *) { return false; }
|
|
|
|
virtual void StartFile() = 0;
|
|
|
|
virtual void FinishAndCloseFile() = 0;
|
|
|
|
virtual bool HasCanvasSize() const = 0;
|
|
|
|
virtual bool CanOutputMesh() const = 0;
|
2009-01-14 05:10:42 +00:00
|
|
|
};
|
|
|
|
class DxfFileWriter : public VectorFileWriter {
|
|
|
|
public:
|
2015-12-28 10:50:38 +00:00
|
|
|
struct BezierPath {
|
|
|
|
std::vector<SBezier *> beziers;
|
|
|
|
};
|
|
|
|
|
2016-01-06 12:40:17 +00:00
|
|
|
std::vector<BezierPath> paths;
|
|
|
|
IdList<Constraint,hConstraint> *constraint;
|
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
static const char *lineTypeName(StipplePattern stippleType);
|
2016-05-18 18:42:33 +00:00
|
|
|
|
|
|
|
bool OutputConstraints(IdList<Constraint,hConstraint> *constraint) override;
|
2015-12-28 10:50:38 +00:00
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
void StartPath( RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
2015-07-10 11:54:39 +00:00
|
|
|
void FinishPath(RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
|
|
|
void Triangle(STriangle *tr) override;
|
|
|
|
void Bezier(SBezier *sb) override;
|
|
|
|
void StartFile() override;
|
|
|
|
void FinishAndCloseFile() override;
|
|
|
|
bool HasCanvasSize() const override { return false; }
|
|
|
|
bool CanOutputMesh() const override { return false; }
|
2016-03-24 13:55:36 +00:00
|
|
|
bool NeedToOutput(Constraint *c);
|
2009-01-27 05:48:40 +00:00
|
|
|
};
|
|
|
|
class EpsFileWriter : public VectorFileWriter {
|
|
|
|
public:
|
2009-10-30 10:38:34 +00:00
|
|
|
Vector prevPt;
|
|
|
|
void MaybeMoveTo(Vector s, Vector f);
|
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
void StartPath( RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
2015-07-10 11:54:39 +00:00
|
|
|
void FinishPath(RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
|
|
|
void Triangle(STriangle *tr) override;
|
|
|
|
void Bezier(SBezier *sb) override;
|
|
|
|
void StartFile() override;
|
|
|
|
void FinishAndCloseFile() override;
|
|
|
|
bool HasCanvasSize() const override { return true; }
|
|
|
|
bool CanOutputMesh() const override { return true; }
|
2009-04-15 06:50:06 +00:00
|
|
|
};
|
|
|
|
class PdfFileWriter : public VectorFileWriter {
|
|
|
|
public:
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
uint32_t xref[10];
|
|
|
|
uint32_t bodyStart;
|
2009-10-30 10:38:34 +00:00
|
|
|
Vector prevPt;
|
|
|
|
void MaybeMoveTo(Vector s, Vector f);
|
2009-04-15 06:50:06 +00:00
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
void StartPath( RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
2015-07-10 11:54:39 +00:00
|
|
|
void FinishPath(RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
|
|
|
void Triangle(STriangle *tr) override;
|
|
|
|
void Bezier(SBezier *sb) override;
|
|
|
|
void StartFile() override;
|
|
|
|
void FinishAndCloseFile() override;
|
|
|
|
bool HasCanvasSize() const override { return true; }
|
|
|
|
bool CanOutputMesh() const override { return true; }
|
2009-01-27 05:48:40 +00:00
|
|
|
};
|
|
|
|
class SvgFileWriter : public VectorFileWriter {
|
|
|
|
public:
|
2009-10-30 10:38:34 +00:00
|
|
|
Vector prevPt;
|
|
|
|
void MaybeMoveTo(Vector s, Vector f);
|
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
void StartPath( RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
2015-07-10 11:54:39 +00:00
|
|
|
void FinishPath(RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
|
|
|
void Triangle(STriangle *tr) override;
|
|
|
|
void Bezier(SBezier *sb) override;
|
|
|
|
void StartFile() override;
|
|
|
|
void FinishAndCloseFile() override;
|
|
|
|
bool HasCanvasSize() const override { return true; }
|
|
|
|
bool CanOutputMesh() const override { return true; }
|
2009-01-27 05:48:40 +00:00
|
|
|
};
|
|
|
|
class HpglFileWriter : public VectorFileWriter {
|
|
|
|
public:
|
|
|
|
static double MmToHpglUnits(double mm);
|
2015-07-10 11:54:39 +00:00
|
|
|
void StartPath( RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
2015-07-10 11:54:39 +00:00
|
|
|
void FinishPath(RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
|
|
|
void Triangle(STriangle *tr) override;
|
|
|
|
void Bezier(SBezier *sb) override;
|
|
|
|
void StartFile() override;
|
|
|
|
void FinishAndCloseFile() override;
|
|
|
|
bool HasCanvasSize() const override { return false; }
|
|
|
|
bool CanOutputMesh() const override { return false; }
|
2009-01-14 05:10:42 +00:00
|
|
|
};
|
2009-06-11 05:57:23 +00:00
|
|
|
class Step2dFileWriter : public VectorFileWriter {
|
|
|
|
StepFileWriter sfw;
|
2015-07-10 11:54:39 +00:00
|
|
|
void StartPath( RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
2015-07-10 11:54:39 +00:00
|
|
|
void FinishPath(RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
|
|
|
void Triangle(STriangle *tr) override;
|
|
|
|
void Bezier(SBezier *sb) override;
|
|
|
|
void StartFile() override;
|
|
|
|
void FinishAndCloseFile() override;
|
|
|
|
bool HasCanvasSize() const override { return false; }
|
|
|
|
bool CanOutputMesh() const override { return false; }
|
2009-06-08 06:50:16 +00:00
|
|
|
};
|
2010-01-14 04:47:17 +00:00
|
|
|
class GCodeFileWriter : public VectorFileWriter {
|
|
|
|
public:
|
|
|
|
SEdgeList sel;
|
2015-07-10 11:54:39 +00:00
|
|
|
void StartPath( RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
2015-07-10 11:54:39 +00:00
|
|
|
void FinishPath(RgbaColor strokeRgb, double lineWidth,
|
2016-05-18 18:42:33 +00:00
|
|
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
|
|
|
void Triangle(STriangle *tr) override;
|
|
|
|
void Bezier(SBezier *sb) override;
|
|
|
|
void StartFile() override;
|
|
|
|
void FinishAndCloseFile() override;
|
|
|
|
bool HasCanvasSize() const override { return false; }
|
|
|
|
bool CanOutputMesh() const override { return false; }
|
2010-01-14 04:47:17 +00:00
|
|
|
};
|
2009-06-08 06:50:16 +00:00
|
|
|
|
2009-04-20 07:30:09 +00:00
|
|
|
#ifdef LIBRARY
|
|
|
|
# define ENTITY EntityBase
|
|
|
|
# define CONSTRAINT ConstraintBase
|
|
|
|
#else
|
|
|
|
# define ENTITY Entity
|
|
|
|
# define CONSTRAINT Constraint
|
|
|
|
#endif
|
2009-04-19 05:53:16 +00:00
|
|
|
class Sketch {
|
2008-03-28 10:00:37 +00:00
|
|
|
public:
|
2009-04-19 05:53:16 +00:00
|
|
|
// These are user-editable, and define the sketch.
|
2008-04-14 10:28:32 +00:00
|
|
|
IdList<Group,hGroup> group;
|
2016-02-17 10:03:07 +00:00
|
|
|
List<hGroup> groupOrder;
|
2009-04-20 07:30:09 +00:00
|
|
|
IdList<CONSTRAINT,hConstraint> constraint;
|
2009-04-19 05:53:16 +00:00
|
|
|
IdList<Request,hRequest> request;
|
2009-09-17 07:32:36 +00:00
|
|
|
IdList<Style,hStyle> style;
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
// These are generated from the above.
|
2009-04-20 07:30:09 +00:00
|
|
|
IdList<ENTITY,hEntity> entity;
|
2008-04-14 10:28:32 +00:00
|
|
|
IdList<Param,hParam> param;
|
|
|
|
|
2009-04-20 07:30:09 +00:00
|
|
|
inline CONSTRAINT *GetConstraint(hConstraint h)
|
2008-04-14 10:28:32 +00:00
|
|
|
{ return constraint.FindById(h); }
|
2009-04-20 07:30:09 +00:00
|
|
|
inline ENTITY *GetEntity (hEntity h) { return entity. FindById(h); }
|
2008-04-14 10:28:32 +00:00
|
|
|
inline Param *GetParam (hParam h) { return param. FindById(h); }
|
2009-04-19 05:53:16 +00:00
|
|
|
inline Request *GetRequest(hRequest h) { return request.FindById(h); }
|
2008-04-20 11:35:10 +00:00
|
|
|
inline Group *GetGroup (hGroup h) { return group. FindById(h); }
|
2009-09-17 07:32:36 +00:00
|
|
|
// Styles are handled a bit differently.
|
2013-09-19 04:33:12 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void Clear();
|
2016-01-23 08:05:02 +00:00
|
|
|
|
|
|
|
BBox CalculateEntityBBox(bool includingInvisible);
|
2016-04-10 11:25:26 +00:00
|
|
|
Group *GetRunningMeshGroupFor(hGroup h);
|
2009-04-19 05:53:16 +00:00
|
|
|
};
|
2009-09-17 07:32:36 +00:00
|
|
|
#undef ENTITY
|
|
|
|
#undef CONSTRAINT
|
2009-04-19 05:53:16 +00:00
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
class SolveSpaceUI {
|
2009-04-19 05:53:16 +00:00
|
|
|
public:
|
2016-04-20 07:50:41 +00:00
|
|
|
TextWindow *pTW;
|
|
|
|
TextWindow &TW;
|
2009-04-19 05:53:16 +00:00
|
|
|
GraphicsWindow GW;
|
2008-04-13 14:28:35 +00:00
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
// The state for undo/redo
|
|
|
|
typedef struct {
|
|
|
|
IdList<Group,hGroup> group;
|
2016-02-17 10:03:07 +00:00
|
|
|
List<hGroup> groupOrder;
|
2008-06-04 10:22:30 +00:00
|
|
|
IdList<Request,hRequest> request;
|
|
|
|
IdList<Constraint,hConstraint> constraint;
|
|
|
|
IdList<Param,hParam> param;
|
2009-09-17 07:32:36 +00:00
|
|
|
IdList<Style,hStyle> style;
|
2008-06-04 10:22:30 +00:00
|
|
|
hGroup activeGroup;
|
2013-09-19 04:33:12 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void Clear() {
|
2013-09-19 04:33:12 +00:00
|
|
|
group.Clear();
|
|
|
|
request.Clear();
|
|
|
|
constraint.Clear();
|
|
|
|
param.Clear();
|
|
|
|
style.Clear();
|
|
|
|
}
|
2008-06-04 10:22:30 +00:00
|
|
|
} UndoState;
|
2013-09-09 19:50:32 +00:00
|
|
|
enum { MAX_UNDO = 16 };
|
2008-06-04 10:22:30 +00:00
|
|
|
typedef struct {
|
|
|
|
UndoState d[MAX_UNDO];
|
|
|
|
int cnt;
|
|
|
|
int write;
|
|
|
|
} UndoStack;
|
|
|
|
UndoStack undo;
|
|
|
|
UndoStack redo;
|
2016-05-05 05:54:05 +00:00
|
|
|
void UndoEnableMenus();
|
|
|
|
void UndoRemember();
|
|
|
|
void UndoUndo();
|
|
|
|
void UndoRedo();
|
2008-06-04 10:22:30 +00:00
|
|
|
void PushFromCurrentOnto(UndoStack *uk);
|
|
|
|
void PopOntoCurrentFrom(UndoStack *uk);
|
|
|
|
void UndoClearState(UndoState *ut);
|
|
|
|
void UndoClearStack(UndoStack *uk);
|
|
|
|
|
2008-06-11 04:22:52 +00:00
|
|
|
// Little bits of extra configuration state
|
2013-09-09 19:50:32 +00:00
|
|
|
enum { MODEL_COLORS = 8 };
|
2015-07-10 11:54:39 +00:00
|
|
|
RgbaColor modelColor[MODEL_COLORS];
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
Vector lightDir[2];
|
|
|
|
double lightIntensity[2];
|
|
|
|
double ambientIntensity;
|
|
|
|
double chordTol;
|
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-01-29 10:33:56 +00:00
|
|
|
double chordTolCalculated;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
int maxSegments;
|
2016-01-27 04:07:54 +00:00
|
|
|
double exportChordTol;
|
|
|
|
int exportMaxSegments;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
double cameraTangent;
|
|
|
|
float gridSpacing;
|
|
|
|
float exportScale;
|
|
|
|
float exportOffset;
|
|
|
|
bool fixExportColors;
|
|
|
|
bool drawBackFaces;
|
|
|
|
bool checkClosedContour;
|
|
|
|
bool showToolbar;
|
2015-07-10 11:54:39 +00:00
|
|
|
RgbaColor backgroundColor;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
bool exportShadedTriangles;
|
|
|
|
bool exportPwlCurves;
|
|
|
|
bool exportCanvasSizeAuto;
|
2016-01-27 04:07:54 +00:00
|
|
|
bool exportMode;
|
2009-09-03 08:13:09 +00:00
|
|
|
struct {
|
|
|
|
float left;
|
|
|
|
float right;
|
|
|
|
float bottom;
|
|
|
|
float top;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
} exportMargin;
|
2009-09-03 08:13:09 +00:00
|
|
|
struct {
|
|
|
|
float width;
|
|
|
|
float height;
|
|
|
|
float dx;
|
|
|
|
float dy;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
} exportCanvas;
|
2010-01-14 04:47:17 +00:00
|
|
|
struct {
|
|
|
|
float depth;
|
|
|
|
int passes;
|
|
|
|
float feed;
|
|
|
|
float plungeFeed;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
} gCode;
|
2008-07-06 07:56:24 +00:00
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
Unit viewUnits;
|
|
|
|
int afterDecimalMm;
|
|
|
|
int afterDecimalInch;
|
2015-03-29 04:46:57 +00:00
|
|
|
int autosaveInterval; // in minutes
|
2010-09-24 02:58:34 +00:00
|
|
|
|
2015-11-06 08:40:12 +00:00
|
|
|
std::string MmToString(double v);
|
2008-06-14 09:51:25 +00:00
|
|
|
double ExprToMm(Expr *e);
|
2015-11-06 08:40:12 +00:00
|
|
|
double StringToMm(const std::string &s);
|
2016-05-05 05:54:05 +00:00
|
|
|
const char *UnitName();
|
|
|
|
double MmPerUnit();
|
|
|
|
int UnitDigitsAfterDecimal();
|
2010-09-24 02:58:34 +00:00
|
|
|
void SetUnitDigitsAfterDecimal(int v);
|
2016-05-05 05:54:05 +00:00
|
|
|
double ChordTolMm();
|
|
|
|
double ExportChordTolMm();
|
|
|
|
int GetMaxSegments();
|
2010-05-03 05:15:28 +00:00
|
|
|
bool usePerspectiveProj;
|
2016-05-05 05:54:05 +00:00
|
|
|
double CameraTangent();
|
2008-06-14 09:51:25 +00:00
|
|
|
|
2010-05-16 16:36:23 +00:00
|
|
|
// Some stuff relating to the tangent arcs created non-parametrically
|
|
|
|
// as special requests.
|
|
|
|
double tangentArcRadius;
|
|
|
|
bool tangentArcManual;
|
|
|
|
bool tangentArcDeleteOld;
|
|
|
|
|
2008-06-14 09:51:25 +00:00
|
|
|
// The platform-dependent code calls this before entering the msg loop
|
2016-05-05 05:54:05 +00:00
|
|
|
void Init();
|
2015-12-27 01:03:24 +00:00
|
|
|
bool OpenFile(const std::string &filename);
|
2016-05-05 05:54:05 +00:00
|
|
|
void Exit();
|
2008-06-11 04:22:52 +00:00
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
// File load/save routines, including the additional files that get
|
2016-05-07 05:27:54 +00:00
|
|
|
// loaded when we have link groups.
|
2008-04-18 11:11:48 +00:00
|
|
|
FILE *fh;
|
2016-05-05 05:54:05 +00:00
|
|
|
void AfterNewFile();
|
2015-12-27 01:03:24 +00:00
|
|
|
static void RemoveFromRecentList(const std::string &filename);
|
|
|
|
static void AddToRecentList(const std::string &filename);
|
|
|
|
std::string saveFile;
|
|
|
|
bool fileLoadError;
|
|
|
|
bool unsaved;
|
2008-04-24 06:22:16 +00:00
|
|
|
typedef struct {
|
2013-08-26 18:58:35 +00:00
|
|
|
char type;
|
|
|
|
const char *desc;
|
|
|
|
char fmt;
|
|
|
|
void *ptr;
|
2008-04-24 06:22:16 +00:00
|
|
|
} SaveTable;
|
|
|
|
static const SaveTable SAVED[];
|
|
|
|
void SaveUsingTable(int type);
|
2008-04-27 10:01:23 +00:00
|
|
|
void LoadUsingTable(char *key, char *val);
|
2008-04-24 06:22:16 +00:00
|
|
|
struct {
|
|
|
|
Group g;
|
|
|
|
Request r;
|
|
|
|
Entity e;
|
|
|
|
Param p;
|
|
|
|
Constraint c;
|
2009-09-17 07:32:36 +00:00
|
|
|
Style s;
|
2008-04-24 06:22:16 +00:00
|
|
|
} sv;
|
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-20 08:31:20 +00:00
|
|
|
static void MenuFile(Command id);
|
2015-03-29 04:46:57 +00:00
|
|
|
bool Autosave();
|
|
|
|
void RemoveAutosave();
|
2008-06-03 18:28:41 +00:00
|
|
|
bool GetFilenameAndSave(bool saveAs);
|
2016-05-05 05:54:05 +00:00
|
|
|
bool OkayToStartNewFile();
|
|
|
|
hGroup CreateDefaultDrawingGroup();
|
|
|
|
void UpdateWindowTitle();
|
|
|
|
void ClearExisting();
|
|
|
|
void NewFile();
|
2015-12-27 01:03:24 +00:00
|
|
|
bool SaveToFile(const std::string &filename);
|
|
|
|
bool LoadAutosaveFor(const std::string &filename);
|
|
|
|
bool LoadFromFile(const std::string &filename);
|
2016-10-11 01:58:04 +00:00
|
|
|
void UpgradeLegacyData();
|
2015-12-27 01:03:24 +00:00
|
|
|
bool LoadEntitiesFromFile(const std::string &filename, EntityList *le,
|
2015-03-18 17:02:11 +00:00
|
|
|
SMesh *m, SShell *sh);
|
2016-01-11 12:18:18 +00:00
|
|
|
bool ReloadAllImported(bool canCancel=false);
|
2008-07-06 09:24:31 +00:00
|
|
|
// And the various export options
|
2015-12-27 01:03:24 +00:00
|
|
|
void ExportAsPngTo(const std::string &filename);
|
|
|
|
void ExportMeshTo(const std::string &filename);
|
2009-10-12 11:34:43 +00:00
|
|
|
void ExportMeshAsStlTo(FILE *f, SMesh *sm);
|
2016-07-04 06:02:30 +00:00
|
|
|
void ExportMeshAsObjTo(FILE *fObj, FILE *fMtl, SMesh *sm);
|
2016-01-11 10:53:04 +00:00
|
|
|
void ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
|
2016-06-26 06:39:27 +00:00
|
|
|
SMesh *sm, SOutlineList *sol);
|
2016-05-25 12:08:19 +00:00
|
|
|
void ExportViewOrWireframeTo(const std::string &filename, bool exportWireframe);
|
2015-12-27 01:03:24 +00:00
|
|
|
void ExportSectionTo(const std::string &filename);
|
2009-10-12 10:40:48 +00:00
|
|
|
void ExportWireframeCurves(SEdgeList *sel, SBezierList *sbl,
|
|
|
|
VectorFileWriter *out);
|
2009-04-14 04:19:23 +00:00
|
|
|
void ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *sm,
|
2016-05-21 05:18:00 +00:00
|
|
|
Vector u, Vector v,
|
|
|
|
Vector n, Vector origin,
|
|
|
|
double cameraTan,
|
2009-03-17 16:33:46 +00:00
|
|
|
VectorFileWriter *out);
|
2008-04-20 11:35:10 +00:00
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
static void MenuAnalyze(Command id);
|
2009-11-08 01:11:38 +00:00
|
|
|
|
|
|
|
// Additional display stuff
|
2008-07-20 11:27:22 +00:00
|
|
|
struct {
|
|
|
|
SContour path;
|
|
|
|
hEntity point;
|
|
|
|
} traced;
|
2009-01-25 09:19:59 +00:00
|
|
|
SEdgeList nakedEdges;
|
2010-01-04 00:35:28 +00:00
|
|
|
struct {
|
|
|
|
bool draw;
|
|
|
|
Vector ptA;
|
|
|
|
Vector ptB;
|
|
|
|
} extraLine;
|
2009-11-08 01:11:38 +00:00
|
|
|
struct {
|
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-05-31 00:55:13 +00:00
|
|
|
std::shared_ptr<Pixmap> pixmap;
|
2009-11-08 01:11:38 +00:00
|
|
|
double scale; // pixels per mm
|
|
|
|
Vector origin;
|
|
|
|
} bgImage;
|
2010-01-14 05:24:32 +00:00
|
|
|
struct {
|
2016-01-27 04:07:54 +00:00
|
|
|
bool draw, showOrigin;
|
2010-01-14 05:24:32 +00:00
|
|
|
Vector pt, u, v;
|
|
|
|
} justExportedInfo;
|
2008-07-20 11:27:22 +00:00
|
|
|
|
2009-12-04 08:08:41 +00:00
|
|
|
class Clipboard {
|
2015-12-30 12:36:31 +00:00
|
|
|
public:
|
2009-12-04 08:08:41 +00:00
|
|
|
List<ClipboardRequest> r;
|
|
|
|
List<Constraint> c;
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void Clear();
|
2009-12-04 08:08:41 +00:00
|
|
|
bool ContainsEntity(hEntity old);
|
|
|
|
hEntity NewEntityFor(hEntity old);
|
|
|
|
};
|
|
|
|
Clipboard clipboard;
|
|
|
|
|
2008-06-02 09:31:26 +00:00
|
|
|
void MarkGroupDirty(hGroup hg);
|
2008-06-02 11:43:27 +00:00
|
|
|
void MarkGroupDirtyByEntity(hEntity he);
|
2008-06-02 09:31:26 +00:00
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
// Consistency checking on the sketch: stuff with missing dependencies
|
|
|
|
// will get deleted automatically.
|
2008-05-17 06:04:55 +00:00
|
|
|
struct {
|
|
|
|
int requests;
|
|
|
|
int groups;
|
|
|
|
int constraints;
|
2009-01-03 12:27:33 +00:00
|
|
|
int nonTrivialConstraints;
|
2008-05-17 06:04:55 +00:00
|
|
|
} deleted;
|
|
|
|
bool GroupExists(hGroup hg);
|
2016-05-05 05:54:05 +00:00
|
|
|
bool PruneOrphans();
|
2008-05-17 06:04:55 +00:00
|
|
|
bool EntityExists(hEntity he);
|
|
|
|
bool GroupsInOrder(hGroup before, hGroup after);
|
|
|
|
bool PruneGroups(hGroup hg);
|
|
|
|
bool PruneRequests(hGroup hg);
|
|
|
|
bool PruneConstraints(hGroup hg);
|
2008-04-27 09:03:01 +00:00
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
enum class Generate : uint32_t {
|
|
|
|
DIRTY,
|
|
|
|
ALL,
|
|
|
|
REGEN,
|
|
|
|
UNTIL_ACTIVE,
|
2016-01-27 09:09:45 +00:00
|
|
|
};
|
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-01-30 01:42:44 +00:00
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
void GenerateAll(Generate type = Generate::DIRTY, bool andFindFree = false,
|
2016-02-17 10:03:07 +00:00
|
|
|
bool genForBBox = false);
|
2009-01-04 12:01:46 +00:00
|
|
|
void SolveGroup(hGroup hg, bool andFindFree);
|
2016-10-13 13:51:11 +00:00
|
|
|
void SolveGroupAndReport(hGroup hg, bool andFindFree);
|
2016-05-05 05:54:05 +00:00
|
|
|
void MarkDraggedParams();
|
|
|
|
void ForceReferences();
|
2008-04-27 09:03:01 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
bool ActiveGroupsOkay();
|
2008-07-20 11:27:22 +00:00
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
// The system to be solved.
|
2016-04-20 07:50:41 +00:00
|
|
|
System *pSys;
|
|
|
|
System &sys;
|
2008-06-03 18:28:41 +00:00
|
|
|
|
2008-06-30 09:09:17 +00:00
|
|
|
// All the TrueType fonts in memory
|
|
|
|
TtfFontList fonts;
|
|
|
|
|
2008-06-25 05:14:49 +00:00
|
|
|
// Everything has been pruned, so we know there's no dangling references
|
|
|
|
// to entities that don't exist. Before that, we mustn't try to display
|
|
|
|
// the sketch!
|
|
|
|
bool allConsistent;
|
|
|
|
|
2008-06-03 18:28:41 +00:00
|
|
|
struct {
|
2015-03-18 17:02:11 +00:00
|
|
|
bool scheduled;
|
2008-06-03 18:28:41 +00:00
|
|
|
bool showTW;
|
|
|
|
bool generateAll;
|
|
|
|
} later;
|
2015-03-18 17:02:11 +00:00
|
|
|
void ScheduleShowTW();
|
|
|
|
void ScheduleGenerateAll();
|
2016-05-05 05:54:05 +00:00
|
|
|
void DoLater();
|
2008-02-09 13:52:01 +00:00
|
|
|
|
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-20 08:31:20 +00:00
|
|
|
static void MenuHelp(Command id);
|
2013-09-19 04:33:12 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void Clear();
|
2016-04-20 07:50:41 +00:00
|
|
|
|
|
|
|
// We allocate TW and sys on the heap to work around an MSVC problem
|
|
|
|
// where it puts zero-initialized global data in the binary (~30M of zeroes)
|
|
|
|
// in release builds.
|
|
|
|
SolveSpaceUI()
|
|
|
|
: pTW(new TextWindow({})), TW(*pTW),
|
|
|
|
pSys(new System({})), sys(*pSys) {}
|
|
|
|
|
|
|
|
~SolveSpaceUI() {
|
|
|
|
delete pTW;
|
|
|
|
delete pSys;
|
|
|
|
}
|
2008-03-28 10:00:37 +00:00
|
|
|
};
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2016-04-13 08:43:06 +00:00
|
|
|
void ImportDxf(const std::string &file);
|
2016-05-07 05:17:23 +00:00
|
|
|
void ImportDwg(const std::string &file);
|
2016-04-13 08:43:06 +00:00
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
extern SolveSpaceUI SS;
|
2009-04-19 05:53:16 +00:00
|
|
|
extern Sketch SK;
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2016-05-21 05:18:00 +00:00
|
|
|
}
|
2015-03-23 17:49:04 +00:00
|
|
|
|
|
|
|
#ifndef __OBJC__
|
|
|
|
using namespace SolveSpace;
|
|
|
|
#endif
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
#endif
|