Commit Graph

152 Commits (f09ae155862f456d70bbb1fc24b21784d69aea0e)

Author SHA1 Message Date
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
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 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 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 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 307965d53f Update selection of extrusion/lathe solid model color to use new
color picker.

And apply same rule to rewrite nearly-white colors (when exporting
with a file format typically viewed on a white background) for fill
color as for stroke color.

[git-p4: depot-paths = "//depot/solvespace/": change = 2176]
2010-08-14 11:00:25 -08:00
Jonathan Westhues fe2ea5d5e1 Improve the non-parametric rounding. It now works on both lines and
circles, using a numerical method. And the user can specify a
radius, instead of letting us choose automatically, and specify
whether the original lines should be kept and made construction, or
deleted.

[git-p4: depot-paths = "//depot/solvespace/": change = 2146]
2010-05-16 08:36:23 -08:00
Jonathan Westhues 949df4d139 Add a constraint for tangency between any combination of arcs
and cubics. Also add that to the library interface.

It might have been better to use a single constraint for that,
plus all the line-curve or line-line cases, but it would break
backwards compatibility if I did that now, and perhaps be
confusing with the 'other' member (which is meaningless for
lines) anyways.

[git-p4: depot-paths = "//depot/solvespace/": change = 2141]
2010-05-09 20:14:06 -08:00
Jonathan Westhues 9f7ff34b98 Add option to treat all dimensions as reference dimensions. This is
useful because it makes it possible to add cosmetic dimensions to
an existing model, without REF appended.

[git-p4: depot-paths = "//depot/solvespace/": change = 2140]
2010-05-09 17:06:09 -08:00
Jonathan Westhues 8481c54012 Major UI changes, to use the checkboxes and radio buttons wherever
possible. This replaces all of the color-coded links, that I liked
but that were nonstandard.

Also rip out the old sweep and helical sweep UI; that was disabled,
but the code was still present.

And fix dependencies in makefile, since textwin.cpp depends on the
icons now.

[git-p4: depot-paths = "//depot/solvespace/": change = 2139]
2010-05-09 10:25:23 -08:00
Jonathan Westhues 4628048d45 Add "lock point where dragged" constraint, in either 2d or 3d.
And call the cubic things splines, not segments, since that's what
they are now.

[git-p4: depot-paths = "//depot/solvespace/": change = 2135]
2010-05-03 21:11:52 -08:00
Jonathan Westhues a11010c593 Fix a gross memory leak: when switching to a new file, either after
File -> New or File -> Open, I freed the Group structures
themselves, but none of their children.

[git-p4: depot-paths = "//depot/solvespace/": change = 2120]
2010-02-28 11:23:01 -08:00
Jonathan Westhues 52f9be0925 Add projected point-point distance constraint.
[git-p4: depot-paths = "//depot/solvespace/": change = 2115]
2010-01-27 10:15:06 -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 9723f4e44f Add support for a clipboard, with cut, copy, and paste. This works
only in a workplane; but this means that plane sketches are
conveniently transformed from one plane to another.

Also tweak snap to grid to ignore unsnappable entities instead of
triggering an error, and to remove arbitrary limit on the number of
entities / comments that will be snapped.

[git-p4: depot-paths = "//depot/solvespace/": change = 2084]
2009-12-04 00:08:41 -08:00
Jonathan Westhues 8e484beec1 Add a warning when zero-length edges appear in the sketch, since
those screw a lot of things up. And add data structure for
clipboard entities, though no code yet.

[git-p4: depot-paths = "//depot/solvespace/": change = 2082]
2009-12-03 11:14:34 -08:00
Jonathan Westhues b9ab62ab3f Remove arbitrary limits on the selection size, and permit more than
one point to be dragged simultaneously. So now a dragged point
drags all the selected points and entities, and a dragged entity
drags its points (except for circles, which drag the radius).

This means that the number of forced points for the solver must now
be unlimited, and it is.

Also add commands to invert the selection within the active group,
and to select an edge chain starting from the current selection.
And redo the context menus a bit; still not great, but less
cluttered and more systematic.

[git-p4: depot-paths = "//depot/solvespace/": change = 2064]
2009-11-03 10:54:49 -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 e7c8d31500 Move code to find outer and inner contours (and which inner
contours go with which outer contour) out of exportstep.cpp, since
I'll need that to do filled contour export for the 2d file formats.

Also add user interface to specify fill color.

[git-p4: depot-paths = "//depot/solvespace/": change = 2057]
2009-10-22 09:16:20 -08:00
Jonathan Westhues 0914a27ff4 Put information about which requests generate which entities, and
how many points are associated with each, into a single table.

