Commit Graph

60 Commits (87d0e097bbbfb895e622cf970f236bcb108167f6)

Author SHA1 Message Date
ruevs 60cd95d608 Dimension constraints only display mode improvements
Make the `TriStateButton` class "universal" and use it in place of the
`OccludedLinesButton` class which is now removed.

Fix the tool-tips on the constraint button to show what will come instead
of what is - just like the the occluded lines button. Also change the
text of the tool-tips wording to be more clear and consistent with other
buttons.

Small stylistic and code formatting changes.
2023-01-17 19:16:36 -05:00
77maxikov a0219b2228 dimonly fix 2023-01-17 19:16:36 -05:00
Tom Sutcliffe 5edb2eebf6 Add "Show Exploded View" menu option
Where each entity in the active workplane sketch is projected a
different amount normal to the workplane, to allow inspection and
easier selection of entities that entirely overlap each other and are
thus otherwise difficult to see or select.

The distance between the exploded "layers" can be controlled in the
configuration page. Negative distances mean the layers are projected in
the opposite direction, relative to the workplane normal.
2021-08-17 17:48:25 +03:00
Tom Sutcliffe c19bd8cc99 Remove unused variable 2021-08-14 20:34:26 -04:00
Eric Chan 37de364257 Addition of ArcLength Ratio and ArcLength Difference constraints to Constraints list 2021-06-28 11:31:53 -04:00
ruevs 7e08b02de1 Allow comments to be associated with point entities
If a single point is selected when a "Constrain | Comment" (`;`) is added
then the comment is associated with the point and its position becomes
relative to the point. In this way the comment will move with the point.

If nothing is selected or more than a single point is selected then
the behaviour is as before and the comment is "floating".

Closes #1032
2021-05-12 19:22:46 -04:00
phkahler 162897eca7 Reimplement DivPivoting as DivProjected.
The old implementation was an approximation, whereas the new one is exact.
2019-09-20 01:09:25 +00:00
Ryan Pavlik 5efb09e6d4 Use the new equality/inequality operators of handles to reduce references to .v. NFC. 2019-07-10 15:40:21 +00:00
EvilSpirit 9d1c295495 Add a setting to format constraint labels using SI prefixes.
Supported metric units: km, m, cm, mm, µm, nm.
Supported USCS units: in, mil, µin.

Also, use the newly introduced unit formatting machinery in tools for
measuring perimeter, area and volume, so that e.g. volume is not
displayed in millions of cubic millimeters.
2019-05-24 12:31:41 +00:00
whitequark ac7b82d7c1 Allow configuring the amount of digits displayed after decimal point.
This is useful in niche cases, like making angular measurement tools.

Also, use simpler and more principled code for numeric precision
while editing constraints: don't special-case angles, but use up to
10 digits after the decimal point for everything.
2019-05-23 17:53:53 +00:00
whitequark 25b6eba148 Adjust angle label margin similarly to eda294ef. 2019-05-21 23:05:05 +00:00
whitequark eda294efb5 Adjust the horizontal constraint label margin to equal vertical.
Right now, horizontally placed labels appear more cramped than
those that are placed vertically.
2018-07-31 17:21:15 +00:00
EvilSpirit 3c36d8f887 Pin comments with custom styles to front layer, like regular ones.
This is the 2.x behavior that was accidentally broken in the canvas
rewrite.
2017-02-17 02:53:20 +00:00
whitequark 8749a175a6 Draw constraints/entities when hovered or selected even if invisible.
This goes really well with the related constraint/request lists,
and in general seems very natural.
2017-01-17 11:53:51 +00:00
EvilSpirit 727c0a97dc Draw projected lines for pt-line-distance constraints in 3d. 2016-12-21 18:43:42 +00:00
EvilSpirit 5763972ed8 Don't apply scale twice for text if both height and stroke are in mm. 2016-12-21 18:34:15 +00:00
Evil-Spirit 3b241392d4 Fix rendering of horizontal/vertical constraint labels.
This was a regression from 2.2 to 3.0, caused by the Canvas
transition.
2016-11-17 00:48:47 +00:00
EvilSpirit 9f97e9aad4 Allow selecting unit (px/mm) in Canvas::Stroke.
By directly specifying the desired end result to the renderer, we
can avoid regeneration of geometry.
2016-10-11 23:32:21 +00:00
EvilSpirit df83ee4c8f Factor out Style::Stroke. 2016-10-11 23:32:05 +00:00
whitequark 4c30c09792 Correctly draw vector text for constraints free in 3d. 2016-08-13 10:51:14 +00:00
whitequark 8bf55b3c62 Fix multiple memory leaks found with LeakSanitizer. 2016-08-07 19:33:42 +00:00
whitequark e462387fca Add tests to cover 95.3% of constrainteq.cpp branches. 2016-08-07 17:33:27 +00:00
whitequark 4b4944264b Align constraint lines to pixel grid.
This ensures that constraints always look crisp, no matter the camera
position.
2016-08-07 17:33:27 +00:00
whitequark e7c8c1c8f2 Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
  * It is now possible to port SolveSpace to a later version of
    OpenGL, such as OpenGLES 2, so that it runs on platforms that
    only have that OpenGL version;
  * The majority of geometry is now rendered without references to
    the camera in C++ code, so a renderer can now submit it to
    the video card once and re-rasterize with a different projection
    matrix every time the projection is changed, avoiding expensive
    reuploads;
  * The DOGD (draw or get distance) interface is now
    a straightforward Canvas implementation;
  * There are no more direct references to SS.GW.(projection)
    in sketch rendering code, which allows rendering to multiple
    viewports;
  * There are no more unnecessary framebuffer flips on CPU on Cocoa
    and GTK;
  * The platform-dependent GL code is now confined to rendergl1.cpp.
  * The Microsoft and Apple headers required by it that are prone to
    identifier conflicts are no longer included globally;
  * The rendergl1.cpp implementation can now be omitted from
    compilation to run SolveSpace headless or with a different
    OpenGL version.

Note these implementation details of Canvas:
  * GetCamera currently always returns a reference to the field
    `Camera camera;`. This is so that a future renderer that caches
    geometry in the video memory can define it as asserting, which
    would provide assurance against code that could accidentally
    put something projection-dependent in the cache;
  * Line and triangle rendering is specified through a level of
    indirection, hStroke and hFill. This is so that a future renderer
    that batches geometry could cheaply group identical styles.
  * DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
    This is so that a future renderer into an output format that
    uses 2d transforms (e.g. SVG) could easily derive those.

Some additional internal changes were required to enable this:
  * Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
    This is so that the renderer could cache uploaded textures
    between API calls, which requires it to capture a (weak)
    reference.
  * The PlatformPathEqual function was properly extracted into
    platform-specific code. This is so that the <windows.h> header
    could be included only where needed (in platform/w32* as well
    as rendergl1.cpp).
  * The SBsp{2,3}::DebugDraw functions were removed. They can be
    rewritten using the Canvas API if they are ever needed.

While no visual changes were originally intended, some minor fixes
happened anyway:
  * The "emphasis" yellow line from top-left corner is now correctly
    rendered much wider.
  * The marquee rectangle is now pixel grid aligned.
  * The hidden entities now do not clobber the depth buffer, removing
    some minor artifacts.
  * The workplane "tab" now scales with the font used to render
    the workplane name.
  * The workplane name font is now taken from the normals style.
  * Workplane and constraint line stipple is insignificantly
    different. This is so that it can reuse the existing stipple
    codepaths; rendering of workplanes and constraints predates
    those.

Some debug functionality was added:
  * In graphics window, an fps counter that becomes red when
    rendering under 60fps is drawn.
2016-07-23 22:31:18 +00:00
EvilSpirit 6e17780e01 Draw projection lines for point-line distance constraints.
This is only visible when the point and line lie within the workplane,
but the constraint label does not.
2016-07-20 07:52:05 +00:00
EvilSpirit 5791310bb1 Annotate constants passed as boolean function arguments.
This is to ensure that:
  * it is clear, when looking at the point of usage, what is
    the purpose of "true" or "false";
  * when refactoring, a simple search will bring up any places that
    need to be changed.

