Commit Graph

336 Commits

Author SHA1 Message Date
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
asapelkin
e951094af9 use emplace_back instead of push_back where justified 2019-11-21 14:48:09 +01:00
wmayer
d0d92b0801 force strict ISO C++ (-Wpedantic)
for Fem, Import, PartDesign, Robot, Sketcher, TechDraw
2019-09-18 14:18:07 +02:00
Zheng, Lei
70857e17e0 Sketcher: fix missing update on expression change 2019-08-30 15:52:31 +02:00
Zheng, Lei
66a719773f Sketcher: fix lost of constraint in undo/redo 2019-08-30 14:57:41 +02:00
Zheng, Lei
93e60caa35 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
9b65a4885d Sketcher: Excise SketchGeometryExtension outside of SketchObject 2019-07-14 12:37:29 +02:00
Abdullah Tahiri
ef30cc2527 Part: Geometry Python interface to get/set an extension 2019-07-14 12:37:29 +02:00
Abdullah Tahiri
b778e21b45 Sketcher Geometry Extension 2019-07-14 12:37:28 +02:00
Abdullah Tahiri
26d3d906c8 Sketcher: Add Sketcher Geometry Extension 2019-07-14 12:37:28 +02:00
Abdullah Tahiri
b9417938c4 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
e632e9feb8 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
e06e03dccb Sketcher: Extend SketchObject to handle constraint state 2019-06-22 08:26:31 +02:00
Abdullah Tahiri
95788dde71 Sketcher: PCH 2019-05-02 07:12:27 +02:00
Abdullah Tahiri
3926ea18ca V547 CWE-571 2019-04-08 14:35:46 +02:00
Abdullah Tahiri
eebd4cecdb V560 CWE-570 2019-04-08 14:35:46 +02:00
wmayer
5f52bd7b46 PVS: V728 An excessive check can be simplified 2019-03-13 13:49:04 +01:00
wmayer
8da09b30e7 fix restoring sketch 2019-03-02 16:23:40 +01:00
wmayer
1e343d339f PVS: V779 Unreachable code detected. It is possible that an error is present. 2019-02-17 20:12:56 +01:00
wmayer
3845350c0a PVS: V773 A memory leak is possible 2019-02-17 18:40:06 +01:00
wmayer
f581d5c8cb PVS: V560 A part of conditional expression is always true 2019-02-17 13:56:48 +01:00
luz.paz
8a4af3b28c Crowdin: Sketcher/App/SketchObject.cpp elaborated term in string 2019-01-30 11:08:03 -02:00
luz.paz
d858a8609d Crowdin: Sketcher/App/SketchObject.cpp uniformity fix 2019-01-30 11:08:03 -02:00
wmayer
be5796b2d0 add method restoreFinished and reimplement it in SketchObject 2018-12-29 15:27:32 +01:00
Mateusz Skowroński
71a8e2668d Fix GCC 8 warning: catching polymorphic type by value [-Wcatch-value=] 2018-12-23 11:05:02 -02:00
Abdullah Tahiri
c88a64e8e7 Make Open vertices detection routine accesible to Python 2018-12-03 12:11:11 +01:00
wmayer
36e3d5ef66 Fix scan coverity issues:
CID 184350:  Null pointer dereferences
2018-11-20 15:11:43 +01:00
Abdullah Tahiri
8db80c5c99 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
8176b7129c SketchObject: Activate relevant propertylist order 2018-11-19 11:31:08 +01:00
Abdullah Tahiri
6df9b895ff Sketcher: Fillet increase debugging verbose and disable by default 2018-11-18 12:03:05 +01:00
wmayer
56db19824e Replace Base::Exception with appropriate subclass 2018-11-14 19:27:52 +01:00
Abdullah Tahiri
07cf5b10d7 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
084c483603 Sketcher: Ellipse trim, handle multiple intersection 2018-11-09 22:30:04 +01:00
Abdullah Tahiri
4245ae6863 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
f6a9cfaad3 fix -Wabsolute-value 2018-11-09 12:46:36 +01:00