From 3e4cc3dbce9e16d61b75cc4b1cc183e235aeb5f6 Mon Sep 17 00:00:00 2001 From: Guido Ranzuglia granzuglia Date: Tue, 16 Jul 2013 09:12:00 +0000 Subject: [PATCH] - MeshLabFilterInterface creation and initialization temporary moved inside FilterThread --- src/meshlab/filterthread.cpp | 12 +- src/meshlab/filterthread.h | 9 +- src/meshlab/glarea.cpp | 2 + src/meshlab/mainwindow.h | 1 - src/meshlab/mainwindow_RunTime.cpp | 919 +++++++++++++++-------------- 5 files changed, 476 insertions(+), 467 deletions(-) diff --git a/src/meshlab/filterthread.cpp b/src/meshlab/filterthread.cpp index 813eaf222..3e3bf66bb 100644 --- a/src/meshlab/filterthread.cpp +++ b/src/meshlab/filterthread.cpp @@ -7,8 +7,9 @@ #include "filterthread.h" FilterThread::FilterThread(QString fname,MeshLabXMLFilterContainer *mfc, MeshDocument& md,EnvWrap& env,QObject *parent) -:QThread(parent), _mfc(mfc), _fname(fname),_md(md),_env(env) +:QThread(parent), _mfc(mfc), _fname(fname),_md(md),_env(env),_glwid(NULL) { + _glwid = new QGLWidget(); } FilterThread *cur=0; @@ -26,7 +27,16 @@ bool FilterThread::QCallBackLocal(const int pos, const char * str) void FilterThread::run() { /*assert(cur==0)*/ + QGLFormat defForm = QGLFormat::defaultFormat(); + _mfc->filterInterface->glContext = new QGLContext(defForm,_glwid->context()->device()); + _mfc->filterInterface->glContext->create(_glwid->context()); cur=this; _ret = _mfc->filterInterface->applyFilter(_fname, _md, _env, QCallBackLocal); cur=0; + +} + +FilterThread::~FilterThread() +{ + delete _glwid; } diff --git a/src/meshlab/filterthread.h b/src/meshlab/filterthread.h index 380f7c4b1..bd37378e5 100644 --- a/src/meshlab/filterthread.h +++ b/src/meshlab/filterthread.h @@ -9,8 +9,7 @@ class FilterThread : public QThread Q_OBJECT public: explicit FilterThread(QString fname,MeshLabXMLFilterContainer *mfc, MeshDocument& md,EnvWrap& env, QObject *parent = 0); - - + ~FilterThread(); MeshLabXMLFilterContainer *_mfc; QString _fname; MeshDocument& _md; @@ -23,10 +22,8 @@ protected: signals: void ThreadCB(const int pos,const QString& str); - - - public slots: - +private: + QGLWidget* _glwid; }; #endif // FILTERTHREAD_H \ No newline at end of file diff --git a/src/meshlab/glarea.cpp b/src/meshlab/glarea.cpp index 1e1936000..970776b94 100644 --- a/src/meshlab/glarea.cpp +++ b/src/meshlab/glarea.cpp @@ -1970,9 +1970,11 @@ void GLArea::showInterruptButton( const bool& show ) void GLArea::completeUpdateRequested() { + makeCurrent(); if ((this->md() != NULL) && (this->md()->rm() != NULL)) loadRaster(this->md()->rm()->id()); //if (md()->mm() != NULL) // trackball.center = md()->mm()->cm.bbox.Center(); update(); + doneCurrent(); } diff --git a/src/meshlab/mainwindow.h b/src/meshlab/mainwindow.h index 7f38aeb40..50d1365f6 100644 --- a/src/meshlab/mainwindow.h +++ b/src/meshlab/mainwindow.h @@ -234,7 +234,6 @@ private: PluginGeneratorGUI* plugingui; QSignalMapper *windowMapper; - PluginManager PM; /* diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index d2fd00357..9ea6a12cf 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -205,27 +205,27 @@ void MainWindow::updateWindowMenu() windowsMenu->addAction(copyShotToClipboardAct); windowsMenu->addAction(pasteShotFromClipboardAct); - //Enabling the actions - MultiViewer_Container *mvc = currentViewContainer(); - if(mvc) - { - setUnsplitAct->setEnabled(mvc->viewerCounter()>1); - GLArea* current = mvc->currentView(); - if(current) - { - setSplitHAct->setEnabled(current->size().height()/2 > current->minimumSizeHint().height()); - setSplitVAct->setEnabled(current->size().width()/2 > current->minimumSizeHint().width()); + //Enabling the actions + MultiViewer_Container *mvc = currentViewContainer(); + if(mvc) + { + setUnsplitAct->setEnabled(mvc->viewerCounter()>1); + GLArea* current = mvc->currentView(); + if(current) + { + setSplitHAct->setEnabled(current->size().height()/2 > current->minimumSizeHint().height()); + setSplitVAct->setEnabled(current->size().width()/2 > current->minimumSizeHint().width()); - linkViewersAct->setEnabled(currentViewContainer()->viewerCounter()>1); - if(currentViewContainer()->viewerCounter()==1) - linkViewersAct->setChecked(false); + linkViewersAct->setEnabled(currentViewContainer()->viewerCounter()>1); + if(currentViewContainer()->viewerCounter()==1) + linkViewersAct->setChecked(false); - windowsMenu->addSeparator(); - } - } - } + windowsMenu->addSeparator(); + } + } + } - QList windows = mdiarea->subWindowList(); + QList windows = mdiarea->subWindowList(); if(windows.size() > 0) windowsMenu->addSeparator(); @@ -404,21 +404,21 @@ void MainWindow::updateMenus() setSelectFaceRenderingAct->setChecked(rm.selectedFace); setSelectVertRenderingAct->setChecked(rm.selectedVert); - // Decorator Menu Checking and unChecking - // First uncheck and disable all the decorators - foreach (QAction *a, PM.decoratorActionList) - { - a->setChecked(false); - a->setEnabled(true); - } - // Check the decorator per Document of the current glarea - foreach (QAction *a, GLA()->iPerDocDecoratorlist) - { a ->setChecked(true); } + // Decorator Menu Checking and unChecking + // First uncheck and disable all the decorators + foreach (QAction *a, PM.decoratorActionList) + { + a->setChecked(false); + a->setEnabled(true); + } + // Check the decorator per Document of the current glarea + foreach (QAction *a, GLA()->iPerDocDecoratorlist) + { a ->setChecked(true); } - // Then check the decorator enabled for the current mesh. - if(GLA()->mm()) - foreach (QAction *a, GLA()->iCurPerMeshDecoratorList()) - { a ->setChecked(true); } + // Then check the decorator enabled for the current mesh. + if(GLA()->mm()) + foreach (QAction *a, GLA()->iCurPerMeshDecoratorList()) + { a ->setChecked(true); } } // if active else @@ -450,20 +450,20 @@ void MainWindow::updateMenus() layerDialog->updateDecoratorParsView(); } } - if (searchMenu != NULL) - searchMenu->searchLineWidth() = longestActionWidthInAllMenus(); + if (searchMenu != NULL) + searchMenu->searchLineWidth() = longestActionWidthInAllMenus(); } void MainWindow::setSplit(QAction *qa) { MultiViewer_Container *mvc = currentViewContainer(); - if(mvc) - { - GLArea *glwClone=new GLArea(mvc, ¤tGlobalParams); - if(qa->text() == tr("&Horizontally")) - mvc->addView(glwClone, Qt::Vertical); - else if(qa->text() == tr("&Vertically")) - mvc->addView(glwClone, Qt::Horizontal); + if(mvc) + { + GLArea *glwClone=new GLArea(mvc, ¤tGlobalParams); + if(qa->text() == tr("&Horizontally")) + mvc->addView(glwClone, Qt::Vertical); + else if(qa->text() == tr("&Vertically")) + mvc->addView(glwClone, Qt::Horizontal); //The loading of the raster must be here if(GLA()->isRaster()){ @@ -483,11 +483,11 @@ void MainWindow::setSplit(QAction *qa) void MainWindow::setUnsplit() { MultiViewer_Container *mvc = currentViewContainer(); - if(mvc) - { - assert(mvc->viewerCounter() >1); + if(mvc) + { + assert(mvc->viewerCounter() >1); - mvc->removeView(mvc->currentView()->getId()); + mvc->removeView(mvc->currentView()->getId()); updateMenus(); } @@ -587,8 +587,8 @@ void MainWindow::setHandleMenu(QPoint point, Qt::Orientation orientation, QSplit void MainWindow::splitFromHandle(QAction *qa ) { MultiViewer_Container *mvc = currentViewContainer(); - QPoint point = qa->data().toPoint(); - int epsilon =10; + QPoint point = qa->data().toPoint(); + int epsilon =10; if(qa->text() == tr("&Right")) point.setX(point.x()+ epsilon); @@ -636,7 +636,7 @@ void MainWindow::unsplitFromHandle(QAction * qa) void MainWindow::linkViewers() { MultiViewer_Container *mvc = currentViewContainer(); - mvc->updateTrackballInViewers(); + mvc->updateTrackballInViewers(); } void MainWindow::viewFrom(QAction *qa) @@ -647,7 +647,7 @@ void MainWindow::viewFrom(QAction *qa) void MainWindow::readViewFromFile() { if(GLA()) GLA()->viewFromFile(); - updateMenus(); + updateMenus(); } @@ -671,7 +671,7 @@ void MainWindow::copyViewToClipBoard() void MainWindow::pasteViewFromClipboard() { if(GLA()) GLA()->viewFromClipboard(); - updateMenus(); + updateMenus(); } void MainWindow::dragEnterEvent(QDragEnterEvent *event) @@ -686,41 +686,41 @@ void MainWindow::dropEvent ( QDropEvent * event ) const QMimeData * data = event->mimeData(); if (data->hasUrls()) { - QList< QUrl > url_list = data->urls(); - for (int i=0, size=url_list.size(); ikeyboardModifiers () == Qt::ControlModifier ) || ( QApplication::keyboardModifiers () == Qt::ControlModifier )) - { - this->newProject(); - } + QList< QUrl > url_list = data->urls(); + for (int i=0, size=url_list.size(); ikeyboardModifiers () == Qt::ControlModifier ) || ( QApplication::keyboardModifiers () == Qt::ControlModifier )) + { + this->newProject(); + } - if(path.endsWith("mlp",Qt::CaseInsensitive) || path.endsWith("aln",Qt::CaseInsensitive)) - openProject(path); - else - importMesh(path); - } + if(path.endsWith("mlp",Qt::CaseInsensitive) || path.endsWith("aln",Qt::CaseInsensitive)) + openProject(path); + else + importMesh(path); + } } } void MainWindow::delCurrentMesh() { - //MeshDoc accessed through current container + //MeshDoc accessed through current container currentViewContainer()->meshDoc.delMesh(currentViewContainer()->meshDoc.mm()); currentViewContainer()->updateAllViewer(); - updateMenus(); + updateMenus(); } void MainWindow::delCurrentRaster() { - //MeshDoc accessed through current container + //MeshDoc accessed through current container currentViewContainer()->meshDoc.delRaster(currentViewContainer()->meshDoc.rm()); - updateMenus(); + updateMenus(); } void MainWindow::endEdit() { - GLA()->endEdit(); + GLA()->endEdit(); } void MainWindow::applyLastFilter() { @@ -731,11 +731,11 @@ void MainWindow::showFilterScript() { FilterScriptDialog dialog(this); dialog.setScript(&(meshDoc()->filterHistory)); - if (dialog.exec()==QDialog::Accepted) - { - runFilterScript(); - return ; - } + if (dialog.exec()==QDialog::Accepted) + { + runFilterScript(); + return ; + } } @@ -744,12 +744,12 @@ void MainWindow::runFilterScript() FilterScript::iterator ii; for(ii= meshDoc()->filterHistory.actionList.begin();ii!= meshDoc()->filterHistory.actionList.end();++ii) { - QAction *action = PM.actionFilterMap[ (*ii).first]; - MeshFilterInterface *iFilter = qobject_cast(action->parent()); + QAction *action = PM.actionFilterMap[ (*ii).first]; + MeshFilterInterface *iFilter = qobject_cast(action->parent()); - int req=iFilter->getRequirements(action); - meshDoc()->mm()->updateDataMask(req); - iFilter->setLog(&meshDoc()->Log); + int req=iFilter->getRequirements(action); + meshDoc()->mm()->updateDataMask(req); + iFilter->setLog(&meshDoc()->Log); RichParameterSet ¶meterSet = (*ii).second; @@ -817,7 +817,7 @@ void MainWindow::runFilterScript() void MainWindow::showTooltip(QAction* q) { QString tip = q->toolTip(); - QToolTip::showText(QCursor::pos(), tip); + QToolTip::showText(QCursor::pos(), tip); } // ///////////////////////////////////////////////// @@ -967,43 +967,43 @@ void MainWindow::startFilter() } /* - callback function that actually start the chosen filter. + callback function that actually start the chosen filter. it is called once the parameters have been filled. - It can be called - from the automatic dialog - from the user defined dialog + It can be called + from the automatic dialog + from the user defined dialog */ void MainWindow::executeFilter(QAction *action, RichParameterSet ¶ms, bool isPreview) { - MeshFilterInterface *iFilter = qobject_cast< MeshFilterInterface *>(action->parent()); + MeshFilterInterface *iFilter = qobject_cast< MeshFilterInterface *>(action->parent()); qb->show(); iFilter->setLog(&meshDoc()->Log); - // Ask for filter requirements (eg a filter can need topology, border flags etc) + // Ask for filter requirements (eg a filter can need topology, border flags etc) // and statisfy them - qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); - MainWindow::globalStatusBar()->showMessage("Starting Filter...",5000); + qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); + MainWindow::globalStatusBar()->showMessage("Starting Filter...",5000); int req=iFilter->getRequirements(action); if (!meshDoc()->meshList.isEmpty()) - meshDoc()->mm()->updateDataMask(req); + meshDoc()->mm()->updateDataMask(req); qApp->restoreOverrideCursor(); - // (3) save the current filter and its parameters in the history + // (3) save the current filter and its parameters in the history if(!isPreview) { - meshDoc()->filterHistory.actionList.append(qMakePair(action->text(),params)); - meshDoc()->Log.ClearBookmark(); + meshDoc()->filterHistory.actionList.append(qMakePair(action->text(),params)); + meshDoc()->Log.ClearBookmark(); } else - meshDoc()->Log.BackToBookmark(); + meshDoc()->Log.BackToBookmark(); // (4) Apply the Filter - bool ret; + bool ret; qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); - QTime tt; tt.start(); + QTime tt; tt.start(); meshDoc()->setBusy(true); RichParameterSet MergedEnvironment(params); MergedEnvironment.join(currentGlobalParams); @@ -1015,69 +1015,69 @@ void MainWindow::executeFilter(QAction *action, RichParameterSet ¶ms, bool i iFilter->glContext->create(filterWidget->context()); try { - ret=iFilter->applyFilter(action, *(meshDoc()), MergedEnvironment, QCallBack); + ret=iFilter->applyFilter(action, *(meshDoc()), MergedEnvironment, QCallBack); - meshDoc()->setBusy(false); + meshDoc()->setBusy(false); - qApp->restoreOverrideCursor(); + qApp->restoreOverrideCursor(); - // (5) Apply post filter actions (e.g. recompute non updated stuff if needed) + // (5) Apply post filter actions (e.g. recompute non updated stuff if needed) - if(ret) - { - meshDoc()->Log.Logf(GLLogStream::SYSTEM,"Applied filter %s in %i msec",qPrintable(action->text()),tt.elapsed()); - if (meshDoc()->mm() != NULL) - meshDoc()->mm()->meshModified() = true; - MainWindow::globalStatusBar()->showMessage("Filter successfully completed...",2000); - if(GLA()) - { - GLA()->setWindowModified(true); - GLA()->setLastAppliedFilter(action); - } - lastFilterAct->setText(QString("Apply filter ") + action->text()); - lastFilterAct->setEnabled(true); - } - else // filter has failed. show the message error. - { - QMessageBox::warning(this, tr("Filter Failure"), QString("Failure of filter : '%1'

").arg(action->text())+iFilter->errorMsg()); // text - MainWindow::globalStatusBar()->showMessage("Filter failed...",2000); - } - // at the end for filters that change the color, or selection set the appropriate rendering mode - if(iFilter->getClass(action) & MeshFilterInterface::FaceColoring ) { - GLA()->setColorMode(vcg::GLW::CMPerFace); - meshDoc()->mm()->updateDataMask(MeshModel::MM_FACECOLOR); - } - if(iFilter->getClass(action) & MeshFilterInterface::VertexColoring ){ - GLA()->setColorMode(vcg::GLW::CMPerVert); - meshDoc()->mm()->updateDataMask(MeshModel::MM_VERTCOLOR); - } - if(iFilter->postCondition(action) & MeshModel::MM_COLOR) - { - GLA()->setColorMode(vcg::GLW::CMPerMesh); - meshDoc()->mm()->updateDataMask(MeshModel::MM_COLOR); - } + if(ret) + { + meshDoc()->Log.Logf(GLLogStream::SYSTEM,"Applied filter %s in %i msec",qPrintable(action->text()),tt.elapsed()); + if (meshDoc()->mm() != NULL) + meshDoc()->mm()->meshModified() = true; + MainWindow::globalStatusBar()->showMessage("Filter successfully completed...",2000); + if(GLA()) + { + GLA()->setWindowModified(true); + GLA()->setLastAppliedFilter(action); + } + lastFilterAct->setText(QString("Apply filter ") + action->text()); + lastFilterAct->setEnabled(true); + } + else // filter has failed. show the message error. + { + QMessageBox::warning(this, tr("Filter Failure"), QString("Failure of filter : '%1'

