log refactoring

This commit is contained in:
alemuntoni 2021-03-01 17:25:35 +01:00
parent c4a2bee41f
commit 3ced3041a4
11 changed files with 97 additions and 97 deletions

View File

@ -28,88 +28,87 @@
#include "GLLogStream.h"
using namespace std;
GLLogStream::GLLogStream()
:QObject()
GLLogStream::GLLogStream() :
QObject(), bookmark(-1)
{
ClearBookmark();
}
void GLLogStream::RealTimeLog(const QString& Id, const QString &meshName, const QString& text)
void GLLogStream::realTimeLog(const QString& Id, const QString &meshName, const QString& text)
{
this->RealTimeLogText.insert(Id,qMakePair(meshName,text) );
this->realTimeLogText.insert(Id,qMakePair(meshName,text) );
}
void GLLogStream::Save(int /*Level*/, const char * filename )
void GLLogStream::save(int /*Level*/, const char * filename )
{
FILE *fp=fopen(filename,"wb");
QList<pair <int,QString> > ::iterator li;
for(li=S.begin();li!=S.end();++li)
for(li=logTextList.begin();li!=logTextList.end();++li)
fprintf(fp,"%s", qUtf8Printable((*li).second));
}
void GLLogStream::ClearBookmark()
void GLLogStream::clearBookmark()
{
bookmark = -1;
}
void GLLogStream::SetBookmark()
void GLLogStream::setBookmark()
{
bookmark=S.size();
bookmark=logTextList.size();
}
void GLLogStream::BackToBookmark()
void GLLogStream::backToBookmark()
{
if(bookmark<0) return;
while(S.size() > bookmark )
S.removeLast();
while(logTextList.size() > bookmark )
logTextList.removeLast();
}
const QList<std::pair<int, QString> >& GLLogStream::logStringList() const
{
return S;
return logTextList;
}
const QMultiMap<QString, QPair<QString, QString> >& GLLogStream::realTimeLogMultiMap() const
{
return RealTimeLogText;
return realTimeLogText;
}
void GLLogStream::clearRealTimeLog()
{
RealTimeLogText.clear();
realTimeLogText.clear();
}
void GLLogStream::print(QStringList &out) const
{
out.clear();
for (const pair <int,QString>& p : S)
for (const pair <int,QString>& p : logTextList)
out.push_back(p.second);
}
void GLLogStream::Clear()
void GLLogStream::clear()
{
S.clear();
logTextList.clear();
}
void GLLogStream::Log(int Level, const char * buf )
void GLLogStream::log(int Level, const char * buf )
{
QString tmp(buf);
S.push_back(std::make_pair(Level,tmp));
logTextList.push_back(std::make_pair(Level,tmp));
qDebug("LOG: %i %s",Level,buf);
emit logUpdated();
}
void GLLogStream::Log(int Level, const string& logMessage)
void GLLogStream::log(int Level, const string& logMessage)
{
S.push_back(std::make_pair(Level, QString::fromStdString(logMessage)));
logTextList.push_back(std::make_pair(Level, QString::fromStdString(logMessage)));
qDebug("LOG: %i %s",Level, logMessage.c_str());
emit logUpdated();
}
void GLLogStream::Log(int Level, const QString& logMessage)
void GLLogStream::log(int Level, const QString& logMessage)
{
S.push_back(std::make_pair(Level, logMessage));
logTextList.push_back(std::make_pair(Level, logMessage));
qDebug("LOG: %i %s",Level, logMessage.toStdString().c_str());
emit logUpdated();
}

View File

