Exemplo n.º 1
0
/**
 * Determines if we have a valid buffer for optimising.
 *
 * Has to be G1s all round with no Z movements, and either all extrusions or all movements.
 *
 * The extrusions also have to be the same mm^3/mm along the path.
 *
 * They also have to describe a circle
 * @param  SplQueue $buffer The buffer
 * @return Boolean          Whether the buffer is valid
 */
function bufferValid($buffer)
{
    global $debug;
    global $pos_error;
    for ($buffer->rewind(); $buffer->valid(); $buffer->next()) {
        if (substr($buffer->current(), 0, 2) !== "G1") {
            $buffer->rewind();
            return false;
        } else {
            if (strpos($buffer->current(), "Z") !== FALSE) {
                $buffer->rewind();
                return false;
            }
        }
    }
    $lines = getLines($buffer);
    $allE = false;
    $allF = false;
    if (!is_null($lines[0]['E'])) {
        $allE = true;
    }
    if (!is_null($lines[0]['F'])) {
        $allF = true;
    }
    foreach ($lines as $num => $line) {
        $allE = $allE && is_null($line['F']) && !is_null($line['E']);
        $allF = $allF && is_null($line['E']) && !is_null($line['F']);
    }
    if (!($allE || $allF)) {
        $buffer->rewind();
        return false;
    }
    if ($allE) {
        $extrusions = getExtrusionLengths($lines);
        $eerror = calculateExtrusionError($extrusions);
        if (calculateExtrusionError($extrusions) === false) {
            $buffer->rewind();
            return false;
        }
    }
    $lines->rewind();
    $circle = getCircle($lines);
    if ($circle === false) {
        $buffer->rewind();
        return false;
    }
    if (max($circle['errors']) > $pos_error) {
        return false;
    }
    $buffer->rewind();
    return $circle;
}
Exemplo n.º 2
0
$group->setSpace(5, 5, 5, 5);
$group->legend->setPosition(0.82, 0.1);
$group->legend->setAlign(LEGEND_CENTER, LEGEND_MIDDLE);
function getCircle($size)
{
    $center = 0;
    $x = array();
    $y = array();
    for ($i = 0; $i <= 20; $i++) {
        $rad = $i / 20 * 2 * M_PI;
        $x[] = $center + cos($rad) * $size;
        $y[] = $center + sin($rad) * $size;
    }
    return array($x, $y);
}
list($x, $y) = getCircle(3);
$plot = new ScatterPlot($y, $x);
$plot->link(TRUE, new DarkBlue());
$plot->mark->setFill(new DarkPink());
$plot->mark->setType(MARK_CIRCLE, 6);
$group->legend->add($plot, 'Circle #1', LEGEND_MARK);
$group->add($plot);
list($x, $y) = getCircle(5);
$plot = new ScatterPlot($y, $x);
$plot->link(TRUE, new DarkGreen());
$plot->mark->setFill(new DarkOrange());
$plot->mark->setType(MARK_SQUARE, 4);
$group->legend->add($plot, 'Circle #2', LEGEND_MARK);
$group->add($plot);
$graph->add($group);
$graph->draw();
Exemplo n.º 3
0
/**
 * @deprecated
 * @param  [type] $buffer [description]
 * @param  string $id     [description]
 * @return [type]         [description]
 */
function processBuffer($buffer, $id = 'gcodeview')
{
    global $pos_error;
    global $debug;
    $lines = getLines($buffer);
    $circle = getCircle($lines);
    if ($circle == false) {
        return false;
    }
    if (max($circle['errors']) < $pos_error) {
        return $circle;
    } else {
        return false;
    }
    //print_r($lines);
}