Moved CAF to Fwk/AppFwk and moved/renamed VisualizationModules to Fwk/VizFwk

This commit is contained in:
sigurdp
2013-09-20 16:01:20 +02:00
parent 7ea10201ec
commit f64d9b7e64
505 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 2.8)
project(LibGuiQt)
# We're getting too much trouble from Qt using strict
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CEE_BASE_CXX_FLAGS}")
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long")
endif()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
include_directories(../LibCore)
include_directories(../LibGeometry)
include_directories(../LibRender)
include_directories(../LibViewing)
set(CEE_SOURCE_FILES
cvfqtBasicAboutDialog.cpp
cvfqtCvfBoundQGLContext.cpp
cvfqtMouseState.cpp
cvfqtOpenGLContext.cpp
cvfqtOpenGLWidget.cpp
cvfqtPerformanceInfoHud.cpp
cvfqtUtils.cpp
)
add_library(${PROJECT_NAME} ${CEE_SOURCE_FILES})

View File

@@ -0,0 +1,395 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cvfBase.h"
#include "cvfSystem.h"
#include "cvfqtBasicAboutDialog.h"
#include <QtCore/QVariant>
#include <QtGui/QVBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtOpenGL/QGLFormat>
namespace cvfqt {
//==================================================================================================
///
/// \class cvfqt::BasicAboutDialog
/// \ingroup GuiQt
///
///
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
BasicAboutDialog::BasicAboutDialog(QWidget* parent)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
{
m_isCreated = false;
//m_appName;
//m_appVersion;
//m_appCopyright;
m_showCeeVizVersion = true;
m_showQtVersion = true;
m_isDebugBuild = false;
}
//--------------------------------------------------------------------------------------------------
/// Set application name to show in the dialog. Must be specified if any other app info is to be displayed
//--------------------------------------------------------------------------------------------------
void BasicAboutDialog::setApplicationName(const QString& appName)
{
CVF_ASSERT(!m_isCreated);
m_appName = appName;
}
//--------------------------------------------------------------------------------------------------
/// Set application version info to display
//--------------------------------------------------------------------------------------------------
void BasicAboutDialog::setApplicationVersion(const QString& ver)
{
CVF_ASSERT(!m_isCreated);
m_appVersion = ver;
}
//--------------------------------------------------------------------------------------------------
/// Set copyright info to display
//--------------------------------------------------------------------------------------------------
void BasicAboutDialog::setCopyright(const QString& copyright)
{
CVF_ASSERT(!m_isCreated);
m_appCopyright = copyright;
}
//--------------------------------------------------------------------------------------------------
/// Set application icon to display
//--------------------------------------------------------------------------------------------------
void BasicAboutDialog::setApplicationIcon(const QIcon& icon)
{
m_appIcon = icon;
}
//--------------------------------------------------------------------------------------------------
/// Enable display of CeeViz version
//--------------------------------------------------------------------------------------------------
void BasicAboutDialog::showCeeVizVersion(bool show)
{
CVF_ASSERT(!m_isCreated);
m_showCeeVizVersion = show;
}
//--------------------------------------------------------------------------------------------------
/// Enable display of Qt version
//--------------------------------------------------------------------------------------------------
void BasicAboutDialog::showQtVersion(bool show)
{
CVF_ASSERT(!m_isCreated);
m_showQtVersion = show;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BasicAboutDialog::addVersionEntry(const QString& verLabel, const QString& verText)
{
CVF_ASSERT(!m_isCreated);
m_verLabels.push_back(verLabel);
m_verTexts.push_back(verText);
CVF_ASSERT(m_verLabels.size() == m_verTexts.size());
}
//--------------------------------------------------------------------------------------------------
/// Set to true to show text in dialog to indicate that we're running a debug build of our app
//--------------------------------------------------------------------------------------------------
void BasicAboutDialog::setIsDebugBuild(bool isDebugBuild)
{
CVF_ASSERT(!m_isCreated);
m_isDebugBuild = isDebugBuild;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BasicAboutDialog::create()
{
// Only allowed to call once
CVF_ASSERT(!m_isCreated);
// Only show app info if app name is non-empty
bool showAppInfo = !m_appName.isEmpty();
// Do an initial resize, dialog will resize itself later based on the widgets we have added
resize(10, 10);
// Set caption, different text depending on whether we're showing app info or not
QString dlgCaption = "Version Information Details";
if (showAppInfo)
{
dlgCaption = "About " + m_appName;
if (m_isDebugBuild) dlgCaption += " (DEBUG)";
}
setWindowTitle(dlgCaption);
// Create the dialog's main layout
QVBoxLayout* dlgMainLayout = new QVBoxLayout(this);
// The the top layout
QVBoxLayout* topLayout = new QVBoxLayout;
topLayout->setSpacing(3);
// Possibly create and set text for widgets with app info
if (showAppInfo)
{
QVBoxLayout* appInfoLayout = new QVBoxLayout;
appInfoLayout->setSpacing(3);
QHBoxLayout* appNameLayout = new QHBoxLayout;
if (!m_appIcon.isNull())
{
QLabel* iconLabel = new QLabel(this);
iconLabel->setPixmap(m_appIcon.pixmap(QSize(200, 200)));
appNameLayout->addWidget(iconLabel);
}
// Always do app name
CVF_ASSERT(!m_appName.isEmpty());
QLabel* appNameLabel = new QLabel(this);
QFont appNameFont(appNameLabel->font());
appNameFont.setPointSize(14);
appNameFont.setBold(true);
appNameLabel->setFont(appNameFont);
appNameLabel->setText(m_appName);
appNameLayout->addWidget(appNameLabel);
appInfoLayout->addLayout(appNameLayout);
// Application version if specified
if (!m_appVersion.isEmpty())
{
QString appVer = m_appVersion;
appVer += cvf::System::is64Bit() ? " (64-bit)" : " (32-bit)";
QLabel* appVersionLabel = new QLabel(this);
QFont appVersionFont(appVersionLabel->font());
appVersionFont.setPointSize(8);
appVersionFont.setBold(TRUE);
appVersionLabel->setFont(appVersionFont);
appVersionLabel->setText(appVer);
appInfoLayout->addWidget(appVersionLabel);
}
// Application copyright if specified
if (!m_appCopyright.isEmpty())
{
QLabel* appCopyrightLabel = new QLabel(this);
appCopyrightLabel->setTextFormat(Qt::RichText);
QFont appCopyrightFont(appCopyrightLabel->font());
appCopyrightFont.setPointSize(8);
appCopyrightFont.setBold(TRUE);
appCopyrightLabel->setFont(appCopyrightFont);
appCopyrightLabel->setText(m_appCopyright);
appInfoLayout->addWidget(appCopyrightLabel);
}
QFrame* line = new QFrame(this);
line->setProperty("frameShape", (int)QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
line->setFrameShape(QFrame::HLine);
appInfoLayout->addWidget(line);
topLayout->addLayout(appInfoLayout);
}
// Possibly show extend version info
if (m_showCeeVizVersion ||
m_showQtVersion ||
m_verLabels.size() > 0)
{
QGridLayout* verInfoLayout = new QGridLayout;
verInfoLayout->setSpacing(0);
int insertRow = 0;
// // CeeViz version
// if (m_showCeeVizVersion)
// {
// QString ver;
// ver.sprintf("%s.%s%s-%s", CVF_MAJOR_VERSION, CVF_MINOR_VERSION, CVF_SPECIAL_BUILD, CVF_BUILD_NUMBER);
//
// addStringPairToVerInfoLayout("CeeViz ver.: ", ver, verInfoLayout, insertRow++);
// }
//
// // Qt version
// if (m_showQtVersion)
// {
// addStringPairToVerInfoLayout("Qt ver.: ", qVersion(), verInfoLayout, insertRow++);
// }
// Custom specified labels
if (m_verLabels.size() > 0)
{
CVF_ASSERT(m_verLabels.size() == m_verTexts.size());
int i;
for (i = 0; i < m_verLabels.size(); i++)
{
addStringPairToVerInfoLayout(m_verLabels[i], m_verTexts[i], verInfoLayout, insertRow++);
}
}
topLayout->addLayout(verInfoLayout);
}
dlgMainLayout->addLayout(topLayout);
QSpacerItem* spacer1 = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
dlgMainLayout->addItem(spacer1);
// The bottom part with the OK button and
// possibly text label indicating that we're running a debug build
QHBoxLayout* bottomLayout = new QHBoxLayout;
// Indicate that this is a debug build
if (m_isDebugBuild)
{
QLabel* debugLabel = new QLabel(this);
debugLabel->setText("<font color='brown'><b>This is a DEBUG build...</b></font>");
bottomLayout->addWidget(debugLabel);
}
// Add OK button
QSpacerItem* spacer2 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
bottomLayout->addItem(spacer2);
QPushButton* buttonOk = new QPushButton("&OK", this);
buttonOk->setAutoDefault(TRUE);
buttonOk->setDefault(TRUE);
buttonOk->setFocus();
connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()) );
bottomLayout->addWidget(buttonOk);
dlgMainLayout->addLayout(bottomLayout);
m_isCreated = true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void BasicAboutDialog::addStringPairToVerInfoLayout(const QString& labelStr, const QString& infoStr, QGridLayout* verInfoLayout, int insertRow)
{
QLabel* label = new QLabel(this);
label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
label->setText(labelStr);
verInfoLayout->addWidget(label, insertRow, 0);
QLabel* info = new QLabel(this);
info->setText(infoStr);
verInfoLayout->addWidget(info, insertRow, 1 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString BasicAboutDialog::openGLVersionString() const
{
QString versionString("OpenGL ");
QGLFormat::OpenGLVersionFlags flags = QGLFormat::openGLVersionFlags();
if (flags & QGLFormat::OpenGL_Version_4_0 ) versionString += "4.0";
else if (flags & QGLFormat::OpenGL_Version_3_3 ) versionString += "3.3";
else if (flags & QGLFormat::OpenGL_Version_3_2 ) versionString += "3.2";
else if (flags & QGLFormat::OpenGL_Version_3_1 ) versionString += "3.1";
else if (flags & QGLFormat::OpenGL_Version_3_0 ) versionString += "3.0";
else if (flags & QGLFormat::OpenGL_ES_Version_2_0 ) versionString += "ES_Version 2.0";
else if (flags & QGLFormat::OpenGL_ES_CommonLite_Version_1_1) versionString += "ES_CommonLite_Version 1.1";
else if (flags & QGLFormat::OpenGL_ES_Common_Version_1_1 ) versionString += "ES_Common_Version 1.1";
else if (flags & QGLFormat::OpenGL_ES_CommonLite_Version_1_0) versionString += "ES_CommonLite_Version 1.0";
else if (flags & QGLFormat::OpenGL_ES_Common_Version_1_0 ) versionString += "ES_Common_Version 1.0";
else if (flags & QGLFormat::OpenGL_Version_2_1 ) versionString += "2.1";
else if (flags & QGLFormat::OpenGL_Version_2_0 ) versionString += "2.0";
else if (flags & QGLFormat::OpenGL_Version_1_5 ) versionString += "1.5";
else if (flags & QGLFormat::OpenGL_Version_1_4 ) versionString += "1.4";
else if (flags & QGLFormat::OpenGL_Version_1_3 ) versionString += "1.3";
else if (flags & QGLFormat::OpenGL_Version_1_2 ) versionString += "1.2";
else if (flags & QGLFormat::OpenGL_Version_1_1 ) versionString += "1.1";
else if (flags & QGLFormat::OpenGL_Version_None ) versionString += "None";
else versionString += "Unknown";
return versionString;
}
} // namespace cvfqt

View File

@@ -0,0 +1,92 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include <QtGui/QDialog>
#include <QtGui/QIcon>
class QGridLayout;
namespace cvfqt {
//==================================================================================================
//
//
//
//==================================================================================================
class BasicAboutDialog : public QDialog
{
public:
BasicAboutDialog(QWidget* parent);
void setApplicationName(const QString& appName);
void setApplicationVersion(const QString& ver);
void setCopyright(const QString& copyright);
void setApplicationIcon(const QIcon& icon);
void showCeeVizVersion(bool show);
void showQtVersion(bool show);
void addVersionEntry(const QString& verLabel, const QString& verText);
void setIsDebugBuild(bool isDebugBuild);
void create();
QString openGLVersionString() const;
private:
void addStringPairToVerInfoLayout(const QString& labelStr, const QString& infoStr, QGridLayout* verInfoLayout, int insertRow);
private:
bool m_isCreated; // Indicates if the create() function has been called
QString m_appName; // Application name, appears in bold at the top of the dialog.
QString m_appVersion; // Application version info. Can be empty
QString m_appCopyright; // Application copyright string. Can be empty
QIcon m_appIcon;
bool m_showCeeVizVersion; // Flags whether CeeViz version info should be shown
bool m_showQtVersion; // Flags whether Qt version info should be shown
QStringList m_verLabels; // Labels for user specified version entries
QStringList m_verTexts; // The actual version text for user specified version entries
bool m_isDebugBuild; // If set to true, will show info in dlg to indicate that this is a debug build
};
}

View File

@@ -0,0 +1,93 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cvfBase.h"
#include "cvfqtCvfBoundQGLContext.h"
#include "cvfqtOpenGLContext.h"
namespace cvfqt {
//==================================================================================================
///
/// \class cvfqt::CvfBoundQGLContext
/// \ingroup GuiQt
///
///
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CvfBoundQGLContext::CvfBoundQGLContext(cvf::OpenGLContextGroup* contextGroup, const QGLFormat & format)
: QGLContext(format)
{
m_cvfGLContext = new OpenGLContext(contextGroup, this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CvfBoundQGLContext::~CvfBoundQGLContext()
{
if (m_cvfGLContext.notNull())
{
// TODO
// Need to resolve the case where the Qt QGLcontext (that we're deriving from) is deleted
// and we are still holding a reference to one or more OpenGLContext objects
// By the time we get here we expect that we're holding the only reference
CVF_ASSERT(m_cvfGLContext->refCount() == 1);
m_cvfGLContext = NULL;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::OpenGLContext* CvfBoundQGLContext::cvfOpenGLContext() const
{
return const_cast<cvf::OpenGLContext*>(m_cvfGLContext.p());
}
} // namespace cvfqt

View File

@@ -0,0 +1,64 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include "cvfOpenGLContext.h"
#include <QtOpenGL/QGLContext>
namespace cvfqt {
//==================================================================================================
//
// Utility class used to piggyback OpenGLContext onto Qt's QGLContext
//
//==================================================================================================
class CvfBoundQGLContext : public QGLContext
{
public:
CvfBoundQGLContext(cvf::OpenGLContextGroup* contextGroup, const QGLFormat & format);
virtual ~CvfBoundQGLContext();
cvf::OpenGLContext* cvfOpenGLContext() const;
private:
cvf::ref<cvf::OpenGLContext> m_cvfGLContext;
};
}

View File

@@ -0,0 +1,257 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cvfBase.h"
#include "cvfMath.h"
#include "cvfqtMouseState.h"
#include <QMouseEvent>
#include <QGraphicsSceneMouseEvent>
#include <math.h>
namespace cvfqt {
//==================================================================================================
///
/// \class cvfqt::MouseState
/// \ingroup GuiQt
///
/// Helper class for storing mouse positions and button states.
/// Should be reset whenever widget looses focus.
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
MouseState::MouseState()
{
m_cleanButtonClickTolerance = 3;
reset();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void MouseState::updateFromMouseEvent(QMouseEvent* event)
{
// Always update with current state
m_mouseButtonState = event->buttons();
m_keyboardModifierFlags = event->modifiers();
// Now do the events themselves
// Mouse press events
if (event->type() == QEvent::MouseButtonPress)
{
// Start by clearing them
m_cleanButtonPressButton = Qt::NoButton;
m_cleanButtonClickButton = Qt::NoButton;;
m_cleanButtonPressPosX = cvf::UNDEFINED_INT;
m_cleanButtonPressPosY = cvf::UNDEFINED_INT;
Qt::MouseButton buttonPressed = event->button();
if (numMouseButtonsInState(m_mouseButtonState) == 1)
{
m_cleanButtonPressButton = buttonPressed;
m_cleanButtonPressPosX = event->x();
m_cleanButtonPressPosY = event->y();
}
}
// Mouse button release events
else if (event->type() == QEvent::MouseButtonRelease)
{
// Clear it now, might set it later
m_cleanButtonClickButton = Qt::NoButton;
Qt::MouseButton buttonReleased = event->button();
// Check if we have a clean press/release sequence
if (m_cleanButtonPressButton == buttonReleased &&
m_cleanButtonPressPosX != cvf::UNDEFINED_INT &&
m_cleanButtonPressPosY != cvf::UNDEFINED_INT)
{
// We have a candidate, check if movement is within tolerance
if (cvf::Math::abs(double((m_cleanButtonPressPosX - event->x()))) <= m_cleanButtonClickTolerance &&
cvf::Math::abs(double((m_cleanButtonPressPosY - event->y()))) <= m_cleanButtonClickTolerance)
{
m_cleanButtonClickButton = buttonReleased;
}
m_cleanButtonPressButton = Qt::NoButton;;
m_cleanButtonPressPosX = cvf::UNDEFINED_INT;
m_cleanButtonPressPosY = cvf::UNDEFINED_INT;
}
}
else if (event->type() == QEvent::MouseMove)
{
// For now nothing to do
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void MouseState::updateFromMouseEvent(QGraphicsSceneMouseEvent* event)
{
// Always update with current state
m_mouseButtonState = event->buttons();
m_keyboardModifierFlags = event->modifiers();
// Now do the events themselves
if (event->type() == QEvent::GraphicsSceneMousePress)
{
// Start by clearing them
m_cleanButtonPressButton = Qt::NoButton;
m_cleanButtonClickButton = Qt::NoButton;;
m_cleanButtonPressPosX = cvf::UNDEFINED_INT;
m_cleanButtonPressPosY = cvf::UNDEFINED_INT;
Qt::MouseButton buttonPressed = event->button();
if (numMouseButtonsInState(m_mouseButtonState) == 1)
{
m_cleanButtonPressButton = buttonPressed;
m_cleanButtonPressPosX = event->screenPos().x();
m_cleanButtonPressPosY = event->screenPos().y();
}
}
// Mouse button release events
else if (event->type() == QEvent::GraphicsSceneMouseRelease)
{
// Clear it now, might set it later
m_cleanButtonClickButton = Qt::NoButton;
Qt::MouseButton buttonReleased = event->button();
// Check if we have a clean press/release sequence
if (m_cleanButtonPressButton == buttonReleased &&
m_cleanButtonPressPosX != cvf::UNDEFINED_INT &&
m_cleanButtonPressPosY != cvf::UNDEFINED_INT)
{
// We have a candidate, check if movement is within tolerance
if (cvf::Math::abs(double((m_cleanButtonPressPosX - event->screenPos().x()))) <= m_cleanButtonClickTolerance &&
cvf::Math::abs(double((m_cleanButtonPressPosY - event->screenPos().y()))) <= m_cleanButtonClickTolerance)
{
m_cleanButtonClickButton = buttonReleased;
}
m_cleanButtonPressButton = Qt::NoButton;;
m_cleanButtonPressPosX = cvf::UNDEFINED_INT;
m_cleanButtonPressPosY = cvf::UNDEFINED_INT;
}
}
else if (event->type() == QEvent::GraphicsSceneMouseMove)
{
// For now nothing to do
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void MouseState::reset()
{
m_mouseButtonState = Qt::NoButton;
m_cleanButtonPressButton = Qt::NoButton;
m_cleanButtonPressPosX = cvf::UNDEFINED_INT;
m_cleanButtonPressPosY = cvf::UNDEFINED_INT;
m_cleanButtonClickButton = Qt::NoButton;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Qt::MouseButtons MouseState::mouseButtonState() const
{
return m_mouseButtonState;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Qt::KeyboardModifiers MouseState::keyboardModifierFlags() const
{
return m_keyboardModifierFlags;
}
//--------------------------------------------------------------------------------------------------
/// Get button that was cleanly clicked if any
//--------------------------------------------------------------------------------------------------
Qt::MouseButton MouseState::cleanButtonClickButton() const
{
return m_cleanButtonClickButton;
}
//--------------------------------------------------------------------------------------------------
/// Static helper function to determine the number of mouse buttons pressed
//--------------------------------------------------------------------------------------------------
int MouseState::numMouseButtonsInState(Qt::MouseButtons buttonState)
{
int iNum = 0;
if (buttonState & Qt::LeftButton) iNum++;
if (buttonState & Qt::RightButton) iNum++;
if (buttonState & Qt::MidButton) iNum++;
return iNum;
}
} // namespace cvfqt

View File

@@ -0,0 +1,81 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
class QMouseEvent;
class QGraphicsSceneMouseEvent;
#include <Qt>
namespace cvfqt {
//==================================================================================================
//
// Helper class for storing mouse positions and button states. Should be reset whenever widget looses focus.
//
//==================================================================================================
class MouseState
{
public:
MouseState();
void updateFromMouseEvent(QMouseEvent* event);
void updateFromMouseEvent(QGraphicsSceneMouseEvent* event);
void reset();
Qt::MouseButtons mouseButtonState() const;
Qt::KeyboardModifiers keyboardModifierFlags() const;
Qt::MouseButton cleanButtonClickButton() const;
public:
static int numMouseButtonsInState(Qt::MouseButtons buttonState);
private:
Qt::MouseButtons m_mouseButtonState; // Stores current mouse button state (combination of mouse buttons that are down)
Qt::KeyboardModifiers m_keyboardModifierFlags; // Stores current keyboard modifier flags (combination of keyboard modifier keys that are down)
int m_cleanButtonClickTolerance; // The movement tolerance in pixels for considering a mouse button press/release sequence a clean button click
Qt::MouseButton m_cleanButtonPressButton; // The mouse button that was last pressed 'cleanly', that is without any other mouse buttons down. Used to detect clean button clicks (for showing context menus etc)
int m_cleanButtonPressPosX; // The position of the mouse cursor in widget coordinates of the last clean button press. Used to check if cursor has moved when button is released
int m_cleanButtonPressPosY; //
Qt::MouseButton m_cleanButtonClickButton; // The button (if any) that was last clicked 'cleanly'.
};
}

View File

@@ -0,0 +1,220 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cvfBase.h"
#include "cvfOpenGL.h"
#include "cvfqtOpenGLContext.h"
#include "cvfqtCvfBoundQGLContext.h"
#include "cvfOpenGLContextGroup.h"
#include "cvfOpenGLCapabilities.h"
namespace cvfqt {
//==================================================================================================
///
/// \class cvfqt::OpenGLContext
/// \ingroup GuiQt
///
/// Derived OpenGLContext that adapts a Qt QGLContext
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
OpenGLContext::OpenGLContext(cvf::OpenGLContextGroup* contextGroup, QGLContext* backingQGLContext)
: cvf::OpenGLContext(contextGroup),
m_isCoreOpenGLProfile(false),
m_majorVersion(0),
m_minorVersion(0)
{
m_qtGLContext = backingQGLContext;
#if QT_VERSION >= 0x040700
CVF_ASSERT(m_qtGLContext);
QGLFormat glFormat = m_qtGLContext->format();
m_majorVersion = glFormat.majorVersion();
m_minorVersion = glFormat.minorVersion();
m_isCoreOpenGLProfile = (glFormat.profile() == QGLFormat::CoreProfile) ? true : false;
#endif
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
OpenGLContext::~OpenGLContext()
{
m_qtGLContext = NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool OpenGLContext::initializeContext()
{
if (!cvf::OpenGLContext::initializeContext())
{
return false;
}
// Possibly override setting for fixed function support
if (m_isCoreOpenGLProfile)
{
group()->capabilities()->setSupportsFixedFunction(false);
}
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void OpenGLContext::makeCurrent()
{
CVF_ASSERT(m_qtGLContext);
m_qtGLContext->makeCurrent();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool OpenGLContext::isCurrent() const
{
if (m_qtGLContext)
{
if (QGLContext::currentContext() == m_qtGLContext)
{
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
/// Make an effort to save current OpenGL state. Must be matched by a call to restoreOpenGLState()
//--------------------------------------------------------------------------------------------------
void OpenGLContext::saveOpenGLState(cvf::OpenGLContext* oglContext)
{
CVF_CALLSITE_OPENGL(oglContext);
const cvf::OpenGLCapabilities* oglCaps = oglContext->capabilities();
// Only relevant for fixed function
if (!oglCaps->supportsFixedFunction())
{
return;
}
CVF_CHECK_OGL(oglContext);
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
CVF_CHECK_OGL(oglContext);
glPushAttrib(GL_ALL_ATTRIB_BITS);
CVF_CHECK_OGL(oglContext);
// Note: Only preserves matrix stack for texture unit 0
if (oglCaps->supportsOpenGL2())
{
glActiveTexture(GL_TEXTURE0);
}
glMatrixMode(GL_TEXTURE);
glPushMatrix();
CVF_CHECK_OGL(oglContext);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
CVF_CHECK_OGL(oglContext);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
CVF_CHECK_OGL(oglContext);
}
//--------------------------------------------------------------------------------------------------
/// Restore OpenGL state that has been saved by saveOpenGLState()
//--------------------------------------------------------------------------------------------------
void OpenGLContext::restoreOpenGLState(cvf::OpenGLContext* oglContext)
{
CVF_CALLSITE_OPENGL(oglContext);
const cvf::OpenGLCapabilities* oglCaps = oglContext->capabilities();
// Only relevant for fixed function
if (!oglCaps->supportsFixedFunction())
{
return;
}
CVF_CHECK_OGL(oglContext);
// Note: Only preserves matrix stack for texture unit 0
if (oglCaps->supportsOpenGL2())
{
glActiveTexture(GL_TEXTURE0);
}
glMatrixMode(GL_TEXTURE);
glPopMatrix();
CVF_CHECK_OGL(oglContext);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
CVF_CHECK_OGL(oglContext);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
CVF_CHECK_OGL(oglContext);
glPopAttrib();
CVF_CHECK_OGL(oglContext);
glPopClientAttrib();
CVF_CHECK_OGL(oglContext);
}
} // namespace cvfqt

View File

@@ -0,0 +1,73 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include "cvfOpenGLContext.h"
class QGLContext;
namespace cvfqt {
//==================================================================================================
//
// Derived OpenGLContext that adapts a Qt QGLContext
//
//==================================================================================================
class OpenGLContext : public cvf::OpenGLContext
{
public:
OpenGLContext(cvf::OpenGLContextGroup* contextGroup, QGLContext* backingQGLContext);
virtual ~OpenGLContext();
virtual bool initializeContext();
virtual void makeCurrent();
virtual bool isCurrent() const;
static void saveOpenGLState(cvf::OpenGLContext* oglContext);
static void restoreOpenGLState(cvf::OpenGLContext* oglContext);
private:
QGLContext* m_qtGLContext;
bool m_isCoreOpenGLProfile; // This is a Core OpenGL profile. Implies OpenGL version of 3.2 or more
int m_majorVersion; // OpenGL version as reported by Qt
int m_minorVersion;
};
}

View File

@@ -0,0 +1,150 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cvfBase.h"
#include "cvfOpenGLContextGroup.h"
#include "cvfqtCvfBoundQGLContext.h"
#include "cvfqtOpenGLWidget.h"
namespace cvfqt {
//==================================================================================================
///
/// \class cvfqt::OpenGLWidget
/// \ingroup GuiQt
///
///
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
OpenGLWidget::OpenGLWidget(cvf::OpenGLContextGroup* contextGroup, const QGLFormat& format, QWidget* parent, Qt::WindowFlags f)
: QGLWidget(new CvfBoundQGLContext(contextGroup, format), parent, NULL, f)
{
// This constructor can only be used with an empty context group!
// We're not able to check this up front, but assert that the count is 1 by the time we get here
CVF_ASSERT(contextGroup->contextCount() == 1);
if (isValid())
{
cvf::ref<cvf::OpenGLContext> myContext = cvfOpenGLContext();
if (myContext.notNull())
{
myContext->initializeContext();
}
}
}
//--------------------------------------------------------------------------------------------------
/// Constructor
///
/// Tries to create a widget that shares OpenGL resources with \a shareWidget
/// To check if creation was actually successful, you must call isValidContext() on the context
/// of the newly created widget. For example:
/// \code
/// myNewWidget->cvfOpenGLContext()->isValidContext();
/// \endcode
///
/// If the context is not valid, sharing failed and the newly created widget/context be discarded.
//--------------------------------------------------------------------------------------------------
OpenGLWidget::OpenGLWidget(OpenGLWidget* shareWidget, QWidget* parent , Qt::WindowFlags f)
: QGLWidget(new CvfBoundQGLContext(shareWidget->cvfOpenGLContext()->group(), shareWidget->format()), parent, shareWidget, f)
{
CVF_ASSERT(shareWidget);
cvf::ref<cvf::OpenGLContext> shareContext = shareWidget->cvfOpenGLContext();
CVF_ASSERT(shareContext.notNull());
cvf::ref<cvf::OpenGLContext> myContext = cvfOpenGLContext();
if (myContext.notNull())
{
// We need to check if we actually got a context that shares resources with shareWidget.
if (isSharing())
{
if (isValid())
{
CVF_ASSERT(myContext->group() == shareContext->group());
myContext->initializeContext();
}
}
else
{
// If we didn't, we need to remove the newly created context from the group it has been added to since
// the construction process above has already optimistically added the new context to the existing group.
// In this case, the newly context is basically defunct so we just shut it down (which will also remove it from the group)
myContext->shutdownContext();
CVF_ASSERT(myContext->group() == NULL);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::OpenGLContext* OpenGLWidget::cvfOpenGLContext() const
{
const QGLContext* qglContext = context();
const CvfBoundQGLContext* contextBinding = dynamic_cast<const CvfBoundQGLContext*>(qglContext);
CVF_ASSERT(contextBinding);
return contextBinding->cvfOpenGLContext();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void OpenGLWidget::cvfShutdownOpenGLContext()
{
// It should be safe to call shutdown multiple times so this call should
// amount to a no-op if the user has already shut down the context
cvf::ref<cvf::OpenGLContext> myContext = cvfOpenGLContext();
if (myContext.notNull())
{
myContext->shutdownContext();
}
}
} // namespace cvfqt

View File

@@ -0,0 +1,66 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include <QtOpenGL/QGLWidget>
namespace cvf
{
class OpenGLContext;
class OpenGLContextGroup;
}
namespace cvfqt {
//==================================================================================================
//
// Derived QGLWidget
//
//==================================================================================================
class OpenGLWidget : public QGLWidget
{
public:
OpenGLWidget(cvf::OpenGLContextGroup* contextGroup, const QGLFormat& format, QWidget* parent, Qt::WindowFlags f = 0);
OpenGLWidget(OpenGLWidget* shareWidget, QWidget* parent , Qt::WindowFlags f = 0);
cvf::OpenGLContext* cvfOpenGLContext() const;
void cvfShutdownOpenGLContext();
};
}

View File

@@ -0,0 +1,241 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cvfBase.h"
#include "cvfCamera.h"
#include "cvfPerformanceInfo.h"
#include "cvfqtPerformanceInfoHud.h"
#include "cvfOpenGLResourceManager.h"
#include <QtGui/QPainter>
#include <vector>
namespace cvfqt {
//==================================================================================================
///
/// \class cvfqt::PerformanceInfoHud
/// \ingroup GuiQt
///
///
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PerformanceInfoHud::PerformanceInfoHud()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PerformanceInfoHud::addStrings(const cvf::PerformanceInfo& performanceInfo)
{
double fps = 0.0;
if (performanceInfo.totalDrawTime > 0.0) fps = 1.0/performanceInfo.totalDrawTime;
double millPrimPerSecond = fps*static_cast<double>(performanceInfo.openGLPrimitiveCount)/1000000.0;
double avgTotalDrawTime = performanceInfo.averageTotalDrawTime();
double avgFPS = 0.0;
if (avgTotalDrawTime > 0.0) avgFPS = 1.0/avgTotalDrawTime;
double avgMillPrimPerSecond = avgFPS*static_cast<double>(performanceInfo.openGLPrimitiveCount)/1000000.0;
double openGLMemSize = (performanceInfo.vertexCount*24.0 + 4.0*(performanceInfo.triangleCount*3.0))/(1024*1024);
// Add spacing if we already have contents
if (!m_drawStrings.empty()) m_drawStrings.push_back("");
m_drawStrings.push_back(QString("FPS: %1 (last: %2)") .arg(avgFPS, 0, 'f', 2).arg(fps, 0, 'f', 2));
m_drawStrings.push_back(QString("Mill. OpenGL prim/s: %1 (last: %2)").arg(avgMillPrimPerSecond, 0, 'f', 2).arg(millPrimPerSecond, 0, 'f', 2));
m_drawStrings.push_back("");
m_drawStrings.push_back(QString("Total draw time: %1 ms (last: %2)") .arg(avgTotalDrawTime*1000.0, 0, 'f', 3).arg(performanceInfo.totalDrawTime*1000.0, 0, 'f', 3));
m_drawStrings.push_back(QString("Compute Vis Parts: %1 ms") .arg(performanceInfo.computeVisiblePartsTime*1000.0, 0, 'f', 3));
m_drawStrings.push_back(QString("Build RenderQueue: %1 ms") .arg(performanceInfo.buildRenderQueueTime*1000.0, 0, 'f', 3));
m_drawStrings.push_back(QString("Sort RenderQueue: %1 ms") .arg(performanceInfo.sortRenderQueueTime*1000.0, 0, 'f', 3));
m_drawStrings.push_back(QString("Render: %1 ms") .arg(performanceInfo.renderEngineTime*1000.0, 0, 'f', 3));
double other = performanceInfo.totalDrawTime - performanceInfo.computeVisiblePartsTime - performanceInfo.buildRenderQueueTime - performanceInfo.sortRenderQueueTime - performanceInfo.renderEngineTime;
m_drawStrings.push_back(QString("Other: %1 ms") .arg(other*1000.0, 0, 'f', 3));
//!!!! strArray.push_back(QString("Last pick time used: %1 ms").arg(m_lastPickTimeUsed*1000.0, 0, 'f', 3));
m_drawStrings.push_back("");
m_drawStrings.push_back(QString("Num visible parts: %1") .arg((int)performanceInfo.visiblePartsCount));
m_drawStrings.push_back(QString("Num rendered parts: %1") .arg((int)performanceInfo.renderedPartsCount));
if (performanceInfo.vertexCount > 0)
{
m_drawStrings.push_back(QString("Num vertices: %1") .arg((int)performanceInfo.vertexCount));
m_drawStrings.push_back(QString("Num triangles: %1") .arg((int)performanceInfo.triangleCount));
m_drawStrings.push_back(QString("OpenGL primitives: %1 mill").arg((double)performanceInfo.openGLPrimitiveCount/1000000.0, 0, 'f', 3));
m_drawStrings.push_back(QString("Total OpenGL array size: %1 MB").arg(openGLMemSize, 0, 'f', 2));
}
m_drawStrings.push_back(QString("Apply render state count: %1").arg((int)performanceInfo.applyRenderStateCount));
m_drawStrings.push_back(QString("Change shader program count: %1").arg((int)performanceInfo.shaderProgramChangesCount));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PerformanceInfoHud::addStrings(const cvf::OpenGLResourceManager& resourceManager)
{
double vboMemUsageMB = static_cast<double>(resourceManager.bufferObjectMemoryUsage())/(1024.0*1024.0);
m_drawStrings.push_back(QString("Num VBOs: %1").arg((int)resourceManager.bufferObjectCount()));
m_drawStrings.push_back(QString("VBO memory usage: %1 MB").arg(vboMemUsageMB, 0, 'f', 2));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PerformanceInfoHud::addStrings(const cvf::Camera& camera)
{
// Add spacing if we already have contents
if (!m_drawStrings.empty()) m_drawStrings.push_back("");
cvf::Vec3d eye, vrp, vup, viewdir;
camera.toLookAt(&eye, &vrp, &vup);
viewdir = (vrp - eye).getNormalized();
m_drawStrings.push_back(QString("Clip planes: %1 -> %2").arg(camera.nearPlane()).arg(camera.farPlane()));
m_drawStrings.push_back(QString("Eye: <%1, %2, %3>").arg(eye.x()).arg(eye.y()).arg(eye.z()));
m_drawStrings.push_back(QString("ViewDir: <%1, %2, %3>").arg(viewdir.x()).arg(viewdir.y()).arg(viewdir.z()));
m_drawStrings.push_back(QString("Up: <%1, %2, %3>").arg(vup.x()).arg(vup.y()).arg(vup.z()));
if (camera.fieldOfViewYDeg() != cvf::UNDEFINED_DOUBLE)
{
m_drawStrings.push_back(QString("FieldOfView: %1").arg(camera.fieldOfViewYDeg()));
}
else
{
m_drawStrings.push_back(QString("FieldOfView: N/A"));
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PerformanceInfoHud::addString(const QString& str)
{
m_drawStrings.push_back(str);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PerformanceInfoHud::draw(QPainter *painter, int widgetWidth, int widgetHeight)
{
/*
//!!!! strArray.push_back(QString("Last pick time used: %1 ms").arg(m_lastPickTimeUsed*1000.0, 0, 'f', 3));
//!!!! m_useDisplayLists ? strArray.push_back("Display lists: ON") : strArray.push_back("Display lists: OFF");
*/
// Draw the strings
QFontMetrics metrics = painter->fontMetrics();
int border = qMax(4, metrics.leading());
painter->setRenderHint(QPainter::TextAntialiasing);
int x = 10;
int y = 10;
int spacing = 5;
std::vector<QRect> rects;
int maxWidth = 0;
int totalHeight = 0;
int i;
for (i = 0; i < m_drawStrings.size(); i++)
{
QString text = m_drawStrings[i];
QRect rect = metrics.boundingRect(0, 0, widgetWidth - 2*border, int(widgetHeight*0.125), Qt::AlignCenter | Qt::TextWordWrap, text);
if (rect.width() > maxWidth) maxWidth = rect.width();
if (text.isEmpty())
{
totalHeight += spacing;
}
else
{
totalHeight += rect.height();
}
rects.push_back(rect);
}
QRect r1(x - border, y - border, maxWidth + 2*border, totalHeight + spacing*m_drawStrings.size());
painter->fillRect(r1, QColor(0, 0, 0, 127));
painter->setPen(Qt::white);
painter->fillRect(r1, QColor(0, 0, 0, 127));
for (i = 0; i < m_drawStrings.size(); i++)
{
QString text = m_drawStrings[i];
QRect rect = rects[i];
if (text.isEmpty())
{
y += spacing;
}
else
{
painter->drawText(x, y, rect.width(), rect.height(), Qt::AlignCenter | Qt::TextWordWrap, text);
y += rect.height() + spacing;
}
}
// Clear all contents
m_drawStrings.clear();
}
} // namespace cvfqt

View File

@@ -0,0 +1,74 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include <QtCore/QStringList>
namespace cvf {
class PerformanceInfo;
class OpenGLResourceManager;
class Camera;
}
class QPainter;
namespace cvfqt {
//==================================================================================================
//
// PerformanceInfoHud
//
//==================================================================================================
class PerformanceInfoHud
{
public:
PerformanceInfoHud();
void addStrings(const cvf::PerformanceInfo& performanceInfo);
void addStrings(const cvf::OpenGLResourceManager& resourceManager);
void addStrings(const cvf::Camera& camera);
void addString(const QString& str);
void draw(QPainter *painter, int widgetWidth, int widgetHeight);
private:
QStringList m_drawStrings; // The list of strings that will be drawn
};
}

View File

@@ -0,0 +1,117 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cvfBase.h"
#include "cvfqtUtils.h"
#include <QtCore/QVector>
namespace cvfqt {
//==================================================================================================
///
/// \class cvfqt::Utils
/// \ingroup GuiQt
///
/// Static helper class for Qt interop
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString Utils::toQString(const cvf::String& ceeString)
{
if (ceeString.isEmpty())
{
return QString();
}
if (sizeof(wchar_t) == 2)
{
const unsigned short* strPtr = reinterpret_cast<const unsigned short*>(ceeString.c_str());
return QString::fromUtf16(strPtr);
}
else if (sizeof(wchar_t) == 4)
{
const unsigned int* strPtr = reinterpret_cast<const unsigned int*>(ceeString.c_str());
return QString::fromUcs4(strPtr);
}
CVF_FAIL_MSG("Unexpected sizeof wchar_t");
return QString();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::String Utils::fromQString(const QString& qtString)
{
if (qtString.length() == 0)
{
return cvf::String();
}
if (sizeof(wchar_t) == 2)
{
const wchar_t* strPtr = reinterpret_cast<const wchar_t*>(qtString.utf16());
return cvf::String(strPtr);
}
else if (sizeof(wchar_t) == 4)
{
QVector<uint> ucs4Str = qtString.toUcs4();
ucs4Str.push_back(0);
const wchar_t* strPtr = reinterpret_cast<const wchar_t*>(ucs4Str.data());
return cvf::String(strPtr);
}
CVF_FAIL_MSG("Unexpected sizeof wchar_t");
return cvf::String();
}
} // namespace cvfqt

View File

@@ -0,0 +1,59 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include "cvfString.h"
#include <QtCore/QString>
namespace cvfqt {
//==================================================================================================
//
// Static helper class for Qt interop
//
//==================================================================================================
class Utils
{
public:
static QString toQString(const cvf::String& ceeString);
static cvf::String fromQString(const QString& qtString);
};
}