forked from jkmnt/matmill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mop_pocket.cs
222 lines (187 loc) · 6.92 KB
/
mop_pocket.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
using System;
using System.Reflection;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Xml.Serialization;
using CamBam;
using CamBam.CAD;
using CamBam.CAM;
using CamBam.Geom;
using CamBam.UI;
using CamBam.Values;
using Matmill;
namespace Trochomops
{
[Serializable]
public class MOPTrochopock : Trochomop, IIcon
{
//--- mop properties
protected double _min_stepover_percentage = 0.9;
//--- invisible and non-serializable properties
[XmlIgnore, Browsable(false)]
public override string MOPTypeName
{
get { return "TrochoPock"; }
}
[XmlIgnore, Browsable(false)]
public Image ActiveIconImage
{
get { return resources.cam_trochopock1;}
}
[XmlIgnore, Browsable(false)]
public string ActiveIconKey
{
get { return "cam_trochopock1"; }
}
[XmlIgnore, Browsable(false)]
public Image InactiveIconImage
{
get { return resources.cam_trochopock0;}
}
[XmlIgnore, Browsable(false)]
public string InactiveIconKey
{
get { return "cam_trochopock0"; }
}
//--- our own new parameters. No reason to make them CBValues, since they couldn't be styled anyway
[
CBAdvancedValue,
Category("Step Over"),
DefaultValue(0.9),
Description("Minimum allowed stepover as a percentage of the nominal stepover (0.1 - 0.9).\nLarger values may leave uncut corners"),
DisplayName("Minimum Stepover")
]
public double Min_stepover
{
get { return _min_stepover_percentage; }
set
{
_min_stepover_percentage = value;
if (value < 0.05 || value > 0.95)
{
_min_stepover_percentage = Math.Max(Math.Min(0.95, value), 0.05);
base.redraw_parameters();
}
}
}
private Sliced_path gen_pocket(ShapeListItem shape)
{
Polyline outline;
Polyline[] islands;
if (shape.Shape is Polyline)
{
outline = (Polyline)shape.Shape;
islands = new Polyline[] { };
}
else if (shape.Shape is CamBam.CAD.Region)
{
CamBam.CAD.Region reg = (CamBam.CAD.Region)shape.Shape;
outline = reg.OuterCurve;
islands = reg.HoleCurves;
}
else
{
return null;
}
Pocket_generator gen = new Pocket_generator(outline, islands);
gen.General_tolerance = is_inch_units() ? 0.001 / 25.4 : 0.001;
gen.Tool_d = base.ToolDiameter.Cached;
gen.Max_ted = base.ToolDiameter.Cached * _stepover.Cached;
gen.Min_ted = base.ToolDiameter.Cached * _stepover.Cached * _min_stepover_percentage;
gen.Startpoint = (Point2F)base.StartPoint.Cached;
gen.Margin = base.RoughingClearance.Cached;
if (_milling_direction.Cached == MillingDirectionOptions.Mixed || base.SpindleDirection.Cached == SpindleDirectionOptions.Off)
{
gen.Mill_direction = RotationDirection.Unknown; // means 'mixed' here
gen.Should_smooth_chords = false;
}
else
{
int dir = (int)(base.SpindleDirection.Cached);
if (_milling_direction.Cached == MillingDirectionOptions.Climb)
dir = -dir;
gen.Mill_direction = (RotationDirection)dir;
gen.Should_smooth_chords = _should_smooth_chords;
}
return gen.run();
}
protected override void _GenerateToolpathsWorker()
{
try
{
base.reset_toolpaths();
if (base.ToolDiameter.Cached == 0)
{
Logger.err("tool diameter is zero");
base.MachineOpStatus = MachineOpStatus.Errors;
return;
}
if (_stepover.Cached == 0 || _stepover.Cached > 1)
{
Logger.err("stepover should be > 0 and <= 1");
base.MachineOpStatus = MachineOpStatus.Errors;
return;
}
// XXX: is it needed ?
base.UpdateGeometryExtrema(base._CADFile);
base._CADFile.MachiningOptions.UpdateGeometryExtrema(base._CADFile);
ShapeList shapes = new ShapeList();
shapes.ApplyTransformations = true;
shapes.AddEntities(base._CADFile, base.PrimitiveIds);
shapes = shapes.DetectRegions();
bool found_opened_polylines = false;
for (int i = shapes.Count - 1; i >= 0; i--)
{
if (shapes[i].Shape is Polyline && ! ((Polyline)shapes[i].Shape).Closed)
{
found_opened_polylines = true;
shapes.RemoveAt(i);
}
}
if (found_opened_polylines)
{
Logger.warn("ignoring open polylines");
base.MachineOpStatus = MachineOpStatus.Warnings;
}
List<Sliced_path> trajectories = new List<Sliced_path>();
foreach (ShapeListItem shape in shapes)
{
Sliced_path traj = gen_pocket(shape);
if (traj != null)
trajectories.Add(traj);
}
if (trajectories.Count == 0)
return;
base.insert_toolpaths(trajectories);
if (base.MachineOpStatus == MachineOpStatus.Unknown)
{
base.MachineOpStatus = MachineOpStatus.OK;
}
}
catch (Exception ex)
{
base.MachineOpStatus = MachineOpStatus.Errors;
ThisApplication.HandleException(ex);
}
finally
{
base._GenerateToolpathsFinal();
}
}
public override MachineOp Clone()
{
return new MOPTrochopock(this);
}
public MOPTrochopock(MOPTrochopock src) : base(src)
{
Min_stepover = src.Min_stepover;
}
public MOPTrochopock()
{
}
public MOPTrochopock(CADFile CADFile, ICollection<Entity> plist) : base(CADFile, plist)
{
}
}
}