From 08dc3885a0b94a61264f6d70dc24e88670ba05c3 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 3 Jun 2024 10:43:50 +0200 Subject: [PATCH 1/3] Octave: Change default port number and add custom port number to Preferences --- .../Application/RiaApplication.cpp | 15 +++++++++- .../Application/RiaPreferences.cpp | 28 +++++++++++++++++-- .../Application/RiaPreferences.h | 13 +++++++-- .../SocketInterface/RiaSocketServer.cpp | 13 +++++++-- .../SocketInterface/RiaSocketServerDefines.h | 12 ++++++++ OctavePlugin/riGetActiveCellCenters.cpp | 2 +- OctavePlugin/riGetActiveCellCorners.cpp | 2 +- OctavePlugin/riGetActiveCellInfo.cpp | 2 +- OctavePlugin/riGetActiveCellProperty.cpp | 2 +- OctavePlugin/riGetCaseGroups.cpp | 2 +- OctavePlugin/riGetCases.cpp | 2 +- OctavePlugin/riGetCellCenters.cpp | 2 +- OctavePlugin/riGetCellCorners.cpp | 2 +- OctavePlugin/riGetCoarseningInfo.cpp | 2 +- OctavePlugin/riGetCurrentCase.cpp | 2 +- OctavePlugin/riGetDynamicNNCValues.cpp | 2 +- OctavePlugin/riGetGridDimensions.cpp | 2 +- OctavePlugin/riGetGridProperty.cpp | 2 +- .../riGetGridPropertyForSelectedCells.cpp | 2 +- OctavePlugin/riGetMainGridDimensions.cpp | 4 +-- OctavePlugin/riGetNNCConnections.cpp | 2 +- OctavePlugin/riGetNNCPropertyNames.cpp | 2 +- OctavePlugin/riGetPropertyNames.cpp | 2 +- OctavePlugin/riGetSelectedCases.cpp | 2 +- OctavePlugin/riGetSelectedCells.cpp | 2 +- OctavePlugin/riGetStaticNNCValues.cpp | 2 +- OctavePlugin/riGetTimeStepDates.cpp | 2 +- OctavePlugin/riGetTimeStepDays.cpp | 2 +- OctavePlugin/riGetWellCells.cpp | 2 +- OctavePlugin/riGetWellNames.cpp | 2 +- OctavePlugin/riGetWellStatus.cpp | 2 +- OctavePlugin/riSetActiveCellProperty.cpp | 2 +- OctavePlugin/riSetGridProperty.cpp | 2 +- OctavePlugin/riSetNNCProperty.cpp | 2 +- OctavePlugin/riSettings.h | 11 ++++++++ 35 files changed, 113 insertions(+), 39 deletions(-) diff --git a/ApplicationLibCode/Application/RiaApplication.cpp b/ApplicationLibCode/Application/RiaApplication.cpp index 7bef9598e1..313f1f8d49 100644 --- a/ApplicationLibCode/Application/RiaApplication.cpp +++ b/ApplicationLibCode/Application/RiaApplication.cpp @@ -1074,7 +1074,7 @@ QStringList RiaApplication::octaveArguments() const arguments.append( "--path" ); arguments << QApplication::applicationDirPath(); - if ( !m_preferences->octaveShowHeaderInfoWhenExecutingScripts ) + if ( !m_preferences->octaveShowHeaderInfoWhenExecutingScripts() ) { // -q // Don't print the usual greeting and version message at startup. @@ -1117,6 +1117,19 @@ QProcessEnvironment RiaApplication::octaveProcessEnvironment() const penv.insert( "LD_LIBRARY_PATH", ldPath ); #endif + // Set the environment variable for the port number used by Octave plugins + // The plugins can access the port number using riOctavePlugin::portNumber() + // If the port number is not set in preferences, the plugins will use the default port number + const QString key = QString::fromStdString( riOctavePlugin::portNumberKey() ); + if ( !m_preferences->octavePortNumber().isEmpty() ) + { + penv.insert( key, m_preferences->octavePortNumber() ); + } + else + { + penv.remove( key ); + } + return penv; } diff --git a/ApplicationLibCode/Application/RiaPreferences.cpp b/ApplicationLibCode/Application/RiaPreferences.cpp index d0ea2ebdee..5c5819524e 100644 --- a/ApplicationLibCode/Application/RiaPreferences.cpp +++ b/ApplicationLibCode/Application/RiaPreferences.cpp @@ -116,11 +116,14 @@ RiaPreferences::RiaPreferences() m_octaveExecutable.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() ); m_octaveExecutable.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::TOP ); - CAF_PDM_InitField( &octaveShowHeaderInfoWhenExecutingScripts, + CAF_PDM_InitField( &m_octaveShowHeaderInfoWhenExecutingScripts, "octaveShowHeaderInfoWhenExecutingScripts", false, "Show Text Header When Executing Scripts" ); - caf::PdmUiNativeCheckBoxEditor::configureFieldForEditor( &octaveShowHeaderInfoWhenExecutingScripts ); + caf::PdmUiNativeCheckBoxEditor::configureFieldForEditor( &m_octaveShowHeaderInfoWhenExecutingScripts ); + + CAF_PDM_InitFieldNoDefault( &m_octavePortNumber, "octavePortNumber", "Octave Port Number" ); + m_octavePortNumber.uiCapability()->setUiEditorTypeName( caf::PdmUiCheckBoxAndTextEditor::uiEditorTypeName() ); CAF_PDM_InitField( &m_pythonExecutable, "pythonExecutable", QString( "python" ), "Python Executable Location" ); m_pythonExecutable.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() ); @@ -442,7 +445,8 @@ void RiaPreferences::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& { caf::PdmUiGroup* octaveGroup = uiOrdering.addNewGroup( "Octave" ); octaveGroup->add( &m_octaveExecutable ); - octaveGroup->add( &octaveShowHeaderInfoWhenExecutingScripts ); + octaveGroup->add( &m_octaveShowHeaderInfoWhenExecutingScripts ); + octaveGroup->add( &m_octavePortNumber ); #ifdef ENABLE_GRPC caf::PdmUiGroup* pythonGroup = uiOrdering.addNewGroup( "Python" ); @@ -954,6 +958,24 @@ QString RiaPreferences::octaveExecutable() const return m_octaveExecutable().trimmed(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiaPreferences::octaveShowHeaderInfoWhenExecutingScripts() const +{ + return m_octaveShowHeaderInfoWhenExecutingScripts(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiaPreferences::octavePortNumber() const +{ + if ( m_octavePortNumber().first ) return m_octavePortNumber().second; + + return {}; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Application/RiaPreferences.h b/ApplicationLibCode/Application/RiaPreferences.h index 96628784f7..baa4a89633 100644 --- a/ApplicationLibCode/Application/RiaPreferences.h +++ b/ApplicationLibCode/Application/RiaPreferences.h @@ -115,7 +115,11 @@ public: // Script paths QString pythonExecutable() const; + + // Octave QString octaveExecutable() const; + bool octaveShowHeaderInfoWhenExecutingScripts() const; + QString octavePortNumber() const; QString loggerFilename() const; int loggerFlushInterval() const; @@ -131,7 +135,6 @@ public: caf::PdmField scriptDirectories; caf::PdmField scriptEditorExecutable; - caf::PdmField octaveShowHeaderInfoWhenExecutingScripts; caf::PdmField showPythonDebugInfo; caf::PdmField ssihubAddress; @@ -203,8 +206,12 @@ private: caf::PdmField m_gridCalculationExpressionFolder; caf::PdmField m_summaryCalculationExpressionFolder; - // Script paths - caf::PdmField m_octaveExecutable; + // Octave + caf::PdmField m_octaveExecutable; + caf::PdmField m_octaveShowHeaderInfoWhenExecutingScripts; + caf::PdmField> m_octavePortNumber; + + // Python caf::PdmField m_pythonExecutable; // Logging diff --git a/ApplicationLibCode/SocketInterface/RiaSocketServer.cpp b/ApplicationLibCode/SocketInterface/RiaSocketServer.cpp index 56d5a76584..c137a9043a 100644 --- a/ApplicationLibCode/SocketInterface/RiaSocketServer.cpp +++ b/ApplicationLibCode/SocketInterface/RiaSocketServer.cpp @@ -56,15 +56,24 @@ RiaSocketServer::RiaSocketServer( QObject* parent ) m_nextPendingConnectionTimer->setInterval( 100 ); m_nextPendingConnectionTimer->setSingleShot( true ); - if ( !m_tcpServer->listen( QHostAddress::LocalHost, 40001 ) ) + int portNumber = riOctavePlugin::defaultPortNumber; + if ( !RiaPreferences::current()->octavePortNumber().isEmpty() ) { - QString txt = "Disabled communication with Octave due to another ResInsight process running."; + portNumber = RiaPreferences::current()->octavePortNumber().toInt(); + } + + if ( !m_tcpServer->listen( QHostAddress::LocalHost, portNumber ) ) + { + QString txt = QString( "Not able to communicate with Octave plugins. Failed to use port number : %1" ).arg( portNumber ); RiaLogging::warning( txt ); return; } + QString txt = QString( "Octave is using port: %1" ).arg( portNumber ); + RiaLogging::info( txt ); + connect( m_nextPendingConnectionTimer, SIGNAL( timeout() ), this, SLOT( slotNewClientConnection() ) ); connect( m_tcpServer, SIGNAL( newConnection() ), this, SLOT( slotNewClientConnection() ) ); } diff --git a/ApplicationLibCode/SocketInterface/RiaSocketServerDefines.h b/ApplicationLibCode/SocketInterface/RiaSocketServerDefines.h index 0a5a1e997f..e46b264ffe 100644 --- a/ApplicationLibCode/SocketInterface/RiaSocketServerDefines.h +++ b/ApplicationLibCode/SocketInterface/RiaSocketServerDefines.h @@ -16,9 +16,21 @@ // ///////////////////////////////////////////////////////////////////////////////// +#pragma once + #include namespace riOctavePlugin { const int qtDataStreamVersion = QDataStream::Qt_4_0; + +// https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers +// Use a port number in the dynamic/private range (49152-65535) +const int defaultPortNumber = 52025; + +inline const std::string portNumberKey() +{ + return "RESINSIGHT_OCTAVE_PORT_NUMBER"; } + +} // namespace riOctavePlugin diff --git a/OctavePlugin/riGetActiveCellCenters.cpp b/OctavePlugin/riGetActiveCellCenters.cpp index 300cf68d5a..1ef594a30a 100644 --- a/OctavePlugin/riGetActiveCellCenters.cpp +++ b/OctavePlugin/riGetActiveCellCenters.cpp @@ -143,7 +143,7 @@ DEFUN_DLD (riGetActiveCellCenters, args, nargout, } NDArray cellCenterValues; - getActiveCellCenters(cellCenterValues, "127.0.0.1", 40001, caseId, porosityModel.c_str()); + getActiveCellCenters(cellCenterValues, "127.0.0.1", riOctavePlugin::portNumber(), caseId, porosityModel.c_str()); return octave_value(cellCenterValues); } diff --git a/OctavePlugin/riGetActiveCellCorners.cpp b/OctavePlugin/riGetActiveCellCorners.cpp index 1c7ba597da..91e7d2df92 100644 --- a/OctavePlugin/riGetActiveCellCorners.cpp +++ b/OctavePlugin/riGetActiveCellCorners.cpp @@ -143,7 +143,7 @@ DEFUN_DLD (riGetActiveCellCorners, args, nargout, } NDArray cellCornerValues; - getActiveCellCorners(cellCornerValues, "127.0.0.1", 40001, caseId, porosityModel.c_str()); + getActiveCellCorners(cellCornerValues, "127.0.0.1", riOctavePlugin::portNumber(), caseId, porosityModel.c_str()); return octave_value(cellCornerValues); } diff --git a/OctavePlugin/riGetActiveCellInfo.cpp b/OctavePlugin/riGetActiveCellInfo.cpp index 9b8e07744d..ef472d8162 100644 --- a/OctavePlugin/riGetActiveCellInfo.cpp +++ b/OctavePlugin/riGetActiveCellInfo.cpp @@ -158,7 +158,7 @@ DEFUN_DLD (riGetActiveCellInfo, args, nargout, } } - getActiveCellInfo(propertyFrames, "127.0.0.1", 40001, caseId, porosityModel); + getActiveCellInfo(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), caseId, porosityModel); return octave_value(propertyFrames); } diff --git a/OctavePlugin/riGetActiveCellProperty.cpp b/OctavePlugin/riGetActiveCellProperty.cpp index 088ab3890f..abdf2a8609 100644 --- a/OctavePlugin/riGetActiveCellProperty.cpp +++ b/OctavePlugin/riGetActiveCellProperty.cpp @@ -193,7 +193,7 @@ DEFUN_DLD (riGetActiveCellProperty, args, nargout, return octave_value_list (); } - getActiveCellProperty(propertyFrames, "127.0.0.1", 40001, caseId, propertyName.c_str(), requestedTimeSteps, porosityModel.c_str()); + getActiveCellProperty(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), caseId, propertyName.c_str(), requestedTimeSteps, porosityModel.c_str()); return octave_value(propertyFrames); } diff --git a/OctavePlugin/riGetCaseGroups.cpp b/OctavePlugin/riGetCaseGroups.cpp index c78cb9c9b1..a3234ef0a6 100644 --- a/OctavePlugin/riGetCaseGroups.cpp +++ b/OctavePlugin/riGetCaseGroups.cpp @@ -103,7 +103,7 @@ DEFUN_DLD (riGetCaseGroups, args, nargout, { std::vector groupNames; std::vector groupIds; - getCaseGroups(groupNames, groupIds, "127.0.0.1", 40001); + getCaseGroups(groupNames, groupIds, "127.0.0.1", riOctavePlugin::portNumber()); size_t groupCount = groupNames.size(); diff --git a/OctavePlugin/riGetCases.cpp b/OctavePlugin/riGetCases.cpp index a3500e0287..7a52dcf932 100644 --- a/OctavePlugin/riGetCases.cpp +++ b/OctavePlugin/riGetCases.cpp @@ -115,7 +115,7 @@ DEFUN_DLD (riGetCases, args, nargout, caseGroupId = argCaseId; } - getCases(caseIds, caseNames, caseTypes, caseGroupIds, caseGroupId, "127.0.0.1", 40001); + getCases(caseIds, caseNames, caseTypes, caseGroupIds, caseGroupId, "127.0.0.1", riOctavePlugin::portNumber()); size_t caseCount = caseIds.size(); diff --git a/OctavePlugin/riGetCellCenters.cpp b/OctavePlugin/riGetCellCenters.cpp index c4807c5b7b..7aa957485c 100644 --- a/OctavePlugin/riGetCellCenters.cpp +++ b/OctavePlugin/riGetCellCenters.cpp @@ -126,7 +126,7 @@ DEFUN_DLD (riGetCellCenters, args, nargout, gridIndex = args(1).uint_value(); } - getCellCenters(cellCenterValues, "127.0.0.1", 40001, caseId, gridIndex); + getCellCenters(cellCenterValues, "127.0.0.1", riOctavePlugin::portNumber(), caseId, gridIndex); return octave_value(cellCenterValues); } diff --git a/OctavePlugin/riGetCellCorners.cpp b/OctavePlugin/riGetCellCorners.cpp index 782a18a468..3fb010bfb6 100644 --- a/OctavePlugin/riGetCellCorners.cpp +++ b/OctavePlugin/riGetCellCorners.cpp @@ -128,7 +128,7 @@ DEFUN_DLD (riGetCellCorners, args, nargout, gridIndex = args(1).uint_value(); } - getCellCorners(cellCornerValues, "127.0.0.1", 40001, caseId, gridIndex); + getCellCorners(cellCornerValues, "127.0.0.1", riOctavePlugin::portNumber(), caseId, gridIndex); return octave_value(cellCornerValues); } diff --git a/OctavePlugin/riGetCoarseningInfo.cpp b/OctavePlugin/riGetCoarseningInfo.cpp index ed415ff420..d68992c5e1 100644 --- a/OctavePlugin/riGetCoarseningInfo.cpp +++ b/OctavePlugin/riGetCoarseningInfo.cpp @@ -115,7 +115,7 @@ DEFUN_DLD (riGetCoarseningInfo, args, nargout, } int32NDArray coarseningInfo; - getCoarseningInfo(coarseningInfo, "127.0.0.1", 40001, caseId); + getCoarseningInfo(coarseningInfo, "127.0.0.1", riOctavePlugin::portNumber(), caseId); return octave_value(coarseningInfo); } diff --git a/OctavePlugin/riGetCurrentCase.cpp b/OctavePlugin/riGetCurrentCase.cpp index d5bfd2590e..3a90e43dc5 100644 --- a/OctavePlugin/riGetCurrentCase.cpp +++ b/OctavePlugin/riGetCurrentCase.cpp @@ -93,7 +93,7 @@ DEFUN_DLD (riGetCurrentCase, args, nargout, QString caseType; qint64 caseGroupId = -1; - getCurrentCase(caseId, caseName, caseType, caseGroupId, "127.0.0.1", 40001); + getCurrentCase(caseId, caseName, caseType, caseGroupId, "127.0.0.1", riOctavePlugin::portNumber()); octave_map fieldMap; diff --git a/OctavePlugin/riGetDynamicNNCValues.cpp b/OctavePlugin/riGetDynamicNNCValues.cpp index ce8473e44e..3700de2f11 100644 --- a/OctavePlugin/riGetDynamicNNCValues.cpp +++ b/OctavePlugin/riGetDynamicNNCValues.cpp @@ -155,7 +155,7 @@ DEFUN_DLD (riGetDynamicNNCValues, args, nargout, if (argIndices[1] >= 0) propertyName = args(argIndices[1]).char_matrix_value().row_as_string(0); if (argIndices[2] >= 0) requestedTimeSteps = args(argIndices[2]).int32_array_value(); - getDynamicNNCValues(propertyFrames, "127.0.0.1", 40001, caseId, propertyName.c_str(), requestedTimeSteps); + getDynamicNNCValues(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), caseId, propertyName.c_str(), requestedTimeSteps); return octave_value(propertyFrames); } diff --git a/OctavePlugin/riGetGridDimensions.cpp b/OctavePlugin/riGetGridDimensions.cpp index 7478b859e8..1e89cbc8ae 100644 --- a/OctavePlugin/riGetGridDimensions.cpp +++ b/OctavePlugin/riGetGridDimensions.cpp @@ -119,7 +119,7 @@ DEFUN_DLD (riGetGridDimensions, args, nargout, } int32NDArray gridDimensions; - getGridDimensions(gridDimensions, "127.0.0.1", 40001, caseId); + getGridDimensions(gridDimensions, "127.0.0.1", riOctavePlugin::portNumber(), caseId); return octave_value(gridDimensions); } diff --git a/OctavePlugin/riGetGridProperty.cpp b/OctavePlugin/riGetGridProperty.cpp index 1507317445..8ddd5572a0 100644 --- a/OctavePlugin/riGetGridProperty.cpp +++ b/OctavePlugin/riGetGridProperty.cpp @@ -211,7 +211,7 @@ DEFUN_DLD (riGetGridProperty, args, nargout, return octave_value_list (); } - getGridProperty(propertyFrames, "127.0.0.1", 40001, caseId, gridIdx, propertyName.c_str(), requestedTimeSteps, porosityModel.c_str()); + getGridProperty(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), caseId, gridIdx, propertyName.c_str(), requestedTimeSteps, porosityModel.c_str()); return octave_value(propertyFrames); } diff --git a/OctavePlugin/riGetGridPropertyForSelectedCells.cpp b/OctavePlugin/riGetGridPropertyForSelectedCells.cpp index 8cd71a5774..17f8dddd08 100644 --- a/OctavePlugin/riGetGridPropertyForSelectedCells.cpp +++ b/OctavePlugin/riGetGridPropertyForSelectedCells.cpp @@ -193,7 +193,7 @@ DEFUN_DLD (riGetGridPropertyForSelectedCells, args, nargout, return octave_value_list (); } - getGridPropertyForSelectedCells(propertyFrames, "127.0.0.1", 40001, caseId, propertyName.c_str(), requestedTimeSteps, porosityModel.c_str()); + getGridPropertyForSelectedCells(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), caseId, propertyName.c_str(), requestedTimeSteps, porosityModel.c_str()); return octave_value(propertyFrames); } diff --git a/OctavePlugin/riGetMainGridDimensions.cpp b/OctavePlugin/riGetMainGridDimensions.cpp index af009cfd91..385f89fe62 100644 --- a/OctavePlugin/riGetMainGridDimensions.cpp +++ b/OctavePlugin/riGetMainGridDimensions.cpp @@ -101,9 +101,9 @@ DEFUN_DLD (riGetMainGridDimensions, args, nargout, int32NDArray propertyFrames; if (nargin > 0) - getMainGridDimensions(propertyFrames, "127.0.0.1", 40001, args(0).char_matrix_value().row_as_string(0).c_str()); + getMainGridDimensions(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), args(0).char_matrix_value().row_as_string(0).c_str()); else - getMainGridDimensions(propertyFrames, "127.0.0.1", 40001, ""); + getMainGridDimensions(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), ""); return octave_value(propertyFrames); } diff --git a/OctavePlugin/riGetNNCConnections.cpp b/OctavePlugin/riGetNNCConnections.cpp index 6595047863..7260c1d5c8 100644 --- a/OctavePlugin/riGetNNCConnections.cpp +++ b/OctavePlugin/riGetNNCConnections.cpp @@ -122,7 +122,7 @@ DEFUN_DLD(riGetNNCConnections, args, nargout, } } - getNNCConnections(connections, "127.0.0.1", 40001, caseId); + getNNCConnections(connections, "127.0.0.1", riOctavePlugin::portNumber(), caseId); Cell cellValuesGridIndex(connections.size(), 2); Cell cellValuesI(connections.size(), 2); diff --git a/OctavePlugin/riGetNNCPropertyNames.cpp b/OctavePlugin/riGetNNCPropertyNames.cpp index ba9140d0b9..84ca1f9806 100644 --- a/OctavePlugin/riGetNNCPropertyNames.cpp +++ b/OctavePlugin/riGetNNCPropertyNames.cpp @@ -115,7 +115,7 @@ DEFUN_DLD (riGetNNCPropertyNames, args, nargout, std::vector propertyNames; std::vector propertyTypes; - getNNCPropertyNames(propertyNames, propertyTypes, "127.0.0.1", 40001, argCaseId); + getNNCPropertyNames(propertyNames, propertyTypes, "127.0.0.1", riOctavePlugin::portNumber(), argCaseId); size_t caseCount = propertyNames.size(); diff --git a/OctavePlugin/riGetPropertyNames.cpp b/OctavePlugin/riGetPropertyNames.cpp index b870448d81..6cd313e3d8 100644 --- a/OctavePlugin/riGetPropertyNames.cpp +++ b/OctavePlugin/riGetPropertyNames.cpp @@ -135,7 +135,7 @@ DEFUN_DLD (riGetPropertyNames, args, nargout, std::vector propertyNames; std::vector propertyTypes; - getPropertyNames(propertyNames, propertyTypes, "127.0.0.1", 40001, argCaseId, porosityModel); + getPropertyNames(propertyNames, propertyTypes, "127.0.0.1", riOctavePlugin::portNumber(), argCaseId, porosityModel); size_t caseCount = propertyNames.size(); diff --git a/OctavePlugin/riGetSelectedCases.cpp b/OctavePlugin/riGetSelectedCases.cpp index 7d65e50ed1..077144d3a9 100644 --- a/OctavePlugin/riGetSelectedCases.cpp +++ b/OctavePlugin/riGetSelectedCases.cpp @@ -105,7 +105,7 @@ DEFUN_DLD (riGetSelectedCases, args, nargout, std::vector caseTypes; std::vector caseGroupIds; - getSelectedCases(caseIds, caseNames, caseTypes, caseGroupIds, "127.0.0.1", 40001); + getSelectedCases(caseIds, caseNames, caseTypes, caseGroupIds, "127.0.0.1", riOctavePlugin::portNumber()); size_t caseCount = caseIds.size(); diff --git a/OctavePlugin/riGetSelectedCells.cpp b/OctavePlugin/riGetSelectedCells.cpp index 157549ac5e..16e263e726 100644 --- a/OctavePlugin/riGetSelectedCells.cpp +++ b/OctavePlugin/riGetSelectedCells.cpp @@ -125,7 +125,7 @@ DEFUN_DLD (riGetSelectedCells, args, nargout, int32NDArray propertyFrames; - getSelectedCells(propertyFrames, "127.0.0.1", 40001, caseId); + getSelectedCells(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), caseId); return octave_value(propertyFrames); } diff --git a/OctavePlugin/riGetStaticNNCValues.cpp b/OctavePlugin/riGetStaticNNCValues.cpp index 0610f6a4de..e3646fcf0c 100644 --- a/OctavePlugin/riGetStaticNNCValues.cpp +++ b/OctavePlugin/riGetStaticNNCValues.cpp @@ -128,7 +128,7 @@ DEFUN_DLD (riGetStaticNNCValues, args, nargout, if (argIndices[0] >= 0) caseId = args(argIndices[0]).int_value(); if (argIndices[1] >= 0) propertyName = args(argIndices[1]).char_matrix_value().row_as_string(0); - getStaticNNCValues(propertyValues, "127.0.0.1", 40001, caseId, propertyName.c_str()); + getStaticNNCValues(propertyValues, "127.0.0.1", riOctavePlugin::portNumber(), caseId, propertyName.c_str()); dim_vector dv(2, 1); dv(0) = propertyValues.size(); diff --git a/OctavePlugin/riGetTimeStepDates.cpp b/OctavePlugin/riGetTimeStepDates.cpp index 9be5748448..27a116ba65 100644 --- a/OctavePlugin/riGetTimeStepDates.cpp +++ b/OctavePlugin/riGetTimeStepDates.cpp @@ -140,7 +140,7 @@ DEFUN_DLD (riGetTimeStepDates, args, nargout, std::vector minuteValues; std::vector secondValues; - getTimeStepDates(yearValues, monthValues, dayValues, hourValues, minuteValues, secondValues, caseId, "127.0.0.1", 40001); + getTimeStepDates(yearValues, monthValues, dayValues, hourValues, minuteValues, secondValues, caseId, "127.0.0.1", riOctavePlugin::portNumber()); size_t timeStepDateCount = yearValues.size(); diff --git a/OctavePlugin/riGetTimeStepDays.cpp b/OctavePlugin/riGetTimeStepDays.cpp index 62f5cf13f3..c563be2d3e 100644 --- a/OctavePlugin/riGetTimeStepDays.cpp +++ b/OctavePlugin/riGetTimeStepDays.cpp @@ -108,7 +108,7 @@ DEFUN_DLD (riGetTimeStepDays, args, nargout, std::vector decimalDays; - getTimeStepDates(decimalDays, caseId, "127.0.0.1", 40001); + getTimeStepDates(decimalDays, caseId, "127.0.0.1", riOctavePlugin::portNumber()); dim_vector dv(2, 1); dv(0) = decimalDays.size(); diff --git a/OctavePlugin/riGetWellCells.cpp b/OctavePlugin/riGetWellCells.cpp index b967636ba0..fb206b5aec 100644 --- a/OctavePlugin/riGetWellCells.cpp +++ b/OctavePlugin/riGetWellCells.cpp @@ -209,7 +209,7 @@ DEFUN_DLD (riGetWellCells, args, nargout, cellStatuses, branchIds, segmentIds, - "127.0.0.1", 40001, + "127.0.0.1", riOctavePlugin::portNumber(), caseId, QString::fromStdString(wellName), requestedTimeStep); size_t cellCount = cellIs.size(); diff --git a/OctavePlugin/riGetWellNames.cpp b/OctavePlugin/riGetWellNames.cpp index 4bbd17733b..d6d825fee5 100644 --- a/OctavePlugin/riGetWellNames.cpp +++ b/OctavePlugin/riGetWellNames.cpp @@ -106,7 +106,7 @@ DEFUN_DLD (riGetWellNames, args, nargout, std::vector wellNames; - getWellNames(wellNames, "127.0.0.1", 40001, argCaseId); + getWellNames(wellNames, "127.0.0.1", riOctavePlugin::portNumber(), argCaseId); size_t caseCount = wellNames.size(); diff --git a/OctavePlugin/riGetWellStatus.cpp b/OctavePlugin/riGetWellStatus.cpp index 318e9b9d80..dcc9c43f27 100644 --- a/OctavePlugin/riGetWellStatus.cpp +++ b/OctavePlugin/riGetWellStatus.cpp @@ -170,7 +170,7 @@ DEFUN_DLD (riGetWellStatus, args, nargout, std::vector wellType; std::vector wellStatus; - getWellStatus(wellType, wellStatus, "127.0.0.1", 40001, caseId, QString::fromStdString(wellName), requestedTimeSteps); + getWellStatus(wellType, wellStatus, "127.0.0.1", riOctavePlugin::portNumber(), caseId, QString::fromStdString(wellName), requestedTimeSteps); size_t caseCount = wellType.size(); diff --git a/OctavePlugin/riSetActiveCellProperty.cpp b/OctavePlugin/riSetActiveCellProperty.cpp index 91edf8f9cd..ca12495424 100644 --- a/OctavePlugin/riSetActiveCellProperty.cpp +++ b/OctavePlugin/riSetActiveCellProperty.cpp @@ -219,7 +219,7 @@ DEFUN_DLD (riSetActiveCellProperty, args, nargout, return octave_value_list (); } - setEclipseProperty(propertyFrames, "127.0.0.1", 40001, caseId, propertyName.c_str(), requestedTimeSteps, porosityModel.c_str()); + setEclipseProperty(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), caseId, propertyName.c_str(), requestedTimeSteps, porosityModel.c_str()); return octave_value_list (); } diff --git a/OctavePlugin/riSetGridProperty.cpp b/OctavePlugin/riSetGridProperty.cpp index 9a77e17173..e38456d10d 100644 --- a/OctavePlugin/riSetGridProperty.cpp +++ b/OctavePlugin/riSetGridProperty.cpp @@ -258,7 +258,7 @@ DEFUN_DLD (riSetGridProperty, args, nargout, return octave_value_list (); } - setEclipseProperty(propertyFrames, "127.0.0.1", 40001, caseId, gridIndex, propertyName.c_str(), timeStepIndices, porosityModel.c_str()); + setEclipseProperty(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), caseId, gridIndex, propertyName.c_str(), timeStepIndices, porosityModel.c_str()); return octave_value_list (); } diff --git a/OctavePlugin/riSetNNCProperty.cpp b/OctavePlugin/riSetNNCProperty.cpp index f58e7f56e6..d52b2e13c2 100644 --- a/OctavePlugin/riSetNNCProperty.cpp +++ b/OctavePlugin/riSetNNCProperty.cpp @@ -186,7 +186,7 @@ DEFUN_DLD (riSetNNCProperty, args, nargout, } } - setNNCProperty(propertyFrames, "127.0.0.1", 40001, caseId, propertyName.c_str(), requestedTimeSteps); + setNNCProperty(propertyFrames, "127.0.0.1", riOctavePlugin::portNumber(), caseId, propertyName.c_str(), requestedTimeSteps); return octave_value_list (); } diff --git a/OctavePlugin/riSettings.h b/OctavePlugin/riSettings.h index a7badf6941..a10e41f869 100644 --- a/OctavePlugin/riSettings.h +++ b/OctavePlugin/riSettings.h @@ -76,5 +76,16 @@ namespace riOctavePlugin #endif } + int portNumber() + { + QString portStr = getenv(riOctavePlugin::portNumberKey().data()); + if (!portStr.isEmpty()) + { + return portStr.toInt(); + } + + return riOctavePlugin::defaultPortNumber; + } + } From acfbd942634cda391d287dded8d26567fa4b2e9d Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 4 Jun 2024 07:42:50 +0200 Subject: [PATCH 2/3] Make it possible to build Octave plugins independent to main build The building of Octave plugins within main ResInsight build on RHEL8 cause the build to use gcc-12, and gcc-12 is extremely slow when building opm-common. Adjust the CMake configuration so it is possible to build the Octave plugins as an independent build job. The plugin binaries can then be uploaded to an external server. The main ResInsight build can download the binaries and include them in the install package for ResInsight. Use the flag RESINSIGHT_USE_EXTERNAL_OCTAVE_PLUGINS to download external Octave plugin binaries. --- .github/workflows/cmake-format.yml | 4 + CMakeLists.txt | 33 ++- Octave/CMakeLists.txt | 33 +++ Octave/OctavePlugin/CMakeLists.txt | 278 ++++++++++++++++++ .../MinGWBuildConfigurationForOctave.txt | 0 .../NNCOctaveInterfaceSpecification.txt | 0 .../OctaveScripts/InputPropTest.m | 0 .../OctavePlugin}/OctaveScripts/LGRSOIL.m | 0 .../OctavePlugin}/OctaveScripts/SatNum.m | 0 .../OctavePlugin}/OctaveScripts/SoilAverage.m | 0 .../OctaveScripts/SoilTimeDiff.m | 0 .../OctavePlugin}/OctaveScripts/kaverage.m | 0 .../OctavePlugin}/OctaveScripts/kslice.m | 0 ...ResInsightOctaveInterfaceSpecification.txt | 0 .../OctavePlugin}/riGetActiveCellCenters.cpp | 0 .../OctavePlugin}/riGetActiveCellCorners.cpp | 0 .../OctavePlugin}/riGetActiveCellInfo.cpp | 0 .../OctavePlugin}/riGetActiveCellProperty.cpp | 0 .../OctavePlugin}/riGetCaseGroups.cpp | 0 .../OctavePlugin}/riGetCases.cpp | 0 .../OctavePlugin}/riGetCellCenters.cpp | 0 .../OctavePlugin}/riGetCellCorners.cpp | 0 .../OctavePlugin}/riGetCoarseningInfo.cpp | 0 .../OctavePlugin}/riGetCurrentCase.cpp | 0 .../OctavePlugin}/riGetDynamicNNCValues.cpp | 0 .../OctavePlugin}/riGetGridDimensions.cpp | 0 .../OctavePlugin}/riGetGridProperty.cpp | 0 .../riGetGridPropertyForSelectedCells.cpp | 0 .../OctavePlugin}/riGetMainGridDimensions.cpp | 0 .../OctavePlugin}/riGetNNCConnections.cpp | 0 .../OctavePlugin}/riGetNNCPropertyNames.cpp | 0 .../OctavePlugin}/riGetPropertyNames.cpp | 0 .../OctavePlugin}/riGetSelectedCases.cpp | 0 .../OctavePlugin}/riGetSelectedCells.cpp | 0 .../OctavePlugin}/riGetStaticNNCValues.cpp | 0 .../OctavePlugin}/riGetTimeStepDates.cpp | 0 .../OctavePlugin}/riGetTimeStepDays.cpp | 0 .../OctavePlugin}/riGetWellCells.cpp | 0 .../OctavePlugin}/riGetWellNames.cpp | 0 .../OctavePlugin}/riGetWellStatus.cpp | 0 .../OctavePlugin}/riSetActiveCellProperty.cpp | 0 .../OctavePlugin}/riSetGridProperty.cpp | 0 .../OctavePlugin}/riSetNNCProperty.cpp | 0 .../OctavePlugin}/riSettings.h | 2 +- Octave/cmake/FindOctave.cmake | 205 +++++++++++++ Octave/cmake/cmake-format.py | 20 ++ OctavePlugin/CMakeLists.txt | 262 ----------------- 47 files changed, 566 insertions(+), 271 deletions(-) create mode 100644 Octave/CMakeLists.txt create mode 100644 Octave/OctavePlugin/CMakeLists.txt rename {OctavePlugin => Octave/OctavePlugin}/MinGWBuildConfigurationForOctave.txt (100%) rename {OctavePlugin => Octave/OctavePlugin}/NNCOctaveInterfaceSpecification.txt (100%) rename {OctavePlugin => Octave/OctavePlugin}/OctaveScripts/InputPropTest.m (100%) rename {OctavePlugin => Octave/OctavePlugin}/OctaveScripts/LGRSOIL.m (100%) rename {OctavePlugin => Octave/OctavePlugin}/OctaveScripts/SatNum.m (100%) rename {OctavePlugin => Octave/OctavePlugin}/OctaveScripts/SoilAverage.m (100%) rename {OctavePlugin => Octave/OctavePlugin}/OctaveScripts/SoilTimeDiff.m (100%) rename {OctavePlugin => Octave/OctavePlugin}/OctaveScripts/kaverage.m (100%) rename {OctavePlugin => Octave/OctavePlugin}/OctaveScripts/kslice.m (100%) rename {OctavePlugin => Octave/OctavePlugin}/ResInsightOctaveInterfaceSpecification.txt (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetActiveCellCenters.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetActiveCellCorners.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetActiveCellInfo.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetActiveCellProperty.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetCaseGroups.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetCases.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetCellCenters.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetCellCorners.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetCoarseningInfo.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetCurrentCase.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetDynamicNNCValues.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetGridDimensions.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetGridProperty.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetGridPropertyForSelectedCells.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetMainGridDimensions.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetNNCConnections.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetNNCPropertyNames.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetPropertyNames.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetSelectedCases.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetSelectedCells.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetStaticNNCValues.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetTimeStepDates.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetTimeStepDays.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetWellCells.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetWellNames.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riGetWellStatus.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riSetActiveCellProperty.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riSetGridProperty.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riSetNNCProperty.cpp (100%) rename {OctavePlugin => Octave/OctavePlugin}/riSettings.h (97%) create mode 100644 Octave/cmake/FindOctave.cmake create mode 100644 Octave/cmake/cmake-format.py delete mode 100644 OctavePlugin/CMakeLists.txt diff --git a/.github/workflows/cmake-format.yml b/.github/workflows/cmake-format.yml index c6db7afa8e..eb6b5ec436 100644 --- a/.github/workflows/cmake-format.yml +++ b/.github/workflows/cmake-format.yml @@ -23,6 +23,10 @@ jobs: find -name CMake*.txt | xargs ~/.local/bin/cmake-format -c ${{ github.workspace }}/cmake/cmake-format.py -i cd .. + cd Octave + find -name CMake*.txt | xargs ~/.local/bin/cmake-format -c ${{ github.workspace }}/cmake/cmake-format.py -i + cd .. + cd Fwk/AppFwk find -name CMake*.txt | xargs ~/.local/bin/cmake-format -c ${{ github.workspace }}/cmake/cmake-format.py -i cd .. diff --git a/CMakeLists.txt b/CMakeLists.txt index be662dc9da..563e4ae070 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1007,15 +1007,32 @@ if(RESINSIGHT_ENABLE_GRPC) endif() add_subdirectory(ApplicationExeCode) -if(OCTAVE_MKOCTFILE) - message(STATUS "Adding OctavePlugin library") - - add_subdirectory(OctavePlugin) -else(OCTAVE_MKOCTFILE) - message( - STATUS "Could not find OCTAVE_MKOCTFILE, skipping OctavePlugin library" +option(RESINSIGHT_USE_EXTERNAL_OCTAVE_PLUGINS "Use external Octave plugins" OFF) +if(RESINSIGHT_USE_EXTERNAL_OCTAVE_PLUGINS) + FetchContent_Declare( + external-octave_plugins + URL https://github.com/CeetronSolutions/resinsight-dependencies/releases/latest/download/OctavePlugins-0.1.1-Linux.tar.gz ) -endif(OCTAVE_MKOCTFILE) + + FetchContent_Populate(external-octave_plugins) + + file(GLOB FILE_AND_SYMLINKS ${external-octave_plugins_SOURCE_DIR}/*.oct) + install( + FILES ${FILE_AND_SYMLINKS} + DESTINATION ${RESINSIGHT_INSTALL_FOLDER} + OPTIONAL + ) +else(RESINSIGHT_USE_EXTERNAL_OCTAVE_PLUGINS) + if(OCTAVE_MKOCTFILE) + message(STATUS "Adding OctavePlugin library") + + add_subdirectory(Octave/OctavePlugin) + else(OCTAVE_MKOCTFILE) + message( + STATUS "Could not find OCTAVE_MKOCTFILE, skipping OctavePlugin library" + ) + endif(OCTAVE_MKOCTFILE) +endif(RESINSIGHT_USE_EXTERNAL_OCTAVE_PLUGINS) # ############################################################################## # Visual Studio : Create the ruleset file to be used by Static Code Analysis diff --git a/Octave/CMakeLists.txt b/Octave/CMakeLists.txt new file mode 100644 index 0000000000..48f509f694 --- /dev/null +++ b/Octave/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.15) + +project(OctavePlugins) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +find_package(Octave) + +if(CEE_USE_QT6) + find_package( + Qt6 + COMPONENTS + REQUIRED Core Gui OpenGL Widgets Network + ) + set(QT_LIBRARIES Qt6::Core Qt6::Gui Qt6::OpenGL Qt6::Widgets Qt6::Network) + qt_standard_project_setup() +else() + find_package( + Qt5 + COMPONENTS + REQUIRED Core Gui OpenGL Widgets Network + ) + set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::OpenGL Qt5::Widgets Qt5::Network) +endif() + +add_subdirectory(OctavePlugin) + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(CPACK_GENERATOR TGZ) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(CPACK_GENERATOR ZIP) +endif() + +include(CPack) diff --git a/Octave/OctavePlugin/CMakeLists.txt b/Octave/OctavePlugin/CMakeLists.txt new file mode 100644 index 0000000000..99beb51cea --- /dev/null +++ b/Octave/OctavePlugin/CMakeLists.txt @@ -0,0 +1,278 @@ +# Some of the functionality in this CMakeLists.txt might be easier to maintain +# if we use a CMake macro to find configuration info for Octave This file is +# currently (2.8.12) not part of default CMake installation See +# http://www.cmake.org/Wiki/CMakeUserFindOctave + +set(CPP_SOURCES + riGetActiveCellProperty.cpp + riSetActiveCellProperty.cpp + riGetActiveCellInfo.cpp + riGetMainGridDimensions.cpp + riGetNNCConnections.cpp + riGetNNCPropertyNames.cpp + riGetCurrentCase.cpp + riGetCaseGroups.cpp + riGetDynamicNNCValues.cpp + riGetStaticNNCValues.cpp + riGetSelectedCases.cpp + riGetSelectedCells.cpp + riGetCases.cpp + riGetTimeStepDates.cpp + riGetTimeStepDays.cpp + riGetGridDimensions.cpp + riGetCoarseningInfo.cpp + riGetCellCenters.cpp + riGetActiveCellCenters.cpp + riGetCellCorners.cpp + riGetActiveCellCorners.cpp + riGetGridProperty.cpp + riSetGridProperty.cpp + riGetGridPropertyForSelectedCells.cpp + riGetPropertyNames.cpp + riGetWellNames.cpp + riGetWellStatus.cpp + riGetWellCells.cpp + riSetNNCProperty.cpp +) + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + # since the compiler passes the option to the linker, double quoting is + # necessary + set(RPATH_COMMAND "-Wl,-rpath,'\\$$ORIGIN'") +endif() + +# recreate the magic that CMake does for MacOS X frameworks in the include list +# when we call mkoctfile as a custom command +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(QT_INCLUDES) + set(QT_FRAMEWORKS) + # QT_INCLUDE_DIR contains two items; the first is the directory containing + # header files, the second is the framework. This setup is specially processed + # in include_directories (); CMake will add -F before the frameworks. We will + # have to replicate that setup here when we want to pass it directly to a + # command see + foreach(item IN ITEMS ${QT_QTNETWORK_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} + ${QT_INCLUDE_DIR} + ) + if("${item}" MATCHES ".framework$") + get_filename_component(frmwrk_path ${item} PATH) + get_filename_component(frmwrk_name ${item} NAME_WE) + # mkoctfile doesn't support arbitrary compiler command, so we must wrap in + # -Wl, to pass to the linker + list(APPEND QT_FRAMEWORKS "-Wl,-F${frmwrk_path}") + list(APPEND QT_FRAMEWORKS "-Wl,-framework,${frmwrk_name}") + else() + list(APPEND QT_INCLUDES "-I${item}") + endif() + endforeach(item) + if(QT_INCLUDES) + list(REMOVE_DUPLICATES QT_INCLUDES) + endif() + if(QT_FRAMEWORKS) + list(REMOVE_DUPLICATES QT_FRAMEWORKS) + endif() +endif() + +message(STATUS "Compiling Octave plugins using : ${OCTAVE_MKOCTFILE}") + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + option(RESINSIGHT_OCTAVE_PLUGIN_QT + "Compile Octave plugin using Qt located insided Octave root folder" ON + ) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + +if(RESINSIGHT_OCTAVE_PLUGIN_QT) + + message( + STATUS + "Compiling Octave plugins using custom Qt located at ${OCTAVE_ROOT_DIR}" + ) + + if(EXISTS ${OCTAVE_ROOT_DIR}/qt5) + set(OCTAVE_QT_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/qt5/include) + set(OCTAVE_QT_QTCORE_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/qt5/include/QtCore) + set(OCTAVE_QT_QTNETWORK_INCLUDE_DIR + ${OCTAVE_ROOT_DIR}/qt5/include/QtNetwork + ) + set(OCTAVE_QT_LIBRARY_DIR ${OCTAVE_ROOT_DIR}/qt5/lib) + set(OCTAVE_QT_QTCORE_LIB Qt5Core) + set(OCTAVE_QT_QTNETWORK_LIB Qt5Network) + else() + set(OCTAVE_QT_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/include) + set(OCTAVE_QT_QTCORE_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/include/QtCore) + set(OCTAVE_QT_QTNETWORK_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/include/QtNetwork) + set(OCTAVE_QT_LIBRARY_DIR ${OCTAVE_ROOT_DIR}/lib) + set(OCTAVE_QT_QTCORE_LIB QtCore4) + set(OCTAVE_QT_QTNETWORK_LIB QtNetwork4) + endif(EXISTS ${OCTAVE_ROOT_DIR}/qt5) + +else() + + if(Qt5Core_FOUND) + message(STATUS "Compiling Octave plugins using system Qt5") + + set(OCTAVE_QT_QTCORE_INCLUDE_DIR ${Qt5Core_INCLUDE_DIRS}) + set(OCTAVE_QT_QTNETWORK_INCLUDE_DIR ${Qt5Network_INCLUDE_DIRS}) + set(OCTAVE_QT_LIBRARY_DIR ${QT_LIBRARY_DIR}) + set(OCTAVE_QT_QTCORE_LIB Qt5Core) + set(OCTAVE_QT_QTNETWORK_LIB Qt5Network) + + endif(Qt5Core_FOUND) + +endif(RESINSIGHT_OCTAVE_PLUGIN_QT) + +list(APPEND MKOCTFILE_INCLUDE_DIRS ${OCTAVE_QT_INCLUDE_DIR}) +list(APPEND MKOCTFILE_INCLUDE_DIRS ${OCTAVE_QT_QTCORE_INCLUDE_DIR}) +list(APPEND MKOCTFILE_INCLUDE_DIRS ${OCTAVE_QT_QTNETWORK_INCLUDE_DIR}) + +# Add socket interface source code folder +list(APPEND MKOCTFILE_INCLUDE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/../../ApplicationLibCode/SocketInterface +) + +list(REMOVE_DUPLICATES MKOCTFILE_INCLUDE_DIRS) +foreach(item ${MKOCTFILE_INCLUDE_DIRS}) + list(APPEND MKOCTFILE_INCLUDE_TEMP -I${item}) +endforeach(item) + +string(REPLACE ";" " " MKOCTFILE_INCLUDE_TEMP "${MKOCTFILE_INCLUDE_TEMP}") + +# Use special command to avoid double quoting in add_custom_command() +separate_arguments( + MKOCTFILE_INCLUDE_COMMAND_STRING WINDOWS_COMMAND "${MKOCTFILE_INCLUDE_TEMP}" +) + +# Clear the list of binary oct files to be produced +set(OCTAVE_BINARY_OCT_FILES) + +if(OCTAVE_MKOCTFILE) + foreach(srcFileName IN LISTS CPP_SOURCES) + + if(NOT IS_ABSOLUTE "${srcFileName}") + set(srcFileName "${CMAKE_CURRENT_SOURCE_DIR}/${srcFileName}") + endif() + + get_filename_component(baseFilename "${srcFileName}" NAME_WE) + + set(octFileName "${CMAKE_CURRENT_BINARY_DIR}/${baseFilename}.oct") + + if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + add_custom_command( + OUTPUT "${octFileName}" + COMMAND set "OCTAVE_HOME=${OCTAVE_ROOT_DIR}" + COMMAND set "PATH=%OCTAVE_HOME%\\bin;%PATH%" + COMMAND + ${OCTAVE_MKOCTFILE} ${MKOCTFILE_INCLUDE_COMMAND_STRING} + ${RPATH_COMMAND} -L${OCTAVE_QT_LIBRARY_DIR} -l${OCTAVE_QT_QTCORE_LIB} + -l${OCTAVE_QT_QTNETWORK_LIB} -o "${octFileName}" "${srcFileName}" + DEPENDS "${srcFileName}" + COMMENT "===> Generating ${octFileName}" + ) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + add_custom_command( + OUTPUT "${octFileName}" + COMMAND + ${OCTAVE_MKOCTFILE} ${QT_INCLUDES} ${QT_FRAMEWORKS} + -I${ResInsight_SOURCE_DIR}/ApplicationLibCode/SocketInterface + ${RPATH_COMMAND} -L${QT_LIBRARY_DIR} -Wl,-framework,QtCore + -Wl,-framework,QtNetwork -o "${octFileName}" "${srcFileName}" + DEPENDS "${srcFileName}" + COMMENT "===> Generating ${octFileName}" + ) + else() + add_custom_command( + OUTPUT "${octFileName}" + COMMAND + OCTAVE_HOME=${OCTAVE_ROOT_DIR} ${OCTAVE_MKOCTFILE} + ${MKOCTFILE_INCLUDE_COMMAND_STRING} ${RPATH_COMMAND} + -L${OCTAVE_QT_LIBRARY_DIR} -l${OCTAVE_QT_QTCORE_LIB} + -l${OCTAVE_QT_QTNETWORK_LIB} -o "${octFileName}" "${srcFileName}" + DEPENDS "${srcFileName}" + COMMENT "===> Generating ${octFileName}" + ) + endif() + + list(APPEND OCTAVE_BINARY_OCT_FILES "${octFileName}") + + endforeach() + + # Create depencedy string represeting the full path to all generated oct-files + foreach(item ${CPP_SOURCES}) + string(REPLACE ".cpp" ".oct" item ${item}) + list(APPEND DEPENDENCY_STRING ${CMAKE_CURRENT_BINARY_DIR}/${item}) + endforeach(item) + + # message("DEPENDENCY_STRING : ${DEPENDENCY_STRING}") + + add_custom_target( + octave_plugins ALL + DEPENDS ${DEPENDENCY_STRING} + SOURCES ${CPP_SOURCES} riSettings.h + ) + + # Copy Octave generated *.oct files to application folder, will make it + # possible to use Octave functions directly from the location of the + # ResInsight binaries + if(TARGET ResInsight) + message( + STATUS + "Target ResInsight exists, add copy of Octave plugins to ApplicationExeCode folder" + ) + + # Make ResInsight dependant on Octave, makes it easiser to debug Octave + # functionality by compiling ResInsight + add_dependencies(ResInsight octave_plugins) + + foreach(oct_bin ${OCTAVE_BINARY_OCT_FILES}) + get_filename_component(Filename "${oct_bin}" NAME) + + if(MSVC) + add_custom_command( + TARGET octave_plugins + POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E copy_if_different "${oct_bin}" + "${CMAKE_CURRENT_BINARY_DIR}/../../ApplicationExeCode/$/${Filename}" + ) + else() + add_custom_command( + TARGET octave_plugins + POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E copy_if_different "${oct_bin}" + "${CMAKE_CURRENT_BINARY_DIR}/../../ApplicationExeCode/${Filename}" + ) + endif(MSVC) + endforeach(oct_bin) + + if(RESINSIGHT_PRIVATE_INSTALL) + install(FILES ${OCTAVE_BINARY_OCT_FILES} + DESTINATION ${RESINSIGHT_INSTALL_FOLDER} + ) + else(RESINSIGHT_PRIVATE_INSTALL) + # probe for site location of .oct files + if(NOT OCTAVE_SITE_OCT_DIR) + find_program( + OCTAVE_CONFIG_COMMAND octave-config + DOC "Path to Octave component and library information retrieval" + ) + exec_program( + ${OCTAVE_CONFIG_COMMAND} ARGS + --oct-site-dir + OUTPUT_VARIABLE OCTAVE_SITE_OCT_DIR + ) + set(OCTAVE_SITE_OCT_DIR + "${OCTAVE_SITE_OCT_DIR}" + CACHE LOCATION "Octave plugin directory" + ) + endif(NOT OCTAVE_SITE_OCT_DIR) + + install(FILES ${OCTAVE_BINARY_OCT_FILES} + DESTINATION ${OCTAVE_SITE_OCT_DIR} + ) + endif(RESINSIGHT_PRIVATE_INSTALL) + else() + install(FILES ${OCTAVE_BINARY_OCT_FILES} DESTINATION .) + endif(TARGET ResInsight) + +endif(OCTAVE_MKOCTFILE) diff --git a/OctavePlugin/MinGWBuildConfigurationForOctave.txt b/Octave/OctavePlugin/MinGWBuildConfigurationForOctave.txt similarity index 100% rename from OctavePlugin/MinGWBuildConfigurationForOctave.txt rename to Octave/OctavePlugin/MinGWBuildConfigurationForOctave.txt diff --git a/OctavePlugin/NNCOctaveInterfaceSpecification.txt b/Octave/OctavePlugin/NNCOctaveInterfaceSpecification.txt similarity index 100% rename from OctavePlugin/NNCOctaveInterfaceSpecification.txt rename to Octave/OctavePlugin/NNCOctaveInterfaceSpecification.txt diff --git a/OctavePlugin/OctaveScripts/InputPropTest.m b/Octave/OctavePlugin/OctaveScripts/InputPropTest.m similarity index 100% rename from OctavePlugin/OctaveScripts/InputPropTest.m rename to Octave/OctavePlugin/OctaveScripts/InputPropTest.m diff --git a/OctavePlugin/OctaveScripts/LGRSOIL.m b/Octave/OctavePlugin/OctaveScripts/LGRSOIL.m similarity index 100% rename from OctavePlugin/OctaveScripts/LGRSOIL.m rename to Octave/OctavePlugin/OctaveScripts/LGRSOIL.m diff --git a/OctavePlugin/OctaveScripts/SatNum.m b/Octave/OctavePlugin/OctaveScripts/SatNum.m similarity index 100% rename from OctavePlugin/OctaveScripts/SatNum.m rename to Octave/OctavePlugin/OctaveScripts/SatNum.m diff --git a/OctavePlugin/OctaveScripts/SoilAverage.m b/Octave/OctavePlugin/OctaveScripts/SoilAverage.m similarity index 100% rename from OctavePlugin/OctaveScripts/SoilAverage.m rename to Octave/OctavePlugin/OctaveScripts/SoilAverage.m diff --git a/OctavePlugin/OctaveScripts/SoilTimeDiff.m b/Octave/OctavePlugin/OctaveScripts/SoilTimeDiff.m similarity index 100% rename from OctavePlugin/OctaveScripts/SoilTimeDiff.m rename to Octave/OctavePlugin/OctaveScripts/SoilTimeDiff.m diff --git a/OctavePlugin/OctaveScripts/kaverage.m b/Octave/OctavePlugin/OctaveScripts/kaverage.m similarity index 100% rename from OctavePlugin/OctaveScripts/kaverage.m rename to Octave/OctavePlugin/OctaveScripts/kaverage.m diff --git a/OctavePlugin/OctaveScripts/kslice.m b/Octave/OctavePlugin/OctaveScripts/kslice.m similarity index 100% rename from OctavePlugin/OctaveScripts/kslice.m rename to Octave/OctavePlugin/OctaveScripts/kslice.m diff --git a/OctavePlugin/ResInsightOctaveInterfaceSpecification.txt b/Octave/OctavePlugin/ResInsightOctaveInterfaceSpecification.txt similarity index 100% rename from OctavePlugin/ResInsightOctaveInterfaceSpecification.txt rename to Octave/OctavePlugin/ResInsightOctaveInterfaceSpecification.txt diff --git a/OctavePlugin/riGetActiveCellCenters.cpp b/Octave/OctavePlugin/riGetActiveCellCenters.cpp similarity index 100% rename from OctavePlugin/riGetActiveCellCenters.cpp rename to Octave/OctavePlugin/riGetActiveCellCenters.cpp diff --git a/OctavePlugin/riGetActiveCellCorners.cpp b/Octave/OctavePlugin/riGetActiveCellCorners.cpp similarity index 100% rename from OctavePlugin/riGetActiveCellCorners.cpp rename to Octave/OctavePlugin/riGetActiveCellCorners.cpp diff --git a/OctavePlugin/riGetActiveCellInfo.cpp b/Octave/OctavePlugin/riGetActiveCellInfo.cpp similarity index 100% rename from OctavePlugin/riGetActiveCellInfo.cpp rename to Octave/OctavePlugin/riGetActiveCellInfo.cpp diff --git a/OctavePlugin/riGetActiveCellProperty.cpp b/Octave/OctavePlugin/riGetActiveCellProperty.cpp similarity index 100% rename from OctavePlugin/riGetActiveCellProperty.cpp rename to Octave/OctavePlugin/riGetActiveCellProperty.cpp diff --git a/OctavePlugin/riGetCaseGroups.cpp b/Octave/OctavePlugin/riGetCaseGroups.cpp similarity index 100% rename from OctavePlugin/riGetCaseGroups.cpp rename to Octave/OctavePlugin/riGetCaseGroups.cpp diff --git a/OctavePlugin/riGetCases.cpp b/Octave/OctavePlugin/riGetCases.cpp similarity index 100% rename from OctavePlugin/riGetCases.cpp rename to Octave/OctavePlugin/riGetCases.cpp diff --git a/OctavePlugin/riGetCellCenters.cpp b/Octave/OctavePlugin/riGetCellCenters.cpp similarity index 100% rename from OctavePlugin/riGetCellCenters.cpp rename to Octave/OctavePlugin/riGetCellCenters.cpp diff --git a/OctavePlugin/riGetCellCorners.cpp b/Octave/OctavePlugin/riGetCellCorners.cpp similarity index 100% rename from OctavePlugin/riGetCellCorners.cpp rename to Octave/OctavePlugin/riGetCellCorners.cpp diff --git a/OctavePlugin/riGetCoarseningInfo.cpp b/Octave/OctavePlugin/riGetCoarseningInfo.cpp similarity index 100% rename from OctavePlugin/riGetCoarseningInfo.cpp rename to Octave/OctavePlugin/riGetCoarseningInfo.cpp diff --git a/OctavePlugin/riGetCurrentCase.cpp b/Octave/OctavePlugin/riGetCurrentCase.cpp similarity index 100% rename from OctavePlugin/riGetCurrentCase.cpp rename to Octave/OctavePlugin/riGetCurrentCase.cpp diff --git a/OctavePlugin/riGetDynamicNNCValues.cpp b/Octave/OctavePlugin/riGetDynamicNNCValues.cpp similarity index 100% rename from OctavePlugin/riGetDynamicNNCValues.cpp rename to Octave/OctavePlugin/riGetDynamicNNCValues.cpp diff --git a/OctavePlugin/riGetGridDimensions.cpp b/Octave/OctavePlugin/riGetGridDimensions.cpp similarity index 100% rename from OctavePlugin/riGetGridDimensions.cpp rename to Octave/OctavePlugin/riGetGridDimensions.cpp diff --git a/OctavePlugin/riGetGridProperty.cpp b/Octave/OctavePlugin/riGetGridProperty.cpp similarity index 100% rename from OctavePlugin/riGetGridProperty.cpp rename to Octave/OctavePlugin/riGetGridProperty.cpp diff --git a/OctavePlugin/riGetGridPropertyForSelectedCells.cpp b/Octave/OctavePlugin/riGetGridPropertyForSelectedCells.cpp similarity index 100% rename from OctavePlugin/riGetGridPropertyForSelectedCells.cpp rename to Octave/OctavePlugin/riGetGridPropertyForSelectedCells.cpp diff --git a/OctavePlugin/riGetMainGridDimensions.cpp b/Octave/OctavePlugin/riGetMainGridDimensions.cpp similarity index 100% rename from OctavePlugin/riGetMainGridDimensions.cpp rename to Octave/OctavePlugin/riGetMainGridDimensions.cpp diff --git a/OctavePlugin/riGetNNCConnections.cpp b/Octave/OctavePlugin/riGetNNCConnections.cpp similarity index 100% rename from OctavePlugin/riGetNNCConnections.cpp rename to Octave/OctavePlugin/riGetNNCConnections.cpp diff --git a/OctavePlugin/riGetNNCPropertyNames.cpp b/Octave/OctavePlugin/riGetNNCPropertyNames.cpp similarity index 100% rename from OctavePlugin/riGetNNCPropertyNames.cpp rename to Octave/OctavePlugin/riGetNNCPropertyNames.cpp diff --git a/OctavePlugin/riGetPropertyNames.cpp b/Octave/OctavePlugin/riGetPropertyNames.cpp similarity index 100% rename from OctavePlugin/riGetPropertyNames.cpp rename to Octave/OctavePlugin/riGetPropertyNames.cpp diff --git a/OctavePlugin/riGetSelectedCases.cpp b/Octave/OctavePlugin/riGetSelectedCases.cpp similarity index 100% rename from OctavePlugin/riGetSelectedCases.cpp rename to Octave/OctavePlugin/riGetSelectedCases.cpp diff --git a/OctavePlugin/riGetSelectedCells.cpp b/Octave/OctavePlugin/riGetSelectedCells.cpp similarity index 100% rename from OctavePlugin/riGetSelectedCells.cpp rename to Octave/OctavePlugin/riGetSelectedCells.cpp diff --git a/OctavePlugin/riGetStaticNNCValues.cpp b/Octave/OctavePlugin/riGetStaticNNCValues.cpp similarity index 100% rename from OctavePlugin/riGetStaticNNCValues.cpp rename to Octave/OctavePlugin/riGetStaticNNCValues.cpp diff --git a/OctavePlugin/riGetTimeStepDates.cpp b/Octave/OctavePlugin/riGetTimeStepDates.cpp similarity index 100% rename from OctavePlugin/riGetTimeStepDates.cpp rename to Octave/OctavePlugin/riGetTimeStepDates.cpp diff --git a/OctavePlugin/riGetTimeStepDays.cpp b/Octave/OctavePlugin/riGetTimeStepDays.cpp similarity index 100% rename from OctavePlugin/riGetTimeStepDays.cpp rename to Octave/OctavePlugin/riGetTimeStepDays.cpp diff --git a/OctavePlugin/riGetWellCells.cpp b/Octave/OctavePlugin/riGetWellCells.cpp similarity index 100% rename from OctavePlugin/riGetWellCells.cpp rename to Octave/OctavePlugin/riGetWellCells.cpp diff --git a/OctavePlugin/riGetWellNames.cpp b/Octave/OctavePlugin/riGetWellNames.cpp similarity index 100% rename from OctavePlugin/riGetWellNames.cpp rename to Octave/OctavePlugin/riGetWellNames.cpp diff --git a/OctavePlugin/riGetWellStatus.cpp b/Octave/OctavePlugin/riGetWellStatus.cpp similarity index 100% rename from OctavePlugin/riGetWellStatus.cpp rename to Octave/OctavePlugin/riGetWellStatus.cpp diff --git a/OctavePlugin/riSetActiveCellProperty.cpp b/Octave/OctavePlugin/riSetActiveCellProperty.cpp similarity index 100% rename from OctavePlugin/riSetActiveCellProperty.cpp rename to Octave/OctavePlugin/riSetActiveCellProperty.cpp diff --git a/OctavePlugin/riSetGridProperty.cpp b/Octave/OctavePlugin/riSetGridProperty.cpp similarity index 100% rename from OctavePlugin/riSetGridProperty.cpp rename to Octave/OctavePlugin/riSetGridProperty.cpp diff --git a/OctavePlugin/riSetNNCProperty.cpp b/Octave/OctavePlugin/riSetNNCProperty.cpp similarity index 100% rename from OctavePlugin/riSetNNCProperty.cpp rename to Octave/OctavePlugin/riSetNNCProperty.cpp diff --git a/OctavePlugin/riSettings.h b/Octave/OctavePlugin/riSettings.h similarity index 97% rename from OctavePlugin/riSettings.h rename to Octave/OctavePlugin/riSettings.h index a10e41f869..aaf019bf2c 100644 --- a/OctavePlugin/riSettings.h +++ b/Octave/OctavePlugin/riSettings.h @@ -16,7 +16,7 @@ // ///////////////////////////////////////////////////////////////////////////////// -#include "../ApplicationLibCode/SocketInterface/RiaSocketServerDefines.h" +#include "../../ApplicationLibCode/SocketInterface/RiaSocketServerDefines.h" namespace riOctavePlugin { diff --git a/Octave/cmake/FindOctave.cmake b/Octave/cmake/FindOctave.cmake new file mode 100644 index 0000000000..a616b58e35 --- /dev/null +++ b/Octave/cmake/FindOctave.cmake @@ -0,0 +1,205 @@ +# - Find Octave +# GNU Octave is a high-level interpreted language, primarily intended for numerical computations. +# available at http://www.gnu.org/software/octave/ +# +# This module defines: +# OCTAVE_EXECUTABLE - octave interpreter +# OCTAVE_INCLUDE_DIRS - include path for mex.h, mexproto.h +# OCTAVE_LIBRARIES - required libraries: octinterp, octave, cruft +# OCTAVE_OCTINTERP_LIBRARY - path to the library octinterp +# OCTAVE_OCTAVE_LIBRARY - path to the library octave +# OCTAVE_CRUFT_LIBRARY - path to the library cruft +# OCTAVE_VERSION_STRING - octave version string +# OCTAVE_MAJOR_VERSION - major version +# OCTAVE_MINOR_VERSION - minor version +# OCTAVE_PATCH_VERSION - patch version +# OCTAVE_OCT_FILE_DIR - object files that will be dynamically loaded +# OCTAVE_OCT_LIB_DIR - oct libraries +# OCTAVE_ROOT_DIR - octave prefix +# OCTAVE_M_SITE_DIR - .m files site dir +# OCTAVE_OCT_SITE_DIR - .oct files site dir +# +# The macro octave_add_oct allows to create compiled modules. +# octave_add_oct (target_name +# [SOURCES] source1 [source2 ...] +# [LINK_LIBRARIES lib1 [lib2 ...]] +# [EXTENSION ext] +#) +# +# To install it, you can the use the variable OCTAVE_OCT_FILE_DIR as follow: +# file (RELATIVE_PATH PKG_OCTAVE_OCT_SITE_DIR ${OCTAVE_ROOT_DIR} ${OCTAVE_OCT_SITE_DIR}) +# install ( +# TARGETS target_name +# DESTINATION ${PKG_OCTAVE_OCT_SITE_DIR} +#) + + +#============================================================================= +# Copyright 2013, Julien Schueller +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of the FreeBSD Project. +#============================================================================= + +find_program(OCTAVE_CONFIG_EXECUTABLE + NAMES octave-config + ) + + +if (OCTAVE_CONFIG_EXECUTABLE) + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTAVE_HOME + OUTPUT_VARIABLE OCTAVE_ROOT_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} --m-site-dir + OUTPUT_VARIABLE OCTAVE_M_SITE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} --oct-site-dir + OUTPUT_VARIABLE OCTAVE_OCT_SITE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p BINDIR + OUTPUT_VARIABLE OCTAVE_BIN_PATHS + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTINCLUDEDIR + OUTPUT_VARIABLE OCTAVE_INCLUDE_PATHS + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR + OUTPUT_VARIABLE OCTAVE_LIBRARIES_PATHS + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTFILEDIR + OUTPUT_VARIABLE OCTAVE_OCT_FILE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR + OUTPUT_VARIABLE OCTAVE_OCT_LIB_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -v + OUTPUT_VARIABLE OCTAVE_VERSION_STRING + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (OCTAVE_VERSION_STRING) + string (REGEX REPLACE "([0-9]+)\\..*" "\\1" OCTAVE_MAJOR_VERSION ${OCTAVE_VERSION_STRING}) + string (REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" OCTAVE_MINOR_VERSION ${OCTAVE_VERSION_STRING}) + string (REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" OCTAVE_PATCH_VERSION ${OCTAVE_VERSION_STRING}) + endif () +endif () + + +find_program(OCTAVE_EXECUTABLE + HINTS ${OCTAVE_BIN_PATHS} + NAMES octave + ) + +find_program(OCTAVE_MKOCTFILE + HINTS ${OCTAVE_BIN_PATHS} + NAMES mkoctfile + ) + +find_library(OCTAVE_OCTINTERP_LIBRARY + NAMES octinterp liboctinterp + HINTS ${OCTAVE_LIBRARIES_PATHS} + ) +find_library(OCTAVE_OCTAVE_LIBRARY + NAMES octave liboctave + HINTS ${OCTAVE_LIBRARIES_PATHS} + ) +find_library(OCTAVE_CRUFT_LIBRARY + NAMES cruft libcruft + HINTS ${OCTAVE_LIBRARIES_PATHS} + ) + +set (OCTAVE_LIBRARIES ${OCTAVE_OCTINTERP_LIBRARY}) +list (APPEND OCTAVE_LIBRARIES ${OCTAVE_OCTAVE_LIBRARY}) +if (OCTAVE_CRUFT_LIBRARY) + list (APPEND OCTAVE_LIBRARIES ${OCTAVE_CRUFT_LIBRARY}) +endif () + +find_path (OCTAVE_INCLUDE_DIR + NAMES octave/oct.h + PATHS "${OCTAVE_INCLUDE_PATHS}/.." + ) + +set (OCTAVE_INCLUDE_DIRS ${OCTAVE_INCLUDE_DIR} ${OCTAVE_INCLUDE_DIR}/octave) + + +macro (octave_add_oct FUNCTIONNAME) + set (_CMD SOURCES) + set (_SOURCES) + set (_LINK_LIBRARIES) + set (_EXTENSION) + set (_OCT_EXTENSION oct) + foreach (_ARG ${ARGN}) + if (${_ARG} MATCHES SOURCES) + set (_CMD SOURCES) + elseif (${_ARG} MATCHES LINK_LIBRARIES) + set (_CMD LINK_LIBRARIES) + elseif (${_ARG} MATCHES EXTENSION) + set (_CMD EXTENSION) + else () + if (${_CMD} MATCHES SOURCES) + list (APPEND _SOURCES "${_ARG}") + elseif (${_CMD} MATCHES LINK_LIBRARIES) + list (APPEND _LINK_LIBRARIES "${_ARG}") + elseif (${_CMD} MATCHES EXTENSION) + set (_OCT_EXTENSION ${_ARG}) + endif () + endif () + endforeach () + add_library (${FUNCTIONNAME} SHARED ${_SOURCES}) + target_link_libraries (${FUNCTIONNAME} ${OCTAVE_LIBRARIES} ${_LINK_LIBRARIES}) + set_target_properties (${FUNCTIONNAME} PROPERTIES + PREFIX "" + SUFFIX ".${_OCT_EXTENSION}" +) +endmacro () + + +# handle REQUIRED and QUIET options +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (Octave REQUIRED_VARS OCTAVE_EXECUTABLE OCTAVE_ROOT_DIR OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES VERSION_VAR OCTAVE_VERSION_STRING) + + +mark_as_advanced ( + OCTAVE_OCT_FILE_DIR + OCTAVE_OCT_LIB_DIR + OCTAVE_OCTINTERP_LIBRARY + OCTAVE_OCTAVE_LIBRARY + OCTAVE_CRUFT_LIBRARY + OCTAVE_LIBRARIES + OCTAVE_INCLUDE_DIR + OCTAVE_INCLUDE_DIRS + OCTAVE_ROOT_DIR + OCTAVE_VERSION_STRING + OCTAVE_MAJOR_VERSION + OCTAVE_MINOR_VERSION + OCTAVE_PATCH_VERSION +) + + diff --git a/Octave/cmake/cmake-format.py b/Octave/cmake/cmake-format.py new file mode 100644 index 0000000000..3dde4ae4ac --- /dev/null +++ b/Octave/cmake/cmake-format.py @@ -0,0 +1,20 @@ +# ----------------------------- +# Options effecting formatting. +# See: https://github.com/cheshirekow/cmake_format +# ----------------------------- +with section("format"): + # How wide to allow formatted cmake files + line_width = 80 + + # How many spaces to tab for indent + tab_size = 2 + + # If true, separate flow control names from their parentheses with a space + separate_ctrl_name_with_space = False + + # If true, separate function names from parentheses with a space + separate_fn_name_with_space = False + + # If a statement is wrapped to more than one line, than dangle the closing + # parenthesis on its own line. + dangle_parens = True diff --git a/OctavePlugin/CMakeLists.txt b/OctavePlugin/CMakeLists.txt deleted file mode 100644 index 950862c362..0000000000 --- a/OctavePlugin/CMakeLists.txt +++ /dev/null @@ -1,262 +0,0 @@ - -# Some of the functionality in this CMakeLists.txt might be easier to maintain if we use a CMake macro to find configuration info for Octave -# This file is currently (2.8.12) not part of default CMake installation -# See http://www.cmake.org/Wiki/CMakeUserFindOctave - -set(CPP_SOURCES - riGetActiveCellProperty.cpp - riSetActiveCellProperty.cpp - riGetActiveCellInfo.cpp - riGetMainGridDimensions.cpp - riGetNNCConnections.cpp - riGetNNCPropertyNames.cpp - riGetCurrentCase.cpp - riGetCaseGroups.cpp - riGetDynamicNNCValues.cpp - riGetStaticNNCValues.cpp - riGetSelectedCases.cpp - riGetSelectedCells.cpp - riGetCases.cpp - riGetTimeStepDates.cpp - riGetTimeStepDays.cpp - riGetGridDimensions.cpp - riGetCoarseningInfo.cpp - riGetCellCenters.cpp - riGetActiveCellCenters.cpp - riGetCellCorners.cpp - riGetActiveCellCorners.cpp - riGetGridProperty.cpp - riSetGridProperty.cpp - riGetGridPropertyForSelectedCells.cpp - riGetPropertyNames.cpp - riGetWellNames.cpp - riGetWellStatus.cpp - riGetWellCells.cpp - riSetNNCProperty.cpp -) - -if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - # since the compiler passes the option to the linker, double quoting is necessary - set (RPATH_COMMAND "-Wl,-rpath,'\\$$ORIGIN'") -endif() - -# recreate the magic that CMake does for MacOS X frameworks in the -# include list when we call mkoctfile as a custom command -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set (QT_INCLUDES) - set (QT_FRAMEWORKS) - # QT_INCLUDE_DIR contains two items; the first is the directory - # containing header files, the second is the framework. This - # setup is specially processed in include_directories (); CMake - # will add -F before the frameworks. We will have to replicate - # that setup here when we want to pass it directly to a command - # see - foreach (item IN ITEMS ${QT_QTNETWORK_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_INCLUDE_DIR}) - if ("${item}" MATCHES ".framework$") - get_filename_component (frmwrk_path ${item} PATH) - get_filename_component (frmwrk_name ${item} NAME_WE) - # mkoctfile doesn't support arbitrary compiler command, - # so we must wrap in -Wl, to pass to the linker - list (APPEND QT_FRAMEWORKS "-Wl,-F${frmwrk_path}") - list (APPEND QT_FRAMEWORKS "-Wl,-framework,${frmwrk_name}") - else () - list (APPEND QT_INCLUDES "-I${item}") - endif () - endforeach (item) - if (QT_INCLUDES) - list (REMOVE_DUPLICATES QT_INCLUDES) - endif () - if (QT_FRAMEWORKS) - list (REMOVE_DUPLICATES QT_FRAMEWORKS) - endif () -endif () - -message (STATUS "Compiling Octave plugins using : ${OCTAVE_MKOCTFILE}") - -if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - option(RESINSIGHT_OCTAVE_PLUGIN_QT "Compile Octave plugin using Qt located insided Octave root folder" ON) -endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") - -if(RESINSIGHT_OCTAVE_PLUGIN_QT) - - message(STATUS "Compiling Octave plugins using custom Qt located at ${OCTAVE_ROOT_DIR}") - - if (EXISTS ${OCTAVE_ROOT_DIR}/qt5) - SET(OCTAVE_QT_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/qt5/include) - SET(OCTAVE_QT_QTCORE_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/qt5/include/QtCore) - SET(OCTAVE_QT_QTNETWORK_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/qt5/include/QtNetwork) - SET(OCTAVE_QT_LIBRARY_DIR ${OCTAVE_ROOT_DIR}/qt5/lib) - SET(OCTAVE_QT_QTCORE_LIB Qt5Core) - SET(OCTAVE_QT_QTNETWORK_LIB Qt5Network) - else () - SET(OCTAVE_QT_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/include) - SET(OCTAVE_QT_QTCORE_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/include/QtCore) - SET(OCTAVE_QT_QTNETWORK_INCLUDE_DIR ${OCTAVE_ROOT_DIR}/include/QtNetwork) - SET(OCTAVE_QT_LIBRARY_DIR ${OCTAVE_ROOT_DIR}/lib) - SET(OCTAVE_QT_QTCORE_LIB QtCore4) - SET(OCTAVE_QT_QTNETWORK_LIB QtNetwork4) - endif(EXISTS ${OCTAVE_ROOT_DIR}/qt5) - -else() - - if (Qt5Core_FOUND) - message(STATUS "Compiling Octave plugins using system Qt5") - - SET(OCTAVE_QT_QTCORE_INCLUDE_DIR ${Qt5Core_INCLUDE_DIRS}) - SET(OCTAVE_QT_QTNETWORK_INCLUDE_DIR ${Qt5Network_INCLUDE_DIRS}) - SET(OCTAVE_QT_LIBRARY_DIR ${QT_LIBRARY_DIR}) - SET(OCTAVE_QT_QTCORE_LIB Qt5Core) - SET(OCTAVE_QT_QTNETWORK_LIB Qt5Network) - - endif(Qt5Core_FOUND) - -endif(RESINSIGHT_OCTAVE_PLUGIN_QT) - -list (APPEND MKOCTFILE_INCLUDE_DIRS ${OCTAVE_QT_INCLUDE_DIR}) -list (APPEND MKOCTFILE_INCLUDE_DIRS ${OCTAVE_QT_QTCORE_INCLUDE_DIR}) -list (APPEND MKOCTFILE_INCLUDE_DIRS ${OCTAVE_QT_QTNETWORK_INCLUDE_DIR}) - - -# Add socket interface source code folder -list (APPEND MKOCTFILE_INCLUDE_DIRS ${ResInsight_SOURCE_DIR}/ApplicationLibCode/SocketInterface) - -list (REMOVE_DUPLICATES MKOCTFILE_INCLUDE_DIRS) -foreach (item ${MKOCTFILE_INCLUDE_DIRS}) - list (APPEND MKOCTFILE_INCLUDE_TEMP -I${item}) -endforeach (item) - -string( REPLACE ";" " " MKOCTFILE_INCLUDE_TEMP "${MKOCTFILE_INCLUDE_TEMP}" ) - -# Use special command to avoid double quoting in add_custom_command() -separate_arguments(MKOCTFILE_INCLUDE_COMMAND_STRING WINDOWS_COMMAND "${MKOCTFILE_INCLUDE_TEMP}") - - -# Clear the list of binary oct files to be produced -set(OCTAVE_BINARY_OCT_FILES) - -if (OCTAVE_MKOCTFILE) - foreach(srcFileName IN LISTS CPP_SOURCES) - - if(NOT IS_ABSOLUTE "${srcFileName}") - set(srcFileName "${CMAKE_CURRENT_SOURCE_DIR}/${srcFileName}") - endif() - - get_filename_component(baseFilename "${srcFileName}" NAME_WE) - - set(octFileName "${CMAKE_CURRENT_BINARY_DIR}/${baseFilename}.oct") - - if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - add_custom_command( - OUTPUT "${octFileName}" - COMMAND set "OCTAVE_HOME=${OCTAVE_ROOT_DIR}" - COMMAND set "PATH=%OCTAVE_HOME%\\bin;%PATH%" - COMMAND ${OCTAVE_MKOCTFILE} - ${MKOCTFILE_INCLUDE_COMMAND_STRING} - ${RPATH_COMMAND} - -L${OCTAVE_QT_LIBRARY_DIR} - -l${OCTAVE_QT_QTCORE_LIB} - -l${OCTAVE_QT_QTNETWORK_LIB} - -o "${octFileName}" "${srcFileName}" - DEPENDS "${srcFileName}" - COMMENT "===> Generating ${octFileName}" - ) - elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - add_custom_command( - OUTPUT "${octFileName}" - COMMAND ${OCTAVE_MKOCTFILE} - ${QT_INCLUDES} - ${QT_FRAMEWORKS} - -I${ResInsight_SOURCE_DIR}/ApplicationLibCode/SocketInterface - ${RPATH_COMMAND} - -L${QT_LIBRARY_DIR} -Wl,-framework,QtCore -Wl,-framework,QtNetwork - -o "${octFileName}" - "${srcFileName}" - DEPENDS "${srcFileName}" - COMMENT "===> Generating ${octFileName}" - ) - else() - add_custom_command( - OUTPUT "${octFileName}" - COMMAND OCTAVE_HOME=${OCTAVE_ROOT_DIR} - ${OCTAVE_MKOCTFILE} - ${MKOCTFILE_INCLUDE_COMMAND_STRING} - ${RPATH_COMMAND} - -L${OCTAVE_QT_LIBRARY_DIR} - -l${OCTAVE_QT_QTCORE_LIB} - -l${OCTAVE_QT_QTNETWORK_LIB} - -o "${octFileName}" "${srcFileName}" - DEPENDS "${srcFileName}" - COMMENT "===> Generating ${octFileName}" - ) - endif() - - list(APPEND OCTAVE_BINARY_OCT_FILES "${octFileName}") - - endforeach() - -# Create depencedy string represeting the full path to all generated oct-files -foreach (item ${CPP_SOURCES}) - string( REPLACE ".cpp" ".oct" item ${item}) - list (APPEND DEPENDENCY_STRING ${CMAKE_CURRENT_BINARY_DIR}/${item}) -endforeach (item) - -#message("DEPENDENCY_STRING : ${DEPENDENCY_STRING}") - -add_custom_target(octave_plugins ALL DEPENDS - ${DEPENDENCY_STRING} - SOURCES - ${CPP_SOURCES} - riSettings.h - ) - - # Copy Octave generated *.oct files to application folder, will make it possible to use Octave functions - # directly from the location of the ResInsight binaries - if (true) - foreach (oct_bin ${OCTAVE_BINARY_OCT_FILES}) - - get_filename_component(Filename "${oct_bin}" NAME) - - if(MSVC) - add_custom_command(TARGET octave_plugins POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${oct_bin}" - "${CMAKE_CURRENT_BINARY_DIR}/../ApplicationExeCode/$/${Filename}" - ) - else() - add_custom_command(TARGET octave_plugins POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${oct_bin}" - "${CMAKE_CURRENT_BINARY_DIR}/../ApplicationExeCode/${Filename}" - ) - endif() - endforeach( oct_bin ) - endif() - - # Make ResInsight dependant on Octave, makes it easiser to debug Octave functionality by compiling ResInsight - add_dependencies(ResInsight octave_plugins) - - - if (RESINSIGHT_PRIVATE_INSTALL) - install(FILES ${OCTAVE_BINARY_OCT_FILES} DESTINATION ${RESINSIGHT_INSTALL_FOLDER}) - else (RESINSIGHT_PRIVATE_INSTALL) - # probe for site location of .oct files - if (NOT OCTAVE_SITE_OCT_DIR) - find_program (OCTAVE_CONFIG_COMMAND - octave-config - DOC "Path to Octave component and library information retrieval" - ) - exec_program (${OCTAVE_CONFIG_COMMAND} - ARGS --oct-site-dir - OUTPUT_VARIABLE OCTAVE_SITE_OCT_DIR - ) - set (OCTAVE_SITE_OCT_DIR "${OCTAVE_SITE_OCT_DIR}" CACHE LOCATION "Octave plugin directory") - endif (NOT OCTAVE_SITE_OCT_DIR) - - install (FILES ${OCTAVE_BINARY_OCT_FILES} - DESTINATION ${OCTAVE_SITE_OCT_DIR} - ) - endif (RESINSIGHT_PRIVATE_INSTALL) - -endif (OCTAVE_MKOCTFILE) - - From 84a07eed2b1739a225be5b1a0a1c73708751a8bc Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 5 Jun 2024 14:06:49 +0200 Subject: [PATCH 3/3] #11463 Look for resinsight_executable in JSON Search for resinsight_executable in JSON-file located at ./share/rips/rips_config.json --- GrpcInterface/Python/rips/instance.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/GrpcInterface/Python/rips/instance.py b/GrpcInterface/Python/rips/instance.py index 1f6f7b0f70..1bfd20779e 100644 --- a/GrpcInterface/Python/rips/instance.py +++ b/GrpcInterface/Python/rips/instance.py @@ -12,6 +12,8 @@ import logging import time import tempfile import signal +import sys +import json import grpc @@ -30,6 +32,7 @@ from .generated.generated_classes import CommandRouter from typing import List, Optional, Tuple from typing_extensions import Self +from pathlib import Path class Instance: @@ -121,6 +124,18 @@ class Instance: if launch_port != -1: requested_port = launch_port + if not resinsight_executable: + filename = Path(sys.prefix) / "share" / "rips" / "rips_config.json" + if filename.is_file(): + f = open(filename) + data = json.load(f) + resinsight_executable = data["resinsight_executable"] + if resinsight_executable: + print( + "In './share/rips/rips_config.json', found resinsight_executable:", + resinsight_executable, + ) + if not resinsight_executable: resinsight_executable_from_env = os.environ.get("RESINSIGHT_EXECUTABLE") if not resinsight_executable_from_env: