Documentation


MainController.h

Go to the documentation of this file.
00001 
00002 //                            MainController.h                                //
00004 
00005 #ifndef MAIN_CONTROLLER_QT_H
00006 #define MAIN_CONTROLLER_QT_H
00007 
00008 #include <qtimer.h>
00009 #include <qscrollview.h>
00010 
00011 #include <X3DTK/kernel.h>
00012 
00013 #include <animal/X3DTK/mainScene.h>
00014 #include <animal/X3DTK/Qt/X3DTreeGUI/X3DTreeQt.h>
00015 #include <animal/X3DTK/Qt/viewer/viewer.h>
00016 #include <animal/picking.h>
00017 
00018 #include "MainControllerDesigner.h"
00019 
00021 typedef std::map<X3DTK::X3DAbstractNode *, QWidget * > X3DQtMap;
00022 
00023 class QDockWindow;
00024 
00028 class MainController : public MainControllerDesigner
00029 {
00030       Q_OBJECT        // must include this if you use Qt signals/slots
00031 
00032 public:
00034   MainController(X3DTK::MainScene * mainScene, bool dw );
00035   
00037   //~MainController();
00038   
00040   
00041   //----------- Getters ------------
00042   X3DTK::Qt::Viewer * getViewer()
00043     { return viewer; }
00044   X3DTK::MainScene * getMainScene()
00045     { return mainScene;}
00046   X3DTK::Qt::X3DTreeQt * getX3DTreeQt()
00047     { return x3dtreeqt; }
00048   //----------- Setters ------------
00049   void setViewer(X3DTK::Qt::Viewer * v);
00050   void addEngine(animal::Engine *);
00051 
00052 public slots:
00053   //----------- Slots for the animation -------------
00054   virtual void doStep();
00055   virtual void startStop();
00056   virtual void reset();
00057   virtual void setAnimStep( int ms );
00058   virtual void setDisplayFreq( int hz );
00059   virtual void setRealTime( bool b );
00060   
00061   //----------- Slots for Input/Output ------------
00062   //virtual void createX3dLoader( X3DTK::X3D::EngineNodeCreator * creator );
00063   virtual void fileOpen();
00064   virtual void fileInsert( X3DTK::X3D::X3DNode * node );
00065   virtual void fileSave();
00066   virtual void fileReload();
00067   
00068   //----------- Slots for GUI --------------------
00069   virtual void toolBarSetShown(bool b);
00070   virtual void menuBarSetShown(bool b);
00071   virtual void clickedRecordButton();
00072   
00073   //----------- Slot for display -----------------
00074   void display();
00075   void computeBbox();
00076   void viewAll();
00077   
00078 public:
00079   void fileOpen(const char * filename);
00080   void activatedManipMode();
00081 
00082   //-----------Mouse and key board events-----------------------------------
00084   virtual void keyPressEvent(QKeyEvent *e);
00086   virtual void mouseDoubleClickEvent(QMouseEvent * e);
00088   virtual void mouseMoveEvent(QMouseEvent * e);
00090   virtual void mousePressEvent(QMouseEvent * e);
00092   virtual void mouseReleaseEvent(QMouseEvent * e);
00093   
00094   // ----------  FF: picking -----------------------------
00095   animal::ConstrainedItem* pickPoint( float origin[3], float direction[3],
00096 float threshold );
00097   // ----------  FF: picking -----------------------------
00098 
00099   //-----------Recording state-----------------------------------
00100   void toggleRecord(bool b);
00101   //void enableRecordButton(bool enable);
00102   
00103   //-----------X3DTK::X3D::X3DNode and their item-------------
00104   void addNode(X3DTK::X3D::X3DNode * node);
00105   
00106   //-----------X3DTK::X3D::X3DNode and their respective QWidget-------------
00108   inline X3DQtMap & getX3DQtMap()
00109   {
00110     return x3dQtMap;
00111   }
00112   
00114   void removeX3DQtMap(X3DTK::X3DAbstractNode* EN);
00115   
00117   QWidget * createQWidgetController(X3DTK::X3D::X3DNode * node);
00118   
00120   template<class X3DNode_t>
00121   inline void defineQWidgetCreationFunction(QWidget * (*createQWidget)(X3DNode_t *, QWidget *))
00122   {
00123     bool find = false;
00124     X3DNode_t * node = new X3DNode_t();
00125     X3DTK::SFString string = node->getTypeName();
00126     for( X3DNodeQWidgetMap::iterator i= x3dNodeQWidgetMap.begin(); i!=x3dNodeQWidgetMap.end(); ++i )
00127     {
00128       if((*i).first == string)
00129         find = true;
00130     }
00131 
00132     if (!find)
00133       x3dNodeQWidgetMap[string] = reinterpret_cast<QWidget * (*)(X3DTK::X3DAbstractNode *, QWidget *)>(createQWidget);
00134   }
00135   
00137 //   template<class Engine_t>
00138 //   inline QWidget * createQWidgetController(Engine_t * engine, QWidget * (*createQWidget)(Engine_t *, QWidget *))
00139 //   {
00140 //     // Create its corresponding widget
00141 //     // The dialog
00142 //     //QString s(typeid(* engine).name());
00143 //     QDialog * dialog = new QDialog(this);
00144 //     //dialog->reparent(this, Qt::WType_Dialog, QPoint(0,0));
00145 //     
00146 //     // Layout of the dialog
00147 //     QHBoxLayout * dialogLayout = new QHBoxLayout(dialog); 
00148 //     dialogLayout->setAutoAdd(true);
00149 // 
00150 //     // The scroll bar 
00151 //     QScrollView * sv = new QScrollView(dialog);
00152 //     sv->setResizePolicy(QScrollView::AutoOneFit);
00153 // 
00154 //     // Create the associated QWidget of the engine 
00155 //     QWidget * Q = createQWidget(engine, sv->viewport(), this);
00156 //     if (Q)
00157 //     {
00158 //       sv->addChild(Q);
00159 //       dialog->show();
00160 //       return dialog;
00161 //     }
00162 //    
00163 //     delete dialog;
00164 //     return NULL;
00165 //    
00166 //   }
00167     void setX3dDirectory(const std::string& d);
00168     std::string getX3dDirectory() const;
00169   
00170 private:
00172   QString openFile;
00173   
00175   X3DTK::MainScene * mainScene;
00176   
00178   QTimer * animTimer;
00180   QTime clock;
00182   bool realTime;
00184   double animStep;
00186   bool go;
00188   int displayStep;
00189  
00191   X3DQtMap x3dQtMap;
00192   
00194   typedef std::map<X3DTK::SFString, QWidget * (*)(X3DTK::X3DAbstractNode *, QWidget *)> X3DNodeQWidgetMap;
00196   X3DNodeQWidgetMap x3dNodeQWidgetMap;
00197   
00198 protected:
00199     std::string x3dDirectory;  
00200     QDockWindow  *w1, *w2;
00201     
00202 signals:
00203     void animationFrequency(int);  
00204 };
00205 
00206 #endif

Generated on Thu Dec 23 13:52:25 2004 by doxygen 1.3.6