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); } }
Rectangle3R CompositeSurface::getBounds() const { Rectangle3R bounds; for (unsigned i = 0; i < surfaces.size(); i++) bounds.add(surfaces[i]->getBounds()); return bounds; }
void Viewer::draw(const View &view) { init(); SmartPointer<Surface> surface = view.surface; // Setup view port Rectangle3R bounds = view.path->getBounds(); if (!surface.isNull()) bounds.add(surface->getBounds()); bounds.add(view.workpiece->getBounds()); view.glDraw(bounds); // Workpiece bounds if (!view.isFlagSet(View::SHOW_WORKPIECE_FLAG) && view.isFlagSet(View::SHOW_WORKPIECE_BOUNDS_FLAG)) { glEnable(GL_DEPTH_TEST); glLineWidth(1); glColor4f(1, 1, 1, 0.5); // White BoundsView(view.workpiece->getBounds()).draw(); } // Enable Lighting view.setLighting(true); // Tool path if (view.isFlagSet(View::SHOW_PATH_FLAG)) view.path->draw(); else view.path->update(); // Model if (view.isFlagSet(View::SHOW_WORKPIECE_FLAG | View::SHOW_SURFACE_FLAG)) { const float ambient[] = {12.0 / 255, 45.0 / 255, 83.0 / 255, 1.00}; const float diffuse[] = {16.0 / 255, 59.0 / 255, 108.0 / 255, 1.00}; glDisable(GL_COLOR_MATERIAL); glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse); view.setWire(view.isFlagSet(View::WIRE_FLAG)); if (!surface.isNull() && view.isFlagSet(View::SHOW_SURFACE_FLAG)) surface->draw(); if (view.isFlagSet(View::SHOW_WORKPIECE_FLAG)) view.workpiece->draw(); glEnable(GL_COLOR_MATERIAL); view.setWire(false); if (view.isFlagSet(View::SHOW_NORMALS_FLAG)) { glColor4f(1.0, 1.0, 0, 0.6); surface->drawNormals(); } } // Bounding box tree // TODO revive this //if (view.isFlagSet(View::SHOW_BBTREE_FLAG)) cutWP->drawBB(); // Tool if (view.isFlagSet(View::SHOW_TOOL_FLAG) && !view.path->getPath().isNull()) { Vector3R currentPosition = view.path->getPosition(); glTranslatef(currentPosition.x(), currentPosition.y(), currentPosition.z()); ToolTable &tools = *view.path->getPath()->getTools(); const Move &move = view.path->getMove(); const Tool &tool = *tools.get(move.getTool()); double diameter = tool.getDiameter(); double radius = tool.getRadius(); double length = tool.getLength(); ToolShape shape = tool.getShape(); if (radius <= 0) { // Default tool specs radius = 25.4 / 8; shape = ToolShape::TS_CONICAL; glColor4f(1, 0, 0, 1); // Red } else glColor4f(1, 0.5, 0, 1); // Orange if (length <= 0) length = 50; switch (shape) { case ToolShape::TS_SPHEROID: { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(0, 0, length / 2); glScaled(1, 1, length / diameter); gluSphere((GLUquadric *)toolQuad, radius, 100, 100); glPopMatrix(); break; } case ToolShape::TS_BALLNOSE: glPushMatrix(); glTranslatef(0, 0, radius); gluSphere((GLUquadric *)toolQuad, radius, 100, 100); drawCylinder((GLUquadric *)toolQuad, radius, radius, length - radius); glPopMatrix(); break; case ToolShape::TS_SNUBNOSE: drawCylinder((GLUquadric *)toolQuad, tool.getSnubDiameter() / 2, radius, length); break; case ToolShape::TS_CONICAL: drawCylinder((GLUquadric *)toolQuad, 0, radius, length); break; case ToolShape::TS_CYLINDRICAL: default: drawCylinder((GLUquadric *)toolQuad, radius, radius, length); break; } } // Disable Lighting view.setLighting(false); CHECK_GL_ERROR(""); }