Added View->View All menu entry

master
Marius Kintel 2014-06-21 16:12:55 -04:00
parent 4097aa887d
commit d066648390
15 changed files with 56 additions and 15 deletions

View File

@ -6,9 +6,9 @@ class CGALRenderer : public Renderer
{ {
public: public:
CGALRenderer(shared_ptr<const class Geometry> geom); CGALRenderer(shared_ptr<const class Geometry> geom);
~CGALRenderer(); virtual ~CGALRenderer();
void draw(bool showfaces, bool showedges) const; virtual void draw(bool showfaces, bool showedges) const;
BoundingBox getBoundingBox() const; virtual BoundingBox getBoundingBox() const;
public: public:
shared_ptr<class Polyhedron> polyhedron; shared_ptr<class Polyhedron> polyhedron;

View File

@ -28,7 +28,7 @@ public:
Camera(enum CameraType camtype = NONE); Camera(enum CameraType camtype = NONE);
void setup(std::vector<double> params); void setup(std::vector<double> params);
void gimbalDefaultTranslate(); void gimbalDefaultTranslate();
void viewAll(const BoundingBox &bbox, float scalefactor); void viewAll(const BoundingBox &bbox, float scalefactor = 1.0f);
// Vectorcam // Vectorcam
Eigen::Vector3d eye; Eigen::Vector3d eye;

View File

@ -3,6 +3,7 @@
#include "stdio.h" #include "stdio.h"
#include "rendersettings.h" #include "rendersettings.h"
#include "mathc99.h" #include "mathc99.h"
#include "renderer.h"
#ifdef _WIN32 #ifdef _WIN32
#include <GL/wglew.h> #include <GL/wglew.h>

View File

@ -25,14 +25,14 @@ Some actions (showCrossHairs) only work properly on Gimbal Camera.
#endif #endif
#include "system-gl.h" #include "system-gl.h"
#include <iostream> #include <iostream>
#include "renderer.h"
#include "Camera.h" #include "Camera.h"
class GLView class GLView
{ {
public: public:
GLView(); GLView();
void setRenderer(Renderer* r); void setRenderer(class Renderer* r);
Renderer *getRenderer() const { return this->renderer; }
void initializeGL(); void initializeGL();
void resizeGL(int w, int h); void resizeGL(int w, int h);

View File

@ -203,6 +203,7 @@ public slots:
void viewPerspective(); void viewPerspective();
void viewOrthogonal(); void viewOrthogonal();
void viewResetView(); void viewResetView();
void viewAll();
void hideConsole(); void hideConsole();
void animateUpdateDocChanged(); void animateUpdateDocChanged();
void animateUpdate(); void animateUpdate();

View File

@ -120,7 +120,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>936</width> <width>936</width>
<height>34</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menu_File"> <widget class="QMenu" name="menu_File">
@ -234,6 +234,7 @@
<addaction name="viewActionBack"/> <addaction name="viewActionBack"/>
<addaction name="viewActionDiagonal"/> <addaction name="viewActionDiagonal"/>
<addaction name="viewActionCenter"/> <addaction name="viewActionCenter"/>
<addaction name="viewActionViewAll"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="viewActionZoomIn"/> <addaction name="viewActionZoomIn"/>
<addaction name="viewActionZoomOut"/> <addaction name="viewActionZoomOut"/>
@ -961,6 +962,11 @@
<string>Ctrl+[</string> <string>Ctrl+[</string>
</property> </property>
</action> </action>
<action name="viewActionViewAll">
<property name="text">
<string>View All</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -147,3 +147,10 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo,
} }
std::for_each(primitives.begin(), primitives.end(), del_fun<OpenCSG::Primitive>()); std::for_each(primitives.begin(), primitives.end(), del_fun<OpenCSG::Primitive>());
} }
BoundingBox OpenCSGRenderer::getBoundingBox() const
{
BoundingBox bbox;
if (this->root_chain) bbox = this->root_chain->getBoundingBox();
return bbox;
}

View File

@ -8,7 +8,8 @@ class OpenCSGRenderer : public Renderer
public: public:
OpenCSGRenderer(class CSGChain *root_chain, CSGChain *highlights_chain, OpenCSGRenderer(class CSGChain *root_chain, CSGChain *highlights_chain,
CSGChain *background_chain, GLint *shaderinfo); 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: private:
void renderCSGChain(class CSGChain *chain, GLint *shaderinfo, void renderCSGChain(class CSGChain *chain, GLint *shaderinfo,
bool highlight, bool background) const; bool highlight, bool background) const;

View File

@ -88,6 +88,15 @@ void QGLView::resetView()
cam.viewer_distance = 140; 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() void QGLView::initializeGL()
{ {
GLenum err = glewInit(); GLenum err = glewInit();

View File

@ -44,6 +44,7 @@ public:
#endif #endif
bool save(const char *filename); bool save(const char *filename);
void resetView(); void resetView();
void viewAll();
public slots: public slots:
void ZoomIn(void); void ZoomIn(void);

View File

@ -123,3 +123,10 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight,
glPopMatrix(); glPopMatrix();
} }
} }
BoundingBox ThrownTogetherRenderer::getBoundingBox() const
{
BoundingBox bbox;
if (this->root_chain) bbox = this->root_chain->getBoundingBox();
return bbox;
}

View File

@ -7,7 +7,8 @@ class ThrownTogetherRenderer : public Renderer
public: public:
ThrownTogetherRenderer(class CSGChain *root_chain, ThrownTogetherRenderer(class CSGChain *root_chain,
CSGChain *highlights_chain, CSGChain *background_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: private:
void renderCSGChain(CSGChain *chain, bool highlight, bool background, bool showedges, void renderCSGChain(CSGChain *chain, bool highlight, bool background, bool showedges,
bool fberror) const; bool fberror) const;

View File

@ -68,11 +68,6 @@ void export_png_preview_common(Tree &tree, Camera &cam, std::ostream &output, Pr
#endif #endif
ThrownTogetherRenderer thrownTogetherRenderer(csgInfo.root_chain, csgInfo.highlights_chain, csgInfo.background_chain); 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 #ifdef ENABLE_OPENCSG
if (previewer == OPENCSG) if (previewer == OPENCSG)
csgInfo.glview->setRenderer(&openCSGRenderer); csgInfo.glview->setRenderer(&openCSGRenderer);
@ -80,6 +75,10 @@ void export_png_preview_common(Tree &tree, Camera &cam, std::ostream &output, Pr
#endif #endif
csgInfo.glview->setRenderer(&thrownTogetherRenderer); csgInfo.glview->setRenderer(&thrownTogetherRenderer);
#ifdef ENABLE_OPENCSG #ifdef ENABLE_OPENCSG
BoundingBox bbox = csgInfo.glview->getRenderer()->getBoundingBox();
setupCamera(cam, bbox, 2.7);
csgInfo.glview->setCamera(cam);
OpenCSG::setContext(0); OpenCSG::setContext(0);
OpenCSG::setOption(OpenCSG::OffscreenSetting, OpenCSG::FrameBufferObject); OpenCSG::setOption(OpenCSG::OffscreenSetting, OpenCSG::FrameBufferObject);
#endif #endif

View File

@ -372,6 +372,7 @@ MainWindow::MainWindow(const QString &filename)
connect(this->viewActionDiagonal, SIGNAL(triggered()), this, SLOT(viewAngleDiagonal())); connect(this->viewActionDiagonal, SIGNAL(triggered()), this, SLOT(viewAngleDiagonal()));
connect(this->viewActionCenter, SIGNAL(triggered()), this, SLOT(viewCenter())); connect(this->viewActionCenter, SIGNAL(triggered()), this, SLOT(viewCenter()));
connect(this->viewActionResetView, SIGNAL(triggered()), this, SLOT(viewResetView())); 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->viewActionPerspective, SIGNAL(triggered()), this, SLOT(viewPerspective()));
connect(this->viewActionOrthogonal, SIGNAL(triggered()), this, SLOT(viewOrthogonal())); connect(this->viewActionOrthogonal, SIGNAL(triggered()), this, SLOT(viewOrthogonal()));
connect(this->viewActionHide, SIGNAL(triggered()), this, SLOT(hideConsole())); connect(this->viewActionHide, SIGNAL(triggered()), this, SLOT(hideConsole()));
@ -2141,6 +2142,12 @@ void MainWindow::viewResetView()
this->qglview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewAll()
{
this->qglview->viewAll();
this->qglview->updateGL();
}
void MainWindow::on_editorDock_visibilityChanged(bool visible) void MainWindow::on_editorDock_visibilityChanged(bool visible)
{ {
if (isClosing) { if (isClosing) {

View File

@ -13,7 +13,8 @@ class Renderer
public: public:
virtual ~Renderer() {} virtual ~Renderer() {}
virtual void draw(bool showfaces, bool showedges) const = 0; virtual void draw(bool showfaces, bool showedges) const = 0;
virtual BoundingBox getBoundingBox() const = 0;
#define CSGMODE_DIFFERENCE_FLAG 0x10 #define CSGMODE_DIFFERENCE_FLAG 0x10
enum csgmode_e { enum csgmode_e {
CSGMODE_NONE = 0x00, CSGMODE_NONE = 0x00,