Merge pull request #5102 from Roy-043/Draft-Update-draft_test_objects.py
Draft: Update draft_test_objects.py
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# ***************************************************************************
|
||||
# * (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
|
||||
# * Copyright (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
|
||||
# * Copyright (c) 2021 FreeCAD Developers *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
@@ -40,7 +41,6 @@ Or load it as a module and use the defined function.
|
||||
## \addtogroup drafttests
|
||||
# @{
|
||||
import datetime
|
||||
import os
|
||||
|
||||
import FreeCAD as App
|
||||
import Part
|
||||
@@ -66,17 +66,7 @@ def _set_text(text_list, position):
|
||||
|
||||
|
||||
def _create_frame(doc=None):
|
||||
"""Draw a frame with information on the version of the software.
|
||||
|
||||
It includes the date created, the version, the release type,
|
||||
and the branch.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
doc: App::Document, optional
|
||||
It defaults to `None`, which then defaults to the current
|
||||
active document, or creates a new document.
|
||||
"""
|
||||
"""Draw a frame with information on the version of the software."""
|
||||
if not doc:
|
||||
doc = App.activeDocument()
|
||||
if not doc:
|
||||
@@ -101,10 +91,10 @@ def _create_frame(doc=None):
|
||||
record.ViewObject.FontSize = 400
|
||||
record.ViewObject.TextColor = (0.0, 0.0, 0.0)
|
||||
|
||||
p1 = Vector(-1000, -3500, 0)
|
||||
p2 = Vector(20000, -3500, 0)
|
||||
p3 = Vector(20000, 8500, 0)
|
||||
p4 = Vector(-1000, 8500, 0)
|
||||
p1 = Vector(-1000, -4000, 0)
|
||||
p2 = Vector(17000, -4000, 0)
|
||||
p3 = Vector(17000, 8000, 0)
|
||||
p4 = Vector(-1000, 8000, 0)
|
||||
|
||||
poly = Part.makePolygon([p1, p2, p3, p4, p1])
|
||||
frame = doc.addObject("Part::Feature", "Frame")
|
||||
@@ -112,199 +102,135 @@ def _create_frame(doc=None):
|
||||
|
||||
|
||||
def _create_objects(doc=None,
|
||||
font_file="/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"):
|
||||
"""Create the objects of the test file.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
doc: App::Document, optional
|
||||
It defaults to `None`, which then defaults to the current
|
||||
active document, or creates a new document.
|
||||
"""
|
||||
font_file=None,
|
||||
hatch_file=None,
|
||||
hatch_name=None):
|
||||
"""Create the objects of the test file."""
|
||||
if not doc:
|
||||
doc = App.activeDocument()
|
||||
if not doc:
|
||||
doc = App.newDocument()
|
||||
|
||||
# Line, wire, and fillet
|
||||
# Drafting ##############################################################
|
||||
|
||||
# Line
|
||||
_msg(16 * "-")
|
||||
_msg("Line")
|
||||
Draft.make_line(Vector(0, 0, 0), Vector(500, 500, 0))
|
||||
t_xpos = -50
|
||||
t_ypos = -200
|
||||
_set_text(["Line"], Vector(t_xpos, t_ypos, 0))
|
||||
_set_text(["Line"], Vector(0, -200, 0))
|
||||
|
||||
# Wire
|
||||
_msg(16 * "-")
|
||||
_msg("Wire")
|
||||
Draft.make_wire([Vector(500, 0, 0),
|
||||
Vector(1000, 500, 0),
|
||||
Vector(1000, 1000, 0)])
|
||||
t_xpos += 500
|
||||
_set_text(["Wire"], Vector(t_xpos, t_ypos, 0))
|
||||
Draft.make_wire([Vector(1000, 0, 0),
|
||||
Vector(1500, 250, 0),
|
||||
Vector(1500, 500, 0)])
|
||||
_set_text(["Wire"], Vector(1000, -200, 0))
|
||||
|
||||
# Fillet
|
||||
_msg(16 * "-")
|
||||
_msg("Fillet")
|
||||
line_h_1 = Draft.make_line(Vector(1500, 0, 0), Vector(1500, 500, 0))
|
||||
line_h_2 = Draft.make_line(Vector(1500, 500, 0), Vector(2000, 500, 0))
|
||||
line_1 = Draft.make_line(Vector(2000, 0, 0), Vector(2000, 500, 0))
|
||||
line_2 = Draft.make_line(Vector(2000, 500, 0), Vector(2500, 500, 0))
|
||||
if App.GuiUp:
|
||||
line_h_1.ViewObject.DrawStyle = "Dotted"
|
||||
line_h_2.ViewObject.DrawStyle = "Dotted"
|
||||
line_1.ViewObject.DrawStyle = "Dotted"
|
||||
line_2.ViewObject.DrawStyle = "Dotted"
|
||||
doc.recompute()
|
||||
Draft.make_fillet([line_1, line_2], 400)
|
||||
_set_text(["Fillet"], Vector(2000, -200, 0))
|
||||
|
||||
Draft.make_fillet([line_h_1, line_h_2], 400)
|
||||
t_xpos += 900
|
||||
_set_text(["Fillet"], Vector(t_xpos, t_ypos, 0))
|
||||
|
||||
# Circle, arc, arc by 3 points
|
||||
_msg(16 * "-")
|
||||
_msg("Circle")
|
||||
circle = Draft.make_circle(350)
|
||||
circle.Placement.Base = Vector(2500, 500, 0)
|
||||
t_xpos += 1050
|
||||
_set_text(["Circle"], Vector(t_xpos, t_ypos, 0))
|
||||
|
||||
# Circular arc
|
||||
_msg(16 * "-")
|
||||
_msg("Circular arc")
|
||||
arc = Draft.make_circle(350, startangle=0, endangle=100)
|
||||
arc.Placement.Base = Vector(3200, 500, 0)
|
||||
t_xpos += 800
|
||||
_set_text(["Circular arc"], Vector(t_xpos, t_ypos, 0))
|
||||
arc = Draft.make_circle(250, startangle=90, endangle=270)
|
||||
arc.Placement.Base = Vector(3250, 250, 0)
|
||||
_set_text(["Circular arc"], Vector(3000, -200, 0))
|
||||
|
||||
# Circular arc 3 points
|
||||
_msg(16 * "-")
|
||||
_msg("Circular arc 3 points")
|
||||
Draft.make_arc_3points([Vector(4600, 0, 0),
|
||||
Vector(4600, 800, 0),
|
||||
Vector(4000, 1000, 0)])
|
||||
t_xpos += 600
|
||||
_set_text(["Circular arc 3 points"], Vector(t_xpos, t_ypos, 0))
|
||||
Draft.make_arc_3points([Vector(4250, 0, 0),
|
||||
Vector(4000, 250, 0),
|
||||
Vector(4250, 500, 0)])
|
||||
_set_text(["Circular arc 3 points"], Vector(4000, -200, 0))
|
||||
|
||||
# Ellipse, polygon, rectangle
|
||||
# Circle
|
||||
_msg(16 * "-")
|
||||
_msg("Circle")
|
||||
circle = Draft.make_circle(250)
|
||||
circle.Placement.Base = Vector(5250, 250, 0)
|
||||
_set_text(["Circle"], Vector(5000, -200, 0))
|
||||
|
||||
# Ellipse
|
||||
_msg(16 * "-")
|
||||
_msg("Ellipse")
|
||||
ellipse = Draft.make_ellipse(500, 300)
|
||||
ellipse.Placement.Base = Vector(5500, 250, 0)
|
||||
t_xpos += 1600
|
||||
_set_text(["Ellipse"], Vector(t_xpos, t_ypos, 0))
|
||||
ellipse = Draft.make_ellipse(250, 150)
|
||||
ellipse.Placement.Base = Vector(6250, 150, 0)
|
||||
_set_text(["Ellipse"], Vector(6000, -200, 0))
|
||||
|
||||
# Rectangle
|
||||
_msg(16 * "-")
|
||||
_msg("Rectangle")
|
||||
rectangle = Draft.make_rectangle(500, 300, 0)
|
||||
rectangle.Placement.Base = Vector(7000, 0, 0)
|
||||
_set_text(["Rectangle"], Vector(7000, -200, 0))
|
||||
|
||||
# Polygon
|
||||
_msg(16 * "-")
|
||||
_msg("Polygon")
|
||||
polygon = Draft.make_polygon(5, 250)
|
||||
polygon.Placement.Base = Vector(6500, 500, 0)
|
||||
t_xpos += 950
|
||||
_set_text(["Polygon"], Vector(t_xpos, t_ypos, 0))
|
||||
|
||||
_msg(16 * "-")
|
||||
_msg("Rectangle")
|
||||
rectangle = Draft.make_rectangle(500, 1000, 0)
|
||||
rectangle.Placement.Base = Vector(7000, 0, 0)
|
||||
t_xpos += 650
|
||||
_set_text(["Rectangle"], Vector(t_xpos, t_ypos, 0))
|
||||
|
||||
# Text
|
||||
_msg(16 * "-")
|
||||
_msg("Text")
|
||||
text = Draft.make_text(["Testing", "text"], Vector(7700, 500, 0))
|
||||
if App.GuiUp:
|
||||
text.ViewObject.FontSize = 100
|
||||
t_xpos += 700
|
||||
_set_text(["Text"], Vector(t_xpos, t_ypos, 0))
|
||||
|
||||
# Linear dimension
|
||||
_msg(16 * "-")
|
||||
_msg("Linear dimension")
|
||||
line = Draft.make_wire([Vector(8700, 200, 0),
|
||||
Vector(8700, 1200, 0)])
|
||||
|
||||
dimension = Draft.make_linear_dimension(Vector(8600, 200, 0),
|
||||
Vector(8600, 1000, 0),
|
||||
Vector(8400, 750, 0))
|
||||
if App.GuiUp:
|
||||
dimension.ViewObject.ArrowSize = 15
|
||||
dimension.ViewObject.ExtLines = 1000
|
||||
dimension.ViewObject.ExtOvershoot = 100
|
||||
dimension.ViewObject.DimOvershoot = 50
|
||||
dimension.ViewObject.FontSize = 100
|
||||
dimension.ViewObject.ShowUnit = False
|
||||
doc.recompute()
|
||||
|
||||
dim_obj = Draft.make_linear_dimension_obj(line, 1, 2,
|
||||
Vector(9000, 750, 0))
|
||||
if App.GuiUp:
|
||||
dim_obj.ViewObject.ArrowSize = 15
|
||||
dim_obj.ViewObject.ArrowType = "Arrow"
|
||||
dim_obj.ViewObject.ExtLines = 100
|
||||
dim_obj.ViewObject.ExtOvershoot = 100
|
||||
dim_obj.ViewObject.DimOvershoot = 50
|
||||
dim_obj.ViewObject.FontSize = 100
|
||||
dim_obj.ViewObject.ShowUnit = False
|
||||
|
||||
t_xpos += 680
|
||||
_set_text(["Dimension"], Vector(t_xpos, t_ypos, 0))
|
||||
|
||||
# Radius and diameter dimension
|
||||
_msg(16 * "-")
|
||||
_msg("Radius and diameter dimension")
|
||||
arc_h = Draft.make_circle(500, startangle=0, endangle=90)
|
||||
arc_h.Placement.Base = Vector(9500, 0, 0)
|
||||
doc.recompute()
|
||||
|
||||
dimension_r = Draft.make_radial_dimension_obj(arc_h, 1,
|
||||
"radius",
|
||||
Vector(9750, 200, 0))
|
||||
if App.GuiUp:
|
||||
dimension_r.ViewObject.ArrowSize = 15
|
||||
dimension_r.ViewObject.FontSize = 100
|
||||
dimension_r.ViewObject.ShowUnit = False
|
||||
|
||||
arc_h2 = Draft.make_circle(450, startangle=-120, endangle=80)
|
||||
arc_h2.Placement.Base = Vector(10000, 1000, 0)
|
||||
doc.recompute()
|
||||
|
||||
dimension_d = Draft.make_radial_dimension_obj(arc_h2, 1,
|
||||
"diameter",
|
||||
Vector(10750, 900, 0))
|
||||
if App.GuiUp:
|
||||
dimension_d.ViewObject.ArrowSize = 15
|
||||
dimension_d.ViewObject.FontSize = 100
|
||||
dimension_d.ViewObject.ShowUnit = False
|
||||
t_xpos += 950
|
||||
_set_text(["Radius dimension",
|
||||
"Diameter dimension"], Vector(t_xpos, t_ypos, 0))
|
||||
|
||||
# Angular dimension
|
||||
_msg(16 * "-")
|
||||
_msg("Angular dimension")
|
||||
Draft.make_line(Vector(10500, 300, 0), Vector(11500, 1000, 0))
|
||||
Draft.make_line(Vector(10500, 300, 0), Vector(11500, 0, 0))
|
||||
angle1 = -20
|
||||
angle2 = 40
|
||||
dimension_a = Draft.make_angular_dimension(Vector(10500, 300, 0),
|
||||
[angle1, angle2],
|
||||
Vector(11500, 300, 0))
|
||||
if App.GuiUp:
|
||||
dimension_a.ViewObject.ArrowSize = 15
|
||||
dimension_a.ViewObject.FontSize = 100
|
||||
t_xpos += 1700
|
||||
_set_text(["Angle dimension"], Vector(t_xpos, t_ypos, 0))
|
||||
polygon.Placement.Base = Vector(8250, 250, 0)
|
||||
_set_text(["Polygon"], Vector(8000, -200, 0))
|
||||
|
||||
# BSpline
|
||||
_msg(16 * "-")
|
||||
_msg("BSpline")
|
||||
Draft.make_bspline([Vector(12500, 0, 0),
|
||||
Vector(12500, 500, 0),
|
||||
Vector(13000, 500, 0),
|
||||
Vector(13000, 1000, 0)])
|
||||
t_xpos += 1500
|
||||
_set_text(["BSpline"], Vector(t_xpos, t_ypos, 0))
|
||||
Draft.make_bspline([Vector(9000, 0, 0),
|
||||
Vector(9100, 200, 0),
|
||||
Vector(9400, 300, 0),
|
||||
Vector(9500, 500, 0)])
|
||||
_set_text(["BSpline"], Vector(9000, -200, 0))
|
||||
|
||||
# Cubic bezier
|
||||
_msg(16 * "-")
|
||||
_msg("Cubic bezier")
|
||||
Draft.make_bezcurve([Vector(10000, 0, 0),
|
||||
Vector(10000, 500, 0),
|
||||
Vector(10500, 0, 0),
|
||||
Vector(10500, 500, 0)], degree=3)
|
||||
_set_text(["Cubic bezier"], Vector(10000, -200, 0))
|
||||
|
||||
# N-degree bezier
|
||||
_msg(16 * "-")
|
||||
_msg("N-degree bezier")
|
||||
Draft.make_bezcurve([Vector (11000, 0, 0),
|
||||
Vector (11100, 400, 0),
|
||||
Vector (11250, 250, 0),
|
||||
Vector (11400, 100, 0),
|
||||
Vector (11500, 500, 0)])
|
||||
_set_text(["N-degree bezier"], Vector(11000, -200, 0))
|
||||
|
||||
# Point
|
||||
_msg(16 * "-")
|
||||
_msg("Point")
|
||||
point = Draft.make_point(13500, 500, 0)
|
||||
point = Draft.make_point(12000, 0, 0)
|
||||
if App.GuiUp:
|
||||
point.ViewObject.PointSize = 10
|
||||
t_xpos += 900
|
||||
_set_text(["Point"], Vector(t_xpos, t_ypos, 0))
|
||||
_set_text(["Point"], Vector(12000, -200, 0))
|
||||
|
||||
# Facebinder
|
||||
_msg(16 * "-")
|
||||
_msg("Facebinder")
|
||||
box = doc.addObject("Part::Box", "Box")
|
||||
box.Length = 200
|
||||
box.Width = 500
|
||||
box.Height = 100
|
||||
box.Placement.Base = Vector(13000, 0, 0)
|
||||
if App.GuiUp:
|
||||
box.ViewObject.Visibility = False
|
||||
facebinder = Draft.make_facebinder([(box, ("Face1", "Face3", "Face6"))])
|
||||
facebinder.Extrusion = 10
|
||||
_set_text(["Facebinder"], Vector(13000, -200, 0))
|
||||
|
||||
# Shapestring
|
||||
_msg(16 * "-")
|
||||
@@ -313,268 +239,347 @@ def _create_objects(doc=None,
|
||||
shape_string = Draft.make_shapestring("Testing",
|
||||
font_file,
|
||||
100)
|
||||
shape_string.Placement.Base = Vector(14000, 500)
|
||||
shape_string.Placement.Base = Vector(14000, 0)
|
||||
except Exception:
|
||||
_wrn("Shapestring could not be created")
|
||||
_wrn("Possible cause: the font file may not exist")
|
||||
_wrn(font_file)
|
||||
rect = Draft.make_rectangle(500, 100)
|
||||
rect.Placement.Base = Vector(14000, 500)
|
||||
t_xpos += 600
|
||||
_set_text(["Shapestring"], Vector(t_xpos, t_ypos, 0))
|
||||
_set_text(["Shapestring"], Vector(14000, -200, 0))
|
||||
|
||||
# Facebinder
|
||||
# Hatch
|
||||
_msg(16 * "-")
|
||||
_msg("Facebinder")
|
||||
box = doc.addObject("Part::Box", "Cube")
|
||||
box.Length = 200
|
||||
box.Width = 500
|
||||
box.Height = 100
|
||||
box.Placement.Base = Vector(15000, 0, 0)
|
||||
_msg("Hatch")
|
||||
rectangle = Draft.make_rectangle(500, 300, 0)
|
||||
rectangle.Placement.Base = Vector(15000, 0, 0)
|
||||
rectangle.MakeFace = True
|
||||
if App.GuiUp:
|
||||
box.ViewObject.Visibility = False
|
||||
rectangle.ViewObject.Visibility = False
|
||||
try:
|
||||
Draft.make_hatch(rectangle,
|
||||
hatch_file,
|
||||
hatch_name,
|
||||
scale=10,
|
||||
rotation=45)
|
||||
except Exception:
|
||||
_wrn("Hatch could not be created")
|
||||
_wrn("Possible cause: the hatch file may not exist")
|
||||
_wrn(hatch_file)
|
||||
_set_text(["Hatch"], Vector(15000, -200, 0))
|
||||
|
||||
facebinder = Draft.make_facebinder([(box, ("Face1", "Face3", "Face6"))])
|
||||
facebinder.Extrusion = 10
|
||||
t_xpos += 780
|
||||
_set_text(["Facebinder"], Vector(t_xpos, t_ypos, 0))
|
||||
# Annotation ############################################################
|
||||
|
||||
# Cubic bezier curve, n-degree bezier curve
|
||||
# Text
|
||||
_msg(16 * "-")
|
||||
_msg("Cubic bezier")
|
||||
Draft.make_bezcurve([Vector(15500, 0, 0),
|
||||
Vector(15578, 485, 0),
|
||||
Vector(15879, 154, 0),
|
||||
Vector(15975, 400, 0),
|
||||
Vector(16070, 668, 0),
|
||||
Vector(16423, 925, 0),
|
||||
Vector(16500, 500, 0)], degree=3)
|
||||
t_xpos += 680
|
||||
_set_text(["Cubic bezier"], Vector(t_xpos, t_ypos, 0))
|
||||
_msg("Text")
|
||||
text = Draft.make_text(["Testing", "text"], Vector(0, 2100, 0))
|
||||
if App.GuiUp:
|
||||
text.ViewObject.FontSize = 100
|
||||
_set_text(["Text"], Vector(0, 1800, 0))
|
||||
|
||||
# Linear dimension
|
||||
_msg(16 * "-")
|
||||
_msg("N-degree bezier")
|
||||
Draft.make_bezcurve([Vector(16500, 0, 0),
|
||||
Vector(17000, 500, 0),
|
||||
Vector(17500, 500, 0),
|
||||
Vector(17500, 1000, 0),
|
||||
Vector(17000, 1000, 0),
|
||||
Vector(17063, 1256, 0),
|
||||
Vector(17732, 1227, 0),
|
||||
Vector(17790, 720, 0),
|
||||
Vector(17702, 242, 0)])
|
||||
t_xpos += 1200
|
||||
_set_text(["n-Bezier"], Vector(t_xpos, t_ypos, 0))
|
||||
_msg("Linear dimension")
|
||||
dimension = Draft.make_linear_dimension(Vector(1500, 2000, 0),
|
||||
Vector(1500, 2400, 0),
|
||||
Vector(1000, 2200, 0))
|
||||
if App.GuiUp:
|
||||
dimension.ViewObject.ArrowSize = 15
|
||||
dimension.ViewObject.ExtLines = 0
|
||||
dimension.ViewObject.ExtOvershoot = 50
|
||||
dimension.ViewObject.DimOvershoot = 25
|
||||
dimension.ViewObject.FontSize = 50
|
||||
dimension.ViewObject.Decimals = 1
|
||||
dimension.ViewObject.ShowUnit = False
|
||||
|
||||
line = Draft.make_wire([Vector(1500, 2600, 0),
|
||||
Vector(1500, 3000, 0)])
|
||||
doc.recompute()
|
||||
dimension = Draft.make_linear_dimension_obj(line, 1, 2,
|
||||
Vector(1000, 2800, 0))
|
||||
if App.GuiUp:
|
||||
dimension.ViewObject.ArrowSize = 15
|
||||
dimension.ViewObject.ArrowType = "Arrow"
|
||||
dimension.ViewObject.ExtLines = -50
|
||||
dimension.ViewObject.ExtOvershoot = 50
|
||||
dimension.ViewObject.DimOvershoot = 25
|
||||
dimension.ViewObject.FontSize = 50
|
||||
dimension.ViewObject.Decimals = 1
|
||||
dimension.ViewObject.ShowUnit = False
|
||||
|
||||
_set_text(["Dimension"], Vector(1000, 1800, 0))
|
||||
|
||||
# Radius and diameter dimension
|
||||
_msg(16 * "-")
|
||||
_msg("Radius and diameter dimension")
|
||||
circle = Draft.make_circle(200)
|
||||
circle.Placement.Base = Vector(2200, 2200, 0)
|
||||
circle.MakeFace = False
|
||||
doc.recompute()
|
||||
dimension = Draft.make_radial_dimension_obj(circle,
|
||||
1,
|
||||
"radius",
|
||||
Vector(2300, 2300, 0))
|
||||
if App.GuiUp:
|
||||
dimension.ViewObject.ArrowSize = 15
|
||||
dimension.ViewObject.FontSize = 50
|
||||
dimension.ViewObject.Decimals = 1
|
||||
dimension.ViewObject.ShowUnit = False
|
||||
|
||||
circle = Draft.make_circle(200)
|
||||
circle.Placement.Base = Vector(2200, 2800, 0)
|
||||
circle.MakeFace = False
|
||||
doc.recompute()
|
||||
dimension = Draft.make_radial_dimension_obj(circle,
|
||||
1,
|
||||
"diameter",
|
||||
Vector(2300, 2900, 0))
|
||||
if App.GuiUp:
|
||||
dimension.ViewObject.ArrowSize = 15
|
||||
dimension.ViewObject.FontSize = 50
|
||||
dimension.ViewObject.Decimals = 1
|
||||
dimension.ViewObject.ShowUnit = False
|
||||
_set_text(["Radius dimension",
|
||||
"Diameter dimension"], Vector(2000, 1800, 0))
|
||||
|
||||
# Angular dimension
|
||||
_msg(16 * "-")
|
||||
_msg("Angular dimension")
|
||||
Draft.make_line(Vector(3000, 2000, 0), Vector(3500, 2000, 0))
|
||||
Draft.make_line(Vector(3000, 2000, 0), Vector(3500, 2500, 0))
|
||||
dimension = Draft.make_angular_dimension(Vector(3000, 2000, 0),
|
||||
[0, 45],
|
||||
Vector(3250, 2250, 0))
|
||||
if App.GuiUp:
|
||||
dimension.ViewObject.ArrowSize = 15
|
||||
dimension.ViewObject.FontSize = 50
|
||||
dimension.ViewObject.Decimals = 1
|
||||
_set_text(["Angle dimension"], Vector(3000, 1800, 0))
|
||||
|
||||
# Label
|
||||
_msg(16 * "-")
|
||||
_msg("Label")
|
||||
place = App.Placement(Vector(18500, 500, 0), App.Rotation())
|
||||
label = Draft.make_label(target_point=Vector(18000, 0, 0),
|
||||
place = App.Placement(Vector(4250, 2250, 0), App.Rotation())
|
||||
label = Draft.make_label(target_point=Vector(4000, 2000, 0),
|
||||
placement=place,
|
||||
custom_text="Example label",
|
||||
distance=-250)
|
||||
distance=-100)
|
||||
label.Text = "Testing"
|
||||
if App.GuiUp:
|
||||
label.ViewObject.ArrowSize = 15
|
||||
label.ViewObject.TextSize = 100
|
||||
label.ViewObject.TextSize = 50
|
||||
doc.recompute()
|
||||
t_xpos += 1200
|
||||
_set_text(["Label"], Vector(t_xpos, t_ypos, 0))
|
||||
_set_text(["Label"], Vector(4000, 1800, 0))
|
||||
|
||||
# Orthogonal array and orthogonal link array
|
||||
# Array #################################################################
|
||||
|
||||
# Orthogonal array
|
||||
_msg(16 * "-")
|
||||
_msg("Orthogonal array")
|
||||
rect_h = Draft.make_rectangle(500, 500)
|
||||
rect_h.Placement.Base = Vector(1500, 2500, 0)
|
||||
rectangle = Draft.make_rectangle(100, 50)
|
||||
rectangle.Placement.Base = Vector(0, 4000, 0)
|
||||
if App.GuiUp:
|
||||
rect_h.ViewObject.Visibility = False
|
||||
|
||||
Draft.make_ortho_array(rect_h,
|
||||
Vector(600, 0, 0),
|
||||
Vector(0, 600, 0),
|
||||
rectangle.ViewObject.Visibility = False
|
||||
Draft.make_ortho_array(rectangle,
|
||||
Vector(200, 0, 0),
|
||||
Vector(0, 150, 0),
|
||||
Vector(0, 0, 0),
|
||||
3, 2, 1,
|
||||
3,
|
||||
2,
|
||||
1,
|
||||
use_link=False)
|
||||
t_xpos = 1700
|
||||
t_ypos = 2200
|
||||
_set_text(["Array"], Vector(t_xpos, t_ypos, 0))
|
||||
|
||||
rect_h_2 = Draft.make_rectangle(500, 100)
|
||||
rect_h_2.Placement.Base = Vector(1500, 5000, 0)
|
||||
if App.GuiUp:
|
||||
rect_h_2.ViewObject.Visibility = False
|
||||
_set_text(["Orthogonal array"], Vector(0, 3800, 0))
|
||||
|
||||
# Orthogonal link array
|
||||
_msg(16 * "-")
|
||||
_msg("Orthogonal link array")
|
||||
Draft.make_ortho_array(rect_h_2,
|
||||
Vector(800, 0, 0),
|
||||
Vector(0, 500, 0),
|
||||
rectangle = Draft.make_rectangle(50, 50)
|
||||
rectangle.Placement.Base = Vector(1000, 4000, 0)
|
||||
if App.GuiUp:
|
||||
rectangle.ViewObject.Visibility = False
|
||||
Draft.make_ortho_array(rectangle,
|
||||
Vector(200, 0, 0),
|
||||
Vector(0, 150, 0),
|
||||
Vector(0, 0, 0),
|
||||
2, 4, 1,
|
||||
3,
|
||||
2,
|
||||
1,
|
||||
use_link=True)
|
||||
t_ypos += 2600
|
||||
_set_text(["Link array"], Vector(t_xpos, t_ypos, 0))
|
||||
_set_text(["Orthogonal link array"], Vector(1000, 3800, 0))
|
||||
|
||||
# Polar array and polar link array
|
||||
# Polar array
|
||||
_msg(16 * "-")
|
||||
_msg("Polar array")
|
||||
wire_h = Draft.make_wire([Vector(5500, 3000, 0),
|
||||
Vector(6000, 3500, 0),
|
||||
Vector(6000, 3200, 0),
|
||||
Vector(5800, 3200, 0)])
|
||||
wire = Draft.make_wire([Vector(2000, 4050, 0),
|
||||
Vector(2000, 4000, 0),
|
||||
Vector(2100, 4000, 0)])
|
||||
if App.GuiUp:
|
||||
wire_h.ViewObject.Visibility = False
|
||||
|
||||
Draft.make_polar_array(wire_h,
|
||||
8,
|
||||
200,
|
||||
Vector(5000, 3000, 0),
|
||||
wire.ViewObject.Visibility = False
|
||||
Draft.make_polar_array(wire,
|
||||
4,
|
||||
90,
|
||||
Vector(2000, 4250, 0),
|
||||
use_link=False)
|
||||
_set_text(["Polar array"], Vector(2000, 3800, 0))
|
||||
|
||||
t_xpos = 4600
|
||||
t_ypos = 2200
|
||||
_set_text(["Polar array"], Vector(t_xpos, t_ypos, 0))
|
||||
|
||||
# Polar link array
|
||||
_msg(16 * "-")
|
||||
_msg("Polar link array")
|
||||
wire_h_2 = Draft.make_wire([Vector(5500, 6000, 0),
|
||||
Vector(6000, 6000, 0),
|
||||
Vector(5800, 5700, 0),
|
||||
Vector(5800, 5750, 0)])
|
||||
wire = Draft.make_wire([Vector(3000, 4050, 0),
|
||||
Vector(3000, 4000, 0),
|
||||
Vector(3050, 4000, 0)])
|
||||
if App.GuiUp:
|
||||
wire_h_2.ViewObject.Visibility = False
|
||||
|
||||
Draft.make_polar_array(wire_h_2,
|
||||
8,
|
||||
200,
|
||||
Vector(5000, 6000, 0),
|
||||
wire.ViewObject.Visibility = False
|
||||
Draft.make_polar_array(wire,
|
||||
4,
|
||||
90,
|
||||
Vector(3000, 4250, 0),
|
||||
use_link=True)
|
||||
t_ypos += 3200
|
||||
_set_text(["Polar link array"], Vector(t_xpos, t_ypos, 0))
|
||||
_set_text(["Polar link array"], Vector(3000, 3800, 0))
|
||||
|
||||
# Circular array and circular link array
|
||||
# Circular array
|
||||
_msg(16 * "-")
|
||||
_msg("Circular array")
|
||||
poly_h = Draft.make_polygon(5, 200)
|
||||
poly_h.Placement.Base = Vector(8000, 3000, 0)
|
||||
polygon = Draft.make_polygon(5, 30)
|
||||
polygon.Placement.Base = Vector(4250, 4250, 0)
|
||||
if App.GuiUp:
|
||||
poly_h.ViewObject.Visibility = False
|
||||
|
||||
Draft.make_circular_array(poly_h,
|
||||
500, 600,
|
||||
polygon.ViewObject.Visibility = False
|
||||
Draft.make_circular_array(polygon,
|
||||
110,
|
||||
100,
|
||||
3,
|
||||
1,
|
||||
Vector(0, 0, 1),
|
||||
Vector(0, 0, 0),
|
||||
use_link=False)
|
||||
t_xpos = 7700
|
||||
t_ypos = 1700
|
||||
_set_text(["Circular array"], Vector(t_xpos, t_ypos, 0))
|
||||
_set_text(["Circular array"], Vector(4000, 3800, 0))
|
||||
|
||||
# Circular link array
|
||||
_msg(16 * "-")
|
||||
_msg("Circular link array")
|
||||
poly_h_2 = Draft.make_polygon(6, 150)
|
||||
poly_h_2.Placement.Base = Vector(8000, 6250, 0)
|
||||
polygon = Draft.make_polygon(6, 30)
|
||||
polygon.Placement.Base = Vector(5250, 4250, 0)
|
||||
if App.GuiUp:
|
||||
poly_h_2.ViewObject.Visibility = False
|
||||
|
||||
Draft.make_circular_array(poly_h_2,
|
||||
550, 450,
|
||||
polygon.ViewObject.Visibility = False
|
||||
Draft.make_circular_array(polygon,
|
||||
110,
|
||||
100,
|
||||
3,
|
||||
1,
|
||||
Vector(0, 0, 1),
|
||||
Vector(0, 0, 0),
|
||||
use_link=True)
|
||||
t_ypos += 3100
|
||||
_set_text(["Circular link array"], Vector(t_xpos, t_ypos, 0))
|
||||
_set_text(["Circular link array"], Vector(5000, 3800, 0))
|
||||
|
||||
# Path array and path link array
|
||||
# Path array
|
||||
_msg(16 * "-")
|
||||
_msg("Path array")
|
||||
poly_h = Draft.make_polygon(3, 250)
|
||||
poly_h.Placement.Base = Vector(10000, 3000, 0)
|
||||
polygon = Draft.make_polygon(3, 30)
|
||||
polygon.Placement.Base = Vector(6000, 4000, 0)
|
||||
if App.GuiUp:
|
||||
poly_h.ViewObject.Visibility = False
|
||||
|
||||
bspline_path = Draft.make_bspline([Vector(10500, 2500, 0),
|
||||
Vector(11000, 3000, 0),
|
||||
Vector(11500, 3200, 0),
|
||||
Vector(12000, 4000, 0)])
|
||||
|
||||
Draft.make_path_array(poly_h, bspline_path, 5,
|
||||
use_link=False)
|
||||
t_xpos = 10400
|
||||
t_ypos = 2200
|
||||
_set_text(["Path array"], Vector(t_xpos, t_ypos, 0))
|
||||
polygon.ViewObject.Visibility = False
|
||||
spline = Draft.make_bspline([Vector(6000, 4000, 0),
|
||||
Vector(6100, 4200, 0),
|
||||
Vector(6400, 4300, 0),
|
||||
Vector(6500, 4500, 0)])
|
||||
Draft.make_path_array(polygon, spline, 5, use_link=False)
|
||||
_set_text(["Path array"], Vector(6000, 3800, 0))
|
||||
|
||||
# Path link array
|
||||
_msg(16 * "-")
|
||||
_msg("Path link array")
|
||||
poly_h_2 = Draft.make_polygon(4, 200)
|
||||
poly_h_2.Placement.Base = Vector(10000, 5000, 0)
|
||||
polygon = Draft.make_polygon(4, 30)
|
||||
polygon.Placement.Base = Vector(7000, 4000, 0)
|
||||
if App.GuiUp:
|
||||
poly_h_2.ViewObject.Visibility = False
|
||||
|
||||
bspline_path_2 = Draft.make_bspline([Vector(10500, 4500, 0),
|
||||
Vector(11000, 6800, 0),
|
||||
Vector(11500, 6000, 0),
|
||||
Vector(12000, 5200, 0)])
|
||||
|
||||
Draft.make_path_array(poly_h_2, bspline_path_2, 6,
|
||||
use_link=True)
|
||||
t_ypos += 2000
|
||||
_set_text(["Path link array"], Vector(t_xpos, t_ypos, 0))
|
||||
polygon.ViewObject.Visibility = False
|
||||
spline = Draft.make_bspline([Vector(7000, 4000, 0),
|
||||
Vector(7100, 4200, 0),
|
||||
Vector(7400, 4300, 0),
|
||||
Vector(7500, 4500, 0)])
|
||||
Draft.make_path_array(polygon, spline, 5, use_link=True)
|
||||
_set_text(["Path link array"], Vector(7000, 3800, 0))
|
||||
|
||||
# Point array
|
||||
_msg(16 * "-")
|
||||
_msg("Point array")
|
||||
poly_h = Draft.make_polygon(3, 250)
|
||||
poly_h.Placement.Base = Vector(12500, 2500, 0)
|
||||
|
||||
point_1 = Draft.make_point(13000, 3000, 0)
|
||||
point_2 = Draft.make_point(13000, 3500, 0)
|
||||
point_3 = Draft.make_point(14000, 2500, 0)
|
||||
point_4 = Draft.make_point(14000, 3000, 0)
|
||||
|
||||
polygon = Draft.make_polygon(3, 30)
|
||||
polygon.Placement.Base = Vector(8000, 4000, 0)
|
||||
point_1 = Draft.make_point(8030, 4030, 0)
|
||||
point_2 = Draft.make_point(8030, 4250, 0)
|
||||
point_3 = Draft.make_point(8470, 4250, 0)
|
||||
point_4 = Draft.make_point(8470, 4470, 0)
|
||||
add_list, delete_list = Draft.upgrade([point_1, point_2,
|
||||
point_3, point_4])
|
||||
compound = add_list[0]
|
||||
if App.GuiUp:
|
||||
compound.ViewObject.PointSize = 5
|
||||
Draft.make_point_array(polygon, compound, use_link=False)
|
||||
_set_text(["Point array"], Vector(8000, 3800, 0))
|
||||
|
||||
Draft.make_point_array(poly_h, compound)
|
||||
t_xpos = 13000
|
||||
t_ypos = 2200
|
||||
_set_text(["Point array"], Vector(t_xpos, t_ypos, 0))
|
||||
|
||||
# Clone and mirror
|
||||
# Point link array
|
||||
_msg(16 * "-")
|
||||
_msg("Clone")
|
||||
wire_h = Draft.make_wire([Vector(15000, 2500, 0),
|
||||
Vector(15200, 3000, 0),
|
||||
Vector(15500, 2500, 0),
|
||||
Vector(15200, 2300, 0)])
|
||||
_msg("Point link array")
|
||||
polygon = Draft.make_polygon(4, 30)
|
||||
polygon.Placement.Base = Vector(9000, 4000, 0)
|
||||
point_1 = Draft.make_point(9030, 4030, 0)
|
||||
point_2 = Draft.make_point(9030, 4250, 0)
|
||||
point_3 = Draft.make_point(9470, 4250, 0)
|
||||
point_4 = Draft.make_point(9470, 4470, 0)
|
||||
add_list, delete_list = Draft.upgrade([point_1, point_2,
|
||||
point_3, point_4])
|
||||
compound = add_list[0]
|
||||
if App.GuiUp:
|
||||
compound.ViewObject.PointSize = 5
|
||||
Draft.make_point_array(polygon, compound, use_link=True)
|
||||
_set_text(["Point link array"], Vector(9000, 3800, 0))
|
||||
|
||||
Draft.make_clone(wire_h, Vector(0, 1000, 0))
|
||||
t_xpos = 15000
|
||||
t_ypos = 2100
|
||||
_set_text(["Clone"], Vector(t_xpos, t_ypos, 0))
|
||||
# Miscellaneous #########################################################
|
||||
|
||||
# Mirror
|
||||
_msg(16 * "-")
|
||||
_msg("Mirror")
|
||||
wire_h = Draft.make_wire([Vector(17000, 2500, 0),
|
||||
Vector(16500, 4000, 0),
|
||||
Vector(16000, 2700, 0),
|
||||
Vector(16500, 2500, 0),
|
||||
Vector(16700, 2700, 0)])
|
||||
wire = Draft.make_wire([Vector(0, 6000, 0),
|
||||
Vector(150, 6200, 0),
|
||||
Vector(500, 6000, 0)])
|
||||
Draft.mirror(wire,
|
||||
Vector(0, 6250, 0),
|
||||
Vector(500, 6250, 0))
|
||||
_set_text(["Mirror"], Vector(0, 5800, 0))
|
||||
|
||||
Draft.mirror(wire_h,
|
||||
Vector(17100, 2000, 0),
|
||||
Vector(17100, 4000, 0))
|
||||
t_xpos = 17000
|
||||
t_ypos = 2200
|
||||
_set_text(["Mirror"], Vector(t_xpos, t_ypos, 0))
|
||||
# Clone
|
||||
_msg(16 * "-")
|
||||
_msg("Clone")
|
||||
wire = Draft.make_wire([Vector(1000, 6000, 0),
|
||||
Vector(1150, 6200, 0),
|
||||
Vector(1500, 6000, 0)])
|
||||
Draft.make_clone(wire, Vector(0, 300, 0))
|
||||
_set_text(["Clone"], Vector(1000, 5800, 0))
|
||||
|
||||
# Shape2DView
|
||||
_msg(16 * "-")
|
||||
_msg("Shape2DView")
|
||||
place = App.Placement(Vector(2000, 6000, 0),
|
||||
App.Rotation(Vector(0, 0, 1), Vector(1, 2, 3)))
|
||||
box = doc.addObject("Part::Box", "Box")
|
||||
box.Length = 200
|
||||
box.Width = 500
|
||||
box.Height = 100
|
||||
box.Placement = place
|
||||
if App.GuiUp:
|
||||
box.ViewObject.Visibility = False
|
||||
Draft.make_shape2dview(box)
|
||||
_set_text(["Shape2DView"], Vector(2000, 5800, 0))
|
||||
|
||||
# WorkingPlaneProxy
|
||||
_msg(16 * "-")
|
||||
_msg("WorkingPlaneProxy")
|
||||
place = App.Placement(Vector(3250, 6250, 0), App.Rotation())
|
||||
proxy = Draft.make_workingplaneproxy(place)
|
||||
if App.GuiUp:
|
||||
proxy.ViewObject.DisplaySize = 500
|
||||
proxy.ViewObject.ArrowSize = 50
|
||||
_set_text(["WorkingPlaneProxy"], Vector(3000, 5800, 0))
|
||||
|
||||
# Layer
|
||||
_msg(16 * "-")
|
||||
_msg("Layer")
|
||||
layer = Draft.make_layer("Custom layer",
|
||||
@@ -582,39 +587,24 @@ def _create_objects(doc=None,
|
||||
shape_color=(0.56, 0.89, 0.56),
|
||||
line_width=4,
|
||||
transparency=50)
|
||||
cube = doc.addObject('Part::Box')
|
||||
cube.Length = 350
|
||||
cube.Width = 300
|
||||
cube.Height = 250
|
||||
cube.Placement.Base = Vector(14000, 5500, 0)
|
||||
|
||||
cone = doc.addObject('Part::Cone')
|
||||
cone.Radius1 = 400
|
||||
cone.Height = 600
|
||||
cone.Angle = 270
|
||||
cone.Placement.Base = Vector(15000, 6000, 0)
|
||||
|
||||
sphere = doc.addObject('Part::Sphere')
|
||||
sphere.Radius = 450
|
||||
sphere.Angle1 = -45
|
||||
sphere.Angle2 = 45
|
||||
sphere.Angle3 = 300
|
||||
sphere.Placement.Base = Vector(14000, 7000, 0)
|
||||
|
||||
layer.Proxy.addObject(layer, cube)
|
||||
layer.Proxy.addObject(layer, cone)
|
||||
box = doc.addObject("Part::Box", "Box")
|
||||
box.Length = 200
|
||||
box.Width = 500
|
||||
box.Height = 100
|
||||
box.Placement.Base = Vector(4000, 6000, 0)
|
||||
sphere = doc.addObject("Part::Sphere", "Sphere")
|
||||
sphere.Radius = 100
|
||||
sphere.Placement.Base = Vector(4400, 6250, 0)
|
||||
layer.Proxy.addObject(layer, box)
|
||||
layer.Proxy.addObject(layer, sphere)
|
||||
_set_text(["Layer"], Vector(4000, 5800, 0))
|
||||
|
||||
t_xpos = 14000
|
||||
t_ypos = 5000
|
||||
_set_text(["Layer"], Vector(t_xpos, t_ypos, 0))
|
||||
doc.recompute()
|
||||
|
||||
|
||||
def create_test_file(file_name="draft_test_objects",
|
||||
file_path=os.environ["HOME"],
|
||||
save=False,
|
||||
font_file="/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"):
|
||||
def create_test_file(font_file=App.getHomePath()+"data/Mod/TechDraw/Resources/fonts/osifont-lgpl3fe.ttf",
|
||||
hatch_file=App.getHomePath()+"data/Mod/TechDraw/PAT/FCPAT.pat",
|
||||
hatch_name="Horizontal5"):
|
||||
"""Create a complete test file of Draft objects.
|
||||
|
||||
It draws a frame with information on the software used to create
|
||||
@@ -622,63 +612,35 @@ def create_test_file(file_name="draft_test_objects",
|
||||
|
||||
Parameters
|
||||
----------
|
||||
file_name: str, optional
|
||||
It defaults to `'draft_test_objects'`.
|
||||
It is the name of the document that is created.
|
||||
|
||||
The `file_name` will be appended to `file_path`
|
||||
to determine the actual path to save. The extension `.FCStd`
|
||||
will be added automatically.
|
||||
|
||||
file_path: str, optional
|
||||
It defaults to the value of `os.environ['HOME']`
|
||||
which in Linux is usually `'/home/user'`.
|
||||
|
||||
If it is the empty string `''` it will use the value
|
||||
returned by `App.getUserAppDataDir()`,
|
||||
for example, `'/home/user/.FreeCAD/'`.
|
||||
|
||||
save: bool, optional
|
||||
It defaults to `False`. If it is `True` the new document
|
||||
will be saved to disk after creating all objects.
|
||||
|
||||
font_file: str, optional
|
||||
It defaults to `'/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf'`.
|
||||
It is the full path of a font in the system to be used
|
||||
to create a `Draft ShapeString`.
|
||||
If the font is not found, this object is not created.
|
||||
It defaults to `App.getHomePath()+"data/Mod/TechDraw/Resources/fonts/osifont-lgpl3fe.ttf"`
|
||||
It is the full path of a font file to be used to create a `Draft ShapeString`.
|
||||
If the file is not found, this object is not created.
|
||||
|
||||
hatch_file: str, optional
|
||||
It defaults to `App.getHomePath()+"data/Mod/TechDraw/PAT/FCPAT.pat"`
|
||||
It is the full path of a PAT file to be used to create a `Draft Hatch`.
|
||||
If the file is not found, this object is not created.
|
||||
|
||||
hatch_name: str, optional
|
||||
It defaults to `"Horizontal5"`
|
||||
It is the name of a hatch pattern in the hatch_file.
|
||||
|
||||
Returns
|
||||
-------
|
||||
App::Document
|
||||
A reference to the test document that was created.
|
||||
|
||||
To Do
|
||||
-----
|
||||
Find a reliable way of getting a default font to be able to create
|
||||
the `Draft ShapeString`.
|
||||
"""
|
||||
doc = App.newDocument(file_name)
|
||||
_msg(16 * "-")
|
||||
_msg("Filename: {}".format(file_name))
|
||||
_msg("If the units tests fail, this script may fail as well")
|
||||
doc = App.newDocument()
|
||||
|
||||
_create_frame(doc=doc)
|
||||
_create_objects(doc=doc, font_file=font_file)
|
||||
_create_objects(doc=doc, font_file=font_file, hatch_file=hatch_file, hatch_name=hatch_name)
|
||||
|
||||
if App.GuiUp:
|
||||
Gui.runCommand("Std_ViewFitAll")
|
||||
|
||||
# Export
|
||||
if not file_path:
|
||||
file_path = App.getUserAppDataDir()
|
||||
|
||||
out_name = os.path.join(file_path, file_name + ".FCStd")
|
||||
doc.FileName = out_name
|
||||
if save:
|
||||
doc.save()
|
||||
_msg(16 * "-")
|
||||
_msg("Saved: {}".format(out_name))
|
||||
Gui.Selection.clearSelection()
|
||||
|
||||
return doc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user