RealGUI.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This program is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU General Public License as published by the Free  *
00007 * Software Foundation; either version 2 of the License, or (at your option)   *
00008 * any later version.                                                          *
00009 *                                                                             *
00010 * This program is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    *
00013 * more details.                                                               *
00014 *                                                                             *
00015 * You should have received a copy of the GNU General Public License along     *
00016 * with this program; if not, write to the Free Software Foundation, Inc., 51  *
00017 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.                   *
00018 *******************************************************************************
00019 *                            SOFA :: Applications                             *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #ifndef SOFA_GUI_VIEWER_REALGUI_H
00028 #define SOFA_GUI_VIEWER_REALGUI_H
00029 
00030 #ifdef SOFA_PML
00031 #  include <sofa/filemanager/sofapml/PMLReader.h>
00032 #  include <sofa/filemanager/sofapml/LMLReader.h>
00033 #endif
00034 
00035 #include <time.h>
00036  
00037 
00038 #include <sofa/gui/SofaGUI.h>
00039 
00040 #include "GUI.h"
00041 #include <sofa/gui/qt/GraphListenerQListView.h>
00042 #include <sofa/gui/qt/FileManagement.h>
00043 #include <sofa/gui/qt/viewer/SofaViewer.h>
00044 #include <sofa/gui/qt/AddObject.h>
00045 #include <sofa/gui/qt/ModifyObject.h>
00046 #include <sofa/gui/qt/DisplayFlagWidget.h>
00047 
00048 #include <sofa/simulation/tree/xml/XML.h>
00049 #include <sofa/helper/system/SetDirectory.h>
00050 
00051 
00052 #ifdef SOFA_QT4
00053 #include <QApplication>
00054 #include <QDesktopWidget>
00055 #include <Q3ListViewItem>
00056 #include <QStackedWidget>
00057 #include <QSlider>
00058 #include <QTimer>
00059 #include <Q3TextDrag>
00060 #include <Q3PopupMenu>
00061 typedef Q3ListViewItem QListViewItem;
00062 typedef QStackedWidget QWidgetStack;
00063 typedef Q3PopupMenu QPopupMenu;
00064 #else
00065 typedef QTextDrag Q3TextDrag;
00066 #include <qapplication.h>
00067 #include <qdesktopwidget.h>
00068 #include <qdragobject.h>
00069 #include <qwidgetstack.h>
00070 #include <qlistview.h>
00071 #include <qslider.h>
00072 #include <qpopupmenu.h>
00073 #endif 
00074  
00075 
00076 namespace sofa
00077 {
00078 
00079 namespace gui
00080 {
00081 
00082 namespace qt
00083 {
00084 
00085 //enum TYPE{ NORMAL, PML, LML};  
00086 enum SCRIPT_TYPE { PHP, PERL };
00087 
00088 using sofa::simulation::tree::GNode;
00089 using sofa::simulation::Node;
00090 #ifdef SOFA_PML
00091 using namespace sofa::filemanager::pml;
00092 #endif
00093 
00094 
00095 class RealGUI : public ::GUI, public SofaGUI
00096 {
00097     Q_OBJECT
00098 
00101 
00102 
00103 public:
00104 
00105     static int InitGUI(const char* name, const std::vector<std::string>& options);
00106     static SofaGUI* CreateGUI(const char* name, const std::vector<std::string>& options, sofa::simulation::Node* groot = NULL, const char* filename = NULL);
00107 
00108     int mainLoop();
00109 
00110     int closeGUI();
00111 
00112     Node* currentSimulation();
00113 
00115 
00116     const char* viewerName;
00117 
00118     sofa::gui::qt::viewer::SofaViewer* viewer;
00119 
00120       RealGUI( const char* viewername, const std::vector<std::string>& options = std::vector<std::string>() );
00121       ~RealGUI();
00122 
00123 
00124       virtual void fileOpen(std::string filename); //, int TYPE=NORMAL);
00125           virtual void fileOpenSimu(std::string filename); //, int TYPE=NORMAL);
00126       virtual void setScene(Node* groot, const char* filename=NULL);
00127       virtual void setTitle( std::string windowTitle );
00128 
00129       //public slots:
00130       virtual void fileNew();
00131       virtual void fileOpen();
00132       virtual void fileSave(); 
00133       virtual void fileSaveAs(){fileSaveAs((Node *)NULL);};
00134       virtual void fileSaveAs(Node *node);   
00135       virtual void fileSaveAs(Node* node,const char* filename);
00136       
00137       virtual void fileReload();
00138       virtual void fileExit();
00139       virtual void saveXML();
00140       virtual void viewerOpenGL();
00141       virtual void viewerQGLViewer();
00142       virtual void viewerOGRE();
00143       
00144       virtual void editRecordDirectory();
00145       virtual void editGnuplotDirectory();
00146 
00147       void dragEnterEvent( QDragEnterEvent* event){event->accept();}
00148       void dropEvent(QDropEvent* event);
00149 
00150       public slots:
00151       void fileRecentlyOpened(int id);
00152       void updateRecentlyOpened(std::string fileLoaded);
00153       void DoubleClickeItemInSceneView(QListViewItem * item);
00154       void RightClickedItemInSceneView(QListViewItem *item, const QPoint& point, int index);
00155       void playpauseGUI(bool value);
00156       void step();
00157       void animate();
00158       void setDt(double);
00159       void setDt(const QString&);
00160       void resetScene();
00161       void screenshot();
00162 
00163       void showhideElements(int FILTER, bool value);
00164 
00165       void clearRecord();
00166       void slot_recordSimulation( bool);
00167       void slot_backward( );
00168       void slot_stepbackward( );
00169 //    void slot_playbackward(  );
00170       void slot_playforward(  ) ;
00171       void slot_stepforward( ) ;
00172       void slot_forward( );
00173       void slot_sliderValue(int);
00174       void slot_loadrecord_timevalue();
00175 
00176 
00177 
00178       void changeInstrument(int);
00179   
00180       void clearGraph();
00181       //Used in Context Menu
00182       void graphSaveObject();
00183       void graphAddObject();
00184       void graphRemoveObject();
00185       void graphModify();
00186       void graphCollapse();
00187       void graphExpand();
00188       void graphDesactivateNode();
00189       void graphActivateNode();
00190       //When adding an object in the graph
00191       void loadObject(std::string path, double dx, double dy, double dz,double rx, double ry, double rz, double scale=1.0);
00192       //refresh the visualization window     
00193       void redraw();
00194       //when a dialog modify object is closed
00195       void modifyUnlock(void *Id);
00196       void transformObject( Node *node, double dx, double dy, double dz, double rx, double ry, double rz, double scale=1.0);
00197       
00198 
00199       void exportGraph();
00200       void exportGraph(sofa::simulation::tree::GNode*);
00201       void exportOBJ(bool exportMTL=true);
00202       void dumpState(bool);
00203       void displayComputationTime(bool);
00204       void setExportGnuplot(bool);
00205       void currentTabChanged(QWidget*);
00206 
00207     signals:
00208       void reload();
00209       void newScene();
00210       void newStep();     
00211       void quit();
00212 
00213     protected:
00214       
00215       void eventNewStep();
00216       void eventNewTime();
00217       void init();
00218       void keyPressEvent ( QKeyEvent * e );
00219       
00220       void loadSimulation(bool one_step=false);
00221 
00222       void initDesactivatedNode();
00223       //Graph Stats
00224       bool graphCreateStats(Node *groot);     
00225       void graphAddCollisionModelsStat(sofa::helper::vector< sofa::core::CollisionModel* > &v);   
00226       void graphSummary();
00227          
00228       bool isErasable(core::objectmodel::Base* element);
00229 
00230       bool m_dumpState;
00231       std::ofstream* m_dumpStateStream;
00232       bool m_exportGnuplot;
00233       bool _animationOBJ; int _animationOBJcounter;// save a succession of .obj indexed by _animationOBJcounter
00234       bool m_displayComputationTime;
00235 
00236 
00237       QWidget* currentTab;
00238       QWidget *tabInstrument;
00239       
00240       GraphListenerQListView* graphListener;
00241       QListViewItem *item_clicked;
00242       GNode *node_clicked;
00243       QTimer* timerStep;
00244       QTimer* timerRecordStep;
00245       QLabel* fpsLabel;
00246       QLabel* timeLabel;
00247       
00248       void setPixmap(std::string pixmap_filename, QPushButton* b);
00249 
00250        double getRecordInitialTime() const; 
00251        void   setRecordInitialTime(const double time);
00252        double getRecordFinalTime  () const;  
00253        void   setRecordFinalTime  (const double time);   
00254        double getRecordTime       () const;  
00255        void   setRecordTime       (const double time);
00256        void   setTimeSimulation   (const double time);
00257       
00258       QPushButton* record;
00259       QPushButton* backward_record;
00260       QPushButton* stepbackward_record;
00261 //    QPushButton* playbackward_record;
00262       QPushButton* playforward_record;
00263       QPushButton* stepforward_record;
00264       QPushButton* forward_record;
00265       
00266       QLineEdit* loadRecordTime;
00267       QLabel* initialTime;
00268       QLabel* finalTime;
00269       QSlider* timeSlider;
00270       
00271       std::string simulation_name;
00272       std::string record_directory;
00273       std::string gnuplot_directory;
00274       std::string writeSceneName;
00275           
00276       QWidgetStack* left_stack;
00277       AddObject *dialog;
00278 
00279 
00280 
00281       sofa::simulation::tree::GNode* getScene() { if (viewer) return viewer->getScene(); else return NULL; }
00282 
00283       void sleep(unsigned int mseconds, unsigned int init_time)
00284       {
00285         unsigned int t = 0;
00286        clock_t goal = mseconds + init_time;
00287        while (goal > clock()) t++;
00288       }
00289       
00290     private:
00291       //Map: Id -> Node currently modified. Used to avoid dependancies during removing actions
00292       std::map< void*, core::objectmodel::Base* >            map_modifyDialogOpened;
00293       
00294       std::map< void*, QDialog* >                       map_modifyObjectWindow;
00295       std::vector<std::pair<core::objectmodel::Base*, Q3ListViewItem*> > items_stats;
00296       //unique ID to pass to a modify object dialog
00297       void *current_Id_modifyDialog;
00298 
00299  
00300       //currently unused: scale is experimental
00301       float object_Scale[2]; 
00302 
00303       float initial_time;
00304       int frameCounter;
00305       //At initialization: list of the path to the basic objects you can add to the scene
00306       std::vector< std::string > list_object;
00307       std::list< GNode *> list_object_added;
00308       std::list< GNode *> list_object_removed;
00309       std::list< GNode *> list_object_initial;
00310       bool record_simulation;
00311 
00312       bool setViewer(const char* name);
00313       void addViewer();   
00314       void setGUI(void);
00315       
00316       bool setWriteSceneName();
00317       void addReadState(bool init);
00318       void addWriteState();
00319       
00320 #ifdef SOFA_PML
00321       virtual void pmlOpen(const char* filename, bool resetView=true);
00322       virtual void lmlOpen(const char* filename);
00323       PMLReader *pmlreader;
00324       LMLReader *lmlreader;
00325 #endif
00326 
00327       DisplayFlagWidget *displayFlag;
00328 
00329 };
00330 
00331 } // namespace qt
00332 
00333 } // namespace gui
00334 
00335 } // namespace sofa
00336 
00337 #endif // SOFA_GUI_VIEWER_REALGUI_H

Generated on Sun Nov 23 02:28:36 2008 for Sofa by  doxygen 1.5.7.1