diff --git a/src/meshlab/glarea.cpp b/src/meshlab/glarea.cpp index 1a96b6315..96a9924c5 100644 --- a/src/meshlab/glarea.cpp +++ b/src/meshlab/glarea.cpp @@ -1985,7 +1985,7 @@ void GLArea::initializeShot(Shotm &shot) shot.Extrinsics.SetIdentity(); } -bool GLArea::viewFromFile() +bool GLArea::readViewFromFile() { QString filename = QFileDialog::getOpenFileName(this, tr("Load Project"), "./", tr("Xml Files (*.xml)")); @@ -2014,6 +2014,52 @@ bool GLArea::viewFromFile() return true; } +bool GLArea::saveViewToFile() +{ + QFileDialog* saveDiag = new QFileDialog(this,tr("Save View To File"), "./", tr("View file (*.xml)")); + +#if defined(Q_OS_WIN) + saveDiag->setOption(QFileDialog::DontUseNativeDialog); +#endif + saveDiag->setAcceptMode(QFileDialog::AcceptSave); + saveDiag->exec(); + QStringList files = saveDiag->selectedFiles(); + if (files.size() != 1) + return; + QString fileName = files[0]; + QFileInfo fi(fileName); + if (fi.isDir()) + return; + if (fi.suffix().isEmpty()) + { + QRegExp reg("\\.\\w+"); + saveDiag->selectedNameFilter().indexOf(reg); + QString ext = reg.cap(); + fileName.append(ext); + fi.setFile(fileName); + } + QDir::setCurrent(fi.absoluteDir().absolutePath()); + + bool ret = false; + qDebug("Saving a file %s\n", qUtf8Printable(fileName)); + if (fileName.isEmpty()) return; + else + { + QFile qFile(fileName); + if (qFile.open(QIODevice::WriteOnly)) { + QTextStream out(&qFile); out << this->viewToText(); + qFile.close(); + ret = true; + } + } + + if(!ret) + QMessageBox::critical(this, tr("Meshlab Saving Error"), QString("Unable to save view file %1\n").arg(fileName)); + + + return true; +} + void GLArea::loadShotFromTextAlignFile(const QDomDocument &doc) { QDomElement root = doc.documentElement(); diff --git a/src/meshlab/glarea.h b/src/meshlab/glarea.h index 6ae7888db..80628ff5a 100644 --- a/src/meshlab/glarea.h +++ b/src/meshlab/glarea.h @@ -523,16 +523,17 @@ private: public: QPair shotFromTrackball(); void viewFromCurrentShot(QString kind); - bool viewFromFile(); + bool saveViewToFile(); + bool readViewFromFile(); void createOrthoView(QString); - void toggleOrtho(); - void trackballStep(QString); + void toggleOrtho(); + void trackballStep(QString); void viewToClipboard(); QString viewToText(); void viewFromClipboard(); void loadShot(const QPair &) ; - void loadShotFromTextAlignFile(const QDomDocument &doc); - void loadViewFromViewStateFile(const QDomDocument &doc); + void loadShotFromTextAlignFile(const QDomDocument &doc); + void loadViewFromViewStateFile(const QDomDocument &doc); private: diff --git a/src/meshlab/mainwindow.h b/src/meshlab/mainwindow.h index 639947fa0..a9ea63d9b 100644 --- a/src/meshlab/mainwindow.h +++ b/src/meshlab/mainwindow.h @@ -217,9 +217,10 @@ private slots: void setUnsplit(); void linkViewers(); void viewFrom(QAction *qa); - void toggleOrtho(); - void trackballStep(QAction *qa); + void toggleOrtho(); + void trackballStep(QAction *qa); void readViewFromFile(); + void saveViewToFile(); void viewFromCurrentMeshShot(); void viewFromCurrentRasterShot(); void copyViewToClipBoard(); @@ -507,6 +508,7 @@ private: QAction *viewFromMeshAct; QAction *viewFromRasterAct; QAction *viewFromFileAct; + QAction *viewToFileAct; QAction *toggleOrthoAct; diff --git a/src/meshlab/mainwindow_Init.cpp b/src/meshlab/mainwindow_Init.cpp index f777bc203..47874156f 100644 --- a/src/meshlab/mainwindow_Init.cpp +++ b/src/meshlab/mainwindow_Init.cpp @@ -392,10 +392,12 @@ connectRenderModeActionList(rendlist);*/ viewFromMeshAct = new QAction(tr("View from Mesh Camera"), this); viewFromRasterAct = new QAction(tr("View from Raster Camera"), this); viewFromRasterAct->setShortcut(Qt::CTRL + Qt::Key_J); - viewFromFileAct = new QAction(tr("View from file"), this); - connect(viewFromFileAct, SIGNAL(triggered()), this, SLOT(readViewFromFile())); + viewFromFileAct = new QAction(tr("Read view from file"), this); + viewToFileAct = new QAction(tr("Save view to file"), this); connect(viewFromMeshAct, SIGNAL(triggered()), this, SLOT(viewFromCurrentMeshShot())); connect(viewFromRasterAct, SIGNAL(triggered()), this, SLOT(viewFromCurrentRasterShot())); + connect(viewFromFileAct, SIGNAL(triggered()), this, SLOT(readViewFromFile())); + connect(viewToFileAct, SIGNAL(triggered()), this, SLOT(saveViewToFile())); copyShotToClipboardAct = new QAction(tr("Copy shot"), this); connect(copyShotToClipboardAct, SIGNAL(triggered()), this, SLOT(copyViewToClipBoard())); diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index 45b66e2dc..d09fb1d31 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -212,6 +212,7 @@ void MainWindow::updateWindowMenu() // View From File act windowsMenu->addAction(viewFromFileAct); + windowsMenu->addAction(viewToFileAct); windowsMenu->addAction(viewFromMeshAct); windowsMenu->addAction(viewFromRasterAct); @@ -733,10 +734,15 @@ void MainWindow::trackballStep(QAction *qa) void MainWindow::readViewFromFile() { - if(GLA()) GLA()->viewFromFile(); + if(GLA()) GLA()->readViewFromFile(); updateMenus(); } +void MainWindow::saveViewToFile() +{ + if(GLA()) GLA()->saveViewToFile(); +} + void MainWindow::viewFromCurrentMeshShot() { if(GLA()) GLA()->viewFromCurrentShot("Mesh");