Developer Documentation
QtBaseViewerSnapshot.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // CLASS QtBaseViewer - IMPLEMENTATION
55 //
56 //=============================================================================
57 
58 
59 //== INCLUDES =================================================================
60 
61 #include "QtBaseViewer.hh"
62 #include "QtGLGraphicsScene.hh"
63 #include "QtGLGraphicsView.hh"
64 
65 #include <QApplication>
66 #include <QStatusBar>
67 #include <QFileInfo>
68 #include <QFileDialog>
69 
70 //== NAMESPACES ===============================================================
71 
72 namespace ACG {
73 namespace QtWidgets {
74 
75 
76 //== IMPLEMENTATION ==========================================================
77 
78 void QtBaseViewer::snapshotBaseFileName(const QString& _fname)
79 {
80  snapshotName_=_fname;
82 }
83 
84 
85 //-----------------------------------------------------------------------------
86 
87 
89 {
90  makeCurrent();
91 
92  glView_->raise();
93  qApp->processEvents();
94  makeCurrent();
95  paintGL();
96  glFinish();
97  copyToImage(*snapshot_, 0, 0, glWidth(), glHeight(), GL_BACK);
98 
99  QFileInfo fi(snapshotName_);
100 
101  QString fname = fi.path() + QDir::separator() +fi.baseName() + "." + QString::number(snapshotCounter_).rightJustified(7, '0') + ".";
102 
103  QString format="png";
104 
105  if (fi.completeSuffix() == "ppm")
106  format="ppmraw";
107 
108  fname += format;
109 
110  bool rval=snapshot_->save(fname,format.toUpper().toLatin1());
111 
112 
113  assert(statusbar_!=0);
114  if (rval)
115  {
116  statusbar_->showMessage(QString("snapshot: ")+fname,5000);
117  if ( action_["SnapshotSavesView"]->isChecked() )
118  {
119  QString view; encodeView(view);
120  QFile f(fname+".view"); f.open(QIODevice::WriteOnly|QIODevice::Truncate);
121  QTextStream sf(&f); sf << view; f.close();
122  }
123  }
124  else
125  {
126  statusbar_->showMessage(QString("could not save snapshot to ")+fname);
127  }
128 
130 }
131 
132 //-----------------------------------------------------------------------------
133 
134 
136 {
137  snapshot();
138 }
139 
140 
141 //-----------------------------------------------------------------------------
142 
143 
145 {
146  QString fname=snapshotName_;
147 
148  fname.replace('%', '$');
149  fname = QFileDialog::getSaveFileName ( 0, "Save snapshot name" );
150  if (!fname.isEmpty())
151  {
152  fname.replace('$', '%');
153 
154  snapshotBaseFileName(fname);
155  assert(statusbar_!=0);
156  QString msg="next snapshot: ";
157  statusbar_->showMessage(msg);
158  }
159 }
160 
161 
162 //-----------------------------------------------------------------------------
163 
164 
166 {
167 }
168 
169 //=============================================================================
170 } // namespace QtWidgets
171 } // namespace ACG
172 //=============================================================================
void encodeView(QString &_view)
convert current view to text representation
unsigned int glHeight() const
get height of QGLWidget
unsigned int glWidth() const
get width of QGLWidget
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
virtual void makeCurrent()
Makes this widget the current widget for OpenGL operations.
void copyToImage(QImage &_image, GLenum _buffer=GL_BACK)
copy current framebuffer to an QImage
virtual void snapshotBaseFileName(const QString &_fname)
virtual void paintGL()
draw the scene. Triggered by updateGL().