Skip to content

Commit 451c0dc

Browse files
Merge pull request #62 from bitbybit-dev/develop
0.19.7
2 parents 3d5bb8e + 1b94b12 commit 451c0dc

12 files changed

+534
-138
lines changed

packages/dev/occt/bitbybit-dev-occt/bitbybit-dev-occt.d.ts

+33
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,35 @@ export declare class GeomAPI {
20712071
delete(): void;
20722072
}
20732073

2074+
export declare class GeomAPI_ProjectPointOnCurve {
2075+
Init_1(P: gp_Pnt, Curve: Handle_Geom_Curve): void;
2076+
Init_2(P: gp_Pnt, Curve: Handle_Geom_Curve, Umin: Standard_Real, Usup: Standard_Real): void;
2077+
Init_3(Curve: Handle_Geom_Curve, Umin: Standard_Real, Usup: Standard_Real): void;
2078+
Perform(P: gp_Pnt): void;
2079+
NbPoints(): Graphic3d_ZLayerId;
2080+
Point(Index: Graphic3d_ZLayerId): gp_Pnt;
2081+
Parameter_1(Index: Graphic3d_ZLayerId): Standard_Real;
2082+
Parameter_2(Index: Graphic3d_ZLayerId, U: Standard_Real): void;
2083+
Distance(Index: Graphic3d_ZLayerId): Standard_Real;
2084+
NearestPoint(): gp_Pnt;
2085+
LowerDistanceParameter(): Standard_Real;
2086+
LowerDistance(): Standard_Real;
2087+
Extrema(): Extrema_ExtPC;
2088+
delete(): void;
2089+
}
2090+
2091+
export declare class GeomAPI_ProjectPointOnCurve_1 extends GeomAPI_ProjectPointOnCurve {
2092+
constructor();
2093+
}
2094+
2095+
export declare class GeomAPI_ProjectPointOnCurve_2 extends GeomAPI_ProjectPointOnCurve {
2096+
constructor(P: gp_Pnt, Curve: Handle_Geom_Curve);
2097+
}
2098+
2099+
export declare class GeomAPI_ProjectPointOnCurve_3 extends GeomAPI_ProjectPointOnCurve {
2100+
constructor(P: gp_Pnt, Curve: Handle_Geom_Curve, Umin: Standard_Real, Usup: Standard_Real);
2101+
}
2102+
20742103
export declare class GeomAPI_PointsToBSpline {
20752104
Init_1(Points: TColgp_Array1OfPnt, DegMin: Graphic3d_ZLayerId, DegMax: Graphic3d_ZLayerId, Continuity: GeomAbs_Shape, Tol3D: Standard_Real): void;
20762105
Init_2(Points: TColgp_Array1OfPnt, ParType: Approx_ParametrizationType, DegMin: Graphic3d_ZLayerId, DegMax: Graphic3d_ZLayerId, Continuity: GeomAbs_Shape, Tol3D: Standard_Real): void;
@@ -10595,6 +10624,10 @@ export type OpenCascadeInstance = {FS: typeof FS} & {
1059510624
ShapeUpgrade_UnifySameDomain_1: typeof ShapeUpgrade_UnifySameDomain_1;
1059610625
ShapeUpgrade_UnifySameDomain_2: typeof ShapeUpgrade_UnifySameDomain_2;
1059710626
GeomAPI: typeof GeomAPI;
10627+
GeomAPI_ProjectPointOnCurve: typeof GeomAPI_ProjectPointOnCurve;
10628+
GeomAPI_ProjectPointOnCurve_1: typeof GeomAPI_ProjectPointOnCurve_1;
10629+
GeomAPI_ProjectPointOnCurve_2: typeof GeomAPI_ProjectPointOnCurve_2;
10630+
GeomAPI_ProjectPointOnCurve_3: typeof GeomAPI_ProjectPointOnCurve_3;
1059810631
GeomAPI_PointsToBSpline: typeof GeomAPI_PointsToBSpline;
1059910632
GeomAPI_PointsToBSpline_1: typeof GeomAPI_PointsToBSpline_1;
1060010633
GeomAPI_PointsToBSpline_2: typeof GeomAPI_PointsToBSpline_2;
Binary file not shown.

packages/dev/occt/bitbybit-dev-occt/bitbybit-dev-occt.yml

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
- symbol: Geom2d_VectorWithMagnitude
192192
- symbol: GeomAPI
193193
- symbol: GeomAPI_PointsToBSpline
194+
- symbol: GeomAPI_ProjectPointOnCurve
194195
- symbol: GeomAbs_JoinType
195196
- symbol: GeomAbs_Shape
196197
- symbol: GeomLProp_SLProps
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import ocFullJS from "./bitbybit-dev-occt.js";
2+
3+
const initOpenCascade = ({
4+
mainJS = ocFullJS,
5+
mainWasm = "https://cdn.jsdelivr.net/gh/bitbybit-dev/[email protected]/wasm/bitbybit-dev-occt.a9520351.wasm",
6+
worker = undefined,
7+
libs = [],
8+
module = {},
9+
} = {}) => {
10+
return new Promise((resolve, reject) => {
11+
new mainJS({
12+
locateFile(path) {
13+
if (path.endsWith('.wasm')) {
14+
return mainWasm;
15+
}
16+
if (path.endsWith('.worker.js') && !!worker) {
17+
return worker;
18+
}
19+
return path;
20+
},
21+
...module
22+
}).then(async oc => {
23+
for (let lib of libs) {
24+
await oc.loadDynamicLibrary(lib, { loadAsync: true, global: true, nodelete: true, allowUndefined: false });
25+
}
26+
resolve(oc);
27+
});
28+
});
29+
};
30+
31+
export default initOpenCascade;

packages/dev/occt/bitbybit-dev-occt/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import ocFullJS from "./bitbybit-dev-occt.js";
2+
import ocFullWasm from "./bitbybit-dev-occt.wasm";
23

34
const initOpenCascade = ({
45
mainJS = ocFullJS,
5-
mainWasm = "https://cdn.jsdelivr.net/gh/bitbybit-dev/[email protected]/wasm/bitbybit-dev-occt.a9520351.wasm",
6+
mainWasm = ocFullWasm,
67
worker = undefined,
78
libs = [],
89
module = {},

packages/dev/occt/generate-prod-build-yaml.js

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ async function start() {
143143
"GeomLib",
144144
"GeomAPI",
145145
"GeomAPI_PointsToBSpline",
146+
"GeomAPI_ProjectPointOnCurve",
146147
"Geom_BezierCurve",
147148
"BitByBitDev",
148149
"gp_Trsf2d",

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

+46-4
Original file line numberDiff line numberDiff line change
@@ -3581,9 +3581,11 @@ export namespace OCCT {
35813581
face: U;
35823582
}
35833583
export class PipeWiresCylindricalDto<T> {
3584-
constructor(shapes?: T[], radius?: number) {
3584+
constructor(shapes?: T[], radius?: number, withContact?: boolean, withCorrection?: boolean) {
35853585
if (shapes !== undefined) { this.shapes = shapes; }
35863586
if (radius !== undefined) { this.radius = radius; }
3587+
if (withContact !== undefined) { this.withContact = withContact; }
3588+
if (withCorrection !== undefined) { this.withCorrection; }
35873589
}
35883590
/**
35893591
* Wire paths to pipe
@@ -3598,11 +3600,23 @@ export namespace OCCT {
35983600
* @step 1
35993601
*/
36003602
radius = 0.1;
3603+
/**
3604+
* If withContact is true, the section is translated to be in contact with the spine.
3605+
* @default false
3606+
*/
3607+
withContact = false;
3608+
/**
3609+
* If withCorrection is true, the section is rotated to be orthogonal to the spine's tangent in the correspondent point.
3610+
* @default false
3611+
*/
3612+
withCorrection = false;
36013613
}
36023614
export class PipeWireCylindricalDto<T> {
3603-
constructor(shape?: T, radius?: number) {
3615+
constructor(shape?: T, radius?: number, withContact?: boolean, withCorrection?: boolean) {
36043616
if (shape !== undefined) { this.shape = shape; }
36053617
if (radius !== undefined) { this.radius = radius; }
3618+
if (withContact !== undefined) { this.withContact = withContact; }
3619+
if (withCorrection !== undefined) { this.withCorrection; }
36063620
}
36073621
/**
36083622
* Wire path to pipe
@@ -3617,12 +3631,24 @@ export namespace OCCT {
36173631
* @step 1
36183632
*/
36193633
radius = 0.1;
3634+
/**
3635+
* If withContact is true, the section is translated to be in contact with the spine.
3636+
* @default false
3637+
*/
3638+
withContact = false;
3639+
/**
3640+
* If withCorrection is true, the section is rotated to be orthogonal to the spine's tangent in the correspondent point.
3641+
* @default false
3642+
*/
3643+
withCorrection = false;
36203644
}
36213645
export class PipePolygonWireNGonDto<T> {
3622-
constructor(shapes?: T, radius?: number, nrCorners?: number) {
3646+
constructor(shapes?: T, radius?: number, nrCorners?: number, withContact?: boolean, withCorrection?: boolean) {
36233647
if (shapes !== undefined) { this.shape = shapes; }
36243648
if (radius !== undefined) { this.radius = radius; }
36253649
if (nrCorners !== undefined) { this.nrCorners = nrCorners; }
3650+
if (withContact !== undefined) { this.withContact = withContact; }
3651+
if (withCorrection !== undefined) { this.withCorrection; }
36263652
}
36273653
/**
36283654
* Wire path to pipe
@@ -3645,6 +3671,16 @@ export namespace OCCT {
36453671
* @step 1
36463672
*/
36473673
nrCorners = 6;
3674+
/**
3675+
* If withContact is true, the section is translated to be in contact with the spine.
3676+
* @default false
3677+
*/
3678+
withContact = false;
3679+
/**
3680+
* If withCorrection is true, the section is rotated to be orthogonal to the spine's tangent in the correspondent point.
3681+
* @default false
3682+
*/
3683+
withCorrection = false;
36483684
}
36493685
export class ExtrudeDto<T> {
36503686
constructor(shape?: T, direction?: Base.Vector3) {
@@ -3954,10 +3990,11 @@ export namespace OCCT {
39543990
index = 1;
39553991
}
39563992
export class RotationExtrudeDto<T> {
3957-
constructor(shape?: T, height?: number, angle?: number) {
3993+
constructor(shape?: T, height?: number, angle?: number, makeSolid?: boolean) {
39583994
if (shape !== undefined) { this.shape = shape; }
39593995
if (height !== undefined) { this.height = height; }
39603996
if (angle !== undefined) { this.angle = angle; }
3997+
if (makeSolid !== undefined) { this.makeSolid = makeSolid; }
39613998
}
39623999
/**
39634000
* Wire to extrude by rotating
@@ -3980,6 +4017,11 @@ export namespace OCCT {
39804017
* @step 1
39814018
*/
39824019
angle = 360;
4020+
/**
4021+
* Make solid of the result
4022+
* @default true
4023+
*/
4024+
makeSolid = true;
39834025
}
39844026

39854027
// Threading : Create Surfaces

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

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export class BooleansService {
7575

7676
if (this.shapeGettersService.getNumSolidsInCompound(difference) === 1) {
7777
const solid = this.shapeGettersService.getSolidFromCompound(difference, 0);
78-
difference.delete();
7978
difference = solid;
8079
}
8180

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

+72-24
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ export class OperationsService {
312312
});
313313
bopalgoBuilder.Perform(new this.occ.Message_ProgressRange_1());
314314
let shapes;
315-
if(!inputs.nonDestructive){
315+
if (!inputs.nonDestructive) {
316316
const res = bopalgoBuilder.Modified(inputs.shape);
317317
const shapeCompound = this.occ.BitByBitDev.BitListOfShapesToCompound(res);
318-
shapes = this.shapeGettersService.getShapesOfCompound({shape: shapeCompound});
318+
shapes = this.shapeGettersService.getShapesOfCompound({ shape: shapeCompound });
319319
} else {
320320
const res = bopalgoBuilder.Shape();
321-
shapes = this.shapeGettersService.getShapesOfCompound({shape: res});
321+
shapes = this.shapeGettersService.getShapesOfCompound({ shape: res });
322322
}
323323

324324
return shapes;
@@ -399,7 +399,11 @@ export class OperationsService {
399399
pipe.Add_1(inputs.shape, false, false);
400400
pipe.Add_1(upperPolygon, false, false);
401401
pipe.Build(new this.occ.Message_ProgressRange_1());
402-
pipe.MakeSolid();
402+
403+
// default should be to make the solid for backwards compatibility
404+
if (inputs.makeSolid || inputs.makeSolid === undefined) {
405+
pipe.MakeSolid();
406+
}
403407

404408
const pipeShape = pipe.Shape();
405409
const result = this.converterService.getActualTypeOfShape(pipeShape);
@@ -430,30 +434,52 @@ export class OperationsService {
430434
const wire = inputs.shape;
431435
const shapesToPassThrough: TopoDS_Shape[] = [];
432436
const edges = this.shapeGettersService.getEdges({ shape: wire });
437+
438+
// Check if the wire is closed
439+
const isClosed = this.wiresService.isWireClosed({ shape: wire }); // Assuming such a method exists
440+
433441
edges.forEach((e, index) => {
434442
const edgeStartPt = this.edgesService.startPointOnEdge({ shape: e });
435443
const tangent = this.edgesService.tangentOnEdgeAtParam({ shape: e, param: 0 });
436-
let tangentPreviousEdgeEnd: Inputs.Base.Vector3;
437444
let averageTangentVec = tangent;
438445

439-
if (index > 0 && index < edges.length - 1) {
440-
const previousEdge = edges[index - 1];
441-
tangentPreviousEdgeEnd = this.edgesService.tangentOnEdgeAtParam({ shape: previousEdge, param: 1 });
442-
averageTangentVec = [tangent[0] + tangentPreviousEdgeEnd[0] / 2, tangent[1] + tangentPreviousEdgeEnd[1] / 2, tangent[2] + tangentPreviousEdgeEnd[2] / 2];
446+
if (edges.length > 1) { // Only average tangents if there’s more than one edge
447+
if (index > 0 || (isClosed && index === 0)) {
448+
const previousEdge = edges[(index - 1 + edges.length) % edges.length]; // Wrap around for closed wires
449+
const tangentPreviousEdgeEnd = this.edgesService.tangentOnEdgeAtParam({ shape: previousEdge, param: 1 });
450+
averageTangentVec = [
451+
(tangent[0] + tangentPreviousEdgeEnd[0]) / 2,
452+
(tangent[1] + tangentPreviousEdgeEnd[1]) / 2,
453+
(tangent[2] + tangentPreviousEdgeEnd[2]) / 2
454+
];
455+
}
443456
}
444-
const ngon = this.wiresService.createNGonWire({ radius: inputs.radius, center: edgeStartPt, direction: averageTangentVec, nrCorners: inputs.nrCorners }) as TopoDS_Wire;
457+
458+
const ngon = this.wiresService.createNGonWire({
459+
radius: inputs.radius,
460+
center: edgeStartPt,
461+
direction: averageTangentVec,
462+
nrCorners: inputs.nrCorners
463+
}) as TopoDS_Wire;
445464
shapesToPassThrough.push(ngon);
446-
if (index === edges.length - 1) {
465+
466+
// For open wires, add a final n-gon at the end of the last edge
467+
if (!isClosed && index === edges.length - 1) {
447468
const edgeEndPt = this.edgesService.endPointOnEdge({ shape: e });
448469
const tangentEndPt = this.edgesService.tangentOnEdgeAtParam({ shape: e, param: 1 });
449-
const ngon = this.wiresService.createNGonWire({ radius: inputs.radius, center: edgeEndPt, direction: tangentEndPt, nrCorners: inputs.nrCorners }) as TopoDS_Wire;
470+
const ngon = this.wiresService.createNGonWire({
471+
radius: inputs.radius,
472+
center: edgeEndPt,
473+
direction: tangentEndPt,
474+
nrCorners: inputs.nrCorners
475+
}) as TopoDS_Wire;
450476
shapesToPassThrough.push(ngon);
451477
}
452478
});
453479

454480
const pipe = new this.occ.BRepOffsetAPI_MakePipeShell(wire);
455481
shapesToPassThrough.forEach(s => {
456-
pipe.Add_1(s, false, false);
482+
pipe.Add_1(s, inputs.withContact === true ? true : false, inputs.withCorrection === true ? true : false);
457483
});
458484

459485
pipe.Build(new this.occ.Message_ProgressRange_1());
@@ -469,30 +495,52 @@ export class OperationsService {
469495
const wire = inputs.shape;
470496
const shapesToPassThrough: TopoDS_Shape[] = [];
471497
const edges = this.shapeGettersService.getEdges({ shape: wire });
498+
499+
// Check if the wire is closed
500+
const isClosed = this.wiresService.isWireClosed({ shape: wire }); // Assuming such a method exists
501+
472502
edges.forEach((e, index) => {
473503
const edgeStartPt = this.edgesService.startPointOnEdge({ shape: e });
474504
const tangent = this.edgesService.tangentOnEdgeAtParam({ shape: e, param: 0 });
475-
let tangentPreviousEdgeEnd: Inputs.Base.Vector3;
476505
let averageTangentVec = tangent;
477506

478-
if (index > 0 && index < edges.length - 1) {
479-
const previousEdge = edges[index - 1];
480-
tangentPreviousEdgeEnd = this.edgesService.tangentOnEdgeAtParam({ shape: previousEdge, param: 1 });
481-
averageTangentVec = [tangent[0] + tangentPreviousEdgeEnd[0] / 2, tangent[1] + tangentPreviousEdgeEnd[1] / 2, tangent[2] + tangentPreviousEdgeEnd[2] / 2];
507+
if (edges.length > 1) { // Only average tangents if there’s more than one edge
508+
if (index > 0 || (isClosed && index === 0)) {
509+
const previousEdge = edges[(index - 1 + edges.length) % edges.length]; // Wrap around for closed wires
510+
const tangentPreviousEdgeEnd = this.edgesService.tangentOnEdgeAtParam({ shape: previousEdge, param: 1 });
511+
averageTangentVec = [
512+
(tangent[0] + tangentPreviousEdgeEnd[0]) / 2,
513+
(tangent[1] + tangentPreviousEdgeEnd[1]) / 2,
514+
(tangent[2] + tangentPreviousEdgeEnd[2]) / 2
515+
];
516+
}
482517
}
483-
const circle = this.entitiesService.createCircle(inputs.radius, edgeStartPt, averageTangentVec, Inputs.OCCT.typeSpecificityEnum.wire) as TopoDS_Wire;
518+
519+
const circle = this.entitiesService.createCircle(
520+
inputs.radius,
521+
edgeStartPt,
522+
averageTangentVec,
523+
Inputs.OCCT.typeSpecificityEnum.wire
524+
) as TopoDS_Wire;
484525
shapesToPassThrough.push(circle);
485-
if (index === edges.length - 1) {
526+
527+
// For open wires, add a final circle at the end of the last edge
528+
if (!isClosed && index === edges.length - 1) {
486529
const edgeEndPt = this.edgesService.endPointOnEdge({ shape: e });
487530
const tangentEndPt = this.edgesService.tangentOnEdgeAtParam({ shape: e, param: 1 });
488-
const line = this.entitiesService.createCircle(inputs.radius, edgeEndPt, tangentEndPt, Inputs.OCCT.typeSpecificityEnum.wire) as TopoDS_Wire;
489-
shapesToPassThrough.push(line);
531+
const circle = this.entitiesService.createCircle(
532+
inputs.radius,
533+
edgeEndPt,
534+
tangentEndPt,
535+
Inputs.OCCT.typeSpecificityEnum.wire
536+
) as TopoDS_Wire;
537+
shapesToPassThrough.push(circle);
490538
}
491539
});
492540

493541
const pipe = new this.occ.BRepOffsetAPI_MakePipeShell(wire);
494542
shapesToPassThrough.forEach(s => {
495-
pipe.Add_1(s, false, false);
543+
pipe.Add_1(s, inputs.withContact === true ? true : false, inputs.withCorrection === true ? true : false);
496544
});
497545

498546
pipe.Build(new this.occ.Message_ProgressRange_1());
@@ -506,7 +554,7 @@ export class OperationsService {
506554

507555
pipeWiresCylindrical(inputs: Inputs.OCCT.PipeWiresCylindricalDto<TopoDS_Wire>) {
508556
return inputs.shapes.map(wire => {
509-
return this.pipeWireCylindrical({ shape: wire, radius: inputs.radius });
557+
return this.pipeWireCylindrical({ shape: wire, radius: inputs.radius, withContact: inputs.withContact, withCorrection: inputs.withCorrection });
510558
});
511559
}
512560

0 commit comments

Comments
 (0)