Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Properties
NAModelsPlot Class Reference

A NAModelsPlot is a layer to draw projection of a parameter space. More...

#include <NAModelsPlot.h>

Inheritance diagram for NAModelsPlot:
SciFigs::GraphContentLayer QGpGuiTools::PropertyItem QGpCoreTools::XMLClass

List of all members.

Public Member Functions

virtual void addProperties (PropertyProxy *pp)
virtual Rect boundingRect () const
double dotDiameter () const
double dotDiameterMM () const
virtual bool hasProperties ()
 NAModelsPlot (AxisWindow *parent=0)
int paramX () const
int paramY () const
virtual void properties (PropertyWidget *w) const
virtual void removeProperties (PropertyProxy *pp)
void setDotDiameter (double d)
void setDotDiameterMM (double d)
void setParamX (int px)
void setParamY (int py)
virtual void setParent (GraphContent *parent)
virtual void setProperty (uint wid, int pid, QVariant val)
virtual const QString & xml_tagName () const
 ~NAModelsPlot ()

Static Public Attributes

static const QString xmlNAModelsPlotTag = "NAModelsPlot"

Protected Member Functions

virtual void paintData (const LayerPainterRequest &lp, QPainter &p, double dotpercm) const
bool saveParameters () const
virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual bool xml_setProperty (XML_SETPROPERTY_ARGS)
virtual void xml_writeBinaryData (XML_WRITEBINARYDATA_ARGS) const
virtual void xml_writeChildren (XML_WRITECHILDREN_ARGS) const
virtual void xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const

Protected Attributes

int _paramX
int _paramY
PSViewer_psViewer
double _size

Static Protected Attributes

static uint _tab = PropertyProxy::uniqueId()

Properties

double dotDiameter

Detailed Description

A NAModelsPlot is a layer to draw projection of a parameter space.

No data is directly stored in this object. It access directly to models generated by NA engine.

The layer is exported either as a NAModelsPlot (for psViewer only) or as a XYValuePlot (available in Figue)


Constructor & Destructor Documentation

References TRACE.

{
  TRACE;
}

Member Function Documentation

void NAModelsPlot::addProperties ( PropertyProxy pp) [virtual]
Rect NAModelsPlot::boundingRect ( ) const [virtual]

Implements SciFigs::GraphContentLayer.

References _psViewer, QGpCoreTools::Rect::add(), PSViewer::lockDataModels(), misfit(), PSViewer::modelList(), QGpCoreTools::Rect::setLimits(), TRACE, and PSViewer::unlockDataModels().

Referenced by PSViewer::setLimits(), and setProperty().

{
  TRACE;
  if(_psViewer->modelList().size() > 0) {
    _psViewer->lockDataModels();
    ModelThreadList::const_iterator it=_psViewer->modelList().begin();
    ModelThreadList::const_iterator itEnd=_psViewer->modelList().end();
    Rect r;
    if(it!=itEnd) {
      double x, y, misfit;
      paramValue(x, y, misfit, it);
      r.setLimits(x, y, x, y);
      for( ++it;it!=itEnd;++it) {
        paramValue(x, y, misfit, it);
        r.add(x, y);
      }
    }
    _psViewer->unlockDataModels();
    return r;
  } else return Rect();
}
double NAModelsPlot::dotDiameter ( ) const [inline]

References _size.

{return _size;}
double NAModelsPlot::dotDiameterMM ( ) const [inline]

References _size.

Referenced by properties().

{return _size*10.0;}
virtual bool NAModelsPlot::hasProperties ( ) [inline, virtual]

Reimplemented from SciFigs::GraphContentLayer.

{return true;}
void NAModelsPlot::paintData ( const LayerPainterRequest lp,
QPainter &  p,
double  dotpercm 
) const [protected, virtual]

Implements SciFigs::GraphContentLayer.

References _psViewer, _size, QGpGuiTools::ColorPalette::color(), PSViewer::lockDataModels(), misfit(), PSViewer::modelList(), SciFigs::LayerPainterRequest::options(), PSViewer::palette(), SciFigs::LayerPainterRequest::terminated(), TRACE, PSViewer::unlockDataModels(), SciFigs::GraphContentOptions::xr2s(), SciFigs::GraphContentOptions::xVisMax(), SciFigs::GraphContentOptions::xVisMin(), SciFigs::GraphContentOptions::yr2s(), SciFigs::GraphContentOptions::yVisMax(), and SciFigs::GraphContentOptions::yVisMin().

