#include <ProcessStatus.h>
Public Slots | |
| void | changeLegend () |
| void | synchronize () |
Public Member Functions | |
| void | clear () |
| void | clearThread (InversionThread *t) |
| Legend & | legend () |
| ProcessStatus (QWidget *parent=0, Qt::WFlags fl=0) | |
| void | removeThread (InversionThread *t) |
| void | setCostMinMax () |
| ~ProcessStatus () | |
Protected Member Functions | |
| void | updateMisfitCurve (InversionThread *t) |
| void | updatePens () |
Protected Attributes | |
| LineLayer * | _curveLayer |
| Legend | _legend |
| StatusThreadMap | _threads |
| bool | _threadsInitialized |
| ProcessStatus::ProcessStatus | ( | QWidget * | parent = 0, |
| Qt::WFlags | fl = 0 |
||
| ) |
Constructs a ProcessStatus as a child of 'parent', with the name 'name' and widget flags set to 'f'.
References _curveLayer, _legend, _threads, _threadsInitialized, changeLegend(), SciFigs::Legend::defaultColors(), SciFigs::AbstractLine::setPen(), SciFigs::LineLayer::setReferenceLine(), SciFigs::AbstractLine::setSymbol(), and TRACE.
: QWidget(parent, fl)
{
TRACE;
setupUi(this);
_threadsInitialized=false;
_curveLayer=0;
threadTable->setSelectionMode(QAbstractItemView::NoSelection);
threadTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
threadTable->setModel(new StatusThreadItem(&_threads, this) );
threadTable->setItemDelegate(new ProcessStatusDelegate(this) );
threadTable->resizeColumnsToContents();
Settings::columnWidth(threadTable, "ProcessStatus");
_legend.defaultColors(10);
_curveLayer=new LineLayer(historyGraph);
PlotLine2D * line;
line=new PlotLine2D;
line->setPen(Pen( Qt::black, 0.3, Qt::SolidLine) );
line->setSymbol(Symbol());
_curveLayer->setReferenceLine(line);
historyGraph->xAxis()->setRange(0, 100);
historyGraph->xAxis()->setTitle( "Generated models" );
historyGraph->yAxis()->setRange(0, 5);
historyGraph->yAxis()->setTitle( "Minimum misfit" );
connect(legendBut, SIGNAL(clicked()), this, SLOT(changeLegend()) );
Settings::splitter(splitter, "ProcessStatus" );
}
| void ProcessStatus::changeLegend | ( | ) | [slot] |
References _legend, SciFigs::LegendProperties::legend(), SciFigs::LegendProperties::setLegend(), QGpGuiTools::Dialog::setMainWidget(), SciFigs::LegendProperties::setPropertySections(), SciFigs::LegendProperties::setReadOnlyText(), TRACE, and updatePens().
Referenced by ProcessStatus().
{
TRACE;
Dialog * d=new Dialog(this);
LegendProperties * dl=new LegendProperties(this);
dl->setPropertySections(LegendTable::All);
d->setMainWidget(dl);
dl->setLegend(_legend);
dl->setReadOnlyText(true);
Settings::getRect(d, "ProcessStatus::legend" );
if(d->exec()==QDialog::Accepted) {
Settings::setRect(d, "ProcessStatus::legend" );
_legend=dl->legend();
updatePens();
historyGraph->graphContent() ->deepUpdate();
}
delete d;
}
| void ProcessStatus::clear | ( | ) |
References _curveLayer, _threads, _threadsInitialized, SciFigs::LineLayer::clear(), and TRACE.
Referenced by DinverGui::clear().
{
TRACE;
qDeleteAll(_threads);
_threads.clear();
_threadsInitialized=false;
_curveLayer->clear();
}
| void ProcessStatus::clearThread | ( | InversionThread * | t | ) |
References _curveLayer, _threads, StatusThreadInfo::line, SciFigs::LineLayer::removeLine(), and TRACE.
Referenced by DinverGui::clearThread().
{
TRACE;
StatusThreadMap::iterator itInfo=_threads.find(t);
if(itInfo==_threads.end()) return;
StatusThreadInfo * tInfo=itInfo.value();
_curveLayer->removeLine(tInfo->line);
_threads.remove(t);
delete tInfo;
historyGraph->deepUpdate();
static_cast<StatusThreadItem *>(threadTable->model())->refresh();
}
| Legend& ProcessStatus::legend | ( | ) | [inline] |
References _legend.
Referenced by ProcessStatusDelegate::paint(), and ProcessStatusDelegate::sizeHint().
{return _legend;}
| void ProcessStatus::removeThread | ( | InversionThread * | t | ) |
References _curveLayer, _threads, StatusThreadInfo::line, SciFigs::LineLayer::removeLine(), and TRACE.
Referenced by DinverGui::removeThread().
{
TRACE;
StatusThreadMap::iterator itInfo=_threads.find(t);
if(itInfo!=_threads.end()) {
StatusThreadInfo& tInfo=*itInfo.value();
if(tInfo.line) _curveLayer->removeLine(tInfo.line);
delete &tInfo;
_threads.remove(t);
}
}
| void ProcessStatus::setCostMinMax | ( | ) |
References _curveLayer, SciFigs::LineLayer::boundingRect(), TRACE, and QGpCoreTools::Rect::y2().
Referenced by synchronize().
{
TRACE;
Rect r=_curveLayer->boundingRect();
historyGraph->yAxis()->setRange(0, r.y2());
}
| void ProcessStatus::synchronize | ( | ) | [slot] |
References _curveLayer, _legend, _threads, _threadsInitialized, InversionThread::activeModelCount(), InversionThread::bestModelCount(), SciFigs::LineLayer::boundingRect(), SciFigs::Legend::count(), StatusThreadInfo::deltaNModels, StatusThreadInfo::deltaNRejected, StatusThreadInfo::deltaTime, dinverGui, InversionThread::expectedModelCount(), InversionThread::giveUpCount(), StatusThreadInfo::nActiveModels, StatusThreadInfo::nGiveUp, StatusThreadInfo::nr, StatusThreadInfo::nRejected, StatusThreadInfo::nValidModels, StatusThreadInfo::nVisitedModels, InversionThread::rejectedCount(), SciFigs::Legend::resize(), setCostMinMax(), StatusThreadInfo::time, TRACE, updateMisfitCurve(), InversionThread::validModelCount(), InversionThread::visitedModelCount(), and QGpCoreTools::Rect::x2().
Referenced by DinverGui::open().
{
TRACE;
bool threadAdded=false;
int totalNModels=0;
ThreadList::const_iterator itEnd=dinverGui->threads().end();
int nThreads=dinverGui->threads().count();
for(int i=0; i<nThreads; i++) {
InversionThread * t=dinverGui->threads().at(i);
// Get info about thread
StatusThreadMap::iterator itInfo=_threads.find(t);
if(itInfo==_threads.end()) {
_threads.insert(t, new StatusThreadInfo);
threadAdded=true;
itInfo=_threads.find(t);
}
StatusThreadInfo& tInfo=*itInfo.value();
tInfo.nVisitedModels=t->visitedModelCount();
tInfo.deltaNModels=t->validModelCount() - tInfo.nValidModels;
tInfo.deltaNRejected=t->rejectedCount() - tInfo.nRejected;
tInfo.nValidModels=t->validModelCount();
tInfo.nActiveModels=t->activeModelCount();
totalNModels += tInfo.nValidModels;
tInfo.nr=t->bestModelCount();
tInfo.nRejected=t->rejectedCount();
tInfo.nGiveUp=t->giveUpCount();
tInfo.deltaTime=tInfo.time.elapsed();
tInfo.time.start();
updateMisfitCurve(t);
if(t->expectedModelCount()>historyGraph->xAxis()->maximum()) {
historyGraph->xAxis()->setRange(0, t->expectedModelCount());
}
}
static_cast<StatusThreadItem *>(threadTable->model())->refresh();
if(threadAdded) {
if( !_threadsInitialized) {
if(totalNModels>0) {
_threadsInitialized=true;
setCostMinMax();
}
}
int nRows=threadTable->model() ->rowCount();
for(int i=0;i < nRows;i++ ) threadTable->resizeRowToContents(i);
Rect r=_curveLayer->boundingRect();
historyGraph->xAxis()->setRange(0, r.x2());
if(_legend.count()<nRows) {
_legend.resize(nRows);
}
}
historyGraph->deepUpdate();
}
| void ProcessStatus::updateMisfitCurve | ( | InversionThread * | t | ) | [protected] |
References _curveLayer, _legend, _threads, SciFigs::LineLayer::addLine(), QGpCoreTools::Curve< pointType >::append(), StatusThreadInfo::bestMisfit, SciFigs::Legend::count(), SciFigs::LineLayer::count(), SciFigs::PlotLine2D::curve(), iModel, StatusThreadInfo::lastValidIndex, StatusThreadInfo::lastVisitedIndex, StatusThreadInfo::line, SciFigs::LineLayer::line(), InversionThread::lock(), SciFigs::GraphContentLayer::lockDelayPainting(), InversionThread::misfit(), StatusThreadInfo::nVisitedModels, SciFigs::Legend::pen(), SciFigs::Legend::resize(), SciFigs::Legend::setText(), SciFigs::Legend::symbol(), TRACE, SciFigs::GraphContentLayer::unlock(), and InversionThread::unlock().
Referenced by synchronize().
{
TRACE;
StatusThreadMap::iterator itInfo=_threads.find(t);
if(itInfo==_threads.end()) return;
StatusThreadInfo& tInfo=*itInfo.value();
if(!tInfo.line) {
int nCurves=_curveLayer->count();
_curveLayer->lockDelayPainting();
if(_legend.count()<nCurves) {
_legend.resize(nCurves+1);
_legend.setText(nCurves, t->objectName());
}
_curveLayer->addLine(_legend.pen(nCurves), _legend.symbol(nCurves) );
_curveLayer->unlock();
tInfo.line=static_cast<PlotLine2D *>(_curveLayer->line(nCurves) );
}
Curve<Point2D>& curve=tInfo.line->curve();
double bestMisfit=tInfo.bestMisfit==0 ? 1e99 : tInfo.bestMisfit;
LayerLocker ll(_curveLayer);
//if(t->hasModelsToImport()) {
// tInfo.bestMisfit=t->reportBestMisfit();
//} else {
t->lock();
printf("ProcessStatus::updateMisfitCurve %i -> %i\n", tInfo.lastVisitedIndex+1, tInfo.nVisitedModels);
for(int iModel=tInfo.lastVisitedIndex+1; iModel<tInfo.nVisitedModels; iModel++) {
double m=t->misfit(iModel);
if(m!=1e99) {
if(m<bestMisfit) {
bestMisfit=m;
curve.append(Point(tInfo.lastValidIndex, bestMisfit));
}
tInfo.lastValidIndex++;
}
//printf("%i last valid index %i @ %lf : %lf\n", iModel, tInfo.lastValidIndex, m, bestMisfit);
}
tInfo.lastVisitedIndex=tInfo.nVisitedModels-1;
t->unlock();
if(bestMisfit!=1e99) tInfo.bestMisfit=bestMisfit; else tInfo.bestMisfit=0;
//}
}
| void ProcessStatus::updatePens | ( | ) | [protected] |
References _curveLayer, _legend, SciFigs::LineLayer::setLegend(), and TRACE.
Referenced by changeLegend().
{
TRACE;
_curveLayer->setLegend(_legend);
}
LineLayer* ProcessStatus::_curveLayer [protected] |
Referenced by clear(), clearThread(), ProcessStatus(), removeThread(), setCostMinMax(), synchronize(), updateMisfitCurve(), and updatePens().
Legend ProcessStatus::_legend [protected] |
Referenced by changeLegend(), legend(), ProcessStatus(), synchronize(), updateMisfitCurve(), and updatePens().
StatusThreadMap ProcessStatus::_threads [protected] |
Referenced by clear(), clearThread(), ProcessStatus(), removeThread(), synchronize(), updateMisfitCurve(), and ~ProcessStatus().
bool ProcessStatus::_threadsInitialized [protected] |
Referenced by clear(), ProcessStatus(), and synchronize().