Commit Graph

334 Commits

Author SHA1 Message Date
Abdullah Tahiri
088abe7353 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
5119513488 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
736aa11f6e 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
d6169d6478 boost: fix for boost < 1.60 2020-06-15 19:38:39 +02:00
Abdullah Tahiri
b08aa0d0e9 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
730154a684 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
45e906ed66 Sketcher: Fix undo on moving geometry
=====================================

fixes #3842
2020-05-31 20:53:07 +02:00
Abdullah Tahiri
9b59de44c2 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
79c8791f4f Sketcher: projection - remove unused variables and function 2020-05-24 15:22:16 +02:00
shermelin
d4e8e0de1b 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
beb226cd67 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
318e080623 [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
e7012a458c 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
7008cf92de Sketcher: [skip ci] fix header uniformity
This PR fixes header uniformity across all Sketcher WB files
2019-12-22 01:00:29 +01:00
asapelkin
ced8100ab9 use emplace_back instead of push_back where justified 2019-11-21 14:48:09 +01:00
wmayer
b1dd1e61a7 force strict ISO C++ (-Wpedantic)
for Fem, Import, PartDesign, Robot, Sketcher, TechDraw
2019-09-18 14:18:07 +02:00
Zheng, Lei
0ad1d0b9e6 Sketcher: fix missing update on expression change 2019-08-30 15:52:31 +02:00
Zheng, Lei
7128cf7989 Sketcher: fix lost of constraint in undo/redo 2019-08-30 14:57:41 +02:00
Zheng, Lei
ced27a69c6 PropertyExpressionEngine: convert to link type property
PropertyExpressionEngine is changed to derived from a new class
PropertyExpressionContainer, which is in turn derives from
PropertyXLinkContainer. This makes PropertyExpressionEngine a link type
property that is capable of external linking. It now uses the unified
link property APIs for dependency management and tracking of object
life time, re-labeling, etc.

ObjectIdentifier is modified to support sub-object reference, but is
not exposed to end-user, because expression syntax is kept mostly
unchanged, which will be submitted in future PR. There is, however,
one small change in expression syntax (ExpressionParser.y) to introduce
local property reference to avoid ambiguity mentioned in
FreeCAD/FreeCAD#1619

Modified Expression/ExpressionModifier interface to support various link
property API for link modification.
2019-08-17 14:52:09 +02:00
Abdullah Tahiri
0e8a2d27a3 Sketcher: Excise SketchGeometryExtension outside of SketchObject 2019-07-14 12:37:29 +02:00
Abdullah Tahiri
6b4148861d Part: Geometry Python interface to get/set an extension 2019-07-14 12:37:29 +02:00
Abdullah Tahiri
11478f4951 Sketcher Geometry Extension 2019-07-14 12:37:28 +02:00
Abdullah Tahiri
247e6a849b Sketcher: Add Sketcher Geometry Extension 2019-07-14 12:37:28 +02:00
Abdullah Tahiri
0912fd0ee7 Sketcher: Fix Carbon copy leads to unsolvable sketch
====================================================

fixes #3973

https://forum.freecadweb.org/viewtopic.php?p=316251#p316198

This commit disables an old "axis orientation correction mode", which tried to
solve a problem with orientation of the axis. It never worked fine and it should
have never been introduced, as everything it intends to do should be done by
setting the appropriate placement offset.
2019-06-23 15:15:46 +02:00
Abdullah Tahiri
9fd2a2d9ff Sketcher: Fix carbon copy construction points
=============================================

fixes #3926

Points made of construction type are special non-constrainable points, such as (current) bspline knots.

This was not intended in Carbon Copy.
2019-06-22 23:15:07 +02:00
Abdullah Tahiri
3a47e27ce4 Sketcher: Extend SketchObject to handle constraint state 2019-06-22 08:26:31 +02:00
Abdullah Tahiri
893d7afccc Sketcher: PCH 2019-05-02 07:12:27 +02:00
Abdullah Tahiri
befbc1d634 V547 CWE-571 2019-04-08 14:35:46 +02:00
Abdullah Tahiri
77a81817fb V560 CWE-570 2019-04-08 14:35:46 +02:00
wmayer
7bcee67566 PVS: V728 An excessive check can be simplified 2019-03-13 13:49:04 +01:00
wmayer
acee9433f0 fix restoring sketch 2019-03-02 16:23:40 +01:00
wmayer
2f31efe4c3 PVS: V779 Unreachable code detected. It is possible that an error is present. 2019-02-17 20:12:56 +01:00
wmayer
e23db2e313 PVS: V773 A memory leak is possible 2019-02-17 18:40:06 +01:00
wmayer
b2a5f47e44 PVS: V560 A part of conditional expression is always true 2019-02-17 13:56:48 +01:00
luz.paz
1126f11e03 Crowdin: Sketcher/App/SketchObject.cpp elaborated term in string 2019-01-30 11:08:03 -02:00
luz.paz
2b3cdf4ad9 Crowdin: Sketcher/App/SketchObject.cpp uniformity fix 2019-01-30 11:08:03 -02:00
wmayer
65c06fce5c add method restoreFinished and reimplement it in SketchObject 2018-12-29 15:27:32 +01:00
Mateusz Skowroński
860a984a1d Fix GCC 8 warning: catching polymorphic type by value [-Wcatch-value=] 2018-12-23 11:05:02 -02:00
Abdullah Tahiri
ee99340558 Make Open vertices detection routine accesible to Python 2018-12-03 12:11:11 +01:00
wmayer
fa5b47df16 Fix scan coverity issues:
CID 184350:  Null pointer dereferences
2018-11-20 15:11:43 +01:00
Abdullah Tahiri
bf6f2b855d Property: dropping isorderrelevant boolean member in favour of bit in the status of the properties 2018-11-19 11:31:09 +01:00
Abdullah Tahiri
af7d75c43f SketchObject: Activate relevant propertylist order 2018-11-19 11:31:08 +01:00
Abdullah Tahiri
50af914311 Sketcher: Fillet increase debugging verbose and disable by default 2018-11-18 12:03:05 +01:00
wmayer
21d01fe6fc Replace Base::Exception with appropriate subclass 2018-11-14 19:27:52 +01:00
Abdullah Tahiri
380f36eff1 Sketcher: Trim support multiple intersections for circles
=========================================================

The problem with ellipses:
https://forum.freecadweb.org/viewtopic.php?f=3&t=31594&sid=37481b7a6c1ae2614c9840fc27a7773e&start=60#p267248

The problem with circles:
https://forum.freecadweb.org/viewtopic.php?f=3&t=31594&sid=37481b7a6c1ae2614c9840fc27a7773e&start=60#p267536
2018-11-09 22:30:04 +01:00
Abdullah Tahiri
605289585f Sketcher: Ellipse trim, handle multiple intersection 2018-11-09 22:30:04 +01:00
Abdullah Tahiri
200d9db0c2 Sketcher: Ellipse trimming with internal aligment geometry
==========================================================

Trimming was not considering a case where an ellipse is trimmed with respect to its own internal aligment geometry.

This resulted in Coincident Constraints with PointPos = Sketcher::none, which is invalid.
2018-11-09 22:30:03 +01:00
wmayer
172f0a0016 fix -Wabsolute-value 2018-11-09 12:46:36 +01:00
wmayer
135c67155d remove trailing spaces 2018-11-05 11:55:14 +01:00
wmayer
a67ee5648c remove trailing spaces 2018-11-05 10:53:01 +01:00