@ -52,56 +52,56 @@ public:
GLLogStream();
~GLLogStream() {}
void print(QStringList &list) const; // Fills a QStringList with the log entries
void Save(int Level, const char *filename);
void Clear();
void save(int Level, const char *filename);
void clear();
template <typename... Ts>
void Logf(int Level, const char * f, Ts&&... ts )
void logf(int Level, const char * f, Ts&&... ts )
{
char buf[buf_size];
int chars_written = snprintf(buf, buf_size, f, std::forward<Ts>(ts)...);
Log(Level, buf);
log(Level, buf);
if(chars_written >= static_cast<int>(buf_size)){
Log(Level, "Log message truncated.");
log(Level, "Log message truncated.");
}
}
void Log(int Level, const char * buf);
void Log(int Level, const std::string& logMessage);
void Log(int Level, const QString& logMessage);
void SetBookmark();
void ClearBookmark();
void BackToBookmark();
void log(int Level, const char * buf);
void log(int Level, const std::string& logMessage);
void log(int Level, const QString& logMessage);
void setBookmark();
void clearBookmark();
void backToBookmark();
const QList<std::pair<int, QString> >& logStringList() const;
const QMultiMap<QString, QPair<QString, QString> >& realTimeLogMultiMap() const;
void clearRealTimeLog();
template <typename... Ts>
void RealTimeLogf(const QString& Id, const QString &meshName, const char * f, Ts&&... ts )
void realTimeLogf(const QString& Id, const QString &meshName, const char * f, Ts&&... ts )
{
char buf[buf_size];
int chars_written = snprintf(buf, buf_size, f, std::forward<Ts>(ts)...);
RealTimeLog(Id, meshName, buf);
realTimeLog(Id, meshName, buf);
if(chars_written >= static_cast<int>(buf_size)){
RealTimeLog(Id, meshName, "Log message truncated.");
realTimeLog(Id, meshName, "Log message truncated.");
}
}
void RealTimeLog(const QString& Id, const QString &meshName, const QString& text);
void realTimeLog(const QString& Id, const QString &meshName, const QString& text);
signals:
void logUpdated();
private:
int bookmark; /// this field is used to place a bookmark for restoring the log. Useful for previeweing
QList<std::pair<int, QString> > S;
QList<std::pair<int, QString> > logTextList;
// The list of strings used in realtime display of info over the mesh.
// Each box is identified by the title, name of the mesh and text.
// the name of the mesh is shown only if two or more box with the same title are shown.
QMultiMap<QString, QPair<QString, QString> > RealTimeLogText;
QMultiMap<QString, QPair<QString, QString> > realTimeLogText;
};
#endif //GLLOGSTREAM_H

View File

@ -13,34 +13,34 @@ void PluginInterface::setLog(GLLogStream* log)
void PluginInterface::log(const char* s)
{
if(logstream != nullptr) {
logstream->Log(GLLogStream::FILTER, s);
logstream->log(GLLogStream::FILTER, s);
}
}
void PluginInterface::log(const std::string& s)
{
if(logstream != nullptr) {
logstream->Log(GLLogStream::FILTER, s);
logstream->log(GLLogStream::FILTER, s);
}
}
void PluginInterface::log(GLLogStream::Levels level, const char* s)
{
if(logstream != nullptr) {
logstream->Log(level, s);
logstream->log(level, s);
}
}
void PluginInterface::log(GLLogStream::Levels level, const std::string& s)
{
if(logstream != nullptr) {
logstream->Log(level, s);
logstream->log(level, s);
}
}
void PluginInterface::realTimeLog(QString Id, const QString& meshName, const char* f)
{
if(logstream != nullptr) {
logstream->RealTimeLog(Id, meshName, f);
logstream->realTimeLog(Id, meshName, f);
}
}

View File

@ -91,7 +91,7 @@ template<typename... Ts>
void PluginInterface::log(const char* f, Ts&&... ts)
{
if(logstream != nullptr) {
logstream->Logf(GLLogStream::FILTER, f, std::forward<Ts>(ts)...);
logstream->logf(GLLogStream::FILTER, f, std::forward<Ts>(ts)...);
}
}
@ -99,7 +99,7 @@ template<typename... Ts>
void PluginInterface::log(const std::string& s, Ts&&... ts)
{
if(logstream != nullptr) {
logstream->Logf(GLLogStream::FILTER, s.c_str(), std::forward<Ts>(ts)...);
logstream->logf(GLLogStream::FILTER, s.c_str(), std::forward<Ts>(ts)...);
}
}
@ -107,7 +107,7 @@ template <typename... Ts>
void PluginInterface::log(GLLogStream::Levels Level, const char* f, Ts&&... ts)
{
if(logstream != nullptr) {
logstream->Logf(Level, f, std::forward<Ts>(ts)...);
logstream->logf(Level, f, std::forward<Ts>(ts)...);
}
}
@ -115,7 +115,7 @@ template <typename... Ts>
void PluginInterface::realTimeLog(QString Id, const QString& meshName, const char* f, Ts&&... ts)
{
if(logstream != nullptr) {
logstream->RealTimeLogf(Id, meshName, f, std::forward<Ts>(ts)...);
logstream->realTimeLogf(Id, meshName, f, std::forward<Ts>(ts)...);
}
}

View File

@ -36,8 +36,8 @@
#include <QDir>
/**
\brief This class provides the basic tools for managing all the plugins. It is used by both meshlab and meshlab server.
*/
* @brief The PluginManager class provides the basic tools for managing all the plugins.
*/
class PluginManager
{
public:

View File

@ -947,7 +947,7 @@ void GLArea::displayHelp()
tableText.replace("Ctrl","Command");
#endif
}
md()->Log.RealTimeLog("Quick Help","",tableText);
md()->Log.realTimeLog("Quick Help","",tableText);
}

View File

@ -138,7 +138,7 @@ public:
{
makeCurrent();
if( this->md() != nullptr){
this->md()->Log.Logf(Level, f, std::forward<Ts>(ts)...);
this->md()->Log.logf(Level, f, std::forward<Ts>(ts)...);
}
}
@ -146,7 +146,7 @@ public:
{
makeCurrent();
if( this->md() != nullptr){
this->md()->Log.Log(Level, f);
this->md()->Log.log(Level, f);
}
}

View File

@ -144,17 +144,17 @@ void LayerDialog::clickW1()
viewState[0] = mw->GLA()->viewToText();
isRecording = false;
ui->bW1->setText(QChar(0x2460));
mw->meshDoc()->Log.Log(0, "Stored View #1");
mw->meshDoc()->Log.log(0, "Stored View #1");
}
else if (viewState[0] != "")
{
QDomDocument doc("StringDoc");
doc.setContent(viewState[0]);
mw->GLA()->loadViewFromViewStateFile(doc);
mw->meshDoc()->Log.Log(0, "Restored View #1");
mw->meshDoc()->Log.log(0, "Restored View #1");
}
else
mw->meshDoc()->Log.Log(0, "No View to Restore");
mw->meshDoc()->Log.log(0, "No View to Restore");
}
void LayerDialog::clickW2()
@ -164,17 +164,17 @@ void LayerDialog::clickW2()
viewState[1] = mw->GLA()->viewToText();
isRecording = false;
ui->bW2->setText(QChar(0x2461));
mw->meshDoc()->Log.Log(0, "Stored View #2");
mw->meshDoc()->Log.log(0, "Stored View #2");
}
else if (viewState[1] != "")
{
QDomDocument doc("StringDoc");
doc.setContent(viewState[1]);
mw->GLA()->loadViewFromViewStateFile(doc);
mw->meshDoc()->Log.Log(0, "Restored View #2");
mw->meshDoc()->Log.log(0, "Restored View #2");
}
else
mw->meshDoc()->Log.Log(0, "No View to Restore");
mw->meshDoc()->Log.log(0, "No View to Restore");
}
void LayerDialog::clickW3()
@ -184,17 +184,17 @@ void LayerDialog::clickW3()
viewState[2] = mw->GLA()->viewToText();
isRecording = false;
ui->bW3->setText(QChar(0x2462));
mw->meshDoc()->Log.Log(0, "Stored View #3");
mw->meshDoc()->Log.log(0, "Stored View #3");
}
else if (viewState[2] != "")
{
QDomDocument doc("StringDoc");
doc.setContent(viewState[2]);
mw->GLA()->loadViewFromViewStateFile(doc);
mw->meshDoc()->Log.Log(0, "Restored View #3");
mw->meshDoc()->Log.log(0, "Restored View #3");
}
else
mw->meshDoc()->Log.Log(0, "No View to Restore");
mw->meshDoc()->Log.log(0, "No View to Restore");
}
void LayerDialog::clickW4()
@ -204,17 +204,17 @@ void LayerDialog::clickW4()
viewState[3] = mw->GLA()->viewToText();
isRecording = false;
ui->bW4->setText(QChar(0x2463));
mw->meshDoc()->Log.Log(0, "Stored View #4");
mw->meshDoc()->Log.log(0, "Stored View #4");
}
else if (viewState[3] != "")
{
QDomDocument doc("StringDoc");
doc.setContent(viewState[3]);
mw->GLA()->loadViewFromViewStateFile(doc);
mw->meshDoc()->Log.Log(0, "Restored View #4");
mw->meshDoc()->Log.log(0, "Restored View #4");
}
else
mw->meshDoc()->Log.Log(0, "No View to Restore");
mw->meshDoc()->Log.log(0, "No View to Restore");
}
void LayerDialog::clickV1()
@ -229,7 +229,7 @@ void LayerDialog::clickV1()
}
isRecording = false;
ui->bV1->setText(QChar(0x2460));
mw->meshDoc()->Log.Log(0, "Stored Visibility #1");
mw->meshDoc()->Log.log(0, "Stored Visibility #1");
}
else if (!visibilityState[0].isEmpty())
{
@ -242,10 +242,10 @@ void LayerDialog::clickV1()
updatePerMeshItemVisibility();
updatePerMeshItemSelectionStatus();
mw->GLA()->update();
mw->meshDoc()->Log.Log(0, "Restored Visibility #1");
mw->meshDoc()->Log.log(0, "Restored Visibility #1");
}
else
mw->meshDoc()->Log.Log(0, "No Visibility to Restore");
mw->meshDoc()->Log.log(0, "No Visibility to Restore");
}
void LayerDialog::clickV2()
{
@ -259,7 +259,7 @@ void LayerDialog::clickV2()
}
isRecording = false;
ui->bV2->setText(QChar(0x2461));
mw->meshDoc()->Log.Log(0, "Stored Visibility #2");
mw->meshDoc()->Log.log(0, "Stored Visibility #2");
}
else if (!visibilityState[1].isEmpty())
{
@ -272,10 +272,10 @@ void LayerDialog::clickV2()
updatePerMeshItemVisibility();
updatePerMeshItemSelectionStatus();
mw->GLA()->update();
mw->meshDoc()->Log.Log(0, "Restored Visibility #2");
mw->meshDoc()->Log.log(0, "Restored Visibility #2");
}
else
mw->meshDoc()->Log.Log(0, "No Visibility to Restore");
mw->meshDoc()->Log.log(0, "No Visibility to Restore");
}
void LayerDialog::clickV3()
{
@ -289,7 +289,7 @@ void LayerDialog::clickV3()
}
isRecording = false;
ui->bV3->setText(QChar(0x2462));
mw->meshDoc()->Log.Log(0, "Stored Visibility #3");
mw->meshDoc()->Log.log(0, "Stored Visibility #3");
}
else if (!visibilityState[2].isEmpty())
{
@ -302,10 +302,10 @@ void LayerDialog::clickV3()
updatePerMeshItemVisibility();
updatePerMeshItemSelectionStatus();
mw->GLA()->update();
mw->meshDoc()->Log.Log(0, "Restored Visibility #3");
mw->meshDoc()->Log.log(0, "Restored Visibility #3");
}
else
mw->meshDoc()->Log.Log(0, "No Visibility to Restore");
mw->meshDoc()->Log.log(0, "No Visibility to Restore");
}
void LayerDialog::clickV4()
{
@ -319,7 +319,7 @@ void LayerDialog::clickV4()
}
isRecording = false;
ui->bV4->setText(QChar(0x2463));
mw->meshDoc()->Log.Log(0, "Stored Visibility #4");
mw->meshDoc()->Log.log(0, "Stored Visibility #4");
}
else if (!visibilityState[3].isEmpty())
{
@ -332,10 +332,10 @@ void LayerDialog::clickV4()
updatePerMeshItemVisibility();
updatePerMeshItemSelectionStatus();
mw->GLA()->update();
mw->meshDoc()->Log.Log(0, "Restored Visibility #4");
mw->meshDoc()->Log.log(0, "Restored Visibility #4");
}
else
mw->meshDoc()->Log.Log(0, "No Visibility to Restore");
mw->meshDoc()->Log.log(0, "No Visibility to Restore");
}
void LayerDialog::enterEvent(QEvent* /*event*/)

