Add background data loader framework and well path loaders.

This commit is contained in:
Kristian Bendiksen 2024-06-28 12:33:19 +02:00
parent d38db625d6
commit 694d2eda66
20 changed files with 954 additions and 51 deletions

View File

@ -54,6 +54,8 @@
#include "RimEclipseView.h" #include "RimEclipseView.h"
#include "RimEnsembleWellLogsCollection.h" #include "RimEnsembleWellLogsCollection.h"
#include "RimFaultReactivationModelCollection.h" #include "RimFaultReactivationModelCollection.h"
#include "RimFileWellPath.h"
#include "RimFileWellPathDataLoader.h"
#include "RimFormationNamesCollection.h" #include "RimFormationNamesCollection.h"
#include "RimFractureTemplateCollection.h" #include "RimFractureTemplateCollection.h"
#include "RimGeoMechCase.h" #include "RimGeoMechCase.h"
@ -63,10 +65,15 @@
#include "RimGridSummaryCase.h" #include "RimGridSummaryCase.h"
#include "RimIdenticalGridCaseGroup.h" #include "RimIdenticalGridCaseGroup.h"
#include "RimMainPlotCollection.h" #include "RimMainPlotCollection.h"
#include "RimModeledWellPath.h"
#include "RimModeledWellPathDataLoader.h"
#include "RimObservedDataCollection.h" #include "RimObservedDataCollection.h"
#include "RimObservedFmuRftData.h" #include "RimObservedFmuRftData.h"
#include "RimObservedSummaryData.h" #include "RimObservedSummaryData.h"
#include "RimOilField.h" #include "RimOilField.h"
#include "RimOsduWellPath.h"
#include "RimOsduWellPathDataLoader.h"
#include "RimPlotWindow.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimScriptCollection.h" #include "RimScriptCollection.h"
#include "RimSeismicData.h" #include "RimSeismicData.h"
@ -96,6 +103,7 @@
#include "RiuViewer.h" #include "RiuViewer.h"
#include "RiuViewerCommands.h" #include "RiuViewerCommands.h"
#include "cafDataLoadController.h"
#include "cafPdmCodeGenerator.h" #include "cafPdmCodeGenerator.h"
#include "cafPdmDataValueField.h" #include "cafPdmDataValueField.h"
#include "cafPdmDefaultObjectFactory.h" #include "cafPdmDefaultObjectFactory.h"
@ -1525,6 +1533,8 @@ void RiaApplication::initialize()
m_project->setPlotTemplateFolders( m_preferences->plotTemplateFolders() ); m_project->setPlotTemplateFolders( m_preferences->plotTemplateFolders() );
caf::SelectionManager::instance()->setPdmRootObject( project() ); caf::SelectionManager::instance()->setPdmRootObject( project() );
initializeDataLoadController();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -1730,3 +1740,22 @@ RiaSumoConnector* RiaApplication::makeSumoConnector()
return m_sumoConnector; return m_sumoConnector;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication::initializeDataLoadController()
{
caf::DataLoadController* dataLoadController = caf::DataLoadController::instance();
const QString wellPathGeometryKeyword = "WELL_PATH_GEOMETRY";
dataLoadController->registerDataLoader( RimFileWellPath::classKeywordStatic(),
wellPathGeometryKeyword,
std::make_shared<RimFileWellPathDataLoader>() );
dataLoadController->registerDataLoader( RimOsduWellPath::classKeywordStatic(),
wellPathGeometryKeyword,
std::make_shared<RimOsduWellPathDataLoader>() );
dataLoadController->registerDataLoader( RimModeledWellPath::classKeywordStatic(),
wellPathGeometryKeyword,
std::make_shared<RimModeledWellPathDataLoader>() );
}

View File

