Commit Graph

516 Commits

Author SHA1 Message Date
Abdullah Tahiri
2a54fba098 Sketcher: SparseQR as default QR method
=======================================

The SparseQR is set as default method. However, in accordance with the previous commit, only if a new enough Eigen library is present will SparseQR be executed.

If the library is old and SparseQR can not be reliably used, FC will automatically fall back to use DenseQR.

This ensures that users that have a new enough library > 3.2.2 will benefit from the performance increase, while the users that use older library will still have
the same performance as in legacy FC.
2015-06-24 17:57:06 +02:00
Abdullah Tahiri
ffaa0c8249 Sketcher: SparseQR conditional compilation
==========================================

For Eigen>=3.2.2 SparseQR is compiled in

For older versions SparseQR is not compiled in and if the option is selected FC gives a warning in the console and falls back to DenseQR.

This ensures that a user can get a sketch solved and work normally even if SparseQR is selected and the Eigen version is too old to support SparseQR.
2015-06-24 17:57:05 +02:00
Abdullah Tahiri
1fc88ebe24 Sketcher: Auto Update Mode bug fix
==================================

Bug:
http://forum.freecadweb.org/viewtopic.php?f=10&t=11341&start=60#p92422

Why?
- When coding Auto Update Mode I forgot to solve the sketch when the constraint is cancelled to restore the solver level constraints.
2015-06-24 17:57:05 +02:00
Abdullah Tahiri
82e24d830e Sketcher: Solver Advanced Control: New Param: QR Pivot Threshold
================================================================

A new parameter added to the form in order to control how low a value should be
to be considered zero (how high a value shall be to be accounted for in rank calculation)

Debug for QR pivot threshold is also added.
2015-06-24 17:57:04 +02:00
Abdullah Tahiri
8f68b14627 Sketcher: DL Solver Debug Improvement
=====================================

- In "Iteration Level" debug mode, DL now shows the stop condition code.
- More debug code
2015-06-24 17:57:04 +02:00
Abdullah Tahiri
efb08cd11c Sketcher: Disable Eigen multithread
===================================

Eigen currently only provides multithread for matrix products. It has been reported that it is even slightly slower than single-thread.
Therefore, temporarely the code is commented out. If Eigen ever implements multithread for QR decomposition, then it will make a lot of
sense to enable this.
2015-06-24 17:57:03 +02:00
Abdullah Tahiri
7f442c5a3f Sketcher: Improvement: Continuous Mode - View sketch Perpendicular
==================================================================

It allows the view sketch perpendicular button to be active during continuous mode creation (and if activated does not exit the continuous mode).

Feature requested:
http://forum.freecadweb.org/viewtopic.php?f=10&t=11051&start=30#p92256
2015-06-24 17:57:02 +02:00
Abdullah Tahiri
22bcb40484 Sketcher: Bug fix: Dense QR is set by default
=============================================

EigenQR branch 3.2 with debug code fails an assertion. The result is generally ok if we disable the assertions, however it
eventually leads to memory leakage.

This commit reenables Eigen's assertions when in debug mode, and sets dense QR as default QR algoritm until Eigen's issue is solved.
2015-06-24 17:57:02 +02:00
Abdullah Tahiri
cb2d70b4f0 Sketcher: Bug fix: Solver Advanced Control in BFGS
==================================================

- ternary operator usage was making BFGS not to iterate
- Amount of debug information for BFGS increased
2015-06-24 17:57:01 +02:00
Abdullah Tahiri
86f0df4f3c Sketcher: Improvement Continuous Creation Mode: Leave Sketch
============================================================

This enables to exit the sketch by clicking the corresponding toolbar icon, even when in creation mode, i.e.
with a drawHandler active.

Requested here:
http://forum.freecadweb.org/viewtopic.php?f=10&t=11051&start=30#p92181
2015-06-24 17:57:01 +02:00
Abdullah Tahiri
f3592c1216 Sketcher: Improvements: Solver Advanced control
===============================================

