From 495d160af7e75e0ffbb06690664ed23bc6193b2d Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Mon, 13 Apr 2015 17:42:20 +0200 Subject: [PATCH] wrong manip ?? --- Apps/Examples/mcmesh.cpp | 57 ++++- Apps/Examples/mcmesh.h | 7 + SCHNApps/src/view.cpp | 466 +++++++++++++++++++++++---------------- 3 files changed, 333 insertions(+), 197 deletions(-) diff --git a/Apps/Examples/mcmesh.cpp b/Apps/Examples/mcmesh.cpp index 566d7f9a1..d8d690a75 100644 --- a/Apps/Examples/mcmesh.cpp +++ b/Apps/Examples/mcmesh.cpp @@ -29,7 +29,8 @@ MCMesh::MCMesh() : m_drawFaces(true), m_render(NULL), m_flatShader(NULL), - m_simpleColorShader(NULL) + m_simpleColorShader(NULL), + m_linesShader(NULL) {} void MCMesh::initGUI() @@ -61,28 +62,69 @@ void MCMesh::cb_initGL() m_simpleColorShader = new Utils::ShaderSimpleColor(); m_simpleColorShader->setAttributePosition(m_positionVBO); + m_colorVBO = new Utils::VBO(); + m_linesShader = new Utils::ShaderBoldLines(); + m_linesShader->setAttributePosition(m_positionVBO); +// m_linesShader->setAttributeColor(m_colorVBO); + registerShader(m_flatShader); registerShader(m_simpleColorShader); + registerShader(m_linesShader); + + m_dr = new Utils::Drawer(); + m_dr->newList(); + m_dr->pointSize(4.0f); + m_dr->lineWidth(25.0f); + m_dr->begin(GL_LINES); + m_dr->color3f(1.0,0.0,0.0); + m_dr->vertex3f(15.0,15.0,65.0); + m_dr->vertex3f(110.0,110.0,65.0); + m_dr->color3f(0.0,1.0,0.0); + m_dr->vertex3f(110.0,15.0,75.0); + m_dr->vertex3f(15.0,110.0,75.0); + m_dr->end(); + m_dr->endList(); + } void MCMesh::cb_redraw() { +glEnable(GL_BLEND); + m_dr->callList(0.5f); if (m_drawEdges) +// { +// glLineWidth(1.0f); +// if (m_drawFaces) +// { +// Geom::Vec4f c(0.0f, 0.0f, 0.0f, 0.0f); +// m_simpleColorShader->setColor(c); +// } +// else +// { +// Geom::Vec4f c(1.0f, 1.0f, 0.0f, 0.0f); +// m_simpleColorShader->setColor(c); +// } +// m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES); +// } { - glLineWidth(1.0f); +// glLineWidth(1.0f); +// m_linesShader->setClippingPlane(Geom::Vec4f(0.03,0.03,-1.1,64)); + + m_linesShader->setLineWidth(12.0f); if (m_drawFaces) { Geom::Vec4f c(0.0f, 0.0f, 0.0f, 0.0f); - m_simpleColorShader->setColor(c); + m_linesShader->setColor(c); } else { Geom::Vec4f c(1.0f, 1.0f, 0.0f, 0.0f); - m_simpleColorShader->setColor(c); + m_linesShader->setColor(c); } - m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES); + m_render->draw(m_linesShader, Algo::Render::GL2::LINES); } + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_LIGHTING); glEnable(GL_POLYGON_OFFSET_FILL); @@ -158,6 +200,11 @@ void MCMesh::updateRender() m_render->initPrimitives(myMap, Algo::Render::GL2::TRIANGLES); m_positionVBO->updateData(position); + m_colorVBO->updateData(position); + Geom::Vec3f *ptr = reinterpret_cast(m_colorVBO->lockPtr()); + for (unsigned int i=0; inbElts();++i) + *ptr++ /= 130.0f; + m_colorVBO->releasePtr(); bb = Algo::Geometry::computeBoundingBox(myMap, position); diff --git a/Apps/Examples/mcmesh.h b/Apps/Examples/mcmesh.h index 848eba69f..7f0caaddc 100644 --- a/Apps/Examples/mcmesh.h +++ b/Apps/Examples/mcmesh.h @@ -39,9 +39,11 @@ #include "Algo/Render/GL2/mapRender.h" #include "Utils/Shaders/shaderFlat.h" #include "Utils/Shaders/shaderSimpleColor.h" +#include "Utils/Shaders/shaderBoldLines.h" #include "Utils/vbo.h" #include "Algo/Geometry/boundingbox.h" +#include "Utils/drawer.h" using namespace CGoGN ; @@ -79,9 +81,14 @@ public: Algo::Render::GL2::MapRender* m_render ; Utils::VBO* m_positionVBO ; + Utils::VBO* m_colorVBO ; Utils::ShaderFlat* m_flatShader ; Utils::ShaderSimpleColor* m_simpleColorShader ; + Utils::ShaderBoldLines* m_linesShader ; + + Utils::Drawer* m_dr; + DATATYPE valLabel; SAlgo::MC::Image* myImg; diff --git a/SCHNApps/src/view.cpp b/SCHNApps/src/view.cpp index 86e6b1c44..49441228a 100644 --- a/SCHNApps/src/view.cpp +++ b/SCHNApps/src/view.cpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace CGoGN { @@ -21,13 +22,15 @@ namespace SCHNApps { unsigned int View::viewCount = 0; -View::View(const QString& name, SCHNApps* s, QGLFormat& format) : - QGLViewer(format, NULL, NULL), + +View::View(const QString& name, SCHNApps* s, const QGLWidget* shareWidget) : + QGLViewer( NULL, shareWidget), b_updatingUI(false), m_name(name), m_schnapps(s), m_currentCamera(NULL), - m_lastSelectedMap(NULL), + m_bbMin(0.0, 0.0, 0.0), + m_bbMax(0.0, 0.0, 0.0), m_buttonArea(NULL), m_closeButton(NULL), m_VsplitButton(NULL), @@ -36,12 +39,19 @@ View::View(const QString& name, SCHNApps* s, QGLFormat& format) : m_mapsButton(NULL), m_pluginsButton(NULL), m_camerasButton(NULL), - m_dialogMaps(NULL) + m_dialogMaps(NULL), + m_dialogPlugins(NULL), + m_dialogCameras(NULL), + m_frameDrawer(NULL), + m_textureWallpaper(NULL), + m_shaderWallpaper(NULL), + b_saveSnapshots(false) { ++viewCount; - m_currentCamera = m_schnapps->addCamera(); - m_currentCamera->linkView(this); + setSnapshotFormat("BMP"); + setSnapshotFileName(m_name); + setSnapshotQuality(100); connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*,MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*,MapHandlerGen*))); @@ -49,8 +59,6 @@ View::View(const QString& name, SCHNApps* s, QGLFormat& format) : m_dialogPlugins = new ListPopUp("Enabled Plugins"); m_dialogCameras = new ListPopUp("Cameras"); -// setCurrentCamera(m_schnapps->addCamera()); - connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*))); connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*))); connect(m_dialogMaps->list(), SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(mapCheckStateChanged(QListWidgetItem*))); @@ -72,65 +80,11 @@ View::View(const QString& name, SCHNApps* s, QGLFormat& format) : foreach(Camera* cam, m_schnapps->getCameraSet().values()) cameraAdded(cam); - m_dialogCameras->check(m_currentCamera->getName(),Qt::Checked); -} - - - - - -View::View(const QString& name, SCHNApps* s, QGLFormat& format, const QGLWidget* shareWidget) : - QGLViewer(format, NULL, shareWidget), - b_updatingUI(false), - m_name(name), - m_schnapps(s), - m_currentCamera(NULL), - m_lastSelectedMap(NULL), - m_buttonArea(NULL), - m_closeButton(NULL), - m_VsplitButton(NULL), - m_HsplitButton(NULL), - m_buttonAreaLeft(NULL), - m_mapsButton(NULL), - m_pluginsButton(NULL), - m_camerasButton(NULL), - m_dialogMaps(NULL) -{ - ++viewCount; - m_currentCamera = m_schnapps->addCamera(); m_currentCamera->linkView(this); - - connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*,MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*,MapHandlerGen*))); - - m_dialogMaps = new ListPopUp("Linked Maps"); - m_dialogPlugins = new ListPopUp("Enabled Plugins"); - m_dialogCameras = new ListPopUp("Cameras"); - -// setCurrentCamera(m_schnapps->addCamera()); - - connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*))); - connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*))); - connect(m_dialogMaps->list(), SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(mapCheckStateChanged(QListWidgetItem*))); - - foreach(MapHandlerGen* map, m_schnapps->getMapSet().values()) - mapAdded(map); - - connect(m_schnapps, SIGNAL(pluginEnabled(Plugin*)), this, SLOT(pluginEnabled(Plugin*))); - connect(m_schnapps, SIGNAL(pluginDisabled(Plugin*)), this, SLOT(pluginDisabled(Plugin*))); - connect(m_dialogPlugins->list(), SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(pluginCheckStateChanged(QListWidgetItem*))); - - foreach(Plugin* plug, m_schnapps->getPluginSet().values()) - pluginEnabled(plug); - - connect(m_schnapps, SIGNAL(cameraAdded(Camera*)), this, SLOT(cameraAdded(Camera*))); - connect(m_schnapps, SIGNAL(cameraRemoved(Camera*)), this, SLOT(cameraRemoved(Camera*))); - connect(m_dialogCameras->list(), SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(cameraCheckStateChanged(QListWidgetItem*))); - - foreach(Camera* cam, m_schnapps->getCameraSet().values()) - cameraAdded(cam); - m_dialogCameras->check(m_currentCamera->getName(),Qt::Checked); + + connect(m_schnapps, SIGNAL(schnappsClosing()), this, SLOT(closeDialogs())); } View::~View() @@ -139,14 +93,12 @@ View::~View() this->setCamera(c); m_currentCamera->unlinkView(this); - foreach(PluginInteraction* p, l_plugins) unlinkPlugin(p); foreach(MapHandlerGen* m, l_maps) unlinkMap(m); - delete m_buttonArea; delete m_buttonAreaLeft; @@ -155,18 +107,16 @@ View::~View() delete m_dialogCameras; } -void View::closeDialogs() -{ - m_dialogMaps->close(); - m_dialogPlugins->close(); - m_dialogCameras->close(); -} - void View::setCurrentCamera(Camera* c) { // DEBUG_SLOT(); - if(c != m_currentCamera && c != NULL) + if(c != m_currentCamera && c) { + // RECORDING + QTextStream* rec = m_schnapps->pythonStreamRecorder(); + if (rec) + *rec << this->getName() << ".setCurrentCamera(\"" << c->getName() << "\");" << endl; + Camera* prev = m_currentCamera; if(prev) prev->unlinkView(this); @@ -175,10 +125,10 @@ void View::setCurrentCamera(Camera* c) this->setCamera(m_currentCamera); m_currentCamera->linkView(this); -// DEBUG_EMIT("currentCameraChanged"); -// emit(currentCameraChanged(prev, c)); + DEBUG_EMIT("currentCameraChanged"); + emit(currentCameraChanged(prev, c)); - if(prev) + if (prev) { QListWidgetItem* prevItem = m_dialogCameras->findItem(prev->getName()); if(prevItem) @@ -188,7 +138,8 @@ void View::setCurrentCamera(Camera* c) b_updatingUI = false; } } - if(m_currentCamera) + + if (m_currentCamera) { QListWidgetItem* curItem = m_dialogCameras->findItem(m_currentCamera->getName()); if(curItem) @@ -199,12 +150,7 @@ void View::setCurrentCamera(Camera* c) } } -// b_updatingUI = true; -// m_dialogCameras->check(c->getName(),Qt::Checked); -// b_updatingUI = false; - -// updateCurrentCameraBB(); - m_currentCamera->updateParams(); + m_currentCamera->fitToViewsBoundingBox(); updateGL(); } } @@ -216,23 +162,32 @@ void View::setCurrentCamera(const QString& name) setCurrentCamera(c); } -bool View::usesCamera(const QString& cameraName) const +bool View::usesCamera(const QString& name) const { - return m_currentCamera->getName() == cameraName; + Camera* c = m_schnapps->getCamera(name); + return usesCamera(c); } + + void View::linkPlugin(PluginInteraction* plugin) { + // RECORDING + QTextStream* rec = m_schnapps->pythonStreamRecorder(); + if (rec) + *rec << this->getName() << ".linkPlugin(\"" << plugin->getName() << "\");" << endl; + DEBUG_SLOT(); if(plugin && !l_plugins.contains(plugin)) { l_plugins.push_back(plugin); plugin->linkView(this); + DEBUG_EMIT("pluginLinked"); emit(pluginLinked(plugin)); b_updatingUI = true; - m_dialogPlugins->check(plugin->getName(),Qt::Checked); + m_dialogPlugins->check(plugin->getName(), Qt::Checked); b_updatingUI = false; updateGL(); @@ -251,12 +206,19 @@ void View::unlinkPlugin(PluginInteraction* plugin) DEBUG_SLOT(); if(l_plugins.removeOne(plugin)) { + // RECORDING + QTextStream* rec = m_schnapps->pythonStreamRecorder(); + if (rec) + *rec << this->getName() << ".unlinkPlugin(\"" << plugin->getName() << "\");" << endl; + + plugin->unlinkView(this); + DEBUG_EMIT("pluginUnlinked"); emit(pluginUnlinked(plugin)); b_updatingUI = true; - m_dialogPlugins->check(plugin->getName(),Qt::Unchecked); + m_dialogPlugins->check(plugin->getName(), Qt::Unchecked); b_updatingUI = false; updateGL(); @@ -278,27 +240,30 @@ bool View::isLinkedToPlugin(const QString& name) const void View::linkMap(MapHandlerGen* map) { + // RECORDING + QTextStream* rec = m_schnapps->pythonStreamRecorder(); + if (rec) + *rec << this->getName() << ".linkMap(\"" << map->getName() << "\");" << endl; + DEBUG_SLOT(); if(map && !l_maps.contains(map)) { l_maps.push_back(map); map->linkView(this); + DEBUG_EMIT("mapLinked"); emit(mapLinked(map)); - std::cout << "View::linkMap Maps:"<getName().toStdString()<< std::endl; - m_currentCamera->updateParams(); - updateGL(); - -// connect(map->getFrame(), SIGNAL(modified()), this, SLOT(updateGL())); -// connect(map->getFrame(), SIGNAL(modified()), m_currentCamera, SLOT(BBModified(map))); connect(map, SIGNAL(selectedCellsChanged(CellSelectorGen*)), this, SLOT(updateGL())); + connect(map, SIGNAL(boundingBoxModified()), this, SLOT(updateBoundingBox())); if(map->isSelectedMap()) setManipulatedFrame(map->getFrame()); + updateBoundingBox(); + b_updatingUI = true; - m_dialogMaps->check(map->getName(),Qt::Checked); + m_dialogMaps->check(map->getName(), Qt::Checked); b_updatingUI = false; } } @@ -315,24 +280,27 @@ void View::unlinkMap(MapHandlerGen* map) DEBUG_SLOT(); if(l_maps.removeOne(map)) { + QTextStream* rec = m_schnapps->pythonStreamRecorder(); + if (rec) + *rec << this->getName() << ".unlinkMap(\"" << map->getName() << "\");" << endl; + + map->unlinkView(this); + DEBUG_EMIT("mapUnlinked"); emit(mapUnlinked(map)); -// updateCurrentCameraBB(); - m_currentCamera->updateParams(); - updateGL(); - - disconnect(map->getFrame(), SIGNAL(modified()), this, SLOT(updateGL())); disconnect(map, SIGNAL(selectedCellsChanged(CellSelectorGen*)), this, SLOT(updateGL())); + disconnect(map, SIGNAL(boundingBoxModified()), this, SLOT(updateBoundingBox())); if(map == m_schnapps->getSelectedMap()) setManipulatedFrame(NULL); + updateBoundingBox(); + b_updatingUI = true; - m_dialogMaps->check(map->getName(),Qt::Unchecked); + m_dialogMaps->check(map->getName(), Qt::Unchecked); b_updatingUI = false; - } } @@ -349,21 +317,20 @@ bool View::isLinkedToMap(const QString& name) const return l_maps.contains(m); } + + + + void View::init() { glewExperimental = GL_TRUE; // needed for GL Core Profile 3.3 glewInit(); -// int major = 0; -// int minor = 0; -// glGetIntegerv(GL_MAJOR_VERSION, &major); -// glGetIntegerv(GL_MINOR_VERSION, &minor); -// std::cout << this->getName().toStdString() << "is using GL "<< major <<"."<< minor << std::endl; - + std::cout << "using " << glGetString(GL_VERSION) << std::endl; qglviewer::Camera* c = this->camera(); this->setCamera(m_currentCamera); - delete c; +// delete c; this->setBackgroundColor(QColor(0,0,0)); glEnable(GL_DEPTH_TEST); @@ -387,7 +354,6 @@ void View::init() m_buttonAreaLeft = new ViewButtonArea(this); m_buttonAreaLeft->setTopLeftPosition(0, 0); - m_mapsButton = new ViewButton(":icons/icons/maps.png", this); m_buttonAreaLeft->addButton(m_mapsButton); connect(m_mapsButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(ui_mapsListView(int, int, int, int))); @@ -400,17 +366,17 @@ void View::init() m_buttonAreaLeft->addButton(m_camerasButton); connect(m_camerasButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(ui_camerasListView(int, int, int, int))); - // FRAME DRAWER m_frameDrawer = new Utils::Drawer(); glm::mat4 mm(1.0); glm::mat4 pm(1.0); - m_frameDrawer->getShader()->updateMatrices(mm, pm); +// m_frameDrawer->getShader()->updateMatrices(mm, pm); + m_frameDrawer->updateMatrices(mm, pm); m_frameDrawer->newList(GL_COMPILE); m_frameDrawer->color3f(0.0f,1.0f,0.0f); - m_frameDrawer->lineWidth(4.0f); + m_frameDrawer->lineWidth(6.0f); m_frameDrawer->begin(GL_LINE_LOOP); m_frameDrawer->vertex3f(-1.0f,-1.0f, 0.0f); m_frameDrawer->vertex3f( 1.0f,-1.0f, 0.0f); @@ -419,18 +385,32 @@ void View::init() m_frameDrawer->end(); m_frameDrawer->endList(); - std::cout << "end INIT of "<< this->getName().toStdString()<< std::endl; + // WALLPAPER -// qglviewer::Camera* c = this->camera(); -// this->setCamera(m_currentCamera); -// delete c; + m_textureWallpaper = new Utils::Texture<2, Geom::Vec3uc>(GL_UNSIGNED_BYTE); + m_textureWallpaper->create(Geom::Vec2ui(16, 16)); + const float max = m_textureWallpaper->size()[0]; + for (unsigned int ki = 0; ki < m_textureWallpaper->size()[0]; ++ki) + { + for (unsigned int kj = 0; kj < m_textureWallpaper->size()[1]; ++kj) + { + float col = 255 - (255 * ((kj/max)*0.6 + 0.2)); + (*m_textureWallpaper)(ki, kj) = Geom::Vec3f(col, col, col); + } + } + m_textureWallpaper->update(); + m_textureWallpaper->setWrapping(GL_CLAMP_TO_EDGE); + + m_shaderWallpaper = new Utils::ShaderWallPaper(); + m_shaderWallpaper->setTextureUnit(GL_TEXTURE0); + m_shaderWallpaper->setTexture(m_textureWallpaper); this->setBackgroundColor(QColor(0,0,0)); } void View::preDraw() { - if (Utils::GLSLShader::CURRENT_OGL_VERSION>=3) + if (Utils::GLSLShader::CURRENT_OGL_VERSION >= 3) makeCurrent(); m_currentCamera->setScreenWidthAndHeight(width(), height()); @@ -439,27 +419,26 @@ void View::preDraw() void View::draw() { - if (Utils::GLSLShader::CURRENT_OGL_VERSION>=3) + if (Utils::GLSLShader::CURRENT_OGL_VERSION >= 3) { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); } + m_shaderWallpaper->draw(); + const CameraSet& cams = m_schnapps->getCameraSet(); QList lc = cams.values(); - foreach(Camera* camera, lc) + foreach (Camera* camera, lc) { - if(camera != m_currentCamera) + if (camera != m_currentCamera) { - if(camera->getDraw()) camera->draw(); - if(camera->getDrawPath()) camera->drawAllPaths(); + if (camera->getDraw()) camera->draw(); + if (camera->getDrawPath()) camera->drawAllPaths(); } } -// for debugging -// m_currentCamera->drawBBCam(); - glm::mat4 mm = getCurrentModelViewMatrix(); glm::mat4 pm = getCurrentProjectionMatrix(); @@ -471,9 +450,9 @@ void View::draw() if(map == selectedMap) { - Utils::GLSLShader* bbShader = map->getBBDrawerShader(); - if(bbShader) - bbShader->updateMatrices(pm, map_mm); + Utils::Drawer* bbDr = map->getBBDrawer(); + if(bbDr) + bbDr->updateMatrices(pm, map_mm); map->drawBB(); } @@ -500,8 +479,9 @@ void View::postDraw() void View::resizeGL(int width, int height) { QGLViewer::resizeGL(width, height); + if(m_buttonArea) - m_buttonArea->setTopRightPosition(width, 0); + m_buttonArea->setTopRightPosition(width/ this->pixelRatio(), 0); if(m_buttonAreaLeft) m_buttonAreaLeft->setTopLeftPosition(0, 0); @@ -522,9 +502,51 @@ void View::drawFrame() void View::keyPressEvent(QKeyEvent* event) { - foreach(PluginInteraction* plugin, l_plugins) - plugin->keyPress(this, event); - QGLViewer::keyPressEvent(event); + if (event->key() == Qt::Key_S) + { + b_saveSnapshots = !b_saveSnapshots; + + if (b_saveSnapshots) + { + QMessageBox msgBox; + msgBox.setText("Snapshot every frame?"); + msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Ok); + if (msgBox.exec() == QMessageBox::Ok) + { + m_schnapps->statusBarMessage("frame snapshot !!", 2000); + connect(this, SIGNAL(drawFinished(bool)), this, SLOT(saveSnapshot(bool))); + } + else + { + m_schnapps->statusBarMessage("cancel frame snapshot", 2000); + b_saveSnapshots = false; + } + } + else + { + disconnect(this, SIGNAL(drawFinished(bool)), this, SLOT(saveSnapshot(bool))); + m_schnapps->statusBarMessage("Stop frame snapshot", 2000); + } + + } + else + { + foreach(PluginInteraction* plugin, l_plugins) + plugin->keyPress(this, event); + + if (event->key() == Qt::Key_Escape) + { + QMessageBox msgBox; + msgBox.setText("Really quit SCHNApps ?"); + msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Ok); + if (msgBox.exec() == QMessageBox::Ok) + m_schnapps->close(); + } + else + QGLViewer::keyPressEvent(event); + } } void View::keyReleaseEvent(QKeyEvent *event) @@ -536,17 +558,23 @@ void View::keyReleaseEvent(QKeyEvent *event) void View::mousePressEvent(QMouseEvent* event) { - if(m_buttonArea->isClicked(event->x(), event->y())) - m_buttonArea->clickButton(event->x(), event->y(), event->globalX(), event->globalY()); - else if(m_buttonAreaLeft->isClicked(event->x(), event->y())) + if (!isSelectedView()) + m_schnapps->setSelectedView(this); + + if (m_buttonAreaLeft->isClicked(event->x(), event->y())) m_buttonAreaLeft->clickButton(event->x(), event->y(), event->globalX(), event->globalY()); else { - if(!isSelectedView()) - m_schnapps->setSelectedView(this); - foreach(PluginInteraction* plugin, l_plugins) - plugin->mousePress(this, event); - QGLViewer::mousePressEvent(event); + hideDialogs(); + if (m_buttonArea->isClicked(event->x(), event->y())) + m_buttonArea->clickButton(event->x(), event->y(), event->globalX(), event->globalY()); + else + { + foreach(PluginInteraction* plugin, l_plugins) + plugin->mousePress(this, event); + + QGLViewer::mousePressEvent(event); + } } } @@ -611,6 +639,27 @@ glm::mat4 View::getCurrentModelViewProjectionMatrix() const } + + + +void View::closeDialogs() +{ + m_dialogMaps->close(); + m_dialogPlugins->close(); + m_dialogCameras->close(); +} + +void View::hideDialogs() +{ + if (m_dialogCameras->isVisible()) + m_dialogCameras->hide(); + if (m_dialogMaps->isVisible()) + m_dialogMaps->hide(); + if (m_dialogPlugins->isVisible()) + m_dialogPlugins->hide(); +} + + void View::selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur) { DEBUG_SLOT(); @@ -619,18 +668,17 @@ void View::selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur) updateGL(); } - -void View::ui_verticalSplitView(int x, int y, int globalX, int globalY) +void View::ui_verticalSplitView(int x, int y, int /*globalX*/, int /*globalY*/) { m_schnapps->splitView(m_name, Qt::Horizontal); } -void View::ui_horizontalSplitView(int x, int y, int globalX, int globalY) +void View::ui_horizontalSplitView(int x, int y, int /*globalX*/, int /*globalY*/) { m_schnapps->splitView(m_name, Qt::Vertical); } -void View::ui_closeView(int x, int y, int globalX, int globalY) +void View::ui_closeView(int x, int y, int /*globalX*/, int /*globalY*/) { m_schnapps->removeView(m_name); } @@ -645,11 +693,12 @@ void View::ui_mapsListView(int x, int y, int globalX, int globalY) m_dialogPlugins->hide(); } else + { m_dialogMaps->hide(); + } } - void View::ui_pluginsListView(int x, int y, int globalX, int globalY) { if (m_dialogPlugins->isHidden()) @@ -660,8 +709,9 @@ void View::ui_pluginsListView(int x, int y, int globalX, int globalY) m_dialogCameras->hide(); } else + { m_dialogPlugins->hide(); - + } } void View::ui_camerasListView(int x, int y, int globalX, int globalY) @@ -674,105 +724,137 @@ void View::ui_camerasListView(int x, int y, int globalX, int globalY) m_dialogMaps->hide(); } else + { m_dialogCameras->hide(); - + } } -void View::mapAdded(MapHandlerGen* mh ) +void View::mapAdded(MapHandlerGen* mh) { DEBUG_SLOT(); if (mh) - { m_dialogMaps->addItem(mh->getName()); - } } -void View::mapRemoved(MapHandlerGen* mh ) +void View::mapRemoved(MapHandlerGen* mh) { DEBUG_SLOT(); if (mh) - { m_dialogMaps->removeItem(mh->getName()); - } } +void View::mapCheckStateChanged(QListWidgetItem* item) +{ + if (!b_updatingUI) + { + DEBUG_SLOT(); + if (item->checkState() == Qt::Checked) + linkMap(item->text()); + else + unlinkMap(item->text()); + } +} void View::pluginEnabled(Plugin *plugin) { DEBUG_SLOT(); if (dynamic_cast(plugin)) - { m_dialogPlugins->addItem(plugin->getName()); - } - } void View::pluginDisabled(Plugin *plugin) { DEBUG_SLOT(); if (dynamic_cast(plugin)) - { m_dialogPlugins->removeItem(plugin->getName()); - } } +void View::pluginCheckStateChanged(QListWidgetItem* item) +{ + if (!b_updatingUI) + { + DEBUG_SLOT(); + if (item->checkState() == Qt::Checked) + linkPlugin(item->text()); + else + unlinkPlugin(item->text()); + } +} void View::cameraAdded(Camera* camera) { DEBUG_SLOT(); if (camera) - { m_dialogCameras->addItem(camera->getName()); - } } void View::cameraRemoved(Camera* camera) { DEBUG_SLOT(); if (camera) - { m_dialogCameras->removeItem(camera->getName()); - } } -void View::mapCheckStateChanged(QListWidgetItem* item) +void View::cameraCheckStateChanged(QListWidgetItem* item) { - if (b_updatingUI) - return; - - DEBUG_SLOT(); - - if (item->checkState()==Qt::Checked) - linkMap(item->text()); - else - unlinkMap(item->text()); - - + if (!b_updatingUI) + { + DEBUG_SLOT(); + if (item->checkState() == Qt::Checked) + setCurrentCamera(item->text()); + } } -void View::pluginCheckStateChanged(QListWidgetItem* item) +void View::updateBoundingBox() { - if (b_updatingUI) - return; + if (!l_maps.empty()) + { + bool initialized = false; - DEBUG_SLOT(); - if (item->checkState()==Qt::Checked) - linkPlugin(item->text()); - else - unlinkPlugin(item->text()); -} + foreach (MapHandlerGen* mhg, l_maps) + { + qglviewer::Vec minbb; + qglviewer::Vec maxbb; + if (mhg->transformedBB(minbb, maxbb)) + { + if (initialized) + { + for (unsigned int dim = 0; dim < 3; ++dim) + { + if (minbb[dim] < m_bbMin[dim]) + m_bbMin[dim] = minbb[dim]; + if (maxbb[dim] > m_bbMax[dim]) + m_bbMax[dim] = maxbb[dim]; + } + } + else + { + for (unsigned int dim = 0; dim < 3; ++dim) + { + m_bbMin[dim] = minbb[dim]; + m_bbMax[dim] = maxbb[dim]; + } + initialized = true; + } + } + } -void View::cameraCheckStateChanged(QListWidgetItem* item) -{ - if (b_updatingUI) - return; + if (!initialized) + { + m_bbMin.setValue(0, 0, 0); + m_bbMax.setValue(0, 0, 0); + } + } + else + { + m_bbMin.setValue(0, 0, 0); + m_bbMax.setValue(0, 0, 0); + } - DEBUG_SLOT(); - if (item->checkState()==Qt::Checked) - setCurrentCamera(item->text()); + DEBUG_EMIT("View::boundingBoxChanged"); + emit(boundingBoxChanged()); } - } // namespace SCHNApps } // namespace CGoGN -- GitLab