Commit Graph

114 Commits

Author SHA1 Message Date
André Caldas
9d54668d1e Deletes GCS::Constraint directly instead of calling GCS::free(). 2023-04-06 16:29:48 +02:00
Uwe
b9864e7b0a [Sketch] placecgs: remove unused includes
- also sort includes
- also fix too long lines etc. (done by clang formatter)
2023-03-26 20:27:18 +02:00
Ajinkya Dahale
bae30c6bd7 [Sketcher][planegcs] Fix knot position in non-uniform B-spline
The default factors set in `addConstraintInternalAlignmentKnotPoint` does not
work if the knots around a C1 knot are not equally far.
2023-03-24 16:30:48 +01:00
flachyjoe
21c2eb6014 Sketcher: Add circle to circle distance constraint 2023-03-19 14:05:35 +01:00
Abdullah Tahiri
c604d1741d Console/ILogger: Refactor and extension
=======================================

Refactor:
 - Substitute the use of variadic templates with parameter packs.
 - Use recently incorporated external library "fmt" to handle printf like formating.
 - Extensive cleaning of pragmas and unnecessary forward declarations.
 - Parameter packs and libfmt provide a much stronger type checking now, so
   conversions that are by standard implicit as bool to int need an explicit static_cast
   to avoid compilation warnings.

Extension:
 - Include a notifier field, so that the originator of the message can be provided. E.g. Document#DocumentObject
 - Include a new type of message called CriticalMessage, this message is intended to have
   special behaviour in the future. Namely, it will be used to notify forward compatilibity issues.
   It will be used to substitute the current signal/slot mechanism.
 - Include two new types of messages for user notifications (Notification and TranslatedNotification). This messages
   will be use to convey UI notifications intended for the user (such as non-intrusive message about the usage of a tool). There
   are two versions to mark whether the string provided as a message is already translated or not. When using the console system for
   notifications, these notifications may originate from the App or the Gui. In the former, it is generally the case that the strings
   of messages are not (yet) translated (but they can be marked with QT_TRANSLATE_NOOP). In the latter, often the messages to be provided
   are already translated.

Python support for CriticalMessage, Notification and TranslatedNofification, including shortcuts:

    Crt = FreeCAD.Console.PrintCritical
    Ntf = FreeCAD.Console.PrintNotification
    Tnf = FreeCAD.Console.PrintTranslatedNotification
2023-03-07 16:13:23 +01:00
luzpaz
729685316e Fix trailing whitespace, typos, headers
Fix trailing whitespace, typos, and header uniformity.
2023-01-23 00:34:37 +01:00
Ajinkya Dahale
a034c40c38 [Sketcher] [planegcs] Add point-on-bspline constraint in planegcs
Only non-rational B-spline for now
2023-01-21 21:41:27 +01:00
Abdullah Tahiri
aa67808f24 GCS: Improvements to popularity contest and conflicting identification
======================================================================

1. Instead of excluding internal alignment constraints from popularity candidate selection, exclude them from the group altogether. This
ensures no group is non-empty with uneligible candidates, which prevents an infinite loop in uncommon circumnstances (when DoFs collapse).

2. Ensure no internal alignment constraint is identified when conflict ensues.
2023-01-06 13:49:56 -06:00
Ajinkya Dahale
dd02c7a6f3 [Sketcher][planegcs] Handle type issues with int and size_t
... and `unsigned int`

Suggestions thanks to @abdullahtahiriyo
2022-12-24 18:22:16 -06:00
Ajinkya Dahale
56b19515b6 [Sketcher] [planegcs] Add "tangent at b-spline knot" constraint
Also squashes:

[Sketcher] [planegcs] Support tangent at NURBS knot

...which means support rational B-splines
2022-12-24 18:22:16 -06:00
luz paz
fa98553775 Fix various typos and grammatical issues 2022-11-30 12:45:29 +01:00
Ajinkya Dahale
249ee72333 [Sketcher][planegcs] Make changes as per comments on #7484
Comments by @abdullahtahiriyo.

Remove default values and smaller constructor for `CenterOfGravity` and
`WeightedLinearCombination` constraints.

Clarify comments.

Improve readability of `CenterOfGravity` and `WeightedLinearCombination`
constraints.
2022-11-16 15:35:37 +01:00
Ajinkya Dahale
2537ea883f [Sketcher][planegcs] Set knot constraint as internal alignment 2022-11-16 15:35:37 +01:00
Ajinkya Dahale
7cd2cbd29c [Sketcher] Constrain B-spline knots as linear combination of poles
Also squashes:

[Sketcher] Create center of gravity constraint in planegcs

[Sketcher] typo

[Sketcher] Use accurate "weights" for knots

By weights we mean the linear combination factor B_i(x) such that
spline(x) = sum(pole_i * B_i(x)) for _non-rational_ splines.

[Sketcher] Use more appropriate weights for knots

These are relevant for knots _away_ from any ends (and possibly other high
multiplicity knots).

[Sketcher] Make COG constraint weights user-definable

[Sketcher] Make `flattenedknots` for periodic B-Splines

[Sketcher] Fix incorrect setup of `flattenedknots`

Without ensuring enough space, iterators become invalid. These iterators are
needed because for periodic B-splines we need to pad flattenedknots with offset
values within flattenedknots.

Apparently there is still some iterator issues even after the reserve. Just use
fresh vectors instead.

[Sketcher] Apply knot constraints by parameter

Hopefully this will allow directly applying constraints on knots.

[Sketcher] Disable some knot updating

[Sketcher] Use center of gravity constraint on knots

[Sketcher] Fix knot COG constraint for periodic splines

[Sketcher] Add start/end point of periodic spline to solver

This removes the trouble of transferring constraints to the underlying knot.

[Sketcher] Support knot constraints on rational B-splines

[Sketcher] Remove virtual from overridden methods in planegcs

Follow 0penbrain's comments

[Sketcher][planegcs] Use `unsigned int` in signatures

Also `size_t` at places

Suggestions by @abdullahtahiriyo
2022-11-16 15:35:37 +01:00
Abdullah Tahiri
bffb82d531 Sketcher: Solver - Improvement of popularity contest and bug fix
================================================================

Master has a problem in that internal alignment constraints are suggested to the user for removal.

This is fundamentally wrong, as an internal alignment constraint are an inherent part of the geometry. They cannot be the ones suggested for removal.

The popularity contest algorithm is an heuristic algorithm that determines which redundant/conflicting constraints should be proposed for removal.

Basically, the algorithm works on groups of redundant/conflicting constraints detected via the QR decomposition. A constraint may belong to more than one group.

The algorithm runs some heuristics, each constraint scoring a value, the one constraint from each group scoring the highest is proposed (is more popular and wins the contest).

This PR documents the algorithm, and adds a further condition, that internal alignment constraints are never proposed.

As the solver works with solver constraints as opposed to the sketcher, which works with sketcher constraints, information about whether a solver constraint originated from a
sketcher constraint that is internal alignment is necessary. So the solver constraint is extended to accomodate this piece of information.

As a bonus, it fixes a bug. Solver constraints carry information of the ID of the corresponding sketcher constraint in their tag. Knots are not currently implemented as constraints.
However, the tag index was not being update. This caused the popularity contest to provide wrong suggestions despite good detection.
2022-10-21 19:54:51 +02:00
Ajinkya Dahale
b179ad385b [Sketcher] [planegcs] Add references for equations
Some equations were mentioned by just the number without telling the resource they were from. The book was found couple years ago but not mentioned here.
2022-10-11 08:07:47 +02:00
wmayer
a7bf7869ae Sketcher: modernize C++: replace 'typedef' with 'using' 2022-08-29 23:13:16 +02:00
berniev
b796a0d376 Mod: use empty 2022-08-06 19:30:13 +02:00
wmayer
d344ccc4eb Sketcher: [skip ci] Fix several clazy issues:
* Missing reference in range-for with non trivial type [-Wclazy-range-loop-reference]
* Unused QString [-Wclazy-unused-non-trivial-variable]
* Missing emit keyword on signal call [-Wclazy-incorrect-emit]
* Don't call QList::operator[]() on temporary [-Wclazy-detaching-temporary]
* Use multi-arg instead [-Wclazy-qstring-arg]
* Maybe you meant to call ViewProvider2DObjectGrid::onChanged() instead [-Wclazy-skipped-base-method]
2022-07-25 12:56:09 +02:00
wmayer
ead5154b18 Sketcher: modernize C++11
* use nullptr
2022-03-23 19:26:15 +01:00
Abdullah Tahiri
727dc9fa9e Sketcher: Fix wrong diameter reference constraint value when blocked
====================================================================

Fixes:
https://forum.freecadweb.org/viewtopic.php?p=474276#p474276
2021-02-06 06:22:30 +01:00
Abdullah Tahiri
186f5a4c19 GCS/Sketcher: Add equal length line constraint using the new single constraint 2021-01-23 07:53:28 +01:00
Abdullah Tahiri
65fb44df6c GCS: report partially redundant constraints 2021-01-23 07:53:28 +01:00
Abdullah Tahiri
2625aabe25 Sketcher/GCS: New Block constraint fixes
========================================

Previous versions relied on a heuristic that proved insufficient for cummulative use of the Block constraint.
The effect is that Block constraints stopped blocking, which is a major bug, as it lead to inadvertedly moving
geometry that was supposed to be blocked.

Fixes:
https://forum.freecadweb.org/viewtopic.php?f=13&t=53515&start=30#p461215
(Thanks Chaospilot)

Know problems with old block constraint (v0.18):
1. If driving constraints were present, they were ignored if inserted before the block constraint (to avoid
redundancy/conflicting). They resulted in

Principles of Working of the new block constraint:
1. Handling of the new block constraint is based two processes, a pre-analysis and a post-analysis. Pre-analysis
works *before* diagnosing the system in the solver. Post-analysis works *after* diagnosing the system in the solver.

2. Pre-analysis is directed to detect geometries affected *exclusively* by a block constraint. This is important
because these geometries can be pre-fixed when creating the solver geometry and constraints before GCS::diagnose()
via initSolution() AND because if no other constraint affects the geometry, the geometry parameters won't even appear
in the Jacobian of GCS, so they won't be reported as dependent parameters (for which post-analysis would be of no use).

3. Post-analysis is directed to detect Geometries affected *not only* by a block constraint. This is important
because pre-fixing these geometries would lead to redundant constraints. The post-analysis, enables to fix just the
parameters that fulfil the dependacy groups.

4. Post-analysis basically identifies which parameters shall be fixed to make geometries having blocking constraints
fixed, while not leading to redundant/conflicting constraints. These parameters must belong to blocked geometry. This
is, groups may comprise parameters belonging to blocked geometry and parameters belonging to unconstrained geometry. It
is licit that the latter remain as dependent parameters. The former are referred to as "blockable parameters". Extending
this concept, there may be unsatisfiable groups (because they do not comprise any bloackable parameter), and it is the
desired outcome NOT to satisfy such groups. It must be emphasised that there is not a single combination of fixed parameters
from the blockable parameters that satisfy all the dependency groups. However:
     1) some combinations do not satisfy all the dependency groups that must be satisfied (e.g. fixing one group containing
        two blockable parameters with a given one may result in another group, fixable only by the former, not to be satisfied).
        This leads, in a subsequent diagnosis, to satisfiable unsatisfied groups.
     2) some combinations lead to partially redundant constraints, that the solver will silently drop in a subsequent diagnosis,
        thereby reducing the rank of the system fixing less than it should.

5. The implementation rationale is as follows:
     1) The implementation is on the order of the groups provided by the QR decomposition used to reveal the parameters
        (see System::identifyDependentParameters in GCS). Zeros are made over the pilot of the full R matrix of the QR decomposition,
        which is a top triangular matrix.This, together with the permutation matrix, allow to know groups of dependent parameters
        (cols between rank and full size). Each group refers to a new parameter not affected by the rank in combination with other free
        parameters intervening in the rank (because of the triangular shape of the R matrix). This results in that each the first column
        between the rank and the full size, may only depend on a number of parameters, while the last full size colum may dependent on
        any amount of previously introduced parameters.
     2) Thus the rationale is to start from the last group (having **potentially** the larger amount of parameters) and selecting as blocking
        for that group the latest blockable parameter. Because previous groups do not have access to the last parameter, this can never
        interfere with previous groups. However, because the last parameter may not be a blockable one, there is a risk of selecting a parameter
        common with other group, albeit the probability is reduced and probably (I have not demonstrated it though and I am not sure), it
        systematically leads to the right solution in one iteration.

GCS: Change dependency group from std::set to std::vector to prevent reordering of parameters.
2020-12-30 18:59:15 +01:00
wmayer
0f31c87cc9 Boost: [skip ci] Fix build warnings from deprecated Boost headers (v1.75) 2020-12-29 15:34:25 +01:00
luz paz
4327243a0a Sketcher: Fix typos and code linting [skip ci] 2020-12-28 23:15:22 +01:00
Abdullah Tahiri
a790e32605 GCS: Const correctness and override qualifier
=============================================

Make several functions operate as const.
Use the override qualifier
2020-12-27 08:24:43 +01:00
Abdullah Tahiri
c2ab51314d GCS: Return a zero sized reduced Jacobian if only driven constraints present
=============================================================================

The reduced Jacobian defaults to the size of the full Jacobian, where driven constraints
and parameters are not considered to build the reduced Jacobian and thus empty rows remain.

