SofaModeler.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  
00028 #ifndef SOFA_MODELER_H
00029 #define SOFA_MODELER_H
00030 
00031 
00032 #include "Modeler.h"
00033 #include "GraphModeler.h"
00034 #include <map>
00035 #include <vector>
00036 #include <string>
00037 #include <sofa/core/ObjectFactory.h>
00038 #include <sofa/helper/Factory.h>
00039 #include <sofa/simulation/tree/GNode.h>
00040 
00041 #include <sofa/gui/SofaGUI.h>
00042 #include <sofa/helper/system/glut.h>
00043 #include <sofa/gui/qt/RealGUI.h>
00044 
00045 #ifdef SOFA_QT4
00046 #include <Q3ListView>
00047 #include <Q3TextDrag>
00048 #include <QPushButton>
00049 #include <QTabWidget>
00050 #include <QTabBar>
00051 #include <Q3PopupMenu>
00052 #else
00053 #include <qlistview.h>
00054 #include <qdragobject.h>
00055 #include <qpushbutton.h>
00056 #include <qtabwidget.h>
00057 #include <qtabbar.h>
00058 #include <qpopupmenu.h>
00059 #endif
00060 
00061 
00062 namespace sofa
00063 {
00064 
00065   namespace gui
00066   {
00067 
00068     namespace qt
00069     {
00070       
00071 #ifndef SOFA_QT4
00072       typedef QListView Q3ListView;
00073       typedef QPopupMenu Q3PopupMenu;
00074 #endif
00075 
00076       typedef sofa::core::ObjectFactory::ClassEntry ClassInfo;
00077       typedef sofa::core::ObjectFactory::Creator    ClassCreator;
00078 
00079       using sofa::simulation::tree::GNode;
00080 
00081 
00082       class SofaModeler : public ::Modeler
00083     {
00084 
00085       Q_OBJECT
00086         public :
00087 
00088       SofaModeler();
00089       ~SofaModeler(){};
00090 
00091     signals:
00092       void loadPresetGraph(std::string);
00093 
00094 
00095     public:
00096 
00098       void createTab();
00099 
00100 
00101       public slots:
00102       void releaseButton();
00103 
00104       void changeComponent(ClassInfo *currentComponent); 
00105 #ifdef SOFA_QT4
00106       void changeInformation(Q3ListViewItem *);
00107 #else
00108       void changeInformation(QListViewItem *);
00109 #endif
00110 
00112       void newGNode();
00113       void newComponent();    
00115       void fileNew(){fileNew(NULL);};
00116       void fileNew(GNode* root);
00117  
00119       void fileOpen();   
00120       void fileOpen(std::string filename);    
00121       void fileOpen(const QString &filename){fileOpen(std::string(filename.ascii()));}
00122 
00124       void fileSave();
00125       void fileSave(std::string filename);
00126       void fileSaveAs();
00127 
00129       void clearTab();
00131       void closeTab();
00133       void newTab();
00134 
00136       void fileExit(){close();};
00137       
00139       void runInSofa();
00140 
00142       void changeCurrentScene( QWidget*);
00144       void changeCurrentScene( int n);
00146       void changeNameWindow(std::string filename);
00147 
00149       void editUndo(){graph->editUndo();}
00151       void editRedo(){graph->editRedo();}
00152 
00154       void loadPreset(int);
00155 
00157       ClassInfo* getInfoFromName(std::string name);
00158 
00159 
00160       void dragEnterEvent( QDragEnterEvent* event)
00161       {
00162         QString text;
00163         Q3TextDrag::decode(event, text);
00164         std::string filename(text.ascii());
00165         std::string test = filename; test.resize(4);
00166         if (test == "file")  event->accept();
00167         else             event->ignore();
00168       }
00169 
00170       void dragMoveEvent( QDragMoveEvent* event)
00171       {   
00172 
00173         QString text;
00174         Q3TextDrag::decode(event, text);
00175         std::string filename(text.ascii());
00176         std::string test = filename; test.resize(4);
00177         if (test == "file")  event->accept();
00178         else             event->ignore();
00179       }
00180 
00181       void dropEvent(QDropEvent* event);
00182       void keyPressEvent ( QKeyEvent * e );
00183      
00185       void fileRecentlyOpened(int id);
00187       void updateRecentlyOpened(std::string fileLoaded);
00188       
00189     protected:
00191       QTabWidget *sceneTab; 
00193       GraphModeler *graph; //currentGraph in Use
00195       QWidget *tabGraph;
00197       //Q3PopupMenu *recentlyOpened;
00199       Q3PopupMenu *preset;
00200       Q3PopupMenu *windowMenu;
00202       std::map< std::string, std::string > mapPreset;
00203 
00204       
00205       std::map<  const QObject* , std::pair<ClassInfo*, QObject*> > mapComponents; 
00206       std::map<  const QWidget*, GraphModeler*> mapGraph;
00207       std::map<  const QWidget*, sofa::gui::qt::RealGUI*> mapSofa;
00208       std::map< int, QWidget*> mapWindow;
00209 
00210     private:
00211       std::string presetPath;
00212       std::string examplePath;
00213       char count;
00214     };
00215     }
00216   }
00217 }
00218 #endif

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