Commit Graph

1737 Commits (f4ad82055e00c02d9ece2cab4730a1104de2e423)

Author SHA1 Message Date
Daniel Richard G 0afb5618ce Quash warnings for floating-point equality comparisons
GCC and Clang's -Wfloat-equal warning notes that comparing floating-point
values with == or != may be questionable. But the few instances of these in
SolveSpace are defensibly correct (as discussed with Jonathan), so to keep
folks from getting nervous that a CAD application isn't handling its floats
correctly, we define an EXACT() macro inside which the -Wfloat-equal
warning is disabled. This macro will also serve as a source-code
annotation, like a comment but better.

(The warning is only disabled for Clang, alas, because GCC is particular
about where _Pragma() can be used. This isn't so bad, however, because the
warning is much easier to enable on Clang [thanks to -Weverything], whereas
with GCC it has to be requested explicitly.)
2013-10-28 00:43:37 -04:00
Daniel Richard G 8bc322eb47 Various fixes for warnings and minutia
This commit consists of numerous small changes, none significant enough to
merit a commit on their own:

* Added extra braces to quash for-loop variable scoping issues for older
  compilers (or "g++ -fno-for-scope")

* Appeased "unreachable code" warnings, spurious or otherwise

* Added casts to fix integer-variable signedness warnings

* Added a dummy virtual method to the VectorFileWriter class to silence the
  -Wweak-vtables warning from Clang++

* Renamed some parameters in the Expr and GraphicsWindow classes to
  eliminate "parameter shadows a field" warnings

* Removed an inert "0 ||" from a conditional, and changed a "&& 0" into an
  "#if 0"

* Added missing elements to array/struct/class initializers to zap further
  warnings

* Indented some cpp conditionals where appropriate

* Qualified some variables and functions as static to quiet "no previous
  declaration" warnings

* toolbar.cpp needed to #include<icons-proto.h> to fix those same "no
  previous declaration" warnings from icons.h

* Added some casts and const qualifiers to the Win32 code to address
  warnings produced by g++ when compiling under MinGW

* Rewrote Cnf{Freeze,Thaw}Float() to use a union rather than pointer
  aliasing; this makes g++ a lot happier

* Removed redundant #includes from win32/w32util.cpp

* With Jonathan's blessing, shortened the last line of the About dialog
  text to better match the preceding lines
2013-10-28 00:42:39 -04:00
Daniel Richard G a5176f4545 Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)

Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.

RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.

(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)

Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.

(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)

In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-25 01:49:12 -04:00
Daniel Richard G dd168ad22c 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 01:45:13 -04:00
Jonathan Westhues 505e3d869c Update Help -> About to note that license is GPLv3. 2013-09-22 03:50:59 -07:00
Daniel Richard G e7f3a3c0db Build fix for Visual Studio 2003
INT_MAX was not being defined, so #include <limits.h>.
2013-09-20 21:38:53 -04:00
Daniel Richard G fb766d1cf9 Make optional the use of the SpaceNavigator libraries 2013-09-20 15:25:14 -04:00
Daniel Richard G 3cfe6b6da1 Synthesize accelerator labels (e.g. "Ctrl+S") instead of hard-coding them
GraphicsWindow::menu[] previously recorded both item names (e.g. "Open...")
and accelerator labels ("Ctrl+O") in .label, and accelerator key/mask
values in .accel. Not only were the accelerator labels redundant given the
latter, they are not needed by GUI toolkits like FLTK, which generate them
from key/mask values.

So we remove the accelerator portion from each menu-item label, and define
a new MakeAcceleratorLabel() routine which takes a key/mask value and
returns the appropriate label. We make use of this new routine in
CreateGraphicsWindowMenus() and GraphicsWindow::ToolbarDrawOrHitTest().
2013-09-20 15:01:00 -04:00
Daniel Richard G 2499a02f2f Minor changes to GraphicsWindow::menu[]
* Added a comment header identifying the columns

* Added Ctrl-Q accelerator for "Exit", as this is standard

* Replaced a Latin-1 "degree" character with an octal escape, to avoid
  source-file encoding issues

* Undefine (some of) the convenience macros used to define the table
  (the method aliases are numerous and unlikely to collide with anything)
2013-09-20 14:34:03 -04:00
Daniel Richard G 4a2711476c Record accelerator for "Show Snap Grid" as '>' instead of Shift-'.'
If we are to synthesize accelerator labels from values of
GraphicsWindow::menu[].accel, it will be more straightforward if
accelerators are represented in the same way that they appear in the menu.
(Windows does return the keystroke as VK_OEM_PERIOD with a Shift modifier,
so we add some special-case logic to recognize that.)
2013-09-20 14:01:31 -04:00
Daniel Richard G 9da2a3a6c7 Use symbolic names for special keys and modifiers
Easier to remember e.g. DELETE_KEY instead of 127 or CTRL_MASK instead of
0x200, and better to have a single definition of each.
2013-09-20 13:54:57 -04:00
Daniel Richard G 37063840db Don't use magic values in GraphicsWindow::menu[].level
We can identify the "Open Recent" and "Import Recent" submenus just as
easily by looking at the value of the .id field (MNU_OPEN_RECENT and
MNU_GROUP_RECENT, respectively).
2013-09-20 13:40:17 -04:00
Daniel Richard G 66758b9595 Miscellaneous adjustments for warnings and code quality
This commit contains a grab bag of minor changes not worth committing
individually:

* Replaced raw Latin-1 characters with octal escapes to avoid source-file
  encoding issues

* Undefined some convenience macros after they've served their purpose

* Rewrote SEdge::From() to avoid confusing less-capable C++ compilers

* Have oops() print a newline at the end of its message

* Removed "static" keyword from the Bernstein() function definition, as it
  has a non-static prototype in srf/surface.h

* Added casts (and changed a variable type) to quell warnings about integer
  size and signedness

* Simplified an expression with our handy arraylen() macro
2013-09-19 02:35:56 -04:00
Daniel Richard G 07b128b877 Define some menu-bar menu items as radio buttons
Some menu items in the menu-bar are toggles (each representing an option
that can be turned on or off independently), and some are 1-of-N selections
(e.g. mm or inches), like tuner buttons on a car radio. Windows can draw an
optional check-mark besides a menu item, and SolveSpace has been using this
feature to implement both kinds of menu items, with the backend logic
making them behave as a toggle or radio button as appropriate.

Other GUI platforms can draw proper radio-button menu items that are
distinct from toggles, however. To allow the platform-specific logic to
tell the two kinds of menu items apart, this change adds the
RadioMenuById() routine, and replaces the appropriate calls to
CheckMenuById() with it. (Note that nothing is changed in the Windows GUI
code; radio-menu items are still drawn with check-marks.)
2013-09-19 00:59:18 -04:00
Daniel Richard G 30ca4ec8ac Use a '*' printf() field width rather than an intermediate format string 2013-09-19 00:50:11 -04:00
Daniel Richard G 16179f34cd Enabled freeing of (most) allocated memory on program exit
The Valgrind tool can give a full accounting of what memory allocations
have yet to be free()d when the program exits. It is easier to find actual
memory leaks in the code if all non-leaked allocations are elided from that
accounting, which is most easily accomplished by free()ing them.

The "most" qualifier is there because some allocations are difficult/
impossible to free, as they are internal to libraries like OpenGL and Xft.
The best we can hope for is to cover all allocations made by SolveSpace
directly.
2013-09-19 00:33:12 -04:00
Daniel Richard G 42a46e83fa Use system-agnostic return values for SaveFileYesNoCancel()
This function was returning ID{YES,NO,CANCEL}, which are specific to
Windows as return values for MessageBox(). These have been replaced with
SAVE_{YES,NO,CANCEL}, which we define ourselves.
2013-09-18 16:49:32 -04:00
Daniel Richard G 70b6bad551 Use '\b' instead of ('h' - 'a' + 1) 2013-09-18 16:41:23 -04:00
Daniel Richard G 718d411699 Renamed *.table files to *.table.h
The *.table files are in fact C header files, and with an *.h extension,
tools will be able to recognize them as such
2013-09-16 17:14:53 -04:00
Daniel Richard G 93145387f4 Fixed uninitialized-memory errors detected by Valgrind 2013-09-16 16:22:14 -04:00
Daniel Richard G 44a3981fbf Use png_get_image_{width,height}() instead of info_ptr->{width,height}
Later versions of libpng (1.5.x) have made the png_info structure opaque,
breaking direct access to its fields. Fortunately, the library also
provides getter routines, and these are available in the more-widely-
deployed 1.2.x series.
2013-09-16 15:57:32 -04:00
Daniel Richard G 66315d5eea Added const qualifiers to edit-control string handling
FLTK's Fl_Input widget, instantiated as {Graphics,Text}EditControl, returns
a 'const char *' string. In order to handle this properly, several of
SolveSpace's internal routines needed to gain a "const" qualifier on the
edit-control string argument.
2013-09-16 15:51:20 -04:00
Daniel Richard G bcb6c7b19b OpenGL fixes
glGetError() was returning GL_INVALID_OPERATION due to some minor missteps
2013-09-09 16:05:33 -04:00
Daniel Richard G 5cca524c62 Changed "static const int" class members into enums
Not only is the enum syntax more compact, it avoids inadvertent link
failures resulting from how C++ treats "static const int" members:

