void MainWindow::loadFile(const QString &fileName)
{
    qDebug()<<"loading file: "<<fileName;
    QFile file(fileName);
    if (!file.open(QFile::ReadOnly | QFile::Text)) {
        QMessageBox::warning(this, tr("Application"),
                             tr("Cannot read file %1:\n%2.")
                             .arg(fileName)
                             .arg(file.errorString()));
        return;
    }
    curFile = QFileInfo(fileName).absoluteFilePath();
    curDir = QFileInfo(fileName).absoluteDir();
    statusBar()->showMessage(tr("File loaded"), 2000);

    QString code = file.readAll();
    extractOptions(code);
    interpretGcode(code);
    refreshLayerNames(code);
    ui->fileTextEdit->setText(code);
    qDebug()<<removeComments(code);

    scene->clear();
    QString picPath = QFileInfo(fileName).absoluteFilePath();
    picPath.chop(5);        //cut .gcode
    picPath.append("svg");
    QGraphicsSvgItem *item = new QGraphicsSvgItem(picPath);
    scene->addItem(item);
    ui->graphicsView->setEnabled(true);
    ui->graphicsView->fitInView(item);

    if(!ui->fileTextEdit->toPlainText().isEmpty())
    {
        setWindowTitle("Spherebot Control      File: " + fileName);
        ui->fileName->setText(QFileInfo(fileName).fileName());
    }
    else ui->sendButton->setEnabled(false);
}
示例#2
0
void PipelineReaderJSON::parsePipeline(Json::Value& tree)
{
    TagMap tags;
    std::vector<Stage*> inputs;

    Json::ArrayIndex last = tree.size() - 1;
    for (Json::ArrayIndex i = 0; i < tree.size(); ++i)
    {
        Json::Value& node = tree[i];

        std::string filename;
        std::string tag;
        std::string type;
        std::vector<Stage*> specifiedInputs;
        Options options;

        // strings are assumed to be filenames
        if (node.isString())
        {
            filename = node.asString();
        }
        else
        {
            type = extractType(node);
            filename = extractFilename(node);
            tag = extractTag(node, tags);
            specifiedInputs = extractInputs(node, tags);
            if (!specifiedInputs.empty())
                inputs = specifiedInputs;
            options = extractOptions(node);
        }

        Stage *s = nullptr;

        // The type is inferred from a filename as a reader if it's not
        // the last stage or if there's only one.
        if ((type.empty() && (i == 0 || i != last)) ||
            Utils::startsWith(type, "readers."))
        {
            StringList files = FileUtils::glob(filename);
            if (files.empty())
                files.push_back(filename);

            for (const std::string& path : files)
            {
                StageCreationOptions ops { path, type, nullptr, options, tag };
                s = &m_manager.makeReader(ops);

                if (specifiedInputs.size())
                    throw pdal_error("JSON pipeline: Inputs not permitted for "
                        " reader: '" + path + "'.");
                inputs.push_back(s);
            }
        }
        else if (type.empty() || Utils::startsWith(type, "writers."))
        {
            StageCreationOptions ops { filename, type, nullptr, options, tag };
            s = &m_manager.makeWriter(ops);
            for (Stage *ts : inputs)
                s->setInput(*ts);
            inputs.clear();
        }
        else
        {
            if (filename.size())
                options.add("filename", filename);
            StageCreationOptions ops { "", type, nullptr, options, tag };
            s = &m_manager.makeFilter(ops);
            for (Stage *ts : inputs)
                s->setInput(*ts);
            inputs.clear();
            inputs.push_back(s);
        }
        // 's' should be valid at this point.  makeXXX will throw if the stage
        // couldn't be constructed.
        if (tag.size())
            tags[tag] = s;
    }
}