[git-p4: depot-paths = "//depot/solvespace/": change = 2056]
2009-10-22 06:02:08 -08:00
Jonathan Westhues 2ca5334bdf Add interpolating splines: both periodic splines (that form a
loop), and open-ended splines, with their tangents specified at
their endpoints.

Also change constraint solver matrix size to 1024, on the theory
that a power of two will generate better array indexing, and
replace fabs() with my own function that for some reason is
faster.

[git-p4: depot-paths = "//depot/solvespace/": change = 2055]
2009-10-20 20:46:01 -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 2e9e0da71f Add ability to relax the constraints, applying only
point-coincident constraints and the entity- or group-generated
constraints. Also fix a bug where a dragged point was not released
when the mouse pointer left the window.

[git-p4: depot-paths = "//depot/solvespace/": change = 2045]
2009-10-01 03:22:56 -08:00
Jonathan Westhues db565438e3 Add text angle for styles. Add ability to quickly change between
perspective and parallel projections. Add a snap grid, for points
and for text comments. Draw text comments in the plane of their
workplane if they have one, otherwise always facing forward.

And fix a few nasty bugs: the possibility of an extremely long
animation onto a workplane, accidental use of the wrong style line
width for constraints, misplaced text box in style screen for
default styles, other little stuff.

[git-p4: depot-paths = "//depot/solvespace/": change = 2037]
2009-09-29 03:35:19 -08:00
Jonathan Westhues 4634961054 Add ability to assign styles to cosmetic text (in the form of
Constraint::COMMENTs), including line width and color, and text
height and origin location.

[git-p4: depot-paths = "//depot/solvespace/": change = 2033]
2009-09-24 07:52:48 -08:00
Jonathan Westhues 9416faca88 Add a context menu, with a grab bag of options. That will need some
refinement later, but it does not affect file formats so it's not
very critical.

[git-p4: depot-paths = "//depot/solvespace/": change = 2032]
2009-09-23 02:59:59 -08:00
Jonathan Westhues 9b8f32dad7 Now actually export the line styles, for PDF, EPS, and SVG file
formats, with the proper color and width. This may need a bit of
cleanup for stuff like the hidden line removal, which currently
loses the style.

Also fix a bug in the test for arcs of a circle. A second-order
Bezier with collinear control points really is an arc, but it's an
arc with infinite radius so stuff tends to blow up. So return false
for that one.

[git-p4: depot-paths = "//depot/solvespace/": change = 2030]
2009-09-21 21:46:30 -08:00
Jonathan Westhues 517c5edbfa Add user interface to modify styles: change the color, line width,
line width units, on-screen and export visibility. So now we can
use that to modify the default styles, or to create custom styles.

Also add code to draw fat lines, with round endcaps, since gl
doesn't do that.

Next we need some user interface to assign styles to entities, and
to make all the export file formats support the style attributes.

[git-p4: depot-paths = "//depot/solvespace/": change = 2029]
2009-09-18 00:14:15 -08:00
Jonathan Westhues ce99217bbb Move colors and line widths for almost everything to the styles
mechanism. This gets filled in from some defaults, and stored in
the registry. The default styles do not get saved in the file, but
user-created styles (which aren't supported yet) do.

[git-p4: depot-paths = "//depot/solvespace/": change = 2028]
2009-09-16 23:32:36 -08:00
Jonathan Westhues e989c86a38 Add ability to set export canvas size (paper size for PDF, bbox
size for EPS, etc.). This can either be fixed, with a given width
and height and offset, or automatic, by the left right bottom top
margins.

And draw nicer dimensions for length, with arrows and more
extension lines. Add code to trim those lines against the
(rectangular, axis-aligned) box that contains the actual number,
and use that (instead of the elliptical interpolation, which was
only approximately right) for diameter dimensions too.

[git-p4: depot-paths = "//depot/solvespace/": change = 2027]
2009-09-03 00:13:09 -08:00
Jonathan Westhues 606af2ff39 Add support for the 3dconnexion six degree of freedom input devices
(in my case, a SpaceNavigator). I can transform the view of the
part, or transform a part in an assembly.

Also fix up mouse wheel input, so that it works even if it comes in
chunks of less than 120 units.

[git-p4: depot-paths = "//depot/solvespace/": change = 2019]
2009-07-20 11:05:33 -08:00
Jonathan Westhues 92da6c665b Change how step and repeat works: now I build the union of all the
steps in thisShell or thisMesh, and then let the Boolean proceed as
usual. If everything works, then this is equivalent. And it's less
code, and it makes stuff like stepping the step and repeat work.

Also begin to work on line/entity/constraint styles, but no real
work yet.

[git-p4: depot-paths = "//depot/solvespace/": change = 2018]
2009-07-19 17:47:59 -08:00
Jonathan Westhues 66c93aab73 Add a mechanism to record the lines drawn when we display a
constraint, so that we can export that too. This includes the lines
for the vector font.

A little ugly; it needs some kind of line style (color or width) to
distinguish those lines from the real geometry in the exported
file.

[git-p4: depot-paths = "//depot/solvespace/": change = 2007]
2009-07-03 12:55:57 -08:00
Jonathan Westhues 3f5c439873 A very important optimisation; if we know that our mesh/shell is
identical to the previous group's (because our thisShell and
thisMesh are empty), then display the previous group's instead.
This saves us re-triangulating the shell (or recalculating the
edges of a triangle mesh) every time our group gets regenerated,
which was horribly slow.

