| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* Copyright (C) 1990-95 Silicon Graphics, Inc. |
| 39 |
* |
| 40 |
_______________________________________________________________________ |
| 41 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 |
| |
| 43 |
| $Revision: 1.2 $ |
| 44 |
| |
| 45 |
| Classes : SoXtExaminerViewer |
| 46 |
| |
| 47 |
| Author(s) : Alain Dumesny |
| 48 |
| |
| 49 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 50 |
_______________________________________________________________________ |
| 51 |
*/ |
| 52 |
#include <cstdlib> |
| 53 |
#include <inttypes.h> |
| 54 |
#include <X11/Intrinsic.h> |
| 55 |
#include <X11/Xlib.h> |
| 56 |
#include <X11/keysym.h> |
| 57 |
|
| 58 |
#include <Xm/LabelG.h> |
| 59 |
#include <Xm/Text.h> |
| 60 |
#include <Xm/ToggleB.h> |
| 61 |
#include <Xm/ToggleBG.h> |
| 62 |
#include <Xm/Form.h> |
| 63 |
#include <Sgm/ThumbWheel.h> |
| 64 |
|
| 65 |
#include <Inventor/SoDB.h> |
| 66 |
#include <Inventor/SoInput.h> |
| 67 |
#include <Inventor/sensors/SoFieldSensor.h> |
| 68 |
#include <Inventor/fields/SoSFTime.h> |
| 69 |
#include <Inventor/nodes/SoOrthographicCamera.h> |
| 70 |
#include <Inventor/nodes/SoPerspectiveCamera.h> |
| 71 |
#include <Inventor/nodes/SoScale.h> |
| 72 |
#include <Inventor/nodes/SoSeparator.h> |
| 73 |
#include <Inventor/nodes/SoSwitch.h> |
| 74 |
#include <Inventor/nodes/SoTranslation.h> |
| 75 |
#include <Inventor/projectors/SbSphereSheetProjector.h> |
| 76 |
#include <Inventor/actions/SoSearchAction.h> |
| 77 |
#include <Inventor/Xt/SoXt.h> |
| 78 |
#include <Inventor/Xt/SoXtCursors.h> |
| 79 |
#include <Inventor/Xt/SoXtResource.h> |
| 80 |
#include <Inventor/Xt/SoXtIcons.h> |
| 81 |
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h> |
| 82 |
#include "SoXtBitmapButton.h" |
| 83 |
#include <GL/gl.h> |
| 84 |
|
| 85 |
|
| 86 |
#ifdef DEBUG |
| 87 |
#include <Inventor/errors/SoDebugError.h> |
| 88 |
#include <SoDebug.h> |
| 89 |
#endif |
| 90 |
|
| 91 |
/* |
| 92 |
* Defines |
| 93 |
*/ |
| 94 |
|
| 95 |
enum ViewerModes { |
| 96 |
PICK_MODE, |
| 97 |
VIEW_MODE, |
| 98 |
SPIN_MODE_ACTIVE, |
| 99 |
PAN_MODE, |
| 100 |
PAN_MODE_ACTIVE, |
| 101 |
DOLLY_MODE_ACTIVE, |
| 102 |
SEEK_MODE |
| 103 |
}; |
| 104 |
|
| 105 |
// list of custom push buttons |
| 106 |
enum { |
| 107 |
CAM_PUSH = 0, |
| 108 |
PUSH_NUM |
| 109 |
}; |
| 110 |
|
| 111 |
|
| 112 |
// size of the rotation buffer, which is used to animate the spinning ball. |
| 113 |
#define ROT_BUFF_SIZE 3 |
| 114 |
|
| 115 |
|
| 116 |
// Resources for labels. |
| 117 |
typedef struct { |
| 118 |
char *examinViewer; |
| 119 |
char *roty; |
| 120 |
char *rotx; |
| 121 |
char *preferenceSheet; |
| 122 |
char *zoom; |
| 123 |
char *dolly; |
| 124 |
char *axesSizeLabel; |
| 125 |
} RES_LABELS; |
| 126 |
static RES_LABELS rl; |
| 127 |
|
| 128 |
static char *defaultLabel[]={ |
| 129 |
"Examiner Viewer", |
| 130 |
"Roty", |
| 131 |
"Rotx", |
| 132 |
"Examiner Viewer Preference Sheet", |
| 133 |
"Zoom", |
| 134 |
"Dolly", |
| 135 |
"axes size:" |
| 136 |
}; |
| 137 |
|
| 138 |
|
| 139 |
// |
| 140 |
// The point of interest geometry description |
| 141 |
// |
| 142 |
char *SoXtExaminerViewer::geometryBuffer = "\ |
| 143 |
#Inventor V2.0 ascii\n\ |
| 144 |
\ |
| 145 |
Separator { \ |
| 146 |
PickStyle { style UNPICKABLE } \ |
| 147 |
LightModel { model BASE_COLOR } \ |
| 148 |
MaterialBinding { value PER_PART } \ |
| 149 |
DrawStyle { lineWidth 2 } \ |
| 150 |
Coordinate3 { point [0 0 0, 1 0 0, 0 1 0, 0 0 1] } \ |
| 151 |
BaseColor { rgb [1 0 0, 0 1 0, 0 0 1] } \ |
| 152 |
IndexedLineSet { coordIndex [1, 0, 2, -1, 0, 3] } \ |
| 153 |
\ |
| 154 |
LightModel { model PHONG } \ |
| 155 |
MaterialBinding { value OVERALL } \ |
| 156 |
Complexity { value .1 } \ |
| 157 |
Separator { \ |
| 158 |
Material { \ |
| 159 |
diffuseColor [ 0.5 0 0 ] \ |
| 160 |
emissiveColor [ 0.5 0 0 ] \ |
| 161 |
} \ |
| 162 |
Translation { translation 1 0 0 } \ |
| 163 |
RotationXYZ { axis Z angle -1.570796327 } \ |
| 164 |
Cone { bottomRadius .2 height .3 } \ |
| 165 |
} \ |
| 166 |
Separator { \ |
| 167 |
Material { \ |
| 168 |
diffuseColor [ 0 0.5 0 ] \ |
| 169 |
emissiveColor [ 0 0.5 0 ] \ |
| 170 |
} \ |
| 171 |
Translation { translation 0 1 0 } \ |
| 172 |
Cone { bottomRadius .2 height .3 } \ |
| 173 |
} \ |
| 174 |
Material { \ |
| 175 |
diffuseColor [ 0 0 0.5 ] \ |
| 176 |
emissiveColor [ 0 0 0.5 ] \ |
| 177 |
} \ |
| 178 |
Translation { translation 0 0 1 } \ |
| 179 |
RotationXYZ { axis X angle 1.570796327 } \ |
| 180 |
Cone { bottomRadius .2 height .3 } \ |
| 181 |
} "; |
| 182 |
|
| 183 |
|
| 184 |
static char *thisClassName = "SoXtExaminerViewer"; |
| 185 |
|
| 186 |
//////////////////////////////////////////////////////////////////////// |
| 187 |
// |
| 188 |
// Public constructor - build the widget right now |
| 189 |
// |
| 190 |
SoXtExaminerViewer::SoXtExaminerViewer( |
| 191 |
Widget parent, |
| 192 |
const char *name, |
| 193 |
SbBool buildInsideParent, |
| 194 |
SoXtFullViewer::BuildFlag b, |
| 195 |
SoXtViewer::Type t) |
| 196 |
: SoXtFullViewer( |
| 197 |
parent, |
| 198 |
name, |
| 199 |
buildInsideParent, |
| 200 |
b, |
| 201 |
t, |
| 202 |
FALSE) // tell GLWidget not to build just yet |
| 203 |
// |
| 204 |
//////////////////////////////////////////////////////////////////////// |
| 205 |
{ |
| 206 |
// In this case, render area is what the app wants, so buildNow = TRUE |
| 207 |
constructorCommon(TRUE); |
| 208 |
} |
| 209 |
|
| 210 |
//////////////////////////////////////////////////////////////////////// |
| 211 |
// |
| 212 |
// SoEXTENDER constructor - the subclass tells us whether to build or not |
| 213 |
// |
| 214 |
SoXtExaminerViewer::SoXtExaminerViewer( |
| 215 |
Widget parent, |
| 216 |
const char *name, |
| 217 |
SbBool buildInsideParent, |
| 218 |
SoXtFullViewer::BuildFlag b, |
| 219 |
SoXtViewer::Type t, |
| 220 |
SbBool buildNow) |
| 221 |
: SoXtFullViewer( |
| 222 |
parent, |
| 223 |
name, |
| 224 |
buildInsideParent, |
| 225 |
b, |
| 226 |
t, |
| 227 |
FALSE) // tell GLWidget not to build just yet |
| 228 |
// |
| 229 |
//////////////////////////////////////////////////////////////////////// |
| 230 |
{ |
| 231 |
// In this case, render area may be what the app wants, |
| 232 |
// or it may want a subclass of render area. Pass along buildNow |
| 233 |
// as it was passed to us. |
| 234 |
constructorCommon(buildNow); |
| 235 |
} |
| 236 |
|
| 237 |
//////////////////////////////////////////////////////////////////////// |
| 238 |
// |
| 239 |
// Called by the constructors |
| 240 |
// |
| 241 |
// private |
| 242 |
// |
| 243 |
void |
| 244 |
SoXtExaminerViewer::constructorCommon(SbBool buildNow) |
| 245 |
// |
| 246 |
//////////////////////////////////////////////////////////////////////// |
| 247 |
{ |
| 248 |
// init local vars |
| 249 |
addVisibilityChangeCallback(visibilityChangeCB, this); |
| 250 |
mode = isViewing() ? VIEW_MODE : PICK_MODE; |
| 251 |
createdCursors = FALSE; |
| 252 |
spinCursor = panCursor = dollyCursor = seekCursor = 0; |
| 253 |
firstBuild = TRUE; |
| 254 |
setSize( SbVec2s(500, 390) ); // default size |
| 255 |
setClassName(thisClassName); |
| 256 |
|
| 257 |
// axis of rotation feedback vars |
| 258 |
feedbackFlag = FALSE; |
| 259 |
feedbackRoot = NULL; |
| 260 |
feedbackSwitch = NULL; |
| 261 |
feedbackSize = 20.0; |
| 262 |
feedbackSizeWheel = NULL; |
| 263 |
|
| 264 |
// init animation variables |
| 265 |
animationEnabled = TRUE; |
| 266 |
animatingFlag = FALSE; |
| 267 |
rotBuffer = new SbRotation[ROT_BUFF_SIZE]; |
| 268 |
lastMotionTime = 0; |
| 269 |
animationSensor = new |
| 270 |
SoFieldSensor(SoXtExaminerViewer::animationSensorCB, this); |
| 271 |
#ifdef DEBUG |
| 272 |
if (SoDebug::GetEnv("IV_DEBUG_SENSORS")) { |
| 273 |
SoDebug::NamePtr("examinerSpinSensor", animationSensor); |
| 274 |
} |
| 275 |
#endif |
| 276 |
|
| 277 |
// init the projector class |
| 278 |
SbViewVolume vv; |
| 279 |
vv.ortho(-1, 1, -1, 1, -10, 10); |
| 280 |
sphereSheet = new SbSphereSheetProjector; |
| 281 |
sphereSheet->setViewVolume( vv ); |
| 282 |
sphereSheet->setSphere( SbSphere( SbVec3f(0, 0, 0), .7) ); |
| 283 |
|
| 284 |
// Initialize buttonList. |
| 285 |
for (int i=0; i<PUSH_NUM; i++) |
| 286 |
buttonList[i] = NULL; |
| 287 |
|
| 288 |
// Build the widget tree, and let SoXtComponent know about our base widget. |
| 289 |
if (buildNow) { |
| 290 |
Widget w = buildWidget(getParentWidget()); |
| 291 |
setBaseWidget(w); |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
//////////////////////////////////////////////////////////////////////// |
| 296 |
// |
| 297 |
// Description: |
| 298 |
// Destructor. |
| 299 |
// |
| 300 |
// Use: public |
| 301 |
|
| 302 |
SoXtExaminerViewer::~SoXtExaminerViewer() |
| 303 |
// |
| 304 |
//////////////////////////////////////////////////////////////////////// |
| 305 |
{ |
| 306 |
delete animationSensor; |
| 307 |
|
| 308 |
for (int i=0; i<PUSH_NUM; i++) |
| 309 |
delete buttonList[i]; |
| 310 |
|
| 311 |
delete sphereSheet; |
| 312 |
if (feedbackRoot) |
| 313 |
feedbackRoot->unref(); |
| 314 |
|
| 315 |
// free the viewer cursors |
| 316 |
if (getDisplay()) { |
| 317 |
Display *display = getDisplay(); |
| 318 |
if (spinCursor) XFreeCursor(display, spinCursor); |
| 319 |
if (panCursor) XFreeCursor(display, panCursor); |
| 320 |
if (dollyCursor) XFreeCursor(display, dollyCursor); |
| 321 |
if (seekCursor) XFreeCursor(display, seekCursor); |
| 322 |
} |
| 323 |
|
| 324 |
delete [] rotBuffer; |
| 325 |
} |
| 326 |
|
| 327 |
//////////////////////////////////////////////////////////////////////// |
| 328 |
// |
| 329 |
// Description: |
| 330 |
// Shows/hide the point of rotation feedback geometry |
| 331 |
// |
| 332 |
// Use: public |
| 333 |
void |
| 334 |
SoXtExaminerViewer::setFeedbackVisibility(SbBool insertFlag) |
| 335 |
// |
| 336 |
//////////////////////////////////////////////////////////////////////// |
| 337 |
{ |
| 338 |
// check for trivial return |
| 339 |
if (camera == NULL || feedbackFlag == insertFlag) { |
| 340 |
feedbackFlag = insertFlag; |
| 341 |
return; |
| 342 |
} |
| 343 |
|
| 344 |
// |
| 345 |
// find the camera parent to insert/remove the feedback root |
| 346 |
// |
| 347 |
SoSearchAction sa; |
| 348 |
if (insertFlag) |
| 349 |
sa.setNode(camera); |
| 350 |
else { |
| 351 |
sa.setNode(feedbackRoot); |
| 352 |
sa.setSearchingAll(TRUE); // find under OFF switches for removal |
| 353 |
} |
| 354 |
sa.apply(sceneRoot); |
| 355 |
SoFullPath *fullPath = (SoFullPath *) sa.getPath(); |
| 356 |
if (!fullPath) { |
| 357 |
#if DEBUG |
| 358 |
SoDebugError::post("SoXtExaminerViewer::setFeedbackVisibility", |
| 359 |
insertFlag ? "ERROR: cannot find camera in graph" : |
| 360 |
"ERROR: cannot find axis feedback in graph"); |
| 361 |
#endif |
| 362 |
return; |
| 363 |
} |
| 364 |
SoGroup *parent = (SoGroup *) fullPath->getNodeFromTail(1); |
| 365 |
|
| 366 |
feedbackFlag = insertFlag; |
| 367 |
|
| 368 |
// make sure the feedback has been built |
| 369 |
if (!feedbackRoot) |
| 370 |
createFeedbackNodes(); |
| 371 |
|
| 372 |
// |
| 373 |
// inserts/remove the feedback axis group |
| 374 |
// |
| 375 |
|
| 376 |
if (feedbackFlag) { |
| 377 |
int camIndex; |
| 378 |
|
| 379 |
// check to make sure that the camera parent is not a switch node |
| 380 |
// (VRML camera viewpoints are kept under a switch node). Otherwise |
| 381 |
// we will insert the feedback after the switch node. |
| 382 |
if (parent->isOfType(SoSwitch::getClassTypeId())) { |
| 383 |
SoNode *switchNode = parent; |
| 384 |
parent = (SoGroup *) fullPath->getNodeFromTail(2); |
| 385 |
camIndex = parent->findChild(switchNode); |
| 386 |
} |
| 387 |
else |
| 388 |
camIndex = parent->findChild(camera); |
| 389 |
|
| 390 |
// return if feedback is already there (this should be an error !) |
| 391 |
if (parent->findChild(feedbackRoot) >= 0) |
| 392 |
return; |
| 393 |
|
| 394 |
// insert the feedback right after the camera+headlight (index+2) |
| 395 |
if (camIndex >= 0) { |
| 396 |
if (isHeadlight()) |
| 397 |
parent->insertChild(feedbackRoot, camIndex+2); |
| 398 |
else |
| 399 |
parent->insertChild(feedbackRoot, camIndex+1); |
| 400 |
} |
| 401 |
|
| 402 |
// make sure the feedback switch is turned to the correct state now |
| 403 |
// that the feedback root has been inserted in the scene |
| 404 |
feedbackSwitch->whichChild.setValue(viewingFlag ? SO_SWITCH_ALL : SO_SWITCH_NONE); |
| 405 |
} |
| 406 |
else { |
| 407 |
if (parent->findChild(feedbackRoot) >= 0) |
| 408 |
parent->removeChild(feedbackRoot); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
//////////////////////////////////////////////////////////////////////// |
| 413 |
// |
| 414 |
// Description: |
| 415 |
// Sets the feedback size. |
| 416 |
// |
| 417 |
// Use: public |
| 418 |
void |
| 419 |
SoXtExaminerViewer::setFeedbackSize(int newSize) |
| 420 |
// |
| 421 |
//////////////////////////////////////////////////////////////////////// |
| 422 |
{ |
| 423 |
if (feedbackSize == newSize) |
| 424 |
return; |
| 425 |
|
| 426 |
// assign new value and redraw (since it is not a field in the scene) |
| 427 |
feedbackSize = newSize; |
| 428 |
if (isFeedbackVisible() && isViewing()) |
| 429 |
scheduleRedraw(); |
| 430 |
} |
| 431 |
|
| 432 |
//////////////////////////////////////////////////////////////////////// |
| 433 |
// |
| 434 |
// Description: |
| 435 |
// Remove the extra geometry when doing a viewAll. |
| 436 |
// |
| 437 |
// Use: virtual public |
| 438 |
void |
| 439 |
SoXtExaminerViewer::viewAll() |
| 440 |
// |
| 441 |
//////////////////////////////////////////////////////////////////////// |
| 442 |
{ |
| 443 |
// stop spinning |
| 444 |
if ( isAnimating() ) |
| 445 |
stopAnimating(); |
| 446 |
|
| 447 |
// temporarily remove the feedback geometry |
| 448 |
if (feedbackFlag && isViewing() && feedbackSwitch) |
| 449 |
feedbackSwitch->whichChild.setValue( SO_SWITCH_NONE ); |
| 450 |
|
| 451 |
// call the base class |
| 452 |
SoXtFullViewer::viewAll(); |
| 453 |
|
| 454 |
// now add the geometry back in |
| 455 |
if (feedbackFlag && isViewing() && feedbackSwitch) |
| 456 |
feedbackSwitch->whichChild.setValue( SO_SWITCH_ALL ); |
| 457 |
} |
| 458 |
|
| 459 |
//////////////////////////////////////////////////////////////////////// |
| 460 |
// |
| 461 |
// Description: |
| 462 |
// Call the parent class and stop animation if any |
| 463 |
// |
| 464 |
// Use: virtual public |
| 465 |
void |
| 466 |
SoXtExaminerViewer::resetToHomePosition() |
| 467 |
// |
| 468 |
//////////////////////////////////////////////////////////////////////// |
| 469 |
{ |
| 470 |
// stop spinning |
| 471 |
if ( isAnimating() ) |
| 472 |
stopAnimating(); |
| 473 |
|
| 474 |
// call the base class |
| 475 |
SoXtFullViewer::resetToHomePosition(); |
| 476 |
} |
| 477 |
|
| 478 |
//////////////////////////////////////////////////////////////////////// |
| 479 |
// |
| 480 |
// Description: |
| 481 |
// Call the parent class and insert/remove the feedback root |
| 482 |
// |
| 483 |
// Use: virtual public |
| 484 |
void |
| 485 |
SoXtExaminerViewer::setCamera(SoCamera *newCamera) |
| 486 |
// |
| 487 |
//////////////////////////////////////////////////////////////////////// |
| 488 |
{ |
| 489 |
if (camera == newCamera) |
| 490 |
return; |
| 491 |
|
| 492 |
// set the right thumbwheel label and toggle button image based on |
| 493 |
// the camera type |
| 494 |
if (newCamera != NULL && (camera == NULL || |
| 495 |
newCamera->getTypeId() != camera->getTypeId())) { |
| 496 |
if (newCamera->isOfType(SoOrthographicCamera::getClassTypeId())) { |
| 497 |
if (buttonList[CAM_PUSH]) |
| 498 |
buttonList[CAM_PUSH]->setIcon(so_xt_ortho_bits, |
| 499 |
so_xt_icon_width, so_xt_icon_height); |
| 500 |
setRightWheelString(rl.zoom); |
| 501 |
} |
| 502 |
else { |
| 503 |
if (buttonList[CAM_PUSH]) |
| 504 |
buttonList[CAM_PUSH]->setIcon(so_xt_persp_bits, |
| 505 |
so_xt_icon_width, so_xt_icon_height); |
| 506 |
setRightWheelString(rl.dolly); |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
// detach feedback which depends on camera |
| 511 |
if ( feedbackFlag ) { |
| 512 |
setFeedbackVisibility(FALSE); |
| 513 |
feedbackFlag = TRUE; // can later be turned on |
| 514 |
} |
| 515 |
|
| 516 |
// call parent class |
| 517 |
SoXtFullViewer::setCamera(newCamera); |
| 518 |
|
| 519 |
// attach feedback back on |
| 520 |
if ( feedbackFlag ) { |
| 521 |
feedbackFlag = FALSE; // enables routine to be called |
| 522 |
setFeedbackVisibility(TRUE); |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
//////////////////////////////////////////////////////////////////////// |
| 527 |
// |
| 528 |
// Description: |
| 529 |
// Call the base class and sets the correct cursors on the window, |
| 530 |
// plus insert/remove the feedback geometry. |
| 531 |
// |
| 532 |
// Use: virtual public |
| 533 |
void |
| 534 |
SoXtExaminerViewer::setViewing(SbBool flag) |
| 535 |
// |
| 536 |
//////////////////////////////////////////////////////////////////////// |
| 537 |
{ |
| 538 |
if (flag == viewingFlag) |
| 539 |
return; |
| 540 |
|
| 541 |
// call the parent class |
| 542 |
SoXtFullViewer::setViewing(flag); |
| 543 |
|
| 544 |
switchMode(isViewing() ? VIEW_MODE : PICK_MODE); |
| 545 |
|
| 546 |
// show/hide the feedback geometry based on the viewing state |
| 547 |
if (feedbackFlag && feedbackSwitch) |
| 548 |
feedbackSwitch->whichChild.setValue(viewingFlag ? SO_SWITCH_ALL : SO_SWITCH_NONE); |
| 549 |
} |
| 550 |
|
| 551 |
//////////////////////////////////////////////////////////////////////// |
| 552 |
// |
| 553 |
// Description: |
| 554 |
// Enables/Disable the viewer cursor on the window. |
| 555 |
// |
| 556 |
// Use: virtual public |
| 557 |
void |
| 558 |
SoXtExaminerViewer::setCursorEnabled(SbBool flag) |
| 559 |
// |
| 560 |
//////////////////////////////////////////////////////////////////////// |
| 561 |
{ |
| 562 |
if (flag == cursorEnabledFlag) |
| 563 |
return; |
| 564 |
|
| 565 |
cursorEnabledFlag = flag; |
| 566 |
|
| 567 |
if (! isViewing()) |
| 568 |
return; |
| 569 |
|
| 570 |
updateCursor(); |
| 571 |
} |
| 572 |
|
| 573 |
//////////////////////////////////////////////////////////////////////// |
| 574 |
// |
| 575 |
// Description: |
| 576 |
// Process the given event to do viewing stuff |
| 577 |
// |
| 578 |
// Use: virtual protected |
| 579 |
void |
| 580 |
SoXtExaminerViewer::processEvent(XAnyEvent *xe) |
| 581 |
// |
| 582 |
//////////////////////////////////////////////////////////////////////// |
| 583 |
{ |
| 584 |
if ( processCommonEvents(xe) ) |
| 585 |
return; |
| 586 |
|
| 587 |
if (!createdCursors) |
| 588 |
updateCursor(); |
| 589 |
|
| 590 |
XButtonEvent *be; |
| 591 |
XMotionEvent *me; |
| 592 |
XKeyEvent *ke; |
| 593 |
XCrossingEvent *ce; |
| 594 |
KeySym keysym; |
| 595 |
|
| 596 |
SbVec2s raSize = getGlxSize(); |
| 597 |
|
| 598 |
switch(xe->type) { |
| 599 |
case ButtonPress: |
| 600 |
case ButtonRelease: |
| 601 |
be = (XButtonEvent *)xe; |
| 602 |
if (be->button != Button1 && be->button != Button2) |
| 603 |
break; |
| 604 |
|
| 605 |
locator[0] = be->x; |
| 606 |
locator[1] = raSize[1] - be->y; |
| 607 |
|
| 608 |
if (mode == SEEK_MODE) { |
| 609 |
if (xe->type == ButtonPress) |
| 610 |
seekToPoint(locator); |
| 611 |
} |
| 612 |
else { |
| 613 |
if (xe->type == ButtonPress) |
| 614 |
interactiveCountInc(); |
| 615 |
else { //... ButtonRelease |
| 616 |
|
| 617 |
// check if we need to start spinning |
| 618 |
if (mode == SPIN_MODE_ACTIVE && animationEnabled |
| 619 |
&& lastMotionTime == be->time) { |
| 620 |
animatingFlag = TRUE; |
| 621 |
computeAverage = TRUE; |
| 622 |
animationSensor->attach(viewerRealTime); |
| 623 |
interactiveCountInc(); |
| 624 |
} |
| 625 |
|
| 626 |
interactiveCountDec(); |
| 627 |
} |
| 628 |
updateViewerMode(be->state); |
| 629 |
} |
| 630 |
if (xe->type == ButtonPress) |
| 631 |
stopAnimating(); |
| 632 |
break; |
| 633 |
|
| 634 |
case KeyPress: |
| 635 |
case KeyRelease: |
| 636 |
ke = (XKeyEvent *)xe; |
| 637 |
keysym = XLookupKeysym(ke, 0); |
| 638 |
|
| 639 |
locator[0] = ke->x; |
| 640 |
locator[1] = raSize[1] - ke->y; |
| 641 |
if (keysym == XK_Control_L || keysym == XK_Control_R) |
| 642 |
updateViewerMode(ke->state); |
| 643 |
break; |
| 644 |
|
| 645 |
case MotionNotify: |
| 646 |
me = (XMotionEvent *)xe; |
| 647 |
switch (mode) { |
| 648 |
case SPIN_MODE_ACTIVE: |
| 649 |
lastMotionTime = me->time; |
| 650 |
spinCamera(SbVec2f(me->x/float(raSize[0]), (raSize[1] - me->y)/float(raSize[1]))); |
| 651 |
break; |
| 652 |
case PAN_MODE_ACTIVE: |
| 653 |
panCamera(SbVec2f(me->x/float(raSize[0]), (raSize[1] - me->y)/float(raSize[1]))); |
| 654 |
break; |
| 655 |
case DOLLY_MODE_ACTIVE: |
| 656 |
dollyCamera( SbVec2s(me->x, raSize[1] - me->y) ); |
| 657 |
break; |
| 658 |
} |
| 659 |
break; |
| 660 |
|
| 661 |
case LeaveNotify: |
| 662 |
case EnterNotify: |
| 663 |
ce = (XCrossingEvent *)xe; |
| 664 |
// |
| 665 |
// because the application might use Ctrl-key for motif menu |
| 666 |
// accelerators we might not receive a key-up event, so make sure |
| 667 |
// to reset any Ctrl mode if we loose focus, but don't do anything |
| 668 |
// if Ctrl-key is not down (nothing to do) or if a mouse button |
| 669 |
// is down (we will get another leaveNotify). |
| 670 |
// |
| 671 |
if (! (ce->state & ControlMask)) |
| 672 |
break; |
| 673 |
if (ce->state & Button1Mask || ce->state & Button2Mask) |
| 674 |
break; |
| 675 |
if (xe->type == LeaveNotify) |
| 676 |
switchMode(VIEW_MODE); |
| 677 |
else |
| 678 |
updateViewerMode(ce->state); |
| 679 |
break; |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
//////////////////////////////////////////////////////////////////////// |
| 684 |
// |
| 685 |
// Description: |
| 686 |
// sets the viewer mode based on what keys and buttons are being pressed |
| 687 |
// |
| 688 |
// Use: private |
| 689 |
void |
| 690 |
SoXtExaminerViewer::updateViewerMode(unsigned int state) |
| 691 |
// |
| 692 |
//////////////////////////////////////////////////////////////////////// |
| 693 |
{ |
| 694 |
// ??? WARNING - this routine ONLY works because of |
| 695 |
// ??? SoXtViewer::updateEventState() which is called for us |
| 696 |
// ??? by SoXtViewer::processCommonEvents(). |
| 697 |
// ??? (XEvent state for button and modifier keys is not updated |
| 698 |
// ??? until after the event is received. WEIRD) |
| 699 |
|
| 700 |
// LEFT+MIDDLE down |
| 701 |
if (state & Button1Mask && state & Button2Mask) { |
| 702 |
switchMode(DOLLY_MODE_ACTIVE); |
| 703 |
} |
| 704 |
|
| 705 |
// LEFT down |
| 706 |
else if (state & Button1Mask) { |
| 707 |
if (state & ControlMask) |
| 708 |
switchMode(PAN_MODE_ACTIVE); |
| 709 |
else |
| 710 |
switchMode(SPIN_MODE_ACTIVE); |
| 711 |
} |
| 712 |
|
| 713 |
// MIDDLE DOWN |
| 714 |
else if (state & Button2Mask) { |
| 715 |
if (state & ControlMask) |
| 716 |
switchMode(DOLLY_MODE_ACTIVE); |
| 717 |
else |
| 718 |
switchMode(PAN_MODE_ACTIVE); |
| 719 |
} |
| 720 |
|
| 721 |
// no buttons down... |
| 722 |
else { |
| 723 |
if (state & ControlMask) |
| 724 |
switchMode(PAN_MODE); |
| 725 |
else |
| 726 |
switchMode(VIEW_MODE); |
| 727 |
} |
| 728 |
} |
| 729 |
|
| 730 |
//////////////////////////////////////////////////////////////////////// |
| 731 |
// |
| 732 |
// Description: |
| 733 |
// switches to the specified viewer mode |
| 734 |
// |
| 735 |
// Use: private |
| 736 |
void |
| 737 |
SoXtExaminerViewer::switchMode(int newMode) |
| 738 |
// |
| 739 |
//////////////////////////////////////////////////////////////////////// |
| 740 |
{ |
| 741 |
Widget raWidget = getRenderAreaWidget(); |
| 742 |
SbVec2s raSize = getGlxSize(); |
| 743 |
|
| 744 |
// assing new mode |
| 745 |
int prevMode = mode; |
| 746 |
mode = newMode; |
| 747 |
|
| 748 |
// update the cursor |
| 749 |
updateCursor(); |
| 750 |
|
| 751 |
// switch to new viewer mode |
| 752 |
switch (newMode) { |
| 753 |
case PICK_MODE: |
| 754 |
if (raWidget && XtWindow(raWidget)) { |
| 755 |
// ???? is if are going into PICK mode and some of our |
| 756 |
// mouse buttons are still down, make sure to decrement |
| 757 |
// interactive count correctly (correct draw style). One |
| 758 |
// for the LEFT and one for MIDDLE mouse. |
| 759 |
Window root_return, child_return; |
| 760 |
int root_x_return, root_y_return; |
| 761 |
int win_x_return, win_y_return; |
| 762 |
unsigned int mask_return; |
| 763 |
XQueryPointer(XtDisplay(raWidget), XtWindow(raWidget), |
| 764 |
&root_return, &child_return, |
| 765 |
&root_x_return, &root_y_return, &win_x_return, |
| 766 |
&win_y_return, &mask_return); |
| 767 |
if (mask_return & Button1Mask && prevMode != SEEK_MODE) |
| 768 |
interactiveCountDec(); |
| 769 |
if (mask_return & Button2Mask && prevMode != SEEK_MODE) |
| 770 |
interactiveCountDec(); |
| 771 |
} |
| 772 |
stopAnimating(); |
| 773 |
break; |
| 774 |
|
| 775 |
case SPIN_MODE_ACTIVE: |
| 776 |
// set the sphere sheet starting point |
| 777 |
sphereSheet->project( |
| 778 |
SbVec2f(locator[0]/float(raSize[0]), locator[1]/float(raSize[1])) ); |
| 779 |
|
| 780 |
// reset the animation queue |
| 781 |
firstIndex = 0; |
| 782 |
lastIndex = -1; |
| 783 |
break; |
| 784 |
|
| 785 |
case PAN_MODE_ACTIVE: |
| 786 |
{ |
| 787 |
// Figure out the focal plane |
| 788 |
SbMatrix mx; |
| 789 |
mx = camera->orientation.getValue(); |
| 790 |
SbVec3f forward(-mx[2][0], -mx[2][1], -mx[2][2]); |
| 791 |
SbVec3f fp = camera->position.getValue() + |
| 792 |
forward * camera->focalDistance.getValue(); |
| 793 |
focalplane = SbPlane(forward, fp); |
| 794 |
|
| 795 |
// map mouse starting position onto the panning plane |
| 796 |
SbViewVolume cameraVolume; |
| 797 |
SbLine line; |
| 798 |
cameraVolume = camera->getViewVolume(raSize[0]/float(raSize[1])); |
| 799 |
cameraVolume.projectPointToLine( |
| 800 |
SbVec2f(locator[0]/float(raSize[0]), locator[1]/float(raSize[1])), line); |
| 801 |
focalplane.intersect(line, locator3D); |
| 802 |
} |
| 803 |
break; |
| 804 |
} |
| 805 |
} |
| 806 |
|
| 807 |
//////////////////////////////////////////////////////////////////////// |
| 808 |
// |
| 809 |
// Description: |
| 810 |
// updates the viewer cursor |
| 811 |
// |
| 812 |
// Use: private |
| 813 |
void |
| 814 |
SoXtExaminerViewer::updateCursor() |
| 815 |
// |
| 816 |
//////////////////////////////////////////////////////////////////////// |
| 817 |
{ |
| 818 |
Widget w = getRenderAreaWidget(); |
| 819 |
Display *display = w ? XtDisplay(w) : NULL; |
| 820 |
Window window = w ? XtWindow(w) : 0; |
| 821 |
|
| 822 |
if (! window) |
| 823 |
return; |
| 824 |
|
| 825 |
if (! createdCursors) |
| 826 |
defineCursors(); |
| 827 |
|
| 828 |
// the viewer cursor are not enabled, then we don't set a new cursor. |
| 829 |
// Instead erase the old viewer cursor. |
| 830 |
if (! cursorEnabledFlag) { |
| 831 |
XUndefineCursor(display, window); |
| 832 |
return; |
| 833 |
} |
| 834 |
|
| 835 |
// ...else set the right cursor for the viewer mode.... |
| 836 |
switch(mode) { |
| 837 |
case PICK_MODE: |
| 838 |
XUndefineCursor(display, window); |
| 839 |
break; |
| 840 |
|
| 841 |
case VIEW_MODE: |
| 842 |
case SPIN_MODE_ACTIVE: |
| 843 |
XDefineCursor(display, window, spinCursor); |
| 844 |
break; |
| 845 |
|
| 846 |
case DOLLY_MODE_ACTIVE: |
| 847 |
XDefineCursor(display, window, dollyCursor); |
| 848 |
break; |
| 849 |
|
| 850 |
case PAN_MODE: |
| 851 |
case PAN_MODE_ACTIVE: |
| 852 |
XDefineCursor(display, window, panCursor); |
| 853 |
break; |
| 854 |
|
| 855 |
case SEEK_MODE: |
| 856 |
XDefineCursor(display, window, seekCursor); |
| 857 |
break; |
| 858 |
} |
| 859 |
} |
| 860 |
|
| 861 |
//////////////////////////////////////////////////////////////////////// |
| 862 |
// |
| 863 |
// Description: |
| 864 |
// draws viewer feedback during a render area redraw of the scene. |
| 865 |
// |
| 866 |
// Use: virtual protected |
| 867 |
void |
| 868 |
SoXtExaminerViewer::actualRedraw() |
| 869 |
// |
| 870 |
//////////////////////////////////////////////////////////////////////// |
| 871 |
{ |
| 872 |
// place the feedback at the focal point |
| 873 |
// ??? we really only need to do this when the camera changes |
| 874 |
if (isViewing() && feedbackFlag && camera != NULL && feedbackRoot) { |
| 875 |
|
| 876 |
// adjust the position to be at the focal point |
| 877 |
SbMatrix mx; |
| 878 |
mx = camera->orientation.getValue(); |
| 879 |
SbVec3f forward(-mx[2][0], -mx[2][1], -mx[2][2]); |
| 880 |
feedbackTransNode->translation = camera->position.getValue() + |
| 881 |
camera->focalDistance.getValue() * forward; |
| 882 |
|
| 883 |
// adjust the size to be constant on the screen |
| 884 |
float height; |
| 885 |
if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) { |
| 886 |
float angle = ((SoPerspectiveCamera *)camera)->heightAngle.getValue(); |
| 887 |
height = camera->focalDistance.getValue() * tanf(angle/2); |
| 888 |
} |
| 889 |
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) |
| 890 |
height = ((SoOrthographicCamera *)camera)->height.getValue() / 2; |
| 891 |
|
| 892 |
// ??? getGlxSize[1] == 0 the very first time, so return in that case |
| 893 |
// ??? else the redraws are 3 times slower from now on !! (alain) |
| 894 |
if (getGlxSize()[1] != 0) { |
| 895 |
float size = 2.0 * height * feedbackSize / float (getGlxSize()[1]); |
| 896 |
feedbackScaleNode->scaleFactor.setValue(size, size, size); |
| 897 |
} |
| 898 |
} |
| 899 |
|
| 900 |
// have the base class draw the scene |
| 901 |
SoXtFullViewer::actualRedraw(); |
| 902 |
} |
| 903 |
|
| 904 |
//////////////////////////////////////////////////////////////////////// |
| 905 |
// |
| 906 |
// Description: |
| 907 |
// Enable/disable the animation feature of the Examiner |
| 908 |
// |
| 909 |
// Use: public |
| 910 |
void |
| 911 |
SoXtExaminerViewer::setAnimationEnabled(SbBool flag) |
| 912 |
// |
| 913 |
//////////////////////////////////////////////////////////////////////// |
| 914 |
{ |
| 915 |
if (animationEnabled == flag) |
| 916 |
return; |
| 917 |
|
| 918 |
animationEnabled = flag; |
| 919 |
if ( !animationEnabled && isAnimating()) |
| 920 |
stopAnimating(); |
| 921 |
} |
| 922 |
|
| 923 |
//////////////////////////////////////////////////////////////////////// |
| 924 |
// |
| 925 |
// Description: |
| 926 |
// Stops ongoing animation (if any) |
| 927 |
// |
| 928 |
// Use: public |
| 929 |
void |
| 930 |
SoXtExaminerViewer::stopAnimating() |
| 931 |
// |
| 932 |
//////////////////////////////////////////////////////////////////////// |
| 933 |
{ |
| 934 |
if (animatingFlag) { |
| 935 |
animatingFlag = FALSE; |
| 936 |
animationSensor->detach(); |
| 937 |
animationSensor->unschedule(); |
| 938 |
interactiveCountDec(); |
| 939 |
} |
| 940 |
} |
| 941 |
|
| 942 |
//////////////////////////////////////////////////////////////////////// |
| 943 |
// |
| 944 |
// Description: |
| 945 |
// Call the base class and sets the correct cursors on the window |
| 946 |
// |
| 947 |
// Use: virtual protected |
| 948 |
void |
| 949 |
SoXtExaminerViewer::setSeekMode(SbBool flag) |
| 950 |
// |
| 951 |
//////////////////////////////////////////////////////////////////////// |
| 952 |
{ |
| 953 |
if ( !isViewing() ) |
| 954 |
return; |
| 955 |
|
| 956 |
// stop spinning |
| 957 |
if (isAnimating()) |
| 958 |
stopAnimating(); |
| 959 |
|
| 960 |
// call the base class |
| 961 |
SoXtFullViewer::setSeekMode(flag); |
| 962 |
|
| 963 |
mode = isSeekMode() ? SEEK_MODE : VIEW_MODE; |
| 964 |
|
| 965 |
updateCursor(); |
| 966 |
} |
| 967 |
|
| 968 |
//////////////////////////////////////////////////////////////////////// |
| 969 |
// |
| 970 |
// Description: |
| 971 |
// Redefine this routine to add some viewer specific stuff. |
| 972 |
// |
| 973 |
// Use: virtual protected |
| 974 |
void |
| 975 |
SoXtExaminerViewer::createPrefSheet() |
| 976 |
// |
| 977 |
//////////////////////////////////////////////////////////////////////// |
| 978 |
{ |
| 979 |
// create the preference sheet shell and form widget |
| 980 |
Widget shell, form; |
| 981 |
createPrefSheetShellAndForm(shell, form); |
| 982 |
|
| 983 |
// create all of the parts |
| 984 |
Widget widgetList[20]; |
| 985 |
int num = 0; |
| 986 |
createDefaultPrefSheetParts(widgetList, num, form); |
| 987 |
widgetList[num++] = createExamPrefSheetGuts(form); |
| 988 |
|
| 989 |
layoutPartsAndMapPrefSheet(widgetList, num, form, shell); |
| 990 |
} |
| 991 |
|
| 992 |
//////////////////////////////////////////////////////////////////////// |
| 993 |
// |
| 994 |
// Description: |
| 995 |
// Creates the viewer extra pref sheet stuff |
| 996 |
// |
| 997 |
// Use: private |
| 998 |
Widget |
| 999 |
SoXtExaminerViewer::createExamPrefSheetGuts(Widget parent) |
| 1000 |
// |
| 1001 |
//////////////////////////////////////////////////////////////////////// |
| 1002 |
{ |
| 1003 |
Widget toggles[2], labels[2]; |
| 1004 |
Arg args[12]; |
| 1005 |
int n; |
| 1006 |
|
| 1007 |
// create a form to hold everything together |
| 1008 |
Widget form = XtCreateWidget("", xmFormWidgetClass, parent, NULL, 0); |
| 1009 |
|
| 1010 |
// create all the parts |
| 1011 |
n = 0; |
| 1012 |
XtSetArg(args[n], XmNset, animationEnabled); n++; |
| 1013 |
XtSetArg(args[n], XmNspacing, 0); n++; |
| 1014 |
XtSetArg(args[n], XmNhighlightThickness, 0); n++; |
| 1015 |
toggles[0] = XtCreateWidget("", xmToggleButtonGadgetClass, form, args, n); |
| 1016 |
labels[0] = XtCreateWidget("Enable spin animation", |
| 1017 |
xmLabelGadgetClass, form, NULL, 0); |
| 1018 |
XtAddCallback(toggles[0], XmNvalueChangedCallback, |
| 1019 |
(XtCallbackProc) SoXtExaminerViewer::animPrefSheetToggleCB, |
| 1020 |
(XtPointer) this); |
| 1021 |
|
| 1022 |
n = 0; |
| 1023 |
XtSetArg(args[n], XmNsensitive, camera != NULL); n++; |
| 1024 |
XtSetArg(args[n], XmNset, feedbackFlag); n++; |
| 1025 |
XtSetArg(args[n], XmNspacing, 0); n++; |
| 1026 |
XtSetArg(args[n], XmNhighlightThickness, 0); n++; |
| 1027 |
toggles[1] = XtCreateWidget("", xmToggleButtonGadgetClass, form, args, n); |
| 1028 |
n = 0; |
| 1029 |
XtSetArg(args[n], XmNsensitive, camera != NULL); n++; |
| 1030 |
labels[1] = XtCreateWidget("Show point of rotation axes", |
| 1031 |
xmLabelGadgetClass, form, args, n); |
| 1032 |
XtAddCallback(toggles[1], XmNvalueChangedCallback, |
| 1033 |
(XtCallbackProc) SoXtExaminerViewer::feedbackPrefSheetToggleCB, |
| 1034 |
(XtPointer) this); |
| 1035 |
|
| 1036 |
// layout |
| 1037 |
n = 0; |
| 1038 |
XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; |
| 1039 |
XtSetArg(args[n], XmNleftWidget, toggles[0]); n++; |
| 1040 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++; |
| 1041 |
XtSetArg(args[n], XmNtopWidget, toggles[0]); n++; |
| 1042 |
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++; |
| 1043 |
XtSetArg(args[n], XmNbottomWidget, toggles[0]); n++; |
| 1044 |
XtSetValues(labels[0], args, n); |
| 1045 |
|
| 1046 |
n = 0; |
| 1047 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; |
| 1048 |
XtSetArg(args[n], XmNtopWidget, toggles[0]); n++; |
| 1049 |
XtSetArg(args[n], XmNtopOffset, 10); n++; |
| 1050 |
XtSetValues(toggles[1], args, n); |
| 1051 |
|
| 1052 |
n = 0; |
| 1053 |
XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; |
| 1054 |
XtSetArg(args[n], XmNleftWidget, toggles[1]); n++; |
| 1055 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++; |
| 1056 |
XtSetArg(args[n], XmNtopWidget, toggles[1]); n++; |
| 1057 |
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++; |
| 1058 |
XtSetArg(args[n], XmNbottomWidget, toggles[1]); n++; |
| 1059 |
XtSetValues(labels[1], args, n); |
| 1060 |
|
| 1061 |
// manage children |
| 1062 |
XtManageChildren(toggles, 2); |
| 1063 |
XtManageChildren(labels, 2); |
| 1064 |
|
| 1065 |
if (feedbackFlag && camera) |
| 1066 |
toggleFeedbackWheelSize(toggles[1]); |
| 1067 |
|
| 1068 |
return form; |
| 1069 |
} |
| 1070 |
|
| 1071 |
//////////////////////////////////////////////////////////////////////// |
| 1072 |
// |
| 1073 |
// Description: |
| 1074 |
// Brings the viewer help card (called by "?" push button) |
| 1075 |
// |
| 1076 |
// Use: virtual protected |
| 1077 |
void |
| 1078 |
SoXtExaminerViewer::openViewerHelpCard() |
| 1079 |
// |
| 1080 |
//////////////////////////////////////////////////////////////////////// |
| 1081 |
{ |
| 1082 |
// tell the base class to open the file for us |
| 1083 |
openHelpCard("SoXtExaminerViewer.help"); |
| 1084 |
} |
| 1085 |
|
| 1086 |
//////////////////////////////////////////////////////////////////////// |
| 1087 |
// |
| 1088 |
// Description: |
| 1089 |
// Call the base class and stop animating |
| 1090 |
// |
| 1091 |
// Use: virtual protected |
| 1092 |
|
| 1093 |
void |
| 1094 |
SoXtExaminerViewer::bottomWheelStart() |
| 1095 |
// |
| 1096 |
//////////////////////////////////////////////////////////////////////// |
| 1097 |
{ |
| 1098 |
SoXtFullViewer::bottomWheelStart(); |
| 1099 |
stopAnimating(); |
| 1100 |
} |
| 1101 |
|
| 1102 |
//////////////////////////////////////////////////////////////////////// |
| 1103 |
// |
| 1104 |
// Description: |
| 1105 |
// Call the base class and stop animating |
| 1106 |
// |
| 1107 |
// Use: virtual protected |
| 1108 |
|
| 1109 |
void |
| 1110 |
SoXtExaminerViewer::leftWheelStart() |
| 1111 |
// |
| 1112 |
//////////////////////////////////////////////////////////////////////// |
| 1113 |
{ |
| 1114 |
SoXtFullViewer::bottomWheelStart(); |
| 1115 |
stopAnimating(); |
| 1116 |
} |
| 1117 |
|
| 1118 |
//////////////////////////////////////////////////////////////////////// |
| 1119 |
// |
| 1120 |
// Description: |
| 1121 |
// Rotates the object around the screen x axis (called by thumb wheel). |
| 1122 |
// |
| 1123 |
// Use: virtual protected |
| 1124 |
|
| 1125 |
void |
| 1126 |
SoXtExaminerViewer::bottomWheelMotion(float newVal) |
| 1127 |
// |
| 1128 |
//////////////////////////////////////////////////////////////////////// |
| 1129 |
{ |
| 1130 |
// get rotation and apply to camera |
| 1131 |
SbVec3f axis(0, 1, 0); |
| 1132 |
SbRotation rot(axis, bottomWheelVal - newVal); |
| 1133 |
rotateCamera(rot); |
| 1134 |
|
| 1135 |
bottomWheelVal = newVal; |
| 1136 |
} |
| 1137 |
|
| 1138 |
//////////////////////////////////////////////////////////////////////// |
| 1139 |
// |
| 1140 |
// Description: |
| 1141 |
// Rotates the object around the screen y axis (called by thumb wheel). |
| 1142 |
// |
| 1143 |
// Use: virtual protected |
| 1144 |
|
| 1145 |
void |
| 1146 |
SoXtExaminerViewer::leftWheelMotion(float newVal) |
| 1147 |
// |
| 1148 |
//////////////////////////////////////////////////////////////////////// |
| 1149 |
{ |
| 1150 |
// get rotation and apply to camera |
| 1151 |
SbVec3f axis(1, 0, 0); |
| 1152 |
SbRotation rot(axis, newVal - leftWheelVal); |
| 1153 |
rotateCamera(rot); |
| 1154 |
|
| 1155 |
leftWheelVal = newVal; |
| 1156 |
} |
| 1157 |
|
| 1158 |
//////////////////////////////////////////////////////////////////////// |
| 1159 |
// |
| 1160 |
// Description: |
| 1161 |
// Moves the camera closer/further away from the plane of interest |
| 1162 |
// (perspective camera case), else change the camera height (orthographic |
| 1163 |
// camera case). |
| 1164 |
// |
| 1165 |
// Use: virtual protected |
| 1166 |
|
| 1167 |
void |
| 1168 |
SoXtExaminerViewer::rightWheelMotion(float newVal) |
| 1169 |
// |
| 1170 |
//////////////////////////////////////////////////////////////////////// |
| 1171 |
{ |
| 1172 |
if (camera == NULL) |
| 1173 |
return; |
| 1174 |
|
| 1175 |
if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) { |
| 1176 |
// change the ortho camera height |
| 1177 |
SoOrthographicCamera *cam = (SoOrthographicCamera *) camera; |
| 1178 |
cam->height = cam->height.getValue() * powf(2.0, newVal - rightWheelVal); |
| 1179 |
} |
| 1180 |
else { |
| 1181 |
// shorter/grow the focal distance given the wheel rotation |
| 1182 |
float focalDistance = camera->focalDistance.getValue();; |
| 1183 |
float newFocalDist = focalDistance; |
| 1184 |
newFocalDist *= powf(2.0, newVal - rightWheelVal); |
| 1185 |
|
| 1186 |
// finally reposition the camera |
| 1187 |
SbMatrix mx; |
| 1188 |
mx = camera->orientation.getValue(); |
| 1189 |
SbVec3f forward(-mx[2][0], -mx[2][1], -mx[2][2]); |
| 1190 |
camera->position = camera->position.getValue() + |
| 1191 |
(focalDistance - newFocalDist) * forward; |
| 1192 |
camera->focalDistance = newFocalDist; |
| 1193 |
} |
| 1194 |
|
| 1195 |
rightWheelVal = newVal; |
| 1196 |
} |
| 1197 |
|
| 1198 |
//////////////////////////////////////////////////////////////////////// |
| 1199 |
// |
| 1200 |
// Description: |
| 1201 |
// This routine is used to define cursors (can only be called after |
| 1202 |
// window has been realized). |
| 1203 |
// |
| 1204 |
// Use: private |
| 1205 |
|
| 1206 |
void |
| 1207 |
SoXtExaminerViewer::defineCursors() |
| 1208 |
// |
| 1209 |
//////////////////////////////////////////////////////////////////////// |
| 1210 |
{ |
| 1211 |
XColor foreground; |
| 1212 |
Pixmap source; |
| 1213 |
Display *display = getDisplay(); |
| 1214 |
Drawable d = DefaultRootWindow(display); |
| 1215 |
|
| 1216 |
// set color |
| 1217 |
foreground.red = 65535; |
| 1218 |
foreground.green = foreground.blue = 0; |
| 1219 |
|
| 1220 |
// spin cursor |
| 1221 |
source = XCreateBitmapFromData(display, d, |
| 1222 |
so_xt_curved_hand_bits, so_xt_curved_hand_width, so_xt_curved_hand_height); |
| 1223 |
spinCursor = XCreatePixmapCursor(display, source, source, |
| 1224 |
&foreground, &foreground, so_xt_curved_hand_x_hot, so_xt_curved_hand_y_hot); |
| 1225 |
XFreePixmap(display, source); |
| 1226 |
|
| 1227 |
// panning cursor |
| 1228 |
source = XCreateBitmapFromData(display, d, |
| 1229 |
so_xt_flat_hand_bits, so_xt_flat_hand_width, so_xt_flat_hand_height); |
| 1230 |
panCursor = XCreatePixmapCursor(display, source, source, |
| 1231 |
&foreground, &foreground, so_xt_flat_hand_x_hot, so_xt_flat_hand_y_hot); |
| 1232 |
XFreePixmap(display, source); |
| 1233 |
|
| 1234 |
// dolly cursor |
| 1235 |
source = XCreateBitmapFromData(display, d, |
| 1236 |
so_xt_pointing_hand_bits, so_xt_pointing_hand_width, so_xt_pointing_hand_height); |
| 1237 |
dollyCursor = XCreatePixmapCursor(display, source, source, |
| 1238 |
&foreground, &foreground, so_xt_pointing_hand_x_hot, so_xt_pointing_hand_y_hot); |
| 1239 |
XFreePixmap(display, source); |
| 1240 |
|
| 1241 |
// seek cursor |
| 1242 |
source = XCreateBitmapFromData(display, d, |
| 1243 |
so_xt_target_bits, so_xt_target_width, so_xt_target_height); |
| 1244 |
seekCursor = XCreatePixmapCursor(display, source, source, |
| 1245 |
&foreground, &foreground, so_xt_target_x_hot, so_xt_target_y_hot); |
| 1246 |
XFreePixmap(display, source); |
| 1247 |
|
| 1248 |
createdCursors = TRUE; |
| 1249 |
} |
| 1250 |
|
| 1251 |
//////////////////////////////////////////////////////////////////////// |
| 1252 |
// |
| 1253 |
// Description: |
| 1254 |
// Rotates the camera around pt of interest by given rotation |
| 1255 |
// |
| 1256 |
// Use: private |
| 1257 |
|
| 1258 |
void |
| 1259 |
SoXtExaminerViewer::rotateCamera(const SbRotation &rot) |
| 1260 |
// |
| 1261 |
//////////////////////////////////////////////////////////////////////// |
| 1262 |
{ |
| 1263 |
if (camera == NULL) |
| 1264 |
return; |
| 1265 |
|
| 1266 |
// get center of rotation |
| 1267 |
SbRotation camRot = camera->orientation.getValue(); |
| 1268 |
float radius = camera->focalDistance.getValue(); |
| 1269 |
SbMatrix mx; |
| 1270 |
mx = camRot; |
| 1271 |
SbVec3f forward( -mx[2][0], -mx[2][1], -mx[2][2]); |
| 1272 |
SbVec3f center = camera->position.getValue() |
| 1273 |
+ radius * forward; |
| 1274 |
|
| 1275 |
// apply new rotation to the camera |
| 1276 |
camRot = rot * camRot; |
| 1277 |
camera->orientation = camRot; |
| 1278 |
|
| 1279 |
// reposition camera to look at pt of interest |
| 1280 |
mx = camRot; |
| 1281 |
forward.setValue( -mx[2][0], -mx[2][1], -mx[2][2]); |
| 1282 |
camera->position = center - radius * forward; |
| 1283 |
} |
| 1284 |
|
| 1285 |
//////////////////////////////////////////////////////////////////////// |
| 1286 |
// |
| 1287 |
// Description: |
| 1288 |
// Moves the camera into the plane defined by the camera forward vector |
| 1289 |
// and the focal point to follow the new mouse location. |
| 1290 |
// |
| 1291 |
// Use: private |
| 1292 |
|
| 1293 |
void |
| 1294 |
SoXtExaminerViewer::panCamera(const SbVec2f &newLocator) |
| 1295 |
// |
| 1296 |
//////////////////////////////////////////////////////////////////////// |
| 1297 |
{ |
| 1298 |
if (camera == NULL) |
| 1299 |
return; |
| 1300 |
|
| 1301 |
// map new mouse location into the camera focal plane |
| 1302 |
SbViewVolume cameraVolume; |
| 1303 |
SbLine line; |
| 1304 |
SbVec3f newLocator3D; |
| 1305 |
SbVec2s raSize = getGlxSize(); |
| 1306 |
cameraVolume = camera->getViewVolume(raSize[0]/float(raSize[1])); |
| 1307 |
cameraVolume.projectPointToLine(newLocator, line); |
| 1308 |
focalplane.intersect(line, newLocator3D); |
| 1309 |
|
| 1310 |
// move the camera by the delta 3D position amount |
| 1311 |
camera->position = camera->position.getValue() + |
| 1312 |
(locator3D - newLocator3D); |
| 1313 |
|
| 1314 |
// You would think we would have to set locator3D to |
| 1315 |
// newLocator3D here. But we don't, because moving the camera |
| 1316 |
// essentially makes locator3D equal to newLocator3D in the |
| 1317 |
// transformed space, and we will project the next newLocator3D in |
| 1318 |
// this transformed space. |
| 1319 |
} |
| 1320 |
|
| 1321 |
//////////////////////////////////////////////////////////////////////// |
| 1322 |
// |
| 1323 |
// Description: |
| 1324 |
// rotates the camera using the sheet sphere projector, given the new |
| 1325 |
// mouse location. |
| 1326 |
// |
| 1327 |
// Use: private |
| 1328 |
|
| 1329 |
void |
| 1330 |
SoXtExaminerViewer::spinCamera(const SbVec2f &newLocator) |
| 1331 |
// |
| 1332 |
//////////////////////////////////////////////////////////////////////// |
| 1333 |
{ |
| 1334 |
// find rotation and rotate camera |
| 1335 |
SbRotation rot; |
| 1336 |
sphereSheet->projectAndGetRotation(newLocator, rot); |
| 1337 |
rot.invert(); |
| 1338 |
|
| 1339 |
rotateCamera(rot); |
| 1340 |
|
| 1341 |
// save rotation for animation |
| 1342 |
lastIndex = ((lastIndex+1) % ROT_BUFF_SIZE); |
| 1343 |
rotBuffer[lastIndex] = rot; |
| 1344 |
|
| 1345 |
// check if queue is full |
| 1346 |
if (((lastIndex+1) % ROT_BUFF_SIZE) == firstIndex) |
| 1347 |
firstIndex = ((firstIndex+1) % ROT_BUFF_SIZE); |
| 1348 |
} |
| 1349 |
|
| 1350 |
//////////////////////////////////////////////////////////////////////// |
| 1351 |
// |
| 1352 |
// Description: |
| 1353 |
// Moves the camera forward/backward based on the new mouse position. |
| 1354 |
// (perspective camera), else change the camera height (orthographic |
| 1355 |
// camera case). |
| 1356 |
// |
| 1357 |
// Use: private |
| 1358 |
|
| 1359 |
void |
| 1360 |
SoXtExaminerViewer::dollyCamera(const SbVec2s &newLocator) |
| 1361 |
// |
| 1362 |
//////////////////////////////////////////////////////////////////////// |
| 1363 |
{ |
| 1364 |
if (camera == NULL) |
| 1365 |
return; |
| 1366 |
|
| 1367 |
// moving the mouse up/down will move the camera futher/closer. |
| 1368 |
// moving the camera sideway will not move the camera at all |
| 1369 |
float d = (newLocator[1] - locator[1]) / 40.0; |
| 1370 |
|
| 1371 |
if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) { |
| 1372 |
// change the ortho camera height |
| 1373 |
SoOrthographicCamera *cam = (SoOrthographicCamera *) camera; |
| 1374 |
cam->height = cam->height.getValue() * powf(2.0, d); |
| 1375 |
} |
| 1376 |
else { |
| 1377 |
// shorter/grow the focal distance given the mouse move |
| 1378 |
float focalDistance = camera->focalDistance.getValue();; |
| 1379 |
float newFocalDist = focalDistance * powf(2.0, d); |
| 1380 |
|
| 1381 |
// finally reposition the camera |
| 1382 |
SbMatrix mx; |
| 1383 |
mx = camera->orientation.getValue(); |
| 1384 |
SbVec3f forward(-mx[2][0], -mx[2][1], -mx[2][2]); |
| 1385 |
camera->position = camera->position.getValue() + |
| 1386 |
(focalDistance - newFocalDist) * forward; |
| 1387 |
camera->focalDistance = newFocalDist; |
| 1388 |
} |
| 1389 |
|
| 1390 |
locator = newLocator; |
| 1391 |
} |
| 1392 |
|
| 1393 |
//////////////////////////////////////////////////////////////////////// |
| 1394 |
// |
| 1395 |
// Description: |
| 1396 |
// Routine which animates the ball spinning (called by sensor). |
| 1397 |
// |
| 1398 |
// Use: private |
| 1399 |
|
| 1400 |
void |
| 1401 |
SoXtExaminerViewer::doSpinAnimation() |
| 1402 |
// |
| 1403 |
//////////////////////////////////////////////////////////////////////// |
| 1404 |
{ |
| 1405 |
// |
| 1406 |
// check if average rotation needs to be computed |
| 1407 |
// |
| 1408 |
|
| 1409 |
if (computeAverage) { |
| 1410 |
float averageAngle, angle; |
| 1411 |
SbVec3f averageAxis, axis; |
| 1412 |
|
| 1413 |
// get number of samples |
| 1414 |
int num = (((lastIndex - firstIndex) + 1 + |
| 1415 |
ROT_BUFF_SIZE) % ROT_BUFF_SIZE); |
| 1416 |
|
| 1417 |
// check for not enough samples |
| 1418 |
if (num < 2) { |
| 1419 |
stopAnimating(); |
| 1420 |
return; |
| 1421 |
} |
| 1422 |
|
| 1423 |
// get average axis of rotation |
| 1424 |
// ??? right now only take one sample |
| 1425 |
rotBuffer[firstIndex].getValue(averageAxis, angle); |
| 1426 |
|
| 1427 |
// get average angle of rotation |
| 1428 |
averageAngle = 0; |
| 1429 |
for (int i=0; i<num; i++) { |
| 1430 |
int n = (firstIndex + i) % ROT_BUFF_SIZE; |
| 1431 |
rotBuffer[n].getValue(axis, angle); |
| 1432 |
averageAngle += angle; |
| 1433 |
} |
| 1434 |
averageAngle /= float(num); |
| 1435 |
|
| 1436 |
averageRotation.setValue(averageAxis, averageAngle); |
| 1437 |
computeAverage = FALSE; |
| 1438 |
} |
| 1439 |
|
| 1440 |
// |
| 1441 |
// rotate camera by average rotation |
| 1442 |
// |
| 1443 |
rotateCamera(averageRotation); |
| 1444 |
} |
| 1445 |
|
| 1446 |
//////////////////////////////////////////////////////////////////////// |
| 1447 |
// |
| 1448 |
// Description: |
| 1449 |
// Show/hide the pref sheet feedback size wheel and label. |
| 1450 |
// |
| 1451 |
// Use: private |
| 1452 |
|
| 1453 |
void |
| 1454 |
SoXtExaminerViewer::toggleFeedbackWheelSize(Widget toggle) |
| 1455 |
// |
| 1456 |
//////////////////////////////////////////////////////////////////////// |
| 1457 |
{ |
| 1458 |
if ( feedbackFlag ) { |
| 1459 |
Widget parent = XtParent(toggle); |
| 1460 |
Arg args[12]; |
| 1461 |
int n; |
| 1462 |
|
| 1463 |
// create the label/thumb/text/label in the toggle parent |
| 1464 |
feedbackLabel[0] = XtCreateWidget(rl.axesSizeLabel, |
| 1465 |
xmLabelGadgetClass, parent, NULL, 0); |
| 1466 |
|
| 1467 |
n = 0; |
| 1468 |
XtSetArg(args[n], XmNvalue, 0); n++; |
| 1469 |
XtSetArg(args[n], SgNangleRange, 0); n++; |
| 1470 |
XtSetArg(args[n], SgNunitsPerRotation, 360); n++; |
| 1471 |
XtSetArg(args[n], SgNshowHomeButton, FALSE); n++; |
| 1472 |
XtSetArg(args[n], XmNhighlightThickness, 0); n++; |
| 1473 |
XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++; |
| 1474 |
feedbackSizeWheel = SgCreateThumbWheel(parent, NULL, args, n); |
| 1475 |
|
| 1476 |
XtAddCallback(feedbackSizeWheel, XmNvalueChangedCallback, |
| 1477 |
(XtCallbackProc) SoXtExaminerViewer::feedbackSizeWheelCB, (XtPointer) this); |
| 1478 |
XtAddCallback(feedbackSizeWheel, XmNdragCallback, |
| 1479 |
(XtCallbackProc) SoXtExaminerViewer::feedbackSizeWheelCB, (XtPointer) this); |
| 1480 |
feedbackSizeWheelVal = 0; |
| 1481 |
|
| 1482 |
n = 0; |
| 1483 |
char str[15]; |
| 1484 |
sprintf(str, "%d", int(feedbackSize)); |
| 1485 |
XtSetArg(args[n], XmNvalue, str); n++; |
| 1486 |
XtSetArg(args[n], XmNhighlightThickness, 1); n++; |
| 1487 |
XtSetArg(args[n], XmNcolumns, 3); n++; |
| 1488 |
feedbackField = XtCreateWidget("", xmTextWidgetClass, |
| 1489 |
parent, args, n); |
| 1490 |
|
| 1491 |
XtAddCallback(feedbackField, XmNactivateCallback, |
| 1492 |
(XtCallbackProc) SoXtExaminerViewer::feedbackSizeFieldCB, |
| 1493 |
(XtPointer) this); |
| 1494 |
|
| 1495 |
feedbackLabel[1] = XtCreateWidget("pixels", |
| 1496 |
xmLabelGadgetClass, parent, NULL, 0); |
| 1497 |
|
| 1498 |
// layout |
| 1499 |
n = 0; |
| 1500 |
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; |
| 1501 |
XtSetArg(args[n], XmNleftOffset, 20); n++; |
| 1502 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; |
| 1503 |
XtSetArg(args[n], XmNtopWidget, toggle); n++; |
| 1504 |
XtSetArg(args[n], XmNtopOffset, 5); n++; |
| 1505 |
XtSetValues(feedbackLabel[0], args, n); |
| 1506 |
|
| 1507 |
n = 0; |
| 1508 |
XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; |
| 1509 |
XtSetArg(args[n], XmNleftWidget, feedbackLabel[0]); n++; |
| 1510 |
XtSetArg(args[n], XmNleftOffset, 5); n++; |
| 1511 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++; |
| 1512 |
XtSetArg(args[n], XmNtopWidget, feedbackLabel[0]); n++; |
| 1513 |
XtSetValues(feedbackSizeWheel, args, n); |
| 1514 |
|
| 1515 |
n = 0; |
| 1516 |
XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; |
| 1517 |
XtSetArg(args[n], XmNleftWidget, feedbackSizeWheel); n++; |
| 1518 |
XtSetArg(args[n], XmNleftOffset, 3); n++; |
| 1519 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++; |
| 1520 |
XtSetArg(args[n], XmNtopWidget, feedbackSizeWheel); n++; |
| 1521 |
XtSetArg(args[n], XmNtopOffset, -5); n++; |
| 1522 |
XtSetValues(feedbackField, args, n); |
| 1523 |
|
| 1524 |
n = 0; |
| 1525 |
XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; |
| 1526 |
XtSetArg(args[n], XmNleftWidget, feedbackField); n++; |
| 1527 |
XtSetArg(args[n], XmNleftOffset, 5); n++; |
| 1528 |
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++; |
| 1529 |
XtSetArg(args[n], XmNbottomWidget, feedbackLabel[0]); n++; |
| 1530 |
XtSetValues(feedbackLabel[1], args, n); |
| 1531 |
|
| 1532 |
// manage children |
| 1533 |
XtManageChild(feedbackLabel[0]); |
| 1534 |
XtManageChild(feedbackSizeWheel); |
| 1535 |
XtManageChild(feedbackField); |
| 1536 |
XtManageChild(feedbackLabel[1]); |
| 1537 |
} |
| 1538 |
else { |
| 1539 |
// destroys the widgets |
| 1540 |
XtDestroyWidget(feedbackLabel[1]); |
| 1541 |
XtDestroyWidget(feedbackField); |
| 1542 |
XtDestroyWidget(feedbackSizeWheel); |
| 1543 |
XtDestroyWidget(feedbackLabel[0]); |
| 1544 |
} |
| 1545 |
} |
| 1546 |
|
| 1547 |
//////////////////////////////////////////////////////////////////////// |
| 1548 |
// |
| 1549 |
// Description: |
| 1550 |
// Build the parent class widget, then register this widget. |
| 1551 |
// |
| 1552 |
// Use: protected |
| 1553 |
Widget |
| 1554 |
SoXtExaminerViewer::buildWidget(Widget parent) |
| 1555 |
// |
| 1556 |
//////////////////////////////////////////////////////////////////////// |
| 1557 |
{ |
| 1558 |
// Get a resource value for menu title. |
| 1559 |
if (firstBuild) { |
| 1560 |
SoXtResource xrp(parent); |
| 1561 |
if (!xrp.getResource( "examinViewer", "ExaminViewer", rl.examinViewer )) |
| 1562 |
rl.examinViewer = defaultLabel[0]; |
| 1563 |
setPopupMenuString(rl.examinViewer); |
| 1564 |
} |
| 1565 |
|
| 1566 |
// Create the root widget and register it with a class name |
| 1567 |
Widget w = SoXtFullViewer::buildWidget(parent); |
| 1568 |
|
| 1569 |
// If first build, get resource values |
| 1570 |
if (firstBuild) { |
| 1571 |
// Full viewer registered the widget for us |
| 1572 |
SoXtResource xr(w); |
| 1573 |
SbBool flag; |
| 1574 |
short val; |
| 1575 |
|
| 1576 |
if (xr.getResource("spinAnimation", "SpinAnimation", flag)) |
| 1577 |
setAnimationEnabled(flag); |
| 1578 |
if (xr.getResource("pointOfRotationAxes", "PointOfRotationAxes", flag)) |
| 1579 |
setFeedbackVisibility(flag); |
| 1580 |
if (xr.getResource("axesSize", "AxesSize", val)) |
| 1581 |
feedbackSize = val; |
| 1582 |
// |
| 1583 |
if (!xr.getResource( "roty", "Roty", rl.roty )) |
| 1584 |
rl.roty = defaultLabel[1]; |
| 1585 |
if (!xr.getResource( "rotx", "Rotx", rl.rotx )) |
| 1586 |
rl.rotx = defaultLabel[2]; |
| 1587 |
if (!xr.getResource( "preferenceSheet","PreferenceSheet",rl.preferenceSheet )) |
| 1588 |
rl.preferenceSheet = defaultLabel[3]; |
| 1589 |
if (!xr.getResource( "zoom", "Zoom", rl.zoom )) |
| 1590 |
rl.zoom = defaultLabel[4]; |
| 1591 |
if (!xr.getResource( "dolly", "Dolly", rl.dolly )) |
| 1592 |
rl.dolly = defaultLabel[5]; |
| 1593 |
if (!xr.getResource( "axesSizeLabel", "AxesSizeLabel", rl.axesSizeLabel )) |
| 1594 |
rl.axesSizeLabel = defaultLabel[6]; |
| 1595 |
|
| 1596 |
// assign decoration names |
| 1597 |
setBottomWheelString(rl.roty); |
| 1598 |
setLeftWheelString(rl.rotx); |
| 1599 |
setPrefSheetString(rl.preferenceSheet); |
| 1600 |
|
| 1601 |
firstBuild = FALSE; |
| 1602 |
} |
| 1603 |
|
| 1604 |
return w; |
| 1605 |
} |
| 1606 |
|
| 1607 |
//////////////////////////////////////////////////////////////////////// |
| 1608 |
// |
| 1609 |
// Description: |
| 1610 |
// add our own button to the existing list |
| 1611 |
// |
| 1612 |
// Use: virtual protected |
| 1613 |
void |
| 1614 |
SoXtExaminerViewer::createViewerButtons(Widget parent) |
| 1615 |
// |
| 1616 |
//////////////////////////////////////////////////////////////////////// |
| 1617 |
{ |
| 1618 |
// get the default buttons |
| 1619 |
SoXtFullViewer::createViewerButtons(parent); |
| 1620 |
|
| 1621 |
// allocate our buttons |
| 1622 |
buttonList[CAM_PUSH] = new SoXtBitmapButton(parent, FALSE); |
| 1623 |
buttonList[CAM_PUSH]->setIcon(so_xt_persp_bits, so_xt_icon_width, so_xt_icon_height); |
| 1624 |
Widget w = buttonList[CAM_PUSH]->getWidget(); |
| 1625 |
XtAddCallback(w, XmNactivateCallback, |
| 1626 |
(XtCallbackProc) SoXtExaminerViewer::camPushCB, (XtPointer) this); |
| 1627 |
|
| 1628 |
// add this button to the list... |
| 1629 |
viewerButtonWidgets->append(w); |
| 1630 |
} |
| 1631 |
|
| 1632 |
//////////////////////////////////////////////////////////////////////// |
| 1633 |
// |
| 1634 |
// Description: |
| 1635 |
// read the point of interest geometry, which will be placed |
| 1636 |
// right after the camera node (or right after the headlight |
| 1637 |
// if the headlight is turned on). |
| 1638 |
// |
| 1639 |
// Use: private |
| 1640 |
void |
| 1641 |
SoXtExaminerViewer::createFeedbackNodes() |
| 1642 |
// |
| 1643 |
//////////////////////////////////////////////////////////////////////// |
| 1644 |
{ |
| 1645 |
// make sure we havn't built this yet... |
| 1646 |
if (feedbackRoot) |
| 1647 |
return; |
| 1648 |
|
| 1649 |
feedbackRoot = new SoSeparator(1); |
| 1650 |
feedbackSwitch = new SoSwitch(3); |
| 1651 |
feedbackTransNode = new SoTranslation; |
| 1652 |
feedbackScaleNode = new SoScale; |
| 1653 |
feedbackRoot->ref(); |
| 1654 |
feedbackRoot->addChild( feedbackSwitch ); |
| 1655 |
feedbackSwitch->addChild( feedbackTransNode ); |
| 1656 |
feedbackSwitch->addChild( feedbackScaleNode ); |
| 1657 |
SoInput in; |
| 1658 |
in.setBuffer((void *)geometryBuffer, (size_t) strlen(geometryBuffer)); |
| 1659 |
SoNode *node; |
| 1660 |
SbBool ok = SoDB::read(&in, node); |
| 1661 |
if (ok && node != NULL) |
| 1662 |
feedbackSwitch->addChild(node); |
| 1663 |
#ifdef DEBUG |
| 1664 |
else |
| 1665 |
SoDebugError::post("SoXtExaminerViewer::createFeedbackNodes", |
| 1666 |
"couldn't read feedback axis geometry"); |
| 1667 |
#endif |
| 1668 |
} |
| 1669 |
|
| 1670 |
// |
| 1671 |
// redefine those generic virtual functions |
| 1672 |
// |
| 1673 |
const char * |
| 1674 |
SoXtExaminerViewer::getDefaultWidgetName() const |
| 1675 |
{ return thisClassName; } |
| 1676 |
|
| 1677 |
const char * |
| 1678 |
SoXtExaminerViewer::getDefaultTitle() const |
| 1679 |
{ return rl.examinViewer; } |
| 1680 |
|
| 1681 |
const char * |
| 1682 |
SoXtExaminerViewer::getDefaultIconTitle() const |
| 1683 |
{ return rl.examinViewer; } |
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
// |
| 1688 |
//////////////////////////////////////////////////////////////////////// |
| 1689 |
// static callbacks stubs |
| 1690 |
//////////////////////////////////////////////////////////////////////// |
| 1691 |
// |
| 1692 |
|
| 1693 |
void |
| 1694 |
SoXtExaminerViewer::camPushCB(Widget, SoXtExaminerViewer *v, void *) |
| 1695 |
{ v->toggleCameraType(); } |
| 1696 |
|
| 1697 |
|
| 1698 |
void |
| 1699 |
SoXtExaminerViewer::animationSensorCB(void *v, SoSensor *) |
| 1700 |
{ ((SoXtExaminerViewer *) v)->doSpinAnimation(); } |
| 1701 |
|
| 1702 |
void |
| 1703 |
SoXtExaminerViewer::animPrefSheetToggleCB(Widget toggle, |
| 1704 |
SoXtExaminerViewer *v, void *) |
| 1705 |
{ |
| 1706 |
v->setAnimationEnabled( XmToggleButtonGetState(toggle) ); |
| 1707 |
} |
| 1708 |
|
| 1709 |
void |
| 1710 |
SoXtExaminerViewer::feedbackPrefSheetToggleCB(Widget toggle, |
| 1711 |
SoXtExaminerViewer *v, void *) |
| 1712 |
{ |
| 1713 |
// show/hide the feedback |
| 1714 |
v->setFeedbackVisibility( XmToggleButtonGetState(toggle) ); |
| 1715 |
|
| 1716 |
// show/hide the extra size setting |
| 1717 |
v->toggleFeedbackWheelSize(toggle); |
| 1718 |
} |
| 1719 |
|
| 1720 |
void |
| 1721 |
SoXtExaminerViewer::feedbackSizeWheelCB(Widget, SoXtExaminerViewer *v, XtPointer *d) |
| 1722 |
{ |
| 1723 |
static SbBool firstDrag = TRUE; |
| 1724 |
SgThumbWheelCallbackStruct *data = (SgThumbWheelCallbackStruct *) d; |
| 1725 |
|
| 1726 |
if (data->reason == XmCR_DRAG) { |
| 1727 |
// for the first move, invoke the start callbacks |
| 1728 |
if (firstDrag) { |
| 1729 |
v->interactiveCountInc(); |
| 1730 |
firstDrag = FALSE; |
| 1731 |
} |
| 1732 |
|
| 1733 |
// grow/shrink the feedback based on the wheel rotation |
| 1734 |
v->feedbackSize *= powf(12, (data->value - v->feedbackSizeWheelVal) / 360.0); |
| 1735 |
v->feedbackSizeWheelVal = data->value; |
| 1736 |
|
| 1737 |
// update the text field |
| 1738 |
char str[15]; |
| 1739 |
sprintf(str, "%d", int(v->feedbackSize)); |
| 1740 |
XmTextSetString(v->feedbackField, str); |
| 1741 |
|
| 1742 |
// redraw since the wheel size isn't a field in the scene |
| 1743 |
if (v->isViewing()) |
| 1744 |
v->scheduleRedraw(); |
| 1745 |
} |
| 1746 |
else { |
| 1747 |
// reason = XmCR_VALUE_CHANGED, invoke the finish callbacks |
| 1748 |
v->interactiveCountDec(); |
| 1749 |
firstDrag = TRUE; |
| 1750 |
} |
| 1751 |
} |
| 1752 |
|
| 1753 |
void |
| 1754 |
SoXtExaminerViewer::feedbackSizeFieldCB(Widget field, SoXtExaminerViewer *v, void *) |
| 1755 |
{ |
| 1756 |
// get text value from the field |
| 1757 |
char *str = XmTextGetString(field); |
| 1758 |
int val; |
| 1759 |
if ( sscanf(str, "%d", &val) && val > 0) |
| 1760 |
v->setFeedbackSize(val); |
| 1761 |
else |
| 1762 |
val = int(v->feedbackSize); |
| 1763 |
free(str); |
| 1764 |
|
| 1765 |
// reformat text field |
| 1766 |
char valStr[15]; |
| 1767 |
sprintf(valStr, "%d", val); |
| 1768 |
XmTextSetString(field, valStr); |
| 1769 |
|
| 1770 |
// make the text field loose the focus |
| 1771 |
XmProcessTraversal(SoXt::getShellWidget(field), XmTRAVERSE_CURRENT); |
| 1772 |
} |
| 1773 |
|
| 1774 |
// called when the viewer becomes visible/hidden - when hidden, make |
| 1775 |
// sure to temporary stop any ongoing animation (and restart it as soon |
| 1776 |
// as we become visible). |
| 1777 |
// |
| 1778 |
void |
| 1779 |
SoXtExaminerViewer::visibilityChangeCB(void *pt, SbBool visible) |
| 1780 |
{ |
| 1781 |
SoXtExaminerViewer *p = (SoXtExaminerViewer *)pt; |
| 1782 |
|
| 1783 |
// only do this if we are/were spinning.... |
| 1784 |
if (! p->animatingFlag) |
| 1785 |
return; |
| 1786 |
|
| 1787 |
if (visible) { |
| 1788 |
// we now are visible again so attach the field sensor |
| 1789 |
p->animationSensor->attach(viewerRealTime); |
| 1790 |
} |
| 1791 |
else { |
| 1792 |
// if hidden, detach the field sensor, but don't change the |
| 1793 |
// animatingFlag var to let us know we need to turn it back on |
| 1794 |
// when we become visible.... |
| 1795 |
p->animationSensor->detach(); |
| 1796 |
p->animationSensor->unschedule(); |
| 1797 |
} |
| 1798 |
} |