Commit bc181b14 authored by John Tourtellott's avatar John Tourtellott
Browse files

Clear pqView instances when closing project

Destroys all pqView instances, collapses layout, and creates pqRenderView
parent 7cb48308
......@@ -20,15 +20,20 @@
#include "smtk/project/Manager.h"
#include "smtk/project/Project.h"
// // Client side
// Paraview
#include "pqActiveObjects.h"
#include "pqApplicationCore.h"
#include "pqCoreUtilities.h"
#include "pqObjectBuilder.h"
#include "pqProxy.h"
#include "pqServer.h"
#include "pqServerManagerModel.h"
#include "pqView.h"
#include "vtkSMViewLayoutProxy.h"
#include <QAction>
#include <QDebug>
#include <QList>
#include <QMessageBox>
#include <QtGlobal>
......@@ -118,9 +123,11 @@ void pqACE3PCloseBehavior::closeProject()
}
} // if (project modified)
// Access the active server and get the project manager
pqServer* server = pqActiveObjects::instance().activeServer();
pqSMTKWrapper* wrapper = pqSMTKBehavior::instance()->resourceManagerForServer(server);
// Access the builtin server and get the project manager
pqServerManagerModel* smModel = pqApplicationCore::instance()->getServerManagerModel();
QList<pqServer*> serverList = smModel->findItems<pqServer*>();
pqServer* builtinServer = serverList[0];
pqSMTKWrapper* wrapper = pqSMTKBehavior::instance()->resourceManagerForServer(builtinServer);
auto projectManager = wrapper->smtkProjectManager();
auto projectName = project->name();
auto resManager = std::static_pointer_cast<smtk::resource::Resource>(project)->manager();
......@@ -145,4 +152,67 @@ void pqACE3PCloseBehavior::closeProject()
projectManager->remove(project);
emit this->projectClosed();
// Reset render views and destroy any remaining pipeline objects (job data, e.g.)
pqCoreUtilities::processEvents();
pqApplicationCore* core = pqApplicationCore::instance();
pqObjectBuilder* builder = core->getObjectBuilder();
foreach(pqServer* server, serverList)
{
// Find the layout proxy
vtkSMViewLayoutProxy* layout = nullptr;
QList<pqProxy*> proxyList = smModel->findItems<pqProxy*>(server);
foreach(pqProxy* proxy, proxyList)
{
// qDebug() << item << typeid(item).name() << proxy->getSMName () << proxy->getSMGroup();
vtkSMViewLayoutProxy* castLayout = dynamic_cast<vtkSMViewLayoutProxy*>(proxy->getProxy());
if (castLayout != nullptr)
{
layout = castLayout;
break;
}
} // foreach (proxy)
// Future: should be able to remove this sanity check
if (layout == nullptr)
{
qWarning() << "Internal error: no layout found for server";
continue;
}
// Destroy all the views and collapse the layout
QList<pqView*> viewList = smModel->findItems<pqView*>(server);
foreach(pqView* view, viewList)
{
vtkSMViewProxy* viewProxy = view->getViewProxy();
int location = layout->RemoveView(viewProxy);
layout->Collapse(location);
builder->destroy(view);
}
// Add single new view
pqView* newView = builder->createView("RenderView", server);
builder->addToLayout(newView);
// Destroy any remaining pipeline sources
QList<pqPipelineSource*> sourceList = smModel->findItems<pqPipelineSource*>(server);
foreach(pqPipelineSource* source, sourceList)
{
builder->destroy(source);
}
#ifndef NDEBUG
// Report what's left
proxyList = smModel->findItems<pqProxy*>(server);
foreach(pqProxy* proxy, proxyList)
{
qDebug() << __FILE__ << __LINE__ << proxy << proxy->getSMName () << proxy->getSMGroup();
}
#endif
} // foreach (server)
// Make sure the builtin server is active
pqActiveObjects::instance().setActiveServer(builtinServer);
} // closeProject()
Supports Markdown
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