A NAModelsPlot is a layer to draw projection of a parameter space. More...
#include <NAModelsPlot.h>
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 |
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)
NAModelsPlot::NAModelsPlot | ( | AxisWindow * | parent = 0 | ) |
References _paramX, _paramY, _psViewer, _size, SciFigs::GraphContentLayer::graphContent(), setParent(), and TRACE.
: GraphContentLayer(parent) { TRACE; _psViewer=0; if(parent) setParent(graphContent()); _size=0.1; _paramX=-1; _paramY=0; }
void NAModelsPlot::addProperties | ( | PropertyProxy * | pp | ) | [virtual] |
Setup property editor
Reimplemented from SciFigs::GraphContentLayer.
References _psViewer, _tab, QGpGuiTools::PropertyProxy::addReference(), QGpGuiTools::PropertyProxy::addTab(), PSViewer::parameterList(), QGpGuiTools::PropertyProxy::setCurrentTab(), NAModelsPlotProperties::setParameterList(), QGpCoreTools::tr(), TRACE, and w.
{ TRACE; if(pp->setCurrentTab(_tab)) { pp->addReference(this); } else { NAModelsPlotProperties * w=new NAModelsPlotProperties; w->setParameterList(_psViewer->parameterList()); pp->addTab(_tab, tr("Parameters"), w, this); } }
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] |
double NAModelsPlot::dotDiameterMM | ( | ) | const [inline] |
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] |
int NAModelsPlot::paramY | ( | ) | const [inline] |
void NAModelsPlot::properties | ( | PropertyWidget * | w | ) | const [virtual] |
Reimplemented from SciFigs::GraphContentLayer.
References NAModelsPlotProperties::DotDiameter, dotDiameterMM(), NAModelsPlotProperties::ParamX, paramX(), NAModelsPlotProperties::ParamY, paramY(), QGpGuiTools::PropertyWidget::setValue(), and TRACE.
{ TRACE; w->setValue(NAModelsPlotProperties::DotDiameter, dotDiameterMM()); w->setValue(NAModelsPlotProperties::ParamX, paramX()+1); w->setValue(NAModelsPlotProperties::ParamY, paramY()+1); }
void NAModelsPlot::removeProperties | ( | PropertyProxy * | pp | ) | [virtual] |
Clean property editor
Reimplemented from SciFigs::GraphContentLayer.
References _tab, and QGpGuiTools::PropertyProxy::removeTab().
bool NAModelsPlot::saveParameters | ( | ) | const [protected] |
References _psViewer, PSViewer::saveParameters(), and TRACE.
Referenced by xml_member(), xml_tagName(), xml_writeChildren(), and xml_writeProperties().
{ TRACE; return _psViewer->saveParameters(); }
void NAModelsPlot::setDotDiameter | ( | double | d | ) | [inline] |
void NAModelsPlot::setDotDiameterMM | ( | double | d | ) | [inline] |
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] |
Reimplemented from SciFigs::GraphContentLayer.
References boundingRect(), SciFigs::AxisWindow::deepUpdate(), SciFigs::GraphContent::deepUpdate(), NAModelsPlotProperties::DotDiameter, SciFigs::GraphContentLayer::graph(), SciFigs::GraphContentLayer::graphContent(), NAModelsPlotProperties::ParamX, NAModelsPlotProperties::ParamY, setDotDiameterMM(), setParamX(), setParamY(), SciFigs::Axis::setRange(), TRACE, QGpCoreTools::Rect::x1(), QGpCoreTools::Rect::x2(), SciFigs::AxisWindow::xAxis(), QGpCoreTools::Rect::y1(), QGpCoreTools::Rect::y2(), and SciFigs::AxisWindow::yAxis().
{ TRACE; bool axisUpdate=false; switch(pid) { case NAModelsPlotProperties::DotDiameter: setDotDiameterMM(val.toDouble()); graphContent() ->deepUpdate(); break; case NAModelsPlotProperties::ParamX: setParamX(val.toInt()-1); axisUpdate=true; break; case NAModelsPlotProperties::ParamY: setParamY(val.toInt()-1); axisUpdate=true; break; } if(axisUpdate) { // force update here because it affects the axis as well (and set limits again) Rect r=boundingRect(); graph()->xAxis()->setRange(r.x1(), r.x2()); graph()->yAxis()->setRange(r.y1(), r.y2()); graph() ->deepUpdate(); } }
XMLMember NAModelsPlot::xml_member | ( | XML_MEMBER_ARGS | ) | [protected, 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:
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.
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] |
Reimplemented from SciFigs::GraphContentLayer.
References SciFigs::XMLSciFigs::data(), paramX(), paramY(), saveParameters(), TRACE, QGpCoreTools::XMLClass::writeBinaryData(), and QGpCoreTools::XMLClass::writeProperty().
{ TRACE; if(saveParameters()) { writeProperty(s, "paramX", paramX()); writeProperty(s, "paramY", paramY()); } GraphContentLayer::xml_writeProperties(s, context); XMLSciFigs * scifigsContext=static_cast<XMLSciFigs *>(context); if(scifigsContext->data() && !saveParameters()) writeBinaryData(s, context); }
int NAModelsPlot::_paramX [protected] |
Referenced by NAModelsPlot(), paramX(), setParamX(), and xml_writeBinaryData().
int NAModelsPlot::_paramY [protected] |
Referenced by NAModelsPlot(), paramY(), setParamY(), and xml_writeBinaryData().
PSViewer* NAModelsPlot::_psViewer [mutable, protected] |
Referenced by addProperties(), boundingRect(), NAModelsPlot(), paintData(), saveParameters(), setParamX(), setParamY(), setParent(), xml_writeBinaryData(), and xml_writeChildren().
double NAModelsPlot::_size [protected] |
Referenced by dotDiameter(), dotDiameterMM(), NAModelsPlot(), paintData(), setDotDiameter(), and setDotDiameterMM().
uint NAModelsPlot::_tab = PropertyProxy::uniqueId() [static, protected] |
Referenced by addProperties(), and removeProperties().
const QString NAModelsPlot::xmlNAModelsPlotTag = "NAModelsPlot" [static] |
Referenced by xml_tagName().
double NAModelsPlot::dotDiameter [read, write] |