Linked List of Rocs

Well, long time without post in planet ( sorry ppl :( )

So, let me make a little resumé of work in Rocs during this winter (yeah, is winter here in Brazil) :

  • Rocs now can use the existing scripts ( first step to KGHN :) );
  • Rocs now can open/write Dot (graphviz), KML and GML files;
  • Rocs support data structu plugins (for now graphs and linked list);
  • Rocs receive some minor improvements like support multiple opened documents and execute a script after load a  file (bonnus :) );

below  is a video that show Rocs starting from a graph, then converting  to a linked list, add some nodes and link then. Of course, that not only  using mouse, but also with the script (that is the final objective).

The script in this example is a simple one that walk over the list to the end and add the new node to end.

list = graphs[0]
var n = list.createNode("NewNode")
var prev = list.front();
while (prev.front()  !=  0){
   prev =prev.front();

As you can see, when we are using linked list plugin, the API of script is diferent from graph API (no make sense we have front(), for instance, when we are working with graphs). A data structure plugin use as base a graph struture to avoid extra work to create a new plugin. To create a new data structure plugin, developer write need write only 2 classes: the plugin it self and a base of data structure as show bellow (some code like constructors and code to kservice was removed to make it short):

class TreeDSPlugin : public DSPluginInterface{
  Graph* changeToDS ( Graph* graph) {
     return new TreeStructure(*graph);
  Graph* createDS ( GraphDocument* parent ){
     return new TreeStructure(parent);
class TreeStructure : public Graph{
 Edge * addEdge(Node* from, Node to){
   if (from->out_edges().count == 2){
   return Graph::addEdge(from, to);

The first class is only a class to provide a library to load at run time ( using kservice ) and build the objects using a specific data structure class. To present a small example, the data structure plugin in second class is a binary tree and the method overwrited is addEdge(), to ensure that a node has only two childs. But this example provide only this basic behavior, no providing any new methods to be used in scripts, no graphics items to be drawn nor new itens to properties windows.

The data structure system, was developed to make easy to write new plugins (few code to be write) but also it can be very powerfull, allowing the new plugins to provide extra methods to be used in scripts, own graphics item (take a look in video to edges), and extra itens in properties window. See images bellow:

All this code is allready in Rocs’ trunk and i’m working now in some details like removing not used members and some refactoring (Graph should be called as BaseDataStructure or something like this). if you want to try it and create you own data structure plugin, ask me how to begin.


Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do

Você está comentando utilizando sua conta Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s

%d blogueiros gostam disto: