mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
Added riGetCurrentCase used to get caseId from current rimCase in ResInsight
p4#: 21593
This commit is contained in:
parent
cb1c276e01
commit
b63306099e
@ -248,9 +248,9 @@ void RiaSocketServer::readCommandFromOctave()
|
||||
bool isSetProperty = args[0] == "SetProperty"; // SetProperty [casename/index] PropertyName
|
||||
bool isGetCellInfo = args[0] == "GetActiveCellInfo"; // GetActiveCellInfo [casename/index]
|
||||
bool isGetGridDim = args[0] == "GetMainGridDimensions"; // GetMainGridDimensions [casename/index]
|
||||
bool isGetCurrentCase = args[0] == "GetCurrentCase";
|
||||
|
||||
|
||||
if (!(isGetProperty || isSetProperty || isGetCellInfo || isGetGridDim))
|
||||
if (!(isGetProperty || isSetProperty || isGetCellInfo || isGetGridDim || isGetCurrentCase))
|
||||
{
|
||||
m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Unknown command: %1").arg(args[0].data()));
|
||||
terminateCurrentConnection();
|
||||
@ -284,6 +284,20 @@ void RiaSocketServer::readCommandFromOctave()
|
||||
}
|
||||
|
||||
reservoir = this->findReservoir(caseName);
|
||||
|
||||
if (isGetCurrentCase)
|
||||
{
|
||||
int caseId = -1;
|
||||
|
||||
if (reservoir)
|
||||
{
|
||||
caseId = reservoir->caseId();
|
||||
}
|
||||
|
||||
socketStream << (qint64)caseId;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (reservoir == NULL)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ set(CPP_SOURCES
|
||||
riSetActiveCellProperty.cpp
|
||||
riGetActiveCellInfo.cpp
|
||||
riGetMainGridDimensions.cpp
|
||||
riGetCurrentCase.cpp
|
||||
)
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
@ -99,6 +100,7 @@ else()
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riSetActiveCellProperty.oct"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetActiveCellInfo.oct"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetMainGridDimensions.oct"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetCurrentCase.oct"
|
||||
|
||||
SOURCES ${CPP_SOURCES}
|
||||
)
|
||||
|
83
OctavePlugin/riGetCurrentCase.cpp
Normal file
83
OctavePlugin/riGetCurrentCase.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
#include <QtNetwork>
|
||||
#include <octave/oct.h>
|
||||
|
||||
#include "riSettings.h"
|
||||
|
||||
void getCurrentCase(int& currentCaseId, const QString &hostName, quint16 port)
|
||||
{
|
||||
QString serverName = hostName;
|
||||
quint16 serverPort = port;
|
||||
|
||||
const int Timeout = riOctave::timeOutMilliSecs;
|
||||
|
||||
QTcpSocket socket;
|
||||
socket.connectToHost(serverName, serverPort);
|
||||
|
||||
if (!socket.waitForConnected(Timeout))
|
||||
{
|
||||
error((("Connection: ") + socket.errorString()).toLatin1().data());
|
||||
return;
|
||||
}
|
||||
|
||||
// Create command and send it:
|
||||
|
||||
QString command("GetCurrentCase");
|
||||
QByteArray cmdBytes = command.toLatin1();
|
||||
|
||||
QDataStream socketStream(&socket);
|
||||
socketStream.setVersion(QDataStream::Qt_4_0);
|
||||
|
||||
socketStream << (qint64)(cmdBytes.size());
|
||||
socket.write(cmdBytes);
|
||||
|
||||
// Get response. First wait for the header
|
||||
|
||||
while (socket.bytesAvailable() < (int)(sizeof(qint64)))
|
||||
{
|
||||
if (!socket.waitForReadyRead(Timeout))
|
||||
{
|
||||
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
qint64 caseId;
|
||||
socketStream >> caseId;
|
||||
|
||||
octave_stdout << "riGetCurrentCase: " << caseId << std::endl;
|
||||
|
||||
currentCaseId = caseId;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DEFUN_DLD (riGetCurrentCase, args, nargout,
|
||||
"Usage:\n"
|
||||
"\n"
|
||||
" riGetCurrentCase()\n"
|
||||
"\n"
|
||||
"Returns meta information for the Case considered to be the “Current Case” by ResInsight.\n"
|
||||
"When ResInsigt loops over a selection of cases and executes an Octave script for each of them,\n"
|
||||
"this function returns the CaseId for that particular Case."
|
||||
)
|
||||
{
|
||||
int nargin = args.length ();
|
||||
if (nargin > 0)
|
||||
{
|
||||
error("riGetCurrentCase: Too many arguments, this function does not take any arguments.\n");
|
||||
print_usage();
|
||||
}
|
||||
else
|
||||
{
|
||||
int caseId;
|
||||
|
||||
getCurrentCase(caseId, "127.0.0.1", 40001);
|
||||
|
||||
return octave_value(caseId);
|
||||
}
|
||||
|
||||
return octave_value_list ();
|
||||
}
|
||||
|
22
OctavePlugin/riSettings.h
Normal file
22
OctavePlugin/riSettings.h
Normal file
@ -0,0 +1,22 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace riOctave
|
||||
{
|
||||
const int timeOutMilliSecs = 5000;
|
||||
}
|
Loading…
Reference in New Issue
Block a user