mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-05 21:53:27 -06:00
* #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:
parent
61e9a2a696
commit
69b20a2aa9
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -30,6 +30,7 @@ class RicImportEclipseCaseFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
static bool openEclipseCaseFromFileNames(const QStringList& fileNames);
|
||||
protected:
|
||||
// Overrides
|
||||
bool isCommandEnabled() override;
|
||||
|
@ -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;
|
||||
|
||||
|
111
ApplicationCode/Commands/RicImportGeneralDataFeature.cpp
Normal file
111
ApplicationCode/Commands/RicImportGeneralDataFeature.cpp
Normal 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");
|
||||
}
|
37
ApplicationCode/Commands/RicImportGeneralDataFeature.h
Normal file
37
ApplicationCode/Commands/RicImportGeneralDataFeature.h
Normal 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;
|
||||
};
|
@ -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);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -28,7 +28,7 @@
|
||||
class RicImportSummaryCaseFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
static bool openSummaryCaseFromFileNames(const QStringList& fileNames);
|
||||
protected:
|
||||
// Overrides
|
||||
bool isCommandEnabled() override;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user