{{ message }}
Repository navigation
Expand file tree
/
Copy pathSlicingComponent.cs
More file actions
307 lines (232 loc) · 10.1 KB
/
Copy pathSlicingComponent.cs
File metadata and controls
307 lines (232 loc) · 10.1 KB
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Grasshopper;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using Rhino.Geometry;
namespace Silkworm
{
public class SlicerComponent : GH_Component
{
/// <summary>::ABOUT::
/// This component exposes the Slicer, Skinner and Filler Methods from the Silkworm Skein Class.
/// </summary>
public SlicerComponent()
: base("Silkworm Slicer", "Slicer",
"Slices Closed or Open 3D Regions into 2D Regions with Planes",
"Silkworm", "Forms")
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddTextParameter("Settings Dictionary", "Settings", "Silkworm Settings Dictionary", GH_ParamAccess.list);
pManager.AddGenericParameter("Brep or Mesh", "Solids", "A List of Solid or Enclosing Regions", GH_ParamAccess.list);
pManager.AddPlaneParameter("Slicing Plane(s)", "Plane(s)", "Multiple or single plane to slice solid with. If you use planes that are not horizontal it is up to you to define how the printer will build these.", GH_ParamAccess.list);
pManager.AddNumberParameter("Layer Height", "Layer", "For a single plane input. This sets the perpendicular offset to the plane, replicating the plane as far as the bounding box of the object", GH_ParamAccess.item);
pManager.AddIntegerParameter("Thickness of Planar Shell", "Shell", "In plane shell thickness", GH_ParamAccess.item, 0);
//pManager.Register_BooleanParam("Detect Bridges and Overhangs", "Bridges", "Only useful for horizontal slicing. If true will generate regions for overhangs and bridges", GH_ParamAccess.item);
//pManager[5].Optional = true;
pManager[2].Optional = true;
pManager[3].Optional = true;
pManager[4].Optional = true;
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.Register_BRepParam("ClosedRegions", "Closed Regions", "A List of Planar Regions, output as follows depending on parameters: 0 - Whole Regions, 1- Shell Regions, 2-Infill Regions");
pManager.Register_CurveParam("OpenRegions", "Open Regions", "A List of Open Regions");
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
#region INPUTS
// import silkwormSettings file
List<string> silkwormSettings = new List<string>();
if (!DA.GetDataList(0, silkwormSettings)) return;
List<GH_ObjectWrapper> things = new List<GH_ObjectWrapper>();
if (!DA.GetDataList(1, things)) return;
// import Silkworm Movement
#endregion
SilkwormUtility sUtil = new SilkwormUtility();
Dictionary<string, string> Settings = sUtil.convertSettings(silkwormSettings);
#region Optional Variables
int shell = -999;
if (!DA.GetData(4, ref shell)) { }
double layerheight = -999;
if (!DA.GetData(3, ref layerheight)) { }
//bool detect = false;
//if (!DA.GetData(5, ref detect)) { }
List<Plane> sliceplanes = new List<Plane>();
if (!DA.GetDataList(2, sliceplanes)) { }
if (shell == -999)
{
shell = int.Parse(Settings["perimeters"]);
}
if (layerheight == -999)
{
layerheight = double.Parse(Settings["layer_height"]);
}
if (sliceplanes.Count<1)
{
sliceplanes.Add(Plane.WorldXY);
}
#endregion
List<Brep> Breps = new List<Brep>();
List<Mesh> Meshes = new List<Mesh>();
SilkwormSkein skein = new SilkwormSkein();
#region Sort Types
foreach (GH_ObjectWrapper obj in things)
{
if (obj.Value is GH_Brep)
{
Brep brep = null;
GH_Convert.ToBrep(obj.Value, ref brep, GH_Conversion.Both);
Breps.Add(brep);
continue;
}
if (obj.Value is GH_Mesh)
{
Mesh mesh = null;
GH_Convert.ToMesh(obj.Value, ref mesh, GH_Conversion.Both);
Meshes.Add(mesh);
continue;
}
}
#endregion
if (Breps.Count>0)
{
skein = new SilkwormSkein(Settings, Breps, sliceplanes, shell, layerheight);
skein.BrepSlice(false);
}
if (Meshes.Count > 0)
{
//TODO
}
//Reflect Errors and Warnings
foreach (string message in skein.ErrorMessages)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message);
}
foreach (string message in skein.WarningMessages)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, message);
}
List<Curve>[] openregions = skein.openRegions;
List<Brep>[] rRegions = skein.Regions;
List<Brep>[] rPerimeterR = skein.regionPerimeter;
List<Brep>[] rInfillR = skein.regionInfill;
GH_Structure<GH_Brep> Regions = new GH_Structure<GH_Brep>();
GH_Structure<GH_Curve> openRegions = new GH_Structure<GH_Curve>();
#region Add Regions to GH_Structure
if (rRegions.GetUpperBound(0) > 1)
{
for (int i = 0; i < rRegions.Length; i++)
{
if (rRegions[i] != null)
{
for (int j = 0; j < rRegions[i].Count; j++)
{
GH_Brep gShapes = new GH_Brep(rRegions[i][j]);
Regions.Insert(gShapes, new GH_Path(i, 0), j);
}
}
}
}
if (rPerimeterR.GetUpperBound(0) > 1)
{
for (int i = 0; i < rPerimeterR.Length; i++)
{
if (rPerimeterR[i] != null)
{
for (int j = 0; j < rPerimeterR[i].Count; j++)
{
GH_Brep gShapes = new GH_Brep(rPerimeterR[i][j]);
Regions.Insert(gShapes, new GH_Path(i, 1), j);
}
}
}
}
if (rInfillR.GetUpperBound(0) > 1)
{
for (int i = 0; i < rInfillR.Length; i++)
{
if (rInfillR[i] != null)
{
for (int j = 0; j < rInfillR[i].Count; j++)
{
GH_Brep gShapes = new GH_Brep(rInfillR[i][j]);
Regions.Insert(gShapes, new GH_Path(i, 2), j);
}
}
}
}
if (openregions.GetUpperBound(0) > 1)
{
for (int i = 0; i < openregions.Length; i++)
{
if (openregions[i] != null)
{
for (int j = 0; j < openregions[i].Count; j++)
{
GH_Curve gShapes = new GH_Curve(openregions[i][j]);
openRegions.Insert(gShapes, new GH_Path(i), j);
}
}
}
}
//TODO
//Add Overhang and Bridges
#endregion
#region Add Open Regions to GH_Structure
if (openregions.GetUpperBound(0) > 1)
{
for (int i = 0; i < openregions.Length; i++)
{
for (int j = 0; j < openregions[i].Count; j++)
{
if (openregions[i][j] != null)
{
SilkwormSegment segment = new SilkwormSegment(openregions[i][j]);
Curve curve = segment.Pline.ToNurbsCurve();
GH_Curve gShapes = new GH_Curve(curve);
openRegions.Insert(gShapes, new GH_Path(i), j);
}
}
}
}
#endregion
#region OUTPUT
if (!DA.SetDataTree(0, Regions)) { return; }
if (!DA.SetDataTree(1, openRegions)) { return; }
#endregion
}
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
//You can add image files to your project resources and access them like this:
return Silkworm.Properties.Resources.slicer;
//return null;
}
}
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("{d84624a7-092e-41a8-a2b4-5d50fcc92e1b}"); }
}
}
}
You can’t perform that action at this time.