").arg(action->text())+iFilter->errorMsg()); // text + MainWindow::globalStatusBar()->showMessage("Filter failed...",2000); + } + // at the end for filters that change the color, or selection set the appropriate rendering mode + if(iFilter->getClass(action) & MeshFilterInterface::FaceColoring ) { + GLA()->setColorMode(vcg::GLW::CMPerFace); + meshDoc()->mm()->updateDataMask(MeshModel::MM_FACECOLOR); + } + if(iFilter->getClass(action) & MeshFilterInterface::VertexColoring ){ + GLA()->setColorMode(vcg::GLW::CMPerVert); + meshDoc()->mm()->updateDataMask(MeshModel::MM_VERTCOLOR); + } + if(iFilter->postCondition(action) & MeshModel::MM_COLOR) + { + GLA()->setColorMode(vcg::GLW::CMPerMesh); + meshDoc()->mm()->updateDataMask(MeshModel::MM_COLOR); + } if(iFilter->postCondition(action) & MeshModel::MM_CAMERA) meshDoc()->mm()->updateDataMask(MeshModel::MM_CAMERA); - if(iFilter->getClass(action) & MeshFilterInterface::Selection ) - { - GLA()->setSelectVertRendering(true); - GLA()->setSelectFaceRendering(true); - } - if(iFilter->getClass(action) & MeshFilterInterface::MeshCreation ) - GLA()->resetTrackBall(); + if(iFilter->getClass(action) & MeshFilterInterface::Selection ) + { + GLA()->setSelectVertRendering(true); + GLA()->setSelectFaceRendering(true); + } + if(iFilter->getClass(action) & MeshFilterInterface::MeshCreation ) + GLA()->resetTrackBall(); - if(iFilter->getClass(action) & MeshFilterInterface::Texture ) - GLA()->updateTexture(); + if(iFilter->getClass(action) & MeshFilterInterface::Texture ) + GLA()->updateTexture(); } catch (std::bad_alloc& bdall) { - meshDoc()->setBusy(false); - qApp->restoreOverrideCursor(); - QMessageBox::warning(this, tr("Filter Failure"), QString("Operating system was not able to allocate the requested memory.
Failure of filter : '%1'
We warmly suggest you to try a 64-bit version of MeshLab.
").arg(action->text())+bdall.what()); // text - MainWindow::globalStatusBar()->showMessage("Filter failed...",2000); + meshDoc()->setBusy(false); + qApp->restoreOverrideCursor(); + QMessageBox::warning(this, tr("Filter Failure"), QString("Operating system was not able to allocate the requested memory.
Failure of filter : '%1'
We warmly suggest you to try a 64-bit version of MeshLab.
").arg(action->text())+bdall.what()); // text + MainWindow::globalStatusBar()->showMessage("Filter failed...",2000); } qb->reset(); @@ -1085,7 +1085,7 @@ void MainWindow::executeFilter(QAction *action, RichParameterSet ¶ms, bool i GLA()->update(); //now there is the container MultiViewer_Container* mvc = currentViewContainer(); if(mvc) - mvc->updateAllViewer(); + mvc->updateAllViewer(); } @@ -1234,13 +1234,13 @@ void MainWindow::executeFilter(MeshLabXMLFilterContainer* mfc, EnvWrap& env, boo ////GLA() is only the parent xmlfiltertimer.restart(); - QGLWidget* filterWidget = new QGLWidget(GLA()); - QGLFormat defForm = QGLFormat::defaultFormat(); - if (filtercpp) + /*if (filtercpp) { + QGLWidget* filterWidget = new QGLWidget(GLA()); + QGLFormat defForm = QGLFormat::defaultFormat(); iFilter->glContext = new QGLContext(defForm,filterWidget->context()->device()); iFilter->glContext->create(filterWidget->context()); - } + }*/ try { /*bool isinter = */(mfc->xmlInfo->filterAttribute(fname,MLXMLElNames::filterIsInterruptible) == "true"); @@ -1270,11 +1270,12 @@ void MainWindow::executeFilter(MeshLabXMLFilterContainer* mfc, EnvWrap& env, boo if (filtercpp) { //I'm using PM.stringXMLFilterMap[fname] instead of mfc passed like parameter because i'm sure that the first one is still alive after the function will exit. + //wid = new QGLWidget(); FilterThread* ft = new FilterThread(fname,&PM.stringXMLFilterMap[fname],*(meshDoc()),env,this); connect(ft,SIGNAL(finished()),this,SLOT(postFilterExecution())); connect(ft,SIGNAL(ThreadCB(const int, const QString&)),this,SLOT(updateProgressBar(const int,const QString&))); connect(xmldialog,SIGNAL(filterInterrupt(const bool)),PM.stringXMLFilterMap[fname].filterInterface,SLOT(setInterrupt(const bool))); - + /*iFilter->glContext->moveToThread(ft);*/ ft->start(); //ret = iFilter->applyFilter(fname, *(meshDoc()), env, QCallBack); } @@ -1413,7 +1414,7 @@ void MainWindow::suspendEditMode() // return if no window is open if(!GLA()) return; - // return if no editing action is currently ongoing + // return if no editing action is currently ongoing if(!GLA()->getCurrentEditAction()) return; GLA()->suspendEditToggle(); @@ -1505,46 +1506,46 @@ void MainWindow::applyDecorateMode() if(iDecorateTemp->getDecorationClass(action)== MeshDecorateInterface::PerDocument) { - bool found=GLA()->iPerDocDecoratorlist.removeOne(action); - if(found) - { - iDecorateTemp->endDecorate(action,*meshDoc(),GLA()->glas.currentGlobalParamSet,GLA()); - iDecorateTemp->setLog(NULL); - GLA()->Logf(GLLogStream::SYSTEM,"Disabled Decorate mode %s",qPrintable(action->text())); - } - else{ - iDecorateTemp->setLog(&meshDoc()->Log); - bool ret = iDecorateTemp->startDecorate(action,*meshDoc(), ¤tGlobalParams, GLA()); - if(ret) { - GLA()->iPerDocDecoratorlist.push_back(action); - GLA()->Logf(GLLogStream::SYSTEM,"Enabled Decorate mode %s",qPrintable(action->text())); - } - else GLA()->Logf(GLLogStream::SYSTEM,"Failed start of Decorate mode %s",qPrintable(action->text())); - } + bool found=GLA()->iPerDocDecoratorlist.removeOne(action); + if(found) + { + iDecorateTemp->endDecorate(action,*meshDoc(),GLA()->glas.currentGlobalParamSet,GLA()); + iDecorateTemp->setLog(NULL); + GLA()->Logf(GLLogStream::SYSTEM,"Disabled Decorate mode %s",qPrintable(action->text())); + } + else{ + iDecorateTemp->setLog(&meshDoc()->Log); + bool ret = iDecorateTemp->startDecorate(action,*meshDoc(), ¤tGlobalParams, GLA()); + if(ret) { + GLA()->iPerDocDecoratorlist.push_back(action); + GLA()->Logf(GLLogStream::SYSTEM,"Enabled Decorate mode %s",qPrintable(action->text())); + } + else GLA()->Logf(GLLogStream::SYSTEM,"Failed start of Decorate mode %s",qPrintable(action->text())); + } } if(iDecorateTemp->getDecorationClass(action)== MeshDecorateInterface::PerMesh) { - MeshModel ¤tMeshModel = *(meshDoc()->mm()); - bool found=GLA()->iCurPerMeshDecoratorList().removeOne(action); - if(found) - { - iDecorateTemp->endDecorate(action,currentMeshModel,GLA()->glas.currentGlobalParamSet,GLA()); - iDecorateTemp->setLog(NULL); - GLA()->Logf(0,"Disabled Decorate mode %s",qPrintable(action->text())); - } - else{ - QString errorMessage; - if (iDecorateTemp->isDecorationApplicable(action,currentMeshModel,errorMessage)) { - iDecorateTemp->setLog(&meshDoc()->Log); - bool ret = iDecorateTemp->startDecorate(action,currentMeshModel, ¤tGlobalParams, GLA()); - if(ret) { - GLA()->iCurPerMeshDecoratorList().push_back(action); - GLA()->Logf(GLLogStream::SYSTEM,"Enabled Decorate mode %s",qPrintable(action->text())); - } - else GLA()->Logf(GLLogStream::SYSTEM,"Failed Decorate mode %s",qPrintable(action->text())); - } - } + MeshModel ¤tMeshModel = *(meshDoc()->mm()); + bool found=GLA()->iCurPerMeshDecoratorList().removeOne(action); + if(found) + { + iDecorateTemp->endDecorate(action,currentMeshModel,GLA()->glas.currentGlobalParamSet,GLA()); + iDecorateTemp->setLog(NULL); + GLA()->Logf(0,"Disabled Decorate mode %s",qPrintable(action->text())); + } + else{ + QString errorMessage; + if (iDecorateTemp->isDecorationApplicable(action,currentMeshModel,errorMessage)) { + iDecorateTemp->setLog(&meshDoc()->Log); + bool ret = iDecorateTemp->startDecorate(action,currentMeshModel, ¤tGlobalParams, GLA()); + if(ret) { + GLA()->iCurPerMeshDecoratorList().push_back(action); + GLA()->Logf(GLLogStream::SYSTEM,"Enabled Decorate mode %s",qPrintable(action->text())); + } + else GLA()->Logf(GLLogStream::SYSTEM,"Failed Decorate mode %s",qPrintable(action->text())); + } + } } layerDialog->updateDecoratorParsView(); @@ -1613,13 +1614,13 @@ void MainWindow::saveProject() #if defined(Q_OS_MAC) saveDiag->setOption(QFileDialog::DontUseNativeDialog,true); #endif - QCheckBox* saveAllFile = new QCheckBox(QString("Save All Files"),saveDiag); + QCheckBox* saveAllFile = new QCheckBox(QString("Save All Files"),saveDiag); saveAllFile->setCheckState(Qt::Unchecked); - QCheckBox* onlyVisibleLayers = new QCheckBox(QString("Only Visible Layers"),saveDiag); + QCheckBox* onlyVisibleLayers = new QCheckBox(QString("Only Visible Layers"),saveDiag); onlyVisibleLayers->setCheckState(Qt::Unchecked); QGridLayout* layout = (QGridLayout*) saveDiag->layout(); - layout->addWidget(saveAllFile,4,2); - layout->addWidget(onlyVisibleLayers,4,1); + layout->addWidget(saveAllFile,4,2); + layout->addWidget(onlyVisibleLayers,4,1); saveDiag->setAcceptMode(QFileDialog::AcceptSave); saveDiag->exec(); @@ -1630,14 +1631,14 @@ void MainWindow::saveProject() // this change of dir is needed for subsequent textures/materials loading QFileInfo fi(fileName); if (fi.isDir()) - return; + return; if (fi.suffix().isEmpty()) { - QRegExp reg("\\.\\w+"); - saveDiag->selectedNameFilter().indexOf(reg); - QString ext = reg.cap(); - fileName.append(ext); - fi.setFile(fileName); + QRegExp reg("\\.\\w+"); + saveDiag->selectedNameFilter().indexOf(reg); + QString ext = reg.cap(); + fileName.append(ext); + fi.setFile(fileName); } QDir::setCurrent(fi.absoluteDir().absolutePath()); @@ -1646,59 +1647,59 @@ void MainWindow::saveProject() QMdiSubWindow* sub = mdiarea->currentSubWindow(); if (sub != NULL) { - sub->setWindowTitle(meshDoc()->docLabel()); - layerDialog->setWindowTitle(meshDoc()->docLabel()); + sub->setWindowTitle(meshDoc()->docLabel()); + layerDialog->setWindowTitle(meshDoc()->docLabel()); } /****************************************************************************/ bool ret; - qDebug("Saving aln file %s\n",qPrintable(fileName)); - if (fileName.isEmpty()) return; - else - { - //save path away so we can use it again - QString path = fileName; - path.truncate(path.lastIndexOf("/")); - lastUsedDirectory.setPath(path); - } + qDebug("Saving aln file %s\n",qPrintable(fileName)); + if (fileName.isEmpty()) return; + else + { + //save path away so we can use it again + QString path = fileName; + path.truncate(path.lastIndexOf("/")); + lastUsedDirectory.setPath(path); + } if (QString(fi.suffix()).toLower() == "aln") { - vector meshNameVector; - vector transfVector; + vector meshNameVector; + vector transfVector; - foreach(MeshModel * mp, meshDoc()->meshList) - { - if((!onlyVisibleLayers->isChecked()) || (mp->visible)) - { - meshNameVector.push_back(qPrintable(mp->relativePathName())); - transfVector.push_back(mp->cm.Tr); - } - } - ret= ALNParser::SaveALN(qPrintable(fileName),meshNameVector,transfVector); + foreach(MeshModel * mp, meshDoc()->meshList) + { + if((!onlyVisibleLayers->isChecked()) || (mp->visible)) + { + meshNameVector.push_back(qPrintable(mp->relativePathName())); + transfVector.push_back(mp->cm.Tr); + } + } + ret= ALNParser::SaveALN(qPrintable(fileName),meshNameVector,transfVector); } else - ret = MeshDocumentToXMLFile(*meshDoc(),fileName,onlyVisibleLayers->isChecked()); + ret = MeshDocumentToXMLFile(*meshDoc(),fileName,onlyVisibleLayers->isChecked()); if (saveAllFile->isChecked()) { - for(int ii = 0; ii < meshDoc()->meshList.size();++ii) - { - MeshModel* mp = meshDoc()->meshList[ii]; - if((!onlyVisibleLayers->isChecked()) || (mp->visible)) - { - ret |= exportMesh(mp->fullName(),mp,true); - } - } + for(int ii = 0; ii < meshDoc()->meshList.size();++ii) + { + MeshModel* mp = meshDoc()->meshList[ii]; + if((!onlyVisibleLayers->isChecked()) || (mp->visible)) + { + ret |= exportMesh(mp->fullName(),mp,true); + } + } } - if(!ret) - QMessageBox::critical(this, tr("Meshlab Saving Error"), QString("Unable to save project file %1\n").arg(fileName)); + if(!ret) + QMessageBox::critical(this, tr("Meshlab Saving Error"), QString("Unable to save project file %1\n").arg(fileName)); } bool MainWindow::openProject(QString fileName) { if (fileName.isEmpty()) - fileName = QFileDialog::getOpenFileName(this,tr("Open Project File"), lastUsedDirectory.path(), "All Project Files (*.mlp *.aln *.out *.nvm);;MeshLab Project (*.mlp);;Align Project (*.aln);;Bundler Output (*.out);;VisualSFM Output (*.nvm)"); + fileName = QFileDialog::getOpenFileName(this,tr("Open Project File"), lastUsedDirectory.path(), "All Project Files (*.mlp *.aln *.out *.nvm);;MeshLab Project (*.mlp);;Align Project (*.aln);;Bundler Output (*.out);;VisualSFM Output (*.nvm)"); if (fileName.isEmpty()) return false; @@ -1707,8 +1708,8 @@ bool MainWindow::openProject(QString fileName) if((fi.suffix().toLower()!="aln") && (fi.suffix().toLower()!="mlp") && (fi.suffix().toLower()!="out") && (fi.suffix().toLower()!="nvm")) { - QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unknown project file extension"); - return false; + QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unknown project file extension"); + return false; } // Common Part: init a Doc if necessary, and @@ -1728,40 +1729,40 @@ bool MainWindow::openProject(QString fileName) 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; - } + 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; - } + 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; - } + 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; + } } if (QString(fi.suffix()).toLower() == "out"){ @@ -1770,13 +1771,13 @@ bool MainWindow::openProject(QString fileName) QString image_list_filename; QString model_filename; - image_list_filename = QFileDialog::getOpenFileName( - this , tr("Open image list file"), - QFileInfo(fileName).absolutePath(), - tr("Bundler images list file (*.txt)") - ); - if(image_list_filename.isEmpty()) - return false; + image_list_filename = QFileDialog::getOpenFileName( + this , tr("Open image list file"), + QFileInfo(fileName).absolutePath(), + tr("Bundler images list file (*.txt)") + ); + if(image_list_filename.isEmpty()) + return false; //model_filename = QFileDialog::getOpenFileName( @@ -1814,13 +1815,13 @@ bool MainWindow::openProject(QString fileName) //QString image_list_filename; QString model_filename; - /*image_list_filename = QFileDialog::getOpenFileName( - this , tr("Open image list file"), - QFileInfo(fileName).absolutePath(), - tr("Bundler images list file (*.txt)") - ); - if(image_list_filename.isEmpty()) - return false;*/ + /*image_list_filename = QFileDialog::getOpenFileName( + this , tr("Open image list file"), + QFileInfo(fileName).absolutePath(), + tr("Bundler images list file (*.txt)") + ); + if(image_list_filename.isEmpty()) + return false;*/ //model_filename = QFileDialog::getOpenFileName( @@ -1850,7 +1851,7 @@ bool MainWindow::openProject(QString fileName) } - //////NVM + //////NVM meshDoc()->setBusy(false); if(this->GLA() == 0) return false; @@ -1865,9 +1866,9 @@ 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)"); + 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); + fileNameList.append(fileName); if (fileNameList.isEmpty()) return false; @@ -1877,65 +1878,65 @@ bool MainWindow::appendProject(QString fileName) 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; + 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(); + 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; - } + 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(); + // 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; - } + 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; - } - } + 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; - } - } + 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); @@ -2013,12 +2014,12 @@ bool MainWindow::importRaster(const QString& fileImg) return false; } - this->meshDoc()->setBusy(true); - RasterModel *rm= meshDoc()->addNewRaster(); - rm->setLabel(fileImg); - rm->addPlane(new Plane(fileName,Plane::RGBA)); - meshDoc()->setBusy(false); - showLayerDlg(true); + this->meshDoc()->setBusy(true); + RasterModel *rm= meshDoc()->addNewRaster(); + rm->setLabel(fileImg); + rm->addPlane(new Plane(fileName,Plane::RGBA)); + meshDoc()->setBusy(false); + showLayerDlg(true); /// Intrinsics extraction from EXIF /// If no CCD Width value is provided, the intrinsics are extracted using the Equivalent 35mm focal @@ -2027,38 +2028,38 @@ bool MainWindow::importRaster(const QString& fileImg) ::ResetJpgfile(); FILE * pFile = fopen(qPrintable(fileName), "rb"); - int ret = ::ReadJpegSections (pFile, READ_METADATA); - fclose(pFile); - if (!ret || (ImageInfo.CCDWidth==0.0f && ImageInfo.FocalLength35mmEquiv==0.0f)) - { - rm->shot.Intrinsics.ViewportPx = vcg::Point2i(rm->currentPlane->image.width(), rm->currentPlane->image.height()); - rm->shot.Intrinsics.CenterPx = vcg::Point2f(float(rm->currentPlane->image.width()/2.0), float(rm->currentPlane->image.width()/2.0)); - rm->shot.Intrinsics.PixelSizeMm[0]=36.0f/(float)rm->currentPlane->image.width(); - rm->shot.Intrinsics.PixelSizeMm[1]=rm->shot.Intrinsics.PixelSizeMm[0]; - rm->shot.Intrinsics.FocalMm = 50.0f; - } - else if (ImageInfo.CCDWidth!=0) - { - rm->shot.Intrinsics.ViewportPx = vcg::Point2i(ImageInfo.Width, ImageInfo.Height); - rm->shot.Intrinsics.CenterPx = vcg::Point2f(float(ImageInfo.Width/2.0), float(ImageInfo.Height/2.0)); - float ratio; - if (ImageInfo.Width>ImageInfo.Height) - ratio=(float)ImageInfo.Width/(float)ImageInfo.Height; - else - ratio=(float)ImageInfo.Height/(float)ImageInfo.Width; - rm->shot.Intrinsics.PixelSizeMm[0]=ImageInfo.CCDWidth/(float)ImageInfo.Width; - rm->shot.Intrinsics.PixelSizeMm[1]=ImageInfo.CCDWidth/((float)ImageInfo.Height*ratio); - rm->shot.Intrinsics.FocalMm = ImageInfo.FocalLength; - } - else - { - rm->shot.Intrinsics.ViewportPx = vcg::Point2i(ImageInfo.Width, ImageInfo.Height); - rm->shot.Intrinsics.CenterPx = vcg::Point2f(float(ImageInfo.Width/2.0), float(ImageInfo.Height/2.0)); - float ratioFocal=ImageInfo.FocalLength/ImageInfo.FocalLength35mmEquiv; - rm->shot.Intrinsics.PixelSizeMm[0]=(36.0f*ratioFocal)/(float)ImageInfo.Width; - rm->shot.Intrinsics.PixelSizeMm[1]=(24.0f*ratioFocal)/(float)ImageInfo.Height; - rm->shot.Intrinsics.FocalMm = ImageInfo.FocalLength; - } + int ret = ::ReadJpegSections (pFile, READ_METADATA); + fclose(pFile); + if (!ret || (ImageInfo.CCDWidth==0.0f && ImageInfo.FocalLength35mmEquiv==0.0f)) + { + rm->shot.Intrinsics.ViewportPx = vcg::Point2i(rm->currentPlane->image.width(), rm->currentPlane->image.height()); + rm->shot.Intrinsics.CenterPx = vcg::Point2f(float(rm->currentPlane->image.width()/2.0), float(rm->currentPlane->image.width()/2.0)); + rm->shot.Intrinsics.PixelSizeMm[0]=36.0f/(float)rm->currentPlane->image.width(); + rm->shot.Intrinsics.PixelSizeMm[1]=rm->shot.Intrinsics.PixelSizeMm[0]; + rm->shot.Intrinsics.FocalMm = 50.0f; + } + else if (ImageInfo.CCDWidth!=0) + { + rm->shot.Intrinsics.ViewportPx = vcg::Point2i(ImageInfo.Width, ImageInfo.Height); + rm->shot.Intrinsics.CenterPx = vcg::Point2f(float(ImageInfo.Width/2.0), float(ImageInfo.Height/2.0)); + float ratio; + if (ImageInfo.Width>ImageInfo.Height) + ratio=(float)ImageInfo.Width/(float)ImageInfo.Height; + else + ratio=(float)ImageInfo.Height/(float)ImageInfo.Width; + rm->shot.Intrinsics.PixelSizeMm[0]=ImageInfo.CCDWidth/(float)ImageInfo.Width; + rm->shot.Intrinsics.PixelSizeMm[1]=ImageInfo.CCDWidth/((float)ImageInfo.Height*ratio); + rm->shot.Intrinsics.FocalMm = ImageInfo.FocalLength; + } + else + { + rm->shot.Intrinsics.ViewportPx = vcg::Point2i(ImageInfo.Width, ImageInfo.Height); + rm->shot.Intrinsics.CenterPx = vcg::Point2f(float(ImageInfo.Width/2.0), float(ImageInfo.Height/2.0)); + float ratioFocal=ImageInfo.FocalLength/ImageInfo.FocalLength35mmEquiv; + rm->shot.Intrinsics.PixelSizeMm[0]=(36.0f*ratioFocal)/(float)ImageInfo.Width; + rm->shot.Intrinsics.PixelSizeMm[1]=(24.0f*ratioFocal)/(float)ImageInfo.Height; + rm->shot.Intrinsics.FocalMm = ImageInfo.FocalLength; + } // End of EXIF reading @@ -2099,14 +2100,14 @@ bool MainWindow::loadMesh(const QString& fileName, MeshIOInterface *pCurrentIOPl return false; } meshDoc()->setBusy(true); - pCurrentIOPlugin->setLog(&meshDoc()->Log); - if (!pCurrentIOPlugin->open(extension, fileName, *mm ,mask,*prePar,QCallBack,this /*gla*/)) - { - QMessageBox::warning(this, tr("Opening Failure"), QString("While opening: '%1'\n\n").arg(fileName)+pCurrentIOPlugin->errorMsg()); // text+ - pCurrentIOPlugin->clearErrorString(); - meshDoc()->setBusy(false); - return false; - } + pCurrentIOPlugin->setLog(&meshDoc()->Log); + if (!pCurrentIOPlugin->open(extension, fileName, *mm ,mask,*prePar,QCallBack,this /*gla*/)) + { + QMessageBox::warning(this, tr("Opening Failure"), QString("While opening: '%1'\n\n").arg(fileName)+pCurrentIOPlugin->errorMsg()); // text+ + pCurrentIOPlugin->clearErrorString(); + meshDoc()->setBusy(false); + return false; + } // After opening the mesh lets ask to the io plugin if this format // requires some optional, or userdriven post-opening processing. // and in that case ask for the required parameters and then @@ -2118,8 +2119,8 @@ bool MainWindow::loadMesh(const QString& fileName, MeshIOInterface *pCurrentIOPl QString err = pCurrentIOPlugin->errorMsg(); if (!err.isEmpty()) { - QMessageBox::warning(this, tr("Opening Problems"), QString("While opening: '%1'\n\n").arg(fileName)+pCurrentIOPlugin->errorMsg()); - pCurrentIOPlugin->clearErrorString(); + QMessageBox::warning(this, tr("Opening Problems"), QString("While opening: '%1'\n\n").arg(fileName)+pCurrentIOPlugin->errorMsg()); + pCurrentIOPlugin->clearErrorString(); } @@ -2132,58 +2133,58 @@ bool MainWindow::loadMesh(const QString& fileName, MeshIOInterface *pCurrentIOPl renderModeTextureAct->setEnabled(false); if(!meshDoc()->mm()->cm.textures.empty()) { - renderModeTextureAct->setChecked(true); - renderModeTextureAct->setEnabled(true); - if(tri::HasPerVertexTexCoord(meshDoc()->mm()->cm) ) - GLA()->setTextureMode(GLW::TMPerVert); - if(tri::HasPerWedgeTexCoord(meshDoc()->mm()->cm) ) - GLA()->setTextureMode(GLW::TMPerWedgeMulti); + renderModeTextureAct->setChecked(true); + renderModeTextureAct->setEnabled(true); + if(tri::HasPerVertexTexCoord(meshDoc()->mm()->cm) ) + GLA()->setTextureMode(GLW::TMPerVert); + if(tri::HasPerWedgeTexCoord(meshDoc()->mm()->cm) ) + GLA()->setTextureMode(GLW::TMPerWedgeMulti); } // In case of polygonal meshes the normal should be updated accordingly if( mask & vcg::tri::io::Mask::IOM_BITPOLYGONAL) { - mm->updateDataMask(MeshModel::MM_POLYGONAL); // just to be sure. Hopefully it should be done in the plugin... - int degNum = tri::Clean::RemoveDegenerateFace(mm->cm); - if(degNum) - GLA()->Logf(0,"Warning model contains %i degenerate faces. Removed them.",degNum); - mm->updateDataMask(MeshModel::MM_FACEFACETOPO); - vcg::tri::UpdateNormal::PerBitQuadFaceNormalized(mm->cm); - vcg::tri::UpdateNormal::PerVertexFromCurrentFaceNormal(mm->cm); + mm->updateDataMask(MeshModel::MM_POLYGONAL); // just to be sure. Hopefully it should be done in the plugin... + int degNum = tri::Clean::RemoveDegenerateFace(mm->cm); + if(degNum) + GLA()->Logf(0,"Warning model contains %i degenerate faces. Removed them.",degNum); + mm->updateDataMask(MeshModel::MM_FACEFACETOPO); + vcg::tri::UpdateNormal::PerBitQuadFaceNormalized(mm->cm); + vcg::tri::UpdateNormal::PerVertexFromCurrentFaceNormal(mm->cm); } // standard case else { - vcg::tri::UpdateNormal::PerFaceNormalized(mm->cm); - if(!( mask & vcg::tri::io::Mask::IOM_VERTNORMAL) ) - vcg::tri::UpdateNormal::PerVertexAngleWeighted(mm->cm); + vcg::tri::UpdateNormal::PerFaceNormalized(mm->cm); + if(!( mask & vcg::tri::io::Mask::IOM_VERTNORMAL) ) + vcg::tri::UpdateNormal::PerVertexAngleWeighted(mm->cm); } vcg::tri::UpdateBounding::Box(mm->cm); // updates bounding box if(mm->cm.fn==0 && mm->cm.en==0){ - GLA()->setDrawMode(vcg::GLW::DMPoints); - if(!(mask & vcg::tri::io::Mask::IOM_VERTNORMAL)) - GLA()->setLight(false); - else - mm->updateDataMask(MeshModel::MM_VERTNORMAL); + GLA()->setDrawMode(vcg::GLW::DMPoints); + if(!(mask & vcg::tri::io::Mask::IOM_VERTNORMAL)) + GLA()->setLight(false); + else + mm->updateDataMask(MeshModel::MM_VERTNORMAL); } if(mm->cm.fn==0 && mm->cm.en>0){ - GLA()->setDrawMode(vcg::GLW::DMWire); - if(!(mask & vcg::tri::io::Mask::IOM_VERTNORMAL)) - GLA()->setLight(false); - else - mm->updateDataMask(MeshModel::MM_VERTNORMAL); + GLA()->setDrawMode(vcg::GLW::DMWire); + if(!(mask & vcg::tri::io::Mask::IOM_VERTNORMAL)) + GLA()->setLight(false); + else + mm->updateDataMask(MeshModel::MM_VERTNORMAL); } else - mm->updateDataMask(MeshModel::MM_VERTNORMAL); + mm->updateDataMask(MeshModel::MM_VERTNORMAL); updateMenus(); int delVertNum = vcg::tri::Clean::RemoveDegenerateVertex(mm->cm); int delFaceNum = vcg::tri::Clean::RemoveDegenerateFace(mm->cm); if(delVertNum>0 || delFaceNum>0 ) - QMessageBox::warning(this, "MeshLab Warning", QString("Warning mesh contains %1 vertices with NAN coords and %2 degenerated faces.\nCorrected.").arg(delVertNum).arg(delFaceNum) ); + QMessageBox::warning(this, "MeshLab Warning", QString("Warning mesh contains %1 vertices with NAN coords and %2 degenerated faces.\nCorrected.").arg(delVertNum).arg(delFaceNum) ); meshDoc()->setBusy(false); - return true; + return true; } // Opening files in a transparent form (IO plugins contribution is hidden to user) @@ -2193,14 +2194,14 @@ bool MainWindow::importMesh(QString fileName) //QStringList suffixList; // HashTable storing all supported formats together with - // the (1-based) index of first plugin which is able to open it + // the (1-based) index of first plugin which is able to open it //QHash allKnownFormats; //PM.LoadFormats(suffixList, allKnownFormats,PluginManager::IMPORT); QStringList fileNameList; - if (fileName.isEmpty()) - fileNameList = QFileDialog::getOpenFileNames(this,tr("Import Mesh"), lastUsedDirectory.path(), PM.inpFilters.join(";;")); - else - fileNameList.push_back(fileName); + if (fileName.isEmpty()) + fileNameList = QFileDialog::getOpenFileNames(this,tr("Import Mesh"), lastUsedDirectory.path(), PM.inpFilters.join(";;")); + else + fileNameList.push_back(fileName); if (fileNameList.isEmpty()) return false; else @@ -2249,7 +2250,7 @@ bool MainWindow::importMesh(QString fileName) if(!par.isEmpty()) { GenericParamDialog postOpenDialog(this, &par, tr("Post-Open Processing")); - postOpenDialog.setFocus(); + postOpenDialog.setFocus(); postOpenDialog.exec(); pCurrentIOPlugin->applyOpenParameter(extension, *mm, par); } @@ -2271,7 +2272,7 @@ void MainWindow::openRecentMesh() { if(!GLA()) return; if(meshDoc()->isBusy()) return; - QAction *action = qobject_cast(sender()); + QAction *action = qobject_cast(sender()); if (action) importMesh(action->data().toString()); } @@ -2339,22 +2340,22 @@ bool MainWindow::exportMesh(QString fileName,MeshModel* mod,const bool saveAllPo QStringList& suffixList = PM.outFilters; //QHash allKnownFormats; - QFileInfo fi(fileName); + QFileInfo fi(fileName); //PM.LoadFormats( suffixList, allKnownFormats,PluginManager::EXPORT); - //QString defaultExt = "*." + mod->suffixName().toLower(); - QString defaultExt = "*." + fi.suffix().toLower(); - if(defaultExt == "*.") - defaultExt = "*.ply"; - if (mod == NULL) - return false; - mod->meshModified() = false; - QString laylabel = "Save \"" + mod->label() + "\" Layer"; - QFileDialog saveDialog(this,laylabel, mod->fullName()); + //QString defaultExt = "*." + mod->suffixName().toLower(); + QString defaultExt = "*." + fi.suffix().toLower(); + if(defaultExt == "*.") + defaultExt = "*.ply"; + if (mod == NULL) + return false; + mod->meshModified() = false; + QString laylabel = "Save \"" + mod->label() + "\" Layer"; + QFileDialog saveDialog(this,laylabel, mod->fullName()); saveDialog.setNameFilters(suffixList); - saveDialog.setAcceptMode(QFileDialog::AcceptSave); + saveDialog.setAcceptMode(QFileDialog::AcceptSave); QStringList matchingExtensions=suffixList.filter(defaultExt); - if(!matchingExtensions.isEmpty()) - saveDialog.selectNameFilter(matchingExtensions.last()); + if(!matchingExtensions.isEmpty()) + saveDialog.selectNameFilter(matchingExtensions.last()); if (fileName.isEmpty()){ int dialogRet = saveDialog.exec(); @@ -2457,7 +2458,7 @@ bool MainWindow::saveAs(QString fileName,const bool saveAllPossibleAttributes) bool MainWindow::saveSnapshot() { - SaveSnapshotDialog dialog(this); + SaveSnapshotDialog dialog(this); dialog.setValues(GLA()->ss); @@ -2466,16 +2467,16 @@ bool MainWindow::saveSnapshot() GLA()->ss=dialog.getValues(); GLA()->saveSnapshot(); - // if user ask to add the snapshot to raster layers - /* - if(dialog.addToRasters()) - { - QString savedfile = QString("%1/%2%3.png") - .arg(GLA()->ss.outdir).arg(GLA()->ss.basename) - .arg(GLA()->ss.counter,2,10,QChar('0')); + // if user ask to add the snapshot to raster layers + /* + if(dialog.addToRasters()) + { + QString savedfile = QString("%1/%2%3.png") + .arg(GLA()->ss.outdir).arg(GLA()->ss.basename) + .arg(GLA()->ss.counter,2,10,QChar('0')); - importRaster(savedfile); - } + importRaster(savedfile); + } */ return true; } @@ -2494,9 +2495,9 @@ void MainWindow::about() void MainWindow::aboutPlugins() { - qDebug( "aboutPlugins(): Current Plugins Dir: %s ",qPrintable(pluginManager().getDefaultPluginDirPath())); - PluginDialog dialog(pluginManager().getDefaultPluginDirPath(), pluginManager().pluginsLoaded, this); - dialog.exec(); + qDebug( "aboutPlugins(): Current Plugins Dir: %s ",qPrintable(pluginManager().getDefaultPluginDirPath())); + PluginDialog dialog(pluginManager().getDefaultPluginDirPath(), pluginManager().pluginsLoaded, this); + dialog.exec(); } void MainWindow::helpOnscreen() @@ -2507,7 +2508,7 @@ if(GLA()) GLA()->toggleHelpVisible(); void MainWindow::helpOnline() { checkForUpdates(false); - QDesktopServices::openUrl(QUrl("http://sourceforge.net/apps/mediawiki/meshlab")); + QDesktopServices::openUrl(QUrl("http://sourceforge.net/apps/mediawiki/meshlab")); } @@ -2554,35 +2555,35 @@ void MainWindow::renderHiddenLines() { GLA()->setDrawMode(GLW::DMHidden ); } void MainWindow::renderSmooth() { GLA()->setDrawMode(GLW::DMSmooth ); } void MainWindow::renderTexture() { - QAction *a = qobject_cast(sender()); + QAction *a = qobject_cast(sender()); if( tri::HasPerVertexTexCoord(meshDoc()->mm()->cm)) - GLA()->setTextureMode(!a->isChecked() ? GLW::TMNone : GLW::TMPerVert); + GLA()->setTextureMode(!a->isChecked() ? GLW::TMNone : GLW::TMPerVert); if( tri::HasPerWedgeTexCoord(meshDoc()->mm()->cm)) - GLA()->setTextureMode(!a->isChecked() ? GLW::TMNone : GLW::TMPerWedgeMulti); + GLA()->setTextureMode(!a->isChecked() ? GLW::TMNone : GLW::TMPerWedgeMulti); } void MainWindow::fullScreen(){ if(!isFullScreen()) { - toolbarState = saveState(); - menuBar()->hide(); - mainToolBar->hide(); - renderToolBar->hide(); - globalStatusBar()->hide(); - setWindowState(windowState()^Qt::WindowFullScreen); - bool found=true; - //Caso di piu' finestre aperte in tile: - if((mdiarea->subWindowList()).size()>1){ - foreach(QWidget *w,mdiarea->subWindowList()){if(w->isMaximized()) found=false;} - if (found)mdiarea->tileSubWindows(); - } + toolbarState = saveState(); + menuBar()->hide(); + mainToolBar->hide(); + renderToolBar->hide(); + globalStatusBar()->hide(); + setWindowState(windowState()^Qt::WindowFullScreen); + bool found=true; + //Caso di piu' finestre aperte in tile: + if((mdiarea->subWindowList()).size()>1){ + foreach(QWidget *w,mdiarea->subWindowList()){if(w->isMaximized()) found=false;} + if (found)mdiarea->tileSubWindows(); + } } else { - menuBar()->show(); - restoreState(toolbarState); - globalStatusBar()->show(); + menuBar()->show(); + restoreState(toolbarState); + globalStatusBar()->show(); setWindowState(windowState()^ Qt::WindowFullScreen); bool found=true; @@ -2599,8 +2600,8 @@ void MainWindow::keyPressEvent(QKeyEvent *e) { if(e->key()==Qt::Key_Return && e->modifiers()==Qt::AltModifier) { - fullScreen(); - e->accept(); + fullScreen(); + e->accept(); } else e->ignore(); }