globals and singletons

This commit is contained in:
alemuntoni 2020-11-30 17:36:12 +01:00
parent d90168ca53
commit e2e5a649eb
8 changed files with 174 additions and 38 deletions

View File

@ -8,9 +8,8 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../ML_VERSION")
endif()
set(HEADERS
parameters/rich_parameter.h
parameters/rich_parameter_list.h
parameters/value.h
globals/globals.h
globals/singletons.h
interfaces/decorate_plugin_interface.h
interfaces/edit_plugin_interface.h
interfaces/filter_plugin_interface.h
@ -28,11 +27,13 @@ set(HEADERS
ml_document/mesh_model_state.h
ml_document/raster_model.h
ml_document/render_raster.h
parameters/rich_parameter.h
parameters/rich_parameter_list.h
parameters/value.h
utilities/file_format.h
GLExtensionsManager.h
GLLogStream.h
filterscript.h
meshlab_singletons.h
meshlabdocumentbundler.h
meshlabdocumentxml.h
ml_selection_buffers.h
@ -44,9 +45,8 @@ set(HEADERS
searcher.h)
set(SOURCES
parameters/rich_parameter.cpp
parameters/rich_parameter_list.cpp
parameters/value.cpp
globals/globals.cpp
globals/singletons.cpp
interfaces/decorate_plugin_interface.cpp
interfaces/filter_plugin_interface.cpp
interfaces/plugin_interface.cpp
@ -57,10 +57,12 @@ set(SOURCES
ml_document/mesh_model_state.cpp
ml_document/raster_model.cpp
ml_document/render_raster.cpp
parameters/rich_parameter.cpp
parameters/rich_parameter_list.cpp
parameters/value.cpp
GLExtensionsManager.cpp
GLLogStream.cpp
filterscript.cpp
meshlab_singletons.cpp
meshlabdocumentbundler.cpp
meshlabdocumentxml.cpp
ml_selection_buffers.cpp

View File

@ -40,12 +40,8 @@ exists(../../ML_VERSION){
# Input
HEADERS += \
GLExtensionsManager.h \
parameters/rich_parameter_list.h \
parameters/value.h \
parameters/rich_parameter.h \
filterscript.h \
GLLogStream.h \
globals/globals.h \
globals/singletons.h \
interfaces/decorate_plugin_interface.h \
interfaces/edit_plugin_interface.h \
interfaces/filter_plugin_interface.h \
@ -62,8 +58,13 @@ HEADERS += \
ml_document/mesh_document.h \
ml_document/raster_model.h \
ml_document/render_raster.h \
parameters/rich_parameter_list.h \
parameters/value.h \
parameters/rich_parameter.h \
utilities/file_format.h \
meshlab_singletons.h \
GLExtensionsManager.h \
filterscript.h \
GLLogStream.h \
plugin_manager.h \
mlexception.h \
mlapplication.h \
@ -73,12 +74,8 @@ HEADERS += \
meshlabdocumentxml.h
SOURCES += \
GLExtensionsManager.cpp \
parameters/rich_parameter.cpp \
parameters/rich_parameter_list.cpp \
parameters/value.cpp \
filterscript.cpp \
GLLogStream.cpp \
globals/globals.cpp \
globals/singletons.cpp \
interfaces/decorate_plugin_interface.cpp \
interfaces/filter_plugin_interface.cpp \
interfaces/plugin_interface.cpp \
@ -89,7 +86,12 @@ SOURCES += \
ml_document/mesh_document.cpp \
ml_document/raster_model.cpp \
ml_document/render_raster.cpp \
meshlab_singletons.cpp \
parameters/rich_parameter.cpp \
parameters/rich_parameter_list.cpp \
parameters/value.cpp \
GLExtensionsManager.cpp \
filterscript.cpp \
GLLogStream.cpp \
plugin_manager.cpp \
mlapplication.cpp \
searcher.cpp \

View File

@ -0,0 +1,99 @@
/****************************************************************************
* MeshLab o o *
* A versatile mesh processing toolbox o o *
* _ O _ *
* Copyright(C) 2005-2020 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#include "globals.h"
#include <QDir>
#include <qapplication.h>
#include "../parameters/rich_parameter_list.h"
RichParameterList& meshlab::defaultGlobalParameterList()
{
static RichParameterList globalRPS;
return globalRPS;
}
QString basePath()
{
QDir baseDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
// Windows:
// during development with visual studio binary could be in the debug/release subdir.
// once deployed plugins dir is in the application directory, so
if (baseDir.dirName() == "debug" || baseDir.dirName() == "release") baseDir.cdUp();
#endif
#if defined(Q_OS_MAC)
// Mac: during developmentwith xcode and well deployed the binary is well buried.
for(int i=0;i<6;++i){
if(baseDir.exists("plugins")) break;
baseDir.cdUp();
}
qDebug("The base dir is %s", qUtf8Printable(baseDir.absolutePath()));
#endif
return baseDir.absolutePath();
}
QString meshlab::defaultPluginPath()
{
QDir pluginsDir(basePath());
#if defined(Q_OS_WIN)
QString d = pluginsDir.dirName();
QString dLower = d.toLower();
if (dLower == "release" || dLower == "relwithdebinfo" || dLower == "debug" ||
dLower == "minsizerel") {
// This is a configuration directory for MS Visual Studio.
pluginsDir.cdUp();
} else {
d.clear();
}
#endif
if (pluginsDir.exists("plugins")) {
pluginsDir.cd("plugins");
#if defined(Q_OS_WIN)
// Re-apply the configuration dir, if any.
if (!d.isEmpty() && pluginsDir.exists(d)) {
pluginsDir.cd(d);
}
#endif
return pluginsDir.absolutePath();
}
#if !defined(Q_OS_MAC) && !defined(Q_OS_WIN)
else if (pluginsDir.dirName() == "bin") {
pluginsDir.cdUp();
pluginsDir.cd("lib");
pluginsDir.cd("meshlab");
if (pluginsDir.exists("plugins")) {
pluginsDir.cd("plugins");
return pluginsDir.absolutePath();
}
}
#endif
//QMessageBox::warning(0,"Meshlab Initialization","Serious error. Unable to find the plugins directory.");
qDebug("Meshlab Initialization: Serious error. Unable to find the plugins directory.");
return {};
}

View File

@ -0,0 +1,38 @@
/****************************************************************************
* MeshLab o o *
* A versatile mesh processing toolbox o o *
* _ O _ *
* Copyright(C) 2005-2020 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef MESHLAB_GLOBALS_H
#define MESHLAB_GLOBALS_H
#include <QString>
class RichParameterList;
namespace meshlab {
RichParameterList& defaultGlobalParameterList();
QString defaultPluginPath();
}
#endif // MESHLAB_GLOBALS_H

View File

@ -1,6 +1,7 @@
#include "meshlab_singletons.h"
#include "singletons.h"
#include "plugin_manager.h"
#include "../plugin_manager.h"
#include "globals.h"
namespace meshlab {
@ -8,19 +9,13 @@ MeshLabSingletons::MeshLabSingletons()
{
}
RichParameterList& MeshLabSingletons::globalRPLInstance()
{
static RichParameterList globalRPS;
return globalRPS;
}
PluginManager& MeshLabSingletons::pluginManagerInstance()
{
static bool initialized = false;
static PluginManager pm;
if (!initialized){
initialized = true;
RichParameterList& globalRPS = globalRPLInstance();
RichParameterList& globalRPS = defaultGlobalParameterList();
pm.loadPlugins(globalRPS);
}
return pm;

View File

@ -29,11 +29,16 @@ class PluginManager;
namespace meshlab {
/**
* @brief The MeshLabSingletons class
* This class contains all the singleton instances used on MeshLab.
* - pluginManager
* - defaultGlobalParameterList
*/
class MeshLabSingletons
{
public:
/** Singleton Instances **/
static RichParameterList& globalRPLInstance();
static PluginManager& pluginManagerInstance();
MeshLabSingletons(MeshLabSingletons const&) = delete;

View File

@ -66,11 +66,6 @@ void DecorateBackgroundPlugin::initGlobalParameterList(const QAction* action, Ri
switch(ID(action))
{
case DP_SHOW_CUBEMAPPED_ENV :
if(!parset.hasParameter(CubeMapPathParam()))
{
QString cubemapDirPath = PluginManager::getBaseDirPath() + QString("/textures/cubemaps/uffizi.jpg");
//parset.addParam(RichString(CubeMapPathParam(), cubemapDirPath,"",""));
}
break;
case DP_SHOW_GRID :
parset.addParam(RichFloat(BoxRatioParam(),1.2f,"Box Ratio","The size of the grid around the object w.r.t. the bbox of the object"));

View File

@ -24,7 +24,7 @@
#include <common/GLExtensionsManager.h>
#include <common/mlapplication.h>
#include <common/mlexception.h>
#include <common/pluginmanager.h>
#include <common/plugin_manager.h>
#include <common/filterscript.h>
#include <common/meshlabdocumentxml.h>
#include <common/meshlabdocumentbundler.h>