void TimeoutMonitor::start () { QString settingsFilePath = QDir::homePath () + "/.sfviewer.config"; if( ! QFileInfo( settingsFilePath).isReadable()) throw QString("Cannot read config file %1").arg(settingsFilePath); // get database information from the INI file QSettings qset( settingsFilePath, QSettings::IniFormat); bool ok; pureWebTimeout_ = qset.value ( "timeout", DefaultPureWebTimeout).toInt ( & ok); if( ! ok) pureWebTimeout_ = DefaultPureWebTimeout; // the last timeout reset is set to current time lastTimeoutReset_.start (); dbg(1) << "Application timeout will be " << pureWebTimeout_ << " seconds.\n"; // connect this class to pure web GetStateManager().ViewManager().RegisterView( "FakeView", this); CSI::PureWeb::Server::ViewImageFormat viewImageFormat; viewImageFormat.PixelFormat = CSI::PureWeb::PixelFormat::Rgb24; viewImageFormat.ScanLineOrder = CSI::PureWeb::ScanLineOrder::TopDown; viewImageFormat.Alignment = 4; GetStateManager().ViewManager().SetViewImageFormat( "FakeView", viewImageFormat); startTimer ( 1000); }
HistogramDialog::HistogramDialog(QWidget * parent, FitsViewerServer & fvs) : QObject(parent), m_fvs( fvs) { m_frameInfoNumber = -1; // m_ui->setupUi(this); // connect signals connect ( & m_recalcTimer, SIGNAL(timeout()), SLOT(recalcTimerCB())); bgColor_ = QColor("black"); markerColor_ = QColor("white"); rectColor_ = QColor( 255, 255, 255, 64); zMin_ = 0; zMax_ = 0; gMin_ = 0; gMax_ = 0; min_ = 0; max_ = 0; m_imageWidth = m_imageHeight = 100; m_smoothGraph = true; m_logScale = true; m_cursorX = 0; m_marginLeft = 5; m_marginRight = 5; m_marginTop = 12; m_marginBottom = 20; m_visibleOnClient = false; // setup a recalculation timer m_recalcTimer.setSingleShot(true); recalculateHistogramDelayed(); m_buffer = QImage( QSize(100,100), QImage::Format_ARGB32_Premultiplied); // PureWeb // the default preset is 99.5% pwset( "/Histogram/Index", 3); GetStateManager().CommandManager().AddUiHandler( "histogram", CSI::Bind(this, &HistogramDialog::pwCommandHandler)); CSI::PureWeb::Server::ViewImageFormat viewImageFormat; viewImageFormat.PixelFormat = CSI::PureWeb::PixelFormat::Bgrx32; viewImageFormat.ScanLineOrder = CSI::PureWeb::ScanLineOrder::TopDown; viewImageFormat.Alignment = 4; GetStateManager().ViewManager().RegisterView("HistogramView", this); GetStateManager().ViewManager().SetViewImageFormat("HistogramView", viewImageFormat); // create and bind global variables // ================================ m_ignoreVarCallbacks = true; QString m_pwPrefix = "/Histogram/"; binder( m_vars.cursor, m_pwPrefix, "cursor"); binder( m_vars.lowerClip, m_pwPrefix, "LowerClip"); binder( m_vars.upperClip, m_pwPrefix, "UpperClip"); m_ignoreVarCallbacks = false; }
const QString &RawVariable::get(bool sync) { if( sync) { std::string stdstr = GetStateManager().XmlStateManager() .GetValue( m_fullPath.toStdString()).ConvertOr<std::string>(""); m_cachedValue = stdstr.c_str(); } return m_cachedValue; }
void State_Console::Update(const sf::Time& l_time) { // Update console loc m_console.Update(l_time.asSeconds()); if(!m_console.IsOpen()){ GetStateManager().SwitchTo(StateType::Game); } }
void HGEGame::InitEngine() { SetupGUI(); // Инициализация компонентов движка Engine::GetSingleton()->SetInputSystem(new HGEInputSystem(mHGE)); Engine::GetSingleton()->SetResourceManager(new HGEResourceManager(mHGE)); Engine::GetSingleton()->SetSoundSystem(new HGESoundSystem(mHGE)); Engine::GetSingleton()->mHGE = mHGE; // Инициализация менеджера состояний GetStateManager()->SetRenderer(new HGERenderer(mHGE)); }
void State_Console::OnDestroy() { EventManager* evMgr = GetStateManager().GetContext().GetEventManager(); evMgr->RemoveCallback(StateType::Console, "Key_Tilde"); evMgr->RemoveCallback(StateType::Console, "Text_Entered"); evMgr->RemoveCallback(StateType::Console, "Key_Return"); evMgr->RemoveCallback(StateType::Console, "Key_Up"); evMgr->RemoveCallback(StateType::Console, "Key_Down"); evMgr->RemoveCallback(StateType::Console, "Key_Left"); evMgr->RemoveCallback(StateType::Console, "Key_Right"); evMgr->RemoveCallback(StateType::Console, "Key_PageUp"); evMgr->RemoveCallback(StateType::Console, "Key_PageDown"); //evMgr->RemoveCallback(StateType::Console, "Key_Shift"); }
RawVariable::CallbackID RawVariable::addCallback(CallbackType fn) { // register us with pureweb now that we have a callback if( ! m_internalCbRegistered) { m_internalCbRegistered = true; GetStateManager().XmlStateManager().AddValueChangedHandler( m_fullPath.toStdString(), CSI::Bind(this, &RawVariable::internalCb)); } auto thisId = m_currId; m_currId ++; m_cbmap[thisId] = fn; return thisId; }
RawVariable::~RawVariable() { dbg(1) << "Destroying GlobalVar " << m_fullPath; if( m_insideInternalCb) { dbg(-1) << ConsoleColors::warning() << "Destroying global variable " << m_fullPath << " while in it's callback!!!!" << ConsoleColors::resetln(); } // deregister with pureweb if( m_internalCbRegistered) { GetStateManager().XmlStateManager().RemoveValueChangedHandler( m_fullPath.toStdString(), CSI::Bind(this, &RawVariable::internalCb)); m_internalCbRegistered = false; } }
void QUProfileController::updateTimerCB() { if( ! m_vars.visibleOnClient-> get()) return; // update m_buffer with the painting redrawAllNow(); if( m_dirtyFlags.graph) { if( ! m_viewName.isEmpty()) { // TODO: deferred vs immediate - investigate which is better... GetStateManager().ViewManager().RenderViewDeferred( m_viewName.toStdString()); // GetStateManager().ViewManager().RenderViewImmediate( m_viewName.toStdString()); } } // reset all dirty flags m_dirtyFlags = DirtyFlags(); }
void State_Console::OnCreate() { SetTrancendent(true); SetTransparent(true); m_console.Add("get_player", [this](std::vector<std::string> l) -> std::string{ if(l[0] == "make"){ /* Character* player = (Character*)GetStateManager().GetContext().GetEntityManager()->Find("Player"); if(player){ if(l[1] == "jump"){ player->Jump(); return "character jumped!"; } else if(l[1] == "attack"){ player->Attack(); return "character attacked!"; } }else{ return "player not found"; } */ } return "get_player: invalid parameters"; }, 2, 2, "make 'jump' 'attack'"); EventManager* evMgr = GetStateManager().GetContext().GetEventManager(); evMgr->AddCallback(StateType::Console, "Key_Tilde", &State_Console::Close, this); evMgr->AddCallback(StateType::Console, "Text_Entered", &Console::HandleTextInput, &m_console); evMgr->AddCallback(StateType::Console, "Key_Return", &Console::ValidateInput, &m_console); evMgr->AddCallback(StateType::Console, "Key_Backspace", &Console::Backspace, &m_console); evMgr->AddCallback(StateType::Console, "Key_Up", &Console::CycleInputUp, &m_console); evMgr->AddCallback(StateType::Console, "Key_Down", &Console::CycleInputDown, &m_console); evMgr->AddCallback(StateType::Console, "Key_Left", &Console::MoveCursorLeft, &m_console); evMgr->AddCallback(StateType::Console, "Key_Right", &Console::MoveCursorRight, &m_console); evMgr->AddCallback(StateType::Console, "Key_PageUp", &Console::ScrollOutputUp, &m_console); evMgr->AddCallback(StateType::Console, "Key_PageDown", &Console::ScrollOutputDown, &m_console); //evMgr->AddCallback(StateType::Console, "Key_Shift", &State_Console::OpenFull, this); }
void HistogramDialog::recalculateHistogramRaw () { if(! m_visibleOnClient) return; ScopedDebug sd( "Recalculating histogram (slow)", 1); // drawable area width/height int daWidth = m_imageWidth - m_marginLeft - m_marginRight; int daHeight = m_imageHeight - m_marginTop - m_marginBottom; m_histInfo.min = zMin_; m_histInfo.max = zMax_; m_histInfo.nNans = 0; m_histInfo.maxBin = 0; int nBins; if( m_smoothGraph) nBins = std::max( daWidth , 10); else nBins = std::max( daWidth / 10, 10); m_histInfo.bins.resize ( nBins); for( int i = 0 ; i < nBins ; i ++ ) m_histInfo.bins[i] = 0; quint64 trueCount = 0; // number of pixels in the clip range quint64 totalPixels = 0; // number of pixels that are not nans if( m_cir) { FitsParser & p = m_cir-> parser (); // alias FitsParser::HeaderInfo header = p.getHeaderInfo (); // totalPixels = header.naxis1 * header.naxis2; for( int y = 0 ; y < header.naxis2 ; y ++ ) { for( int x = 0 ; x < header.naxis1 ; x ++ ) { double v = p.src ( x, y, m_frameInfoNumber); if( isnan (v)) { m_histInfo.nNans ++; // totalPixels --; } else { // TODO: centering in bins...? int i = floor (nBins * (v - m_histInfo.min)/(m_histInfo.max - m_histInfo.min)); if( i >= 0 && i < nBins) { m_histInfo.bins[i] ++; } if( v >= min() && v <= max()){ trueCount ++; } } } } totalPixels = header.naxis1 * header.naxis2 - m_histInfo.nNans; // compute the highest count (so that we can scale this when drawing) for( int i = 0 ; i < m_histInfo.bins.size () ; i ++ ) { m_histInfo.maxBin = std::max( m_histInfo.maxBin, m_histInfo.bins[i]); } } // render the histogram QColor barColor( "#0071FD"); // QColor backgroundColor( "#F3F3DA"); QColor backgroundColor( "#ffffff"); QColor highlightColor( "#FF0000"); m_buffer = QImage( QSize(m_imageWidth, m_imageHeight), m_buffer.format()); int ih = m_imageHeight; QPainter painter( & m_buffer); painter.setRenderHint( QPainter::Antialiasing, true); painter.setRenderHint( QPainter::HighQualityAntialiasing, true); painter.fillRect ( m_buffer.rect (), backgroundColor); // over which bin is the cursor? int cursorBin = m_cursorX - m_marginLeft; if( ! m_smoothGraph) cursorBin = floor( (m_cursorX - m_marginLeft) / double(daWidth) * nBins); cursorBin = clamp( cursorBin, 0, nBins - 1); double maxY = m_histInfo.maxBin; if( m_logScale) maxY = log( maxY + 1); double dx = double(daWidth) / nBins; for( int i = 0 ; i < m_histInfo.bins.size () ; i ++ ) { double y = m_histInfo.bins[i]; if(y == 0) continue; if( m_logScale) y = log(y + 1); y = (daHeight-2) * y / double( maxY) + 2; // painter.fillRect( QRectF( dx * i, ih, dx, -y ), barColor); QPoint p1( round( dx * i) + m_marginLeft, ih - m_marginBottom); QPoint p2( round( dx * (i+1)) - 1 + m_marginLeft, ih - m_marginBottom - y); if( i == cursorBin) painter.fillRect( QRect( p1, p2 ), highlightColor); else painter.fillRect( QRect( p1, p2 ), barColor); } // draw faint rectangles around bars (only if in bar mode) if( ! m_smoothGraph) { for( int i = 0 ; i < m_histInfo.bins.size () ; i ++ ) { double y = m_histInfo.bins[i]; if( m_logScale) y = log(y + 1); y = daHeight * y / double( maxY); // painter.fillRect( QRectF( dx * i, ih, dx, -y ), barColor); QPoint p1( round( dx * i) + m_marginLeft, ih - m_marginBottom); QPoint p2( round( dx * (i+1)) - 1 + m_marginLeft, ih - m_marginBottom - y); painter.setPen( QPen( QColor("black"), 0.1)); painter.drawRect( QRect( p1, p2 )); } } // draw labels for horizontal { double yy = m_imageHeight - m_marginBottom + 1; Plot2dLabelers::BasicLabeler::SharedPtr horizLabeler = std::make_shared< Plot2dLabelers::BasicLabeler >(); QFont m_fontHorizontalLabels( "Arial", 8); QFontMetrics m_fmHorizontalLabels( m_fontHorizontalLabels); int labelFontHeight = m_fmHorizontalLabels.height(); auto measureTxt = [&m_fmHorizontalLabels]( const QString & str) -> double { return m_fmHorizontalLabels.width( str); }; horizLabeler-> setZoom( zMin_, zMax_); horizLabeler-> setPixels( daWidth); horizLabeler-> setDual( false); auto labels = horizLabeler-> compute( measureTxt); painter.setFont( m_fontHorizontalLabels); painter.setPen( "black"); QVector<QPointF> ticks; ticks.append( QPointF( m_marginLeft - 5, yy)); ticks.append( QPointF( m_imageWidth - m_marginRight + 5, yy)); for( auto & label : labels) { double xx = label.centerPix + m_marginLeft; painter.drawText( QRectF( xx, yy + labelFontHeight / 2.0 + 5, 1, 1), Qt::AlignCenter | Qt::TextDontClip, label.txt1 ); ticks.append( QPointF( xx, m_imageHeight - m_marginBottom + 1)); ticks.append( QPointF( xx, m_imageHeight - m_marginBottom + 5)); } // tick marks painter.setPen( QPen( QBrush("blue"), 1)); painter.drawLines( ticks); } // draw the markers double x1 = (min() - zMin_) / (zMax_ - zMin_) * daWidth + m_marginLeft; double x2 = (max() - zMin_) / (zMax_ - zMin_) * daWidth + m_marginLeft; painter.fillRect( QRectF( x1, 5, x2-x1, 5 ), QColor("#008800")); // draw the current cursor position double binCenter = (cursorBin + 0.5) / nBins * (zMax_ - zMin_) + zMin_; double cursorBinVal = m_histInfo.bins[ cursorBin]; GetStateManager().ViewManager().RenderViewDeferred("HistogramView"); // tell clients where the markers are pwset( "/Histogram/marker1", x1 / m_imageWidth); pwset( "/Histogram/marker2", x2 / m_imageWidth); // tell clients other stats // pwset("/Histogram/LowerClip", m_fvs.formatValue( min_)); // pwset("/Histogram/UpperClip", m_fvs.formatValue( max_)); m_vars.lowerClip-> set( min_); m_vars.upperClip-> set( max_); pwset("/Histogram/GlobalMin", m_fvs.formatValue( frameInfo_.min)); pwset("/Histogram/GlobalMax", m_fvs.formatValue( frameInfo_.max)); pwset( "/Histogram/nNaNs", m_histInfo.nNans); pwset( "/Histogram/binValue", m_fvs.formatValue( binCenter)); pwset( "/Histogram/nValuesInBin", cursorBinVal); pwset( "/Histogram/trueCount", QString::number( 100 * double(trueCount) / totalPixels, 'g', 6) + "%"); }
/** * @brief constructor for QUProfileController * @param parent * @param wcsHelper - coordinate/value formatter * @param id * @param title * @param willDoFitting */ QUProfileController::QUProfileController(QObject * parent, const QString & id, const QString & title) : QObject(parent) { m_myId = id; m_pwPrefix = QString( "/quprofile-%1/").arg( m_myId); m_viewName = QString( "quprofile-%1").arg( m_myId); m_initialized = false; // create a render buffer m_buffer = QImage( 2, 2, QImage::QImage::Format_RGB888); // setup fonts m_labelFont = QFont( "Helvetica", 8); m_captionFont = QFont( "Helvetica", 10, QFont::Normal); m_labelFontMetrics.reset( new QFontMetricsF( m_labelFont)); m_captionFontMetrics.reset( new QFontMetricsF( m_captionFont)); // register a view with pureweb CSI::PureWeb::Server::ViewImageFormat viewImageFormat; viewImageFormat.PixelFormat = CSI::PureWeb::PixelFormat::Rgb24; viewImageFormat.ScanLineOrder = CSI::PureWeb::ScanLineOrder::TopDown; viewImageFormat.Alignment = 4; GetStateManager().ViewManager().RegisterView( m_viewName.toStdString(), this); GetStateManager().ViewManager().SetViewImageFormat( m_viewName.toStdString(), viewImageFormat); GetStateManager ().ViewManager ().SetViewInteracting( m_viewName.toStdString(), false); // register PureWeb callback for all commands GetStateManager().CommandManager().AddUiHandler( ("quprofile-" + m_myId).toStdString(), CSI::Bind(this, & QUProfileController::commandDispatcher )); // cursor requests are arriving as state changes GetStateManager().XmlStateManager().AddValueChangedHandler( QString("/requests/quprofile-%1/mouseHover").arg(m_myId).toStdString(), CSI::Bind(this, &QUProfileController::mouseHoverRequestCB)); // set some defaults m_total = 0; m_cursorIndex = -1; m_autoZoom = true; // setup the colormap function (cached) { ColormapFunction cmap = ColormapFunction::sunbow(); cmap.setRgbScales( 0.5, 0.5, 0.5); HistogramColormapFunctor hfun( 0, 1, cmap); m_cmap.reset( new CachedRgbFunction( hfun, 0, 1, 256, Rgb(0,0,0))); } m_updateTimer = new QTimer( this); m_updateTimer->setSingleShot( true); m_updateTimer->setInterval(1); // set up the graph labelers m_vertLabeler = std::make_shared< Plot2dLabelers::BasicLabeler >(); // m_vertLabeler-> setDual( false); m_horizLabeler = std::make_shared< Plot2dLabelers::BasicLabeler >(); // m_horizLabeler-> setDual( false); // connect our update timer to callback connect( m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTimerCB())); // create global variables reflecting the state of the object m_ignoreVarCallbacks = true; binder( this, m_vars.dotSize, "dotSize", 2.5); binder( this, m_vars.transparency, "transparency", 0.5); binder( this, m_vars.showCursor, "showCursor", true); binder( this, m_vars.showMean, "showMean", true); binder( this, m_vars.showGrid, "showGrid", true); binder( this, m_vars.showSunbow, "showSunbow", true); binder( this, m_vars.showConnectingLines, "showConnect", false); binder( this, m_vars.visibleOnClient, "visibleOnClient", false); // outgoing variables (no need to assign callbacks to these) m_vars.qVal.reset( new GlobalState::StringVar( m_pwPrefix + "q")); m_vars.uVal.reset( new GlobalState::StringVar( m_pwPrefix + "u")); m_vars.qMean.reset( new GlobalState::StringVar( m_pwPrefix + "qmean")); m_vars.uMean.reset( new GlobalState::StringVar( m_pwPrefix + "umean")); m_vars.frame.reset( new GlobalState::StringVar( m_pwPrefix + "frame")); m_vars.title.reset( new GlobalState::StringVar( m_pwPrefix + "title")); m_vars.title-> set( title); // unsuspend callback m_ignoreVarCallbacks = false; markDirty(); }
//--------------------------------------------------------- //--------------------------------------------------------- void App::PushInitialState() { GetStateManager()->Push(CSCore::StateSPtr(new SplashState())); }
void State_Console::Draw() { m_console.Draw(GetStateManager().GetContext().GetWindow()->GetRenderWindow()); }
void RawVariable::set(const QString &val) { GetStateManager().XmlStateManager() .SetValueAs( m_fullPath.toStdString(), val.toStdString()); }