Commit Graph

118 Commits

Author SHA1 Message Date
Jonas Bähr
880461593f 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
7e84c3f42f 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
791fe02934 Sketcher: Reformat to current clang-format standard 2023-09-04 07:17:28 -05:00
wmayer
d244dcf2da modernize C++: use nullptr 2023-08-05 11:23:12 -06:00
Abdullah Tahiri
dc7b3bfd66 Sketcher: Expose constraint redundancy information to Python 2023-06-11 18:37:38 +02:00
Abdullah Tahiri
5a2c48b593 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
0e85b24348 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
987b4bda2a Sketcher: App - Clang-format 2023-05-20 07:55:05 +02:00
luzpaz
2c3e6bd70a Sketcher: convert indentations to spaces 2023-01-23 15:46:49 +01:00
Ajinkya Dahale
13a64d60ea [Sketcher] Handle exception in Python while splitting
`SketchObject::split` only appears to throw `ValueError`.
2022-12-21 16:01:23 +01:00
Uwe
170cf81fd5 [Sketch] App P - End: remove unused headers
- also some sorting
2022-12-11 22:36:00 +01:00
Ajinkya Dahale
c5aceb0182 [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
734dfc47c6 Sketcher: Replace C cast 2022-09-18 11:06:51 -05:00
berniev
da9ebc572f Mod: redundant void 2 2022-08-08 10:27:50 +02:00
wmayer
d344ccc4eb 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
b48f7229a3 Sketch: replace PyObject_IsTrue with Base::asBoolean 2022-07-16 12:41:53 +02:00
marioalexis
51f3727d3c Sketcher: Use PyObject_IsTrue in combination with conditional ternary operator 2022-06-22 19:50:03 -04:00
Uwe
68a499574a [Sketch] remove unnecessary Boolean comparisons 2022-06-19 18:35:52 +02:00
wmayer
ead5154b18 Sketcher: modernize C++11
* use nullptr
2022-03-23 19:26:15 +01:00
Ajinkya Dahale
d8c5801b95 [Sketcher] Add insertBSplineKnot to SketcherObject
[Sketcher] Workaround for segfault on knot insertion
2022-01-09 11:33:53 +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
490a6f1961 Sketcher: Python - enable using the setVirtualSpace command individually or by group 2021-09-28 20:07:41 +02:00
Abdullah Tahiri
be153ae2d9 Sketcher: Python wrappers for new remove axes alignment algorithm 2021-06-20 06:16:21 +02:00
wmayer
5a5b20df56 Sketcher: [skip ci] fix memory leak in GeometryFacade 2021-04-27 00:20:57 +02:00
Abdullah Tahiri
18e751530a 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
4d6b1f3eb8 Sketcher - Add new Split Edge action 2021-04-24 14:30:35 +02:00
luz paz
f64f0e7182 Sketcher: remove Py2 code from Sketcher wb 2021-04-22 14:11:04 +02:00
Benjamin Nauck
f6c9cc90ee [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
505ba29c6b [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
46feeb11f6 Sketch: new fillet Python support 2021-02-04 08:10:28 +01:00
Abdullah Tahiri
a3b9edc6d8 Sketcher: Expose delGeometries function to Python 2021-01-06 13:54:00 +01:00
Abdullah Tahiri
64774bc1fe 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
c79ac8d1fc Sketcher: Implement Python function getConstruction(geoId) to retrieve geometry construction status 2020-12-22 07:10:48 +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
709c0b546f Sketcher: Documentation editorial change 2020-11-03 12:01:22 +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
Abdullah Tahiri
0fd808dfc1 Sketcher: Geometry Facade interface for Geometry and SketchGeometryExtension 2020-11-03 12:01:22 +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
mwganson
2bfc6301bc [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
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
wmayer
5fd5db9aed add method to sketch object to get index by user-defined name 2019-10-29 19:35:53 +01:00
Abdullah Tahiri
f45d0e54c0 Sketcher: Python interface to SketchObject 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
c88a64e8e7 Make Open vertices detection routine accesible to Python 2018-12-03 12:11:11 +01:00
luz.paz
4dc201e086 Misc. typo, grammar, and whitespace fixes
[skip ci]
2018-11-27 15:02:58 -03:00
wmayer
c1f19d3854 remove trailing spaces 2018-11-05 10:53:01 +01:00
Abdullah Tahiri
fe78c1a037 Sketcher: Expose mass datum commands to python 2018-11-04 14:41:20 -03:00
Abdullah Tahiri
044e0f6c20 Sketcher: Use transparent exception mechanism for fillets
=========================================================

This ensures that the exception back in the c++ that invoked python retains the type of exception and can be properly catched.
2018-10-28 18:34:50 +01:00