QtCyberle+
- Running the demo
- Basic Steps
- OAWwrl2cpp Compiler
- Implementation of the Script Node
- Embedding the Implemented Script
To start the demo, execute qtcyberle+.exe and load the file embedded_script.wrl through the file menu.
Now you are able to control the orientation of the box whithin the VRML scene through the QT sliders, but you are also able to control the value of the LCD display through the slider within the VRML scene. In the following it will be explained how this can be achieved with the OAW framework. Of course it is possible to make such a component participate in a parallel simulation on a cluster, by using an instance of the SockEventBrokerC.
The basic procedure is very similar to embed CORBA objects into an application:
- Compile the script interface definition from a VRML file to cpp skeleton code
- Implement the functionality of this class by inheritance
- Get from the instanciated world model the script node and set an instance of the implemented script as the implementation object
The usage of the wrl2cpp compiler is:
OAWwrl2cpp -f <wrlfile> -s <script defname> -c <classname>
In the example of this tutorial you'll find in the "embedded_script.wrl" file the script node we want to embed into the QTCyberle example. This script will provide links of three sliders in the QT GUI to the VRML world but also a link from one slider in the VRML world back to the QT GUI. The script we want to compile in this example looks like.
DEF QTCYBERLE_SCRIPT Script {
eventOut SFRotation xRot
eventOut SFRotation yRot
eventOut SFRotation zRot
eventIn SFFloat lcdIn
url ""
}
Through the eventOut slots it will be possible to send events from the QT application into the VRML world and through the eventIn slot events from the VRML world to the QT application. If you compile the "embedded_script.wrl" file with
OAWwrl2cpp -f embedded_script.wrl -s QTCYBERLE_SCRIPT -c QTCyberleScriptC ,
you'll get the files:
qtcyberlescriptc.h
qtcyberlescriptc.cpp
qtcyberlescriptc_impl._h
qtcyberlescriptc_impl._cpp
The first two files are the skeleton files containing all code needed to link this class the OAW distributed framwork. The two latter files contains an template for the inherited class for the implementation. You can use them as a starting point for your implementation of the script by deleteing the underscore from the suffixes and at them together with the files of the skeleton code to your project.
The implementation of the script for this tutorial is very short. First we change the default constructor in the way, that it takes a reference to the QTCyberle object as a reference.
QTCyberleScriptC_Impl::QTCyberleScriptC_Impl(QTCyberle* p){
m_pCyberle=p;
}
void QTCyberleScriptC_Impl::lcdIn(const SFFloat& x, const SFTime& timeStamp){
m_pCyberle->setValueChanged(x);
}
Embedding the Implemented Script
If the script has been implemented it can be implanted to the VRML-world by using the "SetImpl" function of the script node. The script node can be received from the VRML world object with the function "GetDefNode".
OAW::CybScriptC* pQTScript = (OAW::CybScriptC*)m_pWorld->GetDefNode("QTCYBERLE_SCRIPT");
delete m_pScriptImpl;
m_pScriptImpl=0;
if(pQTScript){
m_pScriptImpl = new OAW::QTCyberleScriptC_Impl(this);
pQTScript->SetImpl(m_pScriptImpl);
}
Now the appropriate member functions of the QTCyberleScriptC_Impl object are used. Through the instance of the impleneted script it is possible to trigger eventOut events. Any eventOut function of the Script declaration is mapped to a member function of the skeleton code may the naming convention:
void send_<eventOut name>
So that the QTCyberle object can deligate the QT events from the QTSlider to the VRML Script like this:
void QTCyberle::setXRotation( int degrees ){
if(m_pScriptImpl){
OAW::SFRotation r;
r.x = 1;
r.y = 0;
r.z = 0;
r.w = degrees*3.14/180;
m_pScriptImpl->send_xRot(r);
}
}
The setXRotation function of the QTCyberle object is been connected to the QTSlider like it is common in QT.
QSlider* z = new QSlider ( 0, 360, 60, 0, QSlider::Vertical, this, "zsl" );
z->setTickmarks( QSlider::Left );
QObject::connect( z, SIGNAL(valueChanged(int)),m_pCyberle,SLOT(setZRotation(int)) );