~ubuntu-branches/ubuntu/oneiric/soqt/oneiric

« back to all changes in this revision

Viewing changes to build/msvc7/src/Inventor/Qt/viewers/SoQtFullViewer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2006-02-06 22:34:00 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060206223400-g69m5soqa4zh0gkc
Tags: 1.3.0-3
debian/control: update libsoqt-dev depends.  Closes: #351700.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************\
 
2
 *
 
3
 *  This file is part of the Coin 3D visualization library.
 
4
 *  Copyright (C) 1998-2005 by Systems in Motion.  All rights reserved.
 
5
 *
 
6
 *  This library is free software; you can redistribute it and/or
 
7
 *  modify it under the terms of the GNU General Public License
 
8
 *  ("GPL") version 2 as published by the Free Software Foundation.
 
9
 *  See the file LICENSE.GPL at the root directory of this source
 
10
 *  distribution for additional information about the GNU GPL.
 
11
 *
 
12
 *  For using Coin with software that can not be combined with the GNU
 
13
 *  GPL, and for taking advantage of the additional benefits of our
 
14
 *  support services, please contact Systems in Motion about acquiring
 
15
 *  a Coin Professional Edition License.
 
16
 *
 
17
 *  See <URL:http://www.coin3d.org/> for more information.
 
18
 *
 
19
 *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
 
20
 *  <URL:http://www.sim.no/>.
 
21
 *
 
22
\**************************************************************************/
 
23
 
 
24
// src/Inventor/Qt/viewers/SoQtFullViewer.cpp.  Generated from SoGuiFullViewer.cpp.in by configure.
 
25
 
 
26
// This file contains the generic, "templatize-able" parts of the
 
27
// So*FullViewer sourcecode.
 
28
 
 
29
/*!
 
30
  \class SoQtFullViewer SoQtFullViewer.h Inventor/Qt/viewers/SoQtFullViewer.h
 
31
  \brief The SoQtFullViewer class adds some user interface components to the viewer canvas.
 
32
  \ingroup components viewers
 
33
 
 
34
  The SoQtFullViewer is an abstract viewer class which extends it's
 
35
  superclass (the basic SoQtViewer class) with two major user
 
36
  interface additions:
 
37
 
 
38
  <ul>
 
39
 
 
40
  <li>decorations around the render canvas, with buttons and
 
41
  thumbwheels to control camera interaction and various other aspects
 
42
  of model / scene viewing</li>
 
43
 
 
44
  <li>a popup menu, invoked with the right mouse button, which
 
45
  controls yet more aspects of the rendering and the viewer</li>
 
46
 
 
47
  </ul>
 
48
 
 
49
  The user interface features listed above are the common parts of the
 
50
  user interfaces of the SoQtFullViewer's non-abstract subclasses.
 
51
 
 
52
  For "real" application programs, the viewers / components from this
 
53
  class onwards and further down in the inheritance hierarchy is
 
54
  usually not all that interesting, as they enforces too much extra
 
55
  user interface cruft not compatible with the look and feel of the
 
56
  other parts of the application user interface. So most "real"
 
57
  applications will use either the SoQtViewer or the
 
58
  SoQtRenderArea as their base-level component, and then inherit
 
59
  one of these down into one's own "proper" viewer classes.
 
60
 
 
61
  The non-abstract subclasses of the SoQtFullViewer class are
 
62
  viewer components often used as a test-bed for prototyping / rapid
 
63
  application development when doing quick testing of scenes,
 
64
  stand-alone 3D-models, animation techniques, etc etc.
 
65
 
 
66
 
 
67
  \sa SoQtConstrainedViewer, SoQtExaminerViewer, SoQtPlaneViewer
 
68
*/
 
69
 
 
70
 
 
71
// *************************************************************************
 
72
 
 
73
#include <float.h>
 
74
 
 
75
#include <Inventor/Qt/viewers/SoQtFullViewer.h>
 
76
#include <Inventor/Qt/viewers/SoQtFullViewerP.h>
 
77
#include <Inventor/Qt/widgets/SoQtPopupMenu.h>
 
78
#include <soqtdefs.h>
 
79
 
 
80
#include <Inventor/events/SoMouseButtonEvent.h>
 
81
#include <Inventor/events/SoKeyboardEvent.h>
 
82
#include <Inventor/errors/SoDebugError.h>
 
83
#include <Inventor/nodes/SoOrthographicCamera.h>
 
84
#include <Inventor/nodes/SoPerspectiveCamera.h>
 
85
 
 
86
#ifdef HAVE_CONFIG_H
 
87
#include <config.h>
 
88
#endif // HAVE_CONFIG_H
 
89
 
 
90
// ************************************************************************
 
91
 
 
92
#define PRIVATE(o) (o->pimpl)
 
93
#define PUBLIC(o) (o->pub)
 
94
 
 
95
// ************************************************************************
 
96
 
 
97
// Note: the following function documentation block will also be used
 
98
// for all the miscellaneous viewer subclasses, so keep it general.
 
99
/*!
 
100
  \fn void SoQtFullViewer::createViewerButtons(QWidget * parent, SbPList * buttonlist)
 
101
 
 
102
  Set up the viewer buttons with pixmaps and event connections.
 
103
 
 
104
 
 
105
  One important note if you want to override this method to add your
 
106
  own buttons to the list (in the explanation below, it is assumed
 
107
  that you know how virtual function table pointers are handled by
 
108
  C++):
 
109
 
 
110
  createViewerButtons() is called (indirectly) from the constructors
 
111
  of the viewer classes. This means that you need to delay it's
 
112
  invocation until your own subclass's constructor is run, because
 
113
  otherwise your re-implementation won't have been added to the
 
114
  internal virtual function table yet.
 
115
 
 
116
  Delaying a superclass viewer from building it's decorations is done
 
117
  by passing build==FALSE as the last argument of the protected
 
118
  constructors. You will then have to explicitly trigger the building
 
119
  in your own constructor.
 
120
 
 
121
  Here's a minimal example that shows the steps needed to be able to
 
122
  override createViewerButtons() from SoQtExaminerViewer:
 
123
 
 
124
  \code
 
125
  class MyExaminerViewer : public SoQtExaminerViewer {
 
126
  
 
127
  public:
 
128
    MyExaminerViewer(QWidget * parent);
 
129
  
 
130
  protected:
 
131
    virtual void createViewerButtons(QWidget * parent, SbPList * buttonlist);
 
132
  };
 
133
  
 
134
  MyExaminerViewer::MyExaminerViewer(QWidget * parent)
 
135
    : SoQtExaminerViewer(parent, NULL, TRUE,
 
136
                            SoQtFullViewer::BUILD_ALL, SoQtFullViewer::BROWSER,
 
137
                            // build == FALSE, to delay creation of decorations
 
138
                            FALSE)
 
139
  {
 
140
    // Explicitly trigger the construction of viewer decorations.
 
141
    QWidget * widget = this->buildWidget(this->getParentWidget());
 
142
    this->setBaseWidget(widget);
 
143
  }
 
144
  
 
145
  void
 
146
  MyExaminerViewer::createViewerButtons(QWidget * parent, SbPList * buttonlist)
 
147
  {
 
148
    SoQtExaminerViewer::createViewerButtons(parent, buttonlist);
 
149
    // [now add your own button(s) to the buttonlist]
 
150
  }
 
151
  \endcode
 
152
*/
 
153
 
 
154
/*!
 
155
  \enum SoQtFullViewer::BuildFlag
 
156
 
 
157
  Valid values for the constructor argument that decides how much of
 
158
  the user interface features to set up. The enum values are bitflags
 
159
  that can be OR'ed together.
 
160
*/
 
161
/*!
 
162
  \var SoQtFullViewer::BuildFlag SoQtFullViewer::BUILD_NONE
 
163
 
 
164
  Do not add any of the user interface components.
 
165
*/
 
166
/*!
 
167
  \var SoQtFullViewer::BuildFlag SoQtFullViewer::BUILD_DECORATION
 
168
 
 
169
  Only build and set up the decorations around the OpenGL canvas.
 
170
*/
 
171
/*!
 
172
  \var SoQtFullViewer::BuildFlag SoQtFullViewer::BUILD_POPUP
 
173
 
 
174
  Only build the popup menu. (Activated with the right mousebutton.)
 
175
*/
 
176
/*!
 
177
  \var SoQtFullViewer::BuildFlag SoQtFullViewer::BUILD_ALL
 
178
 
 
179
  Build all user interface components of the SoQtFullViewer.
 
180
*/
 
181
 
 
182
/*!
 
183
  \var QWidget * SoQtFullViewer::leftDecoration
 
184
  The root widget for the left-side decorations.
 
185
*/
 
186
 
 
187
/*!
 
188
  \var QWidget * SoQtFullViewer::leftWheel
 
189
  The widget representing the thumbwheel left of the render canvas.
 
190
*/
 
191
 
 
192
/*!
 
193
  \var QWidget * SoQtFullViewer::leftWheelLabel
 
194
  Label widget of left wheel.
 
195
*/
 
196
 
 
197
/*!
 
198
  \var char * SoQtFullViewer::leftWheelStr
 
199
  Text of left thumbwheel's label.
 
200
*/
 
201
 
 
202
/*!
 
203
  \var float SoQtFullViewer::leftWheelVal
 
204
  Current value of the left thumbwheel.
 
205
*/
 
206
 
 
207
/*!
 
208
  \var QWidget * SoQtFullViewer::bottomDecoration
 
209
  The root widget for the bottom decorations.
 
210
*/
 
211
 
 
212
/*!
 
213
  \var QWidget * SoQtFullViewer::bottomWheel
 
214
  The widget representing the thumbwheel below the render canvas.
 
215
*/
 
216
 
 
217
/*!
 
218
  \var QWidget * SoQtFullViewer::bottomWheelLabel
 
219
  Label widget of bottom wheel.
 
220
*/
 
221
 
 
222
/*!
 
223
  \var char * SoQtFullViewer::bottomWheelStr
 
224
  Text of bottom thumbwheel's label.
 
225
*/
 
226
 
 
227
/*!
 
228
  \var float SoQtFullViewer::bottomWheelVal
 
229
  Current value of the bottom thumbwheel.
 
230
*/
 
231
 
 
232
/*!
 
233
  \var QWidget * SoQtFullViewer::rightDecoration
 
234
  The root widget for the right-side decorations.
 
235
*/
 
236
 
 
237
/*!
 
238
  \var QWidget * SoQtFullViewer::rightWheel
 
239
  The widget representing the thumbwheel on the right side of the render canvas.
 
240
*/
 