- Increased solver debug
- Changing default values from float to string, as float has "only" a precision of 12 decimals.
- Default values as macros
2015-06-24 17:57:00 +02:00
Abdullah Tahiri
516b0d3c56 Sketcher: Workaround for Eigen bug: SparseQR crash on matrices with rows>cols
=============================================================================

There is an issue with an assertion in Eigen, as reported here:
https://forum.kde.org/viewtopic.php?f=74&t=117474
http://forum.freecadweb.org/viewtopic.php?f=10&t=11341&p=92153#p92146

The work-around is to disable debug assertions for Eigen until the problem
gets solved.
2015-06-24 17:57:00 +02:00
Abdullah Tahiri
6030da1182 Sketcher: Solver improvements and bug fixes
===========================================

- Improvement Debug added to redundant solving in Iteration Mode, to show when just one iteration solved the system
- Fix wrong QR information on empty sketch
2015-06-24 17:56:59 +02:00
Abdullah Tahiri
bae32f74bb Sketcher: New setting: Show advanced solver taskbox
===================================================

I makes the advanced solver taskbox by default disabled (not shown) and provides
a setting in Preferences->Display->Sketcher to enable it.
2015-06-24 17:56:59 +02:00
Abdullah Tahiri
796c9d79d4 Sketcher: New Features: SparseQR decomposition and Solver advanced control TaskBox
==================================================================================

The solver has been adapted to use Eigen's SparseQR QR decomposition algorithm. The original
Dense QR implementation is maintained and can be selected using the Advanced Control TaskBox (see below).

The use of SparseQR provides over an order of magnitude improvement in solving time in complex sketches due to
the Sparse nature of the Jacobian matrix of the system of equations.

The solver advanced control is a new TaskBox in the Sketcher that allows to select which algorithms are to be used for
the different solving operations and tweak its parameters. It is not intended to be a user control, but means to debug
solving problems and improve the algorithms and their configuration.

This commit also introduces multithread support for Eigen. Currently it is only limited to products and does not provide
a substantial speed improvement. It is expected to have more multithreaded operations in Eigen in the future.

As a bonus, the TaskBoxes in the Taskbar of the Sketcher remember the last state (collapsed or deployed).
2015-06-24 17:56:58 +02:00
Abdullah Tahiri
480d23f8e1 Sketcher: Bug fix: Unexpected crashes during certain operations
===============================================================

The sketcher crashed for example during effecting a fillet operation.

Cause:
The ElementsWidget/ConstraintWidget was being updated as a consequence of adding/removing geometry/constraints, and it was effecting
a selection after the update, in cases where the geometry in the screen was not being redraw (because the sketchobject was still unsolved), therefore
trying to select an element that according to ViewProvider did not exist (as it is created during redraw).

Solution:
Widgets update when their properties changes, provided that a redraw is effected (which actually also saves some (negligible) time, as they are only updated when they should).
2015-06-24 17:56:57 +02:00
Abdullah Tahiri
93c836fdcf Sketcher: Bug fix Trim
======================

In no update mode, the last constraint was not enforced. The DoF was not properly shown.

The trim operation it is always solved at the end now if in no recompute mode.
2015-06-24 17:56:56 +02:00
Abdullah Tahiri
65310f00ab Sketcher bug fixes: Crash on deleting a line from the sketch
============================================================

- Crashing on deleting line on fully constraint box

As a bonus:
- Fully constrained sketch not shown in green on opening the sketch
2015-06-24 17:56:56 +02:00
Abdullah Tahiri
074d5d7f11 Sketcher: Bug fix External geometry not appearing upon insertion
================================================================

A last moment change to regulate redrawing introduced this issue (reducing the redrawing to the cases where the solver geometry and the sketchObject geometry are equal).
This change also solved other issues.

The case of adding external geometry is special because the DoF is the same after insertion, yet there is an insertion (as opposed to the toggle case, where there is a change but no insertion).