@ -227,6 +227,8 @@ protected:
bool generateCode( const QString& outputPath, gsl::not_null<QString*> errMsg ); bool generateCode( const QString& outputPath, gsl::not_null<QString*> errMsg );
protected: protected:
void initializeDataLoadController();
cvf::ref<cvf::Font> m_defaultSceneFont; cvf::ref<cvf::Font> m_defaultSceneFont;
cvf::ref<cvf::Font> m_defaultAnnotationFont; cvf::ref<cvf::Font> m_defaultAnnotationFont;
cvf::ref<cvf::Font> m_defaultWellLabelFont; cvf::ref<cvf::Font> m_defaultWellLabelFont;

View File

@ -16,6 +16,9 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimWellIAModelData.h ${CMAKE_CURRENT_LIST_DIR}/RimWellIAModelData.h
${CMAKE_CURRENT_LIST_DIR}/RimWellIADataAccess.h ${CMAKE_CURRENT_LIST_DIR}/RimWellIADataAccess.h
${CMAKE_CURRENT_LIST_DIR}/RimOsduWellPath.h ${CMAKE_CURRENT_LIST_DIR}/RimOsduWellPath.h
${CMAKE_CURRENT_LIST_DIR}/RimOsduWellPathDataLoader.h
${CMAKE_CURRENT_LIST_DIR}/RimFileWellPathDataLoader.h
${CMAKE_CURRENT_LIST_DIR}/RimModeledWellPathDataLoader.h
) )
set(SOURCE_GROUP_SOURCE_FILES set(SOURCE_GROUP_SOURCE_FILES
@ -36,12 +39,18 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimWellIAModelData.cpp ${CMAKE_CURRENT_LIST_DIR}/RimWellIAModelData.cpp
${CMAKE_CURRENT_LIST_DIR}/RimWellIADataAccess.cpp ${CMAKE_CURRENT_LIST_DIR}/RimWellIADataAccess.cpp
${CMAKE_CURRENT_LIST_DIR}/RimOsduWellPath.cpp ${CMAKE_CURRENT_LIST_DIR}/RimOsduWellPath.cpp
${CMAKE_CURRENT_LIST_DIR}/RimOsduWellPathDataLoader.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFileWellPathDataLoader.cpp
${CMAKE_CURRENT_LIST_DIR}/RimModeledWellPathDataLoader.cpp
) )
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
list(APPEND CODE_SOURCE_FILES ${SOURCE_GROUP_SOURCE_FILES}) list(APPEND CODE_SOURCE_FILES ${SOURCE_GROUP_SOURCE_FILES})
list(APPEND QT_MOC_HEADERS ${CMAKE_CURRENT_LIST_DIR}/RimOsduWellPathDataLoader.h)
source_group( source_group(
"ProjectDataModel\\WellPath" "ProjectDataModel\\WellPath"
FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES}

View File

@ -0,0 +1,63 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- 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 "RimFileWellPathDataLoader.h"
#include "RiaLogging.h"
#include "RimFileWellPath.h"
#include "RigWellPath.h"
#include "cafProgressInfo.h"
#include <QApplication>
#include <QObject>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFileWellPathDataLoader::RimFileWellPathDataLoader()
: caf::DataLoader()
{
m_wellPathImporter = std::make_unique<RifWellPathImporter>();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFileWellPathDataLoader::loadData( caf::PdmObject& pdmObject, const QString& dataType, int taskId, caf::ProgressInfo& progressInfo )
{
auto* fWPath = dynamic_cast<RimFileWellPath*>( &pdmObject );
if ( fWPath && !fWPath->filePath().isEmpty() )
{
QString errorMessage;
if ( !fWPath->readWellPathFile( &errorMessage, m_wellPathImporter.get(), false ) )
{
RiaLogging::warning( errorMessage );
}
}
taskDone.send( dataType, taskId );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFileWellPathDataLoader::isRunnable() const
{
return true;
}

View File

@ -0,0 +1,45 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- 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 "RimFileWellPath.h"
#include "cafDataLoader.h"
#include "cafProgressInfo.h"
#include <QString>
#include <memory>
#include "RifWellPathImporter.h"
//==================================================================================================
///
///
//==================================================================================================
class RimFileWellPathDataLoader : public caf::DataLoader
{
public:
RimFileWellPathDataLoader();
void loadData( caf::PdmObject& pdmObject, const QString& dataType, int taskId, caf::ProgressInfo& progressInfo ) override;
bool isRunnable() const override;
private:
std::unique_ptr<RifWellPathImporter> m_wellPathImporter;
};

View File

@ -0,0 +1,54 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- 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 "RimModeledWellPathDataLoader.h"
#include "RimModeledWellPath.h"
#include "RigWellPath.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimModeledWellPathDataLoader::RimModeledWellPathDataLoader()
: caf::DataLoader()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimModeledWellPathDataLoader::loadData( caf::PdmObject& pdmObject, const QString& dataType, int taskId, caf::ProgressInfo& progressInfo )
{
auto* mWPath = dynamic_cast<RimModeledWellPath*>( &pdmObject );
if ( mWPath )
{
mWPath->createWellPathGeometry();
}
taskDone.send( dataType, taskId );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimModeledWellPathDataLoader::isRunnable() const
{
return true;
}

View File

@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- 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 "cafDataLoader.h"
#include "cafProgressInfo.h"
#include <QString>
//==================================================================================================
///
///
//==================================================================================================
class RimModeledWellPathDataLoader : public caf::DataLoader
{
public:
RimModeledWellPathDataLoader();
void loadData( caf::PdmObject& pdmObject, const QString& dataType, int taskId, caf::ProgressInfo& progressInfo ) override;
bool isRunnable() const override;
};

View File

@ -0,0 +1,109 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- 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 "RimOsduWellPathDataLoader.h"
#include "Cloud/RiaOsduConnector.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RimOsduWellPath.h"
#include "RifOsduWellPathReader.h"
#include "RigWellPath.h"
#include "cafProgressInfo.h"
#include <QApplication>
#include <QObject>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimOsduWellPathDataLoader::RimOsduWellPathDataLoader()
: caf::DataLoader()
{
RiaApplication* app = RiaApplication::instance();
RiaOsduConnector* osduConnector = app->makeOsduConnector();
connect( osduConnector,
SIGNAL( parquetDownloadFinished( const QByteArray&, const QString&, const QString& ) ),
this,
SLOT( parquetDownloadComplete( const QByteArray&, const QString&, const QString& ) ),
Qt::QueuedConnection );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimOsduWellPathDataLoader::loadData( caf::PdmObject& pdmObject, const QString& dataType, int taskId, caf::ProgressInfo& progressInfo )
{
RiaApplication* app = RiaApplication::instance();
RiaOsduConnector* osduConnector = app->makeOsduConnector();
// TODO: this is weird?
m_dataType = dataType;
auto oWPath = dynamic_cast<RimOsduWellPath*>( &pdmObject );
if ( oWPath )
{
QString trajectoryId = oWPath->wellboreTrajectoryId();
osduConnector->requestWellboreTrajectoryParquetDataById( trajectoryId );
m_wellPaths[trajectoryId] = oWPath;
m_taskIds[trajectoryId] = taskId;
}
QApplication::processEvents();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimOsduWellPathDataLoader::isRunnable() const
{
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimOsduWellPathDataLoader::parquetDownloadComplete( const QByteArray& contents, const QString& url, const QString& id )
{
RiaLogging::info( QString( "Parquet download complete. Id: %1 Size: %2" ).arg( id ).arg( contents.size() ) );
QMutexLocker lock( &m_mutex );
int taskId = m_taskIds[id];
if ( !contents.isEmpty() )
{
m_parquetData[id] = contents;
auto oWPath = m_wellPaths[id];
auto [wellPathGeometry, errorMessage] = RifOsduWellPathReader::readWellPathData( contents, oWPath->datumElevationFromOsdu() );
if ( wellPathGeometry.notNull() )
{
oWPath->setWellPathGeometry( wellPathGeometry.p() );
}
else
{
RiaLogging::warning( errorMessage );
}
}
taskDone.send( m_dataType, taskId );
}

View File

@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- 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 "RimOsduWellPath.h"
#include "cafDataLoader.h"
#include "cafProgressInfo.h"
#include <QMutex>
#include <QObject>
#include <QString>
//==================================================================================================
///
///
//==================================================================================================
class RimOsduWellPathDataLoader : public QObject, public caf::DataLoader
{
Q_OBJECT
public:
RimOsduWellPathDataLoader();
void loadData( caf::PdmObject& pdmObject, const QString& dataType, int taskId, caf::ProgressInfo& progressInfo ) override;
bool isRunnable() const override;
private slots:
void parquetDownloadComplete( const QByteArray& contents, const QString& url, const QString& id );
private:
std::map<QString, QByteArray> m_parquetData;
std::map<QString, RimOsduWellPath*> m_wellPaths;
std::map<QString, int> m_taskIds;
QString m_dataType;
QMutex m_mutex;
};

View File

@ -22,6 +22,7 @@
#include "Cloud/RiaOsduConnector.h" #include "Cloud/RiaOsduConnector.h"
#include "RiaColorTables.h" #include "RiaColorTables.h"
#include "RiaDateStringParser.h"
#include "RiaGuiApplication.h" #include "RiaGuiApplication.h"
#include "RiaLogging.h" #include "RiaLogging.h"
#include "RiaPreferences.h" #include "RiaPreferences.h"
@ -62,6 +63,8 @@
#include "Riu3DMainWindowTools.h" #include "Riu3DMainWindowTools.h"
#include "cafDataLoadController.h"
#include "cafDataLoader.h"
#include "cafPdmFieldScriptingCapability.h" #include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h" #include "cafPdmObjectScriptingCapability.h"
#include "cafPdmUiEditorHandle.h" #include "cafPdmUiEditorHandle.h"
@ -154,73 +157,47 @@ void RimWellPathCollection::loadDataAndUpdate()
RiaApplication* app = RiaApplication::instance(); RiaApplication* app = RiaApplication::instance();
caf::DataLoadController* dataLoadController = caf::DataLoadController::instance();
const QString wellPathGeometryKeyword = "WELL_PATH_GEOMETRY";
for ( RimWellPath* wellPath : allWellPaths() ) for ( RimWellPath* wellPath : allWellPaths() )
{ {
progress.setProgressDescription( QString( "Reading file %1" ).arg( wellPath->name() ) ); progress.setProgressDescription( QString( "Reading well %1" ).arg( wellPath->name() ) );
dataLoadController->loadData( *wellPath, wellPathGeometryKeyword, progress );
}
auto* fWPath = dynamic_cast<RimFileWellPath*>( wellPath ); dataLoadController->blockUntilDone( wellPathGeometryKeyword );
auto* mWPath = dynamic_cast<RimModeledWellPath*>( wellPath );
auto* oWPath = dynamic_cast<RimOsduWellPath*>( wellPath ); for ( RimWellPath* wellPath : allWellPaths() )
if ( fWPath ) {
for ( RimWellLog* wellLog : wellPath->wellLogs() )
{ {
if ( !fWPath->filePath().isEmpty() ) if ( RimWellLogFile* wellLogFile = dynamic_cast<RimWellLogFile*>( wellLog ) )
{ {
QString errorMessage; QString errorMessage;
if ( !fWPath->readWellPathFile( &errorMessage, m_wellPathImporter.get(), false ) ) if ( !wellLogFile->readFile( &errorMessage ) )
{ {
RiaLogging::warning( errorMessage ); RiaLogging::warning( errorMessage );
} }
} }
} else if ( RimOsduWellLog* osduWellLog = dynamic_cast<RimOsduWellLog*>( wellLog ) )
else if ( mWPath )
{
mWPath->createWellPathGeometry();
}
else if ( oWPath )
{
RiaOsduConnector* osduConnector = app->makeOsduConnector();
auto [wellPathGeometry, errorMessage] =
loadWellPathGeometryFromOsdu( osduConnector, oWPath->wellboreTrajectoryId(), oWPath->datumElevationFromOsdu() );
if ( wellPathGeometry.notNull() )
{ {
oWPath->setWellPathGeometry( wellPathGeometry.p() ); RiaOsduConnector* osduConnector = app->makeOsduConnector();
} auto [wellLogData, errorMessage] = loadWellLogFromOsdu( osduConnector, osduWellLog->wellLogId() );
else if ( wellLogData.notNull() )
{ {
RiaLogging::warning( errorMessage ); osduWellLog->setWellLogData( wellLogData.p() );
}
} }
} }
if ( wellPath ) RimStimPlanModelCollection* stimPlanModelCollection = wellPath->stimPlanModelCollection();
if ( stimPlanModelCollection )
{ {
for ( RimWellLog* wellLog : wellPath->wellLogs() ) for ( RimStimPlanModel* stimPlanModel : stimPlanModelCollection->allStimPlanModels() )
{ {
if ( RimWellLogFile* wellLogFile = dynamic_cast<RimWellLogFile*>( wellLog ) ) stimPlanModel->loadDataAndUpdate();
{
QString errorMessage;
if ( !wellLogFile->readFile( &errorMessage ) )
{
RiaLogging::warning( errorMessage );
}
}
else if ( RimOsduWellLog* osduWellLog = dynamic_cast<RimOsduWellLog*>( wellLog ) )
{
RiaOsduConnector* osduConnector = app->makeOsduConnector();
auto [wellLogData, errorMessage] = loadWellLogFromOsdu( osduConnector, osduWellLog->wellLogId() );
if ( wellLogData.notNull() )
{
osduWellLog->setWellLogData( wellLogData.p() );
}
}
}
RimStimPlanModelCollection* stimPlanModelCollection = wellPath->stimPlanModelCollection();
if ( stimPlanModelCollection )
{
for ( RimStimPlanModel* stimPlanModel : stimPlanModelCollection->allStimPlanModels() )
{
stimPlanModel->loadDataAndUpdate();
}
} }
} }
progress.incrementProgress(); progress.incrementProgress();

View File

@ -805,6 +805,7 @@ add_subdirectory(Fwk/AppFwk/cafProjectDataModel/cafPdmCore)
add_subdirectory(Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore) add_subdirectory(Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore)
add_subdirectory(Fwk/AppFwk/cafProjectDataModel/cafPdmXml) add_subdirectory(Fwk/AppFwk/cafProjectDataModel/cafPdmXml)
add_subdirectory(Fwk/AppFwk/cafProjectDataModel) add_subdirectory(Fwk/AppFwk/cafProjectDataModel)
add_subdirectory(Fwk/AppFwk/cafDataLoader)
add_subdirectory(Fwk/AppFwk/cafCommand) add_subdirectory(Fwk/AppFwk/cafCommand)
add_subdirectory(Fwk/AppFwk/cafUserInterface) add_subdirectory(Fwk/AppFwk/cafUserInterface)
@ -864,6 +865,7 @@ list(
cafCommand cafCommand
cafPdmCvf cafPdmCvf
cafTensor cafTensor
cafDataLoader
CommonCode CommonCode
cafVizExtensions cafVizExtensions
cafPdmScripting cafPdmScripting

View File

@ -45,6 +45,7 @@ add_subdirectory(cafCommand)
add_subdirectory(cafCommandFeatures) add_subdirectory(cafCommandFeatures)
add_subdirectory(cafUserInterface) add_subdirectory(cafUserInterface)
add_subdirectory(cafPdmScripting) add_subdirectory(cafPdmScripting)
add_subdirectory(cafDataLoader)
# executables # executables
add_subdirectory(cafTests/cafTestApplication) add_subdirectory(cafTests/cafTestApplication)

View File

@ -0,0 +1,48 @@
project(cafDataLoader)
# Unity Build
if(CAF_ENABLE_UNITY_BUILD)
message("Cmake Unity build is enabled on : ${PROJECT_NAME}")
set(CMAKE_UNITY_BUILD true)
endif()
# Qt
if(CEE_USE_QT6)
find_package(
Qt6
COMPONENTS
REQUIRED Core Gui Widgets
)
set(QT_LIBRARIES Qt6::Core Qt6::Gui Qt6::Widgets)
qt_standard_project_setup()
else()
find_package(
Qt5
COMPONENTS
REQUIRED Core Gui Widgets
)
set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::Widgets)
endif()
set(PROJECT_FILES
cafDataLoader.h
cafDataLoader.cpp
cafDataLoadTask.h
cafDataLoadTask.cpp
cafDataLoadController.h
cafDataLoadController.cpp
)
add_library(${PROJECT_NAME} ${PROJECT_FILES})
target_link_libraries(${PROJECT_NAME} cafProjectDataModel ${QT_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
if(MSVC)
set_target_properties(
${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/W4 /wd4100 /wd4127 /wd4996"
)
endif()
source_group("" FILES ${PROJECT_FILES})

View File

@ -0,0 +1,136 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cafDataLoadController.h"
#include "cafDataLoadTask.h"
#include "cafDataLoader.h"
#include "cafPdmObject.h"
#include <QApplication>
#include <QRunnable>
#include <QThreadPool>
using namespace caf;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
DataLoadController::DataLoadController()
: m_taskId( 0 )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
DataLoadController* DataLoadController::instance()
{
static DataLoadController* singleton = new DataLoadController;
return singleton;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void DataLoadController::registerDataLoader( const QString& objectType,
const QString& dataType,
std::shared_ptr<DataLoader> dataLoader )
{
std::pair<QString, QString> key = { objectType, dataType };
m_dataLoaders[key] = dataLoader;
dataLoader->taskDone.connect( this, &DataLoadController::onTaskFinished );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void DataLoadController::loadData( caf::PdmObject& object, const QString& dataType, ProgressInfo& progressInfo )
{
std::pair<QString, QString> key = { object.classKeyword(), dataType };
auto it = m_dataLoaders.find( key );
if ( it != m_dataLoaders.end() )
{
std::shared_ptr<caf::DataLoader> dataLoader = it->second;
QMutexLocker locker( &m_mutex );
m_pendingTasksByType[dataType]++;
locker.unlock();
if ( dataLoader->isRunnable() )
{
DataLoadTask* task = new DataLoadTask( *this, *dataLoader.get(), object, dataType, m_taskId++, progressInfo );
task->setAutoDelete( true );
QThreadPool::globalInstance()->start( task );
}
else
{
dataLoader->loadData( object, dataType, m_taskId++, progressInfo );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void DataLoadController::blockUntilDone( const QString& dataType )
{
int numPending = 0;
{
QMutexLocker locker( &m_mutex );
numPending = m_pendingTasksByType[dataType];
}
while ( numPending > 0 )
{
{
QMutexLocker locker( &m_mutex );
numPending = m_pendingTasksByType[dataType];
}
QApplication::processEvents();
QThread::msleep( 100 );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void DataLoadController::onTaskFinished( const caf::SignalEmitter* emitter, QString dataType, int taskId )
{
QMutexLocker locker( &m_mutex );
m_pendingTasksByType[dataType]--;
}

View File

@ -0,0 +1,86 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include "cafDataLoader.h"
#include <map>
#include <memory>
#include <QMutex>
#include <QObject>
#include <QRunnable>
#include <QString>
#include <QWaitCondition>
namespace caf
{
class ProgressInfo;
class PdmObject;
//==================================================================================================
///
//==================================================================================================
class DataLoadController : public caf::SignalObserver
{
public:
static DataLoadController* instance();
DataLoadController( const DataLoadController& ) = delete;
DataLoadController& operator=( const DataLoadController& ) = delete;
void registerDataLoader( const QString& objectType, const QString& dataType, std::shared_ptr<DataLoader> dataLoader );
void loadData( caf::PdmObject& object, const QString& dateType, ProgressInfo& progressInfo );
void blockUntilDone( const QString& dataType );
void onTaskFinished( const caf::SignalEmitter* emitter, QString dataType, int taskId );
private:
DataLoadController();
std::map<std::pair<QString, QString>, std::shared_ptr<caf::DataLoader>> m_dataLoaders;
std::map<QString, int> m_pendingTasksByType;
int m_taskId;
QMutex m_mutex;
QWaitCondition m_waitCondition;
};
} // end namespace caf

View File

@ -0,0 +1,67 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cafDataLoadTask.h"
#include "cafDataLoader.h"
#include "cafPdmObject.h"
using namespace caf;
DataLoadTask::DataLoadTask( DataLoadController& controller,
DataLoader& loader,
caf::PdmObject& object,
const QString& dataType,
int taskId,
ProgressInfo& progressInfo )
: QRunnable()
, m_dataLoadController( controller )
, m_loader( loader )
, m_object( object )
, m_dataType( dataType )
, m_taskId( taskId )
, m_progressInfo( progressInfo )
{
}
DataLoadTask::~DataLoadTask()
{
}
void DataLoadTask::run()
{
m_loader.loadData( m_object, m_dataType, m_taskId, m_progressInfo );
}

View File

@ -0,0 +1,75 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include "cafDataLoadController.h"
#include "cafDataLoader.h"
#include <QRunnable>
#include <QString>
namespace caf
{
class ProgressInfo;
class PdmObject;
class DataLoadController;
class DataLoadTask : public QRunnable
{
public:
DataLoadTask( DataLoadController& controller,
DataLoader& loader,
caf::PdmObject& object,
const QString& dataType,
int taskId,
ProgressInfo& progressInfo );
~DataLoadTask() override;
void run() override;
private:
DataLoadController& m_dataLoadController;
DataLoader& m_loader;
caf::PdmObject& m_object;
QString m_dataType;
int m_taskId;
ProgressInfo& m_progressInfo;
};
} // end namespace caf

View File

@ -0,0 +1,47 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cafDataLoader.h"
using namespace caf;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
DataLoader::DataLoader()
: taskDone( this )
{
}

View File

@ -0,0 +1,65 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include <memory>
#include <QString>
#include "cafSignal.h"
namespace caf
{
class ProgressInfo;
class PdmObject;
//==================================================================================================
///
//==================================================================================================
class DataLoader : public SignalEmitter
{
public:
DataLoader();
virtual void loadData( PdmObject& pdmObject, const QString& dataType, int taskId, ProgressInfo& progressInfo ) = 0;
virtual bool isRunnable() const = 0;
caf::Signal<QString, int> taskDone;
};
} // end namespace caf

View File

@ -58,6 +58,7 @@ add_subdirectory(AppFwk/cafCommand)
add_subdirectory(AppFwk/cafCommandFeatures) add_subdirectory(AppFwk/cafCommandFeatures)
add_subdirectory(AppFwk/cafUserInterface) add_subdirectory(AppFwk/cafUserInterface)
add_subdirectory(AppFwk/cafPdmScripting) add_subdirectory(AppFwk/cafPdmScripting)
add_subdirectory(AppFwk/cafDataLoader)
# Unit Tests # Unit Tests
add_subdirectory(AppFwk/cafProjectDataModel/cafProjectDataModel_UnitTests) add_subdirectory(AppFwk/cafProjectDataModel/cafProjectDataModel_UnitTests)