Skip to content

Commit

Permalink
improvements to call python
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchouwenburg committed Jun 5, 2017
1 parent 8f42895 commit 572b45d
Show file tree
Hide file tree
Showing 15 changed files with 466 additions and 23 deletions.
65 changes: 65 additions & 0 deletions baseoperations/creators/createrastercoverage.cpp
Expand Up @@ -11,6 +11,9 @@
#include "itemiterator.h"
#include "pixeliterator.h"
#include "catalog.h"
#include "ilwisoperation.h"
#include "operationhelper.h"
#include "operationhelpergrid.h"
#include "createrastercoverage.h"
#include "ilwiscontext.h"

Expand Down Expand Up @@ -341,6 +344,68 @@ quint64 CreateRasterCoverage::createMetadata()
mastercatalog()->addItems({resource});
return resource.id();
}
//-----------------------------------------------------------------------------------------------------
REGISTER_OPERATION(CreateSimpelRasterCoverage)

quint64 CreateSimpelRasterCoverage::createMetadata()
{
OperationResource resource({"ilwis://operations/createrastercoverage"});
resource.setLongName("Create Simpel Raster coverage");
resource.setSyntax("createrastercoverage(georeference)");
resource.setDescription(TR("Creates a empty raster based on the provided georeference. If a georeference is used to create it it will always have a numeric domain; else it will copy it from the raster"));
resource.setInParameterCount({1});
resource.addInParameter(0, itGEOREF|itRASTER,TR("Georeference"), TR("Geometry of the new rastercoverage"));
resource.setOutParameterCount({1});
resource.addOutParameter(0, itRASTER, TR("raster coverage"), TR("The newly created raster"));
resource.setKeywords("raster,create,workflow");

mastercatalog()->addItems({resource});
return resource.id();
}

OperationImplementation *CreateSimpelRasterCoverage::create(quint64 metaid, const Ilwis::OperationExpression &expr)
{
return new CreateSimpelRasterCoverage( metaid, expr);
}

CreateSimpelRasterCoverage::CreateSimpelRasterCoverage(quint64 metaid,const Ilwis::OperationExpression &expr) : CreateRasterCoverage(metaid, expr)
{}

Ilwis::OperationImplementation::State CreateSimpelRasterCoverage::prepare(ExecutionContext *ctx,const SymbolTable&){
IRasterCoverage inputRaster;
if ( _expression.parm(0).valuetype() == itRASTER){
if(!inputRaster.prepare(_expression.input<QString>(0))){
kernel()->issues()->log(TR("Invalid raster used to create new raster:") + _expression.input<QString>(0));
return sPREPAREFAILED;
}
_outputRaster = OperationHelperRaster::initialize(inputRaster,itRASTER,itRASTERSIZE|itDOMAIN|itCOORDSYSTEM|itGEOREF);
return sPREPARED;
}
QString grf = _expression.input<QString>(0);
if ( ! _grf.prepare(grf)){
kernel()->issues()->log(QString(TR("%1 is and invalid georeference")).arg(grf));
return sPREPAREFAILED;
}
_domain.prepare("code=domain:value");
_stackDomain = IDomain("count");
_stackValueStrings = {"1"};
_stackValueNumbers = {1};
_outputRaster.prepare();
_outputRaster->georeference(_grf);
_outputRaster->setDataDefintions(_domain, _stackValueNumbers , _stackDomain);

return sPREPARED;
}


bool CreateSimpelRasterCoverage::execute(ExecutionContext *ctx, SymbolTable &symTable)
{
if (_prepState == sNOTPREPARED)
if((_prepState = prepare(ctx, symTable)) != sPREPARED)
return false;

setOutput(_outputRaster,ctx,symTable);
logOperation(_outputRaster, _expression);

return true;
}
18 changes: 17 additions & 1 deletion baseoperations/creators/createrastercoverage.h
Expand Up @@ -19,7 +19,7 @@ class CreateRasterCoverage : public OperationImplementation

NEW_OPERATION(CreateRasterCoverage);

private:
protected:
IDomain _domain;
IDomain _stackDomain;
IGeoReference _grf;
Expand All @@ -35,6 +35,22 @@ class CreateRasterCoverage : public OperationImplementation
bool parseStackDefintionTimeCase(const QString &stackDef);
QString expandWildCards(const QString &wildmaps);
};

