00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef SOFA_GRAPHMODELER_H
00028 #define SOFA_GRAPHMODELER_H
00029
00030 #include <deque>
00031
00032 #include "AddPreset.h"
00033
00034 #include <sofa/simulation/tree/GNode.h>
00035 #include <sofa/core/ObjectFactory.h>
00036 #include <sofa/core/objectmodel/BaseObject.h>
00037
00038 #ifdef SOFA_QT4
00039 #include <Q3ListView>
00040 #include <Q3ListViewItem>
00041 #include <Q3TextDrag>
00042 #else
00043 #include <qlistview.h>
00044 #include <qdragobject.h>
00045 #endif
00046 #include <sofa/gui/qt/GraphListenerQListView.h>
00047 #include <sofa/gui/qt/ModifyObject.h>
00048 #include <sofa/simulation/tree/xml/NodeElement.h>
00049 #include <sofa/simulation/tree/xml/ObjectElement.h>
00050
00051 #include <iostream>
00052
00053 namespace sofa
00054 {
00055
00056 namespace gui
00057 {
00058
00059 namespace qt
00060 {
00061
00062 #ifndef SOFA_QT4
00063 typedef QListView Q3ListView;
00064 typedef QListViewItem Q3ListViewItem;
00065 typedef QTextDrag Q3TextDrag;
00066 #endif
00067
00068 typedef sofa::core::ObjectFactory::ClassEntry ClassInfo;
00069 typedef sofa::core::ObjectFactory::Creator ClassCreator;
00070 using sofa::simulation::tree::GNode;
00071 using namespace sofa::core::objectmodel;
00072 using namespace sofa::simulation::tree;
00073
00074 class GraphModeler : public Q3ListView
00075 {
00076
00077 typedef std::map< const QObject* , std::pair< ClassInfo*, QObject*> > ComponentMap;
00078
00079 Q_OBJECT
00080 public:
00081 GraphModeler( QWidget* parent=0, const char* name=0, Qt::WFlags f = 0 ):Q3ListView(parent, name, f), graphListener(NULL)
00082 {
00083 graphListener = new GraphListenerQListView(this);
00084 addColumn("Graph");
00085 header()->hide();
00086 setSorting ( -1 );
00087
00088 #ifdef SOFA_QT4
00089 connect(this, SIGNAL(doubleClicked ( Q3ListViewItem *, const QPoint &, int )), this, SLOT( doubleClick(Q3ListViewItem *)));
00090 connect(this, SIGNAL(rightButtonClicked ( Q3ListViewItem *, const QPoint &, int )), this, SLOT( rightClick(Q3ListViewItem *, const QPoint &, int )));
00091 #else
00092 connect(this, SIGNAL(doubleClicked ( QListViewItem *, const QPoint &, int )), this, SLOT( doubleClick(QListViewItem *)));
00093 connect(this, SIGNAL(rightButtonClicked ( QListViewItem *, const QPoint &, int )), this, SLOT( rightClick(QListViewItem *, const QPoint &, int )));
00094 #endif
00095 DialogAdd=NULL;
00096 };
00097
00098 ~GraphModeler()
00099 {
00100 getSimulation()->unload(getRoot());
00101
00102 delete graphListener;
00103 if (DialogAdd) delete DialogAdd;
00104 }
00105
00106 void clearGraph();
00107 void setFilename(std::string filename){filenameXML = filename;}
00108 std::string getFilename(){return filenameXML;}
00109
00110 void dragEnterEvent( QDragEnterEvent* event)
00111 {
00112 QString text;
00113 Q3TextDrag::decode(event, text);
00114 std::string filename(text.ascii());
00115 std::string test = filename; test.resize(4);
00116 if (test == "file") {event->accept(event->answerRect());}
00117 else event->accept();
00118 }
00119 void dragMoveEvent( QDragMoveEvent* event)
00120 {
00121 QString text;
00122 Q3TextDrag::decode(event, text);
00123 std::string filename(text.ascii());
00124 std::string test = filename; test.resize(4);
00125 if (test == "file") {event->accept(event->answerRect());}
00126 else
00127 {
00128 if ( getGNode(event->pos()))
00129 event->accept(event->answerRect());
00130 else
00131 event->ignore(event->answerRect());
00132 }
00133 }
00134
00135 void dropEvent(QDropEvent* event);
00136
00137 void setLibrary(ComponentMap &s){library=s;}
00138 void setPreset(Q3PopupMenu *_preset){preset=_preset;}
00139
00140 GNode *getGNode(const QPoint &pos);
00141 GNode *getGNode(Q3ListViewItem *item);
00142 GNode *getRoot(){return getGNode(firstChild());}
00143 BaseObject *getObject(Q3ListViewItem *item);
00144
00145 void keyPressEvent ( QKeyEvent * e );
00146
00147 signals:
00148 void fileOpen(std::string);
00149 void closeDialog();
00150
00151 public slots:
00152 void collapseNode();
00153 void collapseNode(Q3ListViewItem* item);
00154 void expandNode();
00155 void expandNode(Q3ListViewItem* item);
00156 GNode *loadNode();
00157 GNode *loadNode(Q3ListViewItem* item, std::string filename="");
00158 void loadPreset(std::string presetName);
00159 void loadPreset(GNode*,std::string,std::string*, std::string*,std::string*,std::string);
00160 void saveNode();
00161 void saveNode(Q3ListViewItem* item);
00162 void openModifyObject();
00163 void openModifyObject(Q3ListViewItem *);
00164 #ifdef SOFA_QT4
00165 void doubleClick(Q3ListViewItem *);
00166 void rightClick(Q3ListViewItem *, const QPoint &, int );
00167 #else
00168 void doubleClick(QListViewItem *);
00169 void rightClick(QListViewItem *, const QPoint &, int );
00170 #endif
00171 GNode *addGNode(GNode *parent, GNode *node=NULL, bool saveHistory=true);
00172 BaseObject *addComponent(GNode *parent, ClassInfo *entry, std::string templateName, bool saveHistory=true );
00173 void deleteComponent();
00174 void deleteComponent(Q3ListViewItem *item, bool saveHistory=true);
00175
00176 void closeGraph()
00177 {
00178 emit(closeDialog());
00179 }
00180 void modifyUnlock ( void *Id );
00181
00182
00183 void editUndo();
00184 void editRedo();
00185
00186 void closeDialogs()
00187 {
00188 std::map< void*, QDialog* >::iterator it; ;
00189 for (it=map_modifyObjectWindow.begin();
00190 it!=map_modifyObjectWindow.end();
00191 it++)
00192 {
00193 delete it->second;
00194 }
00195
00196 }
00197 protected:
00198
00199 bool isNodeErasable ( core::objectmodel::Base* element );
00200 bool isObjectErasable ( core::objectmodel::Base* element );
00201 void updatePresetNode(xml::BaseElement &elem, std::string meshFile, std::string *translation, std::string *rotation, std::string scale);
00202
00203 class Operation
00204 {
00205 public:
00206 Operation(){};
00207 enum op{DELETE_OBJECT, ADD_OBJECT};
00208 Operation(Q3ListViewItem* item_,Base* sofaComponent_, op ID_):
00209 item(item_),sofaComponent(sofaComponent_), ID(ID_)
00210 {}
00211 Q3ListViewItem* item;
00212 Base* sofaComponent;
00213 op ID;
00214 };
00215
00216
00217 GraphListenerQListView *graphListener;
00218 ComponentMap library;
00219 Q3PopupMenu *preset;
00220 AddPreset *DialogAdd;
00221
00222
00223 void *current_Id_modifyDialog;
00224 std::map< void*, Base* > map_modifyDialogOpened;
00225 std::map< void*, QDialog* > map_modifyObjectWindow;
00226
00227 std::string filenameXML;
00228 std::deque< Operation > historyOperation;
00229 std::deque< Operation >::iterator currentStateHistory;
00230
00231 };
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 class ModifyObjectModeler: public ModifyObject
00247 {
00248 public:
00249 ModifyObjectModeler( void *Id_, core::objectmodel::Base* node_clicked, Q3ListViewItem* item_clicked, QWidget* parent_, const char* name= 0 )
00250 {
00251 parent = parent_;
00252 node = NULL;
00253 Id = Id_;
00254 visualContentModified=false;
00255 setCaption(name);
00256 HIDE_FLAG = false;
00257 EMPTY_FLAG = true;
00258 RESIZABLE_FLAG = true;
00259 REINIT_FLAG = false;
00260
00261 energy_curve[0]=NULL; energy_curve[1]=NULL; energy_curve[2]=NULL;
00262
00263 setNode(node_clicked, item_clicked);
00264 connect ( this, SIGNAL( dialogClosed(void *) ) , parent_, SLOT( modifyUnlock(void *)));
00265 }
00266
00267 };
00268
00269 }
00270 }
00271 }
00272
00273 #endif