http://stackoverflow.com/questions/5391973/undefined-reference-to-static-const-int
http://stackoverflow.com/questions/5508182/static-const-int-causes-linking-error-undefined-reference

(And for what it's worth, MSVC6 gave silly errors for these members
wherever a non-zero value was assigned.)
2013-09-09 15:50:32 -04:00
Daniel Richard G a2a78b923f Renamed the MSVC makefile to Makefile.msvc
Automake and CMake both generate a makefile named "Makefile", so this will
prevent the hand-written MSVC makefile from getting clobbered.
2013-08-27 16:46:24 -04:00
Daniel Richard G 74b65e14f9 Revised the MSVC Makefile and build
* Generate icons.h and icons-proto.h in the source directory instead of
  obj/, so that pre-generated copies of these files can be distributed
  without being blown away by "make clean"; also updated the source files
  that #include these to reflect the new location

* Compilation rules rewritten as batch-mode inference rules

* Use Windows commands instead of Unix ones ("del" instead of "rm", "move"
  instead of "mv", etc.)

* Sorted the object lists

* Use tabs to indent rule bodies
2013-08-27 16:44:48 -04:00
Daniel Richard G 398e09fe9e Revised the Perl scripts
* Use "#!/usr/bin/env perl" instead of "#!/usr/bin/perl", as this is better
  practice (it allows e.g. /usr/local/bin/perl to work when executing via
  the shebang)

* Use "use strict" and "use warnings"

* Declare variables with "my" as required by "use strict"

* Take an optional "srcdir" argument so that the scripts can find the icon
  files in a location other than ./icons/ -- this will make building
  outside of the source tree possible in the future

* Add a "this is a generated file" banner to the output, so that it can be
  clearly recognized as a machine-generated file that should not be
  hand-edited

* Minor regex tweaks
2013-08-26 17:45:09 -04:00
Daniel Richard G 0f7a34ccca Fixed a typo: "==" was intended, not "=" 2013-08-26 17:06:53 -04:00
Daniel Richard G e256956d12 Added missing items to GraphicsWindow::menu[] elements
Several MenuEntry elements in GraphicsWindow::menu[] were being initialized
with four items instead of the requisite five, due to a missing fourth
column (corresponding to the .accel field of MenuEntry). This change simply
adds zeroes as the missing column to the appropriate elements.
2013-08-26 17:00:02 -04:00
Daniel Richard G 66f46b7b67 General compiler warning/error fixes
This addresses a grab bag of compiler grievances relating to C++ syntax,
type, and scope, as observed on Linux with g++ and Solaris with Sun
WorkShop 6.
2013-08-26 16:54:04 -04:00
Daniel Richard G 7715fd1bb8 Don't ignore the return value of fgets() and fread() 2013-08-26 16:48:41 -04:00
Daniel Richard G 1b00c8c3ab Use size_t instead of int in the memory allocation routines
size_t is the correct type to use when specifying the memory-size of an
object. That is why sizeof(), strlen() and malloc() all use it.
2013-08-26 16:40:25 -04:00
Daniel Richard G dcc963aa4b Modified Get{BYTE,WORD,DWORD}() to return the respective type
Having e.g. GetWORD() return a WORD rather than int eliminates the need for
a cast when assigning to WORD variables. We use casts only when assigning
to a different (but same-sized) type.

Also, check for EOF explicitly when calling fgetc().
2013-08-26 16:24:16 -04:00
Daniel Richard G a72575d04e Use casts to bridge mismatches in integer-type sizes and signedness
The compiler gets nervous when we (for example) pass in a size_t as an int
parameter, or assign an int to a char, or assign -1 to an unsigned type. By
adding appropriate casts, we inform the compiler that, yes, we know what
we're doing.

