File: globals.cpp

package info (click to toggle)
meshlab 2022.02%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 47,348 kB
  • sloc: cpp: 536,635; ansic: 27,783; sh: 539; makefile: 36
file content (162 lines) | stat: -rw-r--r-- 4,950 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*****************************************************************************
 * MeshLab                                                           o o     *
 * A versatile mesh processing toolbox                             o     o   *
 *                                                                _   O  _   *
 * Copyright(C) 2005-2021                                           \/)\/    *
 * 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 <QDateTime>
#include <QDir>
#include <qapplication.h>

#include "parameters/rich_parameter_list.h"
#include "plugins/plugin_manager.h"
#include "plugins/action_searcher.h"
#include "python/function_set.h"

QString basePath()
{
	QDir baseDir(qApp->applicationDirPath());

#ifdef 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

#ifdef 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") || baseDir.exists("PlugIns"))
			break;
		baseDir.cdUp();
	}
#endif
	return baseDir.absolutePath();
}

QString meshlab::defaultPluginPath()
{
	QDir pluginsDir(basePath());
#ifdef 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");
		return pluginsDir.absolutePath();
	}

	if (pluginsDir.exists("plugins")) {
		pluginsDir.cd("plugins");

#ifdef Q_OS_WIN
		// Re-apply the configuration dir, if any.
		if (!d.isEmpty() && pluginsDir.exists(d)) {
			pluginsDir.cd(d);
		}
#endif

		return pluginsDir.absolutePath();
	}
#ifdef Q_OS_LINUX
	else if (pluginsDir.dirName() == "bin") {
		pluginsDir.cdUp();
#ifdef MESHLAB_LIB_INSTALL_DIR
		pluginsDir.cd(MESHLAB_LIB_INSTALL_DIR);
		if (pluginsDir.exists("plugins")) {
			pluginsDir.cd("plugins");
		}
		return pluginsDir.absolutePath();
#else
		pluginsDir.cd("lib");
		pluginsDir.cd("meshlab");
		if (pluginsDir.exists("plugins")) {
			pluginsDir.cd("plugins");
			return pluginsDir.absolutePath();
		}
#endif // MESHLAB_LIB_INSTALL_DIR
	}
#endif
	qDebug("Meshlab Initialization: Serious error. Unable to find the plugins directory.");
	return {};
}

QString meshlab::defaultShadersPath()
{
	QDir dir(basePath());
#ifdef Q_OS_MAC // TODO: check that this works as expected
	return dir.path() + "/shaders";
#endif
#ifdef Q_OS_LINUX
	dir.cdUp();
	bool res = dir.cd("share/meshlab/shaders");
	if (res) {
		return dir.path();
	}
	else { // reset and return default
		dir.setPath(basePath());
	}
#endif
	return dir.path() + "/shaders";
}

QString meshlab::logDebugFileName()
{
	static QString filename = QDir::homePath() + "/MeshLab" +
							  QString::fromStdString(meshlab::meshlabVersion()) + " " +
							  QDateTime::currentDateTime().toString() + ".log";
	return filename;
}

RichParameterList& meshlab::defaultGlobalParameterList()
{
	static RichParameterList globalRPS;
	return globalRPS;
}

PluginManager& meshlab::pluginManagerInstance()
{
	static PluginManager pm;
	return pm;
}

ActionSearcher& meshlab::actionSearcherInstance()
{
	static ActionSearcher as;
	return as;
}

pymeshlab::FunctionSet& pymeshlab::functionSetInstance()
{
	static FunctionSet fs(meshlab::pluginManagerInstance());
	return fs;
}