Skip to content

Commit 7a3621f

Browse files
added intermediate shape deletion for dimensions
1 parent d2c45d0 commit 7a3621f

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

packages/dev/occt/lib/services/base/dimensions.service.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
TopoDS_Compound,
33
TopoDS_Edge,
4+
TopoDS_Shape,
45
} from "../../../bitbybit-dev-occt/bitbybit-dev-occt";
56
import * as Inputs from "../../api/inputs/inputs";
67
import { TransformsService } from "./transforms.service";
@@ -23,13 +24,14 @@ export class DimensionsService {
2324
) { }
2425

2526
simpleLinearLengthDimension(inputs: Inputs.OCCT.SimpleLinearLengthDimensionDto): TopoDS_Compound {
26-
27+
const shapesToDelete: TopoDS_Shape[] = [];
2728
const lineBetweenPoints = this.wiresService.createLineWireWithExtensions({
2829
start: inputs.start,
2930
end: inputs.end,
3031
extensionStart: inputs.crossingSize,
3132
extensionEnd: inputs.crossingSize,
3233
});
34+
shapesToDelete.push(lineBetweenPoints);
3335

3436
const translatedLine = this.transformsService.translate({
3537
shape: lineBetweenPoints,
@@ -92,6 +94,8 @@ export class DimensionsService {
9294
axis: [0, 1, 0],
9395
});
9496

97+
shapesToDelete.push(...txt.shapes.map((s) => s.shape));
98+
9599
const alignedLabelTxtToDir = this.transformsService.alignNormAndAxis({
96100
shape: rotated,
97101
fromOrigin: [0, 0, 0],
@@ -102,6 +106,8 @@ export class DimensionsService {
102106
toAx: dirStartEnd,
103107
});
104108

109+
shapesToDelete.push(rotated);
110+
105111
const normDir = this.vector.normalized({ vector: inputs.direction });
106112
const offsetLabelVec = this.vector.mul({ vector: normDir, scalar: inputs.labelOffset });
107113

@@ -115,18 +121,28 @@ export class DimensionsService {
115121
translation: addToDir
116122
});
117123

124+
shapesToDelete.push(alignedLabelTxtToDir);
125+
118126
const res = this.converterService.makeCompound({ shapes: [translatedLine, startLineToTranslatedPoint, endLineToTranslatedPoint, labelTransformed] });
119127

128+
// delete shapes
129+
shapesToDelete.forEach((shape) => {
130+
shape.delete();
131+
});
132+
120133
return res;
121134
}
122135

123136
simpleAngularDimension(inputs: Inputs.OCCT.SimpleAngularDimensionDto): TopoDS_Compound {
137+
const shapesToDelete: TopoDS_Shape[] = [];
138+
124139
const normDir1 = this.vector.normalized({ vector: inputs.direction1 });
125140
const endVec = this.vector.mul({ vector: normDir1, scalar: inputs.radius }) as Inputs.Base.Point3;
126141
const endPt = this.point.translatePoints({
127142
points: [endVec],
128143
translation: inputs.center,
129144
})[0];
145+
130146
const line1WithExt = this.wiresService.createLineWireWithExtensions({
131147
start: inputs.center,
132148
end: endPt,
@@ -153,7 +169,7 @@ export class DimensionsService {
153169
point3: endPt2,
154170
reverseNormal: true,
155171
});
156-
172+
157173
const normalThreePointsRev = this.point.normalFromThreePoints({
158174
point1: inputs.center,
159175
point2: endPt,
@@ -162,12 +178,14 @@ export class DimensionsService {
162178
});
163179

164180
const circ = this.entitiesService.createCircle(inputs.radius, inputs.center, normalThreePointsRev, Inputs.OCCT.typeSpecificityEnum.edge) as TopoDS_Edge;
181+
shapesToDelete.push(circ);
165182
const arc = this.edgesService.arcFromCircleAndTwoPoints({
166183
circle: circ,
167184
start: endPt,
168185
end: endPt2,
169186
sense: false,
170187
});
188+
shapesToDelete.push(arc);
171189
const wireArc = this.wiresService.createWireFromEdge({ shape: arc });
172190

173191
const midPt = this.wiresService.midPointOnWire({ shape: wireArc });
@@ -183,13 +201,13 @@ export class DimensionsService {
183201
txtOpt.height = inputs.labelSize;
184202
txtOpt.centerOnOrigin = true;
185203
const txt = this.wiresService.textWiresWithData(txtOpt);
186-
204+
187205
const vectorToMid = this.vector.sub({
188206
first: midPt,
189207
second: inputs.center,
190208
}) as Inputs.Base.Vector3;
191209
const normVecToMid = this.vector.normalized({ vector: vectorToMid }) as Inputs.Base.Vector3;
192-
210+
193211
const alignedLabelTxtToDir = this.transformsService.alignNormAndAxis({
194212
shape: txt.compound,
195213
fromOrigin: [0, 0, 0],
@@ -199,6 +217,7 @@ export class DimensionsService {
199217
toNorm: normalThreePoints,
200218
toAx: normVecToMid,
201219
});
220+
shapesToDelete.push(...txt.shapes.map((s) => s.shape));
202221
const offsetLabelVec = this.vector.mul({ vector: normVecToMid, scalar: inputs.labelOffset });
203222
const addToDir = this.vector.add({
204223
first: midPt,
@@ -208,8 +227,15 @@ export class DimensionsService {
208227
shape: alignedLabelTxtToDir,
209228
translation: addToDir
210229
});
230+
shapesToDelete.push(alignedLabelTxtToDir);
211231

212232
const res = this.converterService.makeCompound({ shapes: [line1WithExt, line2WithExt, wireArc, labelTransformed] });
233+
234+
// delete shapes
235+
shapesToDelete.forEach((shape) => {
236+
shape.delete();
237+
});
238+
213239
return res;
214240
}
215241

0 commit comments

Comments
 (0)