SketchObject has been adapted to require a solver update before moving (which also caused a non-yet-reported crash, a separate bug), and CommandCreateGeo has been adapted to trigger a solve with
auto update mode disabled. This solve is a very low cost one as the geometry is already in place.
2015-06-17 14:53:34 +02:00
wmayer
238becaebb + further optimization in sketcher 2015-06-16 10:18:11 +02:00
wmayer
788fadf4a8 + fix const correctness 2015-06-15 23:42:37 +02:00
Abdullah Tahiri
ec5f3b2b98 Sketcher: new Feature: Group creation of Sketcher geometry and other improvements and bug fixes
===============================================================================================

Group creation:
- complex geometries (consisting of several geometry elements and constraints) have been rewritten to use python list (one command call for all geometries and constraints)
- Ellipse ExposeInternalGeo as group creation of geometries and constraints

To construction mode creation:
- addGeometry python and SketchObject functions modified to take an additional optional parameter "construction" to create the geometry/geometries directly as construction.
  In addition to the shorter form, this helps generate less amount of onChange propagation and Redraws.
- all the geometry creation commands in CommandCreateGeo.cpp have been rewritten to use the new construction argument. This includes modifying the regular polygon script to
take a new optional parameter to create geometry as construction in addGeometry.
- special care is taken in group creation not make construction points
- Show/hide internal geometry implemented with this option.

To solving:
- the solve previously included after every geometry addition (when in no Update, e.i. no Recompute mode) has been removed and each Gui::Command calls either an UpdateActive
for recompute or a Solve in no Update mode. This is behaviour is less intrusive and uniform with group creation.

Bug fixes and redrawing reduction:
- Fixes the CheckId exception problem. The solution also helps further remove redraws during creation of complex geometry (e.g. Slot)
- Fixes touching the sketch by only opening it.
- Code clean up.
2015-06-15 22:56:36 +02:00
Abdullah Tahiri
61bd2d41ac Sketcher: Requested Feature: Remove help button
===============================================

The help button next to the close button in the Task dialog is now removed.

It was requested that this button is removed as it is inconsistent with other help sources and it is not implemented.
2015-06-15 22:56:20 +02:00
Abdullah Tahiri
d1acd124cc Sketcher: Bug fix: Undo/Redo implementation
================================================

Fixes a bug in master that the dependent 3D geometry would not update on Undo (in Auto update mode enabled).

Undo and redo signals are handled by ViewProvider in order to introduce an recompute or solve() of the sketchObject
as determined by the Auto Update Mode in order to update DoF and dependent geometry if necessary.
2015-06-15 22:56:04 +02:00
Abdullah Tahiri
eb7a3c763c Bug fix: General reduction solution / new sketch solving model
=================================================================

The new solving architecture focus all the solving on the SketchObject.

Actions that change the DoF can call execute() (i.e. recompute) or Solve() depending on whether a full recompute of dependent features is required or not.
In both calls the geometry of the solver is updated with the geometry of the SketchObject.

The only additional call that calls the solver is MovePoint. This function may or may not update the geometry of the SketchObject
(as now it is intended for UI related solving, like dragging, rubberbands, ...).

In operations that do not involve a change of DoF and therefore do not require a sketch solving, it may happen that as a side effect of moving a point, the
geometry changes to old behaviour. In order to avoid that, those SketchObject operations, as for example setConstruction or ToggleConstruction,
must set a flag "bool solverNeedsUpdate" to true. In case a movePoint is executed before any other solver execution, the geometry is first updated and then
the moving is performed.

So to keep in mind when programming sketcher operations:
-> Need recompute (UpdateActive)
-> Need solving because DoF changed (solve())
-> The operation does not change DoF (set solverNeedsUpdate to true)
2015-06-15 22:55:28 +02:00
Abdullah Tahiri
4b0bd78814 Sketcher: Bug fixes to Auto-Update Mode
=======================================

- Fixing toggle AutoUpdate Mode
- Fix Auto-Update Sketcher tools
- Fix missing createGeo recomputes
- Missing constraints recomputes fixed

