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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK 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 Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
// -- Core stuff
#include "Core.h"
#include "CamiTKVersion.h"
#include "Log.h"
#include "ExtensionManager.h"
#include "Action.h"
#include <Application.h>
// -- QT stuff
#include <QDir>
#include <QApplication>
#include <QProcess>
// MSVC does not have the C++ Standard rint function (it should be included in any C99 implementation)
#if defined(_WIN32) && !defined(__MINGW32__) && (_MSC_VER < 1800)
#include <math.h>
double rint(double x) {
// middle value point test
if (ceil(x+0.5) == floor(x+0.5)) {
int a = (int)ceil(x);
if (a%2 == 0) {
return ceil(x);
}
else {
return floor(x);
}
}
else
return floor(x+0.5);
}
#endif
namespace camitk {
// ------------- getPaths (static) -----------------
const QString Core::getPaths() {
QStringList diagnosis;
diagnosis << "- CamiTK version......................... " + QString(Core::version);
diagnosis << "- CamiTK Short Version................... " + QString(Core::shortVersion);
diagnosis << "- CamiTK SO NAME......................... " + QString(Core::soVersion);
diagnosis << "- CamiTK Global Installation Directory... " + Core::getGlobalInstallDir();
diagnosis << "- User Installation Directory............ " + Core::getUserInstallDir();
diagnosis << "- Current Working Directory.............. " + Core::getCurrentWorkingDir();
diagnosis << "- Test Data Directory.................... " + Core::getTestDataDir();
diagnosis << "- Component Extension Directories........ " + Core::getComponentDirectories().join(",");
diagnosis << "- Action Extension Directories........... " + Core::getActionDirectories().join(",");
return diagnosis.join("\n");
}
// ------------- getConfig (static) -----------------
const QString Core::getConfig() {
QStringList diagnosis;
//-- first get all paths
diagnosis << getPaths();
//-- component extensions
unsigned int componentCount = 0;
QStringList components;
// regular component extensions
const QMap<QString, ComponentExtension*> & allCE = ExtensionManager::getComponentExtensions();
foreach(ComponentExtension *ce, allCE.values().toSet()) {
components << " - " + ce->getName() + " (" + ce->getFileExtensions().join(", ") + ") " + ExtensionManager::getInstallationString(ce->getLocation()); // to get more information, use ce->getDescription();
componentCount++;
}
// directory extensions
const QMap <QString, camitk::ComponentExtension* >& allDCE = ExtensionManager::getDataDirectoryComponents();
foreach(ComponentExtension *ce, allDCE.values().toSet()) {
components << " - " + ce->getName() + " (directory) " + ExtensionManager::getInstallationString(ce->getLocation());
componentCount++;
}
diagnosis << "- Number of Component Extensions......... " + QString::number(componentCount);
//-- action extensions
unsigned int actionCount = 0;
QStringList actions;
const QMap<QString, ActionExtension* >& allActions = ExtensionManager::getActionExtensions();
foreach(ActionExtension *ae, allActions.values()) {
QStringList actionNames;
for (int i=0; i<ae->getActions().size();i++) {
actionNames << ae->getActions().at(i)->getName(); // + ": " + a->getDescription();
}
actions << " - " + ae->getName() + " " + ExtensionManager::getInstallationString(ExtensionManager::getActionExtensions().key(ae)) +": " + QString::number(ae->getActions().size()) + " actions (" + actionNames.join(", ") + ")"; //+ ae->getDescription();
actionCount += ae->getActions().size();
}
diagnosis << "- Number of Action Extensions............ " + QString::number(actionCount);
//-- details of the extensions
diagnosis << "- Registered components (G=Global, L=Local, W=Working, U=User):";
diagnosis += components;
diagnosis << "- Registered actions (G=Global, L=Local, W=Working, U=User):";
diagnosis += actions;
return diagnosis.join("\n");
}
// ------------- getInstallDirectories (static) -----------------
const QStringList Core::getInstallDirectories(QString suffix) {
QStringList dir;
// current dir actions (build)
QDir currentWorkingDir(getCurrentWorkingDir());
if (currentWorkingDir.cd(suffix))
dir.append(currentWorkingDir.canonicalPath().toUtf8());
// user actions
QDir userConfigDir(getUserInstallDir());
if (userConfigDir.cd(suffix) && !dir.contains(userConfigDir.canonicalPath().toUtf8()))
dir.append(userConfigDir.canonicalPath().toUtf8());
// global actions
QDir globalInstallDir(getGlobalInstallDir());
if (globalInstallDir.cd(suffix) && !dir.contains(globalInstallDir.canonicalPath().toUtf8()))
dir.append(globalInstallDir.canonicalPath().toUtf8());
return dir;
}
// ------------- getActionDirectories (static) -----------------
const QStringList Core::getActionDirectories() {
return getInstallDirectories("lib/"+QString(Core::shortVersion)+"/actions");
}
// ------------- getComponentDirectories (static) -----------------
const QStringList Core::getComponentDirectories() {
return getInstallDirectories("lib/"+QString(Core::shortVersion)+"/components");
}
// ------------- getTestDataDir (static) -----------------
const QString Core::getTestDataDir() {
QStringList testDataDirectories = getInstallDirectories("share/" + QString(Core::shortVersion) + "/testdata");
// just returns the first one if exists
if (testDataDirectories.size()>0)
return testDataDirectories.at(0);
else
// otherwise returns user home directory
return QDir::home().canonicalPath().toUtf8();
}
// ------------- getGlobalInstallDir (static) -----------------
const QString Core::getGlobalInstallDir() {
QDir camitkDir;
QByteArray camitkDirectory;
bool processOk = false;
if (Application::getName() != "camitk-config") {
// run camitk-imp to get the "installed" directory
// note: camitk-imp must be in the path, or it is not considered as installed
// (installed = available at any time)
QProcess process;
process.start("camitk-config", QStringList() << "--camitkDir", QIODevice::ReadWrite | QIODevice::Text);
if (process.waitForStarted(-1)) {
while(process.waitForReadyRead(-1)) {
camitkDirectory += process.readAllStandardOutput();
}
camitkDir = QString(camitkDirectory).trimmed();
// if the directory does not exist check CamiTKDir.txt
processOk = camitkDir.exists();
}
}
// if there was a problem or if this is camitk-config, check CamiTKDir.txt
if (!processOk) {
// not found use the last installation path if available
QFile file(getUserInstallDir()+"/CamiTKDir.txt");
if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text)) {
camitkDirectory = file.readLine();
camitkDir = QString(camitkDirectory).trimmed();
}
else {
// everything failed, use current application directory path (last chance)
camitkDir = qApp->applicationDirPath();
camitkDir.cdUp();
}
}
return camitkDir.canonicalPath().toUtf8();
}
// ------------- getUserConfigDir (static) -----------------
const QString Core::getUserInstallDir() {
// obtain (platform specific) application's data/settings directory from settings file
return QFileInfo(Application::getSettings().fileName()).absolutePath();
}
// ------------- getCurrentWorkingDir (static) -----------------
const QString Core::getCurrentWorkingDir() {
return QDir::currentPath();
}
// ------------- isDebugBuild (static) -----------------
const bool Core::isDebugBuild() {
#ifdef QT_DEBUG
return true;
#else
return false;
#endif
}
// ----------------------------------------------------------------
//
// OBSOLETE PUBLIC METHODS
//
// TODO CAMITK_DEPRECATED. This section list all the methods marked as deprecated.
// They are to be removed in CamiTK 4.0
// ----------------------------------------------------------------
// ------------- getComponentDir (static) -----------------
//TODO remove in CamiTK 4.0 CAMITK_DEPRECATED
const QString Core::getComponentDir() {
QDir appDir(getGlobalInstallDir());
appDir.cd("lib/"+QString(Core::shortVersion)+"/components");
return appDir.canonicalPath().toUtf8();
}
// ------------- getActionDir (static) -----------------
//TODO remove in CamiTK 4.0 CAMITK_DEPRECATED
const QString Core::getActionDir() {
QDir appDir(getGlobalInstallDir());
appDir.cd("lib/"+QString(Core::shortVersion)+"/actions");
return appDir.canonicalPath().toUtf8();
}
// ------------- getModuleDir (static) -----------------
//TODO remove in CamiTK 4.0 CAMITK_DEPRECATED
const QString Core::getModuleDir(const QString & subpath) {
QDir appDir(getGlobalInstallDir());
appDir.cd("lib/"+QString(Core::shortVersion)+"/" + subpath);
return appDir.canonicalPath().toUtf8();
}
// ------------- getLibDir (static) -----------------
//TODO remove in CamiTK 4.0 CAMITK_DEPRECATED
const QString Core::getCoreLibDir() {
return getGlobalInstallDir();
}
}
|