This change also upgrades a va_arg() type from char to int, as char is
always promoted to int when passed through '...'.
2013-08-26 16:19:23 -04:00
Daniel Richard G 8913d11fa5 Quash "variable may be used uninitialized" warnings
Whether or not there is any actual danger of these variables being used
without initialization, the warnings are noise, and getting rid of them is
trivial.
2013-08-26 15:36:00 -04:00
Daniel Richard G df6125efee Fix "jump to label 'foo' crosses initialization of 'bar'" errors
Newer C++ compilers do not allow goto-ing over an initialized variable
declaration, as this violates C++98. We address this by (in most cases)
separating the initialization from the declaration, or moving the goto to
an equivalent location.

Refer to the following discussions for more background:

http://stackoverflow.com/questions/11306799/why-does-c-enforce-such-behavior-in-crosses-initialization
http://stackoverflow.com/questions/12992108/crosses-initialization-of-variable-only-when-initialization-combined-with-decl
2013-08-26 15:24:50 -04:00
Daniel Richard G 02776ea535 Added const qualifiers
String literals in C++ are implicitly typed as 'const char *', and with
this change, their const-ness is maintained when assigning them to
variables or passing them as arguments. This significantly cuts down the
number of warnings generated by the compiler.
2013-08-26 14:58:35 -04:00
Jonathan Westhues affbeafc6c Make a copy of "freeze" library for storing stuff in registry, to
make //depot/solvespace/... entirely self-contained.

[git-p4: depot-paths = "//depot/solvespace/": change = 2216]
2013-08-20 21:54:54 -08:00
Jonathan Westhues defeb6411a Clean up SolveSpace makefile, and add forgotten copyright notice.
[git-p4: depot-paths = "//depot/solvespace/": change = 2213]
2013-07-28 14:53:30 -08:00
Jonathan Westhues bc426a2a7f Delete obsolete text in solvespace/doc/..., superseded by the
stuff on the website.

[git-p4: depot-paths = "//depot/solvespace/": change = 2212]
2013-07-28 14:40:37 -08:00
Jonathan Westhues 0ee8ba1457 Changes in preparation for the release of SolveSpace under the GPL,
to add that license, and change all copyright notices to me, not
Useful Subset, LLC.

[git-p4: depot-paths = "//depot/solvespace/": change = 2211]
2013-07-28 14:08:34 -08:00
Jonathan Westhues 1abd87954c Oops, fix gross memory leak in SolveSpace library due to failure
to destroy temporary heap.

[git-p4: depot-paths = "//depot/solvespace/": change = 2210]
2013-03-15 08:43:35 -08:00
Jonathan Westhues 7919e7171d Make SolveSpace work unrestricted without a license file, and
increase its version number to 1.9.

[git-p4: depot-paths = "//depot/solvespace/": change = 2198]
2012-01-21 12:12:00 -08:00
Jonathan Westhues e11347f613 Oops, update copyright date to 2011 for SolveSpace.
[git-p4: depot-paths = "//depot/solvespace/": change = 2195]
2011-07-04 11:25:17 -08:00
Jonathan Westhues c98a0b381f Increment SolveSpace's version number to 1.8.
[git-p4: depot-paths = "//depot/solvespace/": change = 2194]
2011-07-04 11:10:00 -08:00
Jonathan Westhues fc3dc68f83 Check in the VB.NET example for the SolveSpace library, and update
the documentation accordingly. Also rename the C example for
consistency, and update copyright dates.

[git-p4: depot-paths = "//depot/solvespace/": change = 2190]
2011-03-13 00:04:09 -08:00
Jonathan Westhues b3bdadfeb8 Fix that typo elsewhere in the slvs.dll examples, and note that
VB.NET example in the documentation.

[git-p4: depot-paths = "//depot/solvespace/": change = 2188]
2011-03-05 14:33:05 -08:00
Jonathan Westhues 3dc21ec8dd Make oops() calls exit instead of entering debugger by default,
since the latter looks worse if it happens to someone else.

[git-p4: depot-paths = "//depot/solvespace/": change = 2187]
2011-03-05 12:52:57 -08:00
Jonathan Westhues dcfae0f341 Typo in SolveSpace library example, embarrassing.
[git-p4: depot-paths = "//depot/solvespace/": change = 2186]
2011-03-05 12:22:59 -08:00
Jonathan Westhues 3dea64af47 Make default text in dimension box the exact (up to ten digits
after decimal) current value of the dimension, not the value
truncated to the same number of digits that are usually displayed.

And make the paste transformed screen accept expressions, not
just integers, for the count, angle, and scale.

[git-p4: depot-paths = "//depot/solvespace/": change = 2181]
2010-10-11 19:13:41 -08:00