This is generally not a problem as QR decomposition ignores this rows, except in case where
only driven constraints exist. In such a case no QR decomposition is necessary, and in fact
relying on the size of the QR decomposition leads to the incorrect result that the sketch
is fully constraint, when the opposite is true.

This commit resizes an effectively empty reduced Jacobian to avoid this issue.

Fixes the problem that a line with a single reference constraint is shown as fully constraint.
2020-12-27 08:24:43 +01:00
Abdullah Tahiri
af605e4066 GCS: Improve documentation about debug
======================================

Explicitly indicate that if parameter diagnosis must be silent=false in order to debug,
then the lauch policy during the debug must be set to deferred in order to avoid concurrent
access to Base::Console which is not thread-safe.
2020-12-24 11:59:51 +01:00
Abdullah Tahiri
e3873a73e9 GCS: enable to invalidate diagnosis result 2020-12-21 05:57:42 +01:00
luz paz
ea0ce293f7 Fix typos [skip ci]
Found via `codespell v2.1.dev0`  
```
codespell -q 3 -L aci,ake,aline,alle,alledges,alocation,als,ang,anid,apoints,ba,beginn,behaviour,bloaded,byteorder,calculater,cancelled,cancelling,cas,cascade,click,dum,eiter,elemente,ende,feld,finde,findf,freez,hist,iff,indicies,initialisation,initialise,initialised,initialises,initialisiert,ist,kilometre,lod,mantatory,methode,metres,millim,ot,pard,pres,programm,que,recurrance,rougly,seperator,serie,sinc,strack,substraction,te,thist,thru,tread,uint,unter,vertexes,wallthickness,whitespaces -S ./.git,*.po,*.ts,./ChangeLogpios++,./src/Base/swig*,./src/Mod/Robot/App/kdl_cp,./src/Mod/Import/App/SCL,./src/WindowsInstaller,./src/Doc/FreeCAD.uml
```
2020-12-19 16:35:16 +01:00
Abdullah Tahiri
621a9a0e98 GCS: Set SparseQR conditional compilation guards 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
e0a814bfc7 GCS: Change asynchronous launch policy to default to avoid having to take care of exceptions on oversubscription
================================================================================================================

std:async can take two policies one that forces the task to be run in parallel another (deferred) that runs the task
when wait is called on the future (kind of lazy evaluation).

Default policy is let the system decide (an or of both policies). Nobody is a better position than the system to know
its load and whether it is possible to run the task in parallel or not.

If the system cannot allocate a thread and parallel processing is enforced (as before this commit), then it will throw an
exception. In the present case we would catch it and run the task sequencially. Thus, it makes sense to let the system
decide from the beginning and save the exception and the handling.

In tests I have only managed to see it run in parallel with the default policy.
2020-12-19 11:58:54 +01:00
Abdullah Tahiri
28415f53d4 GCS: renaming parameters to make them more descriptive 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
7f006e2c75 GCS: Augment information provided by GCS with groups of dependent parameters 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
270b0cbc33 GCS: Interface to query whether the used diagnose matrix is empty
=================================================================

Diagnose constraints do not include among others driven constraints. This
function allows to know whether the solver is considering an empty matrix.
2020-12-19 11:58:54 +01:00
Abdullah Tahiri
996f006de3 GCS: Deactivate Debug code and fix warnings in non-Debug mode 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
b2fd91c333 GCS: Asynchronous full geometry parameter identification for Dense QR 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
5e2a2cbbbb GCS: Make QR decompositions for constraints and parameters run asynchronously 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
9f2d34ac4b GCS: QR profiling debug code 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
ac7f6b8ceb GCS: Rewrite diagnose() so that it has a single return point 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
474d5550cf GCS: Diagnose() - Separate DenseQR and SparseQR 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
c635b4b954 GCS: Refactor new SparseQR Dependent Parameter detection code and const correctness 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
2d37d7194a GCS: Detect dependent parameters (geometry) during diagnosis using two SparseQR factorisations 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
982591b0d4 GCS: makeSparseQRDecomposition generalise for transposed and non-transposed matrices 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
820b02b295 GCS: SparseQR compilation guards 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
0f9af72f25 GCS: reduce input parameters in makeDenseQRDecomposition 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
dd4b29333a GCS: Refactor Non-Zero elimination over pivot 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
ed5af06d14 GCS: Refactor diagnose identification of conflicting and redundant constraints 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
a5927e1a61 GCS: Refactor dependent parameters identification which is only available for DenseQR 2020-12-19 11:58:54 +01:00