-
Notifications
You must be signed in to change notification settings - Fork 2
/
chamfer.fs
153 lines (134 loc) · 6.5 KB
/
chamfer.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
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.
// Imports used in interface
export import(path : "onshape/std/chamfermethod.gen.fs", version : "✨");
export import(path : "onshape/std/chamfertype.gen.fs", version : "✨");
export import(path : "onshape/std/edgeBlendCommon.fs", version : "✨");
export import(path : "onshape/std/query.fs", version : "✨");
// Imports used internally
import(path : "onshape/std/containers.fs", version : "✨");
import(path : "onshape/std/feature.fs", version : "✨");
import(path : "onshape/std/math.fs", version : "✨");
import(path : "onshape/std/matrix.fs", version : "✨");
import(path : "onshape/std/sheetMetalAttribute.fs", version : "✨");
import(path : "onshape/std/sheetMetalCornerBreakAttributeBased.fs", version : "✨");
import(path : "onshape/std/sheetMetalUtils.fs", version : "✨");
import(path : "onshape/std/valueBounds.fs", version : "✨");
/**
* The chamfer feature directly performs an [opChamfer] operation.
*/
annotation { "Feature Type Name" : "Chamfer", "Filter Selector" : "allparts" }
export const chamfer = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Entities to chamfer",
"Filter" : ((ActiveSheetMetal.NO && ((EntityType.EDGE && EdgeTopology.TWO_SIDED) || EntityType.FACE))
|| (EntityType.EDGE && SheetMetalDefinitionEntityType.VERTEX))
&& ConstructionObject.NO && SketchObject.NO && ModifiableEntityOnly.YES,
"AdditionalBoxSelectFilter" : EntityType.EDGE }
definition.entities is Query;
chamferCommonOptions(definition);
if (definition.chamferType == ChamferType.OFFSET_ANGLE ||
definition.chamferType == ChamferType.TWO_OFFSETS)
{
annotation {"Name" : "Direction overrides",
"Filter" : ((ActiveSheetMetal.NO && (EntityType.EDGE && EdgeTopology.TWO_SIDED))
|| (EntityType.EDGE && SheetMetalDefinitionEntityType.VERTEX))
&& ConstructionObject.NO && SketchObject.NO && ModifiableEntityOnly.YES,
"AdditionalBoxSelectFilter" : EntityType.EDGE }
definition.directionOverrides is Query;
}
//tangent propagation option (checkbox)
annotation { "Name" : "Tangent propagation", "Default" : true }
definition.tangentPropagation is boolean;
}
{
verifyNoMesh(context, definition, "entities");
if (!isAtVersionOrLater(context, FeatureScriptVersionNumber.V2211_CHAMFER_IMPROVEMENTS))
{
if (definition.chamferMethod == ChamferMethod.FACE_OFFSET && definition.chamferType != ChamferType.EQUAL_OFFSETS &&
!isQueryEmpty(context, definition.directionOverrides))
{
reportFeatureInfo(context, id, ErrorStringEnum.CHAMFER_HELD_BACK);
}
}
if (isAtVersionOrLater(context, FeatureScriptVersionNumber.V575_SHEET_METAL_FILLET_CHAMFER))
{
sheetMetalAwareChamfer(context, id, definition);
}
else
{
standardChamfer(context, id, definition);
}
}, { oppositeDirection : false, tangentPropagation : false, chamferMethod : ChamferMethod.FACE_OFFSET, directionOverrides : qNothing() });
/*
* Call sheetMetalCornerBreakAttributeBased on active sheet metal entities and opChamfer on the remaining entities
*/
function sheetMetalAwareChamfer(context is Context, id is Id, definition is map)
{
var separatedQueries = separateSheetMetalQueries(context, definition.entities);
var hasSheetMetalQueries = !isQueryEmpty(context, separatedQueries.sheetMetalQueries);
var hasNonSheetMetalQueries = !isQueryEmpty(context, separatedQueries.nonSheetMetalQueries);
if (!hasSheetMetalQueries && !hasNonSheetMetalQueries)
{
throw regenError(ErrorStringEnum.CHAMFER_SELECT_EDGES, ["entities"]);
}
if (hasSheetMetalQueries)
{
if (definition.chamferMethod != ChamferMethod.FACE_OFFSET)
{
throw regenError(ErrorStringEnum.SHEET_METAL_CHAMFER_OPTIONS_USE_CORNER_BREAK, ["chamferMethod"]);
}
if (definition.chamferType != ChamferType.EQUAL_OFFSETS)
{
if (definition.chamferType == ChamferType.TWO_OFFSETS)
{
throw regenError(ErrorStringEnum.SHEET_METAL_CHAMFER_OPTIONS_USE_CORNER_BREAK, ["chamferType"]);
}
else if (definition.chamferType == ChamferType.OFFSET_ANGLE)
{
throw regenError(ErrorStringEnum.SHEET_METAL_CHAMFER_OPTIONS_USE_CORNER_BREAK, ["chamferType"]);
}
else
{
throw regenError(ErrorStringEnum.SHEET_METAL_CHAMFER_OPTIONS_USE_CORNER_BREAK, ["chamferType"]);
}
}
reportFeatureInfo(context, id, ErrorStringEnum.SHEET_METAL_USE_CORNER_BREAK_INFO);
var cornerBreakDefinition = {
"entities" : separatedQueries.sheetMetalQueries,
"cornerBreakStyle" : SMCornerBreakStyle.CHAMFER,
"range" : definition.width
};
callSubfeatureAndProcessStatus(id, sheetMetalCornerBreakAttributeBased, context, id + "smChamfer", cornerBreakDefinition);
}
if (hasNonSheetMetalQueries)
{
definition.entities = separatedQueries.nonSheetMetalQueries;
standardChamfer(context, id, definition);
}
}
/*
* Call opChamfer on non-sheet metal edges
*/
function standardChamfer(context is Context, id is Id, definition is map)
{
if (isAtVersionOrLater(context, FeatureScriptVersionNumber.V2211_CHAMFER_IMPROVEMENTS))
{
opChamfer(context, id, definition);
return;
}
if (isAtVersionOrLater(context, FeatureScriptVersionNumber.V414_ASYMMETRIC_CHAMFER_MIRROR_BUG) &&
(definition.chamferType == ChamferType.OFFSET_ANGLE || definition.chamferType == ChamferType.TWO_OFFSETS))
{
var fullTransform = getFullPatternTransform(context);
if (abs(determinant(fullTransform.linear) + 1) < TOLERANCE.zeroLength) //det == -1
{
//we have a reflection on the input body, flip direction
definition.oppositeDirection = !definition.oppositeDirection;
}
}
opChamfer(context, id, definition);
}