Added RiaSocketCommands as placeholder for new commands

Moved declaration to RiaSocketServer.h to be able to create new commands in other files
Added riGetTimeStepDates
p4#: 21655
This commit is contained in:
Magne Sjaastad 2013-05-16 13:43:37 +02:00
parent bb0c4c37c1
commit 2303f30200
7 changed files with 334 additions and 14 deletions

View File

@ -48,15 +48,18 @@ set( USER_INTERFACE_FILES
UserInterface/RiuProcessMonitor.cpp
)
set( SOCKET_INTERFACE_FILES
SocketInterface/RiaSocketServer.cpp
SocketInterface/RiaSocketCommands.cpp
)
list( APPEND CPP_SOURCES
${APPLICATION_FILES}
${USER_INTERFACE_FILES}
${SOCKET_INTERFACE_FILES}
)
list( APPEND CPP_SOURCES
SocketInterface/RiaSocketServer.cpp
)
list( APPEND REFERENCED_CMAKE_FILES
@ -179,6 +182,7 @@ precompiled_header( RAW_SOURCES ALL_INCLUDES ${GCC_PCH_TARGET} ${PCH_NAME} ${PCH
source_group( "Application" FILES ${APPLICATION_FILES} )
source_group( "ModelVisualization" FILES ${MODEL_VISUALIZATION_FILES} )
source_group( "UserInterface" FILES ${USER_INTERFACE_FILES} )
source_group( "SocketInterface" FILES ${SOCKET_INTERFACE_FILES} )
add_executable(ResInsight

View File

@ -0,0 +1,116 @@
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "RiaSocketServer.h"
#include "RimReservoirView.h"
#include "RimResultSlot.h"
#include "RimCellEdgeResultSlot.h"
#include "RimCellRangeFilterCollection.h"
#include "RimCellPropertyFilterCollection.h"
#include "RimWellCollection.h"
#include "Rim3dOverlayInfoConfig.h"
#include "RimReservoirCellResultsCacher.h"
#include "RimCase.h"
#include "RigCaseData.h"
#include "RigCaseCellResultsData.h"
class RiaGetTimeStepDates : public RiaSocketCommand
{
public:
static QString commandName () { return QString("GetTimeStepDates"); }
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
{
int argCaseGroupId = -1;
if (args.size() == 2)
{
argCaseGroupId = args[1].toInt();
}
RimCase* rimCase = server->findReservoir(argCaseGroupId);
bool canFetchData = true;
if (!rimCase || !rimCase->reservoirData())
{
canFetchData = false;
}
size_t scalarIndexWithMaxTimeStepCount = cvf::UNDEFINED_SIZE_T;
if (rimCase && rimCase->reservoirData())
{
rimCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount(&scalarIndexWithMaxTimeStepCount);
if (scalarIndexWithMaxTimeStepCount == cvf::UNDEFINED_SIZE_T)
{
canFetchData = false;
}
}
// Did not find any result to fetch data from, return zero data found
if (!canFetchData)
{
quint64 timeStepCount = 0;
quint64 byteCount = sizeof(quint64);
socketStream << byteCount;
socketStream << timeStepCount;
return true;
}
std::vector<QDateTime> timeStepDates = rimCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(scalarIndexWithMaxTimeStepCount);
quint64 timeStepCount = timeStepDates.size();
quint64 byteCount = sizeof(quint64) + timeStepCount * sizeof(qint32);
socketStream << byteCount;
socketStream << timeStepCount;
for (size_t i = 0; i < timeStepCount; i++)
{
qint32 intValue = 0;
intValue = timeStepDates[i].date().year();
socketStream << intValue;
intValue = timeStepDates[i].date().month();
socketStream << intValue;
intValue = timeStepDates[i].date().day();
socketStream << intValue;
intValue = timeStepDates[i].time().hour();
socketStream << intValue;
intValue = timeStepDates[i].time().minute();
socketStream << intValue;
intValue = timeStepDates[i].time().second();
socketStream << intValue;
}
return true;
}
};
static bool RiaGetTimeStepDates_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetTimeStepDates>(RiaGetTimeStepDates::commandName());

View File

@ -54,17 +54,6 @@
class RiaSocketCommand
{
public:
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) = 0;
virtual bool interpretMore(QDataStream& stream) { return true; }
};
typedef caf::Factory<RiaSocketCommand, QString> RiaSocketCommandFactory;
RimCase * findCaseFromArgs(RiaSocketServer* server, const QList<QByteArray>& args )
{

View File

@ -21,6 +21,7 @@
#include <QDialog>
#include <QAbstractSocket>
#include "RifReaderInterface.h"
#include "cafFactory.h"
class QLabel;
class QPushButton;
@ -86,3 +87,19 @@ private:
//////////////////////////////////////////////////////////////////////////
/// Socket commands, to be moved into a separate file
//////////////////////////////////////////////////////////////////////////
class RiaSocketCommand
{
public:
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) = 0;
virtual bool interpretMore(QDataStream& stream) { return true; }
};
typedef caf::Factory<RiaSocketCommand, QString> RiaSocketCommandFactory;
void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId);

View File

@ -9,6 +9,7 @@ set(CPP_SOURCES
riGetCaseGroups.cpp
riGetSelectedCases.cpp
riGetCases.cpp
riGetTimeStepDates.cpp
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
@ -107,6 +108,7 @@ else()
"${CMAKE_CURRENT_BINARY_DIR}/riGetCaseGroups.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetSelectedCases.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetCases.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetTimeStepDates.oct"
SOURCES ${CPP_SOURCES}
)

View File

@ -0,0 +1,184 @@
#include <QtNetwork>
#include <octave/oct.h>
#include <octave/oct-map.h>
#include "riSettings.h"
void getTimeStepDates( std::vector<qint32>& yearValues,
std::vector<qint32>& monthValues,
std::vector<qint32>& dayValues,
std::vector<qint32>& hourValues,
std::vector<qint32>& minuteValues,
std::vector<qint32>& secondValues,
const qint64& caseId,
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("GetTimeStepDates %1").arg(caseId);
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 timeStepCount;
socketStream >> timeStepCount;
for (size_t i = 0; i < timeStepCount; i++)
{
qint32 intValue;
socketStream >> intValue;
yearValues.push_back(intValue);
socketStream >> intValue;
monthValues.push_back(intValue);
socketStream >> intValue;
dayValues.push_back(intValue);
socketStream >> intValue;
hourValues.push_back(intValue);
socketStream >> intValue;
minuteValues.push_back(intValue);
socketStream >> intValue;
secondValues.push_back(intValue);
}
return;
}
DEFUN_DLD (riGetTimeStepDates, args, nargout,
"Usage:\n"
"\n"
" riGetTimeStepDates()\n"
"\n"
"This function returns the date information for each of the time steps in the case as a Vector of Structures.\n"
"The Structure is defined as:\n"
"TimeStepDate = {\n"
" Year = int # The year eg. 2013\n"
" Month = int # The month. Eg. 12\n"
" Day = int # The day in the month. Eg. 24\n"
" Hour = int # The hour of the day. Eg. 17\n"
" Minute = int # The minute in the hour. Eg. 55\n"
" Second = int # The second within the minute. Eg. 30\n"
"}\n"
"If the CaseId is not defined, ResInsights Current Case is used.\n"
)
{
int nargin = args.length ();
if (nargin > 1)
{
error("riGetTimeStepDates: Too many arguments, this function takes one optional argument.\n");
print_usage();
}
else if (nargout != 1)
{
error("riGetTimeStepDates: Wrong number of output arguments, this function requires one output argument.\n");
print_usage();
}
else
{
qint64 caseId = -1;
if (nargin > 0)
{
if (args(0).is_numeric_type())
{
unsigned int argCaseId = args(0).uint_value();
caseId = argCaseId;
}
}
std::vector<qint32> yearValues;
std::vector<qint32> monthValues;
std::vector<qint32> dayValues;
std::vector<qint32> hourValues;
std::vector<qint32> minuteValues;
std::vector<qint32> secondValues;
getTimeStepDates(yearValues, monthValues, dayValues, hourValues, minuteValues, secondValues, caseId, "127.0.0.1", 40001);
size_t timeStepDateCount = yearValues.size();
// Create cells with N items for each field in the data structure
Cell cellValuesA(timeStepDateCount, 1);
Cell cellValuesB(timeStepDateCount, 1);
Cell cellValuesC(timeStepDateCount, 1);
Cell cellValuesD(timeStepDateCount, 1);
Cell cellValuesE(timeStepDateCount, 1);
Cell cellValuesF(timeStepDateCount, 1);
for (size_t i = 0; i < timeStepDateCount; i++)
{
cellValuesA(i) = yearValues[i];
cellValuesB(i) = monthValues[i];
cellValuesC(i) = dayValues[i];
cellValuesD(i) = hourValues[i];
cellValuesE(i) = minuteValues[i];
cellValuesF(i) = secondValues[i];
}
// Build a map between the field name and field cell values
Octave_map m;
m.assign(riOctavePlugin::timeStepDate_Year, cellValuesA);
m.assign(riOctavePlugin::timeStepDate_Month, cellValuesB);
m.assign(riOctavePlugin::timeStepDate_Day, cellValuesC);
m.assign(riOctavePlugin::timeStepDate_Hour, cellValuesD);
m.assign(riOctavePlugin::timeStepDate_Minute, cellValuesE);
m.assign(riOctavePlugin::timeStepDate_Second, cellValuesF);
return octave_value(m);
}
return octave_value();
}

View File

@ -31,5 +31,13 @@ namespace riOctavePlugin
// Octave data structure : CaseGroupInfo
char caseGroupInfo_CaseGroupId[] = "CaseGroupId";
char caseGroupInfo_CaseGroupName[] = "CaseName";
// Octave data structure : TimeStepDate
char timeStepDate_Year[] = "Year";
char timeStepDate_Month[] = "Month";
char timeStepDate_Day[] = "Day";
char timeStepDate_Hour[] = "Hour";
char timeStepDate_Minute[] = "Minute";
char timeStepDate_Second[] = "Second";
}