Added riGetSelectedCases based on currently selected cases in the main tree view

p4#: 21604
This commit is contained in:
Magne Sjaastad 2013-05-13 22:32:01 +02:00
parent 10b49efae9
commit 22d45bc28f
5 changed files with 244 additions and 1 deletions

View File

@ -250,8 +250,9 @@ void RiaSocketServer::readCommandFromOctave()
bool isGetGridDim = args[0] == "GetMainGridDimensions"; // GetMainGridDimensions [casename/index]
bool isGetCurrentCase = args[0] == "GetCurrentCase";
bool isGetCaseGroups = args[0] == "GetCaseGroups";
bool isGetSelectedCases = args[0] == "GetSelectedCases";
if (!(isGetProperty || isSetProperty || isGetCellInfo || isGetGridDim || isGetCurrentCase || isGetCaseGroups))
if (!(isGetProperty || isSetProperty || isGetCellInfo || isGetGridDim || isGetCurrentCase || isGetCaseGroups || isGetSelectedCases))
{
m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Unknown command: %1").arg(args[0].data()));
terminateCurrentConnection();
@ -357,6 +358,42 @@ void RiaSocketServer::readCommandFromOctave()
return;
}
if (isGetSelectedCases)
{
RiuMainWindow* ruiMainWindow = RiuMainWindow::instance();
if (ruiMainWindow)
{
std::vector<qint64> caseIds;
std::vector<QString> caseNames;
std::vector<qint64> caseTypes;
std::vector<qint64> caseGroupIds;
ruiMainWindow->selectionInfo(caseIds, caseNames, caseTypes, caseGroupIds);
quint64 byteCount = sizeof(quint64);
quint64 selectionCount = caseIds.size();
for (size_t i = 0; i < selectionCount; i++)
{
byteCount += caseNames[i].size() * sizeof(QChar);
byteCount += 3*sizeof(qint64);
}
socketStream << byteCount;
socketStream << selectionCount;
for (size_t i = 0; i < selectionCount; i++)
{
socketStream << caseIds[i];
socketStream << caseNames[i];
socketStream << caseTypes[i];
socketStream << caseGroupIds[i];
}
}
return;
}
if (reservoir == NULL)
{

View File

@ -1520,3 +1520,36 @@ void RiuMainWindow::updateScaleValue()
m_scaleFactor->setEnabled(false);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainWindow::selectionInfo(std::vector<qint64>& caseIds, std::vector<QString>& caseNames, std::vector<qint64>& caseTypes, std::vector<qint64>& caseGroupIds)
{
if (m_treeView && m_treeView->selectionModel())
{
QModelIndexList selectedModelIndexes = m_treeView->selectionModel()->selectedIndexes();
for (int i = 0; i < selectedModelIndexes.size(); i++)
{
caf::PdmUiTreeItem* uiTreeItem = m_treeModelPdm->getTreeItemFromIndex(selectedModelIndexes[i]);
if (uiTreeItem && uiTreeItem->dataObject())
{
RimCase* rimCase = dynamic_cast<RimCase*>(uiTreeItem->dataObject().p());
if (rimCase)
{
caseIds.push_back(rimCase->caseId());
caseNames.push_back(rimCase->caseUserDescription());
caseTypes.push_back(-1);
qint64 caseGroupId = -1;
if (rimCase->parentGridCaseGroup())
{
caseGroupId = rimCase->parentGridCaseGroup()->groupId();
}
caseGroupIds.push_back(caseGroupId);
}
}
}
}
}

View File

@ -84,6 +84,8 @@ public:
void setCurrentObjectInTreeView(caf::PdmObject* object);
void selectionInfo(std::vector<qint64>& caseIds, std::vector<QString>& caseNames, std::vector<qint64>& caseTypes, std::vector<qint64>& caseGroupIds);
protected:
virtual void closeEvent(QCloseEvent* event);

View File

@ -7,6 +7,7 @@ set(CPP_SOURCES
riGetMainGridDimensions.cpp
riGetCurrentCase.cpp
riGetCaseGroups.cpp
riGetSelectedCases.cpp
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
@ -103,6 +104,7 @@ else()
"${CMAKE_CURRENT_BINARY_DIR}/riGetMainGridDimensions.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetCurrentCase.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetCaseGroups.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetSelectedCases.oct"
SOURCES ${CPP_SOURCES}
)

View File

@ -0,0 +1,169 @@
#include <QtNetwork>
#include <octave/oct.h>
#include "riSettings.h"
void getSelectedCases(std::vector<qint64>& caseIds, std::vector<QString>& caseNames, std::vector<qint64>& caseTypes, std::vector<qint64>& caseGroupIds, 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("GetSelectedCases");
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 selectionCount;
socketStream >> selectionCount;
qint64 caseId = -1;
QString caseName;
qint64 caseType = -1;
qint64 caseGroupId = -1;
for (size_t i = 0; i < selectionCount; i++)
{
socketStream >> caseId;
socketStream >> caseName;
socketStream >> caseType;
socketStream >> caseGroupId;
caseIds.push_back(caseId);
caseNames.push_back(caseName);
caseTypes.push_back(caseType);
caseGroupIds.push_back(caseGroupId);
}
return;
}
DEFUN_DLD (riGetSelectedCases, args, nargout,
"Usage:\n"
"\n"
" riGetSelectedCases()\n"
"\n"
"Returns meta information for the Selected Case(s) in ResInsight.\n"
)
{
int nargin = args.length ();
if (nargin > 0)
{
error("riGetCurrentCase: Too many arguments, this function does not take any arguments.\n");
print_usage();
}
else
{
std::vector<qint64> caseIds;
std::vector<QString> caseNames;
std::vector<qint64> caseTypes;
std::vector<qint64> caseGroupIds;
getSelectedCases(caseIds, caseNames, caseTypes, caseGroupIds, "127.0.0.1", 40001);
int caseCount = caseIds.size();
int maxStringLength = 0;
for (size_t i = 0; i < caseCount; i++)
{
if (caseNames[i].length() > maxStringLength)
{
maxStringLength = caseNames[i].length();
}
}
dim_vector dv (1, 1);
dv(0) = caseCount;
int32NDArray octave_caseIds;
octave_caseIds.resize(dv);
int32NDArray octave_caseTypes;
octave_caseTypes.resize(dv);
int32NDArray octave_caseGroupIds;
octave_caseGroupIds.resize(dv);
charMatrix ch;
ch.resize(caseCount, maxStringLength);
for (size_t i = 0; i < caseCount; i++)
{
octave_caseIds(i) = caseIds[i];
ch.insert(caseNames[i].toLatin1().data(), i, 0);
octave_caseTypes(i) = caseTypes[i];
octave_caseGroupIds(i) = caseGroupIds[i];
}
octave_value_list retval;
if (nargout >= 1)
{
retval(0) = octave_caseIds;
}
if (nargout >= 2)
{
retval(1) = octave_value (ch, true, '\'');
}
if (nargout >= 3)
{
retval(2) = octave_caseTypes;
}
if (nargout >= 4)
{
retval(3) = octave_caseGroupIds;
}
return retval;
}
return octave_value_list ();
}