1
# ***************************************************************************
2
# * (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
4
# * This file is part of the FreeCAD CAx development system. *
6
# * This program is free software; you can redistribute it and/or modify *
7
# * it under the terms of the GNU Lesser General Public License (LGPL) *
8
# * as published by the Free Software Foundation; either version 2 of *
9
# * the License, or (at your option) any later version. *
10
# * for detail see the LICENCE text file. *
12
# * FreeCAD is distributed in the hope that it will be useful, *
13
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
# * GNU Library General Public License for more details. *
17
# * You should have received a copy of the GNU Library General Public *
18
# * License along with FreeCAD; if not, write to the Free Software *
19
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22
# ***************************************************************************
23
"""Provides functions to create Arc objects by using 3 points."""
24
## @package make_arc_3points
26
# \brief Provides functions to create Arc objects by using 3 points.
28
## \addtogroup draftmake
35
import draftutils.utils as utils
36
from draftutils.messages import _err
37
from draftutils.translate import translate
39
import draftutils.gui_utils as gui_utils
42
def make_arc_3points(points, placement=None, face=False,
43
support=None, map_mode="Deactivated",
45
"""Draw a circular arc defined by three points in the circumference.
49
points: list of Base::Vector3
50
A list that must be three points.
52
placement: Base::Placement, optional
53
It defaults to `None`.
54
It is a placement, comprised of a `Base` (`Base::Vector3`),
55
and a `Rotation` (`Base::Rotation`).
56
If it exists it moves the center of the new object to the point
57
indicated by `placement.Base`, while `placement.Rotation`
58
is ignored so that the arc keeps the same orientation
59
with which it was created.
61
If both `support` and `placement` are given,
62
`placement.Base` is used for the `AttachmentOffset.Base`,
63
and again `placement.Rotation` is ignored.
66
It defaults to `False`.
67
If it is `True` it will create a face in the closed arc.
68
Otherwise only the circumference edge will be shown.
70
support: App::PropertyLinkSubList, optional
71
It defaults to `None`.
72
It is a list containing tuples to define the attachment
75
A tuple in the list needs two elements;
76
the first is an external object, and the second is another tuple
77
with the names of sub-elements on that external object
78
likes vertices or faces.
80
support = [(obj, ("Face1"))]
81
support = [(obj, ("Vertex1", "Vertex5", "Vertex8"))]
83
This parameter sets the `Support` property but it only really affects
84
the position of the new object when the `map_mode`
85
is set to other than `'Deactivated'`.
87
map_mode: str, optional
88
It defaults to `'Deactivated'`.
89
It defines the type of `'MapMode'` of the new object.
90
This parameter only works when a `support` is also provided.
92
Example: place the new object on a face or another object.
94
support = [(obj, ("Face1"))]
97
Example: place the new object on a plane created by three vertices
100
support = [(obj, ("Vertex1", "Vertex5", "Vertex8"))]
101
map_mode = 'ThreePointsPlane'
103
primitive: bool, optional
104
It defaults to `False`. If it is `True`, it will create a Part
105
primitive instead of a Draft object.
106
In this case, `placement`, `face`, `support`, and `map_mode`
111
Part::Part2DObject or Part::Feature
113
Normally it returns a parametric Draft object (`Part::Part2DObject`).
114
If `primitive` is `True`, it returns a basic `Part::Feature`.
117
Returns `None` if there is a problem and the object cannot be created.
119
_name = "make_arc_3points"
122
utils.type_check([(points, (list, tuple))], name=_name)
124
_err(translate("draft","Points:") + " {}".format(points))
125
_err(translate("draft","Wrong input: must be list or tuple of three points exactly."))
129
_err(translate("draft","Points:") + " {}".format(points))
130
_err(translate("draft","Wrong input: must be list or tuple of three points exactly."))
133
if placement is not None:
135
utils.type_check([(placement, App.Placement)], name=_name)
137
_err(translate("draft","Placement:") + " {}".format(placement))
138
_err(translate("draft","Wrong input: incorrect type of placement."))
144
utils.type_check([(p1, App.Vector),
146
(p3, App.Vector)], name=_name)
148
_err(translate("draft","Wrong input: incorrect type of points."))
152
_edge = Part.Arc(p1, p2, p3)
153
except Part.OCCError as error:
154
_err(translate("draft","Cannot generate shape:") + " " + "{}".format(error))
157
edge = _edge.toShape()
158
radius = edge.Curve.Radius
159
center = edge.Curve.Center
162
obj = App.ActiveDocument.addObject("Part::Feature", "Arc")
166
rot = App.Rotation(edge.Curve.XAxis,
168
edge.Curve.Axis, "ZXY")
169
_placement = App.Placement(center, rot)
170
start = edge.FirstParameter
171
end = math.degrees(edge.LastParameter)
172
obj = Draft.make_circle(radius,
173
placement=_placement, face=face,
174
startangle=start, endangle=end,
177
original_placement = obj.Placement
179
if placement and not support:
180
obj.Placement.Base = placement.Base
182
obj.MapMode = map_mode
184
obj.AttachmentOffset.Base = placement.Base
185
obj.AttachmentOffset.Rotation = original_placement.Rotation