Skip to content

Commit

Permalink
Refs #11597 React to rebinned source being deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonPiccardoSelg committed Apr 21, 2015
1 parent b35f148 commit a080187
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ namespace Mantid

bool doesWorkspaceBelongToRebinnedSource(std::string workspaceName);

void registerRebinnedSource(pqPipelineSource* source);

signals:
void switchSources(std::string rebinnedWorkspaceName, std::string sourceType);

Expand All @@ -86,6 +88,9 @@ namespace Mantid

void afterReplaceHandle(const std::string &workspaceName, const boost::shared_ptr<Mantid::API::Workspace> workspace);

private slots:
void onRebinnedSourceDestroyed();

private:
std::map<std::string, std::string> m_originalWorkspaceToRebinnedWorkspace; ///< Holds the mapping from the original source to the rebinned source

Expand All @@ -112,6 +117,8 @@ namespace Mantid
static void copySafe(vtkSMProxy* dest, vtkSMProxy* source);

void getWorkspaceInfo(pqPipelineSource* source, std::string& workspaceName, std::string& workSpaceType);

void removePipeline(pqPipelineSource* source);
};

} // SimpleGui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ void MdViewerWidget::prepareRebinnedWorkspace(const std::string rebinnedWorkspac
this->renderAndFinalSetup();

this->currentView->onAutoScale(this->ui.colorSelectionWidget);

// Register the source
m_rebinnedSourcesManager.registerRebinnedSource(newRebinnedSource);
}

/**
Expand Down Expand Up @@ -530,6 +533,12 @@ void MdViewerWidget::removeRebinning(pqPipelineSource* source, bool forced, Mode
return;
}

// We need to check that the rebinned workspace name has still a source associated to it
if (!m_rebinnedSourcesManager.isRebinnedSource(rebinnedWorkspaceName))
{
return;
}

// Create the original source
renderOriginalWorkspace(originalWorkspaceName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,15 @@ namespace Mantid
source = getSourceForWorkspace(wsName);
}

// Go to the end of the pipeline
while(source->getNumberOfConsumers() > 0)
{
source = source->getConsumer(0);
}

//Destroy the pipeline from the end
pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
pqPipelineFilter* filter = qobject_cast<pqPipelineFilter*>(source);

while (filter)
{
source = filter->getInput(0);
builder->destroy(filter);
filter = qobject_cast<pqPipelineFilter*>(source);
}

builder->destroy(source); // The listener takes now care of the workspace.
removePipeline(source);

if (isOriginal)
{
untrackWorkspaces(m_originalWorkspaceToRebinnedWorkspace[wsName]);
}
else
{
untrackWorkspaces(m_rebinnedWorkspaceToOriginalWorkspace[wsName]);
untrackWorkspaces(wsName);
}
}
}
Expand Down Expand Up @@ -577,11 +560,21 @@ namespace Mantid
*/
bool RebinnedSourcesManager::isRebinnedSource(std::string name)
{
if (m_rebinnedWorkspaceToOriginalWorkspace.count(name) > 0)
// We need to iterate over all sources and check if the source name exists
pqPipelineSource* source = getSourceForWorkspace(name);

// If the workspace is tracked and the source exists then it is a rebinned source
// else if the workspace is tracked and the source does not exist => untrack it
if (m_rebinnedWorkspaceToOriginalWorkspace.count(name) > 0 && source)
{
return true;
}
else
else if (m_rebinnedWorkspaceToOriginalWorkspace.count(name) > 0 && !source)
{
untrackWorkspaces(name);
return false;
}
else
{
return false;
}
Expand Down Expand Up @@ -609,6 +602,54 @@ namespace Mantid
return false;
}
}

/**
* Register the rebinned source. Specifically, connect to the destroyed signal of the rebinned source.
* @param source The rebinned source.
*/
void RebinnedSourcesManager::registerRebinnedSource(pqPipelineSource* source)
{
if (!source)
{
return;
}

QObject::connect(source, SIGNAL(destroyed()),
this, SLOT(onRebinnedSourceDestroyed()));
}

/**
* React to the deletion of a rebinned source.
*/
void RebinnedSourcesManager::onRebinnedSourceDestroyed()
{

}

/**
* Remove the pipeline
*/
void RebinnedSourcesManager::removePipeline(pqPipelineSource* source)
{
// Go to the end of the pipeline
while(source->getNumberOfConsumers() > 0)
{
source = source->getConsumer(0);
}

//Destroy the pipeline from the end
pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
pqPipelineFilter* filter = qobject_cast<pqPipelineFilter*>(source);

while (filter)
{
source = filter->getInput(0);
builder->destroy(filter);
filter = qobject_cast<pqPipelineFilter*>(source);
}

builder->destroy(source); // The listener takes now care of the workspace.
}
}
}
}

0 comments on commit a080187

Please sign in to comment.