-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbodyDraft.fs
287 lines (257 loc) · 11.7 KB
/
bodyDraft.fs
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
FeatureScript ✨; /* Automatically generated version */
import(path : "onshape/std/evaluate.fs", version : "✨");
import(path : "onshape/std/feature.fs", version : "✨");
import(path : "onshape/std/manipulator.fs", version : "✨");
import(path : "onshape/std/math.fs", version : "✨");
import(path : "onshape/std/surfaceGeometry.fs", version : "✨");
import(path : "onshape/std/topologyUtils.fs", version : "✨");
import(path : "onshape/std/valueBounds.fs", version : "✨");
import(path : "onshape/std/vector.fs", version : "✨");
export import(path : "onshape/std/bodydraftcornertype.gen.fs", version : "✨");
export import(path : "onshape/std/bodydraftconcaverepairtype.gen.fs", version : "✨");
export import(path : "onshape/std/bodydraftmatchfacetype.gen.fs", version : "✨");
export import(path : "onshape/std/bodydraftselectiontype.gen.fs", version : "✨");
/**
* An operation that performs an [opBodyDraft].
*/
annotation { "Feature Type Name" : "Body draft",
"Editing Logic Function" : "bodyDraftEditLogic",
"Manipulator Change Function" : "bodyDraftManipulatorChange" }
export const bodyDraft = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation {
"Name" : "Preselection",
"UIHint" : UIHint.ALWAYS_HIDDEN,
"Filter" : BodyType.SOLID && (EntityType.BODY || EntityType.FACE || EntityType.EDGE) && ModifiableEntityOnly.YES && ActiveSheetMetal.NO
}
definition.preselection is Query;
annotation { "Name" : "Draft scope", "UIHint" : [UIHint.SHOW_LABEL, UIHint.REMEMBER_PREVIOUS_VALUE] }
definition.selectionType is BodyDraftSelectionType;
if (definition.selectionType == BodyDraftSelectionType.EDGES)
{
annotation { "Name" : "Edges", "Filter" : EntityType.EDGE && BodyType.SOLID && ModifiableEntityOnly.YES && ActiveSheetMetal.NO }
definition.topEdges is Query;
}
else if (definition.selectionType == BodyDraftSelectionType.FACES)
{
annotation { "Name" : "Faces", "Filter" : EntityType.FACE && BodyType.SOLID && ModifiableEntityOnly.YES && ActiveSheetMetal.NO }
definition.faces is Query;
}
else
{
annotation { "Name" : "Parts", "Filter" : EntityType.BODY && BodyType.SOLID && ModifiableEntityOnly.YES && ActiveSheetMetal.NO }
definition.bodies is Query;
annotation { "Name" : "Faces to exclude", "Filter" : EntityType.FACE && BodyType.SOLID && ModifiableEntityOnly.YES && ActiveSheetMetal.NO }
definition.excludeFaces is Query;
}
annotation { "Name" : "Draft on self" }
definition.draftOnSelf is boolean;
annotation { "Name" : "Pull direction",
"Filter" : QueryFilterCompound.ALLOWS_PLANE || QueryFilterCompound.ALLOWS_DIRECTION,
"MaxNumberOfPicks" : 1 }
definition.pullDirection is Query;
annotation { "Name" : "Flip pull direction", "UIHint" : UIHint.OPPOSITE_DIRECTION }
definition.flipPullDirection is boolean;
if (!definition.draftOnSelf)
{
annotation { "Name" : "Parting entity",
"Filter" : (EntityType.BODY && BodyType.SHEET && SketchObject.NO) || EntityType.FACE || BodyType.MATE_CONNECTOR,
"MaxNumberOfPicks" : 1 }
definition.partingObject is Query;
}
annotation { "Name" : "Angle" }
isAngle(definition.angle, ANGLE_STRICT_90_BOUNDS);
annotation { "Name" : "Symmetric" }
definition.bothSides is boolean;
if (definition.bothSides)
{
if (definition.selectionType == BodyDraftSelectionType.EDGES)
{
annotation { "Name" : "Bottom edges", "Filter" : EntityType.EDGE && ModifiableEntityOnly.YES && ActiveSheetMetal.NO }
definition.bottomEdges is Query;
}
if (!definition.draftOnSelf)
{
annotation { "Name" : "Match faces at parting", "Default" : true }
definition.matchFacesAtParting is boolean;
if (definition.matchFacesAtParting)
{
annotation { "Group Name" : "Match face options", "Collapsed By Default" : true, "Driving Parameter" : "matchFacesAtParting" }
{
annotation { "Name" : "Match type", "UIHint" : UIHint.SHOW_LABEL, "Default" : BodyDraftMatchFaceType.TANGENT_TO_FACE }
definition.matchFaceType is BodyDraftMatchFaceType;
annotation { "Name" : "Concave repair", "UIHint" : UIHint.SHOW_LABEL }
definition.concaveRepair is BodyDraftConcaveRepairType;
if (definition.concaveRepair != BodyDraftConcaveRepairType.NONE)
{
annotation { "Name" : "Radius" }
isLength(definition.concaveRepairRadius, BLEND_BOUNDS);
}
}
}
}
}
annotation { "Name" : "Corner type", "UIHint" : UIHint.SHOW_LABEL }
definition.cornerType is BodyDraftCornerType;
annotation { "Name" : "Keep material" }
definition.keepMaterial is boolean;
}
{
definition.pullDirection = createManipulators(context, id, definition);
if (definition.selectionType == BodyDraftSelectionType.EDGES)
{
verifyNonemptyQuery(context, definition, "topEdges", ErrorStringEnum.BODY_DRAFT_SELECT_EDGES);
verifyNoMeshInBody(context, definition, "topEdges");
verifyNoMeshInBody(context, definition, "bottomEdges");
}
else if (definition.selectionType == BodyDraftSelectionType.FACES)
{
verifyNonemptyQuery(context, definition, "faces", ErrorStringEnum.BODY_DRAFT_SELECT_FACES);
verifyNoMeshInBody(context, definition, "faces");
}
else if (definition.selectionType == BodyDraftSelectionType.PARTS)
{
verifyNonemptyQuery(context, definition, "bodies", ErrorStringEnum.BODY_DRAFT_SELECT_PARTS);
verifyNoMesh(context, definition, "bodies");
}
verify(definition.pullDirection != undefined, ErrorStringEnum.BODY_DRAFT_BAD_PULL_DIRECTION, {
"faultyParameters" : ["pullDirection"]
});
definition.pullDirection = definition.flipPullDirection ? -definition.pullDirection : definition.pullDirection;
if (!definition.bothSides)
{
definition.matchFacesAtParting = false;
}
opBodyDraft(context, id, definition);
}, { "selectionType" : BodyDraftSelectionType.EDGES, "draftOnSelf" : false, "flipPullDirection" : false, "bothSides" : false,
"matchFacesAtParting" : false, "cornerType" : BodyDraftCornerType.EXTEND, "preselection" : qNothing(), "keepMaterial" : false });
const flipManipulatorId = "flipManipulator";
function createManipulators(context is Context, topLevelId is Id, definition is map)
{
const direction = try silent(extractDirection(context, definition.pullDirection));
if (direction == undefined)
{
return direction;
}
var position;
if (definition.draftOnSelf)
{
var referencedTopology;
if (definition.selectionType == BodyDraftSelectionType.EDGES)
{
referencedTopology = definition.bothSides ? qUnion([definition.topEdges, definition.bottomEdges]) : definition.topEdges;
}
else if (definition.selectionType == BodyDraftSelectionType.FACES)
{
referencedTopology = definition.faces;
}
else
{
referencedTopology = definition.bodies;
}
if (isQueryEmpty(context, referencedTopology))
{
return direction;
}
const distanceResult = try silent(evDistance(context, {
"side0" : qNthElement(referencedTopology, 0),
"side1" : definition.pullDirection
}));
if (distanceResult == undefined)
{
return direction;
}
position = distanceResult.sides[0].point;
}
else
{
if (isQueryEmpty(context, definition.partingObject))
{
return direction;
}
const coords = try silent(evMateConnector(context, {
"mateConnector" : definition.partingObject
}));
if (coords == undefined)
{
const faces = qUnion([qEntityFilter(definition.partingObject, EntityType.FACE), qOwnedByBody(definition.partingObject, EntityType.FACE)]);
const plane = evFaceTangentPlane(context, {
"face" : faces,
"parameter" : vector(0.5, 0.5)
});
position = plane.origin;
}
else
{
position = coords.origin;
}
}
const manip = flipManipulator({
"base" : position,
"direction" : direction,
"flipped" : definition.flipPullDirection
});
addManipulators(context, topLevelId, { (flipManipulatorId) : manip });
return direction;
}
/**
* body draft editing logic
*/
export function bodyDraftEditLogic(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean, specifiedParameters is map) returns map
{
if (oldDefinition == {})
{
if (!isQueryEmpty(context, qEntityFilter(definition.preselection, EntityType.BODY)))
{
definition.selectionType = BodyDraftSelectionType.PARTS;
definition.bodies = qEntityFilter(definition.preselection, EntityType.BODY);
}
else if (!isQueryEmpty(context, qEntityFilter(definition.preselection, EntityType.FACE)))
{
definition.selectionType = BodyDraftSelectionType.FACES;
definition.faces = qEntityFilter(definition.preselection, EntityType.FACE);
}
else if (!isQueryEmpty(context, qEntityFilter(definition.preselection, EntityType.EDGE)))
{
definition.selectionType = BodyDraftSelectionType.EDGES;
definition.topEdges = qEntityFilter(definition.preselection, EntityType.EDGE);
}
definition.preselection = qNothing();
}
if (specifiedParameters.pullDirection != true && isQueryEmpty(context, definition.pullDirection) &&
(oldDefinition.partingObject == undefined || isQueryEmpty(context, oldDefinition.partingObject)))
{
const plane = try silent(evPlane(context, {
"face" : definition.partingObject
}));
if (plane == undefined)
{
return definition;
}
definition.pullDirection = definition.partingObject;
}
if (specifiedParameters.partingObject != true && isQueryEmpty(context, definition.partingObject) &&
(oldDefinition.pullDirection == undefined || isQueryEmpty(context, oldDefinition.pullDirection)))
{
// pull direction allows edges but parting object does not.
if (isQueryEmpty(context, qEntityFilter(definition.pullDirection, EntityType.EDGE)) &&
!isQueryEmpty(context, definition.pullDirection))
{
definition.partingObject = definition.pullDirection;
}
}
return definition;
}
/**
* @internal
* Manipulator change function for `bodyDraft` feature.
*/
export function bodyDraftManipulatorChange(context is Context, definition is map, newManipulators is map) returns map
{
if (newManipulators[flipManipulatorId] != undefined)
{
definition.flipPullDirection = !definition.flipPullDirection;
}
return definition;
}