[git-p4: depot-paths = "//depot/solvespace/": change = 2004]
2009-06-29 23:24:36 -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 03ecbad981 Add beginnings of stuff to represent surfaces as either meshes or
exact surface shells. And add interference checking; I'll be lazy
and just do that on the meshes, by modifying the self-intersection
tester to ignore coplanar triangles (since that can happen in an
assembly).

[git-p4: depot-paths = "//depot/solvespace/": change = 1958]
2009-05-22 02:02:02 -08:00
Jonathan Westhues ddf9364257 Add a separate display mesh and edge list; so if we're working with
a mesh than that's a copy, and if we're working with a shell then
it's the shell's triangulation.

[git-p4: depot-paths = "//depot/solvespace/": change = 1957]
2009-05-21 01:06:26 -08:00
Jonathan Westhues bc6bdfade8 Save the exact surfaces in the exported file, and import and
transform them for assembly.

[git-p4: depot-paths = "//depot/solvespace/": change = 1954]
2009-05-18 23:26:38 -08:00
Jonathan Westhues 4d742a5777 The constraint solver now compiles as a library, and I have a
little test app that links against it. I still need to polish a few
things, but this is more or less as it should be.

[git-p4: depot-paths = "//depot/solvespace/": change = 1944]
2009-04-19 23:30:09 -08:00
Jonathan Westhues b293c0ef41 Split the Entity and Constraint classes into Xxx and XxxBase, with
the fundamental geometric stuff in XxxBase. Next I hope to make the
constraint solver use only the XxxBase types.

[git-p4: depot-paths = "//depot/solvespace/": change = 1941]
2009-04-18 20:28:21 -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
Jonathan Westhues bb4b767e99 Tear everything apart, moving away from meshes and toward shells.
Add stubs for functions to perform Booleans, and get rid of mesh
stuff, including the kd tree accelerated snap to vertex (which
should not be required if the shell triangulation performs as it
should).

Also check that a sketch is not self-intersecting before extruding
it or whatever. This is dead slow, needs n*log(n) implementation.

[git-p4: depot-paths = "//depot/solvespace/": change = 1902]
2009-01-22 19:30:30 -08:00
Jonathan Westhues ebca6130ec Early attempts at rational polynomial surfaces. I can create one
from an extrusion, with piecewise linear trim curves for everything
(that are shared, so that they appear only once for the two
surfaces that each trims). No Boolean operations on them, and the
triangulation is bad, because gl seems to merge collinear edges.

So before going further, I seem to need my own triangulation code.
I have not had great luck in the past, but I can't live without it
now.

[git-p4: depot-paths = "//depot/solvespace/": change = 1899]
2009-01-19 02:37:10 -08:00
Jonathan Westhues 25ed4e1ef1 SPolyCurve (i.e., polynomial curve) vs. SPolygon got too confusing;
let's call those Beziers instead.

[git-p4: depot-paths = "//depot/solvespace/": change = 1898]
2009-01-18 19:51:00 -08:00
Jonathan Westhues 0e623c90c0 Generate the group's polygon from the exact curves, not from edges;
so now we've got the exact curve loops, with their direction
standardized so that we can tell which direction is out. We still
need the polygon in any case, since that's a convenient way to find
each curve's winding number.

And remove some more leftover code from mesh sweeps.

[git-p4: depot-paths = "//depot/solvespace/": change = 1897]
2009-01-18 19:33:15 -08:00
Jonathan Westhues 7a874c20c0 Remove old sweep/helical sweep code for meshes, and add some
untested stuff to start making exact surface shells.

[git-p4: depot-paths = "//depot/solvespace/": change = 1896]
2009-01-16 21:28:49 -08:00
Jonathan Westhues f904c0fbee Entities now generate rational polynomial curves instead of
piecwise linear segments. These are piecewise linear approximated
for display, and currently for the mesh too, but that's the first
step to replace the mesh with exact curved surfaces.

[git-p4: depot-paths = "//depot/solvespace/": change = 1895]
2009-01-14 19:55:42 -08:00