241
 
 
242
/*!
 
243
  \var QWidget * SoQtFullViewer::rightWheelLabel
 
244
  Label widget of right wheel.
 
245
*/
 
246
 
 
247
/*!
 
248
  \var char * SoQtFullViewer::rightWheelStr
 
249
  Text of right thumbwheel's label.
 
250
*/
 
251
 
 
252
/*!
 
253
  \var float SoQtFullViewer::rightWheelVal
 
254
  Current value of the right-side thumbwheel.
 
255
*/
 
256
 
 
257
/*!
 
258
  \var SoQtPopupMenu * SoQtFullViewer::prefmenu
 
259
  Pointer to the popup menu instance.
 
260
*/
 
261
 
 
262
/*!
 
263
  \fn SoQtFullViewer::SoQtFullViewer(QWidget * parent, const char * name, SbBool embed, SoQtFullViewer::BuildFlag buildFlag, SoQtViewer::Type type, SbBool build)
 
264
 
 
265
  Constructor. See parent class for explanation of arguments.
 
266
 
 
267
  Subclasses will probably usually call with the \a buildNow flag set
 
268
  to \c FALSE to be able to do delayed building of the OpenGL canvas
 
269
  after other setup tasks has been performed.
 
270
*/
 
271
 
 
272
/*!
 
273
  \fn SoQtFullViewer::~SoQtFullViewer()
 
274
 
 
275
  Destructor.
 
276
*/
 
277
 
 
278
/*!
 
279
  \fn void SoQtFullViewer::setDecoration(const SbBool enable)
 
280
 
 
281
  Turn the viewer decorations on or off.
 
282
 
 
283
  \sa isDecoration()
 
284
*/
 
285
 
 
286
/*!
 
287
  \fn SbBool SoQtFullViewer::isDecoration(void) const
 
288
 
 
289
  Return \c TRUE if the viewer decorations are on, otherwise \c FALSE.
 
290
 
 
291
  \sa setDecoration()
 
292
*/
 
293
 
 
294
/*!
 
295
  \fn void SoQtFullViewer::setPopupMenuEnabled(const SbBool enable)
 
296
 
 
297
  Decide whether or not if clicking with the right mouse button on
 
298
  the OpenGL canvas should reveal a preferences popup menu when in
 
299
  viewing mode.
 
300
 
 
301
  \sa isPopupMenuEnabled()
 
302
*/
 
303
 
 
304
/*!
 
305
  \fn SbBool SoQtFullViewer::isPopupMenuEnabled(void) const
 
306
 
 
307
  Return \c TRUE if the popup preferences menu is enabled,
 
308
  otherwise \c FALSE.
 
309
 
 
310
  \sa setPopupMenuEnabled()
 
311
*/
 
312
 
 
313
/*!
 
314
  \fn QWidget * SoQtFullViewer::getAppPushButtonParent(void) const
 
315
 
 
316
  Returns the widget which is used as the parent of application
 
317
  specified buttons. The row of application buttons (if any) will be
 
318
  placed in the upper left corner.
 
319
 
 
320
  \sa addAppPushButton(), insertAppPushButton(), removeAppPushButton()
 
321
*/
 
322
 
 
323
/*!
 
324
  \fn void SoQtFullViewer::addAppPushButton(QWidget * newButton)
 
325
 
 
326
  Add an application specific push button to the viewer decorations.
 
327
  Application buttons will be laid out in a vertical row from the
 
328
  upper left corner.
 
329
 
 
330
  The button will be added bottom-most.
 
331
 
 
332
  \sa insertAppPushButton(), removeAppPushButton(), getAppPushButtonParent()
 
333
*/
 
334
 
 
335
/*!
 
336
  \fn void SoQtFullViewer::insertAppPushButton(QWidget * newButton, int index)
 
337
 
 
338
  Insert an application specific push button to the viewer decorations
 
339
  at the given \c index.
 
340
 
 
341
  \sa addAppPushButton(), removeAppPushButton(), getAppPushButtonParent()
 
342
*/
 
343
 
 
344
/*!
 
345
  \fn void SoQtFullViewer::removeAppPushButton(QWidget * oldButton)
 
346
 
 
347
  Remove one of the application specific buttons.
 
348
 
 
349
  \sa addAppPushButton(), insertAppPushButton()
 
350
*/
 
351
 
 
352
/*!
 
353
  \fn int SoQtFullViewer::findAppPushButton(QWidget * oldButton) const
 
354
 
 
355
  Return the index of a particular button that has been specified by
 
356
  the application, or -1 of the button has not been added.
 
357
 
 
358
  \sa addAppPushButton()
 
359
*/
 
360
 
 
361
/*!
 
362
  \fn int SoQtFullViewer::lengthAppPushButton(void) const
 
363
 
 
364
  Return number of application specific buttons added.
 
365
 
 
366
  \sa addAppPushButton(), insertAddAppPushButton()
 
367
*/
 
368
 
 
369
/*!
 
370
  \fn QWidget * SoQtFullViewer::getRenderAreaWidget(void) const
 
371
 
 
372
  Returns the render area OpenGL canvas widget.
 
373
*/
 
374
 
 
375
/*!
 
376
  \fn void SoQtFullViewer::buildDecoration(QWidget * parent)
 
377
 
 
378
  Build viewer decorations.
 
379
*/
 
380
 
 
381
/*!
 
382
  \fn QWidget * SoQtFullViewer::buildLeftTrim(QWidget * parent)
 
383
 
 
384
  Build decorations on the left of the render canvas.  Override this
 
385
  method in subclasses if you want your own decorations on the viewer
 
386
  window.
 
387
 
 
388
  The decoration will be 30 pixels wide.
 
389
*/
 
390
 
 
391
/*!
 
392
  \fn QWidget * SoQtFullViewer::buildBottomTrim(QWidget * parent)
 
393
 
 
394
  Build decorations on the bottom of the render canvas. Override this
 
395
  method in subclasses if you want your own decorations on the viewer window.
 
396
*/
 
397
 
 
398
/*!
 
399
  \fn QWidget * SoQtFullViewer::buildRightTrim(QWidget * parent)
 
400
 
 
401
  Build decorations on the right side of the render canvas. Override this
 
402
  method in subclasses if you want your own decorations on the viewer window.
 
403
*/
 
404
 
 
405
/*!
 
406
  \fn QWidget * SoQtFullViewer::buildAppButtons(QWidget * parent)
 
407
 
 
408
  Build the application specified button row (if any buttons were
 
409
  set up).
 
410
*/
 
411
 
 
412
/*!
 
413
  \fn QWidget * SoQtFullViewer::buildViewerButtons(QWidget * parent)
 
414
 
 
415
  Build and layout viewer specified button row.
 
416
*/
 
417
 
 
418
/*!
 
419
  \fn void SoQtFullViewer::buildPopupMenu(void)
 
420
 
 
421
  Make a popup menu with preferences settings.
 
422
 
 
423
  One important note as for when you want to override this function in
 
424
  a subclass: be aware that it will usually be invoked (indirectly)
 
425
  from this class's constructor. That is \e before the table of
 
426
  virtual function pointers has been set up for the subclass, and
 
427
  because of this, the function will not be called in the subclass
 
428
  even though it is virtual.
 
429
 
 
430
  To make the overriding actually be in effect, you need to delay
 
431
  building the widgets of this class. For information on how to do
 
432
  that, see the documentation of
 
433
  SoQtFullViewer::createViewerButtons().
 
434
*/
 
435
 
 
436
/*!
 
437
  \fn void SoQtFullViewer::openPopupMenu(const SbVec2s position)
 
438
 
 
439
  NOTE: This method is not part of the original InventorXt API.
 
440
*/
 
441
 
 
442
/*!
 
443
  \fn void SoQtFullViewer::setLeftWheelString(const char * const string)
 
444
 
 
445
  Set label of the left thumbwheel.
 
446
*/
 
447
 
 
448
/*!
 
449
  \fn void SoQtFullViewer::setBottomWheelString(const char * const string)
 
450
 
 
451
  Set label of the bottom thumbwheel.
 
452
*/
 
453
 
 
454
/*!
 
455
  \fn void SoQtFullViewer::setRightWheelString(const char * const string)
 
456
 
 
457
  Set label of the right thumbwheel.
 
458
*/
 
459
 
 
460
// ************************************************************************
 
461
 
 
462
// Note: the following function documentation blocks for thumbwheel
 
463
// handling will also be used for all the miscellaneous viewer
 
464
// subclasses, so keep'em general.
 
465
 
 
466
/*!
 
467
  Called when the user start to drag the thumbwheel in the left
 
468
  frame.  Override this method in subclassed viewers to provide your
 
469
  own functionality on the thumbwheel.
 
470
 
 
471
  \sa leftWheelMotion(), leftWheelFinish()
 
472
  \sa bottomWheelStart(), rightWheelStart()
 
473
*/
 
474
void
 
475
SoQtFullViewer::leftWheelStart(void)
 
476
{
 
477
  this->interactiveCountInc();
 
478
}
 
479
 
 
480
/*!
 
481
  Called repeatedly as the user drags the thumbwheel in the left
 
482
  frame.  Override this method in subclassed viewers to provide your
 
483
  own functionality on the thumbwheel.
 
484
 
 
485
  \sa leftWheelStart(), leftWheelFinish()
 
486
  \sa bottomWheelStart(), rightWheelStart()
 
487
*/
 
488
void
 
489
SoQtFullViewer::leftWheelMotion(float value)
 
490
{
 
491
  this->leftWheelVal = value;
 
492
}
 
493
 
 
494
/*!
 
495
  Called as the user let go of the thumbwheel in the left frame
 
496
  after a drag operation. Override this method in subclassed viewers
 
497
  to provide your own functionality on the thumbwheel.
 
498
 
 
499
  \sa leftWheelStart(), leftWheelMotion()
 
500
  \sa bottomWheelStart(), rightWheelStart()
 
501
*/
 
502
void
 
503
SoQtFullViewer::leftWheelFinish(void)
 
504
{
 
505
  this->interactiveCountDec();
 
506
}
 
507
 
 
508
/*!
 
509
  Set a new value for the left thumbwheel.
 
510
*/
 
511
void
 
512
SoQtFullViewer::setLeftWheelValue(const float value)
 
513
{
 
514
  this->leftWheelVal = value;
 
515
  // Wheel may not be constructed yet, but we need to be robust, as
 
516
  // set*WheelValue() is used from subclasses.
 
517
  if (this->leftWheel) {
 
518
    SoQtFullViewerP::setThumbWheelValue(this->leftWheel, value);
 
519
  }
 
520
}
 
521
 
 
522
/*!
 
523
  Get current value of the left thumbwheel.
 
524
 
 
525
  \sa leftWheelMotion()
 
526
*/
 
527
float
 
528
SoQtFullViewer::getLeftWheelValue(void) const
 
529
{
 
530
  return this->leftWheelVal;
 
531
}
 
532
 
 
533
/*!
 
534
  Called when the user start to drag the thumbwheel in the bottom
 
535
  frame.  Override this method in subclassed viewers to provide your
 
536
  own functionality on the thumbwheel.
 
537
 
 
538
  \sa bottomWheelMotion(), bottomWheelFinish()
 
539
  \sa leftWheelStart(), rightWheelStart()
 
540
*/
 
541
void
 
542
SoQtFullViewer::bottomWheelStart(void)
 
543
{
 
544
  this->interactiveCountInc();
 
545
}
 
546
 
 
547
/*!
 
548
  Called repeatedly as the user drags the thumbwheel in the bottom
 
549
  frame.  Override this method in subclassed viewers to provide your
 
550
  own functionality on the thumbwheel.
 
551
 
 
552
  \sa bottomWheelStart(), bottomWheelFinish()
 
553
  \sa leftWheelStart(), rightWheelStart()
 
554
*/
 
555
void
 
556
SoQtFullViewer::bottomWheelMotion(float value)
 
557
{
 
558
  this->bottomWheelVal = value;
 
559
}
 
560
 
 
561
/*!
 
562
  Called as the user let go of the thumbwheel in the bottom frame
 
563
  after a drag operation. Override this method in subclassed viewers
 
564
  to provide your own functionality on the thumbwheel.
 
565
 
 
566
  \sa bottomWheelStart(), bottomWheelMotion()
 
567
  \sa leftWheelStart(), rightWheelStart()
 
568
*/
 
569
void
 
570
SoQtFullViewer::bottomWheelFinish(void)
 
571
{
 
572
  this->interactiveCountDec();
 
573
}
 
574
 
 
575
/*!
 
576
  Set a new value for the bottom thumbwheel.
 
577
*/
 
578
void
 
579
SoQtFullViewer::setBottomWheelValue(const float value)
 
580
{
 
581
  this->bottomWheelVal = value;
 
582
  // Wheel may not be constructed yet, but we need to be robust, as
 
583
  // set*WheelValue() is used from subclasses.
 
584
  if (this->bottomWheel) {
 
585
    SoQtFullViewerP::setThumbWheelValue(this->bottomWheel, value);
 
586
  }
 
587
}
 
588
 
 
589
/*!
 
590
  Get current value of the bottom thumbwheel.
 
591
 
 
592
  \sa bottomWheelMotion()
 
593
*/
 
594
float
 
595
SoQtFullViewer::getBottomWheelValue(void) const
 
596
{
 
597
  return this->bottomWheelVal;
 
598
}
 
599
 
 
600
/*!
 
601
  Called when the user start to drag the thumbwheel in the right
 
602
  frame.  Override this method in subclassed viewers to provide your
 
603
  own functionality on the thumbwheel.
 
604
 
 
605
  \sa rightWheelMotion(), rightWheelFinish()
 
606
  \sa leftWheelStart(), bottomWheelStart()
 
607
*/
 
608
void
 
609
SoQtFullViewer::rightWheelStart(void)
 
610
{
 
611
  this->interactiveCountInc();
 
612
}
 
613
 
 
614
/*!
 
615
  Called repeatedly as the user drags the thumbwheel in the right
 
616
  frame.  Override this method in subclassed viewers to provide your
 
617
  own functionality on the thumbwheel.
 
618
 
 
619
  \sa rightWheelStart(), rightWheelFinish()
 
620
  \sa leftWheelStart(), bottomWheelStart()
 
621
*/
 
622
void
 
623
SoQtFullViewer::rightWheelMotion(float value)
 
624
{
 
625
  this->rightWheelVal = value;
 
626
}
 
627
 
 
628
/*!
 
629
  Called as the user let go of the thumbwheel in the right frame
 
630
  after a drag operation. Override this method in subclassed viewers
 
631
  to provide your own functionality on the thumbwheel.
 
632
 
 
633
  \sa rightWheelStart(), rightWheelMotion()
 
634
  \sa leftWheelStart(), bottomWheelStart()
 
635
*/
 
636
void
 
637
SoQtFullViewer::rightWheelFinish(void)
 
638
{
 
639
  this->interactiveCountDec();
 
640
}
 
641
 
 
642
/*!
 
643
  Set a new value for the right thumbwheel.
 
644
*/
 
645
void
 
646
SoQtFullViewer::setRightWheelValue(const float value)
 
647
{
 
648
  this->rightWheelVal = value;
 
649
  // Wheel may not be constructed yet, but we need to be robust, as
 
650
  // set*WheelValue() is used from subclasses.
 
651
  if (this->rightWheel) {
 
652
    SoQtFullViewerP::setThumbWheelValue(this->rightWheel, value);
 
653
  }
 
654
}
 
655
 
 
656
/*!
 
657
  Get current value of the right thumbwheel.
 
658
 
 
659
  \sa rightWheelMotion()
 
660
*/
 
661
float
 
662
SoQtFullViewer::getRightWheelValue(void) const
 
663
{
 
664
  return this->rightWheelVal;
 
665
}
 
666
 
 
667
// *************************************************************************
 
668
 
 
669
/*!
 
670
  This method returns the native widget for the label below the left
 
671
  thumb wheel.
 
672
*/
 
673
 
 
674
QWidget *
 
675
SoQtFullViewer::getLeftWheelLabelWidget(void) const
 
676
{
 
677
  return this->leftWheelLabel;
 
678
}
 
679
 
 
680
/*!
 
681
  This method returns the native widget for the label below the right thumb
 
682
  wheel.
 
683
*/
 
684
QWidget *
 
685
SoQtFullViewer::getRightWheelLabelWidget(void) const
 
686
{
 
687
  return this->rightWheelLabel;
 
688
}
 
689
 
 
690
/*!
 
691
  This method returns the native widget for the label beside the
 
692
  bottom thumb wheel.
 
693
*/
 
694
QWidget *
 
695
SoQtFullViewer::getBottomWheelLabelWidget(void) const
 
696
{
 
697
  return this->bottomWheelLabel;
 
698
}
 
699
 
 
700
// ************************************************************************
 
701
 
 
702
/*!
 
703
  Set title of popup menu.
 
704
*/
 
705
void
 
706
SoQtFullViewer::setPopupMenuString(const char * name)
 
707
{
 
708
  PRIVATE(this)->popupmenutitle = name;
 
709
  if (this->prefmenu) { this->prefmenu->setMenuTitle(SoGuiFullViewerP::ROOT_MENU, name); }
 
710
}
 
711
 
 
712
 
 
713
// Documented in superclass.
 
714
SbBool
 
715
SoQtFullViewer::processSoEvent(const SoEvent * const ev)
 
716
{
 
717
  // We're in "interact" mode (ie *not* the camera modification mode),
 
718
  // so don't handle the event here. It should either be forwarded to
 
719
  // the scenegraph, or caught by SoQtViewer::processSoEvent() if
 
720
  // it's an ESC press (to switch modes).
 
721
  if (!this->isViewing()) { return inherited::processSoEvent(ev); }
 
722
 
 
723
  // Note: with the original SGI InventorXt, the popup menu is also
 
724
  // activated by RMB clicks in non-viewing mode. We want to allow RMB
 
725
  // clicks to pass through to the scenegraph in non-viewing mode, so
 
726
  // we don't copy that behavior.
 
727
 
 
728
  if (ev->getTypeId().isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
 
729
    SoMouseButtonEvent * const e = (SoMouseButtonEvent *) ev;
 
730
    if ((e->getButton() == SoMouseButtonEvent::BUTTON2)) {
 
731
      if (this->isPopupMenuEnabled()) {
 
732
        if (e->getState() == SoButtonEvent::DOWN) {
 
733
          this->openPopupMenu(e->getPosition());
 
734
        }
 
735
        // Steal all RMB-events if the viewer uses the popup-menu.
 
736
        return TRUE;
 
737
      }
 
738
    }
 
739
  }
 
740
 
 
741
  return inherited::processSoEvent(ev);
 
742
}
 
743
 
 
744
// *************************************************************************
 
745
 
 
746
// FIXME: get rid of this hack and make this file truly
 
747
// "generic". 20020109 mortene.
 
748
#ifndef __COIN_SOWIN__
 
749
 
 
750
// *************************************************************************
 
751
 
 
752
// Doc in superclass.
 
753
void
 
754
SoQtFullViewer::setComponentCursor(const SoQtCursor & cursor)
 
755
{
 
756
  // Overridden to apply the new cursor only for the rendering canvas
 
757
  // widget. Otherwise, the default SoQtComponent
 
758
  // setComponentCursor() method will set the cursor for the top-most
 
759
  // parent widget, which makes it affect all sub-widgets, like the
 
760
  // decorations stuff.
 
761
 
 
762
  SoQtComponent::setWidgetCursor(this->getGLWidget(), cursor);
 
763
}
 
764
 
 
765
// *************************************************************************
 
766
 
 
767
#endif // ! __COIN_SOWIN__
 
768
 
 
769
// ************************************************************************
 
770
 
 
771
#ifndef DOXYGEN_SKIP_THIS
 
772
 
 
773
SoGuiFullViewerP::SoGuiFullViewerP(SoQtFullViewer * owner)
 
774
{
 
775
  this->pub = owner;
 
776
}
 
777
 
 
778
SoGuiFullViewerP::~SoGuiFullViewerP()
 
779
{
 
780
}
 
781
 
 
782
SoQtPopupMenu *
 
783
SoGuiFullViewerP::setupStandardPopupMenu(void)
 