class CreateSimpelRasterCoverage : public CreateRasterCoverage
{
public:
CreateSimpelRasterCoverage();

CreateSimpelRasterCoverage(quint64 metaid, const Ilwis::OperationExpression &expr);

static Ilwis::OperationImplementation *create(quint64 metaid,const Ilwis::OperationExpression& expr);
Ilwis::OperationImplementation::State prepare(ExecutionContext *ctx,const SymbolTable&);

static quint64 createMetadata();

NEW_OPERATION(CreateSimpelRasterCoverage);
bool execute(ExecutionContext *ctx, SymbolTable &symTable);
};
}
}
#endif // CREATERASTERCOVERAGE_H
6 changes: 6 additions & 0 deletions core/catalog/catalog.cpp
Expand Up @@ -81,6 +81,12 @@ QString Catalog::resolve(const QString &nm, IlwisTypes tp) const
{
if ( nm == sUNDEF)
return sUNDEF;
quint64 id = IlwisObject::internalname2id(nm);
if ( id != i64UNDEF){
Resource res = mastercatalog()->id2Resource(id);
if ( res.isValid())
return res.url().toString();
}

QString name = nm;
name = Resource::quoted2string(name);
Expand Down
2 changes: 1 addition & 1 deletion core/catalog/resource.cpp
Expand Up @@ -408,7 +408,7 @@ void Resource::setUrl(const QUrl &url, bool asRaw, bool updateDatabase)
if ( !isRoot(inf.absolutePath())){
name(inf.fileName(), false, updateDatabase);
if ( !inf.isRoot())
addContainer(QUrl::fromLocalFile(inf.absolutePath()),asRaw);
addContainer(QUrl::fromLocalFile(OSHelper::neutralizeFileName(inf.absolutePath())),asRaw);
else
addContainer(QUrl("file:///"),asRaw);
}
Expand Down
83 changes: 81 additions & 2 deletions desktopclient/qml/workbench/creators/CreateScript.qml
Expand Up @@ -21,7 +21,9 @@ Controls.DropableItem{
property bool isNew : true

Item {
anchors.fill: parent
x : 4
width : parent.width - 5
height : parent.height
Column {
id : workflowItems
anchors.fill: parent
Expand Down Expand Up @@ -120,6 +122,68 @@ Controls.DropableItem{
}
}
}

Column {
ListModel {
id : inputparameterList
}
ListModel {
id : outputparameterList
}
width : parent.width
height : 250
spacing : 3
CheckBox{
id : operationCheck
text : qsTr("As Operation")
checked: false
}
Controls.TextEditLabelPair{
id : operationNameField
width : parent.width
labelText: qsTr("Operation Name")
labelWidth: 100
visible: operationCheck.checked
enabled: visible
}
Controls.TextEditLabelPair{
id : longNameField
width : parent.width
labelText: qsTr("Long name")
labelWidth: 100
visible: operationCheck.checked
enabled: visible
}

ParameterList{
id : parameterlistField
visible: operationCheck.checked
enabled: visible
width : parent.width
height : 80
}
Button{
anchors.right : parent.right
anchors.rightMargin: 5
visible: operationCheck.checked
enabled: visible
width : 100
height : 20
text : qsTr("New Parameter")
onClicked: {
details.visible = true;
}
}
ParameterDetails{
id : details
visible: false
enabled: visible
width : parent.width
height : 100
}


}
Rectangle{
x : 2
width : parent.width -4
Expand Down Expand Up @@ -152,6 +216,16 @@ Controls.DropableItem{
} else {
keywords += ", script"
}
var inputparms = []
for(i=0; i < inputparameterList.count; ++i){
var parm = inputparameterList.get(i)
inputparms.push({"name" : parm.name, "valuetype" : parm.valuetype,"description" : parm.description })
}
var outputparms = []
for(i=0; i < outputparameterList.count; ++i){
parm = outputparameterList.get(i)
outputparms.push({"name" : parm.name, "valuetype" : parm.valuetype,"description" : parm.description })
}

var name = nameedit.content
if ( name.indexOf(".py") == -1)
Expand All @@ -161,7 +235,12 @@ Controls.DropableItem{
name : name,
keywords : keywords,
description : descedit.content,
url : mastercatalog.currentUrl + "/" + name
url : mastercatalog.currentUrl + "/" + name,
asoperation : operationCheck.checked,
inputparameters : inputparms,
outputparameters : outputparms,
operationname : operationNameField.content,
longname : longNameField.content
}
var ilwisid = objectcreator.createObject(createInfo)
var filter = "itemid=" + ilwisid
Expand Down
58 changes: 56 additions & 2 deletions desktopclient/qml/workbench/creators/ParameterDetails.qml
@@ -1,5 +1,59 @@
import QtQuick 2.0
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.1
import "../../Global.js" as Global
import "../../controls" as Controls
import "../.." as Base
import UIContextModel 1.0

Item {
Column {
spacing: 3
Controls.TextEditLabelPair{
id : namefield
width : parent.width
labelWidth: 100
labelText: qsTr("Name")
}
Controls.ComboxLabelPair{
width : parent.width
id : datatypefield
labelText: qsTr("Data type")
labelWidth: 100
itemModel: uicontext.typeNames
}

Controls.TextEditLabelPair{
id : descField
width : parent.width
labelWidth: 100
labelText: qsTr("Description")
}
Row {
width : parent.width
height : 22
spacing : 4
Button{
id : addButton
width : 100
height : 20
text : qsTr("Create")
onClicked: {
if (parameterlistField.inputActive)
inputparameterList.append({"name" : namefield.content,"valuetype" : datatypefield.comboText,"description" : descField.content })
else
outputparameterList.append({"name" : namefield.content,"valuetype" : datatypefield.comboText,"description" : descField.content })

details.visible = false
}
}
Button{
width : 100
height : 20
text : qsTr("Close")
onClicked : {
details.visible = false
}
}
}
}

0 comments on commit 572b45d

Please sign in to comment.