Developer Documentation
ViewerProperties.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// Property storage Class for glWidgets
45//
46//=============================================================================
47
48#include <ACG/Scenegraph/DrawModes.hh>
49#include "ViewerProperties.hh"
50
51namespace Viewer {
52
53 ViewerProperties::ViewerProperties(int _id):
54 currentDrawMode_(ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED),
55 snapshotName_("snap"),
56 snapshotFileType_("png"),
57 snapshotCounter_(0),
58 wZoomFactor_(1.0),
59 wZoomFactorShift_(0.2),
60 wInvert_(false),
61 CCWFront_(true),
62 backgroundColor_(0.0f,0.0f,0.0f,1.0f),
63 locked_(0),
64 backFaceCulling_(false),
65 twoSidedLighting_(false),
66 multisampling_(true),
67 mipmapping_(true),
68 animation_(false),
69 glState_(0),
70 objectMarker_(0),
71 currentViewingDirection_(0),
72 rotationLocked_(false),
73 orthoWidth_(2.0),
74 nearPlane_(0.01),
75 farPlane_(100.0),
76 sceneCenter_(ACG::Vec3d( 0.0, 0.0, 0.0 )),
77 sceneRadius_(1.0),
78 trackballCenter_(ACG::Vec3d( 0.0, 0.0, 0.0 )),
79 trackballRadius_(1.0),
80 stereo_(false),
81 cursorPainter_(0),
82 cursorPoint3D_(ACG::Vec3d(0.0,0.0,0.0)),
83 cursorPositionValid_(false),
84 viewerId_(_id),
85 settingsSection_("Viewer" + QString::number(_id) + "/")
86 {
87 }
88
89 ViewerProperties::~ViewerProperties() {
90
91 if ( glState_ != 0 )
92 delete glState_;
93
94 }
95
96 void ViewerProperties::snapshotBaseFileName(const QString& _fname) {
97 snapshotName_ = _fname;
98 snapshotCounter_ = 0;
99 }
100
101 void ViewerProperties::snapshotFileType(const QString& _type) {
102 snapshotFileType_ = _type.trimmed();
103 }
104
105 std::string ViewerProperties::pickMode(){
106
107 std::string mode;
108 emit getPickMode(mode);
109 return mode;
110 }
111
112 void ViewerProperties::pickMode(const std::string& _name){
113 emit setPickMode(_name);
114 }
115
116 Viewer::ActionMode ViewerProperties::actionMode(){
118 emit getActionMode(am);
119 return am;
120 }
121
122 void ViewerProperties::actionMode(const Viewer::ActionMode _am){
123 emit setActionMode(_am);
124 }
125
126 int ViewerProperties::currentViewingDirection(){
127 return currentViewingDirection_;
128 }
129
130 void ViewerProperties::currentViewingDirection(int _dir){
131 currentViewingDirection_ = _dir;
132 }
133
134 bool ViewerProperties::rotationLocked(){
135 return rotationLocked_;
136 }
137
138 void ViewerProperties::rotationLocked(bool _locked){
139 rotationLocked_ = _locked;
140 }
141
142 int ViewerProperties::viewerId() {
143 return viewerId_;
144 }
145
146 void ViewerProperties::viewerId(int _id) {
147 viewerId_ = _id;
148 settingsSection_ = "Viewer" + QString::number(_id) + "/";
149 }
150
151 void ViewerProperties::drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode) {
152 currentDrawMode_ = _mode;
153 emit updated();
154 emit drawModeChanged(viewerId_);
155 }
156
157 ACG::SceneGraph::DrawModes::DrawMode ViewerProperties::drawMode() {
158 return currentDrawMode_;
159 }
160
161 void ViewerProperties::snapshotCounter(const int _counter){
162 snapshotCounter_ = _counter;
163 }
164
165 QString ViewerProperties::snapshotFileType() {
166 return snapshotFileType_;
167 }
168
169 QString ViewerProperties::snapshotName() {
170 return snapshotName_;
171 }
172
173 int ViewerProperties::snapshotCounter() {
174 return snapshotCounter_++;
175 }
176
177 double ViewerProperties::wheelZoomFactor() {
178 return wZoomFactor_;
179 }
180
181 double ViewerProperties::wheelZoomFactorShift() {
182 return wZoomFactorShift_;
183 }
184
185 void ViewerProperties::wheelZoomFactor(double _factor) {
186 wZoomFactor_ = _factor;
187 }
188
189 void ViewerProperties::wheelZoomFactorShift(double _factor) {
190 wZoomFactorShift_ = _factor;
191 }
192
193 bool ViewerProperties::wheelInvert() {
194 return wInvert_;
195 }
196
197 void ViewerProperties::wheelInvert(bool _invert) {
198 wInvert_ = _invert;
199 }
200
201 bool ViewerProperties::isCCWFront(){
202 return CCWFront_;
203 }
204
205 void ViewerProperties::ccwFront() {
206 CCWFront_ = true;
207 emit updated();
208 }
209
210 void ViewerProperties::cwFront() {
211 CCWFront_ = false;
212 emit updated();
213 }
214
215 ACG::Vec4f ViewerProperties::backgroundColor() {
216 return backgroundColor_;
217 }
218
219 QRgb ViewerProperties::backgroundColorRgb(){
220 QColor c;
221 c.setRedF( backgroundColor_[0]);
222 c.setGreenF(backgroundColor_[1]);
223 c.setBlueF( backgroundColor_[2]);
224 c.setAlphaF(backgroundColor_[3]);
225 return c.rgba();
226 }
227
228 QColor ViewerProperties::backgroundQColor(){
229 QColor c;
230 c.setRedF( backgroundColor_[0]);
231 c.setGreenF(backgroundColor_[1]);
232 c.setBlueF( backgroundColor_[2]);
233 c.setAlphaF(backgroundColor_[3]);
234 return c;
235 }
236
237 void ViewerProperties::backgroundColor( ACG::Vec4f _color ) {
238 backgroundColor_ = _color; emit updated();
239 };
240
241 void ViewerProperties::backgroundColor( QRgb _color ) {
242 QColor c(_color);
243 backgroundColor_[0] = c.redF();
244 backgroundColor_[1] = c.greenF();
245 backgroundColor_[2] = c.blueF();
246 backgroundColor_[3] = c.alphaF();
247 emit updated();
248 }
249
250 void ViewerProperties::backgroundColor( QColor _color ) {
251 backgroundColor_[0] = _color.redF();
252 backgroundColor_[1] = _color.greenF();
253 backgroundColor_[2] = _color.blueF();
254 backgroundColor_[3] = _color.alphaF();
255 emit updated();
256 }
257
258 void ViewerProperties::lockUpdate() {
259 locked_++;
260 }
261
262 void ViewerProperties::unLockUpdate(){
263 locked_-- ;
264 if ( locked_ <0 ) {
265 std::cerr << "More unlocks then locks" << std::endl;
266 locked_ = 0;
267 }
268 }
269
270 bool ViewerProperties::updateLocked() {
271 return (locked_ != 0);
272 }
273
274 bool ViewerProperties::backFaceCulling() {
275 return backFaceCulling_;
276 }
277
278 void ViewerProperties::backFaceCulling(bool _state ) {
279 backFaceCulling_ = _state;
280 emit updated();
281 }
282
283 void ViewerProperties::twoSidedLighting(bool _state ) {
284 twoSidedLighting_ = _state;
285 emit updated();
286 }
287
288 bool ViewerProperties::twoSidedLighting() {
289 return twoSidedLighting_;
290 }
291
292 void ViewerProperties::multisampling(bool _state ) {
293 multisampling_ = _state;
294 emit updated();
295 }
296
297 bool ViewerProperties::multisampling() {
298 return multisampling_;
299 }
300
301 void ViewerProperties::mipmapping(bool _state ) {
302 glState_->allow_mipmapping(_state); mipmapping_ = _state; emit updated();
303 }
304
305 bool ViewerProperties::mipmapping() {
306 return mipmapping_;
307 }
308
309 void ViewerProperties::animation(bool _state ) {
310 animation_ = _state;
311 emit updated();
312 }
313
314 bool ViewerProperties::animation() {
315 return animation_;
316 }
317
318 ACG::GLState& ViewerProperties::glState() {
319 return (*glState_);
320 }
321
322 const ACG::GLState& ViewerProperties::glState() const {
323 return (*glState_);
324 }
325
326 void ViewerProperties::setglState(ACG::GLState* _glState) {
327 glState_ = _glState;
328 }
329
330 void ViewerProperties::objectMarker (ViewObjectMarker* _marker) {
331 objectMarker_ = _marker;
332 emit updated();
333 }
334
335 ViewObjectMarker* ViewerProperties::objectMarker() {
336 return objectMarker_;
337 }
338
339 double ViewerProperties::orthoWidth() {
340 return orthoWidth_;
341 }
342
343 void ViewerProperties::orthoWidth(double _width){
344 orthoWidth_ = _width;
345 emit updated();
346 }
347
348 double ViewerProperties::nearPlane(){
349 return nearPlane_;
350 }
351
352 void ViewerProperties::setPlanes( double _near, double _far ) {
353 nearPlane_ = _near;
354 farPlane_ = _far;
355 emit updated();
356 }
357
358 double ViewerProperties::farPlane(){
359 return farPlane_;
360 }
361
362 ACG::Vec3d ViewerProperties::sceneCenter(){
363 return sceneCenter_;
364 }
365
366 void ViewerProperties::sceneCenter(ACG::Vec3d _center){
367 sceneCenter_ = _center;
368 emit updated();
369 }
370
371
372 double ViewerProperties::sceneRadius() {
373 return sceneRadius_;
374 }
375
376 void ViewerProperties::sceneRadius(double _radius ) {
377 sceneRadius_ = _radius;
378 emit updated();}
379
380
381 ACG::Vec3d ViewerProperties::trackballCenter(){
382 return trackballCenter_;
383 }
384
385 void ViewerProperties::trackballCenter(ACG::Vec3d _center){
386 trackballCenter_ = _center;
387 emit updated();
388 }
389
390 double ViewerProperties::trackballRadius() {
391 return trackballRadius_;
392 }
393
394 void ViewerProperties::trackballRadius(double _radius ) {
395 trackballRadius_ = _radius; emit updated();
396 }
397
398 float ViewerProperties::getDevicePixelRatio() const { return device_pixel_ratio_; }
399
401 void ViewerProperties::setDevicePixelRatio(float dpr) { device_pixel_ratio_ = dpr; }
402
403 QPoint ViewerProperties::adjustForDevicePixelRatio(QPoint const & point) const {
404 return QPoint{
405 int(point.x() * getDevicePixelRatio()),
406 int(point.y() * getDevicePixelRatio())
407 };
408 }
409
410 QPointF ViewerProperties::adjustForDevicePixelRatio(QPointF const & point) const
411 {
412 return QPointF{
413 point.x() * getDevicePixelRatio(),
414 point.y() * getDevicePixelRatio()
415 };
416 }
417
418 void ViewerProperties::stereo(bool _stereo) {
419 stereo_ = _stereo;
420 emit updated();
421 }
422
423 bool ViewerProperties::stereo() {
424 return stereo_;
425 }
426
427 CursorPainter* ViewerProperties::cursorPainter() {
428 return cursorPainter_;
429 }
430
431 void ViewerProperties::cursorPainter( CursorPainter* _painter ) {
432 cursorPainter_ = _painter;
433 }
434
435 ACG::Vec3d ViewerProperties::cursorPoint3D() {
436 return cursorPoint3D_;
437 }
438
439 void ViewerProperties::cursorPoint3D(ACG::Vec3d _pos) {
440 cursorPoint3D_ = _pos;
441 }
442
443 bool ViewerProperties::cursorPositionValid() {
444 return cursorPositionValid_;
445 }
446
447 void ViewerProperties::cursorPositionValid(bool _valid) {
448 cursorPositionValid_ = _valid;
449 }
450
451
452
453}
454
ActionMode
Enum listing action modes of the viewers.
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition: DrawModes.cc:81
Namespace providing different geometric functions concerning angles.