Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 | 589x 589x 589x 589x 5x 10x 642x 642x 642x 642x 642x 642x 642x 642x 642x 642x 642x 590x 84x 84x 84x 84x 84x 4x 4x 4x 34x 4x 4x 4x 34x 4x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 32x 32x 5x 27x 22x 22x 5x 5x 69x 5x 5x 5x 133x 5x 5x 5x 5x 31x 31x 31x 480x 31x 31x 31x 31x 8x 8x 8x 32x 8x 8x 8x 8x 11x 11x 11x 77x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 60x 11x 11x 11x 11x 11x 5x 5x 2x 2x 3x 3x 1x 11x 11x 11x 11x 11x 11x 7x 7x 7x 7x 7x 7x 7x 6x 6x 6x 6x 6x 6x 6x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 847x 847x 3781x 847x 847x 2934x 2934x 2934x 2934x 847x 847x 847x 847x 847x 847x 847x 728x 728x 6427x 728x 728x 5699x 5699x 5699x 5699x 728x 728x 728x 250x 250x 250x 250x 250x 250x 250x 250x 250x 250x 250x 250x 170x 170x 170x 170x 170x 170x 9730x 9730x 9730x 9730x 9730x 9730x 9730x 9730x 9730x 9730x 9730x 9730x 9730x 9730x 26x 26x 26x 26x 26x 42x 42x 42x 42x 42x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 2x 2x 2x 2x 2x 3x 3x 3x 3x 3x 3x 3x 73x 73x 3x 1x 3x 1x 3x 3x 1x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 10x 38x 38x 36x 36x 36x 2x 2x 2x 1x 2x 1x 1x 2x 2x 1x 2x 2x 1x 1x 1x 1x 1x 59x 59x 59x 291x 291x 291x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 291x 59x 59x 32x 32x 32x 32x 32x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 299x 299x 299x 299x 1571x 1571x 1571x 1571x 1571x 1571x 1571x 1571x 1571x 1571x 1571x 1571x 575x 575x 575x 299x 299x 28x 28x 28x 28x 28x 28x 2550x 28x 314x 228x 28x 28x 304x 304x 304x 304x 228x 228x 228x 228x 228x 228x 228x 228x 228x 76x 76x 76x 76x 76x 76x 63x 63x 63x 63x 76x 48x 76x 76x 76x 76x 76x 76x 68x 68x 68x 68x 304x 304x 304x 28x 12x 6x 84x 84x 84x 84x 84x 84x 84x 328x 82x 82x 82x 3x 3x 3x 3x 3x 3x 3x 3x 6x 6x 3x 6x 6x 6x 66x 36x 30x 6x 30x 25x 5x 6x 3x 4x 6x 6x 36x 6x 6x 6x 6x 6x 6x 14x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 6x 19x 19x 19x 19x 24x 24x 24x 268x 268x 268x 24x 24x 24x 24x 24x 24x 24x 24x 24x 268x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 43x 43x 131x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 1x 1x 1x 1x 3x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 15x 6x 9x 8x 5x 4x 1x 4x 4x 42x 42x 42x 42x 46x 46x 46x 46x 41x 41x 41x 41x 4x 4x 4x 4x 5x 12x 12x 12x 4x 57x 57x 57x 57x 57x 470x 470x 682x 682x 682x 682x 470x 470x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 214x 214x 214x 934x 934x 934x 934x 934x 934x 934x 934x 934x 934x 934x 934x 934x 934x 934x 214x 934x 214x 1x 1x 1x 1x 1x 1x 1x 1x | import {
GeomAbs_Shape, Geom_Surface, OpenCascadeInstance,
TopoDS_Compound, TopoDS_Edge, TopoDS_Shape, TopoDS_Wire, gp_Pnt, gp_Pnt_3
} from "../../../bitbybit-dev-occt/bitbybit-dev-occt";
import * as Inputs from "../../api/inputs/inputs";
import { Base } from "../../api/inputs/inputs";
import { ShapesHelperService } from "../../api/shapes-helper.service";
import { OCCReferencedReturns } from "../../occ-referenced-returns";
import { EdgesService } from "./edges.service";
import { ShapeGettersService } from "./shape-getters";
import { EntitiesService } from "./entities.service";
import { GeomService } from "./geom.service";
import { TransformsService } from "./transforms.service";
import { ConverterService } from "./converter.service";
import { EnumService } from "./enum.service";
import { TextWiresDataDto, ObjectDefinition } from "../../api/models/bucket";
import { OperationsService } from "./operations.service";
import { FilletsService } from "./fillets.service";
import { BaseBitByBit } from "../../base";
import { VectorHelperService } from "../../api/vector-helper.service";
export class WiresService {
constructor(
private readonly occ: OpenCascadeInstance,
private readonly occRefReturns: OCCReferencedReturns,
private readonly base: BaseBitByBit,
private readonly shapesHelperService: ShapesHelperService,
private readonly shapeGettersService: ShapeGettersService,
private readonly transformsService: TransformsService,
private readonly enumService: EnumService,
private readonly entitiesService: EntitiesService,
private readonly converterService: ConverterService,
private readonly geomService: GeomService,
private readonly edgesService: EdgesService,
private readonly vecHelper: VectorHelperService,
public filletsService: FilletsService,
public operationsService: OperationsService,
) { }
getWireLength(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): number {
const curve = new this.occ.BRepAdaptor_CompCurve_2(inputs.shape, false);
const length = this.geomService.curveLength({ shape: curve });
curve.delete();
return length;
}
getWiresLengths(inputs: Inputs.OCCT.ShapesDto<TopoDS_Wire>): number[] {
Iif (inputs.shapes === undefined) {
throw (Error(("Shapes are not defined")));
}
return inputs.shapes.map(wire => this.getWireLength({ shape: wire }));
}
createRectangleWire(inputs: Inputs.OCCT.RectangleDto): TopoDS_Wire {
const cw = inputs.width / 2;
const cl = inputs.length / 2;
const pt1: Base.Point3 = [cw, 0, cl];
const pt2: Base.Point3 = [-cw, 0, cl];
const pt3: Base.Point3 = [-cw, 0, -cl];
const pt4: Base.Point3 = [cw, 0, -cl];
const points = [pt1, pt2, pt3, pt4].reverse();
const wire = this.createPolygonWire({ points });
const alignedWire = this.transformsService.alignAndTranslate({ shape: wire, direction: inputs.direction, center: inputs.center });
wire.delete();
return alignedWire;
}
createSquareWire(inputs: Inputs.OCCT.SquareDto): TopoDS_Wire {
return this.createRectangleWire({
width: inputs.size,
length: inputs.size,
center: inputs.center,
direction: inputs.direction
});
}
reversedWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): TopoDS_Wire {
const wire: TopoDS_Wire = inputs.shape;
const reversed = wire.Reversed();
const result = this.converterService.getActualTypeOfShape(reversed);
reversed.delete();
return result;
}
reversedWireFromReversedEdges(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): TopoDS_Wire {
const wire: TopoDS_Wire = inputs.shape;
const edges = this.edgesService.getEdgesAlongWire({ shape: wire });
const reversedEdges = edges.map(e => {
return this.converterService.getActualTypeOfShape(e.Reversed());
});
const reversed = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: reversedEdges.reverse() });
const result = this.converterService.getActualTypeOfShape(reversed);
reversed.delete();
reversedEdges.forEach(e => e.delete());
return result;
}
createChristmasTreeWire(inputs: Inputs.OCCT.ChristmasTreeDto) {
const frameInner = this.createLineWire({
start: [inputs.innerDist, 0, 0],
end: [0, inputs.height, 0],
});
const frameOuter = this.createLineWire({
start: [inputs.outerDist, 0, 0],
end: [0, inputs.height, 0],
});
const pointsOnInner = this.divideWireByEqualDistanceToPoints({
shape: frameInner,
nrOfDivisions: inputs.nrSkirts,
removeEndPoint: false,
removeStartPoint: false,
});
const pointsOnOuter = this.divideWireByEqualDistanceToPoints({
shape: frameOuter,
nrOfDivisions: inputs.nrSkirts,
removeEndPoint: false,
removeStartPoint: false,
});
const halfShapeTreePts: Base.Point3[] = [];
if (inputs.trunkWidth > 0 && inputs.trunkHeight > 0) {
halfShapeTreePts.push([0, -inputs.trunkHeight, 0]);
halfShapeTreePts.push([inputs.trunkWidth / 2, -inputs.trunkHeight, 0]);
halfShapeTreePts.push([inputs.trunkWidth / 2, 0, 0]);
} else E{
halfShapeTreePts.push([0, 0, 0]);
}
pointsOnInner.forEach((pt, index) => {
const ptOnOuter = pointsOnOuter[index];
if (index === 0) {
halfShapeTreePts.push(ptOnOuter);
} else if (index !== 0 && index < pointsOnOuter.length - 1) {
halfShapeTreePts.push([pt[0], ptOnOuter[1] + ((inputs.height / inputs.nrSkirts) * 0.1), pt[2]]);
halfShapeTreePts.push(ptOnOuter);
} else {
halfShapeTreePts.push(pt);
}
});
Eif (!inputs.half) {
const secondHalf = halfShapeTreePts.map(pt => [-pt[0], pt[1], pt[2]] as Base.Point3);
secondHalf.pop();
halfShapeTreePts.push(...secondHalf.reverse());
}
let result;
if (inputs.trunkHeight > 0 && inputs.trunkWidth > 0) {
const offsetToTrunkHeight = halfShapeTreePts.map(pt => [pt[0], pt[1] + inputs.trunkHeight, pt[2]] as Base.Point3);
result = this.createPolylineWire({ points: offsetToTrunkHeight });
} else E{
result = this.createPolylineWire({ points: halfShapeTreePts });
}
const rotated = this.transformsService.rotate({ shape: result, angle: inputs.rotation, axis: [0, 1, 0] });
const aligned = this.transformsService.alignAndTranslate({ shape: rotated, direction: inputs.direction, center: inputs.origin });
return aligned;
}
createStarWire(inputs: Inputs.OCCT.StarDto) {
const lines = this.shapesHelperService.starLines(inputs.innerRadius, inputs.outerRadius, inputs.numRays, inputs.half, inputs.offsetOuterEdges);
const edges: TopoDS_Edge[] = [];
lines.forEach(line => {
edges.push(this.edgesService.lineEdge(line));
});
const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: edges });
const alignedWire = this.transformsService.alignAndTranslate({ shape: wire, direction: inputs.direction, center: inputs.center });
wire.delete();
return alignedWire;
}
createParallelogramWire(inputs: Inputs.OCCT.ParallelogramDto) {
const lines = this.shapesHelperService.parallelogram(inputs.width, inputs.height, inputs.angle, inputs.aroundCenter);
const edges: TopoDS_Edge[] = [];
lines.forEach(line => {
edges.push(this.edgesService.lineEdge(line));
});
const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: edges });
const aligned = this.transformsService.alignAndTranslate({ shape: wire, direction: inputs.direction, center: inputs.center });
wire.delete();
return aligned;
}
createHeartWire(inputs: Inputs.OCCT.Heart2DDto) {
const sizeOfBox = inputs.sizeApprox;
const halfSize = sizeOfBox / 2;
const points1: Inputs.Base.Point3[] = [
[0, 0, halfSize * 0.7],
[halfSize / 6, 0, halfSize * 0.9],
[halfSize / 2, 0, halfSize],
[halfSize * 0.75, 0, halfSize * 0.9],
[halfSize, 0, halfSize / 4],
[halfSize / 2, 0, -halfSize / 2],
[0, 0, -halfSize],
];
const points2: Inputs.Base.Point3[] = points1.map(p => [-p[0], p[1], p[2]]);
const tolerance = 0.00001;
const wireFirstHalf = this.interpolatePoints({
points: points1, periodic: false, tolerance
});
const wireSecondHalf = this.interpolatePoints({
points: points2.reverse(), periodic: false, tolerance
});
const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: [wireFirstHalf, wireSecondHalf] });
const rotated = this.transformsService.rotate({ shape: wire, angle: inputs.rotation, axis: [0, 1, 0] });
const aligned = this.transformsService.alignAndTranslate({ shape: rotated, direction: inputs.direction, center: inputs.center });
wire.delete();
rotated.delete();
wireFirstHalf.delete();
wireSecondHalf.delete();
return aligned;
}
createNGonWire(inputs: Inputs.OCCT.NGonWireDto) {
const lines = this.shapesHelperService.ngon(inputs.nrCorners, inputs.radius, [0, 0]);
const edges: TopoDS_Edge[] = [];
lines.forEach(line => {
edges.push(this.edgesService.lineEdge(line));
});
const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: edges });
const aligned = this.transformsService.alignAndTranslate({ shape: wire, direction: inputs.direction, center: inputs.center });
wire.delete();
return aligned;
}
createLPolygonWire(inputs: Inputs.OCCT.LPolygonDto) {
let points: Base.Point3[];
switch (inputs.align) {
case Inputs.OCCT.directionEnum.outside:
points = this.shapesHelperService.polygonL(inputs.widthFirst, inputs.lengthFirst, inputs.widthSecond, inputs.lengthSecond);
break;
case Inputs.OCCT.directionEnum.inside:
points = this.shapesHelperService.polygonLInverted(inputs.widthFirst, inputs.lengthFirst, inputs.widthSecond, inputs.lengthSecond);
break;
case Inputs.OCCT.directionEnum.middle:
points = this.shapesHelperService.polygonLMiddle(inputs.widthFirst, inputs.lengthFirst, inputs.widthSecond, inputs.lengthSecond);
break;
default:
points = this.shapesHelperService.polygonL(inputs.widthFirst, inputs.lengthFirst, inputs.widthSecond, inputs.lengthSecond);
}
const wire = this.createPolygonWire({
points
});
const rotated = this.transformsService.rotate({ shape: wire, angle: inputs.rotation, axis: [0, 1, 0] });
const aligned = this.transformsService.alignAndTranslate({ shape: rotated, direction: inputs.direction, center: inputs.center });
wire.delete();
rotated.delete();
return aligned;
}
createIBeamProfileWire(inputs: Inputs.OCCT.IBeamProfileDto) {
const points = this.shapesHelperService.beamIProfile(
inputs.width,
inputs.height,
inputs.webThickness,
inputs.flangeThickness,
inputs.alignment
);
const wire = this.createPolygonWire({ points });
const rotated = this.transformsService.rotate({ shape: wire, angle: inputs.rotation, axis: [0, 1, 0] });
const aligned = this.transformsService.alignAndTranslate({ shape: rotated, direction: inputs.direction, center: inputs.center });
wire.delete();
rotated.delete();
return aligned;
}
createHBeamProfileWire(inputs: Inputs.OCCT.HBeamProfileDto) {
const points = this.shapesHelperService.beamHProfile(
inputs.width,
inputs.height,
inputs.webThickness,
inputs.flangeThickness,
inputs.alignment
);
const wire = this.createPolygonWire({ points });
const rotated = this.transformsService.rotate({ shape: wire, angle: inputs.rotation, axis: [0, 1, 0] });
const aligned = this.transformsService.alignAndTranslate({ shape: rotated, direction: inputs.direction, center: inputs.center });
wire.delete();
rotated.delete();
return aligned;
}
createTBeamProfileWire(inputs: Inputs.OCCT.TBeamProfileDto) {
const points = this.shapesHelperService.beamTProfile(
inputs.width,
inputs.height,
inputs.webThickness,
inputs.flangeThickness,
inputs.alignment
);
const wire = this.createPolygonWire({ points });
const rotated = this.transformsService.rotate({ shape: wire, angle: inputs.rotation, axis: [0, 1, 0] });
const aligned = this.transformsService.alignAndTranslate({ shape: rotated, direction: inputs.direction, center: inputs.center });
wire.delete();
rotated.delete();
return aligned;
}
createUBeamProfileWire(inputs: Inputs.OCCT.UBeamProfileDto) {
const points = this.shapesHelperService.beamUProfile(
inputs.width,
inputs.height,
inputs.webThickness,
inputs.flangeThickness,
inputs.flangeWidth,
inputs.alignment
);
const wire = this.createPolygonWire({ points });
const rotated = this.transformsService.rotate({ shape: wire, angle: inputs.rotation, axis: [0, 1, 0] });
const aligned = this.transformsService.alignAndTranslate({ shape: rotated, direction: inputs.direction, center: inputs.center });
wire.delete();
rotated.delete();
return aligned;
}
createPolygonWire(inputs: Inputs.OCCT.PolygonDto) {
const gpPoints: gp_Pnt_3[] = [];
for (let ind = 0; ind < inputs.points.length; ind++) {
gpPoints.push(this.entitiesService.gpPnt(inputs.points[ind]));
}
const wireMaker = new this.occ.BRepBuilderAPI_MakeWire_1();
for (let ind = 0; ind < inputs.points.length - 1; ind++) {
const pt1 = gpPoints[ind];
const pt2 = gpPoints[ind + 1];
const innerWire = this.makeWireBetweenTwoPoints(pt1, pt2);
wireMaker.Add_2(innerWire);
}
const pt1 = gpPoints[inputs.points.length - 1];
const pt2 = gpPoints[0];
const innerWire2 = this.makeWireBetweenTwoPoints(pt1, pt2);
wireMaker.Add_2(innerWire2);
const wire = wireMaker.Wire();
wireMaker.delete();
return wire;
}
createPolylineWire(inputs: Inputs.OCCT.PolylineDto) {
const gpPoints: gp_Pnt_3[] = [];
for (let ind = 0; ind < inputs.points.length; ind++) {
gpPoints.push(this.entitiesService.gpPnt(inputs.points[ind]));
}
const wireMaker = new this.occ.BRepBuilderAPI_MakeWire_1();
for (let ind = 0; ind < inputs.points.length - 1; ind++) {
const pt1 = gpPoints[ind];
const pt2 = gpPoints[ind + 1];
const innerWire = this.makeWireBetweenTwoPoints(pt1, pt2);
wireMaker.Add_2(innerWire);
}
const wire = wireMaker.Wire();
wireMaker.delete();
return wire;
}
createLineWire(inputs: Inputs.OCCT.LineDto) {
const gpPoints: gp_Pnt_3[] = [];
gpPoints.push(this.entitiesService.gpPnt(inputs.start));
gpPoints.push(this.entitiesService.gpPnt(inputs.end));
const wireMaker = new this.occ.BRepBuilderAPI_MakeWire_1();
for (let ind = 0; ind < gpPoints.length - 1; ind++) {
const pt1 = gpPoints[ind];
const pt2 = gpPoints[ind + 1];
const innerWire = this.makeWireBetweenTwoPoints(pt1, pt2);
wireMaker.Add_2(innerWire);
}
const wire = wireMaker.Wire();
wireMaker.delete();
return wire;
}
createLineWireWithExtensions(inputs: Inputs.OCCT.LineWithExtensionsDto): TopoDS_Wire {
const direction = this.base.vector.normalized({ vector: this.base.vector.sub({ first: inputs.end, second: inputs.start }) });
const scaledVecStart = this.base.vector.mul({ vector: direction, scalar: -inputs.extensionStart });
const scaledVecEnd = this.base.vector.mul({ vector: direction, scalar: inputs.extensionEnd });
const start = this.base.vector.add({ first: inputs.start, second: scaledVecStart }) as Base.Point3;
const end = this.base.vector.add({ first: inputs.end, second: scaledVecEnd }) as Base.Point3;
return this.createLineWire({ start, end });
}
private makeWireBetweenTwoPoints(pt1: gp_Pnt, pt2: gp_Pnt) {
const seg = new this.occ.GC_MakeSegment_1(pt1, pt2);
const segVal = seg.Value();
const segment = segVal.get();
const edgeMaker = new this.occ.BRepBuilderAPI_MakeEdge_24(
new this.occ.Handle_Geom_Curve_2(segment)
);
const edge = edgeMaker.Edge();
const wireMaker = new this.occ.BRepBuilderAPI_MakeWire_2(edge);
const innerWire = wireMaker.Wire();
edgeMaker.delete();
seg.delete();
segVal.delete();
segment.delete();
edge.delete();
wireMaker.delete();
return innerWire;
}
divideWireByParamsToPoints(inputs: Inputs.OCCT.DivideDto<TopoDS_Wire>): Inputs.Base.Point3[] {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const points = this.geomService.divideCurveToNrSegments({ ...inputs, shape: curve }, curve.FirstParameter(), curve.LastParameter());
curve.delete();
return points;
}
divideWireByEqualDistanceToPoints(inputs: Inputs.OCCT.DivideDto<TopoDS_Wire>): Base.Point3[] {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const points = this.geomService.divideCurveByEqualLengthDistance({ ...inputs, shape: curve });
curve.delete();
return points;
}
pointOnWireAtParam(inputs: Inputs.OCCT.DataOnGeometryAtParamDto<TopoDS_Wire>): Base.Point3 {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const pt = this.geomService.pointOnCurveAtParam({ ...inputs, shape: curve });
curve.delete();
return pt;
}
tangentOnWireAtParam(inputs: Inputs.OCCT.DataOnGeometryAtParamDto<TopoDS_Wire>): Base.Point3 {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const tangent = this.geomService.tangentOnCurveAtParam({ ...inputs, shape: curve });
curve.delete();
return tangent;
}
pointOnWireAtLength(inputs: Inputs.OCCT.DataOnGeometryAtLengthDto<TopoDS_Wire>): Base.Point3 {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const res = this.geomService.pointOnCurveAtLength({ ...inputs, shape: curve });
curve.delete();
return res;
}
pointsOnWireAtLengths(inputs: Inputs.OCCT.DataOnGeometryAtLengthsDto<TopoDS_Wire>): Base.Point3[] {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const res = this.geomService.pointsOnCurveAtLengths({ ...inputs, shape: curve });
curve.delete();
return res;
}
pointsOnWireAtEqualLength(inputs: Inputs.OCCT.PointsOnWireAtEqualLengthDto<TopoDS_Wire>): Base.Point3[] {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const wireLength = this.getWireLength({ shape: wire });
const nrOfLengths = wireLength / inputs.length;
const lengths = [];
let total = 0;
for (let i = 0; i < nrOfLengths; i++) {
lengths.push(inputs.length * i);
total += inputs.length;
}
if (!inputs.includeFirst) {
lengths.shift();
}
if (inputs.tryNext) {
lengths.push(total + inputs.length);
}
const res = this.geomService.pointsOnCurveAtLengths({ lengths, shape: curve });
if (inputs.includeLast) {
res.push(this.endPointOnWire({ shape: wire }));
}
curve.delete();
return res;
}
pointsOnWireAtPatternOfLengths(inputs: Inputs.OCCT.PointsOnWireAtPatternOfLengthsDto<TopoDS_Wire>): Base.Point3[] {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const wireLength = this.getWireLength({ shape: wire });
const lengths = [];
let total = 0;
let lastIndex = 0;
let reachedGoal = false;
while (!reachedGoal) {
for (let i = 0; i < inputs.lengths.length; i++) {
const length = inputs.lengths[i];
if (total + length <= wireLength) {
lengths.push(total + length);
total += length;
lastIndex = i;
} else {
reachedGoal = true;
break;
}
}
}
if (inputs.includeFirst) {
lengths.unshift(0);
}
if (inputs.tryNext) {
if (lastIndex + 1 < inputs.lengths.length) {
lengths.push(total + inputs.lengths[lastIndex + 1]);
} else E{
lengths.push(total + inputs.lengths[0]);
}
}
const res = this.geomService.pointsOnCurveAtLengths({ lengths, shape: curve });
if (inputs.includeLast) {
res.push(this.endPointOnWire({ shape: wire }));
}
curve.delete();
return res;
}
tangentOnWireAtLength(inputs: Inputs.OCCT.DataOnGeometryAtLengthDto<TopoDS_Wire>): Base.Point3 {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const res = this.geomService.tangentOnCurveAtLength({ ...inputs, shape: curve });
curve.delete();
return res;
}
interpolatePoints(inputs: Inputs.OCCT.InterpolationDto) {
const ptList = new this.occ.TColgp_Array1OfPnt_2(1, inputs.points.length);
const gpPnts: gp_Pnt_3[] = [];
for (let pIndex = 1; pIndex <= inputs.points.length; pIndex++) {
const gpPnt = this.entitiesService.gpPnt(inputs.points[pIndex - 1]);
gpPnts.push(gpPnt);
ptList.SetValue(pIndex, gpPnt);
}
const geomBSplineHandle = this.occ.BitByBitDev.BitInterpolate(ptList, inputs.periodic, inputs.tolerance);
if (!geomBSplineHandle.IsNull()) {
const geomBSpline = geomBSplineHandle.get();
const geomCrvHandle = new this.occ.Handle_Geom_Curve_2(geomBSpline);
const edgeMaker = new this.occ.BRepBuilderAPI_MakeEdge_24(geomCrvHandle);
const edge = edgeMaker.Edge();
const wireMaker = new this.occ.BRepBuilderAPI_MakeWire_2(edge);
const wire = wireMaker.Wire();
geomBSplineHandle.Nullify();
geomBSplineHandle.delete();
geomCrvHandle.Nullify();
geomCrvHandle.delete();
edgeMaker.delete();
edge.delete();
wireMaker.delete();
gpPnts.forEach(p => p.delete());
ptList.delete();
return wire;
} else E{
gpPnts.forEach(p => p.delete());
ptList.delete();
return undefined;
}
}
isWireClosed(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): boolean {
const tolerance = 1.0e-7;
const startPointOnWire = this.startPointOnWire({ shape: inputs.shape });
const endPointOnWire = this.endPointOnWire({ shape: inputs.shape });
// This is needed to make follow up algorithm to work properly on open wires
const wireIsClosed = this.base.vector.vectorsTheSame({ vec1: endPointOnWire, vec2: startPointOnWire, tolerance });
return wireIsClosed;
}
splitOnPoints(inputs: Inputs.OCCT.SplitWireOnPointsDto<TopoDS_Wire>): TopoDS_Wire[] {
const wire = inputs.shape;
// Remove duplicate points to avoid incorrect behavior
const splitPoints = this.vecHelper.removeAllDuplicateVectors(inputs.points, 1e-7);
// 1. Get the list of edges from the wire in correct order along the wire
const edges = this.edgesService.getEdgesAlongWire({ shape: wire });
Iif (edges.length === 0) return [];
// 2. Collect split locations as {edgeIndex, parameter}
const splitLocations: { edgeIndex: number; parameter: number }[] = [];
// Add the wire's start point
const firstEdge = edges[0];
let first = { current: 0 };
let last = { current: 0 };
this.occRefReturns.BRep_Tool_Curve_2(firstEdge, first, last);
splitLocations.push({ edgeIndex: 0, parameter: first.current });
// Project each split point onto the wire
splitPoints.forEach((pt) => {
let minDist = Infinity;
let bestEdgeIndex = -1;
let bestParam = 0;
edges.forEach((edge, index) => {
const first = { current: 0 };
const last = { current: 0 };
const curve = this.occRefReturns.BRep_Tool_Curve_2(edge, first, last);
const firstVal = first.current;
const lastVal = last.current;
const gpPnt = this.entitiesService.gpPnt(pt as Base.Point3);
const projector = new this.occ.GeomAPI_ProjectPointOnCurve_2(gpPnt, curve);
Eif (projector.NbPoints() > 0) {
const param = projector.LowerDistanceParameter();
// Clamp the parameter to the edge's range
const clampedParam = Math.max(firstVal, Math.min(lastVal, param));
const dist = projector.Distance(1); // Use the first projection point
if (dist < minDist) {
minDist = dist;
bestEdgeIndex = index;
bestParam = clampedParam;
}
}
});
Eif (bestEdgeIndex >= 0) {
splitLocations.push({ edgeIndex: bestEdgeIndex, parameter: bestParam });
}
});
// Add the wire's end point
const lastEdge = edges[edges.length - 1];
first = { current: 0 };
last = { current: 0 };
this.occRefReturns.BRep_Tool_Curve_2(lastEdge, first, last);
splitLocations.push({ edgeIndex: edges.length - 1, parameter: last.current });
// 3. Remove duplicates and sort split locations by edgeIndex, then parameter
const uniqueLocations = splitLocations.filter((loc, index, self) =>
index === self.findIndex((t) => t.edgeIndex === loc.edgeIndex && t.parameter === loc.parameter)
);
uniqueLocations.sort((a, b) => {
if (a.edgeIndex !== b.edgeIndex) return a.edgeIndex - b.edgeIndex;
return a.parameter - b.parameter;
});
// 4. Create new wires between consecutive split locations
const newWires: TopoDS_Wire[] = [];
for (let i = 0; i < uniqueLocations.length - 1; i++) {
const startLoc = uniqueLocations[i];
const endLoc = uniqueLocations[i + 1];
const wireBuilder = new this.occ.BRepBuilderAPI_MakeWire_1();
if (startLoc.edgeIndex === endLoc.edgeIndex) {
// Same edge: create a single trimmed edge
const edge = edges[startLoc.edgeIndex];
const first = { current: 0 };
const last = { current: 0 };
const curve = this.occRefReturns.BRep_Tool_Curve_2(edge, first, last);
// Avoid zero-length segments
Iif (startLoc.parameter === endLoc.parameter) continue;
const trimmedCurve = new this.occ.Geom_TrimmedCurve(
curve,
startLoc.parameter,
endLoc.parameter,
true,
true
);
const handleTrimmedCurve = new this.occ.Handle_Geom_Curve_2(trimmedCurve);
const newEdge = new this.occ.BRepBuilderAPI_MakeEdge_24(handleTrimmedCurve).Edge();
wireBuilder.Add_1(newEdge);
} else {
// Spans multiple edges
// Trim the start edge
const startEdge = edges[startLoc.edgeIndex];
const startFirst = { current: 0 };
const startLast = { current: 0 };
const startCurve = this.occRefReturns.BRep_Tool_Curve_2(startEdge, startFirst, startLast);
const startLastVal = startLast.current;
if (startLoc.parameter < startLastVal) {
const trimmedStartCurve = new this.occ.Geom_TrimmedCurve(
startCurve,
startLoc.parameter,
startLastVal,
true,
true
);
const handleTrimmedStartCurve = new this.occ.Handle_Geom_Curve_2(trimmedStartCurve);
const newStartEdge = new this.occ.BRepBuilderAPI_MakeEdge_24(handleTrimmedStartCurve).Edge();
wireBuilder.Add_1(newStartEdge);
}
// Add full edges in between
for (let j = startLoc.edgeIndex + 1; j < endLoc.edgeIndex; j++) {
wireBuilder.Add_1(edges[j]);
}
// Trim the end edge
const endEdge = edges[endLoc.edgeIndex];
const endFirst = { current: 0 };
const endLast = { current: 0 };
const endCurve = this.occRefReturns.BRep_Tool_Curve_2(endEdge, endFirst, endLast);
const endFirstVal = endFirst.current;
if (endLoc.parameter > endFirstVal) {
const trimmedEndCurve = new this.occ.Geom_TrimmedCurve(
endCurve,
endFirstVal,
endLoc.parameter,
true,
true
);
const handleTrimmedEndCurve = new this.occ.Handle_Geom_Curve_2(trimmedEndCurve);
const newEndEdge = new this.occ.BRepBuilderAPI_MakeEdge_24(handleTrimmedEndCurve).Edge();
wireBuilder.Add_1(newEndEdge);
}
}
Eif (wireBuilder.IsDone()) {
const newWire = wireBuilder.Wire();
newWires.push(newWire);
}
}
return newWires;
}
createLines(inputs: Inputs.OCCT.LinesDto): TopoDS_Wire[] | TopoDS_Compound {
const wires = inputs.lines.map(p => this.createLineWire(p)).filter(s => s !== undefined);
return this.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
}
createWireFromTwoCirclesTan(inputs: Inputs.OCCT.WireFromTwoCirclesTanDto<TopoDS_Wire>) {
const circleEdge1 = this.shapeGettersService.getEdges({ shape: inputs.circle1 });
const circleEdge2 = this.shapeGettersService.getEdges({ shape: inputs.circle2 });
if (circleEdge1.length === 1 && circleEdge2.length === 1) {
const circularEdge1 = circleEdge1[0];
const circularEdge2 = circleEdge2[0];
const result = this.edgesService.constraintTanLinesOnTwoCircles({
circle1: circularEdge1,
circle2: circularEdge2,
positionResult: inputs.keepLines === Inputs.OCCT.twoSidesStrictEnum.outside ? Inputs.OCCT.positionResultEnum.keepSide2 : Inputs.OCCT.positionResultEnum.keepSide1,
circleRemainders: this.enumService.convertFourSidesStrictEnumToTwoCircleInclusionEnum(inputs.circleRemainders),
tolerance: inputs.tolerance,
});
const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: result });
result.forEach(e => e.delete());
circularEdge1.delete();
circularEdge2.delete();
return wire;
} else E{
throw new Error("Could not find the edges of the provided circle wires.");
}
}
createZigZagBetweenTwoWires(inputs: Inputs.OCCT.ZigZagBetweenTwoWiresDto<TopoDS_Wire>) {
const wire1 = inputs.wire1;
const wire2 = inputs.wire2;
let points1 = [];
let points2 = [];
if (inputs.zigZagsPerEdge) {
const edges1 = this.edgesService.getEdgesAlongWire({ shape: wire1 });
const edges2 = this.edgesService.getEdgesAlongWire({ shape: wire2 });
if (inputs.divideByEqualDistance) {
points1 = edges1.map(e => this.edgesService.divideEdgeByEqualDistanceToPoints({ shape: e, nrOfDivisions: inputs.nrZigZags * 2, removeEndPoint: false, removeStartPoint: false }));
points2 = edges2.map(e => this.edgesService.divideEdgeByEqualDistanceToPoints({ shape: e, nrOfDivisions: inputs.nrZigZags * 2, removeEndPoint: false, removeStartPoint: false }));
} else E{
points1 = edges1.map(e => this.edgesService.divideEdgeByParamsToPoints({ shape: e, nrOfDivisions: inputs.nrZigZags * 2, removeEndPoint: false, removeStartPoint: false }));
points2 = edges2.map(e => this.edgesService.divideEdgeByParamsToPoints({ shape: e, nrOfDivisions: inputs.nrZigZags * 2, removeEndPoint: false, removeStartPoint: false }));
}
} else E{
if (inputs.divideByEqualDistance) {
points1 = [this.divideWireByEqualDistanceToPoints({ shape: wire1, nrOfDivisions: inputs.nrZigZags * 2, removeEndPoint: false, removeStartPoint: false })];
points2 = [this.divideWireByEqualDistanceToPoints({ shape: wire2, nrOfDivisions: inputs.nrZigZags * 2, removeEndPoint: false, removeStartPoint: false })];
} else {
points1 = [this.divideWireByParamsToPoints({ shape: wire1, nrOfDivisions: inputs.nrZigZags * 2, removeEndPoint: false, removeStartPoint: false })];
points2 = [this.divideWireByParamsToPoints({ shape: wire2, nrOfDivisions: inputs.nrZigZags * 2, removeEndPoint: false, removeStartPoint: false })];
}
}
const wires = points1.map((pts1, index) => {
const pts2 = points2[index];
const ptsInZigZagOrder = [];
for (let i = 0; i < pts1.length; i++) {
if (i % 2 === 0) {
if (inputs.inverse) {
ptsInZigZagOrder.push(pts2[i]);
} else {
ptsInZigZagOrder.push(pts1[i]);
}
} else {
if (inputs.inverse) {
ptsInZigZagOrder.push(pts1[i]);
} else {
ptsInZigZagOrder.push(pts2[i]);
}
}
}
return this.createPolylineWire({ points: ptsInZigZagOrder });
});
return this.converterService.combineEdgesAndWiresIntoAWire({ shapes: wires });
}
getWireCenterOfMass(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): Base.Point3 {
return this.geomService.getLinearCenterOfMass(inputs);
}
hexagonsInGrid(inputs: Inputs.OCCT.HexagonsInGridDto): TopoDS_Wire[] {
const hex = this.base.point.hexGridScaledToFit({ ...inputs, centerGrid: true, pointsOnGround: true });
const wires = hex.hexagons.map(hex => {
return this.createPolygonWire({ points: hex });
});
let currentScalePatternWidthIndex = 0;
let currentScalePatternHeightIndex = 0;
let currentInclusionPatternIndex = 0;
let currentFilletPatternIndex = 0;
const res = [];
for (let i = 0; i < inputs.nrHexagonsInHeight; i++) {
for (let j = 0; j < inputs.nrHexagonsInWidth; j++) {
let scaleFromPatternWidth = 1;
Iif (inputs.scalePatternWidth && inputs.scalePatternWidth.length > 0) {
scaleFromPatternWidth = inputs.scalePatternWidth[currentScalePatternWidthIndex];
currentScalePatternWidthIndex++;
if (currentScalePatternWidthIndex >= inputs.scalePatternWidth.length) {
currentScalePatternWidthIndex = 0;
}
}
let scaleFromPatternHeight = 1;
Iif (inputs.scalePatternHeight && inputs.scalePatternHeight.length > 0) {
scaleFromPatternHeight = inputs.scalePatternHeight[currentScalePatternHeightIndex];
currentScalePatternHeightIndex++;
if (currentScalePatternHeightIndex >= inputs.scalePatternHeight.length) {
currentScalePatternHeightIndex = 0;
}
}
let include = true;
Iif (inputs.inclusionPattern && inputs.inclusionPattern.length > 0) {
include = inputs.inclusionPattern[currentInclusionPatternIndex];
currentInclusionPatternIndex++;
if (currentInclusionPatternIndex >= inputs.inclusionPattern.length) {
currentInclusionPatternIndex = 0;
}
}
let fillet = 0;
Iif (inputs.filletPattern && inputs.filletPattern.length > 0) {
fillet = inputs.filletPattern[currentFilletPatternIndex];
currentFilletPatternIndex++;
if (currentFilletPatternIndex >= inputs.filletPattern.length) {
currentFilletPatternIndex = 0;
}
}
Eif (include) {
fillet = hex.maxFilletRadius * fillet;
const hexagon = wires[i * inputs.nrHexagonsInWidth + j];
const hexagonCenter = hex.centers[i * inputs.nrHexagonsInWidth + j];
Iif (fillet > 0) {
const filletRectangle = this.filletsService.fillet2d({
shape: hexagon,
radius: fillet,
});
const scaleVec2 = [scaleFromPatternWidth, 1, scaleFromPatternHeight] as Base.Vector3;
let hexScaled = filletRectangle;
if (scaleFromPatternWidth !== 1 || scaleFromPatternHeight !== 1) {
hexScaled = this.transformsService.scale3d({
shape: filletRectangle,
center: hexagonCenter,
scale: scaleVec2,
});
}
res.push(hexScaled);
} else {
const scaleVec2 = [scaleFromPatternWidth, 1, scaleFromPatternHeight] as Base.Vector3;
let hexScaled = hexagon;
Iif (scaleFromPatternWidth !== 1 || scaleFromPatternHeight !== 1) {
hexScaled = this.transformsService.scale3d({
shape: hexagon,
center: hexagonCenter,
scale: scaleVec2,
});
}
res.push(hexScaled);
}
}
}
}
return res;
}
createWireFromEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>): TopoDS_Wire {
const makeWire = new this.occ.BRepBuilderAPI_MakeWire_2(inputs.shape);
const wire = makeWire.Wire();
makeWire.delete();
return wire;
}
createBSpline(inputs: Inputs.OCCT.BSplineDto): TopoDS_Wire {
const ptList = new this.occ.TColgp_Array1OfPnt_2(1, inputs.points.length + (inputs.closed ? 1 : 0));
const gpPnts: gp_Pnt_3[] = [];
for (let pIndex = 1; pIndex <= inputs.points.length; pIndex++) {
const gpPnt = this.entitiesService.gpPnt(inputs.points[pIndex - 1]);
gpPnts.push(gpPnt);
ptList.SetValue(pIndex, gpPnt);
}
if (inputs.closed) { ptList.SetValue(inputs.points.length + 1, ptList.Value(1)); }
const ptsToBspline = new this.occ.GeomAPI_PointsToBSpline_2(ptList, 3, 8,
(this.occ.GeomAbs_Shape.GeomAbs_C2 as GeomAbs_Shape), 1.0e-3);
const bsplineHandle = ptsToBspline.Curve();
const bspline = bsplineHandle.get();
const bsplineCrv = new this.occ.Handle_Geom_Curve_2(bspline);
const edgeMaker = new this.occ.BRepBuilderAPI_MakeEdge_24(bsplineCrv);
const edge = edgeMaker.Edge();
const wireMaker = new this.occ.BRepBuilderAPI_MakeWire_2(edge);
const wire = wireMaker.Wire();
gpPnts.forEach(p => p.delete());
ptList.delete();
ptsToBspline.delete();
bsplineHandle.Nullify();
bsplineHandle.delete();
bsplineCrv.Nullify();
bsplineCrv.delete();
edgeMaker.delete();
edge.delete();
wireMaker.delete();
return wire;
}
createBezier(inputs: Inputs.OCCT.BezierDto) {
const ptList = new this.occ.TColgp_Array1OfPnt_2(1, inputs.points.length + (inputs.closed ? 1 : 0));
for (let pIndex = 1; pIndex <= inputs.points.length; pIndex++) {
ptList.SetValue(pIndex, this.entitiesService.gpPnt(inputs.points[pIndex - 1]));
}
if (inputs.closed) { ptList.SetValue(inputs.points.length + 1, ptList.Value(1)); }
const geomBezierCurveHandle = new this.occ.Geom_BezierCurve_1(ptList);
const geomCurve = new this.occ.Handle_Geom_Curve_2(geomBezierCurveHandle);
const edgeMaker = new this.occ.BRepBuilderAPI_MakeEdge_24(geomCurve);
const edge = edgeMaker.Edge();
const makeWire = new this.occ.BRepBuilderAPI_MakeWire_2(edge);
const result = makeWire.Wire();
makeWire.delete();
edgeMaker.delete();
edge.delete();
geomCurve.delete();
ptList.delete();
return result;
}
createBezierWeights(inputs: Inputs.OCCT.BezierWeightsDto) {
Iif (!inputs.closed && inputs.points.length !== inputs.weights.length) {
throw new Error("Number of points and weights must be the same when bezier is not clsoed.");
} else Iif (inputs.closed && inputs.points.length !== inputs.weights.length - 1) {
throw new Error("Number of points must be one less than number of weights when bezier is clsoed.");
}
const ptList = new this.occ.TColgp_Array1OfPnt_2(1, inputs.points.length + (inputs.closed ? 1 : 0));
for (let pIndex = 1; pIndex <= inputs.points.length; pIndex++) {
ptList.SetValue(pIndex, this.entitiesService.gpPnt(inputs.points[pIndex - 1]));
}
Iif (inputs.closed) { ptList.SetValue(inputs.points.length + 1, ptList.Value(1)); }
const arrayOfReal = new this.occ.TColStd_Array1OfReal_2(1, inputs.weights.length);
for (let i = 1; i <= inputs.weights.length; i++) {
arrayOfReal.SetValue(i, inputs.weights[i - 1]);
}
const geomBezierCurveHandle = new this.occ.Geom_BezierCurve_2(ptList, arrayOfReal);
const geomCurve = new this.occ.Handle_Geom_Curve_2(geomBezierCurveHandle);
const edgeMaker = new this.occ.BRepBuilderAPI_MakeEdge_24(geomCurve);
const edge = edgeMaker.Edge();
const makeWire = new this.occ.BRepBuilderAPI_MakeWire_2(edge);
const result = makeWire.Wire();
makeWire.delete();
edgeMaker.delete();
edge.delete();
geomCurve.delete();
ptList.delete();
arrayOfReal.delete();
return result;
}
addEdgesAndWiresToWire(inputs: Inputs.OCCT.ShapeShapesDto<TopoDS_Wire, TopoDS_Wire | TopoDS_Edge>): TopoDS_Wire {
const makeWire = new this.occ.BRepBuilderAPI_MakeWire_1();
makeWire.Add_2(inputs.shape);
inputs.shapes.forEach((shape) => {
if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.TopAbs_EDGE) {
makeWire.Add_1(shape);
} else if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.TopAbs_WIRE) {
makeWire.Add_2(shape);
}
});
let result;
if (makeWire.IsDone()) {
result = makeWire.Wire();
} else {
throw new Error("Wire could not be constructed. Check if edges and wires do not have disconnected elements.");
}
makeWire.delete();
return result;
}
startPointOnWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): Base.Point3 {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const res = this.geomService.startPointOnCurve({ shape: curve });
return res;
}
midPointOnWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): Base.Point3 {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const res = this.geomService.pointOnCurveAtParam({ shape: curve, param: 0.5 });
return res;
}
endPointOnWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): Base.Point3 {
const wire = inputs.shape;
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
const res = this.geomService.endPointOnCurve({ shape: curve });
return res;
}
textWires(inputs: Inputs.OCCT.TextWiresDto): TopoDS_Wire[] {
const lines = this.base.textService.vectorText(inputs);
const wires: TopoDS_Wire[] = [];
lines.forEach((line) => {
line.chars.forEach((char) => {
char.paths.forEach(polyline => {
const wire = this.createPolylineWire({ points: polyline });
Eif (wire) {
wires.push(wire);
}
});
});
});
return wires;
}
textWiresWithData(inputs: Inputs.OCCT.TextWiresDto): ObjectDefinition<TextWiresDataDto<string>, TopoDS_Shape> {
const lines = this.base.textService.vectorText(inputs);
const wires: TopoDS_Wire[] = [];
const characterCompounds: { id: string, shape: TopoDS_Compound }[] = [];
lines.forEach((line) => {
line.chars.forEach((char, index) => {
const characterWires = [];
char.paths.forEach(polyline => {
const wire = this.createPolylineWire({ points: polyline });
Eif (wire) {
wires.push(wire);
characterWires.push(wire);
}
});
const characterCompound = this.converterService.makeCompound({ shapes: characterWires });
characterCompounds.push({ id: `char-${index}`, shape: characterCompound });
});
});
const compound = this.converterService.makeCompound({ shapes: wires });
const dataRes = new TextWiresDataDto<string>();
const box = this.operationsService.boundingBoxOfShape({ shape: compound });
const width = box.max[0] - box.min[0];
const height = box.max[1] - box.min[1];
dataRes.width = width;
dataRes.height = height;
dataRes.compound = "text-compound";
const res = new ObjectDefinition<TextWiresDataDto<string>, TopoDS_Compound>();
res.data = dataRes;
res.compound = compound;
res.shapes = [{ id: "text-compound", shape: compound }, ...characterCompounds];
return res;
}
placeWire(wire: TopoDS_Wire, surface: Geom_Surface) {
const edges = this.shapeGettersService.getEdges({ shape: wire });
const newEdges: TopoDS_Edge[] = [];
edges.forEach(e => {
const umin = { current: 0 };
const umax = { current: 0 };
this.occRefReturns.BRep_Tool_Range_1(e, umin, umax);
const crv = this.occRefReturns.BRep_Tool_Curve_2(e, umin, umax);
Eif (!crv.IsNull()) {
const plane = this.entitiesService.gpPln([0, 0, 0], [0, 1, 0]);
const c2dHandle = this.occ.GeomAPI.To2d(crv, plane);
const c2 = c2dHandle.get();
const newEdgeOnSrf = this.edgesService.makeEdgeFromGeom2dCurveAndSurfaceBounded({ curve: c2, surface }, umin.current, umax.current);
Eif (newEdgeOnSrf) {
newEdges.push(newEdgeOnSrf);
}
plane.delete();
c2dHandle.delete();
}
crv.delete();
});
edges.forEach(e => e.delete());
const res = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: newEdges });
newEdges.forEach(e => e.delete());
return res;
}
wiresToPoints(inputs: Inputs.OCCT.WiresToPointsDto<TopoDS_Shape>): Inputs.Base.Point3[][] {
const wires = this.shapeGettersService.getWires({ shape: inputs.shape });
const allWirePoints = [];
wires.forEach(w => {
const edgePoints = this.edgesService.edgesToPoints({ ...inputs, shape: w });
const flatPoints = edgePoints.flat();
const dupsRemoved = this.vecHelper.removeConsecutiveDuplicates(flatPoints, false);
allWirePoints.push(dupsRemoved);
});
return allWirePoints;
}
}
|