diff --git a/src/CGALRenderer.h b/src/CGALRenderer.h index 1442b80e..5a5b3ac6 100644 --- a/src/CGALRenderer.h +++ b/src/CGALRenderer.h @@ -6,9 +6,9 @@ class CGALRenderer : public Renderer { public: CGALRenderer(shared_ptr geom); - ~CGALRenderer(); - void draw(bool showfaces, bool showedges) const; - BoundingBox getBoundingBox() const; + virtual ~CGALRenderer(); + virtual void draw(bool showfaces, bool showedges) const; + virtual BoundingBox getBoundingBox() const; public: shared_ptr polyhedron; diff --git a/src/Camera.h b/src/Camera.h index 63896187..dad092aa 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -28,7 +28,7 @@ public: Camera(enum CameraType camtype = NONE); void setup(std::vector params); void gimbalDefaultTranslate(); - void viewAll(const BoundingBox &bbox, float scalefactor); + void viewAll(const BoundingBox &bbox, float scalefactor = 1.0f); // Vectorcam Eigen::Vector3d eye; diff --git a/src/GLView.cc b/src/GLView.cc index 92dfeee3..81a2f29a 100644 --- a/src/GLView.cc +++ b/src/GLView.cc @@ -3,6 +3,7 @@ #include "stdio.h" #include "rendersettings.h" #include "mathc99.h" +#include "renderer.h" #ifdef _WIN32 #include diff --git a/src/GLView.h b/src/GLView.h index 52891455..83559aff 100644 --- a/src/GLView.h +++ b/src/GLView.h @@ -25,14 +25,14 @@ Some actions (showCrossHairs) only work properly on Gimbal Camera. #endif #include "system-gl.h" #include -#include "renderer.h" #include "Camera.h" class GLView { public: GLView(); - void setRenderer(Renderer* r); + void setRenderer(class Renderer* r); + Renderer *getRenderer() const { return this->renderer; } void initializeGL(); void resizeGL(int w, int h); diff --git a/src/MainWindow.h b/src/MainWindow.h index 71eadc15..af347b1f 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -203,6 +203,7 @@ public slots: void viewPerspective(); void viewOrthogonal(); void viewResetView(); + void viewAll(); void hideConsole(); void animateUpdateDocChanged(); void animateUpdate(); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index cdcf6fb7..31d6d49a 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -120,7 +120,7 @@ 0 0 936 - 34 + 22 @@ -234,6 +234,7 @@ + @@ -961,6 +962,11 @@ Ctrl+[ + + + View All + + diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc index c56dad13..0c1aa4e0 100644 --- a/src/OpenCSGRenderer.cc +++ b/src/OpenCSGRenderer.cc @@ -147,3 +147,10 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo, } std::for_each(primitives.begin(), primitives.end(), del_fun()); } + +BoundingBox OpenCSGRenderer::getBoundingBox() const +{ + BoundingBox bbox; + if (this->root_chain) bbox = this->root_chain->getBoundingBox(); + return bbox; +} diff --git a/src/OpenCSGRenderer.h b/src/OpenCSGRenderer.h index cca7161d..421a43e6 100644 --- a/src/OpenCSGRenderer.h +++ b/src/OpenCSGRenderer.h @@ -8,7 +8,8 @@ class OpenCSGRenderer : public Renderer public: OpenCSGRenderer(class CSGChain *root_chain, CSGChain *highlights_chain, CSGChain *background_chain, GLint *shaderinfo); - void draw(bool showfaces, bool showedges) const; + virtual void draw(bool showfaces, bool showedges) const; + virtual BoundingBox getBoundingBox() const; private: void renderCSGChain(class CSGChain *chain, GLint *shaderinfo, bool highlight, bool background) const; diff --git a/src/QGLView.cc b/src/QGLView.cc index 43bd855e..376c1ff0 100644 --- a/src/QGLView.cc +++ b/src/QGLView.cc @@ -88,6 +88,15 @@ void QGLView::resetView() cam.viewer_distance = 140; } +void QGLView::viewAll() +{ + if (Renderer *r = this->getRenderer()) { + BoundingBox bbox = r->getBoundingBox(); + cam.object_trans = -bbox.center(); + cam.viewAll(r->getBoundingBox()); + } +} + void QGLView::initializeGL() { GLenum err = glewInit(); diff --git a/src/QGLView.h b/src/QGLView.h index e06f5a79..25d6a90d 100644 --- a/src/QGLView.h +++ b/src/QGLView.h @@ -44,6 +44,7 @@ public: #endif bool save(const char *filename); void resetView(); + void viewAll(); public slots: void ZoomIn(void); diff --git a/src/ThrownTogetherRenderer.cc b/src/ThrownTogetherRenderer.cc index 84425883..d95e7afe 100644 --- a/src/ThrownTogetherRenderer.cc +++ b/src/ThrownTogetherRenderer.cc @@ -123,3 +123,10 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight, glPopMatrix(); } } + +BoundingBox ThrownTogetherRenderer::getBoundingBox() const +{ + BoundingBox bbox; + if (this->root_chain) bbox = this->root_chain->getBoundingBox(); + return bbox; +} diff --git a/src/ThrownTogetherRenderer.h b/src/ThrownTogetherRenderer.h index 7933f5b6..5db60fc8 100644 --- a/src/ThrownTogetherRenderer.h +++ b/src/ThrownTogetherRenderer.h @@ -7,7 +7,8 @@ class ThrownTogetherRenderer : public Renderer public: ThrownTogetherRenderer(class CSGChain *root_chain, CSGChain *highlights_chain, CSGChain *background_chain); - void draw(bool showfaces, bool showedges) const; + virtual void draw(bool showfaces, bool showedges) const; + virtual BoundingBox getBoundingBox() const; private: void renderCSGChain(CSGChain *chain, bool highlight, bool background, bool showedges, bool fberror) const; diff --git a/src/export_png.cc b/src/export_png.cc index cccc8b6d..a0b8aff6 100644 --- a/src/export_png.cc +++ b/src/export_png.cc @@ -68,11 +68,6 @@ void export_png_preview_common(Tree &tree, Camera &cam, std::ostream &output, Pr #endif ThrownTogetherRenderer thrownTogetherRenderer(csgInfo.root_chain, csgInfo.highlights_chain, csgInfo.background_chain); - BoundingBox bbox; - if (csgInfo.root_chain) bbox = csgInfo.root_chain->getBoundingBox(); - setupCamera(cam, bbox, 2.7); - - csgInfo.glview->setCamera(cam); #ifdef ENABLE_OPENCSG if (previewer == OPENCSG) csgInfo.glview->setRenderer(&openCSGRenderer); @@ -80,6 +75,10 @@ void export_png_preview_common(Tree &tree, Camera &cam, std::ostream &output, Pr #endif csgInfo.glview->setRenderer(&thrownTogetherRenderer); #ifdef ENABLE_OPENCSG + BoundingBox bbox = csgInfo.glview->getRenderer()->getBoundingBox(); + setupCamera(cam, bbox, 2.7); + + csgInfo.glview->setCamera(cam); OpenCSG::setContext(0); OpenCSG::setOption(OpenCSG::OffscreenSetting, OpenCSG::FrameBufferObject); #endif diff --git a/src/mainwin.cc b/src/mainwin.cc index d56177fa..3f8fe223 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -372,6 +372,7 @@ MainWindow::MainWindow(const QString &filename) connect(this->viewActionDiagonal, SIGNAL(triggered()), this, SLOT(viewAngleDiagonal())); connect(this->viewActionCenter, SIGNAL(triggered()), this, SLOT(viewCenter())); connect(this->viewActionResetView, SIGNAL(triggered()), this, SLOT(viewResetView())); + connect(this->viewActionViewAll, SIGNAL(triggered()), this, SLOT(viewAll())); connect(this->viewActionPerspective, SIGNAL(triggered()), this, SLOT(viewPerspective())); connect(this->viewActionOrthogonal, SIGNAL(triggered()), this, SLOT(viewOrthogonal())); connect(this->viewActionHide, SIGNAL(triggered()), this, SLOT(hideConsole())); @@ -2141,6 +2142,12 @@ void MainWindow::viewResetView() this->qglview->updateGL(); } +void MainWindow::viewAll() +{ + this->qglview->viewAll(); + this->qglview->updateGL(); +} + void MainWindow::on_editorDock_visibilityChanged(bool visible) { if (isClosing) { diff --git a/src/renderer.h b/src/renderer.h index 35b1845d..992ef347 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -13,7 +13,8 @@ class Renderer public: virtual ~Renderer() {} virtual void draw(bool showfaces, bool showedges) const = 0; - + virtual BoundingBox getBoundingBox() const = 0; + #define CSGMODE_DIFFERENCE_FLAG 0x10 enum csgmode_e { CSGMODE_NONE = 0x00,