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
|
/* FSLView - 2D/3D Interactive Image Viewer
Authors: Rama Aravind Vorray
James Saunders
David Flitney
Mark Jenkinson
Stephen Smith
FMRIB Image Analysis Group
Copyright (C) 2002-2005 University of Oxford */
/* CCOPYRIGHT */
#include "preferences.h"
#include <stdlib.h>
#include <iostream>
#include <QtCore/QVariant>
using namespace std;
struct Preferences::Implementation
{
Implementation() : m_assistantpath(""), m_atlaspath(""),
m_fsldir(""), m_mni(""), m_w(0), m_h(0), m_x(0), m_y(0)
{
}
string m_assistantpath;
string m_atlaspath;
string m_fsldir;
string m_mni;
int m_w, m_h, m_x, m_y;
};
Preferences::Handle Preferences::m_instance;
Preferences::Preferences(): m_impl(new Preferences::Implementation())
{
bool ok;
setPath("fmrib.ox.ac.uk", "fslview", QSettings::UserScope);
if(m_impl->m_atlaspath == "") {
QStringList l = readListEntry("/fsl/atlaspath", &ok);
if(ok)
m_impl->m_atlaspath = l.join(":").ascii();
}
}
//! @brief Access Preferences singleton
//!
//! @return a handle to be used as a pointer to a Preferences object
Preferences::Handle Preferences::getInstance()
{
if(!m_instance)
m_instance = Preferences::Handle(new Preferences());
return m_instance;
}
string Preferences::inqAtlasPath()
{
// bool ok;
// if(m_impl->m_atlaspath == "") {
// QStringList l = readListEntry("/fsl/atlaspath", &ok);
// if(ok)
// m_impl->m_atlaspath = l.join(":").ascii();
// }
if(m_impl->m_atlaspath == "")
m_impl->m_atlaspath = string(getenv("FSLATLASPATH") ?
getenv("FSLATLASPATH") :
inqFSLDir() + "/data/atlases");
return m_impl->m_atlaspath;
}
//! @brief Prefered value for window geometry
//!
//! Returns prefered values from Qt prefs or heuristically determines
//! the default placement from passed in desktop width and height measures
//!
//! @param dw width of desktop
//! @param dh height of desktop
//!
//! @return QRect The require geometry
QRect Preferences::inqGeometry(int dw, int dh)
{
QRect result;
int x( readNumEntry("/fslview/geometry/x", -1) );
int y( readNumEntry("/fslview/geometry/y", -1) );
int w( readNumEntry("/fslview/geometry/width", -1) );
int h( readNumEntry("/fslview/geometry/height", -1) );
if( (x == -1) || (y == -1) || (w == -1) || (h == -1) ) {
if(dh <= 800) {
h = (dh * 85) / 100;
w = (dw * 85) / 100;
x = (dw - w)/2;
y = (dh - h)/2;
} else {
h = (dh * 90) / 100;
w = (h * 80) / 100;
x = y = (dh * 5) / 100;
}
}
return QRect(x, y, w, h);
}
void Preferences::setGeometry(const QRect& r)
{
writeEntry( "/fslview/geometry/x", r.x() );
writeEntry( "/fslview/geometry/y", r.y() );
writeEntry( "/fslview/geometry/width", r.width() );
writeEntry( "/fslview/geometry/height", r.height() );
}
//! @brief Prefered value of FSLATLASPATH
//!
//! Returns vector of the prefered values of FSLATLASPATH or FSLDIR/lib/atlases
//!
//! @return The locations to look for atlas data sets
vector<string> Preferences::inqAtlasPathElements()
{
vector<string> result;
string delimiters(":");
string str(inqAtlasPath());
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
string::size_type pos = str.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos)
{
result.push_back( str.substr(lastPos, pos - lastPos) );
lastPos = str.find_first_not_of(delimiters, pos);
pos = str.find_first_of(delimiters, lastPos);
}
return result;
}
//! @brief Prefered value of FSLDIR
//!
//! Returns the prefered value of FSLDIR
//!
//! @return The users prefered value of FSLDIR
string Preferences::inqFSLDir()
{
if(m_impl->m_fsldir == "")
m_impl->m_fsldir = readEntry("/fsl/fsldir", "").ascii();
if(m_impl->m_fsldir == "")
m_impl->m_fsldir = string(getenv("FSLDIR") ? getenv("FSLDIR") : "/usr/share/fsl");
return m_impl->m_fsldir;
}
//! @brief Prefered location of MNI152 T1 brain
//!
//! Returns the prefered location where we can find MNI152 T1 brain image
//!
//! @return The users prefered location for the MNI152 T1 brain image
string Preferences::inqMni152()
{
if(m_impl->m_mni == "")
m_impl->m_mni = readEntry("/fsl/mni","").ascii();
if(m_impl->m_mni == "")
m_impl->m_mni = inqFSLDir() + "/data/standard/MNI152_T1_2mm_brain.nii.gz";
return m_impl->m_mni;
}
string Preferences::inqAssistantPath()
{
if(m_impl->m_assistantpath == "")
m_impl->m_assistantpath = readEntry("/qt/assistantpath","").ascii();
if(m_impl->m_assistantpath == "")
m_impl->m_assistantpath = string(getenv("FSLQTASSISTANTPATH") ?
getenv("FSLQTASSISTANTPATH") : "");
if(m_impl->m_assistantpath == "")
m_impl->m_assistantpath = string(getenv("QTDIR") ?
string(getenv("QTDIR")) + "/bin" :
inqFSLDir() + "/bin");
return m_impl->m_assistantpath;
}
void Preferences::setFSLDir(const std::string& dir)
{
m_impl->m_fsldir = dir;
writeEntry("/fsl/fsldir", dir.c_str());
}
void Preferences::setMni152(const std::string& filename)
{
m_impl->m_mni = filename;
writeEntry("/fsl/mni", filename.c_str());
}
void Preferences::setAssistantPath(const std::string& path)
{
m_impl->m_assistantpath = path;
writeEntry("/qt/assistantpath", path.c_str());
}
void Preferences::setAtlasPath(const std::string& path)
{
m_impl->m_atlaspath = path;
writeEntry("/fsl/atlaspath", QStringList::split(":", path.c_str()));
}
|