2016-12-09 04:11:16 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016 Statoil ASA
|
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RiuExportMultipleSnapshotsWidget.h"
|
|
|
|
|
2016-12-13 08:17:50 -06:00
|
|
|
#include "RiaApplication.h"
|
|
|
|
|
2016-12-14 02:16:44 -06:00
|
|
|
#include "RicExportMultipleSnapshotsFeature.h"
|
|
|
|
|
2016-12-13 09:25:42 -06:00
|
|
|
#include "RimCase.h"
|
2016-12-09 07:40:26 -06:00
|
|
|
#include "RimMultiSnapshotDefinition.h"
|
2016-12-09 04:11:16 -06:00
|
|
|
#include "RimProject.h"
|
2016-12-13 02:52:05 -06:00
|
|
|
#include "RimView.h"
|
2016-12-09 04:11:16 -06:00
|
|
|
|
|
|
|
#include "cafCmdFeatureManager.h"
|
|
|
|
#include "cafPdmUiTableView.h"
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
2016-12-13 09:25:42 -06:00
|
|
|
#include <QFileDialog>
|
2016-12-09 04:11:16 -06:00
|
|
|
#include <QAbstractItemView>
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QDialogButtonBox>
|
2016-12-13 09:25:42 -06:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
2016-12-09 04:11:16 -06:00
|
|
|
#include <QMenu>
|
2016-12-13 09:25:42 -06:00
|
|
|
#include <QPushButton>
|
2016-12-09 04:11:16 -06:00
|
|
|
#include <QTableView>
|
2016-12-13 09:25:42 -06:00
|
|
|
#include <QToolButton>
|
2016-12-09 04:11:16 -06:00
|
|
|
#include <QWidget>
|
2016-12-19 08:05:53 -06:00
|
|
|
#include <QHeaderView>
|
2016-12-09 04:11:16 -06:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiuExportMultipleSnapshotsWidget::RiuExportMultipleSnapshotsWidget(QWidget* parent, RimProject* project)
|
2016-12-14 05:42:13 -06:00
|
|
|
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
2016-12-09 07:40:26 -06:00
|
|
|
m_rimProject(project)
|
2016-12-09 04:11:16 -06:00
|
|
|
{
|
|
|
|
setWindowTitle("Export Multiple Snapshots");
|
|
|
|
|
2016-12-13 09:25:42 -06:00
|
|
|
int nWidth = 800;
|
|
|
|
int nHeight = 300;
|
|
|
|
resize(nWidth, nHeight);
|
|
|
|
|
2016-12-09 04:11:16 -06:00
|
|
|
QVBoxLayout* dialogLayout = new QVBoxLayout;
|
|
|
|
setLayout(dialogLayout);
|
|
|
|
|
|
|
|
m_pdmTableView = new caf::PdmUiTableView(this);
|
|
|
|
m_pdmTableView->tableView()->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
m_pdmTableView->tableView()->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
|
|
connect(m_pdmTableView->tableView(), SIGNAL(customContextMenuRequested(QPoint)), SLOT(customMenuRequested(QPoint)));
|
|
|
|
|
|
|
|
m_pdmTableView->setListField(&(project->multiSnapshotDefinitions()));
|
2016-12-19 08:05:53 -06:00
|
|
|
|
|
|
|
QHeaderView* verticalHeader = m_pdmTableView->tableView()->verticalHeader();
|
|
|
|
verticalHeader->setResizeMode(QHeaderView::Interactive);
|
2016-12-09 04:11:16 -06:00
|
|
|
|
2016-12-09 07:40:26 -06:00
|
|
|
// Set active child array to be able to use generic delete
|
2016-12-09 04:11:16 -06:00
|
|
|
caf::SelectionManager::instance()->setActiveChildArrayFieldHandle(&(project->multiSnapshotDefinitions()));
|
|
|
|
|
|
|
|
dialogLayout->addWidget(m_pdmTableView);
|
|
|
|
|
2016-12-13 09:25:42 -06:00
|
|
|
// Export folder
|
|
|
|
{
|
|
|
|
QHBoxLayout* layout = new QHBoxLayout;
|
|
|
|
|
|
|
|
layout->addWidget(new QLabel("Export folder"));
|
|
|
|
|
|
|
|
// Save images in snapshot catalog relative to project directory
|
|
|
|
QString snapshotFolderName = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("snapshots");
|
|
|
|
|
2016-12-14 06:54:51 -06:00
|
|
|
m_exportFolderLineEdit = new QLineEdit(snapshotFolderName);
|
2016-12-13 09:25:42 -06:00
|
|
|
|
|
|
|
QToolButton* button = new QToolButton;
|
|
|
|
button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
|
|
|
|
button->setText(QLatin1String("..."));
|
|
|
|
|
2016-12-14 06:54:51 -06:00
|
|
|
layout->addWidget(m_exportFolderLineEdit);
|
2016-12-13 09:25:42 -06:00
|
|
|
layout->addWidget(button);
|
|
|
|
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(folderSelectionClicked()));
|
|
|
|
|
|
|
|
dialogLayout->addLayout(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-09 04:11:16 -06:00
|
|
|
// Buttons
|
2016-12-09 07:40:26 -06:00
|
|
|
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
2016-12-09 04:11:16 -06:00
|
|
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
|
|
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
|
|
|
|
2016-12-13 08:17:50 -06:00
|
|
|
QPushButton* exportButton = new QPushButton(tr("Export"));
|
|
|
|
exportButton->setDefault(true);
|
|
|
|
buttonBox->addButton(exportButton, QDialogButtonBox::ActionRole);
|
|
|
|
connect(exportButton, SIGNAL(clicked()), this, SLOT(exportSnapshots()));
|
|
|
|
|
2016-12-09 04:11:16 -06:00
|
|
|
dialogLayout->addWidget(buttonBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiuExportMultipleSnapshotsWidget::~RiuExportMultipleSnapshotsWidget()
|
|
|
|
{
|
2016-12-09 07:40:26 -06:00
|
|
|
m_pdmTableView->setListField(nullptr);
|
|
|
|
|
2016-12-09 04:11:16 -06:00
|
|
|
caf::SelectionManager::instance()->setActiveChildArrayFieldHandle(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuExportMultipleSnapshotsWidget::customMenuRequested(QPoint pos)
|
|
|
|
{
|
|
|
|
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
|
|
|
|
|
|
|
|
QMenu menu;
|
2016-12-09 07:40:26 -06:00
|
|
|
menu.addAction(commandManager->action("PdmListField_DeleteItem","Delete row"));
|
|
|
|
|
2016-12-13 02:52:05 -06:00
|
|
|
QAction* newRowAction = new QAction("New row", this);
|
2016-12-09 07:40:26 -06:00
|
|
|
connect(newRowAction, SIGNAL(triggered()), SLOT(addSnapshotItem()));
|
|
|
|
menu.addAction(newRowAction);
|
2016-12-13 02:52:05 -06:00
|
|
|
|
|
|
|
QAction* clearAllRows = new QAction("Clear", this);
|
|
|
|
connect(clearAllRows, SIGNAL(triggered()), SLOT(deleteAllSnapshotItems()));
|
|
|
|
menu.addAction(clearAllRows);
|
|
|
|
|
2016-12-09 04:11:16 -06:00
|
|
|
|
|
|
|
// Qt doc: QAbstractScrollArea and its subclasses that map the context menu event to coordinates of the viewport().
|
|
|
|
QPoint globalPos = m_pdmTableView->tableView()->viewport()->mapToGlobal(pos);
|
|
|
|
|
|
|
|
menu.exec(globalPos);
|
|
|
|
}
|
2016-12-09 07:40:26 -06:00
|
|
|
|
2016-12-13 02:52:05 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuExportMultipleSnapshotsWidget::deleteAllSnapshotItems()
|
|
|
|
{
|
|
|
|
if (!m_rimProject) return;
|
|
|
|
|
|
|
|
m_rimProject->multiSnapshotDefinitions.deleteAllChildObjects();
|
|
|
|
|
|
|
|
m_rimProject->multiSnapshotDefinitions.uiCapability()->updateConnectedEditors();
|
|
|
|
}
|
|
|
|
|
2016-12-13 08:17:50 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuExportMultipleSnapshotsWidget::exportSnapshots()
|
|
|
|
{
|
2016-12-14 06:54:51 -06:00
|
|
|
RicExportMultipleSnapshotsFeature::exportMultipleSnapshots(m_exportFolderLineEdit->text(), m_rimProject);
|
2016-12-13 08:17:50 -06:00
|
|
|
}
|
|
|
|
|
2016-12-13 09:25:42 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuExportMultipleSnapshotsWidget::folderSelectionClicked()
|
|
|
|
{
|
2016-12-14 06:54:51 -06:00
|
|
|
QString defaultPath = m_exportFolderLineEdit->text();
|
2016-12-13 09:25:42 -06:00
|
|
|
|
2016-12-14 06:54:51 -06:00
|
|
|
QString directoryPath = QFileDialog::getExistingDirectory(m_exportFolderLineEdit,
|
2016-12-13 09:25:42 -06:00
|
|
|
tr("Get existing directory"),
|
|
|
|
defaultPath,
|
|
|
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
|
|
|
|
|
|
|
if (!directoryPath.isEmpty())
|
|
|
|
{
|
2016-12-14 06:54:51 -06:00
|
|
|
m_exportFolderLineEdit->setText(directoryPath);
|
2016-12-13 09:25:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 07:40:26 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuExportMultipleSnapshotsWidget::addSnapshotItem()
|
|
|
|
{
|
|
|
|
if (!m_rimProject) return;
|
|
|
|
|
|
|
|
RimMultiSnapshotDefinition* multiSnapshot = new RimMultiSnapshotDefinition();
|
2016-12-13 02:52:05 -06:00
|
|
|
|
|
|
|
if (m_rimProject->multiSnapshotDefinitions.size() > 0)
|
|
|
|
{
|
2016-12-19 01:49:41 -06:00
|
|
|
//Getting default value from last entered line:
|
2016-12-13 02:52:05 -06:00
|
|
|
RimMultiSnapshotDefinition* other = m_rimProject->multiSnapshotDefinitions[m_rimProject->multiSnapshotDefinitions.size() - 1];
|
|
|
|
|
|
|
|
multiSnapshot->viewObject = other->viewObject();
|
|
|
|
multiSnapshot->timeStepStart = other->timeStepStart();
|
|
|
|
multiSnapshot->timeStepEnd = other->timeStepEnd();
|
|
|
|
}
|
2016-12-13 07:01:25 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
|
|
|
std::vector<RimCase*> cases;
|
|
|
|
proj->allCases(cases);
|
|
|
|
|
|
|
|
if (cases.size() > 0)
|
|
|
|
{
|
2016-12-19 01:49:41 -06:00
|
|
|
RimCase* caseExample = cases.at(0);
|
2016-12-13 07:01:25 -06:00
|
|
|
|
|
|
|
std::vector<RimView*> viewExamples;
|
2016-12-19 01:49:41 -06:00
|
|
|
viewExamples = caseExample->views();
|
2016-12-13 07:01:25 -06:00
|
|
|
|
|
|
|
if (viewExamples.size() > 0)
|
|
|
|
{
|
2016-12-19 01:49:41 -06:00
|
|
|
RimView* viewExample = viewExamples.at(0);
|
|
|
|
multiSnapshot->viewObject = viewExample;
|
|
|
|
multiSnapshot->timeStepStart = viewExample->currentTimeStep();
|
|
|
|
multiSnapshot->timeStepEnd = viewExample->currentTimeStep();
|
2016-12-13 07:01:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 02:52:05 -06:00
|
|
|
|
2016-12-09 07:40:26 -06:00
|
|
|
m_rimProject->multiSnapshotDefinitions.push_back(multiSnapshot);
|
|
|
|
m_rimProject->multiSnapshotDefinitions.uiCapability()->updateConnectedEditors();
|
|
|
|
}
|