Commit Graph

121 Commits

Author SHA1 Message Date
wmayer
78ffa29629 Sketcher: expose the LabelDistance and LabelPosition members of Constraint to Python 2024-02-25 00:10:56 +01:00
Florian Foinant-Willig
c0e8fa1e75 Sketcher: modernize type checking 2023-10-23 18:09:23 +02:00
pre-commit-ci[bot]
e92ed45df9 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2023-09-12 13:02:35 -04:00
Jonas Bähr
5346b51edb Sketcher: Fix check in carbonCopy's python interface
Presumably due to an copy/paste error, carbonCopy used to verify the
referenced object via `isExternalAllowed` (just like addExternal).
Now using `isCarbonCopyAllowed`, the resulting error message is the
expected one for wrong objects, not a generic one after the operation
failed.
2023-09-05 08:49:31 +02:00
Jonas Bähr
9a7523fb4b Sketcher: Fix wrong format string in PyArg_ParseTuple
The part behind the column represents the function name itself, not an
error message. So previously, an argument error looked like this:
("Give an object" is not the method name)
```
>>> obj.carbonCopy()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: Give an object() takes at least 1 argument (0 given)
>>> obj.carbonCopy(123)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: Give an object() argument 1 must be str, not int
```

While the format string also supports a text for the complete error message
(using a semicolon instead), I decided against this: Pythons standard text
is more precise than this:
(the type error here is not "Give an object")
```
>>> obj.carbonCopy()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: Give an object
>>> obj.carbonCopy(123)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: Give an object
```
2023-09-05 00:38:30 +02:00
Chris Hennes
fcedce3c42 Sketcher: Reformat to current clang-format standard 2023-09-04 07:17:28 -05:00
wmayer
9f99285d59 modernize C++: use nullptr 2023-08-05 11:23:12 -06:00
Abdullah Tahiri
00fc2311a6 Sketcher: Expose constraint redundancy information to Python 2023-06-11 18:37:38 +02:00
Abdullah Tahiri
6a96612625 Sketcher: new toPythonCommand sketcher Python method
====================================================

This commit leverages PythonConverter to produce the Python commands necessary to replicate
a sketch.

The output is a tuple comprising line by line the python commands.

Limitations: Only internal geometry is replicated. No external links.

Usage:
ActiveSketch.toPythonCommands()

Example output:
('geoList = []', 'geoList.append(Part.ArcOfCircle(Part.Circle(App.Vector(0.000000, 0.000000, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 65.000000), 3.926991, 8.639380))', 'geoList.append(Part.ArcOfCircle(Part.Circle(App.Vector(-70.304056, -14.307964, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 65.000000), 1.186945, 1.992409))', 'ActiveSketch.addGeometry(geoList,False)', 'del geoList', 'constrGeoList = []', 'constrGeoList.append(Part.LineSegment(App.Vector(-45.961941,45.961941,0.000000),App.Vector(0.000000,0.000000,0.000000)))', 'constrGeoList.append(Part.LineSegment(App.Vector(0.000000,0.000000,0.000000),App.Vector(-45.961941,-45.961941,0.000000)))', 'ActiveSketch.addGeometry(constrGeoList,True)', 'del constrGeoList', 'geoList = []', 'geoList.append(Part.ArcOfCircle(Part.Circle(App.Vector(-70.304056, 14.307964, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 65.000000), 4.290776, 5.096240))', 'geoList.append(Part.ArcOfCircle(Part.Circle(App.Vector(-50.000000, 0.000000, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 65.000000), 2.376910, 3.906275))', 'ActiveSketch.addGeometry(geoList,False)', 'del geoList', 'constraintList = []', "constraintList.append(Sketcher.Constraint('Coincident', 0, 3, -1, 1))", "constraintList.append(Sketcher.Constraint('Coincident', 1, 1, 0, 2))", "constraintList.append(Sketcher.Constraint('Coincident', 2, 1, 0, 2))", "constraintList.append(Sketcher.Constraint('Coincident', 2, 2, 0, 3))", "constraintList.append(Sketcher.Constraint('Coincident', 3, 1, 0, 3))", "constraintList.append(Sketcher.Constraint('Coincident', 3, 2, 0, 1))", "constraintList.append(Sketcher.Constraint('Symmetric', 0, 1, 0, 2, -1))", "constraintList.append(Sketcher.Constraint('Coincident', 4, 2, 0, 1))", "constraintList.append(Sketcher.Constraint('Symmetric', 1, 3, 4, 3, -1))", "constraintList.append(Sketcher.Constraint('Symmetric', 4, 1, 1, 2, -1))", "constraintList.append(Sketcher.Constraint('Coincident', 5, 1, 1, 2))", "constraintList.append(Sketcher.Constraint('Coincident', 5, 2, 4, 1))", "constraintList.append(Sketcher.Constraint('DistanceY', 4, 1, 1, 2, 90.000000))", "constraintList.append(Sketcher.Constraint('Radius', 5, 65.000000))", "constraintList.append(Sketcher.Constraint('DistanceX', 5, 3, 0, 3, 50.000000))", "constraintList.append(Sketcher.Constraint('Equal', 5, 4))", "constraintList.append(Sketcher.Constraint('Equal', 4, 0))", "constraintList.append(Sketcher.Constraint('Perpendicular', 2, 3))", 'ActiveSketch.addConstraint(constraintList)', 'del constraintList', '')

A list directly copiable into the console of a new sketch can be obtained, for example:

for i in ActiveSketch.toPythonCommands():
    print(i)

Example output:
geoList = []
geoList.append(Part.ArcOfCircle(Part.Circle(App.Vector(0.000000, 0.000000, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 65.000000), 3.926991, 8.639380))
geoList.append(Part.ArcOfCircle(Part.Circle(App.Vector(-70.304056, -14.307964, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 65.000000), 1.186945, 1.992409))
ActiveSketch.addGeometry(geoList,False)
del geoList
constrGeoList = []
constrGeoList.append(Part.LineSegment(App.Vector(-45.961941,45.961941,0.000000),App.Vector(0.000000,0.000000,0.000000)))
constrGeoList.append(Part.LineSegment(App.Vector(0.000000,0.000000,0.000000),App.Vector(-45.961941,-45.961941,0.000000)))
ActiveSketch.addGeometry(constrGeoList,True)
del constrGeoList
geoList = []
geoList.append(Part.ArcOfCircle(Part.Circle(App.Vector(-70.304056, 14.307964, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 65.000000), 4.290776, 5.096240))
geoList.append(Part.ArcOfCircle(Part.Circle(App.Vector(-50.000000, 0.000000, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 65.000000), 2.376910, 3.906275))
ActiveSketch.addGeometry(geoList,False)
del geoList
constraintList = []
constraintList.append(Sketcher.Constraint('Coincident', 0, 3, -1, 1))
constraintList.append(Sketcher.Constraint('Coincident', 1, 1, 0, 2))
constraintList.append(Sketcher.Constraint('Coincident', 2, 1, 0, 2))
constraintList.append(Sketcher.Constraint('Coincident', 2, 2, 0, 3))
constraintList.append(Sketcher.Constraint('Coincident', 3, 1, 0, 3))
constraintList.append(Sketcher.Constraint('Coincident', 3, 2, 0, 1))
constraintList.append(Sketcher.Constraint('Symmetric', 0, 1, 0, 2, -1))
constraintList.append(Sketcher.Constraint('Coincident', 4, 2, 0, 1))
constraintList.append(Sketcher.Constraint('Symmetric', 1, 3, 4, 3, -1))
constraintList.append(Sketcher.Constraint('Symmetric', 4, 1, 1, 2, -1))
constraintList.append(Sketcher.Constraint('Coincident', 5, 1, 1, 2))
constraintList.append(Sketcher.Constraint('Coincident', 5, 2, 4, 1))
constraintList.append(Sketcher.Constraint('DistanceY', 4, 1, 1, 2, 90.000000))
constraintList.append(Sketcher.Constraint('Radius', 5, 65.000000))
constraintList.append(Sketcher.Constraint('DistanceX', 5, 3, 0, 3, 50.000000))
constraintList.append(Sketcher.Constraint('Equal', 5, 4))
constraintList.append(Sketcher.Constraint('Equal', 4, 0))
constraintList.append(Sketcher.Constraint('Perpendicular', 2, 3))
ActiveSketch.addConstraint(constraintList)
del constraintList
2023-05-28 14:59:31 +02:00
Abdullah Tahiri
bcedfae708 Sketcher: Command constraints error handling adaptation
=======================================================

- Better handling for exceptions originating in Python addConstraint.
- Refactor to reuse code for handling of exceptions
2023-05-23 14:24:45 +02:00
Abdullah Tahiri
0f14065d0a Sketcher: App - Clang-format 2023-05-20 07:55:05 +02:00
luzpaz
593ab90400 Sketcher: convert indentations to spaces 2023-01-23 15:46:49 +01:00
Ajinkya Dahale
38212da989 [Sketcher] Handle exception in Python while splitting
`SketchObject::split` only appears to throw `ValueError`.
2022-12-21 16:01:23 +01:00
Uwe
365d968ae8 [Sketch] App P - End: remove unused headers
- also some sorting
2022-12-11 22:36:00 +01:00
Ajinkya Dahale
01866dfbfc [Sketcher] Add methods and tools for joining curves
Algorithm to join b-splines:
The code simple concatenates the knots, poles, weights, and knot multiplicities
together, removing data on the connection point of the second curve. Some
further study is needed to see if/when it will give an exact/good connection.

Icon courtesy @bitacovir.
2022-12-04 08:17:20 +01:00
marioalexis
36968c835d Sketcher: Replace C cast 2022-09-18 11:06:51 -05:00
berniev
f4ffd15864 Mod: redundant void 2 2022-08-08 10:27:50 +02:00
wmayer
50ef527ded Sketcher: [skip ci] Fix several clazy issues:
* Missing reference in range-for with non trivial type [-Wclazy-range-loop-reference]
* Unused QString [-Wclazy-unused-non-trivial-variable]
* Missing emit keyword on signal call [-Wclazy-incorrect-emit]
* Don't call QList::operator[]() on temporary [-Wclazy-detaching-temporary]
* Use multi-arg instead [-Wclazy-qstring-arg]
* Maybe you meant to call ViewProvider2DObjectGrid::onChanged() instead [-Wclazy-skipped-base-method]
2022-07-25 12:56:09 +02:00
wmayer
832bdaa7dd Sketch: replace PyObject_IsTrue with Base::asBoolean 2022-07-16 12:41:53 +02:00
marioalexis
ce082d8f4a Sketcher: Use PyObject_IsTrue in combination with conditional ternary operator 2022-06-22 19:50:03 -04:00
Uwe
61be686687 [Sketch] remove unnecessary Boolean comparisons 2022-06-19 18:35:52 +02:00
wmayer
51186c018e Sketcher: modernize C++11
* use nullptr
2022-03-23 19:26:15 +01:00
Ajinkya Dahale
07cad4ab64 [Sketcher] Add insertBSplineKnot to SketcherObject
[Sketcher] Workaround for segfault on knot insertion
2022-01-09 11:33:53 +01:00
Abdullah Tahiri
44567167ff Sketcher: Convert PointPos into an enum CLASS 2021-12-11 16:17:21 +01:00
Abdullah Tahiri
182596ba08 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
b9dcac559c Sketcher: Python - enable using the setVirtualSpace command individually or by group 2021-09-28 20:07:41 +02:00
Abdullah Tahiri
87342ec668 Sketcher: Python wrappers for new remove axes alignment algorithm 2021-06-20 06:16:21 +02:00
wmayer
0ff70c61ed Sketcher: [skip ci] fix memory leak in GeometryFacade 2021-04-27 00:20:57 +02:00
Abdullah Tahiri
841c328eb3 Sketcher: Changes to split edge functionality
=============================================

This commit is directed to external functionality of the split() function.

1. getAppliedConstraints renamed to getConstraintIndices

This is just for clarity being a general function

2. SwapInvolvedGeometry functionality moved to Constraint class

Why?
i. Because it is a specific operation on a constraint, it must not be
a public function, as it does not define interface of the Sketch.
ii. It could be a lambda or a private utility function, but them it would not be reusable.
iii. It could be part of a helper class, but then, it is would be less reusable.

3. renaming of the flag passed to transferConstraints function
2021-04-24 14:38:44 +02:00
Tomas Pavlicek
a7d83b5e15 Sketcher - Add new Split Edge action 2021-04-24 14:30:35 +02:00
luz paz
9e6fe284ed Sketcher: remove Py2 code from Sketcher wb 2021-04-22 14:11:04 +02:00
Benjamin Nauck
8a2cfc268e [Base] Remove includes to StdStlTools.h as that's not needed anymore
std::make_unique was introduced in c++14, so no need to use the back
ported version
2021-03-06 21:20:32 +01:00
Benjamin Nauck
7422a64c84 [Sketcher] Use std::shared_ptr instead of boost::shared_ptr
There's no need to use boost version when stl has support for shared_ptr
2021-03-06 19:32:03 +01:00
j
92041a7376 Sketch: new fillet Python support 2021-02-04 08:10:28 +01:00
Abdullah Tahiri
cf7422af4f Sketcher: Expose delGeometries function to Python 2021-01-06 13:54:00 +01:00
Abdullah Tahiri
56f3db079f Sketcher: Fix crash on constraint rename
========================================

Report:
https://github.com/FreeCAD/FreeCAD/pull/4183
https://github.com/realthunder/FreeCAD_assembly3/issues/387

Problem:
renameConstraint() previously implemented exclusively in SketchObjectPyImp.cpp,
will change the Constraints property without updating the solver. A prospective
drag operation would rely on a deleted pointer constraint which leads to the
crash.

Solution:
- mark the solver status as needing an update
- leverage new through sketchobject r/w interface to ensure solver is synchronised
before the temporary move operation starts

Bonus:
move the core of the function to SketchObject.cpp so that input data validity
check on constraint change is inhibited.
2020-12-27 08:24:43 +01:00
Abdullah Tahiri
33b47ecdd0 Sketcher: Implement Python function getConstruction(geoId) to retrieve geometry construction status 2020-12-22 07:10:48 +01:00
Abdullah Tahiri
170eb8c4fd 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
916526b866 Sketcher: Documentation editorial change 2020-11-03 12:01:22 +01:00
Abdullah Tahiri
063e0a6767 Sketcher: Extend SketchObject Python Interface to get/set SketchGeometryExtension GeometryId (convenience interface) 2020-11-03 12:01:22 +01:00
Abdullah Tahiri
d994e2fe3b Sketcher: Geometry Facade interface for Geometry and SketchGeometryExtension 2020-11-03 12:01:22 +01:00
wmayer
9b806f4ac9 Sketch: [skip ci] handle possible crashes when decreasing degree of a spline 2020-10-23 11:26:15 +02:00
wmayer
d532f8ef33 Sketcher: implement command to decrease degree of a B-spline 2020-10-23 00:36:41 +02:00
mwganson
283ef3ce86 [Sketcher] add python command sketch.getGeoVertexIndex(int index) -- returns tuple (geoId, posId) of vertex at that index in the sketch. usage example: (geoId, posId) = App.ActiveDocument.Sketch.getGeoVertexIndex(int(Gui.Selection.getSelectionEx()[0].SubElementNames[0][6:])-1) 2020-07-19 05:50:12 +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
wmayer
f0c89811bd add method to sketch object to get index by user-defined name 2019-10-29 19:35:53 +01:00
Abdullah Tahiri
0e15d3461f Sketcher: Python interface to SketchObject 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
ee99340558 Make Open vertices detection routine accesible to Python 2018-12-03 12:11:11 +01:00
luz.paz
cfbfa9dc6b Misc. typo, grammar, and whitespace fixes
[skip ci]
2018-11-27 15:02:58 -03:00