Commit 2ead0d90 authored by Cory Quammen's avatar Cory Quammen Committed by Utkarsh Ayachit

Added vtkSMSettings class

This class is meant to be a central location for user-defined program
defaults. It supports the notion of site-wide settings meant to be
used for installations of ParaView in a centralized location for a
specific computing site. Site-wide settings can be overridden by
user-specific settings specified in a file in the user's home
directory.

The site-wide file is named .pvsitesettings.js and its location has
yet to be determined.

The user-specific a file is named .pvsettings.js and it is expected to
be in the user's home directory. An example file for changing the
properties in the SphereSource looks like:

{
  "sources" : {
    "SphereSource" : {
      "Radius" : 4.0,
      "ThetaResolution" : 32,
      "PhiResolution" : 32,
      "Center" : [1.0, 2.0, 3.0]
    }
  }
}

A common pattern of usage is expected to involve calling

vtkSMSettings::SetProxySettings(vtkSMProxy* proxy)

after a proxy is created in the application.

Change-Id: Ieaca8f4d1ea7258372bf84af87b6a1bae0c24ff5
parent b7431c7d
......@@ -569,7 +569,6 @@ void vtkPVSessionServer::OnClientServerMessageRMI(void* message, int message_len
stream);
}
break;
}
}
......
......@@ -81,7 +81,7 @@ public:
REPLY_GATHER_INFORMATION_TAG = 55627,
REPLY_PULL = 55628,
REPLY_LAST_RESULT = 55629,
EXECUTE_STREAM_TAG = 55630,
EXECUTE_STREAM_TAG = 55630
};
// Description:
......
......@@ -69,6 +69,18 @@ public:
// Returns the VTKClassName.
vtkGetStringMacro(VTKClassName);
// Description:
// Assigned by the XML parser. The name assigned in the XML
// configuration. Can be used to figure out the origin of the
// proxy.
vtkGetStringMacro(XMLName);
// Description:
// Assigned by the XML parser. The group in the XML configuration that
// this proxy belongs to. Can be used to figure out the origin of the
// proxy.
vtkGetStringMacro(XMLGroup);
// Description:
// Return true if that Proxy is supposed to have NO vtk class, which means
// its a NullProxy.
......
......@@ -17,10 +17,12 @@
#include "vtkClientServerStream.h"
#include "vtkObjectFactory.h"
#include "vtkPVXMLElement.h"
#include "vtkSIProxy.h"
#include "vtkSMMessage.h"
#include <vector>
#include <assert.h>
#include <vtksys/ios/sstream>
namespace
{
......
......@@ -106,6 +106,7 @@ set (Module_SRCS
vtkSMSession.cxx
vtkSMSessionObject.cxx
vtkSMSessionProxyManager.cxx
vtkSMSettings.cxx
vtkSMSILDomain.cxx
vtkSMSILModel.cxx
vtkSMSourceProxy.cxx
......
......@@ -9,6 +9,7 @@ vtk_module(vtkPVServerManagerCore
vtkPVServerImplementationCore
PRIVATE_DEPENDS
vtksys
vtkjsoncpp
TEST_LABELS
PARAVIEW
TEST_DEPENDS
......
......@@ -310,6 +310,13 @@ public:
// The label assigned by the xml parser.
vtkGetStringMacro(XMLLabel);
// Description:
// The name assigned by the xml parser. Used to get the property
// from a proxy. Note that the name used to obtain a property
// that is on a subproxy may be different from the XMLName of the property,
// see the note on ExposedProperties for vtkSMProxy.
vtkGetStringMacro(XMLName);
// Description:
// If repeatable, a property can have 1 or more values of the same kind.
// This ivar is configured when the xml file is read and is mainly useful
......@@ -396,13 +403,6 @@ protected:
// see the note on ExposedProperties for vtkSMProxy.
vtkSetStringMacro(XMLName);
// Description:
// The name assigned by the xml parser. Used to get the property
// from a proxy. Note that the name used to obtain a property
// that is on a subproxy may be different from the XMLName of the property,
// see the note on ExposedProperties for vtkSMProxy.
vtkGetStringMacro(XMLName);
// Description:
// Internal. Used during XML parsing to get a property with
// given name. Used by the domains when setting required properties.
......
......@@ -28,6 +28,7 @@
#include "vtkPVOptions.h"
#include "vtkPVServerInformation.h"
#include "vtkPVSessionServer.h"
#include "vtkSMSettings.h"
#include "vtkReservedRemoteObjectIds.h"
#include "vtkSMCollaborationManager.h"
#include "vtkSMMessage.h"
......
This diff is collapsed.
/*=========================================================================
Program: ParaView
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkSMSettings
// .SECTION Description
// vtkSMSettings provides the underlying mechanism for setting default property
// values in ParaView
#ifndef __vtkSMSettings_h
#define __vtkSMSettings_h
#include "vtkPVClientServerCoreCoreModule.h" //needed for exports
#include "vtkObject.h"
#include "vtkStdString.h"
class vtkSMDoubleVectorProperty;
class vtkSMInputProperty;
class vtkSMIntVectorProperty;
class vtkSMStringVectorProperty;
class vtkSMProxy;
#include <vector>
class VTKPVCLIENTSERVERCORECORE_EXPORT vtkSMSettings : public vtkObject
{
public:
static vtkSMSettings* New();
vtkTypeMacro(vtkSMSettings, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get singleton instance.
static vtkSMSettings* GetInstance();
// 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();
// Description:
// Load user settings from a specified file. Returns true on
// success, false otherwise.
bool LoadUserSettings(const char* fileName);
// Description:
// Set user-specific settings. These are stored in a home directory.
virtual void SetUserSettingsString(const char* settings);
vtkGetStringMacro(UserSettingsString);;
// 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 SetSiteSettingsString(const char* settings);
vtkGetStringMacro(SiteSettingsString);
// Description:
// Check whether a setting is defined for the requested names.
bool HasSetting(const char* settingName);
// Description:
// Get setting as a scalar value
bool GetScalarSetting(const char* settingName, int & value);
bool GetScalarSetting(const char* settingName, double & value);
bool GetScalarSetting(const char* settingName, long long int & value);
bool GetScalarSetting(const char* settingName, vtkStdString & value);
// Description:
// Get setting as a vector of various numerical types. Returns true on
// success, false on failure. These methods work on values given as
// JSON arrays of numbers as well as singular JSON numbers.
bool GetVectorSetting(const char* settingName, std::vector<int> & values);
bool GetVectorSetting(const char* settingName, std::vector<long long int> & values);
bool GetVectorSetting(const char* settingName, std::vector<double> & values);
// Description:
// Get setting as a vector of string types. Returns true on
// success, false on failure. This method works on values given as
// JSON arrays of strings as well as singular JSON strings.
bool GetVectorSetting(const char* settingName, std::vector<vtkStdString> & values);
// Description:
// Process a vtkSMProxy so that property values in the proxy may
// take on values in the settings.
bool SetProxySettings(vtkSMProxy* proxy, const char* jsonPath);
// Description:
// Set int vector property from JSON path.
bool SetPropertySetting(vtkSMIntVectorProperty* property, const char* jsonPath);
// Description:
// Set double vector property from JSON path.
bool SetPropertySetting(vtkSMDoubleVectorProperty* property, const char* jsonPath);
// Description:
// Set string vector property from JSON path.
bool SetPropertySetting(vtkSMStringVectorProperty* property, const char* jsonPath);
// Description:
// Set input property from JSON path.
bool SetPropertySetting(vtkSMInputProperty* property, const char* jsonPath);
protected:
vtkSMSettings();
virtual ~vtkSMSettings();
private:
vtkSMSettings(const vtkSMSettings&); // Purposely not implemented
void operator=(const vtkSMSettings&); // Purposely not implemented
// User-specified settings
char* UserSettingsString;
// Site-specific settings
char* SiteSettingsString;
class vtkSMSettingsInternal;
vtkSMSettingsInternal * Internal;
};
#endif
......@@ -27,6 +27,7 @@
#include "vtkCommand.h"
#include <vtkPVXMLElement.h>
#include "vtkSMProperty.h"
#include "vtkSMProxy.h"
#include <typeinfo>
#include <limits>
......
......@@ -16,6 +16,7 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkClientServerInterpreter.h"
#include "vtkClientServerInterpreterInitializer.h"
#include "vtkMultiProcessController.h"
#include "vtkNew.h"
#include "vtkOutputWindow.h"
#include "vtkProcessModule.h"
......@@ -23,6 +24,8 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkPVInitializer.h"
#include "vtkPVOptions.h"
#include "vtkPVPluginLoader.h"
#include "vtkPVSession.h"
#include "vtkSMSettings.h"
#include "vtkSmartPointer.h"
#include "vtkSMMessage.h"
#include "vtkSMProperty.h"
......@@ -183,6 +186,71 @@ void vtkInitializationHelper::Initialize(int argc, char**argv,
// These are always loaded (not merely located).
vtkNew<vtkPVPluginLoader> loader;
loader->LoadPluginsFromPluginSearchPath();
// Load settings files. Only load settings on client or root data node
vtkSMSettings * settings = vtkSMSettings::GetInstance();
vtkProcessModule *pm = vtkProcessModule::GetProcessModule();
if (pm->GetProcessType() == vtkProcessModule::PROCESS_CLIENT ||
(pm->GetProcessType() == vtkProcessModule::PROCESS_BATCH &&
pm->GetPartitionId() == 0))
{
settings->LoadSiteSettings();
settings->LoadUserSettings();
}
if (pm->GetProcessType() == vtkProcessModule::PROCESS_BATCH &&
pm->GetSymmetricMPIMode())
{
// Broadcast settings to satellite nodes
vtkMultiProcessController * controller = pm->GetGlobalController();
unsigned int stringSize;
if (controller->GetLocalProcessId() == 0)
{
char* siteSettingsString = settings->GetSiteSettingsString();
stringSize = siteSettingsString ? (strlen(siteSettingsString)+1) : 0;
controller->Broadcast(&stringSize, 1, 0);
if (stringSize > 0)
{
controller->Broadcast(siteSettingsString, stringSize, 0);
}
char* userSettingsString = settings->GetUserSettingsString();
stringSize = userSettingsString ? (strlen(userSettingsString)+1) : 0;
controller->Broadcast(&stringSize, 1, 0);
if (stringSize > 0)
{
controller->Broadcast(userSettingsString, stringSize, 0);
}
}
else // Satellites
{
controller->Broadcast(&stringSize, 1, 0);
if (stringSize > 0)
{
char* siteSettingsString = new char[stringSize];
controller->Broadcast(siteSettingsString, stringSize, 0);
std::cout << "siteSettings: " << siteSettingsString << std::endl;
settings->SetSiteSettingsString(siteSettingsString);
delete[] siteSettingsString;
}
else
{
settings->SetSiteSettingsString(NULL);
}
controller->Broadcast(&stringSize, 1, 0);
if (stringSize > 0)
{
char* userSettingsString = new char[stringSize];
controller->Broadcast(userSettingsString, stringSize, 0);
std::cout << "userSettings: " << userSettingsString << std::endl;
settings->SetUserSettingsString(userSettingsString);
delete[] userSettingsString;
}
else
{
settings->SetUserSettingsString(NULL);
}
}
}
}
//----------------------------------------------------------------------------
......
......@@ -7,7 +7,7 @@
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
......@@ -46,6 +46,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkSMRepresentationProxy.h"
#include "vtkSMSession.h"
#include "vtkSMSessionProxyManager.h"
#include "vtkSMSettings.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMStringVectorProperty.h"
#include "vtkSMTransferFunctionManager.h"
......@@ -75,6 +76,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqViewModuleInterface.h"
#include "vtkSMAnimationSceneProxy.h"
inline QString pqObjectBuilderGetName(vtkSMProxy* proxy,
pqNameCount *nameGenerator)
{
QString label =
proxy->GetXMLLabel()? proxy->GetXMLLabel() : proxy->GetXMLName();
label.remove(' ');
return QString("%1%2").arg(label).arg(
nameGenerator->GetCountAndIncrement(label));
}
namespace pqObjectBuilderNS
{
vtkNew<vtkSMParaViewPipelineController> Controller;
......@@ -117,6 +128,7 @@ namespace pqObjectBuilderNS
// Update animation scene.
vtkSMAnimationSceneProxy::UpdateAnimationUsingDataTimeSteps(
Controller->GetAnimationScene(server->session()));
return source;
}
}
......@@ -263,7 +275,7 @@ pqPipelineSource* pqObjectBuilder::createReader(const QString& sm_group,
QString pname = this->getFileNamePropertyName(proxy);
if (!pname.isEmpty())
{
vtkSMStringVectorProperty* prop =
vtkSMStringVectorProperty* prop =
vtkSMStringVectorProperty::SafeDownCast(
proxy->GetProperty(pname.toLatin1().data()));
if (!prop)
......@@ -281,7 +293,7 @@ pqPipelineSource* pqObjectBuilder::createReader(const QString& sm_group,
if (numFiles == 1 || !prop->GetRepeatCommand())
{
pqSMAdaptor::setElementProperty(prop,
pqSMAdaptor::setElementProperty(prop,
pqObjectBuilderGetPath(files[0], use_dir));
}
else
......@@ -390,7 +402,7 @@ pqView* pqObjectBuilder::createView(const QString& type,
pqObjectBuilderNS::Controller->InitializeView(proxy);
pqServerManagerModel* model =
pqServerManagerModel* model =
pqApplicationCore::instance()->getServerManagerModel();
pqView* view = model->findItem<pqView*>(proxy);
if (view)
......@@ -479,7 +491,7 @@ pqDataRepresentation* pqObjectBuilder::createDataRepresentation(
// Set the reprProxy's input.
pqSMAdaptor::setInputProperty(reprProxy->GetProperty("Input"),
pqSMAdaptor::setInputProperty(reprProxy->GetProperty("Input"),
source->getProxy(), opPort->getPortNumber());
// Let application ignore default and hide display of filters if they must.
if (pqApplicationCore::instance()->getDisplayPolicy()->getHideByDefault())
......@@ -577,7 +589,7 @@ void pqObjectBuilder::destroy(pqRepresentation* repr)
if (stc)
{
// this hides scalar bars only if the LUT is not used by
// any other repr. This must happen after the repr has
// any other repr. This must happen after the repr has
// been deleted.
stc->hideUnusedScalarBars();
}
......@@ -594,7 +606,7 @@ void pqObjectBuilder::destroy(pqProxy* proxy)
//-----------------------------------------------------------------------------
void pqObjectBuilder::destroySources(pqServer* server)
{
pqServerManagerModel* model =
pqServerManagerModel* model =
pqApplicationCore::instance()->getServerManagerModel();
pqObjectBuilder* builder =
pqApplicationCore::instance()->getObjectBuilder();
......@@ -617,7 +629,7 @@ void pqObjectBuilder::destroySources(pqServer* server)
//-----------------------------------------------------------------------------
void pqObjectBuilder::destroyLookupTables(pqServer* server)
{
pqServerManagerModel* model =
pqServerManagerModel* model =
pqApplicationCore::instance()->getServerManagerModel();
pqObjectBuilder* builder =
pqApplicationCore::instance()->getObjectBuilder();
......@@ -628,7 +640,7 @@ void pqObjectBuilder::destroyLookupTables(pqServer* server)
builder->destroy(lut);
}
QList<pqScalarBarRepresentation*> scalarbars =
QList<pqScalarBarRepresentation*> scalarbars =
model->findItems<pqScalarBarRepresentation*>(server);
foreach (pqScalarBarRepresentation* sb, scalarbars)
{
......@@ -661,7 +673,7 @@ void pqObjectBuilder::destroyProxyInternal(pqProxy* proxy)
if (proxy)
{
vtkSMSessionProxyManager* pxm = proxy->proxyManager();
pxm->UnRegisterProxy(proxy->getSMGroup().toLatin1().data(),
pxm->UnRegisterProxy(proxy->getSMGroup().toLatin1().data(),
proxy->getSMName().toLatin1().data(), proxy->getProxy());
}
}
......@@ -845,3 +857,13 @@ void pqObjectBuilder::initializeInheritedProperties(pqDataRepresentation* repr)
iter->Delete();
reprProxy->UpdateVTKObjects();
}
//-----------------------------------------------------------------------------
void pqObjectBuilder::onProxyCreated(pqProxy* proxy)
{
vtkSMProxy* smProxy = proxy->getProxy();
std::string jsonPrefix(".");
jsonPrefix.append(smProxy->GetXMLGroup());
vtkSMSettings::GetInstance()->SetProxySettings(smProxy, jsonPrefix.c_str());
}
This diff is collapsed.
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