7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-26 00:26:09 +00:00
Commit Graph

892 Commits

Author SHA1 Message Date
Tomasz Wlostowski
f7e37bf9f2 kimath: bring back the legacy SHAPE_LINE_CHAIN::Simplify() function
It looks like the new variant (with aMaxError) behaves in a subtly different way, resulting in router hiccups.

This needs more in-depth investigation, but for the moment, the older function does the job.
2024-11-02 19:59:09 +01:00
Andrej Valek
20ee4effdc ReparentModal: fix case when parent is not available
In some situations then parent window couldn't be available. Eg, when
eeschema is executed as standalone on macOS and trying to show
the global design block table dialog before the main frame exists.
So replace the assert with return and check the windows pointers bellow.
2024-10-31 14:42:53 +01:00
Armin Schoisswohl
f1abdfa1aa Modify Circle approximate segment count
Change number of segments of circles to be multiples of 8 and start rotated by delta/2.  This ensures that segments will be aligned to a 45°/90° grid

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18654
2024-10-28 20:40:05 +00:00
Andrej Valek
3ad92bc8db ShowModal: override method in DIALOG_SHIM
All DIALOG_SHIM dialogues which should be modal, has a problem on OSX
that parent could be lost. So call ReparentModal to fix this before
calling the base ShowModal method. This should fix the problem when
modal window has been hidden when windows were switched.

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/3765

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/17460
2024-10-27 16:37:47 +00:00
Seth Hillbrand
8dda9b37fa Change zorder to use unsigned
Edge cases can happen where point + clearance is larger than the bbox.
This can cause the zOrder min and max to get switched as max get a high
bit and is negative.  Clamping to limit the input values and using
uint32 for the output solves the corner case
2024-10-24 17:40:25 -07:00
Seth Hillbrand
64ff47c594 Handle edge cases in kissing zones
When zone kisses happen from different polygons, we need to be careful
not to use the different polygons for ear comparisons or prev/next
pointers

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18654
2024-10-24 17:40:25 -07:00
John Beard
201b60c670 Point editor single-corner chamfer tool
Come up with a plausible default chamfer size, rather
than prompting every time with a modal (and then you have
to handle when the chanfer doesn't fit). This could be
changed if it's more annoying this way. But if we had
proper edge-dragging in zones, probably would be better
than setting a chanfer manually.

Also fix the GetNeighbourIndexes which seems to have
always been broken (but is not actually used by anything at
present).

Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/16771
2024-10-13 11:10:49 +08:00
John Beard
4bad76825c Standardise clamp function
std::clamp and alg:clamp had different argument orders.
Since std::clamp is constexpr, we might as well just use
that now we have it.
2024-10-09 21:27:58 -06:00
John Beard
58669f2b9f BOX2: Correct a clamp
std::clamp is (v, min, max), but alg::clamp is (min, v, max).

I can't quite get my head round why this only causes test failures
on some platforms.
2024-10-09 11:42:16 +08:00
John Beard
55370e7520 QA: BOOST_CHECK to _TEST in some KiMath tests
This tells you the arguments when it fails.

BOOST_TEST is available in all our Boost.Test version.
Even if you didn't use it, these calls should have been
BOOST_TEST_EQUAL(A, B) which also tells you the
arguments on a test failure.
2024-10-09 11:42:16 +08:00
John Beard
91dca89116 Eeschema: Add indicator icons for pins with alt modes
This makes it easier to see which pins have alt modes
available. There is an option to turn them off.

The icon positions are chosen so they they shouldn't
interfere as far as possible:

* If the text is inside, the icon goes more inside
  the body
* If the text is above/below the pin, it goes away from
  the body

This means it won't collide with a symbol wall in
most cases, but some symbols with alt pins on opposing
sides may need to be widened if the icons are show.

Includes a rather fiddly refactor of the SCH_PIN painter
function, which needs quite a lot of massaging to allow
it to figure out where an icon would go. Quite a bit
of logic is broken out into smaller encapsulations with
less visible state to each chunk.

Icon modes for base-name-selected and alt-selected are
included, but only the former works due to information
being thrown away during the SCH_PAINTER tempPin
process.

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/11069
2024-10-08 23:30:50 +08:00
John Beard
a4cbd0adb4 Sym edit: allow to drag pins with edges
Only applies when dragging an edge by the midpoint handle,
and only in the symbol editor if configured to do so.
2024-10-01 18:06:26 +01:00
John Beard
3f131e2011 Abstract REFERENCE_IMAGE to a separate class
Break the non-PCB-specfic parts of PCB_REFERENCE_IMAGE out
to a common REFERENCE_IMAGE class, which is then composed into
the PCB_REFERENCE_IMAGE. This will make it easier to bring the
transform origin logic to eeschema without repetition.
2024-09-30 10:20:20 +01:00
John Beard
889e24988b Reference image: avoid overflow on large scales
This has always been possible (especially through the properties
panel with large scales), but it's even easier if the transform
origin is near a manipulated corner.

Check and reject scales that result in an overflowed image box.
2024-09-28 13:24:26 +01:00
John Beard
215533f31a Unify flip direction handling
There was a gentle mish-mash of booleans, some with
true being left/right and some up/down, and some functions that
can flip in both axes (which is never actually done, and doesn't
really make geometric sense).

Replace all this with the FLIP_DIRECTION enum class, which makes
the intention completely unambiguous.

This also then allows a small scattering of simplifications,
because everything takes the same type and you don't have to
fiddle booleans to fit.
2024-09-27 17:13:13 +01:00
John Beard
4e2162fc97 Bezier: add the function to get point at t
Not of huge practical use on its own, but other maths will
need this.
2024-09-27 17:13:13 +01:00
John Beard
e2370c6e45 BEZIER: Avoid some copying in the ctor 2024-09-25 22:17:33 +01:00
John Beard
aea42a5cdf Pcbnew: handle connected copper circle points
Fixes: https://gitlab.com/kicad/code/kicad/-/issues/18774
2024-09-25 12:28:43 +01:00
John Beard
95beedb612 Dogbones: add slots for acute angles
It's actually not as hard as I thought, though
surely has wierd edge cases which users might need to
handle manually.
2024-09-22 13:45:19 +01:00
John Beard
a5e6f70122 Dogbone: handle small mouths even better
Including floating point roundoff, which can bite
for rectangles.
2024-09-20 10:57:07 +01:00
John Beard
671ecdf13c Dogbone: correct small mouth warning
It has to fit the cutter diameter, not the radius!

Also you can use SHAPE_ARC as a generic arc object.
2024-09-20 10:37:29 +01:00
John Beard
8fdb6d6e88 Feature: Exact item offset tool
This is a little bit like the bounding hull tool, but the
output is "exact" and it only supports the most common
source items.

By 'exact', this means that rounded corners are real arc
segments rather than polygonal approximations. Obviously,
this is rather tricky in the general case, and especially
for any concave shape or anything with a bezier in it.

Envisioned main uses:

* Creating courtyard and silkscreen offsets in footprints
* Making slots around line or arcs.

The one thing that it does not currently do, but which it might
plausibly do without reimplementing Clipper is convex polygons,
which would bring trapezoidal pad outsets for free. But that
is a stretch goal, and bounding hull can be used.
2024-09-19 06:35:43 +01:00
John Beard
1d2fb3ec82 Geom: add a simple OVAL type
Makes it easier to reason about oval shapes in geometric terms.

For now, this isn't a SHAPE, but it could be (and it's a
fairly common primitive, so it could be useful, though the
obvious use (clearance) is equivalent to a SEG with a clearance,
which is already a function that exists.
2024-09-19 06:35:43 +01:00
John Beard
99e1869987 Fix build: use same signature for alg::lexicographical_compare_three_way as std::
This makes it clearer that it is a polyfill-type affair
and make it easier to swap for the std:: one when the
compiler support is guaranteed.

Also avoid double underscores in parameter names,
as well as underscore-capital latter as they are reserved.
2024-09-18 06:56:03 +01:00
John Beard
f6a693475f BOX2: Add a KiROUND specialisation for BOX2D -> BOX2I 2024-09-11 22:35:35 +01:00
John Beard
5e9aba5555 Remove commented-out VECTOR2 dtor
It's been commented out for 11 years, so take the
opportunity while the header is being touched.
2024-09-11 22:35:35 +01:00
John Beard
49b8a5ce74 VECTOR2, BOX2: Add constexpr to many functions
In the core geometric types, this can provide some
useful optimisation opportunites.

As most trig functions and std::sqrt aren't constexpr
until C++26, anything that involves a vector length
can't be constexpr yet. But std::clamp and, importantly,
KiROUND are, which does allow quite a bit. And squared
sizes do work, as they are just multiplies, so size
comparisons work too.

The floating point equals-with-epsilon function can't
be directly made constexpr until C++23 (unless std::abs
is replaced with manual code, but that may then forgo
the use of intrinsics at runtime). And they're probably
not important to have at compile-time.

Add a few tests with static_asserts to show/prove that
some non-trivial operations can be done at compile time,
for example BOX2 merging.
2024-09-11 22:35:35 +01:00
John Beard
f4eb173c43 BOX2: By-value GetInflated method
This allows better value-semantics and const correctness.

This is a common method, as the Inflate method is
in-place:

  BOX2I inflated = other;
  // 'Inflated' is not inflated yet
  inflated.Inflate( delta );
  // Now it is inflated, but it's not const

This is annoying, as the 'inflated' box cannot easily
be made const. Instead:

  const BOX2I inflated = other.GetInflated( delta );
2024-09-11 22:35:35 +01:00
John Beard
7fe5caffa6 BOX2: Fix Inflate parameter type
If this is just 'int', BOX2D will not Inflate
as you might expect if given an non-integer parameter,
but will instead do a conversion.

Use coord_type, like the two-parameter Inflate method.

Add a test for this.
2024-09-11 22:35:35 +01:00
John Beard
b2be0d39bd Snapping: Add construction geometry snapping
This is a pretty major rework of the snapping system.
The GRID_HELPERs now have a separate CONSTRUCTION_MANAGER
which handles some of the state involving "construction
geometry".

This is fed with 'extended' geometry (e.g. "infinite" lines from
segments) for use in generating things like intersection points.
It also handles adding this geoemtry to a GAL view item
(CONSTRUCTION_GEOM) for display to the user.

The process is:

* A TOOL creates a GRID_HELPER
* Optionally, it pre-loads a "persistent" batch of construction
  geometry (e.g. for an item's original position)
* The grid helper finds useful snap 'anchors' as before, including
  those involving the construction items.
* Other items on the board can be 'activated' by snapping to one
  of their main points. Then, if it has construction geometry,
  it will be added to the display. At most 2 items of this kind of
  geometry are shown, plus the original item, to reduce avoid
  too much clutter.

The dashed snap lines state machine is also handled in the
CONSTRUCTION_MANAGER and displayed in the CONSTRUCTION_GEOM item.
2024-09-11 22:35:35 +01:00
John Beard
72e48aed52 Trigo: Add a GetRotated function to get a rotated VECTOR2I
This makes it easier to use value semantics and consts when
constructing geometry.
2024-09-11 22:08:36 +01:00
John Beard
a3a3f7648e Break ERROR_LOC out to its own header
Having this in geometry_utils.h means that touching
that header affects nearly every file, as this type is used
in EDA_SHAPE, BOARD_ITEM and SHAPE.
2024-09-11 22:08:36 +01:00
John Beard
5925f9c374 Break out some geom functions from dimension text adjustment
Put these in a separate header - they don't need to be available
whenever VECTOR2 is, but they are generic, reusable functions that
can have the corner cases defined and tested.
2024-09-11 22:08:36 +01:00
John Beard
80abdee90d Make hash constexpr
Probably doesn't add much directly, but it documents and
enforces the implied contract that the hash is fixed,
and could be used for, say, compile time hash tables.
2024-09-11 22:08:36 +01:00
John Beard
78cb6c1189 SEG: Correct sign in LineDistance 2024-09-06 19:26:58 +01:00
Seth Hillbrand
538b055c98 Remove ambiguity in MM3_HASH ctor 2024-09-06 10:31:16 -07:00
Seth Hillbrand
5ba50c26a9 Update embedded files hash to use Murmur3
SHA256 is fine for one-offs but for large libraries where we might be
running the hash on hundreds of files, the speed difference is
appreciable.  We don't require crytographic hashing, just a check that
the original file hasn't been corrupted so Murmur3 satisfies our basic
requirement.
2024-09-06 09:57:23 -07:00
Seth Hillbrand
3e5ca2ee7a Modify SHAPE_LINE_CHAIN::Simplify() to fix PNS
Issue raised by TomW, points included in new QA test where Simplify was
not properly removing colinear points.

Also removed TestSegmentHitFast() as the speed gains were minimal when
testing against the revised SEG::SquaredDistance routine in
TestSegmentHit()
2024-09-03 17:23:07 -07:00
Alex Shvartzkop
ebb418f22b Avoid some potential integer overflows in circle.cpp. 2024-08-29 00:35:38 +03:00
John Beard
1fb2d7fe26 Pcbnew: Snap to graphic/track intersections
Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/2329
2024-08-28 13:49:36 +01:00
John Beard
0818ee1770 Pcbnew/FPedit: Add snap anchor type indicators
This allows to see what the current snap point is, which is useful when
zoomed in, or the point is like the corner of a rounded pad where it's
"in free space" and might not be immediately obvious.
2024-08-28 13:49:36 +01:00
Seth Hillbrand
fba2b7a04a Modify previous commit to correct logic
We are calculating the same value in two different ways.  If there is an
off-by-one issue in our calculation along axis, this still means that it
was a direct hit on the line as seen in the unit test cases
2024-08-16 17:05:39 -07:00
Lucas Dumont
f3bbf2b7bd Kimath: Squared distance can't be negative
Fixes https://gitlab.com/kicad/code/kicad/-/issues/18473
2024-08-16 17:05:39 -07:00
John Beard
c7fa61cd94 GTK: Enable IME cancellation on canvas focus
This means that it doesn't start consuming hotkeys for
IME composition in the main canvas on Linux.

Text boxes in dialogs and the property manager, for example,
still receive IME composition.

Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/9882
2024-08-14 14:28:54 +01:00
John Beard
7fc367e688 Pcbnew: Add dogbone corner tool
This adds circular arcs in corners to allow for the router
cutter radius when routing a slot or corner that receives
a sharp corner.

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/18512
2024-08-07 23:01:32 -06:00
Seth Hillbrand
c0d8d87364 Cleanup GetClampedCoords
Previous function would drop some KiROUND calls due to inability to
parse the () operator.  Using the _v template gets the constexpr check,
allowing us to avoid the conditional while running
2024-07-25 21:06:04 +02:00
Seth Hillbrand
368d98ef9e Add optional quiet param to KiRound 2024-07-25 21:05:49 +02:00
Seth Hillbrand
69849ba3ca Replace custom Clamp with std::clamp
Fixes bug in parser that had the elements in the wrong order due to our
custom version not matching the standard order
2024-07-25 19:17:17 +02:00
Seth Hillbrand
1be2d7f8b7 Optimize SEG::SquaredDistance
We don't actually need the closest point to figure out the distance.
Since this calculation is used everywhere, we see some non-negligible
gains by picking the length along the projection
2024-07-25 05:21:06 +02:00
Seth Hillbrand
433677fc21 Replace std::lexicographical_compare_three_way
On platforms that don't yet support the std:: version, we implement our
own, possibly slower, version of the 3-way compare
2024-07-24 18:03:29 +02:00