示例#1
0
void plCameraModifier::read(hsStream* S, plResManager* mgr) {
    hsKeyedObject::read(S, mgr);

    clearTrans();
    fBrain = mgr->readKey(S);
    fTrans.setSizeNull(S->readInt());
    for (size_t i=0; i<fTrans.getSize(); i++) {
        fTrans[i] = new CamTrans();
        fTrans[i]->read(S, mgr);
    }
    fFOVw = S->readFloat();
    fFOVh = S->readFloat();

    clearMessageQueue();
    fMessageQueue.setSizeNull(S->readInt());
    fSenderQueue.setSize(fMessageQueue.getSize());
    for (size_t i=0; i<fMessageQueue.getSize(); i++)
        fMessageQueue[i] = plMessage::Convert(mgr->ReadCreatable(S));
    for (size_t i=0; i<fSenderQueue.getSize(); i++)
        fSenderQueue[i] = mgr->readKey(S);

    clearFOVInstructions();
    fFOVInstructions.setSizeNull(S->readInt());
    for (size_t i=0; i<fFOVInstructions.getSize(); i++)
        fFOVInstructions[i] = plCameraMsg::Convert(mgr->ReadCreatable(S));

    fAnimated = S->readBool();
    fStartAnimOnPush = S->readBool();
    fStopAnimOnPop = S->readBool();
    fResetAnimOnPop = S->readBool();
}
Model::Page* Model::DjVuDocument::page(int index) const
{
    QMutexLocker mutexLocker(&m_mutex);

    ddjvu_status_t status;
    ddjvu_pageinfo_t pageinfo;

    while(true)
    {
        status = ddjvu_document_get_pageinfo(m_document, index, &pageinfo);

        if(status < DDJVU_JOB_OK)
        {
            clearMessageQueue(m_context, true);
        }
        else
        {
            break;
        }
    }

    if(status >= DDJVU_JOB_FAILED)
    {
        return 0;
    }

    return new DjVuPage(this, index, pageinfo);
}
QString Model::DjVuPage::text(const QRectF& rect) const
{
    QMutexLocker mutexLocker(&m_parent->m_mutex);

    miniexp_t pageTextExp;

    while(true)
    {
        pageTextExp = ddjvu_document_get_pagetext(m_parent->m_document, m_index, "word");

        if(pageTextExp == miniexp_dummy)
        {
            clearMessageQueue(m_parent->m_context, true);
        }
        else
        {
            break;
        }
    }

    const QString text = loadText(pageTextExp, QTransform::fromScale(m_resolution / 72.0, m_resolution / 72.0).mapRect(rect).toRect(), m_size.height());

    ddjvu_miniexp_release(m_parent->m_document, pageTextExp);

    return text.trimmed();
}
void Model::DjVuDocument::loadProperties(QStandardItemModel* propertiesModel) const
{
    Document::loadProperties(propertiesModel);

    QMutexLocker mutexLocker(&m_mutex);

    propertiesModel->setColumnCount(2);

    miniexp_t annoExp;

    while(true)
    {
        annoExp = ddjvu_document_get_anno(m_document, TRUE);

        if(annoExp == miniexp_dummy)
        {
            clearMessageQueue(m_context, true);
        }
        else
        {
            break;
        }
    }

    const int annoLength = miniexp_length(annoExp);

    for(int annoN = 0; annoN < annoLength; ++annoN)
    {
        miniexp_t listExp = miniexp_nth(annoN, annoExp);
        const int listLength = miniexp_length(listExp);

        if(listLength <= 1 || qstrncmp(miniexp_to_name(miniexp_nth(0, listExp)), "metadata", 8) != 0)
        {
            continue;
        }

        for(int listN = 1; listN < listLength; ++listN)
        {
            miniexp_t keyValueExp = miniexp_nth(listN, listExp);

            if(miniexp_length(keyValueExp) != 2)
            {
                continue;
            }

            const QString key = QString::fromUtf8(miniexp_to_name(miniexp_nth(0, keyValueExp)));
            const QString value = QString::fromUtf8(miniexp_to_str(miniexp_nth(1, keyValueExp)));

            if(!key.isEmpty() && !value.isEmpty())
            {
                propertiesModel->appendRow(QList< QStandardItem* >() << new QStandardItem(key) << new QStandardItem(value));
            }
        }
    }

    ddjvu_miniexp_release(m_document, annoExp);
}
示例#5
0
void plCameraModifier::IPrcParse(const pfPrcTag* tag, plResManager* mgr) {
    if (tag->getName() == "CameraModParams") {
        fFOVw = tag->getParam("FOVw", "45").toFloat();
        fFOVh = tag->getParam("FOVh", "33.75").toFloat();
        fAnimated = tag->getParam("Animated", "false").toBool();
        fStartAnimOnPush = tag->getParam("StartAnimOnPush", "false").toBool();
        fStopAnimOnPop = tag->getParam("StopAnimOnPop", "false").toBool();
        fResetAnimOnPop = tag->getParam("ResetAnimOnPop", "false").toBool();
    } else if (tag->getName() == "Brain") {
        if (tag->hasChildren())
            fBrain = mgr->prcParseKey(tag->getFirstChild());
    } else if (tag->getName() == "Transforms") {
        clearTrans();
        fTrans.setSizeNull(tag->countChildren());
        const pfPrcTag* child = tag->getFirstChild();
        for (size_t i=0; i<fTrans.getSize(); i++) {
            fTrans[i] = new CamTrans();
            fTrans[i]->prcParse(child, mgr);
            child = child->getNextSibling();
        }
    } else if (tag->getName() == "MessageQueue") {
        clearMessageQueue();
        fMessageQueue.setSizeNull(tag->countChildren() / 2);
        fSenderQueue.setSize(fMessageQueue.getSize());
        const pfPrcTag* child = tag->getFirstChild();
        for (size_t i=0; i<fMessageQueue.getSize(); i++) {
            fMessageQueue[i] = plMessage::Convert(mgr->prcParseCreatable(child));
            child = child->getNextSibling();
            fSenderQueue[i] = mgr->prcParseKey(child);
            child = child->getNextSibling();
        }
    } else if (tag->getName() == "FOVInstructions") {
        clearFOVInstructions();
        fFOVInstructions.setSizeNull(tag->countChildren());
        const pfPrcTag* child = tag->getFirstChild();
        for (size_t i=0; i<fFOVInstructions.getSize(); i++) {
            fFOVInstructions[i] = plCameraMsg::Convert(mgr->prcParseCreatable(child));
            child = child->getNextSibling();
        }
    } else {
        hsKeyedObject::IPrcParse(tag, mgr);
    }
}
示例#6
0
QList< QRectF > DjVuPage::search(const QString& text, bool matchCase, bool wholeWords) const
{
    LOCK_PAGE

    miniexp_t pageTextExp = miniexp_nil;

    {
        LOCK_PAGE_GLOBAL

        while(true)
        {
            pageTextExp = ddjvu_document_get_pagetext(m_parent->m_document, m_index, "word");

            if(pageTextExp == miniexp_dummy)
            {
                clearMessageQueue(m_parent->m_context, true);
            }
            else
            {
                break;
            }
        }
    }

    const QTransform transform = QTransform::fromScale(72.0 / m_resolution, 72.0 / m_resolution);
    const QStringList words = text.split(QRegExp(QLatin1String("\\W+")), QString::SkipEmptyParts);

    const QList< QRectF > results = findText(pageTextExp, m_size, transform, words, matchCase, wholeWords);

    {
        LOCK_PAGE_GLOBAL

        ddjvu_miniexp_release(m_parent->m_document, pageTextExp);
    }

    return results;
}
void Model::DjVuDocument::loadOutline(QStandardItemModel* outlineModel) const
{
    Document::loadOutline(outlineModel);

    QMutexLocker mutexLocker(&m_mutex);

    miniexp_t outlineExp;

    while(true)
    {
        outlineExp = ddjvu_document_get_outline(m_document);

        if(outlineExp == miniexp_dummy)
        {
            clearMessageQueue(m_context, true);
        }
        else
        {
            break;
        }
    }

    if(miniexp_length(outlineExp) <= 1)
    {
        return;
    }

    if(qstrncmp(miniexp_to_name(miniexp_nth(0, outlineExp)), "bookmarks", 9) != 0)
    {
        return;
    }

    ::loadOutline(outlineExp, 1, outlineModel->invisibleRootItem(), m_indexByName);

    ddjvu_miniexp_release(m_document, outlineExp);
}
bool Model::DjVuDocument::save(const QString& filePath, bool withChanges) const
{
    Q_UNUSED(withChanges);

    QMutexLocker mutexLocker(&m_mutex);

    FILE* file = fopen(QFile::encodeName(filePath), "w+");

    if(file == 0)
    {
        return false;
    }

    ddjvu_job_t* job = ddjvu_document_save(m_document, file, 0, 0);

    while(!ddjvu_job_done(job))
    {
        clearMessageQueue(m_context, true);
    }

    fclose(file);

    return !ddjvu_job_error(job);
}
示例#9
0
QString DjVuPage::text(const QRectF& rect) const
{
    LOCK_PAGE

    miniexp_t pageTextExp = miniexp_nil;

    {
        LOCK_PAGE_GLOBAL

        while(true)
        {
            pageTextExp = ddjvu_document_get_pagetext(m_parent->m_document, m_index, "word");

            if(pageTextExp == miniexp_dummy)
            {
                clearMessageQueue(m_parent->m_context, true);
            }
            else
            {
                break;
            }
        }
    }

    const QTransform transform = QTransform::fromScale(m_resolution / 72.0, m_resolution / 72.0);

    const QString text = loadText(pageTextExp, m_size, transform.mapRect(rect)).simplified();

    {
        LOCK_PAGE_GLOBAL

        ddjvu_miniexp_release(m_parent->m_document, pageTextExp);
    }

    return text.simplified();
}
示例#10
0
QImage Model::DjVuPage::render(qreal horizontalResolution, qreal verticalResolution, Rotation rotation, const QRect& boundingRect) const
{
    QMutexLocker mutexLocker(&m_parent->m_mutex);

    ddjvu_status_t status;
    ddjvu_page_t* page = ddjvu_page_create_by_pageno(m_parent->m_document, m_index);

    if(page == 0)
    {
        return QImage();
    }

    while(true)
    {
        status = ddjvu_page_decoding_status(page);

        if(status < DDJVU_JOB_OK)
        {
            clearMessageQueue(m_parent->m_context, true);
        }
        else
        {
            break;
        }
    }

    if(status >= DDJVU_JOB_FAILED)
    {
        ddjvu_page_release(page);

        return QImage();
    }

    switch(rotation)
    {
    default:
    case RotateBy0:
        ddjvu_page_set_rotation(page, DDJVU_ROTATE_0);
        break;
    case RotateBy90:
        ddjvu_page_set_rotation(page, DDJVU_ROTATE_270);
        break;
    case RotateBy180:
        ddjvu_page_set_rotation(page, DDJVU_ROTATE_180);
        break;
    case RotateBy270:
        ddjvu_page_set_rotation(page, DDJVU_ROTATE_90);
        break;
    }

    ddjvu_rect_t pagerect;

    pagerect.x = 0;
    pagerect.y = 0;

    switch(rotation)
    {
    default:
    case RotateBy0:
    case RotateBy180:
        pagerect.w = qRound(horizontalResolution / m_resolution * m_size.width());
        pagerect.h = qRound(verticalResolution / m_resolution * m_size.height());
        break;
    case RotateBy90:
    case RotateBy270:
        pagerect.w = qRound(horizontalResolution / m_resolution * m_size.height());
        pagerect.h = qRound(verticalResolution / m_resolution * m_size.width());
        break;
    }

    ddjvu_rect_t renderrect;

    if(boundingRect.isNull())
    {
        renderrect.x = pagerect.x;
        renderrect.y = pagerect.y;
        renderrect.w = pagerect.w;
        renderrect.h = pagerect.h;
    }
    else
    {
        renderrect.x = boundingRect.x();
        renderrect.y = boundingRect.y();
        renderrect.w = boundingRect.width();
        renderrect.h = boundingRect.height();
    }

    QImage image(renderrect.w, renderrect.h, QImage::Format_RGB32);

    if(!ddjvu_page_render(page, DDJVU_RENDER_COLOR, &pagerect, &renderrect, m_parent->m_format, image.bytesPerLine(), reinterpret_cast< char* >(image.bits())))
    {
        image = QImage();
    }

    clearMessageQueue(m_parent->m_context, false);

    ddjvu_page_release(page);

    return image;
}
示例#11
0
QList< QRectF > Model::DjVuPage::search(const QString& text, bool matchCase) const
{
    QMutexLocker mutexLocker(&m_parent->m_mutex);

    miniexp_t pageTextExp;

    while(true)
    {
        pageTextExp = ddjvu_document_get_pagetext(m_parent->m_document, m_index, "word");

        if(pageTextExp == miniexp_dummy)
        {
            clearMessageQueue(m_parent->m_context, true);
        }
        else
        {
            break;
        }
    }

    QList< miniexp_t > words;
    QList< QRectF > results;

    words.append(pageTextExp);

    QRectF rect;
    int index = 0;

    while(!words.isEmpty())
    {
        miniexp_t textExp = words.takeFirst();

        const int textLength = miniexp_length(textExp);

        if(textLength >= 6 && miniexp_symbolp(miniexp_nth(0, textExp)))
        {
            if(qstrncmp(miniexp_to_name(miniexp_nth(0, textExp)), "word", 4) == 0)
            {
                const QString word = QString::fromUtf8(miniexp_to_str(miniexp_nth(5, textExp)));

                if(text.indexOf(word, index, matchCase ? Qt::CaseSensitive : Qt::CaseInsensitive) == index)
                {
                    const int xmin = miniexp_to_int(miniexp_nth(1, textExp));
                    const int ymin = miniexp_to_int(miniexp_nth(2, textExp));
                    const int xmax = miniexp_to_int(miniexp_nth(3, textExp));
                    const int ymax = miniexp_to_int(miniexp_nth(4, textExp));

                    rect = rect.united(QRectF(xmin, m_size.height() - ymax, xmax - xmin, ymax - ymin));

                    index += word.length();

                    while(text.length() > index && text.at(index).isSpace())
                    {
                        ++index;
                    }

                    if(text.length() == index)
                    {
                        results.append(rect);

                        rect = QRectF();
                        index = 0;
                    }
                }
                else
                {
                    rect = QRectF();
                    index = 0;
                }
            }
            else
            {
                for(int textN = 5; textN < textLength; ++textN)
                {
                    words.append(miniexp_nth(textN, textExp));
                }
            }
        }
    }

    ddjvu_miniexp_release(m_parent->m_document, pageTextExp);

    QTransform transform = QTransform::fromScale(72.0 / m_resolution, 72.0 / m_resolution);

    for(int index = 0; index < results.size(); ++index)
    {
        results[index] = transform.mapRect(results[index]);
    }

    return results;
}
示例#12
0
QList< Model::Link* > Model::DjVuPage::links() const
{
    QMutexLocker mutexLocker(&m_parent->m_mutex);

    QList< Link* > links;

    miniexp_t pageAnnoExp;

    while(true)
    {
        pageAnnoExp = ddjvu_document_get_pageanno(m_parent->m_document, m_index);

        if(pageAnnoExp == miniexp_dummy)
        {
            clearMessageQueue(m_parent->m_context, true);
        }
        else
        {
            break;
        }
    }

    const int pageAnnoLength = miniexp_length(pageAnnoExp);

    for(int pageAnnoN = 0; pageAnnoN < pageAnnoLength; ++pageAnnoN)
    {
        miniexp_t linkExp = miniexp_nth(pageAnnoN, pageAnnoExp);

        if(miniexp_length(linkExp) <= 3 || qstrncmp(miniexp_to_name(miniexp_nth(0, linkExp)), "maparea", 7 ) != 0 || !miniexp_symbolp(miniexp_nth(0, miniexp_nth(3, linkExp))))
        {
            continue;
        }

        const QString type = QString::fromUtf8(miniexp_to_name(miniexp_nth(0, miniexp_nth(3, linkExp))));

        if(type == QLatin1String("rect") || type == QLatin1String("oval") || type == QLatin1String("poly"))
        {
            // boundary

            QPainterPath boundary;

            miniexp_t areaExp = miniexp_nth(3, linkExp);
            const int areaLength = miniexp_length( areaExp );

            if(areaLength == 5 && (type == QLatin1String("rect") || type == QLatin1String("oval")))
            {
                QPoint p(miniexp_to_int(miniexp_nth(1, areaExp)), miniexp_to_int(miniexp_nth(2, areaExp)));
                QSize s(miniexp_to_int(miniexp_nth(3, areaExp)), miniexp_to_int(miniexp_nth(4, areaExp)));

                p.setY(m_size.height() - s.height() - p.y());

                const QRectF r(p, s);

                if(type == QLatin1String("rect"))
                {
                    boundary.addRect(r);
                }
                else
                {
                    boundary.addEllipse(r);
                }
            }
            else if(areaLength > 0 && areaLength % 2 == 1 && type == QLatin1String("poly"))
            {
                QPolygon polygon;

                for(int areaExpN = 1; areaExpN < areaLength; areaExpN += 2)
                {
                    QPoint p(miniexp_to_int(miniexp_nth(areaExpN, areaExp)), miniexp_to_int(miniexp_nth(areaExpN + 1, areaExp)));

                    p.setY(m_size.height() - p.y());

                    polygon << p;
                }

                boundary.addPolygon(polygon);
            }

            if(boundary.isEmpty())
            {
                continue;
            }

            boundary = QTransform::fromScale(1.0 / m_size.width(), 1.0 / m_size.height()).map(boundary);

            // target

            QString target;

            miniexp_t targetExp = miniexp_nth(1, linkExp);

            if(miniexp_stringp(targetExp))
            {
                target = QString::fromUtf8(miniexp_to_str(miniexp_nth(1, linkExp)));
            }
            else if(miniexp_length(targetExp) == 3 && qstrncmp(miniexp_to_name(miniexp_nth(0, targetExp)), "url", 3) == 0)
            {
                target = QString::fromUtf8(miniexp_to_str(miniexp_nth(1, targetExp)));
            }

            if(target.isEmpty())
            {
                continue;
            }

            if(target.at(0) == QLatin1Char('#'))
            {
                target.remove(0, 1);

                bool ok = false;
                int targetPage = target.toInt(&ok);

                if(!ok)
                {
                    if(m_parent->m_indexByName.contains(target))
                    {
                        targetPage = m_parent->m_indexByName[target] + 1;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    targetPage = (target.at(0) == QLatin1Char('+') || target.at(0) == QLatin1Char('-')) ? m_index + targetPage : targetPage;
                }

                links.append(new Link(boundary, targetPage));
            }
            else
            {
                links.append(new Link(boundary, target));
            }
        }
    }

    ddjvu_miniexp_release(m_parent->m_document, pageAnnoExp);

    return links;
}
示例#13
0
void ControlDevice::controlDeviceThreadWorker()
{
    if (remote) return;

    clearMessageQueue();

    unsigned int WDRESETTIMER = 0;
    bool USBRESET = false;
    bool RESCANAFTEREXCEPTION = false;

    this->addMsgToDataExchangeLog(Valter::format_string("%s worker started...", this->getControlDeviceId().c_str()));

    string request;
    string response;
    bool isWDReset = false;

    wdTimerNotResetCnt = 0;

    string prevReading = "";
    int filter = 0;

    if (Valter::getInstance()->getGlobalSetting("wdrIntent").compare("true") == 0)
    {
        this->getControlDevicePort()->write("WDINTENTIONALRESETON");
        intentionalWDTimerResetOnAT91SAM7s = true;
        setResetWDTimer(true);
    }

    while (this->getStatus() == ControlDevice::StatusActive)
    {
        try
        {
            if (WDRESETTIMER == wdResetTime - 500)
            {
                isWDReset = false;
                if (resetWDTimer)
                {
                    this->getControlDevicePort()->write("WDRESET");
                    this->addMsgToDataExchangeLog(Valter::format_string("%s ← WDRESET", this->getControlDeviceId().c_str()));
                }
            }
            //process outgoing
            if (requestsAwainting() > 0)
            {
                request = pullRequest();
                if (request.length() == 0)
                {
                    this_thread::sleep_for(std::chrono::milliseconds(1));
                    continue;
                }
                if (request.compare("WDINTENTIONALRESETON") == 0)
                {
                    intentionalWDTimerResetOnAT91SAM7s = true;
                }
                if (request.compare("WDINTENTIONALRESETOFF") == 0)
                {
                    intentionalWDTimerResetOnAT91SAM7s = false;
                }
                if (wdTimerNotResetCnt == 0)
                {
                    this->getControlDevicePort()->write(request.c_str());
                    if (Valter::getInstance()->getLogControlDeviceMessages())
                    {
                        this->addMsgToDataExchangeLog(Valter::format_string("%s ← %s", this->getControlDeviceId().c_str(), request.c_str()));
                    }
                }
            }
            //process incoming
            if (this->getControlDevicePort()->available() > 0)
            {
                response = this->getControlDevicePort()->readline();
                sanitizeConrtolDeviceResponse(response);
                if ((filter > 500) || (response.find_first_of(":") == string::npos))
                {
                    addResponse(response);
                    filter = 0;
                }
                else
                {
                    int value_str_pos = response.find_first_of(":");
                    if (response.substr(0, value_str_pos).compare(prevReading) != 0 || filter > 100)
                    {
                        prevReading = response.substr(0, value_str_pos);
                        addResponse(response);
                        filter = 0;
                    }
                    else
                    {
                        //qDebug("%s filtered", response.c_str());
                    }
                }
                if (Valter::getInstance()->getLogControlDeviceMessages())
                {
                    this->addMsgToDataExchangeLog(Valter::format_string("%s → %s", this->getControlDeviceId().c_str(), response.c_str()));
                }
                if (response.compare("WDRST") == 0)
                {
                    isWDReset = true;
                    WDRESETTIMER = 0;
                    wdTimerNotResetCnt = 0;
                }
            }

            this_thread::sleep_for(std::chrono::milliseconds(1));
            filter++;

            WDRESETTIMER++;

            if (WDRESETTIMER > wdResetTime)
            {
                if (!isWDReset)
                {
                    if (resetWDTimer)
                    {
                        this->getControlDevicePort()->write("WDRESET");
                        this->addMsgToDataExchangeLog(Valter::format_string("%s ← WDRESET", this->getControlDeviceId().c_str()));
                    }
                    wdTimerNotResetCnt++;
                    this->addMsgToDataExchangeLog(Valter::format_string("WD was not Reset on %s Control Device [attempt #%d]", this->getControlDeviceId().c_str(), wdTimerNotResetCnt));
                    if (wdTimerNotResetCnt > 3)
                    {
                        if (intentionalWDTimerResetOnAT91SAM7s)
                        {
                            USBRESET = true;
                            break;
                        }
                        else
                        {
                            this->addMsgToDataExchangeLog(Valter::format_string("(EMULATED Reset %s system device of [%s] Control Device)", this->getSysDevicePath().c_str(), this->getControlDeviceId().c_str()));
                        }
                    }
                }
                WDRESETTIMER = 0;
            }
        }
        catch (const exception &ex)
        {
            this->addMsgToDataExchangeLog(Valter::format_string("Exception [%s] fired in the %s worker", ex.what(), this->getControlDeviceId().c_str()));
            RESCANAFTEREXCEPTION = true;
            break;
        }
    }

    wdTimerNotResetCnt = 0;

    this->addMsgToDataExchangeLog(Valter::format_string("%s worker stopped!", this->getControlDeviceId().c_str()));
    if (USBRESET)
    {
        setStatus(ControlDevice::StatusReady);
        intentionalWDTimerResetOnAT91SAM7s = false;
        rescanningAfterPossibleReset = true;
        this_thread::sleep_for(std::chrono::seconds(5));
        this->setRescanNum(0);
        resetUSBSysDevice();
    }
    if (RESCANAFTEREXCEPTION)
    {
        setStatus(ControlDevice::StatusReady);
        intentionalWDTimerResetOnAT91SAM7s = false;
        rescanningAfterPossibleReset = true;
        this_thread::sleep_for(std::chrono::seconds(5));
        this->setRescanNum(0);
        reScanThisControlDevice();
    }
}