Commit e1dddb54 authored by bonnell's avatar bonnell

Make Query from the CLI return a value. Either the OutputString, the...

Make Query from the CLI return a value. Either the OutputString, the OutputValue or the OutputObject, based on user-settable option

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@22915 18c085ea-50e0-402c-830e-de6fd14e8384
parent fb6d34b5
......@@ -82,7 +82,15 @@ enhancements and bug-fixes that were added to this release.</p>
<a name="Query_changes"></a>
<p><b><font size="4">Changes to VisIt's picks and queries in version 2.8</font></b></p>
<ul>
<li></li>
<li>All queries now provide Xml results.</li>
<li>Queries called from the CLI have been modified to always return a value. The type of returned object is user-settable, and consists of 3 options:
<ul>
<li>String (default): <i>Same as calling GetQueryOutputString()</i> </li>
<li>Value: <i>Same as calling GetQueryOutputValue()</i></li>
<li>Object: <i>Same as calling GetQueryOutputObject()</i></li>
</ul>
The options are chosen via new methods: <i>SetQueryOutputToString()</i>, <i>SetQueryOutputToValue()</i>, or <i>SetQueryOutputToObject()</i>. The option remains valid for all queries during the current VisIt session, unless another call to <i>SetQueryOutputToXXX</i> is made. Calls to <i>GetQueryOutputXXX</i> can still be made, regardless of the query return type chosen. <b>NOTE:</b> The old query output messages are hereby suppressed when making a Query via the CLI.
</li>
<li></li>
</ul>
......
......@@ -5118,9 +5118,15 @@ const char *visit_Query_doc =
"\n"
"Synopsis:\n"
"\n"
"Query(name) -> integer\n"
"Query(name, dict) -> integer\n"
"Query(name, namedarg1=arg1,namedarg2=arg2, ...) -> integer\n"
"Query(name) -> string\n"
"Query(name, dict) -> string\n"
"Query(name, namedarg1=arg1,namedarg2=arg2, ...) -> string\n"
"Query(name) -> double, tuple of double\n"
"Query(name, dict) -> double, tuple of double\n"
"Query(name, namedarg1=arg1,namedarg2=arg2, ...) -> double, tuple of double\n"
"Query(name) -> dictionary\n"
"Query(name, dict) -> dictionary\n"
"Query(name, namedarg1=arg1,namedarg2=arg2, ...) -> dictionary\n"
"\n"
"\n"
"Arguments:\n"
......@@ -5135,7 +5141,10 @@ const char *visit_Query_doc =
"\n"
"Returns:\n"
"\n"
"The Query function returns 1 on success and 0 on failure.\n"
"The Query function returns either a String (default), Value(s), or Object.\n"
"The return type can be customized via calls to SetQueryOutputToXXX(), where\n"
"'XXX' is 'String', 'Value', or 'Object'. For more information on these\n"
"return types, see 'GetQueryOutput'.
"\n"
"\n"
"Description:\n"
......@@ -8386,6 +8395,117 @@ const char *visit_SuppressQueryOutput_doc =
"SuppressQueryOutputOff()\n"
"Query(\"MinMax\")\n"
;
const char *visit_SetQueryOutputToObject_doc =
"SetQueryOutputToObject\n"
"-Sets the query return type to 'Object' (python dictionary).\n"
"\n"
"\n"
"Synopsis:\n"
"\n"
"SetQueryOutputToObject()\n"
"\n"
"\n"
"Returns:\n"
"\n"
"SetQueryOutputToObject does not return a value.\n"
"\n"
"\n"
"Description:\n"
"\n"
"SetQueryOutputToObject changes the return type of future Queries to the\n"
"'object' or Python dictionary form. This is the same object that would be\n"
"returned by calling 'GetQueryOutputObject()' after a Query call. All other\n"
"output modes are still available after the Query call \n"
"(eg GetQueryOutputValue(),GetQueryOutputObject(), GetQueryOutputString()).\n"
"\n"
"\n"
"Example:\n"
"\n"
"% visit -cli\n"
"OpenDatabase(\"/usr/gapps/visit/data/rect2d.silo\")\n"
"AddPlot(\"Pseudocolor\", \"d\")\n"
"DrawPlots()\n"
"\n"
"# Set query output type.\n"
"SetQueryOutputToObject()\n"
"query_output = Query(\"MinMax\")\n"
"print query_output\n"
"{'min': 0.02357020415365696, 'max': 0.9489759802818298, 'max_element_num': 1170, 'min_coord': (0.4833333343267441, 0.4833333343267441), 'max_coord': (0.01666666753590107, 1.3166666626930237), 'max_domain': 0, 'min_element_num': 434, 'min_domain': 0}"
;
const char *visit_SetQueryOutputToValue_doc =
"SetQueryOutputToValue\n"
"-Sets the query return type to 'Value' form.\n"
"\n"
"\n"
"Synopsis:\n"
"\n"
"SetQueryOutputToValue()\n"
"\n"
"\n"
"Returns:\n"
"\n"
"SetQueryOutputToValue does not return a value.\n"
"\n"
"\n"
"Description:\n"
"\n"
"SetQueryOutputToValue changes the return type of future Queries to the\n"
"'value' form. This is the same as what would be returned by calling\n"
"'GetQueryOutputValue()' after a Query call. All other output modes are\n"
"still available after the Query call (eg GetQueryOutputValue(),\n"
"GetQueryOutputObject(), GetQueryOutputString()).\n"
"\n"
"\n"
"Example:\n"
"\n"
"% visit -cli\n"
"OpenDatabase(\"/usr/gapps/visit/data/rect2d.silo\")\n"
"AddPlot(\"Pseudocolor\", \"d\")\n"
"DrawPlots()\n"
"\n"
"# Set query output type.\n"
"SetQueryOutputToValue()\n"
"query_output = Query(\"MinMax\")\n"
"print query_output\n"
"(0.02357020415365696, 0.9489759802818298)"
;
const char *visit_SetQueryOutputToString_doc =
"SetQueryOutputToString\n"
"-Sets the query return type to 'String' form.\n"
"\n"
"\n"
"Synopsis:\n"
"\n"
"SetQueryOutputToString()\n"
"\n"
"\n"
"Returns:\n"
"\n"
"SetQueryOutputToString does not return a value.\n"
"\n"
"\n"
"Description:\n"
"\n"
"SetQueryOutputToString changes the return type of future Queries to the\n"
"'string' form. This is the same as what would be returned by calling\n"
"'GetQueryOutputString' after a Query call. All other output modes are\n"
"still available after the Query call (eg GetQueryOutputValue(),\n"
"GetQueryOutputObject(), GetQueryOutputString()).\n"
"\n"
"\n"
"Example:\n"
"\n"
"% visit -cli\n"
"OpenDatabase(\"/usr/gapps/visit/data/rect2d.silo\")\n"
"AddPlot(\"Pseudocolor\", \"d\")\n"
"DrawPlots()\n"
"\n"
"# Set query output type.\n"
"SetQueryOutputToString()\n"
"query_output = Query(\"MinMax\")\n"
"print query_output\n"
"'\nd -- Min = 0.0235702 (zone 434 at coord <0.483333, 0.483333>)\nd -- Max = 0.948976 (zone 1170 at coord <0.0166667, 1.31667>)\n\n'"
;
const char *visit_SetQueryFloatFormat_doc =
"SetQueryFloatFormat\n"
"-Sets the floating point format string used to generate query output.\n"
......
......@@ -227,6 +227,9 @@ extern const char *visit_SetPlotSILRestriction_doc;
extern const char *visit_SetPreferredFileFormats_doc;
extern const char *visit_SetPrecisionType_doc;
extern const char *visit_SetPrinterAttributes_doc;
extern const char *visit_SetQueryOutputToObject_doc;
extern const char *visit_SetQueryOutputToValue_doc;
extern const char *visit_SetQueryOutputToString_doc;
extern const char *visit_SetQueryFloatFormat_doc;
extern const char *visit_SetQueryOverTimeAttributes_doc;
extern const char *visit_SetRenderingAttributes_doc;
......
......@@ -469,6 +469,13 @@ typedef struct
static std::map<std::string, AnnotationObjectRef> localObjectMap;
static bool suppressQueryOutputState = false;
static enum QueryOutputReturnType {
QueryString = 0,
QueryValue,
QueryObject
} queryOutputReturnType = QueryString;
// pickle related
bool pickleReady=false;
PyObject *pickleDumps=NULL;
......@@ -1097,6 +1104,30 @@ CreateDictionaryFromDBOptions(DBOptionsAttributes &opts)
}
// ****************************************************************************
// Function: ToggleSuppressQueryOutput_NoLogging
//
// Purpose:
// Helper method for toggling SuppressQueryOutput without it being logged.
// Used when query ouput suppression is a consequence of another action,
// like with Pick functions.
//
// Programmer: Kathleen Bigagas
// Creation: January 9, 2012
//
// Modifications:
//
// ****************************************************************************
void
ToggleSuppressQueryOutput_NoLogging(bool onoff)
{
LogFile_IncreaseLevel();
GetViewerMethods()->SuppressQueryOutput(onoff);
Synchronize();
LogFile_DecreaseLevel();
}
//
// Python callbacks for VisIt
......@@ -8824,7 +8855,6 @@ STATIC PyObject *
visit_GetQueryOutputString(PyObject *self, PyObject *args)
{
ENSURE_VIEWER_EXISTS();
NO_ARGUMENTS();
std::string queryOut;
QueryAttributes *qa = GetViewerState()->GetQueryAttributes();
......@@ -8853,7 +8883,6 @@ STATIC PyObject *
visit_GetQueryOutputValue(PyObject *self, PyObject *args)
{
ENSURE_VIEWER_EXISTS();
NO_ARGUMENTS();
QueryAttributes *qa = GetViewerState()->GetQueryAttributes();
doubleVector vals = qa->GetResultsValue();
......@@ -8917,7 +8946,6 @@ STATIC PyObject *
visit_GetQueryOutputObject(PyObject *self, PyObject *args)
{
ENSURE_VIEWER_EXISTS();
NO_ARGUMENTS();
QueryAttributes *qa = GetViewerState()->GetQueryAttributes();
std::string xml_string = qa->GetXmlResult();
......@@ -11035,6 +11063,10 @@ visit_GetQueryParameters(PyObject *self, PyObject *args)
// E4ric Brugger, Mon May 14 10:51:24 PDT 2012
// I added the bov output type to the XRay Image query.
//
// Kathleen Biagas, Thu Feb 27 15:17:45 PST 2014
// Change return type (Object/Value/String) based on user request from
// SetQueryOutputToxxx calls. Default is string.
//
// ****************************************************************************
STATIC PyObject*
......@@ -11313,12 +11345,32 @@ visit_Query_deprecated(PyObject *self, PyObject *args)
params["vars"] = vars;
debug3 << mn << " sending query params: " << params.ToXML() << endl;
if (!suppressQueryOutputState)
ToggleSuppressQueryOutput_NoLogging(true);
MUTEX_LOCK();
GetViewerMethods()->Query(params);
GetViewerMethods()->Query(params);
MUTEX_UNLOCK();
Synchronize();
// Return the success value.
return IntReturnValue(Synchronize());
if (!suppressQueryOutputState)
ToggleSuppressQueryOutput_NoLogging(false);
// Return the output.
PyObject *retval = NULL;
if (QueryObject == queryOutputReturnType)
retval = visit_GetQueryOutputObject(self, args);
else if (QueryValue == queryOutputReturnType)
retval = visit_GetQueryOutputValue(self, args);
else if (QueryString == queryOutputReturnType)
retval = visit_GetQueryOutputString(self, args);
else
{
retval = Py_None;
Py_INCREF(retval);
}
return retval;
}
......@@ -11337,6 +11389,10 @@ visit_Query_deprecated(PyObject *self, PyObject *args)
// Kathleen Biagas, Wed Sep 7 12:46:24 PDT 2011
// Use VisItErrorFunc instead of cerr.
//
// Kathleen Biagas, Thu Feb 27 15:17:45 PST 2014
// Change return type (Object/Value/String) based on user request from
// SetQueryOutputToxxx calls. Default is string.
//
// ****************************************************************************
STATIC PyObject *
......@@ -11411,12 +11467,31 @@ visit_Query(PyObject *self, PyObject *args, PyObject *kwargs)
queryParams["query_name"] = std::string(queryName);
}
if (!suppressQueryOutputState)
ToggleSuppressQueryOutput_NoLogging(true);
MUTEX_LOCK();
GetViewerMethods()->Query(queryParams);
GetViewerMethods()->Query(queryParams);
MUTEX_UNLOCK();
Synchronize();
// Return the success value.
return IntReturnValue(Synchronize());
if (!suppressQueryOutputState)
ToggleSuppressQueryOutput_NoLogging(false);
// Return the output.
PyObject *retval = NULL;
if (QueryObject == queryOutputReturnType)
retval = visit_GetQueryOutputObject(self, args);
else if (QueryValue == queryOutputReturnType)
retval = visit_GetQueryOutputValue(self, args);
else if (QueryString == queryOutputReturnType)
retval = visit_GetQueryOutputString(self, args);
else
{
retval = Py_None;
Py_INCREF(retval);
}
return retval;
}
......@@ -11734,30 +11809,83 @@ visit_SuppressQueryOutputOff(PyObject *self, PyObject *args)
return IntReturnValue(Synchronize());
}
// ****************************************************************************
// Function: ToggleSuppressQueryOutput_NoLogging
// Function: visit_SetQueryOutputToObject
//
// Purpose:
// Helper method for toggling SuppressQueryOutput without it being logged.
// Used when query ouput suppression is a consequence of another action,
// like with Pick functions.
// Sets query return type to be the object(XML) form.
//
// Programmer: Kathleen Bigagas
// Creation: January 9, 2012
// Programmer: Kathleen Biagas
// Creation: February 27, 2014
//
// Modifications:
//
// ****************************************************************************
void
ToggleSuppressQueryOutput_NoLogging(bool onoff)
STATIC PyObject *
visit_SetQueryOutputToObject(PyObject *self, PyObject *args)
{
LogFile_IncreaseLevel();
GetViewerMethods()->SuppressQueryOutput(onoff);
Synchronize();
LogFile_DecreaseLevel();
NO_ARGUMENTS();
if (queryOutputReturnType != QueryObject)
{
queryOutputReturnType = QueryObject;
}
Py_INCREF(Py_None);
return Py_None;
}
// ****************************************************************************
// Function: visit_SetQueryOutputToValue
//
// Purpose:
// Sets query return type to be the value form.
//
// Programmer: Kathleen Biagas
// Creation: February 27, 2014
//
// Modifications:
//
// ****************************************************************************
STATIC PyObject *
visit_SetQueryOutputToValue(PyObject *self, PyObject *args)
{
NO_ARGUMENTS();
if (queryOutputReturnType != QueryValue)
{
queryOutputReturnType = QueryValue;
}
Py_INCREF(Py_None);
return Py_None;
}
// ****************************************************************************
// Function: visit_SetQueryOutputToString
//
// Purpose:
// Sets query return type to be the string form.
//
// Programmer: Kathleen Biagas
// Creation: February 27, 2014
//
// Modifications:
//
// ****************************************************************************
STATIC PyObject *
visit_SetQueryOutputToString(PyObject *self, PyObject *args)
{
NO_ARGUMENTS();
if (queryOutputReturnType != QueryString)
{
queryOutputReturnType = QueryString;
}
Py_INCREF(Py_None);
return Py_None;
}
// ****************************************************************************
// Function: visit_SetQueryFloatFormat()
//
......@@ -16961,6 +17089,9 @@ AddProxyMethods()
AddMethod("ShowToolbars", visit_ShowToolbars, visit_ShowToolbars_doc);
AddMethod("SuppressQueryOutputOn", visit_SuppressQueryOutputOn, visit_SuppressQueryOutput_doc);
AddMethod("SuppressQueryOutputOff", visit_SuppressQueryOutputOff, visit_SuppressQueryOutput_doc);
AddMethod("SetQueryOutputToObject", visit_SetQueryOutputToObject, visit_SetQueryOutputToObject_doc);
AddMethod("SetQueryOutputToValue", visit_SetQueryOutputToValue, visit_SetQueryOutputToValue_doc);
AddMethod("SetQueryOutputToString", visit_SetQueryOutputToString, visit_SetQueryOutputToString_doc);
AddMethod("SetQueryFloatFormat", visit_SetQueryFloatFormat, visit_SetQueryFloatFormat_doc);
AddMethod("TimeSliderGetNStates", visit_TimeSliderGetNStates,
visit_TimeSliderGetNStates_doc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment