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 #include "SofaModeler.h"
00028 #include <sofa/helper/system/FileRepository.h>
00029 #include <sofa/helper/system/SetDirectory.h>
00030
00031
00032
00033
00034 #include <map>
00035 #include <set>
00036 #include <cctype>
00037
00038
00039
00040
00041 #ifdef SOFA_QT4
00042 #include <QToolBox>
00043 #include <QSpacerItem>
00044 #include <QGridLayout>
00045 #include <QTextEdit>
00046 #include <Q3TextBrowser>
00047 #include <QComboBox>
00048 #include <QLabel>
00049 #include <QApplication>
00050 #include <QMenuBar>
00051 #else
00052 #include <qtoolbox.h>
00053 #include <qlayout.h>
00054 #include <qtextedit.h>
00055 #include <qtextbrowser.h>
00056 #include <qcombobox.h>
00057 #include <qapplication.h>
00058 #include <qmenubar.h>
00059 #endif
00060
00061 namespace sofa
00062 {
00063
00064 namespace gui
00065 {
00066
00067 namespace qt
00068 {
00069
00070 #ifndef SOFA_QT4
00071 typedef QTextDrag Q3TextDrag;
00072 #endif
00073
00074
00075 SofaModeler::SofaModeler()
00076 {
00077 count='0';
00078 QWidget *GraphSupport = new QWidget((QWidget*)splitter2);
00079 QGridLayout* GraphLayout = new QGridLayout(GraphSupport, 1,1,5,2,"GraphLayout");
00080
00081
00082 #ifdef SOFA_QT4
00083 fileMenu->removeAction(Action);
00084 #endif
00085 connect(GNodeButton, SIGNAL(pressed()), this, SLOT( releaseButton()));
00086
00087
00088 preset = new Q3PopupMenu(this);
00089 this->menubar->insertItem(tr(QString("&Preset")), preset, 4);
00090 windowMenu = new Q3PopupMenu(this);
00091 this->menubar->insertItem(tr(QString("&Scenes")), windowMenu, 5);
00092
00093 connect(windowMenu, SIGNAL(activated(int)), this, SLOT( changeCurrentScene(int)));
00094
00095 examplePath = sofa::helper::system::SetDirectory::GetParentDir(sofa::helper::system::DataRepository.getFirstPath().c_str()) + std::string( "/examples/" );
00096 presetPath = sofa::helper::system::SetDirectory::GetParentDir(sofa::helper::system::DataRepository.getFirstPath().c_str()) + std::string( "/applications/projects/Modeler/preset/" );
00097 std::string presetFile = presetPath + std::string("preset.ini" );
00098
00099 presetFile = sofa::helper::system::DataRepository.getFile ( presetFile );
00100
00101
00102 std::multimap< std::string, std::pair< std::string,std::string> > presetArchitecture;
00103
00104
00105 std::ifstream end(presetFile.c_str());
00106 std::string s;
00107
00108
00109 std::string directory, namePreset, nameFile;
00110 while( std::getline(end,s) )
00111 {
00112
00113 std::string::size_type slash = s.find('/');
00114 if (slash != std::string::npos)
00115 {
00116 directory = s; directory.resize(slash);
00117 s=s.substr(slash+1);
00118
00119 slash = s.find('/');
00120 if (slash != std::string::npos)
00121 {
00122 namePreset=s; namePreset.resize(slash);
00123 nameFile = s.substr(slash+1);
00124
00125 presetArchitecture.insert(std::make_pair( directory, std::make_pair( namePreset, nameFile) ) );
00126 }
00127
00128 }
00129 }
00130 end.close();
00131
00132 std::multimap< std::string, std::pair< std::string,std::string> >::iterator it_preset = presetArchitecture.begin();
00133 while(it_preset != presetArchitecture.end())
00134 {
00135 std::string directoryName = it_preset->first;
00136 Q3PopupMenu* directory = new Q3PopupMenu(this);
00137 connect( directory, SIGNAL(activated(int)), this, SLOT(loadPreset(int)));
00138 preset->insertItem(QIconSet(), tr( it_preset->first.c_str()), directory);
00139 for (unsigned int i=0;i<presetArchitecture.count(directoryName);i++,it_preset++)
00140 {
00141 directory->insertItem(it_preset->second.first.c_str());
00142 mapPreset.insert(it_preset->second);
00143 }
00144 }
00145
00146
00147
00148 std::set< std::string > setType;
00149 std::multimap< std::string, ClassInfo* > inventory;
00150 std::vector< ClassInfo* > entries;
00151 sofa::core::ObjectFactory::getInstance()->getAllEntries(entries);
00152 for (unsigned int i=0;i<entries.size();++i)
00153 {
00154 #ifdef TEST_CREATION_COMPONENT
00155 sofa::core::objectmodel::BaseObject *object;
00156 if (entries[i]->creatorMap.find(entries[i]->defaultTemplate) != entries[i]->creatorMap.end())
00157 {
00158 object = entries[i]->creatorMap.find(entries[i]->defaultTemplate)->second->createInstance(NULL, NULL);
00159 }
00160 else
00161 {
00162 object = entries[i]->creatorList.begin()->second->createInstance(NULL, NULL);
00163 }
00164 delete object;
00165 #endif
00166 std::set< std::string >::iterator it;
00167 for (it = entries[i]->baseClasses.begin(); it!= entries[i]->baseClasses.end();it++)
00168 {
00169 setType.insert((*it));
00170 inventory.insert(std::make_pair((*it), entries[i]));
00171 }
00172 if (entries[i]->baseClasses.size() == 0)
00173 {
00174 setType.insert("_Undefined_");
00175 inventory.insert(std::make_pair("_Undefined_", entries[i]));
00176 }
00177
00178 }
00179
00180 std::set< std::string >::iterator it;
00181 std::multimap< std::string,ClassInfo* >::iterator itMap;
00182
00183 for (it = setType.begin(); it != setType.end();it++)
00184 {
00185 itMap = inventory.find( (*it) );
00186 unsigned int numRows = inventory.count( (*it) );
00187 QString s=QString(it->c_str()) + QString("Widget");
00188 QWidget* gridWidget = new QWidget(SofaComponents, s);
00189 QGridLayout* gridLayout = new QGridLayout( gridWidget, numRows+1,1);
00190 gridLayout->addItem(new QSpacerItem(1,1,QSizePolicy::Minimum, QSizePolicy::Expanding ), 0,0);
00191
00192
00193 SofaComponents->addItem( gridWidget ,it->c_str() );
00194 unsigned int counterElem=1;
00195 for (unsigned int i=0;i< inventory.count( (*it) ); ++i)
00196 {
00197 ClassInfo* entry = itMap->second;
00198
00199 if ( *it == "ForceField")
00200 {
00201 std::set< std::string >::iterator baseClassIt;
00202 bool isMass=false;
00203 for (baseClassIt = entry->baseClasses.begin(); baseClassIt!= entry->baseClasses.end() && !isMass;baseClassIt++)
00204 {
00205 isMass= (*baseClassIt == "Mass");
00206 }
00207 if (isMass) { itMap++;continue;}
00208 }
00209
00210
00211 if ( *it == "Topology")
00212 {
00213 std::set< std::string >::iterator baseClassIt;
00214 bool isMass=false;
00215 for (baseClassIt = entry->baseClasses.begin(); baseClassIt!= entry->baseClasses.end() && !isMass;baseClassIt++)
00216 {
00217 isMass= (*baseClassIt == "TopologyObject");
00218 }
00219 if (isMass) { itMap++;continue;}
00220 }
00221
00222
00223
00224 QPushButton *button = new QPushButton(gridWidget, QString(entry->className.c_str()));
00225 connect(button, SIGNAL(pressed()), this, SLOT( newComponent()));
00226 connect(button, SIGNAL(pressed()), this, SLOT( releaseButton()));
00227 gridLayout->addWidget(button, counterElem,0);
00228 button->setFlat(false);
00229
00230
00231 std::vector< std::string > templateCombo;
00232 {
00233 std::list< std::pair< std::string, ClassCreator*> >::iterator itTemplate;
00234 for (itTemplate=entry->creatorList.begin(); itTemplate!= entry->creatorList.end();itTemplate++)
00235 {
00236 if (*it == "Mapping")
00237 {
00238 std::string mechanical = itTemplate->first;
00239 mechanical.resize(10+7);
00240 if (mechanical == "MechanicalMapping") continue;
00241 }
00242 else if ( *it == "MechanicalMapping")
00243 {
00244 std::string nonmechanical = itTemplate->first;
00245 nonmechanical.resize(7);
00246 if (nonmechanical == "Mapping") continue;
00247 }
00248 templateCombo.push_back(itTemplate->first);
00249 }
00250 }
00251
00252
00253
00254 QComboBox *combo=NULL;
00255 if ( entry->creatorList.size() > 1 )
00256 {
00257 combo = new QComboBox(gridWidget);
00258
00259 for (unsigned int t=0;t<templateCombo.size();++t)
00260 combo->insertItem(QString(templateCombo[t].c_str()));
00261 if (templateCombo.size() == 1)
00262 {
00263 combo->hide();
00264 gridLayout->addWidget(new QLabel(QString(templateCombo[0].c_str()), gridWidget), counterElem, 1);
00265 }
00266 else
00267 {
00268 gridLayout->addWidget(combo, counterElem,1);
00269 if (templateCombo.size() == 0){combo->hide(); button->hide(); counterElem--;}
00270 }
00271
00272 }
00273 else
00274 {
00275 if (!entry->creatorList.begin()->first.empty())
00276 {
00277 QLabel *templateDescription = new QLabel(QString(entry->creatorList.begin()->first.c_str()), gridWidget);
00278 gridLayout->addWidget(templateDescription, counterElem,1);
00279 }
00280 }
00281 button->setText(QString(entry->className.c_str()));
00282
00283 mapComponents.insert(std::make_pair(button, std::make_pair(entry, combo)));
00284 itMap++;
00285
00286
00287 counterElem++;
00288 }
00289 }
00290
00291 connect( this->infoItem, SIGNAL(linkClicked( const QString &)), this, SLOT(fileOpen(const QString &)));
00292
00293 connect( recentlyOpened, SIGNAL(activated(int)), this, SLOT(fileRecentlyOpened(int)));
00294
00295 sceneTab = new QTabWidget(GraphSupport);
00296 GraphLayout->addWidget(sceneTab,0,0);
00297 connect( sceneTab, SIGNAL(currentChanged( QWidget*)), this, SLOT( changeCurrentScene( QWidget*)));
00298
00299
00300
00301 std::string scenes ( "config/Modeler.ini" );
00302 if ( !sofa::helper::system::DataRepository.findFile ( scenes ) )
00303 {
00304 std::string fileToBeCreated = sofa::helper::system::DataRepository.getFirstPath() + "/" + scenes;
00305
00306 std::ofstream ofile(fileToBeCreated.c_str());
00307 ofile << "";
00308 ofile.close();
00309 }
00310
00311 scenes = sofa::helper::system::DataRepository.getFile ( scenes );
00312
00313 updateRecentlyOpened("");
00314
00315 const QRect screen = QApplication::desktop()->availableGeometry(QApplication::desktop()->primaryScreen());
00316 this->move( ( screen.width()- this->width() ) / 2, ( screen.height() - this->height()) / 2 );
00317 };
00318
00319
00320 void SofaModeler::fileNew( GNode* root)
00321 {
00322 if (!root) graph->setFilename("");
00323 changeNameWindow("");
00324
00325 GNode *current_root=graph->getRoot();
00326 if (current_root) graph->clearGraph();
00327
00328
00329 root = graph->addGNode(NULL, root);
00330 sceneTab->setCurrentPage( sceneTab->count()-1);
00331 }
00332
00333 void SofaModeler::fileOpen()
00334 {
00335 QString s = getOpenFileName ( this, QString(examplePath.c_str()),"Scenes (*.scn *.xml *.simu *.pscn)", "open file dialog", "Choose a file to open" );
00336 if (s.length() >0)
00337 {
00338 fileOpen(s);
00339 examplePath = sofa::helper::system::SetDirectory::GetParentDir(s.ascii());
00340 }
00341 }
00342
00343 void SofaModeler::clearTab()
00344 {
00345 fileNew();
00346 }
00347
00348
00349 void SofaModeler::newTab()
00350 {
00351 std::string newScene="config/newScene.scn";
00352 if (sofa::helper::system::DataRepository.findFile(newScene))
00353 {
00354 newScene = sofa::helper::system::DataRepository.getFile ( newScene);
00355 fileOpen(newScene);
00356 graph->setFilename("");
00357 }
00358 else
00359 {
00360 createTab();
00361 }
00362 }
00363
00364 void SofaModeler::createTab()
00365 {
00366 QWidget *newtab = new QWidget();
00367 tabGraph = newtab;
00368 QVBoxLayout *currentTabLayout = new QVBoxLayout(newtab, 0,1, QString("ModelerScene"));
00369 sceneTab->addTab(newtab, QString("New Scene"));
00370 GraphModeler* modelerGraph = new GraphModeler(newtab,"Modeler");
00371 mapGraph.insert(std::make_pair(newtab, modelerGraph));
00372 mapGraph[newtab] = modelerGraph;
00373 graph = modelerGraph;
00374
00375 graph->setAcceptDrops(true);
00376 currentTabLayout->addWidget(graph,0,0);
00377
00378 graph->setLibrary(mapComponents);
00379 graph->setPreset(preset);
00380 fileNew();
00381
00382 #ifdef SOFA_QT4
00383 connect(graph, SIGNAL(currentChanged(Q3ListViewItem *)), this, SLOT(changeInformation(Q3ListViewItem *)));
00384 #else
00385 connect(graph, SIGNAL(currentChanged(QListViewItem *)), this, SLOT(changeInformation(QListViewItem *)));
00386 #endif
00387 connect(graph, SIGNAL( fileOpen(std::string)), this, SLOT(fileOpen(std::string)));
00388 }
00389
00390 void SofaModeler::closeTab()
00391 {
00392 if (sceneTab->count() == 0) return;
00393
00394 QWidget* curTab = tabGraph;
00395
00396 if (mapSofa.size() &&
00397 mapSofa.find(curTab) != mapSofa.end())
00398 {
00399 mapSofa[curTab]->fileExit();
00400 mapSofa .erase(curTab);
00401 }
00402
00403
00404 std::map< int, QWidget* >::const_iterator it;
00405 for (it = mapWindow.begin();it!=mapWindow.end();it++)
00406 {
00407 if (it->second == curTab) break;
00408 }
00409 windowMenu->removeItem(it->first);
00410 mapWindow.erase(it->first);
00411
00412
00413 GraphModeler *mod = graph;
00414 if (dynamic_cast< GraphModeler* >(mod))
00415 {
00416 mod->closeDialogs();
00417 mod->close();
00418 }
00419
00420
00421 sceneTab->removePage(curTab);
00422 mapGraph.erase(curTab);
00423 curTab->close();
00424
00425
00426 }
00427
00428 void SofaModeler::fileOpen(std::string filename)
00429 {
00430 createTab();
00431 GNode *root = NULL;
00432 xml::BaseElement* newXML=NULL;
00433 if (!filename.empty())
00434 {
00435 sofa::helper::system::SetDirectory chdir ( filename );
00436 newXML = xml::loadFromFile ( filename.c_str() );
00437 if (newXML == NULL) return;
00438 if (!newXML->init()) std::cerr<< "Objects initialization failed.\n";
00439 root = dynamic_cast<GNode*> ( newXML->getObject() );
00440 }
00441 fileNew(root);
00442 sceneTab->setCurrentPage( sceneTab->count()-1);
00443
00444 graph->setFilename(filename);
00445 sceneTab->setTabLabel(tabGraph, QString(sofa::helper::system::SetDirectory::GetFileName(filename.c_str()).c_str()));
00446 sceneTab->setTabToolTip(tabGraph, QString(filename.c_str()));
00447
00448 changeNameWindow(graph->getFilename());
00449
00450 mapWindow.insert(std::make_pair(windowMenu->insertItem( graph->getFilename().c_str()), tabGraph));
00451 }
00452
00453 void SofaModeler::fileRecentlyOpened(int id)
00454 {
00455 fileOpen(recentlyOpened->text(id));
00456 }
00457
00458 void SofaModeler::updateRecentlyOpened(std::string fileLoaded)
00459 {
00460
00461 #ifdef WIN32
00462 for (unsigned int i=0;i<fileLoaded.size();++i)
00463 {
00464 if (fileLoaded[i] == '\\') fileLoaded[i] = '/';
00465 }
00466 #endif
00467 std::string scenes ( "config/Modeler.ini" );
00468
00469 scenes = sofa::helper::system::DataRepository.getFile ( scenes );
00470
00471 std::vector< std::string > list_files;
00472 std::ifstream end(scenes.c_str());
00473 std::string s;
00474 while( std::getline(end,s) )
00475 {
00476 if (strcmp(s.c_str(),fileLoaded.c_str()))
00477 list_files.push_back(sofa::helper::system::DataRepository.getFile(s));
00478 }
00479 end.close();
00480
00481
00482 recentlyOpened->clear();
00483
00484 std::ofstream out;
00485 out.open(scenes.c_str(),std::ios::out);
00486 if (sofa::helper::system::DataRepository.findFile(fileLoaded))
00487 {
00488 fileLoaded = sofa::helper::system::DataRepository.getFile(fileLoaded);
00489 out << fileLoaded << "\n";
00490
00491 recentlyOpened->insertItem(QString(fileLoaded.c_str()));
00492 }
00493 for (unsigned int i=0;i<list_files.size() && i<5;++i)
00494 {
00495 recentlyOpened->insertItem(QString(list_files[i].c_str()));
00496 out << list_files[i] << "\n";
00497 }
00498
00499 out.close();
00500 }
00501
00502
00503 void SofaModeler::fileSave()
00504 {
00505 if (graph->getFilename().empty()) fileSaveAs();
00506 else fileSave(graph->getFilename());
00507 }
00508
00509 void SofaModeler::fileSave(std::string filename)
00510 {
00511 changeNameWindow(filename);
00512 getSimulation()->printXML(graph->getRoot(), filename.c_str());
00513 }
00514
00515
00516 void SofaModeler::fileSaveAs()
00517 {
00518 QString s = sofa::gui::qt::getSaveFileName ( this, QString(examplePath.c_str()), "Scenes (*.scn *.xml)", "save file dialog", "Choose where the scene will be saved" );
00519 if ( s.length() >0 )
00520 {
00521 fileSave ( s.ascii() );
00522
00523 std::string filename = s.ascii();
00524 sceneTab->setTabLabel(tabGraph, QString(sofa::helper::system::SetDirectory::GetFileName(filename.c_str()).c_str()));
00525 sceneTab->setTabToolTip(tabGraph, QString(filename.c_str()));
00526 examplePath = sofa::helper::system::SetDirectory::GetParentDir(filename.c_str());
00527 }
00528 }
00529
00530 void SofaModeler::loadPreset(int id)
00531 {
00532 Q3PopupMenu *s = (Q3PopupMenu*) sender();
00533 std::string presetFile = presetPath+ mapPreset[s->text(id).ascii()];
00534
00535
00536 if (sofa::helper::system::DataRepository.findFile ( presetFile ))
00537 {
00538 presetFile = sofa::helper::system::DataRepository.getFile ( presetFile );
00539 graph->loadPreset(presetFile);
00540 }
00541 else std::cerr<<"Preset : " << presetFile << " Not found\n";
00542 }
00543
00544 void SofaModeler::changeInformation(Q3ListViewItem *item)
00545 {
00546 if (!item) return;
00547 if (item->childCount() != 0) return;
00548 std::string nameObject = item->text(0).ascii();
00549 std::string::size_type end_name = nameObject.find(" ");
00550 if (end_name != std::string::npos) nameObject.resize(end_name);
00551 ClassInfo *currentComponent = getInfoFromName(nameObject);
00552 if (currentComponent) changeComponent(currentComponent);
00553 }
00554
00555
00556
00557 void SofaModeler::newComponent()
00558 {
00559 const QObject* sender = this->sender();
00560
00561 if ( mapComponents.find(sender) == mapComponents.end()) return;
00562 ClassInfo *currentComponent = mapComponents.find(sender)->second.first;
00563 changeComponent(currentComponent);
00564
00565 Q3TextDrag *dragging = new Q3TextDrag(QString(currentComponent->className.c_str()), (QWidget *)sender);
00566 QComboBox *box = (QComboBox *) mapComponents.find(sender)->second.second;
00567 QString textDragged;
00568 if (box)
00569 {
00570 textDragged = box->currentText();
00571 }
00572
00573 dragging->setText(textDragged);
00574 dragging->dragCopy();
00575
00576 }
00577
00578
00579 void SofaModeler::changeComponent(ClassInfo *currentComponent)
00580 {
00581 std::string text;
00582 text = std::string("<H2>") + currentComponent->className + std::string(": ");
00583
00584 std::vector< std::string > possiblePaths;
00585 for (std::set< std::string >::iterator it=currentComponent->baseClasses.begin(); it!=currentComponent->baseClasses.end() ;it++)
00586 {
00587 if (it != currentComponent->baseClasses.begin()) text += std::string(", ");
00588 text += (*it);
00589 std::string baseClassName( *it );
00590 for (unsigned int i=0;i<baseClassName.size();++i)
00591 {
00592 if (isupper(baseClassName[i])) baseClassName[i] = tolower(baseClassName[i]);
00593 }
00594 if (baseClassName == "odesolver") baseClassName="solver";
00595 if (baseClassName == "mastersolver") baseClassName="solver";
00596 if (baseClassName == "topologicalmapping") baseClassName="topology";
00597 if (baseClassName == "topologyobject") baseClassName="topology";
00598 if (baseClassName == "collisionmodel") baseClassName="collision";
00599 std::string path=std::string("Components/") + baseClassName + std::string("/") + currentComponent->className + std::string(".scn");
00600
00601
00602 if ( sofa::helper::system::DataRepository.findFile ( path ) )
00603 possiblePaths.push_back(sofa::helper::system::DataRepository.getFile ( path ));
00604 }
00605 if (possiblePaths.size() == 0)
00606 {
00607 std::string path=std::string("Components/misc/") + currentComponent->className + std::string(".scn");
00608
00609 if ( sofa::helper::system::DataRepository.findFile ( path ) )
00610 possiblePaths.push_back(sofa::helper::system::DataRepository.getFile ( path ));
00611 }
00612
00613 text += std::string("</H2>");
00614
00615 text += std::string("<ul>");
00616
00617 text += std::string("<li><b>Description: </b>") + currentComponent->description + std::string("</li>");
00618 if (!currentComponent->authors.empty())
00619 text += std::string("<li><b>Authors: </b>")+currentComponent->authors +std::string("</li>");
00620 if (!currentComponent->license.empty())
00621 text += std::string("<li><b>License: </b>") + currentComponent->license + std::string("</li>");
00622 if (possiblePaths.size() != 0)
00623 text += std::string("<li><b>Example: </b><a href=\"")+possiblePaths[0]+std::string("\">") + possiblePaths[0] + std::string("</a></li>");
00624
00625 text += std::string("</ul>");
00626
00627 infoItem->setText(text.c_str());
00628
00629 }
00630
00631
00632 void SofaModeler::newGNode()
00633 {
00634 Q3TextDrag *dragging = new Q3TextDrag(QString("GNode"), (QPushButton*)sender());
00635 dragging->setText(QString("GNode"));
00636 dragging->dragCopy();
00637 }
00638
00639
00640 void SofaModeler::changeCurrentScene( QWidget* currentGraph)
00641 {
00642 tabGraph=currentGraph;
00643 graph = mapGraph[currentGraph];
00644 if (graph)
00645 changeNameWindow(graph->getFilename());
00646 }
00647
00648
00649 void SofaModeler::changeCurrentScene(int id)
00650 {
00651 sceneTab->setCurrentPage( sceneTab->indexOf(mapWindow[id]) );
00652 }
00653
00654
00655 void SofaModeler::changeNameWindow(std::string filename)
00656 {
00657
00658 std::string str = "Sofa Modeler";
00659 if (!filename.empty()) str+= std::string(" - ") + filename;
00660 #ifdef WIN32
00661 setWindowTitle ( str.c_str() );
00662 #else
00663 setCaption ( str.c_str() );
00664 #endif
00665 updateRecentlyOpened(filename);
00666 }
00667
00668 ClassInfo* SofaModeler::getInfoFromName(std::string name)
00669 {
00670 std::map< const QObject* , std::pair<ClassInfo*, QObject*> >::iterator it;
00671 for (it=mapComponents.begin();it!= mapComponents.end();it++)
00672 {
00673 if (it->second.first->className == name) return it->second.first;
00674 }
00675 return NULL;
00676 }
00677
00678 void SofaModeler::keyPressEvent ( QKeyEvent *)
00679 {
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698 }
00699
00700 void SofaModeler::dropEvent(QDropEvent* event)
00701 {
00702 QPushButton *push = (QPushButton *)event->source();
00703 if (push) push->setDown(false);
00704
00705 QString text;
00706 Q3TextDrag::decode(event, text);
00707 std::string filename(text.ascii());
00708 std::string test = filename; test.resize(4);
00709 if (test == "file")
00710 {
00711 #ifdef WIN32
00712 filename = filename.substr(8);
00713 #else
00714 filename = filename.substr(7);
00715 #endif
00716
00717 if (filename[filename.size()-1] == '\n')
00718 {
00719 filename.resize(filename.size()-1);
00720 filename[filename.size()-1]='\0';
00721 }
00722
00723 fileOpen(filename);
00724 }
00725 }
00726
00727 void SofaModeler::runInSofa()
00728 {
00729 if (sceneTab->count() == 0) return;
00730 GNode* root=graph->getRoot();
00731 if (!root) return;
00732
00733 sofa::gui::SofaGUI::Init("Modeler");
00734
00735
00736 std::string filename=presetPath+std::string("temp") + (count++) + std::string(".scn");
00737 getSimulation()->printXML(root,filename.c_str());
00738
00739 if (count > '9') count = '0';
00740
00741
00742 std::string gui = sofa::gui::SofaGUI::GetGUIName();
00743 std::vector<std::string> plugins;
00744
00745 if (sofa::gui::SofaGUI::Init("Modeler",gui.c_str())) return ;
00746 sofa::gui::qt::RealGUI *guiSofa = new sofa::gui::qt::RealGUI(gui.c_str());
00747
00748 guiSofa->fileOpen(filename);
00749 guiSofa->show();
00750 guiSofa->setFocus();
00751 mapSofa.insert(std::make_pair(tabGraph, guiSofa));
00752 }
00753
00754 void SofaModeler::releaseButton()
00755 {
00756 QPushButton *push = (QPushButton *)sender();
00757 if (push) push->setDown(false);
00758 }
00759 }
00760 }
00761 }