Various fixes for non-Update mode:
- Fixes lack of update upon entering a conflicting datum constraint.
- Fixes lack of update upon setting the reference/driving status of a constraint

- Added tooltips to buttons
2015-06-15 22:55:04 +02:00
Abdullah Tahiri
339717c96f Sketcher: Bug fix of New Solver Model: DoF and solver update on deletion of constraints
=========================================================

Upon deletion of a constraint, the constraint was still enforced for UI operations (dragging of a point) and DoF was not updated.
2015-06-15 22:54:49 +02:00
Abdullah Tahiri
a21265f9b6 Sketcher: New Feature: Avoiding to continuously recompute all the sketch (and dependent objects)
======================================================================================

There is a checkbox, default disabled, that makes the commands NOT to generate a recompute after each.
This means that if you are editing a sketch that is used to generate a pad or pocket, if the checkbox is
disabled, the dependent objects do not get recomputed.

There is a button next to it to force a manual recompute, in case it is needed.

If the user wants the previous behavior, he only needs to activate the checkbox. The previous status of the box
is restored upon entering a sketch in edit mode.

It is remarkable the case of the Fillet and Trim

On changing ActSketch (solvedSketch) to SketchObject and making movePoint not systematically update the geometry, the solving in MovePoint was confronted with solving for "the last solved geometry",
which is the default behaviour, in some situations (Fillet and Trim) where geometry had changed at SketchObject level, and was the subject of the moving actions.

MovePoint has been updated to take an extra optional parameter, to force the change in solved geometry in those situations.

Some other minor bug also fixed in Fillet creation in CommandCreateGeo.cpp

This commit also introduces conditional recompute on some operations of:
- constraints
- geometry creation (reubication of update active to comprise the autoconstraints within a single UpdateActive)
2015-06-15 22:54:32 +02:00
Abdullah Tahiri
0e92e6356f Sketcher: Major re-structuration: New Solving Model: General Sketch Solve call reduction
=======================================================================================

ActSketch in ViewProvider dissapears. The temporal sketch (sketch.cpp) for solving is now a data member of SketchObject.cpp (hereinafter solvedSketch). All the solving is concentrated in SketchObject.cpp.

SketchObject provides an interface to expose its solver, as it is still currently needed for some UI operations from ViewProviderSketch, like dragging points (solving rubber bands).

ViewProviderSketch still can select whether to draw the solvedSketch geometry (previously ActSketch) geometry (UI staff) or the SketchObject geometry. Performancewise, it makes sense to separate this two
geometries, as the SketchObject one involves modifying the Geometry and Constraint Properties (including all the undo related functionality), which would mess the undo functinality and incur in a big
peformance penalisation while dragging. One characteristic of solvedSketch is that its geometry is solved, whereas the geometry of SketchObject may not have been solved yet.

These geometries may differ at for the following reasons:
1. The geometry corresponds to an ongoing dragging operation, so solvedSketch has the last calculated dragging geometry, while SketchObject has the one corresponding to initial position.
2. Geometry/constraints were added to the sketch, but no solve/execute was triggered yet (envisioned situation is the future group creation functionality not in this commit).

What do I gain?

- Inserting a (simple) geometry element now costs 1 solver execution.
- Inserting a constraint now costs 1 solver executions.

For reference, in previous versions inserting a constraint involved 5 solver executions.

The following information provide a historical review of the coding of this commit (formed of 10 squashed commits):

This is a general sketch solve call reduction, not only during geometry creation (this commit does not include until here any specific measure to reduce calls on geometry creation, that is another branch)

After a lot of profiling, it seems that the "cause"(tm) that creates so many solver calls is that every update generates a solving in ViewProviderSketch, regardless of the need for that update,
many times with the only aim of providing the DoF for the message dialog and keeping ActSketch in sync with SketchObject in case it is needed (currently UI moving points, constraints,...).

