mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added riGetCases
p4#: 21618
This commit is contained in:
@@ -63,10 +63,11 @@ public:
|
||||
|
||||
void assignCaseIdToCase(RimCase* reservoirCase);
|
||||
void assignIdToCaseGroup(RimIdenticalGridCaseGroup* caseGroup);
|
||||
|
||||
void allCases(std::vector<RimCase*>& cases);
|
||||
|
||||
private:
|
||||
RigMainGrid* registerCaseInGridCollection(RigCaseData* rigEclipseCase);
|
||||
void allCases(std::vector<RimCase*>& cases);
|
||||
|
||||
protected:
|
||||
// Overridden methods
|
||||
|
||||
@@ -251,8 +251,9 @@ void RiaSocketServer::readCommandFromOctave()
|
||||
bool isGetCurrentCase = args[0] == "GetCurrentCase";
|
||||
bool isGetCaseGroups = args[0] == "GetCaseGroups";
|
||||
bool isGetSelectedCases = args[0] == "GetSelectedCases";
|
||||
bool isGetCases = args[0] == "GetCases";
|
||||
|
||||
if (!(isGetProperty || isSetProperty || isGetCellInfo || isGetGridDim || isGetCurrentCase || isGetCaseGroups || isGetSelectedCases))
|
||||
if (!(isGetProperty || isSetProperty || isGetCellInfo || isGetGridDim || isGetCurrentCase || isGetCaseGroups || isGetSelectedCases || isGetCases))
|
||||
{
|
||||
m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Unknown command: %1").arg(args[0].data()));
|
||||
terminateCurrentConnection();
|
||||
@@ -393,6 +394,121 @@ void RiaSocketServer::readCommandFromOctave()
|
||||
|
||||
return;
|
||||
}
|
||||
else if (isGetCases)
|
||||
{
|
||||
quint64 argCaseGroupId = -1;
|
||||
|
||||
if (args.size() == 2)
|
||||
{
|
||||
argCaseGroupId = args[1].toInt();
|
||||
}
|
||||
|
||||
if (RiaApplication::instance()->project())
|
||||
{
|
||||
RimProject* proj = RiaApplication::instance()->project();
|
||||
|
||||
std::vector<RimCase*> cases;
|
||||
if (argCaseGroupId == -1)
|
||||
{
|
||||
proj->allCases(cases);
|
||||
}
|
||||
else
|
||||
{
|
||||
RimIdenticalGridCaseGroup* caseGroup = NULL;
|
||||
for (size_t i = 0; i < RiaApplication::instance()->project()->caseGroups().size(); i++)
|
||||
{
|
||||
RimIdenticalGridCaseGroup* cg = RiaApplication::instance()->project()->caseGroups()[i];
|
||||
|
||||
if (argCaseGroupId == cg->groupId())
|
||||
{
|
||||
caseGroup = cg;
|
||||
}
|
||||
}
|
||||
|
||||
if (caseGroup)
|
||||
{
|
||||
for (size_t i = 0; i < caseGroup->statisticsCaseCollection()->reservoirs.size(); i++)
|
||||
{
|
||||
cases.push_back(caseGroup->statisticsCaseCollection()->reservoirs[i]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < caseGroup->caseCollection()->reservoirs.size(); i++)
|
||||
{
|
||||
cases.push_back(caseGroup->caseCollection()->reservoirs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<qint64> caseIds;
|
||||
std::vector<QString> caseNames;
|
||||
std::vector<QString> caseTypes;
|
||||
std::vector<qint64> caseGroupIds;
|
||||
|
||||
for (size_t i = 0; i < cases.size(); i++)
|
||||
{
|
||||
RimCase* rimCase = cases[i];
|
||||
|
||||
QString caseType;
|
||||
qint64 caseGroupId = -1;
|
||||
|
||||
RimCaseCollection* caseCollection = rimCase->parentCaseCollection();
|
||||
if (caseCollection)
|
||||
{
|
||||
caseGroupId = caseCollection->parentCaseGroup()->groupId;
|
||||
|
||||
if (RimIdenticalGridCaseGroup::isStatisticsCaseCollection(caseCollection))
|
||||
{
|
||||
caseType = "StatisticsCase";
|
||||
}
|
||||
else
|
||||
{
|
||||
caseType = "SourceCase";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dynamic_cast<RimInputCase*>(rimCase))
|
||||
{
|
||||
caseType = "InputCase";
|
||||
}
|
||||
else
|
||||
{
|
||||
caseType = "ResultCase";
|
||||
}
|
||||
}
|
||||
|
||||
caseIds.push_back(rimCase->caseId);
|
||||
caseNames.push_back(rimCase->caseUserDescription);
|
||||
caseTypes.push_back(caseType);
|
||||
caseGroupIds.push_back(caseGroupId);
|
||||
}
|
||||
|
||||
quint64 byteCount = sizeof(quint64);
|
||||
quint64 caseCount = caseIds.size();
|
||||
|
||||
for (size_t i = 0; i < caseCount; i++)
|
||||
{
|
||||
byteCount += 2*sizeof(qint64);
|
||||
byteCount += caseNames[i].size() * sizeof(QChar);
|
||||
byteCount += caseTypes[i].size() * sizeof(QChar);
|
||||
}
|
||||
|
||||
socketStream << byteCount;
|
||||
socketStream << caseCount;
|
||||
|
||||
for (size_t i = 0; i < caseCount; i++)
|
||||
{
|
||||
socketStream << caseIds[i];
|
||||
socketStream << caseNames[i];
|
||||
socketStream << caseTypes[i];
|
||||
socketStream << caseGroupIds[i];
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (reservoir == NULL)
|
||||
|
||||
@@ -8,6 +8,7 @@ set(CPP_SOURCES
|
||||
riGetCurrentCase.cpp
|
||||
riGetCaseGroups.cpp
|
||||
riGetSelectedCases.cpp
|
||||
riGetCases.cpp
|
||||
)
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
@@ -105,6 +106,7 @@ else()
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetCurrentCase.oct"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetCaseGroups.oct"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetSelectedCases.oct"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetCases.oct"
|
||||
|
||||
SOURCES ${CPP_SOURCES}
|
||||
)
|
||||
|
||||
162
OctavePlugin/riGetCases.cpp
Normal file
162
OctavePlugin/riGetCases.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
#include <QtNetwork>
|
||||
#include <octave/oct.h>
|
||||
#include <octave/oct-map.h>
|
||||
|
||||
#include "riSettings.h"
|
||||
|
||||
void getCases(std::vector<qint64>& caseIds, std::vector<QString>& caseNames, std::vector<QString>& caseTypes, std::vector<qint64>& caseGroupIds, const qint64& caseGroupId, const QString &hostName, quint16 port)
|
||||
{
|
||||
QString serverName = hostName;
|
||||
quint16 serverPort = port;
|
||||
|
||||
const int timeout = riOctavePlugin::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 = QString("GetCases %1").arg(caseGroupId);
|
||||
QByteArray cmdBytes = command.toLatin1();
|
||||
|
||||
QDataStream socketStream(&socket);
|
||||
socketStream.setVersion(riOctavePlugin::qtDataStreamVersion);
|
||||
|
||||
socketStream << (qint64)(cmdBytes.size());
|
||||
socket.write(cmdBytes);
|
||||
|
||||
// Get response. First wait for the header
|
||||
|
||||
while (socket.bytesAvailable() < (int)(sizeof(quint64)))
|
||||
{
|
||||
if (!socket.waitForReadyRead(timeout))
|
||||
{
|
||||
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
quint64 byteCount;
|
||||
socketStream >> byteCount;
|
||||
|
||||
while (socket.bytesAvailable() < (int)(byteCount))
|
||||
{
|
||||
if (!socket.waitForReadyRead(timeout))
|
||||
{
|
||||
error((("Waiting for data: ") + socket.errorString()).toLatin1().data());
|
||||
return;
|
||||
}
|
||||
OCTAVE_QUIT;
|
||||
}
|
||||
|
||||
quint64 caseCount;
|
||||
socketStream >> caseCount;
|
||||
|
||||
qint64 caseId = -1;
|
||||
QString caseName;
|
||||
QString caseType;
|
||||
qint64 caseGroupIdFromSocket = -1;
|
||||
|
||||
for (size_t i = 0; i < caseCount; i++)
|
||||
{
|
||||
socketStream >> caseId;
|
||||
socketStream >> caseName;
|
||||
socketStream >> caseType;
|
||||
socketStream >> caseGroupIdFromSocket;
|
||||
|
||||
caseIds.push_back(caseId);
|
||||
caseNames.push_back(caseName);
|
||||
caseTypes.push_back(caseType);
|
||||
caseGroupIds.push_back(caseGroupIdFromSocket);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DEFUN_DLD (riGetCases, args, nargout,
|
||||
"Usage:\n"
|
||||
"\n"
|
||||
" riGetCases([CaseGroupId])\n"
|
||||
"\n"
|
||||
"This function returns a CaseInfo Structure for all the cases in the current ResInsight project,\n"
|
||||
"including the Statistics cases and Source cases in a Grid Case Group.\n"
|
||||
"If a CaseGroupId is provided, only the cases in that Case Group will be returned.\n"
|
||||
)
|
||||
{
|
||||
int nargin = args.length ();
|
||||
if (nargin > 1)
|
||||
{
|
||||
error("riGetCurrentCase: Too many arguments, this function takes one optional argument.\n");
|
||||
print_usage();
|
||||
}
|
||||
else if (nargout != 1)
|
||||
{
|
||||
error("riGetCurrentCase: Wrong number of output arguments, this function requires one output argument.\n");
|
||||
print_usage();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<qint64> caseIds;
|
||||
std::vector<QString> caseNames;
|
||||
std::vector<QString> caseTypes;
|
||||
std::vector<qint64> caseGroupIds;
|
||||
|
||||
qint64 caseGroupId = -1;
|
||||
|
||||
if (nargin == 1)
|
||||
{
|
||||
unsigned int argCaseId = args(0).uint_value();
|
||||
caseGroupId = argCaseId;
|
||||
}
|
||||
|
||||
getCases(caseIds, caseNames, caseTypes, caseGroupIds, caseGroupId, "127.0.0.1", 40001);
|
||||
|
||||
size_t caseCount = caseIds.size();
|
||||
|
||||
if (caseCount != caseNames.size() ||
|
||||
caseCount != caseTypes.size() ||
|
||||
caseCount != caseGroupIds.size())
|
||||
{
|
||||
error("riGetCurrentCase: Inconsistent data received from ResInsight.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create cells with N items for each field in the data structure
|
||||
|
||||
Cell cellValuesA(caseCount, 1);
|
||||
Cell cellValuesB(caseCount, 1);
|
||||
Cell cellValuesC(caseCount, 1);
|
||||
Cell cellValuesD(caseCount, 1);
|
||||
|
||||
for (size_t i = 0; i < caseCount; i++)
|
||||
{
|
||||
cellValuesA(i) = caseIds[i];
|
||||
cellValuesB(i) = caseNames[i].toLatin1().data();
|
||||
cellValuesC(i) = caseTypes[i].toLatin1().data();
|
||||
cellValuesD(i) = caseGroupIds[i];
|
||||
}
|
||||
|
||||
// Build a map between the field name and field cell values
|
||||
|
||||
Octave_map m;
|
||||
|
||||
m.assign(riOctavePlugin::caseInfo_CaseId, cellValuesA);
|
||||
m.assign(riOctavePlugin::caseInfo_CaseName, cellValuesB);
|
||||
m.assign(riOctavePlugin::caseInfo_CaseType, cellValuesC);
|
||||
m.assign(riOctavePlugin::caseInfo_CaseGroupId, cellValuesD);
|
||||
|
||||
return octave_value(m);
|
||||
}
|
||||
}
|
||||
|
||||
return octave_value();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user