Skip to content

Commit 21bed56

Browse files
wip pin label dimension
1 parent a1d16be commit 21bed56

5 files changed

Lines changed: 109 additions & 8 deletions

File tree

packages/dev/occt-worker/lib/api/occt/dimensions.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class OCCTDimensions {
1010
}
1111

1212
/**
13-
* Creates simple linear length dimension between two points - measuring units
13+
* Creates simple linear length dimension between two points - measuring units. You decide what kind of units you re using by providing a suffix.
1414
* @param inputs two points, direction, label size, label normal direction, offset, and unit suffix, decimal rounding place
1515
* @returns compound wires representing dimensions
1616
* @group simple
@@ -22,8 +22,8 @@ export class OCCTDimensions {
2222
}
2323

2424
/**
25-
* Creates simple angular dimension
26-
* @param inputs two points, direction, label size, label normal direction, offset, and unit suffix, decimal rounding place
25+
* Creates simple angular dimension. By default we output degrees, but you can opt to use radians.
26+
* @param inputs a center, two directions, radius and various label parameters
2727
* @returns compound wires representing dimension
2828
* @group simple
2929
* @shortname angular dimension
@@ -32,4 +32,16 @@ export class OCCTDimensions {
3232
simpleAngularDimension(inputs: Inputs.OCCT.SimpleAngularDimensionDto): Promise<Inputs.OCCT.TopoDSCompoundPointer> {
3333
return this.occWorkerManager.genericCallToWorkerPromise("dimensions.simpleAngularDimension", inputs);
3434
}
35+
36+
/**
37+
* Creates pin label. It can be used to explain things about the models or mark important things in the 3D scene
38+
* @param inputs a start and end point, direction and parameters for the label
39+
* @returns compound wires representing dimension
40+
* @group simple
41+
* @shortname pin with label
42+
* @drawable true
43+
*/
44+
pinWithLabel(inputs: Inputs.OCCT.PinWithLabelDto): Promise<Inputs.OCCT.TopoDSCompoundPointer> {
45+
return this.occWorkerManager.genericCallToWorkerPromise("dimensions.pinWithLabel", inputs);
46+
}
3547
}

packages/dev/occt/lib/api/inputs/occ-inputs.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6035,7 +6035,7 @@ export namespace OCCT {
60356035
if (direction1 !== undefined) { this.direction1 = direction1; }
60366036
if (direction2 !== undefined) { this.direction2 = direction2; }
60376037
if (center !== undefined) { this.center = center; }
6038-
if( radius !== undefined) { this.radius = radius; }
6038+
if (radius !== undefined) { this.radius = radius; }
60396039
if (offsetFromCenter !== undefined) { this.offsetFromCenter = offsetFromCenter; }
60406040
if (crossingSize !== undefined) { this.extraSize = crossingSize; }
60416041
if (radians !== undefined) { this.radians = radians; }
@@ -6118,4 +6118,59 @@ export namespace OCCT {
61186118
*/
61196119
radians = false;
61206120
}
6121+
export class PinWithLabelDto {
6122+
constructor(startPoint?: Base.Point3, endPoint?: Base.Point3, direction?: Base.Vector3, offsetFromStart?: number, label?: string, labelOffset?: number, labelSize?: number) {
6123+
if (startPoint !== undefined) { this.startPoint = startPoint; }
6124+
if (endPoint !== undefined) { this.endPoint = endPoint; }
6125+
if (direction !== undefined) { this.direction = direction; }
6126+
if (offsetFromStart !== undefined) { this.offsetFromStart = offsetFromStart; }
6127+
if (label !== undefined) { this.label = label; }
6128+
if (labelOffset !== undefined) { this.labelOffset = labelOffset; }
6129+
if (labelSize !== undefined) { this.labelSize = labelSize; }
6130+
}
6131+
/**
6132+
* The start point for dimension
6133+
* @default [0, 0, 0]
6134+
*/
6135+
startPoint: Base.Point3 = [0, 0, 0];
6136+
/**
6137+
* The end point for dimension
6138+
* @default [0, 5, 2]
6139+
*/
6140+
endPoint?: Base.Point3 = [0, 5, 2];
6141+
/**
6142+
* The dimension direction (must include length)
6143+
* @default [0, 0, 1]
6144+
*/
6145+
direction?: Base.Vector3 = [0, 0, 1];
6146+
/**
6147+
* Offset from the start point
6148+
* @default 0
6149+
* @minimum 0
6150+
* @maximum Infinity
6151+
* @step 0.1
6152+
*/
6153+
offsetFromStart? = 0;
6154+
/**
6155+
* The dimension label
6156+
* @default Pin
6157+
*/
6158+
label? = "Pin";
6159+
/**
6160+
* The dimension label offset
6161+
* @default 0.3
6162+
* @minimum -Infinity
6163+
* @maximum Infinity
6164+
* @step 0.1
6165+
*/
6166+
labelOffset? = 0.3;
6167+
/**
6168+
* The dimension label size
6169+
* @default 0.1
6170+
* @minimum 0
6171+
* @maximum Infinity
6172+
* @step 0.1
6173+
*/
6174+
labelSize? = 0.1;
6175+
}
61216176
}