View File

@ -961,7 +961,7 @@ void MainWindow::startFilter()
if(currentViewContainer())
{
iFilter->setLog(currentViewContainer()->LogPtr());
currentViewContainer()->LogPtr()->SetBookmark();
currentViewContainer()->LogPtr()->setBookmark();
}
// just to be sure...
createStdPluginWnd();
@ -1159,9 +1159,9 @@ void MainWindow::executeFilter(const QAction* action, RichParameterList &params,
// (3) save the current filter and its parameters in the history
if(!isPreview)
meshDoc()->Log.ClearBookmark();
meshDoc()->Log.clearBookmark();
else
meshDoc()->Log.BackToBookmark();
meshDoc()->Log.backToBookmark();
// (4) Apply the Filter
bool ret;
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
@ -1236,7 +1236,7 @@ void MainWindow::executeFilter(const QAction* action, RichParameterList &params,
if(ret)
{
meshDoc()->Log.Logf(GLLogStream::SYSTEM,"Applied filter %s in %i msec",qUtf8Printable(action->text()),tt.elapsed());
meshDoc()->Log.logf(GLLogStream::SYSTEM,"Applied filter %s in %i msec",qUtf8Printable(action->text()),tt.elapsed());
if (meshDoc()->mm() != NULL)
meshDoc()->mm()->setMeshModified();
MainWindow::globalStatusBar()->showMessage("Filter successfully completed...",2000);
@ -1250,7 +1250,7 @@ void MainWindow::executeFilter(const QAction* action, RichParameterList &params,
else // filter has failed. show the message error.
{
QMessageBox::warning(this, tr("Filter Failure"), QString("Failure of filter <font color=red>: '%1'</font><br><br>").arg(action->text())+iFilter->errorMsg()); // text
meshDoc()->Log.Logf(GLLogStream::SYSTEM,"Filter failed: %s",qUtf8Printable(iFilter->errorMsg()));
meshDoc()->Log.logf(GLLogStream::SYSTEM,"Filter failed: %s",qUtf8Printable(iFilter->errorMsg()));
MainWindow::globalStatusBar()->showMessage("Filter failed...",2000);
}
@ -2886,7 +2886,7 @@ void MainWindow::updateTexture(int meshid)
if(!res)
{
QString errmsg = QString("Failure of loading texture %1").arg(fi.fileName());
meshDoc()->Log.Log(GLLogStream::WARNING,qUtf8Printable(errmsg));
meshDoc()->Log.log(GLLogStream::WARNING,qUtf8Printable(errmsg));
unexistingtext += "<font color=red>" + filename + "</font><br>";
}
}
@ -3149,7 +3149,7 @@ void MainWindow::addRenderingSystemLogInfo(unsigned mmid)
QString data = QString(deb._currentlyallocated.c_str()) + "\n" + QString(deb._tobedeallocated.c_str()) + "\n" + QString(deb._tobeallocated.c_str()) + "\n" + QString(deb._tobeupdated.c_str()) + "\n";
for(std::vector<std::string>::iterator it = deb._perviewdata.begin();it != deb._perviewdata.end();++it)
data += QString((*it).c_str()) + "<br>";
meshDoc()->Log.Log(GLLogStream::SYSTEM, data);
meshDoc()->Log.log(GLLogStream::SYSTEM, data);
}
}
}

