diff --git a/src/common/meshlabdocumentxml.cpp b/src/common/meshlabdocumentxml.cpp index aab8660873..097022d54e 100644 --- a/src/common/meshlabdocumentxml.cpp +++ b/src/common/meshlabdocumentxml.cpp @@ -6,13 +6,13 @@ #include "meshlabdocumentxml.h" #include -bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers, bool binary, const std::map& rendOpt) +bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers, bool saveViewState, bool binary, const std::map& rendOpt) { md.setFileName(filename); QFileInfo fi(filename); QDir tmpDir = QDir::current(); QDir::setCurrent(fi.absoluteDir().absolutePath()); - QDomDocument doc = MeshDocumentToXML(md, onlyVisibleLayers, binary, rendOpt); + QDomDocument doc = MeshDocumentToXML(md, onlyVisibleLayers, saveViewState, binary, rendOpt); QFile file(filename); file.open(QIODevice::WriteOnly); QTextStream qstream(&file); @@ -80,11 +80,6 @@ bool MeshDocumentFromXML(MeshDocument &md, QString filename, bool binary, std::m visible = (mesh.attributes().namedItem("visible").nodeValue().toInt() == 1); MeshModel* mm = md.addNewMesh(filen, label); mm->visible = visible; - /*if (mesh.attributes().contains("renderingOptions")) - { - QString value = mesh.attributes().namedItem("renderingOptions").nodeValue(); - rendOpt.insert(std::pair(mm->id(), value.toStdString())); - }*/ QDomNode tr = mesh.firstChildElement("MLMatrix44"); if (!tr.isNull()) @@ -181,33 +176,37 @@ bool MeshDocumentFromXML(MeshDocument &md, QString filename, bool binary, std::m return true; } -QDomElement MeshModelToXML(MeshModel *mp, QDomDocument &doc, bool binary, const MLRenderingData& rendOpt = MLRenderingData()) +QDomElement MeshModelToXML(MeshModel *mp, QDomDocument &doc, bool binary, bool saveViewState, const MLRenderingData& rendOpt = MLRenderingData()) { QDomElement meshElem = doc.createElement("MLMesh"); meshElem.setAttribute("label", mp->label()); meshElem.setAttribute("filename", mp->relativePathName()); - meshElem.setAttribute("visible", mp->isVisible()); + meshElem.setAttribute("visible", saveViewState?mp->isVisible():true); if (binary) meshElem.appendChild(Matrix44mToBinaryXML(mp->cm.Tr, doc)); else meshElem.appendChild(Matrix44mToXML(mp->cm.Tr, doc)); - - QDomElement renderingElem = doc.createElement("RenderingOption"); - std::string text; - rendOpt.serialize(text); - QDomText nd = doc.createTextNode(QString(text.c_str())); - renderingElem.appendChild(nd); - MLRenderingData::GLOptionsType opt; - if (rendOpt.get(opt)) + + if (saveViewState) { - renderingElem.setAttribute("boxColor", QString("%1 %2 %3 %4").arg(opt._perbbox_fixed_color[0]).arg(opt._perbbox_fixed_color[1]).arg(opt._perbbox_fixed_color[2]).arg(opt._perbbox_fixed_color[3])); - renderingElem.setAttribute("pointColor", QString("%1 %2 %3 %4").arg(opt._perpoint_fixed_color[0]).arg(opt._perpoint_fixed_color[1]).arg(opt._perpoint_fixed_color[2]).arg(opt._perpoint_fixed_color[3])); - renderingElem.setAttribute("wireColor", QString("%1 %2 %3 %4").arg(opt._perwire_fixed_color[0]).arg(opt._perwire_fixed_color[1]).arg(opt._perwire_fixed_color[2]).arg(opt._perwire_fixed_color[3])); - renderingElem.setAttribute("solidColor", QString("%1 %2 %3 %4").arg(opt._persolid_fixed_color[0]).arg(opt._persolid_fixed_color[1]).arg(opt._persolid_fixed_color[2]).arg(opt._persolid_fixed_color[3])); - renderingElem.setAttribute("pointSize", opt._perpoint_pointsize); - renderingElem.setAttribute("wireWidth", opt._perwire_wirewidth); + QDomElement renderingElem = doc.createElement("RenderingOption"); + std::string text; + rendOpt.serialize(text); + QDomText nd = doc.createTextNode(QString(text.c_str())); + renderingElem.appendChild(nd); + MLRenderingData::GLOptionsType opt; + if (rendOpt.get(opt)) + { + renderingElem.setAttribute("boxColor", QString("%1 %2 %3 %4").arg(opt._perbbox_fixed_color[0]).arg(opt._perbbox_fixed_color[1]).arg(opt._perbbox_fixed_color[2]).arg(opt._perbbox_fixed_color[3])); + renderingElem.setAttribute("pointColor", QString("%1 %2 %3 %4").arg(opt._perpoint_fixed_color[0]).arg(opt._perpoint_fixed_color[1]).arg(opt._perpoint_fixed_color[2]).arg(opt._perpoint_fixed_color[3])); + renderingElem.setAttribute("wireColor", QString("%1 %2 %3 %4").arg(opt._perwire_fixed_color[0]).arg(opt._perwire_fixed_color[1]).arg(opt._perwire_fixed_color[2]).arg(opt._perwire_fixed_color[3])); + renderingElem.setAttribute("solidColor", QString("%1 %2 %3 %4").arg(opt._persolid_fixed_color[0]).arg(opt._persolid_fixed_color[1]).arg(opt._persolid_fixed_color[2]).arg(opt._persolid_fixed_color[3])); + renderingElem.setAttribute("pointSize", opt._perpoint_pointsize); + renderingElem.setAttribute("wireWidth", opt._perwire_wirewidth); + } + meshElem.appendChild(renderingElem); } - meshElem.appendChild(renderingElem); + return meshElem; } @@ -233,7 +232,7 @@ QDomElement PlaneToXML(Plane* pl, const QString& basePath, QDomDocument& doc) return planeElem; } -QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool binary, const std::map& rendOpt) +QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool saveViewState, bool binary, const std::map& rendOpt) { QDomDocument ddoc("MeshLabDocument"); @@ -247,9 +246,9 @@ QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool bi { QDomElement meshElem; if (rendOpt.find(mmp->id()) != rendOpt.end()) - meshElem = MeshModelToXML(mmp, ddoc, binary, rendOpt.at(mmp->id())); + meshElem = MeshModelToXML(mmp, ddoc, binary, saveViewState, rendOpt.at(mmp->id())); else - meshElem = MeshModelToXML(mmp, ddoc, binary); + meshElem = MeshModelToXML(mmp, ddoc, binary, saveViewState); mgroot.appendChild(meshElem); } } diff --git a/src/common/meshlabdocumentxml.h b/src/common/meshlabdocumentxml.h index d9610bde51..36ddcdfc6d 100644 --- a/src/common/meshlabdocumentxml.h +++ b/src/common/meshlabdocumentxml.h @@ -8,8 +8,8 @@ #include -QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool binary, const std::map& rendOpt = std::map()); -bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers, bool binary, const std::map& rendOpt = std::map()); +QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool saveViewState, bool binary, const std::map& rendOpt = std::map()); +bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers, bool saveViewState, bool binary, const std::map& rendOpt = std::map()); bool MeshDocumentFromXML(MeshDocument &md, QString filename, bool binary, std::map& rendOpt); QDomElement RasterModelToXML(RasterModel *mp,QDomDocument &doc, bool binary); QDomElement PlaneToXML(Plane* pl,const QString& basePath,QDomDocument& doc); diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index 4349185c31..c33c9dae5f 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -2150,11 +2150,14 @@ void MainWindow::saveProject() saveAllFile->setCheckState(Qt::Unchecked); QCheckBox* onlyVisibleLayers = new QCheckBox(QString("Only Visible Layers"),saveDiag); onlyVisibleLayers->setCheckState(Qt::Unchecked); + QCheckBox* saveViewState = new QCheckBox(QString("Save View State"), saveDiag); + saveViewState->setCheckState(Qt::Checked); QGridLayout* layout = qobject_cast(saveDiag->layout()); if (layout != NULL) { - layout->addWidget(saveAllFile,4,2); - layout->addWidget(onlyVisibleLayers,4,1); + layout->addWidget(onlyVisibleLayers, 4, 0); + layout->addWidget(saveViewState, 4, 1); + layout->addWidget(saveAllFile, 4, 2); } saveDiag->setAcceptMode(QFileDialog::AcceptSave); saveDiag->exec(); @@ -2215,13 +2218,13 @@ void MainWindow::saveProject() else { std::map rendOpt; - foreach(MeshModel * mp, meshDoc()->meshList) - { - MLRenderingData ml; - getRenderingData(mp->id(), ml); - rendOpt.insert(std::pair(mp->id(), ml)); - } - ret = MeshDocumentToXMLFile(*meshDoc(), fileName, onlyVisibleLayers->isChecked(), QString(fi.suffix()).toLower() == "mlb", rendOpt); + foreach(MeshModel * mp, meshDoc()->meshList) + { + MLRenderingData ml; + getRenderingData(mp->id(), ml); + rendOpt.insert(std::pair(mp->id(), ml)); + } + ret = MeshDocumentToXMLFile(*meshDoc(), fileName, onlyVisibleLayers->isChecked(), saveViewState->isChecked(), QString(fi.suffix()).toLower() == "mlb", rendOpt); } if (saveAllFile->isChecked()) diff --git a/src/meshlabserver/mainserver.cpp b/src/meshlabserver/mainserver.cpp index efeac05562..90ce0b8540 100644 --- a/src/meshlabserver/mainserver.cpp +++ b/src/meshlabserver/mainserver.cpp @@ -299,7 +299,7 @@ class MeshLabServer } QDir::setCurrent(curDir.absolutePath()); - return MeshDocumentToXMLFile(md,filename,false, outprojinfo.suffix().toLower() == "mlb"); + return MeshDocumentToXMLFile(md, filename, false, false, outprojinfo.suffix().toLower() == "mlb"); } bool script(MeshDocument &meshDocument,const QString& scriptfile,FILE* fp)