{
  TRACE;
  _psViewer->lockDataModels();
  const GraphContentOptions& gc=lp.options();
  ColorPalette pal=*_psViewer->palette();

  double pointSizeF=_size * dotpercm;
  int pointSize, halfSize;
  if(pointSizeF<2.0) {
    pointSize=2;
    halfSize=1;
  } else {
    pointSize=(int) (pointSizeF);
    halfSize=(int) (0.5 * pointSizeF);
  }
  double x, y, misfit;
  ModelThreadList::const_iterator it;
  ModelThreadList::const_iterator itEnd=_psViewer->modelList().end();
  for(it=_psViewer->modelList().begin();it!=itEnd;++it) {
    if(lp.terminated()) {
      _psViewer->unlockDataModels();
      return;
    }
    paramValue(x, y, misfit, it);
    if(x > gc.xVisMin() && x < gc.xVisMax()) {
      if(y > gc.yVisMin() && y < gc.yVisMax()) {
        const QColor & col=pal.color(misfit);
        p.setPen(col);
        p.setBrush(col);
        int orx=gc.xr2s(x) - halfSize;
        int ory=gc.yr2s(y) - halfSize;
        p.drawEllipse(orx, ory, pointSize, pointSize);
      }
    }
  }
  _psViewer->unlockDataModels();
}
int NAModelsPlot::paramX ( ) const [inline]

References _paramX.

Referenced by properties(), and xml_writeProperties().

{return _paramX;}
int NAModelsPlot::paramY ( ) const [inline]

References _paramY.

Referenced by properties(), and xml_writeProperties().

{return _paramY;}
void NAModelsPlot::properties ( PropertyWidget w) const [virtual]

Clean property editor

Reimplemented from SciFigs::GraphContentLayer.

References _tab, and QGpGuiTools::PropertyProxy::removeTab().

{
  pp->removeTab(_tab, this);
}
bool NAModelsPlot::saveParameters ( ) const [protected]
void NAModelsPlot::setDotDiameter ( double  d) [inline]

References _size.

{_size=d;}
void NAModelsPlot::setDotDiameterMM ( double  d) [inline]

References _size.

Referenced by setProperty().

{_size=d*0.1;}
void NAModelsPlot::setParamX ( int  px)

px may range from -1 to the number of available parameters

-1 means misfit

References _paramX, _psViewer, SciFigs::GraphContent::graph(), SciFigs::GraphContentLayer::graphContent(), DinverCore::Parameter::name(), PSViewer::parameterList(), SciFigs::Axis::setAutoTicks(), SciFigs::Axis::setMajorTicks(), SciFigs::Axis::setMinorTicks(), SciFigs::Axis::setScaleType(), SciFigs::Axis::setTitle(), str, TRACE, DinverCore::Parameter::unit(), InversionThread::variableParameter(), and SciFigs::AxisWindow::xAxis().

Referenced by PSViewer::addPlot(), setProperty(), and xml_setProperty().

{
  TRACE;
  LayerLocker ll(this);
  _paramX=px;
  const InversionThread * paramSet=_psViewer->parameterList();
  Axis& axis=*graphContent() ->graph() ->xAxis();
  QString str;
  if(px >= 0) {
    const Parameter & param=*paramSet->variableParameter(px);
    str=QString( "%1 (%2)" ).arg(param.name()).arg(param.unit());
  } else {
    str="Misfit";
    axis.setScaleType(Scale::Log);
    axis.setAutoTicks(false);
    axis.setMajorTicks(10.0);
    axis.setMinorTicks(2.0);
  }
  axis.setTitle(str);
}
void NAModelsPlot::setParamY ( int  py)

py may range from -1 to the number of available parameters

-1 means misfit

References _paramY, _psViewer, SciFigs::GraphContent::graph(), SciFigs::GraphContentLayer::graphContent(), DinverCore::Parameter::name(), PSViewer::parameterList(), SciFigs::Axis::setAutoTicks(), SciFigs::Axis::setMajorTicks(), SciFigs::Axis::setMinorTicks(), SciFigs::Axis::setScaleType(), SciFigs::Axis::setTitle(), str, TRACE, DinverCore::Parameter::unit(), InversionThread::variableParameter(), and SciFigs::AxisWindow::yAxis().

Referenced by PSViewer::addPlot(), setProperty(), and xml_setProperty().

{
  TRACE;
  LayerLocker ll(this);
  _paramY=py;
  const InversionThread * paramSet=_psViewer->parameterList();
  Axis& axis=*graphContent() ->graph() ->yAxis();
  QString str;
  if(py >= 0) {
    const Parameter & param=*paramSet->variableParameter(py);
    str=QString( "%1 (%2)" ).arg(param.name()).arg(param.unit());
  } else {
    str="Misfit";
    axis.setScaleType(Scale::Log);
    axis.setAutoTicks(false);
    axis.setMajorTicks(10.0);
    axis.setMinorTicks(2.0);
  }
  axis.setTitle(str);
}
void NAModelsPlot::setParent ( GraphContent parent) [virtual]

Set parent has no effect if the layer has already a parent (i.e. already inserted in a layer stack). This function is mainly called by the xml restore where layer objects are created without parent.

If you re-implement this function you must explicitely call it from your contructor otherwise your function won't be executed when the layer is created with a non null parent (normal way).

Reimplemented from SciFigs::GraphContentLayer.

References _psViewer, SciFigs::GraphContent::graph(), SciFigs::GraphicObject::sheet(), TRACE, and w.

Referenced by NAModelsPlot().

{
  TRACE;
  if(parent) {
    AxisWindow * w=parent->graph();
    if(w->sheet()) {
      _psViewer=qobject_cast<PSViewer *>(w->sheet()->parentWidget());
    }
  }
  GraphContentLayer::setParent(parent);
}
void NAModelsPlot::setProperty ( uint  wid,
int  pid,
QVariant  val 
) [virtual]

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 SciFigs::GraphContentLayer.

References saveParameters(), and TRACE.

{
  TRACE;
  Q_UNUSED(attributes);
  Q_UNUSED(context);
  if(saveParameters()) {
    if(tag=="paramX") return XMLMember(0);
    else if(tag=="paramY") return XMLMember(1);
  }
  return XMLMember(XMLMember::Unknown);
}
bool NAModelsPlot::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 SciFigs::GraphContentLayer.

References setParamX(), setParamY(), and TRACE.

{
  TRACE;
  Q_UNUSED(tag);
  Q_UNUSED(attributes);
  Q_UNUSED(context);
  switch (memberID) {
  case 0: setParamX(content.toInt()); return true;
  case 1: setParamY(content.toInt()); return true;
  }
  return false;
}
const QString & NAModelsPlot::xml_tagName ( ) const [virtual]

Reimplemented from SciFigs::GraphContentLayer.

References saveParameters(), TRACE, and xmlNAModelsPlotTag.

{
  TRACE;
  if(saveParameters())
    return xmlNAModelsPlotTag;
  else
    return XYValuePlot::xmlXYValuePlotTag;
}
void NAModelsPlot::xml_writeBinaryData ( XML_WRITEBINARYDATA_ARGS  ) const [protected, virtual]

This function must be re-implemented in all classes dealing with binary data that cannot be saved in an ASCII xml file (e.g. due to the amount of data).

The way binary data is stored drastically changed in November 2006 with the introduction of tar.gz structures for xml files. Each class willing to store binary data can automatically generate a new file (with an automatic file name) in the .tar.gz structure by sending bytes to s.

See also xml_setBinaryData().

For the arguments of this function use Macro XML_WRITEBINARYDATA_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References _paramX, _paramY, _psViewer, ModelThreadInfo::index(), PSViewer::lockDataModels(), InversionThread::misfit(), PSViewer::modelList(), ModelThreadInfo::thread(), TRACE, PSViewer::unlockDataModels(), and InversionThread::variableParameterValue().

{
  TRACE;
  Q_UNUSED(context);
  _psViewer->lockDataModels();
  ModelThreadList::const_iterator it;
  ModelThreadList::const_iterator itEnd=_psViewer->modelList().end();
  int n=_psViewer->modelList().count();
  s << n;

  if(_paramX>=0) {
    int p=_paramX;
    for(it=_psViewer->modelList().begin();it!=itEnd;++it) {
      const ModelThreadInfo& modelInfo=*it;
      s << modelInfo.thread()->variableParameterValue(modelInfo.index(),p);
    }
  } else {
    for(it=_psViewer->modelList().begin();it!=itEnd;++it) {
      const ModelThreadInfo& modelInfo=*it;
      s << modelInfo.thread()->misfit(modelInfo.index());
    }
  }

  if(_paramY>=0) {
    int p=_paramY;
    for(it=_psViewer->modelList().begin();it!=itEnd;++it) {
      const ModelThreadInfo& modelInfo=*it;
      s << modelInfo.thread()->variableParameterValue(modelInfo.index(),p);
    }
  } else {
    for(it=_psViewer->modelList().begin();it!=itEnd;++it) {
      const ModelThreadInfo& modelInfo=*it;
      s << (*it).thread()->misfit(modelInfo.index());
    }
  }

  for(it=_psViewer->modelList().begin();it!=itEnd;++it) {
    const ModelThreadInfo& modelInfo=*it;
    s << (*it).thread()->misfit(modelInfo.index());
  }

  _psViewer->unlockDataModels();
}
void NAModelsPlot::xml_writeChildren ( XML_WRITECHILDREN_ARGS  ) const [protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

References _psViewer, SciFigs::XMLSciFigs::data(), PSViewer::palette(), saveParameters(), TRACE, and QGpCoreTools::XMLClass::xml_save().

{
  TRACE;
  XMLSciFigs * scifigsContext=static_cast<XMLSciFigs *>(context);
  if(scifigsContext->data() && !saveParameters()) {
    _psViewer->palette()->xml_save(s, context);
  }
}
void NAModelsPlot::xml_writeProperties ( XML_WRITEPROPERTIES_ARGS  ) const [protected, virtual]

Member Data Documentation

int NAModelsPlot::_paramX [protected]
int NAModelsPlot::_paramY [protected]
PSViewer* NAModelsPlot::_psViewer [mutable, protected]
double NAModelsPlot::_size [protected]
uint NAModelsPlot::_tab = PropertyProxy::uniqueId() [static, protected]

Referenced by addProperties(), and removeProperties().

const QString NAModelsPlot::xmlNAModelsPlotTag = "NAModelsPlot" [static]

Referenced by xml_tagName().


Property Documentation

double NAModelsPlot::dotDiameter [read, write]

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