Exemplo n.º 1
0
void QtWin::loadWorkpiece() {
  if (project->getAutomaticWorkpiece()) on_automaticCuboidRadioButton_clicked();
  else on_manualCuboidRadioButton_clicked();

  LOCK_UI_UPDATES;
  ui->marginDoubleSpinBox->setValue(project->getWorkpieceMargin());

  ToolUnits units = project->getUnits();

  // Bounds
  real scale = units == ToolUnits::UNITS_MM ? 1 : 1 / 25.4;
  Rectangle3R bounds = project->getWorkpieceBounds();
  ui->xDimDoubleSpinBox->setValue(bounds.getDimensions().x() * scale);
  ui->yDimDoubleSpinBox->setValue(bounds.getDimensions().y() * scale);
  ui->zDimDoubleSpinBox->setValue(bounds.getDimensions().z() * scale);
  ui->xOffsetDoubleSpinBox->setValue(bounds.getMin().x() * scale);
  ui->yOffsetDoubleSpinBox->setValue(bounds.getMin().y() * scale);
  ui->zOffsetDoubleSpinBox->setValue(bounds.getMin().z() * scale);

  // Update Workpiece steps
  real step = units == ToolUnits::UNITS_MM ? 1 : 0.125;
  ui->xDimDoubleSpinBox->setSingleStep(step);
  ui->yDimDoubleSpinBox->setSingleStep(step);
  ui->zDimDoubleSpinBox->setSingleStep(step);
  ui->xOffsetDoubleSpinBox->setSingleStep(step);
  ui->yOffsetDoubleSpinBox->setSingleStep(step);
  ui->zOffsetDoubleSpinBox->setSingleStep(step);

  // Update visual
  view->setWorkpiece(bounds);
  redraw();
}
Exemplo n.º 2
0
void Project::updateAutomaticWorkpiece(ToolPath &path) {
  if (!getAutomaticWorkpiece()) return;
  setAutomaticWorkpiece(true);
  Rectangle3R wpBounds;

  // Guess workpiece bounds from cutting moves
  vector<SmartPointer<Sweep> > sweeps;
  vector<Rectangle3R> bboxes;

  for (unsigned i = 0; i < path.size(); i++) {
    const Move &move = path.at(i);

    if (move.getType() == MoveType::MOVE_RAPID) continue;

    int tool = move.getTool();
    if (tool < 0) continue;

    if (sweeps.size() <= (unsigned)tool) sweeps.resize(tool + 1);
    if (sweeps[tool].isNull()) sweeps[tool] = tools.get(tool).getSweep();

    sweeps[tool]->getBBoxes(move.getStartPt(), move.getEndPt(), bboxes, 0);
  }

  for (unsigned i = 0; i < bboxes.size(); i++) wpBounds.add(bboxes[i]);

  if (wpBounds == Rectangle3R()) return;

  // Start from z = 0
  Vector3R bMin = wpBounds.getMin();
  Vector3R bMax = wpBounds.getMax();
  wpBounds = Rectangle3R(bMin, Vector3R(bMax.x(), bMax.y(), 0));

  // At least 2mm thick
  if (wpBounds.getHeight() < 2)
    wpBounds.add(Vector3R(bMin.x(), bMin.y(), bMin.z() - 2));

  if (wpBounds.isReal()) {
    // Margin
    Vector3R margin =
      wpBounds.getDimensions() * getWorkpieceMargin() / 100.0;
    wpBounds.add(wpBounds.getMin() - margin);
    wpBounds.add(wpBounds.getMax() + Vector3R(margin.x(), margin.y(), 0));

    setWorkpieceBounds(wpBounds);
  }
}
Exemplo n.º 3
0
void QtWin::updateToolPathBounds() {
  Rectangle3R bounds = *toolPath;
  Vector3R bMin = bounds.getMin();
  Vector3R bMax = bounds.getMax();
  Vector3R bDim = bounds.getDimensions();

  setUnitLabel(ui->toolPathBoundsXMinLabel, bMin.x());
  setUnitLabel(ui->toolPathBoundsXMaxLabel, bMax.x());
  setUnitLabel(ui->toolPathBoundsXDimLabel, bDim.x());

  setUnitLabel(ui->toolPathBoundsYMinLabel, bMin.y());
  setUnitLabel(ui->toolPathBoundsYMaxLabel, bMax.y());
  setUnitLabel(ui->toolPathBoundsYDimLabel, bDim.y());

  setUnitLabel(ui->toolPathBoundsZMinLabel, bMin.z());
  setUnitLabel(ui->toolPathBoundsZMaxLabel, bMax.z());
  setUnitLabel(ui->toolPathBoundsZDimLabel, bDim.z());
}
Exemplo n.º 4
0
void QtWin::updateWorkpieceBounds() {
  if (project.isNull()) return;

  Rectangle3R bounds = project->getWorkpieceBounds();
  Vector3R bMin = bounds.getMin();
  Vector3R bMax = bounds.getMax();
  Vector3R bDim = bounds.getDimensions();

  setUnitLabel(ui->workpieceBoundsXMinLabel, bMin.x());
  setUnitLabel(ui->workpieceBoundsXMaxLabel, bMax.x());
  setUnitLabel(ui->workpieceBoundsXDimLabel, bDim.x());

  setUnitLabel(ui->workpieceBoundsYMinLabel, bMin.y());
  setUnitLabel(ui->workpieceBoundsYMaxLabel, bMax.y());
  setUnitLabel(ui->workpieceBoundsYDimLabel, bDim.y());

  setUnitLabel(ui->workpieceBoundsZMinLabel, bMin.z());
  setUnitLabel(ui->workpieceBoundsZMaxLabel, bMax.z());
  setUnitLabel(ui->workpieceBoundsZDimLabel, bDim.z());
}
Exemplo n.º 5
0
void ViewPort::glDraw(const Rectangle3R &bbox) const {
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  // Background
  glBegin(GL_QUADS);
  glColor3ub(0x25, 0x30, 0x40);
  glVertex2f(-1, -1);
  glVertex2f(1, -1);
  glColor3ub(0x5, 0x5, 0x5);
  glVertex2f(1, 1);
  glVertex2f(-1, 1);
  glEnd();

  // Compute "radius"
  Vector3R dims = bbox.getDimensions();
  real radius = dims.x() < dims.y() ? dims.y() : dims.x();
  radius = dims.z() < radius ? radius : dims.z();

  // Perspective
  gluPerspective(45, (float)width / height, 1, 100000);

  // Translate
  glTranslatef(translation.x() * radius / zoom,
               translation.y() * radius / zoom, 0);

  // Scale
  gluLookAt(0, 0, radius / zoom, 0, 0, 0, 0, 1, 0);

  glMatrixMode(GL_MODELVIEW);

  // Rotate
  glRotated(rotation[0], rotation[1], rotation[2], rotation[3]);

  // Center
  Vector3R center = bbox.getCenter();
  glTranslatef(-center.x(), -center.y(), -center.z());

  // Axes
  if (axes) {
    double length = (bbox.getWidth() + bbox.getLength() + bbox.getHeight()) / 3;
    length *= 0.1;
    double radius = length / 20;

    setLighting(true);

    for (int axis = 0; axis < 3; axis++)
      for (int up = 0; up < 2; up++)
        drawAxis(axis, up, length, radius);

    setLighting(false);
  }
  
  // Bounds
  if (bounds) {
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(1, 0x5555);
    glLineWidth(1);
    glColor4f(1, 1, 1, 0.5); // White

    BoundsView(bbox).draw();

    glDisable(GL_LINE_STIPPLE);
  }
}
Exemplo n.º 6
0
Workpiece::Workpiece(const Rectangle3R &r) :
  Rectangle3R(r), center(r.getCenter()) {
  Vector3R halfDim = r.getDimensions() / 2;
  halfDim2 = halfDim * halfDim;
}