00001 /*---------------------------------------------------------------------------*\ 00002 * OpenSG * 00003 * * 00004 * * 00005 * Copyright (C) 2000-2002 by the OpenSG Forum * 00006 * * 00007 * www.opensg.org * 00008 * * 00009 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de * 00010 * * 00011 \*---------------------------------------------------------------------------*/ 00012 /*---------------------------------------------------------------------------*\ 00013 * License * 00014 * * 00015 * This library is free software; you can redistribute it and/or modify it * 00016 * under the terms of the GNU Library General Public License as published * 00017 * by the Free Software Foundation, version 2. * 00018 * * 00019 * This library is distributed in the hope that it will be useful, but * 00020 * WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00022 * Library General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU Library General Public * 00025 * License along with this library; if not, write to the Free Software * 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00027 * * 00028 \*---------------------------------------------------------------------------*/ 00029 /*---------------------------------------------------------------------------*\ 00030 * Changes * 00031 * * 00032 * * 00033 * * 00034 * * 00035 * * 00036 * * 00037 \*---------------------------------------------------------------------------*/ 00038 00039 //--------------------------------------------------------------------------- 00040 // Includes 00041 //--------------------------------------------------------------------------- 00042 00043 #include "qstring.h" 00044 00045 #include "OSGWindowQTPlugin.h" 00046 00047 // #include "OSGQGLDesignerWidget_qt.h" 00048 #include "OSGQGLManagedDesignerWidget_qt.h" 00049 #include "OSGQGLManagedWidget_pixmap.xpm" 00050 00051 #include <OSGDrawAction.h> 00052 #include "OSGSimpleGeometry.h" 00053 #include "OSGViewport.h" 00054 #include "OSGPerspectiveCamera.h" 00055 #include "OSGSolidBackground.h" 00056 #include "OSGTrackball.h" 00057 00058 #include <OSGNode.h> 00059 00060 OSG_USING_NAMESPACE 00061 00062 00063 /***************************************************************************\ 00064 * Description * 00065 \***************************************************************************/ 00066 00072 /***************************************************************************\ 00073 * Class methods * 00074 \***************************************************************************/ 00075 00076 /*-------------------------------------------------------------------------*\ 00077 - public - 00078 \*-------------------------------------------------------------------------*/ 00079 00080 /*------------------------- constructors ----------------------------------*/ 00081 00084 OSGWindowQTPlugin::OSGWindowQTPlugin() 00085 { 00086 osgInit(0, NULL); 00087 } 00088 00091 OSGWindowQTPlugin::~OSGWindowQTPlugin() 00092 { 00093 osgExit(); 00094 } 00095 00096 00099 QStringList OSGWindowQTPlugin::keys() const 00100 { 00101 QStringList list; 00102 00103 // the OSGQGLDesignerWidget is disabled because it needs to be inherited 00104 // to be used. A widget plugin cannot be inherited within designer 00105 // list << "OSGQGLDesignerWidget"; 00106 list << "OSGQGLManagedDesignerWidget"; 00107 return list; 00108 } 00109 00112 QWidget* 00113 OSGWindowQTPlugin::create( const QString &key, QWidget *parent, const char *name ) 00114 { 00115 // the OSGQGLDesignerWidget is disabled because it needs to be inherited 00116 // to be used. A widget plugin cannot be inherited within designer 00117 // if ( key == "OSGQGLDesignerWidget" ) 00118 // { 00119 // OSGQGLDesignerWidget *w = new OSGQGLDesignerWidget( parent, name ); 00120 // ViewportPtr vp = osg::NullFC; 00121 // NodePtr root = osg::NullFC; 00122 // TransformPtr cam_trans = osg::NullFC; 00123 // DrawAction *ract; 00124 // PerspectiveCameraPtr cam = osg::NullFC; 00125 // SolidBackgroundPtr bkgnd = SolidBackground::create(); 00126 // Trackball *tball = new Trackball(); // mem leak here 00127 // 00128 // // beacon for camera and light 00129 // NodePtr b1n = Node::create(); 00130 // GroupPtr b1 = Group::create(); 00131 // beginEditCP(b1n); 00132 // b1n->setCore( b1 ); 00133 // endEditCP(b1n); 00134 // 00135 // // transformation 00136 // NodePtr t1n = Node::create(); 00137 // TransformPtr t1 = Transform::create(); 00138 // beginEditCP(t1n); 00139 // t1n->setCore( t1 ); 00140 // t1n->addChild( b1n ); 00141 // endEditCP(t1n); 00142 // 00143 // cam_trans = t1; 00144 // 00145 // // light 00146 // 00147 // NodePtr dlight = Node::create(); 00148 // DirectionalLightPtr dl = DirectionalLight::create(); 00149 // 00150 // beginEditCP(dlight); 00151 // dlight->setCore( dl ); 00152 // endEditCP(dlight); 00153 // 00154 // beginEditCP(dl); 00155 // dl->setAmbient( .3, .3, .3, 1 ); 00156 // dl->setDiffuse( 1, 1, 1, 1 ); 00157 // dl->setDirection(0,0,1); 00158 // dl->setBeacon( b1n); 00159 // endEditCP(dl); 00160 // 00161 // // root 00162 // root = Node::create(); 00163 // GroupPtr gr1 = Group::create(); 00164 // beginEditCP(root); 00165 // root->setCore( gr1 ); 00166 // root->addChild( t1n ); 00167 // root->addChild( dlight ); 00168 // endEditCP(root); 00169 // 00170 // NodePtr file = makeInitialScene(); 00171 // file->updateVolume(); 00172 // 00173 // Vec3f min,max; 00174 // file->getVolume().getBounds( min, max ); 00175 // 00176 // beginEditCP(dlight); 00177 // dlight->addChild( file ); 00178 // endEditCP(dlight); 00179 // 00180 // // camera 00181 // cam = PerspectiveCamera::create(); 00182 // cam->setBeacon( b1n ); 00183 // cam->setFov( deg2rad( 60 ) ); 00184 // cam->setNear( 100 ); 00185 // cam->setFar( 100000 ); 00186 // 00187 // // Background 00188 // bkgnd->setColor( Color3f( 0,0,1 ) ); 00189 // 00190 // // Viewport 00191 // 00192 // vp = Viewport::create(); 00193 // vp->setCamera( cam ); 00194 // vp->setBackground( bkgnd ); 00195 // vp->setRoot( root ); 00196 // vp->setSize( 0,0, 1,1 ); 00197 // 00198 // // Action 00199 // ract = DrawAction::create(); 00200 // 00201 // Vec3f pos( 0, 0, max[2] + ( max[2] - min[2] ) * 1.5 ); 00202 // 00203 // tball->setMode( Trackball::OSGObject ); 00204 // tball->setStartPosition( pos, true ); 00205 // tball->setSum( true ); 00206 // tball->setTranslationMode( Trackball::OSGFree ); 00207 // 00208 // QTWindowPtr osgWin = QTWindow::create(); 00209 // osgWin->setGlWidget( w ); 00210 // osgWin->addPort( vp ); 00211 // osgWin->init(); // create the context 00212 // osgWin->activate(); // and activate it 00213 // 00214 // return w; 00215 // } 00216 if ( key == "OSGQGLManagedDesignerWidget" ) 00217 { 00218 OSGQGLManagedDesignerWidget *w = 00219 new OSGQGLManagedDesignerWidget( parent, name ); 00220 00221 w->getManager().setRoot( makeInitialScene() ); 00222 return w; 00223 } 00224 return 0; 00225 } 00226 00227 osg::NodePtr OSGWindowQTPlugin::makeInitialScene() 00228 { 00229 OSG::NodePtr scene = OSG::makeTorus(.5, 1, 8, 8); 00230 OSG::NodePtr scene2 = OSG::makeTorus(.1, 2, 10, 12); 00231 00232 OSG::NodePtr grn = OSG::Node::create(); 00233 OSG::GroupPtr gr = OSG::Group::create(); 00234 00235 OSG::beginEditCP(grn, OSG::Node::CoreFieldMask | OSG::Node::ChildrenFieldMask ); 00236 grn->setCore(gr); 00237 grn->addChild(scene); 00238 grn->addChild(scene2); 00239 OSG::endEditCP (grn, OSG::Node::CoreFieldMask | OSG::Node::ChildrenFieldMask ); 00240 00241 return grn; 00242 } 00243 00246 QString OSGWindowQTPlugin::includeFile( const QString& key ) const 00247 { 00248 // the OSGQGLDesignerWidget is disabled because it needs to be inherited 00249 // to be used. A widget plugin cannot be inherited within designer 00250 // if ( key == "OSGQGLDesignerWidget" ) 00251 // return "OSGQGLDesignerWidget_qt.h"; 00252 if ( key == "OSGQGLManagedDesignerWidget" ) 00253 return "OpenSG/OSGQGLManagedDesignerWidget_qt.h"; 00254 return QString::null; 00255 } 00256 00259 QString OSGWindowQTPlugin::group( const QString& key ) const 00260 { 00261 // the OSGQGLDesignerWidget is disabled because it needs to be inherited 00262 // to be used. A widget plugin cannot be inherited within designer 00263 // if ( key == "OSGQGLDesignerWidget" ) 00264 // return "OpenSG"; 00265 if ( key == "OSGQGLManagedDesignerWidget" ) 00266 return "OpenSG"; 00267 return QString::null; 00268 } 00269 00272 QIconSet OSGWindowQTPlugin::iconSet( const QString& key ) const 00273 { 00274 // the OSGQGLDesignerWidget is disabled because it needs to be inherited 00275 // to be used. A widget plugin cannot be inherited within designer 00276 // if ( key == "OSGQGLDesignerWidget" ) 00277 // return QIconSet( QPixmap( OSGQGLManagedWidget_pixmap ) ); 00278 if ( key == "OSGQGLManagedDesignerWidget" ) 00279 return QIconSet( QPixmap( OSGQGLManagedWidget_pixmap ) ); 00280 return QIconSet(); 00281 } 00282 00285 QString OSGWindowQTPlugin::toolTip( const QString& key ) const 00286 { 00287 // the OSGQGLDesignerWidget is disabled because it needs to be inherited 00288 // to be used. A widget plugin cannot be inherited within designer 00289 // if ( key == "OSGQGLDesignerWidget" ) 00290 // return "OpenSG Qt Designer Widget"; 00291 if ( key == "OSGQGLManagedDesignerWidget" ) 00292 return "OpenSG Managed Qt Designer Widget"; 00293 return QString::null; 00294 } 00295 00299 QString OSGWindowQTPlugin::whatsThis( const QString& key ) const 00300 { 00301 // the OSGQGLDesignerWidget is disabled because it needs to be inherited 00302 // to be used. A widget plugin cannot be inherited within designer 00303 // if ( key == "OSGQGLDesignerWidget" ) 00304 // return "A widget to display OpenSG scene"; 00305 if ( key == "OSGQGLManagedDesignerWidget" ) 00306 return "A widget to display OpenSG scene with Simple Scene Manager features"; 00307 return QString::null; 00308 } 00309 00313 bool OSGWindowQTPlugin::isContainer( const QString & key ) const 00314 { 00315 // the OSGQGLDesignerWidget is disabled because it needs to be inherited 00316 // to be used. A widget plugin cannot be inherited within designer 00317 // if ( key == "OSGQGLDesignerWidget" ) 00318 // return false; 00319 if ( key == "OSGQGLManagedDesignerWidget" ) 00320 return false; 00321 return false; 00322 } 00323 00324 Q_EXPORT_PLUGIN( OSGWindowQTPlugin ) 00325 00326 /*-------------------------------------------------------------------------*/ 00327 /* cvs id's */ 00328 00329 #ifdef __sgi 00330 #pragma set woff 1174 00331 #endif 00332 00333 #ifdef OSG_LINUX_ICC 00334 #pragma warning( disable : 177 ) 00335 #endif 00336 00337 namespace 00338 { 00339 static Char8 cvsid_cpp[] = "@(#)$Id: OSGWindowQTPlugin.cpp,v 1.2 2003/07/09 08:53:32 dirk Exp $"; 00340 static Char8 cvsid_hpp[] = OSGWINDOWQTPLUGIN_HEADER_CVSID; 00341 } 00342
1.4.3