Commit Graph

251 Commits

Author SHA1 Message Date
0penBrain
2c2b9752fd [Sketcher] Fix check for fixed items in tangent+perpendicular 2022-02-06 05:12:15 +01:00
wmayer
ad7ab573eb PD: PrefQuantitySpinBox now requires an explicit entry name for the parameter group 2022-01-31 16:47:08 +01:00
Abdullah Tahiri
92e6094449 Sketcher: EditModeCoinManager/DrawSkechHandler refactoring
======================================================

Creation of EditModeCoinManager class and helpers.

In a nutshell:
- EditModeCoinManager gets most of the content of struct EditData
- Drawing is partly outsourced to EditModeCoinManager
- EditModeCoinManager gets a nested Observer class to deal with parameters
- A struct DrawingParameters is created to store all parameters used for drawing
- EditModeCoinManager assume responsibility for determining the drawing size of the Axes
- Preselection detection responsibility is moved to EditModeCoinManager.
- Generation of constraint nodes and constraint drawing is moved to EditModeCoinManager.
- Constraint generation parameters are refactored into ConstraintParameters.
- Text rendering functions are moved to EditModeCoinManager.
- Move HDPI resolution responsibility from VPSketch to EditModeCoinManager
- Move responsibility to create the scenograph for edit mode to EditModeCoinManager
- Move full updateColor responsibility to EditModeCoinManager
- Allows for mapping N logical layers (LayerId of GeometryFacade) to M coin Layers (M<N). This
is convenient as, unless the representation must be different, there is no point in creating coin
layers (overhead).

Refactoring of geometry drawing:
- Determination of the curve values to draw are outsourced to OCC (SRP and remove code duplications).
- Refactor specific drawing of each geometry type into a single template method, based on classes of geometry.
- Drawing of geometry and constraints made agnostic of scale factors of BSpline weights so that a uniform treatment can be provided.

Refactoring of Overlay Layer:
- A new class EditModeInformationOverlayConverter is a full rewrite of the previous overlay routines.

ViewProviderSketch:
- Major cleanup due to migration of functionalities to EditModeCoinManager
- Reduce public api of ViewProviderSketch due to refactor of DrawSketchHandler
- Major addition of documentation
- ShortcutListener implementation using new ViewProvider Attorney
- Gets a parameter handling nested class to handle all parameters (observer)
- Move rubberband to smart pointer
- Refactor selection and preselection into nested classes
- Removal of SEL_PARAMS macro. This macro was making the code unreadable as it "captured" a local stringstream that appeared unused. Substituted by local private member functions.
- Remove EditData
- Improve documentation
- Refactor Preselection struct to remove magical numbers
- Refactor Selection mechanism to remove hacks

ViewProviderSketchDrawSketchHandlerAttorney:
- new Attorney to limit access to ViewProviderSketch and reduce its public interface
- In order to enforce a certain degree of encapsulation and promote a not too tight coupling, while still allowing well
defined collaboration, DrawSketchHandler accesses ViewProviderSketch via this Attorney class.
-DrawSketchHandler has the responsibility of drawing edit temporal curves and markers necessary to enable visual feedback
to the user, as well as the UI interaction during such edits. This is its exclusive responsibility under the Single
Responsibility Principle.
- A plethora of speciliased handlers derive from DrawSketchHandler for each specialised editing (see for example all the
handlers for creation of new geometry). These derived classes do * not * have direct access to the
ViewProviderSketchDrawSketchHandlerAttorney. This is intentional to keep coupling under control. However, generic
functionality requiring access to the Attorney can be implemented in DrawSketchHandler and used from its derived classes
by virtue of the inheritance. This promotes a concentrating the coupling in a single point (and code reuse).

EditModeCoinManager:
- Refactor of updateConstraintColor
- Multifield - new struct to identify a single element in a multifield field per layer
- Move geometry management to delegate class EditModeCoinGeometryManager
- Remove refactored code that was never used in the original ViewProviderSketch.

CommandSketcherBSpline:
- EditModeCoinManager automatically tracks parameter change and triggers the necessary redraw, rendering an explicit redraw obsolete and unnecessary.

Rebase on top of master:
- Commits added to master to ViewProviderSketch applied to EditModeCoinManager.
- Memory leaks - wmayer
- Constraint Diameter Symbol - OpenBrain
- Minor bugfix to display angle constraints - syres

