-
Notifications
You must be signed in to change notification settings - Fork 2
/
fillSurface.fs
243 lines (214 loc) · 9.81 KB
/
fillSurface.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
FeatureScript ✨; /* Automatically generated version */
// This module is part of the FeatureScript Standard Library and is distributed under the MIT License.
// See the LICENSE tab for the license text.
// Copyright (c) 2013-Present PTC Inc.
export import(path : "onshape/std/geometriccontinuity.gen.fs", version : "✨");
export import(path : "onshape/std/tool.fs", version : "✨");
import(path : "onshape/std/boolean.fs", version : "✨");
import(path : "onshape/std/containers.fs", version : "✨");
import(path : "onshape/std/feature.fs", version : "✨");
import(path : "onshape/std/query.fs", version : "✨");
import(path : "onshape/std/topologyUtils.fs", version : "✨");
import(path : "onshape/std/transform.fs", version : "✨");
import(path : "onshape/std/units.fs", version : "✨");
import(path : "onshape/std/valueBounds.fs", version : "✨");
/**
* @internal
* Whether we're using the guides as precise constraints or sampling them
*/
export enum FillConstraintMode
{
annotation { "Name" : "Precise" }
PRECISE,
annotation { "Name" : "Sampled" }
SAMPLED
}
/**
* @internal
* The bounds for number of samples used in constraint sampling.
*/
export const SAMPLE_BOUNDS =
{
(unitless) : [1, 5, 50]
} as IntegerBoundSpec;
/**
* Creates a surface bounded by input edges with prescribed continuity conditions, using [opFillSurface].
*/
annotation { "Feature Type Name" : "Fill" ,
"Filter Selector" : "allparts",
"Editing Logic Function" : "fillEditLogic" }
export const fill = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Preselection", "UIHint" : UIHint.ALWAYS_HIDDEN, "Filter" : ModifiableEntityOnly.YES && ((EntityType.EDGE && ConstructionObject.NO) || (EntityType.BODY && BodyType.WIRE && SketchObject.NO))}
definition.preselectedEntities is Query;
surfaceOperationTypePredicate(definition);
annotation { "Name" : "Edges", "Item name" : "edge", "Driven query" : "entities", "Item label template" : "[#continuity] #entities", "UIHint" : UIHint.SHOW_CREATE_SELECTION }
definition.edges is array;
for (var edge in definition.edges)
{
annotation { "Name" : "Edges", "Filter" : ModifiableEntityOnly.YES && ((EntityType.EDGE && ConstructionObject.NO) || (EntityType.BODY && BodyType.WIRE && SketchObject.NO)),
"UIHint" : UIHint.ALWAYS_HIDDEN }
edge.entities is Query;
annotation { "Name" : "Continuity", "UIHint" : [ UIHint.SHOW_LABEL, UIHint.MATCH_LAST_ARRAY_ITEM ] }
edge.continuity is GeometricContinuity;
if (edge.continuity != GeometricContinuity.G0 && edge.adjacentFaces != undefined)
{
annotation { "Name" : "Adjacent faces", "Filter" : EntityType.FACE }
edge.adjacentFaces is Query;
}
}
annotation {"Name" : "Guides"}
definition.addGuides is boolean;
if (definition.addGuides)
{
annotation { "Name" : "Vertices or curves",
"Filter" : EntityType.VERTEX || EntityType.EDGE || (EntityType.BODY && BodyType.WIRE && SketchObject.NO)}
definition.guideEntities is Query;
annotation {"Name" : "Mode"}
definition.constraintMode is FillConstraintMode;
if (definition.constraintMode == FillConstraintMode.SAMPLED)
{
annotation {"Name" : "Sample size" }
isInteger(definition.sampleSize, SAMPLE_BOUNDS);
}
}
annotation {"Name" : "Show isocurves"}
definition.showIsocurves is boolean;
if (definition.showIsocurves)
{
annotation {"Name" : "Count" }
isInteger(definition.curveCount, ISO_GRID_BOUNDS);
}
surfaceJoinStepScopePredicate(definition);
}
{
if (definition.addGuides)
{
verifyNoMesh(context, definition, "guideEntities");
}
verifyNonemptyArray(context, definition, "edges", ErrorStringEnum.FILL_SURFACE_NO_EDGES);
if (!definition.addGuides)
definition.guideEntities = qNothing();
definition.useSampling = (definition.constraintMode == FillConstraintMode.SAMPLED);
definition = updateEdgeSelections(context, definition);
verifyNoMesh(context, {"edges" : definition.allEdges}, "edges");
var remainingTransform = getRemainderPatternTransform(context,
{"references" : definition.allEdges });
opFillSurface(context, id, definition);
transformResultIfNecessary(context, id, remainingTransform);
const reconstructOp = function(id)
{
opFillSurface(context, id, updateEdgeSelections(context, definition));
transformResultIfNecessary(context, id, remainingTransform);
};
if (definition.surfaceOperationType == NewSurfaceOperationType.ADD)
{
if (isAtVersionOrLater(context, FeatureScriptVersionNumber.V1197_DETECT_SURFACE_JOIN_CPP))
{
joinSurfaceBodiesWithAutoMatching(context, id, definition, true, reconstructOp);
}
else
{
var matches = createTopologyMatchesForSurfaceJoin(context, id, definition, qCreatedBy(id, EntityType.EDGE),
definition.allEdges, remainingTransform);
checkForNotJoinableSurfacesInScope(context, id, definition, matches);
joinSurfaceBodies(context, id, matches, true, reconstructOp);
}
if (getFeatureInfo(context, id) == ErrorStringEnum.BOOLEAN_NO_TARGET_SURFACE ||
(getFeatureError(context, id) != undefined &&
getFeatureError(context, id) != ErrorStringEnum.BOOLEAN_NO_TARGET_SURFACE) )
{
//update error message to fill related one, and also error out when no matches could be found
reportFeatureError(context, id, ErrorStringEnum.FILL_SURFACE_ATTACH_FAIL);
}
}
}, { showIsocurves : false, preselectedEntities : qNothing(), defaultSurfaceScope : true, useSampling : false,
addGuides : false, constraintMode : FillConstraintMode.PRECISE, curveCount : 10, sampleSize : 5});
function updateEdgeSelections(context is Context, definition is map) returns map
{
var edgesG0 = [];
var edgesG1 = [];
var edgesG2 = [];
var allEdges = [];
var adjacentFaces = [];
if (isAtVersionOrLater(context, FeatureScriptVersionNumber.V1890_FOLLOW_LAMINAR_SOURCE_COINCIDENCE_CHECK))
{
for (var edge in definition.edges)
{
var laminarEdges = qConstructionFilter(followWireEdgesToLaminarSource(context, edge.entities), ConstructionObject.NO);
allEdges = append(allEdges, laminarEdges);
if (edge.continuity == GeometricContinuity.G0)
{
edgesG0 = append(edgesG0, laminarEdges);
}
else
{
if (edge.adjacentFaces != undefined && !isQueryEmpty(context, edge.adjacentFaces))
{
adjacentFaces = append(adjacentFaces, {"edges" : laminarEdges,
"faces" : edge.adjacentFaces});
}
}
if (edge.continuity == GeometricContinuity.G1)
{
edgesG1 = append(edgesG1, laminarEdges);
}
if (edge.continuity == GeometricContinuity.G2)
{
edgesG2 = append(edgesG2, laminarEdges);
}
}
definition.edgesG0 = qUnion(edgesG0);
definition.edgesG1 = qUnion(edgesG1);
definition.edgesG2 = qUnion(edgesG2);
definition.allEdges = qUnion(allEdges);
definition.adjacentFaces = adjacentFaces;
}
else
{
for (var edge in definition.edges)
{
allEdges = append(allEdges, edge.entities);
if (edge.continuity == GeometricContinuity.G0)
{
edgesG0 = append(edgesG0, edge.entities);
}
if (edge.continuity == GeometricContinuity.G1)
{
edgesG1 = append(edgesG1, edge.entities);
}
if (edge.continuity == GeometricContinuity.G2)
{
edgesG2 = append(edgesG2, edge.entities);
}
}
definition.edgesG0 = qConstructionFilter(followWireEdgesToLaminarSource(context, qUnion(edgesG0)), ConstructionObject.NO);
definition.edgesG1 = qConstructionFilter(followWireEdgesToLaminarSource(context, qUnion(edgesG1)), ConstructionObject.NO);
definition.edgesG2 = qConstructionFilter(followWireEdgesToLaminarSource(context, qUnion(edgesG2)), ConstructionObject.NO);
definition.allEdges = qConstructionFilter(followWireEdgesToLaminarSource(context, qUnion(allEdges)), ConstructionObject.NO);
}
return definition;
}
/**
* @internal
* Editing logic function for `surface fill` feature.
*/
export function fillEditLogic(context is Context, id is Id, oldDefinition is map, definition is map,
specifiedParameters is map, hiddenBodies is Query) returns map
{
if (oldDefinition == {}) //preselection processing only
{
const preselections = evaluateQuery(context, definition.preselectedEntities);
if (@size(preselections) > 0)
{
for (var selection in preselections)
{
definition.edges = append(definition.edges, {"entities" : qUnion([selection]), "continuity" : GeometricContinuity.G0});
}
}
definition.preselectedEntities = qNothing();
}
var updatedDefinition = updateEdgeSelections(context, definition);
return surfaceOperationTypeEditLogic(context, id, definition, specifiedParameters, updatedDefinition.allEdges, hiddenBodies);
}