784
{
 
785
  SoQtPopupMenu * menu = SoQtPopupMenu::createInstance();
 
786
 
 
787
  menu->newMenu("rootmenu", ROOT_MENU);
 
788
  // FIXME: none of the So*-toolkits so far uses the rootmenu title to
 
789
  // set up a title string at the top of the root popupmenu. 20010810 mortene.
 
790
  menu->setMenuTitle(ROOT_MENU, this->popupmenutitle.getString());
 
791
 
 
792
#if 0 // OBSOLETED: this looks ugly and confusing for the user. 20010810 mortene.
 
793
  // Simple hack for a common / generic way of setting up a title for
 
794
  // the popupmenu.
 
795
  menu->newMenuItem("rootmenutitle", ROOT_MENU_TITLE);
 
796
  menu->setMenuItemTitle(ROOT_MENU_TITLE, this->popupmenutitle.getString());
 
797
  menu->addMenuItem(ROOT_MENU, ROOT_MENU_TITLE);
 
798
  menu->setMenuItemEnabled(ROOT_MENU_TITLE, FALSE);
 
799
  menu->addSeparator(ROOT_MENU);
 
800
#endif // OBSOLETED
 
801
 
 
802
  menu->newMenu("functionsmenu", FUNCTIONS_MENU);
 
803
  menu->setMenuTitle(FUNCTIONS_MENU, _("Functions"));
 
804
  menu->newMenu("drawstylesmenu", DRAWSTYLES_MENU);
 
805
  menu->setMenuTitle(DRAWSTYLES_MENU, _("Draw Styles"));
 
806
  menu->newMenu("stereomenu", STEREO_MENU);
 
807
  menu->setMenuTitle(STEREO_MENU, _("Stereo Viewing"));
 
808
  menu->newMenuItem("examining", EXAMINING_ITEM);
 
809
  menu->setMenuItemTitle(EXAMINING_ITEM, _("Viewing"));
 
810
  menu->newMenuItem("decoration", DECORATION_ITEM);
 
811
  menu->setMenuItemTitle(DECORATION_ITEM, _("Decorations"));
 
812
  menu->newMenuItem("headlight", HEADLIGHT_ITEM);
 
813
  menu->setMenuItemTitle(HEADLIGHT_ITEM, _("Headlight"));
 
814
  menu->newMenuItem("fullscreen", FULLSCREEN_ITEM);
 
815
  menu->setMenuItemTitle(FULLSCREEN_ITEM, _("Fullscreen"));
 
816
 
 
817
  menu->addMenu(ROOT_MENU, FUNCTIONS_MENU);
 
818
  menu->addMenu(ROOT_MENU, DRAWSTYLES_MENU);
 
819
  menu->addMenu(ROOT_MENU, STEREO_MENU);
 
820
  menu->addMenuItem(ROOT_MENU, EXAMINING_ITEM);
 
821
  menu->addMenuItem(ROOT_MENU, DECORATION_ITEM);
 
822
  menu->addMenuItem(ROOT_MENU, HEADLIGHT_ITEM);
 
823
  menu->addMenuItem(ROOT_MENU, FULLSCREEN_ITEM);
 
824
 
 
825
  menu->newMenuItem("home", HOME_ITEM);
 
826
  menu->setMenuItemTitle(HOME_ITEM, _("Home"));
 
827
  menu->newMenuItem("set_home", SET_HOME_ITEM);
 
828
  menu->setMenuItemTitle(SET_HOME_ITEM, _("Set Home"));
 
829
  menu->newMenuItem("view_all", VIEW_ALL_ITEM);
 
830
  menu->setMenuItemTitle(VIEW_ALL_ITEM, _("View All"));
 
831
  menu->newMenuItem("seek", SEEK_ITEM);
 
832
  menu->setMenuItemTitle(SEEK_ITEM, _("Seek"));
 
833
 
 
834
  menu->addMenuItem(FUNCTIONS_MENU, HOME_ITEM);
 
835
  menu->addMenuItem(FUNCTIONS_MENU, SET_HOME_ITEM);
 
836
  menu->addMenuItem(FUNCTIONS_MENU, VIEW_ALL_ITEM);
 
837
  menu->addMenuItem(FUNCTIONS_MENU, SEEK_ITEM);
 
838
 
 
839
  menu->newMenu("drawstylesstill", DRAWSTYLES_STILL_MENU);
 
840
  menu->setMenuTitle(DRAWSTYLES_STILL_MENU, _("Still Drawstyle"));
 
841
 
 
842
  menu->newMenuItem("as_is", AS_IS_ITEM);
 
843
  menu->setMenuItemTitle(AS_IS_ITEM, _("as is"));
 
844
  menu->newMenuItem("hidden_line", HIDDEN_LINE_ITEM);
 
845
  menu->setMenuItemTitle(HIDDEN_LINE_ITEM, _("hidden line"));
 
846
  menu->newMenuItem("wireframe_overlay", WIREFRAME_OVERLAY_ITEM);
 
847
  menu->setMenuItemTitle(WIREFRAME_OVERLAY_ITEM, _("wireframe overlay"));
 
848
  menu->newMenuItem("no_textures", NO_TEXTURE_ITEM);
 
849
  menu->setMenuItemTitle(NO_TEXTURE_ITEM, _("no texture"));
 
850
  menu->newMenuItem("low_resolution", LOW_RESOLUTION_ITEM);
 
851
  menu->setMenuItemTitle(LOW_RESOLUTION_ITEM, _("low resolution"));
 
852
  menu->newMenuItem("wireframe", WIREFRAME_ITEM);
 
853
  menu->setMenuItemTitle(WIREFRAME_ITEM, _("wireframe"));
 
854
  menu->newMenuItem("points", POINTS_ITEM);
 
855
  menu->setMenuItemTitle(POINTS_ITEM, _("points"));
 
856
  menu->newMenuItem("bounding_box", BOUNDING_BOX_ITEM);
 
857
  menu->setMenuItemTitle(BOUNDING_BOX_ITEM, _("bounding box (no depth)"));
 
858
 
 
859
  menu->newRadioGroup(STILL_GROUP);
 
860
  menu->addRadioGroupItem(STILL_GROUP, AS_IS_ITEM);
 
861
  menu->addRadioGroupItem(STILL_GROUP, HIDDEN_LINE_ITEM);
 
862
  menu->addRadioGroupItem(STILL_GROUP, WIREFRAME_OVERLAY_ITEM);
 
863
  menu->addRadioGroupItem(STILL_GROUP, NO_TEXTURE_ITEM);
 
864
  menu->addRadioGroupItem(STILL_GROUP, LOW_RESOLUTION_ITEM);
 
865
  menu->addRadioGroupItem(STILL_GROUP, WIREFRAME_ITEM);
 
866
  menu->addRadioGroupItem(STILL_GROUP, POINTS_ITEM);
 
867
  menu->addRadioGroupItem(STILL_GROUP, BOUNDING_BOX_ITEM);
 
868
 
 
869
  menu->addMenuItem(DRAWSTYLES_STILL_MENU, AS_IS_ITEM);
 
870
  menu->addMenuItem(DRAWSTYLES_STILL_MENU, HIDDEN_LINE_ITEM);
 
871
  menu->addMenuItem(DRAWSTYLES_STILL_MENU, WIREFRAME_OVERLAY_ITEM);
 
872
  menu->addMenuItem(DRAWSTYLES_STILL_MENU, NO_TEXTURE_ITEM);
 
873
  menu->addMenuItem(DRAWSTYLES_STILL_MENU, LOW_RESOLUTION_ITEM);
 
874
  menu->addMenuItem(DRAWSTYLES_STILL_MENU, WIREFRAME_ITEM);
 
875
  menu->addMenuItem(DRAWSTYLES_STILL_MENU, POINTS_ITEM);
 
876
  menu->addMenuItem(DRAWSTYLES_STILL_MENU, BOUNDING_BOX_ITEM);
 
877
 
 
878
  menu->newMenu("drawstylesanimation", DRAWSTYLES_ANIMATING_MENU);
 
879
  menu->setMenuTitle(DRAWSTYLES_ANIMATING_MENU, _("Animating Drawstyle"));
 
880
 
 
881
  menu->newMenuItem("move_same_as_still", MOVE_SAME_AS_STILL_ITEM);
 
882
  menu->setMenuItemTitle(MOVE_SAME_AS_STILL_ITEM, _("same as still"));
 
883
  menu->newMenuItem("move_no_texture", MOVE_NO_TEXTURE_ITEM);
 
884
  menu->setMenuItemTitle(MOVE_NO_TEXTURE_ITEM, _("no texture"));
 
885
  menu->newMenuItem("move_low_res", MOVE_LOW_RES_ITEM);
 
886
  menu->setMenuItemTitle(MOVE_LOW_RES_ITEM, _("low resolution"));
 
887
  menu->newMenuItem("move_wireframe", MOVE_WIREFRAME_ITEM);
 
888
  menu->setMenuItemTitle(MOVE_WIREFRAME_ITEM, _("wireframe"));
 
889
  menu->newMenuItem("move_low_res_wireframe", MOVE_LOW_RES_WIREFRAME_ITEM);
 
890
  menu->setMenuItemTitle(MOVE_LOW_RES_WIREFRAME_ITEM,
 
891
    _("low res wireframe (no depth)"));
 
892
  menu->newMenuItem("move_points", MOVE_POINTS_ITEM);
 
893
  menu->setMenuItemTitle(MOVE_POINTS_ITEM, _("points"));
 
894
  menu->newMenuItem("move_low_res_points", MOVE_LOW_RES_POINTS_ITEM);
 
895
  menu->setMenuItemTitle(MOVE_LOW_RES_POINTS_ITEM,
 
896
    _("low res points (no depth)"));
 
897
  menu->newMenuItem("move_bounding_box", MOVE_BOUNDING_BOX_ITEM);
 
898
  menu->setMenuItemTitle(MOVE_BOUNDING_BOX_ITEM, _("bounding box (no depth)"));
 
899
 
 
900
  menu->newRadioGroup(MOVE_GROUP);
 
901
  menu->addRadioGroupItem(MOVE_GROUP, MOVE_SAME_AS_STILL_ITEM);
 
902
  menu->addRadioGroupItem(MOVE_GROUP, MOVE_NO_TEXTURE_ITEM);
 
903
  menu->addRadioGroupItem(MOVE_GROUP, MOVE_LOW_RES_ITEM);
 
904
  menu->addRadioGroupItem(MOVE_GROUP, MOVE_WIREFRAME_ITEM);
 
905
  menu->addRadioGroupItem(MOVE_GROUP, MOVE_LOW_RES_WIREFRAME_ITEM);
 
906
  menu->addRadioGroupItem(MOVE_GROUP, MOVE_POINTS_ITEM);
 
907
  menu->addRadioGroupItem(MOVE_GROUP, MOVE_LOW_RES_POINTS_ITEM);
 
908
  menu->addRadioGroupItem(MOVE_GROUP, MOVE_BOUNDING_BOX_ITEM);
 
909
 
 
910
  menu->addMenuItem(DRAWSTYLES_ANIMATING_MENU, MOVE_SAME_AS_STILL_ITEM);
 
911
  menu->addMenuItem(DRAWSTYLES_ANIMATING_MENU, MOVE_NO_TEXTURE_ITEM);
 
912
  menu->addMenuItem(DRAWSTYLES_ANIMATING_MENU, MOVE_LOW_RES_ITEM);
 
913
  menu->addMenuItem(DRAWSTYLES_ANIMATING_MENU, MOVE_WIREFRAME_ITEM);
 
914
  menu->addMenuItem(DRAWSTYLES_ANIMATING_MENU, MOVE_LOW_RES_WIREFRAME_ITEM);
 
915
  menu->addMenuItem(DRAWSTYLES_ANIMATING_MENU, MOVE_POINTS_ITEM);
 
916
  menu->addMenuItem(DRAWSTYLES_ANIMATING_MENU, MOVE_LOW_RES_POINTS_ITEM);
 
917
  menu->addMenuItem(DRAWSTYLES_ANIMATING_MENU, MOVE_BOUNDING_BOX_ITEM);
 
918
 
 
919
  menu->newMenu("transparencytype", TRANSPARENCY_TYPE_MENU);
 
920
  menu->setMenuTitle(TRANSPARENCY_TYPE_MENU, _("Transparency Type"));
 
921
  menu->newRadioGroup(TRANSPARENCY_GROUP);
 
922
 
 
923
  { // Fill in menu items in radiomenu with transparency selections.
 
924
 
 
925
    struct menutransparencyitem {
 
926
      const char * name, * title;
 
927
      int id;
 
928
    };
 
929
 
 
930
    struct menutransparencyitem items[] = {
 
931
#ifdef __COIN__
 
932
      { "none", _("none"), NONE_TRANSPARENCY_ITEM },
 
933
#endif // __COIN__
 
934
      { "screen_door", _("screen door"), SCREEN_DOOR_TRANSPARENCY_ITEM },
 
935
      { "add", _("add"), ADD_TRANSPARENCY_ITEM },
 
936
      { "delayed_add", _("delayed add"), DELAYED_ADD_TRANSPARENCY_ITEM },
 
937
      { "sorted_object_add", _("sorted object add"), SORTED_OBJECT_ADD_TRANSPARENCY_ITEM },
 
938
      { "blend", _("blend"), BLEND_TRANSPARENCY_ITEM },
 
939
      { "delayed_blend", _("delayed blend"), DELAYED_BLEND_TRANSPARENCY_ITEM },
 
940
      { "sorted_object_blend", _("sorted object blend"), SORTED_OBJECT_BLEND_TRANSPARENCY_ITEM }
 
941
#ifdef __COIN__ // Coin extensions
 
942
      ,
 
943
      { "sorted_object_sorted_triangle_add", _("sorted object sorted triangle add"), SORTED_OBJECT_SORTED_TRIANGLE_ADD_TRANSPARENCY_ITEM },
 
944
      { "sorted_object_sorted_triangle_blend", _("sorted object sorted triangle blend"), SORTED_OBJECT_SORTED_TRIANGLE_BLEND_TRANSPARENCY_ITEM }
 
945
#endif // __COIN__
 
946
#ifdef HAVE_SORTED_LAYERS_BLEND
 
947
      , { "sorted_layers_blend", _("sorted layers blend"), SORTED_LAYERS_BLEND_ITEM }
 
948
#endif // HAVE_SORTED_LAYERS_BLEND
 
949
    };
 
950
 
 
951
    int nritems = sizeof(items) / sizeof(struct menutransparencyitem);
 
952
    for (int i = 0; i < nritems; i++) {
 
953
      menu->newMenuItem(items[i].name, items[i].id);
 
954
      menu->setMenuItemTitle(items[i].id, items[i].title);
 
955
      menu->addRadioGroupItem(TRANSPARENCY_GROUP, items[i].id);
 
956
      menu->addMenuItem(TRANSPARENCY_TYPE_MENU, items[i].id);
 
957
    }
 
958
  }
 
959
 
 
960
  menu->newMenuItem("stereooff", STEREO_OFF_ITEM);
 
961
  menu->newMenuItem("stereoredcyan", STEREO_ANAGLYPH_ITEM);
 
962
  menu->newMenuItem("stereoquadbuffer", STEREO_QUADBUFFER_ITEM);
 
963
  menu->setMenuItemTitle(STEREO_OFF_ITEM, _("Off"));
 
964
  menu->setMenuItemTitle(STEREO_ANAGLYPH_ITEM, _("Red/Cyan Anaglyph"));
 
965
  menu->setMenuItemTitle(STEREO_QUADBUFFER_ITEM, _("Quad buffer"));
 
966
 
 
967
  menu->newMenuItem("stereointerleavedrows", STEREO_INTERLEAVED_ROWS_ITEM);
 
968
  menu->setMenuItemTitle(STEREO_INTERLEAVED_ROWS_ITEM, _("Interleaved Rows"));
 
969
  menu->newMenuItem("stereointerleavedcolumns", STEREO_INTERLEAVED_COLUMNS_ITEM);
 
970
  menu->setMenuItemTitle(STEREO_INTERLEAVED_COLUMNS_ITEM, _("Interleaved Columns"));
 
971
 
 
972
  menu->newRadioGroup(STEREO_GROUP);
 
973
  menu->addRadioGroupItem(STEREO_GROUP, STEREO_OFF_ITEM);
 
974
  menu->addRadioGroupItem(STEREO_GROUP, STEREO_ANAGLYPH_ITEM);
 
975
  menu->addRadioGroupItem(STEREO_GROUP, STEREO_QUADBUFFER_ITEM);
 
976
  menu->addRadioGroupItem(STEREO_GROUP, STEREO_INTERLEAVED_ROWS_ITEM);
 
977
  menu->addRadioGroupItem(STEREO_GROUP, STEREO_INTERLEAVED_COLUMNS_ITEM);
 
978
 
 
979
  menu->addMenuItem(STEREO_MENU, STEREO_OFF_ITEM);
 
980
  menu->addMenuItem(STEREO_MENU, STEREO_ANAGLYPH_ITEM);
 
981
  menu->addMenuItem(STEREO_MENU, STEREO_QUADBUFFER_ITEM);
 
982
  menu->addMenuItem(STEREO_MENU, STEREO_INTERLEAVED_ROWS_ITEM);
 
983
  menu->addMenuItem(STEREO_MENU, STEREO_INTERLEAVED_COLUMNS_ITEM);
 
984
 
 
985
  menu->newMenu("renderbuffertype", RENDER_BUFFER_TYPE_MENU);
 
986
  menu->setMenuTitle(RENDER_BUFFER_TYPE_MENU, _("Render Buffer Type"));
 
987
 
 
988
  menu->newMenuItem("single_buffer", SINGLE_BUFFER_ITEM);
 
989
  menu->setMenuItemTitle(SINGLE_BUFFER_ITEM, _("single"));
 
990
  menu->newMenuItem("double_buffer", DOUBLE_BUFFER_ITEM);
 
991
  menu->setMenuItemTitle(DOUBLE_BUFFER_ITEM, _("double"));
 
992
  menu->newMenuItem("interactive_buffer", INTERACTIVE_BUFFER_ITEM);
 
993
  menu->setMenuItemTitle(INTERACTIVE_BUFFER_ITEM, _("interactive"));
 
994
 
 
995
  menu->newRadioGroup(BUFFER_GROUP);
 
996
  menu->addRadioGroupItem(BUFFER_GROUP, SINGLE_BUFFER_ITEM);
 
997
  menu->addRadioGroupItem(BUFFER_GROUP, DOUBLE_BUFFER_ITEM);
 
998
  menu->addRadioGroupItem(BUFFER_GROUP, INTERACTIVE_BUFFER_ITEM);
 
999
 
 
1000
  menu->addMenuItem(RENDER_BUFFER_TYPE_MENU, SINGLE_BUFFER_ITEM);
 
1001
  menu->addMenuItem(RENDER_BUFFER_TYPE_MENU, DOUBLE_BUFFER_ITEM);
 
1002
  menu->addMenuItem(RENDER_BUFFER_TYPE_MENU, INTERACTIVE_BUFFER_ITEM);
 
1003
 
 
1004
  menu->addMenu(DRAWSTYLES_MENU, DRAWSTYLES_STILL_MENU);
 
1005
  menu->addMenu(DRAWSTYLES_MENU, DRAWSTYLES_ANIMATING_MENU);
 
1006
  menu->addMenu(DRAWSTYLES_MENU, TRANSPARENCY_TYPE_MENU);
 
1007
  menu->addMenu(DRAWSTYLES_MENU, RENDER_BUFFER_TYPE_MENU);
 
1008
 
 
1009
  int toggle;
 
1010
  toggle = menu->newRadioGroup();
 
1011
  menu->addRadioGroupItem(toggle, EXAMINING_ITEM);
 
1012
  toggle = menu->newRadioGroup();
 
1013
  menu->addRadioGroupItem(toggle, DECORATION_ITEM);
 
1014
  toggle = menu->newRadioGroup();
 
1015
  menu->addRadioGroupItem(toggle, HEADLIGHT_ITEM);
 
1016
  toggle = menu->newRadioGroup();
 
1017
  menu->addRadioGroupItem(toggle, FULLSCREEN_ITEM);
 
1018
 
 
1019
  menu->addMenuSelectionCallback(SoGuiFullViewerP::menuSelectionCallback,
 
1020
                                 (void *) this);
 
1021
 
 
1022
  PUBLIC(this)->prefmenu = menu;
 
1023
  return menu;
 
1024
}
 
