mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added QtMinimal and QtMinimal_GLWidget
This commit is contained in:
parent
0dccff3867
commit
ad2fd65804
@ -78,10 +78,12 @@ if (CEE_BUILD_TEST_APPS)
|
||||
add_subdirectory(Tests/SnippetsBasis)
|
||||
|
||||
if (CEE_BUILD_GUI_QT)
|
||||
add_subdirectory(TestApps/Qt/QtMinimal)
|
||||
|
||||
if (CEE_USE_QT5)
|
||||
add_subdirectory(TestApps/Qt/QtMinimal_GLWidget)
|
||||
add_subdirectory(TestApps/Qt/QtMinimal_deprecated)
|
||||
add_subdirectory(TestApps/Qt/QtMultiView_deprecated)
|
||||
add_subdirectory(TestApps/Qt/QtSnippetRunner)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
54
Fwk/VizFwk/TestApps/Qt/QtMinimal/CMakeLists.txt
Normal file
54
Fwk/VizFwk/TestApps/Qt/QtMinimal/CMakeLists.txt
Normal file
@ -0,0 +1,54 @@
|
||||
project(QtMinimal)
|
||||
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CEE_STANDARD_CXX_FLAGS}")
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long")
|
||||
endif()
|
||||
|
||||
|
||||
find_package(OpenGL)
|
||||
|
||||
if (CEE_USE_QT6)
|
||||
find_package(Qt6 COMPONENTS REQUIRED OpenGLWidgets)
|
||||
set(QT_LIBRARIES Qt6::OpenGLWidgets )
|
||||
elseif (CEE_USE_QT5)
|
||||
find_package(Qt5 REQUIRED COMPONENTS Widgets)
|
||||
set(QT_LIBRARIES Qt5::Widgets)
|
||||
else()
|
||||
message(FATAL_ERROR "No supported Qt version selected for build")
|
||||
endif()
|
||||
|
||||
|
||||
include_directories(${LibCore_SOURCE_DIR})
|
||||
include_directories(${LibGeometry_SOURCE_DIR})
|
||||
include_directories(${LibRender_SOURCE_DIR})
|
||||
include_directories(${LibViewing_SOURCE_DIR})
|
||||
include_directories(${LibGuiQt_SOURCE_DIR})
|
||||
|
||||
set(CEE_LIBS LibGuiQt LibViewing LibRender LibGeometry LibCore)
|
||||
|
||||
|
||||
set(CEE_CODE_FILES
|
||||
QMMain.cpp
|
||||
QMMainWindow.cpp
|
||||
QMMainWindow.h
|
||||
QMWidget.cpp
|
||||
QMWidget.h
|
||||
)
|
||||
|
||||
# Headers that need MOCing
|
||||
set(MOC_HEADER_FILES
|
||||
QMMainWindow.h
|
||||
)
|
||||
|
||||
if (CEE_USE_QT6)
|
||||
qt_wrap_cpp(MOC_SOURCE_FILES ${MOC_HEADER_FILES})
|
||||
elseif (CEE_USE_QT5)
|
||||
qt5_wrap_cpp(MOC_SOURCE_FILES ${MOC_HEADER_FILES})
|
||||
endif()
|
||||
|
||||
add_executable(${PROJECT_NAME} ${CEE_CODE_FILES} ${MOC_SOURCE_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} ${CEE_LIBS} ${OPENGL_LIBRARIES} ${QT_LIBRARIES})
|
||||
|
66
Fwk/VizFwk/TestApps/Qt/QtMinimal/QMMain.cpp
Normal file
66
Fwk/VizFwk/TestApps/Qt/QtMinimal/QMMain.cpp
Normal 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cvfLibCore.h"
|
||||
|
||||
#include "QMMainWindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
cvf::LogManager* logManager = cvf::LogManager::instance();
|
||||
logManager->logger("cee.cvf.OpenGL")->setLevel(cvf::Logger::LL_DEBUG);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// On Linux, Qt will use the system locale, force number formatting settings back to "C" locale
|
||||
setlocale(LC_NUMERIC,"C");
|
||||
|
||||
QMMainWindow window;
|
||||
QString platform = cvf::System::is64Bit() ? "(64bit)" : "(32bit)";
|
||||
window.setWindowTitle("Qt Minimal " + platform);
|
||||
window.resize(1000, 800);;
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
163
Fwk/VizFwk/TestApps/Qt/QtMinimal/QMMainWindow.cpp
Normal file
163
Fwk/VizFwk/TestApps/Qt/QtMinimal/QMMainWindow.cpp
Normal file
@ -0,0 +1,163 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// 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 "cvfLibCore.h"
|
||||
#include "cvfLibRender.h"
|
||||
#include "cvfLibGeometry.h"
|
||||
#include "cvfLibViewing.h"
|
||||
|
||||
#include "QMMainWindow.h"
|
||||
#include "QMWidget.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMMainWindow::QMMainWindow()
|
||||
{
|
||||
QFrame* mainFrame = new QFrame;
|
||||
QHBoxLayout* frameLayout = new QHBoxLayout(mainFrame);
|
||||
setCentralWidget(mainFrame);
|
||||
|
||||
m_contextGroup = new cvf::OpenGLContextGroup;
|
||||
|
||||
// Pass pointer to ourselves to get notified when the vizWidget is ready for use and we can load our default scene
|
||||
m_vizWidget = new QMWidget(m_contextGroup.p(), mainFrame, this);
|
||||
|
||||
m_vizWidget->setFocus();
|
||||
frameLayout->addWidget(m_vizWidget);
|
||||
|
||||
QMenu* menu = menuBar()->addMenu("&Scenes");
|
||||
menu->addAction("Default Scene", this, SLOT(slotCreateDefaultScene()));
|
||||
menu->addSeparator();
|
||||
menu->addAction("Clear Scene", this, SLOT(slotClearScene()));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMMainWindow::handleVizWidgetIsOpenGLReady()
|
||||
{
|
||||
slotCreateDefaultScene();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMMainWindow::slotCreateDefaultScene()
|
||||
{
|
||||
cvf::ref<cvf::ModelBasicList> model = new cvf::ModelBasicList;
|
||||
|
||||
const bool useShaders = true;
|
||||
|
||||
CVF_ASSERT(m_contextGroup->isContextGroupInitialized());
|
||||
cvf::ShaderProgramGenerator spGen("SimpleHeadlight", cvf::ShaderSourceProvider::instance());
|
||||
spGen.configureStandardHeadlightColor();
|
||||
cvf::ref<cvf::ShaderProgram> shaderProg = spGen.generate();
|
||||
|
||||
{
|
||||
cvf::GeometryBuilderDrawableGeo builder;
|
||||
cvf::GeometryUtils::createSphere(2, 10, 10, &builder);
|
||||
|
||||
cvf::ref<cvf::Effect> eff = new cvf::Effect;
|
||||
if (useShaders)
|
||||
{
|
||||
eff->setShaderProgram(shaderProg.p());
|
||||
eff->setUniform(new cvf::UniformFloat("u_color", cvf::Color4f(cvf::Color3::GREEN)));
|
||||
}
|
||||
else
|
||||
{
|
||||
eff->setRenderState(new cvf::RenderStateMaterial_FF(cvf::Color3::BLUE));
|
||||
}
|
||||
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("MySphere");
|
||||
part->setDrawable(0, builder.drawableGeo().p());
|
||||
part->setEffect(eff.p());
|
||||
|
||||
model->addPart(part.p());
|
||||
}
|
||||
|
||||
{
|
||||
cvf::GeometryBuilderDrawableGeo builder;
|
||||
cvf::GeometryUtils::createBox(cvf::Vec3f(5, 0, 0), 2, 3, 4, &builder);
|
||||
|
||||
cvf::ref<cvf::Effect> eff = new cvf::Effect;
|
||||
if (useShaders)
|
||||
{
|
||||
eff->setShaderProgram(shaderProg.p());
|
||||
eff->setUniform(new cvf::UniformFloat("u_color", cvf::Color4f(cvf::Color3::YELLOW)));
|
||||
}
|
||||
else
|
||||
{
|
||||
eff->setRenderState(new cvf::RenderStateMaterial_FF(cvf::Color3::RED));
|
||||
}
|
||||
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("MyBox");
|
||||
part->setDrawable(0, builder.drawableGeo().p());
|
||||
part->setEffect(eff.p());
|
||||
|
||||
model->addPart(part.p());
|
||||
}
|
||||
|
||||
model->updateBoundingBoxesRecursive();
|
||||
|
||||
cvf::ref<cvf::Scene> scene = new cvf::Scene;
|
||||
scene->addModel(model.p());
|
||||
|
||||
CVF_ASSERT(m_vizWidget);
|
||||
m_vizWidget->setScene(scene.p());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMMainWindow::slotClearScene()
|
||||
{
|
||||
CVF_ASSERT(m_vizWidget);
|
||||
m_vizWidget->setScene(NULL);
|
||||
}
|
||||
|
||||
|
71
Fwk/VizFwk/TestApps/Qt/QtMinimal/QMMainWindow.h
Normal file
71
Fwk/VizFwk/TestApps/Qt/QtMinimal/QMMainWindow.h
Normal file
@ -0,0 +1,71 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// 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 "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfOpenGLContextGroup.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QPointer>
|
||||
|
||||
class QMWidget;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class QMMainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QMMainWindow();
|
||||
|
||||
void handleVizWidgetIsOpenGLReady();
|
||||
|
||||
private slots:
|
||||
void slotCreateDefaultScene();
|
||||
void slotClearScene();
|
||||
|
||||
private:
|
||||
cvf::ref<cvf::OpenGLContextGroup> m_contextGroup;
|
||||
QPointer<QMWidget> m_vizWidget;
|
||||
};
|
||||
|
235
Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.cpp
Normal file
235
Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.cpp
Normal file
@ -0,0 +1,235 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// 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 "QMWidget.h"
|
||||
#include "QMMainWindow.h"
|
||||
|
||||
#include "cvfRendering.h"
|
||||
#include "cvfRenderSequence.h"
|
||||
#include "cvfScene.h"
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfManipulatorTrackball.h"
|
||||
#include "cvfOverlayAxisCross.h"
|
||||
#include "cvfFixedAtlasFont.h"
|
||||
#include "cvfRayIntersectSpec.h"
|
||||
#include "cvfHitItemCollection.h"
|
||||
#include "cvfHitItem.h"
|
||||
#include "cvfTrace.h"
|
||||
#include "cvfPart.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMWidget::QMWidget(cvf::OpenGLContextGroup* contextGroup, QWidget* parent, QMMainWindow* mainWindow)
|
||||
: cvfqt::OpenGLWidget(contextGroup, parent),
|
||||
m_mainWindow(mainWindow)
|
||||
{
|
||||
CVF_ASSERT(contextGroup);
|
||||
|
||||
m_camera = new cvf::Camera;
|
||||
|
||||
cvf::ref<cvf::Rendering> rendering = new cvf::Rendering;
|
||||
rendering->setCamera(m_camera.p());
|
||||
rendering->addOverlayItem(new cvf::OverlayAxisCross(m_camera.p(), new cvf::FixedAtlasFont(cvf::FixedAtlasFont::STANDARD)));
|
||||
|
||||
m_renderSequence = new cvf::RenderSequence;
|
||||
m_renderSequence->addRendering(rendering.p());
|
||||
|
||||
m_trackball = new cvf::ManipulatorTrackball;
|
||||
m_trackball->setCamera(m_camera.p());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMWidget::~QMWidget()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget::setScene(cvf::Scene* scene)
|
||||
{
|
||||
cvf::ref<cvf::Rendering> rendering = m_renderSequence->firstRendering();
|
||||
CVF_ASSERT(rendering.notNull());
|
||||
|
||||
rendering->setScene(scene);
|
||||
if (scene)
|
||||
{
|
||||
cvf::BoundingBox bb = scene->boundingBox();
|
||||
if (bb.isValid())
|
||||
{
|
||||
m_camera->fitView(bb, -cvf::Vec3d::Z_AXIS, cvf::Vec3d::Y_AXIS);
|
||||
m_trackball->setRotationPoint(bb.center());
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget::resizeGL(int w, int h)
|
||||
{
|
||||
if (m_camera.notNull())
|
||||
{
|
||||
m_camera->viewport()->set(0, 0, w, h);
|
||||
m_camera->setProjectionAsPerspective(m_camera->fieldOfViewYDeg(), m_camera->nearPlane(), m_camera->farPlane());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget::paintGL()
|
||||
{
|
||||
cvf::OpenGLContext* currentOglContext = cvfOpenGLContext();
|
||||
CVF_ASSERT(currentOglContext);
|
||||
|
||||
if (m_renderSequence.notNull())
|
||||
{
|
||||
m_renderSequence->render(currentOglContext);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
if (m_renderSequence.isNull()) return;
|
||||
|
||||
Qt::MouseButtons mouseBn = event->buttons();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
||||
const int posX = event->position().toPoint().x();
|
||||
const int posY = height() - event->position().toPoint().y();
|
||||
#else
|
||||
const int posX = event->x();
|
||||
const int posY = height() - event->y();
|
||||
#endif
|
||||
|
||||
cvf::ManipulatorTrackball::NavigationType navType = cvf::ManipulatorTrackball::NONE;
|
||||
if (mouseBn == Qt::LeftButton)
|
||||
{
|
||||
navType = cvf::ManipulatorTrackball::PAN;
|
||||
}
|
||||
else if (mouseBn == Qt::RightButton)
|
||||
{
|
||||
navType = cvf::ManipulatorTrackball::ROTATE;
|
||||
}
|
||||
else if (mouseBn == (Qt::LeftButton | Qt::RightButton) || mouseBn == Qt::MiddleButton)
|
||||
{
|
||||
navType = cvf::ManipulatorTrackball::WALK;
|
||||
}
|
||||
|
||||
if (navType != m_trackball->activeNavigation())
|
||||
{
|
||||
m_trackball->startNavigation(navType, posX, posY);
|
||||
}
|
||||
|
||||
bool needRedraw = m_trackball->updateNavigation(posX, posY);
|
||||
if (needRedraw)
|
||||
{
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
if (m_renderSequence.isNull()) return;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
||||
const int posX = event->position().toPoint().x();
|
||||
const int posY = height() - event->position().toPoint().y();
|
||||
#else
|
||||
const int posX = event->x();
|
||||
const int posY = height() - event->y();
|
||||
#endif
|
||||
|
||||
if (event->buttons() == Qt::LeftButton &&
|
||||
event->modifiers() == Qt::ControlModifier)
|
||||
{
|
||||
cvf::Rendering* r = m_renderSequence->firstRendering();
|
||||
cvf::ref<cvf::RayIntersectSpec> ris = r->rayIntersectSpecFromWindowCoordinates(posX, posY);
|
||||
|
||||
cvf::HitItemCollection hic;
|
||||
if (r->rayIntersect(*ris, &hic))
|
||||
{
|
||||
cvf::HitItem* item = hic.firstItem();
|
||||
CVF_ASSERT(item && item->part());
|
||||
|
||||
cvf::Vec3d isect = item->intersectionPoint();
|
||||
m_trackball->setRotationPoint(isect);
|
||||
|
||||
cvf::Trace::show("hitting part: '%s' coords: %.3f %.3f %.3f", item->part()->name().toAscii().ptr(), isect.x(), isect.y(), isect.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget::mouseReleaseEvent(QMouseEvent* /*event*/)
|
||||
{
|
||||
m_trackball->endNavigation();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget::onWidgetOpenGLReady()
|
||||
{
|
||||
if (m_mainWindow)
|
||||
{
|
||||
m_mainWindow->handleVizWidgetIsOpenGLReady();
|
||||
}
|
||||
}
|
83
Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.h
Normal file
83
Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.h
Normal file
@ -0,0 +1,83 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// 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 "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfRenderSequence.h"
|
||||
#include "cvfManipulatorTrackball.h"
|
||||
#include "cvfScene.h"
|
||||
#include "cvfOpenGLContextGroup.h"
|
||||
|
||||
#include "cvfqtOpenGLWidget.h"
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
class QMMainWindow;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class QMWidget : public cvfqt::OpenGLWidget
|
||||
{
|
||||
public:
|
||||
QMWidget(cvf::OpenGLContextGroup* contextGroup, QWidget* parent, QMMainWindow* mainWindow);
|
||||
~QMWidget();
|
||||
|
||||
void setScene(cvf::Scene* scene);
|
||||
|
||||
protected:
|
||||
virtual void resizeGL(int w, int h);
|
||||
virtual void paintGL();
|
||||
|
||||
virtual void mouseMoveEvent(QMouseEvent* event);
|
||||
virtual void mousePressEvent(QMouseEvent* event);
|
||||
virtual void mouseReleaseEvent(QMouseEvent* event);
|
||||
|
||||
private:
|
||||
virtual void onWidgetOpenGLReady();
|
||||
|
||||
private:
|
||||
QPointer<QMMainWindow> m_mainWindow;
|
||||
cvf::ref<cvf::RenderSequence> m_renderSequence;
|
||||
cvf::ref<cvf::Camera> m_camera;
|
||||
cvf::ref<cvf::ManipulatorTrackball> m_trackball;
|
||||
};
|
||||
|
47
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/CMakeLists.txt
Normal file
47
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/CMakeLists.txt
Normal file
@ -0,0 +1,47 @@
|
||||
project(QtMinimal_GLWidget)
|
||||
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CEE_STANDARD_CXX_FLAGS}")
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long")
|
||||
endif()
|
||||
|
||||
|
||||
find_package(OpenGL)
|
||||
|
||||
if (CEE_USE_QT5)
|
||||
find_package(Qt5 REQUIRED COMPONENTS Widgets OpenGL)
|
||||
set(QT_LIBRARIES Qt5::Widgets Qt5::OpenGL)
|
||||
else()
|
||||
message(FATAL_ERROR "No supported Qt version selected for build")
|
||||
endif()
|
||||
|
||||
|
||||
include_directories(${LibCore_SOURCE_DIR})
|
||||
include_directories(${LibGeometry_SOURCE_DIR})
|
||||
include_directories(${LibRender_SOURCE_DIR})
|
||||
include_directories(${LibViewing_SOURCE_DIR})
|
||||
include_directories(${LibGuiQt_SOURCE_DIR})
|
||||
|
||||
set(CEE_LIBS LibGuiQt LibViewing LibRender LibGeometry LibCore)
|
||||
|
||||
|
||||
set(CEE_SOURCE_FILES
|
||||
QMMain_GLW.cpp
|
||||
QMMainWindow_GLW.cpp
|
||||
QMWidget_GLW.cpp
|
||||
)
|
||||
|
||||
# Headers that need MOCing
|
||||
set(MOC_HEADER_FILES
|
||||
QMMainWindow_GLW.h
|
||||
QMWidget_GLW.h
|
||||
)
|
||||
|
||||
if (CEE_USE_QT5)
|
||||
qt5_wrap_cpp(MOC_SOURCE_FILES ${MOC_HEADER_FILES})
|
||||
endif()
|
||||
|
||||
add_executable(${PROJECT_NAME} ${CEE_SOURCE_FILES} ${MOC_SOURCE_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} ${CEE_LIBS} ${OPENGL_LIBRARIES} ${QT_LIBRARIES})
|
153
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/QMMainWindow_GLW.cpp
Normal file
153
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/QMMainWindow_GLW.cpp
Normal file
@ -0,0 +1,153 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// 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 "cvfLibCore.h"
|
||||
#include "cvfLibRender.h"
|
||||
#include "cvfLibGeometry.h"
|
||||
#include "cvfLibViewing.h"
|
||||
|
||||
#include "QMMainWindow_GLW.h"
|
||||
#include "QMWidget_GLW.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
|
||||
using cvf::ref;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMMainWindow_GLW::QMMainWindow_GLW()
|
||||
{
|
||||
QFrame* mainFrame = new QFrame;
|
||||
QHBoxLayout* frameLayout = new QHBoxLayout(mainFrame);
|
||||
setCentralWidget(mainFrame);
|
||||
|
||||
m_contextGroup = new cvf::OpenGLContextGroup;
|
||||
m_vizWidget = new QMWidget_GLW(m_contextGroup.p(), mainFrame);
|
||||
|
||||
m_vizWidget->setFocus();
|
||||
frameLayout->addWidget(m_vizWidget);
|
||||
|
||||
|
||||
m_createDefaultSceneAction = new QAction("Default Scene", this);
|
||||
m_clearSceneAction = new QAction("Clear Scene", this);
|
||||
connect(m_createDefaultSceneAction, SIGNAL(triggered()), SLOT(slotCreateDefaultScene()));
|
||||
connect(m_clearSceneAction, SIGNAL(triggered()), SLOT(slotClearScene()));
|
||||
|
||||
QMenu* menu = menuBar()->addMenu("&Scenes");
|
||||
menu->addAction(m_createDefaultSceneAction);
|
||||
menu->addSeparator();
|
||||
menu->addAction(m_clearSceneAction);
|
||||
|
||||
slotCreateDefaultScene();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMMainWindow_GLW::slotCreateDefaultScene()
|
||||
{
|
||||
ref<cvf::ModelBasicList> model = new cvf::ModelBasicList;
|
||||
|
||||
{
|
||||
cvf::GeometryBuilderDrawableGeo builder;
|
||||
cvf::GeometryUtils::createSphere(2, 10, 10, &builder);
|
||||
|
||||
ref<cvf::Effect> eff = new cvf::Effect;
|
||||
eff->setRenderState(new cvf::RenderStateMaterial_FF(cvf::Color3::BLUE));
|
||||
|
||||
ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("MySphere");
|
||||
part->setDrawable(0, builder.drawableGeo().p());
|
||||
part->setEffect(eff.p());
|
||||
|
||||
model->addPart(part.p());
|
||||
}
|
||||
|
||||
{
|
||||
cvf::GeometryBuilderDrawableGeo builder;
|
||||
cvf::GeometryUtils::createBox(cvf::Vec3f(5, 0, 0), 2, 3, 4, &builder);
|
||||
|
||||
ref<cvf::Effect> eff = new cvf::Effect;
|
||||
eff->setRenderState(new cvf::RenderStateMaterial_FF(cvf::Color3::RED));
|
||||
|
||||
ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("MyBox");
|
||||
part->setDrawable(0, builder.drawableGeo().p());
|
||||
part->setEffect(eff.p());
|
||||
|
||||
model->addPart(part.p());
|
||||
}
|
||||
|
||||
model->updateBoundingBoxesRecursive();
|
||||
|
||||
ref<cvf::Scene> scene = new cvf::Scene;
|
||||
scene->addModel(model.p());
|
||||
|
||||
CVF_ASSERT(m_vizWidget);
|
||||
m_vizWidget->setScene(scene.p());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMMainWindow_GLW::slotClearScene()
|
||||
{
|
||||
CVF_ASSERT(m_vizWidget);
|
||||
m_vizWidget->setScene(NULL);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMMainWindow_GLW::closeEvent(QCloseEvent* /*event*/)
|
||||
{
|
||||
CVF_ASSERT(m_contextGroup.notNull());
|
||||
CVF_ASSERT(m_vizWidget);
|
||||
|
||||
// Shut down the CeeViz OpenGL context contained in the widget
|
||||
// Deletes all OpenGL resources and removes context from context group
|
||||
m_vizWidget->cvfShutdownOpenGLContext();
|
||||
}
|
73
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/QMMainWindow_GLW.h
Normal file
73
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/QMMainWindow_GLW.h
Normal 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 "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfOpenGLContextGroup.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class QMWidget_GLW;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class QMMainWindow_GLW : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QMMainWindow_GLW();
|
||||
|
||||
private slots:
|
||||
void slotCreateDefaultScene();
|
||||
void slotClearScene();
|
||||
|
||||
private:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
|
||||
private:
|
||||
cvf::ref<cvf::OpenGLContextGroup> m_contextGroup;
|
||||
QMWidget_GLW* m_vizWidget;
|
||||
QAction* m_createDefaultSceneAction;
|
||||
QAction* m_clearSceneAction;
|
||||
};
|
||||
|
63
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/QMMain_GLW.cpp
Normal file
63
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/QMMain_GLW.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// 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 "cvfLibCore.h"
|
||||
|
||||
#include "QMMainWindow_GLW.h"
|
||||
|
||||
#include "QApplication"
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// On Linux, Qt will use the system locale, force number formatting settings back to "C" locale
|
||||
setlocale(LC_NUMERIC,"C");
|
||||
|
||||
QMMainWindow_GLW window;
|
||||
QString platform = cvf::System::is64Bit() ? "(64bit)" : "(32bit)";
|
||||
window.setWindowTitle("Qt Minimal GLWidget " + platform);
|
||||
window.resize(1000, 800);;
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
215
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/QMWidget_GLW.cpp
Normal file
215
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/QMWidget_GLW.cpp
Normal file
@ -0,0 +1,215 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// 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 "cvfLibCore.h"
|
||||
#include "cvfLibRender.h"
|
||||
#include "cvfLibGeometry.h"
|
||||
#include "cvfLibViewing.h"
|
||||
|
||||
#include "QMWidget_GLW.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
using cvf::ref;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMWidget_GLW::QMWidget_GLW(cvf::OpenGLContextGroup* contextGroup, QWidget* parent)
|
||||
: cvfqt::GLWidget(contextGroup, QGLFormat(), parent)
|
||||
{
|
||||
m_camera = new cvf::Camera;
|
||||
|
||||
ref<cvf::Rendering> rendering = new cvf::Rendering;
|
||||
rendering->setCamera(m_camera.p());
|
||||
rendering->addOverlayItem(new cvf::OverlayAxisCross(m_camera.p(), new cvf::FixedAtlasFont(cvf::FixedAtlasFont::STANDARD)));
|
||||
|
||||
m_renderSequence = new cvf::RenderSequence;
|
||||
m_renderSequence->addRendering(rendering.p());
|
||||
|
||||
m_trackball = new cvf::ManipulatorTrackball;
|
||||
m_trackball->setCamera(m_camera.p());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMWidget_GLW::~QMWidget_GLW()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget_GLW::setScene(cvf::Scene* scene)
|
||||
{
|
||||
ref<cvf::Rendering> rendering = m_renderSequence->firstRendering();
|
||||
CVF_ASSERT(rendering.notNull());
|
||||
|
||||
rendering->setScene(scene);
|
||||
|
||||
if (scene)
|
||||
{
|
||||
cvf::BoundingBox bb = scene->boundingBox();
|
||||
if (bb.isValid())
|
||||
{
|
||||
m_camera->fitView(bb, -cvf::Vec3d::Z_AXIS, cvf::Vec3d::Y_AXIS);
|
||||
m_trackball->setRotationPoint(bb.center());
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget_GLW::resizeGL(int width, int height)
|
||||
{
|
||||
if (m_camera.notNull())
|
||||
{
|
||||
m_camera->viewport()->set(0, 0, width, height);
|
||||
m_camera->setProjectionAsPerspective(m_camera->fieldOfViewYDeg(), m_camera->nearPlane(), m_camera->farPlane());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget_GLW::paintEvent(QPaintEvent* /*event*/)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
makeCurrent();
|
||||
|
||||
cvf::OpenGLContext* currentOglContext = cvfOpenGLContext();
|
||||
CVF_ASSERT(currentOglContext);
|
||||
CVF_CHECK_OGL(currentOglContext);
|
||||
|
||||
painter.beginNativePainting();
|
||||
|
||||
cvf::OpenGLUtils::pushOpenGLState(currentOglContext);
|
||||
|
||||
if (m_renderSequence.notNull())
|
||||
{
|
||||
m_renderSequence->render(currentOglContext);
|
||||
}
|
||||
|
||||
cvf::OpenGLUtils::popOpenGLState(currentOglContext);
|
||||
|
||||
painter.endNativePainting();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget_GLW::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
if (m_renderSequence.isNull()) return;
|
||||
|
||||
Qt::MouseButtons mouseBn = event->buttons();
|
||||
int posX = event->x();
|
||||
int posY = height() - event->y();
|
||||
|
||||
cvf::ManipulatorTrackball::NavigationType navType = cvf::ManipulatorTrackball::NONE;
|
||||
if (mouseBn == Qt::LeftButton)
|
||||
{
|
||||
navType = cvf::ManipulatorTrackball::PAN;
|
||||
}
|
||||
else if (mouseBn == Qt::RightButton)
|
||||
{
|
||||
navType = cvf::ManipulatorTrackball::ROTATE;
|
||||
}
|
||||
else if (mouseBn == (Qt::LeftButton | Qt::RightButton) || mouseBn == Qt::MiddleButton)
|
||||
{
|
||||
navType = cvf::ManipulatorTrackball::WALK;
|
||||
}
|
||||
|
||||
if (navType != m_trackball->activeNavigation())
|
||||
{
|
||||
m_trackball->startNavigation(navType, posX, posY);
|
||||
}
|
||||
|
||||
bool needRedraw = m_trackball->updateNavigation(posX, posY);
|
||||
if (needRedraw)
|
||||
{
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget_GLW::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
if (m_renderSequence.isNull()) return;
|
||||
|
||||
if (event->buttons() == Qt::LeftButton && event->modifiers() == Qt::ControlModifier)
|
||||
{
|
||||
cvf::Rendering* r = m_renderSequence->firstRendering();
|
||||
ref<cvf::RayIntersectSpec> ris = r->rayIntersectSpecFromWindowCoordinates(event->x(), height() - event->y());
|
||||
|
||||
cvf::HitItemCollection hic;
|
||||
if (r->rayIntersect(*ris, &hic))
|
||||
{
|
||||
cvf::HitItem* item = hic.firstItem();
|
||||
CVF_ASSERT(item && item->part());
|
||||
|
||||
cvf::Vec3d isect = item->intersectionPoint();
|
||||
m_trackball->setRotationPoint(isect);
|
||||
|
||||
cvf::Trace::show("hitting part: '%s' coords: %.3f %.3f %.3f", item->part()->name().toAscii().ptr(), isect.x(), isect.y(), isect.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMWidget_GLW::mouseReleaseEvent(QMouseEvent* /*event*/)
|
||||
{
|
||||
m_trackball->endNavigation();
|
||||
}
|
||||
|
79
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/QMWidget_GLW.h
Normal file
79
Fwk/VizFwk/TestApps/Qt/QtMinimal_GLWidget/QMWidget_GLW.h
Normal file
@ -0,0 +1,79 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// 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 "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfRenderSequence.h"
|
||||
#include "cvfManipulatorTrackball.h"
|
||||
#include "cvfScene.h"
|
||||
#include "cvfOpenGLContextGroup.h"
|
||||
|
||||
#include "cvfqtGLWidget.h"
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class QMWidget_GLW : public cvfqt::GLWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QMWidget_GLW(cvf::OpenGLContextGroup* contextGroup, QWidget* parent);
|
||||
~QMWidget_GLW();
|
||||
|
||||
void setScene(cvf::Scene* scene);
|
||||
|
||||
protected:
|
||||
void resizeGL(int width, int height);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
void mouseMoveEvent(QMouseEvent* event);
|
||||
void mouseReleaseEvent(QMouseEvent* event);
|
||||
|
||||
private:
|
||||
cvf::ref<cvf::RenderSequence> m_renderSequence;
|
||||
cvf::ref<cvf::Camera> m_camera;
|
||||
cvf::ref<cvf::ManipulatorTrackball> m_trackball;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user