Пример #1
0
js::Value GCodeLibrary::toolSetCB(const js::Arguments &args) {
  SmartPointer<OpenSCAM::Tool> tool = ctx.tools->get(args["number"].toUint32());

  uint32_t units;
  double scale = 1;
  if (args.has("units")) units = args["units"].toUint32();
  else units = unitAdapter.getUnits();
  if (units == MachineUnitAdapter::METRIC)
    tool->setUnits(OpenSCAM::ToolUnits::UNITS_MM);
  else {
    tool->setUnits(OpenSCAM::ToolUnits::UNITS_INCH);
    scale = 25.4;
  }

  if (args.has("shape"))
    tool->setShape((OpenSCAM::ToolShape::enum_t)args["shape"].toUint32());

  tool->setLength(scale * args.getNumber("length"));
  tool->setDiameter(scale * args.getNumber("diameter"));
  tool->setSnubDiameter(scale * args.getNumber("snub"));
  tool->setFrontAngle(args.getNumber("front_angle"));
  tool->setBackAngle(args.getNumber("back_angle"));
  tool->setOrientation(args.getNumber("orientation"));

  return js::Value();
}
Пример #2
0
js::Value GCodeLibrary::speedCB(const js::Arguments &args) {
  // Return spindle info if no arguments were given
  if (!args.getCount()) {
    js::Value array = js::Value::createArray(3);

    spin_mode_t mode;
    double max;
    array.set(0, ctx.machine.getSpeed(&mode, &max));
    array.set(1, mode);
    array.set(2, max);

    return array;
  }

  // Otherwise set spindle
  spin_mode_t mode = REVOLUTIONS_PER_MINUTE;
  double max = 0;

  if (args.has("surface")) {
    mode = CONSTANT_SURFACE_SPEED;
    if (args.has("max")) max = args["max"].toNumber();
  }

  ctx.machine.setSpeed(args["rate"].toNumber(), mode, max);

  return ctx.machine.getSpeed();
}
Пример #3
0
js::Value GCodeLibrary::feedCB(const js::Arguments &args) {
  // Return feed info if no arguments were given
  if (!args.getCount()) {
    js::Value array = js::Value::createArray(2);

    feed_mode_t mode;
    array.set(0, ctx.machine.getFeed(&mode));
    array.set(1, mode);

    return array;
  }

  // Otherwise set feed
  feed_mode_t mode = MM_PER_MINUTE;
  if (args.has("mode")) {
    mode = (feed_mode_t)args["mode"].toUint32();
    switch (mode) {
    case INVERSE_TIME: case MM_PER_MINUTE: case MM_PER_REVOLUTION: break;
    default: THROW("Feed mode must be FEED_INVERSE_TIME, FEED_UNITS_PER_MIN or "
                   "FEED_UNITS_PER_REV");
    }
  }

  ctx.machine.setFeed(args["rate"].toNumber(), mode);

  return ctx.machine.getFeed();
}
Пример #4
0
MatrixModule::axes_t MatrixModule::parseMatrix(const js::Arguments &args) {
  if (!args.has("matrix")) return XYZ;

  axes_t matrix = (axes_t)args["matrix"].toUint32();
  if (AXES_COUNT <= matrix) THROWS("Invalid matrix number " << matrix);

  return matrix;
}
Пример #5
0
void GCodeLibrary::parseAxes(const js::Arguments &args, Axes &axes,
                             bool incremental) {
  for (const char *axis ="xyzabcuvw"; *axis; axis++) {
    string name = string(1, *axis);
    if (args.has(name)) axes.set(*axis, args.getNumber(name) +
                                 (incremental ? axes.get(*axis) : 0));
  }
}
Пример #6
0
js::Value GCodeLibrary::arcCB(const js::Arguments &args) {
  Vector3D
    offset(args.getNumber("x"), args.getNumber("y"), args.getNumber("z"));
  double angle = args.getNumber("angle");
  plane_t plane = args.has("plane") ? (plane_t)args.getUint32("plane") : XY;

  ctx.machine.arc(offset, angle, plane);

  return js::Value();
}
Пример #7
0
js::Value GCodeLibrary::unitsCB(const js::Arguments &args) {
  MachineUnitAdapter::units_t units = unitAdapter.getUnits();

  if (args.has("type"))
    switch (args["type"].toUint32()) {
    case MachineUnitAdapter::IMPERIAL:
      unitAdapter.setUnits(MachineUnitAdapter::IMPERIAL);
      break;
    case MachineUnitAdapter::METRIC:
      unitAdapter.setUnits(MachineUnitAdapter::METRIC);
      break;
    default: THROWS("Units type must be one of IMPERIAL or METRIC");
    }
  else return js::Value(units);

  return js::Value();
}