1025
 
 
1026
// ************************************************************************
 
1027
 
 
1028
void
 
1029
SoGuiFullViewerP::prepareMenu(SoQtPopupMenu * menu)
 
1030
{
 
1031
  //// Misc. //////////////////////////////////////////////////////////
 
1032
  menu->setMenuItemMarked(DECORATION_ITEM, PUBLIC(this)->isDecoration());
 
1033
  menu->setMenuItemMarked(EXAMINING_ITEM, PUBLIC(this)->isViewing());
 
1034
  menu->setMenuItemMarked(HEADLIGHT_ITEM, PUBLIC(this)->isHeadlight());
 
1035
  menu->setMenuItemMarked(FULLSCREEN_ITEM, PUBLIC(this)->isFullScreen());
 
1036
 
 
1037
  //// Basic drawstyles. //////////////////////////////////////////////
 
1038
  this->setDrawStyleMenuActivation(SoQtFullViewer::STILL,
 
1039
                                   PUBLIC(this)->getDrawStyle(SoQtFullViewer::STILL));
 
1040
  this->setDrawStyleMenuActivation(SoQtFullViewer::INTERACTIVE,
 
1041
                                   PUBLIC(this)->getDrawStyle(SoQtFullViewer::INTERACTIVE));
 
1042
 
 
1043
  //// Transparency setting. //////////////////////////////////////////
 
1044
  switch (PUBLIC(this)->getTransparencyType()) {
 
1045
  case SoGLRenderAction::SCREEN_DOOR:
 
1046
    menu->setMenuItemMarked(SCREEN_DOOR_TRANSPARENCY_ITEM, TRUE);
 
1047
    break;
 
1048
  case SoGLRenderAction::ADD:
 
1049
    menu->setMenuItemMarked(ADD_TRANSPARENCY_ITEM, TRUE);
 
1050
    break;
 
1051
  case SoGLRenderAction::DELAYED_ADD:
 
1052
    menu->setMenuItemMarked(DELAYED_ADD_TRANSPARENCY_ITEM, TRUE);
 
1053
    break;
 
1054
  case SoGLRenderAction::SORTED_OBJECT_ADD:
 
1055
    menu->setMenuItemMarked(SORTED_OBJECT_ADD_TRANSPARENCY_ITEM, TRUE);
 
1056
    break;
 
1057
  case SoGLRenderAction::BLEND:
 
1058
    menu->setMenuItemMarked(BLEND_TRANSPARENCY_ITEM, TRUE);
 
1059
    break;
 
1060
  case SoGLRenderAction::DELAYED_BLEND:
 
1061
    menu->setMenuItemMarked(DELAYED_BLEND_TRANSPARENCY_ITEM, TRUE);
 
1062
    break;
 
1063
  case SoGLRenderAction::SORTED_OBJECT_BLEND:
 
1064
    menu->setMenuItemMarked(SORTED_OBJECT_BLEND_TRANSPARENCY_ITEM, TRUE);
 
1065
    break;
 
1066
#ifdef __COIN__  // Coin extensions
 
1067
  case SoGLRenderAction::NONE:
 
1068
    menu->setMenuItemMarked(NONE_TRANSPARENCY_ITEM, TRUE);
 
1069
    break;
 
1070
  case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD:
 
1071
    menu->setMenuItemMarked(SORTED_OBJECT_SORTED_TRIANGLE_ADD_TRANSPARENCY_ITEM, TRUE);
 
1072
    break;
 
1073
  case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND:
 
1074
    menu->setMenuItemMarked(SORTED_OBJECT_SORTED_TRIANGLE_BLEND_TRANSPARENCY_ITEM, TRUE);
 
1075
    break;
 
1076
#endif // __COIN__
 
1077
#ifdef HAVE_SORTED_LAYERS_BLEND
 
1078
  case SoGLRenderAction::SORTED_LAYERS_BLEND:
 
1079
    menu->setMenuItemMarked(SORTED_LAYERS_BLEND_ITEM, TRUE);
 
1080
    break;
 
1081
#endif // HAVE_SORTED_LAYERS_BLEND
 
1082
  default:
 
1083
#if SOQT_DEBUG
 
1084
    SoDebugError::postInfo("SoGuiFullViewerP::prepareMenu",
 
1085
                           "Unknown transparency type");
 
1086
#endif // SOQT_DEBUG
 
1087
    break;
 
1088
  }
 
1089
 
 
1090
  //// Stereo viewing. ////////////////////////////////////////////////
 
1091
 
 
1092
  const SoQtViewer::StereoType type = PUBLIC(this)->getStereoType();
 
1093
  switch (type) {
 
1094
  case SoQtViewer::STEREO_NONE:
 
1095
    menu->setMenuItemMarked(STEREO_OFF_ITEM, TRUE);
 
1096
    break;
 
1097
  case SoQtViewer::STEREO_ANAGLYPH:
 
1098
    menu->setMenuItemMarked(STEREO_ANAGLYPH_ITEM, TRUE);
 
1099
    break;
 
1100
  case SoQtViewer::STEREO_QUADBUFFER:
 
1101
    menu->setMenuItemMarked(STEREO_QUADBUFFER_ITEM, TRUE);
 
1102
    break;
 
1103
  case SoQtViewer::STEREO_INTERLEAVED_ROWS:
 
1104
    menu->setMenuItemMarked(STEREO_INTERLEAVED_ROWS_ITEM, TRUE);
 
1105
    break;
 
1106
  case SoQtViewer::STEREO_INTERLEAVED_COLUMNS:
 
1107
    menu->setMenuItemMarked(STEREO_INTERLEAVED_COLUMNS_ITEM, TRUE);
 
1108
    break;
 
1109
  default:
 
1110
    assert(FALSE); break;
 
1111
  }
 
1112
 
 
1113
  //// GL canvas settings. ////////////////////////////////////////////
 
1114
  switch (PUBLIC(this)->getBufferingType()) {
 
1115
  case SoQtViewer::BUFFER_SINGLE:
 
1116
    menu->setMenuItemMarked(SINGLE_BUFFER_ITEM, TRUE);
 
1117
    break;
 
1118
  case SoQtViewer::BUFFER_DOUBLE:
 
1119
    menu->setMenuItemMarked(DOUBLE_BUFFER_ITEM, TRUE);
 
1120
    break;
 
1121
  case SoQtViewer::BUFFER_INTERACTIVE:
 
1122
    menu->setMenuItemMarked(INTERACTIVE_BUFFER_ITEM, TRUE);
 
1123
    break;
 
1124
  default:
 
1125
#if SOQT_DEBUG
 
1126
    SoDebugError::postInfo("SoGuiFullViewerP::prepareMenu",
 
1127
                           "Unknown buffer type");
 
1128
#endif // SOQT_DEBUG
 
1129
    break;
 
1130
  }
 
1131
}
 
