Commit Graph

370 Commits

Author SHA1 Message Date
David Österberg
bfc036daa4 Update src/Mod/Sketcher/App/SketchObject.cpp
Co-authored-by: Chris Hennes <chennes@pioneerlibrarysystem.org>
2020-12-21 08:37:37 +01:00
David Osterberg
edb87a0663 Delete Equal constraints on LineSegments in SketchObject::trim
This closes:
https://tracker.freecadweb.org/view.php?id=4510
2020-12-21 08:37:37 +01:00
Abdullah Tahiri
c3acfcc0a0 Sketcher: Fix Array/copy/move
==============================

Do not copy/array internal alignment geometry if the geometry it defines is not part of the operation. Silently ignore it.

If the reference for the operation is one such geometry (or it is the only one), then abort the operation.
2020-12-20 19:27:29 +01:00
Abdullah Tahiri
ade218f58c Sketcher: fix knots PointPos coded as mid instead of start 2020-12-20 19:27:29 +01:00
Abdullah Tahiri
2ebed71e7a Sketcher: fix crash on mirroring geometry defined by internal alignment geometry
================================================================================

Internal Alignment constraint mirroring was never implemented. With the enhancements
brought with implementation of geometry extensions in the sketcher, this lack of
implementation became a crash, as geometry was marked as being internal alignment, while
no associated internal alignment constraint was created.

Restrictions:
- Internal alignment geometry is only to be mirrored if the geometry it defines is also
being mirrored. Internal alignment geometry is otherwise skipped. This is because it
does not make sense to have a pole without a b-spline, or a major axis of a ellipse without
an ellipse.

fixes #4514
2020-12-20 19:27:29 +01:00
Abdullah Tahiri
cb68fa4fb8 Sketcher: rewrite SketchObject getGeometryWithDependentParameters to use SolverGeometryExtension 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
70f85505d0 Sketcher: delete internal alignment geometry using new delGeometries function 2020-12-19 11:58:54 +01:00
luz paz
cb58706e80 Fix various 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,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,ist,kilometre,lod,mantatory,methode,metres,millimetre,modell,nd,noe,normale,normaly,nto,numer,oder,orgin,orginx,orginy,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,./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
```
2020-12-12 08:07:47 +01:00
Abdullah Tahiri
40c0f0aa01 Sketcher: refactor onDocumentRestored() 2020-12-10 18:34:06 +01:00
Abdullah Tahiri
f33aab5f5e Sketcher: Reduce ViewProviderUpdates when deleting Internal Alignment Geometry
==============================================================================

Deletion of a geometry having internal alignment geometry (B-Spline, Ellipse, ...)
involves calling a geometry deletion operation for each internal aligment constraint
in addition to the one of the geometry.

Before this commit, an update call was performed for each of these operations. Now,
there is a single update trigger operation after all the geometries are deleted.
2020-12-10 18:34:06 +01:00
Abdullah Tahiri
4e199bd23e Sketcher: Fix construction migration 2020-12-10 18:34:06 +01:00
Abdullah Tahiri
a624a35af1 Sketcher - Construction Migration - step 4: Migration function from legacy construction geometry to extension
==============================================================================================================

This function is charged with receiving the construction information in a
GeometryMigrationExtension and setting the right data members of SketchGeometryExtension.
2020-12-10 18:34:06 +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
Abdullah Tahiri
e5eff3f06b Sketcher: Constraint-Driven geometry status
============================================

This is a new concept which originates from the new ability of sketcher geometry to store a geometry state via
geometry extensions.

The idea is that some geometry state is enforced via constraints (InternalAlignment constraints and Block constraint) which
effectively set the state. However, it is convenient to have direct access of the geometry state from the geometry for representation
(ViewProvider) and for the solver. This is the constraint-driven geometry state concept.

The addition/removal of the constraint defines the life cycle of the geometry state and is responsible for setting and removing
the state, so that geometry state and constraint are kept synchronised.

The life cycle is completed with proper serialisation of the geometry state.

In summary:
1. Upon restore, the stored state is restored and any migration is handled to set the status for legacy files (backwards compatibility)
2. Functionality adding constraints (of the relevant type) calls addGeometryState to set the status
3. Functionality removing constraints (of the relevant type) calls removeGeometryState to remove the status
4. Save mechanism will ensure persistance of the geometry state
2020-12-10 18:34:06 +01:00
Abdullah Tahiri
02737a3b5b Sketcher: After restore migration mechanism
===========================================================

The introduction of the ability of the geometry extensions to store information leads opens new
possibilities to the sketcher, which may require migration of previous versions of the sketcher.

A striking example is the migration of the GeomPoint+Construction to mark a B-Spline knot to a proper
geometry state based on the sketch geometr extension.

It also enables to make aware the geometry of the Blocked status, by restoring the geometr blocked
status.

This commit defines an scheleton for this mechanism.
2020-12-10 18:34:06 +01:00
wmayer
db537b8f90 Sketcher: [skip ci] use delGeometries to delete all superfluous geometry in one go after changing multiplicity 2020-11-05 15:19:39 +01:00
wmayer
9801b36e73 Sketcher: [skip ci] add method SketchObject::delGeometries 2020-11-05 12:37:07 +01:00
wmayer
a5b338630f Sketcher: [skip ci] minor optimization in SketchObject::delGeometry 2020-11-05 10:04:42 +01:00
luz paz
ff5f3799d8 Fix various typos [skip-ci]
Found via `codespell v2.0.dev`  
```
codespell -q 3 -L aci,ake,aline,alle,alledges,alocation,als,ang,anid,ba,beginn,behaviour,bloaded,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,ist,kilometre,lod,mantatory,methode,metres,millimetre,modell,nd,noe,normale,normaly,nto,numer,oder,orgin,orginx,orginy,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,./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
```
2020-11-04 10:18:30 +01:00
Abdullah Tahiri
284c4d93f7 Sketcher: Extend SketchObject Python Interface to get/set SketchGeometryExtension GeometryId (convenience interface) 2020-11-03 12:01:22 +01:00
wmayer
6ebee86867 Sketcher: [skip ci] avoid possible memory leak 2020-10-30 13:21:51 +01:00
Abdullah Tahiri
1f46b72491 Part: Geometry - encapsulate construction access 2020-10-25 03:52:51 +01:00
wmayer
4a8201a237 Sketch: [skip ci] handle possible crashes when decreasing degree of a spline 2020-10-23 11:26:15 +02:00
wmayer
fc89f4eb0c Sketcher: implement command to decrease degree of a B-spline 2020-10-23 00:36:41 +02:00
wmayer
0306c237ed Sketcher: [skip ci] fix inconsistent indentations in SketchObject::rebuildExternalGeometry 2020-09-24 11:32:22 +02:00
shermelin
923607b46b Projections of arcs of circle, orthogonal case
Implementation when circle plane orthogonal to projection plane.
2020-09-24 11:22:58 +02:00
wmayer
dc65b055e5 LGTM: [skip ci] fix: Empty branch of conditional
An empty block after a conditional can be a sign of an omission and can decrease maintainability of the code.
Such blocks should contain an explanatory comment to aid future maintainers.
2020-07-26 15:49:14 +02:00
wmayer
e83dd3c0ce Coverity: Using invalid iterator 2020-07-20 17:34:27 +02:00
wmayer
0b45b11344 Coverity: Resource leak 2020-07-20 17:34:24 +02:00
luz paz
83f34a1e5b Fix Crowdin typos and various other typos/grammar [skip ci]
Found via codespell v2.0.dev0  
```
codespell -q 3 -L aci,ake,aline,alle,alledges,alocation,als,ang,anid,ba,beginn,behaviour,bloaded,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,ist,kilometre,lod,mantatory,methode,metres,millimetre,modell,nd,noe,normale,normaly,nto,numer,oder,orgin,orginx,orginy,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,./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
```
2020-07-12 11:42:27 +02:00
Abdullah Tahiri
39b81e40a9 Sketcher: fix access to isPerformingTransaction on null pointer
===============================================================

Fixes this crash:
https://forum.freecadweb.org/viewtopic.php?f=3&t=48414#p414255
2020-07-07 18:09:55 +02:00
Thomas Gimpel
33841eb827 Sketcher: fix crash, when cloning element having a non-driving distance, radius, diameter or angle constraint; fixes #4393 2020-07-03 20:38:06 +02:00
Abdullah Tahiri
31b1ad874f Sketcher: Augment malformed constraint messages
===============================================

Enable a user recomputing an object/document to identify which sketch has the malformed constraints.
2020-07-02 19:54:15 +02:00
wmayer
ebbcdf5ff7 Sketcher: [skip ci] fixes -Wmaybe-uninitialized 2020-07-01 19:50:40 +02:00
Abdullah Tahiri
c35d8be9a3 Sketcher: Check invalid constraint indices in unmanaged operations
==================================================================

It is possible to bypass SketchObject in modifying geometry and constraints. Like in here:
https://forum.freecadweb.org/viewtopic.php?f=3&t=41326&start=20#p408409

This leads to unexpected behaviour and even crashes.

With this commit the new mechanism of constraint indices check is leveraged in cases not involving SketchObject operations (aka managed operations).

Direct assignment of properties from Python (sketcher unmanaged operations), undergo this extra indices check.

When indices in constraints are outside the geometry range, the constraints are shown as empty and the error is shown in the report window.
2020-07-01 14:04:25 +02:00
Abdullah Tahiri
926625b678 Sketcher: Use move semantics wherever sensible
==============================================

Take advantage of PropertyGeometryList setValues() move overload in order to make code more readable and prevent
memory leaks (mostly by inadvertedly not deleting cloned geometry and constraints).

PropertyGeometryList and PropertyConstraintList are vectors of heap allocated pointers. Copying a vector
makes a shallow copy, not a deep copy (the pointers are the same in the copy).

For property management, setValues() function taking a const reference effectively make a deep copy of all
pointed objects. This means that heap allocated pointers of the client class passed to these functions must be
released by the client. While this sounds sensible, forgetting to is easy. In the cases where the developer
remembered to release these pointers, extra code is needed just for memory management.

This commit does not seek a substantial performance increase that would justify rewritting the code, although code
may be slightly faster sometimes.

Functions where setValues() is conditional are not changed to move semantics, as it makes no sense to make a deep copy to sometimes
perform a second deep copy later on. This code still uses const ref setValues().

CHECKS performed to refactored functions with this commit:

1) That the vector is NOT used after moving its content.

2) That whereever there is a clone(), there must be EITHER
    -a std::move if using rvalue setValues()
    OR
    - a delete to free the heap memory after setValues if using the const ref setValues()

3) That memory is released if an exception occurred.

N.B.: A couple of memory leaks are fixed in this commit too.
2020-07-01 14:04:25 +02:00
Abdullah Tahiri
ac167aa850 Sketcher: ViewProviderSketch inhibit update if internal transaction is ongoing
==============================================================================

Inhibit ViewProviderSketch updateData with invalid data (internal transaction).

Trigger update internally for internal transactions in SketchObject via touched()
so as to trigger updateData.

This leads to a reduction of updateData calls.
2020-07-01 14:04:25 +02:00
Abdullah Tahiri
3941b69170 Sketcher: Internal Transaction Support and ensure valid constraint geometry indices
===================================================================================

On changing the geometry property (for example from Python), the constraints geometry indices was not rebuild in order to avoid
redundant and unnecessary rebuilds. However, this might cause crashes, as the status of the sketch (or its properties) may be invalid.

It also refactors into OnChanged common functionality.

This commit does NOT solve that the user may be inserting invalid geometry indices to the First/Second/Third of Constraints (invalid input).
Only makes sure that geometry indices (geometry types) of PropertyConstraintList match the geometry.

Solution:

1. Force the rebuild of the constraint geometry indices upon assignment of new Geometry.
2. Force the rebuild of the constraint geometry indices upon assigment of constraints, if they result in invalid geometry indices.
3. Introduce the concept of internal transaction to avoid those rebuilds, checks and updates in case of an ongoing internal transaction,
thereby preventing them as it was done before introducing 1 and 2 (in the case of SketchObject internal transactions).
2020-07-01 14:04:25 +02:00
wmayer
f3b460e42e boost: fix for boost < 1.60 2020-06-15 19:38:39 +02:00
Abdullah Tahiri
8ef32eab8b Sketcher: onUndoRedoFinished implementation and request
=======================================================

The sketchobject is now left in a known status after undo/redo transaction
2020-06-14 14:44:28 +02:00
wmayer
4ec45b545e boost 1.73.0: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated 2020-06-12 17:51:33 +02:00
Abdullah Tahiri
28222fe066 Sketcher: Fix undo on moving geometry
=====================================

fixes #3842
2020-05-31 20:53:07 +02:00
Abdullah Tahiri
6f3160db3e Sketcher: Enable undo when trimming
===================================

Reported here:
https://forum.freecadweb.org/viewtopic.php?p=311853#p312647
2020-05-26 19:28:35 +02:00
Abdullah Tahiri
c1ca01b0e7 Sketcher: projection - remove unused variables and function 2020-05-24 15:22:16 +02:00
shermelin
2017eb46ac Added corner cases
- deal with exchange of minor/major axis
- projected ellipse = circle builds a circle
- projected is a segment
2020-05-24 15:21:47 +02:00
shermelin
74bd67623f First test of ellipse projection
- general case implemented

TODO:
- catch and implement limit cases (parallel, orthogonal, inverted
  major/minor, circle...
2020-05-24 15:21:47 +02:00
shermelin
9b8b128a0d [Sketcher] Project full circle, impl. missing cases
Implements cases for full (closed) circle, when not parallel to the
sketch plane.
2020-05-09 17:20:34 +02:00
Abdullah Tahiri
7d9cfeb2c5 Sketcher: Fix trim
==================

https://forum.freecadweb.org/viewtopic.php?p=387303#p387303

1. Trim had a bug that the type of the constraint on the second point was equal to the first one regardless of the situation.

2. Trim did not have support for checking whether points were close to the edge and relied on preexisting constraints.
2020-04-14 19:00:51 +02:00
luz.paz
b2ffebf1c0 Sketcher: [skip ci] fix header uniformity
This PR fixes header uniformity across all Sketcher WB files
2019-12-22 01:00:29 +01:00