iLand
Public Slots | Public Member Functions | Static Public Member Functions | Static Public Attributes | Properties | List of all members
ScriptGlobal Class Reference

This is a global interface providing useful functionality for javascripts. More...

#include <scriptglobal.h>

Inheritance diagram for ScriptGlobal:

Public Slots

QVariant setting (QString key)
 get a value from the global xml-settings (returns undefined if not present) More...
 
void set (QString key, QString value)
 set the value of a setting More...
 
void print (QString message)
 print the contents of the message to the log More...
 
void alert (QString message)
 shows a message box to the user (if in GUI mode) More...
 
void include (QString filename)
 "include" the given script file and evaluate. The path is relative to the "script" path More...
 
QString defaultDirectory (QString dir)
 get default directory of category 'dir' More...
 
QString path (QString filename)
 get a path relative to the project main folder More...
 
QString loadTextFile (QString fileName)
 load content from a text file in a String ( More...
 
void saveTextFile (QString fileName, QString content)
 save string (content) to a text file. More...
 
bool fileExists (QString fileName)
 return true if the given file exists. More...
 
void systemCmd (QString command)
 execute system command (e.g., copy files) More...
 
int addSingleTrees (const int resourceIndex, QString content)
 add single trees More...
 
int addTrees (const int resourceIndex, QString content)
 add tree distribution More...
 
int addTreesOnMap (const int standID, QString content)
 add trees (distribution mode) for stand 'standID' More...
 
int addSaplingsOnMap (MapGridWrapper *map, const int mapID, QString species, int px_per_hectare, double height, int age)
 
int addSaplings (int standId, double x, double y, double width, double height, QString species, double treeheight, int age)
 add sapling on a metric rectangle given with width and height at x/y. More...
 
void removeSaplings (int standId, double x, double y, double width, double height)
 remove all saplings from a metric rectangle. See also addSaplings(). More...
 
bool startOutput (QString table_name)
 starts output 'table_name'. return true if successful More...
 
bool stopOutput (QString table_name)
 stops output 'table_name'. return true if successful More...
 
void debugOutputFilter (QList< int > ru_indices)
 enable debug outputs for a list of resource units (output for other RUs are suppressed) More...
 
bool saveDebugOutputs (bool do_clear)
 save debug outputs to file; if do_clear=true then debug data is cleared from memorey More...
 
void setViewport (double x, double y, double scale_px_per_m)
 set the viewport of the main project area view More...
 
bool screenshot (QString file_name)
 make a screenshot from the central viewing widget More...
 
void repaint ()
 force a repainting of the GUI visualization (if available) More...
 
bool gridToFile (QString grid_type, QString file_name)
 create a "ESRI-grid" text file 'grid_type' is one of a fixed list of names, 'file_name' the ouptut file location More...
 
QJSValue grid (QString type)
 return Javascript grid for given type More...
 
QJSValue speciesShareGrid (QString species)
 return a grid with the basal area of the given species (resource unit resolution) More...
 
QJSValue resourceUnitGrid (QString expression)
 return a grid (level of resource units) with the result of an expression evaluated in the context of the resource unit. More...
 
QJSValue resourceUnit (int index)
 access to single resource unit (returns a reference) More...
 
bool seedMapToFile (QString species, QString file_name)
 save the "seedmap" (i.e. a grid showing the seed distribution) as ESRI rastser file More...
 
void wait (int milliseconds)
 wait for 'milliseconds' or (if ms=-1 until a key is pressed) More...
 
bool saveModelSnapshot (QString file_name)
 saves a snapshot of the current model state (trees, soil, etc.) to a dedicated SQLite database. More...
 
bool loadModelSnapshot (QString file_name)
 loads a snapshot of the current model state (trees, soil, etc.) from a dedicated SQLite database. More...
 
bool saveStandSnapshot (int stand_id, QString file_name)
 
bool loadStandSnapshot (int stand_id, QString file_name)
 
bool saveStandCarbon (int stand_id, QList< int > ru_ids, bool rid_mode=true)
 
bool loadStandCarbon ()
 
void reloadABE ()
 
void setUIshortcuts (QJSValue shortcuts)
 set a list of JS shortcuts in the UI More...
 
void test_tree_mortality (double thresh, int years, double p_death)
 

Public Member Functions

 ScriptGlobal (QObject *parent=nullptr)
 
bool qt5 () const
 is this the qt5-model? (changes in script object creation) More...
 
int msec () const
 the milliseconds since the start of the day More...
 
int year () const
 current year in the model More...
 
int resourceUnitCount () const
 get number of resource uinit More...
 
QString currentDir () const
 current execution directory (default is the Script execution directory) More...
 
void setCurrentDir (QString newDir)
 set current working dir More...
 
double worldX ()
 extent of the world (without buffer) in meters (x-direction) More...
 
double worldY ()
 extent of the world (without buffer) in meters (y-direction) More...
 
QJSValue viewOptions ()
 retrieve current viewing options (JS - object) More...
 
void setViewOptions (QJSValue opts)
 set current view options More...
 

Static Public Member Functions

static void setupGlobalScripting ()
 
static void loadScript (const QString &fileName)
 
static QString executeScript (QString cmd)
 
static QString executeJSFunction (QString function)
 
static QString formattedErrorMessage (const QJSValue &error_value, const QString &sourcecode)
 
static QJSValue valueFromJs (const QJSValue &js_value, const QString &key, const QString default_value=QLatin1Literal(""), const QString &errorMessage=QLatin1Literal(""))
 
static QString JStoString (QJSValue value)
 

Static Public Attributes

static QObject * scriptOutput = nullptr
 public "pipe" for script output (is redirected to GUI if available) More...
 

Properties

int year
 
int resourceUnitCount
 
QString currentDir
 
double worldX
 
double worldY
 
bool qt5
 
int msec
 
QJSValue viewOptions
 

Detailed Description

This is a global interface providing useful functionality for javascripts.

Within javascript-code an instance of this class can be accessed as "Globals" in the global scope (no instantiation necessary).

Constructor & Destructor Documentation

◆ ScriptGlobal()

ScriptGlobal::ScriptGlobal ( QObject *  parent = nullptr)

Member Function Documentation

◆ addSaplings

int ScriptGlobal::addSaplings ( int  standId,
double  x,
double  y,
double  width,
double  height,
QString  species,
double  treeheight,
int  age 
)
slot

add sapling on a metric rectangle given with width and height at x/y.

if a standId is provided (-1 or 0: no stand), x/y is relative to the lower left edge of the stand rectangle. If no stand is provided, x/y are absolute (relative to the project area). returns the number of successfully added sapling cells

◆ addSaplingsOnMap

int ScriptGlobal::addSaplingsOnMap ( MapGridWrapper map,
const int  mapID,
QString  species,
int  px_per_hectare,
double  height,
int  age 
)
slot

◆ addSingleTrees

int ScriptGlobal::addSingleTrees ( const int  resourceIndex,
QString  content 
)
slot

add single trees

add trees on given resource unit

Parameters
contentinit file in a string (containing headers)
Returns
number of trees added

◆ addTrees

int ScriptGlobal::addTrees ( const int  resourceIndex,
QString  content 
)
slot

add tree distribution

◆ addTreesOnMap

int ScriptGlobal::addTreesOnMap ( const int  standID,
QString  content 
)
slot

add trees (distribution mode) for stand 'standID'

◆ alert

void ScriptGlobal::alert ( QString  message)
slot

shows a message box to the user (if in GUI mode)

◆ currentDir()

QString ScriptGlobal::currentDir ( ) const
inline

current execution directory (default is the Script execution directory)

◆ debugOutputFilter

void ScriptGlobal::debugOutputFilter ( QList< int >  ru_indices)
slot

enable debug outputs for a list of resource units (output for other RUs are suppressed)

◆ defaultDirectory

QString ScriptGlobal::defaultDirectory ( QString  dir)
slot

get default directory of category 'dir'

◆ executeJSFunction()

QString ScriptGlobal::executeJSFunction ( QString  function)
static

◆ executeScript()

QString ScriptGlobal::executeScript ( QString  cmd)
static

◆ fileExists

bool ScriptGlobal::fileExists ( QString  fileName)
slot

return true if the given file exists.

◆ formattedErrorMessage()

QString ScriptGlobal::formattedErrorMessage ( const QJSValue &  error_value,
const QString &  sourcecode 
)
static

◆ grid

QJSValue ScriptGlobal::grid ( QString  type)
slot

return Javascript grid for given type

◆ gridToFile

bool ScriptGlobal::gridToFile ( QString  grid_type,
QString  file_name 
)
slot

create a "ESRI-grid" text file 'grid_type' is one of a fixed list of names, 'file_name' the ouptut file location

write grid to a file...

◆ include

void ScriptGlobal::include ( QString  filename)
slot

"include" the given script file and evaluate. The path is relative to the "script" path

◆ JStoString()

QString ScriptGlobal::JStoString ( QJSValue  value)
static

◆ loadModelSnapshot

bool ScriptGlobal::loadModelSnapshot ( QString  file_name)
slot

loads a snapshot of the current model state (trees, soil, etc.) from a dedicated SQLite database.

◆ loadScript()

void ScriptGlobal::loadScript ( const QString &  fileName)
static

◆ loadStandCarbon

bool ScriptGlobal::loadStandCarbon ( )
slot

◆ loadStandSnapshot

bool ScriptGlobal::loadStandSnapshot ( int  stand_id,
QString  file_name 
)
slot

◆ loadTextFile

QString ScriptGlobal::loadTextFile ( QString  fileName)
slot

load content from a text file in a String (

See also
CSVFile)

◆ msec()

int ScriptGlobal::msec ( ) const

the milliseconds since the start of the day

◆ path

QString ScriptGlobal::path ( QString  filename)
slot

get a path relative to the project main folder

◆ print

void ScriptGlobal::print ( QString  message)
slot

print the contents of the message to the log

◆ qt5()

bool ScriptGlobal::qt5 ( ) const
inline

is this the qt5-model? (changes in script object creation)

◆ reloadABE

void ScriptGlobal::reloadABE ( )
slot

◆ removeSaplings

void ScriptGlobal::removeSaplings ( int  standId,
double  x,
double  y,
double  width,
double  height 
)
slot

remove all saplings from a metric rectangle. See also addSaplings().

◆ repaint

void ScriptGlobal::repaint ( )
slot

force a repainting of the GUI visualization (if available)

◆ resourceUnit

QJSValue ScriptGlobal::resourceUnit ( int  index)
slot

access to single resource unit (returns a reference)

◆ resourceUnitCount()

int ScriptGlobal::resourceUnitCount ( ) const

get number of resource uinit

◆ resourceUnitGrid

QJSValue ScriptGlobal::resourceUnitGrid ( QString  expression)
slot

return a grid (level of resource units) with the result of an expression evaluated in the context of the resource unit.

◆ saveDebugOutputs

bool ScriptGlobal::saveDebugOutputs ( bool  do_clear)
slot

save debug outputs to file; if do_clear=true then debug data is cleared from memorey

◆ saveModelSnapshot

bool ScriptGlobal::saveModelSnapshot ( QString  file_name)
slot

saves a snapshot of the current model state (trees, soil, etc.) to a dedicated SQLite database.

◆ saveStandCarbon

bool ScriptGlobal::saveStandCarbon ( int  stand_id,
QList< int >  ru_ids,
bool  rid_mode = true 
)
slot

◆ saveStandSnapshot

bool ScriptGlobal::saveStandSnapshot ( int  stand_id,
QString  file_name 
)
slot

◆ saveTextFile

void ScriptGlobal::saveTextFile ( QString  fileName,
QString  content 
)
slot

save string (content) to a text file.

◆ screenshot

bool ScriptGlobal::screenshot ( QString  file_name)
slot

make a screenshot from the central viewing widget

◆ seedMapToFile

bool ScriptGlobal::seedMapToFile ( QString  species,
QString  file_name 
)
slot

save the "seedmap" (i.e. a grid showing the seed distribution) as ESRI rastser file

◆ set

void ScriptGlobal::set ( QString  key,
QString  value 
)
slot

set the value of a setting

◆ setCurrentDir()

void ScriptGlobal::setCurrentDir ( QString  newDir)
inline

set current working dir

◆ setting

QVariant ScriptGlobal::setting ( QString  key)
slot

get a value from the global xml-settings (returns undefined if not present)

◆ setUIshortcuts

void ScriptGlobal::setUIshortcuts ( QJSValue  shortcuts)
slot

set a list of JS shortcuts in the UI

◆ setupGlobalScripting()

void ScriptGlobal::setupGlobalScripting ( )
static

◆ setViewOptions()

void ScriptGlobal::setViewOptions ( QJSValue  opts)

set current view options

◆ setViewport

void ScriptGlobal::setViewport ( double  x,
double  y,
double  scale_px_per_m 
)
slot

set the viewport of the main project area view

◆ speciesShareGrid

QJSValue ScriptGlobal::speciesShareGrid ( QString  species)
slot

return a grid with the basal area of the given species (resource unit resolution)

◆ startOutput

bool ScriptGlobal::startOutput ( QString  table_name)
slot

starts output 'table_name'. return true if successful

◆ stopOutput

bool ScriptGlobal::stopOutput ( QString  table_name)
slot

stops output 'table_name'. return true if successful

◆ systemCmd

void ScriptGlobal::systemCmd ( QString  command)
slot

execute system command (e.g., copy files)

◆ test_tree_mortality

void ScriptGlobal::test_tree_mortality ( double  thresh,
int  years,
double  p_death 
)
slot

◆ valueFromJs()

QJSValue ScriptGlobal::valueFromJs ( const QJSValue &  js_value,
const QString &  key,
const QString  default_value = QLatin1Literal(""),
const QString &  errorMessage = QLatin1Literal("") 
)
static

◆ viewOptions()

QJSValue ScriptGlobal::viewOptions ( )

retrieve current viewing options (JS - object)

◆ wait

void ScriptGlobal::wait ( int  milliseconds)
slot

wait for 'milliseconds' or (if ms=-1 until a key is pressed)

◆ worldX()

double ScriptGlobal::worldX ( )

extent of the world (without buffer) in meters (x-direction)

◆ worldY()

double ScriptGlobal::worldY ( )

extent of the world (without buffer) in meters (y-direction)

◆ year()

int ScriptGlobal::year ( ) const

current year in the model

Member Data Documentation

◆ scriptOutput

QObject * ScriptGlobal::scriptOutput = nullptr
static

public "pipe" for script output (is redirected to GUI if available)

Property Documentation

◆ currentDir

QString ScriptGlobal::currentDir
readwrite

◆ msec

int ScriptGlobal::msec
read

◆ qt5

bool ScriptGlobal::qt5
read

◆ resourceUnitCount

int ScriptGlobal::resourceUnitCount
read

◆ viewOptions

QJSValue ScriptGlobal::viewOptions
readwrite

◆ worldX

double ScriptGlobal::worldX
read

◆ worldY

double ScriptGlobal::worldY
read

◆ year

int ScriptGlobal::year
read

The documentation for this class was generated from the following files: