Commit 9e9ca479 authored by Cory Quammen's avatar Cory Quammen Committed by Utkarsh Ayachit

Loading of settings on the VTK side respects --disable-registry

Settings will not be loaded when this flag is enabled.

Also refactored vtkSMSettings class to load any number of
settings strings/files and to assign priorities for the
different settings.

Change-Id: I6eed2553cd83579db1dbb1a15f831ad6ffe0e6b1
parent ad95b769
......@@ -75,6 +75,7 @@ vtkPVOptions::vtkPVOptions()
this->SetStereoType("Anaglyph");
this->Timeout = 0;
this->EnableStackTrace = 0;
this->DisableRegistry = 0;
this->ForceMPIInitOnClient = 0;
this->ForceNoMPIInitOnClient = 0;
......@@ -259,6 +260,9 @@ void vtkPVOptions::Initialize()
this->AddBooleanArgument("--enable-bt", 0, &this->EnableStackTrace,
"Enable stack trace signal handler.");
this->AddBooleanArgument("--disable-registry", "-dr", &this->DisableRegistry,
"Do not use registry when running ParaView (for testing).");
#if defined(PARAVIEW_USE_MPI)
// We add these here so that "--help" on the process can print these variables
// out. Note the code in vtkProcessModule::Initialize() doesn't really rely on
......
......@@ -145,6 +145,11 @@ public:
vtkGetMacro(EnableStackTrace, int);
vtkSetMacro(EnableStackTrace, int);
// Description:
// Flag for disabling loading of options and settings stored by the
// application. Often used for testing.
vtkGetMacro(DisableRegistry, int);
enum ProcessTypeEnum
{
PARAVIEW = 0x2,
......@@ -223,6 +228,7 @@ private:
int SatelliteMessageIds;
int PrintMonitors;
int EnableStackTrace;
int DisableRegistry;
int ForceMPIInitOnClient;
int ForceNoMPIInitOnClient;
......
......@@ -44,9 +44,18 @@ int main(int argc, char* argv[])
cout << settingString;
vtkSMSettings * settings = vtkSMSettings::GetInstance();
settings->SetUserSettingsFromString(settingString);
// Overwrite site settings in case the site settings file exists on the test machine
settings->SetSiteSettingsFromString(NULL);
settings->AddSettingsFromString(settingString, 1.0);
const char * higherPrioritySettingsString =
"{\n"
" \"sources\" : {\n"
" \"SphereSource\" : {\n"
" \"Radius\" : 1.0\n"
" }\n"
" }\n"
"}\n";
settings->AddSettingsFromString(higherPrioritySettingsString, 2.0);
vtkNew<vtkSMParaViewPipelineController> controller;
......@@ -70,7 +79,7 @@ int main(int argc, char* argv[])
vtkSMDoubleVectorProperty::SafeDownCast(sphere->GetProperty("Radius"));
if (radiusProperty)
{
if (radiusProperty->GetElement(0) != 4.25)
if (radiusProperty->GetElement(0) != 1.0)
{
cerr << "Failed at " << __LINE__ << endl;
return EXIT_FAILURE;
......@@ -89,7 +98,7 @@ int main(int argc, char* argv[])
}
else
{
cerr << "Could no get Radius property\n";
cerr << "Could not get Radius property\n";
}
session->Delete();
......
......@@ -20,7 +20,7 @@ settingsString = """
{
// Default settings for sources.
"sources" : {
// A sphere source is awesome
// A sphere source
"SphereSource" : {
/* New comment
New comment 2 */
......@@ -38,8 +38,9 @@ settingsString = """
""" % (trueRadius, trueThetaResolution, trueCenter[0], trueCenter[1], trueCenter[2])
settings = paraview.servermanager.vtkSMSettings.GetInstance()
settings.SetUserSettingsFromString(settingsString)
settings.SetSiteSettingsFromString("{}")
settings.ClearAllSettings()
settings.AddSettingsFromString(settingsString, 2000000.0)
settings.AddSettingsFromString("{}", 1500000.0)
sourcesComment = settings.GetSettingDescription(".sources")
if sourcesComment != "// Default settings for sources.":
......@@ -47,7 +48,7 @@ if sourcesComment != "// Default settings for sources.":
sys.exit(-1)
sourcesSphereSourceComment = settings.GetSettingDescription(".sources.SphereSource")
if sourcesSphereSourceComment != "// A sphere source is awesome":
if sourcesSphereSourceComment != "// A sphere source":
print "Comment for .sources.SphereSource was not what was expected"
sys.exit(-1)
......@@ -103,46 +104,16 @@ radiusProperty = s.GetProperty("Radius")
radius = radiusProperty.GetElement(0)
if radius != trueRadius:
print "Radius property does not match setting value"
s.FastDelete()
sys.exit(-1)
s.FastDelete()
#
#
# Now clear out the settings and test setting values
#
#
settings.SetUserSettingsFromString(None)
settingsString = settings.GetUserSettingsAsString()
if settingsString != "{}\n":
print "User settings set from None should be {}"
sys.exit(-1)
settings.SetSiteSettingsFromString(None)
settingsString = settings.GetSiteSettingsAsString()
if settingsString != "{}\n":
print "Site settings set from None should be {}"
sys.exit(-1)
settings.SetUserSettingsFromString("")
settingsString = settings.GetUserSettingsAsString()
if settingsString != "{}\n":
print "User settings set from empty string should be {}"
sys.exit(-1)
settings.SetSiteSettingsFromString("")
settingsString = settings.GetSiteSettingsAsString()
if settingsString != "{}\n":
print "Site settings set from empty string should be {}"
sys.exit(-1)
settings.SetUserSettingsFromString("{}")
settingsString = settings.GetUserSettingsAsString()
if settingsString != "{}\n":
print "User settings set from {} should be {}"
sys.exit(-1)
settings.SetSiteSettingsFromString("{}")
settingsString = settings.GetSiteSettingsAsString()
if settingsString != "{}\n":
print "Site settings set from {} should be {}"
sys.exit(-1)
settings.ClearAllSettings()
if settings.HasSetting(".sources.SphereSource"):
print "Setting '.sources.SphereSource' should have been cleared"
sys.exit(-1)
......
......@@ -42,44 +42,30 @@ public:
static vtkSMSettings* GetInstance();
// Description:
// Load settings and distribute to all processes if in batch symmetric mode.
bool LoadSettings();
// Add settings from a string. The string should contain valid JSON-formatted
// text. The "priority" indicates how to treat a setting that has definitions
// in more than one string passed to this class in multiple calls to this
// function. If two settings strings contain values for the same
// setting, then the setting from the string with higher priority will be
// used.
bool AddSettingsFromString(const std::string & settings, double priority);
// Description:
// Load user settings from default location. On linux/unix, this is
// $HOME/.pvsettings.user.js. On Windows, this is under
// %USERPROFILE%/.pvsettings.js. Returns true on success, false
// otherwise.
bool LoadUserSettings();
// The same as AddSettingsFromString, but this method reads the settings
// string from the named file. The fileName should be a full path.
bool AddSettingsFromFile(const std::string & fileName, double priority);
// Description:
// Load user settings from a specified file. Returns true on
// success, false otherwise.
bool LoadUserSettings(const char* fileName);
// Clear out all settings.
void ClearAllSettings();
// Description:
// Set user-specific settings. These are stored in a home directory.
virtual void SetUserSettingsFromString(const char* settings);
virtual std::string GetUserSettingsAsString();
// Distribute settings to all processes if in batch symmetric mode.
bool DistributeSettings();
// Description:
// Load site settings from default location TBD. Returns true on success,
// false otherwise.
bool LoadSiteSettings();
// Description:
// Load site settings from a file. Returns true on success, false
// otherwise.
bool LoadSiteSettings(const char* fileName);
// Description:
// Set site-specific settings. These are stored in a location TBD.
virtual void SetSiteSettingsFromString(const char* settings);
virtual std::string GetSiteSettingsAsString();
// Description:
// Save settings to file(s)
bool SaveSettings();
// Save highest priority settings to file
bool SaveSettings(const std::string & filePath);
// Description:
// Check whether a setting is defined for the requested names.
......@@ -145,18 +131,6 @@ protected:
vtkSMSettings();
virtual ~vtkSMSettings();
// Description:
// Get the path to the root of the settings files
std::string GetSettingsFilePathRoot();
// Description:
// Get the path to the user settings file
std::string GetUserSettingsFilePath();
// Description:
// Get the path to the site settings file
std::string GetSiteSettingsFilePath();
private:
vtkSMSettings(const vtkSMSettings&); // Not implemented
void operator=(const vtkSMSettings&); // Not implemented
......
......@@ -187,7 +187,10 @@ void vtkInitializationHelper::Initialize(int argc, char**argv,
loader->LoadPluginsFromPluginSearchPath();
// Load settings files.
vtkSMSettings::GetInstance()->LoadSettings();
if (!options->GetDisableRegistry())
{
vtkInitializationHelper::LoadSettings();
}
}
//----------------------------------------------------------------------------
......@@ -202,7 +205,11 @@ void vtkInitializationHelper::StandaloneInitialize()
void vtkInitializationHelper::Finalize()
{
// Write out settings file(s)
bool savingSucceeded = vtkSMSettings::GetInstance()->SaveSettings();
std::string userSettingsFile =
vtkInitializationHelper::GetUserSettingsDirectory();
userSettingsFile.append("UserSettings.json");
vtkSMSettings* settings = vtkSMSettings::GetInstance();
bool savingSucceeded = settings->SaveSettings(userSettingsFile.c_str());
if (!savingSucceeded)
{
cerr << "Saving settings file failed\n";
......@@ -222,6 +229,63 @@ void vtkInitializationHelper::StandaloneFinalize()
google::protobuf::ShutdownProtobufLibrary();
}
//----------------------------------------------------------------------------
bool vtkInitializationHelper::LoadSettings()
{
vtkSMSettings* settings = vtkSMSettings::GetInstance();
bool success = true;
// Load user-level settings
std::string userSettingsFileName = vtkInitializationHelper::GetUserSettingsDirectory();
userSettingsFileName.append("UserSettings.json");
success = success && settings->AddSettingsFromFile(userSettingsFileName, 2.0);
// Load site-level settings
// FIXME - site settings will likely live elsewhere
std::string siteSettingsFile = vtkInitializationHelper::GetUserSettingsDirectory();
siteSettingsFile.append("SiteSettings.json");
success = success && settings->AddSettingsFromFile(siteSettingsFile, 1.0);
settings->DistributeSettings();
return success;
}
//----------------------------------------------------------------------------
std::string vtkInitializationHelper::GetUserSettingsDirectory()
{
#if defined(WIN32)
const char* appData = getenv("APPDATA");
if (!appData)
{
return std::string();
}
std::string separator("\\");
std::string fileName(appData);
if (fileName[fileName.size()-1] != separator[0])
{
fileName.append(separator);
}
fileName += "ParaView" + separator;
#else
const char* home = getenv("HOME");
if (!home)
{
return std::string();
}
std::string separator("/");
std::string fileName(home);
if (fileName[fileName.size()-1] != separator[0])
{
fileName.append(separator);
}
fileName += ".config" + separator + "ParaView" + separator;
#endif
return fileName;
}
//----------------------------------------------------------------------------
void vtkInitializationHelper::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -61,6 +61,15 @@ protected:
vtkInitializationHelper() {};
virtual ~vtkInitializationHelper() {};
// Description:
// Load settings
static bool LoadSettings();
// Description:
// Get directory for user settings file. The last character is always the
// file path separator appropriate for the system.
static std::string GetUserSettingsDirectory();
private:
vtkInitializationHelper(const vtkInitializationHelper&); // Not implemented
void operator=(const vtkInitializationHelper&); // Not implemented
......
......@@ -74,7 +74,6 @@ pqOptions::pqOptions()
this->TestDirectory = 0;
this->DataDirectory = 0;
this->ExitAppWhenTestsDone = 0;
this->DisableRegistry = 0;
this->ServerResourceName = 0;
this->DisableLightKit = 0;
this->CurrentImageThreshold = 12;
......@@ -114,9 +113,6 @@ void pqOptions::Initialize()
this->AddBooleanArgument("--exit", NULL, &this->ExitAppWhenTestsDone,
"Exit application when testing is done. Use for testing.");
this->AddBooleanArgument("--disable-registry", "-dr", &this->DisableRegistry,
"Do not use registry when running ParaView (for testing).");
this->AddArgument("--server", "-s",
&this->ServerResourceName,
"Set the name of the server resource to connect with when the client starts.");
......
......@@ -54,7 +54,6 @@ public:
vtkGetStringMacro(DataDirectory);
vtkGetMacro(ExitAppWhenTestsDone, int);
vtkGetMacro(DisableRegistry, int);
// Returns the test scripts as a list.
QStringList GetTestScripts();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment