Add Draft workbench to .pre-commit-config (#24664)
* Add Draft workbench to .pre-commit-config * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -84,37 +84,35 @@ def make_arc_3points(points, placement=None, face=False, support=None, primitive
|
||||
try:
|
||||
utils.type_check([(points, (list, tuple))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Points:") + " {}".format(points))
|
||||
_err(translate("draft","Wrong input: must be a list or tuple of 3 points exactly."))
|
||||
_err(translate("draft", "Points:") + " {}".format(points))
|
||||
_err(translate("draft", "Wrong input: must be a list or tuple of 3 points exactly."))
|
||||
return None
|
||||
|
||||
if len(points) != 3:
|
||||
_err(translate("draft","Points:") + " {}".format(points))
|
||||
_err(translate("draft","Wrong input: must be list or tuple of 3 points exactly."))
|
||||
_err(translate("draft", "Points:") + " {}".format(points))
|
||||
_err(translate("draft", "Wrong input: must be list or tuple of 3 points exactly."))
|
||||
return None
|
||||
|
||||
p1, p2, p3 = points
|
||||
|
||||
try:
|
||||
utils.type_check([(p1, App.Vector),
|
||||
(p2, App.Vector),
|
||||
(p3, App.Vector)], name=_name)
|
||||
utils.type_check([(p1, App.Vector), (p2, App.Vector), (p3, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: incorrect type of points."))
|
||||
_err(translate("draft", "Wrong input: incorrect type of points."))
|
||||
return None
|
||||
|
||||
if placement is not None:
|
||||
try:
|
||||
utils.type_check([(placement, App.Placement)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Placement:") + " {}".format(placement))
|
||||
_err(translate("draft","Wrong input: incorrect type of placement."))
|
||||
_err(translate("draft", "Placement:") + " {}".format(placement))
|
||||
_err(translate("draft", "Wrong input: incorrect type of placement."))
|
||||
return None
|
||||
|
||||
try:
|
||||
edge = Part.Arc(p1, p2, p3).toShape()
|
||||
except Part.OCCError as error:
|
||||
_err(translate("draft","Cannot generate shape:") + " " + "{}".format(error))
|
||||
_err(translate("draft", "Cannot generate shape:") + " " + "{}".format(error))
|
||||
return None
|
||||
|
||||
if primitive:
|
||||
@@ -124,4 +122,5 @@ def make_arc_3points(points, placement=None, face=False, support=None, primitive
|
||||
|
||||
return make_circle.make_circle(edge, placement=placement, face=face, support=support)
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -43,10 +43,7 @@ if App.GuiUp:
|
||||
from draftviewproviders.view_draftlink import ViewProviderDraftLink
|
||||
|
||||
|
||||
def make_array(base_object,
|
||||
arg1, arg2, arg3,
|
||||
arg4=None, arg5=None, arg6=None,
|
||||
use_link=True):
|
||||
def make_array(base_object, arg1, arg2, arg3, arg4=None, arg5=None, arg6=None, use_link=True):
|
||||
"""Create a Draft Array of the given object.
|
||||
|
||||
Rectangular array
|
||||
@@ -82,14 +79,13 @@ def make_array(base_object,
|
||||
"""
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
if use_link:
|
||||
# The Array class must be called in this special way
|
||||
# to make it a LinkArray
|
||||
new_obj = doc.addObject("Part::FeaturePython", "Array",
|
||||
Array(None), None, True)
|
||||
new_obj = doc.addObject("Part::FeaturePython", "Array", Array(None), None, True)
|
||||
else:
|
||||
new_obj = doc.addObject("Part::FeaturePython", "Array")
|
||||
Array(new_obj)
|
||||
@@ -129,7 +125,9 @@ def make_array(base_object,
|
||||
ViewProviderDraftLink(new_obj.ViewObject)
|
||||
else:
|
||||
if new_obj.ArrayType == "circular":
|
||||
new_obj.Proxy.execute(new_obj) # Updates Count which is required for correct DiffuseColor.
|
||||
new_obj.Proxy.execute(
|
||||
new_obj
|
||||
) # Updates Count which is required for correct DiffuseColor.
|
||||
ViewProviderDraftArray(new_obj.ViewObject)
|
||||
gui_utils.format_object(new_obj, new_obj.Base)
|
||||
new_obj.ViewObject.Proxy.resetColors(new_obj.ViewObject)
|
||||
@@ -139,17 +137,17 @@ def make_array(base_object,
|
||||
return new_obj
|
||||
|
||||
|
||||
def makeArray(baseobject,
|
||||
arg1, arg2, arg3,
|
||||
arg4=None, arg5=None, arg6=None,
|
||||
name="Array", use_link=False):
|
||||
def makeArray(
|
||||
baseobject, arg1, arg2, arg3, arg4=None, arg5=None, arg6=None, name="Array", use_link=False
|
||||
):
|
||||
"""Create an Array. DEPRECATED. Use 'make_array'."""
|
||||
_wrn("Do not use this function directly; instead, use "
|
||||
"'make_ortho_array', 'make_polar_array', "
|
||||
"or 'make_circular_array'.")
|
||||
_wrn(
|
||||
"Do not use this function directly; instead, use "
|
||||
"'make_ortho_array', 'make_polar_array', "
|
||||
"or 'make_circular_array'."
|
||||
)
|
||||
|
||||
return make_array(baseobject, arg1, arg2, arg3, arg4, arg5, arg6, use_link)
|
||||
|
||||
return make_array(baseobject,
|
||||
arg1, arg2, arg3,
|
||||
arg4, arg5, arg6, use_link)
|
||||
|
||||
## @}
|
||||
|
||||
@@ -38,9 +38,7 @@ if App.GuiUp:
|
||||
from draftviewproviders.view_bezcurve import ViewProviderBezCurve
|
||||
|
||||
|
||||
def make_bezcurve(pointslist,
|
||||
closed=False, placement=None, face=None, support=None,
|
||||
degree=None):
|
||||
def make_bezcurve(pointslist, closed=False, placement=None, face=None, support=None, degree=None):
|
||||
"""make_bezcurve(pointslist, [closed], [placement])
|
||||
|
||||
Creates a Bezier Curve object from the given list of vectors.
|
||||
@@ -72,15 +70,17 @@ def make_bezcurve(pointslist,
|
||||
if not App.ActiveDocument:
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
if not isinstance(pointslist,list):
|
||||
if not isinstance(pointslist, list):
|
||||
nlist = []
|
||||
for v in pointslist.Vertexes:
|
||||
nlist.append(v.Point)
|
||||
pointslist = nlist
|
||||
if placement:
|
||||
utils.type_check([(placement,App.Placement)], "make_bezcurve")
|
||||
if len(pointslist) == 2: fname = "Line"
|
||||
else: fname = "BezCurve"
|
||||
utils.type_check([(placement, App.Placement)], "make_bezcurve")
|
||||
if len(pointslist) == 2:
|
||||
fname = "Line"
|
||||
else:
|
||||
fname = "BezCurve"
|
||||
obj = App.ActiveDocument.addObject("Part::FeaturePython", fname)
|
||||
obj.addExtension("Part::AttachExtensionPython")
|
||||
BezCurve(obj)
|
||||
@@ -89,18 +89,19 @@ def make_bezcurve(pointslist,
|
||||
obj.Degree = degree
|
||||
else:
|
||||
import Part
|
||||
obj.Degree = min((len(pointslist)-(1 * (not closed))),
|
||||
Part.BezierCurve().MaxDegree)
|
||||
|
||||
obj.Degree = min((len(pointslist) - (1 * (not closed))), Part.BezierCurve().MaxDegree)
|
||||
obj.Closed = closed
|
||||
obj.AttachmentSupport = support
|
||||
if face is not None:
|
||||
obj.MakeFace = face
|
||||
obj.Proxy.resetcontinuity(obj)
|
||||
if placement: obj.Placement = placement
|
||||
if placement:
|
||||
obj.Placement = placement
|
||||
if App.GuiUp:
|
||||
ViewProviderBezCurve(obj.ViewObject)
|
||||
# if not face: obj.ViewObject.DisplayMode = "Wireframe"
|
||||
# obj.ViewObject.DisplayMode = "Wireframe"
|
||||
# if not face: obj.ViewObject.DisplayMode = "Wireframe"
|
||||
# obj.ViewObject.DisplayMode = "Wireframe"
|
||||
gui_utils.format_object(obj)
|
||||
gui_utils.select(obj)
|
||||
|
||||
|
||||
@@ -67,16 +67,16 @@ def make_bspline(pointslist, closed=False, placement=None, face=None, support=No
|
||||
if not App.ActiveDocument:
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
if not isinstance(pointslist,list):
|
||||
if not isinstance(pointslist, list):
|
||||
nlist = []
|
||||
for v in pointslist.Vertexes:
|
||||
nlist.append(v.Point)
|
||||
pointslist = nlist
|
||||
if len(pointslist) < 2:
|
||||
_err = "Draft.make_bspline: not enough points"
|
||||
App.Console.PrintError(translate("draft", _err)+"\n")
|
||||
App.Console.PrintError(translate("draft", _err) + "\n")
|
||||
return
|
||||
if (pointslist[0] == pointslist[-1]):
|
||||
if pointslist[0] == pointslist[-1]:
|
||||
if len(pointslist) > 2:
|
||||
closed = True
|
||||
pointslist.pop()
|
||||
@@ -85,13 +85,15 @@ def make_bspline(pointslist, closed=False, placement=None, face=None, support=No
|
||||
else:
|
||||
# len == 2 and first == last GIGO
|
||||
_err = "Draft.make_bspline: Invalid pointslist"
|
||||
App.Console.PrintError(translate("Draft", _err)+"\n")
|
||||
App.Console.PrintError(translate("Draft", _err) + "\n")
|
||||
return
|
||||
# should have sensible parms from here on
|
||||
if placement:
|
||||
utils.type_check([(placement,App.Placement)], "make_bspline")
|
||||
if len(pointslist) == 2: fname = "Line"
|
||||
else: fname = "BSpline"
|
||||
utils.type_check([(placement, App.Placement)], "make_bspline")
|
||||
if len(pointslist) == 2:
|
||||
fname = "Line"
|
||||
else:
|
||||
fname = "BSpline"
|
||||
obj = App.ActiveDocument.addObject("Part::FeaturePython", fname)
|
||||
obj.addExtension("Part::AttachExtensionPython")
|
||||
BSpline(obj)
|
||||
@@ -100,7 +102,8 @@ def make_bspline(pointslist, closed=False, placement=None, face=None, support=No
|
||||
obj.AttachmentSupport = support
|
||||
if face is not None:
|
||||
obj.MakeFace = face
|
||||
if placement: obj.Placement = placement
|
||||
if placement:
|
||||
obj.Placement = placement
|
||||
if App.GuiUp:
|
||||
ViewProviderBSpline(obj.ViewObject)
|
||||
gui_utils.format_object(obj)
|
||||
|
||||
@@ -54,7 +54,7 @@ def _get_normal(axis, ref_rot):
|
||||
local_comp_vec = App.Vector(1, 0, 0)
|
||||
comp_vec = ref_rot.multVec(local_comp_vec)
|
||||
axis = App.Vector(axis) # create independent copy
|
||||
if axis.getAngle(comp_vec) > math.pi/2:
|
||||
if axis.getAngle(comp_vec) > math.pi / 2:
|
||||
axis = axis.negative()
|
||||
return axis
|
||||
|
||||
@@ -104,10 +104,9 @@ def make_circle(radius, placement=None, face=None, startangle=None, endangle=Non
|
||||
return
|
||||
|
||||
if placement:
|
||||
utils.type_check([(placement,App.Placement)], "make_circle")
|
||||
utils.type_check([(placement, App.Placement)], "make_circle")
|
||||
|
||||
if (isinstance(radius, Part.Edge) and len(radius.Vertexes) > 1) \
|
||||
or startangle != endangle:
|
||||
if (isinstance(radius, Part.Edge) and len(radius.Vertexes) > 1) or startangle != endangle:
|
||||
name = "Arc"
|
||||
else:
|
||||
name = "Circle"
|
||||
|
||||
@@ -35,11 +35,16 @@ from draftutils.messages import _err
|
||||
from draftutils.translate import translate
|
||||
|
||||
|
||||
def make_circular_array(base_object,
|
||||
r_distance=100, tan_distance=50,
|
||||
number=3, symmetry=1,
|
||||
axis=App.Vector(0, 0, 1), center=App.Vector(0, 0, 0),
|
||||
use_link=True):
|
||||
def make_circular_array(
|
||||
base_object,
|
||||
r_distance=100,
|
||||
tan_distance=50,
|
||||
number=3,
|
||||
symmetry=1,
|
||||
axis=App.Vector(0, 0, 1),
|
||||
center=App.Vector(0, 0, 0),
|
||||
use_link=True,
|
||||
):
|
||||
"""Create a circular array from the given object.
|
||||
|
||||
Parameters
|
||||
@@ -122,38 +127,46 @@ def make_circular_array(base_object,
|
||||
|
||||
found, base_object = utils.find_object(base_object, doc=App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","Wrong input: base_object not in document."))
|
||||
_err(translate("draft", "Wrong input: base_object not in document."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(r_distance, (int, float, App.Units.Quantity)),
|
||||
(tan_distance, (int, float, App.Units.Quantity))],
|
||||
name=_name)
|
||||
utils.type_check(
|
||||
[
|
||||
(r_distance, (int, float, App.Units.Quantity)),
|
||||
(tan_distance, (int, float, App.Units.Quantity)),
|
||||
],
|
||||
name=_name,
|
||||
)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number or quantity."))
|
||||
_err(translate("draft", "Wrong input: must be a number or quantity."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(number, int),
|
||||
(symmetry, int)], name=_name)
|
||||
utils.type_check([(number, int), (symmetry, int)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be an integer number."))
|
||||
_err(translate("draft", "Wrong input: must be an integer number."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(axis, App.Vector),
|
||||
(center, App.Vector)], name=_name)
|
||||
utils.type_check([(axis, App.Vector), (center, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
use_link = bool(use_link)
|
||||
|
||||
new_obj = make_array.make_array(base_object,
|
||||
arg1=r_distance, arg2=tan_distance,
|
||||
arg3=axis, arg4=center,
|
||||
arg5=number, arg6=symmetry,
|
||||
use_link=use_link)
|
||||
new_obj = make_array.make_array(
|
||||
base_object,
|
||||
arg1=r_distance,
|
||||
arg2=tan_distance,
|
||||
arg3=axis,
|
||||
arg4=center,
|
||||
arg5=number,
|
||||
arg6=symmetry,
|
||||
use_link=use_link,
|
||||
)
|
||||
return new_obj
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -64,19 +64,23 @@ def make_clone(obj, delta=None, forcedraft=False):
|
||||
if prefix:
|
||||
prefix = prefix.strip() + " "
|
||||
|
||||
if not isinstance(obj,list):
|
||||
if not isinstance(obj, list):
|
||||
obj = [obj]
|
||||
|
||||
if len(obj) == 1 \
|
||||
and obj[0].isDerivedFrom("Part::Part2DObject") \
|
||||
and utils.get_type(obj[0]) not in ["BezCurve", "BSpline", "Wire"]:
|
||||
if (
|
||||
len(obj) == 1
|
||||
and obj[0].isDerivedFrom("Part::Part2DObject")
|
||||
and utils.get_type(obj[0]) not in ["BezCurve", "BSpline", "Wire"]
|
||||
):
|
||||
# "BezCurve", "BSpline" and "Wire" objects created with < v1.1
|
||||
# are "Part::Part2DObject" objects but they need not be 2D.
|
||||
cl = App.ActiveDocument.addObject("Part::Part2DObjectPython", "Clone2D")
|
||||
cl.Label = prefix + obj[0].Label + " (2D)"
|
||||
elif len(obj) == 1 \
|
||||
and (hasattr(obj[0], "CloneOf") or utils.get_type(obj[0]) == "BuildingPart") \
|
||||
and not forcedraft:
|
||||
elif (
|
||||
len(obj) == 1
|
||||
and (hasattr(obj[0], "CloneOf") or utils.get_type(obj[0]) == "BuildingPart")
|
||||
and not forcedraft
|
||||
):
|
||||
# arch objects can be clones
|
||||
try:
|
||||
import Arch
|
||||
@@ -87,13 +91,13 @@ def make_clone(obj, delta=None, forcedraft=False):
|
||||
if utils.get_type(obj[0]) == "BuildingPart":
|
||||
cl = Arch.makeComponent()
|
||||
else:
|
||||
try: # new-style make function
|
||||
try: # new-style make function
|
||||
cl = getattr(Arch, "make_" + obj[0].Proxy.Type.lower())()
|
||||
except Exception:
|
||||
try: # old-style make function
|
||||
try: # old-style make function
|
||||
cl = getattr(Arch, "make" + obj[0].Proxy.Type)()
|
||||
except Exception:
|
||||
pass # not a standard Arch object... Fall back to Draft mode
|
||||
pass # not a standard Arch object... Fall back to Draft mode
|
||||
if cl:
|
||||
base = utils.get_clone_base(obj[0])
|
||||
cl.Label = prefix + base.Label
|
||||
@@ -119,9 +123,9 @@ def make_clone(obj, delta=None, forcedraft=False):
|
||||
cl.Objects = obj
|
||||
if delta:
|
||||
cl.Placement.move(delta)
|
||||
elif (len(obj) == 1) and hasattr(obj[0],"Placement"):
|
||||
elif (len(obj) == 1) and hasattr(obj[0], "Placement"):
|
||||
cl.Placement = obj[0].Placement
|
||||
if hasattr(cl,"LongName") and hasattr(obj[0],"LongName"):
|
||||
if hasattr(cl, "LongName") and hasattr(obj[0], "LongName"):
|
||||
cl.LongName = obj[0].LongName
|
||||
if App.GuiUp:
|
||||
ViewProviderClone(cl.ViewObject)
|
||||
|
||||
@@ -58,7 +58,7 @@ def make_copy(obj, force=None, reparent=False, simple_copy=False):
|
||||
|
||||
newobj = None
|
||||
|
||||
if simple_copy and hasattr(obj, 'Shape'):
|
||||
if simple_copy and hasattr(obj, "Shape"):
|
||||
# this was the old implementation that is actually not used by default
|
||||
_name = utils.get_real_name(obj.Name)
|
||||
newobj = App.ActiveDocument.addObject("Part::Feature", _name)
|
||||
@@ -91,4 +91,5 @@ def make_copy(obj, force=None, reparent=False, simple_copy=False):
|
||||
|
||||
return newobj
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -48,9 +48,10 @@ from draftutils.translate import translate
|
||||
from draftobjects.dimension import LinearDimension, AngularDimension
|
||||
|
||||
if App.GuiUp:
|
||||
from draftviewproviders.view_dimension \
|
||||
import (ViewProviderLinearDimension,
|
||||
ViewProviderAngularDimension)
|
||||
from draftviewproviders.view_dimension import (
|
||||
ViewProviderLinearDimension,
|
||||
ViewProviderAngularDimension,
|
||||
)
|
||||
|
||||
|
||||
def _get_flip_text_lin(p1, p2, wp, normal):
|
||||
@@ -65,15 +66,15 @@ def _get_flip_text_lin(p1, p2, wp, normal):
|
||||
return False
|
||||
if math.isclose(abs(ang), math.pi, abs_tol=tol):
|
||||
return True
|
||||
if math.isclose(ang, math.pi/2, abs_tol=tol):
|
||||
if math.isclose(ang, math.pi / 2, abs_tol=tol):
|
||||
return False
|
||||
if math.isclose(ang, -math.pi/2, abs_tol=tol):
|
||||
if math.isclose(ang, -math.pi / 2, abs_tol=tol):
|
||||
return True
|
||||
# 90-180 (in that quadrant + 1st point closest to the origin):
|
||||
if math.pi/2 < ang < math.pi:
|
||||
if math.pi / 2 < ang < math.pi:
|
||||
return True
|
||||
# 180-270:
|
||||
if -math.pi < ang < -math.pi/2:
|
||||
if -math.pi < ang < -math.pi / 2:
|
||||
return True
|
||||
# 0-90 and 270-360:
|
||||
return False
|
||||
@@ -84,6 +85,7 @@ def _get_flip_text_ang(cen, sta, end, normal):
|
||||
if not params.get_param("DimAutoFlipText"):
|
||||
return False
|
||||
import Part
|
||||
|
||||
circle = Part.makeCircle(1, cen, normal, sta, end)
|
||||
mid = edges.findMidpoint(circle)
|
||||
wp = WorkingPlane.get_working_plane(update=False)
|
||||
@@ -135,7 +137,7 @@ def make_dimension(p1, p2, p3=None, p4=None):
|
||||
if App.GuiUp:
|
||||
# invert the normal if we are viewing it from the back
|
||||
vnorm = gui_utils.get3DView().getViewDirection()
|
||||
if vnorm.getAngle(normal) < math.pi/2:
|
||||
if vnorm.getAngle(normal) < math.pi / 2:
|
||||
normal = normal.negative()
|
||||
|
||||
new_obj.Normal = normal
|
||||
@@ -217,8 +219,8 @@ def make_dimension(p1, p2, p3=None, p4=None):
|
||||
|
||||
def makeDimension(p1, p2, p3=None, p4=None):
|
||||
"""Create a dimension. DEPRECATED. Use 'make_dimension'."""
|
||||
_wrn(translate("draft","This function is deprecated. Do not use this function directly."))
|
||||
_wrn(translate("draft","Use one of 'make_linear_dimension', or 'make_linear_dimension_obj'."))
|
||||
_wrn(translate("draft", "This function is deprecated. Do not use this function directly."))
|
||||
_wrn(translate("draft", "Use one of 'make_linear_dimension', or 'make_linear_dimension_obj'."))
|
||||
|
||||
return make_dimension(p1, p2, p3, p4)
|
||||
|
||||
@@ -258,26 +260,26 @@ def make_linear_dimension(p1, p2, dim_line=None):
|
||||
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(p1, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(p2, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
if dim_line:
|
||||
try:
|
||||
utils.type_check([(dim_line, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
else:
|
||||
diff = p2.sub(p1)
|
||||
@@ -347,61 +349,70 @@ def make_linear_dimension_obj(edge_object, i1=1, i2=2, dim_line=None):
|
||||
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
if isinstance(edge_object, (list, tuple)):
|
||||
_err(translate("draft","Wrong input: edge_object must not be a list or tuple."))
|
||||
_err(translate("draft", "Wrong input: edge_object must not be a list or tuple."))
|
||||
return None
|
||||
|
||||
found, edge_object = utils.find_object(edge_object, doc)
|
||||
if not found:
|
||||
_err(translate("draft","Wrong input: edge_object not in document."))
|
||||
_err(translate("draft", "Wrong input: edge_object not in document."))
|
||||
return None
|
||||
|
||||
if not hasattr(edge_object, "Shape"):
|
||||
_err(translate("draft","Wrong input: object doesn't have a 'Shape' to measure."))
|
||||
_err(translate("draft", "Wrong input: object doesn't have a 'Shape' to measure."))
|
||||
return None
|
||||
if (not hasattr(edge_object.Shape, "Vertexes")
|
||||
or len(edge_object.Shape.Vertexes) < 1):
|
||||
_err(translate("draft","Wrong input: object does not have at least 1 element in 'Vertexes' to use for measuring."))
|
||||
if not hasattr(edge_object.Shape, "Vertexes") or len(edge_object.Shape.Vertexes) < 1:
|
||||
_err(
|
||||
translate(
|
||||
"draft",
|
||||
"Wrong input: object does not have at least 1 element in 'Vertexes' to use for measuring.",
|
||||
)
|
||||
)
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(i1, int)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be an integer."))
|
||||
_err(translate("draft", "Wrong input: must be an integer."))
|
||||
return None
|
||||
|
||||
if i1 < 1:
|
||||
i1 = 1
|
||||
_wrn(translate("draft","i1: values below 1 are not allowed; will be set to 1."))
|
||||
_wrn(translate("draft", "i1: values below 1 are not allowed; will be set to 1."))
|
||||
|
||||
vx1 = edge_object.getSubObject("Vertex" + str(i1))
|
||||
if not vx1:
|
||||
_err(translate("draft","Wrong input: vertex not in object."))
|
||||
_err(translate("draft", "Wrong input: vertex not in object."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(i2, int)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
if i2 < 1:
|
||||
i2 = len(edge_object.Shape.Vertexes)
|
||||
_wrn(translate("draft","i2: values below 1 are not allowed; will be set to the last vertex in the object."))
|
||||
_wrn(
|
||||
translate(
|
||||
"draft",
|
||||
"i2: values below 1 are not allowed; will be set to the last vertex in the object.",
|
||||
)
|
||||
)
|
||||
|
||||
vx2 = edge_object.getSubObject("Vertex" + str(i2))
|
||||
if not vx2:
|
||||
_err(translate("draft","Wrong input: vertex not in object."))
|
||||
_err(translate("draft", "Wrong input: vertex not in object."))
|
||||
return None
|
||||
|
||||
if dim_line:
|
||||
try:
|
||||
utils.type_check([(dim_line, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
else:
|
||||
diff = vx2.Point.sub(vx1.Point)
|
||||
@@ -419,8 +430,7 @@ def make_linear_dimension_obj(edge_object, i1=1, i2=2, dim_line=None):
|
||||
return new_obj
|
||||
|
||||
|
||||
def make_radial_dimension_obj(edge_object, index=1, mode="radius",
|
||||
dim_line=None):
|
||||
def make_radial_dimension_obj(edge_object, index=1, mode="radius", dim_line=None):
|
||||
"""Create a radial or diameter dimension from an arc object.
|
||||
|
||||
Parameters
|
||||
@@ -467,56 +477,60 @@ def make_radial_dimension_obj(edge_object, index=1, mode="radius",
|
||||
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
found, edge_object = utils.find_object(edge_object, doc)
|
||||
if not found:
|
||||
_err(translate("draft","Wrong input: edge_object not in document."))
|
||||
_err(translate("draft", "Wrong input: edge_object not in document."))
|
||||
return None
|
||||
|
||||
if not hasattr(edge_object, "Shape"):
|
||||
_err(translate("draft","Wrong input: object doesn't have a 'Shape' to measure."))
|
||||
_err(translate("draft", "Wrong input: object doesn't have a 'Shape' to measure."))
|
||||
return None
|
||||
if (not hasattr(edge_object.Shape, "Edges")
|
||||
or len(edge_object.Shape.Edges) < 1):
|
||||
_err(translate("draft","Wrong input: object doesn't have at least one element in 'Edges' to use for measuring."))
|
||||
if not hasattr(edge_object.Shape, "Edges") or len(edge_object.Shape.Edges) < 1:
|
||||
_err(
|
||||
translate(
|
||||
"draft",
|
||||
"Wrong input: object doesn't have at least one element in 'Edges' to use for measuring.",
|
||||
)
|
||||
)
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(index, int)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be an integer."))
|
||||
_err(translate("draft", "Wrong input: must be an integer."))
|
||||
return None
|
||||
|
||||
if index < 1:
|
||||
index = 1
|
||||
_wrn(translate("draft","index: values below 1 are not allowed; will be set to 1."))
|
||||
_wrn(translate("draft", "index: values below 1 are not allowed; will be set to 1."))
|
||||
|
||||
edge = edge_object.getSubObject("Edge" + str(index))
|
||||
if not edge:
|
||||
_err(translate("draft","Wrong input: index doesn't correspond to an edge in the object."))
|
||||
_err(translate("draft", "Wrong input: index doesn't correspond to an edge in the object."))
|
||||
return None
|
||||
|
||||
if not hasattr(edge, "Curve") or edge.Curve.TypeId != 'Part::GeomCircle':
|
||||
_err(translate("draft","Wrong input: index doesn't correspond to a circular edge."))
|
||||
if not hasattr(edge, "Curve") or edge.Curve.TypeId != "Part::GeomCircle":
|
||||
_err(translate("draft", "Wrong input: index doesn't correspond to a circular edge."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(mode, str)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a string, 'radius' or 'diameter'."))
|
||||
_err(translate("draft", "Wrong input: must be a string, 'radius' or 'diameter'."))
|
||||
return None
|
||||
|
||||
if mode not in ("radius", "diameter"):
|
||||
_err(translate("draft","Wrong input: must be a string, 'radius' or 'diameter'."))
|
||||
_err(translate("draft", "Wrong input: must be a string, 'radius' or 'diameter'."))
|
||||
return None
|
||||
|
||||
if dim_line:
|
||||
try:
|
||||
utils.type_check([(dim_line, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
else:
|
||||
center = edge_object.Shape.Edges[index - 1].Curve.Center
|
||||
@@ -532,9 +546,12 @@ def make_radial_dimension_obj(edge_object, index=1, mode="radius",
|
||||
return new_obj
|
||||
|
||||
|
||||
def make_angular_dimension(center=App.Vector(0, 0, 0),
|
||||
angles=None, # If None, set to [0,90]
|
||||
dim_line=App.Vector(10, 10, 0), normal=None):
|
||||
def make_angular_dimension(
|
||||
center=App.Vector(0, 0, 0),
|
||||
angles=None, # If None, set to [0,90]
|
||||
dim_line=App.Vector(10, 10, 0),
|
||||
normal=None,
|
||||
):
|
||||
"""Create an angular dimension from the given center and angles.
|
||||
|
||||
Parameters
|
||||
@@ -581,27 +598,26 @@ def make_angular_dimension(center=App.Vector(0, 0, 0),
|
||||
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(center, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(angles, (tuple, list))], name=_name)
|
||||
|
||||
if len(angles) != 2:
|
||||
_err(translate("draft","Wrong input: must be a list with two angles."))
|
||||
_err(translate("draft", "Wrong input: must be a list with two angles."))
|
||||
return None
|
||||
|
||||
ang1, ang2 = angles
|
||||
utils.type_check([(ang1, (int, float)),
|
||||
(ang2, (int, float))], name=_name)
|
||||
utils.type_check([(ang1, (int, float)), (ang2, (int, float))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a list with two angles."))
|
||||
_err(translate("draft", "Wrong input: must be a list with two angles."))
|
||||
return None
|
||||
|
||||
# If the angle is larger than 360 degrees, make sure
|
||||
@@ -613,14 +629,14 @@ def make_angular_dimension(center=App.Vector(0, 0, 0),
|
||||
try:
|
||||
utils.type_check([(dim_line, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
if normal:
|
||||
try:
|
||||
utils.type_check([(dim_line, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
if not normal:
|
||||
@@ -636,7 +652,7 @@ def make_angular_dimension(center=App.Vector(0, 0, 0),
|
||||
# This is determined by the angle between the current
|
||||
# 3D view and the provided normal being below 90 degrees
|
||||
vnorm = gui_utils.get3DView().getViewDirection()
|
||||
if vnorm.getAngle(normal) < math.pi/2:
|
||||
if vnorm.getAngle(normal) < math.pi / 2:
|
||||
normal = normal.negative()
|
||||
|
||||
new_obj.Center = center
|
||||
@@ -660,7 +676,7 @@ def makeAngularDimension(center, angles, p3, normal=None):
|
||||
ang1, ang2 = angles
|
||||
angles = [math.degrees(ang2), math.degrees(ang1)]
|
||||
|
||||
return make_angular_dimension(center=center, angles=angles,
|
||||
dim_line=p3, normal=normal)
|
||||
return make_angular_dimension(center=center, angles=angles, dim_line=p3, normal=normal)
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -52,13 +52,13 @@ def make_facebinder(selectionset, name="Facebinder"):
|
||||
if not App.ActiveDocument:
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
if not isinstance(selectionset,list):
|
||||
if not isinstance(selectionset, list):
|
||||
selectionset = [selectionset]
|
||||
fb = App.ActiveDocument.addObject("Part::FeaturePython",name)
|
||||
fb = App.ActiveDocument.addObject("Part::FeaturePython", name)
|
||||
Facebinder(fb)
|
||||
if App.GuiUp:
|
||||
ViewProviderFacebinder(fb.ViewObject)
|
||||
faces = [] # unused variable?
|
||||
faces = [] # unused variable?
|
||||
fb.Proxy.addSubobjects(fb, selectionset)
|
||||
gui_utils.select(fb)
|
||||
return fb
|
||||
|
||||
@@ -48,6 +48,7 @@ DraftGeomUtils = lz.LazyLoader("DraftGeomUtils", globals(), "DraftGeomUtils")
|
||||
## \addtogroup draftmake
|
||||
# @{
|
||||
|
||||
|
||||
def _preprocess(objs, radius, chamfer):
|
||||
"""Check the inputs and return the edges for the fillet and the objects to be deleted."""
|
||||
edges = []
|
||||
@@ -139,4 +140,5 @@ def make_fillet(objs, radius=100, chamfer=False, delete=False):
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -1,35 +1,36 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2021 Yorik van Havre <yorik@uncreated.net> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
# ***************************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2021 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
"""This module contains FreeCAD commands for the Draft workbench"""
|
||||
|
||||
import FreeCAD
|
||||
from draftobjects.hatch import Hatch
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
from draftviewproviders.view_hatch import ViewProviderDraftHatch
|
||||
import draftutils.gui_utils as gui_utils
|
||||
|
||||
def make_hatch(baseobject, filename, pattern, scale, rotation, translate=True):
|
||||
|
||||
def make_hatch(baseobject, filename, pattern, scale, rotation, translate=True):
|
||||
"""make_hatch(baseobject, filename, pattern, scale, rotation, translate): Creates and returns a
|
||||
hatch object made by applying the given pattern of the given PAT file to the faces of
|
||||
the given base object. Given scale, rotation and translate factors are applied to the hatch object.
|
||||
|
||||
@@ -41,12 +41,17 @@ if App.GuiUp:
|
||||
from draftviewproviders.view_label import ViewProviderLabel
|
||||
|
||||
|
||||
def make_label(target_point=App.Vector(0, 0, 0),
|
||||
placement=App.Vector(30, 30, 0),
|
||||
target_object=None, subelements=None,
|
||||
label_type="Custom", custom_text="Label",
|
||||
direction="Horizontal", distance=-10,
|
||||
points=None):
|
||||
def make_label(
|
||||
target_point=App.Vector(0, 0, 0),
|
||||
placement=App.Vector(30, 30, 0),
|
||||
target_object=None,
|
||||
subelements=None,
|
||||
label_type="Custom",
|
||||
custom_text="Label",
|
||||
direction="Horizontal",
|
||||
distance=-10,
|
||||
points=None,
|
||||
):
|
||||
"""Create a Label object containing different types of information.
|
||||
|
||||
The current color and text height and font specified in preferences
|
||||
@@ -190,7 +195,7 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
if not target_point:
|
||||
@@ -198,17 +203,15 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
try:
|
||||
utils.type_check([(target_point, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
if not placement:
|
||||
placement = App.Placement()
|
||||
try:
|
||||
utils.type_check([(placement, (App.Placement,
|
||||
App.Vector,
|
||||
App.Rotation))], name=_name)
|
||||
utils.type_check([(placement, (App.Placement, App.Vector, App.Rotation))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a placement, a vector, or a rotation."))
|
||||
_err(translate("draft", "Wrong input: must be a placement, a vector, or a rotation."))
|
||||
return None
|
||||
|
||||
# Convert the vector or rotation to a full placement
|
||||
@@ -219,12 +222,12 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
|
||||
if target_object:
|
||||
if isinstance(target_object, (list, tuple)):
|
||||
_err(translate("draft","Wrong input: target_object must not be a list."))
|
||||
_err(translate("draft", "Wrong input: target_object must not be a list."))
|
||||
return None
|
||||
|
||||
found, target_object = utils.find_object(target_object, doc)
|
||||
if not found:
|
||||
_err(translate("draft","Wrong input: target_object not in document."))
|
||||
_err(translate("draft", "Wrong input: target_object not in document."))
|
||||
return None
|
||||
|
||||
if target_object and subelements:
|
||||
@@ -233,10 +236,14 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
if isinstance(subelements, str):
|
||||
subelements = [subelements]
|
||||
|
||||
utils.type_check([(subelements, (list, tuple, str))],
|
||||
name=_name)
|
||||
utils.type_check([(subelements, (list, tuple, str))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: subelements must be a list or tuple of strings, or a single string."))
|
||||
_err(
|
||||
translate(
|
||||
"draft",
|
||||
"Wrong input: subelements must be a list or tuple of strings, or a single string.",
|
||||
)
|
||||
)
|
||||
return None
|
||||
|
||||
# The subelements list is used to build a special list
|
||||
@@ -247,7 +254,7 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
for sub in subelements:
|
||||
_sub = target_object.getSubObject(sub)
|
||||
if not _sub:
|
||||
_err(translate("draft","Wrong input: subelement {} not in object.").format(sub))
|
||||
_err(translate("draft", "Wrong input: subelement {} not in object.").format(sub))
|
||||
return None
|
||||
|
||||
if not label_type:
|
||||
@@ -255,12 +262,16 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
try:
|
||||
utils.type_check([(label_type, str)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: label_type must be a string."))
|
||||
_err(translate("draft", "Wrong input: label_type must be a string."))
|
||||
return None
|
||||
|
||||
types = label.get_label_types()
|
||||
if label_type not in types:
|
||||
_err(translate("draft", "Wrong input: label_type must be one of the following:") + " " + str(types).strip("[]"))
|
||||
_err(
|
||||
translate("draft", "Wrong input: label_type must be one of the following:")
|
||||
+ " "
|
||||
+ str(types).strip("[]")
|
||||
)
|
||||
return None
|
||||
|
||||
if not custom_text:
|
||||
@@ -268,12 +279,11 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
try:
|
||||
utils.type_check([(custom_text, (str, list))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a list of strings or a single string."))
|
||||
_err(translate("draft", "Wrong input: must be a list of strings or a single string."))
|
||||
return None
|
||||
|
||||
if (type(custom_text) is list
|
||||
and not all(isinstance(element, str) for element in custom_text)):
|
||||
_err(translate("draft","Wrong input: must be a list of strings or a single string."))
|
||||
if type(custom_text) is list and not all(isinstance(element, str) for element in custom_text):
|
||||
_err(translate("draft", "Wrong input: must be a list of strings or a single string."))
|
||||
return None
|
||||
|
||||
if not direction:
|
||||
@@ -281,11 +291,19 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
try:
|
||||
utils.type_check([(direction, str)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a string, 'Horizontal', 'Vertical', or 'Custom'."))
|
||||
_err(
|
||||
translate(
|
||||
"draft", "Wrong input: must be a string, 'Horizontal', 'Vertical', or 'Custom'."
|
||||
)
|
||||
)
|
||||
return None
|
||||
|
||||
if direction not in ("Horizontal", "Vertical", "Custom"):
|
||||
_err(translate("draft","Wrong input: must be a string, 'Horizontal', 'Vertical', or 'Custom'."))
|
||||
_err(
|
||||
translate(
|
||||
"draft", "Wrong input: must be a string, 'Horizontal', 'Vertical', or 'Custom'."
|
||||
)
|
||||
)
|
||||
return None
|
||||
|
||||
if not distance:
|
||||
@@ -293,11 +311,13 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
try:
|
||||
utils.type_check([(distance, (int, float))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number."))
|
||||
_err(translate("draft", "Wrong input: must be a number."))
|
||||
return None
|
||||
|
||||
if points:
|
||||
_err_msg = translate("draft","Wrong input: points {} must be a list of at least two vectors.").format(points)
|
||||
_err_msg = translate(
|
||||
"draft", "Wrong input: points {} must be a list of at least two vectors."
|
||||
).format(points)
|
||||
try:
|
||||
utils.type_check([(points, (tuple, list))], name=_name)
|
||||
except TypeError:
|
||||
@@ -312,8 +332,7 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
_err(_err_msg)
|
||||
return None
|
||||
|
||||
new_obj = doc.addObject("App::FeaturePython",
|
||||
"dLabel")
|
||||
new_obj = doc.addObject("App::FeaturePython", "dLabel")
|
||||
label.Label(new_obj)
|
||||
|
||||
new_obj.TargetPoint = target_point
|
||||
@@ -331,7 +350,7 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
new_obj.StraightDistance = distance
|
||||
if points:
|
||||
if direction != "Custom":
|
||||
_wrn(translate("draft","Direction is not 'Custom'; points won't be used."))
|
||||
_wrn(translate("draft", "Direction is not 'Custom'; points won't be used."))
|
||||
new_obj.Points = points
|
||||
|
||||
if App.GuiUp:
|
||||
@@ -348,8 +367,9 @@ def make_label(target_point=App.Vector(0, 0, 0),
|
||||
return new_obj
|
||||
|
||||
|
||||
def makeLabel(targetpoint=None, target=None, direction=None,
|
||||
distance=None, labeltype=None, placement=None):
|
||||
def makeLabel(
|
||||
targetpoint=None, target=None, direction=None, distance=None, labeltype=None, placement=None
|
||||
):
|
||||
"""Create a Label. DEPRECATED. Use 'make_label'."""
|
||||
utils.use_instead("make_label")
|
||||
|
||||
@@ -358,10 +378,14 @@ def makeLabel(targetpoint=None, target=None, direction=None,
|
||||
|
||||
if target:
|
||||
try:
|
||||
utils.type_check([(target, (tuple, list))],
|
||||
name=_name)
|
||||
utils.type_check([(target, (tuple, list))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a list of two elements. For example, [object, 'Edge1']."))
|
||||
_err(
|
||||
translate(
|
||||
"draft",
|
||||
"Wrong input: must be a list of two elements. For example, [object, 'Edge1'].",
|
||||
)
|
||||
)
|
||||
return None
|
||||
|
||||
# In the old function `target` is the original parameter,
|
||||
@@ -383,12 +407,15 @@ def makeLabel(targetpoint=None, target=None, direction=None,
|
||||
target_object = target[0]
|
||||
subelements = target[1]
|
||||
|
||||
return make_label(target_point=targetpoint,
|
||||
placement=placement,
|
||||
target_object=target_object,
|
||||
subelements=subelements,
|
||||
label_type=labeltype,
|
||||
direction=direction,
|
||||
distance=distance)
|
||||
return make_label(
|
||||
target_point=targetpoint,
|
||||
placement=placement,
|
||||
target_object=target_object,
|
||||
subelements=subelements,
|
||||
label_type=labeltype,
|
||||
direction=direction,
|
||||
distance=distance,
|
||||
)
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -35,8 +35,7 @@ from draftutils.messages import _err
|
||||
from draftutils.translate import translate
|
||||
|
||||
if App.GuiUp:
|
||||
from draftviewproviders.view_layer import (ViewProviderLayer,
|
||||
ViewProviderLayerContainer)
|
||||
from draftviewproviders.view_layer import ViewProviderLayer, ViewProviderLayerContainer
|
||||
|
||||
|
||||
def get_layer_container():
|
||||
@@ -51,15 +50,14 @@ def get_layer_container():
|
||||
"""
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
for obj in doc.Objects:
|
||||
if obj.Name == "LayerContainer":
|
||||
return obj
|
||||
|
||||
obj = doc.addObject("App::DocumentObjectGroupPython",
|
||||
"LayerContainer")
|
||||
obj = doc.addObject("App::DocumentObjectGroupPython", "LayerContainer")
|
||||
obj.Label = translate("draft", "Layers")
|
||||
|
||||
LayerContainer(obj)
|
||||
@@ -77,12 +75,14 @@ def getLayerContainer():
|
||||
return get_layer_container()
|
||||
|
||||
|
||||
def make_layer(name=None,
|
||||
line_color=(0.0, 0.0, 0.0), # does not match default DefaultShapeLineColor
|
||||
shape_color=(0.8, 0.8, 0.8), # does not match default DefaultShapeColor
|
||||
line_width=2.0,
|
||||
draw_style="Solid",
|
||||
transparency=0):
|
||||
def make_layer(
|
||||
name=None,
|
||||
line_color=(0.0, 0.0, 0.0), # does not match default DefaultShapeLineColor
|
||||
shape_color=(0.8, 0.8, 0.8), # does not match default DefaultShapeColor
|
||||
line_width=2.0,
|
||||
draw_style="Solid",
|
||||
transparency=0,
|
||||
):
|
||||
"""Create a Layer object in the active document.
|
||||
|
||||
If a layer container named `'LayerContainer'` does not exist, it is created.
|
||||
@@ -140,14 +140,14 @@ def make_layer(name=None,
|
||||
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
if name is not None:
|
||||
try:
|
||||
utils.type_check([(name, str)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: it must be a string."))
|
||||
_err(translate("draft", "Wrong input: it must be a string."))
|
||||
return None
|
||||
else:
|
||||
name = translate("draft", "Layer")
|
||||
@@ -156,22 +156,22 @@ def make_layer(name=None,
|
||||
try:
|
||||
utils.type_check([(line_color, tuple)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a tuple of three floats 0.0 to 1.0."))
|
||||
_err(translate("draft", "Wrong input: must be a tuple of three floats 0.0 to 1.0."))
|
||||
return None
|
||||
|
||||
if not all(isinstance(color, (int, float)) for color in line_color):
|
||||
_err(translate("draft","Wrong input: must be a tuple of three floats 0.0 to 1.0."))
|
||||
_err(translate("draft", "Wrong input: must be a tuple of three floats 0.0 to 1.0."))
|
||||
return None
|
||||
|
||||
if shape_color is not None:
|
||||
try:
|
||||
utils.type_check([(shape_color, tuple)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a tuple of three floats 0.0 to 1.0."))
|
||||
_err(translate("draft", "Wrong input: must be a tuple of three floats 0.0 to 1.0."))
|
||||
return None
|
||||
|
||||
if not all(isinstance(color, (int, float)) for color in shape_color):
|
||||
_err(translate("draft","Wrong input: must be a tuple of three floats 0.0 to 1.0."))
|
||||
_err(translate("draft", "Wrong input: must be a tuple of three floats 0.0 to 1.0."))
|
||||
return None
|
||||
|
||||
if line_width is not None:
|
||||
@@ -179,18 +179,26 @@ def make_layer(name=None,
|
||||
utils.type_check([(line_width, (int, float))], name=_name)
|
||||
line_width = float(abs(line_width))
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number."))
|
||||
_err(translate("draft", "Wrong input: must be a number."))
|
||||
return None
|
||||
|
||||
if draw_style is not None:
|
||||
try:
|
||||
utils.type_check([(draw_style, str)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be 'Solid', 'Dashed', 'Dotted', or 'Dashdot'."))
|
||||
_err(
|
||||
translate(
|
||||
"draft", "Wrong input: must be 'Solid', 'Dashed', 'Dotted', or 'Dashdot'."
|
||||
)
|
||||
)
|
||||
return None
|
||||
|
||||
if draw_style not in ('Solid', 'Dashed', 'Dotted', 'Dashdot'):
|
||||
_err(translate("draft","Wrong input: must be 'Solid', 'Dashed', 'Dotted', or 'Dashdot'."))
|
||||
if draw_style not in ("Solid", "Dashed", "Dotted", "Dashdot"):
|
||||
_err(
|
||||
translate(
|
||||
"draft", "Wrong input: must be 'Solid', 'Dashed', 'Dotted', or 'Dashdot'."
|
||||
)
|
||||
)
|
||||
return None
|
||||
|
||||
if transparency is not None:
|
||||
@@ -198,7 +206,7 @@ def make_layer(name=None,
|
||||
utils.type_check([(transparency, (int, float))], name=_name)
|
||||
transparency = int(abs(transparency))
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number between 0 and 100."))
|
||||
_err(translate("draft", "Wrong input: must be a number between 0 and 100."))
|
||||
return None
|
||||
|
||||
obj = doc.addObject("App::FeaturePython", "Layer")
|
||||
@@ -225,4 +233,5 @@ def make_layer(name=None,
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -54,7 +54,7 @@ def make_line(first_param, last_param=None):
|
||||
if hasattr(first_param, "StartPoint") and hasattr(first_param, "EndPoint"):
|
||||
p2 = first_param.EndPoint
|
||||
p1 = first_param.StartPoint
|
||||
elif hasattr(p1,"Vertexes"):
|
||||
elif hasattr(p1, "Vertexes"):
|
||||
p2 = first_param.Vertexes[-1].Point
|
||||
p1 = first_param.Vertexes[0].Point
|
||||
else:
|
||||
@@ -62,7 +62,7 @@ def make_line(first_param, last_param=None):
|
||||
App.Console.PrintError(_err + "\n")
|
||||
return
|
||||
|
||||
obj = make_wire.make_wire([p1,p2])
|
||||
obj = make_wire.make_wire([p1, p2])
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
@@ -35,14 +35,16 @@ from draftutils.messages import _wrn, _err
|
||||
from draftutils.translate import translate
|
||||
|
||||
|
||||
def _make_ortho_array(base_object,
|
||||
v_x=App.Vector(10, 0, 0),
|
||||
v_y=App.Vector(0, 10, 0),
|
||||
v_z=App.Vector(0, 0, 10),
|
||||
n_x=2,
|
||||
n_y=2,
|
||||
n_z=1,
|
||||
use_link=True):
|
||||
def _make_ortho_array(
|
||||
base_object,
|
||||
v_x=App.Vector(10, 0, 0),
|
||||
v_y=App.Vector(0, 10, 0),
|
||||
v_z=App.Vector(0, 0, 10),
|
||||
n_x=2,
|
||||
n_y=2,
|
||||
n_z=1,
|
||||
use_link=True,
|
||||
):
|
||||
"""Create an orthogonal array from the given object.
|
||||
|
||||
This is a simple wrapper of the `draftmake.make_array.make_array`
|
||||
@@ -58,10 +60,9 @@ def _make_ortho_array(base_object,
|
||||
"""
|
||||
_name = "_make_ortho_array"
|
||||
|
||||
new_obj = make_array.make_array(base_object,
|
||||
arg1=v_x, arg2=v_y, arg3=v_z,
|
||||
arg4=n_x, arg5=n_y, arg6=n_z,
|
||||
use_link=use_link)
|
||||
new_obj = make_array.make_array(
|
||||
base_object, arg1=v_x, arg2=v_y, arg3=v_z, arg4=n_x, arg5=n_y, arg6=n_z, use_link=use_link
|
||||
)
|
||||
return new_obj
|
||||
|
||||
|
||||
@@ -69,27 +70,31 @@ def _are_vectors(v_x, v_y, v_z=None, name="Unknown"):
|
||||
"""Check that the vectors are numbers."""
|
||||
try:
|
||||
if v_z:
|
||||
utils.type_check([(v_x, (int, float, App.Vector)),
|
||||
(v_y, (int, float, App.Vector)),
|
||||
(v_z, (int, float, App.Vector))],
|
||||
name=name)
|
||||
utils.type_check(
|
||||
[
|
||||
(v_x, (int, float, App.Vector)),
|
||||
(v_y, (int, float, App.Vector)),
|
||||
(v_z, (int, float, App.Vector)),
|
||||
],
|
||||
name=name,
|
||||
)
|
||||
else:
|
||||
utils.type_check([(v_x, (int, float, App.Vector)),
|
||||
(v_y, (int, float, App.Vector))],
|
||||
name=name)
|
||||
utils.type_check(
|
||||
[(v_x, (int, float, App.Vector)), (v_y, (int, float, App.Vector))], name=name
|
||||
)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number or vector."))
|
||||
_err(translate("draft", "Wrong input: must be a number or vector."))
|
||||
return False, v_x, v_y, v_z
|
||||
|
||||
if not isinstance(v_x, App.Vector):
|
||||
v_x = App.Vector(v_x, 0, 0)
|
||||
_wrn(translate("draft","Input: single value expanded to vector."))
|
||||
_wrn(translate("draft", "Input: single value expanded to vector."))
|
||||
if not isinstance(v_y, App.Vector):
|
||||
v_y = App.Vector(0, v_y, 0)
|
||||
_wrn(translate("draft","Input: single value expanded to vector."))
|
||||
_wrn(translate("draft", "Input: single value expanded to vector."))
|
||||
if v_z and not isinstance(v_z, App.Vector):
|
||||
v_z = App.Vector(0, 0, v_z)
|
||||
_wrn(translate("draft","Input: single value expanded to vector."))
|
||||
_wrn(translate("draft", "Input: single value expanded to vector."))
|
||||
|
||||
return True, v_x, v_y, v_z
|
||||
|
||||
@@ -98,24 +103,21 @@ def _are_integers(n_x, n_y, n_z=None, name="Unknown"):
|
||||
"""Check that the numbers are integers, with minimum value of 1."""
|
||||
try:
|
||||
if n_z:
|
||||
utils.type_check([(n_x, int),
|
||||
(n_y, int),
|
||||
(n_z, int)], name=name)
|
||||
utils.type_check([(n_x, int), (n_y, int), (n_z, int)], name=name)
|
||||
else:
|
||||
utils.type_check([(n_x, int),
|
||||
(n_y, int)], name=name)
|
||||
utils.type_check([(n_x, int), (n_y, int)], name=name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be an integer number."))
|
||||
_err(translate("draft", "Wrong input: must be an integer number."))
|
||||
return False, n_x, n_y, n_z
|
||||
|
||||
if n_x < 1:
|
||||
_wrn(translate("draft","Input: number of elements must be at least 1. It is set to 1."))
|
||||
_wrn(translate("draft", "Input: number of elements must be at least 1. It is set to 1."))
|
||||
n_x = 1
|
||||
if n_y < 1:
|
||||
_wrn(translate("draft","Input: number of elements must be at least 1. It is set to 1."))
|
||||
_wrn(translate("draft", "Input: number of elements must be at least 1. It is set to 1."))
|
||||
n_y = 1
|
||||
if n_z and n_z < 1:
|
||||
_wrn(translate("draft","Input: number of elements must be at least 1. It is set to 1."))
|
||||
_wrn(translate("draft", "Input: number of elements must be at least 1. It is set to 1."))
|
||||
n_z = 1
|
||||
|
||||
return True, n_x, n_y, n_z
|
||||
@@ -125,14 +127,13 @@ def _are_numbers(d_x, d_y, d_z=None, name="Unknown"):
|
||||
"""Check that the numbers are numbers."""
|
||||
try:
|
||||
if d_z:
|
||||
utils.type_check([(d_x, (int, float)),
|
||||
(d_y, (int, float)),
|
||||
(d_z, (int, float))], name=name)
|
||||
utils.type_check(
|
||||
[(d_x, (int, float)), (d_y, (int, float)), (d_z, (int, float))], name=name
|
||||
)
|
||||
else:
|
||||
utils.type_check([(d_x, (int, float)),
|
||||
(d_y, (int, float))], name=name)
|
||||
utils.type_check([(d_x, (int, float)), (d_y, (int, float))], name=name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number."))
|
||||
_err(translate("draft", "Wrong input: must be a number."))
|
||||
return False, d_x, d_y, d_z
|
||||
|
||||
return True, d_x, d_y, d_z
|
||||
@@ -142,19 +143,21 @@ def _find_object_in_doc(base_object, doc=None):
|
||||
"""Check that a document is available and the object exists."""
|
||||
found, base_object = utils.find_object(base_object, doc=doc)
|
||||
if not found:
|
||||
_err(translate("draft","Wrong input: base_object not in document."))
|
||||
_err(translate("draft", "Wrong input: base_object not in document."))
|
||||
|
||||
return found, base_object
|
||||
|
||||
|
||||
def make_ortho_array(base_object,
|
||||
v_x=App.Vector(10, 0, 0),
|
||||
v_y=App.Vector(0, 10, 0),
|
||||
v_z=App.Vector(0, 0, 10),
|
||||
n_x=2,
|
||||
n_y=2,
|
||||
n_z=1,
|
||||
use_link=True):
|
||||
def make_ortho_array(
|
||||
base_object,
|
||||
v_x=App.Vector(10, 0, 0),
|
||||
v_y=App.Vector(0, 10, 0),
|
||||
v_z=App.Vector(0, 0, 10),
|
||||
n_x=2,
|
||||
n_y=2,
|
||||
n_z=1,
|
||||
use_link=True,
|
||||
):
|
||||
"""Create an orthogonal array from the given object.
|
||||
|
||||
Parameters
|
||||
@@ -248,8 +251,7 @@ def make_ortho_array(base_object,
|
||||
"""
|
||||
_name = "make_ortho_array"
|
||||
|
||||
found, base_object = _find_object_in_doc(base_object,
|
||||
doc=App.activeDocument())
|
||||
found, base_object = _find_object_in_doc(base_object, doc=App.activeDocument())
|
||||
if not found:
|
||||
return None
|
||||
|
||||
@@ -263,19 +265,15 @@ def make_ortho_array(base_object,
|
||||
|
||||
use_link = bool(use_link)
|
||||
|
||||
new_obj = _make_ortho_array(base_object,
|
||||
v_x=v_x, v_y=v_y, v_z=v_z,
|
||||
n_x=n_x, n_y=n_y, n_z=n_z,
|
||||
use_link=use_link)
|
||||
new_obj = _make_ortho_array(
|
||||
base_object, v_x=v_x, v_y=v_y, v_z=v_z, n_x=n_x, n_y=n_y, n_z=n_z, use_link=use_link
|
||||
)
|
||||
return new_obj
|
||||
|
||||
|
||||
def make_ortho_array2d(base_object,
|
||||
v_x=App.Vector(10, 0, 0),
|
||||
v_y=App.Vector(0, 10, 0),
|
||||
n_x=2,
|
||||
n_y=2,
|
||||
use_link=True):
|
||||
def make_ortho_array2d(
|
||||
base_object, v_x=App.Vector(10, 0, 0), v_y=App.Vector(0, 10, 0), n_x=2, n_y=2, use_link=True
|
||||
):
|
||||
"""Create a 2D orthogonal array from the given object.
|
||||
|
||||
This works the same as `make_ortho_array`.
|
||||
@@ -321,8 +319,7 @@ def make_ortho_array2d(base_object,
|
||||
"""
|
||||
_name = "make_ortho_array2d"
|
||||
|
||||
found, base_object = _find_object_in_doc(base_object,
|
||||
doc=App.activeDocument())
|
||||
found, base_object = _find_object_in_doc(base_object, doc=App.activeDocument())
|
||||
if not found:
|
||||
return None
|
||||
|
||||
@@ -336,21 +333,11 @@ def make_ortho_array2d(base_object,
|
||||
|
||||
use_link = bool(use_link)
|
||||
|
||||
new_obj = _make_ortho_array(base_object,
|
||||
v_x=v_x, v_y=v_y,
|
||||
n_x=n_x, n_y=n_y,
|
||||
use_link=use_link)
|
||||
new_obj = _make_ortho_array(base_object, v_x=v_x, v_y=v_y, n_x=n_x, n_y=n_y, use_link=use_link)
|
||||
return new_obj
|
||||
|
||||
|
||||
def make_rect_array(base_object,
|
||||
d_x=10,
|
||||
d_y=10,
|
||||
d_z=10,
|
||||
n_x=2,
|
||||
n_y=2,
|
||||
n_z=1,
|
||||
use_link=True):
|
||||
def make_rect_array(base_object, d_x=10, d_y=10, d_z=10, n_x=2, n_y=2, n_z=1, use_link=True):
|
||||
"""Create a rectangular array from the given object.
|
||||
|
||||
This function wraps around `make_ortho_array`
|
||||
@@ -393,8 +380,7 @@ def make_rect_array(base_object,
|
||||
"""
|
||||
_name = "make_rect_array"
|
||||
|
||||
found, base_object = _find_object_in_doc(base_object,
|
||||
doc=App.activeDocument())
|
||||
found, base_object = _find_object_in_doc(base_object, doc=App.activeDocument())
|
||||
if not found:
|
||||
return None
|
||||
|
||||
@@ -408,23 +394,20 @@ def make_rect_array(base_object,
|
||||
|
||||
use_link = bool(use_link)
|
||||
|
||||
new_obj = _make_ortho_array(base_object,
|
||||
v_x=App.Vector(d_x, 0, 0),
|
||||
v_y=App.Vector(0, d_y, 0),
|
||||
v_z=App.Vector(0, 0, d_z),
|
||||
n_x=n_x,
|
||||
n_y=n_y,
|
||||
n_z=n_z,
|
||||
use_link=use_link)
|
||||
new_obj = _make_ortho_array(
|
||||
base_object,
|
||||
v_x=App.Vector(d_x, 0, 0),
|
||||
v_y=App.Vector(0, d_y, 0),
|
||||
v_z=App.Vector(0, 0, d_z),
|
||||
n_x=n_x,
|
||||
n_y=n_y,
|
||||
n_z=n_z,
|
||||
use_link=use_link,
|
||||
)
|
||||
return new_obj
|
||||
|
||||
|
||||
def make_rect_array2d(base_object,
|
||||
d_x=10,
|
||||
d_y=10,
|
||||
n_x=2,
|
||||
n_y=2,
|
||||
use_link=True):
|
||||
def make_rect_array2d(base_object, d_x=10, d_y=10, n_x=2, n_y=2, use_link=True):
|
||||
"""Create a 2D rectangular array from the given object.
|
||||
|
||||
This function wraps around `make_ortho_array`,
|
||||
@@ -468,8 +451,7 @@ def make_rect_array2d(base_object,
|
||||
"""
|
||||
_name = "make_rect_array2d"
|
||||
|
||||
found, base_object = _find_object_in_doc(base_object,
|
||||
doc=App.activeDocument())
|
||||
found, base_object = _find_object_in_doc(base_object, doc=App.activeDocument())
|
||||
if not found:
|
||||
return None
|
||||
|
||||
@@ -483,12 +465,15 @@ def make_rect_array2d(base_object,
|
||||
|
||||
use_link = bool(use_link)
|
||||
|
||||
new_obj = _make_ortho_array(base_object,
|
||||
v_x=App.Vector(d_x, 0, 0),
|
||||
v_y=App.Vector(0, d_y, 0),
|
||||
n_x=n_x,
|
||||
n_y=n_y,
|
||||
use_link=use_link)
|
||||
new_obj = _make_ortho_array(
|
||||
base_object,
|
||||
v_x=App.Vector(d_x, 0, 0),
|
||||
v_y=App.Vector(0, d_y, 0),
|
||||
n_x=n_x,
|
||||
n_y=n_y,
|
||||
use_link=use_link,
|
||||
)
|
||||
return new_obj
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -50,14 +50,21 @@ if App.GuiUp:
|
||||
from draftviewproviders.view_draftlink import ViewProviderDraftLink
|
||||
|
||||
|
||||
def make_path_array(base_object, path_object, count=4,
|
||||
extra=App.Vector(0, 0, 0), subelements=None,
|
||||
align=False, align_mode="Original",
|
||||
tan_vector=App.Vector(1, 0, 0),
|
||||
force_vertical=False,
|
||||
vertical_vector=App.Vector(0, 0, 1),
|
||||
start_offset=0.0, end_offset=0.0,
|
||||
use_link=True):
|
||||
def make_path_array(
|
||||
base_object,
|
||||
path_object,
|
||||
count=4,
|
||||
extra=App.Vector(0, 0, 0),
|
||||
subelements=None,
|
||||
align=False,
|
||||
align_mode="Original",
|
||||
tan_vector=App.Vector(1, 0, 0),
|
||||
force_vertical=False,
|
||||
vertical_vector=App.Vector(0, 0, 1),
|
||||
start_offset=0.0,
|
||||
end_offset=0.0,
|
||||
use_link=True,
|
||||
):
|
||||
"""Make a Draft PathArray object.
|
||||
|
||||
Distribute copies of a `base_object` along `path_object`
|
||||
@@ -166,32 +173,30 @@ def make_path_array(base_object, path_object, count=4,
|
||||
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
found, base_object = utils.find_object(base_object, doc)
|
||||
if not found:
|
||||
_err(translate("draft","Wrong input: base_object not in document."))
|
||||
_err(translate("draft", "Wrong input: base_object not in document."))
|
||||
return None
|
||||
|
||||
found, path_object = utils.find_object(path_object, doc)
|
||||
if not found:
|
||||
_err(translate("draft","Wrong input: path_object not in document."))
|
||||
_err(translate("draft", "Wrong input: path_object not in document."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(count, (int, float))],
|
||||
name=_name)
|
||||
utils.type_check([(count, (int, float))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number."))
|
||||
_err(translate("draft", "Wrong input: must be a number."))
|
||||
return None
|
||||
count = int(count)
|
||||
|
||||
try:
|
||||
utils.type_check([(extra, App.Vector)],
|
||||
name=_name)
|
||||
utils.type_check([(extra, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
if subelements:
|
||||
@@ -200,10 +205,13 @@ def make_path_array(base_object, path_object, count=4,
|
||||
if isinstance(subelements, str):
|
||||
subelements = [subelements]
|
||||
|
||||
utils.type_check([(subelements, (list, tuple, str))],
|
||||
name=_name)
|
||||
utils.type_check([(subelements, (list, tuple, str))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a list or tuple of strings, or a single string."))
|
||||
_err(
|
||||
translate(
|
||||
"draft", "Wrong input: must be a list or tuple of strings, or a single string."
|
||||
)
|
||||
)
|
||||
return None
|
||||
|
||||
# The subelements list is used to build a special list
|
||||
@@ -228,43 +236,38 @@ def make_path_array(base_object, path_object, count=4,
|
||||
align = bool(align)
|
||||
|
||||
try:
|
||||
utils.type_check([(align_mode, str)],
|
||||
name=_name)
|
||||
utils.type_check([(align_mode, str)], name=_name)
|
||||
|
||||
if align_mode not in ("Original", "Frenet", "Tangent"):
|
||||
raise TypeError
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be 'Original', 'Frenet', or 'Tangent'."))
|
||||
_err(translate("draft", "Wrong input: must be 'Original', 'Frenet', or 'Tangent'."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(tan_vector, App.Vector)],
|
||||
name=_name)
|
||||
utils.type_check([(tan_vector, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
force_vertical = bool(force_vertical)
|
||||
try:
|
||||
utils.type_check([(vertical_vector, App.Vector)],
|
||||
name=_name)
|
||||
utils.type_check([(vertical_vector, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(start_offset, (int, float))],
|
||||
name=_name)
|
||||
utils.type_check([(start_offset, (int, float))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number."))
|
||||
_err(translate("draft", "Wrong input: must be a number."))
|
||||
return None
|
||||
start_offset = float(start_offset)
|
||||
|
||||
try:
|
||||
utils.type_check([(end_offset, (int, float))],
|
||||
name=_name)
|
||||
utils.type_check([(end_offset, (int, float))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number."))
|
||||
_err(translate("draft", "Wrong input: must be a number."))
|
||||
return None
|
||||
end_offset = float(end_offset)
|
||||
|
||||
@@ -273,8 +276,7 @@ def make_path_array(base_object, path_object, count=4,
|
||||
if use_link:
|
||||
# The PathArray class must be called in this special way
|
||||
# to make it a PathLinkArray
|
||||
new_obj = doc.addObject("Part::FeaturePython", "PathArray",
|
||||
PathArray(None), None, True)
|
||||
new_obj = doc.addObject("Part::FeaturePython", "PathArray", PathArray(None), None, True)
|
||||
else:
|
||||
new_obj = doc.addObject("Part::FeaturePython", "PathArray")
|
||||
PathArray(new_obj)
|
||||
@@ -305,44 +307,37 @@ def make_path_array(base_object, path_object, count=4,
|
||||
return new_obj
|
||||
|
||||
|
||||
def makePathArray(baseobject, pathobject, count,
|
||||
xlate=None, align=False,
|
||||
pathobjsubs=[],
|
||||
use_link=False):
|
||||
def makePathArray(
|
||||
baseobject, pathobject, count, xlate=None, align=False, pathobjsubs=[], use_link=False
|
||||
):
|
||||
"""Create PathArray. DEPRECATED. Use 'make_path_array'."""
|
||||
utils.use_instead('make_path_array')
|
||||
utils.use_instead("make_path_array")
|
||||
|
||||
return make_path_array(baseobject, pathobject, count,
|
||||
xlate, pathobjsubs,
|
||||
align,
|
||||
use_link)
|
||||
return make_path_array(baseobject, pathobject, count, xlate, pathobjsubs, align, use_link)
|
||||
|
||||
|
||||
def make_path_twisted_array(base_object, path_object,
|
||||
count=15, rot_factor=0.25,
|
||||
use_link=True):
|
||||
def make_path_twisted_array(base_object, path_object, count=15, rot_factor=0.25, use_link=True):
|
||||
"""Create a Path twisted array."""
|
||||
_name = "make_path_twisted_array"
|
||||
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
found, base_object = utils.find_object(base_object, doc)
|
||||
if not found:
|
||||
_err(translate("draft","Wrong input: base_object not in document."))
|
||||
_err(translate("draft", "Wrong input: base_object not in document."))
|
||||
return None
|
||||
|
||||
found, path_object = utils.find_object(path_object, doc)
|
||||
if not found:
|
||||
_err(translate("draft","Wrong input: path_object not in document."))
|
||||
_err(translate("draft", "Wrong input: path_object not in document."))
|
||||
return None
|
||||
try:
|
||||
utils.type_check([(count, (int, float))],
|
||||
name=_name)
|
||||
utils.type_check([(count, (int, float))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number."))
|
||||
_err(translate("draft", "Wrong input: must be a number."))
|
||||
return None
|
||||
count = int(count)
|
||||
|
||||
@@ -350,8 +345,9 @@ def make_path_twisted_array(base_object, path_object,
|
||||
if use_link:
|
||||
# The PathTwistedArray class must be called in this special way
|
||||
# to make it a PathTwistLinkArray
|
||||
new_obj = doc.addObject("Part::FeaturePython", "PathTwistedArray",
|
||||
PathTwistedArray(None), None, True)
|
||||
new_obj = doc.addObject(
|
||||
"Part::FeaturePython", "PathTwistedArray", PathTwistedArray(None), None, True
|
||||
)
|
||||
else:
|
||||
new_obj = doc.addObject("Part::FeaturePython", "PathTwistedArray")
|
||||
PathTwistedArray(new_obj)
|
||||
@@ -373,4 +369,5 @@ def make_path_twisted_array(base_object, path_object,
|
||||
|
||||
return new_obj
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -38,7 +38,7 @@ if App.GuiUp:
|
||||
|
||||
|
||||
def make_point(X=0, Y=0, Z=0, color=None, name="Point", point_size=5):
|
||||
""" make_point(x, y, z, [color(r, g, b), point_size]) or
|
||||
"""make_point(x, y, z, [color(r, g, b), point_size]) or
|
||||
make_point(Vector, color(r, g, b), point_size])
|
||||
|
||||
Creates a Draft Point in the current document.
|
||||
|
||||
@@ -99,9 +99,11 @@ def make_point_array(base_object, point_object, extra=None, use_link=True):
|
||||
_err(translate("draft", "Wrong input: point_object not in document."))
|
||||
return None
|
||||
|
||||
if not ((hasattr(point_object, "Shape") and hasattr(point_object.Shape, "Vertexes"))
|
||||
or hasattr(point_object, "Mesh")
|
||||
or hasattr(point_object, "Points")):
|
||||
if not (
|
||||
(hasattr(point_object, "Shape") and hasattr(point_object.Shape, "Vertexes"))
|
||||
or hasattr(point_object, "Mesh")
|
||||
or hasattr(point_object, "Points")
|
||||
):
|
||||
_err(translate("draft", "Wrong input: object has the wrong type."))
|
||||
return None
|
||||
|
||||
@@ -109,10 +111,7 @@ def make_point_array(base_object, point_object, extra=None, use_link=True):
|
||||
extra = App.Placement()
|
||||
|
||||
try:
|
||||
utils.type_check([(extra, (App.Placement,
|
||||
App.Vector,
|
||||
App.Rotation))],
|
||||
name=_name)
|
||||
utils.type_check([(extra, (App.Placement, App.Vector, App.Rotation))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft", "Wrong input: must be a placement, a vector, or a rotation."))
|
||||
return None
|
||||
@@ -126,8 +125,7 @@ def make_point_array(base_object, point_object, extra=None, use_link=True):
|
||||
if use_link:
|
||||
# The PointArray class must be called in this special way
|
||||
# to make it a LinkArray
|
||||
new_obj = doc.addObject("Part::FeaturePython", "PointArray",
|
||||
PointArray(None), None, True)
|
||||
new_obj = doc.addObject("Part::FeaturePython", "PointArray", PointArray(None), None, True)
|
||||
else:
|
||||
new_obj = doc.addObject("Part::FeaturePython", "PointArray")
|
||||
PointArray(new_obj)
|
||||
@@ -140,7 +138,9 @@ def make_point_array(base_object, point_object, extra=None, use_link=True):
|
||||
if use_link:
|
||||
ViewProviderDraftLink(new_obj.ViewObject)
|
||||
else:
|
||||
new_obj.Proxy.execute(new_obj) # Updates Count which is required for correct DiffuseColor.
|
||||
new_obj.Proxy.execute(
|
||||
new_obj
|
||||
) # Updates Count which is required for correct DiffuseColor.
|
||||
ViewProviderDraftArray(new_obj.ViewObject)
|
||||
gui_utils.format_object(new_obj, new_obj.Base)
|
||||
new_obj.ViewObject.Proxy.resetColors(new_obj.ViewObject)
|
||||
@@ -152,8 +152,9 @@ def make_point_array(base_object, point_object, extra=None, use_link=True):
|
||||
|
||||
def makePointArray(base, ptlst):
|
||||
"""Create PointArray. DEPRECATED. Use 'make_point_array'."""
|
||||
utils.use_instead('make_point_array')
|
||||
utils.use_instead("make_point_array")
|
||||
|
||||
return make_point_array(base, ptlst)
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -35,9 +35,7 @@ from draftutils.messages import _err
|
||||
from draftutils.translate import translate
|
||||
|
||||
|
||||
def make_polar_array(base_object,
|
||||
number=5, angle=360, center=App.Vector(0, 0, 0),
|
||||
use_link=True):
|
||||
def make_polar_array(base_object, number=5, angle=360, center=App.Vector(0, 0, 0), use_link=True):
|
||||
"""Create a polar array from the given object.
|
||||
|
||||
Parameters
|
||||
@@ -94,31 +92,32 @@ def make_polar_array(base_object,
|
||||
|
||||
found, base_object = utils.find_object(base_object, doc=App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","Wrong input: base_object not in document."))
|
||||
_err(translate("draft", "Wrong input: base_object not in document."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(number, int)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be an integer number."))
|
||||
_err(translate("draft", "Wrong input: must be an integer number."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(angle, (int, float))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a number."))
|
||||
_err(translate("draft", "Wrong input: must be a number."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(center, App.Vector)], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a vector."))
|
||||
_err(translate("draft", "Wrong input: must be a vector."))
|
||||
return None
|
||||
|
||||
use_link = bool(use_link)
|
||||
new_obj = make_array.make_array(base_object,
|
||||
arg1=center, arg2=angle, arg3=number,
|
||||
use_link=use_link)
|
||||
new_obj = make_array.make_array(
|
||||
base_object, arg1=center, arg2=angle, arg3=number, use_link=use_link
|
||||
)
|
||||
return new_obj
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -63,8 +63,9 @@ def make_polygon(nfaces, radius=1, inscribed=True, placement=None, face=None, su
|
||||
if not App.ActiveDocument:
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
if nfaces < 3: return None
|
||||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython","Polygon")
|
||||
if nfaces < 3:
|
||||
return None
|
||||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython", "Polygon")
|
||||
Polygon(obj)
|
||||
obj.FacesNumber = nfaces
|
||||
obj.Radius = radius
|
||||
@@ -75,7 +76,8 @@ def make_polygon(nfaces, radius=1, inscribed=True, placement=None, face=None, su
|
||||
else:
|
||||
obj.DrawMode = "circumscribed"
|
||||
obj.AttachmentSupport = support
|
||||
if placement: obj.Placement = placement
|
||||
if placement:
|
||||
obj.Placement = placement
|
||||
if App.GuiUp:
|
||||
ViewProviderDraft(obj.ViewObject)
|
||||
gui_utils.format_object(obj)
|
||||
|
||||
@@ -65,7 +65,7 @@ def make_rectangle(length, height=0, placement=None, face=None, support=None):
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
|
||||
if isinstance(length,(list,tuple)) and (len(length) == 4):
|
||||
if isinstance(length, (list, tuple)) and (len(length) == 4):
|
||||
verts = length
|
||||
xv = verts[1].sub(verts[0])
|
||||
yv = verts[3].sub(verts[0])
|
||||
@@ -75,9 +75,9 @@ def make_rectangle(length, height=0, placement=None, face=None, support=None):
|
||||
return make_rectangle(xv.Length, yv.Length, rp, face, support)
|
||||
|
||||
if placement:
|
||||
utils.type_check([(placement,App.Placement)], "make_rectangle")
|
||||
utils.type_check([(placement, App.Placement)], "make_rectangle")
|
||||
|
||||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython","Rectangle")
|
||||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython", "Rectangle")
|
||||
Rectangle(obj)
|
||||
|
||||
obj.Length = length
|
||||
@@ -87,7 +87,8 @@ def make_rectangle(length, height=0, placement=None, face=None, support=None):
|
||||
if face is not None:
|
||||
obj.MakeFace = face
|
||||
|
||||
if placement: obj.Placement = placement
|
||||
if placement:
|
||||
obj.Placement = placement
|
||||
|
||||
if App.GuiUp:
|
||||
ViewProviderRectangle(obj.ViewObject)
|
||||
|
||||
@@ -36,7 +36,7 @@ if App.GuiUp:
|
||||
from draftviewproviders.view_base import ViewProviderDraftAlt
|
||||
|
||||
|
||||
def make_shape2dview(baseobj,projectionVector=None,facenumbers=[]):
|
||||
def make_shape2dview(baseobj, projectionVector=None, facenumbers=[]):
|
||||
"""make_shape2dview(object, [projectionVector], [facenumbers])
|
||||
|
||||
Add a 2D shape to the document, which is a 2D projection of the given object.
|
||||
@@ -55,7 +55,7 @@ def make_shape2dview(baseobj,projectionVector=None,facenumbers=[]):
|
||||
if not App.ActiveDocument:
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython","Shape2DView")
|
||||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython", "Shape2DView")
|
||||
Shape2DView(obj)
|
||||
if App.GuiUp:
|
||||
ViewProviderDraftAlt(obj.ViewObject)
|
||||
|
||||
@@ -51,8 +51,7 @@ def make_shapestring(String, FontFile, Size=100, Tracking=0):
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
|
||||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython",
|
||||
"ShapeString")
|
||||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython", "ShapeString")
|
||||
ShapeString(obj)
|
||||
obj.String = String
|
||||
obj.FontFile = FontFile
|
||||
@@ -63,7 +62,8 @@ def make_shapestring(String, FontFile, Size=100, Tracking=0):
|
||||
ViewProviderShapeString(obj.ViewObject)
|
||||
gui_utils.format_object(obj)
|
||||
obrep = obj.ViewObject
|
||||
if "PointSize" in obrep.PropertiesList: obrep.PointSize = 1 # hide the segment end points
|
||||
if "PointSize" in obrep.PropertiesList:
|
||||
obrep.PointSize = 1 # hide the segment end points
|
||||
gui_utils.select(obj)
|
||||
obj.recompute()
|
||||
return obj
|
||||
|
||||
@@ -38,8 +38,15 @@ from draftutils import utils
|
||||
from draftutils.translate import translate
|
||||
|
||||
|
||||
def make_sketch(objects_list, autoconstraints=False, addTo=None,
|
||||
delete=False, name="Sketch", radiusPrecision=-1, tol=1e-3):
|
||||
def make_sketch(
|
||||
objects_list,
|
||||
autoconstraints=False,
|
||||
addTo=None,
|
||||
delete=False,
|
||||
name="Sketch",
|
||||
radiusPrecision=-1,
|
||||
tol=1e-3,
|
||||
):
|
||||
"""make_sketch(objects_list, [autoconstraints], [addTo], [delete],
|
||||
[name], [radiusPrecision], [tol])
|
||||
|
||||
@@ -82,22 +89,20 @@ def make_sketch(objects_list, autoconstraints=False, addTo=None,
|
||||
shape_norm_yes = list()
|
||||
shape_norm_no = list()
|
||||
|
||||
if not isinstance(objects_list,(list,tuple)):
|
||||
if not isinstance(objects_list, (list, tuple)):
|
||||
objects_list = [objects_list]
|
||||
|
||||
for obj in objects_list:
|
||||
if isinstance(obj,Part.Shape):
|
||||
if isinstance(obj, Part.Shape):
|
||||
shape = obj
|
||||
elif not hasattr(obj, "Shape"):
|
||||
App.Console.PrintError(translate("draft",
|
||||
"No shape found") + "\n")
|
||||
App.Console.PrintError(translate("draft", "No shape found") + "\n")
|
||||
return None
|
||||
else:
|
||||
shape = obj.Shape
|
||||
|
||||
if not DraftGeomUtils.is_planar(shape, tol):
|
||||
App.Console.PrintError(translate("draft",
|
||||
"All shapes must be planar") + "\n")
|
||||
App.Console.PrintError(translate("draft", "All shapes must be planar") + "\n")
|
||||
return None
|
||||
|
||||
if DraftGeomUtils.get_normal(shape, tol):
|
||||
@@ -105,15 +110,13 @@ def make_sketch(objects_list, autoconstraints=False, addTo=None,
|
||||
else:
|
||||
shape_norm_no.append(shape)
|
||||
|
||||
|
||||
shapes_list = shape_norm_yes + shape_norm_no
|
||||
|
||||
# test if all shapes are coplanar
|
||||
if len(shape_norm_yes) >= 1:
|
||||
for shape in shapes_list[1:]:
|
||||
if not DraftGeomUtils.are_coplanar(shapes_list[0], shape, tol):
|
||||
App.Console.PrintError(translate("draft",
|
||||
"All shapes must be coplanar") + "\n")
|
||||
App.Console.PrintError(translate("draft", "All shapes must be coplanar") + "\n")
|
||||
return None
|
||||
# define sketch normal
|
||||
normal = DraftGeomUtils.get_normal(shapes_list[0], tol)
|
||||
@@ -129,8 +132,7 @@ def make_sketch(objects_list, autoconstraints=False, addTo=None,
|
||||
normal = App.Vector(0, 0, 1)
|
||||
else:
|
||||
if not DraftGeomUtils.is_planar(poly, tol):
|
||||
App.Console.PrintError(translate("draft",
|
||||
"All shapes must be coplanar") + "\n")
|
||||
App.Console.PrintError(translate("draft", "All shapes must be coplanar") + "\n")
|
||||
return None
|
||||
normal = DraftGeomUtils.get_shape_normal(poly)
|
||||
else:
|
||||
@@ -148,24 +150,22 @@ def make_sketch(objects_list, autoconstraints=False, addTo=None,
|
||||
|
||||
def addRadiusConstraint(edge):
|
||||
try:
|
||||
if radiusPrecision<0:
|
||||
if radiusPrecision < 0:
|
||||
return
|
||||
if radiusPrecision==0:
|
||||
constraints.append(Constraint("Radius",
|
||||
nobj.GeometryCount-1, edge.Curve.Radius))
|
||||
if radiusPrecision == 0:
|
||||
constraints.append(Constraint("Radius", nobj.GeometryCount - 1, edge.Curve.Radius))
|
||||
return
|
||||
r = round(edge.Curve.Radius,radiusPrecision)
|
||||
constraints.append(Constraint("Equal",
|
||||
radiuses[r], nobj.GeometryCount-1))
|
||||
r = round(edge.Curve.Radius, radiusPrecision)
|
||||
constraints.append(Constraint("Equal", radiuses[r], nobj.GeometryCount - 1))
|
||||
except KeyError:
|
||||
radiuses[r] = nobj.GeometryCount-1
|
||||
constraints.append(Constraint("Radius", nobj.GeometryCount-1, r))
|
||||
radiuses[r] = nobj.GeometryCount - 1
|
||||
constraints.append(Constraint("Radius", nobj.GeometryCount - 1, r))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def convertBezier(edge):
|
||||
if DraftGeomUtils.geomType(edge) == "BezierCurve":
|
||||
return(edge.Curve.toBSpline(edge.FirstParameter,edge.LastParameter).toShape())
|
||||
return edge.Curve.toBSpline(edge.FirstParameter, edge.LastParameter).toShape()
|
||||
else:
|
||||
return edge
|
||||
|
||||
@@ -181,7 +181,9 @@ def make_sketch(objects_list, autoconstraints=False, addTo=None,
|
||||
|
||||
point = shapes_list[0].Vertexes[0].Point
|
||||
base = App.Vector(normal)
|
||||
base.Length = point.dot(base.normalize()) # See https://forum.freecad.org/viewtopic.php?f=22&t=69304#p601149
|
||||
base.Length = point.dot(
|
||||
base.normalize()
|
||||
) # See https://forum.freecad.org/viewtopic.php?f=22&t=69304#p601149
|
||||
|
||||
nobj.Placement = App.Placement(base, rotation)
|
||||
|
||||
@@ -204,18 +206,23 @@ def make_sketch(objects_list, autoconstraints=False, addTo=None,
|
||||
shape = obj if tp == "Shape" else obj.Shape
|
||||
for e in shape.Edges:
|
||||
newedge = convertBezier(e)
|
||||
nobj.addGeometry(DraftGeomUtils.orientEdge(
|
||||
newedge, normal, make_arc=True))
|
||||
nobj.addGeometry(DraftGeomUtils.orientEdge(newedge, normal, make_arc=True))
|
||||
addRadiusConstraint(newedge)
|
||||
ok = True
|
||||
|
||||
if ok and delete:
|
||||
|
||||
def delObj(obj):
|
||||
if obj.InList:
|
||||
App.Console.PrintWarning(translate("draft",
|
||||
"Cannot delete object {} with dependency".format(obj.Label)) + "\n")
|
||||
App.Console.PrintWarning(
|
||||
translate(
|
||||
"draft", "Cannot delete object {} with dependency".format(obj.Label)
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
else:
|
||||
obj.Document.removeObject(obj.Name)
|
||||
|
||||
try:
|
||||
if delete == "all":
|
||||
objs = [obj]
|
||||
@@ -226,8 +233,10 @@ def make_sketch(objects_list, autoconstraints=False, addTo=None,
|
||||
else:
|
||||
delObj(obj)
|
||||
except Exception as ex:
|
||||
App.Console.PrintWarning(translate("draft",
|
||||
"Failed to delete object {}: {}".format(obj.Label, ex)) + "\n")
|
||||
App.Console.PrintWarning(
|
||||
translate("draft", "Failed to delete object {}: {}".format(obj.Label, ex))
|
||||
+ "\n"
|
||||
)
|
||||
|
||||
nobj.addConstraint(constraints)
|
||||
if autoconstraints:
|
||||
|
||||
@@ -89,28 +89,25 @@ def make_text(string, placement=None, screen=False, height=None, line_spacing=1)
|
||||
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
try:
|
||||
utils.type_check([(string, (str, list))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a list of strings or a single string."))
|
||||
_err(translate("draft", "Wrong input: must be a list of strings or a single string."))
|
||||
return None
|
||||
|
||||
if (type(string) is list
|
||||
and not all(isinstance(element, str) for element in string)):
|
||||
_err(translate("draft","Wrong input: must be a list of strings or a single string."))
|
||||
if type(string) is list and not all(isinstance(element, str) for element in string):
|
||||
_err(translate("draft", "Wrong input: must be a list of strings or a single string."))
|
||||
return None
|
||||
|
||||
if not placement:
|
||||
placement = App.Placement()
|
||||
try:
|
||||
utils.type_check([(placement, (App.Placement,
|
||||
App.Vector,
|
||||
App.Rotation))], name=_name)
|
||||
utils.type_check([(placement, (App.Placement, App.Vector, App.Rotation))], name=_name)
|
||||
except TypeError:
|
||||
_err(translate("draft","Wrong input: must be a placement, a vector, or a rotation."))
|
||||
_err(translate("draft", "Wrong input: must be a placement, a vector, or a rotation."))
|
||||
return None
|
||||
|
||||
# Convert the vector or rotation to a full placement
|
||||
@@ -175,7 +172,7 @@ def convert_draft_texts(textslist=None):
|
||||
|
||||
found, doc = utils.find_doc(App.activeDocument())
|
||||
if not found:
|
||||
_err(translate("draft","No active document. Aborting."))
|
||||
_err(translate("draft", "No active document. Aborting."))
|
||||
return None
|
||||
|
||||
if not textslist:
|
||||
@@ -215,4 +212,5 @@ def convertDraftTexts(textslist=[]):
|
||||
utils.use_instead("convert_draft_texts")
|
||||
return convert_draft_texts(textslist)
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -72,12 +72,12 @@ def make_wire(pointslist, closed=False, placement=None, face=None, support=None,
|
||||
|
||||
import Part
|
||||
|
||||
if isinstance(pointslist, (list,tuple)):
|
||||
if isinstance(pointslist, (list, tuple)):
|
||||
for pnt in pointslist:
|
||||
if not isinstance(pnt, App.Vector):
|
||||
App.Console.PrintError(
|
||||
"Items must be Base.Vector objects, not {}\n".format(
|
||||
type(pnt)))
|
||||
"Items must be Base.Vector objects, not {}\n".format(type(pnt))
|
||||
)
|
||||
return None
|
||||
|
||||
elif isinstance(pointslist, Part.Wire):
|
||||
@@ -89,11 +89,9 @@ def make_wire(pointslist, closed=False, placement=None, face=None, support=None,
|
||||
pointslist = [v.Point for v in pointslist.OrderedVertexes]
|
||||
|
||||
else:
|
||||
App.Console.PrintError("Can't make Draft Wire from {}\n".format(
|
||||
type(pointslist)))
|
||||
App.Console.PrintError("Can't make Draft Wire from {}\n".format(type(pointslist)))
|
||||
return None
|
||||
|
||||
|
||||
if len(pointslist) == 0:
|
||||
App.Console.PrintWarning("Draft Wire created with empty point list\n")
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ def make_workingplaneproxy(placement):
|
||||
specify the p.
|
||||
"""
|
||||
if App.ActiveDocument:
|
||||
obj = App.ActiveDocument.addObject("App::FeaturePython","WPProxy")
|
||||
obj = App.ActiveDocument.addObject("App::FeaturePython", "WPProxy")
|
||||
WorkingPlaneProxy(obj)
|
||||
if App.GuiUp:
|
||||
ViewProviderWorkingPlaneProxy(obj.ViewObject)
|
||||
|
||||
Reference in New Issue
Block a user