Select Git revision
test_property.py
-
Daniel Brown authored
Large amount of changes to the param object which now include being able to put and set parameters and commands. Also adding the modulator component.
Daniel Brown authoredLarge amount of changes to the param object which now include being able to put and set parameters and commands. Also adding the modulator component.
pulsatingscience.cpp 15.09 KiB
/******************************************************************************
* Copyright (C) 2008 by Oliver Bock *
* oliver.bock[AT]aei.mpg.de *
* *
* This file is part of PulsatingScience. *
* *
* PulsatingScience is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation, version 3 of the License. *
* *
* PulsatingScience is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with PulsatingScience. If not, see <http://www.gnu.org/licenses/>. *
* *
******************************************************************************/
#include "pulsatingscience.h"
#include "plotdata.h"
#include "preseteditor.h"
#include <QSettings>
#ifdef __APPLE__
#include "/System/Library/Frameworks/Carbon.framework/Versions/A/Headers/Carbon.h"
#endif
PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent)
{
ui.setupUi(this);
QAction* animControl = ui.dockAnimControl->toggleViewAction();
animControl->setStatusTip(tr("Toggle the animation control visibility"));
animControl->setShortcut(QKeySequence(tr("Alt+A")));
ui.menuView->addAction(animControl);
#ifdef __APPLE__
ui.actionMenu_bar->setEnabled(false);
#endif
// inital status (based on GUI)
m_menuBarVisible = ui.actionMenu_bar->isChecked();
m_statusBarVisible = ui.actionStatus_bar->isChecked();
m_animControlVisible = true;
m_animControlFloating = ui.dockAnimControl->isFloating();
m_hiddenDemoModeActivated = false;
// register alternate shortcuts (will be enabled when menu is hidden)
m_menuBarShortcut = new QShortcut(ui.actionMenu_bar->shortcut(), this);
m_menuBarShortcut->setEnabled(false);
m_fullscreenShortcut = new QShortcut(ui.actionFullscreen->shortcut(), this);
m_fullscreenShortcut->setEnabled(false);
m_fullscreenESCShortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this);
m_fullscreenESCShortcut->setEnabled(false);
// register "hidden" demo mode shortcut for IYA2009 exhibition
m_hiddenShortcut = new QShortcut(QKeySequence(Qt::SHIFT + Qt::ALT + Qt::Key_D), this);
// establish object communications
connect(ui.pulsarGlWidget, SIGNAL(pulseProfileUpdated(const PlotData&)),
ui.pulseScopeWidget, SLOT(plot(const PlotData&)));
connect(ui.pulsarGlWidget, SIGNAL(pulseProfileUpdated(const PlotData&)),
this, SLOT(updateAmplitudes(const PlotData&)));
connect(m_hiddenShortcut, SIGNAL(activated()),
this, SLOT(toggleHiddenDemoMode()));
// prepare inactivity timer
m_inactivityTimer = new QTimer(this);
connect(m_inactivityTimer, SIGNAL(timeout()), this, SLOT(userInactivityCallback()));
// restore previously saved window and splitter layout
QCoreApplication::setOrganizationName("Max-Planck-Insitut für Gravitationsphysik");
QCoreApplication::setOrganizationDomain("aei.mpg.de");
QCoreApplication::setApplicationName("GW170817");
QSettings settings;
restoreGeometry(settings.value("windowGeometry").toByteArray());
restoreState(settings.value("windowState").toByteArray());
ui.splitter->restoreState(settings.value("splitterSizes").toByteArray());
// restore source presets
m_presets = new PresetModel();
ui.cmbSource->setModel(m_presets);
ui.cmbSource->setCurrentIndex(settings.value("currentPreset", 0).toInt());
// For Bruce: set initial values for iota and psi
ui.sliderSourceIota->setValue(146);
ui.sliderSourceInclination->setValue(177);
// save initial state
saveOrRestoreInitialAnimationSettings();
}
PulsatingScience::~PulsatingScience()
{
if(m_menuBarShortcut) {
m_menuBarShortcut->disconnect();
delete m_menuBarShortcut;
}
if(m_fullscreenShortcut) {
m_fullscreenShortcut->disconnect();
delete m_fullscreenShortcut;
}
if(m_fullscreenESCShortcut) {
m_fullscreenESCShortcut->disconnect();
delete m_fullscreenESCShortcut;
}
if(m_hiddenShortcut) {
m_hiddenShortcut->disconnect();
delete m_hiddenShortcut;
}
if(m_inactivityTimer) {
delete m_inactivityTimer;
}
if(m_presets) {
delete m_presets;
}
}
void PulsatingScience::closeEvent(QCloseEvent *event)
{
if(m_hiddenDemoModeActivated) {
event->ignore();
}
else {
// save window and splitter layout
QSettings settings;
settings.setValue("windowGeometry", saveGeometry());
settings.setValue("windowState", saveState());
settings.setValue("splitterSizes", ui.splitter->saveState());
settings.setValue("currentPreset", ui.cmbSource->currentIndex());
event->accept();
}
}
void PulsatingScience::on_cmbSource_currentIndexChanged(int index)
{
ui.lblSource->setText(m_presets->preset(index).getDescription());
// TODO: change source
}
void PulsatingScience::on_chkLHO_clicked(bool checked)
{
ui.pulsarGlWidget->setLHOState(checked);
}
void PulsatingScience::on_chkLLO_clicked(bool checked)
{
ui.pulsarGlWidget->setLLOState(checked);
}
void PulsatingScience::on_chkVirgo_clicked(bool checked)
{
ui.pulsarGlWidget->setVirgoState(checked);
}
void PulsatingScience::on_chkKAGRA_clicked(bool checked)
{
ui.pulsarGlWidget->setKAGRAState(checked);
}
void PulsatingScience::on_chkLI_clicked(bool checked)
{
ui.pulsarGlWidget->setLIState(checked);
}
void PulsatingScience::on_sliderLHOAngle_valueChanged(int value)
{
ui.pulsarGlWidget->setLHOAngle(value);
ui.lcdLHOAngle->display(QString::number(value));
}
void PulsatingScience::on_sliderLLOAngle_valueChanged(int value)
{
ui.pulsarGlWidget->setLLOAngle(value);
ui.lcdLLOAngle->display(QString::number(value));
}
void PulsatingScience::on_sliderVirgoAngle_valueChanged(int value)
{
ui.pulsarGlWidget->setVirgoAngle(value);
ui.lcdVirgoAngle->display(QString::number(value));
}
void PulsatingScience::on_sliderKAGRAAngle_valueChanged(int value)
{
ui.pulsarGlWidget->setKAGRAAngle(value);
ui.lcdKAGRAAngle->display(QString::number(value));
}
void PulsatingScience::on_sliderLIAngle_valueChanged(int value)
{
ui.pulsarGlWidget->setLIAngle(value);
ui.lcdLIAngle->display(QString::number(value));
}
void PulsatingScience::on_sliderSourceIota_valueChanged(int value)
{
ui.pulsarGlWidget->setSourceIota(value);
ui.lcdSourceIota->display(QString::number(value));
}
void PulsatingScience::on_sliderSourceInclination_valueChanged(int value)
{
ui.pulsarGlWidget->setSourceInclination(value);
ui.lcdSourceInclination->display(QString::number(value));
}
void PulsatingScience::menuBarToggled()
{
if(ui.menuBar->isVisible()) {
on_actionMenu_bar_toggled(false);
ui.actionMenu_bar->setChecked(false);
}
else if(!ui.actionFullscreen->isChecked()) {
// allow menu bar only when NOT in fullscreen mode
on_actionMenu_bar_toggled(true);
ui.actionMenu_bar->setChecked(true);
}
}
void PulsatingScience::on_actionPresetsEdit_triggered() {
PresetEditor dialog(m_presets, this);
dialog.exec();
}
void PulsatingScience::on_actionMenu_bar_toggled(bool checked)
{
if(checked) {
ui.menuBar->show();
m_menuBarVisible = true;
// deactivate alternate shortcuts
m_fullscreenShortcut->disconnect();
m_fullscreenShortcut->setEnabled(false);
m_menuBarShortcut->disconnect();
m_menuBarShortcut->setEnabled(false);
}
else {
ui.menuBar->hide();
m_menuBarVisible = false;
// activate alternate shortcuts
m_fullscreenShortcut->setEnabled(true);
connect(m_fullscreenShortcut, SIGNAL(activated()), this, SLOT(fullscreenToggled()));
m_menuBarShortcut->setEnabled(true);
connect(m_menuBarShortcut, SIGNAL(activated()), this, SLOT(menuBarToggled()));
}
}
void PulsatingScience::fullscreenToggled()
{
if((windowState() & Qt::WindowFullScreen) > 0) {
on_actionFullscreen_toggled(false);
ui.actionFullscreen->setChecked(false);
}
else {
on_actionFullscreen_toggled(true);
ui.actionFullscreen->setChecked(true);
}
}
void PulsatingScience::on_actionReset_triggered()
{
saveOrRestoreInitialAnimationSettings();
}
void PulsatingScience::on_actionFullscreen_toggled(bool checked)
{
if(checked) {
window()->setWindowState(windowState() | Qt::WindowFullScreen);
// assuming text being black
setBackgroundRole(QPalette::Text);
#ifndef __APPLE__
if(m_menuBarVisible) {
on_actionMenu_bar_toggled(false);
// keep visibility setting
m_menuBarVisible = true;
}
#endif
if(m_statusBarVisible) ui.statusbar->hide();
if(m_animControlVisible && !m_animControlFloating) {
ui.dockAnimControl->hide();
// keep visibility setting
m_animControlVisible = true;
}
m_fullscreenESCShortcut->setEnabled(true);
connect(m_fullscreenESCShortcut, SIGNAL(activated()), this, SLOT(fullscreenToggled()));
}
else {
window()->setWindowState(windowState() & ~Qt::WindowFullScreen);
setBackgroundRole(QPalette::Window);
#ifndef __APPLE__
if(m_menuBarVisible) on_actionMenu_bar_toggled(true);
#endif
if(m_statusBarVisible) ui.statusbar->show();
if(m_animControlVisible && !m_animControlFloating) ui.dockAnimControl->show();
m_fullscreenESCShortcut->disconnect();
m_fullscreenESCShortcut->setEnabled(false);
}
}
void PulsatingScience::on_actionStatus_bar_toggled(bool checked)
{
if(checked) {
ui.statusbar->show();
m_statusBarVisible = true;
}
else {
ui.statusbar->hide();
m_statusBarVisible = false;
}
}
void PulsatingScience::on_dockAnimControl_visibilityChanged(bool visible) {
m_animControlVisible = visible;
}
void PulsatingScience::on_dockAnimControl_topLevelChanged(bool topLevel) {
m_animControlFloating = topLevel;
}
void PulsatingScience::on_actionAbout_triggered()
{
QString content = "<b>%1</b><br>"
"<br>"
"%2: Oliver Bock<br>"
"%3: Bruce Allen<br>"
"<br>"
"%4: GNU General Public License v3<br>"
"<br>"
"Copyright © 2017 %5";
content = content.arg(
tr("GW170817"),
tr("UI/Graphics Code"),
tr("Physics Code"),
tr("License"),
tr("Max Planck Institute for Gravitational Physics"));
QMessageBox::about(this, tr("About \"GW170817\""), content);
}
void PulsatingScience::toggleHiddenDemoMode()
{
if(m_hiddenDemoModeActivated) {
#ifdef __APPLE__
window()->setWindowFlags(windowFlags()
& ~Qt::FramelessWindowHint
& ~Qt::WindowStaysOnTopHint);
window()->showNormal();
#endif
// show Menubar & Dock
on_actionMenu_bar_toggled(true);
ui.actionMenu_bar->setChecked(true);
window()->setWindowState(windowState() & ~Qt::WindowFullScreen);
ui.dockAnimControl->setFeatures(QDockWidget::DockWidgetClosable
| QDockWidget::DockWidgetMovable
| QDockWidget::DockWidgetFloatable);
m_inactivityTimer->stop();
m_hiddenDemoModeActivated = false;
}
else {
#ifdef __APPLE__
window()->setWindowFlags(windowFlags()
| Qt::FramelessWindowHint
| Qt::WindowStaysOnTopHint);
window()->showMaximized();
#endif
// hide Menubar & Dock
on_actionMenu_bar_toggled(false);
ui.actionMenu_bar->setChecked(false);
window()->setWindowState(windowState() | Qt::WindowFullScreen);
ui.dockAnimControl->setFeatures(QDockWidget::NoDockWidgetFeatures);
m_inactivityTimer->start(600000);
m_hiddenDemoModeActivated = true;
}
}
bool PulsatingScience::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::MouseButtonPress) {
userActivity();
}
// return original event (we don't want to change any behavior)
return QObject::eventFilter(obj, event);
}
void PulsatingScience::userActivity()
{
if(m_hiddenDemoModeActivated) {
// restart existing timer
m_inactivityTimer->start();
}
}
void PulsatingScience::userInactivityCallback()
{
saveOrRestoreInitialAnimationSettings();
}
void PulsatingScience::updateAmplitudes(const PlotData& data) {
QString s;
ui.lcdAmpLHO->display(s.sprintf("%.2f", data.m_ampLHO));
ui.lcdAmpLLO->display(s.sprintf("%.2f", data.m_ampLLO));
ui.lcdAmpVirgo->display(s.sprintf("%.2f", data.m_ampVirgo));
ui.lcdAmpKAGRA->display(s.sprintf("%.2f", data.m_ampKAGRA));
ui.lcdAmpLI->display(s.sprintf("%.2f", data.m_ampLI));
}
void PulsatingScience::saveOrRestoreInitialAnimationSettings()
{
static bool initialized = false;
static int sliderLHOAngle;
static int sliderLLOAngle;
static int sliderVirgoAngle;
static int sliderKAGRAAngle;
static int sliderLIAngle;
static int sliderSourceIota;
static int sliderSourceInclination;
static double cameraAngleH;
static double cameraAngleV;
static double cameraZoom;
if(initialized) {
// restore intial settings
ui.sliderLHOAngle->setValue(sliderLHOAngle);
ui.sliderLLOAngle->setValue(sliderLLOAngle);
ui.sliderSourceIota->setValue(sliderSourceIota);
ui.sliderVirgoAngle->setValue(sliderVirgoAngle);
ui.sliderKAGRAAngle->setValue(sliderKAGRAAngle);
ui.sliderLIAngle->setValue(sliderLIAngle);
ui.sliderSourceInclination->setValue(sliderSourceInclination);
ui.pulsarGlWidget->resetCameraPosition(cameraAngleH, cameraAngleV, cameraZoom);
}
else {
// save initial settings
sliderLHOAngle = ui.sliderLHOAngle->value();
sliderLLOAngle = ui.sliderLLOAngle->value();
sliderSourceIota = ui.sliderSourceIota->value();
sliderVirgoAngle = ui.sliderVirgoAngle->value();
sliderKAGRAAngle = ui.sliderKAGRAAngle->value();
sliderLIAngle = ui.sliderLIAngle->value();
sliderSourceInclination = ui.sliderSourceInclination->value();
ui.pulsarGlWidget->getCameraPosition(cameraAngleH, cameraAngleV, cameraZoom);
initialized = true;
}
}