1132
 
 
1133
// ************************************************************************
 
1134
 
 
1135
void
 
1136
SoGuiFullViewerP::menuSelection(int menuitemid)
 
1137
{
 
1138
  SbBool ok;
 
1139
 
 
1140
  switch (menuitemid) {
 
1141
  case -1:
 
1142
    // means no item was selected
 
1143
#if SOQT_DEBUG
 
1144
    SoDebugError::postInfo("SoGuiFullViewerP::menuSelection",
 
1145
                           "-1 not appropriate on callback usage");
 
1146
#endif // SOQT_DEBUG
 
1147
    break;
 
1148
 
 
1149
  case EXAMINING_ITEM:
 
1150
    PUBLIC(this)->setViewing(PUBLIC(this)->isViewing() ? FALSE : TRUE);
 
1151
    break;
 
1152
  case DECORATION_ITEM:
 
1153
    PUBLIC(this)->setDecoration(PUBLIC(this)->isDecoration() ? FALSE : TRUE);
 
1154
    break;
 
1155
  case HEADLIGHT_ITEM:
 
1156
    PUBLIC(this)->setHeadlight(PUBLIC(this)->isHeadlight() ? FALSE : TRUE);
 
1157
    break;
 
1158
  case FULLSCREEN_ITEM:
 
1159
    (void)PUBLIC(this)->setFullScreen(PUBLIC(this)->isFullScreen() ? FALSE : TRUE);
 
1160
    break;
 
1161
 
 
1162
  case HOME_ITEM:
 
1163
    PUBLIC(this)->resetToHomePosition();
 
1164
    break;
 
1165
  case SET_HOME_ITEM:
 
1166
    PUBLIC(this)->saveHomePosition();
 
1167
    break;
 
1168
  case VIEW_ALL_ITEM:
 
1169
    PUBLIC(this)->viewAll();
 
1170
    break;
 
1171
  case SEEK_ITEM:
 
1172
    ((SoQtFullViewerP *)this)->seekbuttonClicked();
 
1173
    break;
 
1174
 
 
1175
  case AS_IS_ITEM:
 
1176
  case HIDDEN_LINE_ITEM:
 
1177
  case WIREFRAME_OVERLAY_ITEM:
 
1178
  case NO_TEXTURE_ITEM:
 
1179
  case LOW_RESOLUTION_ITEM:
 
1180
  case WIREFRAME_ITEM:
 
1181
  case POINTS_ITEM:
 
1182
  case BOUNDING_BOX_ITEM:
 
1183
    this->drawstyleActivated(menuitemid);
 
1184
    break;
 
1185
 
 
1186
  case MOVE_SAME_AS_STILL_ITEM:
 
1187
  case MOVE_NO_TEXTURE_ITEM:
 
1188
  case MOVE_LOW_RES_ITEM:
 
1189
  case MOVE_WIREFRAME_ITEM:
 
1190
  case MOVE_LOW_RES_WIREFRAME_ITEM:
 
1191
  case MOVE_POINTS_ITEM:
 
1192
  case MOVE_LOW_RES_POINTS_ITEM:
 
1193
  case MOVE_BOUNDING_BOX_ITEM:
 
1194
    this->drawstyleActivated(menuitemid);
 
1195
    break;
 
1196
 
 
1197
  case SCREEN_DOOR_TRANSPARENCY_ITEM:
 
1198
  case ADD_TRANSPARENCY_ITEM:
 
1199
  case DELAYED_ADD_TRANSPARENCY_ITEM:
 
1200
  case SORTED_OBJECT_ADD_TRANSPARENCY_ITEM:
 
1201
  case BLEND_TRANSPARENCY_ITEM:
 
1202
  case DELAYED_BLEND_TRANSPARENCY_ITEM:
 
1203
  case SORTED_OBJECT_BLEND_TRANSPARENCY_ITEM:
 
1204
  case SORTED_OBJECT_SORTED_TRIANGLE_ADD_TRANSPARENCY_ITEM:
 
1205
  case SORTED_OBJECT_SORTED_TRIANGLE_BLEND_TRANSPARENCY_ITEM:
 
1206
  case NONE_TRANSPARENCY_ITEM:
 
1207
  case SORTED_LAYERS_BLEND_ITEM: // define test is not needed. This enum is always defined
 
1208
    this->drawstyleActivated(menuitemid);
 
1209
    PUBLIC(this)->scheduleRedraw();
 
1210
    break;
 
1211
 
 
1212
  case SINGLE_BUFFER_ITEM:
 
1213
  case DOUBLE_BUFFER_ITEM:
 
1214
  case INTERACTIVE_BUFFER_ITEM:
 
1215
    this->drawstyleActivated(menuitemid);
 
1216
    break;
 
1217
 
 
1218
  case STEREO_OFF_ITEM:
 
1219
    ok = PUBLIC(this)->setStereoType(SoQtViewer::STEREO_NONE);
 
1220
    assert(ok);
 
1221
    break;
 
1222
  case STEREO_ANAGLYPH_ITEM:
 
1223
    ok = PUBLIC(this)->setStereoType(SoQtViewer::STEREO_ANAGLYPH);
 
1224
    assert(ok && "anaglyph stereo should always be possible");
 
1225
    break;
 
1226
  case STEREO_QUADBUFFER_ITEM:
 
1227
    ok = PUBLIC(this)->setStereoType(SoQtViewer::STEREO_QUADBUFFER);
 
1228
    if (!ok) { PUBLIC(this)->setStereoType(SoQtViewer::STEREO_NONE); }
 
1229
    break;
 
1230
  case STEREO_INTERLEAVED_ROWS_ITEM:
 
1231
    ok = PUBLIC(this)->setStereoType(SoQtViewer::STEREO_INTERLEAVED_ROWS);
 
1232
    if (!ok) { PUBLIC(this)->setStereoType(SoQtViewer::STEREO_NONE); }
 
1233
    break;
 
1234
  case STEREO_INTERLEAVED_COLUMNS_ITEM:
 
1235
    ok = PUBLIC(this)->setStereoType(SoQtViewer::STEREO_INTERLEAVED_COLUMNS);
 
1236
    if (!ok) { PUBLIC(this)->setStereoType(SoQtViewer::STEREO_NONE); }
 
1237
    break;
 
1238
 
 
1239
  default:
 
1240
    SoDebugError::postInfo("SoGuiFullViewerP::menuSelection",
 
1241
                           "popup menu handling for item %d is not implemented", 
 
1242
                           menuitemid);
 
1243
    break;
 
1244
  }
 
1245
}
 
