From e93f57fb63d56cc2d18449143b85c2b500b24bb9 Mon Sep 17 00:00:00 2001 From: Marco Callieri mcallieri Date: Thu, 26 Apr 2012 08:26:58 +0000 Subject: [PATCH] added "append project to current" menu entry (first working draft), still have to define a policy for duplicated entries --- src/meshlab/mainwindow.h | 3 +- src/meshlab/mainwindow_Init.cpp | 4 ++ src/meshlab/mainwindow_RunTime.cpp | 86 ++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/src/meshlab/mainwindow.h b/src/meshlab/mainwindow.h index ffffcd0db..53c9709d8 100644 --- a/src/meshlab/mainwindow.h +++ b/src/meshlab/mainwindow.h @@ -79,6 +79,7 @@ private slots: public slots: bool importMesh(QString fileName=QString()); bool openProject(QString fileName=QString()); + bool appendProject(QString fileName=QString()); void updateCustomSettings(); private slots: @@ -346,7 +347,7 @@ private: //////////// Actions Menu File /////////////////////// QAction *newProjectAct; - QAction *openProjectAct,*saveProjectAct,*saveProjectAsAct; + QAction *openProjectAct, *appendProjectAct, *saveProjectAct, *saveProjectAsAct; QAction *importMeshAct, *exportMeshAct, *exportMeshAsAct; QAction *importRasterAct; QAction *closeProjectAct; diff --git a/src/meshlab/mainwindow_Init.cpp b/src/meshlab/mainwindow_Init.cpp index 964e79d2c..c2efa9a09 100644 --- a/src/meshlab/mainwindow_Init.cpp +++ b/src/meshlab/mainwindow_Init.cpp @@ -119,6 +119,9 @@ void MainWindow::createActions() openProjectAct->setShortcut(Qt::CTRL+Qt::Key_O); connect(openProjectAct, SIGNAL(triggered()), this, SLOT(openProject())); + appendProjectAct = new QAction(tr("Append project to current..."), this); + connect(appendProjectAct, SIGNAL(triggered()), this, SLOT(appendProject())); + saveProjectAct = new QAction(QIcon(":/images/save.png"),tr("&Save Project"), this); saveProjectAct->setShortcutContext(Qt::ApplicationShortcut); saveProjectAct->setShortcut(Qt::CTRL+Qt::Key_S); @@ -468,6 +471,7 @@ void MainWindow::createMenus() fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newProjectAct); fileMenu->addAction(openProjectAct); + fileMenu->addAction(appendProjectAct); fileMenu->addAction(saveProjectAct); fileMenu->addAction(closeProjectAct); fileMenu->addSeparator(); diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index c6d2c97d1..a641b664b 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -1633,6 +1633,92 @@ bool MainWindow::openProject(QString fileName) return true; } +bool MainWindow::appendProject(QString fileName) +{ + QStringList fileNameList; + + if (fileName.isEmpty()) + fileNameList = QFileDialog::getOpenFileNames(this,tr("Append Project File"), lastUsedDirectory.path(), "All Project Files (*.mlp *.aln);;MeshLab Project (*.mlp);;Align Project (*.aln)"); + else + fileNameList.append(fileName); + + if (fileNameList.isEmpty()) return false; + + // Common Part: init a Doc if necessary, and + bool activeDoc = (bool) !mdiarea->subWindowList().empty() && mdiarea->currentSubWindow(); + bool activeEmpty = activeDoc && meshDoc()->meshList.empty(); + + if (activeEmpty) // it is wrong to try appending to an empty project, even if it is possible + { + QMessageBox::critical(this, tr("Meshlab Opening Error"), "Current project is empty, cannot append"); + return false; + } + + meshDoc()->setBusy(true); + + // load all projects + foreach(fileName,fileNameList) + { + QFileInfo fi(fileName); + lastUsedDirectory = fi.absoluteDir(); + + if((fi.suffix().toLower()!="aln") && (fi.suffix().toLower()!="mlp")) + { + QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unknown project file extension"); + return false; + } + + // this change of dir is needed for subsequent textures/materials loading + QDir::setCurrent(fi.absoluteDir().absolutePath()); + qb->show(); + + if (QString(fi.suffix()).toLower() == "aln") + { + vector rmv; + int retVal=ALNParser::ParseALN(rmv,qPrintable(fileName)); + if(retVal != ALNParser::NoError) + { + QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unable to open ALN file"); + return false; + } + + bool openRes=true; + vector::iterator ir; + for(ir=rmv.begin();ir!=rmv.end() && openRes;++ir) + { + QString relativeToProj = fi.absoluteDir().absolutePath() + "/" + (*ir).filename.c_str(); + meshDoc()->addNewMesh(relativeToProj,relativeToProj); + loadMeshWithStandardParams(relativeToProj,this->meshDoc()->mm()); + if(openRes) meshDoc()->mm()->cm.Tr=(*ir).trasformation; + } + } + + if (QString(fi.suffix()).toLower() == "mlp") + { + if (!MeshDocumentFromXML(*meshDoc(),fileName)) + { + QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unable to open MLP file"); + return false; + } + for (int i=0; imeshList.size(); i++) + { + QString fullPath = meshDoc()->meshList[i]->fullName(); + meshDoc()->setBusy(true); + Matrix44f trm = this->meshDoc()->meshList[i]->cm.Tr; // save the matrix, because loadMeshClear it... + loadMeshWithStandardParams(fullPath,this->meshDoc()->meshList[i]); + this->meshDoc()->meshList[i]->cm.Tr=trm; + } + } + } + + meshDoc()->setBusy(false); + if(this->GLA() == 0) return false; + this->currentViewContainer()->resetAllTrackBall(); + qb->reset(); + saveRecentProjectList(fileName); + return true; +} + GLArea* MainWindow::newProject(const QString& projName) { filterMenu->setEnabled(!filterMenu->actions().isEmpty());