Architecture Description
=======================

* Encapsulation and collaboration - restricting friendship - reducing public interface

Summary:
- DrawSketchHandler to ViewProviderSketch friendship regulated via attorney.
- ShortcutListener to ViewProviderSketch friendship regulated via attorney.
- EditModeCoinManager (new class) to ViewProviderSketch friendship regulated via attorney.
- ViewProviderSketch public interface is heavily reduced.

In further detail:
While access from ViewProviderSketch to other classes is regulated via their public interface, DrawSketchHandler, ShortcutListener and EditCoinManager (new class) access
to ViewProviderSketch non-public interface via attorneys. Previously, it was an unrestricted access (friend classes). Now this interface is restricted and regulated via attorneys.
This increases the encapsulation of ViewProviderSketch, reduces the coupling between classes and promotes an ordered growth. This I call the "collaboration interface".

At the same time, ViewProviderSketch substantially reduces its public interface. Access from Command draw handlers (deriving from DrawSketchHandler) is intended to be restricted to
the functionality exposed by DrawSketchHandler to its derived classes. However, this is still only partly enforced to keep the refactoring within limits. A further refactoring of
DrawSketchHandler and derivatives is for future discussion.

* Complexity and delegation

Summary:
- Complexity of coin node management is dealt with by delegation to helper classes and specialised objects.

In further detail:

ViewProviderSketch is halved in terms of code size. Higher level ViewProviderSketch functions remain

* Automatic update of parameters - Parameter observer nested classes

Summary:
- ViewProviderSketch and CoinManager get their own observer nested classes to monitor the parameters relevant to them and automatically update on change.

The split enables that each class deals only with parameters within their own responsibilities, effectively isolating the specifics and decoupling the implementations. It is
more convenient as there is no need to leave edit mode to update parameters. It is more compact as it leverages core code.

More information:
https://forum.freecadweb.org/viewtopic.php?p=553257#p553257
2021-12-27 21:03:51 +01:00
Abdullah Tahiri
97c82a6703 Sketcher: Convert PointPos into an enum CLASS 2021-12-11 16:17:21 +01:00
Abdullah Tahiri
bb76be1371 Sketcher: GeoId, GeoElementId and GeoUndef refactor
===================================================

This commit is an independent refactor of the identifications used at Sketcher level.

It introduces a new type "GeoElementId" as a combination of GeoId and PointPos.

It moves the Undefined GeoId, previous Constraint::GeoUndef to GeoEnum, together with all
other fixed values of GeoIds.
2021-12-11 16:17:21 +01:00
Abdullah Tahiri
f29a6a0518 Sketcher: move GUI common utility functions to a new file Utils.h
=================================================================

Common utility functions used by almost all Command classes were previous in Constraint.h.

Aside from providing a very bad intent, it created unnecessary header dependencies.

This commit separates these common functions into a new header, utils.h, which is then
used in all command classes where it is necessary.
2021-12-07 16:30:55 +01:00
0penBrain
e5ea670633 [Sketcher][Bugfix] Fix crash when applying 'Constrain internal alignment' on contraints, fixes #4790 2021-11-22 20:08:07 +01:00
luz paz
42e8287699 Fix various typos
Found via `codespell -q 3 -L aci,ake,aline,alle,alledges,alocation,als,ang,anid,apoints,ba,beginn,behaviour,bloaded,bottome,byteorder,calculater,cancelled,cancelling,cas,cascade,centimetre,childs,colour,colours,commen,connexion,currenty,dof,doubleclick,dum,eiter,elemente,ende,feld,finde,findf,freez,hist,iff,indicies,initialisation,initialise,initialised,initialises,initialisiert,inout,ist,kilometre,lod,mantatory,methode,metres,millimetre,modell,nd,noe,normale,normaly,nto,numer,oder,ontop,orgin,orginx,orginy,ot,pard,parms,pres,programm,que,recurrance,rougly,seperator,serie,sinc,strack,substraction,te,thist,thru,tread,uint,unter,vertexes,wallthickness,whitespaces -S ./.git,*.po,*.ts,./ChangeLog.txt,./src/3rdParty,./src/Mod/Assembly/App/opendcm,./src/CXX,./src/zipios++,./src/Base/swig*,./src/Mod/Robot/App/kdl_cp,./src/Mod/Import/App/SCL,./src/WindowsInstaller,./src/Doc/FreeCAD.uml,./build/doc/SourceDocu`
2021-10-20 18:18:33 -04:00
Abdullah Tahiri
0926a4148b Sketcher: Default Shortcuts
===========================

Following:
https://forum.freecadweb.org/viewtopic.php?p=539914#p539914

Following requests from OpenBrain and ChrisB:
https://forum.freecadweb.org/viewtopic.php?p=540015#p540015

Following request from M4X:

Recomendation to use "L" and "I" for vertical and horizontal distance constraints and "R" for radius.

https://forum.freecadweb.org/viewtopic.php?p=540049#p540049

https://forum.freecadweb.org/viewtopic.php?p=540011#p540011
2021-10-16 09:23:22 +02:00
wmayer
6f6272f12b Sketcher: [skip ci] remove superfluous QT_TRANSLATE_NOOP from Sketcher commands 2021-09-29 15:46:06 +02:00
FreeCAD-Tools
caeffd21b4 Update CommandConstraints.cpp 2021-09-27 15:47:23 +03:00
FreeCAD-Tools
ff1b29ffe1 Update CommandConstraints.cpp 2021-09-27 15:44:55 +03:00
Abdullah Tahiri
873e0977ca Sketcher: Minor fixes sketcher radius/diameter presentation
===========================================================

Some minor fixes:

https://forum.freecadweb.org/viewtopic.php?p=535406#p535406

https://forum.freecadweb.org/viewtopic.php?p=535511#p535511
2021-09-24 06:57:59 +02:00
0penBrain
1d98cc08e7 [Sketcher] Add an option to get randomness in radius/diameter display angle 2021-09-24 06:57:09 +02:00
0penBrain
daa52ab7b8 [Sketcher] Display radius/diameter constraints with some angle
So they are easily differentiated from distance constraints
 Default angle can be customized with 'BaseApp/Preferences/Mod/Sketcher/RaDiaAngle'
2021-09-24 06:57:09 +02:00
0penBrain
3553d8ed3a [Sketcher] Code simplification by systematically using 'finishDistance' to determine label distance 2021-09-24 06:57:09 +02:00
Abdullah Tahiri
9073517291 Sketcher: Default parameter to meaningful value 2021-06-19 13:56:18 +02:00
0penBrain
dfc975dd93 [Sketcher] Radiam is default tool for radius/diameter constraining
Default is no more an option but last used tool is remained for next session
2021-06-19 13:45:53 +02:00
0penBrain
eda1e4b1df [Sketcher] Radiam : fix bug in constraint processing 2021-06-19 13:45:53 +02:00
wmayer
4de2ad46b2 Sketcher: replace or keyword with || as it's not supported by all compilers 2021-06-13 11:02:27 +02:00
0penBrain
2ef1516121 [Sketcher] Radiam : add specific management for Bspline poles 2021-06-12 07:07:28 +02:00
0penBrain
ea1e6595b5 [Sketcher] Radiam : make the command basically usable into Gui 2021-06-12 07:07:28 +02:00
0penBrain
74cfdb57af [Sketcher] Introduce 'Radiam' command that auto set radius or diameter constraint based on geom type
Radius is applied in arcs and BSpline poles
 Diameter is applied on complete circles that aren't BSpline poles
2021-06-12 07:07:28 +02:00
0penBrain
85f37a1dbc [Sketcher] Fix 'Reference' checkbox not working for diameter 2021-06-06 07:12:38 +02:00
0penBrain
e02902cfa2 [Sketcher] Fix 'Reference' checkbox not working for radius/diameter ; fixes #4627
As a consequence :
Remove message box when several arcs/circles are selected ...
... and enforce creation of equality constraints in this case
Former existing option of adding a dimensional constraint ...
... to each circle encouraged improper constraining
2021-06-04 06:12:51 +02:00
wmayer
c4f411af26 Gui: use public methods in Command sub-classes 2021-04-21 19:34:50 +02:00
Chris Hennes
6227a711c3 [Sketcher] Remove deprecated Qt < 5.9 code 2021-04-01 19:38:23 +02:00
Syres916
7a8792f64b [Sketcher] Constraints Allow User to...
...set Diameter as default constraint for Arcs and Circles
See discussion : https://forum.freecadweb.org/viewtopic.php?f=3&t=57054
2021-03-27 06:13:09 +01:00
Abdullah Tahiri
3a656d8597 Sketcher: UI Constraint Creation - PointOnObject + Tangency on edge constraint substitution
============================================================================================

On creation of a constraint from the UI (toolbar/menu):

1. if a PointOnObject constraint preexisted the addition of an
edge-to-edge tangency, substitute it with a point-to-edge tangency.

2. if an edge-to-edge tangency preexisted, addition of a PointOnObject
results in a substitution of the edge-to-edge tangency with an edge-to-curve
tangency.

Bonus:
- Refactor of this with preexisting coincident+tangent substitution.
- Activate both substitutions in continuous constraint addition mode.
2021-03-20 18:12:54 +01:00
Abdullah Tahiri
c08a19626f Sketcher: Use old NotifyConstraintSubstitution parameter in DlgCheackableMessageBox 2021-03-20 15:59:15 +01:00
David Osterberg
d759a8e43d Sketcher: Change constraint-conversion MessageBox to DlgCheckableMessageBox 2021-03-20 15:59:15 +01:00
Abdullah Tahiri
a56a22de56 Sketcher: fix horizontal distance constraint on external edge
=============================================================

Fixes:
https://forum.freecadweb.org/viewtopic.php?f=3&t=54348#p467107
2021-01-15 14:38:48 +01:00
Abdullah Tahiri
942c40227e Sketcher: Fix lock constraint reference mode
============================================

Fixes:
https://forum.freecadweb.org/viewtopic.php?p=461600#p461517
2020-12-30 20:20:20 +01:00
Abdullah Tahiri
4ea97faa5b Sketcher: check for BSpline knot instead of construction point
==============================================================

Previously construction points was used to code bspline knots.
Now construction points are normal sketcher points, which can be
made defining.

This commit renames and adapts the checks for fixed geometry.

fixes:
https://forum.freecadweb.org/posting.php?mode=quote&f=3&p=461472#pr461472
2020-12-29 07:22:21 +01:00
Abdullah Tahiri
67e5f9c3e9 Sketcher: Make select-constraint select-elements mode consistent with select-element select-constraint
======================================================================================================

https://forum.freecadweb.org/viewtopic.php?f=13&t=53515&p=461142#p460687

When using select-constraint then select elements, allow both point-line-point and point-point-line.
2020-12-27 08:19:23 +01:00
donovaly
f2d17774e8 [Sketch] fix SnellsLaw dialog
- add missing class to UI file (found and automatically added by Qt Designer)
- add more sensible stepsize - you are dealing in practice with rations in the range 1.2 - 1.6 thus a stepsize of 1.0 is not helpful
2020-12-25 12:00:49 +01:00
Abdullah Tahiri
985f3510f5 Sketcher: Fix crash when creating an angle constrain on a line segment
======================================================================

Most of these crashes come from previous code not checking for Constraint::GeoUndef.

Most of these crashes come from isBSpline(), any of the two overloads.

isBSpline is made to throw exception when null, which should prevent the crash while
creating a reportable error.
2020-12-19 11:58:54 +01:00
Abdullah Tahiri
51189caba4 Sketcher: Fix equality constraint command
=========================================

For select constraint then click elements mode.

Fixes:
https://forum.freecadweb.org/viewtopic.php?f=10&t=51716&p=458207#p457974
2020-12-16 15:21:21 +01:00
Abdullah Tahiri
e8674fc13d Sketcher: Fix crash on applying angle constraint on arc
=======================================================

The GeoId passed was Constraint::GeoUndef (-2000).

Fixes:
https://forum.freecadweb.org/viewtopic.php?f=10&t=51716&p=458202#p458160
2020-12-16 14:20:02 +01:00
Abdullah Tahiri
395a0f19b4 Part/Sketcher - Construction Migration - step 3: Removal of Geometry construction data member
=============================================================================================

This commits removes the Geometry construction data member and adapts sketcher code to use
GeometryFacade to access construction information via the SketchGeometryExtension.
2020-12-10 18:34:06 +01:00
Abdullah Tahiri
95c1a262b7 Sketcher: Unit independent pole weight for B-Splines (Weight constraint)
========================================================================

Until now BSpline poles were circles relying on physical length units. This lead to several
problems:
- While the BSpline weight follows the circle size, weights do not have length units, but are adimensinal
- As representation of the BSpline depends on the physical size of the circle, the numerical value to be
  set to a pole circle differs from the numerical value of the weight.

The present commit:
1. Separates pole circle representation (physical size), from the numerical value used in the radius constraint,
so that the value in the constraint is the weight, the value representation is a factor of the weight value (in this
commit is getScaleFactor(), but this will change in the next commit). Dragging accounts for this scale factor too.
2. While Radius constraint button is used to constraint a B-Spline weight as before, this creates a Weight constraint,
which is a new type of constraint. This is done so that the value is truly adimensional and is so presented in all kind
of editors that rely on the units indicated by the constraint. It is obviously also shown as adimensional (thus without units),
in the 3D view and in the datum dialogs.
3. Because the circle of the pole of a B-Spline is not a geometric circle, but a graphical representation of the pole and how
it affects the corresponding B-Spline, constraint creation commands are limited so that no point on object, tangent, perpendicular
or SnellLaw constraints can be created on a B-Spline weight circle. This is also the case for the Diameter constraint, which won't
accept the circle. Equality constraints work either on only circles or only weights, but not on a mixture of them.

Bonus: This commit fixes a bug in master, that using the select equality constraint then click in two geometric elements mode, you
could make a circle equal to an ellipse resulting in malformed solver constraints.
2020-12-10 18:34:06 +01:00
Chris Hennes
c23e1dd7ba Release handler in commands where not needed
Fixes #0004478: Active constraint tool blocks sidebar tasks from working.

Many commands are interrupted by the existence of a handler. Rather than having these commands silently cancel, purge the handler if a command executes that does not need it.

When right-clicking on an item in the Constraint Task sidebar, any current operation is cancelled and the FreeCAD selection is synced with the selected items in the constraints QListWidget. This allows all of the menu items in the context menu to function properly: if the selection is not synced, anything that relies on the FreeCAD selection (like Delete) will sillently fail.
2020-11-07 20:17:19 +01:00
luz paz
396695240f Issue #4473: Expose openCommand() CommandConstraints.cpp to translation
`Sketcher/Gui/CommandConstraints.cpp` will now be parsed for translation. Based on https://github.com/FreeCAD/FreeCAD/pull/3993#issuecomment-715906238  
( ref. Issue #4473 )
2020-11-03 15:15:16 +01:00
Abdullah Tahiri
1f46b72491 Part: Geometry - encapsulate construction access 2020-10-25 03:52:51 +01:00
Neinei0k
bc2d3e9d2b Sketcher: Fix ticket #4399
The reason for this behaviour is that root point (origin) and axes are not treated as fixed geometry. Every external geometry has negative ID which is at most GeoEnum::RefExt defined as -3 in the file src/Mod/Sketcher/App/SketchObject.cpp. Ids of root point and axes are also defined in this file with id -1 for root point and horizontal axis, and -2 for vertical axis. To fix the problem, GeoEnum::RefExt id was replaced by root point id in the condition checking for the largest id of fixed geometry.
2020-10-25 02:27:06 +01:00
luz paz
f16f974048 Sketcher: Capitalize opeCommand() text [skip-ci] 2020-10-24 12:26:35 +02:00
luz paz
e73ea7d244 Sketcher: Fix typos [skip-ci] 2020-10-24 12:26:35 +02:00
0penBrain
537089b346 [Sketcher] Allow selection of 2 vertices for horizontal/vertical constraint in continuous mode
Fixes #4444
2020-10-21 17:22:53 +02:00
vocx-fc
c6b6b314a1 Sketcher: small style changes to make the lines shorter 2020-10-01 09:59:26 +02:00
vocx-fc
68c7b1f078 Sketcher: rename constraint icons to be more consistent with the rest
`Sketcher_ConstrainBlock` to `Constraint_Block`.
`Sketcher_ConstrainLock` to `Constraint_Lock`, and the corresponding
`_Driven` variant.

Adjust the icons in the taskpanel for the sketcher constraints,
elements, and for the action menu for constraints.

Adjust the icon order in the `Sketcher.qrc` resource file.
2020-10-01 09:59:26 +02:00