1246
 
 
1247
 
 
1248
// ************************************************************************
 
1249
 
 
1250
void
 
1251
SoGuiFullViewerP::menuSelectionCallback(int menuitemid,
 
1252
                                        void * userdata)
 
1253
{
 
1254
  SoGuiFullViewerP * viewer = (SoGuiFullViewerP *) userdata;
 
1255
  viewer->menuSelection(menuitemid);
 
1256
}
 
1257
 
 
1258
// ************************************************************************
 
1259
 
 
1260
void
 
1261
SoGuiFullViewerP::setDrawStyleMenuActivation(SoQtViewer::DrawType type,
 
1262
                                             SoQtViewer::DrawStyle value)
 
1263
{
 
1264
  assert(PUBLIC(this)->prefmenu != NULL);
 
1265
 
 
1266
  switch (type) {
 
1267
  case SoQtViewer::STILL:
 
1268
    switch (value) {
 
1269
    case SoQtViewer::VIEW_AS_IS:
 
1270
      PUBLIC(this)->prefmenu->setMenuItemMarked(AS_IS_ITEM, TRUE);
 
1271
      break;
 
1272
    case SoQtViewer::VIEW_HIDDEN_LINE:
 
1273
      PUBLIC(this)->prefmenu->setMenuItemMarked(HIDDEN_LINE_ITEM, TRUE);
 
1274
      break;
 
1275
    case SoQtViewer::VIEW_WIREFRAME_OVERLAY:
 
1276
      PUBLIC(this)->prefmenu->setMenuItemMarked(WIREFRAME_OVERLAY_ITEM, TRUE);
 
1277
      break;
 
1278
    case SoQtViewer::VIEW_NO_TEXTURE:
 
1279
      PUBLIC(this)->prefmenu->setMenuItemMarked(NO_TEXTURE_ITEM, TRUE);
 
1280
      break;
 
1281
    case SoQtViewer::VIEW_LOW_COMPLEXITY:
 
1282
      PUBLIC(this)->prefmenu->setMenuItemMarked(LOW_RESOLUTION_ITEM, TRUE);
 
1283
      break;
 
1284
    case SoQtViewer::VIEW_LOW_RES_LINE:
 
1285
#if SOQT_DEBUG
 
1286
      SoDebugError::postWarning("SoQtFullViewer::setDrawStyleMenuActivation",
 
1287
                                "Use VIEW_LINE, not VIEW_LOW_RES_LINE for the STILL drawstyle.");
 
1288
#endif // debug
 
1289
    case SoQtViewer::VIEW_LINE:
 
1290
      PUBLIC(this)->prefmenu->setMenuItemMarked(WIREFRAME_ITEM, TRUE);
 
1291
      break;
 
1292
    case SoQtViewer::VIEW_LOW_RES_POINT:
 
1293
#if SOQT_DEBUG
 
1294
      SoDebugError::postWarning("SoQtFullViewer::setDrawStyleMenuActivation",
 
1295
                                "Use VIEW_POINT, not VIEW_LOW_RES_POINT for the STILL drawstyle.");
 
1296
#endif // debug
 
1297
    case SoQtViewer::VIEW_POINT:
 
1298
      PUBLIC(this)->prefmenu->setMenuItemMarked(POINTS_ITEM, TRUE);
 
1299
      break;
 
1300
    case SoQtViewer::VIEW_BBOX:
 
1301
      PUBLIC(this)->prefmenu->setMenuItemMarked(BOUNDING_BOX_ITEM, TRUE);
 
1302
      break;
 
1303
    default:
 
1304
#if SOQT_DEBUG
 
1305
      SoDebugError::postWarning("SoQtFullViewer::setDrawStyleMenuActivation",
 
1306
                                "Unsupporter still-drawstyle");
 
1307
#endif // debug
 
1308
      break;
 
1309
    }
 
1310
    break;
 
1311
 
 
1312
  case SoQtViewer::INTERACTIVE:
 
1313
    switch (value) {
 
1314
    case SoQtViewer::VIEW_SAME_AS_STILL:
 
1315
      PUBLIC(this)->prefmenu->setMenuItemMarked(MOVE_SAME_AS_STILL_ITEM, TRUE);
 
1316
      break;
 
1317
    case SoQtViewer::VIEW_NO_TEXTURE:
 
1318
      PUBLIC(this)->prefmenu->setMenuItemMarked(MOVE_NO_TEXTURE_ITEM, TRUE);
 
1319
      break;
 
1320
    case SoQtViewer::VIEW_LOW_COMPLEXITY:
 
1321
      PUBLIC(this)->prefmenu->setMenuItemMarked(MOVE_LOW_RES_ITEM, TRUE);
 
1322
      break;
 
1323
    case SoQtViewer::VIEW_LINE:
 
1324
      PUBLIC(this)->prefmenu->setMenuItemMarked(MOVE_WIREFRAME_ITEM, TRUE);
 
1325
      break;
 
1326
    case SoQtViewer::VIEW_LOW_RES_LINE:
 
1327
      PUBLIC(this)->prefmenu->setMenuItemMarked(MOVE_LOW_RES_WIREFRAME_ITEM, TRUE);
 
1328
      break;
 
1329
    case SoQtViewer::VIEW_POINT:
 
1330
      PUBLIC(this)->prefmenu->setMenuItemMarked(MOVE_POINTS_ITEM, TRUE);
 
1331
      break;
 
1332
    case SoQtViewer::VIEW_LOW_RES_POINT:
 
1333
      PUBLIC(this)->prefmenu->setMenuItemMarked(MOVE_LOW_RES_POINTS_ITEM, TRUE);
 
1334
      break;
 
1335
    case SoQtViewer::VIEW_BBOX:
 
1336
      PUBLIC(this)->prefmenu->setMenuItemMarked(MOVE_BOUNDING_BOX_ITEM, TRUE);
 
1337
      break;
 
1338
    default:
 
1339
#if SOQT_DEBUG
 
1340
      SoDebugError::postWarning("SoQtFullViewer::setDrawStyleMenuActivation",
 
1341
                                "Unsupporter interactive drawstyle");
 
1342
#endif // debug
 
1343
      break;
 
1344
    }
 
1345
    break;
 
1346
 
 
1347
  default:
 
1348
#if SOQT_DEBUG
 
1349
    SoDebugError::postWarning("SoQtFullViewer::setDrawStyleMenuActivation",
 
1350
                              "Unsupporter drawstyle type");
 
1351
#endif // debug
 
1352
    break;
 
1353
  }
 
1354
}
 
1355
 
 
1356
// ************************************************************************
 
1357
 
 
1358
void
 
1359
SoGuiFullViewerP::drawstyleActivated(int menuitemid)
 
1360
{
 
1361
  switch (menuitemid) {
 
1362
  case SINGLE_BUFFER_ITEM:
 
1363
    PUBLIC(this)->setBufferingType(SoQtViewer::BUFFER_SINGLE);
 
1364
    return;
 
1365
  case DOUBLE_BUFFER_ITEM:
 
1366
    PUBLIC(this)->setBufferingType(SoQtViewer::BUFFER_DOUBLE);
 
1367
    return;
 
1368
  case INTERACTIVE_BUFFER_ITEM:
 
1369
    PUBLIC(this)->setBufferingType(SoQtViewer::BUFFER_INTERACTIVE);
 
1370
    return;
 
1371
  default:
 
1372
    break;
 
1373
  }
 
1374
 
 
1375
  // FIXME: should perhaps override transparency type to be screendoor
 
1376
  // if we detect that the OpenGL canvas has 0 alpha bits available?
 
1377
  // 20030626 mortene.
 
1378
  switch (menuitemid) {
 
1379
  case SCREEN_DOOR_TRANSPARENCY_ITEM:
 
1380
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::SCREEN_DOOR);
 
1381
    return;
 
1382
  case ADD_TRANSPARENCY_ITEM:
 
1383
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::ADD);
 
1384
    return;
 
1385
  case DELAYED_ADD_TRANSPARENCY_ITEM:
 
1386
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::DELAYED_ADD);
 
1387
    return;
 
1388
  case SORTED_OBJECT_ADD_TRANSPARENCY_ITEM:
 
1389
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
 
1390
    return;
 
1391
  case BLEND_TRANSPARENCY_ITEM:
 
1392
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::BLEND);
 
1393
    return;
 
1394
  case DELAYED_BLEND_TRANSPARENCY_ITEM:
 
1395
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::DELAYED_BLEND);
 
1396
    return;
 
1397
  case SORTED_OBJECT_BLEND_TRANSPARENCY_ITEM:
 
1398
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
 
1399
    return;
 
1400
#ifdef __COIN__ // Coin extensions
 
1401
  case NONE_TRANSPARENCY_ITEM:
 
1402
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::NONE);
 
1403
    return;
 
1404
  case SORTED_OBJECT_SORTED_TRIANGLE_ADD_TRANSPARENCY_ITEM:
 
1405
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD);
 
1406
    return;
 
1407
  case SORTED_OBJECT_SORTED_TRIANGLE_BLEND_TRANSPARENCY_ITEM:
 
1408
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND);
 
1409
    return;
 
1410
#endif // __COIN__
 
1411
#ifdef HAVE_SORTED_LAYERS_BLEND
 
1412
  case SORTED_LAYERS_BLEND_ITEM:
 
1413
    PUBLIC(this)->setTransparencyType(SoGLRenderAction::SORTED_LAYERS_BLEND);
 
1414
    return;
 
1415
#endif // HAVE_SORTED_LAYERS_BLEND
 
1416
  default:
 
1417
    // some other menu item, just continue
 
1418
    break;
 
1419
  }
 
1420
 
 
1421
  SoQtViewer::DrawStyle val = SoQtViewer::VIEW_AS_IS;
 