Also, argument names were synchronized between declaration and
implementation.

As an exception, these are not annotated:
  * Printf(/*halfLine=*/), to avoid pointless churn.
2016-05-26 12:43:52 +00:00
whitequark 1249f8496e Enable exhaustive switch coverage warnings as an error, and use them.
Specifically, this enables -Wswitch=error on GCC/Clang and its MSVC
equivalent; the exact way it is handled varies slightly, but what
they all have in common is that in a switch statement over an
enumeration, any enumerand that is not explicitly (via case:) or
implicitly (via default:) handled in the switch triggers an error.

Moreover, we also change the switch statements in three ways:

  * Switch statements that ought to be extended every time a new
    enumerand is added (e.g. Entity::DrawOrGetDistance(), are changed
    to explicitly list every single enumerand, and not have a
    default: branch.

    Note that the assertions are kept because it is legal for
    a enumeration to have a value unlike any of its defined
    enumerands, and we can e.g. read garbage from a file, or
    an uninitialized variable. This requires some rearranging if
    a default: branch is undesired.

  * Switch statements that ought to only ever see a few select
    enumerands, are changed to always assert in the default: branch.

  * Switch statements that do something meaningful for a few
    enumerands, and ignore everything else, are changed to do nothing
    in a default: branch, under the assumption that changing them
    every time an enumerand is added or removed would just result
    in noise and catch no bugs.

This commit also removes the {Request,Entity,Constraint}::UNKNOWN and
Entity::DATUM_POINT enumerands, as those were just fancy names for
zeroes. They mess up switch exhaustiveness checks and most of the time
were not the best way to implement what they did anyway.
2016-05-26 12:43:52 +00:00
EvilSpirit f33ddc94fb Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:

  class Foo {
    enum { X = 1, Y = 2 };
    int kind;
  }
  ... foo.kind = Foo::X; ...

and convert it to this:

  class Foo {
    enum class Kind : uint32_t { X = 1, Y = 2 };
    Kind kind;
  }
  ... foo.kind = Foo::Kind::X;

(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)

The benefits are as follows:
  * The type of the field gives a clear indication of intent, both
    to humans and tools (such as binding generators).
  * The compiler is able to automatically warn when a switch is not
    exhaustive; but this is currently suppressed by the
      default: ssassert(false, ...)
    idiom.
  * Integers and plain enums are weakly type checked: they implicitly
    convert into each other. This can hide bugs where type conversion
    is performed but not intended. Enum classes are strongly type
    checked.
  * Plain enums pollute parent namespaces; enum classes do not.
    Almost every defined enum we have already has a kind of ad-hoc
    namespacing via `NAMESPACE_`, which is now explicit.
  * Plain enums do not have a well-defined ABI size, which is
    important for bindings. Enum classes can have it, if specified.
    We specify the base type for all enums as uint32_t, which is
    a safe choice and allows us to not change the numeric values
    of any variants.

This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-25 07:17:14 +00:00
whitequark 274233fe08 Eliminate Constraint::dogd.refp.
While we're at it, let's also emphasize both parts of a two-part
constraint to make it easier to find.
2016-05-25 03:22:54 +00:00
whitequark 20d87d93c5 Add const qualifiers to functions where trivially possible.
This will allow us in future to accept `const T &` anywhere it's
necessary to reduce the amount of copying.

This commit is quite conservative: it does not attempt very hard to
refactor code that performs incidental mutation. In particular
dogd and caches are not marked with the `mutable` keyword.
dogd will be eliminated later, opening up more opportunities to
add const qualifiers.

This commit also doesn't introduce any uses of the newly added const
qualifers. This will be done later.
2016-05-25 03:22:54 +00:00
EvilSpirit bbca4cc224 Rewrite declarations of form f(void) as f().
In C++ there is no difference and newly added functions are all
declared as f(), so this brings back consistency.
2016-05-20 12:43:20 +00:00
whitequark ad4a204edf Replace all oops() checks with ssassert()s.
This includes explanation and context for non-obvious cases and
shortens debug cycles when just-in-time debugging is not available
(like on Linux) by immediately printing description of the assert
as well as symbolized backtrace.
2016-05-20 12:38:30 +00:00
EvilSpirit 7b8e8b0b41 DXF: export color as indexed, not RGB.
The version of AutoCAD we advertise is unable to read RGB color, so
software attempting to be compatible with it ignores color attributes.
2016-05-17 11:47:49 +00:00
whitequark c17f1160dc Allow snapping constraint labels to grid.
This is pretty much the only way to get a sketch with tidily placed
dimensions.
2016-04-23 04:38:32 +00:00
EvilSpirit a4a353f01b Reverse arrows on an angle constraint when the label is outside. 2016-04-16 12:05:10 +00:00
EvilSpirit 3b7e7289c8 Continue an extension arc towards angle constraint label. 2016-04-16 09:05:21 +00:00
EvilSpirit 92f5bd450c Display angle in the middle of its dimension line, not adjacent.
Less visual clutter and more consistency with distance constraints.
2016-04-16 09:05:21 +00:00
EvilSpirit 07f3ab95e4 Draw extension lines for angle constraints between line segments. 2016-04-16 09:05:21 +00:00
whitequark bcb484e941 Do not display trailing zeroes for integer angles.
Angles that aren't an integral number of degrees are extremely
rare, and the label is often in a tight space, which warrants
special-casing this.
2016-04-16 03:10:56 +00:00
whitequark 7a01c840d3 Display and edit length difference constraints as lengths.
Before this commit, they worked sort of like length ratio
constraints, leading to wildly incorrect results in inch mode.
2016-04-16 03:10:56 +00:00
whitequark bd51a9edac Use the Unicode diameter symbol ⌀ in diameter constraints.
Before this commit, the diameter symbol was drawn using custom code,
which is not necessary anymore.
2016-04-16 03:10:56 +00:00
whitequark 0f304b4c64 Rigorously treat font scale factors.
The old values were chosen without a good understanding of font
metrics.
2016-04-15 21:53:08 +00:00
EvilSpirit e17a24814b DXF: only export visible constraints. 2016-04-08 10:15:29 +00:00
EvilSpirit 73f28b9731 Make normals and workplanes non-stylable.
This does not seem to have any useful application, and it can
result in odd misrenderings with some styles.
2016-04-08 10:12:28 +00:00
whitequark fb0aee91ea Add a degree symbol to angle constraints. 2016-03-23 14:16:17 +00:00
EvilSpirit a0576e2a50 Allow changing text size for default styles.
This is especially useful for High-DPI displays on non-OS X.
2016-03-05 12:02:13 +00:00
EvilSpirit 96344c85a6 Eliminate DEFAULT_TEXT_HEIGHT from drawing code.
Instead, query the text height for constraint style.
2016-03-05 12:02:13 +00:00
EvilSpirit a71d5894aa Draw extension lines from pt-line-distance to line ends.
Before this commit, if a pt-line-distance constraint is placed so
that the dimension line doesn't touch the line, no extension is
drawn. After this commit, an extension line will be drawn towards
the nearest end of the line.
2016-02-19 23:00:35 +00:00
whitequark 5c15cbf5f6 Remove extraneous instances of .c_str().
Most of these were just converting char* into std::string back and
forth; some more used ReadUTF8, which was converted to use nicer
STL-style iterators over UTF-8 text.

The remaining ones are:
  * arguments to Expr::From, which we'll change when refactoring
    the expression lexer;
  * arguments to varargs functions, which we'll change when adding
    localization (that requires custom printf-style functions to
    allow for changing argument order);
  * arguments where only string literals are ever passed, which
    are OK;
  * in platform-specific code, which is OK.
2016-02-19 10:22:53 +00:00
whitequark 29ad1acdfe Enable and mollify -Wunused-variable.
In my (whitequark's) experience this warning tends to expose
copy-paste errors with a high SNR, so making a few fragments
slightly less symmetric is worth it.

Also mollify -Wlogical-op-parentheses while we're at it.
2016-02-14 14:29:47 +00:00