Commit cb37ae4b authored by allens's avatar allens
Browse files

added support for QTableWidgets in the libsim

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@27810 18c085ea-50e0-402c-830e-de6fd14e8384
parent 90fb5534
......@@ -65,9 +65,9 @@ class DBATTS_API avtSimulationInformation : public AttributeSubject
public:
enum RunMode
{
Unknown,
Running,
Stopped
Unknown = 0,
Running = 1,
Stopped = 2
};
// These constructors are for objects of this class
......
......@@ -103,6 +103,7 @@ using std::ostringstream;
#include <simv2_ExpressionMetaData.h>
#include <simv2_MaterialMetaData.h>
#include <simv2_MeshMetaData.h>
#include <simv2_MessageMetaData.h>
#include <simv2_NameList.h>
#include <simv2_SimulationMetaData.h>
#include <simv2_SpeciesMetaData.h>
......@@ -1011,6 +1012,44 @@ CommandMetaDataToCommandSpec(visit_handle h, avtSimulationCommandSpecification &
scs.SetArgumentType(avtSimulationCommandSpecification::CmdArgNone);
free(name);
}
int enabled = 1;
if(simv2_CommandMetaData_getEnabled(h, &enabled) == VISIT_OKAY)
{
scs.SetEnabled(enabled);
}
}
// ****************************************************************************
// Method: MessageMetaDataToString
//
// Purpose:
// Populates string from MessageMetaData.
//
// Arguments:
//
// Returns:
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Tue Mar 9 13:46:29 PST 2010
//
// Modifications:
//
// ****************************************************************************
void
MessageMetaDataToString(visit_handle h, std::string &str)
{
char *name = NULL;
if(simv2_MessageMetaData_getName(h, &name) == VISIT_OKAY)
{
str = std::string(name);
free(name);
}
}
#endif
......@@ -1267,6 +1306,25 @@ avtSimV2FileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
}
}
//
// Add simulation messages.
//
int numMessages = 0;
simv2_SimulationMetaData_getNumMessages(h, numMessages);
for (int i=0; i < numMessages; i++)
{
visit_handle cHandle = VISIT_INVALID_HANDLE;
if(simv2_SimulationMetaData_getMessage(h, i, cHandle) == VISIT_OKAY)
{
std::string message;
MessageMetaDataToString(cHandle, message);
md->GetSimInfo().SetMessage(message);
}
}
if (DebugStream::Level4())
{
debug4 << mName << "Returning meta data:" << endl;
......
......@@ -54,6 +54,7 @@
#include <QLayout>
#include <QLineEdit>
#include <QMessageBox>
#include <QMetaMethod>
#include <QMetaObject>
#include <QProgressBar>
#include <QPushButton>
......@@ -63,6 +64,8 @@
#include <QSpinBox>
#include <QSplitter>
#include <QTextEdit>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QTreeWidget>
#include <DebugStream.h>
......@@ -265,6 +268,7 @@ QvisSimulationWindow::CreateWindowContents()
this, SLOT(executePushButtonCommand(const QString &)));
connect(simCommands, SIGNAL(showCommandWindow()),
this, SLOT(showCommandWindow()));
connect(simCommands, SIGNAL(executeStart(const QString &)),
this, SLOT(executeStartCommand(const QString &)));
connect(simCommands, SIGNAL(executeStop(const QString &)),
......@@ -424,6 +428,21 @@ ConnectUIChildren(QObject *obj, SimCommandSlots *cc)
qDebug(" %d: ctor: %s", m, mm.signature());
}
#endif
#if 0
// Useful for getting slot signature
for(int m = 0; m < mo->methodCount(); ++m)
{
QMetaMethod mm = mo->method(m);
if(mm.methodType() == QMetaMethod::Signal)
{
std::cerr << ui->objectName().toStdString() << " "
<< mm.signature() << std::endl;
}
}
#endif
if (mo->indexOfSignal("clicked()") != -1)
{
//qDebug("connect %s clicked()\n", ui->objectName().toStdString().c_str());
......@@ -441,45 +460,45 @@ ConnectUIChildren(QObject *obj, SimCommandSlots *cc)
if (mo->indexOfSignal("valueChanged(const QDate&)") != -1)
{
QObject::connect(ui, SIGNAL(valueChanged(const QDate&)),
cc, SLOT(ValueChangedHandler(const QDate &)));
cc, SLOT(ValueChangedHandler(const QDate &)));
}
if (mo->indexOfSignal("valueChanged(const QTime&)") != -1)
{
QObject::connect(ui, SIGNAL(valueChanged(const QTime&)),
cc, SLOT(ValueChangedHandler(const QTime &)));
cc, SLOT(ValueChangedHandler(const QTime &)));
}
if (mo->indexOfSignal("itemChanged(QTableWidgetItem)") != -1)
{
QObject::connect(ui, SIGNAL(itemChanged(const QTableWidgetItem &item)),
cc, SLOT(ItemChangedHandler(const QTableWidgetItem &)));
}
if (mo->indexOfSignal("stateChanged(int)") != -1)
{
//qDebug("connect %s stateChanged(int)\n", ui->objectName().toStdString().c_str());
QObject::connect(ui, SIGNAL(stateChanged(int)),
cc, SLOT(StateChangedHandler(int)));
cc, SLOT(StateChangedHandler(int)));
}
if (mo->indexOfSignal("activated(int)") != -1)
{
//qDebug("connect %s activated(int)\n", ui->objectName().toStdString().c_str());
QObject::connect(ui, SIGNAL(activated(int)),
cc, SLOT(ActivatedHandler(int)));
cc, SLOT(ActivatedHandler(int)));
}
if (mo->indexOfSignal("textChanged(QString)") != -1)
{
QObject::connect(ui, SIGNAL(textChanged(const QString &)),
cc, SLOT(TextChangedHandler(const QString&)));
cc, SLOT(TextChangedHandler(const QString&)));
}
if (mo->indexOfSignal("currentChanged(int,int)") != -1)
if (mo->indexOfSignal("cellChanged(int,int)") != -1)
{
QObject::connect(ui, SIGNAL(currentChanged(int, int)),
cc, SLOT(CurrentChangedHandler(int, int)));
}
if (mo->indexOfSignal("valueChanged(int,int)") != -1)
{
QObject::connect(ui, SIGNAL(valueChanged(int, int)),
cc, SLOT(ValueChangedHandler(int, int)));
QObject::connect(ui, SIGNAL(cellChanged(int, int)),
cc, SLOT(CellChangedHandler(int, int)));
}
// We've hooked up signals for this object, now do its children.
......@@ -658,12 +677,14 @@ QvisSimulationWindow::UpdateUIComponent (QWidget *window,
#endif
void
QvisSimulationWindow::UpdateUIComponent(QWidget *window, const QString &name, const QString &value, bool e)
QvisSimulationWindow::UpdateUIComponent(QWidget *window, const QString &name,
const QString &value, bool e)
{
QObject *ui = window->findChild<QWidget *>(name);
if (ui)
{
debug5 << "Looking up component = " << name.toStdString().c_str() << endl;
debug5 << "Looking up component = "
<< name.toStdString().c_str() << endl;
// Block signals so updating the user interface does not cause a
// command to go back to the simulation.
......@@ -681,7 +702,7 @@ QvisSimulationWindow::UpdateUIComponent(QWidget *window, const QString &name, co
if (ui->inherits( "QLineEdit"))
{
debug5 << "found button " << name.toStdString() << " text = "
debug5 << "found line edit " << name.toStdString() << " text = "
<< value.toStdString() << endl;
((QLineEdit*)ui)->setText(value );
}
......@@ -765,6 +786,40 @@ QvisSimulationWindow::UpdateUIComponent(QWidget *window, const QString &name, co
((QCheckBox*)ui)->setChecked(value=="1");
}
if (ui->inherits("QTableWidget"))
{
((QWidget *)ui)->setEnabled(true);
char var[128];
char val[128];
int row, column;
sscanf (value.toStdString().c_str(),"%d | %d | %s",
&row, &column, val);
debug5 << "found QTableWidget " << name.toStdString()
<< " row = " << row << " column = " << column
<< std::endl;
QTableWidgetItem *newItem =
new QTableWidgetItem(tr("%1").arg(val));
if( e )
newItem->setFlags( Qt::ItemIsSelectable |
Qt::ItemIsEditable |
Qt::ItemIsEnabled );
else
newItem->setFlags(Qt::NoItemFlags);
if( ((QTableWidget*)ui)->rowCount() < row )
((QTableWidget*)ui)->setRowCount(row+1);
if( ((QTableWidget*)ui)->columnCount() < column )
((QTableWidget*)ui)->setColumnCount(column+1);
((QTableWidget*)ui)->setItem(row, column, newItem);
}
// Unblock signals.
ui->blockSignals(false);
}
......@@ -1272,12 +1327,20 @@ QvisSimulationWindow::UpdateInformation()
}
else
{
avtSimulationCommandSpecification::CommandArgumentType t;
t = md->GetSimInfo().GetGenericCommands(c).GetArgumentType();
bool e = md->GetSimInfo().GetGenericCommands(c).GetEnabled();
avtSimulationCommandSpecification cmd =
md->GetSimInfo().GetGenericCommands(c);
avtSimulationCommandSpecification::CommandArgumentType t =
cmd.GetArgumentType();
if (t == avtSimulationCommandSpecification::CmdArgNone)
{
QString bName = QString(md->GetSimInfo().GetGenericCommands(c).GetName().c_str());
QString bName = QString(cmd.GetName().c_str());
bool e = cmd.GetEnabled();
// std::cerr << cmd.GetName() << " " << cmd.GetEnabled()
// << std::endl;
updateSize |= simCommands->setButtonCommand(c, bName);
simCommands->setButtonEnabled(c, e);
}
......@@ -1292,9 +1355,10 @@ QvisSimulationWindow::UpdateInformation()
simCommands->adjustSize();
}
// If we've not created a dynamic commands window already and we can get a
// decent-looking UI filename, enabled the custom command button
// so we can create a window when that button is clicked.
// If we've not created a dynamic commands window already and
// we can get a decent-looking UI filename, enabled the custom
// command button so we can create a window when that button
// is clicked.
if(DynamicCommandsWin == NULL)
{
QString fname(GetUIFile(activeEngine));
......
......@@ -176,8 +176,8 @@ private:
QvisUiLoader *uiLoader;
QMap<int,int> simulationToEngineListMap;
QvisStripChartMgr *stripCharts;
QvisSimulationMessageWindow *simMessages;
QvisSimulationCommandWindow *simCommands;
QvisSimulationCommandWindow *simCommands;
QvisSimulationMessageWindow *simMessages;
};
#endif
......@@ -266,14 +266,14 @@ void SimCommandSlots::StateChangedHandler(int OnOff)
}
// ****************************************************************************
// Method: SimCommandSlots::CurrentChangedHandler
// Method: SimCommandSlots::CellChangedHandler
//
// Purpose:
// This is the CurrentChangedHandler signal handler function. It is generated
// This is the CellChangedHandler signal handler function. It is generated
// when the users changes a text value inside a text custom UI widget.
//
// Programmer: Shelly Prevost
// Creation: Jan 6, 2006
// Creation: Mon Jun 18 16:56:13 PDT 2007
//
// Modifications:
// Brad Whitlock, Tue Jul 8 11:28:04 PDT 2008
......@@ -281,10 +281,10 @@ void SimCommandSlots::StateChangedHandler(int OnOff)
//
// ****************************************************************************
void SimCommandSlots::CurrentChangedHandler(int row, int col)
void SimCommandSlots::CellChangedHandler(int row, int col)
{
const QObject *ui = sender();
debug5 << "inside CurrentChangedHandler signal" << endl;
debug5 << "inside CellChangedHandler signal" << endl;
QString tvalue;
if (ui)
{
......@@ -296,44 +296,11 @@ void SimCommandSlots::CurrentChangedHandler(int row, int col)
}
else
debug5 << "unknown signaler" << endl;
QString value = QString::number(row) + ";" + QString::number(col) + ";" + tvalue;
SendCMD("currentChanged(int,int)", ui, value);
}
QString value =
QString::number(row) + " | " + QString::number(col) + " | " + tvalue;
// ****************************************************************************
// Method: SimCommandSlots::ValueChangedHandler
//
// Purpose:
// This is the CurrentChangedHandler signal handler function. It is generated
// when the users changes a text value inside a text custom UI widget.
//
// Programmer: Shelly Prevost
// Creation: Mon Jun 18 16:56:13 PDT 2007
//
// Modifications:
// Brad Whitlock, Tue Jul 8 11:28:04 PDT 2008
// Qt 4.
//
// ****************************************************************************
void SimCommandSlots::ValueChangedHandler(int row, int col)
{
const QObject *ui = sender();
debug5 << "inside ValueChangedHandler signal" << endl;
QString tvalue;
if (ui)
{
debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
<< ui->objectName().toStdString().c_str() << " parent " << ui->parent()->objectName().toStdString().c_str() << endl;
tvalue = ((QTableWidget *)ui)->item(row, col)->text();
debug5 << "New Value row,col,text = " << row << ", " << col << ", "
<< tvalue.toStdString() << endl;
}
else
debug5 << "unknown signaler" << endl;
QString value = QString::number(row) + ";" + QString::number(col) + ";" + tvalue;
SendCMD("valueChanged(int,int)", ui, value);
SendCMD("cellChanged(int,int)", ui, value);
}
// ****************************************************************************
......@@ -353,7 +320,7 @@ void SimCommandSlots::ValueChangedHandler(int row, int col)
void SimCommandSlots::ActivatedHandler(int index)
{
const QObject *ui = sender();
debug5 << "inside ValueChangedHandler signal" << endl;
debug5 << "inside ActivateHandler signal" << endl;
if (ui)
{
debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
......
......@@ -82,8 +82,7 @@ public slots:
void ValueChangedHandler(const QDate &theDate);
void ActivatedHandler(int);
void StateChangedHandler(int);
void CurrentChangedHandler(int, int);
void ValueChangedHandler(int, int);
void CellChangedHandler(int, int);
int SendCMD(QString sig, const QObject *ui,QString value);
private:
......
......@@ -81,6 +81,7 @@ LibsimLibrary::LibsimLibrary(const char* lib) :
mVisIt_CommandMetaData_alloc = (int (*)(visit_handle*)) mLibsim.symbol("VisIt_CommandMetaData_alloc");
mVisIt_CommandMetaData_setName = (int (*)(visit_handle,const char*)) mLibsim.symbol("VisIt_CommandMetaData_setName");
mVisIt_CommandMetaData_setEnable = (int (*)(visit_handle,const int)) mLibsim.symbol("VisIt_CommandMetaData_setEnable");
mDomainList_setDomains = (int (*)(visit_handle,int,visit_handle)) mLibsim.symbol("VisIt_DomainList_setDomains");
mVariableData_setDataI = (int (*)(visit_handle,int,int,int,int*)) mLibsim.symbol("VisIt_VariableData_setDataI");
......
......@@ -127,6 +127,8 @@ public:
return mVisIt_CommandMetaData_alloc(h); }
int CommandMetaData_setName(visit_handle h,const char *name) {
return mVisIt_CommandMetaData_setName(h,name); }
int CommandMetaData_setEnable(visit_handle h,const int) {
return mVisIt_CommandMetaData_setEnable(h,enable); }
int MeshMetaData_alloc(visit_handle *h) {
return mVisIt_MeshMetaData_alloc(h); }
......
......@@ -2,6 +2,8 @@
<Attribute name="CommandMetaData" purpose="" persistent="false" keyframe="false" exportAPI="" exportInclude="" codefile="CommandMetaData.code">
<Field name="name" label="name" type="string">
</Field>
<Field name="enabled" label="enabled" type="int">
</Field>
<Function name="simv2_CommandMetaData_check" user="true" member="true">
</Function>
</Attribute>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SimUI.h"
......@@ -54,6 +55,7 @@ sim_ui_handle(const char *name, char *args)
{
int handled = 0;
const sim_ui_element *ui = sim_ui_find(name);
if(ui != NULL)
{
/* Get the arguments. */
......@@ -101,6 +103,14 @@ sim_ui_handle(const char *name, char *args)
(*ui->slot_stateChanged)(ivalue, ui->slot_stateChanged_data);
++handled;
}
if(strcmp(signalName, "cellChanged(int,int)") == 0 &&
ui->slot_cellChanged != NULL)
{
char *text = value;
(*ui->slot_cellChanged)(value, ui->slot_cellChanged_data);
++handled;
}
}
return (handled > 0) ? 1 : 0;
......
......@@ -18,6 +18,9 @@ typedef struct
void (*slot_stateChanged)(int, void *);
void *slot_stateChanged_data;
void (*slot_cellChanged)(char*, void *);
void *slot_cellChanged_data;
} sim_ui_element;
int sim_ui_handle(const char *name, char *args);
......
......@@ -4176,6 +4176,22 @@ VisItUI_textChanged(const char *name, void (*cb)(char*,void*), void *cbdata)
return retval;
}
int
VisItUI_cellChanged(const char *name, void (*cb)(char*,void*), void *cbdata)
{
int retval = VISIT_ERROR;
sim_ui_element *e = NULL;
LIBSIM_API_ENTER(VisItUI_cellChanged);
if((e = sim_ui_get(name)) != NULL)
{
e->slot_cellChanged = cb;
e->slot_cellChanged_data = cbdata;
retval = VISIT_OKAY;
}
LIBSIM_API_LEAVE(VisItUI_cellChanged);
return retval;
}
int
VisItUI_setValueI(const char *name, int value, int enabled)
{
......@@ -4186,7 +4202,25 @@ VisItUI_setValueI(const char *name, int value, int enabled)
if (engine && callbacks != NULL && callbacks->control.execute_command)
{
char cmd[500];
sprintf(cmd, "SetUI:i:%s:%d:%d", name, value, enabled?1:0);
sprintf(cmd, "SetUI:s:%s:%d:%d", name, value, enabled?1:0);
(*callbacks->control.execute_command)(engine, cmd);
retval = VISIT_OKAY;
}
LIBSIM_API_LEAVE(VisItUI_setValueI)
return retval;
}
int
VisItUI_setValueD(const char *name, double value, int enabled)
{
int retval = VISIT_ERROR;
LIBSIM_API_ENTER(VisItUI_setValueI);
/* Make sure the function exists before using it. */
if (engine && callbacks != NULL && callbacks->control.execute_command)
{
char cmd[500];
sprintf(cmd, "SetUI:s:%s:%lf:%d", name, value, enabled?1:0);
(*callbacks->control.execute_command)(engine, cmd);
retval = VISIT_OKAY;
}
......@@ -4212,6 +4246,67 @@ VisItUI_setValueS(const char *name, const char *value, int enabled)
return retval;
}
int
VisItUI_setTableValueI(const char *name,
int row, int column, int value, int enabled)
{
int retval = VISIT_ERROR;
LIBSIM_API_ENTER(VisItUI_setTableValueI);
/* Make sure the function exists before using it. */
if (engine && callbacks != NULL && callbacks->control.execute_command)
{
char cmd[500];
sprintf(cmd, "SetUI:s:%s:%d | %d | %d :%d",
name, row, column, value, enabled?1:0);
(*callbacks->control.execute_command)(engine, cmd);
retval = VISIT_OKAY;
}
LIBSIM_API_LEAVE(VisItUI_setTableValueI)
return retval;
}
int
VisItUI_setTableValueD(const char *name,
int row, int column, double value, int enabled)
{
int retval = VISIT_ERROR;
LIBSIM_API_ENTER(VisItUI_setTableValueI);
/* Make sure the function exists before using it. */
if (engine && callbacks != NULL && callbacks->control.execute_command)
{
char cmd[500];
sprintf(cmd, "SetUI:s:%s:%d | %d | %lf :%d",
name, row, column, value, enabled?1:0);
(*callbacks->control.execute_command)(engine, cmd);
retval = VISIT_OKAY;
}
LIBSIM_API_LEAVE(VisItUI_setTableValueI)
return retval;
}
int
VisItUI_setTableValueS(const char *name,
int row, int column, const char *value, int enabled)
{
int retval = VISIT_ERROR;
LIBSIM_API_ENTER(VisItUI_setTableValueS);
/* Make sure the function exists before using it. */
if (engine && callbacks != NULL && callbacks->control.execute_command)
{
char cmd[500];
sprintf(cmd, "SetUI:s:%s:%d | %d | %s :%d",
name, row, column, value, enabled?1:0);
(*callbacks->control.execute_command)(engine, cmd);
retval = VISIT_OKAY;
}
LIBSIM_API_LEAVE(VisItUI_setTableValueS)
return retval;
}
/***************************************************************************
EXPERIMENTAL PLOTTING CODE
......
......@@ -1328,10 +1328,19 @@ int VisItUI_clicked(const char *name, void (*cb)(void*), void *cbdata2);
int VisItUI_stateChanged(const char *name, void (*cb)(int,void*), void *cbdata2);
int VisItUI_valueChanged(const char *name, void (*cb)(int,void*), void *cbdata2);
int VisItUI_textChanged(const char *name, void (*cb)(char *,void*), void *cbdata2);
int VisItUI_cellChanged(const char *name, void (*cb)(char *,void*), void *cbdata2);
int VisItUI_setValueI(const char *name, int value, int enabled);
int VisItUI_setValueD(const char *name, double value, int enabled);
int VisItUI_setValueS(const char *name, const char *value, int enabled);
int VisItUI_setTableValueI(const char *name,
int row, int col, int value, int enabled);
int VisItUI_setTableValueD(const char *name,
int row, int col, double value, int enabled);