Sketch solver is now a data member of SketchObject instead of a temporal object that gets initilized and destroyed.

This allows:
1. Potentially more synergy reducing calls to setUpSketch (still to be seen, still to be optimized)
2. Allowing SketchObject to access the latest geometry that has been solved => In future, allow objects that use SketchObject to obtain the latest
solved geometry instead the geometry of SketchObject that may still be unsolved. This is relevant for drawing the geometry

No more solving in ViewProviderSketch. Solving a Sketch is now an exclusive competence of SketchObject.

There is however a lot of cleaning to do in ViewProviderSketch

(I mean, not that these commits are making a mess in VPSketch,
but that as a consequence of the changes, it should be possible to
optimize VPSketch, specially moving and drawing methods)

Very useful comment for future developers that may wonder why a solve per constraint just upon addition is necessary.

Added a new function to get the size of the geometry of the instance of the solver object (Sketch.cpp).
The previous way was to extract the geometry, which is costly and error prone, as you have to delete it afterwards.

Inserted comment about the necessity of triggering a Part2D update during edit mode
2015-06-15 22:53:59 +02:00
Ian Rees
418cefd7ee Cleaning up compile warnings, mainly in Sketcher
fabs() instead of std::abs(), add cmath include
2015-06-04 18:12:39 +02:00
wmayer
c3808cd991 + Use update mechanism for CmdSketcherToggleConstruction 2015-06-03 19:12:48 +02:00
wmayer
cf1a77a44d + Use update mechanism for CmdSketcherToggleDrivingConstraint 2015-06-03 18:31:30 +02:00
wmayer
a12f700aa2 + fix some warnings 2015-05-30 20:59:25 +02:00
wmayer
351e7aae6f + fix wrong default of ContinueMode in settings panel 2015-05-30 20:42:33 +02:00
wmayer
eef340f19c + fix whitespaces 2015-05-30 20:30:12 +02:00
Abdullah Tahiri
3b1873f1dc Sketcher Improvement: Always enable geometry creation
==============================================================================

Now you can switch from one tool to the next just by clicking on the next tool
2015-05-30 16:39:34 +02:00
Abdullah Tahiri
ca356c308e Sketcher Driving/Reference and Construction/Normal single buttons icons
=======================================================================
2015-05-30 16:39:33 +02:00
Abdullah Tahiri
0bd3801314 Sketcher: UI Improvement Smart button for constraints and geometry toogle/creation
==================================================================================

Geometry button:
- if no object selected, the legacy toggle icon has a new functionality, switch to/from creating in construction mode
- if object selected, it has the legacy functionality
- the button can be clicked during "continuos creation mode" to switch from creating to/from creating in construction mode

Constraint button:
- The button is not selectable if nothing is selected (it would be impossible to determine the effect)
- When constraints are selected, the button toggles the constraints to/from Driving.
- When geometry is selected, the button switches from/to reference mode, the change is apparent from the color of the constraint icons.

Continuous creation mode:
- Default changed so that it is active unless you change it in settings

Updated terminology
2015-05-30 16:39:32 +02:00
Abdullah Tahiri
a1c3b942aa Sketcher: Driving/reference creation improvements and some other fixes
======================================================================

- Changing from Driving to reference does not include unnecessary solvings.
- Added some checks to avoid making Driving constraints when calling directly from python and involving only external geometry (would give redundant constraints).
- New python command toggleDriving to just change the status from reference to Driving
- New UI toolbar Command to toggle constraints
- Fix to allow switching from/to construction mode during continuous mode creation.
- Enable/Disable for constraints in constraints widget has changed to operate on multiselection and now effects "toggle" instead of enable/disable.
- Disable the option to directly create a SnellsLaw non-driving constraint (this constraint does not support direct creation, it can be toggled to non-driving after creation though).
2015-05-30 16:39:32 +02:00
Abdullah Tahiri
4dfc96e102 Bug fix: Point was created as construction on construction mode
==============================================================

Points should not be construction points.
2015-05-30 16:39:31 +02:00
Abdullah Tahiri
8685e94b76 Bug fix: Sketcher fillet on construction lines
==============================================

The fillet applied to construction lines generates normal (not construction) geometry.

How to replicate?
1.Make a square and make all lines construction lines.
2.Apply fillet tool, there result will be a white line fillet connecting two blue constructions lines.
2015-05-30 16:39:31 +02:00
Abdullah Tahiri
75fa12964e Sketcher Driving/reference mode icons 2015-05-30 16:39:30 +02:00
Abdullah Tahiri
765b720c48 Sketcher New Feature: Toggle Mode for Reference/Driving constraints
===================================================================

It allows to create constraints directly into Reference or Driving mode.

It does not include icons
2015-05-30 16:39:30 +02:00
Abdullah Tahiri
d5ec887526 Sketcher: Construction Mode Icons 2015-05-30 16:39:28 +02:00
Abdullah Tahiri
1c803df7d4 Sketcher new Feature: Creation Mode of geometry
===============================================

It allows to select whether the geometry will be created as construction geometry or normal geometry.

This commit includes an important bug fix to reduce the number of times the sketcher solver is called when toggling
geometry. It makes an important difference in the creation during construction mode and InternalAligment geometry like the ellipse.

This commit does not include icons.

You have a button next to toggle that after having been clicked, switches from Normal to Construction geometry and vice versa
2015-05-30 16:39:28 +02:00
Abdullah Tahiri
3231a0c92a Sketcher: New Feature: External Geometry Linking improvement
============================================================

It lifts the need of clicking on the external geometry icon upon importing each external geometry element.

All the elements on which the user clicks are imported until the user right clicks with the mouse or presses ESC, like the Trim or Fillet tools.
2015-05-30 16:39:27 +02:00
Abdullah Tahiri
ba5a8fe87c Sketcher: New Feature: Continuous creation mode
===============================================

When creating a type of geometric element, the user can create as many elements of that type he wishes without having to click the button before each insertion.

The insertion of that type of elements ends by pressing ESC or clicking the right button of the mouse.

This mode is by default disabled and can be enabled in Preferences->Display->Sketch->Geometry Creation "Continue Mode".
2015-05-30 16:39:26 +02:00
Abdullah Tahiri
f7c9566f1e Sketcher bug fixes: Non-driving constraints editable on double click and color settings not working
===================================================================================================

This fixes a bug in the original implementation, that a non-driving constraint value could be
edited by double clicking on it in the 3D view.

It also includes minimal documentation on some functions.

It also includes:
- Color setting for non-driving constraints was not working.
- Settle UI terminology dispute:
  * Driving Constraint (normal red constraint)
  * Reference Constraint (non-driving constraint)
2015-05-30 16:39:26 +02:00
Abdullah Tahiri
ad180fb2c3 Sketcher New Feature: Non-driving constraints Icons by bejant
=============================================================

Nice icons to differentiate driving from non-driving constraints by bejant
2015-05-30 16:39:25 +02:00
Abdullah Tahiri
bc85670ce9 Sketcher new Feature: Non-driving constraints (aka Driven constraints or dimensions)
====================================================================================

It allows to enable and disable a constraint in the constraint list.

When disabled, the constraints current value is shown, but its value is not enforced (it is driven by the other constraints and user interaction).

A disabled constraint can be enabled (as far as it is enforceable, see non-driving constraints to external geometry below).

The sketcher functionality has been extended to support non-driving constraints to external geometry elements. This were previously excluded from
the possibility of creating a constraint on them (as their values depend on other sketches and would be redundant with the unchanged value or conflicting when value is changed).
Now these constraints are created as non-driving, but as they are not enforceable, the UI does not allow you to make them driving.

The constraint filter has been extended to include a Non-Driving constraints category.

Thanks again to Werner for his continuous support, and specially in this case to DeepSOIC, as he pointed towards a much better implementation solution than my original idea.
2015-05-30 16:39:25 +02:00