#4007 Create new combined import button and move the others to an opt… (#4021)

* #4007 Create new combined import button and move the others to an optional "Import"-toolbar

* #4007 Make sure we check that fileName vector isn't empty before accessing it
This commit is contained in:
Gaute Lindkvist 2019-01-31 09:02:09 +01:00 committed by GitHub
parent 61e9a2a696
commit 69b20a2aa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 205 additions and 23 deletions

View File

@ -42,6 +42,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicImportSummaryCaseFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportSummaryCasesFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportObservedDataFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportObservedDataInMenuFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportGeneralDataFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicExportFeatureImpl.h
${CMAKE_CURRENT_LIST_DIR}/RicSelectOrCreateViewFeatureImpl.h
@ -119,6 +120,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicImportSummaryCaseFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportSummaryCasesFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportObservedDataFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportObservedDataInMenuFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportGeneralDataFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicExportFeatureImpl.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSelectOrCreateViewFeatureImpl.cpp

View File

@ -34,6 +34,23 @@
CAF_CMD_SOURCE_INIT(RicImportEclipseCaseFeature, "RicImportEclipseCaseFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportEclipseCaseFeature::openEclipseCaseFromFileNames(const QStringList& fileNames)
{
QStringList newCaseFiles;
if (RiaImportEclipseCaseTools::openEclipseCasesFromFile(fileNames, &newCaseFiles))
{
for (const auto newCaseFile : newCaseFiles)
{
RiaApplication::instance()->addToRecentFiles(newCaseFile);
}
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -51,16 +68,13 @@ void RicImportEclipseCaseFeature::onActionTriggered(bool isChecked)
QString defaultDir = app->lastUsedDialogDirectory("BINARY_GRID");
QStringList fileNames = QFileDialog::getOpenFileNames(Riu3DMainWindowTools::mainWindowWidget(), "Import Eclipse File", defaultDir, "Eclipse Grid Files (*.GRID *.EGRID)");
if (fileNames.size()) defaultDir = QFileInfo(fileNames.last()).absolutePath();
if (fileNames.isEmpty()) return;
defaultDir = QFileInfo(fileNames.last()).absolutePath();
app->setLastUsedDialogDirectory("BINARY_GRID", defaultDir);
QStringList newCaseFiles;
RiaImportEclipseCaseTools::openEclipseCasesFromFile(fileNames, &newCaseFiles);
for (const auto newCaseFile : newCaseFiles)
{
RiaApplication::instance()->addToRecentFiles(newCaseFile);
}
openEclipseCaseFromFileNames(fileNames);
}
//--------------------------------------------------------------------------------------------------

View File

@ -30,6 +30,7 @@ class RicImportEclipseCaseFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
static bool openEclipseCaseFromFileNames(const QStringList& fileNames);
protected:
// Overrides
bool isCommandEnabled() override;

View File

@ -101,7 +101,7 @@ void RicImportInputEclipseCaseFeature::onActionTriggered(bool isChecked)
{
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectory("INPUT_FILES");
QStringList fileNames = QFileDialog::getOpenFileNames(Riu3DMainWindowTools::mainWindowWidget(), "Import Eclipse Input Files", defaultDir, "Eclipse Input Files and Input Properties Eclipse Input Files (*.GRDECL);;All Files (*.*)");
QStringList fileNames = QFileDialog::getOpenFileNames(Riu3DMainWindowTools::mainWindowWidget(), "Import Eclipse Input Files", defaultDir, "Eclipse Input Files and Input Properties (*.GRDECL);;All Files (*.*)");
if (fileNames.isEmpty()) return;

View File

@ -0,0 +1,111 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor 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 "RicImportGeneralDataFeature.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RicImportEclipseCaseFeature.h"
#include "RicImportInputEclipseCaseFeature.h"
#include "RicImportSummaryCaseFeature.h"
#include "Riu3DMainWindowTools.h"
#include <QAction>
#include <QFileDialog>
#include <QString>
#include <QStringList>
CAF_CMD_SOURCE_INIT(RicImportGeneralDataFeature, "RicImportGeneralDataFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportGeneralDataFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportGeneralDataFeature::onActionTriggered(bool isChecked)
{
RiaApplication* app = RiaApplication::instance();
QString eclipseGridFilePattern("*.GRID *.EGRID");
QString eclipseInputFilePattern("*.GRDECL");
QString eclipseSummaryFilePattern("*.SMSPEC");
QStringList filePatternTexts = {
QString("Eclipse Files (%1 %2 %3)").arg(eclipseGridFilePattern).arg(eclipseInputFilePattern).arg(eclipseSummaryFilePattern),
QString("Eclipse Grid Files (%1)").arg(eclipseGridFilePattern),
QString("Eclipse Input Files and Input Properties (%1)").arg(eclipseInputFilePattern),
QString("Eclipse Summary File (%1)").arg(eclipseSummaryFilePattern)
};
QString fullPattern = filePatternTexts.join(";;");
QString defaultDir = app->lastUsedDialogDirectory("GENERAL_DATA");
QStringList fileNames = QFileDialog::getOpenFileNames(
Riu3DMainWindowTools::mainWindowWidget(), "Import Data File", defaultDir, fullPattern);
if (fileNames.empty()) return;
defaultDir = QFileInfo(fileNames.last()).absolutePath();
app->setLastUsedDialogDirectory("GENERAL_DATA", defaultDir);
QStringList eclipseCaseFiles;
QStringList eclipseInputFiles;
QStringList eclipseSummaryFiles;
for (const QString& fileName : fileNames)
{
if (fileName.endsWith("GRID"))
{
eclipseCaseFiles.push_back(fileName);
}
else if (fileName.endsWith("GRDECL"))
{
eclipseInputFiles.push_back(fileName);
}
else if (fileName.endsWith("SMSPEC"))
{
eclipseSummaryFiles.push_back(fileName);
}
}
if (!eclipseCaseFiles.empty())
{
RicImportEclipseCaseFeature::openEclipseCaseFromFileNames(eclipseCaseFiles);
}
if (!eclipseInputFiles.empty())
{
RicImportInputEclipseCaseFeature::openInputEclipseCaseFromFileNames(eclipseInputFiles);
}
if (!eclipseSummaryFiles.empty())
{
RicImportSummaryCaseFeature::openSummaryCaseFromFileNames(eclipseSummaryFiles);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportGeneralDataFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setIcon(QIcon(":/Case48x48.png"));
actionToSetup->setText("Import Eclipse Data Files");
}

View File

@ -0,0 +1,37 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
#include <vector>
//==================================================================================================
///
//==================================================================================================
class RicImportGeneralDataFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered(bool isChecked) override;
void setupActionLook(QAction* actionToSetup) override;
};

View File

@ -40,6 +40,24 @@
CAF_CMD_SOURCE_INIT(RicImportSummaryCaseFeature, "RicImportSummaryCaseFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportSummaryCaseFeature::openSummaryCaseFromFileNames(const QStringList& fileNames)
{
std::vector<RimSummaryCase*> newCases;
if (RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles(fileNames, &newCases))
{
RicImportSummaryCasesFeature::addCasesToGroupIfRelevant(newCases);
for (const RimSummaryCase* newCase : newCases)
{
RiaApplication::instance()->addToRecentFiles(newCase->summaryHeaderFilename());
}
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -67,20 +85,12 @@ void RicImportSummaryCaseFeature::onActionTriggered(bool isChecked)
fileNames.push_back(RiaFilePathTools::toInternalSeparator(s));
}
if (fileNames.isEmpty()) return;
// Remember the path to next time
app->setLastUsedDialogDirectory("INPUT_FILES", QFileInfo(fileNames.last()).absolutePath());
if (fileNames.isEmpty()) return;
std::vector<RimSummaryCase*> newCases;
if (RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles(fileNames, &newCases))
{
RicImportSummaryCasesFeature::addCasesToGroupIfRelevant(newCases);
for (const RimSummaryCase* newCase : newCases)
{
RiaApplication::instance()->addToRecentFiles(newCase->summaryHeaderFilename());
}
}
openSummaryCaseFromFileNames(fileNames);
}
//--------------------------------------------------------------------------------------------------

View File

@ -28,7 +28,7 @@
class RicImportSummaryCaseFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
static bool openSummaryCaseFromFileNames(const QStringList& fileNames);
protected:
// Overrides
bool isCommandEnabled() override;

View File

@ -529,11 +529,18 @@ void RiuMainWindow::createToolBars()
{
QToolBar* toolbar = addToolBar(tr("Standard"));
toolbar->setObjectName(toolbar->windowTitle());
toolbar->addAction(cmdFeatureMgr->action("RicImportGeneralDataFeature"));
toolbar->addAction(cmdFeatureMgr->action("RicOpenProjectFeature"));
toolbar->addAction(cmdFeatureMgr->action("RicSaveProjectFeature"));
}
{
QToolBar* toolbar = addToolBar(tr("Import"));
toolbar->setObjectName(toolbar->windowTitle());
toolbar->addAction(cmdFeatureMgr->action("RicImportEclipseCaseFeature"));
toolbar->addAction(cmdFeatureMgr->action("RicImportInputEclipseCaseFeature"));
toolbar->addAction(cmdFeatureMgr->action("RicImportSummaryCaseFeature"));
toolbar->addAction(cmdFeatureMgr->action("RicOpenProjectFeature"));
toolbar->addAction(cmdFeatureMgr->action("RicSaveProjectFeature"));
toolbar->hide();
}
{