Table of Contents
Rocs internally uses the QtScript scripting engine, which is a specific JavaScript engine. This means, all algorithms that you implement must use JavaScript. How JavaScript works and how to write JavaScript code is not covered in this handbook, though we explain how to access data structures, data elements and pointers of your data structures from the scripting engine. Since you never use the basic data structure object but one that is provided by the currently used data structure backend, the functionality of the data structure is extended by the corresponding backend and you should have a look at the specialized functionality. Especially, data structure backends use the common terms from their domain (nodes and edges in graphs, leafs and roots in trees, etc.)
It is important to know that changes done by the scripting engine are directly reflected at the properties at the visual graph editor whiteboard. Hence, the scripts actually modify the data structures.
Every backend provides a special set of functions and properties for its data structures and their elements. But also every backend provides the properties and functions that are defined for the base data structure. Hence, everything explained in this sections is available for every data structure backend.
Data structures are identified by their names.
Assuming you created a data structure with name testgraph, then you can access the data structure simply by writing this identifier.
For example, to get an array with all data elements in the given data structure, you can write testgraph.list_nodes(); in the script.
Each data element has the following properties that can be read or written:
double x // x coordinate of current position
double y // y coordinate of current position
double width // size
string value // value
int id // unique identifier for data element
string name // name
string color // color in HEXA
Further, every dynamic property of a data element can be accessed by its name.
Each data element object provides the following methods:
int type(); // data type of data element
int set_type(int); // set data type of the data element
void add_property(string name, // add dynamic property to data element with specified name and value
string value);
array adj_data(); // list of adjacent data
array adj_pointers(); // list of adjacent pointers
array input_pointers(); // list of input pointers
array output_pointers(); // list of output pointers
array loop_pointers(); // list of pointers forming a self-loop
array connected_pointers(target); // list of pointers pointing to 'target'
void remove(); // remove this data element
Each pointer has the following properties that can be read or written:
string color // color in HEXA
string value // value
string name // name
double width // width
string style // value out of: dot, dash, dash dot, solid
Further, every dynamic property of a pointer can be accessed by its name.
Each pointer object provides the following methods:
int type(); // pointer type of pointer
int set_type(int); // set pointer type of the pointer
void add_property(string name, // add dynamic property to data element with specified name and value
string value);
node start(); // start node of the pointer
node end(); // target node of the pointer
void remove(); // remove this pointer