Advertisement
kirepudsje

Untitled

Apr 3rd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 12.03 KB | None | 0 0
  1. diff --git a/src/components/operation.js b/src/components/operation.js
  2. index 4acf911..c4c68f9 100644
  3. --- a/src/components/operation.js
  4. +++ b/src/components/operation.js
  5. @@ -513,6 +513,8 @@ export const OPERATION_FIELDS = {
  6.      cutRate: { name: 'cutRate', label: 'Cut Rate', units: 'mm/min', input: NumberInput, ...checkFeedRateRange('XY'), contextMenu: FieldContextMenu() },
  7.      toolSpeed: { name: 'toolSpeed', label: 'Tool Speed (0=Off)', units: 'rpm', input: NumberInput, ...checkFeedRateRange('S') },
  8.  
  9. +    dogBones: { name: 'dogBones', label: 'Dog Bones', units: '', input: ToggleInput, contextMenu: FieldContextMenu() },
  10. +
  11.      useA: { name: 'useA', label: 'Use A Axis', units: '', input: ToggleInput, contextMenu: FieldContextMenu() },
  12.      aAxisDiameter: { name: 'aAxisDiameter', label: 'A Diameter', units: 'mm', input: NumberInput, ...checkPositive, ...ifUseA },
  13.  
  14. @@ -588,10 +590,10 @@ export const OPERATION_TYPES = {
  15.              ...OPERATION_GROUPS.Filters.fields, ...OPERATION_GROUPS.Macros.fields
  16.          ]
  17.      },
  18. -    'Mill Pocket': { allowTabs: true, tabFields: true, fields: ['name', 'filterFillColor', 'filterStrokeColor', 'direction', 'margin', 'toolSpeed', 'millRapidZ', 'millStartZ', 'millEndZ', 'passDepth', 'toolDiameter', 'stepOver', 'segmentLength', 'plungeRate', 'cutRate', 'ramp', 'hookOperationStart', 'hookOperationEnd'] },
  19. +    'Mill Pocket': { allowTabs: true, tabFields: true, fields: ['name', 'filterFillColor', 'filterStrokeColor', 'direction', 'margin', 'toolSpeed', 'millRapidZ', 'millStartZ', 'millEndZ', 'passDepth', 'toolDiameter', 'stepOver', 'segmentLength', 'plungeRate', 'cutRate', 'ramp', 'dogBones', 'hookOperationStart', 'hookOperationEnd'] },
  20.      'Mill Cut': { allowTabs: true, tabFields: true, fields: ['name', 'filterFillColor', 'filterStrokeColor', 'direction', 'toolSpeed', 'millRapidZ', 'millStartZ', 'millEndZ', 'passDepth', 'toolDiameter', 'segmentLength', 'plungeRate', 'cutRate', 'ramp', 'hookOperationStart', 'hookOperationEnd'] },
  21. -    'Mill Cut Inside': { allowTabs: true, tabFields: true, fields: ['name', 'filterFillColor', 'filterStrokeColor', 'direction', 'margin', 'toolSpeed', 'millRapidZ', 'millStartZ', 'millEndZ', 'passDepth', 'cutWidth', 'toolDiameter', 'stepOver', 'plungeRate', 'cutRate', 'segmentLength', 'ramp', 'hookOperationStart', 'hookOperationEnd'] },
  22. -    'Mill Cut Outside': { allowTabs: true, tabFields: true, fields: ['name', 'filterFillColor', 'filterStrokeColor', 'direction', 'margin', 'toolSpeed', 'millRapidZ', 'millStartZ', 'millEndZ', 'passDepth', 'cutWidth', 'toolDiameter', 'stepOver', 'plungeRate', 'cutRate', 'segmentLength', 'ramp', 'hookOperationStart', 'hookOperationEnd'] },
  23. +    'Mill Cut Inside': { allowTabs: true, tabFields: true, fields: ['name', 'filterFillColor', 'filterStrokeColor', 'direction', 'margin', 'toolSpeed', 'millRapidZ', 'millStartZ', 'millEndZ', 'passDepth', 'cutWidth', 'toolDiameter', 'stepOver', 'plungeRate', 'cutRate', 'segmentLength', 'ramp', 'dogBones', 'hookOperationStart', 'hookOperationEnd'] },
  24. +    'Mill Cut Outside': { allowTabs: true, tabFields: true, fields: ['name', 'filterFillColor', 'filterStrokeColor', 'direction', 'margin', 'toolSpeed', 'millRapidZ', 'millStartZ', 'millEndZ', 'passDepth', 'cutWidth', 'toolDiameter', 'stepOver', 'plungeRate', 'cutRate', 'segmentLength', 'ramp', 'dogBones', 'hookOperationStart', 'hookOperationEnd'] },
  25.      'Mill V Carve': { allowTabs: false, fields: ['name', 'filterFillColor', 'filterStrokeColor', 'direction', 'toolAngle', 'millRapidZ', 'millStartZ', 'toolSpeed', 'passDepth', 'segmentLength', 'plungeRate', 'cutRate', 'hookOperationStart', 'hookOperationEnd'] },
  26.      'Lathe Conv Face/Turn': { skipDocs: true, tabFields: false, fields: ['name', 'latheToolBackSide', 'latheRapidToDiameter', 'latheRapidToZ', 'latheStartZ', 'latheRoughingFeed', 'latheRoughingDepth', 'latheFinishFeed', 'latheFinishDepth', 'latheFinishExtraPasses', 'latheFace', 'latheFaceEndDiameter', 'latheTurnAdd', 'latheTurns', 'hookOperationStart', 'hookOperationEnd'] },
  27.  };
  28. diff --git a/src/lib/cam-gcode-laser-cut.js b/src/lib/cam-gcode-laser-cut.js
  29. index a0526b2..b907062 100644
  30. --- a/src/lib/cam-gcode-laser-cut.js
  31. +++ b/src/lib/cam-gcode-laser-cut.js
  32. @@ -213,11 +213,11 @@ export function getLaserCutGcodeFromOp(settings, opIndex, op, geometry, openGeom
  33.      } else if (op.type === 'Laser Cut Inside') {
  34.          if (op.margin)
  35.              geometry = offset(geometry, -op.margin * mmToClipperScale);
  36. -        camPaths = insideOutside(geometry, op.laserDiameter * mmToClipperScale, true, op.cutWidth * mmToClipperScale, op.stepOver, op.direction === 'Climb', false);
  37. +        camPaths = insideOutside(geometry, op.laserDiameter * mmToClipperScale, true, op.cutWidth * mmToClipperScale, op.stepOver, op.direction === 'Climb', false, false);
  38.      } else if (op.type === 'Laser Cut Outside') {
  39.          if (op.margin)
  40.              geometry = offset(geometry, op.margin * mmToClipperScale);
  41. -        camPaths = insideOutside(geometry, op.laserDiameter * mmToClipperScale, false, op.cutWidth * mmToClipperScale, op.stepOver, op.direction === 'Climb', false);
  42. +        camPaths = insideOutside(geometry, op.laserDiameter * mmToClipperScale, false, op.cutWidth * mmToClipperScale, op.stepOver, op.direction === 'Climb', false, false);
  43.      } else if (op.type === 'Laser Fill Path') {
  44.          if (op.margin)
  45.              geometry = offset(geometry, -op.margin * mmToClipperScale);
  46. diff --git a/src/lib/cam-gcode-mill.js b/src/lib/cam-gcode-mill.js
  47. index d88d1a3..2b22072 100644
  48. --- a/src/lib/cam-gcode-mill.js
  49. +++ b/src/lib/cam-gcode-mill.js
  50. @@ -230,17 +230,17 @@ export function getMillGcodeFromOp(settings, opIndex, op, geometry, openGeometry
  51.      if (op.type === 'Mill Pocket') {
  52.          if (op.margin)
  53.              geometry = offset(geometry, -op.margin * mmToClipperScale);
  54. -        camPaths = pocket(geometry, op.toolDiameter * mmToClipperScale, op.stepOver, op.direction === 'Climb');
  55. +        camPaths = pocket(geometry, op.toolDiameter * mmToClipperScale, op.stepOver, op.direction === 'Climb', op.dogBones);
  56.      } else if (op.type === 'Mill Cut') {
  57.          camPaths = cut(geometry, openGeometry, op.direction === 'Climb');
  58.      } else if (op.type === 'Mill Cut Inside') {
  59.          if (op.margin)
  60.              geometry = offset(geometry, -op.margin * mmToClipperScale);
  61. -        camPaths = insideOutside(geometry, op.toolDiameter * mmToClipperScale, true, op.cutWidth * mmToClipperScale, op.stepOver, op.direction === 'Climb', true);
  62. +        camPaths = insideOutside(geometry, op.toolDiameter * mmToClipperScale, true, op.cutWidth * mmToClipperScale, op.stepOver, op.direction === 'Climb', true, op.dogBones);
  63.      } else if (op.type === 'Mill Cut Outside') {
  64.          if (op.margin)
  65.              geometry = offset(geometry, op.margin * mmToClipperScale);
  66. -        camPaths = insideOutside(geometry, op.toolDiameter * mmToClipperScale, false, op.cutWidth * mmToClipperScale, op.stepOver, op.direction === 'Climb', true);
  67. +        camPaths = insideOutside(geometry, op.toolDiameter * mmToClipperScale, false, op.cutWidth * mmToClipperScale, op.stepOver, op.direction === 'Climb', true, op.dogBones);
  68.      } else if (op.type === 'Mill V Carve') {
  69.          camPaths = vCarve(geometry, op.toolAngle, op.passDepth * mmToClipperScale);
  70.      }
  71. diff --git a/src/lib/cam.js b/src/lib/cam.js
  72. index 4893ef4..faaf216 100644
  73. --- a/src/lib/cam.js
  74. +++ b/src/lib/cam.js
  75. @@ -18,7 +18,7 @@
  76.  import ClipperLib from 'clipper-lib';
  77.  import { mat3, vec2 } from 'gl-matrix';
  78.  
  79. -import { diff, offset, cPathsToClipperPaths, cPathsToCamPaths, clipperBounds, clipperPathsToCPaths, clipperToCppScale } from './mesh';
  80. +import { diff, offset, cPathsToClipperPaths, cPathsToCamPaths, clipperBounds, clipperPathsToCPaths, clipperToCppScale, mmToClipperScale } from './mesh';
  81.  
  82.  require('script-loader!web-cam-cpp');
  83.  
  84. @@ -152,11 +152,86 @@ function mergePaths(bounds, paths) {
  85.      return camPaths;
  86.  }
  87.  
  88. +// Add segments for dog bones to a calculated offset path.
  89. +function addDogBones(paths, geometry, diam, isInside) {
  90. +    function normalize(v) {
  91. +   let mag = Math.hypot(v.X, v.Y);
  92. +   return {X: v.X / mag, Y: v.Y / mag};
  93. +    }
  94. +
  95. +    let newPaths = [];
  96. +    for (let path of paths) {
  97. +        let newPath = [];
  98. +   if (path.length < 3) {
  99. +       newPaths.push(path);
  100. +       continue;
  101. +        }
  102. +   if (isInside)
  103. +       path.reverse();
  104. +   let p0 = path[path.length - 2];
  105. +   let p1 = path[path.length - 1];
  106. +        for (let p2 of path) {
  107. +       let v01 = {X: p1.X - p0.X, Y: p1.Y - p0.Y};
  108. +       let v12 = {X: p2.X - p1.X, Y: p2.Y - p1.Y};
  109. +       if (v01.X * v12.Y < v01.Y * v12.X) { // if inside corner
  110. +       v01 = normalize(v01);
  111. +       v12 = normalize(v12);
  112. +       // check for too accute angle. cosd(180 - 22.5) = -0.924
  113. +       if (v01.X * v12.X + v01.Y * v12.Y < -0.924) {
  114. +           newPath.push(p2);
  115. +           p0 = p1;
  116. +           p1 = p2;
  117. +           continue;
  118. +           }
  119. +
  120. +       // direction of dog bone
  121. +       let vdb = normalize({X: v01.X - v12.X, Y: v01.Y - v12.Y});
  122. +       // max extend of dog bone, purely based on angle of segments
  123. +       let me = .5 * diam * (1 / (vdb.Y * v01.X - vdb.X * v01.Y) - 1);
  124. +
  125. +       // find closest intersect with geometry to cope with fillets
  126. +       let r = {X: vdb.X * me, Y: vdb.Y * me};
  127. +       let s, t, u;
  128. +       for (let geomPath of geometry) {
  129. +           let q0 = geomPath[geomPath.length - 1];
  130. +           for (let q1 of geomPath) {
  131. +           let s = {X: q1.X - q0.X, Y: q1.Y - q0.Y};
  132. +           let rxs = r.X * s.Y - r.Y * s.X;
  133. +           if (-1e-10 > rxs || rxs > 1e-10) { // not in parallel
  134. +               t = ((q0.X-p1.X) * s.Y - (q0.Y-p1.Y) * s.X) / rxs;
  135. +               u = ((q0.X-p1.X) * r.Y - (q0.Y-p1.Y) * r.X) / rxs;
  136. +               if (0 <= t && t <= 1 && 0 <= u && u <= 1) {
  137. +               r.X = r.X * t - vdb.X * .5 * diam;
  138. +               r.Y = r.Y * t - vdb.Y * .5 * diam;
  139. +               }
  140. +           }
  141. +           q0 = q1;
  142. +           }
  143. +       }
  144. +       // prevent tiny dogbones <= 0.1 mm
  145. +       if (Math.hypot(r.X, r.Y) > .1 * mmToClipperScale) {
  146. +           newPath.push({X: p1.X + r.X, Y: p1.Y + r.Y});
  147. +           newPath.push(p1);
  148. +           }
  149. +       }
  150. +       newPath.push(p2);
  151. +       p0 = p1;
  152. +       p1 = p2;
  153. +        }
  154. +   if (isInside)
  155. +       newPath.reverse();
  156. +   newPaths.push(newPath);
  157. +    }
  158. +    return newPaths;
  159. +}
  160. +
  161.  // Compute paths for pocket operation on Clipper geometry. Returns array
  162.  // of CamPath. cutterDia is in Clipper units. stepover is in the range (0, 100).
  163. -export function pocket(geometry, cutterDia, stepover, climb) {
  164. +export function pocket(geometry, cutterDia, stepover, climb, dogBones) {
  165.      stepover = stepover / 100;
  166.      let current = offset(geometry, -cutterDia / 2);
  167. +    if (dogBones)
  168. +   current = addDogBones(current, geometry, cutterDia, true);
  169.      let bounds = current.slice(0);
  170.      let allPaths = [];
  171.      while (current.length !== 0) {
  172. @@ -170,10 +245,11 @@ export function pocket(geometry, cutterDia, stepover, climb) {
  173.      return mergePaths(bounds, allPaths);
  174.  };
  175.  
  176. +
  177.  // Compute paths for inside/outside operation on Clipper geometry. Returns array
  178.  // of CamPath. cutterDia and width are in Clipper units. stepover is in the
  179.  // range (0, 100].
  180. -export function insideOutside(geometry, cutterDia, isInside, width, stepover, climb, allowRecutInBounds) {
  181. +export function insideOutside(geometry, cutterDia, isInside, width, stepover, climb, allowRecutInBounds, dogBones) {
  182.  
  183.      stepover = stepover / 100;
  184.      width = Math.max(width, cutterDia);
  185. @@ -200,6 +276,8 @@ export function insideOutside(geometry, cutterDia, isInside, width, stepover, cl
  186.          eachOffset = eachWidth;
  187.          needReverse = climb;
  188.      }
  189. +    if (dogBones)
  190. +   current = addDogBones(current, geometry, cutterDia, isInside);
  191.  
  192.      while (currentWidth <= width) {
  193.          if (needReverse)
  194. diff --git a/src/reducers/operation.js b/src/reducers/operation.js
  195. index b90bc47..861079d 100644
  196. --- a/src/reducers/operation.js
  197. +++ b/src/reducers/operation.js
  198. @@ -42,6 +42,7 @@ export const OPERATION_INITIALSTATE = {
  199.      ramp: false,
  200.      useA: false,
  201.      aAxisDiameter: 0,
  202. +    dogBones: false,
  203.      useBlower: false,
  204.      smoothing: false,       // lw.raster-to-gcode: Smoothing the input image ?
  205.      brightness: 0,          // lw.raster-to-gcode: Image brightness [-255 to +255]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement