Commit Graph

22 Commits (f09ae155862f456d70bbb1fc24b21784d69aea0e)

Author SHA1 Message Date
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
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 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
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 b974a4adeb A big nasty change, originally just to add paste transformed. So it
does that, and adds a scale factor to that transformation (instead
of just mirroring, as before), but also:

    * Replace the "import mirrored" mechanism with a scale factor,
      which if negative corresponds to a reflection as well.

    * Fix self-intersection checker to report a meaningful point
      when edges are collinear.

    * Don't blow an assertion on some types of invalid file;
      instead provide a nice error message to the user.

    * Clear the naked edges before each regen.

    * Don't create zero-length line segments by snapping a line
      segment's end to its beginning.

[git-p4: depot-paths = "//depot/solvespace/": change = 2086]
2009-12-15 04:26:22 -08:00
Jonathan Westhues 2f115ec950 A monster change to add support for filled paths. This requires us
to assemble Beziers into outer and inner loops, and find those
loops made up of entities with filled styles. The open paths are
maintained in a separate list, and we assemble as many closed paths
as possible even when open paths exist.

This changes many things. The coplanar check is now performed on
the Beziers, not the resulting polygon. The way that the polygon is
used to determine loop directions is also modified.

Also fix the mouse behavior when dragging a point: drop it when the
mouse is released, even if it is released outside the window, but
don't drop it if the pointer is dragged out of and then back into
our window.

Also special-case SSurface::ClosestPointTo() for planes, for speed.

[git-p4: depot-paths = "//depot/solvespace/": change = 2058]
2009-10-28 23:16:28 -08:00
Jonathan Westhues 730bb8f73e Make the export scale factor affect the surfaces in a STEP file,
and lay groundwork for wireframe export.

[git-p4: depot-paths = "//depot/solvespace/": change = 2052]
2009-10-12 01:28:34 -08:00
Jonathan Westhues c153e23f49 Add option to mirror imported geometry, including the shell, mesh,
and parametric entities. Also consolidate the text screen functions
to change group options into a single function for everything.

[git-p4: depot-paths = "//depot/solvespace/": change = 2051]
2009-10-09 04:57:10 -08:00
Jonathan Westhues f7f9000c68 Discard intersection curves that lie entirely outside of one
surface's domain of u, v in [0, 1]. Cache the starting guess when
projecting a point into a ratpoly surface, to avoid brute force
searching for a good one every time. Split edges even if they
aren't quite inside the trim curve, since the trim boundaries are
pwl, not exact; unnecessary splits won't hurt, but failure to split
when necessary will. Make the triangulation code use a better (but
not perfect) epsilon, to avoid "can't find ear" failures on very
fine meshes.

And turn on compiler optimization! I had somehow forgotten about
that, and it's a ~2x improvement.

[git-p4: depot-paths = "//depot/solvespace/": change = 2026]
2009-08-20 20:58:28 -08:00
Jonathan Westhues bd36221219 Clean up the marching step size / chord tol stuff, and add code to
export an inexact curve by approximating it with piecwise cubic
segments (whose endpoints lie exactly on the curve, and with exact
tangent directions at the endpoints).

[git-p4: depot-paths = "//depot/solvespace/": change = 1995]
2009-06-21 18:54:09 -08:00
Jonathan Westhues 9455037e49 Add beginnings of STEP export, which weren't as horrible as I had
feared. Though I don't have rational surfaces or curves going yet,
and I don't have the stuff to handle holes or multiple outer
contours in a single surface.

[git-p4: depot-paths = "//depot/solvespace/": change = 1974]
2009-06-07 22:50:16 -08:00
Jonathan Westhues 2d653eada8 Add code to identify planes and cylindrical surfaces from a solid
of revolution, and put them in the same form as if they had been
draw by an extrusion (so that we can use all the same special case
intersection curves).

And add code to merge coincident faces into one. That turns out to
be more than a cosmetic/efficiency thing, since edge splitting
fails at the join between two coincident faces.

[git-p4: depot-paths = "//depot/solvespace/": change = 1965]
2009-06-04 21:38:41 -08:00
Jonathan Westhues 438d517c5a If a Boolean fails, then make a note of it in the group's text
window screen, and remind the user that they could 'fix' the
problem by working with meshes instead.

[git-p4: depot-paths = "//depot/solvespace/": change = 1962]
2009-05-30 00:49:09 -08:00
Jonathan Westhues ddbd0ff77b Add ability to represent our surfaces as either a shell or a mesh,
according to the user's preference. I templated the housekeeping
stuff for Boolean operations and step and repeat, so it's
relatively clean.

Still need to add the stuff to make a mesh vertex-to-vertex, and to
export sections of a mesh.

[git-p4: depot-paths = "//depot/solvespace/": change = 1959]
2009-05-24 03:37:07 -08:00
Jonathan Westhues 1d88f96e13 Make surfaces of revolution with control points on the axis
triangulate correctly; don't screw up generating them, and make
sure that the ratpoly stuff doesn't blow up near the singularity.

[git-p4: depot-paths = "//depot/solvespace/": change = 1953]
2009-05-18 00:18:32 -08:00
Jonathan Westhues 40ed1b7ac1 Generate intersection curves for surfaces of extrusion along a
parallel axis (which are always lines parallel to that axis).

Remove short pwl segments when possible, to avoid short edges that
get misclassified.

[git-p4: depot-paths = "//depot/solvespace/": change = 1952]
2009-05-17 23:26:51 -08:00
Jonathan Westhues d6d198ee40 Add triangulation of surfaces with compound curvature; I just build
a grid of quads, with adaptive spacing. The quads that lie entirely
within the trim polygon are triangulated and knocked out from the
polygon, and then the polygon is triangulated.

That works okay, though rather slow. But there are issues with
surfaces of revolution that touch the axis, since they end up with
a singularity. That will require some thought.

[git-p4: depot-paths = "//depot/solvespace/": change = 1951]
2009-05-08 00:33:04 -08:00
Jonathan Westhues 3581d9b9ec Construct surfaces of revolution from lathe groups, although we're
not triangulating them correctly yet.

[git-p4: depot-paths = "//depot/solvespace/": change = 1950]
2009-04-28 18:42:44 -08:00
Jonathan Westhues b5c8aade21 Add exact export of arcs for EPS, DXF, SVG, and of nonrational
polynomial curves for SVG.

[git-p4: depot-paths = "//depot/solvespace/": change = 1937]
2009-04-14 18:55:18 -08:00
Jonathan Westhues 775653a75d Add beginnings of exact curve export. We take the trim curves in
our specified section plane; we then split them according to the
start and endpoints of each STrimBy, using de Castejau's algorithm.
These sections get projected (possibly in perspective, which I do
correctly) into 2d and exported.

Except, for now they just get pwl'd in the export files. That's the
fallback, since it works for any file format. But that's the place
to add special cases for circles etc., or to export them exactly.
DXF supports the latter, but very painfully since I would need to
write a later-versioned file, which requires thousands of lines of
baggage. I'll probably stick with arcs.

[git-p4: depot-paths = "//depot/solvespace/": change = 1936]
2009-04-13 20:19:23 -08:00
Jonathan Westhues 71adc0bf54 Split ratpoly.cpp; now that contains only the mathematical stuff,
and curve.cpp and surface.cpp contain the rest.

Also get rid of the meshError stuff; will just use the nakedEdges
mechanism for that. And I won't run the interference test
continuously, have added a menu item for that.

[git-p4: depot-paths = "//depot/solvespace/": change = 1934]
2009-03-28 22:05:28 -08:00