void QSofaListView::Modify() { void *current_Id_modifyDialog = NULL; emit Lock(true); if ( currentItem() != NULL ) { ModifyObjectFlags dialogFlags = ModifyObjectFlags(); dialogFlags.setFlagsForSofa(); ModifyObject* dialogModifyObject = NULL; if (object_.type == typeData) //user clicked on a data { current_Id_modifyDialog = object_.ptr.Data; } if (object_.type == typeNode) { current_Id_modifyDialog = object_.ptr.Node; } if(object_.type == typeObject) { current_Id_modifyDialog = object_.ptr.Object; } assert(current_Id_modifyDialog != NULL); //Opening of a dialog window automatically created std::map< void*, QDialog* >::iterator testWindow = map_modifyObjectWindow.find( current_Id_modifyDialog); if ( testWindow != map_modifyObjectWindow.end()) { //Object already being modified: no need to open a new window (*testWindow).second->raise(); emit Lock(false); return; } dialogModifyObject = new ModifyObject(current_Id_modifyDialog,currentItem(),this,dialogFlags,currentItem()->text(0).toStdString().c_str()); if(object_.type == typeData) dialogModifyObject->createDialog(object_.ptr.Data); if(object_.type == typeNode) dialogModifyObject->createDialog((Base*)object_.ptr.Node); if(object_.type == typeObject) dialogModifyObject->createDialog((Base*)object_.ptr.Object); map_modifyDialogOpened.insert( std::make_pair ( current_Id_modifyDialog, currentItem()) ); map_modifyObjectWindow.insert( std::make_pair(current_Id_modifyDialog, dialogModifyObject)); connect ( dialogModifyObject, SIGNAL( objectUpdated() ), this, SIGNAL( Updated() )); connect ( this, SIGNAL( Close() ), dialogModifyObject, SLOT( closeNow() ) ); connect ( dialogModifyObject, SIGNAL( dialogClosed(void *) ) , this, SLOT( modifyUnlock(void *))); connect ( dialogModifyObject, SIGNAL( nodeNameModification(simulation::Node*) ) , this, SLOT( nodeNameModification(simulation::Node*) )); connect ( dialogModifyObject, SIGNAL( dataModified(QString) ), this, SIGNAL( dataModified(QString) ) ); dialogModifyObject->show(); dialogModifyObject->raise(); }
void GraphModeler::openModifyObject(QTreeWidgetItem *item) { if (!item) return; Base* object = graphListener->findObject(item); BaseData* data = graphListener->findData(item); if( data == NULL && object == NULL) { assert(0); } ModifyObjectFlags dialogFlags = ModifyObjectFlags(); dialogFlags.setFlagsForModeler(); if (data) //user clicked on a data { current_Id_modifyDialog = data; } else { if(object) { current_Id_modifyDialog = object; if (object->toConfigurationSetting()) dialogFlags.HIDE_FLAG=true; } else { assert(0); } } //Unicity and identification of the windows std::map< void*, QDialog* >::iterator testWindow = map_modifyObjectWindow.find( current_Id_modifyDialog); if ( testWindow != map_modifyObjectWindow.end()) { //Object already being modified: no need to open a new window (*testWindow).second->raise(); return; } ModifyObject *dialogModify = new ModifyObject( current_Id_modifyDialog,item,this,dialogFlags,item->text(0).toStdString().c_str()); connect(dialogModify, SIGNAL(beginObjectModification(sofa::core::objectmodel::Base*)), historyManager, SLOT(beginModification(sofa::core::objectmodel::Base*))); connect(dialogModify, SIGNAL(endObjectModification(sofa::core::objectmodel::Base*)), historyManager, SLOT(endModification(sofa::core::objectmodel::Base*))); if(data) { dialogModify->createDialog(data); } if(object) { dialogModify->createDialog(object); } if(object && propertyWidget) propertyWidget->addComponent(object->getName().c_str(), object, item); map_modifyObjectWindow.insert( std::make_pair(current_Id_modifyDialog, dialogModify)); //If the item clicked is a node, we add it to the list of the element modified map_modifyDialogOpened.insert ( std::make_pair ( current_Id_modifyDialog, item ) ); connect ( dialogModify, SIGNAL( dialogClosed(void *) ) , this, SLOT( modifyUnlock(void *))); dialogModify->show(); dialogModify->raise(); }
SofaModeler::SofaModeler():recentlyOpenedFilesManager(Utils::getSofaPathPrefix() + "/config/Modeler.ini") ,runSofaGUI(NULL) { setWindowTitle(QString("Sofa Modeler")); setAcceptDrops(true); resize(1000, 600); createActions(); fooAction = new QAction("Recently Opened Files...", this); createMenu(); createToolbar(); widget = new QWidget(this); widget->setGeometry(QRect(0, 57, 1000, 543)); setCentralWidget(widget); //index to add in temporary scenes created by the Modeler count='0'; // int menuIndex=4; isPasteReady=false; pasteAction->setEnabled(false); fileMenu->removeAction(fooAction); setDebugBinary(false); //---------------------------------------------------------------------- //Get the different path needed examplePath = sofa::helper::system::SetDirectory::GetParentDir(sofa::helper::system::DataRepository.getFirstPath().c_str()) + std::string( "/examples/" ); openPath = examplePath; binPath = Utils::getExecutableDirectory() + "/"; presetPath = examplePath + std::string("Objects/"); std::string presetFile = std::string("config/preset.ini" ); presetFile = sofa::helper::system::DataRepository.getFile ( presetFile ); QMenu *openTutorial = new QMenu(this); openTutorial->setTitle(QString(tr("&Tutorials"))); this->menuBar()->addMenu(/* QString(tr("&Tutorials")), */ openTutorial /*, menuIndex++ */); openTutorial->addAction(openTutorialsAction); toolBar->addAction(openTutorialsAction); //Find all the scene files in examples directory std::vector< QString > exampleQString; std::vector< QString > filter; const QString path(examplePath.c_str()); filter.push_back("*.scn"); filter.push_back("*.xml"); sofa::gui::qt::getFilesInDirectory(path, exampleQString, true, filter); //---------------------------------------------------------------------- // Create the Left part of the GUI //---------------------------------------------------------------------- //---------------------------------------------------------------------- //Create a Dock Window to receive the Sofa Library QDockWidget *dockLibrary=new QDockWidget("Library", this); dockLibrary->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); addDockWidget(Qt::LeftDockWidgetArea, dockLibrary); QWidget *leftPartWidget = new QWidget( dockLibrary); leftPartWidget->setObjectName("LibraryLayout"); QVBoxLayout *leftPartLayout = new QVBoxLayout(leftPartWidget); //---------------------------------------------------------------------- //Add a Filter to the Library QWidget *filterContainer = new QWidget( leftPartWidget ); filterContainer->setObjectName("filterContainer"); QHBoxLayout *filterLayout = new QHBoxLayout(filterContainer); leftPartLayout->addWidget(filterContainer); //--> Label QLabel *filterLabel= new QLabel(QString("Filter: "),filterContainer); filterLayout->addWidget(filterLabel); //--> Filter filterLibrary = new FilterLibrary(filterContainer); filterLayout->addWidget(filterLibrary); //--> Clear Button QPushButton *clearButton= new QPushButton(QString("X"),filterContainer); filterLayout->addWidget(clearButton); clearButton->setMaximumHeight(16); clearButton->setMaximumWidth(16); connect(filterLibrary, SIGNAL( filterList( const FilterQuery &) ), this, SLOT(searchText( const FilterQuery &)) ); connect(clearButton, SIGNAL( clicked()), filterLibrary, SLOT(clearText())); //---------------------------------------------------------------------- //Add the Sofa Library QSofaTreeLibrary *l = new QSofaTreeLibrary(leftPartWidget); library = l; leftPartLayout->addWidget(l); //---------------------------------------------------------------------- //Add the button to create Node QPushButton *GNodeButton = new QPushButton( leftPartWidget); GNodeButton->setObjectName("GNodeButton"); GNodeButton->setText("Node"); leftPartLayout->addWidget(GNodeButton); connect( GNodeButton, SIGNAL( pressed() ), this, SLOT( pressedGNodeButton() ) ); dockLibrary->setWidget(leftPartWidget); connect(l, SIGNAL( componentDragged( std::string, std::string, std::string, ClassEntry::SPtr) ), this, SLOT( componentDraggedReception( std::string, std::string, std::string, ClassEntry::SPtr) )); for (unsigned int i=0; i<exampleQString.size(); ++i) exampleFiles.push_back(exampleQString[i].toStdString()); //---------------------------------------------------------------------- //Create the information widget infoItem = new QTextBrowser(this->centralWidget()); infoItem->setMaximumHeight(195); connect( infoItem, SIGNAL(anchorClicked(const QUrl&)), this, SLOT(fileOpen(const QUrl&))); #ifndef WIN32 infoItem->setOpenExternalLinks(true); #endif leftPartLayout->addWidget(infoItem); //---------------------------------------------------------------------- // Create the Right part of the GUI //---------------------------------------------------------------------- // setRightJustification(true); QHBoxLayout *mainLayout = new QHBoxLayout(this->centralWidget()); //---------------------------------------------------------------------- //Create the scene graph visualization sceneTab = new QTabWidget(this->centralWidget()); mainLayout->addWidget(sceneTab); //option available only since Qt 4.5 #if QT_VERSION >= 0x040500 sceneTab->setTabsClosable(true); connect( sceneTab, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); #endif connect( sceneTab, SIGNAL(currentChanged( int)), this, SLOT( changeCurrentScene( int))); //---------------------------------------------------------------------- //Create the properties visualization ModifyObjectFlags modifyObjectFlags = ModifyObjectFlags(); modifyObjectFlags.setFlagsForModeler(); QDockWidget* dockProperty = new QDockWidget("Properties", this); dockProperty->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); addDockWidget(Qt::RightDockWidgetArea, dockProperty); // connect(dockProperty, SIGNAL(placeChanged(Q3DockWindow::Place)), this, SLOT(propertyDockMoved(Q3DockWindow::Place))); propertyWidget = new QDisplayPropertyWidget(modifyObjectFlags, dockProperty); dockProperty->setWidget(propertyWidget); //---------------------------------------------------------------------- //Add plugin manager window. ->load external libs plugin_dialog = new SofaPluginManager(); plugin_dialog->hide(); this->connect( plugin_dialog->buttonClose, SIGNAL(clicked() ), this, SLOT( rebuildLibrary() )); this->connect( plugin_dialog->buttonClose, SIGNAL(clicked() ), this, SLOT( updateViewerList() )); rebuildLibrary(); //---------------------------------------------------------------------- // Create the Menus //---------------------------------------------------------------------- //---------------------------------------------------------------------- //Add menu runSofa QMenu *runSofaMenu = new QMenu(this); runSofaMenu->setTitle(QString(tr("&RunSofa"))); this->menuBar()->addMenu(runSofaMenu /*, menuIndex++ */); runSofaMenu->addAction(runInSofaAction); toolBar->addAction(runInSofaAction); runSofaMenu->addAction("Change Sofa Binary...", this, SLOT( changeSofaBinary())); sofaBinary=std::string(); runSofaGUI = new QMenu(this); runSofaGUI->setTitle(tr("Viewer")); runSofaMenu->addMenu(runSofaGUI); updateViewerList(); //---------------------------------------------------------------------- //Add menu Preset preset = new QMenu(this); // this->menuBar()->insertItem(tr(QString("&Presets")), preset, menuIndex++); //---------------------------------------------------------------------- //Add menu Window: to quickly find an opened simulation windowMenu = new QMenu(this); windowMenu->setTitle(QString(tr("&Scenes"))); //windowMenu->addAction(QIcon(), QString(tr("&Scenes")),this, )); this->menuBar()->addMenu(windowMenu); windowMenu->addSeparator(); connect(windowMenu, SIGNAL(triggered(QAction*)), this, SLOT( changeCurrentScene(QAction*))); //---------------------------------------------------------------------- //Create the Preset Menu std::multimap< std::string, std::pair< std::string,std::string> > presetArchitecture; std::ifstream end(presetFile.c_str()); std::string s; std::string directory, namePreset, nameFile; while( std::getline(end,s) ) { //s contains the current line std::string::size_type slash = s.find('/'); if (slash != std::string::npos) { directory = s; directory.resize(slash); s=s.substr(slash+1); slash = s.find('/'); if (slash != std::string::npos) { namePreset=s; namePreset.resize(slash); nameFile = s.substr(slash+1); nameFile.resize(nameFile.size()-1); presetArchitecture.insert(std::make_pair( directory, std::make_pair( namePreset, nameFile) ) ); } } } end.close(); std::multimap< std::string, std::pair< std::string,std::string> >::iterator it_preset = presetArchitecture.begin(); while(it_preset != presetArchitecture.end()) { std::string directoryName = it_preset->first; QMenu* directory = new QMenu(this); connect( directory, SIGNAL(triggered(QAction*)), this, SLOT(loadPreset(QAction*))); directory->setTitle( tr( it_preset->first.c_str())); preset->addMenu(directory); std::map< std::string, std::string > &mPreset=mapPreset[directory]; for (unsigned int i=0; i<presetArchitecture.count(directoryName); i++,it_preset++) { directory->addAction(it_preset->second.first.c_str());//, this, SLOT(loadPreset()) ); mPreset.insert(it_preset->second); } } //---------------------------------------------------------------------- //Configure Recently Opened Menu // const int indexRecentlyOpened=fileMenu->actions().count()-2; QMenu *recentMenu = recentlyOpenedFilesManager.createWidget(this); //TODOQT5 fileMenu->addMenu(recentMenu /*,indexRecentlyOpened,indexRecentlyOpened */); connect(recentMenu, SIGNAL(triggered(QAction*)), this, SLOT(fileRecentlyOpened(QAction*))); //---------------------------------------------------------------------- //Center the application in the screen const QRect screen = QApplication::desktop()->availableGeometry(QApplication::desktop()->primaryScreen()); this->move( ( screen.width()- this->width() ) / 2, ( screen.height() - this->height()) / 2 ); //---------------------------------------------------------------------- //Configure the Tutorials tuto=0; displayHelpModeler(); }