packages/dev/occt/lib/occ-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class OccHelper {
8484
this.wiresService = new WiresService(occ, this.occRefReturns, this.vector, this.shapesHelperService, this.shapeGettersService, this.transformsService,
8585
this.enumService, this.entitiesService, this.converterService, this.geomService, this.edgesService, this.textService, this.operationsService);
8686

87-
this.dimensionsService = new DimensionsService(this.vector, this.point, this.transformsService,
87+
this.dimensionsService = new DimensionsService(this.math, this.vector, this.point, this.transformsService,
8888
this.converterService, this.entitiesService, this.edgesService, this.wiresService);
8989

9090
this.verticesService.wiresService = this.wiresService;

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import * as Inputs from "../../api/inputs/inputs";
77
import { TransformsService } from "./transforms.service";
88
import { ConverterService } from "./converter.service";
99
import { WiresService } from "./wires.service";
10-
import { Point, Vector } from "@bitbybit-dev/base";
10+
import { MathBitByBit, Point, Vector } from "@bitbybit-dev/base";
1111
import { EdgesService } from "./edges.service";
1212
import { EntitiesService } from "./entities.service";
1313

1414
export class DimensionsService {
1515

1616
constructor(
17+
private readonly math: MathBitByBit,
1718
private readonly vector: Vector,
1819
private readonly point: Point,
1920
private readonly transformsService: TransformsService,
@@ -189,13 +190,17 @@ export class DimensionsService {
189190
const wireArc = this.wiresService.createWireFromEdge({ shape: arc });
190191

191192
const midPt = this.wiresService.midPointOnWire({ shape: wireArc });
192-
const angleDeg = this.vector.angleBetween({
193+
let angle = this.vector.angleBetween({
193194
first: inputs.direction1,
194195
second: inputs.direction2,
195196
}) as number;
196197

198+
if (inputs.radians) {
199+
angle = this.math.degToRad({number: angle});
200+
}
201+
197202
const txtOpt = new Inputs.OCCT.TextWiresDto();
198-
txtOpt.text = angleDeg.toFixed(inputs.decimalPlaces) + " " + inputs.labelSuffix;
203+
txtOpt.text = angle.toFixed(inputs.decimalPlaces) + " " + inputs.labelSuffix;
199204
txtOpt.xOffset = 0;
200205
txtOpt.yOffset = 0;
201206
txtOpt.height = inputs.labelSize;
@@ -239,4 +244,28 @@ export class DimensionsService {
239244
return res;
240245
}
241246

247+
pinWithLabel(inputs: Inputs.OCCT.PinWithLabelDto): TopoDS_Compound {
248+
const pinLine = this.wiresService.createLineWireWithExtensions({
249+
start: inputs.startPoint,
250+
end: inputs.endPoint,
251+
extensionStart: -inputs.offsetFromStart,
252+
extensionEnd: 0,
253+
});
254+
255+
const text = this.wiresService.textWiresWithData({
256+
text: inputs.label,
257+
xOffset: 0,
258+
yOffset: 0,
259+
height: inputs.labelSize,
260+
centerOnOrigin: true,
261+
});
262+
const labelTransformed = this.transformsService.translate({
263+
shape: text.compound,
264+
translation: inputs.endPoint,
265+
});
266+
267+
const res = this.converterService.makeCompound({ shapes: [pinLine, labelTransformed] });
268+
return res;
269+
}
270+
242271
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,10 @@ export class OCCTDimensions {
1717
simpleAngularDimension(inputs: Inputs.OCCT.SimpleAngularDimensionDto): TopoDS_Compound {
1818
return this.och.dimensionsService.simpleAngularDimension(inputs);
1919
}
20+
21+
pinWithLabel(inputs: Inputs.OCCT.PinWithLabelDto): TopoDS_Compound {
22+
return this.och.dimensionsService.pinWithLabel(inputs);
23+
}
24+
2025

2126
}

0 commit comments

Comments
 (0)