#include <Simulator.h>
Public Member Functions | |
| void | init (const QVector< Point2D > &array) |
| void | setKmax (double kmax) |
| Simulator (QWidget *parent=0, Qt::WFlags fl=0) | |
| ~Simulator () | |
Protected Slots | |
| void | displaySource (int index) |
| void | on_addSource_clicked () |
| void | on_attenuationButton_toggled (bool checked) |
| void | on_attenuationEdit_valueChanged (double q) |
| void | on_frequencyEdit_valueChanged (double f) |
| void | on_gridSizeEdit_valueChanged (double k) |
| void | on_removeSource_clicked () |
| void | setAllSources () |
| void | setKmax () |
| void | setSource (QModelIndex topLeft, QModelIndex bottomRight) |
| void | setWaveModel () |
| Simulator::Simulator | ( | QWidget * | parent = 0, |
| Qt::WFlags | fl = 0 |
||
| ) |
References setSource(), setWaveModel(), and TRACE.
: QWidget(parent, fl | Qt::Window)
{
TRACE;
setAttribute(Qt::WA_DeleteOnClose);
setupUi(this);
SourceItemModel * model=new SourceItemModel(&_sources, this);
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setSource(QModelIndex,QModelIndex)));
sourceTable->setModel(model);
SourceDelegate * delegate=new SourceDelegate(this);
connect(sourceTable, SIGNAL(clicked(const QModelIndex&)), delegate, SLOT(colorClicked(QModelIndex)));
sourceTable->setItemDelegate(delegate);
sourceTable->setSelectionBehavior(QAbstractItemView::SelectItems);
sourceTable->setSelectionMode(QAbstractItemView::SingleSelection);
sourceTable->setEditTriggers(QAbstractItemView::AllEditTriggers);
connect(planeWavesButton, SIGNAL(toggled(bool)), this, SLOT(setWaveModel()));
connect(circularWavesButton, SIGNAL(toggled(bool)), this, SLOT(setWaveModel()));
Settings::getWidget(this, "Simulator" );
_gridLayer=0;
_velocityLayer=0;
_azimuthLayer=0;
_kLayer=0;
// Not yet implemented
highResolution->hide();
}
| void Simulator::displaySource | ( | int | index | ) | [protected, slot] |
References SourceParameters::azimuthMath(), SourceParameters::color(), QGpCoreTools::cos(), MediumParameters::frequency(), SciFigs::LineLayer::line(), SciFigs::CircleViewer::set(), SciFigs::AbstractLine::setPen(), SciFigs::AbstractLine::setX(), SciFigs::AbstractLine::setY(), QGpCoreTools::sin(), TRACE, and SourceParameters::velocity().
Referenced by setAllSources(), and setSource().
{
TRACE;
const SourceParameters& src=_sources.at(index);
QColor col=src.color();
double v=src.velocity();
double k=2.0*M_PI*_medium.frequency()/v;
double a=src.azimuthMath();
_velocityLayer->set(index, 0, 0, k, k, 0.0, col);
AbstractLine * l=_azimuthLayer->line(index);
l->setPen(Pen(col, 0.6, Qt::SolidLine));
l->setX(1, k*cos(a));
l->setY(1, k*sin(a), 0);
}
| void Simulator::init | ( | const QVector< Point2D > & | array | ) |
References ArrayCore::KminSolver::calculate(), ArrayCore::KmaxSolver::calculate(), QGpCoreTools::endl(), on_addSource_clicked(), on_frequencyEdit_valueChanged(), on_gridSizeEdit_valueChanged(), SciFigs::LiveGridLayer::setFunction(), setKmax(), SciFigs::GridPlot::setLinearPalette(), SciFigs::GraphContentLayer::setOpacity(), SciFigs::AbstractLine::setPen(), SciFigs::LineLayer::setReferenceLine(), SciFigs::LiveGridLayer::setSampling(), FKArrayMap::setStations(), SciFigs::AbstractLine::setSymbol(), setWaveModel(), FKArrayMap::theoreticalKmax(), QGpCoreTools::tr(), and TRACE.
Referenced by main().
{
TRACE;
// Wavenumber map
waveNumMap->xAxis()->setTitle(tr("Wave number X (rad/m)"));
waveNumMap->xAxis()->setTitleInversedScale(tr("Wave length X/(2*pi) (m/rad)"));
waveNumMap->yAxis()->setTitle(tr("Wave number Y (rad/m)"));
waveNumMap->yAxis()->setTitleInversedScale(tr("Wave length Y/(2*pi) (m/rad)"));
_gridLayer=new LiveGridLayer(waveNumMap);
_gridLayer->setSampling(3);
_fkmap=new FKArrayMap;
_fkmap->setStations(array);
_gridLayer->setFunction(_fkmap);
_gridLayer->setObjectName("wave number map");
_gridLayer->setLinearPalette(0.0, 1.0);
_velocityLayer=new CircleViewer(waveNumMap);
_velocityLayer->setObjectName("velocity");
_azimuthLayer=new LineLayer(waveNumMap);
_azimuthLayer->setObjectName("azimuth");
PlotLine2D * line=new PlotLine2D;
line->setPen(Pen(Qt::black, 0.6, Qt::SolidLine));
line->setSymbol(Symbol());
_azimuthLayer->setReferenceLine(line);
_kLayer=new CircleMask(waveNumMap);
_kLayer->setObjectName("grid size");
_kLayer->setOpacity(0.75);
// Estimate kmax from station coordinates
KminSolver kminSolver(array);
bool ok=true;
double kmin=kminSolver.calculate(ok);
if(ok && kmin>0.0) {
_kmaxSolver=new KmaxSolver(array,kmin);
connect(&_kmaxTimer, SIGNAL(timeout()), this, SLOT(setKmax()));
connect(_kmaxSolver, SIGNAL(finished()), this, SLOT(setKmax()));
_kmaxSolver->calculate();
_kmaxTimer.start(1000);
} else {
_kmaxSolver=0;
App::stream() << tr("Error computing kmin for station coordinates") << endl;
setKmax(5.0*_fkmap->theoreticalKmax());
}
on_frequencyEdit_valueChanged(frequencyEdit->value());
on_gridSizeEdit_valueChanged(gridSizeEdit->value());
on_addSource_clicked(); // force initialization with at least one source
setWaveModel();
}
| void Simulator::on_addSource_clicked | ( | ) | [protected, slot] |
References SciFigs::CircleViewer::add(), SciFigs::LineLayer::addLine(), FKArrayMap::addSource(), SciFigs::AbstractLine::append(), setSource(), SciFigs::AbstractLine::setX(), SciFigs::AbstractLine::setY(), FKArrayMap::sourceCount(), and TRACE.
Referenced by init().
{
TRACE;
static_cast<SourceItemModel *>(sourceTable->model())->addSource();
_fkmap->addSource();
_velocityLayer->add(0, 0, 0, 0, 0.0, Qt::black);
AbstractLine * l=_azimuthLayer->addLine();
l->append();
l->append();
l->setX(0, 0.0);
l->setY(0, 0.0, 0);
setSource(_fkmap->sourceCount()-1);
}
| void Simulator::on_attenuationButton_toggled | ( | bool | checked | ) | [protected, slot] |
References setAllSources(), MediumParameters::setAttenuation(), and TRACE.
{
TRACE;
if(checked) {
_medium.setAttenuation(attenuationEdit->value());
attenuationEdit->setEnabled(true);
} else {
_medium.setAttenuation(0.0);
attenuationEdit->setEnabled(false);
}
setAllSources();
}
| void Simulator::on_attenuationEdit_valueChanged | ( | double | q | ) | [protected, slot] |
References setAllSources(), MediumParameters::setAttenuation(), and TRACE.
{
TRACE;
_medium.setAttenuation(q);
setAllSources();
}
| void Simulator::on_frequencyEdit_valueChanged | ( | double | f | ) | [protected, slot] |
References setAllSources(), MediumParameters::setFrequency(), and TRACE.
Referenced by init().
{
TRACE;
_medium.setFrequency(f);
setAllSources();
}
| void Simulator::on_gridSizeEdit_valueChanged | ( | double | k | ) | [protected, slot] |
References SciFigs::GraphContentLayer::deepUpdate(), SciFigs::CircleMask::set(), and TRACE.
Referenced by init().
{
TRACE;
_kLayer->set(0, 0, k, k, Qt::white);
_kLayer->deepUpdate();
}
| void Simulator::on_removeSource_clicked | ( | ) | [protected, slot] |
References SciFigs::CircleViewer::remove(), SciFigs::LineLayer::removeLine(), FKArrayMap::removeSource(), and TRACE.
{
TRACE;
int index=sourceTable->currentIndex().row();
if(index>=0) {
static_cast<SourceItemModel *>(sourceTable->model())->removeSource(index);
_fkmap->removeSource(index);
_velocityLayer->remove(index);
_azimuthLayer->removeLine(index);
updateMap();
}
}
| void Simulator::setAllSources | ( | ) | [protected, slot] |
References displaySource(), SciFigs::GraphContentLayer::lockDelayPainting(), FKArrayMap::setSourceSignals(), FKArrayMap::setStationSignals(), FKArrayMap::sourceCount(), TRACE, and SciFigs::GraphContentLayer::unlock().
Referenced by on_attenuationButton_toggled(), on_attenuationEdit_valueChanged(), on_frequencyEdit_valueChanged(), and setWaveModel().
{
TRACE;
_gridLayer->lockDelayPainting();
int n=_fkmap->sourceCount();
for(int i=0; i<n; i++) {
_fkmap->setSourceSignals(i, _sources.at(i), _medium);
displaySource(i);
}
_gridLayer->unlock();
_fkmap->setStationSignals();
updateMap();
}
| void Simulator::setKmax | ( | double | kmax | ) |
References QGpCoreTools::Rect::enlarge(), QGpCoreTools::LinearScale, QGpCoreTools::Rect::setLimits(), TRACE, QGpCoreTools::Rect::x1(), QGpCoreTools::Rect::x2(), QGpCoreTools::Rect::y1(), and QGpCoreTools::Rect::y2().
{
TRACE;
gridSizeEdit->setValue(kmax);
kmax*=2;
Rect r;
r.setLimits(-kmax, -kmax, kmax, kmax);
r.enlarge(0.05, LinearScale, LinearScale);
waveNumMap->xAxis()->setRange(r.x1(), r.x2());
waveNumMap->yAxis()->setRange(r.y1(), r.y2());
}
| void Simulator::setKmax | ( | ) | [protected, slot] |
| void Simulator::setSource | ( | QModelIndex | topLeft, |
| QModelIndex | bottomRight | ||
| ) | [protected, slot] |
References displaySource(), and TRACE.
Referenced by on_addSource_clicked(), and Simulator().
{
TRACE;
setSource(topLeft.row());
displaySource(topLeft.row());
}
| void Simulator::setWaveModel | ( | ) | [protected, slot] |
References SourceParameters::CircularWaves, SourceParameters::PlaneWaves, setAllSources(), and TRACE.
Referenced by init(), and Simulator().
{
TRACE;
if(planeWavesButton->isChecked()) {
attenuationEdit->setEnabled(false);
attenuationButton->setEnabled(false);
static_cast<SourceItemModel *>(sourceTable->model())->setSourceType(SourceParameters::PlaneWaves);
static_cast<SourceDelegate *>(sourceTable->itemDelegate())->setSourceType(SourceParameters::PlaneWaves);
for(int i=0; i<_sources.count(); i++) {
_sources[i].setType(SourceParameters::PlaneWaves);
}
} else {
attenuationButton->setEnabled(true);
attenuationEdit->setEnabled(attenuationButton->isChecked());
static_cast<SourceItemModel *>(sourceTable->model())->setSourceType(SourceParameters::CircularWaves);
static_cast<SourceDelegate *>(sourceTable->itemDelegate())->setSourceType(SourceParameters::CircularWaves);
for(int i=0; i<_sources.count(); i++) {
_sources[i].setType(SourceParameters::CircularWaves);
}
}
setAllSources();
}