Commit 2f240aac authored by jcfr's avatar jcfr
Browse files

ENH: RegisterDisplayableManager / UnRegisterDisplayableManager returns a boolean + updated test

git-svn-id: http://svn.slicer.org/Slicer4/trunk@15637 3bd1e089-480b-0410-8dfb-8563597acbee
parent be85eb6f
......@@ -101,7 +101,15 @@ int vtkMRMLThreeDViewDisplayableManagerFactoryTest1(int vtkNotUsed(argc), char*
//----------------------------------------------------------------------------
// Register invalid DisplayableManager
factory->RegisterDisplayableManager("vtkMRMLINVALIDManager");
bool success = factory->RegisterDisplayableManager("vtkMRMLINVALIDManager");
if (success)
{
std::cerr << "Line " << __LINE__
<< " - Problem with method factory->RegisterDisplayableManager()" << std::endl;
std::cerr << "\tExpected: 0" << std::endl;
std::cerr << "\tCurrent: " << success << std::endl;
return EXIT_FAILURE;
}
if (factory->GetRegisteredDisplayableManagerCount() != 0)
{
......@@ -114,7 +122,15 @@ int vtkMRMLThreeDViewDisplayableManagerFactoryTest1(int vtkNotUsed(argc), char*
//----------------------------------------------------------------------------
// Register CameraDisplayableManager
factory->RegisterDisplayableManager("vtkMRMLCameraDisplayableManager");
success = factory->RegisterDisplayableManager("vtkMRMLCameraDisplayableManager");
if (!success)
{
std::cerr << "Line " << __LINE__
<< " - Problem with method factory->RegisterDisplayableManager()" << std::endl;
std::cerr << "\tExpected: 1" << std::endl;
std::cerr << "\tCurrent: " << success << std::endl;
return EXIT_FAILURE;
}
if (factory->GetRegisteredDisplayableManagerCount() != 1)
{
......@@ -126,7 +142,15 @@ int vtkMRMLThreeDViewDisplayableManagerFactoryTest1(int vtkNotUsed(argc), char*
}
// Register again CameraDisplayableManager - The count should remain the same
factory->RegisterDisplayableManager("vtkMRMLCameraDisplayableManager");
success = factory->RegisterDisplayableManager("vtkMRMLCameraDisplayableManager");
if (success)
{
std::cerr << "Line " << __LINE__
<< " - Problem with method factory->RegisterDisplayableManager()" << std::endl;
std::cerr << "\tExpected: 0" << std::endl;
std::cerr << "\tCurrent: " << success << std::endl;
return EXIT_FAILURE;
}
if (factory->GetRegisteredDisplayableManagerCount() != 1)
{
......@@ -286,7 +310,7 @@ int vtkMRMLThreeDViewDisplayableManagerFactoryTest1(int vtkNotUsed(argc), char*
//----------------------------------------------------------------------------
// Attempt to UnRegister a DisplayableManager already instanciated in a Group
factory->UnRegisterDisplayableManager("vtkMRMLCameraDisplayableManager");
success = factory->UnRegisterDisplayableManager("vtkMRMLCameraDisplayableManager");
if (factory->GetRegisteredDisplayableManagerCount() != 1)
{
......
......@@ -116,13 +116,13 @@ bool vtkMRMLDisplayableManagerFactory::IsDisplayableManagerRegistered(const char
}
//----------------------------------------------------------------------------
void vtkMRMLDisplayableManagerFactory::RegisterDisplayableManager(const char* vtkClassOrScriptName)
bool vtkMRMLDisplayableManagerFactory::RegisterDisplayableManager(const char* vtkClassOrScriptName)
{
// Sanity checks
if (!vtkClassOrScriptName)
{
vtkWarningMacro(<<"RegisterDisplayableManager - vtkClassOrScriptName is NULL");
return;
return false;
}
// Check if the DisplayableManager has already been registered
......@@ -134,7 +134,7 @@ void vtkMRMLDisplayableManagerFactory::RegisterDisplayableManager(const char* vt
if ( it != this->Internal->DisplayableManagerClassNames.end())
{
vtkWarningMacro(<<"RegisterDisplayableManager - " << vtkClassOrScriptName << " already registered");
return;
return false;
}
// Check if vtkClassOrScriptName is a valid vtk className
......@@ -147,10 +147,12 @@ void vtkMRMLDisplayableManagerFactory::RegisterDisplayableManager(const char* vt
std::string str(vtkClassOrScriptName);
if (str.find(".py") == std::string::npos)
{
return;
vtkWarningMacro(<<"RegisterDisplayableManager - Failed to register " << vtkClassOrScriptName);
return false;
}
#else
return;
vtkWarningMacro(<<"RegisterDisplayableManager - Failed to register " << vtkClassOrScriptName);
return false;
#endif
}
......@@ -159,16 +161,18 @@ void vtkMRMLDisplayableManagerFactory::RegisterDisplayableManager(const char* vt
this->InvokeEvent(Self::DisplayableManagerFactoryRegisteredEvent,
const_cast<char*>(vtkClassOrScriptName));
return true;
}
//----------------------------------------------------------------------------
void vtkMRMLDisplayableManagerFactory::UnRegisterDisplayableManager(const char* vtkClassOrScriptName)
bool vtkMRMLDisplayableManagerFactory::UnRegisterDisplayableManager(const char* vtkClassOrScriptName)
{
// Sanity checks
if (!vtkClassOrScriptName)
{
vtkWarningMacro(<<"UnRegisterDisplayableManager - vtkClassOrScriptName is NULL");
return;
return false;
}
// Check if the DisplayableManager is registered
......@@ -180,13 +184,15 @@ void vtkMRMLDisplayableManagerFactory::UnRegisterDisplayableManager(const char*
if ( it == this->Internal->DisplayableManagerClassNames.end())
{
vtkWarningMacro(<<"UnRegisterDisplayableManager - " << vtkClassOrScriptName << " is NOT registered");
return;
return false;
}
this->Internal->DisplayableManagerClassNames.erase(it);
this->InvokeEvent(Self::DisplayableManagerFactoryUnRegisteredEvent,
const_cast<char*>(vtkClassOrScriptName));
return true;
}
//----------------------------------------------------------------------------
......
......@@ -54,20 +54,20 @@ public:
/// is already registered.
bool IsDisplayableManagerRegistered(const char* vtkClassName);
///
/// Register Displayable Manager identified by \a vtkClassOrScriptName
/// Returns True if displayable manager was successfully registered
/// \a vtkClassOrScriptName should be either:
/// a VTK class registered using the CMake macro VTK_MAKE_INSTANTIATOR3
/// a python script having the extension .py
/// Internally for each registered python script, a scripted displayable manager
/// will be instanciated.
void RegisterDisplayableManager(const char* vtkClassOrScriptName);
bool RegisterDisplayableManager(const char* vtkClassOrScriptName);
///
/// UnRegister Displayable Manager identified by \a vtkClassOrScriptName
/// UnRegister Displayable Manager identified by \a vtkClassOrScriptName.
/// Returns True if displayable manager was successfully unregistered
/// \a vtkClassOrScriptName should be either a VTK class registered using the
/// CMake macro VTK_MAKE_INSTANTIATOR3 or a python script name.
void UnRegisterDisplayableManager(const char* vtkClassOrScriptName);
bool UnRegisterDisplayableManager(const char* vtkClassOrScriptName);
///
/// Return number of registered displayable managers
......
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