Skip to content

Commit

Permalink
saving view state in project is now optional
Browse files Browse the repository at this point in the history
added checkbox in project saving window. Default is ON (save state).
  • Loading branch information
mcallieri committed Aug 29, 2018
1 parent b1b7728 commit 68f4b09
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
53 changes: 26 additions & 27 deletions src/common/meshlabdocumentxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#include "meshlabdocumentxml.h"
#include <wrap/qt/shot_qt.h>

bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers, bool binary, const std::map<int, MLRenderingData>& rendOpt)
bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers, bool saveViewState, bool binary, const std::map<int, MLRenderingData>& 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);
Expand Down Expand Up @@ -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<int, std::string>(mm->id(), value.toStdString()));
}*/
QDomNode tr = mesh.firstChildElement("MLMatrix44");

if (!tr.isNull())
Expand Down Expand Up @@ -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;
}

Expand All @@ -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<int, MLRenderingData>& rendOpt)
QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool saveViewState, bool binary, const std::map<int, MLRenderingData>& rendOpt)
{
QDomDocument ddoc("MeshLabDocument");

Expand All @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/meshlabdocumentxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include<map>


QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool binary, const std::map<int, MLRenderingData>& rendOpt = std::map<int, MLRenderingData>());
bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers, bool binary, const std::map<int, MLRenderingData>& rendOpt = std::map<int, MLRenderingData>());
QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool saveViewState, bool binary, const std::map<int, MLRenderingData>& rendOpt = std::map<int, MLRenderingData>());
bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers, bool saveViewState, bool binary, const std::map<int, MLRenderingData>& rendOpt = std::map<int, MLRenderingData>());
bool MeshDocumentFromXML(MeshDocument &md, QString filename, bool binary, std::map<int, MLRenderingData>& rendOpt);
QDomElement RasterModelToXML(RasterModel *mp,QDomDocument &doc, bool binary);
QDomElement PlaneToXML(Plane* pl,const QString& basePath,QDomDocument& doc);
Expand Down
21 changes: 12 additions & 9 deletions src/meshlab/mainwindow_RunTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QGridLayout*>(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();
Expand Down Expand Up @@ -2215,13 +2218,13 @@ void MainWindow::saveProject()
else
{
std::map<int, MLRenderingData> rendOpt;
foreach(MeshModel * mp, meshDoc()->meshList)
{
MLRenderingData ml;
getRenderingData(mp->id(), ml);
rendOpt.insert(std::pair<int, MLRenderingData>(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<int, MLRenderingData>(mp->id(), ml));
}
ret = MeshDocumentToXMLFile(*meshDoc(), fileName, onlyVisibleLayers->isChecked(), saveViewState->isChecked(), QString(fi.suffix()).toLower() == "mlb", rendOpt);
}

if (saveAllFile->isChecked())
Expand Down
2 changes: 1 addition & 1 deletion src/meshlabserver/mainserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68f4b09

Please sign in to comment.