1422
  switch (menuitemid) {
 
1423
  case AS_IS_ITEM:
 
1424
    val = SoQtViewer::VIEW_AS_IS;
 
1425
    break;
 
1426
  case HIDDEN_LINE_ITEM:
 
1427
    val = SoQtViewer::VIEW_HIDDEN_LINE;
 
1428
    break;
 
1429
  case WIREFRAME_OVERLAY_ITEM:
 
1430
    val = SoQtViewer::VIEW_WIREFRAME_OVERLAY;
 
1431
    break;
 
1432
  case NO_TEXTURE_ITEM:
 
1433
    val = SoQtViewer::VIEW_NO_TEXTURE;
 
1434
    break;
 
1435
  case LOW_RESOLUTION_ITEM:
 
1436
    val = SoQtViewer::VIEW_LOW_COMPLEXITY;
 
1437
    break;
 
1438
  case WIREFRAME_ITEM:
 
1439
    val = SoQtViewer::VIEW_LINE;
 
1440
    break;
 
1441
  case POINTS_ITEM:
 
1442
    val = SoQtViewer::VIEW_POINT;
 
1443
    break;
 
1444
  case BOUNDING_BOX_ITEM:
 
1445
    val = SoQtViewer::VIEW_BBOX;
 
1446
    break;
 
1447
 
 
1448
  case MOVE_SAME_AS_STILL_ITEM:
 
1449
    val = SoQtViewer::VIEW_SAME_AS_STILL;
 
1450
    break;
 
1451
  case MOVE_NO_TEXTURE_ITEM:
 
1452
    val = SoQtViewer::VIEW_NO_TEXTURE;
 
1453
    break;
 
1454
  case MOVE_LOW_RES_ITEM:
 
1455
    val = SoQtViewer::VIEW_LOW_COMPLEXITY;
 
1456
    break;
 
1457
  case MOVE_WIREFRAME_ITEM:
 
1458
    val = SoQtViewer::VIEW_LINE;
 
1459
    break;
 
1460
  case MOVE_LOW_RES_WIREFRAME_ITEM:
 
1461
    val = SoQtViewer::VIEW_LOW_RES_LINE;
 
1462
    break;
 
1463
  case MOVE_POINTS_ITEM:
 
1464
    val = SoQtViewer::VIEW_POINT;
 
1465
    break;
 
1466
  case MOVE_LOW_RES_POINTS_ITEM:
 
1467
    val = SoQtViewer::VIEW_LOW_RES_POINT;
 
1468
    break;
 
1469
  case MOVE_BOUNDING_BOX_ITEM:
 
1470
    val = SoQtViewer::VIEW_BBOX;
 
1471
    break;
 
1472
 
 
1473
  default:
 
1474
    assert(0);
 
1475
    break;
 
1476
  }
 
1477
 
 
1478
  SoQtViewer::DrawType type = SoQtViewer::STILL;
 
1479
 
 
1480
  switch (menuitemid) {
 
1481
  case AS_IS_ITEM:
 
1482
  case HIDDEN_LINE_ITEM:
 
1483
  case WIREFRAME_OVERLAY_ITEM:
 
1484
  case NO_TEXTURE_ITEM:
 
1485
  case LOW_RESOLUTION_ITEM:
 
1486
  case WIREFRAME_ITEM:
 
1487
  case POINTS_ITEM:
 
1488
  case BOUNDING_BOX_ITEM:
 
1489
    type = SoQtViewer::STILL;
 
1490
    break;
 
1491
 
 
1492
  case MOVE_SAME_AS_STILL_ITEM:
 
1493
  case MOVE_NO_TEXTURE_ITEM:
 
1494
  case MOVE_LOW_RES_ITEM:
 
1495
  case MOVE_WIREFRAME_ITEM:
 
1496
  case MOVE_LOW_RES_WIREFRAME_ITEM:
 
1497
  case MOVE_POINTS_ITEM:
 
1498
  case MOVE_LOW_RES_POINTS_ITEM:
 
1499
  case MOVE_BOUNDING_BOX_ITEM:
 
1500
    type = SoQtViewer::INTERACTIVE;
 
1501
    break;
 
1502
 
 
1503
  default:
 
1504
    assert(0);
 
1505
    break;
 
1506
  }
 
1507
 
 
1508
  PUBLIC(this)->setDrawStyle(type, val);
 
1509
}
 
1510
 
 
1511
// ************************************************************************
 
1512
 
 
1513
// Move camera parallel with the plane orthogonal to the camera
 
1514
// direction vector.
 
1515
//
 
1516
// Used from both SoGuiPlaneViewer and SoGuiExaminerViewer.
 
1517
// Implemented in the SoGuiFullViewer private class to collect common
 
1518
// code.
 
1519
void
 
1520
SoGuiFullViewerP::pan(SoCamera * cam,
 
1521
                      float aspectratio, const SbPlane & panningplane,
 
1522
                      const SbVec2f & currpos, const SbVec2f & prevpos)
 
1523
{
 
1524
  if (cam == NULL) return; // can happen for empty scenegraph
 
1525
  if (currpos == prevpos) return; // useless invocation
 
1526
 
 
1527
#if SOQT_DEBUG && 0
 
1528
  SoDebugError::postInfo("SoGuiFullViewerP::pan",
 
1529
                         "was(%.3g, %.3g) -> now(%.3g, %.3g)",
 
1530
                         prevpos[0], prevpos[1], currpos[0], currpos[1]);
 
1531
#endif // SOQT_DEBUG
 
1532
 
 
1533
  // Find projection points for the last and current mouse coordinates.
 
1534
  SbViewVolume vv = cam->getViewVolume(aspectratio);
 
1535
  SbLine line;
 
1536
  vv.projectPointToLine(currpos, line);
 
1537
  SbVec3f current_planept;
 
1538
  panningplane.intersect(line, current_planept);
 
1539
  vv.projectPointToLine(prevpos, line);
 
1540
  SbVec3f old_planept;
 
1541
  panningplane.intersect(line, old_planept);
 
1542
 
 
1543
  // Reposition camera according to the vector difference between the
 
1544
  // projected points.
 
1545
  cam->position = cam->position.getValue() - (current_planept - old_planept);
 
1546
}
 
1547
 
 
1548
// *************************************************************************
 
1549
 
 
1550
// Dependent on the camera type this will either shrink or expand the
 
1551
// height of the viewport (orthogonal camera) or move the camera
 
1552
// closer or further away from the focal point in the scene.
 
1553
//
 
1554
// Used from both SoGuiPlaneViewer and SoGuiExaminerViewer.
 
1555
// Implemented in the SoGuiFullViewer private class to collect common
 
1556
// code.
 
1557
void
 
1558
SoGuiFullViewerP::zoom(SoCamera * cam, const float diffvalue)
 
1559
{
 
1560
  if (cam == NULL) return; // can happen for empty scenegraph
 
1561
  SoType t = cam->getTypeId();
 
1562
  SbName tname = t.getName();
 
1563
 
 
1564
  // This will be in the range of <0, ->>.
 
1565
  float multiplicator = float(exp(diffvalue));
 
1566
 
 
1567
  if (t.isDerivedFrom(SoOrthographicCamera::getClassTypeId())) {
 
1568
 
 
1569
    // Since there's no perspective, "zooming" in the original sense
 
1570
    // of the word won't have any visible effect. So we just increase
 
1571
    // or decrease the field-of-view values of the camera instead, to
 
1572
    // "shrink" the projection size of the model / scene.
 
1573
    SoOrthographicCamera * oc = (SoOrthographicCamera *)cam;
 
1574
    oc->height = oc->height.getValue() * multiplicator;
 
1575
 
 
1576
  }
 
1577
  else {
 
1578
    // FrustumCamera can be found in the SmallChange CVS module (it's
 
1579
    // a camera that lets you specify (for instance) an off-center
 
1580
    // frustum (similar to glFrustum())
 
1581
    if (!t.isDerivedFrom(SoPerspectiveCamera::getClassTypeId()) &&
 
1582
        tname != "FrustumCamera") {
 
1583
      static SbBool first = TRUE;
 
1584
      if (first) {
 
1585
        SoDebugError::postWarning("SoGuiFullViewerP::zoom",
 
1586
                                  "Unknown camera type, "
 
1587
                                  "will zoom by moving position, but this might not be correct.");
 
1588
        first = FALSE;
 
1589
      }
 
1590
    }
 
1591
    
 
1592
    const float oldfocaldist = cam->focalDistance.getValue();
 
1593
    const float newfocaldist = oldfocaldist * multiplicator;
 
1594
 
 
1595
    SbVec3f direction;
 
1596
    cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
 
1597
 
 
1598
    const SbVec3f oldpos = cam->position.getValue();
 
1599
    const SbVec3f newpos = oldpos + (newfocaldist - oldfocaldist) * -direction;
 
1600
 
 
1601
    // This catches a rather common user interface "buglet": if the
 
1602
    // user zooms the camera out to a distance from origo larger than
 
1603
    // what we still can safely do floating point calculations on
 
1604
    // (i.e. without getting NaN or Inf values), the faulty floating
 
1605
    // point values will propagate until we start to get debug error
 
1606
    // messages and eventually an assert failure from core Coin code.
 
1607
    //
 
1608
    // With the below bounds check, this problem is avoided.
 
1609
    //
 
1610
    // (But note that we depend on the input argument ''diffvalue'' to
 
1611
    // be small enough that zooming happens gradually. Ideally, we
 
1612
    // should also check distorigo with isinf() and isnan() (or
 
1613
    // inversely; isinfite()), but those only became standardized with
 
1614
    // C99.)
 
1615
    const float distorigo = newpos.length();
 
1616
    // sqrt(FLT_MAX) == ~ 1e+19, which should be both safe for further
 
1617
    // calculations and ok for the end-user and app-programmer.
 
1618
    if (distorigo > float(sqrt(FLT_MAX))) {
 
1619
#if SOQT_DEBUG && 0 // debug
 
1620
      SoDebugError::postWarning("SoGuiFullViewerP::zoom",
 
1621
                                "zoomed too far (distance to origo==%f (%e))",
 
1622
                                distorigo, distorigo);
 
1623
#endif // debug
 
1624
    }
 
1625
    else {
 
1626
      cam->position = newpos;
 
1627
      cam->focalDistance = newfocaldist;
 
1628
    }
 
1629
  }
 
1630
}
 
1631
 
 
1632
// ************************************************************************
 
1633
 
 
1634
#endif // DOXYGEN_SKIP_THIS
 
1635
 
 
1636
#undef PRIVATE
 
1637
#undef PUBLIC
 
1638