geometrix 0.5.37 → 0.5.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3,7 +3,8 @@ declare const colors: {
3
3
  line: string;
4
4
  vector: string;
5
5
  contour: string;
6
- main: string;
6
+ mainOuter: string;
7
+ mainInner: string;
7
8
  mainB: string;
8
9
  second: string;
9
10
  secondB: string;
@@ -269,6 +270,7 @@ interface tPaxContourPath {
269
270
  seg: tPaxSeg[];
270
271
  }
271
272
  type tPaxContour = tPaxContourPath | tPaxContourCircle;
273
+ type tPaxFace = tPaxContour[];
272
274
  declare function paxCircle(cx: number, cy: number, radius: number): tPaxContourCircle;
273
275
  declare class PaxPath {
274
276
  seg: tPaxSeg[];
@@ -403,11 +405,15 @@ interface tLayers {
403
405
  ruler: boolean;
404
406
  refframe: boolean;
405
407
  }
408
+ /**
409
+ * The face-type is a list of contours. The first contour is the outer, the remaining are the inner contours
410
+ */
411
+ type tOuterInner = tContour[];
406
412
  declare class Figure {
407
413
  pointList: Point[];
408
414
  lineList: Line[];
409
415
  vectorList: Vector[];
410
- mainList: tContour[];
416
+ mainList: tOuterInner[];
411
417
  mainBList: tContour[];
412
418
  secondList: tContour[];
413
419
  secondBList: tContour[];
@@ -422,13 +428,23 @@ declare class Figure {
422
428
  addLine(iline: Line): void;
423
429
  addLines(ilines: Line[]): void;
424
430
  addVector(ivector: Vector): void;
425
- addMain(icontour: tContour): void;
431
+ /**
432
+ * add one Outer contour and several Inner contours to the Main Layer
433
+ * @param {tOuterInner} iFace - the Face (i.e one Outer and several Inner contours) to be added
434
+ */
435
+ addMainOI(iFace: tOuterInner): void;
436
+ /**
437
+ * add one Outer contour to the Main Layer
438
+ * @param {tContour} iFace - the Face (without inner contours) to be added
439
+ */
440
+ addMainO(iFace: tContour): void;
426
441
  addSecond(icontour: tContour): void;
427
442
  addDynamics(icontour: tContour): void;
428
443
  translate(ix: number, iy: number): Figure;
429
444
  translatePolar(ia: number, il: number): Figure;
430
445
  rotate(ix: number, iy: number, ia: number): Figure;
431
446
  mergeFigure(ifig: Figure, mainToSecond?: boolean): void;
447
+ mainListC(): tContour[];
432
448
  clear(): void;
433
449
  /** @internal */
434
450
  getMinMax(): void;
@@ -440,9 +456,9 @@ declare class Figure {
440
456
  draw(ctx: CanvasRenderingContext2D, adjust: tCanvasAdjust, layers: tLayers): void;
441
457
  }
442
458
  declare function figure(): Figure;
443
- type tFaces = Record<string, Figure>;
459
+ type tFigures = Record<string, Figure>;
444
460
  /** For cli-app and ui-app */
445
- declare function mergeFaces(iFaces: tFaces): Figure;
461
+ declare function mergeFaces(iFigures: tFigures): Figure;
446
462
  declare function initLayers(): tLayers;
447
463
  declare function copyLayers(iLayers: tLayers): tLayers;
448
464
 
@@ -508,7 +524,7 @@ declare class DesignParam {
508
524
  declare function designParam(iparamDef: tParamDef, suffix?: string): DesignParam;
509
525
  declare function pNumber(name: string, unit: string, init: number, min?: number, max?: number, step?: number): tParam;
510
526
  declare function pCheckbox(name: string, init: boolean): tParam;
511
- declare function pDropdown(name: string, values: string[]): tParam;
527
+ declare function pDropdown(name: string, values: string[], iInit?: number): tParam;
512
528
  declare function pSectionSeparator(name: string): tParam;
513
529
 
514
530
  type tPosiOrien = [number, number, number];
@@ -524,7 +540,7 @@ interface tGeom {
524
540
  partName: string;
525
541
  calcErr: boolean;
526
542
  logstr: string;
527
- fig: tFaces;
543
+ fig: tFigures;
528
544
  vol: tVolume;
529
545
  sub: tSubDesign;
530
546
  }
@@ -587,7 +603,8 @@ declare enum EFormat {
587
603
  ePAX = 5,
588
604
  eOPENSCAD = 6,
589
605
  eJSCAD = 7,
590
- eZIP = 8
606
+ eFREECAD = 8,
607
+ eZIP = 9
591
608
  }
592
609
  declare function fileTextContent(fgeom: tGeomFunc, paramVal: tParamVal, ipDef: tParamDef, eFace: string, exportFormat: EFormat): string;
593
610
  declare function fileBinContent(fgeom: tGeomFunc, tSim: number, paramVal: tParamVal, ipDef: tParamDef, exportFormat: EFormat): Promise<Blob>;
@@ -657,4 +674,4 @@ declare function version_details(appPackage: tPackage): string[];
657
674
 
658
675
  declare function checkImpPages(pages: tAllPageDef): [boolean, string];
659
676
 
660
- export { Contour, ContourCircle, DesignParam, DxfSeg, DxfWrite, EBVolume, EExtrude, EFormat, Figure, Line, PSeg, PType, PaxPath, Point, SegDbg, SegEnum, Segment1, Segment2, ShapePoint, Transform3d, Vector, aBFromLaLbAa, aCFromAaAb, aCFromLaLbLc, adjustCenter, adjustInit, adjustRect, adjustScale, adjustTranslate, adjustZero, arcSeg1To2, arcSeg2To1, bisector, canvas2point, canvasTranslatePolar, checkGeom, checkImpPages, circleCenter, colors, contour, contourCircle, copyLayers, createParamFile, ctrOblong, ctrRectRot, ctrRectRot2, ctrRectangle, ctrTrapezoid, ctrTrapezoidRot2, degToRad, designParam, dxfSegArc, dxfSegCircle, dxfSegLine, dxfWriter, ffix, figure, fileBin, fileBinContent, fileMime, fileSuffix, fileTextContent, fround, gSegDbg, initGeom, initLayers, isActiveCorner, isAddPoint, isCorner, isSeg, isWithin, lbFromLaAaAb, lcFromLaLbAc, line, linePP, makeCorner, mergeFaces, oneDesignParam, orientedArc, pCheckbox, pDropdown, pNumber, pSectionSeparator, paramListToVal, parseParamFile, paxCircle, paxPath, point, point2canvas, pointMinMax, prefixLog, radToDeg, radius2canvas, rightTriLaFromLbLc, rightTriLbFromLaLc, roundZero, type tAffine, type tAllLink, type tAllPageDef, type tBVolume, type tCanvasAdjust, type tCartesian, type tContour, type tDependencies, type tDesignParamList, type tDesignParamOne, type tExtrude, type tFaces, type tGeom, type tGeomFunc, type tInherit, type tLayers, type tPackage, type tPageDef, type tParam, type tParamChanged, type tParamDef, type tParamVal, type tParamValInFile, type tPaxContour, type tPaxContourCircle, type tPaxContourPath, type tPaxSeg, type tPaxSegArc, type tPaxSegSt, type tPolar, type tPosiOrien, type tSimTime, type tSubDesign, type tSubInst, type tT3dMatrix, type tVec3, type tVec4, type tVolume, tolerance, transform3d, vector, version_details, withinHPiHPi, withinPiPi, withinZero2Pi, withinZeroPi, zeroPDef };
677
+ export { Contour, ContourCircle, DesignParam, DxfSeg, DxfWrite, EBVolume, EExtrude, EFormat, Figure, Line, PSeg, PType, PaxPath, Point, SegDbg, SegEnum, Segment1, Segment2, ShapePoint, Transform3d, Vector, aBFromLaLbAa, aCFromAaAb, aCFromLaLbLc, adjustCenter, adjustInit, adjustRect, adjustScale, adjustTranslate, adjustZero, arcSeg1To2, arcSeg2To1, bisector, canvas2point, canvasTranslatePolar, checkGeom, checkImpPages, circleCenter, colors, contour, contourCircle, copyLayers, createParamFile, ctrOblong, ctrRectRot, ctrRectRot2, ctrRectangle, ctrTrapezoid, ctrTrapezoidRot2, degToRad, designParam, dxfSegArc, dxfSegCircle, dxfSegLine, dxfWriter, ffix, figure, fileBin, fileBinContent, fileMime, fileSuffix, fileTextContent, fround, gSegDbg, initGeom, initLayers, isActiveCorner, isAddPoint, isCorner, isSeg, isWithin, lbFromLaAaAb, lcFromLaLbAc, line, linePP, makeCorner, mergeFaces, oneDesignParam, orientedArc, pCheckbox, pDropdown, pNumber, pSectionSeparator, paramListToVal, parseParamFile, paxCircle, paxPath, point, point2canvas, pointMinMax, prefixLog, radToDeg, radius2canvas, rightTriLaFromLbLc, rightTriLbFromLaLc, roundZero, type tAffine, type tAllLink, type tAllPageDef, type tBVolume, type tCanvasAdjust, type tCartesian, type tContour, type tDependencies, type tDesignParamList, type tDesignParamOne, type tExtrude, type tFigures, type tGeom, type tGeomFunc, type tInherit, type tLayers, type tOuterInner, type tPackage, type tPageDef, type tParam, type tParamChanged, type tParamDef, type tParamVal, type tParamValInFile, type tPaxContour, type tPaxContourCircle, type tPaxContourPath, type tPaxFace, type tPaxSeg, type tPaxSegArc, type tPaxSegSt, type tPolar, type tPosiOrien, type tSimTime, type tSubDesign, type tSubInst, type tT3dMatrix, type tVec3, type tVec4, type tVolume, tolerance, transform3d, vector, version_details, withinHPiHPi, withinPiPi, withinZero2Pi, withinZeroPi, zeroPDef };
package/dist/index.js CHANGED
@@ -71,7 +71,8 @@ var colors = {
71
71
  line: "grey",
72
72
  vector: "DarkTurquoise",
73
73
  contour: "green",
74
- main: "SteelBlue",
74
+ mainOuter: "SlateBlue",
75
+ mainInner: "SteelBlue",
75
76
  mainB: "SlateGrey",
76
77
  second: "Violet",
77
78
  secondB: "SlateGrey",
@@ -2493,12 +2494,28 @@ var Figure = class _Figure {
2493
2494
  addVector(ivector) {
2494
2495
  this.vectorList.push(ivector);
2495
2496
  }
2496
- addMain(icontour) {
2497
- const roundedContour = icontour.generateContour();
2498
- this.addPoints(roundedContour.generatePoints());
2499
- this.addLines(roundedContour.generateLines());
2500
- this.mainList.push(roundedContour);
2501
- this.mainBList.push(icontour.extractSkeleton());
2497
+ /**
2498
+ * add one Outer contour and several Inner contours to the Main Layer
2499
+ * @param {tOuterInner} iFace - the Face (i.e one Outer and several Inner contours) to be added
2500
+ */
2501
+ addMainOI(iFace) {
2502
+ const oneFace = [];
2503
+ for (const oneCtr of iFace) {
2504
+ const roundedContour = oneCtr.generateContour();
2505
+ this.addPoints(roundedContour.generatePoints());
2506
+ this.addLines(roundedContour.generateLines());
2507
+ oneFace.push(roundedContour);
2508
+ this.mainBList.push(oneCtr.extractSkeleton());
2509
+ }
2510
+ this.mainList.push(oneFace);
2511
+ }
2512
+ /**
2513
+ * add one Outer contour to the Main Layer
2514
+ * @param {tContour} iFace - the Face (without inner contours) to be added
2515
+ */
2516
+ addMainO(iFace) {
2517
+ const face = [iFace];
2518
+ this.addMainOI(face);
2502
2519
  }
2503
2520
  addSecond(icontour) {
2504
2521
  const roundedContour = icontour.generateContour();
@@ -2523,8 +2540,12 @@ var Figure = class _Figure {
2523
2540
  for (const vec of this.vectorList) {
2524
2541
  rfig.addVector(vec.translate(ix, iy));
2525
2542
  }
2526
- for (const ctr of this.mainList) {
2527
- rfig.addMain(ctr.translate(ix, iy));
2543
+ for (const face of this.mainList) {
2544
+ const oneFace = [];
2545
+ for (const ctr of face) {
2546
+ oneFace.push(ctr.translate(ix, iy));
2547
+ }
2548
+ rfig.addMainOI(oneFace);
2528
2549
  }
2529
2550
  for (const ctr of this.secondList) {
2530
2551
  rfig.addSecond(ctr.translate(ix, iy));
@@ -2549,8 +2570,12 @@ var Figure = class _Figure {
2549
2570
  for (const vec of this.vectorList) {
2550
2571
  rfig.addVector(vec.rotate(pt0, ia));
2551
2572
  }
2552
- for (const ctr of this.mainList) {
2553
- rfig.addMain(ctr.rotate(ix, iy, ia));
2573
+ for (const face of this.mainList) {
2574
+ const oneFace = [];
2575
+ for (const ctr of face) {
2576
+ oneFace.push(ctr.rotate(ix, iy, ia));
2577
+ }
2578
+ rfig.addMainOI(oneFace);
2554
2579
  }
2555
2580
  for (const ctr of this.secondList) {
2556
2581
  rfig.addSecond(ctr.rotate(ix, iy, ia));
@@ -2570,11 +2595,17 @@ var Figure = class _Figure {
2570
2595
  for (const vec of ifig.vectorList) {
2571
2596
  this.addVector(vec.clone());
2572
2597
  }
2573
- for (const ctr of ifig.mainList) {
2598
+ for (const face of ifig.mainList) {
2599
+ const oneFace = [];
2600
+ for (const ctr of face) {
2601
+ oneFace.push(ctr.clone());
2602
+ }
2574
2603
  if (mainToSecond) {
2575
- this.addSecond(ctr.clone());
2604
+ for (const ctr of oneFace) {
2605
+ this.addSecond(ctr);
2606
+ }
2576
2607
  } else {
2577
- this.addMain(ctr.clone());
2608
+ this.addMainOI(oneFace);
2578
2609
  }
2579
2610
  }
2580
2611
  for (const ctr of ifig.secondList) {
@@ -2584,6 +2615,15 @@ var Figure = class _Figure {
2584
2615
  this.addDynamics(ctr.clone());
2585
2616
  }
2586
2617
  }
2618
+ mainListC() {
2619
+ const rListC = [];
2620
+ for (const face of this.mainList) {
2621
+ for (const ctr of face) {
2622
+ rListC.push(ctr);
2623
+ }
2624
+ }
2625
+ return rListC;
2626
+ }
2587
2627
  clear() {
2588
2628
  this.pointList = [];
2589
2629
  this.lineList = [];
@@ -2676,8 +2716,14 @@ var Figure = class _Figure {
2676
2716
  }
2677
2717
  }
2678
2718
  if (layers.main) {
2679
- for (const li of this.mainList) {
2680
- li.draw(ctx, adjust, colors.main);
2719
+ for (const face of this.mainList) {
2720
+ for (const [idx, li] of face.entries()) {
2721
+ let ctrColor = colors.mainOuter;
2722
+ if (idx > 0) {
2723
+ ctrColor = colors.mainInner;
2724
+ }
2725
+ li.draw(ctx, adjust, ctrColor);
2726
+ }
2681
2727
  }
2682
2728
  }
2683
2729
  if (layers.mainB) {
@@ -2717,10 +2763,10 @@ var Figure = class _Figure {
2717
2763
  function figure() {
2718
2764
  return new Figure();
2719
2765
  }
2720
- function mergeFaces(iFaces) {
2766
+ function mergeFaces(iFigures) {
2721
2767
  const rfig = figure();
2722
- for (const face in iFaces) {
2723
- const fig = iFaces[face];
2768
+ for (const ifig in iFigures) {
2769
+ const fig = iFigures[ifig];
2724
2770
  for (const ipoint of fig.pointList) {
2725
2771
  rfig.pointList.push(ipoint);
2726
2772
  }
@@ -2730,8 +2776,8 @@ function mergeFaces(iFaces) {
2730
2776
  for (const ivector of fig.vectorList) {
2731
2777
  rfig.vectorList.push(ivector);
2732
2778
  }
2733
- for (const ctr of fig.mainList) {
2734
- rfig.mainList.push(ctr);
2779
+ for (const face of fig.mainList) {
2780
+ rfig.mainList.push(face);
2735
2781
  }
2736
2782
  for (const ctr of fig.mainBList) {
2737
2783
  rfig.mainBList.push(ctr);
@@ -2923,11 +2969,15 @@ function pCheckbox(name, init) {
2923
2969
  };
2924
2970
  return rParam;
2925
2971
  }
2926
- function pDropdown(name, values) {
2972
+ function pDropdown(name, values, iInit = 0) {
2973
+ let init = 0;
2974
+ if (iInit < values.length) {
2975
+ init = iInit;
2976
+ }
2927
2977
  const rParam = {
2928
2978
  name,
2929
2979
  unit: "dropdown",
2930
- init: 0,
2980
+ init,
2931
2981
  min: 0,
2932
2982
  max: values.length - 1,
2933
2983
  step: 1,
@@ -3001,10 +3051,14 @@ function prefixLog(iLog, iPartName) {
3001
3051
  // src/write_pax.ts
3002
3052
  var PaxWrite = class {
3003
3053
  //constructor() {}
3004
- figureToPaxF(aCtr) {
3054
+ figureToPaxF(aFaces) {
3005
3055
  const rPaxF = [];
3006
- for (const ctr of aCtr) {
3007
- rPaxF.push(ctr.toPax());
3056
+ for (const face of aFaces) {
3057
+ const oneFace = [];
3058
+ for (const ctr of face) {
3059
+ oneFace.push(ctr.toPax());
3060
+ }
3061
+ rPaxF.push(oneFace);
3008
3062
  }
3009
3063
  return rPaxF;
3010
3064
  }
@@ -3021,7 +3075,7 @@ var PaxWrite = class {
3021
3075
  partName: geome0.partName,
3022
3076
  pDef: ipDef,
3023
3077
  params: paramVal,
3024
- faces: this.getFigures(geome0.fig),
3078
+ figures: this.getFigures(geome0.fig),
3025
3079
  volume: geome0.vol,
3026
3080
  subs: geome0.sub,
3027
3081
  log: geome0.logstr
@@ -3197,26 +3251,28 @@ var OpenscadWrite = class {
3197
3251
  const rStr = "// Generated by Parametrix\n";
3198
3252
  return rStr;
3199
3253
  }
3200
- getOneFigure(aCtr, faceId) {
3254
+ getOneFigure(aFaces, faceId) {
3201
3255
  const oscadWF = new OpenscadWriteFigure();
3202
- for (const paxCtr of aCtr) {
3203
- if (paxCtr.circle === true) {
3204
- const paxCircle2 = paxCtr;
3205
- const oscadSeg = oscadSegCircle(paxCircle2.cx, paxCircle2.cy, paxCircle2.radius);
3206
- oscadWF.addContour(oscadSeg);
3207
- } else {
3208
- const paxPath2 = paxCtr;
3209
- const oscadSeg = toOpenscadSeg(paxPath2.seg);
3210
- oscadWF.addContour(oscadSeg);
3256
+ for (const paxFace of aFaces) {
3257
+ for (const paxCtr of paxFace) {
3258
+ if (paxCtr.circle === true) {
3259
+ const paxCircle2 = paxCtr;
3260
+ const oscadSeg = oscadSegCircle(paxCircle2.cx, paxCircle2.cy, paxCircle2.radius);
3261
+ oscadWF.addContour(oscadSeg);
3262
+ } else {
3263
+ const paxPath2 = paxCtr;
3264
+ const oscadSeg = toOpenscadSeg(paxPath2.seg);
3265
+ oscadWF.addContour(oscadSeg);
3266
+ }
3211
3267
  }
3212
3268
  }
3213
3269
  const rOscadF = oscadWF.getFigure(faceId);
3214
3270
  return rOscadF;
3215
3271
  }
3216
- getAllFigures(faces, partName) {
3272
+ getAllFigures(figures, partName) {
3217
3273
  let rStr = "";
3218
- for (const face in faces) {
3219
- const figu = this.getOneFigure(faces[face], `${partName}_${face}`);
3274
+ for (const face in figures) {
3275
+ const figu = this.getOneFigure(figures[face], `${partName}_${face}`);
3220
3276
  rStr += figu;
3221
3277
  }
3222
3278
  return rStr;
@@ -3327,7 +3383,7 @@ module ${inherit.outName} () {
3327
3383
  const subGeoms = this.getAllSubGeoms(vol.inherits);
3328
3384
  for (const oneGeom of subGeoms) {
3329
3385
  const paxJson = paxWrite().getPaxJson({}, oneGeom, zeroPDef);
3330
- rStr += this.getAllFigures(paxJson.faces, paxJson.partName);
3386
+ rStr += this.getAllFigures(paxJson.figures, paxJson.partName);
3331
3387
  rStr += this.getVolume(oneGeom.vol);
3332
3388
  }
3333
3389
  rStr += this.getAllInherits(vol.inherits);
@@ -3344,7 +3400,7 @@ pax_${partName}();
3344
3400
  }
3345
3401
  getExportFile(pax) {
3346
3402
  let rStr = this.getHeader();
3347
- rStr += this.getAllFigures(pax.faces, pax.partName);
3403
+ rStr += this.getAllFigures(pax.figures, pax.partName);
3348
3404
  rStr += this.getVolume(pax.volume);
3349
3405
  rStr += this.getFooter(pax.partName);
3350
3406
  return rStr;
@@ -3460,17 +3516,19 @@ const main = () => {
3460
3516
  `;
3461
3517
  return rStr;
3462
3518
  }
3463
- getOneFigure(aCtr, faceId) {
3519
+ getOneFigure(aFaces, faceId) {
3464
3520
  const ojscadWF = new OjscadWriteFigure();
3465
- for (const paxCtr of aCtr) {
3466
- if (paxCtr.circle === true) {
3467
- const paxCircle2 = paxCtr;
3468
- const ojscadSeg = ojscadSegCircle(paxCircle2.cx, paxCircle2.cy, paxCircle2.radius);
3469
- ojscadWF.addContour(ojscadSeg);
3470
- } else {
3471
- const paxPath2 = paxCtr;
3472
- const ojscadSeg = toOpenjscadSeg(paxPath2.seg);
3473
- ojscadWF.addContour(ojscadSeg);
3521
+ for (const paxFace of aFaces) {
3522
+ for (const paxCtr of paxFace) {
3523
+ if (paxCtr.circle === true) {
3524
+ const paxCircle2 = paxCtr;
3525
+ const ojscadSeg = ojscadSegCircle(paxCircle2.cx, paxCircle2.cy, paxCircle2.radius);
3526
+ ojscadWF.addContour(ojscadSeg);
3527
+ } else {
3528
+ const paxPath2 = paxCtr;
3529
+ const ojscadSeg = toOpenjscadSeg(paxPath2.seg);
3530
+ ojscadWF.addContour(ojscadSeg);
3531
+ }
3474
3532
  }
3475
3533
  }
3476
3534
  const rOjscadF = ojscadWF.getFigure(faceId);
@@ -3576,7 +3634,7 @@ const ${inherit.outName} =
3576
3634
  const subGeoms = this.getAllSubGeoms(vol.inherits);
3577
3635
  for (const oneGeom of subGeoms) {
3578
3636
  const paxJson = paxWrite().getPaxJson({}, oneGeom, zeroPDef);
3579
- rStr += this.getAllFigures(paxJson.faces, paxJson.partName);
3637
+ rStr += this.getAllFigures(paxJson.figures, paxJson.partName);
3580
3638
  rStr += this.getVolume(oneGeom.vol);
3581
3639
  }
3582
3640
  rStr += this.getAllInherits(vol.inherits);
@@ -3595,7 +3653,7 @@ module.exports = { main };
3595
3653
  }
3596
3654
  getExportFile(pax) {
3597
3655
  let rStr = this.getHeader();
3598
- rStr += this.getAllFigures(pax.faces, pax.partName);
3656
+ rStr += this.getAllFigures(pax.figures, pax.partName);
3599
3657
  rStr += this.getVolume(pax.volume);
3600
3658
  rStr += this.getFooter(pax.partName);
3601
3659
  return rStr;
@@ -3606,6 +3664,276 @@ function ojscadWrite() {
3606
3664
  return rOjscadWrite;
3607
3665
  }
3608
3666
 
3667
+ // src/write_freecad.ts
3668
+ var approxMaxAngle3 = Math.PI / 8;
3669
+ var approxMaxLength3 = 20;
3670
+ function oscadSegLine2(p2x, p2y) {
3671
+ const rSeg = [[p2x, p2y]];
3672
+ return rSeg;
3673
+ }
3674
+ function oscadSegArc2(cx, cy, radius, aa1, aa2, arcCcw) {
3675
+ const rSeg = arc_to_stroke(cx, cy, radius, aa1, aa2, arcCcw, approxMaxAngle3, approxMaxLength3);
3676
+ return rSeg;
3677
+ }
3678
+ function oscadSegCircle2(cx, cy, radius) {
3679
+ const rSeg = circle_to_stroke(cx, cy, radius, approxMaxAngle3, approxMaxLength3);
3680
+ return rSeg;
3681
+ }
3682
+ function toOpenscadSeg2(paxCtr) {
3683
+ const rOscadSeg = [];
3684
+ let px1 = 0;
3685
+ let py1 = 0;
3686
+ for (const seg of paxCtr) {
3687
+ if (seg.typ === 0 /* eStart */) {
3688
+ rOscadSeg.push(...oscadSegLine2(seg.px, seg.py));
3689
+ } else if (seg.typ === 1 /* eStroke */) {
3690
+ rOscadSeg.push(...oscadSegLine2(seg.px, seg.py));
3691
+ } else if (seg.typ === 2 /* eArc */) {
3692
+ try {
3693
+ const sega = seg;
3694
+ const seg1 = new Segment1(
3695
+ convTypePaxToSeg1(sega.typ),
3696
+ sega.px,
3697
+ sega.py,
3698
+ sega.radius,
3699
+ sega.large,
3700
+ sega.ccw
3701
+ );
3702
+ const seg2 = arcSeg1To2(px1, py1, seg1);
3703
+ rOscadSeg.push(
3704
+ ...oscadSegArc2(
3705
+ seg2.pc.cx,
3706
+ seg2.pc.cy,
3707
+ seg1.radius,
3708
+ seg2.a1,
3709
+ seg2.a2,
3710
+ seg2.arcCcw
3711
+ )
3712
+ );
3713
+ } catch (emsg) {
3714
+ console.log("err730: " + emsg);
3715
+ }
3716
+ }
3717
+ px1 = seg.px;
3718
+ py1 = seg.py;
3719
+ }
3720
+ return rOscadSeg;
3721
+ }
3722
+ function ff6(ifloat) {
3723
+ return ifloat.toFixed(4);
3724
+ }
3725
+ var OpenscadWriteFigure2 = class {
3726
+ pts;
3727
+ ptIdx;
3728
+ idx;
3729
+ constructor() {
3730
+ this.pts = [];
3731
+ this.ptIdx = [];
3732
+ this.idx = 0;
3733
+ }
3734
+ addContour(ictr) {
3735
+ const pts2 = [];
3736
+ const ptIdx2 = [];
3737
+ for (const pt of ictr) {
3738
+ const [px, py] = pt;
3739
+ pts2.push(`[ ${ff6(px)}, ${ff6(py)} ]`);
3740
+ ptIdx2.push(` ${this.idx}`);
3741
+ this.idx += 1;
3742
+ }
3743
+ const ptStr = `[ ${pts2.join(",")} ]`;
3744
+ const ptIdxStr = `[ ${ptIdx2.join(",")} ]`;
3745
+ this.pts.push(ptStr);
3746
+ this.ptIdx.push(ptIdxStr);
3747
+ }
3748
+ getFigure(faceId) {
3749
+ let rStr = "";
3750
+ const aList = [];
3751
+ const bList = [];
3752
+ for (const idx of this.pts.keys()) {
3753
+ const aId = `ca_${faceId}_${idx}`;
3754
+ const bId = `cb_${faceId}_${idx}`;
3755
+ rStr += `${aId} = ${this.pts[idx]};
3756
+ `;
3757
+ rStr += `${bId} = ${this.ptIdx[idx]};
3758
+ `;
3759
+ aList.push(aId);
3760
+ bList.push(bId);
3761
+ }
3762
+ const aListStr = aList.join(", ");
3763
+ const bListStr = bList.join(", ");
3764
+ rStr += `a_${faceId} = concat(${aListStr});
3765
+ `;
3766
+ rStr += `b_${faceId} = [${bListStr}];
3767
+ `;
3768
+ return rStr;
3769
+ }
3770
+ };
3771
+ var FreecadWrite = class {
3772
+ //constructor() {}
3773
+ getHeader() {
3774
+ const rStr = "// Generated by Parametrix\n";
3775
+ return rStr;
3776
+ }
3777
+ getOneFigure(aFaces, faceId) {
3778
+ const oscadWF = new OpenscadWriteFigure2();
3779
+ for (const paxFace of aFaces) {
3780
+ for (const paxCtr of paxFace) {
3781
+ if (paxCtr.circle === true) {
3782
+ const paxCircle2 = paxCtr;
3783
+ const oscadSeg = oscadSegCircle2(paxCircle2.cx, paxCircle2.cy, paxCircle2.radius);
3784
+ oscadWF.addContour(oscadSeg);
3785
+ } else {
3786
+ const paxPath2 = paxCtr;
3787
+ const oscadSeg = toOpenscadSeg2(paxPath2.seg);
3788
+ oscadWF.addContour(oscadSeg);
3789
+ }
3790
+ }
3791
+ }
3792
+ const rOscadF = oscadWF.getFigure(faceId);
3793
+ return rOscadF;
3794
+ }
3795
+ getAllFigures(faces, partName) {
3796
+ let rStr = "";
3797
+ for (const face in faces) {
3798
+ const figu = this.getOneFigure(faces[face], `${partName}_${face}`);
3799
+ rStr += figu;
3800
+ }
3801
+ return rStr;
3802
+ }
3803
+ getOneExtrude(extrud) {
3804
+ let extrudMethod = "rotate_extrude";
3805
+ let extrudOption = "";
3806
+ if (extrud.extrudeMethod === 0 /* eLinearOrtho */) {
3807
+ if (extrud.length === void 0) {
3808
+ console.log("err103: design error: scad-linear_extrude length undefined!");
3809
+ }
3810
+ extrudMethod = "linear_extrude";
3811
+ extrudOption = `height = ${extrud.length}`;
3812
+ }
3813
+ const rStr = `
3814
+ module ${extrud.outName} () {
3815
+ translate( [ ${extrud.translate[0]}, ${extrud.translate[1]}, ${extrud.translate[2]} ])
3816
+ rotate( [ ${radToDeg(extrud.rotate[0])}, ${radToDeg(extrud.rotate[1])}, ${radToDeg(
3817
+ extrud.rotate[2]
3818
+ )} ])
3819
+ ${extrudMethod}(${extrudOption}) polygon(a_${extrud.face}, b_${extrud.face});
3820
+ }
3821
+ `;
3822
+ return rStr;
3823
+ }
3824
+ getAllExtrudes(extrudes) {
3825
+ let rStr = "";
3826
+ for (const extrud of extrudes) {
3827
+ const subp = this.getOneExtrude(extrud);
3828
+ rStr += subp;
3829
+ }
3830
+ return rStr;
3831
+ }
3832
+ getOneVolume(volum) {
3833
+ let vMethod = "identity";
3834
+ switch (volum.boolMethod) {
3835
+ case 1 /* eIntersection */:
3836
+ vMethod = "intersection";
3837
+ break;
3838
+ case 2 /* eUnion */:
3839
+ vMethod = "union";
3840
+ break;
3841
+ case 3 /* eSubstraction */:
3842
+ vMethod = "difference";
3843
+ break;
3844
+ }
3845
+ const inList2 = [];
3846
+ for (const elem of volum.inList) {
3847
+ inList2.push(`${elem}();`);
3848
+ }
3849
+ const inList3 = inList2.join("\n");
3850
+ let rStr = `
3851
+ module ${volum.outName} () {
3852
+ ${vMethod} () {
3853
+ ${inList3}
3854
+ }
3855
+ }
3856
+ `;
3857
+ if (volum.boolMethod === 0 /* eIdentity */) {
3858
+ rStr = `
3859
+ module ${volum.outName} () {
3860
+ ${inList3}
3861
+ }
3862
+ `;
3863
+ }
3864
+ return rStr;
3865
+ }
3866
+ getAllVolumes(volumes) {
3867
+ let rStr = "";
3868
+ for (const volum of volumes) {
3869
+ const subp = this.getOneVolume(volum);
3870
+ rStr += subp;
3871
+ }
3872
+ return rStr;
3873
+ }
3874
+ getAllSubGeoms(inherits) {
3875
+ const rGeoms = [];
3876
+ for (const inher of inherits) {
3877
+ if (!rGeoms.includes(inher.subgeom)) {
3878
+ rGeoms.push(inher.subgeom);
3879
+ }
3880
+ }
3881
+ return rGeoms;
3882
+ }
3883
+ getOneInherit(inherit) {
3884
+ const rStr = `
3885
+ module ${inherit.outName} () {
3886
+ translate( [ ${inherit.translate[0]}, ${inherit.translate[1]}, ${inherit.translate[2]} ])
3887
+ rotate( [ ${radToDeg(inherit.rotate[0])}, ${radToDeg(inherit.rotate[1])}, ${radToDeg(
3888
+ inherit.rotate[2]
3889
+ )} ])
3890
+ ${inherit.subdesign}();
3891
+ }
3892
+ `;
3893
+ return rStr;
3894
+ }
3895
+ getAllInherits(inherits) {
3896
+ let rStr = "";
3897
+ for (const inher of inherits) {
3898
+ const subinhe = this.getOneInherit(inher);
3899
+ rStr += subinhe;
3900
+ }
3901
+ return rStr;
3902
+ }
3903
+ getVolume(vol) {
3904
+ let rStr = "";
3905
+ if (vol.inherits !== void 0) {
3906
+ const subGeoms = this.getAllSubGeoms(vol.inherits);
3907
+ for (const oneGeom of subGeoms) {
3908
+ const paxJson = paxWrite().getPaxJson({}, oneGeom, zeroPDef);
3909
+ rStr += this.getAllFigures(paxJson.figures, paxJson.partName);
3910
+ rStr += this.getVolume(oneGeom.vol);
3911
+ }
3912
+ rStr += this.getAllInherits(vol.inherits);
3913
+ }
3914
+ rStr += this.getAllExtrudes(vol.extrudes);
3915
+ rStr += this.getAllVolumes(vol.volumes);
3916
+ return rStr;
3917
+ }
3918
+ getFooter(partName) {
3919
+ const rStr = `
3920
+ pax_${partName}();
3921
+ `;
3922
+ return rStr;
3923
+ }
3924
+ getExportFile(pax) {
3925
+ let rStr = this.getHeader();
3926
+ rStr += this.getAllFigures(pax.figures, pax.partName);
3927
+ rStr += this.getVolume(pax.volume);
3928
+ rStr += this.getFooter(pax.partName);
3929
+ return rStr;
3930
+ }
3931
+ };
3932
+ function freecadWrite() {
3933
+ const rFreecadWrite = new FreecadWrite();
3934
+ return rFreecadWrite;
3935
+ }
3936
+
3609
3937
  // src/aaExportContent.ts
3610
3938
  import * as zip from "@zip.js/zip.js";
3611
3939
  var MinMaxPoint = class {
@@ -3695,7 +4023,7 @@ function figureToSvg(aCtr) {
3695
4023
  }
3696
4024
  function figureToSvgDeco(fig) {
3697
4025
  const sw2 = svgWriter2();
3698
- sw2.addAContour(fig.mainList, "main", colors.main);
4026
+ sw2.addAContour(fig.mainListC(), "main", colors.mainInner);
3699
4027
  sw2.addAContour(fig.mainBList, "mainB", colors.mainB);
3700
4028
  sw2.addAContour(fig.secondList, "second", colors.second);
3701
4029
  sw2.addAContour(fig.secondBList, "secondB", colors.secondB);
@@ -3741,6 +4069,11 @@ function makeOpenjscad(geome0) {
3741
4069
  const rStr = ojscadWrite().getExportFile(paxJson);
3742
4070
  return rStr;
3743
4071
  }
4072
+ function makeFreecad(geome0) {
4073
+ const paxJson = paxWrite().getPaxJson({}, geome0, zeroPDef);
4074
+ const rStr = freecadWrite().getExportFile(paxJson);
4075
+ return rStr;
4076
+ }
3744
4077
  async function makeZip(paramVal, geome0, tSim, geome1, ipDef) {
3745
4078
  const zipFileWriter = new zip.BlobWriter("application/zip");
3746
4079
  const zipWriter = new zip.ZipWriter(zipFileWriter);
@@ -3752,9 +4085,9 @@ async function makeZip(paramVal, geome0, tSim, geome1, ipDef) {
3752
4085
  const zLog1 = new zip.TextReader(geome1.logstr);
3753
4086
  await zipWriter.add(`geom_${partName}_t${tSim}_log.txt`, zLog1);
3754
4087
  for (const face in geome0.fig) {
3755
- const svgOne = new zip.TextReader(figureToSvg(geome0.fig[face].mainList));
4088
+ const svgOne = new zip.TextReader(figureToSvg(geome0.fig[face].mainListC()));
3756
4089
  await zipWriter.add(`face_${partName}_${face}.svg`, svgOne);
3757
- const dxfOne = new zip.TextReader(figureToDxf(geome0.fig[face].mainList));
4090
+ const dxfOne = new zip.TextReader(figureToDxf(geome0.fig[face].mainListC()));
3758
4091
  await zipWriter.add(`face_${partName}_${face}.dxf`, dxfOne);
3759
4092
  const svgOneDeco = new zip.TextReader(figureToSvgDeco(geome0.fig[face]));
3760
4093
  await zipWriter.add(`deco_${partName}_${face}.svg`, svgOneDeco);
@@ -3762,9 +4095,9 @@ async function makeZip(paramVal, geome0, tSim, geome1, ipDef) {
3762
4095
  await zipWriter.add(`deco_${partName}_${face}_t${tSim}.svg`, svgOneDecoT);
3763
4096
  }
3764
4097
  const mergedFace = mergeFaces(geome0.fig);
3765
- const svgMerged = new zip.TextReader(figureToSvg(mergedFace.mainList));
4098
+ const svgMerged = new zip.TextReader(figureToSvg(mergedFace.mainListC()));
3766
4099
  await zipWriter.add(`face_${partName}_all_merged.svg`, svgMerged);
3767
- const dxfMerged = new zip.TextReader(figureToDxf(mergedFace.mainList));
4100
+ const dxfMerged = new zip.TextReader(figureToDxf(mergedFace.mainListC()));
3768
4101
  await zipWriter.add(`face_${partName}_all_merged.dxf`, dxfMerged);
3769
4102
  const svgMergedDeco = new zip.TextReader(figureToSvgDeco(mergedFace));
3770
4103
  await zipWriter.add(`deco_${partName}_all_merged.svg`, svgMergedDeco);
@@ -3776,6 +4109,8 @@ async function makeZip(paramVal, geome0, tSim, geome1, ipDef) {
3776
4109
  await zipWriter.add(`${partName}_noarc_openscad.scad`, zSCad);
3777
4110
  const zJScad = new zip.TextReader(makeOpenjscad(geome0));
3778
4111
  await zipWriter.add(`${partName}_noarc_jscad.js`, zJScad);
4112
+ const zFreecad = new zip.TextReader(makeFreecad(geome0));
4113
+ await zipWriter.add(`${partName}_freecad.py`, zFreecad);
3779
4114
  await zipWriter.close();
3780
4115
  const rFileContent = await zipFileWriter.getData();
3781
4116
  return rFileContent;
@@ -3791,7 +4126,8 @@ var EFormat = /* @__PURE__ */ ((EFormat2) => {
3791
4126
  EFormat2[EFormat2["ePAX"] = 5] = "ePAX";
3792
4127
  EFormat2[EFormat2["eOPENSCAD"] = 6] = "eOPENSCAD";
3793
4128
  EFormat2[EFormat2["eJSCAD"] = 7] = "eJSCAD";
3794
- EFormat2[EFormat2["eZIP"] = 8] = "eZIP";
4129
+ EFormat2[EFormat2["eFREECAD"] = 8] = "eFREECAD";
4130
+ EFormat2[EFormat2["eZIP"] = 9] = "eZIP";
3795
4131
  return EFormat2;
3796
4132
  })(EFormat || {});
3797
4133
  function fileTextContent(fgeom, paramVal, ipDef, eFace, exportFormat) {
@@ -3802,23 +4138,23 @@ function fileTextContent(fgeom, paramVal, ipDef, eFace, exportFormat) {
3802
4138
  if (exportFormat === 0 /* eSVG */) {
3803
4139
  if (figList.includes(eFace)) {
3804
4140
  const figu = geome0.fig[eFace];
3805
- rFileContent = figureToSvg(figu.mainList);
4141
+ rFileContent = figureToSvg(figu.mainListC());
3806
4142
  } else {
3807
4143
  console.log(`err749: fileTextContent eFace ${eFace} invalid`);
3808
4144
  }
3809
4145
  } else if (exportFormat === 1 /* eSVGALL */) {
3810
4146
  const figu = mergeFaces(geome0.fig);
3811
- rFileContent = figureToSvg(figu.mainList);
4147
+ rFileContent = figureToSvg(figu.mainListC());
3812
4148
  } else if (exportFormat === 2 /* eDXF */) {
3813
4149
  if (figList.includes(eFace)) {
3814
4150
  const figu = geome0.fig[eFace];
3815
- rFileContent = figureToDxf(figu.mainList);
4151
+ rFileContent = figureToDxf(figu.mainListC());
3816
4152
  } else {
3817
4153
  console.log(`err759: fileTextContent eFace ${eFace} invalid`);
3818
4154
  }
3819
4155
  } else if (exportFormat === 3 /* eDXFALL */) {
3820
4156
  const figu = mergeFaces(geome0.fig);
3821
- rFileContent = figureToDxf(figu.mainList);
4157
+ rFileContent = figureToDxf(figu.mainListC());
3822
4158
  } else if (exportFormat === 4 /* eTXTLOG */) {
3823
4159
  rFileContent = makeLog(geome0);
3824
4160
  } else if (exportFormat === 5 /* ePAX */) {
@@ -3827,6 +4163,8 @@ function fileTextContent(fgeom, paramVal, ipDef, eFace, exportFormat) {
3827
4163
  rFileContent = makeOpenscad(geome0);
3828
4164
  } else if (exportFormat === 7 /* eJSCAD */) {
3829
4165
  rFileContent = makeOpenjscad(geome0);
4166
+ } else if (exportFormat === 8 /* eFREECAD */) {
4167
+ rFileContent = makeFreecad(geome0);
3830
4168
  } else {
3831
4169
  console.log(`err912: unknown exportFormat ${exportFormat}`);
3832
4170
  }
@@ -3840,7 +4178,7 @@ async function fileBinContent(fgeom, tSim, paramVal, ipDef, exportFormat) {
3840
4178
  const geome1 = fgeom(tSim, paramVal);
3841
4179
  let rFileContent = new Blob();
3842
4180
  if (!geome0.calcErr && !geome1.calcErr) {
3843
- if (exportFormat === 8 /* eZIP */) {
4181
+ if (exportFormat === 9 /* eZIP */) {
3844
4182
  rFileContent = await makeZip(paramVal, geome0, tSim, geome1, ipDef);
3845
4183
  } else {
3846
4184
  console.log(`err913: unknown exportFormat ${exportFormat}`);
@@ -3864,7 +4202,9 @@ function fileMime(exportFormat) {
3864
4202
  rMime = "text/plain";
3865
4203
  } else if (exportFormat === 7 /* eJSCAD */) {
3866
4204
  rMime = "text/plain";
3867
- } else if (exportFormat === 8 /* eZIP */) {
4205
+ } else if (exportFormat === 8 /* eFREECAD */) {
4206
+ rMime = "text/plain";
4207
+ } else if (exportFormat === 9 /* eZIP */) {
3868
4208
  rMime = "application/zip";
3869
4209
  }
3870
4210
  return rMime;
@@ -3883,14 +4223,16 @@ function fileSuffix(exportFormat) {
3883
4223
  rSuffix = "_noarc_openscad.scad";
3884
4224
  } else if (exportFormat === 7 /* eJSCAD */) {
3885
4225
  rSuffix = "_noarc_jscad.js";
3886
- } else if (exportFormat === 8 /* eZIP */) {
4226
+ } else if (exportFormat === 8 /* eFREECAD */) {
4227
+ rSuffix = "_freecad.py";
4228
+ } else if (exportFormat === 9 /* eZIP */) {
3887
4229
  rSuffix = ".zip";
3888
4230
  }
3889
4231
  return rSuffix;
3890
4232
  }
3891
4233
  function fileBin(exportFormat) {
3892
4234
  let rBin = false;
3893
- if (exportFormat === 8 /* eZIP */) {
4235
+ if (exportFormat === 9 /* eZIP */) {
3894
4236
  rBin = true;
3895
4237
  }
3896
4238
  return rBin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geometrix",
3
- "version": "0.5.37",
3
+ "version": "0.5.39",
4
4
  "description": "The 2D geometry engine of the parametrix",
5
5
  "private": false,
6
6
  "repository": {
@@ -63,11 +63,11 @@
63
63
  "clean": "shx rm -fr dist node_modules"
64
64
  },
65
65
  "dependencies": {
66
- "@zip.js/zip.js": "^2.7.44",
66
+ "@zip.js/zip.js": "^2.7.45",
67
67
  "json5": "^2.2.3"
68
68
  },
69
69
  "devDependencies": {
70
- "@types/node": "^20.12.11",
70
+ "@types/node": "^20.13.0",
71
71
  "@typescript-eslint/eslint-plugin": "^7.0.1",
72
72
  "@typescript-eslint/parser": "^7.0.1",
73
73
  "eslint": "^8.57.0",