mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Rename ApplicationCode to ApplicationLibCode
This commit is contained in:
67
ApplicationLibCode/Application/CMakeLists_files.cmake
Normal file
67
ApplicationLibCode/Application/CMakeLists_files.cmake
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaApplication.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaConsoleApplication.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGuiApplication.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCompletionTypeCalculationScheduler.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaDefines.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFractureDefines.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPreferences.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPorosityModel.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSummaryCurveDefinition.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCurveSetDefinition.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaRftPltCurveDefinition.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPlotWindowRedrawScheduler.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseFileNameTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFeatureCommandContext.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStringListSerializer.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaNncDefines.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStimPlanModelDefines.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaApplication.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaConsoleApplication.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGuiApplication.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCompletionTypeCalculationScheduler.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaDefines.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFractureDefines.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaMain.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPreferences.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPorosityModel.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSummaryCurveDefinition.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCurveSetDefinition.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaRftPltCurveDefinition.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPlotWindowRedrawScheduler.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseFileNameTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFeatureCommandContext.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStringListSerializer.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaNncDefines.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStimPlanModelDefines.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
${SOURCE_GROUP_HEADER_FILES}
|
||||
)
|
||||
|
||||
list(APPEND CODE_SOURCE_FILES
|
||||
${SOURCE_GROUP_SOURCE_FILES}
|
||||
)
|
||||
|
||||
set (QT_MOC_HEADERS
|
||||
${QT_MOC_HEADERS}
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaConsoleApplication.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGuiApplication.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCompletionTypeCalculationScheduler.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPlotWindowRedrawScheduler.h
|
||||
)
|
||||
|
||||
|
||||
source_group( "Application" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )
|
||||
1904
ApplicationLibCode/Application/RiaApplication.cpp
Normal file
1904
ApplicationLibCode/Application/RiaApplication.cpp
Normal file
File diff suppressed because it is too large
Load Diff
272
ApplicationLibCode/Application/RiaApplication.h
Normal file
272
ApplicationLibCode/Application/RiaApplication.h
Normal file
@@ -0,0 +1,272 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 "RiaDefines.h"
|
||||
#ifdef ENABLE_GRPC
|
||||
#include "RiaGrpcServer.h"
|
||||
#endif
|
||||
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
#include "cvfFont.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
#include <QMutex>
|
||||
#include <QPointer>
|
||||
#include <QProcess>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QString>
|
||||
|
||||
#include <gsl/gsl>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
class QAction;
|
||||
|
||||
class Drawable;
|
||||
|
||||
class RIProcess;
|
||||
|
||||
class RiaPreferences;
|
||||
class RiaProjectModifier;
|
||||
class RiaSocketServer;
|
||||
|
||||
class RigEclipseCaseData;
|
||||
|
||||
class RimCommandObject;
|
||||
class RimEclipseCase;
|
||||
class RimEclipseView;
|
||||
class RimWellPath;
|
||||
class RimGridView;
|
||||
class RimProject;
|
||||
class RimSummaryPlot;
|
||||
class Rim3dView;
|
||||
class RimViewWindow;
|
||||
class RimWellLogFile;
|
||||
class RimWellLogPlot;
|
||||
class RimWellAllocationPlot;
|
||||
|
||||
class RiuMainWindow;
|
||||
class RiuMainWindowBase;
|
||||
class RiuPlotMainWindow;
|
||||
class RiuRecentFileActionProvider;
|
||||
class RiaArgumentParser;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class UiProcess;
|
||||
}
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class ProgramOptions;
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
/// Base class for all ResInsight applications. I.e. console and GUI
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaApplication
|
||||
{
|
||||
public:
|
||||
enum class ProjectLoadAction
|
||||
{
|
||||
PLA_NONE = 0,
|
||||
PLA_CALCULATE_STATISTICS = 1
|
||||
};
|
||||
|
||||
enum class ApplicationStatus
|
||||
{
|
||||
KEEP_GOING = 0,
|
||||
EXIT_COMPLETED,
|
||||
EXIT_WITH_ERROR
|
||||
};
|
||||
|
||||
public:
|
||||
static RiaApplication* instance();
|
||||
RiaApplication();
|
||||
virtual ~RiaApplication();
|
||||
|
||||
static const char* getVersionStringApp( bool includeCrtInfo );
|
||||
static bool enableDevelopmentFeatures();
|
||||
|
||||
void setActiveReservoirView( Rim3dView* );
|
||||
Rim3dView* activeReservoirView();
|
||||
const Rim3dView* activeReservoirView() const;
|
||||
RimGridView* activeGridView();
|
||||
RimGridView* activeMainOrComparisonGridView();
|
||||
int currentScriptCaseId() const;
|
||||
|
||||
RimProject* project();
|
||||
|
||||
void createMockModel();
|
||||
void createResultsMockModel();
|
||||
void createLargeResultsMockModel();
|
||||
void createMockModelCustomized();
|
||||
void createInputMockModel();
|
||||
|
||||
bool openFile( const QString& fileName );
|
||||
|
||||
bool isProjectSavedToDisc() const;
|
||||
QString currentProjectPath() const;
|
||||
QString createAbsolutePathFromProjectRelativePath( QString projectRelativePath );
|
||||
|
||||
bool loadProject( const QString& projectFileName );
|
||||
bool loadProject( const QString& projectFileName, ProjectLoadAction loadAction, RiaProjectModifier* projectModifier );
|
||||
|
||||
bool saveProject( gsl::not_null<QString*> errorMessage );
|
||||
bool saveProjectAs( const QString& fileName, gsl::not_null<QString*> errorMessage );
|
||||
|
||||
static bool hasValidProjectFileExtension( const QString& fileName );
|
||||
void closeProject();
|
||||
|
||||
QString lastUsedDialogDirectory( const QString& dialogName );
|
||||
QString lastUsedDialogDirectoryWithFallbackToProjectFolder( const QString& dialogName );
|
||||
QString lastUsedDialogDirectoryWithFallback( const QString& dialogName, const QString& fallbackDirectory );
|
||||
void setLastUsedDialogDirectory( const QString& dialogName, const QString& directory );
|
||||
|
||||
bool openOdbCaseFromFile( const QString& fileName, bool applyTimeStepFilter = false );
|
||||
|
||||
std::vector<RimWellPath*> addWellPathsToModel( QList<QString> wellPathFilePaths,
|
||||
bool importGrouped,
|
||||
gsl::not_null<QStringList*> errorMessages );
|
||||
void addWellPathFormationsToModel( QList<QString> wellPathFilePaths );
|
||||
std::vector<RimWellLogFile*> addWellLogsToModel( const QList<QString>& wellLogFilePaths,
|
||||
gsl::not_null<QStringList*> errorMessages );
|
||||
|
||||
QString scriptDirectories() const;
|
||||
QString scriptEditorPath() const;
|
||||
|
||||
QString octavePath() const;
|
||||
QStringList octaveArguments() const;
|
||||
QProcessEnvironment octaveProcessEnvironment() const;
|
||||
|
||||
QString pythonPath() const;
|
||||
QProcessEnvironment pythonProcessEnvironment() const;
|
||||
|
||||
bool launchProcess( const QString& program, const QStringList& arguments, const QProcessEnvironment& processEnvironment );
|
||||
bool launchProcessForMultipleCases( const QString& program,
|
||||
const QStringList& arguments,
|
||||
const std::vector<int>& caseIds,
|
||||
const QProcessEnvironment& processEnvironment );
|
||||
void terminateProcess();
|
||||
void waitForProcess() const;
|
||||
|
||||
RiaPreferences* preferences();
|
||||
void applyPreferences();
|
||||
|
||||
QString commandLineParameterHelp();
|
||||
void setCommandLineHelpText( const QString& commandLineHelpText );
|
||||
|
||||
void setCacheDataObject( const QString& key, const QVariant& dataObject );
|
||||
QVariant cacheDataObject( const QString& key ) const;
|
||||
|
||||
void executeCommandFile( const QString& commandFile );
|
||||
void addCommandObject( RimCommandObject* commandObject );
|
||||
void executeCommandObjects();
|
||||
void waitUntilCommandObjectsHasBeenProcessed();
|
||||
|
||||
int launchUnitTests();
|
||||
|
||||
const QString startDir() const;
|
||||
void setStartDir( const QString& startDir );
|
||||
|
||||
static std::vector<QString> readFileListFromTextFile( QString listFileName );
|
||||
|
||||
cvf::Font* defaultSceneFont();
|
||||
cvf::Font* sceneFont( int fontSize );
|
||||
cvf::Font* defaultAnnotationFont();
|
||||
cvf::Font* defaultWellLabelFont();
|
||||
|
||||
bool initializeGrpcServer( const cvf::ProgramOptions& progOpt );
|
||||
|
||||
// Public implementation specific overrides
|
||||
virtual void initialize();
|
||||
virtual ApplicationStatus handleArguments( gsl::not_null<cvf::ProgramOptions*> progOpt ) = 0;
|
||||
virtual int launchUnitTestsWithConsole();
|
||||
virtual void addToRecentFiles( const QString& fileName ) {}
|
||||
virtual void showFormattedTextInMessageBoxOrConsole( const QString& errMsg ) = 0;
|
||||
|
||||
virtual void launchGrpcServer() = 0;
|
||||
|
||||
#ifdef ENABLE_GRPC
|
||||
virtual RiaGrpcServer* grpcServer() const = 0;
|
||||
#endif
|
||||
protected:
|
||||
// Protected implementation specific overrides
|
||||
virtual void invokeProcessEvents( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) = 0;
|
||||
virtual void onFileSuccessfullyLoaded( const QString& fileName, RiaDefines::ImportFileType fileType ) {}
|
||||
|
||||
virtual void onProjectBeingOpened() {}
|
||||
virtual void onProjectOpened() = 0;
|
||||
virtual void onProjectOpeningError( const QString& errMsg ) = 0;
|
||||
virtual void onProjectBeingClosed() {}
|
||||
virtual void onProjectClosed() = 0;
|
||||
virtual void onProjectBeingSaved() {}
|
||||
virtual void onProjectSaved() {}
|
||||
|
||||
virtual void startMonitoringWorkProgress( caf::UiProcess* uiProcess ) {}
|
||||
virtual void stopMonitoringWorkProgress() {}
|
||||
|
||||
void loadAndUpdatePlotData();
|
||||
|
||||
friend class RiaRegressionTestRunner;
|
||||
void resetProject();
|
||||
|
||||
bool generateCode( const QString& outputPath, gsl::not_null<QString*> errMsg );
|
||||
|
||||
protected:
|
||||
cvf::ref<cvf::Font> m_defaultSceneFont;
|
||||
cvf::ref<cvf::Font> m_defaultAnnotationFont;
|
||||
cvf::ref<cvf::Font> m_defaultWellLabelFont;
|
||||
|
||||
caf::PdmPointer<Rim3dView> m_activeReservoirView;
|
||||
std::unique_ptr<RimProject> m_project;
|
||||
|
||||
QPointer<RiaSocketServer> m_socketServer;
|
||||
std::unique_ptr<caf::UiProcess> m_workerProcess;
|
||||
|
||||
#ifdef ENABLE_GRPC
|
||||
std::unique_ptr<RiaGrpcServer> m_grpcServer;
|
||||
#endif
|
||||
|
||||
// Execute for all settings
|
||||
std::list<int> m_scriptCaseIds;
|
||||
int m_currentScriptCaseId;
|
||||
QString m_currentProgram;
|
||||
QStringList m_currentArguments;
|
||||
std::unique_ptr<RiaPreferences> m_preferences;
|
||||
|
||||
std::map<QString, QString> m_fileDialogDefaultDirectories;
|
||||
QString m_startupDefaultDirectory;
|
||||
QString m_commandLineHelpText;
|
||||
QMap<QString, QVariant> m_sessionCache; // Session cache used to store username/passwords per session
|
||||
|
||||
std::list<caf::PdmPointer<RimCommandObject>> m_commandQueue;
|
||||
QMutex m_commandQueueLock;
|
||||
|
||||
bool m_runningWorkerProcess;
|
||||
|
||||
private:
|
||||
static RiaApplication* s_riaApplication;
|
||||
};
|
||||
@@ -0,0 +1,170 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaCompletionTypeCalculationScheduler.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RigCaseCellResultsData.h"
|
||||
#include "RigEclipseCaseData.h"
|
||||
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimEclipseCaseCollection.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "RiuMainWindow.h"
|
||||
#include "RiuViewer.h"
|
||||
|
||||
#include "cafPdmUiTreeView.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QTreeView>
|
||||
|
||||
#include "cafProgressState.h"
|
||||
#include <set>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaCompletionTypeCalculationScheduler* RiaCompletionTypeCalculationScheduler::instance()
|
||||
{
|
||||
static RiaCompletionTypeCalculationScheduler theInstance;
|
||||
|
||||
return &theInstance;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaCompletionTypeCalculationScheduler::scheduleRecalculateCompletionTypeAndRedrawAllViews()
|
||||
{
|
||||
std::vector<RimEclipseCase*> eclipseCases =
|
||||
RimProject::current()->activeOilField()->analysisModels->cases().childObjects();
|
||||
|
||||
scheduleRecalculateCompletionTypeAndRedrawAllViews( eclipseCases );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaCompletionTypeCalculationScheduler::scheduleRecalculateCompletionTypeAndRedrawAllViews( RimEclipseCase* eclipseCase )
|
||||
{
|
||||
std::vector<RimEclipseCase*> eclipseCases;
|
||||
eclipseCases.push_back( eclipseCase );
|
||||
|
||||
scheduleRecalculateCompletionTypeAndRedrawAllViews( eclipseCases );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaCompletionTypeCalculationScheduler::scheduleRecalculateCompletionTypeAndRedrawAllViews(
|
||||
const std::vector<RimEclipseCase*>& eclipseCases )
|
||||
{
|
||||
for ( RimEclipseCase* eclipseCase : eclipseCases )
|
||||
{
|
||||
CVF_ASSERT( eclipseCase );
|
||||
|
||||
if ( eclipseCase->eclipseCaseData() )
|
||||
{
|
||||
eclipseCase->eclipseCaseData()
|
||||
->results( RiaDefines::PorosityModelType::MATRIX_MODEL )
|
||||
->clearScalarResult( RiaDefines::ResultCatType::DYNAMIC_NATIVE, RiaDefines::completionTypeResultName() );
|
||||
|
||||
// Delete virtual perforation transmissibilities, as these are the basis for the computation of completion type
|
||||
eclipseCase->eclipseCaseData()->setVirtualPerforationTransmissibilities( nullptr );
|
||||
}
|
||||
|
||||
m_eclipseCasesToRecalculate.push_back( eclipseCase );
|
||||
}
|
||||
|
||||
startTimer();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaCompletionTypeCalculationScheduler::slotRecalculateCompletionType()
|
||||
{
|
||||
if ( caf::ProgressState::isActive() )
|
||||
{
|
||||
startTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
std::set<RimEclipseCase*> uniqueCases( m_eclipseCasesToRecalculate.begin(), m_eclipseCasesToRecalculate.end() );
|
||||
|
||||
Rim3dView* activeView = RiaApplication::instance()->activeReservoirView();
|
||||
QModelIndex mi = RiuMainWindow::instance()->projectTreeView()->treeView()->currentIndex();
|
||||
|
||||
for ( RimEclipseCase* eclipseCase : uniqueCases )
|
||||
{
|
||||
if ( eclipseCase )
|
||||
{
|
||||
for ( const auto& w : eclipseCase->views() )
|
||||
{
|
||||
RimEclipseView* eclView = dynamic_cast<RimEclipseView*>( w );
|
||||
if ( eclView )
|
||||
{
|
||||
eclView->calculateCompletionTypeAndRedrawIfRequired();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_eclipseCasesToRecalculate.clear();
|
||||
|
||||
// Recalculation of completion type causes active view to be set to potentially a different view
|
||||
// Also current index in project tree is changed. Restore both to initial state.
|
||||
|
||||
if ( activeView && activeView->viewer() )
|
||||
{
|
||||
RiaApplication::instance()->setActiveReservoirView( activeView );
|
||||
RiuMainWindow::instance()->setActiveViewer( activeView->viewer()->layoutWidget() );
|
||||
}
|
||||
|
||||
if ( mi.isValid() )
|
||||
{
|
||||
RiuMainWindow::instance()->projectTreeView()->treeView()->setCurrentIndex( mi );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaCompletionTypeCalculationScheduler::~RiaCompletionTypeCalculationScheduler()
|
||||
{
|
||||
delete m_recalculateCompletionTypeTimer;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaCompletionTypeCalculationScheduler::startTimer()
|
||||
{
|
||||
if ( !m_recalculateCompletionTypeTimer )
|
||||
{
|
||||
m_recalculateCompletionTypeTimer = new QTimer( this );
|
||||
m_recalculateCompletionTypeTimer->setSingleShot( true );
|
||||
connect( m_recalculateCompletionTypeTimer, SIGNAL( timeout() ), this, SLOT( slotRecalculateCompletionType() ) );
|
||||
}
|
||||
|
||||
m_recalculateCompletionTypeTimer->start( 1500 );
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "cafPdmPointer.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class QTimer;
|
||||
class RimEclipseCase;
|
||||
|
||||
class RiaCompletionTypeCalculationScheduler : public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
static RiaCompletionTypeCalculationScheduler* instance();
|
||||
void scheduleRecalculateCompletionTypeAndRedrawAllViews();
|
||||
void scheduleRecalculateCompletionTypeAndRedrawAllViews( RimEclipseCase* eclipseCase );
|
||||
|
||||
private slots:
|
||||
void slotRecalculateCompletionType();
|
||||
|
||||
private:
|
||||
RiaCompletionTypeCalculationScheduler()
|
||||
: m_recalculateCompletionTypeTimer( nullptr )
|
||||
{
|
||||
}
|
||||
~RiaCompletionTypeCalculationScheduler() override;
|
||||
|
||||
RiaCompletionTypeCalculationScheduler( const RiaCompletionTypeCalculationScheduler& o ) = delete;
|
||||
void operator=( const RiaCompletionTypeCalculationScheduler& o ) = delete;
|
||||
|
||||
void scheduleRecalculateCompletionTypeAndRedrawAllViews( const std::vector<RimEclipseCase*>& eclipseCases );
|
||||
|
||||
void startTimer();
|
||||
|
||||
private:
|
||||
std::vector<caf::PdmPointer<RimEclipseCase>> m_eclipseCasesToRecalculate;
|
||||
QTimer* m_recalculateCompletionTypeTimer;
|
||||
};
|
||||
452
ApplicationLibCode/Application/RiaConsoleApplication.cpp
Normal file
452
ApplicationLibCode/Application/RiaConsoleApplication.cpp
Normal file
@@ -0,0 +1,452 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaConsoleApplication.h"
|
||||
|
||||
#include "RiaArgumentParser.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiaProjectModifier.h"
|
||||
#include "RiaSocketServer.h"
|
||||
|
||||
#include "RicImportGeneralDataFeature.h"
|
||||
|
||||
#include "cvfProgramOptions.h"
|
||||
#include "cvfqtUtils.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaConsoleApplication* RiaConsoleApplication::instance()
|
||||
{
|
||||
RiaConsoleApplication* currentConsoleApp = dynamic_cast<RiaConsoleApplication*>( RiaApplication::instance() );
|
||||
CAF_ASSERT( currentConsoleApp && "Should never be called from a method that isn't within the Console context" );
|
||||
return currentConsoleApp;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaConsoleApplication::RiaConsoleApplication( int& argc, char** argv )
|
||||
: QCoreApplication( argc, argv )
|
||||
, RiaApplication()
|
||||
{
|
||||
installEventFilter( this );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaConsoleApplication::~RiaConsoleApplication()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::initialize()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#pragma warning( push ) // Saves the current warning state.
|
||||
#pragma warning( disable : 4996 ) // Temporarily disables warning 4996.
|
||||
|
||||
bool isReOpenStdToConsoleNeeded = false;
|
||||
|
||||
if ( AttachConsole( ATTACH_PARENT_PROCESS ) )
|
||||
{
|
||||
int fileType = GetFileType( GetStdHandle( STD_OUTPUT_HANDLE ) );
|
||||
|
||||
// FILE_TYPE_CHAR indicates a windows console buffer.
|
||||
// FILE_TYPE_PIPE indicates redirection imposed by the starting shell (eg migw shell)
|
||||
// If we are dealing with a pipe, we do not want to do the reopen, and destroy the connection.
|
||||
|
||||
if ( fileType == FILE_TYPE_CHAR )
|
||||
{
|
||||
isReOpenStdToConsoleNeeded = true;
|
||||
}
|
||||
}
|
||||
else if ( AllocConsole() )
|
||||
{
|
||||
isReOpenStdToConsoleNeeded = true;
|
||||
}
|
||||
|
||||
if ( isReOpenStdToConsoleNeeded )
|
||||
{
|
||||
freopen( "conout$", "w", stdout );
|
||||
freopen( "conout$", "w", stderr );
|
||||
freopen( "conin$", "r", stdin );
|
||||
}
|
||||
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
RiaApplication::initialize();
|
||||
|
||||
RiaLogging::setLoggerInstance( std::make_unique<RiaStdOutLogger>() );
|
||||
RiaLogging::loggerInstance()->setLevel( int( RILogLevel::RI_LL_DEBUG ) );
|
||||
|
||||
m_socketServer = new RiaSocketServer( this );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaApplication::ApplicationStatus RiaConsoleApplication::handleArguments( gsl::not_null<cvf::ProgramOptions*> progOpt )
|
||||
{
|
||||
// Handling of the actual command line options
|
||||
// --------------------------------------------------------
|
||||
if ( cvf::Option o = progOpt->option( "ignoreArgs" ) )
|
||||
{
|
||||
return ApplicationStatus::KEEP_GOING;
|
||||
}
|
||||
|
||||
if ( progOpt->option( "help" ) || progOpt->option( "?" ) )
|
||||
{
|
||||
this->showFormattedTextInMessageBoxOrConsole( "\nThe current command line options in ResInsight are:\n" +
|
||||
this->commandLineParameterHelp() );
|
||||
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
|
||||
}
|
||||
|
||||
// Code generation
|
||||
// -----------------
|
||||
if ( cvf::Option o = progOpt->option( "generate" ) )
|
||||
{
|
||||
CVF_ASSERT( o.valueCount() == 1 );
|
||||
QString outputFile = cvfqt::Utils::toQString( o.value( 0 ) );
|
||||
|
||||
QString errMsg;
|
||||
if ( !RiaApplication::generateCode( outputFile, &errMsg ) )
|
||||
{
|
||||
RiaLogging::error( QString( "Error: %1" ).arg( errMsg ) );
|
||||
return RiaApplication::ApplicationStatus::EXIT_WITH_ERROR;
|
||||
}
|
||||
|
||||
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
|
||||
}
|
||||
|
||||
// Unit testing
|
||||
// --------------------------------------------------------
|
||||
if ( cvf::Option o = progOpt->option( "unittest" ) )
|
||||
{
|
||||
int testReturnValue = launchUnitTestsWithConsole();
|
||||
if ( testReturnValue == 0 )
|
||||
{
|
||||
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::error( "Error running unit tests" );
|
||||
return RiaApplication::ApplicationStatus::EXIT_WITH_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if ( cvf::Option o = progOpt->option( "startdir" ) )
|
||||
{
|
||||
CVF_ASSERT( o.valueCount() == 1 );
|
||||
setStartDir( cvfqt::Utils::toQString( o.value( 0 ) ) );
|
||||
}
|
||||
|
||||
QString projectFileName;
|
||||
|
||||
if ( progOpt->hasOption( "last" ) )
|
||||
{
|
||||
projectFileName = preferences()->lastUsedProjectFileName;
|
||||
}
|
||||
|
||||
if ( cvf::Option o = progOpt->option( "project" ) )
|
||||
{
|
||||
CVF_ASSERT( o.valueCount() == 1 );
|
||||
projectFileName = cvfqt::Utils::toQString( o.value( 0 ) );
|
||||
}
|
||||
|
||||
if ( !projectFileName.isEmpty() )
|
||||
{
|
||||
cvf::ref<RiaProjectModifier> projectModifier;
|
||||
RiaApplication::ProjectLoadAction projectLoadAction = RiaApplication::ProjectLoadAction::PLA_NONE;
|
||||
|
||||
if ( cvf::Option o = progOpt->option( "replaceCase" ) )
|
||||
{
|
||||
if ( projectModifier.isNull() ) projectModifier = new RiaProjectModifier;
|
||||
|
||||
if ( o.valueCount() == 1 )
|
||||
{
|
||||
// One argument is available, use replace case for first occurrence in the project
|
||||
|
||||
QString gridFileName = cvfqt::Utils::toQString( o.safeValue( 0 ) );
|
||||
projectModifier->setReplaceCaseFirstOccurrence( gridFileName );
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t optionIdx = 0;
|
||||
while ( optionIdx < o.valueCount() )
|
||||
{
|
||||
const int caseId = o.safeValue( optionIdx++ ).toInt( -1 );
|
||||
QString gridFileName = cvfqt::Utils::toQString( o.safeValue( optionIdx++ ) );
|
||||
|
||||
if ( caseId != -1 && !gridFileName.isEmpty() )
|
||||
{
|
||||
projectModifier->setReplaceCase( caseId, gridFileName );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( cvf::Option o = progOpt->option( "replaceSourceCases" ) )
|
||||
{
|
||||
if ( projectModifier.isNull() ) projectModifier = new RiaProjectModifier;
|
||||
|
||||
if ( o.valueCount() == 1 )
|
||||
{
|
||||
// One argument is available, use replace case for first occurrence in the project
|
||||
|
||||
std::vector<QString> gridFileNames =
|
||||
readFileListFromTextFile( cvfqt::Utils::toQString( o.safeValue( 0 ) ) );
|
||||
projectModifier->setReplaceSourceCasesFirstOccurrence( gridFileNames );
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t optionIdx = 0;
|
||||
while ( optionIdx < o.valueCount() )
|
||||
{
|
||||
const int groupId = o.safeValue( optionIdx++ ).toInt( -1 );
|
||||
std::vector<QString> gridFileNames =
|
||||
readFileListFromTextFile( cvfqt::Utils::toQString( o.safeValue( optionIdx++ ) ) );
|
||||
|
||||
if ( groupId != -1 && !gridFileNames.empty() )
|
||||
{
|
||||
projectModifier->setReplaceSourceCasesById( groupId, gridFileNames );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
projectLoadAction = RiaApplication::ProjectLoadAction::PLA_CALCULATE_STATISTICS;
|
||||
}
|
||||
|
||||
if ( cvf::Option o = progOpt->option( "replacePropertiesFolder" ) )
|
||||
{
|
||||
if ( projectModifier.isNull() ) projectModifier = new RiaProjectModifier;
|
||||
|
||||
if ( o.valueCount() == 1 )
|
||||
{
|
||||
QString propertiesFolder = cvfqt::Utils::toQString( o.safeValue( 0 ) );
|
||||
projectModifier->setReplacePropertiesFolderFirstOccurrence( propertiesFolder );
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t optionIdx = 0;
|
||||
while ( optionIdx < o.valueCount() )
|
||||
{
|
||||
const int caseId = o.safeValue( optionIdx++ ).toInt( -1 );
|
||||
QString propertiesFolder = cvfqt::Utils::toQString( o.safeValue( optionIdx++ ) );
|
||||
|
||||
if ( caseId != -1 && !propertiesFolder.isEmpty() )
|
||||
{
|
||||
projectModifier->setReplacePropertiesFolder( caseId, propertiesFolder );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadProject( projectFileName, projectLoadAction, projectModifier.p() );
|
||||
}
|
||||
|
||||
if ( cvf::Option o = progOpt->option( "case" ) )
|
||||
{
|
||||
QStringList fileNames =
|
||||
RicImportGeneralDataFeature::fileNamesFromCaseNames( cvfqt::Utils::toQStringList( o.values() ) );
|
||||
|
||||
RicImportGeneralDataFeature::openEclipseFilesFromFileNames( fileNames, true );
|
||||
}
|
||||
|
||||
if ( cvf::Option o = progOpt->option( "commandFile" ) )
|
||||
{
|
||||
QString commandFile = cvfqt::Utils::toQString( o.safeValue( 0 ) );
|
||||
if ( !progOpt->hasOption( "startdir" ) )
|
||||
{
|
||||
QFileInfo commandFileInfo( commandFile );
|
||||
QString commandDir = commandFileInfo.absolutePath();
|
||||
setStartDir( commandDir );
|
||||
}
|
||||
|
||||
cvf::Option projectOption = progOpt->option( "commandFileProject" );
|
||||
cvf::Option caseOption = progOpt->option( "commandFileReplaceCases" );
|
||||
if ( projectOption && caseOption )
|
||||
{
|
||||
projectFileName = cvfqt::Utils::toQString( projectOption.value( 0 ) );
|
||||
|
||||
std::vector<int> caseIds;
|
||||
std::vector<QString> caseListFiles;
|
||||
|
||||
if ( caseOption.valueCount() == 1 )
|
||||
{
|
||||
caseListFiles.push_back( cvfqt::Utils::toQString( caseOption.safeValue( 0 ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t optionIdx = 0;
|
||||
while ( optionIdx < caseOption.valueCount() )
|
||||
{
|
||||
const int caseId = caseOption.safeValue( optionIdx++ ).toInt( -1 );
|
||||
QString caseListFile = cvfqt::Utils::toQString( caseOption.safeValue( optionIdx++ ) );
|
||||
|
||||
if ( caseId != -1 && !caseListFile.isEmpty() )
|
||||
{
|
||||
caseIds.push_back( caseId );
|
||||
caseListFiles.push_back( caseListFile );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( caseIds.empty() && !caseListFiles.empty() )
|
||||
{
|
||||
QString caseListFile = caseListFiles[0];
|
||||
std::vector<QString> caseFiles = readFileListFromTextFile( caseListFile );
|
||||
for ( const QString& caseFile : caseFiles )
|
||||
{
|
||||
RiaProjectModifier projectModifier;
|
||||
projectModifier.setReplaceCaseFirstOccurrence( caseFile );
|
||||
loadProject( projectFileName, RiaApplication::ProjectLoadAction::PLA_NONE, &projectModifier );
|
||||
executeCommandFile( commandFile );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CVF_ASSERT( caseIds.size() == caseListFiles.size() );
|
||||
|
||||
std::vector<std::vector<QString>> allCaseFiles;
|
||||
size_t maxFiles = 0;
|
||||
|
||||
for ( size_t i = 0; i < caseIds.size(); ++i )
|
||||
{
|
||||
std::vector<QString> caseFiles = readFileListFromTextFile( caseListFiles[i] );
|
||||
allCaseFiles.push_back( caseFiles );
|
||||
maxFiles = std::max( caseFiles.size(), maxFiles );
|
||||
}
|
||||
|
||||
for ( size_t i = 0; i < caseIds.size(); ++i )
|
||||
{
|
||||
RiaProjectModifier projectModifier;
|
||||
for ( size_t j = 0; j < maxFiles; ++j )
|
||||
{
|
||||
if ( allCaseFiles[i].size() > j )
|
||||
{
|
||||
projectModifier.setReplaceCase( caseIds[i], allCaseFiles[i][j] );
|
||||
}
|
||||
}
|
||||
|
||||
loadProject( projectFileName, RiaApplication::ProjectLoadAction::PLA_NONE, &projectModifier );
|
||||
executeCommandFile( commandFile );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
executeCommandFile( commandFile );
|
||||
}
|
||||
return ApplicationStatus::EXIT_COMPLETED;
|
||||
}
|
||||
|
||||
return ApplicationStatus::KEEP_GOING;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::showFormattedTextInMessageBoxOrConsole( const QString& errMsg )
|
||||
{
|
||||
std::cout << errMsg.toStdString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::launchGrpcServer()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
m_grpcServer->runInThread();
|
||||
m_idleTimer = new QTimer( this );
|
||||
connect( m_idleTimer, SIGNAL( timeout() ), this, SLOT( runIdleProcessing() ) );
|
||||
m_idleTimer->start( 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_GRPC
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaGrpcServer* RiaConsoleApplication::grpcServer() const
|
||||
{
|
||||
return m_grpcServer.get();
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::invokeProcessEvents( QEventLoop::ProcessEventsFlags flags /*= QEventLoop::AllEvents*/ )
|
||||
{
|
||||
processEvents( flags );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::onProjectOpeningError( const QString& errMsg )
|
||||
{
|
||||
RiaLogging::error( errMsg );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::onProjectOpened()
|
||||
{
|
||||
loadAndUpdatePlotData();
|
||||
processEvents();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::onProjectClosed()
|
||||
{
|
||||
processEvents();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::runIdleProcessing()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
if ( RiaGrpcServer::receivedExitRequest() )
|
||||
{
|
||||
m_grpcServer->quit();
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_grpcServer->processAllQueuedRequests();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
65
ApplicationLibCode/Application/RiaConsoleApplication.h
Normal file
65
ApplicationLibCode/Application/RiaConsoleApplication.h
Normal file
@@ -0,0 +1,65 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaApplication.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include <QPointer>
|
||||
#include <QTimer>
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class ProgramOptions;
|
||||
}
|
||||
|
||||
class RiaConsoleApplication : public QCoreApplication, public RiaApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static RiaConsoleApplication* instance();
|
||||
|
||||
RiaConsoleApplication( int& argc, char** argv );
|
||||
~RiaConsoleApplication() override;
|
||||
|
||||
// Public RiaApplication overrides
|
||||
void initialize() override;
|
||||
ApplicationStatus handleArguments( gsl::not_null<cvf::ProgramOptions*> progOpt ) override;
|
||||
void showFormattedTextInMessageBoxOrConsole( const QString& errMsg ) override;
|
||||
void launchGrpcServer() override;
|
||||
#ifdef ENABLE_GRPC
|
||||
RiaGrpcServer* grpcServer() const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// Protected implementation specific overrides
|
||||
void invokeProcessEvents( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) override;
|
||||
void onProjectOpeningError( const QString& errMsg ) override;
|
||||
void onProjectOpened() override;
|
||||
void onProjectClosed() override;
|
||||
|
||||
private slots:
|
||||
void runIdleProcessing();
|
||||
|
||||
private:
|
||||
#ifdef ENABLE_GRPC
|
||||
QPointer<QTimer> m_idleTimer;
|
||||
#endif
|
||||
};
|
||||
69
ApplicationLibCode/Application/RiaCurveSetDefinition.cpp
Normal file
69
ApplicationLibCode/Application/RiaCurveSetDefinition.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaCurveSetDefinition.h"
|
||||
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
#include "RimSummaryCaseCollection.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaCurveSetDefinition::RiaCurveSetDefinition()
|
||||
: m_ensemble( nullptr )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaCurveSetDefinition::RiaCurveSetDefinition( RimSummaryCaseCollection* ensemble,
|
||||
const RifEclipseSummaryAddress& summaryAddress )
|
||||
: m_ensemble( ensemble )
|
||||
, m_summaryAddress( summaryAddress )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryCaseCollection* RiaCurveSetDefinition::ensemble() const
|
||||
{
|
||||
return m_ensemble;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const RifEclipseSummaryAddress& RiaCurveSetDefinition::summaryAddress() const
|
||||
{
|
||||
return m_summaryAddress;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaCurveSetDefinition::operator<( const RiaCurveSetDefinition& other ) const
|
||||
{
|
||||
if ( m_ensemble != other.ensemble() )
|
||||
{
|
||||
return ( m_ensemble < other.ensemble() );
|
||||
}
|
||||
|
||||
return ( m_summaryAddress < other.summaryAddress() );
|
||||
}
|
||||
47
ApplicationLibCode/Application/RiaCurveSetDefinition.h
Normal file
47
ApplicationLibCode/Application/RiaCurveSetDefinition.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class RimSummaryCaseCollection;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaCurveSetDefinition
|
||||
{
|
||||
public:
|
||||
RiaCurveSetDefinition();
|
||||
explicit RiaCurveSetDefinition( RimSummaryCaseCollection* emsemble, const RifEclipseSummaryAddress& summaryAddress );
|
||||
|
||||
RimSummaryCaseCollection* ensemble() const;
|
||||
const RifEclipseSummaryAddress& summaryAddress() const;
|
||||
|
||||
bool operator<( const RiaCurveSetDefinition& other ) const;
|
||||
|
||||
private:
|
||||
RimSummaryCaseCollection* m_ensemble;
|
||||
RifEclipseSummaryAddress m_summaryAddress;
|
||||
};
|
||||
652
ApplicationLibCode/Application/RiaDefines.cpp
Normal file
652
ApplicationLibCode/Application/RiaDefines.cpp
Normal file
@@ -0,0 +1,652 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 "RiaDefines.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::ResultCatType>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::ResultCatType::DYNAMIC_NATIVE, "DYNAMIC_NATIVE", "Dynamic" );
|
||||
addItem( RiaDefines::ResultCatType::STATIC_NATIVE, "STATIC_NATIVE", "Static" );
|
||||
addItem( RiaDefines::ResultCatType::SOURSIMRL, "SOURSIMRL", "SourSimRL" );
|
||||
addItem( RiaDefines::ResultCatType::GENERATED, "GENERATED", "Generated" );
|
||||
addItem( RiaDefines::ResultCatType::INPUT_PROPERTY, "INPUT_PROPERTY", "Input Property" );
|
||||
addItem( RiaDefines::ResultCatType::FORMATION_NAMES, "FORMATION_NAMES", "Formation Names" );
|
||||
addItem( RiaDefines::ResultCatType::ALLAN_DIAGRAMS, "ALLAN_DIAGRAMS", "Allan Diagrams" );
|
||||
addItem( RiaDefines::ResultCatType::FLOW_DIAGNOSTICS, "FLOW_DIAGNOSTICS", "Flow Diagnostics" );
|
||||
addItem( RiaDefines::ResultCatType::INJECTION_FLOODING, "INJECTION_FLOODING", "Injection Flooding" );
|
||||
setDefault( RiaDefines::ResultCatType::DYNAMIC_NATIVE );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::DepthUnitType>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::DepthUnitType::UNIT_METER, "UNIT_METER", "Meter" );
|
||||
addItem( RiaDefines::DepthUnitType::UNIT_FEET, "UNIT_FEET", "Feet" );
|
||||
addItem( RiaDefines::DepthUnitType::UNIT_NONE, "UNIT_NONE", "None" );
|
||||
|
||||
setDefault( RiaDefines::DepthUnitType::UNIT_METER );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::DepthTypeEnum>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::DepthTypeEnum::MEASURED_DEPTH, "MEASURED_DEPTH", "Measured Depth" );
|
||||
addItem( RiaDefines::DepthTypeEnum::TRUE_VERTICAL_DEPTH, "TRUE_VERTICAL_DEPTH", "True Vertical Depth (MSL)" );
|
||||
addItem( RiaDefines::DepthTypeEnum::PSEUDO_LENGTH, "PSEUDO_LENGTH", "Pseudo Length" );
|
||||
addItem( RiaDefines::DepthTypeEnum::CONNECTION_NUMBER, "CONNECTION_NUMBER", "Connection Number" );
|
||||
addItem( RiaDefines::DepthTypeEnum::TRUE_VERTICAL_DEPTH_RKB, "TRUE_VERTICAL_DEPTH_RKB", "True Vertical Depth (RKB)" );
|
||||
setDefault( RiaDefines::DepthTypeEnum::MEASURED_DEPTH );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::PlotAxis>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, "PLOT_AXIS_LEFT", "Left" );
|
||||
addItem( RiaDefines::PlotAxis::PLOT_AXIS_RIGHT, "PLOT_AXIS_RIGHT", "Right" );
|
||||
|
||||
setDefault( RiaDefines::PlotAxis::PLOT_AXIS_LEFT );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::PhaseType>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::PhaseType::OIL_PHASE, "OIL_PHASE", "Oil" );
|
||||
addItem( RiaDefines::PhaseType::GAS_PHASE, "GAS_PHASE", "Gas" );
|
||||
addItem( RiaDefines::PhaseType::WATER_PHASE, "WATER_PHASE", "Water" );
|
||||
setDefault( RiaDefines::PhaseType::OIL_PHASE );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::WellPathComponentType>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::WellPathComponentType::WELL_PATH, "WELL_PATH", "Well Path" );
|
||||
addItem( RiaDefines::WellPathComponentType::PERFORATION_INTERVAL, "PERFORATION_INTERVAL", "Perforation Interval" );
|
||||
addItem( RiaDefines::WellPathComponentType::FISHBONES, "FISHBONES", "Fishbones" );
|
||||
addItem( RiaDefines::WellPathComponentType::FRACTURE, "FRACTURE", "Fracture" );
|
||||
addItem( RiaDefines::WellPathComponentType::ICD, "ICD", "ICD" );
|
||||
addItem( RiaDefines::WellPathComponentType::AICD, "AICD", "AICD" );
|
||||
addItem( RiaDefines::WellPathComponentType::ICV, "ICV", "ICV" );
|
||||
addItem( RiaDefines::WellPathComponentType::CASING, "CASING", "Casing" );
|
||||
addItem( RiaDefines::WellPathComponentType::LINER, "LINER", "Liner" );
|
||||
addItem( RiaDefines::WellPathComponentType::PACKER, "PACKER", "Packer" );
|
||||
addItem( RiaDefines::WellPathComponentType::UNDEFINED_COMPONENT, "UNDEFINED", "Undefined Component" );
|
||||
setDefault( RiaDefines::WellPathComponentType::WELL_PATH );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::MeshModeType>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::MeshModeType::FULL_MESH, "FULL_MESH", "All" );
|
||||
addItem( RiaDefines::MeshModeType::FAULTS_MESH, "FAULTS_MESH", "Faults only" );
|
||||
addItem( RiaDefines::MeshModeType::NO_MESH, "NO_MESH", "None" );
|
||||
setDefault( RiaDefines::MeshModeType::FULL_MESH );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::GridCaseAxis>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::GridCaseAxis::UNDEFINED_AXIS, "None", "None" );
|
||||
addItem( RiaDefines::GridCaseAxis::AXIS_I, "I", "I" );
|
||||
addItem( RiaDefines::GridCaseAxis::AXIS_J, "J", "J" );
|
||||
addItem( RiaDefines::GridCaseAxis::AXIS_K, "K", "K" );
|
||||
|
||||
setDefault( RiaDefines::GridCaseAxis::AXIS_K );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::ThemeEnum>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::ThemeEnum::DEFAULT, "DEFAULT", "Default theme" );
|
||||
addItem( RiaDefines::ThemeEnum::DARK, "DARK", "Dark theme" );
|
||||
addItem( RiaDefines::ThemeEnum::LIGHT, "LIGHT", "Light theme" );
|
||||
setDefault( RiaDefines::ThemeEnum::DEFAULT );
|
||||
}
|
||||
|
||||
} // namespace caf
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDefines::isPerCellFaceResult( const QString& resultName )
|
||||
{
|
||||
if ( resultName.compare( RiaDefines::combinedTransmissibilityResultName(), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( resultName.compare( RiaDefines::combinedMultResultName(), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( resultName.compare( RiaDefines::ternarySaturationResultName(), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( resultName.compare( RiaDefines::combinedRiTranResultName(), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( resultName.compare( RiaDefines::combinedRiMultResultName(), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( resultName.compare( RiaDefines::combinedRiAreaNormTranResultName(), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( resultName.compare( RiaDefines::combinedWaterFluxResultName(), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( resultName.compare( RiaDefines::combinedOilFluxResultName(), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( resultName.compare( RiaDefines::combinedGasFluxResultName(), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( resultName.endsWith( "IJK" ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDefines::isNativeCategoryResult( const QString& resultName )
|
||||
{
|
||||
return resultName.endsWith( "NUM" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::undefinedResultName()
|
||||
{
|
||||
const static QString undefResultName = "None";
|
||||
|
||||
return undefResultName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::undefinedGridFaultName()
|
||||
{
|
||||
return "Undefined Grid Faults";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::undefinedGridFaultWithInactiveName()
|
||||
{
|
||||
return "Undefined Grid Faults With Inactive";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::combinedTransmissibilityResultName()
|
||||
{
|
||||
return "TRANXYZ";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::combinedWaterFluxResultName()
|
||||
{
|
||||
return "FLRWATIJK";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::combinedOilFluxResultName()
|
||||
{
|
||||
return "FLROILIJK";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::combinedGasFluxResultName()
|
||||
{
|
||||
return "FLRGASIJK";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::ternarySaturationResultName()
|
||||
{
|
||||
return "TERNARY";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::combinedMultResultName()
|
||||
{
|
||||
return "MULTXYZ";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::eqlnumResultName()
|
||||
{
|
||||
return "EQLNUM";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riTranXResultName()
|
||||
{
|
||||
return "riTRANX";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riTranYResultName()
|
||||
{
|
||||
return "riTRANY";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riTranZResultName()
|
||||
{
|
||||
return "riTRANZ";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::combinedRiTranResultName()
|
||||
{
|
||||
return "riTRANXYZ";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riMultXResultName()
|
||||
{
|
||||
return "riMULTX";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riMultYResultName()
|
||||
{
|
||||
return "riMULTY";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riMultZResultName()
|
||||
{
|
||||
return "riMULTZ";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::combinedRiMultResultName()
|
||||
{
|
||||
return "riMULTXYZ";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riAreaNormTranXResultName()
|
||||
{
|
||||
return "riTRANXbyArea";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riAreaNormTranYResultName()
|
||||
{
|
||||
return "riTRANYbyArea";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riAreaNormTranZResultName()
|
||||
{
|
||||
return "riTRANZbyArea";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::combinedRiAreaNormTranResultName()
|
||||
{
|
||||
return "riTRANXYZbyArea";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riCellVolumeResultName()
|
||||
{
|
||||
return "riCELLVOLUME";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::riOilVolumeResultName()
|
||||
{
|
||||
return "riOILVOLUME";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::mobilePoreVolumeName()
|
||||
{
|
||||
return "MOBPORV";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::completionTypeResultName()
|
||||
{
|
||||
return "Completion Type";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::formationBinaryAllanResultName()
|
||||
{
|
||||
return "Binary Formation Allan";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::formationAllanResultName()
|
||||
{
|
||||
return "Formation Allan";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<QString> RiaDefines::nncResultNames()
|
||||
{
|
||||
return { combinedTransmissibilityResultName(),
|
||||
formationAllanResultName(),
|
||||
formationBinaryAllanResultName(),
|
||||
combinedWaterFluxResultName(),
|
||||
combinedGasFluxResultName(),
|
||||
combinedOilFluxResultName(),
|
||||
combinedRiAreaNormTranResultName(),
|
||||
combinedRiMultResultName(),
|
||||
combinedRiTranResultName() };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::mockModelBasic()
|
||||
{
|
||||
return "Result Mock Debug Model Simple";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::mockModelBasicWithResults()
|
||||
{
|
||||
return "Result Mock Debug Model With Results";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::mockModelLargeWithResults()
|
||||
{
|
||||
return "Result Mock Debug Model Large With Results";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::mockModelCustomized()
|
||||
{
|
||||
return "Result Mock Debug Model Customized";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::mockModelBasicInputCase()
|
||||
{
|
||||
return "Input Mock Debug Model Simple";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::activeFormationNamesResultName()
|
||||
{
|
||||
return "Active Formation Names";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::wbsAzimuthResult()
|
||||
{
|
||||
return "Azimuth";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::wbsInclinationResult()
|
||||
{
|
||||
return "Inclination";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::wbsPPResult()
|
||||
{
|
||||
return "PP";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::wbsSHResult()
|
||||
{
|
||||
return "SHMIN";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::wbsSHMkResult()
|
||||
{
|
||||
return "SH_MK";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::wbsOBGResult()
|
||||
{
|
||||
return "OBG";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::wbsFGResult()
|
||||
{
|
||||
return "FG";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::wbsSFGResult()
|
||||
{
|
||||
return "SFG";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QString> RiaDefines::wbsAngleResultNames()
|
||||
{
|
||||
return { wbsAzimuthResult(), wbsInclinationResult() };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QString> RiaDefines::wbsDerivedResultNames()
|
||||
{
|
||||
return {
|
||||
wbsFGResult(),
|
||||
wbsOBGResult(),
|
||||
wbsPPResult(),
|
||||
wbsSFGResult(),
|
||||
wbsSHResult(),
|
||||
wbsSHMkResult(),
|
||||
};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaDefines::minimumDefaultValuePlot()
|
||||
{
|
||||
return -10.0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaDefines::minimumDefaultLogValuePlot()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaDefines::maximumDefaultValuePlot()
|
||||
{
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaDefines::ImportFileType RiaDefines::obtainFileTypeFromFileName( const QString& fileName )
|
||||
{
|
||||
if ( fileName.endsWith( "EGRID", Qt::CaseInsensitive ) )
|
||||
{
|
||||
return ImportFileType::ECLIPSE_EGRID_FILE;
|
||||
}
|
||||
else if ( fileName.endsWith( "GRID", Qt::CaseInsensitive ) )
|
||||
{
|
||||
return ImportFileType::ECLIPSE_GRID_FILE;
|
||||
}
|
||||
else if ( fileName.endsWith( "GRDECL", Qt::CaseInsensitive ) )
|
||||
{
|
||||
return ImportFileType::ECLIPSE_INPUT_FILE;
|
||||
}
|
||||
else if ( fileName.endsWith( "SMSPEC", Qt::CaseInsensitive ) )
|
||||
{
|
||||
return ImportFileType::ECLIPSE_SUMMARY_FILE;
|
||||
}
|
||||
else if ( fileName.endsWith( "ODB", Qt::CaseInsensitive ) )
|
||||
{
|
||||
return ImportFileType::GEOMECH_ODB_FILE;
|
||||
}
|
||||
else if ( fileName.endsWith( ".rsp", Qt::CaseInsensitive ) || fileName.endsWith( ".rip", Qt::CaseInsensitive ) )
|
||||
{
|
||||
return ImportFileType::RESINSIGHT_PROJECT_FILE;
|
||||
}
|
||||
return ImportFileType::NOT_A_VALID_IMPORT_FILE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::defaultDirectoryLabel( RiaDefines::ImportFileType fileType )
|
||||
{
|
||||
QString defaultDirLabel;
|
||||
|
||||
int fileTypeAsInt = int( fileType );
|
||||
|
||||
if ( fileType == ImportFileType::ANY_ECLIPSE_FILE )
|
||||
{
|
||||
defaultDirLabel = "GENERAL_DATA";
|
||||
}
|
||||
else if ( fileTypeAsInt & int( ImportFileType::ECLIPSE_RESULT_GRID ) )
|
||||
{
|
||||
defaultDirLabel = "BINARY_GRID";
|
||||
}
|
||||
else if ( fileTypeAsInt & int( ImportFileType::ECLIPSE_INPUT_FILE ) )
|
||||
{
|
||||
defaultDirLabel = "INPUT_FILES";
|
||||
}
|
||||
else if ( fileTypeAsInt & int( ImportFileType::ECLIPSE_SUMMARY_FILE ) )
|
||||
{
|
||||
// TODO: Summary files used "INPUT_FILES" as last used directory.
|
||||
// Check if this is correct.
|
||||
defaultDirLabel = "INPUT_FILES";
|
||||
}
|
||||
else if ( fileTypeAsInt & int( ImportFileType::GEOMECH_ODB_FILE ) )
|
||||
{
|
||||
defaultDirLabel = "GEOMECH_MODEL";
|
||||
}
|
||||
|
||||
return defaultDirLabel;
|
||||
}
|
||||
226
ApplicationLibCode/Application/RiaDefines.h
Normal file
226
ApplicationLibCode/Application/RiaDefines.h
Normal file
@@ -0,0 +1,226 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 <QString>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace RiaDefines
|
||||
{
|
||||
enum class ResultCatType
|
||||
{
|
||||
DYNAMIC_NATIVE,
|
||||
STATIC_NATIVE,
|
||||
SOURSIMRL,
|
||||
GENERATED,
|
||||
INPUT_PROPERTY,
|
||||
FORMATION_NAMES,
|
||||
ALLAN_DIAGRAMS,
|
||||
FLOW_DIAGNOSTICS,
|
||||
INJECTION_FLOODING,
|
||||
REMOVED,
|
||||
|
||||
UNDEFINED = 999
|
||||
};
|
||||
|
||||
// WARNING: DO NOT CHANGE THE ORDER WITHOUT KNOWING WHAT YOU ARE DOING!
|
||||
// You may well change the behaviour of property filters.
|
||||
enum class WellPathComponentType
|
||||
{
|
||||
// Production Tube
|
||||
WELL_PATH,
|
||||
// Well path flow completions
|
||||
PERFORATION_INTERVAL,
|
||||
FISHBONES,
|
||||
FRACTURE,
|
||||
ICD,
|
||||
AICD,
|
||||
ICV,
|
||||
// Well path construction features
|
||||
CASING,
|
||||
LINER,
|
||||
PACKER,
|
||||
UNDEFINED_COMPONENT
|
||||
};
|
||||
|
||||
enum class MeshModeType
|
||||
{
|
||||
FULL_MESH,
|
||||
FAULTS_MESH,
|
||||
NO_MESH
|
||||
};
|
||||
|
||||
bool isPerCellFaceResult( const QString& resultName );
|
||||
bool isNativeCategoryResult( const QString& resultName );
|
||||
|
||||
QString undefinedResultName();
|
||||
QString undefinedGridFaultName();
|
||||
QString undefinedGridFaultWithInactiveName();
|
||||
QString combinedTransmissibilityResultName();
|
||||
QString combinedWaterFluxResultName();
|
||||
QString combinedOilFluxResultName();
|
||||
QString combinedGasFluxResultName();
|
||||
|
||||
QString ternarySaturationResultName();
|
||||
QString combinedMultResultName();
|
||||
|
||||
QString eqlnumResultName();
|
||||
|
||||
QString riTranXResultName();
|
||||
QString riTranYResultName();
|
||||
QString riTranZResultName();
|
||||
QString combinedRiTranResultName();
|
||||
|
||||
QString riMultXResultName();
|
||||
QString riMultYResultName();
|
||||
QString riMultZResultName();
|
||||
QString combinedRiMultResultName();
|
||||
|
||||
QString riAreaNormTranXResultName();
|
||||
QString riAreaNormTranYResultName();
|
||||
QString riAreaNormTranZResultName();
|
||||
QString combinedRiAreaNormTranResultName();
|
||||
|
||||
QString riCellVolumeResultName();
|
||||
QString riOilVolumeResultName();
|
||||
QString mobilePoreVolumeName();
|
||||
|
||||
QString completionTypeResultName();
|
||||
|
||||
// Fault results
|
||||
QString formationBinaryAllanResultName();
|
||||
QString formationAllanResultName();
|
||||
std::set<QString> nncResultNames();
|
||||
|
||||
// Mock model text identifiers
|
||||
QString mockModelBasic();
|
||||
QString mockModelBasicWithResults();
|
||||
QString mockModelLargeWithResults();
|
||||
QString mockModelCustomized();
|
||||
QString mockModelBasicInputCase();
|
||||
|
||||
QString activeFormationNamesResultName();
|
||||
|
||||
// Well path derived results
|
||||
QString wbsAzimuthResult();
|
||||
QString wbsInclinationResult();
|
||||
QString wbsPPResult();
|
||||
QString wbsSHResult();
|
||||
QString wbsSHMkResult();
|
||||
QString wbsOBGResult();
|
||||
QString wbsFGResult();
|
||||
QString wbsSFGResult();
|
||||
|
||||
// List of well path derived results
|
||||
std::vector<QString> wbsAngleResultNames();
|
||||
std::vector<QString> wbsDerivedResultNames();
|
||||
|
||||
// Units and conversions
|
||||
enum class DepthUnitType
|
||||
{
|
||||
UNIT_METER,
|
||||
UNIT_FEET,
|
||||
UNIT_NONE
|
||||
};
|
||||
|
||||
// Depth types used for well log plots
|
||||
enum class DepthTypeEnum
|
||||
{
|
||||
MEASURED_DEPTH,
|
||||
TRUE_VERTICAL_DEPTH,
|
||||
PSEUDO_LENGTH,
|
||||
CONNECTION_NUMBER,
|
||||
TRUE_VERTICAL_DEPTH_RKB
|
||||
};
|
||||
|
||||
// Defines relate to plotting
|
||||
enum class PlotAxis
|
||||
{
|
||||
PLOT_AXIS_LEFT,
|
||||
PLOT_AXIS_RIGHT,
|
||||
PLOT_AXIS_BOTTOM
|
||||
};
|
||||
|
||||
double minimumDefaultValuePlot();
|
||||
double minimumDefaultLogValuePlot();
|
||||
double maximumDefaultValuePlot();
|
||||
|
||||
enum class PhaseType
|
||||
{
|
||||
OIL_PHASE,
|
||||
GAS_PHASE,
|
||||
WATER_PHASE,
|
||||
PHASE_NOT_APPLICABLE
|
||||
};
|
||||
|
||||
enum class ImportFileType
|
||||
{
|
||||
NOT_A_VALID_IMPORT_FILE = 0x00,
|
||||
ECLIPSE_GRID_FILE = 0x01,
|
||||
ECLIPSE_EGRID_FILE = 0x02,
|
||||
ECLIPSE_INPUT_FILE = 0x04,
|
||||
ECLIPSE_SUMMARY_FILE = 0x08,
|
||||
GEOMECH_ODB_FILE = 0x10,
|
||||
RESINSIGHT_PROJECT_FILE = 0x20,
|
||||
ECLIPSE_RESULT_GRID = ECLIPSE_GRID_FILE | ECLIPSE_EGRID_FILE,
|
||||
ANY_ECLIPSE_FILE = ECLIPSE_RESULT_GRID | ECLIPSE_INPUT_FILE | ECLIPSE_SUMMARY_FILE,
|
||||
ANY_IMPORT_FILE = 0xFF
|
||||
};
|
||||
|
||||
ImportFileType obtainFileTypeFromFileName( const QString& fileName );
|
||||
QString defaultDirectoryLabel( ImportFileType fileTypes );
|
||||
|
||||
enum class CaseType
|
||||
{
|
||||
UNDEFINED_CASE = -1,
|
||||
ECLIPSE_RESULT_CASE = 1,
|
||||
ECLIPSE_INPUT_CASE = 2,
|
||||
ECLIPSE_STAT_CASE = 3,
|
||||
ECLIPSE_SOURCE_CASE = 4,
|
||||
GEOMECH_ODB_CASE = 5
|
||||
};
|
||||
|
||||
enum class FontSettingType
|
||||
{
|
||||
SCENE_FONT,
|
||||
ANNOTATION_FONT,
|
||||
WELL_LABEL_FONT,
|
||||
PLOT_FONT
|
||||
};
|
||||
|
||||
enum class GridCaseAxis
|
||||
{
|
||||
AXIS_I,
|
||||
AXIS_J,
|
||||
AXIS_K,
|
||||
UNDEFINED_AXIS
|
||||
};
|
||||
|
||||
enum class ThemeEnum
|
||||
{
|
||||
DEFAULT,
|
||||
DARK,
|
||||
LIGHT,
|
||||
UNDEFINED
|
||||
};
|
||||
|
||||
}; // namespace RiaDefines
|
||||
141
ApplicationLibCode/Application/RiaEclipseFileNameTools.cpp
Normal file
141
ApplicationLibCode/Application/RiaEclipseFileNameTools.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaEclipseFileNameTools.h"
|
||||
|
||||
#include "QFileInfo"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
void caf::AppEnum<RiaEclipseFileNameTools::EclipseFileType>::setUp()
|
||||
{
|
||||
addItem( RiaEclipseFileNameTools::EclipseFileType::ECLIPSE_DATA, "DATA", "Data Deck" );
|
||||
addItem( RiaEclipseFileNameTools::EclipseFileType::ECLIPSE_GRID, "GRID", "Grid" );
|
||||
addItem( RiaEclipseFileNameTools::EclipseFileType::ECLIPSE_EGRID, "EGRID", "Grid" );
|
||||
addItem( RiaEclipseFileNameTools::EclipseFileType::ECLIPSE_UNRST, "UNRST", "Unified Restart" );
|
||||
addItem( RiaEclipseFileNameTools::EclipseFileType::ECLIPSE_SMSPEC, "SMSPEC", "Summary Specification" );
|
||||
addItem( RiaEclipseFileNameTools::EclipseFileType::ECLIPSE_UNSMRY, "UNSMR", "Summary Vectors" );
|
||||
|
||||
addItem( RiaEclipseFileNameTools::EclipseFileType::RESINSIGHT_PROJECT, "rsp", "ResInsight Project" );
|
||||
}
|
||||
|
||||
} // End namespace caf
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaEclipseFileNameTools::RiaEclipseFileNameTools( const QString& inputFilePath )
|
||||
{
|
||||
QFileInfo fi( inputFilePath );
|
||||
|
||||
m_baseName = fi.absolutePath() + "/" + fi.baseName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaEclipseFileNameTools::findRelatedSummarySpecFile()
|
||||
{
|
||||
return relatedFilePath( EclipseFileType::ECLIPSE_SMSPEC );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaEclipseFileNameTools::findRelatedGridFile()
|
||||
{
|
||||
QString candidate = relatedFilePath( EclipseFileType::ECLIPSE_EGRID );
|
||||
if ( !candidate.isEmpty() )
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
|
||||
return relatedFilePath( EclipseFileType::ECLIPSE_GRID );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaEclipseFileNameTools::findRelatedDataFile()
|
||||
{
|
||||
return relatedFilePath( EclipseFileType::ECLIPSE_DATA );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaEclipseFileNameTools::isProjectFile( const QString& fileName )
|
||||
{
|
||||
return hasMatchingSuffix( fileName, EclipseFileType::RESINSIGHT_PROJECT );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaEclipseFileNameTools::isGridFile( const QString& fileName )
|
||||
{
|
||||
if ( hasMatchingSuffix( fileName, EclipseFileType::ECLIPSE_EGRID ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return hasMatchingSuffix( fileName, EclipseFileType::ECLIPSE_GRID );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaEclipseFileNameTools::isSummarySpecFile( const QString& fileName )
|
||||
{
|
||||
return hasMatchingSuffix( fileName, EclipseFileType::ECLIPSE_SMSPEC );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaEclipseFileNameTools::relatedFilePath( EclipseFileType fileType ) const
|
||||
{
|
||||
const QString extension = caf::AppEnum<EclipseFileType>::text( fileType );
|
||||
const QString completeFilePath = m_baseName + "." + extension;
|
||||
|
||||
QFileInfo fi( completeFilePath );
|
||||
if ( fi.exists() )
|
||||
{
|
||||
return fi.absoluteFilePath();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaEclipseFileNameTools::hasMatchingSuffix( const QString& fileName, EclipseFileType fileType )
|
||||
{
|
||||
QFileInfo fi( fileName );
|
||||
|
||||
QString suffix = fi.completeSuffix();
|
||||
|
||||
if ( suffix.compare( caf::AppEnum<EclipseFileType>::text( fileType ), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
63
ApplicationLibCode/Application/RiaEclipseFileNameTools.h
Normal file
63
ApplicationLibCode/Application/RiaEclipseFileNameTools.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "cafAppEnum.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaEclipseFileNameTools
|
||||
{
|
||||
public:
|
||||
enum class EclipseFileType
|
||||
{
|
||||
ECLIPSE_DATA,
|
||||
ECLIPSE_GRID,
|
||||
ECLIPSE_EGRID,
|
||||
ECLIPSE_UNRST,
|
||||
ECLIPSE_SMSPEC,
|
||||
ECLIPSE_UNSMRY,
|
||||
RESINSIGHT_PROJECT,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
public:
|
||||
explicit RiaEclipseFileNameTools( const QString& fileName );
|
||||
|
||||
QString findRelatedGridFile();
|
||||
QString findRelatedSummarySpecFile();
|
||||
QString findRelatedDataFile();
|
||||
|
||||
static bool isProjectFile( const QString& fileName );
|
||||
static bool isGridFile( const QString& fileName );
|
||||
static bool isSummarySpecFile( const QString& fileName );
|
||||
|
||||
private:
|
||||
QString relatedFilePath( EclipseFileType fileType ) const;
|
||||
|
||||
static bool hasMatchingSuffix( const QString& fileName, EclipseFileType fileType );
|
||||
|
||||
private:
|
||||
QString m_baseName;
|
||||
};
|
||||
147
ApplicationLibCode/Application/RiaFeatureCommandContext.cpp
Normal file
147
ApplicationLibCode/Application/RiaFeatureCommandContext.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaFeatureCommandContext.h"
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaFeatureCommandContext::RiaFeatureCommandContext()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaFeatureCommandContext::~RiaFeatureCommandContext()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaFeatureCommandContext::setObject( QObject* object )
|
||||
{
|
||||
m_pointerToQObject = object;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QObject* RiaFeatureCommandContext::object() const
|
||||
{
|
||||
return m_pointerToQObject;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFeatureCommandContext::titleString() const
|
||||
{
|
||||
if ( m_pointerToQObject )
|
||||
{
|
||||
QVariant variant = m_pointerToQObject->property( titleStringIdentifier().data() );
|
||||
|
||||
return variant.toString();
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFeatureCommandContext::contentString() const
|
||||
{
|
||||
if ( m_pointerToQObject )
|
||||
{
|
||||
QVariant variant = m_pointerToQObject->property( contentStringIdentifier().data() );
|
||||
|
||||
return variant.toString();
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaFeatureCommandContext::titleStringIdentifier()
|
||||
{
|
||||
return "titleStringIdentifier";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaFeatureCommandContext::contentStringIdentifier()
|
||||
{
|
||||
return "contentStringIdentifier";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaFeatureCommandContext* RiaFeatureCommandContext::instance()
|
||||
{
|
||||
static RiaFeatureCommandContext* commandFileExecutorInstance = new RiaFeatureCommandContext();
|
||||
return commandFileExecutorInstance;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaFeatureCommandContextHelper::RiaFeatureCommandContextHelper( QObject* externalObject )
|
||||
{
|
||||
RiaFeatureCommandContext::instance()->setObject( externalObject );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaFeatureCommandContextHelper::~RiaFeatureCommandContextHelper()
|
||||
{
|
||||
RiaFeatureCommandContext::instance()->setObject( nullptr );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaFeatureCommandContextTextHelper::RiaFeatureCommandContextTextHelper( const QString& title, const QString& text )
|
||||
{
|
||||
m_object = new QObject;
|
||||
|
||||
m_object->setProperty( RiaFeatureCommandContext::titleStringIdentifier().data(), title );
|
||||
m_object->setProperty( RiaFeatureCommandContext::contentStringIdentifier().data(), text );
|
||||
|
||||
RiaFeatureCommandContext::instance()->setObject( m_object );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaFeatureCommandContextTextHelper::~RiaFeatureCommandContextTextHelper()
|
||||
{
|
||||
if ( m_object )
|
||||
{
|
||||
m_object->deleteLater();
|
||||
m_object = nullptr;
|
||||
}
|
||||
}
|
||||
74
ApplicationLibCode/Application/RiaFeatureCommandContext.h
Normal file
74
ApplicationLibCode/Application/RiaFeatureCommandContext.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 <QObject>
|
||||
#include <QPointer>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaFeatureCommandContext
|
||||
{
|
||||
friend class RiaFeatureCommandContextHelper;
|
||||
|
||||
public:
|
||||
static RiaFeatureCommandContext* instance();
|
||||
|
||||
RiaFeatureCommandContext( const RiaFeatureCommandContext& ) = delete;
|
||||
|
||||
QObject* object() const;
|
||||
void setObject( QObject* object );
|
||||
|
||||
QString titleString() const;
|
||||
QString contentString() const;
|
||||
|
||||
static std::string titleStringIdentifier();
|
||||
static std::string contentStringIdentifier();
|
||||
|
||||
private:
|
||||
RiaFeatureCommandContext();
|
||||
~RiaFeatureCommandContext();
|
||||
|
||||
private:
|
||||
QPointer<QObject> m_pointerToQObject;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaFeatureCommandContextHelper
|
||||
{
|
||||
public:
|
||||
explicit RiaFeatureCommandContextHelper( QObject* externalObject );
|
||||
~RiaFeatureCommandContextHelper();
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaFeatureCommandContextTextHelper
|
||||
{
|
||||
public:
|
||||
RiaFeatureCommandContextTextHelper( const QString& title, const QString& text );
|
||||
~RiaFeatureCommandContextTextHelper();
|
||||
|
||||
private:
|
||||
QObject* m_object;
|
||||
};
|
||||
124
ApplicationLibCode/Application/RiaFontCache.cpp
Normal file
124
ApplicationLibCode/Application/RiaFontCache.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaFontCache.h"
|
||||
|
||||
#include "RiaGuiApplication.h"
|
||||
|
||||
#include "cafFixedAtlasFont.h"
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <cmath>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::FixedAtlasFont::FontSize mapToAtlasFontSize( int pointSize )
|
||||
{
|
||||
if ( pointSize >= 6 && pointSize < 8 )
|
||||
return caf::FixedAtlasFont::POINT_SIZE_6;
|
||||
else if ( pointSize >= 8 && pointSize < 10 )
|
||||
return caf::FixedAtlasFont::POINT_SIZE_8;
|
||||
else if ( pointSize >= 10 && pointSize < 12 )
|
||||
return caf::FixedAtlasFont::POINT_SIZE_10;
|
||||
else if ( pointSize >= 12 && pointSize < 14 )
|
||||
return caf::FixedAtlasFont::POINT_SIZE_12;
|
||||
else if ( pointSize >= 14 && pointSize < 16 )
|
||||
return caf::FixedAtlasFont::POINT_SIZE_14;
|
||||
else if ( pointSize >= 16 && pointSize < 20 )
|
||||
return caf::FixedAtlasFont::POINT_SIZE_16;
|
||||
else if ( pointSize >= 20 && pointSize < 28 )
|
||||
return caf::FixedAtlasFont::POINT_SIZE_24;
|
||||
|
||||
return caf::FixedAtlasFont::POINT_SIZE_32;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<caf::FixedAtlasFont::FontSize, cvf::ref<caf::FixedAtlasFont>> RiaFontCache::ms_fonts;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<caf::FixedAtlasFont> RiaFontCache::getFont( FontSize pointFontSize )
|
||||
{
|
||||
int pointSize = caf::FontTools::absolutePointSize( pointFontSize );
|
||||
return getFont( pointSize );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<caf::FixedAtlasFont> RiaFontCache::getFont( int pointSize )
|
||||
{
|
||||
int currentDPI = 96;
|
||||
if ( RiaGuiApplication::isRunning() )
|
||||
{
|
||||
currentDPI = RiaGuiApplication::desktop()->logicalDpiX();
|
||||
}
|
||||
// the Fixed Atlas Fonts appear to be assuming a DPI of 96, so we need scaling.
|
||||
double scaling = currentDPI / 96.0;
|
||||
int scaledSize = scaling * pointSize;
|
||||
auto atlasFontSize = mapToAtlasFontSize( scaledSize );
|
||||
|
||||
auto existing_it = ms_fonts.find( atlasFontSize );
|
||||
if ( existing_it == ms_fonts.end() )
|
||||
{
|
||||
auto newFont = new caf::FixedAtlasFont( atlasFontSize );
|
||||
bool inserted = false;
|
||||
std::tie( existing_it, inserted ) = ms_fonts.insert( std::make_pair( atlasFontSize, newFont ) );
|
||||
CAF_ASSERT( inserted );
|
||||
}
|
||||
return existing_it->second;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// In the 2019 releases the font size was stored as an enum value rather than actual size
|
||||
/// Use this method for legacy conversion
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaFontCache::FontSize RiaFontCache::legacyEnumToPointSize( int enumValue )
|
||||
{
|
||||
switch ( enumValue )
|
||||
{
|
||||
case 0:
|
||||
return FontSize::FONT_SIZE_8;
|
||||
case 1:
|
||||
return FontSize::FONT_SIZE_10;
|
||||
case 2:
|
||||
return FontSize::FONT_SIZE_12;
|
||||
case 3:
|
||||
return FontSize::FONT_SIZE_14;
|
||||
case 4:
|
||||
return FontSize::FONT_SIZE_16;
|
||||
case 5:
|
||||
return FontSize::FONT_SIZE_24;
|
||||
case 6:
|
||||
return FontSize::FONT_SIZE_32;
|
||||
default:
|
||||
return FontSize::FONT_SIZE_8;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaFontCache::clear()
|
||||
{
|
||||
ms_fonts.clear();
|
||||
}
|
||||
52
ApplicationLibCode/Application/RiaFontCache.h
Normal file
52
ApplicationLibCode/Application/RiaFontCache.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafFixedAtlasFont.h"
|
||||
#include "cafFontTools.h"
|
||||
|
||||
#include "cvfObject.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <typename T>
|
||||
class AppEnum;
|
||||
}
|
||||
|
||||
class RimSummaryCaseCollection;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaFontCache
|
||||
{
|
||||
public:
|
||||
using FontSize = caf::FontTools::FontSize;
|
||||
using FontSizeEnum = caf::FontTools::FontSizeEnum;
|
||||
|
||||
static cvf::ref<caf::FixedAtlasFont> getFont( FontSize fontSize );
|
||||
static cvf::ref<caf::FixedAtlasFont> getFont( int pointSize );
|
||||
static FontSize legacyEnumToPointSize( int enumValue );
|
||||
static void clear();
|
||||
|
||||
private:
|
||||
static std::map<caf::FixedAtlasFont::FontSize, cvf::ref<caf::FixedAtlasFont>> ms_fonts;
|
||||
};
|
||||
79
ApplicationLibCode/Application/RiaFractureDefines.cpp
Normal file
79
ApplicationLibCode/Application/RiaFractureDefines.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaFractureDefines.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::conductivityResultName()
|
||||
{
|
||||
return "CONDUCTIVITY";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::unitStringConductivity( RiaEclipseUnitTools::UnitSystem unitSystem )
|
||||
{
|
||||
switch ( unitSystem )
|
||||
{
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_METRIC:
|
||||
return "md-m";
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_FIELD:
|
||||
return "md-ft";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaDefines::nonDarcyFlowAlpha( RiaEclipseUnitTools::UnitSystem unitSystem )
|
||||
{
|
||||
switch ( unitSystem )
|
||||
{
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_METRIC:
|
||||
return 2.24460e-10;
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_FIELD:
|
||||
return 6.83352e-8;
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_LAB:
|
||||
return 5.41375E-11;
|
||||
// case RiaEclipseUnitTools::PVT_METRIC: return 2.25533E-10;
|
||||
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::faciesColorLegendName()
|
||||
{
|
||||
return "Facies colors";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::rockTypeColorLegendName()
|
||||
{
|
||||
return "Rock Types";
|
||||
}
|
||||
34
ApplicationLibCode/Application/RiaFractureDefines.h
Normal file
34
ApplicationLibCode/Application/RiaFractureDefines.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaEclipseUnitTools.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace RiaDefines
|
||||
{
|
||||
QString conductivityResultName();
|
||||
QString unitStringConductivity( RiaEclipseUnitTools::UnitSystem unitSystem );
|
||||
|
||||
double nonDarcyFlowAlpha( RiaEclipseUnitTools::UnitSystem unitSystem );
|
||||
|
||||
QString faciesColorLegendName();
|
||||
QString rockTypeColorLegendName();
|
||||
}; // namespace RiaDefines
|
||||
1796
ApplicationLibCode/Application/RiaGuiApplication.cpp
Normal file
1796
ApplicationLibCode/Application/RiaGuiApplication.cpp
Normal file
File diff suppressed because it is too large
Load Diff
191
ApplicationLibCode/Application/RiaGuiApplication.h
Normal file
191
ApplicationLibCode/Application/RiaGuiApplication.h
Normal file
@@ -0,0 +1,191 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaApplication.h"
|
||||
#include "RiaDefines.h"
|
||||
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
#include "cvfObject.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMutex>
|
||||
#include <QPointer>
|
||||
#include <QProcess>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
class QAction;
|
||||
|
||||
class Drawable;
|
||||
|
||||
class RIProcess;
|
||||
|
||||
class RiaPreferences;
|
||||
class RiaProjectModifier;
|
||||
class RiaSocketServer;
|
||||
|
||||
class RigEclipseCaseData;
|
||||
|
||||
class RimCommandObject;
|
||||
class RimEclipseCase;
|
||||
class RimEclipseView;
|
||||
class RimGridView;
|
||||
class RimProject;
|
||||
class RimSummaryPlot;
|
||||
class Rim3dView;
|
||||
class RimViewWindow;
|
||||
class RimWellLogPlot;
|
||||
class RimWellAllocationPlot;
|
||||
|
||||
class RiuMainWindow;
|
||||
class RiuMainWindowBase;
|
||||
class RiuMdiMaximizeWindowGuard;
|
||||
class RiuPlotMainWindow;
|
||||
class RiuRecentFileActionProvider;
|
||||
class RiaArgumentParser;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class FontHolderInterface;
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaGuiApplication : public QApplication, public RiaApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class RINavigationPolicy
|
||||
{
|
||||
NAVIGATION_POLICY_CEETRON,
|
||||
NAVIGATION_POLICY_CAD,
|
||||
NAVIGATION_POLICY_GEOQUEST,
|
||||
NAVIGATION_POLICY_RMS
|
||||
};
|
||||
|
||||
public:
|
||||
static bool isRunning();
|
||||
static RiaGuiApplication* instance();
|
||||
|
||||
RiaGuiApplication( int& argc, char** argv );
|
||||
~RiaGuiApplication() override;
|
||||
|
||||
bool saveProject();
|
||||
QString promptForProjectSaveAsFileName() const;
|
||||
bool askUserToSaveModifiedProject();
|
||||
bool saveProjectAs( const QString& fileName );
|
||||
|
||||
void runMultiCaseSnapshots( const QString& templateProjectFileName,
|
||||
std::vector<QString> gridFileNames,
|
||||
const QString& snapshotFolderName );
|
||||
bool useShaders() const;
|
||||
|
||||
RINavigationPolicy navigationPolicy() const;
|
||||
|
||||
RiuMainWindow* getOrCreateAndShowMainWindow();
|
||||
RiuMainWindow* mainWindow();
|
||||
RimViewWindow* activePlotWindow() const;
|
||||
|
||||
RiuPlotMainWindow* getOrCreateMainPlotWindow();
|
||||
RiuPlotMainWindow* getOrCreateAndShowMainPlotWindow();
|
||||
RiuPlotMainWindow* mainPlotWindow();
|
||||
RiuMainWindowBase* mainWindowByID( int mainWindowID );
|
||||
|
||||
static RimViewWindow* activeViewWindow();
|
||||
static RiuMainWindowBase* activeMainWindow();
|
||||
|
||||
bool isMain3dWindowVisible() const;
|
||||
bool isMainPlotWindowVisible() const;
|
||||
|
||||
void closeMainWindowIfOpenButHidden();
|
||||
void closeMainPlotWindowIfOpenButHidden();
|
||||
|
||||
std::vector<QAction*> recentFileActions() const;
|
||||
|
||||
static void clearAllSelections();
|
||||
void applyGuiPreferences( const RiaPreferences* oldPreferences = nullptr,
|
||||
const std::vector<caf::FontHolderInterface*>& defaultFontObjects = {} );
|
||||
void updateGrpcServer();
|
||||
static int applicationResolution();
|
||||
|
||||
// Public RiaApplication overrides
|
||||
void initialize() override;
|
||||
ApplicationStatus handleArguments( gsl::not_null<cvf::ProgramOptions*> progOpt ) override;
|
||||
int launchUnitTestsWithConsole() override;
|
||||
void addToRecentFiles( const QString& fileName ) override;
|
||||
void showFormattedTextInMessageBoxOrConsole( const QString& errMsg ) override;
|
||||
void launchGrpcServer() override;
|
||||
#ifdef ENABLE_GRPC
|
||||
RiaGrpcServer* grpcServer() const override;
|
||||
#endif
|
||||
protected:
|
||||
// Protected RiaApplication overrides
|
||||
void invokeProcessEvents( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) override;
|
||||
void onFileSuccessfullyLoaded( const QString& fileName, RiaDefines::ImportFileType fileType ) override;
|
||||
|
||||
void onProjectBeingOpened() override;
|
||||
void onProjectOpeningError( const QString& errMsg ) override;
|
||||
void onProjectOpened() override;
|
||||
void onProjectBeingClosed() override;
|
||||
void onProjectClosed() override;
|
||||
void onProjectBeingSaved() override;
|
||||
void onProjectSaved() override;
|
||||
|
||||
void startMonitoringWorkProgress( caf::UiProcess* uiProcess ) override;
|
||||
void stopMonitoringWorkProgress() override;
|
||||
|
||||
private:
|
||||
void setWindowCaptionFromAppState();
|
||||
|
||||
void createMainWindow();
|
||||
void deleteMainWindow();
|
||||
|
||||
void createMainPlotWindow();
|
||||
void deleteMainPlotWindow();
|
||||
|
||||
void storeTreeViewState();
|
||||
|
||||
bool notify( QObject*, QEvent* ) override;
|
||||
|
||||
private slots:
|
||||
void slotWorkerProcessFinished( int exitCode, QProcess::ExitStatus exitStatus );
|
||||
void runIdleProcessing();
|
||||
void onProgramExit();
|
||||
|
||||
private:
|
||||
RiuMainWindow* m_mainWindow;
|
||||
RiuPlotMainWindow* m_mainPlotWindow;
|
||||
#ifdef ENABLE_GRPC
|
||||
QPointer<QTimer> m_idleTimer;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<RiuRecentFileActionProvider> m_recentFileActionProvider;
|
||||
|
||||
std::unique_ptr<RiuMdiMaximizeWindowGuard> m_maximizeWindowGuard;
|
||||
};
|
||||
133
ApplicationLibCode/Application/RiaMain.cpp
Normal file
133
ApplicationLibCode/Application/RiaMain.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// 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 "RiaArgumentParser.h"
|
||||
#include "RiaConsoleApplication.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "cvfProgramOptions.h"
|
||||
#include "cvfqtUtils.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
RiaApplication* createApplication( int& argc, char* argv[] )
|
||||
{
|
||||
for ( int i = 1; i < argc; ++i )
|
||||
{
|
||||
if ( !qstrcmp( argv[i], "--console" ) || !qstrcmp( argv[i], "--unittest" ) )
|
||||
{
|
||||
return new RiaConsoleApplication( argc, argv );
|
||||
}
|
||||
}
|
||||
return new RiaGuiApplication( argc, argv );
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
#ifndef WIN32
|
||||
// From Qt 5.3 and onwards Qt has a mechanism for checking this automatically
|
||||
// But it only checks user id not group id, so better to do it ourselves.
|
||||
if ( getuid() != geteuid() || getgid() != getegid() )
|
||||
{
|
||||
std::cerr << "FATAL: The application binary appears to be running setuid or setgid, this is a security hole."
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
RiaLogging::loggerInstance()->setLevel( int( RILogLevel::RI_LL_DEBUG ) );
|
||||
|
||||
std::unique_ptr<RiaApplication> app( createApplication( argc, argv ) );
|
||||
|
||||
cvf::ProgramOptions progOpt;
|
||||
bool result = RiaArgumentParser::parseArguments( &progOpt );
|
||||
|
||||
const cvf::String usageText = progOpt.usageText( 110, 30 );
|
||||
app->initialize();
|
||||
app->setCommandLineHelpText( cvfqt::Utils::toQString( usageText ) );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
std::vector<cvf::String> unknownOptions = progOpt.unknownOptions();
|
||||
QString unknownOptionsText;
|
||||
for ( cvf::String option : unknownOptions )
|
||||
{
|
||||
unknownOptionsText += QString( "\tUnknown option: %1\n" ).arg( cvfqt::Utils::toQString( option ) );
|
||||
}
|
||||
|
||||
app->showFormattedTextInMessageBoxOrConsole(
|
||||
"ERROR: Unknown command line options detected ! \n" + unknownOptionsText + "\n\n" +
|
||||
"The current command line options in ResInsight are:\n" + app->commandLineParameterHelp() );
|
||||
|
||||
if ( dynamic_cast<RiaGuiApplication*>( app.get() ) == nullptr )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
QLocale::setDefault( QLocale( QLocale::English, QLocale::UnitedStates ) );
|
||||
setlocale( LC_NUMERIC, "C" );
|
||||
|
||||
// Handle the command line arguments.
|
||||
// Todo: Move to a one-shot timer, delaying the execution until we are inside the event loop.
|
||||
// The complete handling of the resulting ApplicationStatus must be moved along.
|
||||
// The reason for this is: deleteLater() does not work outside the event loop
|
||||
// Make execution of command line stuff operate in identical conditions as interactive operation.
|
||||
|
||||
RiaApplication::ApplicationStatus status = app->handleArguments( &progOpt );
|
||||
|
||||
if ( status == RiaApplication::ApplicationStatus::EXIT_COMPLETED )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if ( status == RiaApplication::ApplicationStatus::EXIT_WITH_ERROR )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else if ( status == RiaApplication::ApplicationStatus::KEEP_GOING )
|
||||
{
|
||||
int exitCode = 0;
|
||||
try
|
||||
{
|
||||
if ( app->initializeGrpcServer( progOpt ) )
|
||||
{
|
||||
app->launchGrpcServer();
|
||||
}
|
||||
exitCode = QCoreApplication::instance()->exec();
|
||||
}
|
||||
catch ( std::exception& exep )
|
||||
{
|
||||
std::cout << "A standard c++ exception that terminated ResInsight caught in RiaMain.cpp: " << exep.what()
|
||||
<< std::endl;
|
||||
throw;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cout << "An unknown exception that terminated ResInsight caught in RiaMain.cpp. " << std::endl;
|
||||
throw;
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
CVF_ASSERT( false && "Unknown ApplicationStatus" );
|
||||
return -1;
|
||||
}
|
||||
324
ApplicationLibCode/Application/RiaMemoryCleanup.cpp
Normal file
324
ApplicationLibCode/Application/RiaMemoryCleanup.cpp
Normal file
@@ -0,0 +1,324 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaMemoryCleanup.h"
|
||||
|
||||
#include "RigCaseCellResultsData.h"
|
||||
#include "RigFemPartResultsCollection.h"
|
||||
#include "RigFemResultAddress.h"
|
||||
#include "RigGeoMechCaseData.h"
|
||||
#include "Rim3dView.h"
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimEclipseResultDefinition.h"
|
||||
#include "RimGeoMechCase.h"
|
||||
#include "RimGeoMechResultDefinition.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "RigEclipseResultInfo.h"
|
||||
#include "cafPdmUiListEditor.h"
|
||||
#include "cafPdmUiPushButtonEditor.h"
|
||||
#include "cafPdmUiTreeSelectionEditor.h"
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RiaMemoryCleanup, "RiaMemoryCleanup" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaMemoryCleanup::RiaMemoryCleanup()
|
||||
{
|
||||
// clang-format off
|
||||
CAF_PDM_InitFieldNoDefault(&m_case, "DataCase", "Case", "", "", "");
|
||||
m_case = nullptr;
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_resultsToDelete, "ResultsToDelete", "Results In Memory", "", "", "");
|
||||
m_resultsToDelete.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::TOP);
|
||||
m_resultsToDelete.uiCapability()->setUiEditorTypeName(caf::PdmUiTreeSelectionEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_performDelete, "ClearSelectedData", "", "", "", "");
|
||||
caf::PdmUiPushButtonEditor::configureEditorForField(&m_performDelete);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaMemoryCleanup::setPropertiesFromView( Rim3dView* view )
|
||||
{
|
||||
if ( !view ) return;
|
||||
|
||||
m_case = view->ownerCase();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaMemoryCleanup::clearSelectedResultsFromMemory()
|
||||
{
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( m_case() );
|
||||
RimGeoMechCase* geoMechCase = dynamic_cast<RimGeoMechCase*>( m_case() );
|
||||
if ( eclipseCase )
|
||||
{
|
||||
RigCaseCellResultsData* caseData = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
|
||||
if ( caseData )
|
||||
{
|
||||
std::vector<RigEclipseResultAddress> resultsToDelete = selectedEclipseResults();
|
||||
for ( const RigEclipseResultAddress& resultAddr : resultsToDelete )
|
||||
{
|
||||
caseData->clearScalarResult( resultAddr );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( geoMechCase )
|
||||
{
|
||||
RigGeoMechCaseData* data = geoMechCase->geoMechData();
|
||||
if ( data )
|
||||
{
|
||||
RigFemPartResultsCollection* resultsCollection = data->femPartResults();
|
||||
if ( resultsCollection )
|
||||
{
|
||||
std::vector<RigFemResultAddress> resultsToDelete = selectedGeoMechResults();
|
||||
for ( RigFemResultAddress result : resultsToDelete )
|
||||
{
|
||||
resultsCollection->deleteResult( result );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_resultsToDelete.v().clear();
|
||||
m_eclipseResultAddresses.clear();
|
||||
m_geomResultAddresses.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RigFemResultAddress> RiaMemoryCleanup::selectedGeoMechResults() const
|
||||
{
|
||||
std::vector<RigFemResultAddress> results;
|
||||
if ( dynamic_cast<const RimGeoMechCase*>( m_case() ) )
|
||||
{
|
||||
for ( size_t index : m_resultsToDelete() )
|
||||
{
|
||||
CVF_ASSERT( index < m_geomResultAddresses.size() );
|
||||
results.push_back( m_geomResultAddresses[index] );
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RigEclipseResultAddress> RiaMemoryCleanup::selectedEclipseResults() const
|
||||
{
|
||||
std::vector<RigEclipseResultAddress> results;
|
||||
if ( dynamic_cast<const RimEclipseCase*>( m_case() ) )
|
||||
{
|
||||
for ( size_t index : m_resultsToDelete() )
|
||||
{
|
||||
CVF_ASSERT( index < m_eclipseResultAddresses.size() );
|
||||
results.push_back( m_eclipseResultAddresses[index] );
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<RigFemResultAddress> RiaMemoryCleanup::findGeoMechCaseResultsInUse() const
|
||||
{
|
||||
std::set<RigFemResultAddress> resultsInUse;
|
||||
RimGeoMechCase* geoMechCase = dynamic_cast<RimGeoMechCase*>( m_case() );
|
||||
if ( geoMechCase )
|
||||
{
|
||||
std::vector<RimFemResultObserver*> geoMechResults;
|
||||
geoMechCase->descendantsIncludingThisOfType( geoMechResults );
|
||||
for ( RimFemResultObserver* resultDef : geoMechResults )
|
||||
{
|
||||
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>*>( resultDef->objectToggleField() );
|
||||
if ( !field || ( *field )() )
|
||||
{
|
||||
std::vector<RigFemResultAddress> required = resultDef->observedResults();
|
||||
resultsInUse.insert( required.begin(), required.end() );
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultsInUse;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<RigEclipseResultAddress> RiaMemoryCleanup::findEclipseResultsInUse() const
|
||||
{
|
||||
std::set<RigEclipseResultAddress> resultsInUse;
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( m_case() );
|
||||
if ( eclipseCase )
|
||||
{
|
||||
std::vector<RimEclipseResultDefinition*> eclipseResultDefs;
|
||||
eclipseCase->descendantsIncludingThisOfType( eclipseResultDefs );
|
||||
for ( RimEclipseResultDefinition* resultDef : eclipseResultDefs )
|
||||
{
|
||||
RigEclipseResultAddress resultAddr( resultDef->resultType(), resultDef->resultVariable() );
|
||||
resultsInUse.insert( resultAddr );
|
||||
}
|
||||
}
|
||||
|
||||
return resultsInUse;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaMemoryCleanup::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
||||
const QVariant& oldValue,
|
||||
const QVariant& newValue )
|
||||
{
|
||||
if ( changedField == &m_case )
|
||||
{
|
||||
m_resultsToDelete.uiCapability()->updateConnectedEditors();
|
||||
}
|
||||
else if ( changedField == &m_performDelete )
|
||||
{
|
||||
clearSelectedResultsFromMemory();
|
||||
m_resultsToDelete.uiCapability()->updateConnectedEditors();
|
||||
m_performDelete = false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QList<caf::PdmOptionItemInfo> RiaMemoryCleanup::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly )
|
||||
{
|
||||
QList<caf::PdmOptionItemInfo> options;
|
||||
if ( fieldNeedingOptions == &m_case )
|
||||
{
|
||||
RimProject* proj = RimProject::current();
|
||||
if ( proj )
|
||||
{
|
||||
std::vector<RimEclipseCase*> eclipseCases = proj->eclipseCases();
|
||||
for ( RimEclipseCase* c : eclipseCases )
|
||||
{
|
||||
options.push_back( caf::PdmOptionItemInfo( c->caseUserDescription(), c, false, c->uiIconProvider() ) );
|
||||
}
|
||||
|
||||
std::vector<RimGeoMechCase*> geoMechCases = proj->geoMechCases();
|
||||
for ( RimGeoMechCase* c : geoMechCases )
|
||||
{
|
||||
options.push_back( caf::PdmOptionItemInfo( c->caseUserDescription(), c, false, c->uiIconProvider() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( fieldNeedingOptions == &m_resultsToDelete )
|
||||
{
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( m_case() );
|
||||
RimGeoMechCase* geoMechCase = dynamic_cast<RimGeoMechCase*>( m_case() );
|
||||
if ( eclipseCase )
|
||||
{
|
||||
std::set<RigEclipseResultAddress> resultsInUse = findEclipseResultsInUse();
|
||||
RigCaseCellResultsData* caseData = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
|
||||
if ( caseData )
|
||||
{
|
||||
m_eclipseResultAddresses = caseData->existingResults();
|
||||
|
||||
for ( size_t i = 0; i < m_eclipseResultAddresses.size(); ++i )
|
||||
{
|
||||
const RigEclipseResultAddress& resultAddr = m_eclipseResultAddresses[i];
|
||||
if ( caseData->isResultLoaded( resultAddr ) )
|
||||
{
|
||||
bool inUse = resultsInUse.count( resultAddr );
|
||||
|
||||
const RigEclipseResultInfo* resInfo = caseData->resultInfo( resultAddr );
|
||||
|
||||
QString posText = caf::AppEnum<RiaDefines::ResultCatType>::uiText( resInfo->resultType() );
|
||||
QString resultsText = QString( "%1, %2" ).arg( posText ).arg( resInfo->resultName() );
|
||||
if ( inUse )
|
||||
{
|
||||
resultsText += QString( " [used in view]" );
|
||||
}
|
||||
options.push_back( caf::PdmOptionItemInfo( resultsText, (qulonglong)i, inUse ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( geoMechCase )
|
||||
{
|
||||
std::set<RigFemResultAddress> resultsInUse = findGeoMechCaseResultsInUse();
|
||||
RigGeoMechCaseData* caseData = geoMechCase->geoMechData();
|
||||
if ( caseData )
|
||||
{
|
||||
RigFemPartResultsCollection* results = caseData->femPartResults();
|
||||
m_geomResultAddresses = results->loadedResults();
|
||||
|
||||
for ( size_t i = 0; i < m_geomResultAddresses.size(); ++i )
|
||||
{
|
||||
const RigFemResultAddress& result = m_geomResultAddresses[i];
|
||||
bool inUse = resultsInUse.count( result );
|
||||
QString posText = caf::AppEnum<RigFemResultPosEnum>::uiTextFromIndex( result.resultPosType );
|
||||
QString resultsText =
|
||||
QString( "%1, %2" ).arg( posText ).arg( QString::fromStdString( result.fieldName ) );
|
||||
if ( !result.componentName.empty() )
|
||||
{
|
||||
resultsText += QString( ", %1" ).arg( QString::fromStdString( result.componentName ) );
|
||||
}
|
||||
if ( inUse )
|
||||
{
|
||||
resultsText += QString( " [used in view]" );
|
||||
}
|
||||
options.push_back( caf::PdmOptionItemInfo( resultsText, (qulonglong)i, inUse ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaMemoryCleanup::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
||||
{
|
||||
uiOrdering.add( &m_case );
|
||||
uiOrdering.add( &m_resultsToDelete );
|
||||
uiOrdering.add( &m_performDelete );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaMemoryCleanup::defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute )
|
||||
{
|
||||
if ( field == &m_performDelete )
|
||||
{
|
||||
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute );
|
||||
if ( attrib )
|
||||
{
|
||||
attrib->m_buttonText = "Clear Checked Data From Memory";
|
||||
}
|
||||
}
|
||||
}
|
||||
64
ApplicationLibCode/Application/RiaMemoryCleanup.h
Normal file
64
ApplicationLibCode/Application/RiaMemoryCleanup.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "cafPdmChildArrayField.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmPtrField.h"
|
||||
#include "cafPdmUiItem.h"
|
||||
|
||||
class RimCase;
|
||||
class Rim3dView;
|
||||
class RigFemResultAddress;
|
||||
class RigEclipseResultAddress;
|
||||
|
||||
class RiaMemoryCleanup : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RiaMemoryCleanup();
|
||||
|
||||
void setPropertiesFromView( Rim3dView* view );
|
||||
void clearSelectedResultsFromMemory();
|
||||
|
||||
protected:
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
|
||||
private:
|
||||
std::vector<RigFemResultAddress> selectedGeoMechResults() const;
|
||||
std::vector<RigEclipseResultAddress> selectedEclipseResults() const;
|
||||
std::set<RigFemResultAddress> findGeoMechCaseResultsInUse() const;
|
||||
std::set<RigEclipseResultAddress> findEclipseResultsInUse() const;
|
||||
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly ) override;
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute ) override;
|
||||
|
||||
private:
|
||||
caf::PdmPtrField<RimCase*> m_case;
|
||||
caf::PdmField<std::vector<size_t>> m_resultsToDelete;
|
||||
std::vector<RigFemResultAddress> m_geomResultAddresses;
|
||||
std::vector<RigEclipseResultAddress> m_eclipseResultAddresses;
|
||||
caf::PdmField<bool> m_performDelete;
|
||||
};
|
||||
75
ApplicationLibCode/Application/RiaNncDefines.cpp
Normal file
75
ApplicationLibCode/Application/RiaNncDefines.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020 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 "RiaNncDefines.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::propertyNameFluxWat()
|
||||
{
|
||||
return "FLRWAT";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::propertyNameFluxOil()
|
||||
{
|
||||
return "FLROIL";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::propertyNameFluxGas()
|
||||
{
|
||||
return "FLRGAS";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::propertyNameCombTrans()
|
||||
{
|
||||
return "TRAN";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::propertyNameRiCombTrans()
|
||||
{
|
||||
return "riTRAN";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::propertyNameRiCombTransByArea()
|
||||
{
|
||||
return "riTRANbyArea";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::propertyNameRiCombMult()
|
||||
{
|
||||
return "riMULT";
|
||||
}
|
||||
32
ApplicationLibCode/Application/RiaNncDefines.h
Normal file
32
ApplicationLibCode/Application/RiaNncDefines.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020 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 <QString>
|
||||
|
||||
namespace RiaDefines
|
||||
{
|
||||
QString propertyNameFluxWat();
|
||||
QString propertyNameFluxOil();
|
||||
QString propertyNameFluxGas();
|
||||
QString propertyNameCombTrans();
|
||||
QString propertyNameRiCombTrans();
|
||||
QString propertyNameRiCombTransByArea();
|
||||
QString propertyNameRiCombMult();
|
||||
}; // namespace RiaDefines
|
||||
173
ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.cpp
Normal file
173
ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaPlotWindowRedrawScheduler.h"
|
||||
|
||||
#include "RiuMultiPlotBook.h"
|
||||
#include "RiuMultiPlotPage.h"
|
||||
#include "RiuQwtPlotWidget.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "cafProgressState.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaPlotWindowRedrawScheduler* RiaPlotWindowRedrawScheduler::instance()
|
||||
{
|
||||
static RiaPlotWindowRedrawScheduler theInstance;
|
||||
|
||||
return &theInstance;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::scheduleMultiPlotWindowUpdate( RiuMultiPlotBook* plotWindow )
|
||||
{
|
||||
m_plotWindowsToUpdate.push_back( plotWindow );
|
||||
|
||||
startTimer( 0 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::scheduleMultiPlotPageUpdate( RiuMultiPlotPage* plotPage )
|
||||
{
|
||||
m_plotPagesToUpdate.push_back( plotPage );
|
||||
|
||||
startTimer( 0 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::schedulePlotWidgetReplot( RiuQwtPlotWidget* plotWidget )
|
||||
{
|
||||
m_plotWidgetsToReplot.push_back( plotWidget );
|
||||
|
||||
startTimer( 0 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::clearAllScheduledUpdates()
|
||||
{
|
||||
if ( m_plotWindowUpdateTimer )
|
||||
{
|
||||
while ( m_plotWindowUpdateTimer->isActive() )
|
||||
{
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
}
|
||||
m_plotWidgetsToReplot.clear();
|
||||
m_plotPagesToUpdate.clear();
|
||||
m_plotWindowsToUpdate.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::performScheduledUpdatesAndReplots()
|
||||
{
|
||||
std::vector<QPointer<RiuMultiPlotBook>> plotWindowsToUpdate;
|
||||
std::vector<QPointer<RiuMultiPlotPage>> plotPagesToUpdate;
|
||||
std::vector<QPointer<RiuQwtPlotWidget>> plotWidgetsToReplot;
|
||||
|
||||
plotWindowsToUpdate.swap( m_plotWindowsToUpdate );
|
||||
plotPagesToUpdate.swap( m_plotPagesToUpdate );
|
||||
plotWidgetsToReplot.swap( m_plotWidgetsToReplot );
|
||||
|
||||
std::set<QPointer<RiuQwtPlotWidget>> updatedPlots;
|
||||
std::set<QPointer<RiuMultiPlotBook>> updatedPlotWindows;
|
||||
std::set<QPointer<RiuMultiPlotPage>> updatedPlotPages;
|
||||
|
||||
for ( QPointer<RiuMultiPlotBook> plotWindow : plotWindowsToUpdate )
|
||||
{
|
||||
if ( !plotWindow.isNull() && !updatedPlotWindows.count( plotWindow ) )
|
||||
{
|
||||
for ( RiuMultiPlotPage* page : plotWindow->pages() )
|
||||
{
|
||||
plotPagesToUpdate.erase( std::remove( plotPagesToUpdate.begin(), plotPagesToUpdate.end(), page ),
|
||||
plotPagesToUpdate.end() );
|
||||
}
|
||||
|
||||
plotWindow->performUpdate();
|
||||
updatedPlotWindows.insert( plotWindow );
|
||||
}
|
||||
}
|
||||
|
||||
for ( QPointer<RiuMultiPlotPage> plotPage : plotPagesToUpdate )
|
||||
{
|
||||
if ( !plotPage.isNull() && !updatedPlotPages.count( plotPage ) )
|
||||
{
|
||||
plotPage->performUpdate();
|
||||
updatedPlotPages.insert( plotPage );
|
||||
}
|
||||
}
|
||||
|
||||
// Perform update and replot. Make sure we handle legend update
|
||||
for ( QPointer<RiuQwtPlotWidget> plot : plotWidgetsToReplot )
|
||||
{
|
||||
if ( !plot.isNull() && !updatedPlots.count( plot ) )
|
||||
{
|
||||
plot->replot();
|
||||
updatedPlots.insert( plot );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::slotUpdateAndReplotScheduledItemsWhenReady()
|
||||
{
|
||||
if ( caf::ProgressState::isActive() )
|
||||
{
|
||||
startTimer( 100 );
|
||||
return;
|
||||
}
|
||||
|
||||
performScheduledUpdatesAndReplots();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::startTimer( int msecs )
|
||||
{
|
||||
if ( !m_plotWindowUpdateTimer )
|
||||
{
|
||||
m_plotWindowUpdateTimer.reset( new QTimer( this ) );
|
||||
connect( m_plotWindowUpdateTimer.data(),
|
||||
SIGNAL( timeout() ),
|
||||
this,
|
||||
SLOT( slotUpdateAndReplotScheduledItemsWhenReady() ) );
|
||||
}
|
||||
|
||||
if ( !m_plotWindowUpdateTimer->isActive() )
|
||||
{
|
||||
m_plotWindowUpdateTimer->setSingleShot( true );
|
||||
m_plotWindowUpdateTimer->start( msecs );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "cafPdmPointer.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QScopedPointer>
|
||||
#include <QTimer>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RiuMultiPlotPage;
|
||||
class RiuMultiPlotBook;
|
||||
class RiuQwtPlotWidget;
|
||||
|
||||
class RiaPlotWindowRedrawScheduler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static RiaPlotWindowRedrawScheduler* instance();
|
||||
void scheduleMultiPlotWindowUpdate( RiuMultiPlotBook* plotWindow );
|
||||
void scheduleMultiPlotPageUpdate( RiuMultiPlotPage* plotWindow );
|
||||
void schedulePlotWidgetReplot( RiuQwtPlotWidget* plotWidget );
|
||||
void clearAllScheduledUpdates();
|
||||
void performScheduledUpdatesAndReplots();
|
||||
|
||||
private slots:
|
||||
void slotUpdateAndReplotScheduledItemsWhenReady();
|
||||
|
||||
private:
|
||||
RiaPlotWindowRedrawScheduler() = default;
|
||||
~RiaPlotWindowRedrawScheduler() = default;
|
||||
|
||||
void startTimer( int msecs );
|
||||
|
||||
private:
|
||||
std::vector<QPointer<RiuQwtPlotWidget>> m_plotWidgetsToReplot;
|
||||
std::vector<QPointer<RiuMultiPlotBook>> m_plotWindowsToUpdate;
|
||||
std::vector<QPointer<RiuMultiPlotPage>> m_plotPagesToUpdate;
|
||||
QScopedPointer<QTimer> m_plotWindowUpdateTimer;
|
||||
};
|
||||
33
ApplicationLibCode/Application/RiaPorosityModel.cpp
Normal file
33
ApplicationLibCode/Application/RiaPorosityModel.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaPorosityModel.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::PorosityModelType>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::PorosityModelType::MATRIX_MODEL, "MATRIX_MODEL", "Matrix" );
|
||||
addItem( RiaDefines::PorosityModelType::FRACTURE_MODEL, "FRACTURE_MODEL", "Fracture" );
|
||||
|
||||
setDefault( RiaDefines::PorosityModelType::MATRIX_MODEL );
|
||||
}
|
||||
} // namespace caf
|
||||
31
ApplicationLibCode/Application/RiaPorosityModel.h
Normal file
31
ApplicationLibCode/Application/RiaPorosityModel.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
namespace RiaDefines
|
||||
{
|
||||
enum class PorosityModelType
|
||||
{
|
||||
MATRIX_MODEL,
|
||||
FRACTURE_MODEL
|
||||
};
|
||||
};
|
||||
1168
ApplicationLibCode/Application/RiaPreferences.cpp
Normal file
1168
ApplicationLibCode/Application/RiaPreferences.cpp
Normal file
File diff suppressed because it is too large
Load Diff
254
ApplicationLibCode/Application/RiaPreferences.h
Normal file
254
ApplicationLibCode/Application/RiaPreferences.h
Normal file
@@ -0,0 +1,254 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2019- Equinor ASA
|
||||
// Copyright (C) 2011-2018 Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 "RiaDefines.h"
|
||||
#include "RiaFontCache.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaQDateTimeTools.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
#include "cafPdmChildField.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
// Include to make Pdm work for cvf::Color
|
||||
#include "cafPdmFieldCvfColor.h"
|
||||
|
||||
#include <QPageLayout>
|
||||
#include <QPageSize>
|
||||
#include <QStringList>
|
||||
|
||||
#include <map>
|
||||
|
||||
class RifReaderSettings;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaPreferences : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
using DateFormatComponents = RiaQDateTimeTools::DateFormatComponents;
|
||||
using TimeFormatComponents = RiaQDateTimeTools::TimeFormatComponents;
|
||||
|
||||
enum class SummaryRestartFilesImportMode
|
||||
{
|
||||
IMPORT,
|
||||
NOT_IMPORT,
|
||||
SEPARATE_CASES
|
||||
};
|
||||
typedef caf::AppEnum<SummaryRestartFilesImportMode> SummaryRestartFilesImportModeType;
|
||||
typedef RiaFontCache::FontSizeEnum FontSizeEnum;
|
||||
|
||||
enum class SummaryHistoryCurveStyleMode
|
||||
{
|
||||
SYMBOLS,
|
||||
LINES,
|
||||
SYMBOLS_AND_LINES
|
||||
};
|
||||
typedef caf::AppEnum<SummaryHistoryCurveStyleMode> SummaryHistoryCurveStyleModeType;
|
||||
|
||||
typedef caf::AppEnum<QPageSize::PageSizeId> PageSizeEnum;
|
||||
typedef caf::AppEnum<QPageLayout::Orientation> PageOrientationEnum;
|
||||
|
||||
bool enableFaultsByDefault() const;
|
||||
|
||||
public:
|
||||
RiaPreferences( void );
|
||||
~RiaPreferences( void ) override;
|
||||
|
||||
static RiaPreferences* current();
|
||||
|
||||
QStringList tabNames();
|
||||
|
||||
const RifReaderSettings* readerSettings() const;
|
||||
|
||||
// Debug settings
|
||||
bool appendClassNameToUiText() const;
|
||||
bool appendFieldKeywordToToolTipText() const;
|
||||
bool showViewIdInProjectTree() const;
|
||||
bool showTestToolbar() const;
|
||||
bool includeFractureDebugInfoFile() const;
|
||||
bool showProjectChangedDialog() const;
|
||||
QString holoLensExportFolder() const;
|
||||
bool useShaders() const;
|
||||
bool show3dInformation() const;
|
||||
QString gtestFilter() const;
|
||||
|
||||
const QString& dateFormat() const;
|
||||
const QString& timeFormat() const;
|
||||
QString dateTimeFormat( DateFormatComponents dateComponents = DateFormatComponents::DATE_FORMAT_YEAR_MONTH_DAY,
|
||||
TimeFormatComponents timeComponents = TimeFormatComponents::TIME_FORMAT_HOUR_MINUTE_SECOND ) const;
|
||||
|
||||
bool searchPlotTemplateFoldersRecursively() const;
|
||||
QStringList plotTemplateFolders() const;
|
||||
void appendPlotTemplateFolders( const QString& folder );
|
||||
QString defaultPlotTemplateAbsolutePath() const;
|
||||
void setDefaultPlotTemplatePath( const QString& templatePath );
|
||||
bool showSummaryTimeAsLongString() const;
|
||||
bool useMultipleThreadsWhenReadingSummaryData() const;
|
||||
bool showProgressBar() const;
|
||||
bool openExportedPdfInViewer() const;
|
||||
|
||||
RiaDefines::ThemeEnum guiTheme() const;
|
||||
|
||||
std::map<RiaDefines::FontSettingType, RiaFontCache::FontSize> defaultFontSizes() const;
|
||||
|
||||
void writePreferencesToApplicationStore();
|
||||
QPageLayout defaultPageLayout() const;
|
||||
QMarginsF margins() const;
|
||||
|
||||
double surfaceImportResamplingDistance() const;
|
||||
|
||||
QString multiLateralWellNamePattern() const;
|
||||
static QString defaultMultiLateralWellNamePattern();
|
||||
|
||||
// 3D view
|
||||
RiaDefines::MeshModeType defaultMeshModeType() const;
|
||||
RiaGuiApplication::RINavigationPolicy navigationPolicy() const;
|
||||
int defaultScaleFactorZ() const;
|
||||
bool showLegendBackground() const;
|
||||
bool showInfoBox() const;
|
||||
bool showGridBox() const;
|
||||
|
||||
// Script paths
|
||||
QString pythonExecutable() const;
|
||||
QString octaveExecutable() const;
|
||||
|
||||
public: // Pdm Fields
|
||||
caf::PdmField<bool> enableGrpcServer;
|
||||
caf::PdmField<int> defaultGrpcPortNumber;
|
||||
|
||||
caf::PdmField<QString> scriptDirectories;
|
||||
caf::PdmField<QString> scriptEditorExecutable;
|
||||
caf::PdmField<bool> octaveShowHeaderInfoWhenExecutingScripts;
|
||||
caf::PdmField<bool> showPythonDebugInfo;
|
||||
|
||||
caf::PdmField<QString> ssihubAddress;
|
||||
|
||||
caf::PdmField<cvf::Color3f> defaultGridLineColors;
|
||||
caf::PdmField<cvf::Color3f> defaultFaultGridLineColors;
|
||||
caf::PdmField<cvf::Color3f> defaultViewerBackgroundColor;
|
||||
caf::PdmField<cvf::Color3f> defaultWellLabelColor;
|
||||
caf::PdmField<bool> showLasCurveWithoutTvdWarning;
|
||||
|
||||
caf::PdmField<FontSizeEnum> defaultSceneFontSize;
|
||||
caf::PdmField<FontSizeEnum> defaultWellLabelFontSize;
|
||||
caf::PdmField<FontSizeEnum> defaultAnnotationFontSize;
|
||||
caf::PdmField<FontSizeEnum> defaultPlotFontSize;
|
||||
|
||||
caf::PdmField<QString> lastUsedProjectFileName;
|
||||
|
||||
caf::PdmField<bool> autocomputeDepthRelatedProperties;
|
||||
caf::PdmField<bool> loadAndShowSoil;
|
||||
|
||||
caf::PdmField<bool> summaryRestartFilesShowImportDialog;
|
||||
caf::PdmField<SummaryRestartFilesImportModeType> summaryImportMode;
|
||||
caf::PdmField<SummaryRestartFilesImportModeType> gridImportMode;
|
||||
caf::PdmField<SummaryRestartFilesImportModeType> summaryEnsembleImportMode;
|
||||
|
||||
caf::PdmField<QString> defaultSummaryCurvesTextFilter;
|
||||
caf::PdmField<SummaryHistoryCurveStyleModeType> defaultSummaryHistoryCurveStyle;
|
||||
|
||||
caf::PdmField<bool> holoLensDisableCertificateVerification;
|
||||
caf::PdmField<QString> csvTextExportFieldSeparator;
|
||||
|
||||
protected:
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute ) override;
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly ) override;
|
||||
void initAfterRead() override;
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
|
||||
private:
|
||||
static QString tabNameGeneral();
|
||||
static QString tabNameEclipse();
|
||||
static QString tabNamePlotting();
|
||||
static QString tabNameScripting();
|
||||
static QString tabNameExport();
|
||||
static QString tabNameSystem();
|
||||
static QString tabNameImport();
|
||||
|
||||
static double defaultMarginSize( QPageSize::PageSizeId pageSizeId );
|
||||
|
||||
private:
|
||||
caf::PdmChildField<RifReaderSettings*> m_readerSettings;
|
||||
|
||||
caf::PdmField<bool> m_appendClassNameToUiText;
|
||||
caf::PdmField<bool> m_appendFieldKeywordToToolTipText;
|
||||
caf::PdmField<bool> m_showViewIdInProjectTree;
|
||||
caf::PdmField<bool> m_useShaders;
|
||||
caf::PdmField<bool> m_showHud;
|
||||
|
||||
caf::PdmField<bool> m_showProjectChangedDialog;
|
||||
|
||||
caf::PdmField<bool> m_showTestToolbar;
|
||||
caf::PdmField<bool> m_includeFractureDebugInfoFile;
|
||||
caf::PdmField<QString> m_holoLensExportFolder;
|
||||
caf::PdmField<QString> m_dateFormat;
|
||||
caf::PdmField<QString> m_timeFormat;
|
||||
caf::PdmField<bool> m_showSummaryTimeAsLongString;
|
||||
caf::PdmField<bool> m_useMultipleThreadsWhenLoadingSummaryData;
|
||||
caf::PdmField<bool> m_showProgressBar;
|
||||
caf::PdmField<QString> m_gtestFilter;
|
||||
|
||||
caf::PdmField<caf::AppEnum<RiaDefines::ThemeEnum>> m_guiTheme;
|
||||
|
||||
caf::PdmField<PageSizeEnum> m_pageSize;
|
||||
caf::PdmField<PageOrientationEnum> m_pageOrientation;
|
||||
caf::PdmField<double> m_pageLeftMargin;
|
||||
caf::PdmField<double> m_pageRightMargin;
|
||||
caf::PdmField<double> m_pageTopMargin;
|
||||
caf::PdmField<double> m_pageBottomMargin;
|
||||
caf::PdmField<bool> m_openExportedPdfInViewer;
|
||||
|
||||
caf::PdmField<QString> m_plotTemplateFolders;
|
||||
caf::PdmField<bool> m_searchPlotTemplateFoldersRecursively;
|
||||
caf::PdmField<caf::FilePath> m_defaultPlotTemplate;
|
||||
|
||||
// Script paths
|
||||
caf::PdmField<QString> m_octaveExecutable;
|
||||
caf::PdmField<QString> m_pythonExecutable;
|
||||
|
||||
// Surface Import
|
||||
caf::PdmField<double> m_surfaceImportResamplingDistance;
|
||||
|
||||
// Well Path Import
|
||||
caf::PdmField<QString> m_multiLateralWellPattern;
|
||||
|
||||
// 3d view
|
||||
caf::PdmField<caf::AppEnum<RiaDefines::MeshModeType>> m_defaultMeshModeType;
|
||||
caf::PdmField<caf::AppEnum<RiaGuiApplication::RINavigationPolicy>> m_navigationPolicy;
|
||||
caf::PdmField<int> m_defaultScaleFactorZ;
|
||||
caf::PdmField<bool> m_showLegendBackground;
|
||||
caf::PdmField<bool> m_enableFaultsByDefault;
|
||||
caf::PdmField<bool> m_showInfoBox;
|
||||
caf::PdmField<bool> m_showGridBox;
|
||||
|
||||
QStringList m_tabNames;
|
||||
};
|
||||
71
ApplicationLibCode/Application/RiaRftPltCurveDefinition.cpp
Normal file
71
ApplicationLibCode/Application/RiaRftPltCurveDefinition.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaRftPltCurveDefinition.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaRftPltCurveDefinition::RiaRftPltCurveDefinition( const RifDataSourceForRftPlt& address,
|
||||
const QString& wellName,
|
||||
const QDateTime& timeStep )
|
||||
: m_curveAddress( address )
|
||||
, m_wellName( wellName )
|
||||
, m_timeStep( timeStep )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const RifDataSourceForRftPlt& RiaRftPltCurveDefinition::address() const
|
||||
{
|
||||
return m_curveAddress;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString& RiaRftPltCurveDefinition::wellName() const
|
||||
{
|
||||
return m_wellName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QDateTime& RiaRftPltCurveDefinition::timeStep() const
|
||||
{
|
||||
return m_timeStep;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaRftPltCurveDefinition::operator<( const RiaRftPltCurveDefinition& other ) const
|
||||
{
|
||||
if ( m_curveAddress == other.m_curveAddress )
|
||||
{
|
||||
if ( m_wellName == other.m_wellName )
|
||||
{
|
||||
return m_timeStep < other.m_timeStep;
|
||||
}
|
||||
return m_wellName < other.m_wellName;
|
||||
}
|
||||
return m_curveAddress < other.m_curveAddress;
|
||||
}
|
||||
50
ApplicationLibCode/Application/RiaRftPltCurveDefinition.h
Normal file
50
ApplicationLibCode/Application/RiaRftPltCurveDefinition.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifDataSourceForRftPlt.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class RimSummaryCase;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaRftPltCurveDefinition
|
||||
{
|
||||
public:
|
||||
explicit RiaRftPltCurveDefinition( const RifDataSourceForRftPlt& address,
|
||||
const QString& wellName,
|
||||
const QDateTime& timeStep );
|
||||
|
||||
const RifDataSourceForRftPlt& address() const;
|
||||
const QString& wellName() const;
|
||||
const QDateTime& timeStep() const;
|
||||
|
||||
bool operator<( const RiaRftPltCurveDefinition& other ) const;
|
||||
|
||||
private:
|
||||
RifDataSourceForRftPlt m_curveAddress;
|
||||
QString m_wellName;
|
||||
QDateTime m_timeStep;
|
||||
};
|
||||
59
ApplicationLibCode/Application/RiaStimPlanModelDefines.cpp
Normal file
59
ApplicationLibCode/Application/RiaStimPlanModelDefines.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaStimPlanModelDefines.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
void AppEnum<RiaDefines::CurveProperty>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::CurveProperty::UNDEFINED, "UNDEFINED", "Undefined" );
|
||||
addItem( RiaDefines::CurveProperty::FACIES, "FACIES", "Facies" );
|
||||
addItem( RiaDefines::CurveProperty::LAYERS, "LAYERS", "Layers" );
|
||||
addItem( RiaDefines::CurveProperty::POROSITY, "POROSITY", "Porosity" );
|
||||
addItem( RiaDefines::CurveProperty::PERMEABILITY_X, "PERMEABILITY_X", "Permeability Horizontal" );
|
||||
addItem( RiaDefines::CurveProperty::PERMEABILITY_Z, "PERMEABILITY_Z", "Permeability Vertical" );
|
||||
addItem( RiaDefines::CurveProperty::INITIAL_PRESSURE, "INITIAL_PRESSURE", "Initial Pressure" );
|
||||
addItem( RiaDefines::CurveProperty::PRESSURE, "PRESSURE", "Pressure" );
|
||||
addItem( RiaDefines::CurveProperty::STRESS, "STRESS", "Stress" );
|
||||
addItem( RiaDefines::CurveProperty::INITIAL_STRESS, "INITIAL_STRESS", "Initial Stress" );
|
||||
addItem( RiaDefines::CurveProperty::STRESS_GRADIENT, "STRESS_GRADIENT", "Stress Gradient" );
|
||||
addItem( RiaDefines::CurveProperty::YOUNGS_MODULUS, "YOUNGS_MODULUS", "Young's Modulus" );
|
||||
addItem( RiaDefines::CurveProperty::POISSONS_RATIO, "POISSONS_RATIO", "Poisson's Ratio" );
|
||||
addItem( RiaDefines::CurveProperty::K_IC, "K_IC", "K-Ic" );
|
||||
addItem( RiaDefines::CurveProperty::PROPPANT_EMBEDMENT, "PROPPANT_EMBEDMENT", "Proppant Embedment" );
|
||||
addItem( RiaDefines::CurveProperty::BIOT_COEFFICIENT, "BIOT_COEFFICIENT", "Biot Coefficient" );
|
||||
addItem( RiaDefines::CurveProperty::K0, "K0", "k0" );
|
||||
addItem( RiaDefines::CurveProperty::FLUID_LOSS_COEFFICIENT, "FLUID_LOSS_COEFFICIENT", "Fluid Loss Coefficient" );
|
||||
addItem( RiaDefines::CurveProperty::SPURT_LOSS, "SPURT_LOSS", "Spurt Loss" );
|
||||
addItem( RiaDefines::CurveProperty::TEMPERATURE, "TEMPERATURE", "Temperature" );
|
||||
addItem( RiaDefines::CurveProperty::RELATIVE_PERMEABILITY_FACTOR,
|
||||
"RELATIVE_PERMEABILITY_FACTOR",
|
||||
"Relative Permeability Factor" );
|
||||
addItem( RiaDefines::CurveProperty::PORO_ELASTIC_CONSTANT, "PORO_ELASTIC_CONSTANT", "Poro-Elastic Constant" );
|
||||
addItem( RiaDefines::CurveProperty::THERMAL_EXPANSION_COEFFICIENT,
|
||||
"THERMAL_EXPANSION_COEFFICIENT",
|
||||
"Thermal Expansion Coefficient" );
|
||||
addItem( RiaDefines::CurveProperty::IMMOBILE_FLUID_SATURATION, "IMMOBILE_FLUID_SATURATION", "Immobile Fluid Saturation" );
|
||||
addItem( RiaDefines::CurveProperty::NET_TO_GROSS, "NET_TO_GROSS", "Net-To-Gross" );
|
||||
addItem( RiaDefines::CurveProperty::POROSITY_UNSCALED, "POROSITY_UNSCALED", "Porosity (Unscaled)" );
|
||||
|
||||
setDefault( RiaDefines::CurveProperty::UNDEFINED );
|
||||
}
|
||||
}; // namespace caf
|
||||
56
ApplicationLibCode/Application/RiaStimPlanModelDefines.h
Normal file
56
ApplicationLibCode/Application/RiaStimPlanModelDefines.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaEclipseUnitTools.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace RiaDefines
|
||||
{
|
||||
enum class CurveProperty
|
||||
{
|
||||
UNDEFINED,
|
||||
FACIES,
|
||||
LAYERS,
|
||||
POROSITY,
|
||||
PERMEABILITY_X,
|
||||
PERMEABILITY_Z,
|
||||
INITIAL_PRESSURE,
|
||||
PRESSURE,
|
||||
STRESS,
|
||||
INITIAL_STRESS,
|
||||
STRESS_GRADIENT,
|
||||
YOUNGS_MODULUS,
|
||||
POISSONS_RATIO,
|
||||
K_IC,
|
||||
PROPPANT_EMBEDMENT,
|
||||
BIOT_COEFFICIENT,
|
||||
K0,
|
||||
FLUID_LOSS_COEFFICIENT,
|
||||
SPURT_LOSS,
|
||||
TEMPERATURE,
|
||||
RELATIVE_PERMEABILITY_FACTOR,
|
||||
PORO_ELASTIC_CONSTANT,
|
||||
THERMAL_EXPANSION_COEFFICIENT,
|
||||
IMMOBILE_FLUID_SATURATION,
|
||||
NET_TO_GROSS,
|
||||
POROSITY_UNSCALED,
|
||||
};
|
||||
}; // namespace RiaDefines
|
||||
69
ApplicationLibCode/Application/RiaStringListSerializer.cpp
Normal file
69
ApplicationLibCode/Application/RiaStringListSerializer.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaStringListSerializer.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaStringListSerializer::RiaStringListSerializer( const QString& key )
|
||||
: m_key( key )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaStringListSerializer::addString( const QString& textString, int maxStringCount )
|
||||
{
|
||||
QSettings settings;
|
||||
QStringList stringList = settings.value( m_key ).toStringList();
|
||||
|
||||
stringList.removeAll( textString );
|
||||
stringList.prepend( textString );
|
||||
while ( stringList.size() > maxStringCount )
|
||||
stringList.removeLast();
|
||||
|
||||
settings.setValue( m_key, stringList );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaStringListSerializer::removeString( const QString& textString )
|
||||
{
|
||||
QSettings settings;
|
||||
QStringList files = settings.value( m_key ).toStringList();
|
||||
files.removeAll( textString );
|
||||
|
||||
settings.setValue( m_key, files );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RiaStringListSerializer::textStrings()
|
||||
{
|
||||
QSettings settings;
|
||||
QStringList stringList = settings.value( m_key ).toStringList();
|
||||
|
||||
return stringList;
|
||||
}
|
||||
40
ApplicationLibCode/Application/RiaStringListSerializer.h
Normal file
40
ApplicationLibCode/Application/RiaStringListSerializer.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 <QString>
|
||||
|
||||
class QStringList;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaStringListSerializer
|
||||
{
|
||||
public:
|
||||
explicit RiaStringListSerializer( const QString& key );
|
||||
|
||||
void addString( const QString& textString, int maxStringCount );
|
||||
void removeString( const QString& textString );
|
||||
|
||||
QStringList textStrings();
|
||||
|
||||
private:
|
||||
QString m_key;
|
||||
};
|
||||
260
ApplicationLibCode/Application/RiaSummaryCurveDefinition.cpp
Normal file
260
ApplicationLibCode/Application/RiaSummaryCurveDefinition.cpp
Normal file
@@ -0,0 +1,260 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaSummaryCurveDefinition.h"
|
||||
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSummaryCaseCollection.h"
|
||||
|
||||
#include "cafAssert.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaSummaryCurveDefinition::RiaSummaryCurveDefinition()
|
||||
: m_summaryCase( nullptr )
|
||||
, m_ensemble( nullptr )
|
||||
, m_isEnsembleCurve( false )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaSummaryCurveDefinition::RiaSummaryCurveDefinition( gsl::not_null<RimSummaryCase*> summaryCase,
|
||||
const RifEclipseSummaryAddress& summaryAddress,
|
||||
bool isEnsembleCurve )
|
||||
: m_summaryCase( summaryCase )
|
||||
, m_summaryAddress( summaryAddress )
|
||||
, m_isEnsembleCurve( isEnsembleCurve )
|
||||
{
|
||||
if ( summaryCase )
|
||||
{
|
||||
RimSummaryCaseCollection* ensemble = nullptr;
|
||||
summaryCase->firstAncestorOfType( ensemble );
|
||||
m_ensemble = ensemble;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaSummaryCurveDefinition::RiaSummaryCurveDefinition( gsl::not_null<RimSummaryCaseCollection*> ensemble,
|
||||
const RifEclipseSummaryAddress& summaryAddress )
|
||||
: m_summaryCase( nullptr )
|
||||
, m_summaryAddress( summaryAddress )
|
||||
, m_ensemble( ensemble )
|
||||
, m_isEnsembleCurve( true )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryCase* RiaSummaryCurveDefinition::summaryCase() const
|
||||
{
|
||||
return m_summaryCase;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryCaseCollection* RiaSummaryCurveDefinition::ensemble() const
|
||||
{
|
||||
return m_ensemble;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const RifEclipseSummaryAddress& RiaSummaryCurveDefinition::summaryAddress() const
|
||||
{
|
||||
return m_summaryAddress;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaSummaryCurveDefinition::isEnsembleCurve() const
|
||||
{
|
||||
return m_isEnsembleCurve;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSummaryCurveDefinition::resultValues( const RiaSummaryCurveDefinition& curveDefinition,
|
||||
gsl::not_null<std::vector<double>*> values )
|
||||
{
|
||||
if ( !curveDefinition.summaryAddress().isValid() ) return;
|
||||
if ( !curveDefinition.summaryCase() ) return;
|
||||
|
||||
RifSummaryReaderInterface* reader = curveDefinition.summaryCase()->summaryReader();
|
||||
if ( !reader ) return;
|
||||
|
||||
reader->values( curveDefinition.summaryAddress(), values );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<time_t>& RiaSummaryCurveDefinition::timeSteps( const RiaSummaryCurveDefinition& curveDefinition )
|
||||
{
|
||||
static std::vector<time_t> dummy;
|
||||
|
||||
if ( !curveDefinition.summaryAddress().isValid() ) return dummy;
|
||||
if ( !curveDefinition.summaryCase() ) return dummy;
|
||||
|
||||
RifSummaryReaderInterface* reader = curveDefinition.summaryCase()->summaryReader();
|
||||
if ( !reader ) return dummy;
|
||||
|
||||
return reader->timeSteps( curveDefinition.summaryAddress() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaSummaryCurveDefinition::curveDefinitionText() const
|
||||
{
|
||||
QString caseName;
|
||||
if ( summaryCase() )
|
||||
caseName = summaryCase()->displayCaseName();
|
||||
else if ( ensemble() )
|
||||
caseName = ensemble()->name();
|
||||
|
||||
return RiaSummaryCurveDefinition::curveDefinitionText( caseName, summaryAddress() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaSummaryCurveDefinition::curveDefinitionText( const QString& caseName,
|
||||
const RifEclipseSummaryAddress& summaryAddress )
|
||||
{
|
||||
QString txt;
|
||||
|
||||
txt += caseName;
|
||||
txt += ", ";
|
||||
|
||||
txt += QString::fromStdString( summaryAddress.uiText() );
|
||||
|
||||
return txt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaSummaryCurveDefinition::operator<( const RiaSummaryCurveDefinition& other ) const
|
||||
{
|
||||
if ( m_ensemble != other.ensemble() )
|
||||
{
|
||||
QString ensembleName;
|
||||
QString otherEnsembleName;
|
||||
|
||||
if ( m_ensemble )
|
||||
{
|
||||
ensembleName = m_ensemble->name();
|
||||
}
|
||||
|
||||
if ( other.ensemble() )
|
||||
{
|
||||
otherEnsembleName = other.ensemble()->name();
|
||||
}
|
||||
|
||||
// First check if names are different to ensure stable alphabetic sort
|
||||
if ( ensembleName != otherEnsembleName )
|
||||
{
|
||||
return ensembleName < otherEnsembleName;
|
||||
}
|
||||
|
||||
// Use pointer address, sorting will be be unstable
|
||||
return m_ensemble < other.ensemble();
|
||||
}
|
||||
|
||||
if ( m_summaryCase != other.summaryCase() )
|
||||
{
|
||||
QString summaryCaseName;
|
||||
QString otherSummaryCaseName;
|
||||
|
||||
if ( m_summaryCase )
|
||||
{
|
||||
summaryCaseName = m_summaryCase->displayCaseName();
|
||||
}
|
||||
if ( other.summaryCase() )
|
||||
{
|
||||
otherSummaryCaseName = other.summaryCase()->displayCaseName();
|
||||
}
|
||||
|
||||
// First check if names are different to ensure stable alphabetic sort
|
||||
if ( summaryCaseName != otherSummaryCaseName )
|
||||
{
|
||||
return summaryCaseName < otherSummaryCaseName;
|
||||
}
|
||||
|
||||
// Use pointer address, sorting will be be unstable
|
||||
return m_summaryCase < other.summaryCase();
|
||||
}
|
||||
|
||||
if ( m_summaryAddress != other.summaryAddress() )
|
||||
{
|
||||
return ( m_summaryAddress < other.summaryAddress() );
|
||||
}
|
||||
|
||||
return m_isEnsembleCurve < other.isEnsembleCurve();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSummaryCurveDefinitionAnalyser::setCurveDefinitions( const std::vector<RiaSummaryCurveDefinition>& curveDefs )
|
||||
{
|
||||
m_singleSummaryCases.clear();
|
||||
m_ensembles.clear();
|
||||
m_quantityNames.clear();
|
||||
m_summaryItems.clear();
|
||||
|
||||
for ( const auto& curveDef : curveDefs )
|
||||
{
|
||||
bool valid = false;
|
||||
if ( curveDef.ensemble() && curveDef.isEnsembleCurve() )
|
||||
{
|
||||
m_ensembles.insert( curveDef.ensemble() );
|
||||
valid = true;
|
||||
}
|
||||
else if ( curveDef.summaryCase() )
|
||||
{
|
||||
m_singleSummaryCases.insert( curveDef.summaryCase() );
|
||||
|
||||
if ( curveDef.summaryCase()->ensemble() )
|
||||
{
|
||||
m_ensembles.insert( curveDef.summaryCase()->ensemble() );
|
||||
}
|
||||
valid = true;
|
||||
}
|
||||
if ( valid )
|
||||
{
|
||||
RifEclipseSummaryAddress address = curveDef.summaryAddress();
|
||||
|
||||
m_quantityNames.insert( address.quantityName() );
|
||||
|
||||
address.setQuantityName( "" );
|
||||
if ( !address.itemUiText().empty() ) m_summaryItems.insert( address );
|
||||
}
|
||||
}
|
||||
}
|
||||
79
ApplicationLibCode/Application/RiaSummaryCurveDefinition.h
Normal file
79
ApplicationLibCode/Application/RiaSummaryCurveDefinition.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <gsl/gsl>
|
||||
|
||||
class RimSummaryCase;
|
||||
class RimSummaryCaseCollection;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaSummaryCurveDefinition
|
||||
{
|
||||
public:
|
||||
RiaSummaryCurveDefinition();
|
||||
explicit RiaSummaryCurveDefinition( gsl::not_null<RimSummaryCase*> summaryCase,
|
||||
const RifEclipseSummaryAddress& summaryAddress,
|
||||
bool isEnsembleCurve );
|
||||
explicit RiaSummaryCurveDefinition( gsl::not_null<RimSummaryCaseCollection*> ensemble,
|
||||
const RifEclipseSummaryAddress& summaryAddress );
|
||||
|
||||
RimSummaryCase* summaryCase() const;
|
||||
const RifEclipseSummaryAddress& summaryAddress() const;
|
||||
RimSummaryCaseCollection* ensemble() const;
|
||||
bool isEnsembleCurve() const;
|
||||
|
||||
bool operator<( const RiaSummaryCurveDefinition& other ) const;
|
||||
|
||||
// TODO: Consider moving to a separate tools class
|
||||
static void resultValues( const RiaSummaryCurveDefinition& curveDefinition, gsl::not_null<std::vector<double>*> values );
|
||||
static const std::vector<time_t>& timeSteps( const RiaSummaryCurveDefinition& curveDefinition );
|
||||
|
||||
QString curveDefinitionText() const;
|
||||
|
||||
static QString curveDefinitionText( const QString& caseName, const RifEclipseSummaryAddress& summaryAddress );
|
||||
|
||||
private:
|
||||
RimSummaryCase* m_summaryCase;
|
||||
RifEclipseSummaryAddress m_summaryAddress;
|
||||
RimSummaryCaseCollection* m_ensemble;
|
||||
bool m_isEnsembleCurve;
|
||||
};
|
||||
|
||||
class RiaSummaryCurveDefinitionAnalyser
|
||||
{
|
||||
public:
|
||||
RiaSummaryCurveDefinitionAnalyser() = default;
|
||||
void setCurveDefinitions( const std::vector<RiaSummaryCurveDefinition>& curveDefs );
|
||||
|
||||
std::set<RimSummaryCase*> m_singleSummaryCases; // All summary cases used
|
||||
std::set<RimSummaryCaseCollection*> m_ensembles; // All the ensembles referenced by the summary cases
|
||||
|
||||
std::set<RifEclipseSummaryAddress> m_summaryItems; // Quantity name set to "", stores only the identifiers
|
||||
std::set<std::string> m_quantityNames; // Quantity names from the addresses
|
||||
};
|
||||
143
ApplicationLibCode/Application/RiaViewRedrawScheduler.cpp
Normal file
143
ApplicationLibCode/Application/RiaViewRedrawScheduler.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaViewRedrawScheduler.h"
|
||||
#include "Rim3dView.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QTimer>
|
||||
|
||||
#include "cafProgressState.h"
|
||||
#include <set>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaViewRedrawScheduler* RiaViewRedrawScheduler::instance()
|
||||
{
|
||||
static RiaViewRedrawScheduler theInstance;
|
||||
|
||||
return &theInstance;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Schedule a creation of the Display model and redraw of the reservoir view
|
||||
/// The redraw will happen as soon as the event loop is entered
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaViewRedrawScheduler::scheduleDisplayModelUpdateAndRedraw( Rim3dView* resViewToUpdate )
|
||||
{
|
||||
m_resViewsToUpdate.push_back( resViewToUpdate );
|
||||
|
||||
startTimer( 0 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaViewRedrawScheduler::clearViewsScheduledForUpdate()
|
||||
{
|
||||
if ( m_resViewUpdateTimer )
|
||||
{
|
||||
while ( m_resViewUpdateTimer->isActive() )
|
||||
{
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
}
|
||||
m_resViewsToUpdate.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaViewRedrawScheduler::updateAndRedrawScheduledViews()
|
||||
{
|
||||
// Compress to remove duplicates
|
||||
// and update dependent views after independent views
|
||||
|
||||
std::set<Rim3dView*> independent3DViewsToUpdate;
|
||||
std::set<Rim3dView*> dependent3DViewsToUpdate;
|
||||
|
||||
for ( size_t i = 0; i < m_resViewsToUpdate.size(); ++i )
|
||||
{
|
||||
if ( !m_resViewsToUpdate[i] ) continue;
|
||||
|
||||
if ( m_resViewsToUpdate[i]->viewController() )
|
||||
dependent3DViewsToUpdate.insert( m_resViewsToUpdate[i] );
|
||||
else
|
||||
independent3DViewsToUpdate.insert( m_resViewsToUpdate[i] );
|
||||
}
|
||||
|
||||
for ( std::set<Rim3dView*>::iterator it = independent3DViewsToUpdate.begin(); it != independent3DViewsToUpdate.end();
|
||||
++it )
|
||||
{
|
||||
if ( *it )
|
||||
{
|
||||
( *it )->createDisplayModelAndRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
for ( std::set<Rim3dView*>::iterator it = dependent3DViewsToUpdate.begin(); it != dependent3DViewsToUpdate.end(); ++it )
|
||||
{
|
||||
if ( *it )
|
||||
{
|
||||
( *it )->createDisplayModelAndRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
m_resViewsToUpdate.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaViewRedrawScheduler::slotUpdateAndRedrawScheduledViewsWhenReady()
|
||||
{
|
||||
if ( caf::ProgressState::isActive() )
|
||||
{
|
||||
startTimer( 100 );
|
||||
return;
|
||||
}
|
||||
|
||||
updateAndRedrawScheduledViews();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaViewRedrawScheduler::startTimer( int msecs )
|
||||
{
|
||||
if ( !m_resViewUpdateTimer )
|
||||
{
|
||||
m_resViewUpdateTimer = new QTimer( this );
|
||||
connect( m_resViewUpdateTimer, SIGNAL( timeout() ), this, SLOT( slotUpdateAndRedrawScheduledViewsWhenReady() ) );
|
||||
}
|
||||
|
||||
if ( !m_resViewUpdateTimer->isActive() )
|
||||
{
|
||||
m_resViewUpdateTimer->setSingleShot( true );
|
||||
m_resViewUpdateTimer->start( msecs );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaViewRedrawScheduler::~RiaViewRedrawScheduler()
|
||||
{
|
||||
delete m_resViewUpdateTimer;
|
||||
}
|
||||
55
ApplicationLibCode/Application/RiaViewRedrawScheduler.h
Normal file
55
ApplicationLibCode/Application/RiaViewRedrawScheduler.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "cafPdmPointer.h"
|
||||
#include <QObject>
|
||||
#include <vector>
|
||||
|
||||
class QTimer;
|
||||
class Rim3dView;
|
||||
|
||||
class RiaViewRedrawScheduler : public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
static RiaViewRedrawScheduler* instance();
|
||||
void scheduleDisplayModelUpdateAndRedraw( Rim3dView* resViewToUpdate );
|
||||
void clearViewsScheduledForUpdate();
|
||||
void updateAndRedrawScheduledViews();
|
||||
|
||||
private slots:
|
||||
void slotUpdateAndRedrawScheduledViewsWhenReady();
|
||||
|
||||
private:
|
||||
void startTimer( int msecs );
|
||||
|
||||
RiaViewRedrawScheduler()
|
||||
: m_resViewUpdateTimer( nullptr )
|
||||
{
|
||||
}
|
||||
~RiaViewRedrawScheduler() override;
|
||||
|
||||
RiaViewRedrawScheduler( const RiaViewRedrawScheduler& o ) = delete;
|
||||
void operator=( const RiaViewRedrawScheduler& o ) = delete;
|
||||
|
||||
std::vector<caf::PdmPointer<Rim3dView>> m_resViewsToUpdate;
|
||||
QTimer* m_resViewUpdateTimer;
|
||||
};
|
||||
106
ApplicationLibCode/Application/Tools/CMakeLists_files.cmake
Normal file
106
ApplicationLibCode/Application/Tools/CMakeLists_files.cmake
Normal file
@@ -0,0 +1,106 @@
|
||||
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaArgumentParser.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaDateStringParser.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaColorTables.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaColorTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseUnitTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaImageCompareReporter.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaImageFileCompare.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaImageTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaLogging.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaProjectModifier.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaRegressionTest.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaImportEclipseCaseTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaQDateTimeTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSummaryTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWellNameComparer.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStdStringTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaInterpolationTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSummaryCurveAnalyzer.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSimWellBranchTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaProjectFileVersionTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStringEncodingTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaTextStringTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaTextFileCompare.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaRegressionTestRunner.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaExtractionTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFilePathTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCurveMerger.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCurveMerger.inl
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCurveDataTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaTimeHistoryCurveResampler.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStatisticsTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOffshoreSphericalCoords.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMeanCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaMedianCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMeanCalculator.inl
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOptionItemFactory.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGitDiff.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCellDividingTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFieldHandleTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaBoundingBoxTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWellLogUnitTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWellLogUnitTools.inl
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaTimeTTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaValidRegExpValidator.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaArgumentParser.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaDateStringParser.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaColorTables.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaColorTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseUnitTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaImageCompareReporter.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaImageFileCompare.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaImageTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaLogging.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaProjectModifier.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaRegressionTest.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaImportEclipseCaseTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaQDateTimeTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSummaryTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWellNameComparer.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStdStringTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaInterpolationTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSummaryCurveAnalyzer.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSimWellBranchTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaProjectFileVersionTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStringEncodingTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaTextStringTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaTextFileCompare.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaRegressionTestRunner.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaExtractionTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFilePathTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCurveMerger.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCurveDataTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaTimeHistoryCurveResampler.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStatisticsTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOptionItemFactory.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGitDiff.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCellDividingTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFieldHandleTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaBoundingBoxTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaTimeTTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaValidRegExpValidator.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
${SOURCE_GROUP_HEADER_FILES}
|
||||
)
|
||||
|
||||
list(APPEND CODE_SOURCE_FILES
|
||||
${SOURCE_GROUP_SOURCE_FILES}
|
||||
)
|
||||
|
||||
set (QT_MOC_HEADERS
|
||||
${QT_MOC_HEADERS}
|
||||
)
|
||||
|
||||
|
||||
source_group( "Application\\Tools" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )
|
||||
160
ApplicationLibCode/Application/Tools/RiaArgumentParser.cpp
Normal file
160
ApplicationLibCode/Application/Tools/RiaArgumentParser.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaArgumentParser.h"
|
||||
|
||||
#include "RiaBaseDefs.h"
|
||||
#include "RiaImportEclipseCaseTools.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiaProjectModifier.h"
|
||||
#include "RiaRegressionTestRunner.h"
|
||||
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "RiuMainWindow.h"
|
||||
#include "RiuPlotMainWindow.h"
|
||||
|
||||
#include "RicfCommandFileExecutor.h"
|
||||
|
||||
#include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h"
|
||||
#include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
|
||||
#include "ExportCommands/RicSnapshotViewToFileFeature.h"
|
||||
#include "RicImportSummaryCasesFeature.h"
|
||||
|
||||
#include "cafPdmScriptIOMessages.h"
|
||||
#include "cvfProgramOptions.h"
|
||||
#include "cvfqtUtils.h"
|
||||
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaArgumentParser::parseArguments( cvf::ProgramOptions* progOpt )
|
||||
{
|
||||
CVF_ASSERT( progOpt );
|
||||
progOpt->registerOption( "help", "", "Displays help text and exits." );
|
||||
progOpt->registerOption( "?", "", "Displays help text and exits." );
|
||||
|
||||
progOpt->registerOption( "project", "<filename>", "Open project file <filename>.", cvf::ProgramOptions::SINGLE_VALUE );
|
||||
progOpt->registerOption( "last", "", "Open last used project." );
|
||||
progOpt->registerOption( "case",
|
||||
"<casename|filename> [<casename|filename> ...]",
|
||||
"Imports the Eclipse cases specified by case name with or without extension."
|
||||
"If <casename>, import the corresponding grid file and summary file"
|
||||
"If <filename> has extension .GRRID/.EGRID, import the grid file and corresponding "
|
||||
"summary file"
|
||||
"If <filename> has extension .SMSPEC, import the summary file (does not open the "
|
||||
"corresponding grid file)",
|
||||
cvf::ProgramOptions::MULTI_VALUE );
|
||||
progOpt->registerOption( "size",
|
||||
"<width> <height>",
|
||||
"Set size of the main application window.",
|
||||
cvf::ProgramOptions::MULTI_VALUE );
|
||||
progOpt->registerOption( "console", "", "Launch as a console application without graphics" );
|
||||
progOpt->registerOption( "server",
|
||||
"[<portnumber>]",
|
||||
"Launch as a GRPC server. Default port is 50051",
|
||||
cvf::ProgramOptions::SINGLE_VALUE );
|
||||
progOpt->registerOption( "startdir", "<folder>", "Set startup directory.\n", cvf::ProgramOptions::SINGLE_VALUE );
|
||||
|
||||
progOpt->registerOption( "summaryplot",
|
||||
"[<plotOptions>] <eclipsesummaryvectors> <eclipsedatafiles>",
|
||||
"Creates a summary plot using all the <eclipsedatafiles>,"
|
||||
"and all the summary vectors defined in <eclipsesummaryvectors>."
|
||||
"Use --summaryplot -help to show a more detailed help text.\n",
|
||||
cvf::ProgramOptions::OPTIONAL_MULTI_VALUE );
|
||||
|
||||
progOpt->registerOption( "commandFile", "<commandfile>", "Execute the command file.", cvf::ProgramOptions::SINGLE_VALUE );
|
||||
progOpt->registerOption( "commandFileReplaceCases",
|
||||
"[<caseId>] <caseListFile>",
|
||||
"Supply list of cases to replace in project, performing command file for each case.",
|
||||
cvf::ProgramOptions::SINGLE_VALUE );
|
||||
progOpt->registerOption( "commandFileProject",
|
||||
"<filename>",
|
||||
"Project to use if performing case looping for command file. Used in conjunction with "
|
||||
"'commandFileReplaceCases'.\n",
|
||||
cvf::ProgramOptions::SINGLE_VALUE );
|
||||
|
||||
progOpt->registerOption( "snapshotsize",
|
||||
"<width> <height>",
|
||||
"Set size of exported snapshot images.",
|
||||
cvf::ProgramOptions::MULTI_VALUE );
|
||||
progOpt->registerOption( "snapshotfolder",
|
||||
"<folder>",
|
||||
"Set the destination folder for exported snapshot images.\n",
|
||||
cvf::ProgramOptions::SINGLE_VALUE );
|
||||
progOpt->registerOption( "savesnapshots",
|
||||
"all|views|plots",
|
||||
"Save snapshot of all views or plots to project file location sub folder 'snapshots'. "
|
||||
"Option 'all' "
|
||||
"will include both views and plots. Application closes after snapshots have been written.",
|
||||
cvf::ProgramOptions::OPTIONAL_MULTI_VALUE );
|
||||
progOpt->registerOption( "multiCaseSnapshots",
|
||||
"<gridListFile>",
|
||||
"For each grid file listed in the <gridListFile> file, replace the first case in the "
|
||||
"project and save "
|
||||
"snapshots of all views.\n",
|
||||
cvf::ProgramOptions::SINGLE_VALUE );
|
||||
|
||||
progOpt->registerOption( "replaceCase",
|
||||
"[<caseId>] <newGridFile>",
|
||||
"Replace grid in <caseId> or first case with <newgridFile>. Repeat parameter for multiple "
|
||||
"replace operations.",
|
||||
cvf::ProgramOptions::MULTI_VALUE,
|
||||
cvf::ProgramOptions::COMBINE_REPEATED );
|
||||
progOpt->registerOption( "replaceSourceCases",
|
||||
"[<caseGroupId>] <gridListFile>",
|
||||
"Replace source cases in <caseGroupId> or first grid case group with the grid files "
|
||||
"listed in the "
|
||||
"<gridListFile> file. Repeat parameter for multiple replace operations.",
|
||||
cvf::ProgramOptions::MULTI_VALUE,
|
||||
cvf::ProgramOptions::COMBINE_REPEATED );
|
||||
progOpt->registerOption( "replacePropertiesFolder",
|
||||
"[<caseId>] <newPropertiesFolder>",
|
||||
"Replace the folder containing property files for an eclipse input case.\n",
|
||||
cvf::ProgramOptions::MULTI_VALUE );
|
||||
|
||||
progOpt->registerOption( "updateregressiontestbase", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE );
|
||||
progOpt->registerOption( "regressiontest", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE );
|
||||
#ifdef USE_UNIT_TESTS
|
||||
progOpt->registerOption( "unittest", "", "System command" );
|
||||
#endif
|
||||
progOpt->registerOption( "generate", "[<outputFile>]", "Generate code or documentation", cvf::ProgramOptions::SINGLE_VALUE );
|
||||
progOpt->registerOption( "ignoreArgs", "", "System command. Ignore all arguments. Mostly for testing purposes" );
|
||||
|
||||
progOpt->setOptionPrefix( cvf::ProgramOptions::DOUBLE_DASH );
|
||||
|
||||
QStringList arguments = QCoreApplication::arguments();
|
||||
|
||||
bool parseOk = progOpt->parse( cvfqt::Utils::toStringVector( arguments ) );
|
||||
|
||||
// If positional parameter functionality is to be supported, the test for existence of positionalParameters must be
|
||||
// removed This is based on a pull request by @andlaus https://github.com/OPM/ResInsight/pull/162
|
||||
if ( !parseOk || !progOpt->positionalParameters().empty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
36
ApplicationLibCode/Application/Tools/RiaArgumentParser.h
Normal file
36
ApplicationLibCode/Application/Tools/RiaArgumentParser.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class ProgramOptions;
|
||||
}
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaArgumentParser
|
||||
{
|
||||
public:
|
||||
static bool parseArguments( cvf::ProgramOptions* progOpt );
|
||||
};
|
||||
34
ApplicationLibCode/Application/Tools/RiaBoundingBoxTools.cpp
Normal file
34
ApplicationLibCode/Application/Tools/RiaBoundingBoxTools.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 "RiaBoundingBoxTools.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::BoundingBox RiaBoundingBoxTools::inflate( const cvf::BoundingBox& boundingBox, double factor )
|
||||
{
|
||||
cvf::Vec3d center = boundingBox.center();
|
||||
cvf::Vec3d sizes = boundingBox.extent() * factor;
|
||||
|
||||
cvf::Vec3d newMin( center.x() - sizes.x() / 2.0, center.y() - sizes.y() / 2.0, center.z() - sizes.z() / 2.0 );
|
||||
cvf::Vec3d newMax( center.x() + sizes.x() / 2.0, center.y() + sizes.y() / 2.0, center.z() + sizes.z() / 2.0 );
|
||||
return cvf::BoundingBox( newMin, newMax );
|
||||
}
|
||||
34
ApplicationLibCode/Application/Tools/RiaBoundingBoxTools.h
Normal file
34
ApplicationLibCode/Application/Tools/RiaBoundingBoxTools.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 <cvfBoundingBox.h>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaBoundingBoxTools
|
||||
{
|
||||
public:
|
||||
static cvf::BoundingBox inflate( const cvf::BoundingBox& boundingBox, double factor );
|
||||
};
|
||||
210
ApplicationLibCode/Application/Tools/RiaCellDividingTools.cpp
Normal file
210
ApplicationLibCode/Application/Tools/RiaCellDividingTools.cpp
Normal file
@@ -0,0 +1,210 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaCellDividingTools.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Internal functions
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Splits a line in a number of equal parts
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<cvf::Vec3d> splitLine( cvf::Vec3d ptStart, cvf::Vec3d ptEnd, size_t partCount );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Calculates all points on a face described by edge points from all four edges.
|
||||
/// The result is a grid of points including the given edge points
|
||||
///
|
||||
/// edgeXPtsHigh
|
||||
/// |-------------|
|
||||
/// | |
|
||||
/// edgeYPtsLow | | edgeYPtsHigh
|
||||
/// | |
|
||||
/// |-------------|
|
||||
/// edgeXPtsLow
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<std::vector<cvf::Vec3d>> calcFacePoints( const std::vector<cvf::Vec3d> edgeXPtsLow,
|
||||
const std::vector<cvf::Vec3d> edgeXPtsHigh,
|
||||
const std::vector<cvf::Vec3d> edgeYPtsLow,
|
||||
const std::vector<cvf::Vec3d> edgeYPtsHigh );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<cvf::Vec3d>
|
||||
RiaCellDividingTools::createHexCornerCoords( std::array<cvf::Vec3d, 8> mainCellCorners, size_t nx, size_t ny, size_t nz )
|
||||
{
|
||||
std::array<std::pair<size_t, size_t>, 12> edgeCorners = {
|
||||
std::make_pair( 0, 1 ),
|
||||
std::make_pair( 3, 2 ),
|
||||
std::make_pair( 4, 5 ),
|
||||
std::make_pair( 7, 6 ), // X
|
||||
std::make_pair( 0, 3 ),
|
||||
std::make_pair( 4, 7 ),
|
||||
std::make_pair( 1, 2 ),
|
||||
std::make_pair( 5, 6 ), // Y
|
||||
std::make_pair( 0, 4 ),
|
||||
std::make_pair( 1, 5 ),
|
||||
std::make_pair( 3, 7 ),
|
||||
std::make_pair( 2, 6 ), // Z
|
||||
};
|
||||
|
||||
std::array<size_t, 3> nxyz = { nx, ny, nz };
|
||||
std::array<std::vector<cvf::Vec3d>, 12> edgePoints;
|
||||
|
||||
for ( int i = 0; i < 12; i++ )
|
||||
{
|
||||
int partCountsIndex = i / 4;
|
||||
edgePoints[i] = splitLine( mainCellCorners[edgeCorners[i].first],
|
||||
mainCellCorners[edgeCorners[i].second],
|
||||
nxyz[partCountsIndex] );
|
||||
}
|
||||
|
||||
// lowIJ, highIJ, lowJK, highKJ,
|
||||
std::vector<std::vector<std::vector<cvf::Vec3d>>> nodes;
|
||||
nodes.reserve( ( nx + 1 ) * ( ny + 1 ) * ( nz + 1 ) );
|
||||
|
||||
auto xyFacePtsLow = calcFacePoints( edgePoints[0], edgePoints[1], edgePoints[4], edgePoints[6] );
|
||||
auto xyFacePtsHigh = calcFacePoints( edgePoints[2], edgePoints[3], edgePoints[5], edgePoints[7] );
|
||||
auto yzFacePtsLow = calcFacePoints( edgePoints[4], edgePoints[5], edgePoints[8], edgePoints[10] );
|
||||
auto yzFacePtsHigh = calcFacePoints( edgePoints[6], edgePoints[7], edgePoints[9], edgePoints[11] );
|
||||
auto xzFacePtsLow = calcFacePoints( edgePoints[0], edgePoints[2], edgePoints[8], edgePoints[9] );
|
||||
auto xzFacePtsHigh = calcFacePoints( edgePoints[1], edgePoints[3], edgePoints[10], edgePoints[11] );
|
||||
|
||||
nodes.push_back( xyFacePtsLow );
|
||||
|
||||
for ( size_t z = 1; z < nz; z++ )
|
||||
{
|
||||
auto xyFacePoints = calcFacePoints( xzFacePtsLow[z], xzFacePtsHigh[z], yzFacePtsLow[z], yzFacePtsHigh[z] );
|
||||
nodes.push_back( xyFacePoints );
|
||||
}
|
||||
|
||||
nodes.push_back( xyFacePtsHigh );
|
||||
|
||||
std::vector<cvf::Vec3d> coords;
|
||||
coords.reserve( nx * ny * nz * 8 );
|
||||
|
||||
for ( size_t z = 1; z < nz + 1; z++ )
|
||||
{
|
||||
for ( size_t y = 1; y < ny + 1; y++ )
|
||||
{
|
||||
for ( size_t x = 1; x < nx + 1; x++ )
|
||||
{
|
||||
std::array<cvf::Vec3d, 8> cs;
|
||||
|
||||
cs[0] = nodes[z - 1][y - 1][x - 1];
|
||||
cs[1] = nodes[z - 1][y - 1][x];
|
||||
cs[2] = nodes[z - 1][y][x];
|
||||
cs[3] = nodes[z - 1][y][x - 1];
|
||||
|
||||
cs[4] = nodes[z][y - 1][x - 1];
|
||||
cs[5] = nodes[z][y - 1][x];
|
||||
cs[6] = nodes[z][y][x];
|
||||
cs[7] = nodes[z][y][x - 1];
|
||||
|
||||
coords.insert( coords.end(), cs.begin(), cs.end() );
|
||||
}
|
||||
}
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaCellDividingTools::computeFlowDistance( const std::array<cvf::Vec3d, 8>& cellVertices,
|
||||
const cvf::Vec3d& areaCenter )
|
||||
{
|
||||
auto subCellCorners = createHexCornerCoords( cellVertices, 2, 2, 2 );
|
||||
|
||||
double weightedDistanceTotal = 0.0;
|
||||
double weightTotal = 0.0;
|
||||
|
||||
for ( size_t c = 0; c < 8; c++ )
|
||||
{
|
||||
double weight = 1.0;
|
||||
weightTotal += weight;
|
||||
|
||||
cvf::Vec3d centerOfSubCell = cvf::Vec3d::ZERO;
|
||||
{
|
||||
cvf::Vec3d vertexSum = cvf::Vec3d::ZERO;
|
||||
for ( size_t v = 0; v < 8; v++ )
|
||||
vertexSum += subCellCorners[c * 8 + v];
|
||||
centerOfSubCell = vertexSum / 8;
|
||||
}
|
||||
|
||||
auto dist = ( centerOfSubCell - areaCenter ).length();
|
||||
weightedDistanceTotal += ( dist * weight );
|
||||
}
|
||||
|
||||
return weightedDistanceTotal / weightTotal;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<cvf::Vec3d> splitLine( cvf::Vec3d ptStart, cvf::Vec3d ptEnd, size_t partCount )
|
||||
{
|
||||
std::vector<cvf::Vec3d> pts = { ptStart };
|
||||
|
||||
for ( size_t i = 1; i < partCount; i++ )
|
||||
{
|
||||
pts.push_back( cvf::Vec3d( ptStart.x() + ( ptEnd.x() - ptStart.x() ) * i / partCount,
|
||||
ptStart.y() + ( ptEnd.y() - ptStart.y() ) * i / partCount,
|
||||
ptStart.z() + ( ptEnd.z() - ptStart.z() ) * i / partCount ) );
|
||||
}
|
||||
pts.push_back( ptEnd );
|
||||
return pts;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<std::vector<cvf::Vec3d>> calcFacePoints( const std::vector<cvf::Vec3d> edgeXPtsLow,
|
||||
const std::vector<cvf::Vec3d> edgeXPtsHigh,
|
||||
const std::vector<cvf::Vec3d> edgeYPtsLow,
|
||||
const std::vector<cvf::Vec3d> edgeYPtsHigh )
|
||||
{
|
||||
CVF_ASSERT( edgeXPtsLow.size() == edgeXPtsHigh.size() && edgeYPtsLow.size() == edgeYPtsHigh.size() );
|
||||
|
||||
size_t xSize = edgeXPtsLow.size();
|
||||
size_t ySize = edgeYPtsLow.size();
|
||||
|
||||
std::vector<std::vector<cvf::Vec3d>> pts;
|
||||
|
||||
// Add low edge points
|
||||
pts.push_back( edgeXPtsLow );
|
||||
|
||||
// Interior points
|
||||
for ( size_t y = 1; y < ySize - 1; y++ )
|
||||
{
|
||||
auto interiorPts = splitLine( edgeYPtsLow[y], edgeYPtsHigh[y], xSize - 1 );
|
||||
pts.push_back( interiorPts );
|
||||
}
|
||||
|
||||
// Add low edge points
|
||||
pts.push_back( edgeXPtsHigh );
|
||||
return pts;
|
||||
}
|
||||
36
ApplicationLibCode/Application/Tools/RiaCellDividingTools.h
Normal file
36
ApplicationLibCode/Application/Tools/RiaCellDividingTools.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 <cvfVector3.h>
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaCellDividingTools
|
||||
{
|
||||
public:
|
||||
static std::vector<cvf::Vec3d>
|
||||
createHexCornerCoords( std::array<cvf::Vec3d, 8> mainCellCorners, size_t nx, size_t ny, size_t nz );
|
||||
|
||||
static double computeFlowDistance( const std::array<cvf::Vec3d, 8>& cellVertices, const cvf::Vec3d& areaCenter );
|
||||
};
|
||||
733
ApplicationLibCode/Application/Tools/RiaColorTables.cpp
Normal file
733
ApplicationLibCode/Application/Tools/RiaColorTables.cpp
Normal file
@@ -0,0 +1,733 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaColorTables.h"
|
||||
#include "RiaColorTools.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <QColor>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::normalPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ cvf::Color3ub( 0, 0, 255 ),
|
||||
cvf::Color3ub( 0, 127, 255 ),
|
||||
cvf::Color3ub( 0, 255, 255 ),
|
||||
cvf::Color3ub( 0, 255, 0 ),
|
||||
cvf::Color3ub( 255, 255, 0 ),
|
||||
cvf::Color3ub( 255, 127, 0 ),
|
||||
cvf::Color3ub( 255, 0, 0 ) };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::normalPaletteOppositeOrderingColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ cvf::Color3ub( 255, 0, 0 ),
|
||||
cvf::Color3ub( 255, 127, 0 ),
|
||||
cvf::Color3ub( 255, 255, 0 ),
|
||||
cvf::Color3ub( 0, 255, 0 ),
|
||||
cvf::Color3ub( 0, 255, 255 ),
|
||||
cvf::Color3ub( 0, 127, 255 ),
|
||||
cvf::Color3ub( 0, 0, 255 ) };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::blackWhitePaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ cvf::Color3ub::BLACK, cvf::Color3ub::WHITE };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::whiteBlackPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ cvf::Color3ub::WHITE, cvf::Color3ub::BLACK };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::pinkWhitePaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ cvf::Color3ub::DEEP_PINK, cvf::Color3ub::WHITE };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::whitePinkPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ cvf::Color3ub::WHITE, cvf::Color3ub::DEEP_PINK };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::blueWhiteRedPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ cvf::Color3ub::BLUE, cvf::Color3ub::WHITE, cvf::Color3ub::RED };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::redWhiteBluePaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ cvf::Color3ub::RED, cvf::Color3ub::WHITE, cvf::Color3ub::BLUE };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::categoryPaletteColors()
|
||||
{
|
||||
static caf::ColorTable colorTable = caf::ColorTable( categoryColors() );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::contrastCategoryPaletteColors()
|
||||
{
|
||||
static caf::ColorTable colorTable = caf::ColorTable( contrastCategoryColors() );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::tensorWhiteGrayBlackPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub::WHITE,
|
||||
cvf::Color3ub::LIGHT_GRAY,
|
||||
cvf::Color3ub::BLACK,
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::tensorOrangeBlueWhitePaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 236, 118, 0 ), // Orange
|
||||
cvf::Color3ub( 56, 56, 255 ), // Vivid Blue
|
||||
cvf::Color3ub( 210, 248, 250 ), // White Turquoiseish
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::tensorsMagentaBrownGrayPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 248, 0, 170 ), // Magenta
|
||||
cvf::Color3ub::BROWN,
|
||||
cvf::Color3ub::LIGHT_GRAY,
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::angularPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ cvf::Color3ub( 255, 0, 255 ),
|
||||
cvf::Color3ub( 0, 0, 255 ),
|
||||
cvf::Color3ub( 0, 127, 255 ),
|
||||
cvf::Color3ub( 0, 255, 255 ),
|
||||
cvf::Color3ub( 0, 255, 0 ),
|
||||
cvf::Color3ub( 255, 255, 0 ),
|
||||
cvf::Color3ub( 255, 127, 0 ),
|
||||
cvf::Color3ub( 255, 0, 0 ),
|
||||
cvf::Color3ub( 255, 0, 255 ) };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::rainbowPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ cvf::Color3ub::BLACK,
|
||||
cvf::Color3ub::MAGENTA,
|
||||
cvf::Color3ub::BLUE,
|
||||
cvf::Color3ub::CYAN,
|
||||
cvf::Color3ub::GREEN,
|
||||
cvf::Color3ub::RED,
|
||||
cvf::Color3ub::YELLOW,
|
||||
cvf::Color3ub::WHITE };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::stimPlanPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 220, 220, 220 ), // Grey
|
||||
cvf::Color3ub( 0, 0, 255 ), // Blue
|
||||
cvf::Color3ub( 0, 128, 255 ), // Lighter blue
|
||||
cvf::Color3ub( 80, 240, 60 ), // Darker green
|
||||
cvf::Color3ub( 0, 255, 0 ), // Green
|
||||
cvf::Color3ub( 255, 255, 0 ), // Yellow
|
||||
cvf::Color3ub( 255, 192, 0 ), // Light orange
|
||||
cvf::Color3ub( 255, 128, 0 ), // Orange
|
||||
cvf::Color3ub( 255, 64, 0 ), // Red-orange
|
||||
cvf::Color3ub( 255, 0, 255 ) // Magenta
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::faultsPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 101, 132, 96 ), // Dark green
|
||||
cvf::Color3ub( 255, 131, 140 ), // Old pink
|
||||
cvf::Color3ub( 210, 176, 112 ), // Light Brown
|
||||
cvf::Color3ub( 140, 171, 238 ), // Light gray blue
|
||||
cvf::Color3ub( 255, 205, 131 ), // Peach
|
||||
cvf::Color3ub( 220, 212, 166 ), // Dark off white
|
||||
cvf::Color3ub( 130, 255, 120 ), // Light green
|
||||
cvf::Color3ub( 166, 220, 215 ), // Light gray torquise
|
||||
cvf::Color3ub( 168, 220, 166 ), // Light gray green
|
||||
cvf::Color3ub( 255, 64, 236 ) // Magneta
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::wellsPaletteColors()
|
||||
{
|
||||
return categoryPaletteColors();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::summaryCurveDefaultPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 0, 112, 136 ), // Dark Green-Blue
|
||||
cvf::Color3ub( 202, 0, 0 ), // Red
|
||||
cvf::Color3ub( 78, 204, 0 ), // Clear Green
|
||||
cvf::Color3ub( 236, 118, 0 ), // Orange
|
||||
cvf::Color3ub( 130, 130, 130 ), // Grey
|
||||
cvf::Color3ub( 56, 56, 255 ), // Vivid Blue
|
||||
cvf::Color3ub( 248, 0, 170 ), // Magenta
|
||||
cvf::Color3ub( 169, 2, 240 ), // Purple
|
||||
cvf::Color3ub( 0, 221, 221 ), // Turquoise
|
||||
cvf::Color3ub( 201, 168, 206 ), // Light Violet
|
||||
cvf::Color3ub( 0, 205, 68 ), // Bluish Green
|
||||
cvf::Color3ub( 236, 188, 0 ), // Mid Yellow
|
||||
cvf::Color3ub( 51, 204, 255 ), // Bluer Turquoise
|
||||
cvf::Color3ub( 164, 193, 0 ), // Mid Yellowish Green
|
||||
cvf::Color3ub( 0, 143, 239 ) // Dark Light Blue
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::summaryCurveRedPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 202, 0, 0 ), // Off Red
|
||||
cvf::Color3ub( 255, 51, 51 ), // Bright Red
|
||||
cvf::Color3ub( 255, 102, 102 ) // Light Red
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::summaryCurveGreenPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 78, 204, 0 ), // Clear Green
|
||||
cvf::Color3ub( 164, 193, 0 ), // Mid Yellowish Green
|
||||
cvf::Color3ub( 0, 205, 68 ) // Bluish Green
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::summaryCurveBluePaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 56, 56, 255 ), // Vivid Blue
|
||||
cvf::Color3ub( 0, 143, 239 ), // Dark Light Blue
|
||||
cvf::Color3ub( 153, 153, 255 ) // Off Light Blue
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::summaryCurveBrownPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 186, 101, 44 ),
|
||||
cvf::Color3ub( 99, 53, 23 ), // Highway Brown
|
||||
cvf::Color3ub( 103, 56, 24 ), // Dark Brown
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::summaryCurveNoneRedGreenBlueBrownPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 236, 118, 0 ), // Orange
|
||||
cvf::Color3ub( 0, 0, 0 ), // Black
|
||||
cvf::Color3ub( 248, 0, 170 ), // Magenta
|
||||
cvf::Color3ub( 236, 188, 0 ), // Mid Yellow
|
||||
cvf::Color3ub( 169, 2, 240 ), // Purple
|
||||
cvf::Color3ub( 0, 221, 221 ), // Turquoise
|
||||
cvf::Color3ub( 201, 168, 206 ) // Light Violet
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::wellLogPlotPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ caf::ColorTable::fromQColor( QColor( "peru" ) ),
|
||||
caf::ColorTable::fromQColor( QColor( "blueviolet" ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::darkYellow ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::darkCyan ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::darkMagenta ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::darkGray ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::yellow ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::magenta ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::cyan ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::gray ) ),
|
||||
caf::ColorTable::fromQColor( QColor( "yellowgreen" ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::black ) ) };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::selectionPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{ caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::magenta ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::cyan ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::blue ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::red ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::green ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::yellow ) ),
|
||||
caf::ColorTable::fromQColor( Qt::GlobalColor( Qt::gray ) ) };
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::timestepsPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 56, 56, 255 ), // Vivid Blue
|
||||
cvf::Color3ub( 0, 143, 239 ), // Dark Light Blue
|
||||
cvf::Color3ub( 0, 112, 136 ), // Dark Green-Blue
|
||||
cvf::Color3ub( 51, 204, 255 ), // Bluer Turquoise
|
||||
cvf::Color3ub( 0, 221, 221 ), // Turquoise
|
||||
cvf::Color3ub( 0, 205, 68 ), // Bluish Green
|
||||
cvf::Color3ub( 78, 204, 0 ), // Clear Green
|
||||
cvf::Color3ub( 164, 193, 0 ), // Mid Yellowish Green
|
||||
cvf::Color3ub( 236, 188, 0 ), // Mid Yellow
|
||||
cvf::Color3ub( 236, 118, 0 ), // Orange
|
||||
cvf::Color3ub( 202, 0, 0 ), // Red
|
||||
cvf::Color3ub( 248, 0, 170 ), // Magenta
|
||||
cvf::Color3ub( 201, 168, 206 ), // Light Violet
|
||||
cvf::Color3ub( 169, 2, 240 ), // Purple
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::editableWellPathsPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 201, 145, 201 ), // Gray pink
|
||||
cvf::Color3ub( 173, 23, 212 ), // Strong Purple
|
||||
cvf::Color3ub( 143, 46, 219 ), // Purple
|
||||
cvf::Color3ub( 102, 76, 230 ), // Gray Blue
|
||||
cvf::Color3ub( 71, 99, 237 ), // Lighter Gray Blue
|
||||
cvf::Color3ub( 31, 130, 247 ), // Strong Blue
|
||||
cvf::Color3ub( 0, 153, 255 ), // Dark Turquise
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::wellPathsPaletteColors()
|
||||
{
|
||||
// Use inverted category colors to avoid identical colors if we have few sim wells and few well paths
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( invertedCategoryColors() );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::waterAndRockPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 127, 205, 255 ), // Sea Blue
|
||||
cvf::Color3ub( 100, 100, 100 ) // Gray
|
||||
};
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::ColorTable& RiaColorTables::correlationPaletteColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 255, 25, 50 ), // Bluish red
|
||||
cvf::Color3ub( 240, 240, 240 ), // Light Gray
|
||||
cvf::Color3ub( 255, 100, 50 ), // Dark red Orange
|
||||
};
|
||||
|
||||
static caf::ColorTable colorTable = caf::ColorTable( colors );
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTables::undefinedCellColor()
|
||||
{
|
||||
return cvf::Color3::GRAY;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaColorTables::WellPathComponentColors RiaColorTables::wellPathComponentColors()
|
||||
{
|
||||
return { { RiaDefines::WellPathComponentType::WELL_PATH, cvf::Color3::CEETRON },
|
||||
{ RiaDefines::WellPathComponentType::PERFORATION_INTERVAL, cvf::Color3::DARK_MAGENTA },
|
||||
{ RiaDefines::WellPathComponentType::FISHBONES, cvf::Color3::DARK_GREEN },
|
||||
{ RiaDefines::WellPathComponentType::FRACTURE, cvf::Color3::CRIMSON },
|
||||
{ RiaDefines::WellPathComponentType::ICD, cvf::Color3::DARK_ORANGE },
|
||||
{ RiaDefines::WellPathComponentType::AICD, cvf::Color3::INDIGO },
|
||||
{ RiaDefines::WellPathComponentType::ICV, cvf::Color3::ORCHID },
|
||||
{ RiaDefines::WellPathComponentType::CASING, cvf::Color3::SEA_GREEN },
|
||||
{ RiaDefines::WellPathComponentType::LINER, cvf::Color3::OLIVE },
|
||||
{ RiaDefines::WellPathComponentType::PACKER, cvf::Color3::GRAY },
|
||||
{ RiaDefines::WellPathComponentType::UNDEFINED_COMPONENT, cvf::Color3::MAGENTA } };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTables::defaultGridLineColor()
|
||||
{
|
||||
return cvf::Color3f( 0.92f, 0.92f, 0.92f );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTables::defaultFaultLineColor()
|
||||
{
|
||||
return cvf::Color3f( 0.08f, 0.08f, 0.08f );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTables::defaultWellLabelColor()
|
||||
{
|
||||
return cvf::Color3f( 0.92f, 0.92f, 0.92f );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTables::defaultViewerBackgroundColor()
|
||||
{
|
||||
return cvf::Color3f( 0.69f, 0.77f, 0.87f );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::ColorTable RiaColorTables::createBrightnessBasedColorTable( cvf::Color3ub baseColor, int brightnessLevelCount )
|
||||
{
|
||||
CVF_ASSERT( brightnessLevelCount >= 1 );
|
||||
QColor baseRGB( baseColor.r(), baseColor.g(), baseColor.b() );
|
||||
float hueF = baseRGB.hslHueF();
|
||||
float satF = baseRGB.hslSaturationF();
|
||||
|
||||
std::vector<cvf::Color3ub> colors;
|
||||
if ( brightnessLevelCount == 1 )
|
||||
{
|
||||
colors.push_back( cvf::Color3ub( RiaColorTools::fromQColorTo3f( QColor::fromHslF( hueF, satF, 0.5 ) ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int i = 0; i < brightnessLevelCount; ++i )
|
||||
{
|
||||
float brightness = static_cast<float>( i ) / static_cast<float>( brightnessLevelCount - 1 );
|
||||
colors.push_back( cvf::Color3ub( RiaColorTools::fromQColorTo3f( QColor::fromHslF( hueF, satF, brightness ) ) ) );
|
||||
}
|
||||
}
|
||||
return caf::ColorTable( colors );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<RiaDefines::PhaseType, caf::ColorTable> RiaColorTables::phaseColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> waterColors{ cvf::Color3ub( cvf::Color3::DARK_BLUE ),
|
||||
cvf::Color3ub( cvf::Color3::SKY_BLUE ) };
|
||||
static std::vector<cvf::Color3ub> gasColors{ cvf::Color3ub( cvf::Color3::DARK_RED ),
|
||||
cvf::Color3ub( cvf::Color3::PINK ) };
|
||||
static std::vector<cvf::Color3ub> oilColors{ cvf::Color3ub( cvf::Color3::DARK_GREEN ),
|
||||
cvf::Color3ub( cvf::Color3::YELLOW_GREEN ) };
|
||||
|
||||
return { { RiaDefines::PhaseType::WATER_PHASE, caf::ColorTable( waterColors ) },
|
||||
{ RiaDefines::PhaseType::GAS_PHASE, caf::ColorTable( gasColors ) },
|
||||
{ RiaDefines::PhaseType::OIL_PHASE, caf::ColorTable( oilColors ) } };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<cvf::Color3ub> RiaColorTables::categoryColors()
|
||||
{
|
||||
// Based on http://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors
|
||||
// and Kelly Colors and sorted by hue
|
||||
// See also http://www.w3schools.com/colors/ for palettes etc.
|
||||
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 128, 62, 117 ), // hwb(310, 24%, 50%) strong_purple
|
||||
cvf::Color3ub( 212, 28, 132 ), // hwb(326, 11%, 17%) strong_purplish_red
|
||||
cvf::Color3ub( 246, 118, 142 ), // hwb(349, 46%, 4%) strong_purplish_pink
|
||||
cvf::Color3ub( 193, 0, 32 ), // hwb(350, 0%, 24%) vivid_red
|
||||
cvf::Color3ub( 127, 24, 13 ), // hwb( 6, 5%, 50%) strong_reddish_brown
|
||||
cvf::Color3ub( 241, 58, 19 ), // hwb( 11, 7%, 5%) vivid_reddish_orange
|
||||
cvf::Color3ub( 255, 122, 92 ), // hwb( 11, 36%, 0%) strong_yellowish_pink
|
||||
cvf::Color3ub( 129, 112, 102 ), // hwb( 22, 40%, 49%) medium_gray
|
||||
cvf::Color3ub( 255, 104, 0 ), // hwb( 24, 0%, 0%) vivid_orange
|
||||
cvf::Color3ub( 89, 51, 21 ), // hwb( 26, 8%, 65%) deep_yellowish_brown
|
||||
cvf::Color3ub( 255, 142, 0 ), // hwb( 33, 0%, 0%) vivid_orange_yellow
|
||||
cvf::Color3ub( 206, 162, 98 ), // hwb( 36, 38%, 19%) grayish_yellow
|
||||
cvf::Color3ub( 244, 200, 0 ), // hwb( 49, 0%, 4%) vivid_greenish_yellow
|
||||
cvf::Color3ub( 147, 170, 0 ), // hwb( 68, 0%, 33%) vivid_yellowish_green
|
||||
cvf::Color3ub( 59, 84, 23 ), // hwb( 85, 9%, 67%) dark_olive_green
|
||||
cvf::Color3ub( 0, 125, 52 ), // hwb(145, 0%, 51%) vivid_green
|
||||
cvf::Color3ub( 54, 125, 123 ), // hwb(178, 21%, 51%) vivid_blueish_green
|
||||
cvf::Color3ub( 0, 83, 138 ), // hwb(204, 0%, 46%) strong_blue
|
||||
cvf::Color3ub( 166, 189, 215 ), // hwb(212, 65%, 16%) very_light_blue
|
||||
cvf::Color3ub( 46, 76, 224 ) // hwb(230, 18%, 12%) medium_blue
|
||||
};
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<cvf::Color3ub> RiaColorTables::contrastCategoryColors()
|
||||
{
|
||||
// Based on http://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors
|
||||
// and Kelly Colors and sorted by hue
|
||||
// See also http://www.w3schools.com/colors/ for palettes etc.
|
||||
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 244, 200, 0 ), // hwb( 49, 0%, 4%) vivid_greenish_yellow
|
||||
cvf::Color3ub( 128, 62, 117 ), // hwb(310, 24%, 50%) strong_purple
|
||||
cvf::Color3ub( 255, 104, 0 ), // hwb( 24, 0%, 0%) vivid_orange
|
||||
cvf::Color3ub( 166, 189, 215 ), // hwb(212, 65%, 16%) very_light_blue
|
||||
cvf::Color3ub( 193, 0, 32 ), // hwb(350, 0%, 24%) vivid_red
|
||||
cvf::Color3ub( 206, 162, 98 ), // hwb( 36, 38%, 19%) grayish_yellow
|
||||
cvf::Color3ub( 129, 112, 102 ), // hwb( 22, 40%, 49%) medium_gray
|
||||
cvf::Color3ub( 0, 125, 52 ), // hwb(145, 0%, 51%) vivid_green
|
||||
cvf::Color3ub( 246, 118, 142 ), // hwb(349, 46%, 4%) strong_purplish_pink
|
||||
cvf::Color3ub( 0, 83, 138 ), // hwb(204, 0%, 46%) strong_blue
|
||||
cvf::Color3ub( 255, 122, 92 ), // hwb( 11, 36%, 0%) strong_yellowish_pink
|
||||
cvf::Color3ub( 212, 28, 132 ), // hwb(326, 11%, 17%) strong_purplish_red
|
||||
cvf::Color3ub( 255, 142, 0 ), // hwb( 33, 0%, 0%) vivid_orange_yellow
|
||||
cvf::Color3ub( 59, 84, 23 ), // hwb( 85, 9%, 67%) dark_olive_green
|
||||
cvf::Color3ub( 127, 24, 13 ), // hwb( 6, 5%, 50%) strong_reddish_brown
|
||||
cvf::Color3ub( 54, 125, 123 ), // hwb(178, 21%, 51%) vivid_blueish_green
|
||||
cvf::Color3ub( 241, 58, 19 ), // hwb( 11, 7%, 5%) vivid_reddish_orange
|
||||
cvf::Color3ub( 147, 170, 0 ), // hwb( 68, 0%, 33%) vivid_yellowish_green
|
||||
cvf::Color3ub( 46, 76, 224 ), // hwb(230, 18%, 12%) medium_blue
|
||||
cvf::Color3ub( 89, 51, 21 ), // hwb( 26, 8%, 65%) deep_yellowish_brown
|
||||
cvf::Color3ub( 0, 0, 0 ) // hwb(0, 0%, 100%) black
|
||||
};
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<cvf::Color3ub> RiaColorTables::invertedCategoryColors()
|
||||
{
|
||||
static std::vector<cvf::Color3ub> colors{
|
||||
cvf::Color3ub( 46, 76, 224 ), // hwb(230, 18%, 12%) medium_blue
|
||||
cvf::Color3ub( 166, 189, 215 ), // hwb(212, 65%, 16%) very_light_blue
|
||||
cvf::Color3ub( 0, 83, 138 ), // hwb(204, 0%, 46%) strong_blue
|
||||
cvf::Color3ub( 54, 125, 123 ), // hwb(178, 21%, 51%) vivid_blueish_green
|
||||
cvf::Color3ub( 0, 125, 52 ), // hwb(145, 0%, 51%) vivid_green
|
||||
cvf::Color3ub( 59, 84, 23 ), // hwb( 85, 9%, 67%) dark_olive_green
|
||||
cvf::Color3ub( 147, 170, 0 ), // hwb( 68, 0%, 33%) vivid_yellowish_green
|
||||
cvf::Color3ub( 244, 200, 0 ), // hwb( 49, 0%, 4%) vivid_greenish_yellow
|
||||
cvf::Color3ub( 206, 162, 98 ), // hwb( 36, 38%, 19%) grayish_yellow
|
||||
cvf::Color3ub( 255, 142, 0 ), // hwb( 33, 0%, 0%) vivid_orange_yellow
|
||||
cvf::Color3ub( 89, 51, 21 ), // hwb( 26, 8%, 65%) deep_yellowish_brown
|
||||
cvf::Color3ub( 255, 104, 0 ), // hwb( 24, 0%, 0%) vivid_orange
|
||||
cvf::Color3ub( 129, 112, 102 ), // hwb( 22, 40%, 49%) medium_gray
|
||||
cvf::Color3ub( 255, 122, 92 ), // hwb( 11, 36%, 0%) strong_yellowish_pink
|
||||
cvf::Color3ub( 241, 58, 19 ), // hwb( 11, 7%, 5%) vivid_reddish_orange
|
||||
cvf::Color3ub( 127, 24, 13 ), // hwb( 6, 5%, 50%) strong_reddish_brown
|
||||
cvf::Color3ub( 193, 0, 32 ), // hwb(350, 0%, 24%) vivid_red
|
||||
cvf::Color3ub( 246, 118, 142 ), // hwb(349, 46%, 4%) strong_purplish_pink
|
||||
cvf::Color3ub( 212, 28, 132 ), // hwb(326, 11%, 17%) strong_purplish_red
|
||||
cvf::Color3ub( 128, 62, 117 ) // hwb(310, 24%, 50%) strong_purple
|
||||
};
|
||||
|
||||
return colors;
|
||||
}
|
||||
84
ApplicationLibCode/Application/Tools/RiaColorTables.h
Normal file
84
ApplicationLibCode/Application/Tools/RiaColorTables.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiaDefines.h"
|
||||
#include "cafColorTable.h"
|
||||
#include <map>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaColorTables
|
||||
{
|
||||
public:
|
||||
typedef std::map<RiaDefines::WellPathComponentType, cvf::Color3::ColorIdent> WellPathComponentColors;
|
||||
|
||||
static const caf::ColorTable& normalPaletteColors();
|
||||
static const caf::ColorTable& normalPaletteOppositeOrderingColors();
|
||||
static const caf::ColorTable& blackWhitePaletteColors();
|
||||
static const caf::ColorTable& whiteBlackPaletteColors();
|
||||
static const caf::ColorTable& pinkWhitePaletteColors();
|
||||
static const caf::ColorTable& whitePinkPaletteColors();
|
||||
static const caf::ColorTable& blueWhiteRedPaletteColors();
|
||||
static const caf::ColorTable& redWhiteBluePaletteColors();
|
||||
static const caf::ColorTable& categoryPaletteColors();
|
||||
static const caf::ColorTable& contrastCategoryPaletteColors();
|
||||
static const caf::ColorTable& tensorWhiteGrayBlackPaletteColors();
|
||||
static const caf::ColorTable& tensorOrangeBlueWhitePaletteColors();
|
||||
static const caf::ColorTable& tensorsMagentaBrownGrayPaletteColors();
|
||||
static const caf::ColorTable& angularPaletteColors();
|
||||
static const caf::ColorTable& rainbowPaletteColors();
|
||||
static const caf::ColorTable& stimPlanPaletteColors();
|
||||
static const caf::ColorTable& faultsPaletteColors();
|
||||
static const caf::ColorTable& wellsPaletteColors();
|
||||
static const caf::ColorTable& summaryCurveDefaultPaletteColors();
|
||||
static const caf::ColorTable& summaryCurveRedPaletteColors();
|
||||
static const caf::ColorTable& summaryCurveGreenPaletteColors();
|
||||
static const caf::ColorTable& summaryCurveBluePaletteColors();
|
||||
static const caf::ColorTable& summaryCurveBrownPaletteColors();
|
||||
static const caf::ColorTable& summaryCurveNoneRedGreenBlueBrownPaletteColors();
|
||||
static const caf::ColorTable& wellLogPlotPaletteColors();
|
||||
static const caf::ColorTable& selectionPaletteColors();
|
||||
static const caf::ColorTable& timestepsPaletteColors();
|
||||
static const caf::ColorTable& editableWellPathsPaletteColors();
|
||||
static const caf::ColorTable& wellPathsPaletteColors();
|
||||
static const caf::ColorTable& waterAndRockPaletteColors();
|
||||
static const caf::ColorTable& correlationPaletteColors();
|
||||
|
||||
static cvf::Color3f undefinedCellColor();
|
||||
|
||||
static WellPathComponentColors wellPathComponentColors();
|
||||
|
||||
// Default 3d View colors
|
||||
static cvf::Color3f defaultGridLineColor();
|
||||
static cvf::Color3f defaultFaultLineColor();
|
||||
static cvf::Color3f defaultWellLabelColor();
|
||||
static cvf::Color3f defaultViewerBackgroundColor();
|
||||
|
||||
static caf::ColorTable createBrightnessBasedColorTable( cvf::Color3ub baseColor, int brightnessLevelCount );
|
||||
|
||||
static std::map<RiaDefines::PhaseType, caf::ColorTable> phaseColors();
|
||||
|
||||
private:
|
||||
static std::vector<cvf::Color3ub> categoryColors();
|
||||
static std::vector<cvf::Color3ub> contrastCategoryColors();
|
||||
static std::vector<cvf::Color3ub> invertedCategoryColors();
|
||||
};
|
||||
209
ApplicationLibCode/Application/Tools/RiaColorTools.cpp
Normal file
209
ApplicationLibCode/Application/Tools/RiaColorTools.cpp
Normal file
@@ -0,0 +1,209 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- Equinor ASA
|
||||
// Copyright (C) 2017 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 "RiaColorTools.h"
|
||||
#include "RiuGuiTheme.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include <QPalette>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Uses W3.org relative luminance calculation taking into account the different luminance of the different colors
|
||||
/// https://www.w3.org/TR/WCAG20-TECHS/G18.html
|
||||
/// Luminance is between [0, 1] so anything above 0.5 is considered in the bright half of the spectrum.
|
||||
/// However, subjectively the contrast looks better if the threshold is to 0.4 so black contrast is used a bit more
|
||||
/// often.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaColorTools::isBrightnessAboveThreshold( cvf::Color3f backgroundColor )
|
||||
{
|
||||
if ( relativeLuminance( backgroundColor ) > 0.4 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTools::computeOffsetColor( cvf::Color3f color, float offsetFactor )
|
||||
{
|
||||
float gridR = 0.0;
|
||||
float gridG = 0.0;
|
||||
float gridB = 0.0;
|
||||
|
||||
if ( isBrightnessAboveThreshold( color ) )
|
||||
{
|
||||
gridR = color.r() - ( color.r() * offsetFactor );
|
||||
gridG = color.g() - ( color.g() * offsetFactor );
|
||||
gridB = color.b() - ( color.b() * offsetFactor );
|
||||
}
|
||||
else
|
||||
{
|
||||
gridR = color.r() + ( 1.0f - color.r() ) * offsetFactor;
|
||||
gridG = color.g() + ( 1.0f - color.g() ) * offsetFactor;
|
||||
gridB = color.b() + ( 1.0f - color.b() ) * offsetFactor;
|
||||
}
|
||||
|
||||
return cvf::Color3f( cvf::Math::clamp( gridR, 0.0f, 1.0f ),
|
||||
cvf::Math::clamp( gridG, 0.0f, 1.0f ),
|
||||
cvf::Math::clamp( gridB, 0.0f, 1.0f ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTools::darkContrastColor()
|
||||
{
|
||||
return cvf::Color3f::fromByteColor( 10, 10, 10 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTools::brightContrastColor()
|
||||
{
|
||||
return cvf::Color3f::WHITE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTools::darkContrastColorSofter()
|
||||
{
|
||||
return cvf::Color3f::fromByteColor( 30, 30, 30 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTools::brightContrastColorSofter()
|
||||
{
|
||||
return cvf::Color3f::fromByteColor( 200, 200, 200 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTools::contrastColor( cvf::Color3f backgroundColor, bool softerContrast )
|
||||
{
|
||||
if ( isBrightnessAboveThreshold( backgroundColor ) )
|
||||
{
|
||||
if ( softerContrast ) return darkContrastColorSofter();
|
||||
return darkContrastColor();
|
||||
}
|
||||
if ( softerContrast ) return brightContrastColorSofter();
|
||||
return brightContrastColor();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QColor RiaColorTools::toQColor( cvf::Color3f color, float alpha )
|
||||
{
|
||||
QColor qcolor( color.rByte(), color.gByte(), color.bByte() );
|
||||
qcolor.setAlphaF( alpha );
|
||||
return qcolor;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QColor RiaColorTools::toQColor( cvf::Color4f color )
|
||||
{
|
||||
return toQColor( color.toColor3f(), color.a() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTools::fromQColorTo3f( QColor color )
|
||||
{
|
||||
return cvf::Color3f( color.redF(), color.greenF(), color.blueF() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QColor RiaColorTools::textColor()
|
||||
{
|
||||
return RiuGuiTheme::getColorByVariableName( "textColor" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTools::textColor3f()
|
||||
{
|
||||
return fromQColorTo3f( textColor() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTools::blendCvfColors( const cvf::Color3f& color1,
|
||||
const cvf::Color3f& color2,
|
||||
int weight1 /*= 1*/,
|
||||
int weight2 /*= 1*/ )
|
||||
{
|
||||
CVF_ASSERT( weight1 > 0 && weight2 > 0 );
|
||||
int weightsum = weight1 + weight2;
|
||||
return cvf::Color3f( ( color1.r() * weight1 + color2.r() * weight2 ) / weightsum,
|
||||
( color1.g() * weight1 + color2.g() * weight2 ) / weightsum,
|
||||
( color1.b() * weight1 + color2.b() * weight2 ) / weightsum );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QColor RiaColorTools::blendQColors( const QColor& color1, const QColor& color2, int weight1 /*= 1*/, int weight2 /*= 1*/ )
|
||||
{
|
||||
CVF_ASSERT( weight1 > 0 && weight2 > 0 );
|
||||
int weightsum = weight1 + weight2;
|
||||
return QColor( ( color1.red() * weight1 + color2.red() * weight2 ) / weightsum,
|
||||
( color1.green() * weight1 + color2.green() * weight2 ) / weightsum,
|
||||
( color1.blue() * weight1 + color2.blue() * weight2 ) / weightsum );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
float RiaColorTools::relativeLuminance( cvf::Color3f backgroundColor )
|
||||
{
|
||||
float R = calculateNonLinearColorValue( backgroundColor.r() );
|
||||
float G = calculateNonLinearColorValue( backgroundColor.g() );
|
||||
float B = calculateNonLinearColorValue( backgroundColor.b() );
|
||||
|
||||
double luminance = 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
||||
return luminance;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
float RiaColorTools::calculateNonLinearColorValue( float colorFraction )
|
||||
{
|
||||
return colorFraction <= 0.03928 ? colorFraction / 12.92 : std::pow( ( colorFraction + 0.055 ) / 1.055, 2.4 );
|
||||
}
|
||||
55
ApplicationLibCode/Application/Tools/RiaColorTools.h
Normal file
55
ApplicationLibCode/Application/Tools/RiaColorTools.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- Equinor ASA
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfArray.h"
|
||||
|
||||
#include <QColor>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaColorTools
|
||||
{
|
||||
public:
|
||||
static bool isBrightnessAboveThreshold( cvf::Color3f backgroundColor );
|
||||
|
||||
static cvf::Color3f computeOffsetColor( cvf::Color3f color, float offsetFactor );
|
||||
static cvf::Color3f darkContrastColor();
|
||||
static cvf::Color3f brightContrastColor();
|
||||
static cvf::Color3f darkContrastColorSofter();
|
||||
static cvf::Color3f brightContrastColorSofter();
|
||||
static cvf::Color3f contrastColor( cvf::Color3f backgroundColor, bool softerContrast = false );
|
||||
static QColor toQColor( cvf::Color3f color, float alpha = 1.0f );
|
||||
static QColor toQColor( cvf::Color4f color );
|
||||
static cvf::Color3f fromQColorTo3f( QColor );
|
||||
|
||||
static QColor textColor();
|
||||
static cvf::Color3f textColor3f();
|
||||
|
||||
static cvf::Color3f
|
||||
blendCvfColors( const cvf::Color3f& color1, const cvf::Color3f& color2, int weight1 = 1, int weight2 = 1 );
|
||||
static QColor blendQColors( const QColor& color1, const QColor& color2, int weight1 = 1, int weight2 = 1 );
|
||||
|
||||
private:
|
||||
static float relativeLuminance( cvf::Color3f backgroundColor );
|
||||
static float calculateNonLinearColorValue( float colorFraction );
|
||||
};
|
||||
103
ApplicationLibCode/Application/Tools/RiaCurveDataTools.cpp
Normal file
103
ApplicationLibCode/Application/Tools/RiaCurveDataTools.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2015- Statoil ASA
|
||||
// Copyright (C) 2015- Ceetron Solutions AS
|
||||
//
|
||||
// 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 "RiaCurveDataTools.h"
|
||||
|
||||
#include <cmath> // Needed for HUGE_VAL on Linux
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaCurveDataTools::CurveIntervals RiaCurveDataTools::calculateIntervalsOfValidValues( const std::vector<double>& values,
|
||||
bool includePositiveValuesOnly )
|
||||
{
|
||||
CurveIntervals intervals;
|
||||
|
||||
int startIdx = -1;
|
||||
size_t vIdx = 0;
|
||||
|
||||
size_t valueCount = values.size();
|
||||
while ( vIdx < valueCount )
|
||||
{
|
||||
bool isValid = RiaCurveDataTools::isValidValue( values[vIdx], includePositiveValuesOnly );
|
||||
|
||||
if ( !isValid )
|
||||
{
|
||||
if ( startIdx >= 0 )
|
||||
{
|
||||
size_t endIdx = vIdx - 1;
|
||||
intervals.push_back( std::make_pair( startIdx, endIdx ) );
|
||||
startIdx = -1;
|
||||
}
|
||||
}
|
||||
else if ( startIdx < 0 )
|
||||
{
|
||||
startIdx = (int)vIdx;
|
||||
}
|
||||
|
||||
vIdx++;
|
||||
}
|
||||
|
||||
if ( startIdx >= 0 && startIdx < ( (int)valueCount ) )
|
||||
{
|
||||
intervals.push_back( std::make_pair( startIdx, valueCount - 1 ) );
|
||||
}
|
||||
|
||||
return intervals;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<std::pair<size_t, size_t>> RiaCurveDataTools::computePolyLineStartStopIndices( const CurveIntervals& intervals )
|
||||
{
|
||||
std::vector<std::pair<size_t, size_t>> lineStartAndStopIndices;
|
||||
|
||||
const size_t intervalCount = intervals.size();
|
||||
if ( intervalCount < 1 ) return lineStartAndStopIndices;
|
||||
|
||||
size_t index = 0;
|
||||
for ( size_t intIdx = 0; intIdx < intervalCount; intIdx++ )
|
||||
{
|
||||
size_t intervalSize = intervals[intIdx].second - intervals[intIdx].first + 1;
|
||||
lineStartAndStopIndices.push_back( std::make_pair( index, index + intervalSize - 1 ) );
|
||||
|
||||
index += intervalSize;
|
||||
}
|
||||
|
||||
return lineStartAndStopIndices;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaCurveDataTools::isValidValue( double value, bool allowPositiveValuesOnly )
|
||||
{
|
||||
if ( value == HUGE_VAL || value == -HUGE_VAL || value != value )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( allowPositiveValuesOnly && value <= 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
68
ApplicationLibCode/Application/Tools/RiaCurveDataTools.h
Normal file
68
ApplicationLibCode/Application/Tools/RiaCurveDataTools.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2015- Statoil ASA
|
||||
// Copyright (C) 2015- Ceetron Solutions AS
|
||||
//
|
||||
// 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 "cvfAssert.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class QDateTime;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaCurveDataTools
|
||||
{
|
||||
public:
|
||||
typedef std::vector<std::pair<size_t, size_t>> CurveIntervals;
|
||||
|
||||
enum class ErrorAxis
|
||||
{
|
||||
ERROR_ALONG_X_AXIS,
|
||||
ERROR_ALONG_Y_AXIS
|
||||
};
|
||||
|
||||
public:
|
||||
static CurveIntervals calculateIntervalsOfValidValues( const std::vector<double>& values,
|
||||
bool includePositiveValuesOnly );
|
||||
|
||||
template <typename T>
|
||||
static void
|
||||
getValuesByIntervals( const std::vector<T>& values, const CurveIntervals& intervals, std::vector<T>* filteredValues )
|
||||
{
|
||||
CVF_ASSERT( filteredValues );
|
||||
|
||||
for ( size_t intIdx = 0; intIdx < intervals.size(); intIdx++ )
|
||||
{
|
||||
for ( size_t vIdx = intervals[intIdx].first; vIdx <= intervals[intIdx].second; vIdx++ )
|
||||
{
|
||||
filteredValues->push_back( values[vIdx] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static std::vector<std::pair<size_t, size_t>> computePolyLineStartStopIndices( const CurveIntervals& intervals );
|
||||
|
||||
public:
|
||||
static bool isValidValue( double value, bool allowPositiveValuesOnly );
|
||||
};
|
||||
20
ApplicationLibCode/Application/Tools/RiaCurveMerger.cpp
Normal file
20
ApplicationLibCode/Application/Tools/RiaCurveMerger.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "RiaCurveMerger.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <time.h>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <>
|
||||
bool XValueComparator<double>::equals( const double& lhs, const double& rhs )
|
||||
{
|
||||
double eps = 1.0e-12 * std::max( std::fabs( lhs ), std::fabs( rhs ) );
|
||||
return std::fabs( lhs - rhs ) < eps;
|
||||
}
|
||||
|
||||
template <>
|
||||
double XValueComparator<time_t>::diff( const time_t& lhs, const time_t& rhs )
|
||||
{
|
||||
return difftime( lhs, rhs );
|
||||
}
|
||||
86
ApplicationLibCode/Application/Tools/RiaCurveMerger.h
Normal file
86
ApplicationLibCode/Application/Tools/RiaCurveMerger.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiaCurveDataTools.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
template <typename XValueType>
|
||||
class XValueComparator
|
||||
{
|
||||
public:
|
||||
bool operator()( const XValueType& lhs, const XValueType& rhs ) const;
|
||||
static bool equals( const XValueType& lhs, const XValueType& rhs );
|
||||
static double diff( const XValueType& lhs, const XValueType& rhs );
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
template <typename XValueType>
|
||||
class RiaCurveMerger
|
||||
{
|
||||
public:
|
||||
typedef XValueComparator<XValueType> XComparator;
|
||||
RiaCurveMerger();
|
||||
|
||||
void addCurveData( const std::vector<XValueType>& xValues, const std::vector<double>& yValues );
|
||||
size_t curveCount() const;
|
||||
|
||||
void computeInterpolatedValues( bool includeValuesFromPartialCurves = true );
|
||||
|
||||
RiaCurveDataTools::CurveIntervals validIntervalsForAllXValues() const;
|
||||
const std::vector<XValueType>& allXValues() const;
|
||||
const std::vector<double>& interpolatedYValuesForAllXValues( size_t curveIdx ) const;
|
||||
|
||||
// Non-const access is not required by any clients, but the expression parser has no available const interface
|
||||
// for specifying a data source for an expression variable. Allow non-const access to avoid copy of the contained
|
||||
// values, interpolated for all time steps
|
||||
//
|
||||
// See ExpressionParserImpl::assignVector()
|
||||
std::vector<double>& interpolatedYValuesForAllXValues( size_t curveIdx );
|
||||
|
||||
public:
|
||||
// Helper methods, available as public to be able to access from unit tests
|
||||
|
||||
static double interpolatedYValue( const XValueType& xValue,
|
||||
const std::vector<XValueType>& curveXValues,
|
||||
const std::vector<double>& curveYValues );
|
||||
|
||||
private:
|
||||
void computeUnionOfXValues( bool includeValuesFromPartialCurves );
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::vector<XValueType>, std::vector<double>>> m_originalValues;
|
||||
|
||||
RiaCurveDataTools::CurveIntervals m_validIntervalsForAllXValues;
|
||||
|
||||
std::vector<XValueType> m_allXValues;
|
||||
std::vector<std::vector<double>> m_interpolatedValuesForAllCurves;
|
||||
};
|
||||
|
||||
typedef RiaCurveMerger<time_t> RiaTimeHistoryCurveMerger;
|
||||
|
||||
template <>
|
||||
bool XValueComparator<double>::equals( const double& lhs, const double& rhs );
|
||||
template <>
|
||||
double XValueComparator<time_t>::diff( const time_t& lhs, const time_t& rhs );
|
||||
|
||||
#include "RiaCurveMerger.inl"
|
||||
291
ApplicationLibCode/Application/Tools/RiaCurveMerger.inl
Normal file
291
ApplicationLibCode/Application/Tools/RiaCurveMerger.inl
Normal file
@@ -0,0 +1,291 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 <algorithm>
|
||||
#include <cmath> // Needed for HUGE_VAL on Linux
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
bool XValueComparator<XValueType>::operator()( const XValueType& lhs, const XValueType& rhs ) const
|
||||
{
|
||||
if ( XValueComparator<XValueType>::equals( lhs, rhs ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return lhs < rhs;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
double XValueComparator<XValueType>::diff( const XValueType& lhs, const XValueType& rhs )
|
||||
{
|
||||
return lhs - rhs;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
bool XValueComparator<XValueType>::equals( const XValueType& lhs, const XValueType& rhs )
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
RiaCurveMerger<XValueType>::RiaCurveMerger()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
void RiaCurveMerger<XValueType>::addCurveData( const std::vector<XValueType>& xValues, const std::vector<double>& yValues )
|
||||
{
|
||||
CVF_ASSERT( xValues.size() == yValues.size() );
|
||||
|
||||
if ( !xValues.empty() )
|
||||
{
|
||||
m_originalValues.push_back( std::make_pair( xValues, yValues ) );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
size_t RiaCurveMerger<XValueType>::curveCount() const
|
||||
{
|
||||
return m_interpolatedValuesForAllCurves.size();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
RiaCurveDataTools::CurveIntervals RiaCurveMerger<XValueType>::validIntervalsForAllXValues() const
|
||||
{
|
||||
return m_validIntervalsForAllXValues;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
const std::vector<XValueType>& RiaCurveMerger<XValueType>::allXValues() const
|
||||
{
|
||||
return m_allXValues;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
const std::vector<double>& RiaCurveMerger<XValueType>::interpolatedYValuesForAllXValues( size_t curveIdx ) const
|
||||
{
|
||||
CVF_ASSERT( curveIdx < m_interpolatedValuesForAllCurves.size() );
|
||||
|
||||
return m_interpolatedValuesForAllCurves[curveIdx];
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
std::vector<double>& RiaCurveMerger<XValueType>::interpolatedYValuesForAllXValues( size_t curveIdx )
|
||||
{
|
||||
CVF_ASSERT( curveIdx < m_interpolatedValuesForAllCurves.size() );
|
||||
|
||||
return m_interpolatedValuesForAllCurves[curveIdx];
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
void RiaCurveMerger<XValueType>::computeInterpolatedValues( bool includeValuesFromPartialCurves )
|
||||
{
|
||||
m_validIntervalsForAllXValues.clear();
|
||||
m_allXValues.clear();
|
||||
m_interpolatedValuesForAllCurves.clear();
|
||||
|
||||
computeUnionOfXValues( includeValuesFromPartialCurves );
|
||||
|
||||
const size_t curveCount = m_originalValues.size();
|
||||
if ( curveCount == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t dataValueCount = m_allXValues.size();
|
||||
if ( dataValueCount == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_interpolatedValuesForAllCurves.resize( curveCount );
|
||||
|
||||
std::vector<double> accumulatedValidValues( dataValueCount, 1.0 );
|
||||
|
||||
for ( size_t curveIdx = 0; curveIdx < curveCount; curveIdx++ )
|
||||
{
|
||||
std::vector<double>& curveValues = m_interpolatedValuesForAllCurves[curveIdx];
|
||||
curveValues.resize( dataValueCount );
|
||||
|
||||
for ( size_t valueIndex = 0; valueIndex < dataValueCount; valueIndex++ )
|
||||
{
|
||||
double interpolValue = interpolatedYValue( m_allXValues[valueIndex],
|
||||
m_originalValues[curveIdx].first,
|
||||
m_originalValues[curveIdx].second );
|
||||
if ( !RiaCurveDataTools::isValidValue( interpolValue, false ) )
|
||||
{
|
||||
accumulatedValidValues[valueIndex] = HUGE_VAL;
|
||||
}
|
||||
|
||||
curveValues[valueIndex] = interpolValue;
|
||||
}
|
||||
}
|
||||
|
||||
m_validIntervalsForAllXValues = RiaCurveDataTools::calculateIntervalsOfValidValues( accumulatedValidValues, false );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
void RiaCurveMerger<XValueType>::computeUnionOfXValues( bool includeValuesForPartialCurves )
|
||||
{
|
||||
m_allXValues.clear();
|
||||
|
||||
std::set<XValueType, XComparator> unionOfXValues;
|
||||
|
||||
std::vector<std::pair<XValueType, XValueType>> originalXBounds;
|
||||
for ( const auto& curveData : m_originalValues )
|
||||
{
|
||||
if ( curveData.first.empty() ) continue;
|
||||
|
||||
for ( const auto& x : curveData.first )
|
||||
{
|
||||
unionOfXValues.insert( x );
|
||||
}
|
||||
auto minmax_it = std::minmax_element( curveData.first.begin(), curveData.first.end() );
|
||||
originalXBounds.push_back( std::make_pair( *( minmax_it.first ), *( minmax_it.second ) ) );
|
||||
}
|
||||
|
||||
if ( !includeValuesForPartialCurves )
|
||||
{
|
||||
for ( auto it = unionOfXValues.begin(); it != unionOfXValues.end(); )
|
||||
{
|
||||
bool outsideBounds = false;
|
||||
for ( const auto& curveXBounds : originalXBounds )
|
||||
{
|
||||
if ( *it < curveXBounds.first || *it > curveXBounds.second )
|
||||
{
|
||||
outsideBounds = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( outsideBounds )
|
||||
{
|
||||
it = unionOfXValues.erase( it );
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_allXValues = std::vector<XValueType>( unionOfXValues.begin(), unionOfXValues.end() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename XValueType>
|
||||
double RiaCurveMerger<XValueType>::interpolatedYValue( const XValueType& interpolationXValue,
|
||||
const std::vector<XValueType>& xValues,
|
||||
const std::vector<double>& yValues )
|
||||
{
|
||||
if ( yValues.size() != xValues.size() ) return HUGE_VAL;
|
||||
|
||||
const bool removeInterpolatedValues = false;
|
||||
|
||||
for ( size_t firstI = 0; firstI < xValues.size(); firstI++ )
|
||||
{
|
||||
if ( XComparator::equals( xValues.at( firstI ), interpolationXValue ) )
|
||||
{
|
||||
const double& firstValue = yValues.at( firstI );
|
||||
if ( !RiaCurveDataTools::isValidValue( firstValue, removeInterpolatedValues ) )
|
||||
{
|
||||
return HUGE_VAL;
|
||||
}
|
||||
|
||||
return firstValue;
|
||||
}
|
||||
|
||||
size_t secondI = firstI + 1;
|
||||
|
||||
if ( secondI < xValues.size() )
|
||||
{
|
||||
if ( XComparator::equals( xValues.at( secondI ), interpolationXValue ) )
|
||||
{
|
||||
const double& secondValue = yValues.at( secondI );
|
||||
if ( !RiaCurveDataTools::isValidValue( secondValue, removeInterpolatedValues ) )
|
||||
{
|
||||
return HUGE_VAL;
|
||||
}
|
||||
|
||||
return secondValue;
|
||||
}
|
||||
|
||||
if ( xValues.at( firstI ) < interpolationXValue && xValues.at( secondI ) > interpolationXValue )
|
||||
{
|
||||
const double& firstValue = yValues.at( firstI );
|
||||
const double& secondValue = yValues.at( secondI );
|
||||
|
||||
bool isFirstValid = RiaCurveDataTools::isValidValue( firstValue, removeInterpolatedValues );
|
||||
if ( !isFirstValid ) return HUGE_VAL;
|
||||
|
||||
bool isSecondValid = RiaCurveDataTools::isValidValue( secondValue, removeInterpolatedValues );
|
||||
if ( !isSecondValid ) return HUGE_VAL;
|
||||
|
||||
double firstDiff = fabs( XComparator::diff( interpolationXValue, xValues.at( firstI ) ) );
|
||||
double secondDiff = fabs( XComparator::diff( xValues.at( secondI ), interpolationXValue ) );
|
||||
|
||||
double firstWeight = secondDiff / ( firstDiff + secondDiff );
|
||||
double secondWeight = firstDiff / ( firstDiff + secondDiff );
|
||||
|
||||
double val = ( firstValue * firstWeight ) + ( secondValue * secondWeight );
|
||||
|
||||
CVF_ASSERT( RiaCurveDataTools::isValidValue( val, removeInterpolatedValues ) );
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return HUGE_VAL;
|
||||
}
|
||||
320
ApplicationLibCode/Application/Tools/RiaDateStringParser.cpp
Normal file
320
ApplicationLibCode/Application/Tools/RiaDateStringParser.cpp
Normal file
@@ -0,0 +1,320 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaDateStringParser.h"
|
||||
|
||||
#include "RiaQDateTimeTools.h"
|
||||
#include "RiaStdStringTools.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
const std::string MONTH_NAMES[] =
|
||||
{ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" };
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaDateStringParser::parseDateString( const QString& dateString )
|
||||
{
|
||||
return RiaDateStringParser::parseDateString( dateString.toStdString() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaDateStringParser::parseDateString( const std::string& dateString )
|
||||
{
|
||||
int year = -1, month = -1, day = -1;
|
||||
bool parsedOk = false;
|
||||
if ( hasSeparators( dateString ) )
|
||||
{
|
||||
parsedOk = tryParseYearFirst( dateString, year, month, day ) ||
|
||||
tryParseDayFirst( dateString, year, month, day ) || tryParseMonthFirst( dateString, year, month, day );
|
||||
}
|
||||
if ( !parsedOk )
|
||||
{
|
||||
auto firstNumerical = dateString.find_first_of( "0123456789" );
|
||||
if ( firstNumerical != std::string::npos )
|
||||
{
|
||||
std::string subString = dateString.substr( firstNumerical );
|
||||
|
||||
parsedOk = tryParseYearFirstNoSeparators( subString, year, month, day ) ||
|
||||
tryParseDayFirstNoSeparators( subString, year, month, day ) ||
|
||||
tryParseMonthFirstNoSeparators( subString, year, month, day );
|
||||
}
|
||||
}
|
||||
|
||||
QDateTime dt;
|
||||
dt.setTimeSpec( RiaQDateTimeTools::currentTimeSpec() );
|
||||
if ( parsedOk ) dt.setDate( QDate( year, month, day ) );
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Try parse formats
|
||||
/// 'yyyy mm dd'
|
||||
/// 'yyyy MMM dd'
|
||||
/// 'yyyy_mm_dd'
|
||||
/// 'yyyy_MMM_dd'
|
||||
/// 'yyyy-mm-dd'
|
||||
/// 'yyyy-MMM-dd'
|
||||
/// 'yyyy.MMM.dd'
|
||||
/// MMM is month name (shortened)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseYearFirst( const std::string& s, int& year, int& month, int& day )
|
||||
{
|
||||
auto firstSep = s.find_first_of( separators() );
|
||||
auto lastSep = s.find_first_of( separators(), firstSep + 1 );
|
||||
|
||||
if ( firstSep == std::string::npos || lastSep == std::string::npos ) return false;
|
||||
|
||||
auto sYear = s.substr( 0, firstSep );
|
||||
auto sMonth = s.substr( firstSep + 1, lastSep - firstSep - 1 );
|
||||
auto sDay = s.substr( lastSep + 1 );
|
||||
|
||||
return tryParseYear( sYear, year ) && tryParseMonth( sMonth, month ) && tryParseDay( sDay, day );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Try parse formats
|
||||
/// 'dd mm yyyy'
|
||||
/// 'dd MMM yyyy'
|
||||
/// 'dd_mm_yyyy'
|
||||
/// 'dd_MMM_yyyy'
|
||||
/// 'dd-mm-yyyy'
|
||||
/// 'dd-MMM-yyyy'
|
||||
/// 'dd.mm.yyyy'
|
||||
/// 'dd.MMM.yyyy'
|
||||
/// MMM is month name (shortened)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseDayFirst( const std::string& s, int& year, int& month, int& day )
|
||||
{
|
||||
auto firstSep = s.find_first_of( separators() );
|
||||
auto lastSep = s.find_first_of( separators(), firstSep + 1 );
|
||||
|
||||
if ( firstSep == std::string::npos || lastSep == std::string::npos ) return false;
|
||||
|
||||
auto sDay = s.substr( 0, firstSep );
|
||||
auto sMonth = s.substr( firstSep + 1, lastSep - firstSep - 1 );
|
||||
auto sYear = s.substr( lastSep + 1 );
|
||||
|
||||
return tryParseYear( sYear, year ) && tryParseMonth( sMonth, month ) && tryParseDay( sDay, day );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseMonthFirst( const std::string& s, int& year, int& month, int& day )
|
||||
{
|
||||
auto firstSep = s.find_first_of( separators() );
|
||||
auto lastSep = s.find_first_of( separators(), firstSep + 1 );
|
||||
|
||||
if ( firstSep == std::string::npos || lastSep == std::string::npos ) return false;
|
||||
|
||||
auto sMonth = s.substr( 0, firstSep );
|
||||
auto sDay = s.substr( firstSep + 1, lastSep - firstSep - 1 );
|
||||
auto sYear = s.substr( lastSep + 1 );
|
||||
|
||||
return tryParseYear( sYear, year ) && tryParseMonth( sMonth, month ) && tryParseDay( sDay, day );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseYearFirstNoSeparators( const std::string& s, int& year, int& month, int& day )
|
||||
{
|
||||
if ( s.length() == 8 )
|
||||
{
|
||||
// Four digit year
|
||||
auto sYear = s.substr( 0, 4 );
|
||||
auto sMonth = s.substr( 4, 2 );
|
||||
auto sDay = s.substr( 6, 2 );
|
||||
return tryParseYear( sYear, year ) && tryParseMonth( sMonth, month ) && tryParseDay( sDay, day );
|
||||
}
|
||||
else if ( s.length() == 6 )
|
||||
{
|
||||
// Two digit year
|
||||
auto sYear = s.substr( 0, 2 );
|
||||
auto sMonth = s.substr( 2, 2 );
|
||||
auto sDay = s.substr( 4, 2 );
|
||||
|
||||
return tryParseYear( sYear, year ) && tryParseMonth( sMonth, month ) && tryParseDay( sDay, day );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseDayFirstNoSeparators( const std::string& s, int& year, int& month, int& day )
|
||||
{
|
||||
if ( s.length() == 8 )
|
||||
{
|
||||
// Four digit year
|
||||
auto sDay = s.substr( 0, 2 );
|
||||
auto sMonth = s.substr( 2, 2 );
|
||||
auto sYear = s.substr( 4, 4 );
|
||||
|
||||
return tryParseYear( sYear, year ) && tryParseMonth( sMonth, month ) && tryParseDay( sDay, day );
|
||||
}
|
||||
else if ( s.length() == 6 )
|
||||
{
|
||||
// Two digit year
|
||||
auto sDay = s.substr( 0, 2 );
|
||||
auto sMonth = s.substr( 2, 2 );
|
||||
auto sYear = s.substr( 4, 2 );
|
||||
|
||||
return tryParseYear( sYear, year ) && tryParseMonth( sMonth, month ) && tryParseDay( sDay, day );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseMonthFirstNoSeparators( const std::string& s, int& year, int& month, int& day )
|
||||
{
|
||||
if ( s.length() == 8 )
|
||||
{
|
||||
// Four digit year
|
||||
auto sMonth = s.substr( 0, 2 );
|
||||
auto sDay = s.substr( 2, 2 );
|
||||
auto sYear = s.substr( 4, 4 );
|
||||
|
||||
return tryParseYear( sYear, year ) && tryParseMonth( sMonth, month ) && tryParseDay( sDay, day );
|
||||
}
|
||||
else if ( s.length() == 6 )
|
||||
{
|
||||
// Two digit year
|
||||
auto sMonth = s.substr( 0, 2 );
|
||||
auto sDay = s.substr( 2, 2 );
|
||||
auto sYear = s.substr( 4, 2 );
|
||||
|
||||
return tryParseYear( sYear, year ) && tryParseMonth( sMonth, month ) && tryParseDay( sDay, day );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseYear( const std::string& s, int& year )
|
||||
{
|
||||
if ( RiaStdStringTools::containsAlphabetic( s ) ) return false;
|
||||
|
||||
auto today = QDate::currentDate();
|
||||
int y = RiaStdStringTools::toInt( s );
|
||||
if ( y < 100 )
|
||||
{
|
||||
if ( y > 70 )
|
||||
y += 1900;
|
||||
else
|
||||
y += 2000;
|
||||
}
|
||||
|
||||
if ( y > 1970 && y <= today.year() + 100 ) // Support dates 100 years into the future.
|
||||
{
|
||||
year = y;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseMonth( const std::string& s, int& month )
|
||||
{
|
||||
if ( RiaStdStringTools::containsAlphabetic( s ) )
|
||||
{
|
||||
auto sMonth = s;
|
||||
sMonth = trimString( sMonth );
|
||||
std::transform( sMonth.begin(), sMonth.end(), sMonth.begin(), []( const char c ) -> char {
|
||||
return (char)::tolower( c );
|
||||
} );
|
||||
|
||||
for ( int i = 0; i < 12; i++ )
|
||||
{
|
||||
if ( MONTH_NAMES[i].compare( 0, sMonth.size(), sMonth ) == 0 )
|
||||
{
|
||||
month = i + 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int m = RiaStdStringTools::toInt( s );
|
||||
if ( m >= 1 && m <= 12 )
|
||||
{
|
||||
month = m;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseDay( const std::string& s, int& day )
|
||||
{
|
||||
if ( RiaStdStringTools::containsAlphabetic( s ) ) return false;
|
||||
|
||||
int d = RiaStdStringTools::toInt( s );
|
||||
if ( d >= 1 && d <= 31 )
|
||||
{
|
||||
day = d;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaDateStringParser::separators()
|
||||
{
|
||||
return " -_.";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::hasSeparators( const std::string& s )
|
||||
{
|
||||
auto firstSep = s.find_first_of( separators() );
|
||||
return firstSep != std::string::npos;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaDateStringParser::trimString( const std::string& s )
|
||||
{
|
||||
auto sCopy = s.substr( 0, s.find_last_not_of( ' ' ) + 1 );
|
||||
sCopy = sCopy.substr( sCopy.find_first_not_of( ' ' ) );
|
||||
return sCopy;
|
||||
}
|
||||
52
ApplicationLibCode/Application/Tools/RiaDateStringParser.h
Normal file
52
ApplicationLibCode/Application/Tools/RiaDateStringParser.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <string>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaDateStringParser
|
||||
{
|
||||
public:
|
||||
static QDateTime parseDateString( const QString& dateString );
|
||||
static QDateTime parseDateString( const std::string& dateString );
|
||||
|
||||
private:
|
||||
static bool tryParseYearFirst( const std::string& s, int& year, int& month, int& day );
|
||||
static bool tryParseDayFirst( const std::string& s, int& year, int& month, int& day );
|
||||
static bool tryParseMonthFirst( const std::string& s, int& year, int& month, int& day );
|
||||
|
||||
static bool tryParseYearFirstNoSeparators( const std::string& s, int& year, int& month, int& day );
|
||||
static bool tryParseDayFirstNoSeparators( const std::string& s, int& year, int& month, int& day );
|
||||
static bool tryParseMonthFirstNoSeparators( const std::string& s, int& year, int& month, int& day );
|
||||
|
||||
static bool tryParseYear( const std::string& s, int& year );
|
||||
static bool tryParseMonth( const std::string& s, int& month );
|
||||
static bool tryParseDay( const std::string& s, int& day );
|
||||
|
||||
static std::string separators();
|
||||
static bool hasSeparators( const std::string& s );
|
||||
static std::string trimString( const std::string& s );
|
||||
};
|
||||
195
ApplicationLibCode/Application/Tools/RiaEclipseUnitTools.cpp
Normal file
195
ApplicationLibCode/Application/Tools/RiaEclipseUnitTools.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017- 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 "RiaEclipseUnitTools.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
void RiaEclipseUnitTools::UnitSystemType::setUp()
|
||||
{
|
||||
addItem( RiaEclipseUnitTools::UnitSystem::UNITS_METRIC, "UNITS_METRIC", "Metric" );
|
||||
addItem( RiaEclipseUnitTools::UnitSystem::UNITS_FIELD, "UNITS_FIELD", "Field" );
|
||||
addItem( RiaEclipseUnitTools::UnitSystem::UNITS_UNKNOWN, "UNITS_UNKNOWN", "Unknown" );
|
||||
|
||||
setDefault( RiaEclipseUnitTools::UnitSystem::UNITS_METRIC );
|
||||
}
|
||||
} // namespace caf
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaEclipseUnitTools::darcysConstant( UnitSystem unitSystem )
|
||||
{
|
||||
// See "Cartesian transmissibility calculations" in the "Eclipse Technical Description"
|
||||
// CDARCY Darcys constant
|
||||
// = 0.00852702 (E300); 0.008527 (ECLIPSE 100) (METRIC)
|
||||
// = 0.00112712 (E300); 0.001127 (ECLIPSE 100) (FIELD)
|
||||
// = 3.6 (LAB)
|
||||
// = 0.00864 (PVT - M)
|
||||
switch ( unitSystem )
|
||||
{
|
||||
case UnitSystem::UNITS_FIELD:
|
||||
return 0.001127;
|
||||
case UnitSystem::UNITS_METRIC:
|
||||
return 0.008527;
|
||||
default:
|
||||
CVF_ASSERT( false );
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaDefines::DepthUnitType RiaEclipseUnitTools::depthUnit( UnitSystem unit )
|
||||
{
|
||||
switch ( unit )
|
||||
{
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_METRIC:
|
||||
return RiaDefines::DepthUnitType::UNIT_METER;
|
||||
break;
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_FIELD:
|
||||
return RiaDefines::DepthUnitType::UNIT_FEET;
|
||||
break;
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_LAB:
|
||||
return RiaDefines::DepthUnitType::UNIT_NONE;
|
||||
break;
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_UNKNOWN:
|
||||
return RiaDefines::DepthUnitType::UNIT_NONE;
|
||||
break;
|
||||
default:
|
||||
return RiaDefines::DepthUnitType::UNIT_NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Convert Gas to oil equivalents
|
||||
/// If field unit, the Gas is in Mega ft^3 while the others are in [stb] (barrel)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaEclipseUnitTools::convertSurfaceGasFlowRateToOilEquivalents( UnitSystem caseUnitSystem, double eclGasFlowRate )
|
||||
{
|
||||
/// Unused Gas to Barrel conversion :
|
||||
/// we convert gas to stb as well. Based on
|
||||
/// 1 [stb] = 0.15898729492800007 [m^3]
|
||||
/// 1 [ft] = 0.3048 [m]
|
||||
/// megaFt3ToStbFactor = 1.0 / (1.0e-6 * 0.15898729492800007 * ( 1.0 / 0.3048 )^3 )
|
||||
/// double megaFt3ToStbFactor = 178107.60668;
|
||||
|
||||
double fieldGasToOilEquivalent = 1.0e6 / 5800; // Mega ft^3 to BOE
|
||||
double metricGasToOilEquivalent = 1.0 / 1.0e3; // Sm^3 Gas to Sm^3 oe
|
||||
|
||||
double oilEquivalentGasRate = HUGE_VAL;
|
||||
|
||||
if ( caseUnitSystem == RiaEclipseUnitTools::UnitSystem::UNITS_FIELD )
|
||||
oilEquivalentGasRate = fieldGasToOilEquivalent * eclGasFlowRate;
|
||||
if ( caseUnitSystem == RiaEclipseUnitTools::UnitSystem::UNITS_METRIC )
|
||||
oilEquivalentGasRate = metricGasToOilEquivalent * eclGasFlowRate;
|
||||
|
||||
return oilEquivalentGasRate;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaEclipseUnitTools::unitStringPressure( UnitSystem unitSystem )
|
||||
{
|
||||
switch ( unitSystem )
|
||||
{
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_METRIC:
|
||||
return "barsa";
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_FIELD:
|
||||
return "psia";
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_LAB:
|
||||
return "atma";
|
||||
case RiaEclipseUnitTools::UnitSystem::UNITS_UNKNOWN:
|
||||
return "";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaEclipseUnitTools::convertToMeter( double sourceValue, const QString& sourceValueUnitText )
|
||||
{
|
||||
QString timmed = sourceValueUnitText.trimmed();
|
||||
|
||||
if ( timmed.compare( "m", Qt::CaseInsensitive ) == 0 || timmed.compare( "md-m", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return sourceValue;
|
||||
}
|
||||
else if ( timmed.compare( "cm", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return sourceValue / 100.0;
|
||||
}
|
||||
else if ( timmed.compare( "mm", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return sourceValue / 1000.0;
|
||||
}
|
||||
else if ( timmed.compare( "in", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return RiaEclipseUnitTools::inchToMeter( sourceValue );
|
||||
}
|
||||
else if ( timmed.compare( "ft", Qt::CaseInsensitive ) == 0 || timmed.compare( "md-ft", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return RiaEclipseUnitTools::feetToMeter( sourceValue );
|
||||
}
|
||||
|
||||
return HUGE_VAL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaEclipseUnitTools::convertToFeet( double sourceValue, const QString& sourceValueUnitText )
|
||||
{
|
||||
QString timmed = sourceValueUnitText.trimmed();
|
||||
|
||||
if ( timmed.compare( "ft", Qt::CaseInsensitive ) == 0 || timmed.compare( "md-ft", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return sourceValue;
|
||||
}
|
||||
else if ( timmed.compare( "in", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return RiaEclipseUnitTools::inchToFeet( sourceValue );
|
||||
}
|
||||
else if ( timmed.compare( "cm", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
double meter = sourceValue / 100.0;
|
||||
return RiaEclipseUnitTools::meterToFeet( meter );
|
||||
}
|
||||
else if ( timmed.compare( "mm", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
double meter = sourceValue / 1000.0;
|
||||
return RiaEclipseUnitTools::meterToFeet( meter );
|
||||
}
|
||||
else if ( timmed.compare( "m", Qt::CaseInsensitive ) == 0 || timmed.compare( "md-m", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return RiaEclipseUnitTools::meterToFeet( sourceValue );
|
||||
}
|
||||
|
||||
return HUGE_VAL;
|
||||
}
|
||||
65
ApplicationLibCode/Application/Tools/RiaEclipseUnitTools.h
Normal file
65
ApplicationLibCode/Application/Tools/RiaEclipseUnitTools.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017- 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiaDefines.h"
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
class RiaEclipseUnitTools
|
||||
{
|
||||
public:
|
||||
enum class UnitSystem
|
||||
{
|
||||
UNITS_METRIC,
|
||||
UNITS_FIELD,
|
||||
UNITS_LAB,
|
||||
UNITS_UNKNOWN,
|
||||
};
|
||||
|
||||
typedef caf::AppEnum<RiaEclipseUnitTools::UnitSystem> UnitSystemType;
|
||||
|
||||
static double feetPerMeter() { return 3.2808399; }
|
||||
static double meterPerFeet() { return 0.3048000; }
|
||||
|
||||
static double meterToFeet( double meter ) { return meter * feetPerMeter(); }
|
||||
static double feetToMeter( double feet ) { return feet * meterPerFeet(); }
|
||||
static double meterToInch( double meter ) { return meter * feetPerMeter() * 12.0; }
|
||||
static double inchToMeter( double inch ) { return ( inch / 12.0 ) * meterPerFeet(); }
|
||||
static double inchToFeet( double inch ) { return ( inch / 12.0 ); }
|
||||
static double mmToMeter( double mm ) { return mm / 1000.0; }
|
||||
static double meterToMm( double meter ) { return 1000.0 * meter; }
|
||||
|
||||
static double barToPascal( double bar ) { return bar * 100000.0; }
|
||||
static double pascalToBar( double pas ) { return pas / 100000.0; }
|
||||
|
||||
static double barToPsi( double bar ) { return bar * 14.5038; }
|
||||
static double barPerMeterToPsiPerFeet( double barPerMeter ) { return barPerMeter * 4.42075; }
|
||||
static double gigaPascalToPascal( double gigaPascal ) { return gigaPascal * 1.0e9; }
|
||||
|
||||
static double darcysConstant( UnitSystem unitSystem );
|
||||
|
||||
static RiaDefines::DepthUnitType depthUnit( UnitSystem unit );
|
||||
|
||||
static double convertSurfaceGasFlowRateToOilEquivalents( UnitSystem, double eclGasFlowRate );
|
||||
|
||||
static QString unitStringPressure( UnitSystem unitSystem );
|
||||
|
||||
static double convertToMeter( double sourceValue, const QString& unitText );
|
||||
static double convertToFeet( double sourceValue, const QString& unitText );
|
||||
};
|
||||
95
ApplicationLibCode/Application/Tools/RiaExtractionTools.cpp
Normal file
95
ApplicationLibCode/Application/Tools/RiaExtractionTools.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaExtractionTools.h"
|
||||
|
||||
#include "RigWellPath.h"
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimMainPlotCollection.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSimWellInView.h"
|
||||
#include "RimWellLogPlotCollection.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RigEclipseWellLogExtractor* RiaExtractionTools::findOrCreateWellLogExtractor( RimWellPath* wellPath,
|
||||
RimEclipseCase* eclipseCase )
|
||||
{
|
||||
if ( !( wellPath && eclipseCase ) ) return nullptr;
|
||||
|
||||
auto wlPlotCollection = wellLogPlotCollection();
|
||||
if ( !wlPlotCollection ) return nullptr;
|
||||
|
||||
return wlPlotCollection->findOrCreateExtractor( wellPath, eclipseCase );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RigGeoMechWellLogExtractor* RiaExtractionTools::findOrCreateWellLogExtractor( RimWellPath* wellPath,
|
||||
RimGeoMechCase* geomCase )
|
||||
{
|
||||
if ( !( wellPath && geomCase ) ) return nullptr;
|
||||
|
||||
auto wlPlotCollection = wellLogPlotCollection();
|
||||
if ( !wlPlotCollection ) return nullptr;
|
||||
|
||||
return wlPlotCollection->findOrCreateExtractor( wellPath, geomCase );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RigEclipseWellLogExtractor* RiaExtractionTools::findOrCreateSimWellExtractor( const RimSimWellInView* simWell,
|
||||
const RigWellPath* wellPathGeom )
|
||||
{
|
||||
if ( !( simWell && wellPathGeom ) ) return nullptr;
|
||||
|
||||
auto wlPlotCollection = wellLogPlotCollection();
|
||||
if ( !wlPlotCollection ) return nullptr;
|
||||
|
||||
RimEclipseCase* eclipseCase = nullptr;
|
||||
simWell->firstAncestorOrThisOfType( eclipseCase );
|
||||
if ( !( eclipseCase && eclipseCase->eclipseCaseData() ) )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QString caseUserDescription = eclipseCase->caseUserDescription();
|
||||
|
||||
return wlPlotCollection->findOrCreateSimWellExtractor( simWell->name,
|
||||
caseUserDescription,
|
||||
wellPathGeom,
|
||||
eclipseCase->eclipseCaseData() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimWellLogPlotCollection* RiaExtractionTools::wellLogPlotCollection()
|
||||
{
|
||||
auto proj = RimProject::current();
|
||||
if ( !proj ) return nullptr;
|
||||
|
||||
auto plotCollection = proj->mainPlotCollection();
|
||||
if ( !plotCollection ) return nullptr;
|
||||
|
||||
auto wellLogPlotCollection = plotCollection->wellLogPlotCollection();
|
||||
return wellLogPlotCollection;
|
||||
}
|
||||
46
ApplicationLibCode/Application/Tools/RiaExtractionTools.h
Normal file
46
ApplicationLibCode/Application/Tools/RiaExtractionTools.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 <gsl/gsl>
|
||||
|
||||
class RigEclipseWellLogExtractor;
|
||||
class RigGeoMechWellLogExtractor;
|
||||
class RigWellPath;
|
||||
class RimEclipseCase;
|
||||
class RimGeoMechCase;
|
||||
class RimSimWellInView;
|
||||
class RimWellLogPlotCollection;
|
||||
class RimWellPath;
|
||||
|
||||
class QString;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
namespace RiaExtractionTools
|
||||
{
|
||||
RigEclipseWellLogExtractor* findOrCreateWellLogExtractor( RimWellPath* wellPath, RimEclipseCase* eclipseCase );
|
||||
RigGeoMechWellLogExtractor* findOrCreateWellLogExtractor( RimWellPath* wellPath, RimGeoMechCase* geomCase );
|
||||
|
||||
RigEclipseWellLogExtractor* findOrCreateSimWellExtractor( const RimSimWellInView* simWell, const RigWellPath* wellPathGeom );
|
||||
|
||||
RimWellLogPlotCollection* wellLogPlotCollection();
|
||||
|
||||
}; // namespace RiaExtractionTools
|
||||
44
ApplicationLibCode/Application/Tools/RiaFieldHandleTools.cpp
Normal file
44
ApplicationLibCode/Application/Tools/RiaFieldHandleTools.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- Equinor ASA
|
||||
// Copyright (C) 2018- Ceetron Solutions AS
|
||||
//
|
||||
// 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 "RiaFieldHandleTools.h"
|
||||
|
||||
#include "cafPdmFieldHandle.h"
|
||||
#include "cafPdmUiFieldHandle.h"
|
||||
#include "cafPdmXmlFieldHandle.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaFieldhandleTools::disableWriteAndSetFieldHidden( caf::PdmFieldHandle* fieldHandle )
|
||||
{
|
||||
CVF_ASSERT( fieldHandle );
|
||||
|
||||
if ( fieldHandle->uiCapability() )
|
||||
{
|
||||
fieldHandle->uiCapability()->setUiHidden( true );
|
||||
}
|
||||
|
||||
if ( fieldHandle->xmlCapability() )
|
||||
{
|
||||
fieldHandle->xmlCapability()->setIOWritable( false );
|
||||
}
|
||||
}
|
||||
34
ApplicationLibCode/Application/Tools/RiaFieldHandleTools.h
Normal file
34
ApplicationLibCode/Application/Tools/RiaFieldHandleTools.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- Equinor ASA
|
||||
// Copyright (C) 2018- Ceetron Solutions AS
|
||||
//
|
||||
// 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
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmFieldHandle;
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaFieldhandleTools
|
||||
{
|
||||
public:
|
||||
static void disableWriteAndSetFieldHidden( caf::PdmFieldHandle* fieldHandle );
|
||||
};
|
||||
364
ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp
Normal file
364
ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp
Normal file
@@ -0,0 +1,364 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 "RiaFilePathTools.h"
|
||||
#include "RiaTextStringTools.h"
|
||||
|
||||
#include "cafAssert.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QChar RiaFilePathTools::separator()
|
||||
{
|
||||
return '/';
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::toInternalSeparator( const QString& path )
|
||||
{
|
||||
QString currNativeSep = QDir::separator();
|
||||
|
||||
if ( currNativeSep == "/" )
|
||||
{
|
||||
// On Linux like system -> Do not convert separators
|
||||
return path;
|
||||
}
|
||||
|
||||
// On other systems (i.e. Windows) -> Convert to internal separator (/)
|
||||
QString output = path;
|
||||
return output.replace( QString( "\\" ), separator() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString& RiaFilePathTools::appendSeparatorIfNo( QString& path )
|
||||
{
|
||||
if ( !path.endsWith( separator() ) )
|
||||
{
|
||||
path.append( separator() );
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::relativePath( const QString& rootDir, const QString& dir )
|
||||
{
|
||||
if ( dir.startsWith( rootDir ) )
|
||||
{
|
||||
QString relPath = dir;
|
||||
relPath.remove( 0, rootDir.size() );
|
||||
|
||||
if ( relPath.startsWith( separator() ) ) relPath.remove( 0, 1 );
|
||||
return appendSeparatorIfNo( relPath );
|
||||
}
|
||||
else
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaFilePathTools::equalPaths( const QString& path1, const QString& path2 )
|
||||
{
|
||||
QString p1 = path1;
|
||||
QString p2 = path2;
|
||||
appendSeparatorIfNo( p1 );
|
||||
appendSeparatorIfNo( p2 );
|
||||
return p1 == p2;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Own canonicalPath method since the QDir::canonicalPath seems to not work
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::canonicalPath( const QString& path )
|
||||
{
|
||||
return QDir( path ).absolutePath();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<QString, QString> RiaFilePathTools::toFolderAndFileName( const QString& absFileName )
|
||||
{
|
||||
auto absFN = toInternalSeparator( absFileName );
|
||||
int lastSep = absFN.lastIndexOf( separator() );
|
||||
if ( lastSep > 0 )
|
||||
{
|
||||
return std::make_pair( absFN.left( lastSep ), absFN.mid( lastSep + 1 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::make_pair( "", absFN );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::removeDuplicatePathSeparators( const QString& path )
|
||||
{
|
||||
QString correctedPath = path;
|
||||
QString prefix;
|
||||
|
||||
QString doubleBackslash = R"(\\)";
|
||||
if ( correctedPath.size() > 2 )
|
||||
{
|
||||
QString prefixCandidate = correctedPath.left( 2 );
|
||||
if ( prefixCandidate == doubleBackslash || prefixCandidate == "//" )
|
||||
{
|
||||
prefix = prefixCandidate;
|
||||
|
||||
correctedPath = correctedPath.right( correctedPath.size() - 2 );
|
||||
}
|
||||
}
|
||||
|
||||
correctedPath.replace( QString( "%1%1" ).arg( separator() ), separator() );
|
||||
correctedPath.replace( doubleBackslash, R"(\)" );
|
||||
|
||||
correctedPath = prefix + correctedPath;
|
||||
|
||||
return correctedPath;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::rootSearchPathFromSearchFilter( const QString& searchFilter )
|
||||
{
|
||||
QStringList pathPartList = searchFilter.split( separator() );
|
||||
|
||||
QStringList::iterator pathPartIt = pathPartList.begin();
|
||||
|
||||
for ( ; pathPartIt != pathPartList.end(); ++pathPartIt )
|
||||
{
|
||||
QString pathPart = *pathPartIt;
|
||||
|
||||
// Remove allowed escaping of wildcards
|
||||
|
||||
pathPart.replace( "[[]", "" );
|
||||
pathPart.replace( "[]]", "" );
|
||||
pathPart.replace( "[?]", "" );
|
||||
pathPart.replace( "[*]", "" );
|
||||
|
||||
if ( pathPart.contains( "*" ) ) break;
|
||||
if ( pathPart.contains( "?" ) ) break;
|
||||
if ( pathPart.contains( "[" ) ) break;
|
||||
}
|
||||
|
||||
pathPartList.erase( pathPartIt, pathPartList.end() );
|
||||
|
||||
return pathPartList.join( separator() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::commonRootOfFileNames( const QStringList& fileList )
|
||||
{
|
||||
QStringList fileNameList;
|
||||
for ( auto filePath : fileList )
|
||||
{
|
||||
QFileInfo fileInfo( filePath );
|
||||
QString fileNameWithoutExt = fileInfo.baseName();
|
||||
fileNameList.push_back( fileNameWithoutExt );
|
||||
}
|
||||
QString root = RiaTextStringTools::commonRoot( fileNameList );
|
||||
return root;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RiaFilePathTools::splitPathIntoComponents( const QString& inputPath, bool splitExtensionIntoSeparateEntry )
|
||||
{
|
||||
auto path = QDir::cleanPath( inputPath );
|
||||
|
||||
QStringList components;
|
||||
|
||||
QDir dir( path );
|
||||
|
||||
QFileInfo fileInfo( path );
|
||||
|
||||
if ( splitExtensionIntoSeparateEntry )
|
||||
{
|
||||
QString extension = fileInfo.completeSuffix();
|
||||
path = path.replace( QString( ".%1" ).arg( extension ), "" );
|
||||
components.push_front( extension );
|
||||
components.push_front( fileInfo.baseName() );
|
||||
}
|
||||
else
|
||||
{
|
||||
components.push_back( fileInfo.fileName() );
|
||||
}
|
||||
|
||||
while ( dir.cdUp() )
|
||||
{
|
||||
components.push_front( dir.dirName() );
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
struct PathNode
|
||||
{
|
||||
QString name;
|
||||
PathNode* parent;
|
||||
std::list<std::unique_ptr<PathNode>> children;
|
||||
QString fileName;
|
||||
|
||||
PathNode( const QString& name, PathNode* parent )
|
||||
: name( name )
|
||||
, parent( parent )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void addToPathTree( PathNode* node, QStringList pathComponents, const QString& fileName )
|
||||
{
|
||||
CAF_ASSERT( node );
|
||||
if ( !pathComponents.empty() )
|
||||
{
|
||||
QString pathComponent = pathComponents.front();
|
||||
pathComponents.pop_front();
|
||||
|
||||
for ( auto it = node->children.begin(); it != node->children.end(); ++it )
|
||||
{
|
||||
if ( it->get()->name == pathComponent )
|
||||
{
|
||||
addToPathTree( it->get(), pathComponents, fileName );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
node->children.push_back( std::unique_ptr<PathNode>( new PathNode( pathComponent, node ) ) );
|
||||
addToPathTree( node->children.back().get(), pathComponents, fileName );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Reached leaf, just set file name
|
||||
node->fileName = fileName;
|
||||
}
|
||||
}
|
||||
|
||||
void trimTree( PathNode* node )
|
||||
{
|
||||
if ( node->children.size() == 1u )
|
||||
{
|
||||
// Unnecessary level. Remove it.
|
||||
std::unique_ptr<PathNode> singleChildNode = std::move( node->children.front() );
|
||||
node->children.clear();
|
||||
node->children.swap( singleChildNode->children );
|
||||
node->fileName = singleChildNode->fileName;
|
||||
|
||||
// Re-parent children
|
||||
for ( auto it = node->children.begin(); it != node->children.end(); ++it )
|
||||
{
|
||||
it->get()->parent = node;
|
||||
}
|
||||
trimTree( node );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( auto it = node->children.begin(); it != node->children.end(); ++it )
|
||||
{
|
||||
trimTree( it->get() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void extractLeafNodes( PathNode* node, std::list<PathNode*>* leafNodes )
|
||||
{
|
||||
if ( node->children.empty() )
|
||||
{
|
||||
leafNodes->push_back( node );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( auto it = node->children.begin(); it != node->children.end(); ++it )
|
||||
{
|
||||
extractLeafNodes( it->get(), leafNodes );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pathToNode( PathNode* node, QStringList* path )
|
||||
{
|
||||
CAF_ASSERT( path );
|
||||
|
||||
if ( node != nullptr )
|
||||
{
|
||||
if ( !node->name.isEmpty() ) path->push_front( node->name );
|
||||
pathToNode( node->parent, path );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Takes a list of file paths and returns a map with the key components that separate the path
|
||||
/// from the others.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<QString, QStringList> RiaFilePathTools::keyPathComponentsForEachFilePath( const QStringList& filePaths )
|
||||
{
|
||||
std::map<QString, QStringList> allComponents;
|
||||
|
||||
std::multiset<QString> allPathComponents;
|
||||
for ( auto fileName : filePaths )
|
||||
{
|
||||
QStringList pathComponentsForFile = splitPathIntoComponents( fileName, true );
|
||||
allComponents[fileName] = pathComponentsForFile;
|
||||
|
||||
for ( auto pathComponent : pathComponentsForFile )
|
||||
{
|
||||
allPathComponents.insert( pathComponent );
|
||||
}
|
||||
}
|
||||
|
||||
auto topNode = std::unique_ptr<PathNode>( new PathNode( "", nullptr ) );
|
||||
|
||||
for ( auto keyComponentsPair : allComponents )
|
||||
{
|
||||
addToPathTree( topNode.get(), keyComponentsPair.second, keyComponentsPair.first );
|
||||
}
|
||||
|
||||
trimTree( topNode.get() );
|
||||
std::list<PathNode*> leafNodes;
|
||||
extractLeafNodes( topNode.get(), &leafNodes );
|
||||
|
||||
std::map<QString, QStringList> keyComponents;
|
||||
for ( PathNode* node : leafNodes )
|
||||
{
|
||||
QStringList path;
|
||||
pathToNode( node, &path );
|
||||
keyComponents[node->fileName] = path;
|
||||
}
|
||||
|
||||
return keyComponents;
|
||||
}
|
||||
51
ApplicationLibCode/Application/Tools/RiaFilePathTools.h
Normal file
51
ApplicationLibCode/Application/Tools/RiaFilePathTools.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 <QByteArray>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaFilePathTools
|
||||
{
|
||||
public:
|
||||
static const QChar separator();
|
||||
static QString toInternalSeparator( const QString& path );
|
||||
static QString& appendSeparatorIfNo( QString& path );
|
||||
static QString relativePath( const QString& rootDir, const QString& dir );
|
||||
static bool equalPaths( const QString& path1, const QString& path2 );
|
||||
static QString canonicalPath( const QString& path );
|
||||
static std::pair<QString, QString> toFolderAndFileName( const QString& absFileName );
|
||||
static QString removeDuplicatePathSeparators( const QString& path );
|
||||
static QString rootSearchPathFromSearchFilter( const QString& searchFilter );
|
||||
static QString commonRootOfFileNames( const QStringList& filePaths );
|
||||
|
||||
static QStringList splitPathIntoComponents( const QString& path, bool splitExtensionIntoSeparateEntry = false );
|
||||
|
||||
static std::map<QString, QStringList> keyPathComponentsForEachFilePath( const QStringList& filePaths );
|
||||
};
|
||||
125
ApplicationLibCode/Application/Tools/RiaGitDiff.cpp
Normal file
125
ApplicationLibCode/Application/Tools/RiaGitDiff.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaGitDiff.h"
|
||||
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QProcess>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaGitDiff::RiaGitDiff( const QString& pathToDiffTool )
|
||||
: m_pathToGitTool( pathToDiffTool )
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaGitDiff::~RiaGitDiff()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGitDiff::reset()
|
||||
{
|
||||
m_lastError = ErrorType::IC_NO_ERROR;
|
||||
m_errorMsg.clear();
|
||||
m_errorDetails.clear();
|
||||
m_diffOutput.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaGitDiff::executeDiff( const QString& baseFolder )
|
||||
{
|
||||
reset();
|
||||
|
||||
QString fullFilePath = "git";
|
||||
if ( !m_pathToGitTool.isEmpty() )
|
||||
{
|
||||
fullFilePath = m_pathToGitTool + "/" + fullFilePath;
|
||||
}
|
||||
|
||||
QString incomingCurrentPath = QDir::currentPath();
|
||||
QDir::setCurrent( baseFolder );
|
||||
|
||||
QString args = "diff";
|
||||
|
||||
QString completeCommand = QString( "\"%1\" %2" ).arg( fullFilePath ).arg( args );
|
||||
|
||||
// Launch process and wait
|
||||
QProcess proc;
|
||||
proc.start( completeCommand );
|
||||
proc.waitForFinished( 30000 );
|
||||
|
||||
QDir::setCurrent( incomingCurrentPath );
|
||||
|
||||
QProcess::ProcessError procError = proc.error();
|
||||
if ( procError != QProcess::UnknownError )
|
||||
{
|
||||
m_lastError = ErrorType::SEVERE_ERROR;
|
||||
m_errorMsg = "Error running 'git' tool process";
|
||||
m_errorDetails = completeCommand;
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray stdOut = proc.readAllStandardOutput();
|
||||
m_diffOutput = stdOut;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaGitDiff::ErrorType RiaGitDiff::error() const
|
||||
{
|
||||
return m_lastError;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaGitDiff::errorMessage() const
|
||||
{
|
||||
return m_errorMsg;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaGitDiff::errorDetails() const
|
||||
{
|
||||
return m_errorDetails;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaGitDiff::diffOutput() const
|
||||
{
|
||||
return m_diffOutput;
|
||||
}
|
||||
57
ApplicationLibCode/Application/Tools/RiaGitDiff.h
Normal file
57
ApplicationLibCode/Application/Tools/RiaGitDiff.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 <QString>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// Use external tool 'git' to produce a text string representing the diff
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaGitDiff
|
||||
{
|
||||
public:
|
||||
enum class ErrorType
|
||||
{
|
||||
IC_NO_ERROR, // No error occurred
|
||||
IC_ERROR, // An error occurred
|
||||
SEVERE_ERROR // Severe error occurred, it is likely that another call to compare() will also fail
|
||||
};
|
||||
|
||||
public:
|
||||
explicit RiaGitDiff( const QString& pathToGitTool );
|
||||
~RiaGitDiff();
|
||||
|
||||
bool executeDiff( const QString& baseFolder );
|
||||
ErrorType error() const;
|
||||
QString errorMessage() const;
|
||||
QString errorDetails() const;
|
||||
QString diffOutput() const;
|
||||
|
||||
private:
|
||||
void reset();
|
||||
|
||||
private:
|
||||
const QString m_pathToGitTool;
|
||||
ErrorType m_lastError;
|
||||
QString m_errorMsg;
|
||||
QString m_errorDetails;
|
||||
QString m_diffOutput;
|
||||
};
|
||||
225
ApplicationLibCode/Application/Tools/RiaImageCompareReporter.cpp
Normal file
225
ApplicationLibCode/Application/Tools/RiaImageCompareReporter.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// 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 "RiaImageCompareReporter.h"
|
||||
#include <QDir>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
RiaImageCompareReporter::RiaImageCompareReporter( void )
|
||||
{
|
||||
m_showOriginal = true;
|
||||
m_showGenerated = true;
|
||||
m_showInteractiveDiff = false;
|
||||
}
|
||||
|
||||
RiaImageCompareReporter::~RiaImageCompareReporter( void )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaImageCompareReporter::addImageDirectoryComparisonSet( const std::string& title,
|
||||
const std::string& baseImageDir,
|
||||
const std::string& newImagesDir,
|
||||
const std::string& diffImagesDir )
|
||||
{
|
||||
m_directorySets.push_back( DirSet( title, baseImageDir, newImagesDir, diffImagesDir ) );
|
||||
}
|
||||
|
||||
std::string removeCommonStart( const std::string& mask, const std::string& filename )
|
||||
{
|
||||
size_t i;
|
||||
for ( i = 0; i < mask.size() && i < filename.size(); ++i )
|
||||
{
|
||||
if ( mask[i] != filename[i] ) break;
|
||||
}
|
||||
|
||||
return filename.substr( i );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaImageCompareReporter::generateHTMLReport( const std::string& fileName, const std::string& diff2htmlHeaderText )
|
||||
{
|
||||
if ( m_directorySets.size() == 0 ) return;
|
||||
|
||||
std::ofstream output( fileName.c_str() );
|
||||
if ( !output )
|
||||
{
|
||||
std::cout << "Trouble opening test report file: " << fileName;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string html;
|
||||
|
||||
html += "<html>\n";
|
||||
html += "<head>\n";
|
||||
|
||||
if ( m_showInteractiveDiff )
|
||||
{
|
||||
html += cssString();
|
||||
}
|
||||
|
||||
html += diff2htmlHeaderText;
|
||||
|
||||
html += "</head>\n";
|
||||
html += "\n";
|
||||
html += "<body>\n";
|
||||
html += "<title>Regression-Test Report</title>\n";
|
||||
html += "\n";
|
||||
|
||||
for ( size_t dsIdx = 0; dsIdx < m_directorySets.size(); ++dsIdx )
|
||||
{
|
||||
std::vector<std::string> baseImageNames = getPngFilesInDirectory( m_directorySets[dsIdx].m_baseImageDir );
|
||||
|
||||
html += "<table>\n";
|
||||
html += " <tr>\n";
|
||||
html += " <td colspan=\"3\" bgcolor=\"darkblue\" height=\"40\"> <b><font color=\"white\" size=\"3\"> " +
|
||||
m_directorySets[dsIdx].m_title + " </font></b> </td>\n";
|
||||
html += " </tr>\n";
|
||||
|
||||
std::string baseImageFolder = removeCommonStart( fileName, m_directorySets[dsIdx].m_baseImageDir );
|
||||
std::string genImageFolder = removeCommonStart( fileName, m_directorySets[dsIdx].m_newImagesDir );
|
||||
std::string diffImageFolder = removeCommonStart( fileName, m_directorySets[dsIdx].m_diffImagesDir );
|
||||
|
||||
for ( size_t fIdx = 0; fIdx < baseImageNames.size(); ++fIdx )
|
||||
{
|
||||
html += " <tr>\n";
|
||||
html += " <td colspan=\"3\" bgcolor=\"lightgray\"> " + baseImageNames[fIdx] + "</td>\n";
|
||||
html += " </tr>\n";
|
||||
|
||||
html += " <tr>\n";
|
||||
if ( m_showOriginal )
|
||||
{
|
||||
html += " <td> <img src=\"" + baseImageFolder + "/" + baseImageNames[fIdx] +
|
||||
"\" width=\"100%\" alt=\"" + baseImageFolder + "/" + baseImageNames[fIdx] + "\" > </td>\n";
|
||||
}
|
||||
|
||||
if ( m_showGenerated )
|
||||
{
|
||||
html += " <td> <img src=\"" + genImageFolder + "/" + baseImageNames[fIdx] +
|
||||
"\" width=\"100%\" alt=\"" + genImageFolder + "/" + baseImageNames[fIdx] + "\" > </td>\n";
|
||||
}
|
||||
|
||||
if ( m_showInteractiveDiff )
|
||||
{
|
||||
html += " <td> <div class = \"image-slider\"> <div> <img src=\"" + baseImageFolder + "/" +
|
||||
baseImageNames[fIdx] + "\" > </div> <img src = \"" + genImageFolder + "/" +
|
||||
baseImageNames[fIdx] + "\" > </div> </td>\n";
|
||||
}
|
||||
|
||||
html += " <td> <img src=\"" + diffImageFolder + "/" + baseImageNames[fIdx] +
|
||||
"\" width=\"100%\" alt=\"" + diffImageFolder + "/" + baseImageNames[fIdx] + "\" > </td>\n";
|
||||
html += " </tr>\n";
|
||||
|
||||
// A little air between images
|
||||
html += " <tr> <td height=\"10\"> </td> </tr>\n";
|
||||
}
|
||||
|
||||
html += "</table>\n";
|
||||
|
||||
html += "\n";
|
||||
}
|
||||
|
||||
output << html;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaImageCompareReporter::showInteractiveOnly()
|
||||
{
|
||||
m_showOriginal = false;
|
||||
m_showGenerated = false;
|
||||
m_showInteractiveDiff = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Retuns the names of the *.png files in a directory. The names are without path, but with extension
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
std::vector<std::string> RiaImageCompareReporter::getPngFilesInDirectory( const std::string& searchPath )
|
||||
{
|
||||
QDir searchDir( QString::fromStdString( searchPath ) );
|
||||
|
||||
searchDir.setFilter( QDir::Files );
|
||||
// QStringList filter;
|
||||
// filter.append("*.png");
|
||||
// searchDir.setNameFilters(filter);
|
||||
|
||||
QStringList imageFiles = searchDir.entryList();
|
||||
|
||||
std::vector<std::string> fileNames;
|
||||
for ( int i = 0; i < imageFiles.size(); ++i )
|
||||
{
|
||||
fileNames.push_back( imageFiles[i].toStdString() );
|
||||
}
|
||||
|
||||
return fileNames;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaImageCompareReporter::cssString() const
|
||||
{
|
||||
std::string html;
|
||||
|
||||
html += "<style media=\"screen\" type=\"text/css\">";
|
||||
|
||||
html += "";
|
||||
html += ".image-slider {";
|
||||
html += "position:relative;";
|
||||
html += "display: inline-block;";
|
||||
html += "line-height: 0;";
|
||||
html += "}";
|
||||
|
||||
html += ".image-slider > div {";
|
||||
html += "position: absolute;";
|
||||
html += "top: 0; bottom: 0; left: 0;";
|
||||
html += "width: 25px;";
|
||||
html += "max-width: 100%;";
|
||||
html += "overflow: hidden;";
|
||||
html += "resize: horizontal;";
|
||||
html += "}";
|
||||
|
||||
html += ".image-slider > div:before {";
|
||||
html += "content: '';";
|
||||
html += "position: absolute;";
|
||||
html += "right: 0; bottom: 0;";
|
||||
html += "width: 23px; height: 23px;";
|
||||
html += "padding: 5px;";
|
||||
html += "background: linear-gradient(-45deg, gray 50%, transparent 0);";
|
||||
html += "background-clip: content-box;";
|
||||
html += "cursor: ew-resize;";
|
||||
html += "-webkit-filter: drop-shadow(0 0 6px black);";
|
||||
html += "filter: drop-shadow(0 0 6px black);";
|
||||
html += "}";
|
||||
|
||||
html += ".image-slider img {";
|
||||
html += "user-select: none;";
|
||||
html += "max-width: 1000px;";
|
||||
html += "}";
|
||||
|
||||
html += "</style>";
|
||||
|
||||
return html;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// 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 <string>
|
||||
#include <vector>
|
||||
|
||||
class RiaImageCompareReporter
|
||||
{
|
||||
public:
|
||||
RiaImageCompareReporter();
|
||||
virtual ~RiaImageCompareReporter();
|
||||
|
||||
void addImageDirectoryComparisonSet( const std::string& title,
|
||||
const std::string& baseImageDir,
|
||||
const std::string& newImagesDir,
|
||||
const std::string& diffImagesDir );
|
||||
void generateHTMLReport( const std::string& filenName, const std::string& pathToDiff2html );
|
||||
|
||||
void showInteractiveOnly();
|
||||
|
||||
private:
|
||||
static std::vector<std::string> getPngFilesInDirectory( const std::string& searchPath );
|
||||
std::string cssString() const;
|
||||
|
||||
private:
|
||||
struct DirSet
|
||||
{
|
||||
DirSet( const std::string& title,
|
||||
const std::string& baseImageDir,
|
||||
const std::string& newImagesDir,
|
||||
const std::string& diffImagesDir )
|
||||
: m_title( title )
|
||||
, m_baseImageDir( baseImageDir )
|
||||
, m_newImagesDir( newImagesDir )
|
||||
, m_diffImagesDir( diffImagesDir )
|
||||
{
|
||||
}
|
||||
|
||||
std::string m_title;
|
||||
std::string m_baseImageDir;
|
||||
std::string m_newImagesDir;
|
||||
std::string m_diffImagesDir;
|
||||
};
|
||||
|
||||
std::vector<DirSet> m_directorySets;
|
||||
|
||||
bool m_showOriginal;
|
||||
bool m_showGenerated;
|
||||
bool m_showInteractiveDiff;
|
||||
};
|
||||
152
ApplicationLibCode/Application/Tools/RiaImageFileCompare.cpp
Normal file
152
ApplicationLibCode/Application/Tools/RiaImageFileCompare.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// 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 "RiaImageFileCompare.h"
|
||||
#include <QtCore/QProcess>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaImageFileCompare::RiaImageFileCompare( QString compareExecutable )
|
||||
: m_compareExecutable( compareExecutable )
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaImageFileCompare::~RiaImageFileCompare()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaImageFileCompare::reset()
|
||||
{
|
||||
m_imagesEqual = false;
|
||||
m_lastError = ErrorType::IC_NO_ERROR;
|
||||
m_errorMsg = "";
|
||||
m_errorDetails = "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaImageFileCompare::runComparison( const QString& imgFileName, const QString& refFileName, const QString& diffFileName )
|
||||
{
|
||||
reset();
|
||||
|
||||
if ( m_compareExecutable.isEmpty() )
|
||||
{
|
||||
m_lastError = ErrorType::SEVERE_ERROR;
|
||||
m_errorMsg = "Cannot compare images, no compare executable set";
|
||||
return false;
|
||||
}
|
||||
|
||||
// QString args = QString("-fuzz 2% -lowlight-color white -metric ae \"%1\" \"%2\"
|
||||
// \"%3\"").arg(imgFileName).arg(refFileName).arg((diffFileName));
|
||||
// The ImageMagick compare tool on RedHat 5 does not support the lowlight-color options
|
||||
// Use GCC version as a crude mechanism for disabling use of this option on RedHat5
|
||||
#if ( __GNUC__ == 4 && __GNUC_MINOR__ <= 1 )
|
||||
QString args =
|
||||
QString( "-fuzz 0.4% -metric ae \"%1\" \"%2\" \"%3\"" ).arg( imgFileName ).arg( refFileName ).arg( ( diffFileName ) );
|
||||
#else
|
||||
QString args = QString( "-fuzz 0.4% -lowlight-color white -metric ae \"%1\" \"%2\" \"%3\"" )
|
||||
.arg( imgFileName )
|
||||
.arg( refFileName )
|
||||
.arg( ( diffFileName ) );
|
||||
#endif
|
||||
QString completeCommand = QString( "\"%1\" %2" ).arg( m_compareExecutable ).arg( args );
|
||||
|
||||
// Launch process and wait
|
||||
QProcess proc;
|
||||
proc.start( completeCommand );
|
||||
proc.waitForFinished( 30000 );
|
||||
|
||||
QProcess::ProcessError procError = proc.error();
|
||||
if ( procError != QProcess::UnknownError )
|
||||
{
|
||||
m_lastError = ErrorType::SEVERE_ERROR;
|
||||
m_errorMsg = "Error running compare tool process";
|
||||
m_errorDetails = completeCommand;
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray stdErr = proc.readAllStandardError();
|
||||
int procExitCode = proc.exitCode();
|
||||
if ( procExitCode == 0 )
|
||||
{
|
||||
// Strip out whitespace and look for 0 (as in zero pixel differences)
|
||||
stdErr = stdErr.simplified();
|
||||
if ( !stdErr.isEmpty() && stdErr[0] == '0' )
|
||||
{
|
||||
m_imagesEqual = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Report non-severe error
|
||||
m_lastError = ErrorType::IC_ERROR;
|
||||
m_errorMsg = "Error running compare tool process";
|
||||
m_errorDetails = stdErr;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaImageFileCompare::imagesEqual() const
|
||||
{
|
||||
return m_imagesEqual;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaImageFileCompare::ErrorType RiaImageFileCompare::error() const
|
||||
{
|
||||
return m_lastError;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaImageFileCompare::errorMessage() const
|
||||
{
|
||||
return m_errorMsg;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaImageFileCompare::errorDetails() const
|
||||
{
|
||||
return m_errorDetails;
|
||||
}
|
||||
57
ApplicationLibCode/Application/Tools/RiaImageFileCompare.h
Normal file
57
ApplicationLibCode/Application/Tools/RiaImageFileCompare.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// 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 <QString>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// Compare two images (currently using ImageMagick in an external process)
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaImageFileCompare
|
||||
{
|
||||
public:
|
||||
enum class ErrorType
|
||||
{
|
||||
IC_NO_ERROR, // No error occurred
|
||||
IC_ERROR, // An error occurred
|
||||
SEVERE_ERROR // Severe error occurred, it is likely that another call to compare() will also fail
|
||||
};
|
||||
|
||||
public:
|
||||
explicit RiaImageFileCompare( QString compareExecutable );
|
||||
~RiaImageFileCompare();
|
||||
|
||||
bool runComparison( const QString& imgFileName, const QString& refFileName, const QString& diffFileName );
|
||||
bool imagesEqual() const;
|
||||
ErrorType error() const;
|
||||
QString errorMessage() const;
|
||||
QString errorDetails() const;
|
||||
|
||||
private:
|
||||
void reset();
|
||||
|
||||
private:
|
||||
QString m_compareExecutable; // The executable for the ImageMagick compare tool
|
||||
bool m_imagesEqual; // Result of last comparison
|
||||
ErrorType m_lastError; // Error for last execution
|
||||
QString m_errorMsg;
|
||||
QString m_errorDetails;
|
||||
};
|
||||
135
ApplicationLibCode/Application/Tools/RiaImageTools.cpp
Normal file
135
ApplicationLibCode/Application/Tools/RiaImageTools.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
#include "RiaImageTools.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QImage>
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Meijster, Roerdink, Hesselink
|
||||
/// A GENERAL ALGORITHM FOR COMPUTING DISTANCE TRANSFORMS IN LINEAR TIME
|
||||
/// http://fab.cba.mit.edu/classes/S62.12/docs/Meijster_distance.pdf
|
||||
/// Currently Euclidean only, but can be easily extended by replacing the lambda functions.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaImageTools::distanceTransform2d( std::vector<std::vector<unsigned int>>& image )
|
||||
{
|
||||
if ( image.empty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ( image.front().empty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
const int64_t M = (int64_t)image.size();
|
||||
const int64_t N = (int64_t)image.front().size();
|
||||
|
||||
int64_t infVal = M + N;
|
||||
CVF_ASSERT( infVal <= std::numeric_limits<unsigned int>::max() );
|
||||
|
||||
// First phase
|
||||
std::vector<std::vector<int64_t>> g( M );
|
||||
|
||||
#pragma omp parallel for
|
||||
for ( int64_t x = 0; x < M; ++x )
|
||||
{
|
||||
g[x].resize( N, infVal );
|
||||
if ( image[x][0] )
|
||||
{
|
||||
g[x][0] = 0;
|
||||
}
|
||||
for ( int64_t y = 1; y < N - 1; ++y )
|
||||
{
|
||||
if ( image[x][y] )
|
||||
{
|
||||
g[x][y] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
g[x][y] = 1 + g[x][y - 1];
|
||||
}
|
||||
}
|
||||
for ( int64_t y = N - 2; y >= 0; --y )
|
||||
{
|
||||
if ( g[x][y + 1] < g[x][y] )
|
||||
{
|
||||
g[x][y] = 1 + g[x][y + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto f = []( int64_t x, int64_t i, const std::vector<std::vector<int64_t>>& g, int64_t y ) {
|
||||
return ( x - i ) * ( x - i ) + g[i][y] * g[i][y];
|
||||
};
|
||||
|
||||
auto sep = []( int64_t i, int64_t u, const std::vector<std::vector<int64_t>>& g, int64_t y ) {
|
||||
if ( i == u ) return (int64_t)0;
|
||||
|
||||
int64_t numerator = u * u - i * i + g[u][y] * g[u][y] - g[i][y] * g[i][y];
|
||||
int64_t divisor = 2 * ( u - i );
|
||||
return numerator / divisor;
|
||||
};
|
||||
|
||||
// Second phase
|
||||
#pragma omp parallel for
|
||||
for ( int64_t y = 0; y < N; ++y )
|
||||
{
|
||||
int64_t q = 0;
|
||||
std::vector<int64_t> s( std::max( N, M ), (int64_t)0 );
|
||||
std::vector<int64_t> t( std::max( N, M ), (int64_t)0 );
|
||||
|
||||
for ( int64_t u = 1; u < M - 1; ++u )
|
||||
{
|
||||
while ( q >= 0 && f( t[q], s[q], g, y ) > f( t[q], u, g, y ) )
|
||||
{
|
||||
q--;
|
||||
}
|
||||
if ( q < 0 )
|
||||
{
|
||||
q = 0;
|
||||
s[0] = u;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t w = 1 + sep( (int64_t)s[q], u, g, y );
|
||||
if ( w < M )
|
||||
{
|
||||
q++;
|
||||
s[q] = u;
|
||||
t[q] = w;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( int64_t u = M - 1; u >= 0; --u )
|
||||
{
|
||||
int64_t fVal = f( u, s[q], g, y );
|
||||
CVF_ASSERT( fVal <= std::numeric_limits<double>::max() );
|
||||
image[u][y] = static_cast<unsigned int>( fVal );
|
||||
if ( u == t[q] )
|
||||
{
|
||||
q = q - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaImageTools::makeGrayScale( QImage& image )
|
||||
{
|
||||
for ( int i = 0; i < image.height(); i++ )
|
||||
{
|
||||
uchar* scanLine = image.scanLine( i );
|
||||
for ( int j = 0; j < image.width(); j++ )
|
||||
{
|
||||
QRgb* pixel = reinterpret_cast<QRgb*>( scanLine + j * 4 );
|
||||
int gray = qGray( *pixel );
|
||||
int alpha = qAlpha( *pixel );
|
||||
*pixel = QColor( gray, gray, gray, alpha ).rgba();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
ApplicationLibCode/Application/Tools/RiaImageTools.h
Normal file
30
ApplicationLibCode/Application/Tools/RiaImageTools.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 <vector>
|
||||
|
||||
class QImage;
|
||||
|
||||
class RiaImageTools
|
||||
{
|
||||
public:
|
||||
static void distanceTransform2d( std::vector<std::vector<unsigned int>>& image );
|
||||
static void makeGrayScale( QImage& image );
|
||||
};
|
||||
@@ -0,0 +1,458 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaImportEclipseCaseTools.h"
|
||||
|
||||
#include "ApplicationCommands/RicShowMainWindowFeature.h"
|
||||
|
||||
#include "SummaryPlotCommands/RicNewSummaryCurveFeature.h"
|
||||
#include "SummaryPlotCommands/RicNewSummaryPlotFeature.h"
|
||||
#include "SummaryPlotCommands/RicSummaryPlotFeatureImpl.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "RifEclipseSummaryTools.h"
|
||||
#include "RifSummaryCaseRestartSelector.h"
|
||||
|
||||
#include "RigGridManager.h"
|
||||
|
||||
#include "RimCaseCollection.h"
|
||||
#include "RimCompletionTemplateCollection.h"
|
||||
#include "RimEclipseCaseCollection.h"
|
||||
#include "RimEclipseCellColors.h"
|
||||
#include "RimEclipseInputCase.h"
|
||||
#include "RimEclipseResultCase.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimFileSummaryCase.h"
|
||||
#include "RimGridSummaryCase.h"
|
||||
#include "RimIdenticalGridCaseGroup.h"
|
||||
#include "RimMainPlotCollection.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSummaryCaseCollection.h"
|
||||
#include "RimSummaryCaseMainCollection.h"
|
||||
#include "RimSummaryCurve.h"
|
||||
#include "RimSummaryCurveCollection.h"
|
||||
#include "RimSummaryCurveFilter.h"
|
||||
#include "RimSummaryPlot.h"
|
||||
#include "RimSummaryPlotCollection.h"
|
||||
#include "RimWellLogRftCurve.h"
|
||||
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
#include "RiuMainWindow.h"
|
||||
#include "RiuPlotMainWindow.h"
|
||||
#include "RiuPlotMainWindowTools.h"
|
||||
|
||||
#include "cafProgressInfo.h"
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList& fileNames,
|
||||
FileCaseIdMap* openedFilesOut,
|
||||
bool noDialog )
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
RimProject* project = app->project();
|
||||
|
||||
// Get list of files to import
|
||||
RifSummaryCaseRestartSelector selector;
|
||||
if ( noDialog ) selector.showDialog( false );
|
||||
selector.determineFilesToImportFromGridFiles( fileNames );
|
||||
std::vector<RifSummaryCaseFileResultInfo> summaryFileInfos = selector.summaryFileInfos();
|
||||
|
||||
FileCaseIdMap openedFiles;
|
||||
|
||||
// Import eclipse case files
|
||||
for ( const QString& gridCaseFile : selector.gridCaseFiles() )
|
||||
{
|
||||
int caseId = RiaImportEclipseCaseTools::openEclipseCaseFromFile( gridCaseFile );
|
||||
if ( caseId >= 0 )
|
||||
{
|
||||
openedFiles.insert( std::make_pair( gridCaseFile, caseId ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !openedFiles.empty() )
|
||||
{
|
||||
if ( project && project->mainPlotCollection() )
|
||||
{
|
||||
project->mainPlotCollection()->ensureDefaultFlowPlotsAreCreated();
|
||||
}
|
||||
}
|
||||
|
||||
// Import summary cases
|
||||
if ( !summaryFileInfos.empty() )
|
||||
{
|
||||
RimSummaryCaseMainCollection* sumCaseColl =
|
||||
project->activeOilField() ? project->activeOilField()->summaryCaseMainCollection() : nullptr;
|
||||
if ( sumCaseColl )
|
||||
{
|
||||
std::vector<RimSummaryCase*> newSumCases = sumCaseColl->createSummaryCasesFromFileInfos( summaryFileInfos );
|
||||
for ( RimSummaryCase* newSumCase : newSumCases )
|
||||
{
|
||||
RimSummaryCaseCollection* existingCollection = nullptr;
|
||||
QString gridCaseFile =
|
||||
RifEclipseSummaryTools::findGridCaseFileFromSummaryHeaderFile( newSumCase->summaryHeaderFilename() );
|
||||
RimEclipseCase* gridCase = project->eclipseCaseFromGridFileName( gridCaseFile );
|
||||
if ( gridCase )
|
||||
{
|
||||
RimSummaryCase* existingSummaryCase =
|
||||
sumCaseColl->findSummaryCaseFromFileName( newSumCase->summaryHeaderFilename() );
|
||||
RimGridSummaryCase* existingGridSummaryCase = dynamic_cast<RimGridSummaryCase*>( existingSummaryCase );
|
||||
RimFileSummaryCase* existingFileSummaryCase = dynamic_cast<RimFileSummaryCase*>( existingSummaryCase );
|
||||
if ( existingGridSummaryCase )
|
||||
{
|
||||
delete newSumCase; // No need to add anything new. Already have one.
|
||||
continue;
|
||||
}
|
||||
else if ( existingFileSummaryCase )
|
||||
{
|
||||
existingFileSummaryCase->firstAncestorOrThisOfType( existingCollection );
|
||||
|
||||
// Replace file summary case pointers in Rft Curves
|
||||
std::vector<RimWellLogRftCurve*> rftCurves;
|
||||
existingFileSummaryCase->objectsWithReferringPtrFieldsOfType( rftCurves );
|
||||
for ( RimWellLogRftCurve* curve : rftCurves )
|
||||
{
|
||||
if ( curve->summaryCase() == existingSummaryCase )
|
||||
{
|
||||
curve->setSummaryCase( newSumCase );
|
||||
}
|
||||
}
|
||||
|
||||
// Replace all occurrences of file sum with ecl sum
|
||||
|
||||
std::vector<RimSummaryCurve*> objects;
|
||||
existingFileSummaryCase->objectsWithReferringPtrFieldsOfType( objects );
|
||||
|
||||
// UI settings of a curve filter is updated based
|
||||
// on the new case association for the curves in the curve filter
|
||||
// UI is updated by loadDataAndUpdate()
|
||||
|
||||
for ( RimSummaryCurve* summaryCurve : objects )
|
||||
{
|
||||
if ( summaryCurve )
|
||||
{
|
||||
if ( summaryCurve->summaryCaseX() == existingSummaryCase )
|
||||
{
|
||||
summaryCurve->setSummaryCaseX( newSumCase );
|
||||
}
|
||||
if ( summaryCurve->summaryCaseY() == existingSummaryCase )
|
||||
{
|
||||
summaryCurve->setSummaryCaseY( newSumCase );
|
||||
}
|
||||
|
||||
RimSummaryCurveCollection* parentCollection = nullptr;
|
||||
summaryCurve->firstAncestorOrThisOfType( parentCollection );
|
||||
if ( parentCollection )
|
||||
{
|
||||
parentCollection->loadDataAndUpdate( true );
|
||||
parentCollection->updateConnectedEditors();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove existing case
|
||||
sumCaseColl->removeCase( existingFileSummaryCase );
|
||||
delete existingFileSummaryCase;
|
||||
}
|
||||
}
|
||||
if ( existingCollection )
|
||||
{
|
||||
existingCollection->addCase( newSumCase );
|
||||
}
|
||||
else
|
||||
{
|
||||
sumCaseColl->addCase( newSumCase );
|
||||
}
|
||||
sumCaseColl->updateAllRequiredEditors();
|
||||
}
|
||||
|
||||
if ( !newSumCases.empty() )
|
||||
{
|
||||
RimSummaryPlotCollection* summaryPlotColl = project->mainPlotCollection()->summaryPlotCollection();
|
||||
|
||||
RicSummaryPlotFeatureImpl::ensureAtLeastOnePlot( summaryPlotColl, newSumCases.front() );
|
||||
|
||||
RiuPlotMainWindowTools::setExpanded( newSumCases.front() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( selector.foundErrors() )
|
||||
{
|
||||
QString errorMessage = selector.createCombinedErrorMessage();
|
||||
RiaLogging::error( errorMessage );
|
||||
}
|
||||
|
||||
project->activeOilField()->completionTemplateCollection()->setDefaultUnitSystemBasedOnLoadedCases();
|
||||
|
||||
RiuPlotMainWindowTools::refreshToolbars();
|
||||
|
||||
if ( openedFilesOut )
|
||||
{
|
||||
*openedFilesOut = openedFiles;
|
||||
}
|
||||
|
||||
return !openedFiles.empty();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaImportEclipseCaseTools::openEclipseCaseFromFile( const QString& fileName )
|
||||
{
|
||||
if ( !caf::Utils::fileExists( fileName ) ) return -1;
|
||||
|
||||
return RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( fileName, false );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilter( const QString& fileName )
|
||||
{
|
||||
if ( !caf::Utils::fileExists( fileName ) ) return false;
|
||||
|
||||
return RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( fileName, true ) >= 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaImportEclipseCaseTools::openEclipseInputCaseFromFileNames( const QStringList& fileNames,
|
||||
QString* fileContainingGrid /*=nullptr*/ )
|
||||
{
|
||||
RimEclipseInputCase* rimInputReservoir = new RimEclipseInputCase();
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
RimProject* project = app->project();
|
||||
|
||||
project->assignCaseIdToCase( rimInputReservoir );
|
||||
|
||||
bool gridImportSuccess = rimInputReservoir->openDataFileSet( fileNames );
|
||||
if ( !gridImportSuccess )
|
||||
{
|
||||
RiaLogging::error( "Failed to import grid" );
|
||||
return false;
|
||||
}
|
||||
|
||||
RimEclipseCaseCollection* analysisModels = project->activeOilField() ? project->activeOilField()->analysisModels()
|
||||
: nullptr;
|
||||
if ( analysisModels == nullptr ) return false;
|
||||
|
||||
analysisModels->cases.push_back( rimInputReservoir );
|
||||
|
||||
RimEclipseView* riv = rimInputReservoir->createAndAddReservoirView();
|
||||
|
||||
riv->cellResult()->setResultType( RiaDefines::ResultCatType::INPUT_PROPERTY );
|
||||
|
||||
riv->loadDataAndUpdate();
|
||||
|
||||
if ( !riv->cellResult()->hasResult() )
|
||||
{
|
||||
riv->cellResult()->setResultVariable( RiaDefines::undefinedResultName() );
|
||||
}
|
||||
|
||||
analysisModels->updateConnectedEditors();
|
||||
|
||||
Riu3DMainWindowTools::selectAsCurrentItem( riv->cellResult() );
|
||||
|
||||
if ( fileContainingGrid )
|
||||
{
|
||||
*fileContainingGrid = rimInputReservoir->gridFileName();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaImportEclipseCaseTools::openMockModel( const QString& name )
|
||||
{
|
||||
return RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( name, false );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( const QString& fileName, bool showTimeStepFilter )
|
||||
{
|
||||
QFileInfo gridFileName( fileName );
|
||||
QString caseName = gridFileName.completeBaseName();
|
||||
|
||||
RimEclipseResultCase* rimResultReservoir = new RimEclipseResultCase();
|
||||
rimResultReservoir->setCaseInfo( caseName, fileName );
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
RimProject* project = app->project();
|
||||
|
||||
RimEclipseCaseCollection* analysisModels = project->activeOilField() ? project->activeOilField()->analysisModels()
|
||||
: nullptr;
|
||||
if ( analysisModels == nullptr )
|
||||
{
|
||||
delete rimResultReservoir;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( RiaGuiApplication::isRunning() )
|
||||
{
|
||||
RicShowMainWindowFeature::showMainWindow();
|
||||
}
|
||||
|
||||
analysisModels->cases.push_back( rimResultReservoir );
|
||||
|
||||
if ( !rimResultReservoir->importGridAndResultMetaData( showTimeStepFilter ) )
|
||||
{
|
||||
analysisModels->removeCaseFromAllGroups( rimResultReservoir );
|
||||
|
||||
delete rimResultReservoir;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
RimEclipseView* riv = rimResultReservoir->createAndAddReservoirView();
|
||||
|
||||
riv->loadDataAndUpdate();
|
||||
|
||||
if ( !riv->cellResult()->hasResult() )
|
||||
{
|
||||
riv->cellResult()->setResultVariable( RiaDefines::undefinedResultName() );
|
||||
}
|
||||
|
||||
analysisModels->updateConnectedEditors();
|
||||
|
||||
if ( RiaGuiApplication::isRunning() )
|
||||
{
|
||||
RiuMainWindow::instance()->selectAsCurrentItem( riv->cellResult() );
|
||||
}
|
||||
return rimResultReservoir->caseId();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaImportEclipseCaseTools::addEclipseCases( const QStringList& fileNames,
|
||||
RimIdenticalGridCaseGroup** resultingCaseGroup /*=nullptr*/ )
|
||||
{
|
||||
if ( fileNames.size() == 0 ) return true;
|
||||
|
||||
// First file is read completely including grid.
|
||||
// The main grid from the first case is reused directly in for the other cases.
|
||||
// When reading active cell info, only the total cell count is tested for consistency
|
||||
RimEclipseResultCase* mainResultCase = nullptr;
|
||||
std::vector<std::vector<int>> mainCaseGridDimensions;
|
||||
RimIdenticalGridCaseGroup* gridCaseGroup = nullptr;
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
RimProject* project = app->project();
|
||||
|
||||
{
|
||||
QString firstFileName = fileNames[0];
|
||||
QFileInfo gridFileName( firstFileName );
|
||||
|
||||
QString caseName = gridFileName.completeBaseName();
|
||||
|
||||
RimEclipseResultCase* rimResultReservoir = new RimEclipseResultCase();
|
||||
rimResultReservoir->setCaseInfo( caseName, firstFileName );
|
||||
if ( !rimResultReservoir->openEclipseGridFile() )
|
||||
{
|
||||
delete rimResultReservoir;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
rimResultReservoir->readGridDimensions( mainCaseGridDimensions );
|
||||
|
||||
mainResultCase = rimResultReservoir;
|
||||
RimOilField* oilField = project->activeOilField();
|
||||
if ( oilField && oilField->analysisModels() )
|
||||
{
|
||||
gridCaseGroup = oilField->analysisModels->createIdenticalCaseGroupFromMainCase( mainResultCase );
|
||||
}
|
||||
}
|
||||
|
||||
caf::ProgressInfo info( fileNames.size(), "Reading Active Cell data" );
|
||||
|
||||
for ( int i = 1; i < fileNames.size(); i++ )
|
||||
{
|
||||
QString caseFileName = fileNames[i];
|
||||
QFileInfo gridFileName( caseFileName );
|
||||
|
||||
QString caseName = gridFileName.completeBaseName();
|
||||
|
||||
RimEclipseResultCase* rimResultReservoir = new RimEclipseResultCase();
|
||||
rimResultReservoir->setCaseInfo( caseName, caseFileName );
|
||||
|
||||
std::vector<std::vector<int>> caseGridDimensions;
|
||||
rimResultReservoir->readGridDimensions( caseGridDimensions );
|
||||
|
||||
bool identicalGrid = RigGridManager::isGridDimensionsEqual( mainCaseGridDimensions, caseGridDimensions );
|
||||
if ( identicalGrid )
|
||||
{
|
||||
if ( rimResultReservoir->openAndReadActiveCellData( mainResultCase->eclipseCaseData() ) )
|
||||
{
|
||||
RimOilField* oilField = project->activeOilField();
|
||||
if ( oilField && oilField->analysisModels() )
|
||||
{
|
||||
oilField->analysisModels()->insertCaseInCaseGroup( gridCaseGroup, rimResultReservoir );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete rimResultReservoir;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete rimResultReservoir;
|
||||
}
|
||||
|
||||
info.setProgress( i );
|
||||
}
|
||||
|
||||
if ( gridCaseGroup )
|
||||
{
|
||||
// Create placeholder results and propagate results info from main case to all other cases
|
||||
gridCaseGroup->loadMainCaseAndActiveCellInfo();
|
||||
|
||||
if ( resultingCaseGroup )
|
||||
{
|
||||
*resultingCaseGroup = gridCaseGroup;
|
||||
}
|
||||
}
|
||||
|
||||
project->activeOilField()->analysisModels()->updateConnectedEditors();
|
||||
|
||||
if ( RiaGuiApplication::isRunning() && gridCaseGroup && gridCaseGroup->statisticsCaseCollection()->reservoirs.size() > 0 )
|
||||
{
|
||||
RiuMainWindow::instance()->selectAsCurrentItem( gridCaseGroup->statisticsCaseCollection()->reservoirs[0] );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
class QString;
|
||||
class QStringList;
|
||||
|
||||
class RimIdenticalGridCaseGroup;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaImportEclipseCaseTools
|
||||
{
|
||||
public:
|
||||
typedef std::map<QString, int> FileCaseIdMap;
|
||||
|
||||
static bool openEclipseCasesFromFile( const QStringList& fileNames,
|
||||
FileCaseIdMap* openedFilesOut = nullptr,
|
||||
bool noDialog = false );
|
||||
static bool openEclipseCaseShowTimeStepFilter( const QString& fileName );
|
||||
|
||||
static bool openEclipseInputCaseFromFileNames( const QStringList& fileNames, QString* fileContainingGrid = nullptr );
|
||||
static bool openMockModel( const QString& name );
|
||||
|
||||
static bool addEclipseCases( const QStringList& fileNames, RimIdenticalGridCaseGroup** resultingCaseGroup = nullptr );
|
||||
|
||||
private:
|
||||
static int openEclipseCaseFromFile( const QString& fileName );
|
||||
static int openEclipseCaseShowTimeStepFilterImpl( const QString& fileName, bool showTimeStepFilter );
|
||||
};
|
||||
212
ApplicationLibCode/Application/Tools/RiaInterpolationTools.cpp
Normal file
212
ApplicationLibCode/Application/Tools/RiaInterpolationTools.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020 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 "RiaInterpolationTools.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool almostEqual( double a, double b, double maxRelDiff = std::numeric_limits<double>::epsilon() * 128 )
|
||||
{
|
||||
// Calculate the difference.
|
||||
double diff = std::fabs( a - b );
|
||||
double fabsa = std::fabs( a );
|
||||
double fabsb = std::fabs( b );
|
||||
// Find the largest
|
||||
double largest = ( fabsb > fabsa ) ? fabsb : fabsa;
|
||||
return ( diff <= largest * maxRelDiff );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaInterpolationTools::linear( const std::vector<double>& x, const std::vector<double>& y, double value )
|
||||
{
|
||||
assert( x.size() == y.size() );
|
||||
|
||||
// Handle cases with only one data point.
|
||||
if ( x.size() <= 1 )
|
||||
{
|
||||
return std::numeric_limits<double>::infinity();
|
||||
}
|
||||
|
||||
// Find the lower boundary
|
||||
bool found = false;
|
||||
int lowerIndex = 0;
|
||||
for ( int i = 0; i < static_cast<int>( x.size() - 1 ); i++ )
|
||||
{
|
||||
if ( x[i] <= value && x[i + 1] >= value )
|
||||
{
|
||||
lowerIndex = i;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Value is outside of the defined range
|
||||
if ( !found )
|
||||
{
|
||||
// Check if we are just outside the boundaries
|
||||
if ( almostEqual( value, x[0] ) )
|
||||
return y[0];
|
||||
else if ( almostEqual( value, x[x.size() - 1] ) )
|
||||
return y[x.size() - 1];
|
||||
return std::numeric_limits<double>::infinity();
|
||||
}
|
||||
|
||||
int upperIndex = lowerIndex + 1;
|
||||
|
||||
double lowerX = x[lowerIndex];
|
||||
double lowerY = y[lowerIndex];
|
||||
double upperX = x[upperIndex];
|
||||
double upperY = y[upperIndex];
|
||||
|
||||
double deltaY = upperY - lowerY;
|
||||
double deltaX = upperX - lowerX;
|
||||
|
||||
return lowerY + ( ( value - lowerX ) / deltaX ) * deltaY;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaInterpolationTools::extrapolate( const std::vector<double>& x, const std::vector<double>& y, double value )
|
||||
{
|
||||
return y[0] + ( value - x[0] ) / ( x[1] - x[0] ) * ( y[1] - y[0] );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaInterpolationTools::findNextDataPoint( const std::vector<double>& values, int index )
|
||||
{
|
||||
for ( size_t i = index; i < values.size(); i++ )
|
||||
{
|
||||
if ( values[i] != std::numeric_limits<double>::infinity() ) return static_cast<int>( i );
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaInterpolationTools::findPreviousDataPoint( const std::vector<double>& values, int index )
|
||||
{
|
||||
assert( index >= 0 );
|
||||
|
||||
for ( int i = index; i >= 0; i-- )
|
||||
{
|
||||
if ( values[i] != std::numeric_limits<double>::infinity() ) return static_cast<int>( i );
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaInterpolationTools::extrapolateRange( int start,
|
||||
int end,
|
||||
int firstPoint,
|
||||
int lastPoint,
|
||||
const std::vector<double>& x,
|
||||
std::vector<double>& y )
|
||||
{
|
||||
std::vector<double> xs = { x[firstPoint], x[lastPoint] };
|
||||
std::vector<double> ys = { y[firstPoint], y[lastPoint] };
|
||||
for ( int index = start; index < end; index++ )
|
||||
{
|
||||
y[index] = extrapolate( xs, ys, x[index] );
|
||||
}
|
||||
|
||||
return end;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaInterpolationTools::interpolateRange( int start,
|
||||
int end,
|
||||
int firstPoint,
|
||||
int lastPoint,
|
||||
const std::vector<double>& x,
|
||||
std::vector<double>& y )
|
||||
{
|
||||
assert( start <= end );
|
||||
|
||||
std::vector<double> xs = { x[firstPoint], x[lastPoint] };
|
||||
std::vector<double> ys = { y[firstPoint], y[lastPoint] };
|
||||
for ( int index = start; index < end; index++ )
|
||||
{
|
||||
y[index] = RiaInterpolationTools::linear( xs, ys, x[index] );
|
||||
}
|
||||
|
||||
return end;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaInterpolationTools::interpolateMissingValues( const std::vector<double>& x, std::vector<double>& y )
|
||||
{
|
||||
assert( x.size() == y.size() );
|
||||
|
||||
int index = 0;
|
||||
|
||||
// Previous index which is not inf
|
||||
int prevSetIndex = -1;
|
||||
|
||||
while ( index < static_cast<int>( y.size() ) )
|
||||
{
|
||||
// Missing values are inf in the input data
|
||||
if ( y[index] == std::numeric_limits<double>::infinity() )
|
||||
{
|
||||
// Find the next index with a value
|
||||
int nextSetIndex = findNextDataPoint( y, index + 1 );
|
||||
|
||||
if ( prevSetIndex == -1 )
|
||||
{
|
||||
// The first value is inf: need to find next two valid points and extrapolate
|
||||
int nextSetIndex2 = findNextDataPoint( y, nextSetIndex + 1 );
|
||||
index = extrapolateRange( index, nextSetIndex, nextSetIndex, nextSetIndex2, x, y );
|
||||
}
|
||||
else if ( nextSetIndex == -1 )
|
||||
{
|
||||
// The last value is inf: extrapolate from two last data points
|
||||
int prevSetIndex2 = findPreviousDataPoint( y, prevSetIndex - 1 );
|
||||
index = extrapolateRange( index, (int)y.size(), prevSetIndex2, prevSetIndex, x, y );
|
||||
}
|
||||
else if ( nextSetIndex != static_cast<int>( y.size() ) )
|
||||
{
|
||||
// The missing values somewhere between non-inf data: interpolate all the values
|
||||
index = interpolateRange( index, nextSetIndex, prevSetIndex, nextSetIndex, x, y );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nothing to do for the values which are not missing
|
||||
prevSetIndex = index;
|
||||
++index;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
ApplicationLibCode/Application/Tools/RiaInterpolationTools.h
Normal file
50
ApplicationLibCode/Application/Tools/RiaInterpolationTools.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020 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 <vector>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaInterpolationTools
|
||||
{
|
||||
public:
|
||||
static double linear( const std::vector<double>& x, const std::vector<double>& y, double value );
|
||||
|
||||
// Interpolate/extrapolate away inf values in y vector.
|
||||
static void interpolateMissingValues( const std::vector<double>& x, std::vector<double>& y );
|
||||
|
||||
private:
|
||||
static int interpolateRange( int start,
|
||||
int end,
|
||||
int firstPoint,
|
||||
int lastPoint,
|
||||
const std::vector<double>& x,
|
||||
std::vector<double>& y );
|
||||
static int extrapolateRange( int start,
|
||||
int end,
|
||||
int firstPoint,
|
||||
int lastPoint,
|
||||
const std::vector<double>& x,
|
||||
std::vector<double>& y );
|
||||
static int findNextDataPoint( const std::vector<double>& values, int index );
|
||||
static int findPreviousDataPoint( const std::vector<double>& values, int index );
|
||||
static double extrapolate( const std::vector<double>& x, const std::vector<double>& y, double value );
|
||||
};
|
||||
334
ApplicationLibCode/Application/Tools/RiaLogging.cpp
Normal file
334
ApplicationLibCode/Application/Tools/RiaLogging.cpp
Normal file
@@ -0,0 +1,334 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaLogging.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaRegressionTestRunner.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4668 )
|
||||
// Define this one to tell windows.h to not define min() and max() as macros
|
||||
#if defined WIN32 && !defined NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#pragma warning( pop )
|
||||
#else
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QString>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaDefaultConsoleLogger : public RiaLogger
|
||||
{
|
||||
public:
|
||||
RiaDefaultConsoleLogger();
|
||||
|
||||
int level() const override;
|
||||
void setLevel( int logLevel ) override;
|
||||
void error( const char* message ) override;
|
||||
void warning( const char* message ) override;
|
||||
void info( const char* message ) override;
|
||||
void debug( const char* message ) override;
|
||||
|
||||
private:
|
||||
static void writeMessageToConsole( const char* prefix, const char* message );
|
||||
static void writeToConsole( const std::string& str );
|
||||
|
||||
private:
|
||||
int m_logLevel;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaDefaultConsoleLogger::RiaDefaultConsoleLogger()
|
||||
: m_logLevel( int( RILogLevel::RI_LL_WARNING ) )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaDefaultConsoleLogger::level() const
|
||||
{
|
||||
return m_logLevel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaDefaultConsoleLogger::setLevel( int logLevel )
|
||||
{
|
||||
m_logLevel = logLevel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaDefaultConsoleLogger::error( const char* message )
|
||||
{
|
||||
writeMessageToConsole( "ERROR: ", message );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaDefaultConsoleLogger::warning( const char* message )
|
||||
{
|
||||
writeMessageToConsole( "warn: ", message );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaDefaultConsoleLogger::info( const char* message )
|
||||
{
|
||||
writeMessageToConsole( "info: ", message );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaDefaultConsoleLogger::debug( const char* message )
|
||||
{
|
||||
writeMessageToConsole( "debug: ", message );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaDefaultConsoleLogger::writeMessageToConsole( const char* prefix, const char* message )
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
// VF_ASSERT(prefix);
|
||||
oss << prefix;
|
||||
|
||||
if ( message )
|
||||
{
|
||||
oss << message << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "<no message>" << std::endl;
|
||||
}
|
||||
|
||||
writeToConsole( oss.str() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaDefaultConsoleLogger::writeToConsole( const std::string& str )
|
||||
{
|
||||
#ifdef WIN32
|
||||
AllocConsole();
|
||||
HANDLE hStdOutputHandle = GetStdHandle( STD_OUTPUT_HANDLE );
|
||||
if ( hStdOutputHandle )
|
||||
{
|
||||
DWORD stringLength = static_cast<DWORD>( str.length() );
|
||||
|
||||
unsigned long iDum = 0;
|
||||
WriteConsoleA( hStdOutputHandle, str.c_str(), stringLength, &iDum, nullptr );
|
||||
}
|
||||
#else
|
||||
fputs( str.c_str(), stderr );
|
||||
#endif
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
std::unique_ptr<RiaLogger> RiaLogging::sm_logger = std::make_unique<RiaDefaultConsoleLogger>();
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaLogger* RiaLogging::loggerInstance()
|
||||
{
|
||||
return sm_logger.get();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaLogging::setLoggerInstance( std::unique_ptr<RiaLogger> loggerInstance )
|
||||
{
|
||||
sm_logger = std::move( loggerInstance );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaLogging::error( const QString& message )
|
||||
{
|
||||
if ( sm_logger && sm_logger->level() >= int( RILogLevel::RI_LL_ERROR ) )
|
||||
{
|
||||
#pragma omp critical( critical_section_logging )
|
||||
sm_logger->error( message.toLatin1().constData() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaLogging::warning( const QString& message )
|
||||
{
|
||||
if ( sm_logger && sm_logger->level() >= int( RILogLevel::RI_LL_WARNING ) )
|
||||
{
|
||||
#pragma omp critical( critical_section_logging )
|
||||
sm_logger->warning( message.toLatin1().constData() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaLogging::info( const QString& message )
|
||||
{
|
||||
if ( sm_logger && sm_logger->level() >= int( RILogLevel::RI_LL_INFO ) )
|
||||
{
|
||||
#pragma omp critical( critical_section_logging )
|
||||
sm_logger->info( message.toLatin1().constData() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaLogging::debug( const QString& message )
|
||||
{
|
||||
if ( sm_logger && sm_logger->level() >= int( RILogLevel::RI_LL_DEBUG ) )
|
||||
{
|
||||
#pragma omp critical( critical_section_logging )
|
||||
sm_logger->debug( message.toLatin1().constData() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaLogging::errorInMessageBox( QWidget* parent, const QString& title, const QString& text )
|
||||
{
|
||||
if ( RiaGuiApplication::isRunning() && !RiaRegressionTestRunner::instance()->isRunningRegressionTests() )
|
||||
{
|
||||
QMessageBox::warning( parent, title, text );
|
||||
}
|
||||
|
||||
RiaLogging::error( text );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuMessageLoggerBase::RiuMessageLoggerBase()
|
||||
: m_logLevel( (int)RILogLevel::RI_LL_WARNING )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiuMessageLoggerBase::level() const
|
||||
{
|
||||
return m_logLevel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMessageLoggerBase::setLevel( int logLevel )
|
||||
{
|
||||
m_logLevel = logLevel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMessageLoggerBase::error( const char* message )
|
||||
{
|
||||
writeMessageWithPrefixToLogger( "ERROR: ", message );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMessageLoggerBase::warning( const char* message )
|
||||
{
|
||||
writeMessageWithPrefixToLogger( "warning: ", message );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMessageLoggerBase::info( const char* message )
|
||||
{
|
||||
writeMessageWithPrefixToLogger( "info: ", message );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMessageLoggerBase::debug( const char* message )
|
||||
{
|
||||
writeMessageWithPrefixToLogger( "debug: ", message );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMessageLoggerBase::writeMessageWithPrefixToLogger( const char* prefix, const char* message )
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << prefix;
|
||||
|
||||
if ( message )
|
||||
{
|
||||
oss << message << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "<no message>" << std::endl;
|
||||
}
|
||||
|
||||
writeMessageToLogger( oss.str() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaStdOutLogger::writeMessageToLogger( const std::string& str )
|
||||
{
|
||||
std::cout << str;
|
||||
}
|
||||
109
ApplicationLibCode/Application/Tools/RiaLogging.h
Normal file
109
ApplicationLibCode/Application/Tools/RiaLogging.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class QString;
|
||||
class QWidget;
|
||||
|
||||
enum class RILogLevel
|
||||
{
|
||||
RI_LL_ERROR = 1,
|
||||
RI_LL_WARNING = 2,
|
||||
RI_LL_INFO = 3,
|
||||
RI_LL_DEBUG = 4
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// Logger interface for the application
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaLogger
|
||||
{
|
||||
public:
|
||||
virtual ~RiaLogger() {}
|
||||
|
||||
virtual int level() const = 0;
|
||||
virtual void setLevel( int logLevel ) = 0;
|
||||
|
||||
virtual void error( const char* message ) = 0;
|
||||
virtual void warning( const char* message ) = 0;
|
||||
virtual void info( const char* message ) = 0;
|
||||
virtual void debug( const char* message ) = 0;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaLogging
|
||||
{
|
||||
public:
|
||||
static RiaLogger* loggerInstance();
|
||||
static void setLoggerInstance( std::unique_ptr<RiaLogger> loggerInstance );
|
||||
|
||||
static void error( const QString& message );
|
||||
static void warning( const QString& message );
|
||||
static void info( const QString& message );
|
||||
static void debug( const QString& message );
|
||||
|
||||
static void errorInMessageBox( QWidget* parent, const QString& title, const QString& text );
|
||||
|
||||
private:
|
||||
static std::unique_ptr<RiaLogger> sm_logger;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiuMessageLoggerBase : public RiaLogger
|
||||
{
|
||||
public:
|
||||
explicit RiuMessageLoggerBase();
|
||||
|
||||
int level() const override;
|
||||
void setLevel( int logLevel ) override;
|
||||
|
||||
void error( const char* message ) override;
|
||||
void warning( const char* message ) override;
|
||||
void info( const char* message ) override;
|
||||
void debug( const char* message ) override;
|
||||
|
||||
protected:
|
||||
virtual void writeMessageToLogger( const std::string& str ) = 0;
|
||||
|
||||
private:
|
||||
void writeMessageWithPrefixToLogger( const char* prefix, const char* message );
|
||||
|
||||
private:
|
||||
int m_logLevel;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaStdOutLogger : public RiuMessageLoggerBase
|
||||
{
|
||||
public:
|
||||
void writeMessageToLogger( const std::string& str ) override;
|
||||
};
|
||||
77
ApplicationLibCode/Application/Tools/RiaMedianCalculator.h
Normal file
77
ApplicationLibCode/Application/Tools/RiaMedianCalculator.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020- 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 "cafAssert.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
class RiaMedianCalculator
|
||||
{
|
||||
public:
|
||||
RiaMedianCalculator() = default;
|
||||
|
||||
void add( T value );
|
||||
double median() const;
|
||||
bool valid() const;
|
||||
|
||||
private:
|
||||
std::vector<T> m_values;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
void RiaMedianCalculator<T>::add( T value )
|
||||
{
|
||||
m_values.insert( std::lower_bound( m_values.begin(), m_values.end(), value ), value );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
double RiaMedianCalculator<T>::median() const
|
||||
{
|
||||
CAF_ASSERT( valid() && "You must ensure the result is valid before calling this" );
|
||||
|
||||
auto count = m_values.size();
|
||||
if ( count == 1u )
|
||||
return m_values.front();
|
||||
else if ( count % 2 == 0 )
|
||||
{
|
||||
return ( m_values[count / 2 - 1] + m_values[count / 2] ) * 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_values[count / 2];
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
bool RiaMedianCalculator<T>::valid() const
|
||||
{
|
||||
return !m_values.empty();
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "cvfVector3.h"
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
|
||||
// Y - North, X - East, Z - up but depth is negative Z
|
||||
// azi is measured from the Northing (Y) Axis in Clockwise direction looking down
|
||||
// inc is measured from the negative Z (depth) axis
|
||||
|
||||
const double singularityEpsilon = 1.0e-5;
|
||||
|
||||
class RiaOffshoreSphericalCoords
|
||||
{
|
||||
public:
|
||||
explicit RiaOffshoreSphericalCoords( const cvf::Vec3f& vec )
|
||||
{
|
||||
// Azimuth:
|
||||
if ( fabs( vec[0] ) < singularityEpsilon && fabs( vec[1] ) < singularityEpsilon )
|
||||
incAziR[1] = 0.0f;
|
||||
else
|
||||
incAziR[1] = atan2( vec[0], vec[1] ); // atan2(Y, X)
|
||||
|
||||
// R
|
||||
incAziR[2] = vec.length();
|
||||
|
||||
// Inclination from vertical down
|
||||
if ( fabs( incAziR[2] ) < singularityEpsilon )
|
||||
incAziR[0] = 0.0f;
|
||||
else
|
||||
incAziR[0] = acos( -vec[2] / incAziR[2] );
|
||||
}
|
||||
|
||||
explicit RiaOffshoreSphericalCoords( const cvf::Vec3d& vec )
|
||||
{
|
||||
// Azimuth:
|
||||
if ( fabs( vec[0] ) < singularityEpsilon && fabs( vec[1] ) < singularityEpsilon )
|
||||
incAziR[1] = 0.0;
|
||||
else
|
||||
incAziR[1] = atan2( vec[0], vec[1] ); // atan2(Y, X)
|
||||
|
||||
// R
|
||||
incAziR[2] = vec.length();
|
||||
|
||||
// Inclination from vertical down
|
||||
if ( fabs( incAziR[2] ) < singularityEpsilon )
|
||||
incAziR[0] = 0.0;
|
||||
else
|
||||
incAziR[0] = acos( -vec[2] / incAziR[2] );
|
||||
}
|
||||
double inc() const { return incAziR[0]; }
|
||||
double azi() const { return incAziR[1]; }
|
||||
double r() const { return incAziR[2]; }
|
||||
|
||||
// Note that this is a double function, while the rest of the class is float.
|
||||
// Todo: Convert class to a template to enable float and double versions of everything
|
||||
static cvf::Vec3d unitVectorFromAziInc( double azimuth, double inclination )
|
||||
{
|
||||
return cvf::Vec3d( sin( azimuth ) * sin( inclination ), cos( azimuth ) * sin( inclination ), -cos( inclination ) );
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<double, 3> incAziR;
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaOptionItemFactory.h"
|
||||
|
||||
#include "Rim3dView.h"
|
||||
#include "RimCase.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOptionItemFactory::appendOptionItemFromViewNameAndCaseName( Rim3dView* view,
|
||||
QList<caf::PdmOptionItemInfo>* optionItems )
|
||||
{
|
||||
if ( !view || !optionItems ) return;
|
||||
|
||||
QString displayName = view->autoName();
|
||||
|
||||
caf::IconProvider iconProvider = view->uiCapability()->uiIconProvider();
|
||||
|
||||
optionItems->push_back( caf::PdmOptionItemInfo( displayName, view, false, iconProvider ) );
|
||||
}
|
||||
31
ApplicationLibCode/Application/Tools/RiaOptionItemFactory.h
Normal file
31
ApplicationLibCode/Application/Tools/RiaOptionItemFactory.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "cafPdmUiItem.h"
|
||||
|
||||
#include <QList>
|
||||
|
||||
class Rim3dView;
|
||||
|
||||
class RiaOptionItemFactory
|
||||
{
|
||||
public:
|
||||
static void appendOptionItemFromViewNameAndCaseName( Rim3dView* view, QList<caf::PdmOptionItemInfo>* optionItems );
|
||||
};
|
||||
@@ -0,0 +1,159 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaProjectFileVersionTools.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectFileVersionTools::isCandidateVersionNewerThanOther( const QString& candidateProjectFileVersion,
|
||||
const QString& projectFileVersion )
|
||||
{
|
||||
int candidateMajorVersion = 0;
|
||||
int candidateMinorVersion = 0;
|
||||
int candidatePatchNumber = 0;
|
||||
int candidateDevelopmentId = 0;
|
||||
|
||||
RiaProjectFileVersionTools::decodeVersionString( candidateProjectFileVersion,
|
||||
&candidateMajorVersion,
|
||||
&candidateMinorVersion,
|
||||
&candidatePatchNumber,
|
||||
&candidateDevelopmentId );
|
||||
|
||||
int majorVersion = 0;
|
||||
int minorVersion = 0;
|
||||
int patchNumber = 0;
|
||||
int developmentId = 0;
|
||||
|
||||
RiaProjectFileVersionTools::decodeVersionString( projectFileVersion,
|
||||
&majorVersion,
|
||||
&minorVersion,
|
||||
&patchNumber,
|
||||
&developmentId );
|
||||
|
||||
return RiaProjectFileVersionTools::isCandidateNewerThanOther( candidateMajorVersion,
|
||||
candidateMinorVersion,
|
||||
candidatePatchNumber,
|
||||
candidateDevelopmentId,
|
||||
majorVersion,
|
||||
minorVersion,
|
||||
patchNumber,
|
||||
developmentId );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectFileVersionTools::decodeVersionString( const QString& projectFileVersion,
|
||||
int* majorVersion,
|
||||
int* minorVersion,
|
||||
int* patch,
|
||||
int* developmentId )
|
||||
{
|
||||
if ( projectFileVersion.isEmpty() ) return;
|
||||
|
||||
QStringList subStrings = projectFileVersion.split( "." );
|
||||
|
||||
if ( subStrings.size() > 0 )
|
||||
{
|
||||
*majorVersion = subStrings[0].toInt();
|
||||
}
|
||||
|
||||
if ( subStrings.size() > 1 )
|
||||
{
|
||||
*minorVersion = subStrings[1].toInt();
|
||||
}
|
||||
|
||||
if ( subStrings.size() > 2 )
|
||||
{
|
||||
QString candidate = subStrings[2];
|
||||
QString candidateDigitsOnly = RiaProjectFileVersionTools::stringOfDigits( candidate );
|
||||
|
||||
*patch = candidateDigitsOnly.toInt();
|
||||
}
|
||||
|
||||
if ( subStrings.size() > 3 )
|
||||
{
|
||||
QString candidate = subStrings.back();
|
||||
QString candidateDigitsOnly = RiaProjectFileVersionTools::stringOfDigits( candidate );
|
||||
|
||||
*developmentId = candidateDigitsOnly.toInt();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectFileVersionTools::isCandidateNewerThanOther( int candidateMajorVersion,
|
||||
int candidateMinorVersion,
|
||||
int candidatePatchNumber,
|
||||
int candidateDevelopmentId,
|
||||
int otherMajorVersion,
|
||||
int otherMinorVersion,
|
||||
int otherPatchNumber,
|
||||
int otherDevelopmentId )
|
||||
{
|
||||
if ( candidateMajorVersion != otherMajorVersion )
|
||||
{
|
||||
return ( candidateMajorVersion > otherMajorVersion );
|
||||
}
|
||||
|
||||
if ( candidateMinorVersion != otherMinorVersion )
|
||||
{
|
||||
return ( candidateMinorVersion > otherMinorVersion );
|
||||
}
|
||||
|
||||
if ( candidatePatchNumber != otherPatchNumber )
|
||||
{
|
||||
return ( candidatePatchNumber > otherPatchNumber );
|
||||
}
|
||||
|
||||
if ( candidateDevelopmentId != otherDevelopmentId )
|
||||
{
|
||||
return ( candidateDevelopmentId > otherDevelopmentId );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaProjectFileVersionTools::stringOfDigits( const QString& string )
|
||||
{
|
||||
QString digitsOnly;
|
||||
|
||||
for ( const auto& c : string )
|
||||
{
|
||||
if ( c.isDigit() )
|
||||
{
|
||||
digitsOnly += c;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !digitsOnly.isEmpty() )
|
||||
{
|
||||
return digitsOnly;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return digitsOnly;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaProjectFileVersionTools
|
||||
{
|
||||
public:
|
||||
static bool isCandidateVersionNewerThanOther( const QString& candidateProjectFileVersion,
|
||||
const QString& otherProjectFileVersion );
|
||||
|
||||
// Public to be able to unit test function, not intended to be used
|
||||
static void decodeVersionString( const QString& projectFileVersion,
|
||||
int* majorVersion,
|
||||
int* minorVersion,
|
||||
int* patch,
|
||||
int* developmentId );
|
||||
|
||||
private:
|
||||
static bool isCandidateNewerThanOther( int candidateMajorVersion,
|
||||
int candidateMinorVersion,
|
||||
int candidatePatchNumber,
|
||||
int candidateDevelopmentId,
|
||||
int otherMajorVersion,
|
||||
int otherMinorVersion,
|
||||
int otherPatchNumber,
|
||||
int otherDevelopmentId );
|
||||
|
||||
static QString stringOfDigits( const QString& string );
|
||||
};
|
||||
354
ApplicationLibCode/Application/Tools/RiaProjectModifier.cpp
Normal file
354
ApplicationLibCode/Application/Tools/RiaProjectModifier.cpp
Normal file
@@ -0,0 +1,354 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
// 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 "RiaProjectModifier.h"
|
||||
|
||||
#include "RimCaseCollection.h"
|
||||
#include "RimEclipseCaseCollection.h"
|
||||
#include "RimEclipseInputCase.h"
|
||||
#include "RimEclipseResultCase.h"
|
||||
#include "RimGeoMechCase.h"
|
||||
#include "RimIdenticalGridCaseGroup.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaProjectModifier::RiaProjectModifier()
|
||||
: m_invalidateExternalFilePaths( false )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplaceCaseFirstOccurrence( const QString& newGridFileName )
|
||||
{
|
||||
m_caseIdToGridFileNameMap[RiaProjectModifier::firstOccurrenceId()] = makeFilePathAbsolute( newGridFileName );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplaceCase( int caseIdToReplace, const QString& newGridFileName )
|
||||
{
|
||||
if ( caseIdToReplace >= 0 )
|
||||
{
|
||||
m_caseIdToGridFileNameMap[caseIdToReplace] = makeFilePathAbsolute( newGridFileName );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplaceSourceCasesFirstOccurrence( const std::vector<QString>& newGridFileNames )
|
||||
{
|
||||
m_groupIdToGridFileNamesMap[RiaProjectModifier::firstOccurrenceId()] = newGridFileNames;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplaceSourceCasesById( int caseGroupIdToReplace, const std::vector<QString>& newGridFileNames )
|
||||
{
|
||||
if ( caseGroupIdToReplace >= 0 )
|
||||
{
|
||||
m_groupIdToGridFileNamesMap[caseGroupIdToReplace] = newGridFileNames;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplacePropertiesFolderFirstOccurrence( QString newPropertiesFolder )
|
||||
{
|
||||
m_caseIdToPropertiesFolderMap[RiaProjectModifier::firstOccurrenceId()] = makeFilePathAbsolute( newPropertiesFolder );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplacePropertiesFolder( int caseIdToReplace, QString newPropertiesFolder )
|
||||
{
|
||||
if ( caseIdToReplace >= 0 )
|
||||
{
|
||||
m_caseIdToPropertiesFolderMap[caseIdToReplace] = makeFilePathAbsolute( newPropertiesFolder );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setInvalidateExternalFilePaths()
|
||||
{
|
||||
m_invalidateExternalFilePaths = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::invalidateExternalFilePaths( RimProject* project )
|
||||
{
|
||||
std::vector<caf::FilePath*> filePaths = project->allFilePaths();
|
||||
|
||||
const QString invalidPath = "path_does_not_exist";
|
||||
for ( caf::FilePath* filePath : filePaths )
|
||||
{
|
||||
filePath->setPath( invalidPath );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectModifier::applyModificationsToProject( RimProject* project )
|
||||
{
|
||||
if ( m_caseIdToGridFileNameMap.size() > 0 )
|
||||
{
|
||||
replaceCase( project );
|
||||
}
|
||||
|
||||
if ( m_groupIdToGridFileNamesMap.size() > 0 )
|
||||
{
|
||||
replaceSourceCases( project );
|
||||
}
|
||||
|
||||
if ( m_caseIdToPropertiesFolderMap.size() > 0 )
|
||||
{
|
||||
replacePropertiesFolder( project );
|
||||
}
|
||||
|
||||
if ( m_invalidateExternalFilePaths )
|
||||
{
|
||||
invalidateExternalFilePaths( project );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::replaceSourceCases( RimProject* project )
|
||||
{
|
||||
for ( RimOilField* oilField : project->oilFields() )
|
||||
{
|
||||
RimEclipseCaseCollection* analysisModels = oilField ? oilField->analysisModels() : nullptr;
|
||||
if ( analysisModels )
|
||||
{
|
||||
for ( RimIdenticalGridCaseGroup* caseGroup : analysisModels->caseGroups )
|
||||
{
|
||||
for ( auto item : m_groupIdToGridFileNamesMap )
|
||||
{
|
||||
int groupIdToReplace = item.first;
|
||||
if ( groupIdToReplace == RiaProjectModifier::firstOccurrenceId() )
|
||||
{
|
||||
groupIdToReplace = firstGroupId( project );
|
||||
}
|
||||
|
||||
if ( groupIdToReplace == caseGroup->groupId() )
|
||||
{
|
||||
RimCaseCollection* caseCollection = caseGroup->caseCollection;
|
||||
caseCollection->reservoirs.deleteAllChildObjects();
|
||||
|
||||
for ( QString fileName : item.second )
|
||||
{
|
||||
QString caseName = caseNameFromGridFileName( fileName );
|
||||
|
||||
// Use this slightly hackish method in order to get a new unique ID
|
||||
RimEclipseResultCase* resCase = new RimEclipseResultCase;
|
||||
resCase->setCaseInfo( caseName, fileName );
|
||||
|
||||
caseCollection->reservoirs.push_back( resCase );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::replaceCase( RimProject* project )
|
||||
{
|
||||
std::vector<RimCase*> allCases;
|
||||
project->allCases( allCases );
|
||||
|
||||
for ( RimCase* rimCase : allCases )
|
||||
{
|
||||
RimEclipseResultCase* eclipseResultCase = dynamic_cast<RimEclipseResultCase*>( rimCase );
|
||||
RimGeoMechCase* geomechCase = dynamic_cast<RimGeoMechCase*>( rimCase );
|
||||
if ( eclipseResultCase || geomechCase )
|
||||
{
|
||||
for ( auto item : m_caseIdToGridFileNameMap )
|
||||
{
|
||||
int caseIdToReplace = item.first;
|
||||
if ( caseIdToReplace == RiaProjectModifier::firstOccurrenceId() )
|
||||
{
|
||||
caseIdToReplace = firstCaseId( project );
|
||||
}
|
||||
|
||||
if ( caseIdToReplace == rimCase->caseId() )
|
||||
{
|
||||
QString replaceFileName = item.second;
|
||||
if ( eclipseResultCase )
|
||||
{
|
||||
eclipseResultCase->setGridFileName( replaceFileName );
|
||||
eclipseResultCase->caseUserDescription = caseNameFromGridFileName( replaceFileName );
|
||||
}
|
||||
else if ( geomechCase )
|
||||
{
|
||||
geomechCase->setGridFileName( replaceFileName );
|
||||
geomechCase->caseUserDescription = caseNameFromGridFileName( replaceFileName );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::replacePropertiesFolder( RimProject* project )
|
||||
{
|
||||
std::vector<RimCase*> allCases;
|
||||
project->allCases( allCases );
|
||||
|
||||
for ( RimCase* rimCase : allCases )
|
||||
{
|
||||
RimEclipseInputCase* inputCase = dynamic_cast<RimEclipseInputCase*>( rimCase );
|
||||
|
||||
if ( inputCase )
|
||||
{
|
||||
for ( auto item : m_caseIdToPropertiesFolderMap )
|
||||
{
|
||||
int caseIdToReplace = item.first;
|
||||
|
||||
if ( caseIdToReplace == RiaProjectModifier::firstOccurrenceId() )
|
||||
{
|
||||
caseIdToReplace = firstInputCaseId( project );
|
||||
}
|
||||
|
||||
if ( caseIdToReplace == inputCase->caseId() )
|
||||
{
|
||||
inputCase->updateAdditionalFileFolder( item.second );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Returns absolute path name to the specified file.
|
||||
///
|
||||
/// If \a relOrAbsolutePath is a relative, the current working directory for the process will be
|
||||
/// used in order to make the path absolute.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaProjectModifier::makeFilePathAbsolute( const QString& relOrAbsolutePath )
|
||||
{
|
||||
QFileInfo theFile( relOrAbsolutePath );
|
||||
theFile.makeAbsolute();
|
||||
return theFile.filePath();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaProjectModifier::caseNameFromGridFileName( const QString& fullGridFilePathName )
|
||||
{
|
||||
QFileInfo fi( fullGridFilePathName );
|
||||
|
||||
return fi.baseName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaProjectModifier::firstCaseId( RimProject* project )
|
||||
{
|
||||
std::vector<RimCase*> allCases;
|
||||
project->allCases( allCases );
|
||||
|
||||
for ( RimCase* rimCase : allCases )
|
||||
{
|
||||
RimEclipseResultCase* resultCase = dynamic_cast<RimEclipseResultCase*>( rimCase );
|
||||
if ( resultCase )
|
||||
{
|
||||
return resultCase->caseId();
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaProjectModifier::firstGroupId( RimProject* project )
|
||||
{
|
||||
for ( size_t oilFieldIdx = 0; oilFieldIdx < project->oilFields().size(); oilFieldIdx++ )
|
||||
{
|
||||
RimOilField* oilField = project->oilFields[oilFieldIdx];
|
||||
RimEclipseCaseCollection* analysisModels = oilField ? oilField->analysisModels() : nullptr;
|
||||
if ( analysisModels )
|
||||
{
|
||||
if ( analysisModels->caseGroups.size() > 0 )
|
||||
{
|
||||
return analysisModels->caseGroups[0]->groupId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaProjectModifier::firstInputCaseId( RimProject* project )
|
||||
{
|
||||
std::vector<RimCase*> allCases;
|
||||
project->allCases( allCases );
|
||||
|
||||
for ( RimCase* rimCase : allCases )
|
||||
{
|
||||
RimEclipseInputCase* resultCase = dynamic_cast<RimEclipseInputCase*>( rimCase );
|
||||
if ( resultCase )
|
||||
{
|
||||
return resultCase->caseId();
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaProjectModifier::firstOccurrenceId()
|
||||
{
|
||||
return -999;
|
||||
}
|
||||
76
ApplicationLibCode/Application/Tools/RiaProjectModifier.h
Normal file
76
ApplicationLibCode/Application/Tools/RiaProjectModifier.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
// 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 "cvfObject.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class RimProject;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaProjectModifier : public cvf::Object
|
||||
{
|
||||
public:
|
||||
RiaProjectModifier();
|
||||
|
||||
void setReplaceCaseFirstOccurrence( const QString& newGridFileName );
|
||||
void setReplaceCase( int caseIdToReplace, const QString& newGridFileName );
|
||||
|
||||
void setReplaceSourceCasesFirstOccurrence( const std::vector<QString>& newGridFileNames );
|
||||
void setReplaceSourceCasesById( int caseGroupIdToReplace, const std::vector<QString>& newGridFileNames );
|
||||
|
||||
void setReplacePropertiesFolderFirstOccurrence( QString newPropertiesFolder );
|
||||
void setReplacePropertiesFolder( int caseIdToReplace, QString newPropertiesFolder );
|
||||
|
||||
// Used by the regression test system to invalidate all paths to test if the tests run as expected if external files
|
||||
// are missing/invalid
|
||||
void setInvalidateExternalFilePaths();
|
||||
|
||||
bool applyModificationsToProject( RimProject* project );
|
||||
|
||||
private:
|
||||
void replaceSourceCases( RimProject* project );
|
||||
void replaceCase( RimProject* project );
|
||||
void replacePropertiesFolder( RimProject* project );
|
||||
void invalidateExternalFilePaths( RimProject* project );
|
||||
|
||||
static QString makeFilePathAbsolute( const QString& relOrAbsolutePath );
|
||||
static QString caseNameFromGridFileName( const QString& fullGridFilePathName );
|
||||
|
||||
static int firstCaseId( RimProject* project );
|
||||
static int firstGroupId( RimProject* project );
|
||||
static int firstInputCaseId( RimProject* project );
|
||||
|
||||
static int firstOccurrenceId();
|
||||
|
||||
private:
|
||||
std::map<int, QString> m_caseIdToGridFileNameMap;
|
||||
std::map<int, std::vector<QString>> m_groupIdToGridFileNamesMap;
|
||||
std::map<int, QString> m_caseIdToPropertiesFolderMap;
|
||||
bool m_invalidateExternalFilePaths;
|
||||
};
|
||||
528
ApplicationLibCode/Application/Tools/RiaQDateTimeTools.cpp
Normal file
528
ApplicationLibCode/Application/Tools/RiaQDateTimeTools.cpp
Normal file
@@ -0,0 +1,528 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaQDateTimeTools.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QLocale>
|
||||
#include <QString>
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
#include "cafPdmUiItem.h"
|
||||
|
||||
#include <cvfAssert.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const DateTimeSpan RiaQDateTimeTools::TIMESPAN_DAY = DateTimeSpan( 0, 0, 1 );
|
||||
const DateTimeSpan RiaQDateTimeTools::TIMESPAN_WEEK = DateTimeSpan( 0, 0, 7 );
|
||||
const DateTimeSpan RiaQDateTimeTools::TIMESPAN_MONTH = DateTimeSpan( 0, 1, 0 );
|
||||
const DateTimeSpan RiaQDateTimeTools::TIMESPAN_QUARTER = DateTimeSpan( 0, 3, 0 );
|
||||
const DateTimeSpan RiaQDateTimeTools::TIMESPAN_HALFYEAR = DateTimeSpan( 0, 6, 0 );
|
||||
const DateTimeSpan RiaQDateTimeTools::TIMESPAN_YEAR = DateTimeSpan( 1, 0, 0 );
|
||||
const DateTimeSpan RiaQDateTimeTools::TIMESPAN_DECADE = DateTimeSpan( 10, 0, 0 );
|
||||
|
||||
namespace caf
|
||||
{
|
||||
// clang-format off
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaQDateTimeTools::DateFormatComponents>::setUp()
|
||||
{
|
||||
addItem( RiaQDateTimeTools::DATE_FORMAT_NONE, "NO_DATE", "No Date" );
|
||||
addItem( RiaQDateTimeTools::DATE_FORMAT_YEAR, "YEAR", "Year Only" );
|
||||
addItem( RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH, "YEAR_MONTH", "Year and Month" );
|
||||
addItem( RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH_DAY, "YEAR_MONTH_DAY", "Year, Month and Day" );
|
||||
setDefault( RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH_DAY );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaQDateTimeTools::TimeFormatComponents>::setUp()
|
||||
{
|
||||
addItem( RiaQDateTimeTools::TimeFormatComponents::TIME_FORMAT_NONE, "NO_TIME", "No Time of Day" );
|
||||
addItem( RiaQDateTimeTools::TimeFormatComponents::TIME_FORMAT_HOUR, "HOUR", "Hour Only" );
|
||||
addItem( RiaQDateTimeTools::TimeFormatComponents::TIME_FORMAT_HOUR_MINUTE, "HOUR_MINUTE", "Hour and Minute" );
|
||||
addItem( RiaQDateTimeTools::TimeFormatComponents::TIME_FORMAT_HOUR_MINUTE_SECOND, "HOUR_MINUTE_SECONDS", "Hour, Minutes and Seconds" );
|
||||
setDefault( RiaQDateTimeTools::TimeFormatComponents::TIME_FORMAT_NONE );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaQDateTimeTools::DateTimePeriod>::setUp()
|
||||
{
|
||||
addItem( RiaQDateTimeTools::DateTimePeriod::NONE, "NONE", "None" );
|
||||
addItem( RiaQDateTimeTools::DateTimePeriod::DAY, "DAY", "Day" );
|
||||
addItem( RiaQDateTimeTools::DateTimePeriod::WEEK, "WEEK", "Week" );
|
||||
addItem( RiaQDateTimeTools::DateTimePeriod::MONTH, "MONTH", "Month" );
|
||||
addItem( RiaQDateTimeTools::DateTimePeriod::QUARTER, "QUARTER", "Quarter" );
|
||||
addItem( RiaQDateTimeTools::DateTimePeriod::HALFYEAR, "HALFYEAR", "Half Year" );
|
||||
addItem( RiaQDateTimeTools::DateTimePeriod::YEAR, "YEAR", "Year" );
|
||||
addItem( RiaQDateTimeTools::DateTimePeriod::DECADE, "DECADE", "Decade" );
|
||||
setDefault( RiaQDateTimeTools::DateTimePeriod::NONE );
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
} // namespace caf
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Qt::TimeSpec RiaQDateTimeTools::currentTimeSpec()
|
||||
{
|
||||
return Qt::UTC;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
quint64 RiaQDateTimeTools::secondsInDay()
|
||||
{
|
||||
return 60 * 60 * 24;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
quint64 RiaQDateTimeTools::secondsInYear()
|
||||
{
|
||||
return 60 * 60 * 24 * 365;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::fromString( const QString& dateString, const QString& format )
|
||||
{
|
||||
QDateTime dt = QDateTime::fromString( dateString, format );
|
||||
dt.setTimeSpec( currentTimeSpec() );
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::fromYears( double years )
|
||||
{
|
||||
double yearsAfterEpoch = years - 1970.0;
|
||||
|
||||
QDateTime dt = RiaQDateTimeTools::epoch();
|
||||
|
||||
return RiaQDateTimeTools::addYears( dt, yearsAfterEpoch );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::fromTime_t( time_t t )
|
||||
{
|
||||
auto qdt = createUtcDateTime();
|
||||
qdt.setTime_t( t );
|
||||
return qdt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::addMSecs( const QDateTime& dt, double msecs )
|
||||
{
|
||||
return dt.addMSecs( msecs );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::addDays( const QDateTime& dt, double days )
|
||||
{
|
||||
double integerPart = 0.0;
|
||||
double fractionPart = 0.0;
|
||||
|
||||
fractionPart = modf( days, &integerPart );
|
||||
|
||||
QDateTime tmp = dt.addDays( integerPart );
|
||||
tmp = tmp.addSecs( fractionPart * RiaQDateTimeTools::secondsInDay() );
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::addYears( const QDateTime& dt, double years )
|
||||
{
|
||||
double integerPart = 0.0;
|
||||
double fractionPart = 0.0;
|
||||
|
||||
fractionPart = modf( years, &integerPart );
|
||||
|
||||
QDateTime tmp = dt.addYears( integerPart );
|
||||
tmp = tmp.addSecs( fractionPart * RiaQDateTimeTools::secondsInYear() );
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::addSpan( const QDateTime& dt, DateTimeSpan span )
|
||||
{
|
||||
return createUtcDateTime( dt ).addYears( span.years() ).addMonths( span.months() ).addDays( span.days() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::subtractSpan( const QDateTime& dt, DateTimeSpan span )
|
||||
{
|
||||
return createUtcDateTime( dt ).addYears( -span.years() ).addMonths( -span.months() ).addDays( -span.days() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::addPeriod( const QDateTime& dt, RiaQDateTimeTools::DateTimePeriod period )
|
||||
{
|
||||
return addSpan( dt, timeSpan( period ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::subtractPeriod( const QDateTime& dt, RiaQDateTimeTools::DateTimePeriod period )
|
||||
{
|
||||
return subtractSpan( dt, timeSpan( period ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::epoch()
|
||||
{
|
||||
// NB: Not able to use QDateTime::fromMSecsSinceEpoch as this was introduced in Qt 4.7
|
||||
|
||||
QDateTime dt;
|
||||
dt.setDate( QDate( 1970, 1, 1 ) );
|
||||
dt.setTimeSpec( currentTimeSpec() );
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::createUtcDateTime()
|
||||
{
|
||||
auto qdt = QDateTime();
|
||||
qdt.setTimeSpec( currentTimeSpec() );
|
||||
return qdt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::createUtcDateTime( const QDate& date )
|
||||
{
|
||||
auto qdt = QDateTime( date );
|
||||
qdt.setTimeSpec( currentTimeSpec() );
|
||||
return qdt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::createUtcDateTime( const QDate& date, const QTime& time )
|
||||
{
|
||||
auto qdt = QDateTime( date, time, currentTimeSpec() );
|
||||
return qdt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::createUtcDateTime( const QDateTime& dt )
|
||||
{
|
||||
auto qdt = QDateTime( dt );
|
||||
qdt.setTimeSpec( currentTimeSpec() );
|
||||
return qdt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaQDateTimeTools::lessThan( const QDateTime& dt1, const QDateTime& dt2 )
|
||||
{
|
||||
// dt1 < dt2
|
||||
return dt1.secsTo( dt2 ) > 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const DateTimeSpan RiaQDateTimeTools::timeSpan( RiaQDateTimeTools::DateTimePeriod period )
|
||||
{
|
||||
switch ( period )
|
||||
{
|
||||
case RiaQDateTimeTools::DateTimePeriod::DAY:
|
||||
return TIMESPAN_DAY;
|
||||
case RiaQDateTimeTools::DateTimePeriod::WEEK:
|
||||
return TIMESPAN_WEEK;
|
||||
case RiaQDateTimeTools::DateTimePeriod::MONTH:
|
||||
return TIMESPAN_MONTH;
|
||||
case RiaQDateTimeTools::DateTimePeriod::QUARTER:
|
||||
return TIMESPAN_QUARTER;
|
||||
case RiaQDateTimeTools::DateTimePeriod::HALFYEAR:
|
||||
return TIMESPAN_HALFYEAR;
|
||||
case RiaQDateTimeTools::DateTimePeriod::YEAR:
|
||||
return TIMESPAN_YEAR;
|
||||
case RiaQDateTimeTools::DateTimePeriod::DECADE:
|
||||
return TIMESPAN_DECADE;
|
||||
}
|
||||
CVF_ASSERT( false );
|
||||
return DateTimeSpan();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RiaQDateTimeTools::truncateTime( const QDateTime& dt, RiaQDateTimeTools::DateTimePeriod period )
|
||||
{
|
||||
int y = dt.date().year();
|
||||
int m = dt.date().month();
|
||||
int d = dt.date().day();
|
||||
int dow = dt.date().dayOfWeek();
|
||||
|
||||
switch ( period )
|
||||
{
|
||||
case RiaQDateTimeTools::DateTimePeriod::DAY:
|
||||
return createUtcDateTime( QDate( y, m, d ) );
|
||||
case RiaQDateTimeTools::DateTimePeriod::WEEK:
|
||||
return createUtcDateTime( QDate( y, m, d ).addDays( -dow + 1 ) );
|
||||
case RiaQDateTimeTools::DateTimePeriod::MONTH:
|
||||
return createUtcDateTime( QDate( y, m, 1 ) );
|
||||
case RiaQDateTimeTools::DateTimePeriod::QUARTER:
|
||||
return createUtcDateTime( QDate( y, ( ( m - 1 ) / 3 ) * 3 + 1, 1 ) );
|
||||
case RiaQDateTimeTools::DateTimePeriod::HALFYEAR:
|
||||
return createUtcDateTime( QDate( y, ( ( m - 1 ) / 6 ) * 6 + 1, 1 ) );
|
||||
case RiaQDateTimeTools::DateTimePeriod::YEAR:
|
||||
return createUtcDateTime( QDate( y, 1, 1 ) );
|
||||
case RiaQDateTimeTools::DateTimePeriod::DECADE:
|
||||
return createUtcDateTime( QDate( ( y / 10 ) * 10, 1, 1 ) );
|
||||
}
|
||||
CVF_ASSERT( false );
|
||||
return createUtcDateTime();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RiaQDateTimeTools::DateTimePeriod> RiaQDateTimeTools::dateTimePeriods()
|
||||
{
|
||||
std::vector<DateTimePeriod> allPeriods;
|
||||
|
||||
for ( size_t i = 0; i < DateTimePeriodEnum::size(); i++ )
|
||||
{
|
||||
allPeriods.push_back( DateTimePeriodEnum::fromIndex( i ) );
|
||||
}
|
||||
|
||||
return allPeriods;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaQDateTimeTools::dateTimePeriodName( RiaQDateTimeTools::DateTimePeriod period )
|
||||
{
|
||||
return DateTimePeriodEnum::uiText( period );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaQDateTimeTools::toStringUsingApplicationLocale( const QDateTime& dt, const QString& format )
|
||||
{
|
||||
// Default application locale is set in RiaMain
|
||||
// QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
|
||||
//
|
||||
// QDate/QDateTime use system locale for toString() functions
|
||||
|
||||
QLocale defaultApplicationLocale;
|
||||
|
||||
return defaultApplicationLocale.toString( dt, format );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaQDateTimeTools::createTimeFormatStringFromDates( const std::vector<QDateTime>& dates )
|
||||
{
|
||||
bool hasHoursAndMinutesInTimesteps = false;
|
||||
bool hasSecondsInTimesteps = false;
|
||||
bool hasMillisecondsInTimesteps = false;
|
||||
|
||||
for ( size_t i = 0; i < dates.size(); i++ )
|
||||
{
|
||||
if ( dates[i].time().msec() != 0.0 )
|
||||
{
|
||||
hasMillisecondsInTimesteps = true;
|
||||
hasSecondsInTimesteps = true;
|
||||
hasHoursAndMinutesInTimesteps = true;
|
||||
break;
|
||||
}
|
||||
else if ( dates[i].time().second() != 0.0 )
|
||||
{
|
||||
hasHoursAndMinutesInTimesteps = true;
|
||||
hasSecondsInTimesteps = true;
|
||||
}
|
||||
else if ( dates[i].time().hour() != 0.0 || dates[i].time().minute() != 0.0 )
|
||||
{
|
||||
hasHoursAndMinutesInTimesteps = true;
|
||||
}
|
||||
}
|
||||
|
||||
QString formatString = dateFormatString();
|
||||
if ( hasHoursAndMinutesInTimesteps )
|
||||
{
|
||||
formatString += " - hh:mm";
|
||||
if ( hasSecondsInTimesteps )
|
||||
{
|
||||
formatString += ":ss";
|
||||
if ( hasMillisecondsInTimesteps )
|
||||
{
|
||||
formatString += ".zzz";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return formatString;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaQDateTimeTools::dateFormatString()
|
||||
{
|
||||
return "dd.MMM yyyy";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QString> RiaQDateTimeTools::supportedDateFormats()
|
||||
{
|
||||
std::vector<QString> dateFormats;
|
||||
|
||||
// See enum DateFormatComponents in header
|
||||
// The semi-colon separated components are:
|
||||
// DATE_FORMAT_YEAR, ..YEAR_MONTH, ..YEAR_MONTH_DAY
|
||||
dateFormats.push_back( "yyyy;yyyy-MM;yyyy-MM-dd" );
|
||||
dateFormats.push_back( "yyyy;MMM yyyy;dd. MMM yyyy" );
|
||||
dateFormats.push_back( "yyyy;MMM yyyy;MMM dd. yyyy" );
|
||||
dateFormats.push_back( "yyyy;MM/yyyy;dd/MM/yyyy" );
|
||||
dateFormats.push_back( "yyyy;M/yyyy;d/M/yyyy" );
|
||||
dateFormats.push_back( "yyyy;M/yyyy;M/d/yyyy" );
|
||||
dateFormats.push_back( "yy;M/yy;d/M/yy" );
|
||||
dateFormats.push_back( "yy;M/yy;M/d/yy" );
|
||||
dateFormats.push_back( "yyyy;MM-yyyy;dd-MM-yyyy" );
|
||||
dateFormats.push_back( "yyyy;MM.yyyy;dd.MM.yyyy" );
|
||||
dateFormats.push_back( "yyyy;MM-yyyy;MM-dd-yyyy" );
|
||||
dateFormats.push_back( "yyyy;MM.yyyy;MM.dd.yyyy" );
|
||||
dateFormats.push_back( "yy;MM-yy;dd-MM-yy" );
|
||||
dateFormats.push_back( "yy;MM-yy;MM-dd-yy" );
|
||||
|
||||
return dateFormats;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QString> RiaQDateTimeTools::supportedTimeFormats()
|
||||
{
|
||||
std::vector<QString> timeFormats;
|
||||
|
||||
// See enum TimeFormatComponents in header
|
||||
// The semi-colon separated components are:
|
||||
// TIME_FORMAT_HOUR, ..HOUR_MINUTE, ..HOUR_MINUTE_SECOND and ..HOUR_MINUTE_MILLISECOND
|
||||
timeFormats.push_back( "HH;HH:mm;HH:mm:ss;HH:mm:ss.zzz" );
|
||||
timeFormats.push_back( "H;H:mm;H:mm:ss;H:mm:ss.zzz" );
|
||||
timeFormats.push_back( "hh AP;hh:mm AP;hh:mm:ss AP;hh:mm:ss.zzz AP" );
|
||||
timeFormats.push_back( "h AP;h:mm AP;h:mm:ss AP;h:mm:ss.zzz AP" );
|
||||
|
||||
return timeFormats;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaQDateTimeTools::dateFormatString( const QString& fullDateFormat, DateFormatComponents dateComponents )
|
||||
{
|
||||
if ( dateComponents == DATE_FORMAT_NONE ) return "";
|
||||
|
||||
QStringList allVariants = fullDateFormat.split( ";" );
|
||||
if ( static_cast<int>( dateComponents ) < allVariants.size() )
|
||||
{
|
||||
return allVariants[dateComponents];
|
||||
}
|
||||
CVF_ASSERT( false && "Date format string is malformed" );
|
||||
return "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaQDateTimeTools::timeFormatString( const QString& fullTimeFormat, TimeFormatComponents timeComponents )
|
||||
{
|
||||
if ( timeComponents == TimeFormatComponents::TIME_FORMAT_NONE ) return "";
|
||||
|
||||
QStringList allVariants = fullTimeFormat.split( ";" );
|
||||
if ( static_cast<int>( timeComponents ) < allVariants.size() )
|
||||
{
|
||||
return allVariants[static_cast<int>( timeComponents )];
|
||||
}
|
||||
CVF_ASSERT( false && "Time format string is malformed" );
|
||||
return "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QList<caf::PdmOptionItemInfo> RiaQDateTimeTools::createOptionItems( const std::vector<time_t>& timeSteps )
|
||||
{
|
||||
QList<caf::PdmOptionItemInfo> options;
|
||||
|
||||
std::vector<QDateTime> dateTimes;
|
||||
for ( time_t timeT : timeSteps )
|
||||
{
|
||||
QDateTime dateTime = RiaQDateTimeTools::fromTime_t( timeT );
|
||||
|
||||
dateTimes.push_back( dateTime );
|
||||
}
|
||||
|
||||
QString formatString = RiaQDateTimeTools::createTimeFormatStringFromDates( dateTimes );
|
||||
|
||||
for ( size_t i = 0; i < dateTimes.size(); i++ )
|
||||
{
|
||||
const auto& dt = dateTimes[i];
|
||||
QString text = RiaQDateTimeTools::toStringUsingApplicationLocale( dt, formatString );
|
||||
options.push_back( { text, static_cast<int>( i ) } );
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
175
ApplicationLibCode/Application/Tools/RiaQDateTimeTools.h
Normal file
175
ApplicationLibCode/Application/Tools/RiaQDateTimeTools.h
Normal file
@@ -0,0 +1,175 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
#include <qglobal.h>
|
||||
#include <qnamespace.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
#include <QVariant>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class QDateTime;
|
||||
class QDate;
|
||||
class QTime;
|
||||
class DateTimeSpan;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmOptionItemInfo;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaQDateTimeTools
|
||||
{
|
||||
static const DateTimeSpan TIMESPAN_DAY;
|
||||
static const DateTimeSpan TIMESPAN_WEEK;
|
||||
static const DateTimeSpan TIMESPAN_MONTH;
|
||||
static const DateTimeSpan TIMESPAN_QUARTER;
|
||||
static const DateTimeSpan TIMESPAN_HALFYEAR;
|
||||
static const DateTimeSpan TIMESPAN_YEAR;
|
||||
static const DateTimeSpan TIMESPAN_DECADE;
|
||||
|
||||
public:
|
||||
enum DateFormatComponents
|
||||
{
|
||||
DATE_FORMAT_UNSPECIFIED = -2,
|
||||
DATE_FORMAT_NONE = -1,
|
||||
DATE_FORMAT_YEAR = 0,
|
||||
DATE_FORMAT_YEAR_MONTH,
|
||||
DATE_FORMAT_YEAR_MONTH_DAY,
|
||||
DATE_FORMAT_SIZE
|
||||
};
|
||||
|
||||
enum class TimeFormatComponents
|
||||
{
|
||||
TIME_FORMAT_UNSPECIFIED = -2,
|
||||
TIME_FORMAT_NONE = -1,
|
||||
TIME_FORMAT_HOUR,
|
||||
TIME_FORMAT_HOUR_MINUTE,
|
||||
TIME_FORMAT_HOUR_MINUTE_SECOND,
|
||||
TIME_FORMAT_HOUR_MINUTE_SECOND_MILLISECOND,
|
||||
TIME_FORMAT_SIZE
|
||||
};
|
||||
|
||||
enum class DateTimePeriod
|
||||
{
|
||||
NONE = -1,
|
||||
DAY,
|
||||
WEEK,
|
||||
MONTH,
|
||||
QUARTER,
|
||||
HALFYEAR,
|
||||
YEAR,
|
||||
DECADE
|
||||
};
|
||||
using DateTimePeriodEnum = caf::AppEnum<DateTimePeriod>;
|
||||
|
||||
static Qt::TimeSpec currentTimeSpec();
|
||||
|
||||
static QDateTime fromString( const QString& dateString, const QString& format );
|
||||
static QDateTime fromYears( double years );
|
||||
static QDateTime fromTime_t( time_t t );
|
||||
|
||||
static QDateTime addMSecs( const QDateTime& dt, double msecs );
|
||||
static QDateTime addDays( const QDateTime& dt, double days );
|
||||
static QDateTime addYears( const QDateTime& dt, double years );
|
||||
static QDateTime addSpan( const QDateTime& dt, DateTimeSpan span );
|
||||
static QDateTime subtractSpan( const QDateTime& dt, DateTimeSpan span );
|
||||
static QDateTime addPeriod( const QDateTime& dt, RiaQDateTimeTools::DateTimePeriod period );
|
||||
static QDateTime subtractPeriod( const QDateTime& dt, RiaQDateTimeTools::DateTimePeriod period );
|
||||
|
||||
static QDateTime epoch();
|
||||
|
||||
static QDateTime createUtcDateTime();
|
||||
static QDateTime createUtcDateTime( const QDate& date );
|
||||
static QDateTime createUtcDateTime( const QDate& date, const QTime& time );
|
||||
static QDateTime createUtcDateTime( const QDateTime& dt );
|
||||
|
||||
static bool lessThan( const QDateTime& dt1, const QDateTime& dt2 );
|
||||
|
||||
static const DateTimeSpan timeSpan( RiaQDateTimeTools::DateTimePeriod period );
|
||||
static QDateTime truncateTime( const QDateTime& dt, RiaQDateTimeTools::DateTimePeriod period );
|
||||
|
||||
static std::vector<RiaQDateTimeTools::DateTimePeriod> dateTimePeriods();
|
||||
static QString dateTimePeriodName( RiaQDateTimeTools::DateTimePeriod period );
|
||||
|
||||
// This function uses C locale to make sure the text representation of a date is stable, independent of the locale
|
||||
// settings on local machine. Required for stable regression testing.
|
||||
static QString toStringUsingApplicationLocale( const QDateTime& dt, const QString& format );
|
||||
|
||||
static QString createTimeFormatStringFromDates( const std::vector<QDateTime>& dates );
|
||||
static QString dateFormatString();
|
||||
|
||||
static std::vector<QString> supportedDateFormats();
|
||||
static std::vector<QString> supportedTimeFormats();
|
||||
|
||||
static QString
|
||||
dateFormatString( const QString& fullDateFormat,
|
||||
DateFormatComponents dateComponents = DateFormatComponents::DATE_FORMAT_YEAR_MONTH_DAY );
|
||||
static QString
|
||||
timeFormatString( const QString& fullTimeFormat,
|
||||
TimeFormatComponents timeComponents = TimeFormatComponents::TIME_FORMAT_HOUR_MINUTE_SECOND );
|
||||
|
||||
static QList<caf::PdmOptionItemInfo> createOptionItems( const std::vector<time_t>& timeSteps );
|
||||
|
||||
private:
|
||||
static quint64 secondsInDay();
|
||||
static quint64 secondsInYear();
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class DateTimeSpan
|
||||
{
|
||||
public:
|
||||
DateTimeSpan()
|
||||
: m_years( 0 )
|
||||
, m_months( 0 )
|
||||
, m_days( 0 )
|
||||
{
|
||||
}
|
||||
DateTimeSpan( int years, int months, int days )
|
||||
: m_years( years )
|
||||
, m_months( months )
|
||||
, m_days( days )
|
||||
{
|
||||
}
|
||||
|
||||
int years() const { return m_years; }
|
||||
int months() const { return m_months; }
|
||||
int days() const { return m_days; }
|
||||
|
||||
bool isEmpty() { return m_years == 0 && m_months == 0 && m_days; }
|
||||
|
||||
private:
|
||||
int m_years;
|
||||
int m_months;
|
||||
int m_days;
|
||||
};
|
||||
135
ApplicationLibCode/Application/Tools/RiaRegressionTest.cpp
Normal file
135
ApplicationLibCode/Application/Tools/RiaRegressionTest.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// 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 "RiaRegressionTest.h"
|
||||
|
||||
#include "cafPdmSettings.h"
|
||||
#include "cafPdmUiFilePathEditor.h"
|
||||
#include "cafPdmUiTextEditor.h"
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RiaRegressionTest, "RiaRegressionTest" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaRegressionTest::RiaRegressionTest( void )
|
||||
{
|
||||
CAF_PDM_InitFieldNoDefault( &folderContainingCompareTool,
|
||||
"workingFolder",
|
||||
"Folder containing <b>compare</b>",
|
||||
"",
|
||||
"Location of compare tool from Image Magic suite",
|
||||
"" );
|
||||
folderContainingCompareTool.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &folderContainingDiffTool,
|
||||
"folderContainingDiffTool",
|
||||
"Folder containing <b>diff</b>",
|
||||
"",
|
||||
"Location of diff tool used for text compare",
|
||||
"" );
|
||||
folderContainingDiffTool.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &folderContainingGitTool,
|
||||
"folderContainingGitTool",
|
||||
"Folder containing <b>git</b>",
|
||||
"",
|
||||
"Location of git tool used for text compare",
|
||||
"" );
|
||||
folderContainingGitTool.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( ®ressionTestFolder, "regressionTestFolder", "Regression Test Folder", "", "", "" );
|
||||
regressionTestFolder.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() );
|
||||
|
||||
CAF_PDM_InitField( &showInteractiveDiffImages, "showInteractiveDiffImages", false, "Interactive Diff Images", "", "", "" );
|
||||
CAF_PDM_InitField( &useOpenMPForGeometryCreation,
|
||||
"useOpenMPForGeometryCreation",
|
||||
true,
|
||||
"Use OpenMP For Geometry Creation",
|
||||
"",
|
||||
"",
|
||||
"" );
|
||||
|
||||
CAF_PDM_InitField( &openReportInBrowser, "openReportInBrowser", false, "Open Generated Report in Browser", "", "", "" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &testFilter,
|
||||
"testFilter",
|
||||
"Test Filter",
|
||||
"",
|
||||
"If empty, all tests are executed.\nTo execute a subset of tests, specify folder names "
|
||||
"separated by ;",
|
||||
"" );
|
||||
testFilter.uiCapability()->setUiEditorTypeName( caf::PdmUiTextEditor::uiEditorTypeName() );
|
||||
|
||||
CAF_PDM_InitField( &appendTestsAfterTestFilter,
|
||||
"appendTestsAfterTestFilter",
|
||||
false,
|
||||
"Append All Tests After Test Filter",
|
||||
"",
|
||||
"",
|
||||
"" );
|
||||
|
||||
CAF_PDM_InitField( &invalidateExternalFilePaths,
|
||||
"invalidateExternalFilePaths",
|
||||
false,
|
||||
"Invalidate External File Paths",
|
||||
"",
|
||||
"",
|
||||
"" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaRegressionTest::~RiaRegressionTest( void )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaRegressionTest::writeSettingsToApplicationStore() const
|
||||
{
|
||||
caf::PdmSettings::writeFieldsToApplicationStore( this );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaRegressionTest::readSettingsFromApplicationStore()
|
||||
{
|
||||
caf::PdmSettings::readFieldsFromApplicationStore( this );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaRegressionTest::defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute )
|
||||
{
|
||||
if ( field == &folderContainingDiffTool || field == &folderContainingCompareTool ||
|
||||
field == ®ressionTestFolder || field == &folderContainingGitTool )
|
||||
{
|
||||
caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast<caf::PdmUiFilePathEditorAttribute*>( attribute );
|
||||
if ( myAttr )
|
||||
{
|
||||
myAttr->m_selectDirectory = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
52
ApplicationLibCode/Application/Tools/RiaRegressionTest.h
Normal file
52
ApplicationLibCode/Application/Tools/RiaRegressionTest.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// 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 "cafAppEnum.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
class RiaRegressionTest : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RiaRegressionTest( void );
|
||||
~RiaRegressionTest( void ) override;
|
||||
|
||||
void writeSettingsToApplicationStore() const;
|
||||
void readSettingsFromApplicationStore();
|
||||
|
||||
public:
|
||||
caf::PdmField<QString> folderContainingCompareTool;
|
||||
caf::PdmField<QString> folderContainingDiffTool;
|
||||
caf::PdmField<QString> folderContainingGitTool;
|
||||
caf::PdmField<QString> regressionTestFolder;
|
||||
caf::PdmField<QString> testFilter;
|
||||
caf::PdmField<bool> showInteractiveDiffImages;
|
||||
caf::PdmField<bool> useOpenMPForGeometryCreation;
|
||||
caf::PdmField<bool> openReportInBrowser;
|
||||
caf::PdmField<bool> appendTestsAfterTestFilter;
|
||||
caf::PdmField<bool> invalidateExternalFilePaths;
|
||||
|
||||
protected:
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute ) override;
|
||||
};
|
||||
679
ApplicationLibCode/Application/Tools/RiaRegressionTestRunner.cpp
Normal file
679
ApplicationLibCode/Application/Tools/RiaRegressionTestRunner.cpp
Normal file
@@ -0,0 +1,679 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaRegressionTestRunner.h"
|
||||
|
||||
#include "RiaGitDiff.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaImageCompareReporter.h"
|
||||
#include "RiaImageFileCompare.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaProjectModifier.h"
|
||||
#include "RiaRegressionTest.h"
|
||||
#include "RiaTextFileCompare.h"
|
||||
|
||||
#include "RicfCommandFileExecutor.h"
|
||||
|
||||
#include "Rim3dView.h"
|
||||
#include "RimCase.h"
|
||||
#include "RimMainPlotCollection.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "RiuMainWindow.h"
|
||||
#include "RiuMainWindowTools.h"
|
||||
#include "RiuPlotMainWindow.h"
|
||||
#include "RiuViewer.h"
|
||||
|
||||
#include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h"
|
||||
#include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
|
||||
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QElapsedTimer>
|
||||
#include <QMdiSubWindow>
|
||||
#include <QSettings>
|
||||
#include <QStatusBar>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
namespace RegTestNames
|
||||
{
|
||||
const QString generatedFilesFolderName = "RegTestGeneratedFiles";
|
||||
const QString baseFilesFolderName = "RegTestBaseFiles";
|
||||
const QString generatedFolderName = "RegTestGeneratedImages";
|
||||
const QString diffFolderName = "RegTestDiffImages";
|
||||
const QString baseFolderName = "RegTestBaseImages";
|
||||
const QString testProjectName = "RegressionTest";
|
||||
const QString testFolderFilter = "TestCase*";
|
||||
const QString imageCompareExeName = "compare";
|
||||
const QString reportFileName = "ResInsightRegressionTestReport.html";
|
||||
const QString commandFileFilter = "commandfile-*";
|
||||
}; // namespace RegTestNames
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void logInfoTextWithTimeInSeconds( const QElapsedTimer& time, const QString& msg )
|
||||
{
|
||||
double timeRunning = time.elapsed() / 1000.0;
|
||||
|
||||
QString timeText = QString( "(%1 s) " ).arg( timeRunning, 0, 'f', 1 );
|
||||
|
||||
RiaLogging::info( timeText + msg );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaRegressionTestRunner::RiaRegressionTestRunner()
|
||||
: m_runningRegressionTests( false )
|
||||
, m_appendAllTestsAfterLastItemInFilter( false )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaRegressionTestRunner* RiaRegressionTestRunner::instance()
|
||||
{
|
||||
static RiaRegressionTestRunner* singleton = new RiaRegressionTestRunner;
|
||||
return singleton;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaRegressionTestRunner::runRegressionTest()
|
||||
{
|
||||
m_runningRegressionTests = true;
|
||||
|
||||
QString currentApplicationPath = QDir::currentPath();
|
||||
|
||||
RiaRegressionTest regressionTestConfig;
|
||||
regressionTestConfig.readSettingsFromApplicationStore();
|
||||
if ( !regressionTestConfig.folderContainingCompareTool().isEmpty() )
|
||||
{
|
||||
// Windows Only : The image compare tool requires current working directory to be at the folder
|
||||
// containing the image compare tool
|
||||
|
||||
QDir::setCurrent( regressionTestConfig.folderContainingCompareTool() );
|
||||
}
|
||||
|
||||
QString generatedFolderName = RegTestNames::generatedFolderName;
|
||||
QString diffFolderName = RegTestNames::diffFolderName;
|
||||
QString baseFolderName = RegTestNames::baseFolderName;
|
||||
QString regTestProjectName = RegTestNames::testProjectName;
|
||||
QString regTestFolderFilter = RegTestNames::testFolderFilter;
|
||||
|
||||
QDir testDir( m_rootPath ); // If string is empty it will end up as cwd
|
||||
testDir.setFilter( QDir::Dirs );
|
||||
QStringList dirNameFilter;
|
||||
dirNameFilter.append( regTestFolderFilter );
|
||||
testDir.setNameFilters( dirNameFilter );
|
||||
|
||||
QFileInfoList folderList = subDirectoriesForTestExecution( testDir );
|
||||
|
||||
// delete diff and generated images
|
||||
|
||||
for ( const QFileInfo& fi : folderList )
|
||||
{
|
||||
QDir testCaseFolder( fi.filePath() );
|
||||
|
||||
{
|
||||
QDir genDir( testCaseFolder.filePath( generatedFolderName ) );
|
||||
removeDirectoryWithContent( genDir );
|
||||
}
|
||||
|
||||
{
|
||||
QDir diffDir( testCaseFolder.filePath( diffFolderName ) );
|
||||
removeDirectoryWithContent( diffDir );
|
||||
}
|
||||
|
||||
{
|
||||
QDir generatedFiles( testCaseFolder.filePath( RegTestNames::generatedFilesFolderName ) );
|
||||
removeDirectoryWithContent( generatedFiles );
|
||||
}
|
||||
}
|
||||
|
||||
QString htmlReportFileName =
|
||||
generateHtmlReport( folderList, baseFolderName, generatedFolderName, diffFolderName, testDir );
|
||||
|
||||
if ( regressionTestConfig.openReportInBrowser() )
|
||||
{
|
||||
QDesktopServices::openUrl( htmlReportFileName );
|
||||
}
|
||||
|
||||
RiaLogging::info( "--------------------------------------------------" );
|
||||
RiaLogging::info( QTime::currentTime().toString() + ": Launching regression tests" );
|
||||
RiaLogging::info( "--------------------------------------------------" );
|
||||
|
||||
QElapsedTimer timeStamp;
|
||||
timeStamp.start();
|
||||
logInfoTextWithTimeInSeconds( timeStamp, "Starting regression tests\n" );
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
|
||||
for ( const QFileInfo& folderFileInfo : folderList )
|
||||
{
|
||||
QDir testCaseFolder( folderFileInfo.filePath() );
|
||||
|
||||
bool anyCommandFilesExecuted =
|
||||
findAndExecuteCommandFiles( testCaseFolder, regressionTestConfig, htmlReportFileName );
|
||||
|
||||
if ( !anyCommandFilesExecuted )
|
||||
{
|
||||
QString projectFileName;
|
||||
|
||||
if ( testCaseFolder.exists( regTestProjectName + ".rip" ) )
|
||||
{
|
||||
projectFileName = regTestProjectName + ".rip";
|
||||
}
|
||||
|
||||
if ( testCaseFolder.exists( regTestProjectName + ".rsp" ) )
|
||||
{
|
||||
projectFileName = regTestProjectName + ".rsp";
|
||||
}
|
||||
|
||||
if ( !projectFileName.isEmpty() )
|
||||
{
|
||||
cvf::ref<RiaProjectModifier> projectModifier;
|
||||
if ( regressionTestConfig.invalidateExternalFilePaths )
|
||||
{
|
||||
projectModifier = cvf::make_ref<RiaProjectModifier>();
|
||||
projectModifier->setInvalidateExternalFilePaths();
|
||||
}
|
||||
logInfoTextWithTimeInSeconds( timeStamp, "Initializing test :" + testCaseFolder.absolutePath() );
|
||||
|
||||
app->loadProject( testCaseFolder.filePath( projectFileName ),
|
||||
RiaApplication::ProjectLoadAction::PLA_NONE,
|
||||
projectModifier.p() );
|
||||
|
||||
// Wait until all command objects have completed
|
||||
app->waitUntilCommandObjectsHasBeenProcessed();
|
||||
|
||||
setDefaultSnapshotSizeFor3dViews();
|
||||
|
||||
QString fullPathGeneratedFolder = testCaseFolder.absoluteFilePath( generatedFolderName );
|
||||
RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( fullPathGeneratedFolder );
|
||||
|
||||
QApplication::processEvents();
|
||||
setDefaultSnapshotSizeForPlotWindows();
|
||||
|
||||
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( fullPathGeneratedFolder );
|
||||
|
||||
app->closeProject();
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::error( "Could not find a regression test file named : " + testCaseFolder.absolutePath() +
|
||||
"/" + regTestProjectName + ".rsp" );
|
||||
}
|
||||
}
|
||||
|
||||
// Do a complete reset of project settings to avoid transfer of settings to next regression test
|
||||
app->resetProject();
|
||||
|
||||
QDir baseDir( testCaseFolder.filePath( baseFolderName ) );
|
||||
QDir genDir( testCaseFolder.filePath( generatedFolderName ) );
|
||||
QDir diffDir( testCaseFolder.filePath( diffFolderName ) );
|
||||
if ( !diffDir.exists() ) testCaseFolder.mkdir( diffFolderName );
|
||||
baseDir.setFilter( QDir::Files );
|
||||
QStringList baseImageFileNames = baseDir.entryList();
|
||||
|
||||
for ( int fIdx = 0; fIdx < baseImageFileNames.size(); ++fIdx )
|
||||
{
|
||||
QString fileName = baseImageFileNames[fIdx];
|
||||
RiaImageFileCompare imgComparator( RegTestNames::imageCompareExeName );
|
||||
bool ok = imgComparator.runComparison( genDir.filePath( fileName ),
|
||||
baseDir.filePath( fileName ),
|
||||
diffDir.filePath( fileName ) );
|
||||
if ( !ok )
|
||||
{
|
||||
qDebug() << "Error comparing :" << imgComparator.errorMessage() << "\n" << imgComparator.errorDetails();
|
||||
}
|
||||
}
|
||||
|
||||
logInfoTextWithTimeInSeconds( timeStamp, "Completed test :" + testCaseFolder.absolutePath() );
|
||||
}
|
||||
|
||||
// Invoke git diff
|
||||
|
||||
{
|
||||
QString folderContainingGit = regressionTestConfig.folderContainingGitTool();
|
||||
RiaGitDiff gitDiff( folderContainingGit );
|
||||
gitDiff.executeDiff( m_rootPath );
|
||||
|
||||
QString diffText = gitDiff.diffOutput();
|
||||
if ( !diffText.isEmpty() )
|
||||
{
|
||||
QFile file( htmlReportFileName );
|
||||
if ( file.open( QIODevice::Append | QIODevice::Text ) )
|
||||
{
|
||||
QTextStream stream( &file );
|
||||
|
||||
QString divSectionForDiff = R"(
|
||||
<div id = "destination-elem-id"[innerHtml] = "outputHtml">
|
||||
original
|
||||
</div>
|
||||
|
||||
)";
|
||||
stream << divSectionForDiff;
|
||||
stream << "</body>";
|
||||
|
||||
{
|
||||
QString generateDiffString = R"(
|
||||
<script type="text/javascript">
|
||||
|
||||
function generateDiff() {
|
||||
return `
|
||||
)";
|
||||
|
||||
generateDiffString += diffText;
|
||||
|
||||
generateDiffString += R"(
|
||||
`;
|
||||
};
|
||||
)";
|
||||
|
||||
generateDiffString += R"(
|
||||
var diffHtml = Diff2Html.getPrettyHtml(
|
||||
generateDiff(),
|
||||
{inputFormat: 'diff', showFiles: true, matching: 'lines', outputFormat: 'side-by-side'}
|
||||
);
|
||||
|
||||
document.getElementById("destination-elem-id").innerHTML = diffHtml;
|
||||
</script>
|
||||
</html>
|
||||
)";
|
||||
stream << generateDiffString;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RiaLogging::info( "\n" );
|
||||
logInfoTextWithTimeInSeconds( timeStamp, "Completed regression tests" );
|
||||
|
||||
QDir::setCurrent( currentApplicationPath );
|
||||
|
||||
m_runningRegressionTests = false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaRegressionTestRunner::findAndExecuteCommandFiles( const QDir& testCaseFolder,
|
||||
const RiaRegressionTest& regressionTestConfig,
|
||||
const QString& htmlReportFileName )
|
||||
{
|
||||
QStringList filterList;
|
||||
filterList << RegTestNames::commandFileFilter;
|
||||
|
||||
QFileInfoList commandFileEntries = testCaseFolder.entryInfoList( filterList );
|
||||
if ( commandFileEntries.empty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QString currentAbsolutePath = QDir::current().absolutePath();
|
||||
|
||||
// Set current path to the folder containing the command file, as this is required when using file references
|
||||
// in the command file
|
||||
QDir::setCurrent( testCaseFolder.path() );
|
||||
|
||||
for ( const auto& fileInfo : commandFileEntries )
|
||||
{
|
||||
QString commandFile = fileInfo.absoluteFilePath();
|
||||
|
||||
QFile file( commandFile );
|
||||
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||
{
|
||||
RiaLogging::error( "Failed to open command file : " + commandFile );
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream in( &file );
|
||||
RicfCommandFileExecutor::instance()->executeCommands( in );
|
||||
}
|
||||
}
|
||||
|
||||
QDir::setCurrent( currentAbsolutePath );
|
||||
|
||||
// Create diff based on generated folders
|
||||
{
|
||||
QString html;
|
||||
|
||||
RiaTextFileCompare textFileCompare( regressionTestConfig.folderContainingDiffTool() );
|
||||
|
||||
QString baseFilesFolderName = testCaseFolder.filePath( RegTestNames::baseFilesFolderName );
|
||||
QString generatedFilesFolderName = testCaseFolder.filePath( RegTestNames::generatedFilesFolderName );
|
||||
|
||||
QFileInfo fib( baseFilesFolderName );
|
||||
QFileInfo fig( generatedFilesFolderName );
|
||||
|
||||
if ( fib.exists() && fig.exists() )
|
||||
{
|
||||
{
|
||||
QString headerText = testCaseFolder.dirName();
|
||||
|
||||
html += "<table>\n";
|
||||
html += " <tr>\n";
|
||||
html +=
|
||||
" <td colspan=\"3\" bgcolor=\"darkblue\" height=\"40\"> <b><font color=\"white\" size=\"3\"> " +
|
||||
headerText + " </font></b> </td>\n";
|
||||
html += " </tr>\n";
|
||||
|
||||
textFileCompare.runComparison( baseFilesFolderName, generatedFilesFolderName );
|
||||
|
||||
QString diff = textFileCompare.diffOutput();
|
||||
if ( diff.isEmpty() )
|
||||
{
|
||||
html += " <tr>\n";
|
||||
html += " <td colspan=\"3\" bgcolor=\"lightgray\"> <font color=\"green\">No text diff "
|
||||
"detected</font> </td> \n";
|
||||
html += " </tr>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
html += " <tr>\n";
|
||||
html += " <td colspan=\"3\" bgcolor=\"lightgray\"> <font color=\"red\">Text diff detected - "
|
||||
"output from diff tool : </font> </td> \n";
|
||||
html += " </tr>\n";
|
||||
}
|
||||
|
||||
// Table end
|
||||
html += "</table>\n";
|
||||
|
||||
if ( !diff.isEmpty() )
|
||||
{
|
||||
html += QString( "<code> %1 </code>" ).arg( diff );
|
||||
}
|
||||
}
|
||||
|
||||
QFile file( htmlReportFileName );
|
||||
if ( file.open( QIODevice::Append | QIODevice::Text ) )
|
||||
{
|
||||
QTextStream stream( &file );
|
||||
|
||||
stream << html;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaRegressionTestRunner::generateHtmlReport( const QFileInfoList& folderList,
|
||||
const QString& baseFolderName,
|
||||
const QString& generatedFolderName,
|
||||
const QString& diffFolderName,
|
||||
const QDir& testDir )
|
||||
{
|
||||
RiaImageCompareReporter imageCompareReporter;
|
||||
|
||||
// Minor workaround
|
||||
// Use registry to define if interactive diff images should be created
|
||||
// Defined by user in RiaRegressionTest
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
bool useInteractiveDiff = settings.value( "showInteractiveDiffImages" ).toBool();
|
||||
if ( useInteractiveDiff )
|
||||
{
|
||||
imageCompareReporter.showInteractiveOnly();
|
||||
}
|
||||
}
|
||||
|
||||
for ( const QFileInfo& fi : folderList )
|
||||
{
|
||||
QDir testCaseFolder( fi.filePath() );
|
||||
|
||||
QString testFolderName = testCaseFolder.dirName();
|
||||
QString reportBaseFolderName = testCaseFolder.filePath( baseFolderName );
|
||||
QString reportGeneratedFolderName = testCaseFolder.filePath( generatedFolderName );
|
||||
QString reportDiffFolderName = testCaseFolder.filePath( diffFolderName );
|
||||
|
||||
imageCompareReporter.addImageDirectoryComparisonSet( testFolderName.toStdString(),
|
||||
reportBaseFolderName.toStdString(),
|
||||
reportGeneratedFolderName.toStdString(),
|
||||
reportDiffFolderName.toStdString() );
|
||||
}
|
||||
|
||||
QString htmlReportFileName = testDir.filePath( RegTestNames::reportFileName );
|
||||
|
||||
QString htmldiff2htmlText = diff2htmlHeaderText( m_rootPath );
|
||||
imageCompareReporter.generateHTMLReport( htmlReportFileName.toStdString(), htmldiff2htmlText.toStdString() );
|
||||
|
||||
return htmlReportFileName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaRegressionTestRunner::removeDirectoryWithContent( QDir& dirToDelete )
|
||||
{
|
||||
caf::Utils::removeDirectoryAndFilesRecursively( dirToDelete.absolutePath() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaRegressionTestRunner::setDefaultSnapshotSizeFor3dViews()
|
||||
{
|
||||
RiuMainWindow* mainWnd = RiuMainWindow::instance();
|
||||
if ( !mainWnd ) return;
|
||||
|
||||
QSize defaultSize = RiaRegressionTestRunner::regressionDefaultImageSize();
|
||||
|
||||
RiuMainWindowTools::setFixedWindowSizeFor3dViews( mainWnd, defaultSize.width(), defaultSize.height() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaRegressionTestRunner::setDefaultSnapshotSizeForPlotWindows()
|
||||
{
|
||||
RiuPlotMainWindow* plotMainWindow = RiaGuiApplication::instance()->mainPlotWindow();
|
||||
if ( !plotMainWindow ) return;
|
||||
|
||||
QSize defaultSize = RiaRegressionTestRunner::regressionDefaultImageSize();
|
||||
|
||||
RiuMainWindowTools::setWindowSizeOnWidgetsInMdiWindows( plotMainWindow, defaultSize.width(), defaultSize.height() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize RiaRegressionTestRunner::regressionDefaultImageSize()
|
||||
{
|
||||
return QSize( 1000, 745 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaRegressionTestRunner::diff2htmlHeaderText( const QString& testRootPath )
|
||||
{
|
||||
QString html;
|
||||
|
||||
QString oldProjPath = QDir::fromNativeSeparators( testRootPath );
|
||||
QStringList pathFolders = oldProjPath.split( "/", QString::KeepEmptyParts );
|
||||
|
||||
QString path;
|
||||
for ( const auto& f : pathFolders )
|
||||
{
|
||||
if ( f.compare( "ProjectFiles", Qt::CaseInsensitive ) == 0 ) break;
|
||||
path += f;
|
||||
path += "/";
|
||||
}
|
||||
|
||||
{
|
||||
html = R"(
|
||||
<!-- CSS -->
|
||||
<link rel = "stylesheet" type = "text/css" href = "dist/diff2html.css">
|
||||
|
||||
<!--Javascripts-->
|
||||
<script type = "text/javascript" src = "dist/diff2html.js"></script>
|
||||
<script type = "text/javascript" src = "dist/diff2html-ui.js"></script>
|
||||
)";
|
||||
|
||||
QString pathToDiff2html = path + "diff2html/dist/";
|
||||
html = html.replace( "dist/", pathToDiff2html );
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QFileInfoList RiaRegressionTestRunner::subDirectoriesForTestExecution( const QDir& directory )
|
||||
{
|
||||
if ( m_testFilter.isEmpty() )
|
||||
{
|
||||
QFileInfoList folderList = directory.entryInfoList();
|
||||
|
||||
return folderList;
|
||||
}
|
||||
|
||||
bool anyMatchFound = false;
|
||||
|
||||
QFileInfoList foldersMatchingTestFilter;
|
||||
|
||||
QFileInfoList folderList = directory.entryInfoList();
|
||||
for ( const auto& fi : folderList )
|
||||
{
|
||||
QString path = fi.path();
|
||||
QString baseName = fi.baseName();
|
||||
|
||||
for ( const auto& s : m_testFilter )
|
||||
{
|
||||
QString trimmed = s.trimmed();
|
||||
if ( ( m_appendAllTestsAfterLastItemInFilter && anyMatchFound ) ||
|
||||
baseName.contains( trimmed, Qt::CaseInsensitive ) )
|
||||
{
|
||||
foldersMatchingTestFilter.push_back( fi );
|
||||
anyMatchFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foldersMatchingTestFilter;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaRegressionTestRunner::executeRegressionTests()
|
||||
{
|
||||
RiaRegressionTest testConfig;
|
||||
testConfig.readSettingsFromApplicationStore();
|
||||
|
||||
QString testPath = testConfig.regressionTestFolder();
|
||||
QStringList testFilter = testConfig.testFilter().split( ";", QString::SkipEmptyParts );
|
||||
|
||||
if ( testConfig.appendTestsAfterTestFilter )
|
||||
{
|
||||
m_appendAllTestsAfterLastItemInFilter = true;
|
||||
}
|
||||
|
||||
executeRegressionTests( testPath, testFilter );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaRegressionTestRunner::executeRegressionTests( const QString& regressionTestPath, const QStringList& testFilter )
|
||||
{
|
||||
RiuMainWindow* mainWnd = RiuMainWindow::instance();
|
||||
if ( mainWnd )
|
||||
{
|
||||
mainWnd->hideAllDockWidgets();
|
||||
mainWnd->statusBar()->close();
|
||||
|
||||
mainWnd->setDefaultWindowSize();
|
||||
|
||||
m_regressionTestSettings.readSettingsFromApplicationStore();
|
||||
|
||||
m_rootPath = regressionTestPath;
|
||||
m_testFilter = testFilter;
|
||||
runRegressionTest();
|
||||
|
||||
mainWnd->loadWinGeoAndDockToolBarLayout();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaRegressionTestRunner::isRunningRegressionTests() const
|
||||
{
|
||||
return m_runningRegressionTests;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaRegressionTestRunner::useOpenMPForGeometryCreation() const
|
||||
{
|
||||
if ( !m_runningRegressionTests ) return false;
|
||||
|
||||
return m_regressionTestSettings.useOpenMPForGeometryCreation;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaRegressionTestRunner::updateRegressionTest( const QString& testRootPath )
|
||||
{
|
||||
// Find all sub folders
|
||||
|
||||
QDir testDir( testRootPath ); // If string is empty it will end up as cwd
|
||||
testDir.setFilter( QDir::Dirs );
|
||||
QStringList dirNameFilter;
|
||||
dirNameFilter.append( RegTestNames::testFolderFilter );
|
||||
testDir.setNameFilters( dirNameFilter );
|
||||
|
||||
QFileInfoList folderList = testDir.entryInfoList();
|
||||
|
||||
for ( const auto& fi : folderList )
|
||||
{
|
||||
QDir testCaseFolder( fi.filePath() );
|
||||
|
||||
QDir baseDir( testCaseFolder.filePath( RegTestNames::baseFolderName ) );
|
||||
removeDirectoryWithContent( baseDir );
|
||||
testCaseFolder.mkdir( RegTestNames::baseFolderName );
|
||||
|
||||
QDir genDir( testCaseFolder.filePath( RegTestNames::generatedFolderName ) );
|
||||
|
||||
QStringList imageFileNames = genDir.entryList();
|
||||
|
||||
for ( int fIdx = 0; fIdx < imageFileNames.size(); ++fIdx )
|
||||
{
|
||||
QString fileName = imageFileNames[fIdx];
|
||||
QFile::copy( genDir.filePath( fileName ), baseDir.filePath( fileName ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RiaRegressionTest.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QSize>
|
||||
#include <QStringList>
|
||||
|
||||
class QDir;
|
||||
class RiaRegressionTest;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaRegressionTestRunner
|
||||
{
|
||||
public:
|
||||
static RiaRegressionTestRunner* instance();
|
||||
|
||||
void executeRegressionTests( const QString& regressionTestPath, const QStringList& testFilter );
|
||||
void executeRegressionTests();
|
||||
|
||||
bool isRunningRegressionTests() const;
|
||||
bool useOpenMPForGeometryCreation() const;
|
||||
|
||||
static void updateRegressionTest( const QString& testRootPath );
|
||||
|
||||
static void setDefaultSnapshotSizeFor3dViews();
|
||||
static void setDefaultSnapshotSizeForPlotWindows();
|
||||
|
||||
private:
|
||||
RiaRegressionTestRunner();
|
||||
|
||||
void runRegressionTest();
|
||||
|
||||
bool findAndExecuteCommandFiles( const QDir& testCaseFolder,
|
||||
const RiaRegressionTest& regressionTestConfig,
|
||||
const QString& htmlReportFileName );
|
||||
|
||||
QString generateHtmlReport( const QFileInfoList& folderList,
|
||||
const QString& baseFolderName,
|
||||
const QString& generatedFolderName,
|
||||
const QString& diffFolderName,
|
||||
const QDir& testDir );
|
||||
|
||||
static void removeDirectoryWithContent( QDir& dirToDelete );
|
||||
static QSize regressionDefaultImageSize();
|
||||
static QString diff2htmlHeaderText( const QString& testRootPath );
|
||||
QFileInfoList subDirectoriesForTestExecution( const QDir& directory );
|
||||
|
||||
private:
|
||||
QString m_rootPath;
|
||||
QStringList m_testFilter;
|
||||
bool m_appendAllTestsAfterLastItemInFilter;
|
||||
bool m_runningRegressionTests;
|
||||
RiaRegressionTest m_regressionTestSettings;
|
||||
};
|
||||
136
ApplicationLibCode/Application/Tools/RiaSimWellBranchTools.cpp
Normal file
136
ApplicationLibCode/Application/Tools/RiaSimWellBranchTools.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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 "RiaSimWellBranchTools.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RigEclipseCaseData.h"
|
||||
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimWellPlotTools.h"
|
||||
|
||||
#include "cafPdmUiOrdering.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<const RigWellPath*> RiaSimWellBranchTools::simulationWellBranches( const QString& simWellName,
|
||||
bool useAutoDetectionOfBranches )
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
RimProject* proj = app->project();
|
||||
|
||||
// Find first case containing the specified simulation well
|
||||
std::vector<RimEclipseCase*> simCases;
|
||||
proj->descendantsIncludingThisOfType( simCases );
|
||||
|
||||
auto caseItr = std::find_if( simCases.begin(), simCases.end(), [&simWellName]( const RimEclipseCase* eclCase ) {
|
||||
const auto& eclData = eclCase->eclipseCaseData();
|
||||
return eclData != nullptr && eclData->hasSimulationWell( simWellName );
|
||||
} );
|
||||
RimEclipseCase* eclipseCase = caseItr != simCases.end() ? *caseItr : nullptr;
|
||||
RigEclipseCaseData* eclCaseData = eclipseCase != nullptr ? eclipseCase->eclipseCaseData() : nullptr;
|
||||
return eclCaseData != nullptr ? eclCaseData->simulationWellBranches( simWellName, false, useAutoDetectionOfBranches )
|
||||
: std::vector<const RigWellPath*>();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QList<caf::PdmOptionItemInfo>
|
||||
RiaSimWellBranchTools::valueOptionsForBranchIndexField( const std::vector<const RigWellPath*>& simulationWellPaths )
|
||||
{
|
||||
QList<caf::PdmOptionItemInfo> options;
|
||||
|
||||
size_t branchCount = simulationWellPaths.size();
|
||||
if ( simulationWellPaths.size() == 0 )
|
||||
{
|
||||
options.push_front( caf::PdmOptionItemInfo( "None", -1 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int bIdx = 0; bIdx < static_cast<int>( branchCount ); ++bIdx )
|
||||
{
|
||||
options.push_back(
|
||||
caf::PdmOptionItemInfo( "Branch " + QString::number( bIdx + 1 ), QVariant::fromValue( bIdx ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSimWellBranchTools::appendSimWellBranchFieldsIfRequiredFromWellName( caf::PdmUiOrdering* uiOrdering,
|
||||
const QString& wellPathOrSimWellName,
|
||||
const caf::PdmField<bool>& branchDetectionField,
|
||||
const caf::PdmField<int>& branchIndexField )
|
||||
{
|
||||
if ( !RimWellPlotTools::hasAssociatedWellPath( wellPathOrSimWellName ) )
|
||||
{
|
||||
const QString simWellName = RimWellPlotTools::simWellName( wellPathOrSimWellName );
|
||||
|
||||
RiaSimWellBranchTools::appendSimWellBranchFieldsIfRequiredFromSimWellName( uiOrdering,
|
||||
simWellName,
|
||||
branchDetectionField,
|
||||
branchIndexField );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSimWellBranchTools::appendSimWellBranchFieldsIfRequiredFromSimWellName( caf::PdmUiOrdering* uiOrdering,
|
||||
const QString& simWellName,
|
||||
const caf::PdmField<bool>& branchDetectionField,
|
||||
const caf::PdmField<int>& branchIndexField )
|
||||
{
|
||||
if ( RiaSimWellBranchTools::simulationWellBranches( simWellName, true ).size() > 1 )
|
||||
{
|
||||
uiOrdering->add( &branchDetectionField );
|
||||
|
||||
if ( RiaSimWellBranchTools::simulationWellBranches( simWellName, branchDetectionField ).size() > 1 )
|
||||
{
|
||||
uiOrdering->add( &branchIndexField );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaSimWellBranchTools::clampBranchIndex( const QString& simWellName, int branchIndexValue, bool branchDetection )
|
||||
{
|
||||
auto branches = RiaSimWellBranchTools::simulationWellBranches( simWellName, branchDetection );
|
||||
|
||||
if ( branches.size() == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int maxIndexValue = static_cast<int>( branches.size() ) - 1;
|
||||
if ( branchIndexValue > maxIndexValue )
|
||||
{
|
||||
branchIndexValue = maxIndexValue;
|
||||
}
|
||||
|
||||
return branchIndexValue;
|
||||
}
|
||||
59
ApplicationLibCode/Application/Tools/RiaSimWellBranchTools.h
Normal file
59
ApplicationLibCode/Application/Tools/RiaSimWellBranchTools.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafPdmField.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RigWellPath;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmOptionItemInfo;
|
||||
class PdmUiOrdering;
|
||||
} // namespace caf
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaSimWellBranchTools
|
||||
{
|
||||
public:
|
||||
static std::vector<const RigWellPath*> simulationWellBranches( const QString& simWellName,
|
||||
bool useAutoDetectionOfBranches );
|
||||
|
||||
static QList<caf::PdmOptionItemInfo>
|
||||
valueOptionsForBranchIndexField( const std::vector<const RigWellPath*>& simulationWellPaths );
|
||||
|
||||
static void appendSimWellBranchFieldsIfRequiredFromWellName( caf::PdmUiOrdering* uiOrdering,
|
||||
const QString& wellPathOrSimWellName,
|
||||
const caf::PdmField<bool>& branchDetectionField,
|
||||
const caf::PdmField<int>& branchIndexField );
|
||||
|
||||
static void appendSimWellBranchFieldsIfRequiredFromSimWellName( caf::PdmUiOrdering* uiOrdering,
|
||||
const QString& simWellName,
|
||||
const caf::PdmField<bool>& branchDetectionField,
|
||||
const caf::PdmField<int>& branchIndexField );
|
||||
|
||||
static int clampBranchIndex( const QString& simWellName, int branchIndexValue, bool branchDetection );
|
||||
};
|
||||
96
ApplicationLibCode/Application/Tools/RiaStatisticsTools.cpp
Normal file
96
ApplicationLibCode/Application/Tools/RiaStatisticsTools.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 "RiaStatisticsTools.h"
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
#include "RigStatisticsMath.h"
|
||||
|
||||
#include "cafAssert.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString RiaStatisticsTools::replacePercentileByPValueText( const QString& percentile )
|
||||
{
|
||||
QString result = percentile;
|
||||
|
||||
if ( result == ENSEMBLE_STAT_P10_QUANTITY_NAME )
|
||||
{
|
||||
result = ENSEMBLE_STAT_P90_QUANTITY_NAME;
|
||||
}
|
||||
else if ( result == ENSEMBLE_STAT_P90_QUANTITY_NAME )
|
||||
{
|
||||
result = ENSEMBLE_STAT_P10_QUANTITY_NAME;
|
||||
}
|
||||
else if ( percentile.contains( QString( "%1:" ).arg( ENSEMBLE_STAT_P10_QUANTITY_NAME ) ) )
|
||||
{
|
||||
result.replace( ENSEMBLE_STAT_P10_QUANTITY_NAME, ENSEMBLE_STAT_P90_QUANTITY_NAME );
|
||||
}
|
||||
else if ( percentile.contains( QString( "%1:" ).arg( ENSEMBLE_STAT_P90_QUANTITY_NAME ) ) )
|
||||
{
|
||||
result.replace( ENSEMBLE_STAT_P90_QUANTITY_NAME, ENSEMBLE_STAT_P10_QUANTITY_NAME );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaStatisticsTools::pearsonCorrelation( const std::vector<double>& xValues, const std::vector<double>& yValues )
|
||||
{
|
||||
const double eps = 1.0e-8;
|
||||
double rangeX = 0.0, rangeY = 0.0;
|
||||
RigStatisticsMath::calculateBasicStatistics( xValues, nullptr, nullptr, nullptr, &rangeX, nullptr, nullptr );
|
||||
RigStatisticsMath::calculateBasicStatistics( yValues, nullptr, nullptr, nullptr, &rangeY, nullptr, nullptr );
|
||||
if ( rangeX < eps || rangeY < eps ) return 0.0;
|
||||
|
||||
if ( xValues.size() != yValues.size() ) return 0.0;
|
||||
if ( xValues.empty() ) return 0.0;
|
||||
|
||||
size_t sampleSize = xValues.size();
|
||||
|
||||
double meanX = 0.0, meanY = 0.0;
|
||||
for ( size_t i = 0; i < sampleSize; ++i )
|
||||
{
|
||||
meanX += xValues[i];
|
||||
meanY += yValues[i];
|
||||
}
|
||||
meanX /= sampleSize;
|
||||
meanY /= sampleSize;
|
||||
|
||||
double sumNumerator = 0.0;
|
||||
double sumxDiffSquared = 0.0, sumyDiffSquared = 0.0;
|
||||
for ( size_t i = 0; i < sampleSize; ++i )
|
||||
{
|
||||
double xDiff = xValues[i] - meanX;
|
||||
double yDiff = yValues[i] - meanY;
|
||||
sumNumerator += xDiff * yDiff;
|
||||
sumxDiffSquared += xDiff * xDiff;
|
||||
sumyDiffSquared += yDiff * yDiff;
|
||||
}
|
||||
|
||||
if ( sumxDiffSquared < eps && sumyDiffSquared < eps ) return 1.0;
|
||||
if ( sumxDiffSquared < eps || sumyDiffSquared < eps ) return 0.0;
|
||||
|
||||
return sumNumerator / ( std::sqrt( sumxDiffSquared ) * std::sqrt( sumyDiffSquared ) );
|
||||
}
|
||||
55
ApplicationLibCode/Application/Tools/RiaStatisticsTools.h
Normal file
55
ApplicationLibCode/Application/Tools/RiaStatisticsTools.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 <cmath>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
class QString;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaStatisticsTools
|
||||
{
|
||||
public:
|
||||
static const QString replacePercentileByPValueText( const QString& percentile );
|
||||
|
||||
template <class NumberType>
|
||||
static bool isInvalidNumber( NumberType value )
|
||||
{
|
||||
return !isValidNumber<NumberType>( value );
|
||||
}
|
||||
|
||||
template <class NumberType>
|
||||
static bool isValidNumber( NumberType value )
|
||||
{
|
||||
if ( std::isinf( value ) ) return false;
|
||||
if ( std::isnan( value ) ) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static double pearsonCorrelation( const std::vector<double>& xValues, const std::vector<double>& yValues );
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user