View File

@ -151,7 +151,7 @@ void MLDefaultMeshDecorators::decorateMesh( MeshModel & m,const MLRenderingData&
inf += "<b>" + QString::number(bvH().size()) + " </b> vertex";
else
inf += "<b>" + QString::number(beH().size()/2) + " </b> edges";
log.RealTimeLog("Boundary",m.shortName(),inf);
log.realTimeLog("Boundary",m.shortName(),inf);
}
if (opts._peredge_faceboundary_enabled)
@ -161,7 +161,7 @@ void MLDefaultMeshDecorators::decorateMesh( MeshModel & m,const MLRenderingData&
inf += "<b>" + QString::number(bvH().size()) + " </b> vertex";
else
inf += "<b>" + QString::number(bfH().size()/3) + " </b> faces";
log.RealTimeLog("Boundary Faces",m.shortName(),inf);
log.realTimeLog("Boundary Faces",m.shortName(),inf);
}
}
@ -175,7 +175,7 @@ void MLDefaultMeshDecorators::decorateMesh( MeshModel & m,const MLRenderingData&
QString inf;
inf += "<b>" + QString::number(vvH().size()) + " </b> non manifold vertices<br><b>" + QString::number(tvH().size() / 3) + "</b> faces over non manifold edges";
log.RealTimeLog("Non Manifold Vertices",m.shortName(),inf);
log.realTimeLog("Non Manifold Vertices",m.shortName(),inf);
}
if (opts._peredge_edgemanifold_enabled)
@ -187,7 +187,7 @@ void MLDefaultMeshDecorators::decorateMesh( MeshModel & m,const MLRenderingData&
drawTriVector(m.cm.Tr, fvH());
QString inf;
inf += "<b>" + QString::number(bvH().size()/2) + " </b> non manifold edges<br><b>" + QString::number(fvH().size()/3) + "</b> faces over non manifold edges";
log.RealTimeLog("Non Manifold Edges",m.shortName(),inf);
log.realTimeLog("Non Manifold Edges",m.shortName(),inf);
}
if (opts._peredge_text_boundary_enabled)

View File

@ -173,13 +173,14 @@ static void Dijkstra(_MyMeshType& m, VertexType& v, int numOfNeighbours, float m
static void DeletePerVertexAttribute(_MyMeshType& m)
{
KNNGraph<_MyMeshType>::DeleteKNNTree(m);
KNNGraph<_MyMeshType>::DeleteKNNTree(m);
bool hasDistParam = tri::HasPerVertexAttribute(m, "DistParam");
if (hasDistParam) {
Allocator<_MyMeshType>::DeletePerVertexAttribute(m, "DistParam");
}
return;
//keeping the DistParam attribute, it could be useful to other plugins
//bool hasDistParam = tri::HasPerVertexAttribute(m, "DistParam");
//if (hasDistParam) {
// Allocator<_MyMeshType>::DeletePerVertexAttribute(m, "DistParam");
//}
return;
}
}; // end ComponentFinder Class