GTK+ IOStream  Beta
<< GTK+ >> add C++ IOStream operators to GTK+. Now with extra abilities ... like network serialisation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Brief intro to GTK+ IOStream - build GUIs similar to iostream operation and object broker your classes over the network.

Copyright

Copyright 2001 to 2013 Matt Flax flatm.nosp@m.ax@f.nosp@m.latma.nosp@m.x.or.nosp@m.g

License

This software is governed by the GPL license.

Introduction

This software is for building GUIs, Object Request Broking (ORB) classes over networks and the interfaceing of C++ to Octave.org using Eigen3 matrices.

The GUI related classes are intended to be light weight GTK wrappers for use in C++.

The ORB (object request brokering) classes ORBOriginator and ORBReplicator utilise Zeroc Ice to implement the actual ORB application layer. When the term ORB is used, it implies the following :

Octave is interfaced using Eigen3 which is a hardware optimised matrix computation library.

As far as the GUI software is concerned, it is all contanined in the class header files, this means that you can simply include the headers and code away without having to worry about compiling any source code files other then your own.

GUI detail

The general paradigm is that you can very easily construct GTK object and in some cases use the C++ IOStream paradigm to build graphical user interfaces (GUIs).

For example, I will create labels in a Vertical box like so :

VBox vbox; // create a VBox
Labels labels; // Create a labels structure
labels<<"First Label"<<"Second Label"; // Load some labels
vbox<<labels; // Put the labels into the VBox
vbox.show(); // show the VBox

Similar things can be done with buttons (label buttons, toggle buttons, XPM and transparent XPM buttons are also supported)

This example runs gtk as normal and loads an HBox into the GTK top window. The HBox is loaded with a quit label button.

// The quit button callback
static void quit(void *wid, gpointer data){
gtk_main_quit();
}
int main(int argc, char *argv[]){
gtk_init( &argc, &argv ); // start GTK
GtkInterface topWindow; // create the top window
HBox hbox; // create a horizontal box for holding the buttons
Buttons buttons; // create a buttons holder
buttons<<BUTTONLABELSTRUCT("Quit", quit, NULL); // load a label button - other button types are also available
hbox<< buttons; // add the button to the HBox
hbox.show(); // show the HBox
topWindow<< hBox; // load the HBox into the top window
gtk_main(); // run GTK
}

The Labels and Buttons are actually based on the LinkList datatype - which is a templated lightweight doubly linked list.

If you want to get compact, you can write like so :

topWindow << (hbox << buttons<<BUTTONLABELSTRUCT("Quit", quit, NULL)).show();

If you want access to the GTK+ widgets, it is easy

GtkWidget* widget=hbox.getWidget(); // Standard GtkWidgets are readily accessible for all classes.

Plotting example

Plotting is easy and is similar to Octave.org (Matlab) style plotting commands.

For example the following code :

#define cnt 4
float x[cnt]={0.0, 1., 2., 3.};
float y1[cnt]={0.0, 1., 2., 3.};
float y2[cnt]={1.0, 2., 3., 4.};
Plot figure; // create and show a Figure
figure.plot(x,y1,cnt); // Plot the first line with default colours
figure.hold(true); // hold the current curve and add another
figure.plot(x,y2,cnt, "r1"); // plot this one as a red line
// Changing the style of the plot
figure.limits(-1.0,4.0,-1.,5.0); // open the window out to be able to see all
figure.grid(true); // show a grid
figure.title("Figure 1 title"); // add the title, x label and y label
figure.xLabel("X axis label");
figure.yLabel("Y axis label");

Produces this :

PlotExample.png

Octave detail

Octave is simplistically instantiated and run like so :

Octave octave(args);
output = octave.runM("yourMFile.m", input);

A more detailed description can be found in the Octave class detailed description.

To utilise the Octave code, the Octave.C file must be linked with your code. The reason for separating the Octave source from the header is that octave uses libfftw.so, where as you may want to use libfftwf.so in your own code. By separating the Octave code out from the Octave header file, you are able to link against the Octave header and utilise octave without having to link against its shared libraries directly.

Object Request Broking detail

ORB is desigend to be trivial.

On the originating side of the network, the following is executed

ORBOriginator origin(argc, argv, string("BasePipe")); // This is the original locaiton where the classes are created
// Create a class and add it to the ORB application layer
ORBTestClass *otc = new ORBTestClass; // this is the class to be added to the ORB application layer
origin.addClass(otc, otc->name); // add it to the originator

On the replication side of the network, the following is executed

// create the replicator which will connect to loopback
ORBTestReplicator replicator(argc, argv, string("BasePipe"), string("127.0.0.1")); // This is the replicating locaiton where the classes are proxies
// If you want the same class with the same state as it is on the originator, you can like so :
ORBTestClass *otc = replicator.getObjectPointer<ORBTestClass>(ORBTestClass::name);
cout<<"variable = "<<otc->variable<<endl;
// By using a proxy, you can execute the originator class's methods
ORBTestICEPrx oRBTestICEPrx = replicator.getObjectProxy<ORBTestICEPrx>(ORBTestClass::name);
cout<<"input = "<<oRBTestICEPrx->method(1)<<endl;

A more detailed example is in the ORBTest.C class. There is also other documentation in the ORBOriginator and ORBReplicator class documentation.

To utilise the ORB (ORBOriginator and ORBReplicator) code, you must specify your network protocol in a .ice file. This .ice file specifies in object oriented code what objects you will be sending over the network (simple types are int, float, vector<TYPE> and many others). The slice2cpp application is run at compile time to machine generate .C code from the .ice files. These then are linked into your application.