PDA

View Full Version : Structure of Qt Widget Application for a CLIPS frontend



Agent92
20th November 2016, 02:03
Hi,

As mentioned I'm working on developing a frontend for CLIPS using Qt. I am not inexperienced in designing GUIs but I've only used Swing and wxWidgets(Python). I chose Qt since it's cross platform and I can write in C++. My question is- How do I integrate various CLIPS features into my Qt Application? Should I create one Widget class and then define all the callbacks in it and call it in my main ? Or should I create a separate class for agenda browser, fact browser etc?

Thanks in advance.

anda_skoa
20th November 2016, 10:59
Aside from the obvious question of what this CLIPS is, this doesn't sounds like a very Qt specific question.

Just like with any of the fraemworks you've worked before, you can structure your project in any way that you find good to work with.

Cheers,
_

d_stranz
20th November 2016, 20:14
the obvious question of what this CLIPS is

I presume the OP is referring to the expert system implementation tool, CLIPS, developed by NASA in the 1980s, and now a SourceForge project. I have never used it, but from what I read it has primarily a command-line oriented interface. The developers have implemented GUI-like interfaces for Windows and Mac, but these look like thin veneers over a command line terminal, with a bunch of menus and dialogs for parameter configuration and rule browsing. The main interface still appears to be a command line. Unimpressive and unimaginative.

You should be referring to Chapter 4 in the CLIPS Advanced Programming Guide (APG), on Embedding CLIPS. I would represent the interface to the CLIPS environment as a QObject-based class (Let's call it QCLIPSObject). This will likely be a Singleton and implemented as a global variable for use by the rest of your app (much like there is a global Qt variable named "qApp" holding a pointer to the single instance of the QApplication object). The communication between the rest of your GUI and CLIPS will be through signals and slots implemented on QCLIPSObject. Either your main() function or your QMainWindow constructor will create this Singleton instance and assign it to the global variable. In order to keep your GUI responsive, you will need to add a static method to this class that is a callback from CLIPS implementing a "periodic function" (see 4.1.2 EnvAddPeriodicFunction in CLIPS APG). In this function, you'll need to call QApplication::processEvents().

The QCLIPSObject class would also have methods called in its constructor to initialize CLIPS, install the periodic function, and install any other callbacks needed for interaction with CLIPS. Callbacks from CLIPS map to static C++ methods of QCLIPSObject. In those static methods, you will emit Qt signals (called through the global QCLIPSObject pointer) so that the rest of your app can get notice of what CLIPS is doing.

You could choose initially to implement your GUI in the same way as in the CLIPS Interface Guide (IG), with menus on a Qt QMainWindow-based class to drive interaction with your CLIPS object. You could add dialogs (each implemented as a separate QDialog-based class with a UI constructed using Qt Designer).

AFAIK, Qt doesn't have a widget that emulates a command line console but there is an old SourceForge project (https://sourceforge.net/projects/qconsole/) that could probably be ported to Qt 5 if you wanted to go that route.

If you want to get fancier, then instead of using QDialog for your various browsers, you could implement them as QDockWidget-based classes instead. An easy way to do this is to implement the GUI as derived from QWidget. You could then choose to embed that QWidget either in a QDialog or in a QDockWidget without modification.

I don't know what your application is for CLIPS. If all you want to do is to implement a new GUI for interaction with it, then a console-based approach is probably as far as you can go. If you are actually targeting a specific application area, then you can add other graphical widgets to display plots and so forth. Some of the NASA-published papers on the CLIPS web site have some 1980 - 1990 era graphical interfaces developed for specific CLIPS applications.

If you want to get really fancy and make a lot of work for yourself, you can design this whole system to be extensible using plugins. Qt has classes and libraries for implementing plugin-based applications in which an application's basic functionality can be extended using plugins implemented in DLLs. Qt Creator is in fact implemented this way.

Have fun.