Section & unless( bool const skip )
 {
     if ( skip )
     {
         if ( segments.empty() )
             throw std::runtime_error( "Curve::unless() called, but no segment present" );
         segments.pop_back();
     }
     return *this;
 }
Example #2
0
void MainWindow::rerenderBox()
{
    m_pixmap.fill(Qt::white);

    QPainter painter(&m_pixmap);
    painter.setRenderHint(QPainter::Antialiasing);

    painter.setPen(QPen(Qt::black, 3));
    painter.drawRect(m_boxOffset, m_boxOffset, m_boxParameters.boxSize.x, m_boxParameters.boxSize.y);

    const Segments trace = getTrace();
    if (trace.empty())
    {
        return;
    }

    QPen penBuffer(QColor::fromRgb(1, 0, 0), 2, Qt::SolidLine);
    double redColorBuffer = m_boxParameters.initialRedColorValue;

    Hit firstLeftHit;
    Hit firstBottomHit;
    Hit firstRightHit;
    Hit firstTopHit;
    unsigned char seqNum = 0;

    for (Segments::const_iterator f = trace.cbegin(); f != trace.cend(); ++f)
    {
        if (f != trace.cend() - 1)
        {
            penBuffer.setColor(QColor::fromRgb((int)redColorBuffer, 0, 0));
            redColorBuffer = max(min(255.0, redColorBuffer * m_boxParameters.redColorMultiplier), 0.0);

            painter.setPen(penBuffer);
            painter.drawLine(QPointF(m_boxOffset + f->x, m_boxOffset + f->y),
                             QPointF(m_boxOffset + (f+1)->x, m_boxOffset + (f+1)->y));
        }

        if (f != trace.cbegin())
        {
            const QPointF srcPoint = QPointF(f->x, f->y);

            if (!firstLeftHit.found && abs(f->x) < m_eps)
            {
                firstLeftHit = Hit(srcPoint, seqNum++);
            }
            else if (!firstRightHit.found && abs(m_boxParameters.boxSize.x - f->x) < m_eps)
            {
                firstRightHit= Hit(srcPoint, seqNum++);
            }
            else if (!firstTopHit.found && abs(f->y) < m_eps)
            {
                firstTopHit = Hit(srcPoint, seqNum++);
            }
            else if (!firstBottomHit.found && abs(m_boxParameters.boxSize.y - f->y) < m_eps)
            {
                firstBottomHit = Hit(srcPoint, seqNum++);
            }
        }
    }

    painter.setPen(QPen(Qt::black, 4));

    const QPointF boxOffset(m_boxOffset, m_boxOffset);
    const QPointF labelXOffset(m_boxOffset / 2, 0);
    const QPointF labelYOffset(0, m_boxOffset / 2);

    if (firstLeftHit.found)
    {
        painter.drawText(boxOffset + firstLeftHit.point - labelXOffset,
                         QString::number(firstLeftHit.seqNumber));
    }

    if (firstBottomHit.found)
    {
        painter.drawText(boxOffset + firstBottomHit.point + labelYOffset,
                         QString::number(firstBottomHit.seqNumber));
    }

    if (firstRightHit.found)
    {
        painter.drawText(boxOffset + firstRightHit.point + labelXOffset,
                         QString::number(firstRightHit.seqNumber));
    }

    if (firstTopHit.found)
    {
        painter.drawText(boxOffset + firstTopHit.point - labelYOffset,
                         QString::number(firstTopHit.seqNumber));
    }

    repaint();
}