Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pyMKcam
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
pyMKcam
Commits
7a7960e6
Commit
7a7960e6
authored
Jul 20, 2012
by
Lars Kruse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup of the libarea patch
parent
a8948307
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
121 deletions
+48
-121
LibArea.py
pycam/Toolpath/LibArea.py
+48
-121
No files found.
pycam/Toolpath/LibArea.py
View file @
7a7960e6
# -*- coding: utf-8 -*-
import
copy
import
copy
import
area
import
area
import
pycam.Utils.log
import
pycam.Geometry.Line
import
pycam.Geometry.Line
import
pycam.Geometry.Polygon
import
pycam.Geometry.Polygon
_log
=
pycam
.
Utils
.
log
.
get_logger
()
def
_pocket_model
(
polygons
):
def
_pocket_model
(
polygons
):
"""Create pocketing path."""
"""Create pocketing path."""
...
@@ -13,144 +18,80 @@ def _pocket_model(polygons):
...
@@ -13,144 +18,80 @@ def _pocket_model(polygons):
ARC_CCW
=
1
ARC_CCW
=
1
ARC_CW
=
-
1
ARC_CW
=
-
1
#print "Model\n#lines:", model.get_num_of_lines()
print
"#line_groups:"
,
len
(
polygons
)
# copy pycam.Model to libarea.Area
# copy pycam.Model to libarea.Area
my_area
=
area
.
Area
()
my_area
=
area
.
Area
()
my_pocketParams
=
PocketParams
()
for
lg
in
polygons
:
for
lg
in
polygons
:
#print "line_group:", lg
print
"line_group() #Points:"
,
len
(
lg
.
get_points
())
my_curve
=
area
.
Curve
()
my_curve
=
area
.
Curve
()
if
lg
.
is_closed
is
True
:
""" TODO: direction is not used for now
if lg.is_closed:
curve_type = ARC_CW
curve_type = ARC_CW
else:
else:
curve_type = LINE
curve_type = LINE
p_first
=
True
"""
p_skip
=
False
for
pt
in
lg
.
get_points
():
for
pt
in
lg
.
get_points
():
#print "point(x,y): (%f,%f)" % (pt.x, pt.y)
if
p_first
:
my_curve
.
append
(
area
.
Vertex
(
area
.
Point
(
pt
[
0
],
pt
[
1
])))
else
:
if
p_skip
:
# ugly hack to load same begin/end point only once
p_skip
=
False
else
:
my_curve
.
append
(
area
.
Vertex
(
area
.
Point
(
pt
[
0
],
pt
[
1
])))
my_curve
.
append
(
area
.
Vertex
(
area
.
Point
(
pt
[
0
],
pt
[
1
])))
p_skip
=
True
"""
if p_previous is None:
p_previous = area.Point(pt.x, pt.y)
else:
p_next = area.Point(pt.x, pt.y)
my_curve.append(area.Vertex(LINE, p_previous, p_next))
p_previous = p_next
"""
my_area
.
append
(
my_curve
)
my_area
.
append
(
my_curve
)
my_pocketParams
=
PocketParams
()
return
_pocket_area
(
my_area
,
my_pocketParams
)
"""
# print the copy area its content
print "----------------------------------------"
print "copy area # Curves:", my_area.num_curves()
i=1
for c in my_area.getCurves():
print "Curve:
%
i, # points:
%
i"
%
( i, c.getNumVertices())
for v in c.getVertices():
print "point(x,y): (
%
f,
%
f)"
%
( v.p.x, v.p.y )
i+=1
print "----------------------------------------"
"""
pocket_polygons
=
[]
_pocket_area
(
my_area
,
my_pocketParams
,
pocket_polygons
)
return
pocket_polygons
def
_pocket_area
(
a
,
params
,
polygons
):
def
_pocket_area
(
a
,
params
):
polygons
=
[]
my_params
=
params
my_params
=
params
if
(
my_params
.
m_rapid_down_to_height
>
my_params
.
m_clearance_height
):
if
(
my_params
.
m_rapid_down_to_height
>
my_params
.
m_clearance_height
):
my_params
.
m_rapid_down_to_height
=
my_params
.
m_clearance_height
my_params
.
m_rapid_down_to_height
=
my_params
.
m_clearance_height
a
.
m_round_corners_factor
=
params
.
m_round_corner_factor
a
.
m_round_corners_factor
=
params
.
m_round_corner_factor
first_offset
=
my_params
.
m_tool_diameter
*
0.5
+
my_params
.
m_material_allowance
# copy Area instance
#a_firstoffset = copy.deepcopy(a) # TODO Curve deepcopy not yet fully covered, thus Area neither as it depends on it
a_firstoffset
=
area
.
Area
()
for
c
in
a
.
getCurves
():
copy_curve
=
area
.
Curve
()
for
vt
in
c
.
getVertices
():
copy_curve
.
append
(
copy
.
deepcopy
(
vt
))
a_firstoffset
.
append
(
copy_curve
)
a_firstoffset
.
Offset
(
first_offset
)
arealist
=
[]
arealist
.
append
(
a_firstoffset
)
# debug
_recur
(
my_params
,
arealist
,
a_firstoffset
);
#print "arealist length:", len(arealist)
layer_count
=
int
((
my_params
.
m_start_depth
-
my_params
.
m_final_depth
)
/
my_params
.
m_step_down
)
if
(
layer_count
*
my_params
.
m_step_down
+
0.00001
<
params
.
m_start_depth
-
my_params
.
m_final_depth
):
layer_count
+=
1
print
"layercount:"
,
layer_count
"""
arealist
=
_get_inner_polygons
(
my_params
,
a
)
for i in range (1, layer_count+1):
if
params
.
m_from_center
:
depth = my_params.m_final_depth
arealist
.
reverse
()
if (i != layer_count):
depth = my_params.m_start_depth - i * my_params.m_step_down
for a in arealist:
cut_area(a, depth) # generate toolpath
"""
# add all vertices from all areas to the polygons list
# add all vertices from all areas to the polygons list
print
"#area's:"
,
len
(
arealist
)
vertex2point
=
lambda
vt
:
(
vt
.
p
.
x
,
vt
.
p
.
y
,
0.0
)
for
a
in
arealist
:
for
a
in
arealist
:
#print "areaList()"
for
c
in
a
.
getCurves
():
for
c
in
a
.
getCurves
():
print
"Curve() #vertices:"
,
c
.
getNumVertices
()
my_poly
=
pycam
.
Geometry
.
Polygon
.
Polygon
()
my_poly
=
pycam
.
Geometry
.
Polygon
.
Polygon
()
p_previous
=
None
vertices
=
c
.
getVertices
()
p_next
=
None
if
not
vertices
:
for
vt
in
c
.
getVertices
():
continue
p_previous
=
vertex2point
(
vertices
.
pop
(
0
))
for
vt
in
vertices
:
# from 2D to 3D with Z=0
# from 2D to 3D with Z=0
if
p_previous
is
None
:
current
=
vertex2point
(
vt
)
p_previous
=
(
vt
.
p
.
x
,
vt
.
p
.
y
,
0.0
)
my_poly
.
append
(
pycam
.
Geometry
.
Line
.
Line
(
p_previous
,
current
))
else
:
p_previous
=
current
p_next
=
(
vt
.
p
.
x
,
vt
.
p
.
y
,
0.0
)
my_poly
.
append
(
pycam
.
Geometry
.
Line
.
Line
(
p_previous
,
p_next
))
p_previous
=
p_next
#polygons.append(Line(p1, p2))
#polygons.append(Point(vt.p.x, vt.p.y, 0.0))
polygons
.
append
(
my_poly
)
polygons
.
append
(
my_poly
)
return
polygons
def
_recur
(
params
,
arealist
,
a1
):
if
(
a1
.
num_curves
==
0
):
return
;
if
(
params
.
m_from_center
):
def
_get_area_copy
(
original
):
arealist
.
insert
(
0
,
a1
)
# prepend
# TODO: Curve deepcopy not yet fully covered, thus Area neither as it depends on it
else
:
#a_offset = copy.deepcopy(a1)
arealist
.
append
(
a1
)
result
=
area
.
Area
()
for
c
in
original
.
getCurves
():
# copy Area instance
#a_offset = copy.deepcopy(a1) # TODO Curve deepcopy not yet fully covered, thus Area neither as it depends on it
a_offset
=
area
.
Area
()
for
c
in
a1
.
getCurves
():
copy_curve
=
area
.
Curve
()
copy_curve
=
area
.
Curve
()
for
vt
in
c
.
getVertices
():
for
vt
in
c
.
getVertices
():
copy_curve
.
append
(
copy
.
deepcopy
(
vt
))
copy_curve
.
append
(
copy
.
deepcopy
(
vt
))
a_offset
.
append
(
copy_curve
)
result
.
append
(
copy_curve
)
return
result
a_offset
.
Offset
(
params
.
m_step_over
)
def
_get_inner_polygons
(
params
,
a1
):
if
a1
.
num_curves
==
0
:
return
[]
areas
=
[]
# copy Area instance
a_offset
=
_get_area_copy
(
a1
)
a_offset
.
Offset
(
params
.
m_step_over
)
for
curve
in
a_offset
.
getCurves
():
for
curve
in
a_offset
.
getCurves
():
a2
=
area
.
Area
()
a2
=
area
.
Area
()
a2
.
append
(
curve
)
a2
.
append
(
curve
)
_recur
(
params
,
arealist
,
a2
)
areas
.
append
(
a2
)
areas
.
extend
(
_get_inner_polygons
(
params
,
a2
))
return
areas
class
PocketParams
:
class
PocketParams
:
"""Settings used for pocketing toolpath generation."""
"""Settings used for pocketing toolpath generation."""
...
@@ -161,22 +102,8 @@ class PocketParams:
...
@@ -161,22 +102,8 @@ class PocketParams:
m_clearance_height
=
5
m_clearance_height
=
5
m_start_depth
=
0
m_start_depth
=
0
m_step_down
=
1
m_step_down
=
1
m_final_depth
=
-
1
m_final_depth
=
-
1
# original: -3
m_rapid_down_to_height
=
2
m_tool_diameter
=
2
m_format_style
=
0
"""
Original settings
m_from_center = True
m_round_corner_factor = 1.0
m_material_allowance = 0.0
m_step_over = 1.5
m_clearance_height = 5
m_start_depth = 0
m_step_down = 1
m_final_depth = -3
m_rapid_down_to_height
=
2
m_rapid_down_to_height
=
2
m_tool_diameter = 3
m_tool_diameter
=
2
# original:
3
m_format_style
=
0
m_format_style
=
0
"""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment