mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1018 Added saving of snapshots to loop infrastructure already established
This commit is contained in:
parent
8bf1456644
commit
f57f9d356e
@ -19,19 +19,26 @@
|
||||
#include "RicExportMultipleSnapshotsFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RicSnapshotViewToClipboardFeature.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
#include "RimCellRangeFilter.h"
|
||||
#include "RimCellRangeFilterCollection.h"
|
||||
#include "RimMultiSnapshotDefinition.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimView.h"
|
||||
|
||||
#include "RiuExportMultipleSnapshotsWidget.h"
|
||||
#include "RiuViewer.h"
|
||||
|
||||
#include "cafCmdExecCommandManager.h"
|
||||
#include "cafFrameAnimationControl.h"
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include "QDir"
|
||||
#include <QDir>
|
||||
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicExportMultipleSnapshotsFeature, "RicExportMultipleSnapshotsFeature");
|
||||
@ -78,7 +85,7 @@ void RicExportMultipleSnapshotsFeature::setupActionLook(QAction* actionToSetup)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportMultipleSnapshotsFeature::exportMultipleSnapshots(const QString& folder, RimProject* project)
|
||||
{
|
||||
if (!project) return; //Er dette OK syntax??
|
||||
if (!project) return;
|
||||
|
||||
QDir snapshotPath(folder);
|
||||
if (!snapshotPath.exists())
|
||||
@ -104,54 +111,75 @@ void RicExportMultipleSnapshotsFeature::exportMultipleSnapshots(const QString& f
|
||||
if (activeView && activeView->viewer())
|
||||
{
|
||||
timeSteps = activeCase->timeStepStrings();
|
||||
RiuViewer* viewer = activeView->viewer();
|
||||
int initialFramIndex = viewer->currentFrameIndex();
|
||||
|
||||
for (int i=msd->timeStepStart(); i <= msd->timeStepEnd(); i++)
|
||||
{
|
||||
//TODO: This naming will not give images in the correct order when sorted on name..
|
||||
timeStepString = timeSteps[i].replace(".", "-");
|
||||
|
||||
viewer->setCurrentFrame(i);
|
||||
viewer->animationControl()->setCurrentFrameOnly(i);
|
||||
|
||||
if (msd->sliceDirection == RimMultiSnapshotDefinition::NO_RANGEFILTER)
|
||||
{
|
||||
QString fileName = activeCase->caseUserDescription() + "_" + activeView->name() + "_" + timeStepString + ".png";
|
||||
QString fileName = activeCase->caseUserDescription() + "_" + activeView->name() + "_" + timeStepString;
|
||||
fileName.replace(" ", "-");
|
||||
|
||||
//TODO: Before saveSnapshotAs is called the folder name must be changed from dummy value in widget
|
||||
QString absoluteFileName = caf::Utils::constructFullFileName(folder, fileName, ".png");
|
||||
//RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, activeView);
|
||||
|
||||
qDebug() << absoluteFileName;
|
||||
|
||||
RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, activeView);
|
||||
}
|
||||
else
|
||||
{
|
||||
RimCellRangeFilter* rangeFilter = new RimCellRangeFilter;
|
||||
activeView->rangeFilterCollection()->rangeFilters.push_back(rangeFilter);
|
||||
|
||||
bool rangeFilterInitState = activeView->rangeFilterCollection()->isActive();
|
||||
activeView->rangeFilterCollection()->isActive = true;
|
||||
|
||||
for (int i = msd->startSliceIndex(); i <= msd->endSliceIndex(); i++)
|
||||
{
|
||||
rangeFilterString = msd->sliceDirection().text() + QString::number(i);
|
||||
|
||||
// setActiveReservoirView(riv);
|
||||
// RiuViewer* viewer = riv->viewer();
|
||||
// mainWnd->setActiveViewer(viewer->layoutWidget());
|
||||
// clearViewsScheduledForUpdate();
|
||||
// //riv->updateCurrentTimeStepAndRedraw();
|
||||
// riv->createDisplayModelAndRedraw();
|
||||
// viewer->repaint();
|
||||
// for (int i=msd->timeStepStart(); i<msd->timeStepEnd(); i++)
|
||||
|
||||
|
||||
QString fileName = activeCase->caseUserDescription() + "_" + activeView->name() + "_" + timeStepString + "_" + rangeFilterString + ".png";
|
||||
QString fileName = activeCase->caseUserDescription() + "_" + activeView->name() + "_" + timeStepString + "_" + rangeFilterString;
|
||||
fileName.replace(" ", "-");
|
||||
|
||||
//TODO: Before saveSnapshotAs is called the folder name must be changed from dummy value in widget
|
||||
rangeFilter->setDefaultValues();
|
||||
if (msd->sliceDirection == RimMultiSnapshotDefinition::RANGEFILTER_I)
|
||||
{
|
||||
rangeFilter->cellCountI = 1;
|
||||
rangeFilter->startIndexI = i;
|
||||
}
|
||||
else if (msd->sliceDirection == RimMultiSnapshotDefinition::RANGEFILTER_J)
|
||||
{
|
||||
rangeFilter->cellCountJ = 1;
|
||||
rangeFilter->startIndexJ = i;
|
||||
}
|
||||
else if (msd->sliceDirection == RimMultiSnapshotDefinition::RANGEFILTER_K)
|
||||
{
|
||||
rangeFilter->cellCountK = 1;
|
||||
rangeFilter->startIndexK = i;
|
||||
}
|
||||
|
||||
activeView->rangeFilterCollection()->updateDisplayModeNotifyManagedViews(rangeFilter);
|
||||
// Make sure the redraw is processed
|
||||
QCoreApplication::instance()->processEvents();
|
||||
|
||||
QString absoluteFileName = caf::Utils::constructFullFileName(folder, fileName, ".png");
|
||||
//RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, activeView);
|
||||
|
||||
qDebug() << absoluteFileName;
|
||||
|
||||
|
||||
RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, activeView);
|
||||
}
|
||||
|
||||
}
|
||||
activeView->rangeFilterCollection()->rangeFilters.removeChildObject(rangeFilter);
|
||||
delete rangeFilter;
|
||||
|
||||
activeView->rangeFilterCollection()->isActive = rangeFilterInitState;
|
||||
activeView->scheduleCreateDisplayModelAndRedraw();
|
||||
QCoreApplication::instance()->processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
viewer->setCurrentFrame(initialFramIndex);
|
||||
viewer->animationControl()->setCurrentFrameOnly(initialFramIndex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,8 @@ QList<caf::PdmOptionItemInfo> RimMultiSnapshotDefinition::calculateValueOptions(
|
||||
for (RimCase* c : cases)
|
||||
{
|
||||
options.push_back(caf::PdmOptionItemInfo(c->caseUserDescription(), QVariant::fromValue(caf::PdmPointer<caf::PdmObjectHandle>(c))));
|
||||
// options.push_back(caf::PdmOptionItemInfo(c->caseUserDescription(), c));
|
||||
// TODO: Update to simpler implementation
|
||||
}
|
||||
|
||||
//options.push_back(caf::PdmOptionItemInfo("All", QVariant::fromValue(caf::PdmPointer<caf::PdmObjectHandle>(nullptr))));
|
||||
@ -98,6 +100,7 @@ QList<caf::PdmOptionItemInfo> RimMultiSnapshotDefinition::calculateValueOptions(
|
||||
for (RimView* view : views)
|
||||
{
|
||||
options.push_back(caf::PdmOptionItemInfo(view->name(), QVariant::fromValue(caf::PdmPointer<caf::PdmObjectHandle>(view))));
|
||||
//options.push_back(caf::PdmOptionItemInfo(view->name(), view));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,13 +84,13 @@ RiuExportMultipleSnapshotsWidget::RiuExportMultipleSnapshotsWidget(QWidget* pare
|
||||
// Save images in snapshot catalog relative to project directory
|
||||
QString snapshotFolderName = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("snapshots");
|
||||
|
||||
m_lineEdit = new QLineEdit(snapshotFolderName);
|
||||
m_exportFolderLineEdit = new QLineEdit(snapshotFolderName);
|
||||
|
||||
QToolButton* button = new QToolButton;
|
||||
button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
|
||||
button->setText(QLatin1String("..."));
|
||||
|
||||
layout->addWidget(m_lineEdit);
|
||||
layout->addWidget(m_exportFolderLineEdit);
|
||||
layout->addWidget(button);
|
||||
|
||||
connect(button, SIGNAL(clicked()), this, SLOT(folderSelectionClicked()));
|
||||
@ -147,7 +147,6 @@ void RiuExportMultipleSnapshotsWidget::customMenuRequested(QPoint pos)
|
||||
menu.exec(globalPos);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -160,33 +159,29 @@ void RiuExportMultipleSnapshotsWidget::deleteAllSnapshotItems()
|
||||
m_rimProject->multiSnapshotDefinitions.uiCapability()->updateConnectedEditors();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuExportMultipleSnapshotsWidget::exportSnapshots()
|
||||
{
|
||||
// RicExportMultipleSnapshotsFeature::staticMethod()
|
||||
QString dummyFolder = "folder"; //TODO: Must be a real folder before saving images!!!
|
||||
RicExportMultipleSnapshotsFeature::exportMultipleSnapshots(dummyFolder, m_rimProject);
|
||||
RicExportMultipleSnapshotsFeature::exportMultipleSnapshots(m_exportFolderLineEdit->text(), m_rimProject);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuExportMultipleSnapshotsWidget::folderSelectionClicked()
|
||||
{
|
||||
QString defaultPath = m_lineEdit->text();
|
||||
QString defaultPath = m_exportFolderLineEdit->text();
|
||||
|
||||
QString directoryPath = QFileDialog::getExistingDirectory(m_lineEdit,
|
||||
QString directoryPath = QFileDialog::getExistingDirectory(m_exportFolderLineEdit,
|
||||
tr("Get existing directory"),
|
||||
defaultPath,
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
|
||||
if (!directoryPath.isEmpty())
|
||||
{
|
||||
m_lineEdit->setText(directoryPath);
|
||||
m_exportFolderLineEdit->setText(directoryPath);
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +194,6 @@ void RiuExportMultipleSnapshotsWidget::addSnapshotItem()
|
||||
|
||||
RimMultiSnapshotDefinition* multiSnapshot = new RimMultiSnapshotDefinition();
|
||||
|
||||
|
||||
//Getting default value from last entered line:
|
||||
if (m_rimProject->multiSnapshotDefinitions.size() > 0)
|
||||
{
|
||||
@ -210,12 +204,10 @@ void RiuExportMultipleSnapshotsWidget::addSnapshotItem()
|
||||
multiSnapshot->timeStepStart = other->timeStepStart();
|
||||
multiSnapshot->timeStepEnd = other->timeStepEnd();
|
||||
|
||||
|
||||
// Variant using copy based on xml string
|
||||
// QString copyOfOriginalObject = other->writeObjectToXmlString();
|
||||
// multiSnapshot->readObjectFromXmlString(copyOfOriginalObject, caf::PdmDefaultObjectFactory::instance());
|
||||
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
@ -240,13 +232,8 @@ void RiuExportMultipleSnapshotsWidget::addSnapshotItem()
|
||||
multiSnapshot->viewObject = ViewExample;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
m_rimProject->multiSnapshotDefinitions.push_back(multiSnapshot);
|
||||
m_rimProject->multiSnapshotDefinitions.uiCapability()->updateConnectedEditors();
|
||||
|
||||
|
@ -47,5 +47,5 @@ private slots:
|
||||
private:
|
||||
RimProject* m_rimProject;
|
||||
caf::PdmUiTableView* m_pdmTableView;
|
||||
QLineEdit* m_lineEdit;
|
||||
QLineEdit* m_exportFolderLineEdit;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user