mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
Importing several SIMEVENTS files together now merges them into one document before coalescing, so keyword events with the same owner, type and timestamp are combined across files, not only within one file. - Add merge_simulator_events_documents, parse_simulator_events_files and apply_simulator_events_files. Source locations carry the file name, so conflict warnings and errors identify both files. - Reject mismatched UNIT, and a second RESTART or duplicate WELSPECS across files. Collect parse errors from all files in one pass. - Warn when files declare the same FILTER name with different expressions, and keep each file's filter instead of reusing the first one. - CLI accepts multiple files; the import dialog allows multi-selection.
96 lines
4.2 KiB
C++
96 lines
4.2 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2026- 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 "RicImportSimulatorEventsFeature.h"
|
|
|
|
#include "RiaApplication.h"
|
|
#include "RiaGuiApplication.h"
|
|
#include "RiaLogging.h"
|
|
|
|
#include "Riu3DMainWindowTools.h"
|
|
#include "RiuFileDialogTools.h"
|
|
#include "RiuMainWindow.h"
|
|
|
|
#include <QAction>
|
|
#include <QFileInfo>
|
|
#include <QMessageBox>
|
|
|
|
CAF_CMD_SOURCE_INIT( RicImportSimulatorEventsFeature, "RicImportSimulatorEventsFeature" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicImportSimulatorEventsFeature::onActionTriggered( bool isChecked )
|
|
{
|
|
// The import runs as a Python child process which applies the events to this instance through
|
|
// gRPC, so both the script server and a Python interpreter must be available.
|
|
RiaApplication* app = RiaApplication::instance();
|
|
if ( !app->activeGrpcPortNumber() )
|
|
{
|
|
QMessageBox::warning( Riu3DMainWindowTools::mainWindowWidget(),
|
|
"Import Simulator Events",
|
|
"The Python script server is not running. Enable it in Preferences -> Scripting and restart ResInsight." );
|
|
return;
|
|
}
|
|
|
|
if ( app->pythonPath().isEmpty() )
|
|
{
|
|
QMessageBox::warning( Riu3DMainWindowTools::mainWindowWidget(),
|
|
"Import Simulator Events",
|
|
"No Python executable is configured in Preferences -> Scripting." );
|
|
return;
|
|
}
|
|
|
|
QString defaultDir = app->lastUsedDialogDirectory( "SIMULATOR_EVENTS_DIR" );
|
|
QStringList fileNames = RiuFileDialogTools::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(),
|
|
"Import Simulator Events",
|
|
defaultDir,
|
|
"Simulator Events Files (*.events);;All Files (*.*)" );
|
|
if ( fileNames.isEmpty() ) return;
|
|
|
|
app->setLastUsedDialogDirectory( "SIMULATOR_EVENTS_DIR", QFileInfo( fileNames.front() ).absolutePath() );
|
|
|
|
// Show the process monitor so the report and any errors from the child process are visible.
|
|
RiuMainWindow* mainWindow = RiuMainWindow::instance();
|
|
if ( !mainWindow )
|
|
{
|
|
mainWindow = RiaGuiApplication::instance()->getOrCreateAndShowMainWindow();
|
|
}
|
|
mainWindow->showProcessMonitorDockPanel();
|
|
|
|
// Unbuffered output ("-u") so the report streams into the process monitor promptly. The child
|
|
// process finds this instance through the RESINSIGHT_GRPC_PORT environment variable.
|
|
// Multiple files are merged into one document, so matching events from different files are
|
|
// combined into a single timeline event.
|
|
QStringList arguments = { "-u", "-m", "rips.simulator_events", "--apply" };
|
|
arguments.append( fileNames );
|
|
if ( !app->launchProcess( app->pythonPath(), arguments, app->pythonProcessEnvironment() ) )
|
|
{
|
|
RiaLogging::error( "Failed to launch the Python interpreter. Another script may already be running." );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicImportSimulatorEventsFeature::setupActionLook( QAction* actionToSetup )
|
|
{
|
|
actionToSetup->setText( "Import Simulator Events" );
|
|
actionToSetup->setIcon( QIcon( ":/Well.svg" ) );
|
|
}
|