Example #1
0
SelectionDrawer::SelectionDrawer(DrawerInterface *parentDrawer, RootDrawer *rootdrawer, const IOOptions &options) : SimpleDrawer("SelectionDrawer", parentDrawer,rootdrawer, options)
{
    _vertexShader = "featurevertexshader_nvdia.glsl";
    _fragmentShader = "featurefragmentshader_nvdia.glsl";

    QColor clr;
    _colors.resize(13);
    if ( options.contains("areacolor")){
        clr = options["areacolor"].value<QColor>();
    }else {
        clr = QColor(80,80,0);
        clr.setAlphaF(0.15);
    }
    _colors[9] = _colors[10] = _colors[11] = _colors[12] = clr;
    clr.setAlphaF(0.5);
    _colors[5] = _colors[6] = _colors[7] = _colors[8] = clr;

    if ( options.contains("bordercolor")){
        clr = options["bordercolor"].value<QColor>();
    }else {
        clr = QColor(0,0,0);
        clr.setAlphaF(1);
    }
    _colors[0] = _colors[1] = _colors[2] = _colors[3] = _colors[4] = clr;
    QVector3D pos(0,0,0);
    _vertices = { pos,pos,pos,pos,pos, pos,pos,pos,pos, pos,pos,pos,pos};

    _indices.push_back(VertexIndex(0, 5, itLINE, iUNDEF));
    _indices.push_back(VertexIndex(5, 2, itLINE, iUNDEF));
    _indices.push_back(VertexIndex(7, 2, itLINE, iUNDEF));
    _indices.push_back(VertexIndex(9, 4, itPOLYGON, iUNDEF));
}
void OperationCatalogModel::prepare(const IOOptions& opt){
    if ( opt.contains("globaloperationscatalog")){
        _isGlobalOperationsCatalog = opt["globaloperationscatalog"].toBool();
    }
    _refresh  = true;
    gatherItems();
}
bool Ilwis3Connector::store(IlwisObject *obj, const IOOptions &options)
{
    bool ok = true;
    int storemode = options.contains("storemode") ? options["storemode"].toInt() : IlwisObject::smMETADATA | IlwisObject::smBINARYDATA;

    if ( storemode & IlwisObject::smMETADATA)
        ok &= storeMetaData(obj, options);
    if ( ok && storemode & IlwisObject::smBINARYDATA)
        ok &= storeBinaryData(obj);

    return ok;
}
void OperationCatalogModel::prepare(const IOOptions& opt){

    if ( opt.contains("globaloperationscatalog")){
        _isGlobalOperationsCatalog = opt["globaloperationscatalog"].toBool();
        QString filter = "(type=" + QString::number(itSINGLEOPERATION) + " or type=" + QString::number(itWORKFLOW) + ")";
        _view.filter("basefilter", filter);
    }
    _refresh  = true;
    catalogType(CatalogModel::ctOPERATION|CatalogModel::ctINTERNAL);
    catalogViewManager()->registerCatalogModel(this);
    gatherItems();
}
bool SpreadSheetTableConnector::store(IlwisObject *object, const IOOptions &options ){
    if ( !_spreadsheet){
        ERROR2(ERR_NO_INITIALIZED_2,TR("Spreadsheet"), object->name());
        return false;
    }
    QString file = _resource.toLocalFile();
    if ( QFileInfo(file).suffix() == "")
        if ( options.contains("format"))
            file += "." + options["format"].toString();
    _spreadsheet->openSheet(file, false);
    if (!_spreadsheet->isValid())
        return false;

    Table * tbl = static_cast<Table *>(object);
    bool allDeafultNames = true;
    for(int col = 0; col < tbl->columnCount() && allDeafultNames; ++col){
        allDeafultNames &= tbl->columndefinition(col).name().indexOf("column_") == 0;
    }
    if ( !allDeafultNames){
        for(int col = 0; col < tbl->columnCount(); ++col){
            _spreadsheet->cellValue(col, 0, tbl->columndefinition(col).name(), true );
        }
    }
    int rowStart = allDeafultNames ? 0 : 1;
    std::vector<ColumnDefinition *> coldefs(tbl->columnCount(),0);
    for(int col = 0; col < tbl->columnCount(); ++col) {
        if(hasType(tbl->columndefinition(col).datadef().domain()->ilwisType(), itITEMDOMAIN))
            coldefs[col] = &tbl->columndefinitionRef(col);
    }
    for(int row = 0; row < tbl->recordCount(); ++row){
        const Record& rec = tbl->record(row);
        for(int col = 0; col < tbl->columnCount(); ++col) {
            if ( coldefs[col]){
                QVariant v = coldefs[col]->datadef().domain<>()->impliedValue(rec.cell(col));
                _spreadsheet->cellValue(col, row + rowStart, v, true);
            } else {
                _spreadsheet->cellValue(col, row + rowStart, rec.cell(col), true);
            }
        }
    }

    QString error = _spreadsheet->storeSheet(_resource.toLocalFile());
    if ( !error.isEmpty()){
        kernel()->issues()->log(error);
        return false;
    }



    return true;
}
bool DownloadManager::loadData(IlwisObject *object, const IOOptions &options){
    QUrl url = _resource.url(true);

    QUrlQuery query(url);
    if ( object->ilwisType() == itRASTER){
        RasterCoverage *raster = static_cast<RasterCoverage*>(object);
        _blockSizeBytes = raster->grid()->blockSize(0);
        if ( options.contains("blockindex")){
            _currentBlock = options["blockindex"].toInt();
            int layer = _currentBlock / raster->grid()->blocksPerBand();
            int relativeBlock = _currentBlock - layer * raster->grid()->blocksPerBand();
            unsigned int minLine = raster->grid()->maxLines() * relativeBlock ;
            unsigned int maxLine = std::min( minLine + raster->grid()->maxLines(), raster->size().ysize());
            query.addQueryItem("lines",QString("%1 %2 %3").arg(layer).arg(minLine).arg(maxLine));
        }
    }
    query.addQueryItem("datatype","data");
    url.setQuery(query);
    QString urltxt = url.toString();
    _object = object;
    QNetworkRequest request(url);

    QNetworkReply *reply = kernel()->network().get(request);

    if ( object->ilwisType() == itRASTER)
        connect(reply, &QNetworkReply::readyRead, this, &DownloadManager::readReadyRaster);
    else
        connect(reply, &QNetworkReply::readyRead, this, &DownloadManager::readReady);
    connect(reply, &QNetworkReply::downloadProgress, this, &DownloadManager::downloadProgress);
    connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &DownloadManager::error);
    connect(reply, &QNetworkReply::finished, this, &DownloadManager::finishedData);

    QEventLoop loop; // waits for request to complete
    connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
    loop.exec();

    delete reply;

    return true;
}
Example #7
0
bool IlwisObject::setConnector(ConnectorInterface *connector, int mode, const IOOptions &options)
{
    if ( (!(mode == cmOUTPUT)) && isReadOnly())
        return false;


    if (mode & cmINPUT){
        quint64 pointer = (quint64) ( _connector.data());
        quint64 npointer = (quint64) ( connector);
        if ( pointer != npointer || npointer == 0){
            _connector.reset(connector);
            if ( !_connector.isNull()){
                bool ok = true;
                connector->addProperty("connectormode",IlwisObject::cmINPUT);
                if ( !(options.contains("create") && options.find("create").value().toBool() == true))
                    ok = _connector->loadMetaData(this, options);
                changed(false);
                return ok;
            }
        }
        else {
            kernel()->issues()->log(QString("Duplicate (out)connector assignement for input/output in %1").arg(name()),IssueObject::itWarning);
        }
    }
    if ( mode == cmOUTPUT ){ // skip cmOUTPUt | cmINPUT;
        quint64 pointer = (quint64) ( _outConnector.data());
        quint64 npointer = (quint64) ( connector);
        if ( pointer != npointer || npointer == 0){
            connector->addProperty("connectormode",IlwisObject::cmOUTPUT);
            _outConnector.reset(connector);
        }
        else {
            kernel()->issues()->log(QString("Duplicate (out)connector assignement for input/output in %1").arg(name()),IssueObject::itWarning);
        }
    }

    return true;
}
bool FeatureLayerDrawer::prepare(DrawerInterface::PreparationType prepType, const IOOptions &options)
{
    if(!LayerDrawer::prepare(prepType, options))
        return false;

    if ( hasType(prepType, ptSHADERS) && !isPrepared(ptSHADERS)){
        _vboColor = _shaders.attributeLocation("vertexColor");
        _scaleCenter = _shaders.uniformLocation("scalecenter");
        _scaleFactor = _shaders.uniformLocation("scalefactor");

        _prepared |= DrawerInterface::ptSHADERS;
    }
    if ( hasType(prepType, DrawerInterface::ptGEOMETRY) && !isPrepared(DrawerInterface::ptGEOMETRY)){



        IFeatureCoverage features = coverage().as<FeatureCoverage>();
        if ( !features.isValid()){
            return ERROR2(ERR_COULDNT_CREATE_OBJECT_FOR_2,"FeatureCoverage", TR("Visualization"));
        }
        // set all to 0
        //_indices = std::vector<VertexIndex>();
        _vertices = QVector<QVector3D>();
        _normals = QVector<QVector3D>();
        _colors = std::vector<VertexColor>();
        // get a description of how to render
        VisualAttribute attr = visualProperty(activeAttribute());


        std::vector<std::shared_ptr<BaseSpatialAttributeSetter>> setters(5); // types are 1 2 4, for performance a vector is used thoug not all elements are used
        // for the moment I use the simple setters, in the future this will be representation dependent
        createAttributeSetter(features, setters, rootDrawer());

        _featureDrawings.resize(features->featureCount());
        int featureIndex = 0;
        for(const SPFeatureI& feature : features){
            QVariant value =  attr.columnIndex() != iUNDEF ? feature(attr.columnIndex()) : featureIndex;
            IlwisTypes geomtype = feature->geometryType();
             _featureDrawings[featureIndex] = setters[geomtype]->setSpatialAttributes(feature,_vertices,_normals);
            const QColor& clr = geomtype == itPOLYGON ? _boundaryColor : _lineColor;
            setters[geomtype]->setColorAttributes(attr,value,clr,_featureDrawings[featureIndex],_colors) ;
            ++featureIndex;
        }
        // implicity the redoing of the geometry is also redoing the representation stuff(a.o. colors)
        _prepared |= ( DrawerInterface::ptGEOMETRY | DrawerInterface::ptRENDER);

    }
    if ( hasType(prepType, DrawerInterface::ptRENDER) && !isPrepared(DrawerInterface::ptRENDER)){
        IFeatureCoverage features = coverage().as<FeatureCoverage>();
        int featureIndex = 0;
        std::vector<std::shared_ptr<BaseSpatialAttributeSetter>> setters(5); // types are 1 2 4, for performance a vector is used thoug not all elements are used
        // for the moment I use the simple setters, in the future this will be representation dependent
        createAttributeSetter(features, setters, rootDrawer());
        VisualAttribute attr = visualProperty(activeAttribute());
        if ( !features.isValid()){
            return ERROR2(ERR_COULDNT_CREATE_OBJECT_FOR_2,"FeatureCoverage", TR("Visualization"));
        }
        _colors.resize(0);
        bool polygononly = false;
        if ( options.contains("polygononly"))
            polygononly = options["polygononly"].toBool();

        for(const SPFeatureI& feature : features){
            if ( polygononly && feature->geometryType() != itPOLYGON){
                ++featureIndex;
                continue;
            }
            QVariant value =  attr.columnIndex() != iUNDEF ? feature(attr.columnIndex()) : featureIndex;
            IlwisTypes geomtype = feature->geometryType();
            const QColor& clr = geomtype == itPOLYGON ? _boundaryColor : _lineColor;
            setters[geomtype]->setColorAttributes(attr,value,clr,_featureDrawings[featureIndex],_colors) ;
            ++featureIndex;
        }
        _prepared |= DrawerInterface::ptRENDER;
    }

    //initialize();
    return true;
}