Public Member Functions | Static Public Attributes | Protected Member Functions
MatlabTarget Class Reference

Brief description of class still missing. More...

#include <MatlabTarget.h>

Inheritance diagram for MatlabTarget:
QGpCoreTools::XMLClass

List of all members.

Public Member Functions

QString forwardScript () const
QString initScript () const
bool isEmpty () const
bool isOk (int nParams)
 MatlabTarget ()
 MatlabTarget (const MatlabTarget &o)
QString scriptPath () const
void setForwardScript (QString s)
void setInitScript (QString s)
void setScriptPath (QString s)
void setStartup (QString s)
QString startup () const
virtual const QString & xml_tagName () const

Static Public Attributes

static const QString xmlMatlabTargetTag = "MatlabTarget"

Protected Member Functions

virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual bool xml_setProperty (XML_SETPROPERTY_ARGS)
virtual void xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

{}
    : XMLClass()
{
  _startup=o._startup;
  _scriptPath=o._scriptPath;
  _initScript=o._initScript;
  _forwardScript=o._forwardScript;
}

Member Function Documentation

QString MatlabTarget::forwardScript ( ) const [inline]

Referenced by MatlabTargetWidget::setFrom().

{return _forwardScript;}
QString MatlabTarget::initScript ( ) const [inline]

Referenced by MatlabTargetWidget::setFrom().

{return _initScript;}
bool MatlabTarget::isEmpty ( ) const [inline]

Referenced by isOk().

{return _forwardScript.isEmpty();}
bool MatlabTarget::isOk ( int  nParams)

References QGpCoreTools::endl(), isEmpty(), MATLAB_OUTPUT_BUFFER_SIZE, QGpCoreTools::tr(), and TRACE.

{
  TRACE;
  if(isEmpty()) {
    return true;
  }
#ifdef GP_MATLAB_LIBS
  App::stream() << tr("Testing scripts ...") << endl;
  App::setStreamPrefix("[Testing] ");
  Engine * matlab=engOpen(_startup.toAscii().data());
  if( ! matlab) {
    App::stream() << tr("Error starting Matlab engine.") << endl;
    App::setStreamPrefix("");
    return false;
  }
  char buffer[MATLAB_OUTPUT_BUFFER_SIZE];
  buffer[MATLAB_OUTPUT_BUFFER_SIZE-1]='\0';
  engOutputBuffer(matlab, buffer, MATLAB_OUTPUT_BUFFER_SIZE);
  if(!_scriptPath.isEmpty()) {
    QString cmd="addpath('" + _scriptPath + "');";
    App::stream() << cmd << endl;
    if(engEvalString( matlab, cmd.toAscii().data())!=0) {
      App::stream() << tr("Error adding path '%1'.").arg(_scriptPath) << endl;
      if(buffer[0]!='\0') App::stream() << buffer+4 << endl;
      engClose(matlab);
      App::setStreamPrefix("");
      return false;
    }
  }
  if(buffer[0]!='\0') App::stream() << buffer+4 << endl;
  App::stream() << _initScript << endl;
  if(engEvalString( matlab, _initScript.toAscii().data())!=0) {
    App::stream() << tr("Error running initialization script '%1' in Matlab environment.").arg(_initScript) << endl;
    if(buffer[0]!='\0') App::stream() << buffer+4 << endl;
    engClose(matlab);
    App::setStreamPrefix("");
    return false;
  }
  if(buffer[0]!='\0') App::stream() << buffer+4 << endl;
  mxArray * dinverModel=mxCreateDoubleMatrix(1, nParams, mxREAL);
  for(int i=0; i<nParams;i++) {
    mxGetPr(dinverModel)[i]=0.0;
  }
  if(engPutVariable( matlab, "dinverModel", dinverModel)!=0) {
    App::stream() << tr("Error setting variable dinverModel in Matlab environment.") << endl;
    mxDestroyArray(dinverModel);
    engClose(matlab);
    App::setStreamPrefix("");
    return false;
  }
  mxArray * dinverOk=mxCreateLogicalScalar(true);
  if(engPutVariable( matlab, "dinverOk", dinverOk)!=0) {
    App::stream() << tr("Error setting variable dinverOk in Matlab environment.") << endl;
    mxDestroyArray(dinverOk);
    engClose(matlab);
    App::setStreamPrefix("");
    return false;
  }
  App::stream() << _forwardScript << endl;
  if(engEvalString( matlab, _forwardScript.toAscii().data())!=0) {
    App::stream() << tr("Error running forward script '%1' in Matlab environment.").arg(_forwardScript) << endl;
    if(buffer[0]!='\0') App::stream() << buffer+4 << endl;
    engClose(matlab);
    App::setStreamPrefix("");
    return false;
  }
  if(buffer[0]!='\0') App::stream() << buffer+4 << endl;
  mxArray * dinverMisfit=engGetVariable(matlab, "dinverMisfit" );
  if( ! dinverMisfit) {
    App::stream() << tr("Error retreiving variable 'dinverMisfit' from Matlab environment.") << endl;
    engClose(matlab);
    App::setStreamPrefix("");
    return false;
  }
  if(mxGetNumberOfDimensions( dinverMisfit)!=2 ||
       mxGetDimensions(dinverMisfit)[0]!=1 ||
       mxGetDimensions(dinverMisfit)[1]!=1) {
    App::stream() << tr("Error variable 'dinverMisfit' is not a scalar.") << endl;
    engClose(matlab);
    App::setStreamPrefix("");
    return false;
  }
  mxDestroyArray(dinverMisfit);
  engClose(matlab);
  App::setStreamPrefix("");
  return true;
#else
  Q_UNUSED(nParams);
  App::stream() << tr("Matlab engine not available, check your configuration.") << endl;
  return false;
#endif
}
QString MatlabTarget::scriptPath ( ) const [inline]

Referenced by MatlabTargetWidget::setFrom().

{return _scriptPath;}
void MatlabTarget::setForwardScript ( QString  s) [inline]

Referenced by MatlabTargetWidget::target().

{_forwardScript=s;}
void MatlabTarget::setInitScript ( QString  s) [inline]

Referenced by MatlabTargetWidget::target().

{_initScript=s;}
void MatlabTarget::setScriptPath ( QString  s) [inline]

Referenced by MatlabTargetWidget::target().

{_scriptPath=s;}
void MatlabTarget::setStartup ( QString  s) [inline]

Referenced by MatlabTargetWidget::target().

{_startup=s;}
QString MatlabTarget::startup ( ) const [inline]

Referenced by MatlabTargetWidget::setFrom().

{return _startup;}

Re-implement this function to offer XML restore (children and properties) support to your class.

From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:

  • An integer: id number of a property
  • A XMLClass * : a child of this object identified by tag
  • Default constructor: error, unknow child or property

Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):

    static const QString tmp("childrenName");
    XMLRestoreAttributeIterator it=map.find(tmp);
    if(it!=map.end()) {
      // found attribute "childrenName"
    }

If the map of attributes is not used:

    Q_UNUSED(attributes);
    if(tag=="x1") return XMLMember(0);
    else if(tag=="y1") return XMLMember(1);
    else if(tag=="x2") return XMLMember(2);
    else if(tag=="y2") return XMLMember(3);
    else return XMLMember(XMLMember::Unknown);

Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.

    if(tag=="anInteger") return XMLMember(0);
    else if(tag=="aString") return XMLMember(1);
    else if(tag=="aDouble") return XMLMember(2);
    return AbstractLine::xml_member(tag, attributes, context)+3;

For the arguments of this function use Macro XML_MEMBER_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References TRACE.

{
  TRACE;
  Q_UNUSED(attributes)
  Q_UNUSED(context);
  if(tag=="startup" ) return XMLMember(0);
  else if(tag=="scriptPath" ) return XMLMember(1);
  else if(tag=="initScript" ) return XMLMember(2);
  else if(tag=="forwardScript" ) return XMLMember(3);
  else return XMLMember(XMLMember::Unknown);
}
bool MatlabTarget::xml_setProperty ( XML_SETPROPERTY_ARGS  ) [protected, virtual]

Re-implement this function to offer XML restore properties support to your class.

From memberID set the corresponding property with value content. The map of attributes is given as a supplementary information (not useful in all cases).

For a general case:

  Q_UNUSED(attributes);
  double val=content.toDouble();
  switch (memberID) {
  case 0:
    _x1=val;
    return true;
  case 1:
    _y1=val;
    return true;
  case 2:
    _x2=val;
    return true;
  case 3:
    _y2=val;
    return true;
  default:
    return false;
  }

For classes inheriting other classes (see also xml_member())

  switch (memberID) {
  case 0:
    _anInteger=content.toString();
    return true;
  case 1:
    _aString=content.toInt();
    return true;
  case 2:
    _aDouble=content.toDouble();
    return true;
  default:
    return AbstractLine::xml_setProperty(memberID-3, map, content);

For the arguments of this function use Macro XML_SETPROPERTY_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References TRACE.

{
  TRACE;
  Q_UNUSED(tag)
  Q_UNUSED(attributes)
  Q_UNUSED(context);
  switch (memberID) {
  case 0: _startup=content.toString(); return true;
  case 1: _scriptPath=content.toString(); return true;
  case 2: _initScript=content.toString(); return true;
  case 3: _forwardScript=content.toString(); return true;
  default: return false;
  }
}
virtual const QString& MatlabTarget::xml_tagName ( ) const [inline, virtual]
void MatlabTarget::xml_writeProperties ( XML_WRITEPROPERTIES_ARGS  ) const [protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

References TRACE, and QGpCoreTools::XMLClass::writeProperty().

{
  TRACE;
  Q_UNUSED(context);
  writeProperty(s, "startup", _startup);
  writeProperty(s, "scriptPath", _scriptPath);
  writeProperty(s, "initScript", _initScript);
  writeProperty(s, "forwardScript", _forwardScript);
}

Member Data Documentation

const QString MatlabTarget::xmlMatlabTargetTag = "MatlabTarget" [static]

Referenced by xml_tagName().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines