Friday, March 13, 2009

Flux Balanace Analaysis and generic C interfaces

It is difficult to create intricate interfaces using the C API. What is more practical is to just write a C++ plugin. So, suppose you need a relatively complicated interface for a C function, then the procedure is as follows:

  • design the interface using Qt C++
  • write the C program and make it into a dynamic library
  • make the C++ plugin call the C program using LibraryThread
  • place the C++ dynamic library in the "menu.txt" file so that it appears along with the other "functions".
The Flux Balance Analysis function is one such example. The interface is a regular plugin, but it calls the C program (lpsolve.c) when the run button is pressed. The plugin can therefore respond to selection events and other events. The plugin creates a matrix that is passed on to lpsolve.c as input.

Normal C dynamic libraries are loaded using the LibraryThread class. However, since these C++ programs are different, the LibraryThread performs a check to see whether the "loadTCTool" function exists in the library. If it does exist, then the library is loaded as a plugin on the main thread and not as a threaded C program, which is usually on a separate thread.



The diagram above shows how different libraries are loaded. Essentially, if the library contains the "run" function, it is assumed to be a C program. If it contains the "loadTCTool" function, it is assumed to be a C++ library that adds a new tool to the main window. The LibraryThread runs the C program on a separate thread and unloads the library when the program is finished. The C++ libraries represent widgets and other such tools which are only unloaded when TinkerCell exists.

No comments: