| 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 |
_______________________________________________________________________ |
| 42 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 43 |
| |
| 44 |
| $Revision: 1.11 $ |
| 45 |
| |
| 46 |
| Classes : SoSceneViewer |
| 47 |
| |
| 48 |
| Author(s) : Thad Beier, David Mott, Alain Dumesny, Paul Isaacs, |
| 49 |
| Rikk Carey, Dave Immel |
| 50 |
| |
| 51 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 52 |
_______________________________________________________________________ |
| 53 |
*/ |
| 54 |
|
| 55 |
#include <cstdlib> // for system() and getenv() |
| 56 |
#include <unistd.h> // for access() |
| 57 |
|
| 58 |
#include <X11/StringDefs.h> |
| 59 |
#include <X11/Intrinsic.h> |
| 60 |
#include <X11/Xatom.h> |
| 61 |
|
| 62 |
#include <Xm/Protocols.h> |
| 63 |
#include <Xm/Xm.h> |
| 64 |
#include <Xm/BulletinB.h> |
| 65 |
#include <Xm/CascadeB.h> |
| 66 |
#include <Xm/CascadeBG.h> |
| 67 |
#include <Xm/FileSB.h> |
| 68 |
#include <Xm/Form.h> |
| 69 |
#include <Xm/Label.h> |
| 70 |
#include <Xm/FileSB.h> |
| 71 |
#include <Xm/PushB.h> |
| 72 |
#include <Xm/PushBG.h> |
| 73 |
#include <Xm/SeparatoG.h> |
| 74 |
#include <Xm/Text.h> |
| 75 |
#include <Xm/ToggleB.h> |
| 76 |
#include <Xm/ToggleBG.h> |
| 77 |
#include <Xm/DropTrans.h> |
| 78 |
|
| 79 |
#include <Inventor/SoDB.h> |
| 80 |
#include <Inventor/misc/SoByteStream.h> |
| 81 |
#include <Inventor/SoNodeKitPath.h> |
| 82 |
#include <Inventor/SoPickedPoint.h> |
| 83 |
#include <Inventor/SoLists.h> |
| 84 |
#include <Inventor/Xt/SoXt.h> |
| 85 |
#include <Inventor/Xt/SoXtClipboard.h> |
| 86 |
#include <Inventor/Xt/SoXtDirectionalLightEditor.h> |
| 87 |
#include <Inventor/Xt/SoXtMaterialEditor.h> |
| 88 |
#include <Inventor/Xt/SoXtPrintDialog.h> |
| 89 |
#include <Inventor/Xt/SoXtResource.h> |
| 90 |
#include <Inventor/Xt/SoXtTransformSliderSet.h> |
| 91 |
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h> |
| 92 |
#include <Inventor/Xt/viewers/SoXtFlyViewer.h> |
| 93 |
#include <Inventor/Xt/viewers/SoXtPlaneViewer.h> |
| 94 |
#include <Inventor/Xt/viewers/SoXtWalkViewer.h> |
| 95 |
#include <Inventor/actions/SoBoxHighlightRenderAction.h> |
| 96 |
#include <Inventor/actions/SoGetBoundingBoxAction.h> |
| 97 |
#include <Inventor/actions/SoGetMatrixAction.h> |
| 98 |
#include <Inventor/actions/SoSearchAction.h> |
| 99 |
#include <Inventor/actions/SoWriteAction.h> |
| 100 |
#include <Inventor/details/SoNodeKitDetail.h> |
| 101 |
#include <Inventor/draggers/SoDirectionalLightDragger.h> |
| 102 |
#include <Inventor/draggers/SoTabBoxDragger.h> |
| 103 |
#include <Inventor/manips/SoCenterballManip.h> |
| 104 |
#include <Inventor/manips/SoDirectionalLightManip.h> |
| 105 |
#include <Inventor/manips/SoHandleBoxManip.h> |
| 106 |
#include <Inventor/manips/SoJackManip.h> |
| 107 |
#include <Inventor/manips/SoPointLightManip.h> |
| 108 |
#include <Inventor/manips/SoSpotLightManip.h> |
| 109 |
#include <Inventor/manips/SoTabBoxManip.h> |
| 110 |
#include <Inventor/manips/SoTrackballManip.h> |
| 111 |
#include <Inventor/manips/SoTransformBoxManip.h> |
| 112 |
#include <Inventor/manips/SoTransformerManip.h> |
| 113 |
#include <Inventor/nodekits/SoBaseKit.h> |
| 114 |
#include <Inventor/nodekits/SoCameraKit.h> |
| 115 |
#include <Inventor/nodekits/SoSceneKit.h> |
| 116 |
#include <Inventor/nodes/SoCallback.h> |
| 117 |
#include <Inventor/nodes/SoCube.h> |
| 118 |
#include <Inventor/nodes/SoDirectionalLight.h> |
| 119 |
#include <Inventor/nodes/SoEnvironment.h> |
| 120 |
#include <Inventor/nodes/SoLabel.h> |
| 121 |
#include <Inventor/nodes/SoLight.h> |
| 122 |
#include <Inventor/nodes/SoMaterial.h> |
| 123 |
#include <Inventor/nodes/SoOrthographicCamera.h> |
| 124 |
#include <Inventor/nodes/SoPointLight.h> |
| 125 |
#include <Inventor/nodes/SoSelection.h> |
| 126 |
#include <Inventor/nodes/SoShape.h> |
| 127 |
#include <Inventor/nodes/SoSpotLight.h> |
| 128 |
#include <Inventor/nodes/SoSwitch.h> |
| 129 |
#include <Inventor/nodes/SoTranslation.h> |
| 130 |
|
| 131 |
#include "SoSceneViewer.h" |
| 132 |
#include "SoSceneMenu.h" |
| 133 |
#include "SvManipList.h" |
| 134 |
#include "../../samples/widgets/MyColorEditor.h" |
| 135 |
#include "../../samples/widgets/MyFileRead.h" |
| 136 |
#include "../../samples/widgets/MyDropSite.h" |
| 137 |
#include "../../samples/common/InventorLogo.h" |
| 138 |
|
| 139 |
#include <GL/gl.h> |
| 140 |
#ifdef DEBUG |
| 141 |
#include <assert.h> |
| 142 |
#endif |
| 143 |
|
| 144 |
|
| 145 |
// |
| 146 |
// Macros and constants |
| 147 |
// |
| 148 |
|
| 149 |
// toggle button macros |
| 150 |
#define TOGGLE_ON(BUTTON) \ |
| 151 |
XmToggleButtonSetState((Widget) BUTTON, TRUE, FALSE) |
| 152 |
#define TOGGLE_OFF(BUTTON) \ |
| 153 |
XmToggleButtonSetState((Widget) BUTTON, FALSE, FALSE) |
| 154 |
|
| 155 |
#define FOG_FUDGE 1.6 |
| 156 |
#define SV_NUM_LIGHTS 6 |
| 157 |
|
| 158 |
#define SWITCH_LIGHT_OFF(SWITCH) (SWITCH)->whichChild.setValue(SO_SWITCH_NONE) |
| 159 |
#define SWITCH_LIGHT_ON(SWITCH) (SWITCH)->whichChild.setValue(SO_SWITCH_ALL) |
| 160 |
#define IS_LIGHT_ON(SWITCH) ((SWITCH)->whichChild.getValue() == SO_SWITCH_ALL) |
| 161 |
|
| 162 |
#define SV_ENV_LABEL "SoSceneViewer Environment v3.0" |
| 163 |
|
| 164 |
#define _ATOM_(DISPLAY,NAME) (XmInternAtom(DISPLAY, NAME, False)) |
| 165 |
|
| 166 |
#define SCREEN(w) XScreenNumberOfScreen(XtScreen(w)) |
| 167 |
|
| 168 |
// |
| 169 |
// Structs |
| 170 |
// |
| 171 |
|
| 172 |
struct SoSceneViewerData { |
| 173 |
int id; |
| 174 |
SoSceneViewer *classPt; |
| 175 |
Widget widget; |
| 176 |
}; |
| 177 |
|
| 178 |
class SvLightData { |
| 179 |
public: |
| 180 |
// Constructor inits everything to NULL |
| 181 |
SvLightData(); |
| 182 |
|
| 183 |
SoSceneViewer *classPt; |
| 184 |
SoSwitch *lightSwitch; |
| 185 |
SoTranslation *translation; // for placing a directional light manip |
| 186 |
SoScale *scale; |
| 187 |
SoLight *light; |
| 188 |
SoScale *scaleInverse; |
| 189 |
SoTranslation *translationInverse; |
| 190 |
SoType type; |
| 191 |
char *name; |
| 192 |
MyColorEditor *colorEditor; |
| 193 |
SbBool isManip(); |
| 194 |
SbBool shouldBeManip; // Used to remember what it was when |
| 195 |
// they all get turned off for writing, |
| 196 |
// printing, etc. |
| 197 |
Widget cascadeWidget; |
| 198 |
Widget submenuWidget; |
| 199 |
Widget onOffWidget; |
| 200 |
Widget iconWidget; |
| 201 |
Widget editColorWidget; |
| 202 |
Widget removeWidget; |
| 203 |
}; |
| 204 |
|
| 205 |
SvLightData::SvLightData() |
| 206 |
{ |
| 207 |
classPt = NULL; |
| 208 |
lightSwitch = NULL; |
| 209 |
translation = NULL; |
| 210 |
scale = NULL; |
| 211 |
light = NULL; |
| 212 |
scaleInverse = NULL; |
| 213 |
translationInverse = NULL; |
| 214 |
name = NULL; |
| 215 |
colorEditor = NULL; |
| 216 |
shouldBeManip = FALSE; |
| 217 |
cascadeWidget = NULL; |
| 218 |
submenuWidget = NULL; |
| 219 |
onOffWidget = NULL; |
| 220 |
iconWidget = NULL; |
| 221 |
editColorWidget = NULL; |
| 222 |
removeWidget = NULL; |
| 223 |
} |
| 224 |
|
| 225 |
SbBool SvLightData::isManip() |
| 226 |
{ |
| 227 |
if (light == NULL) |
| 228 |
return FALSE; |
| 229 |
|
| 230 |
if (light->isOfType( SoDirectionalLightManip::getClassTypeId())) |
| 231 |
return TRUE; |
| 232 |
else if (light->isOfType( SoPointLightManip::getClassTypeId()) ) |
| 233 |
return TRUE; |
| 234 |
else if (light->isOfType( SoSpotLightManip::getClassTypeId()) ) |
| 235 |
return TRUE; |
| 236 |
|
| 237 |
return FALSE; |
| 238 |
} |
| 239 |
|
| 240 |
//////////////////////////////////////////////////////////////////////// |
| 241 |
// |
| 242 |
// Set the Inventor logo on the screen. |
| 243 |
// |
| 244 |
static void |
| 245 |
logoCB(void *, SoAction *action) |
| 246 |
{ |
| 247 |
if (action->isOfType(SoGLRenderAction::getClassTypeId())) { |
| 248 |
glViewport(0, 0, 80, 80); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
static void |
| 253 |
setOverlayLogo(SoXtRenderArea *ra) |
| 254 |
{ |
| 255 |
static SoSeparator *logo = NULL; |
| 256 |
|
| 257 |
if (logo == NULL) { |
| 258 |
SoInput in; |
| 259 |
in.setBuffer((void *)ivLogo, ivLogoSize); |
| 260 |
logo = SoDB::readAll(&in); |
| 261 |
logo->ref(); |
| 262 |
|
| 263 |
// Add a callback node which will set the viewport |
| 264 |
SoCallback *cb = new SoCallback; |
| 265 |
cb->setCallback(logoCB); |
| 266 |
logo->insertChild(cb, 0); |
| 267 |
} |
| 268 |
|
| 269 |
SbColor col(1, 1, 1); |
| 270 |
ra->setOverlayColorMap(1, 1, &col); |
| 271 |
ra->setOverlaySceneGraph(logo); |
| 272 |
} |
| 273 |
// |
| 274 |
//////////////////////////////////////////////////////////////////////// |
| 275 |
|
| 276 |
//////////////////////////////////////////////////////////////////////// |
| 277 |
// |
| 278 |
// Public constructor - build the widget right now |
| 279 |
// |
| 280 |
SoSceneViewer::SoSceneViewer( |
| 281 |
Widget parent, |
| 282 |
const char *name, |
| 283 |
SbBool buildInsideParent, |
| 284 |
SoSelection *inputGraph, |
| 285 |
const char *envFile) |
| 286 |
: SoXtComponent( |
| 287 |
parent, |
| 288 |
name, |
| 289 |
buildInsideParent) |
| 290 |
// |
| 291 |
//////////////////////////////////////////////////////////////////////// |
| 292 |
{ |
| 293 |
// In this case, render area is what the app wants, so buildNow = TRUE |
| 294 |
constructorCommon(inputGraph, envFile, TRUE); |
| 295 |
} |
| 296 |
|
| 297 |
//////////////////////////////////////////////////////////////////////// |
| 298 |
// |
| 299 |
// SoEXTENDER constructor - the subclass tells us whether to build or not |
| 300 |
// |
| 301 |
SoSceneViewer::SoSceneViewer( |
| 302 |
Widget parent, |
| 303 |
const char *name, |
| 304 |
SbBool buildInsideParent, |
| 305 |
SoSelection *inputGraph, |
| 306 |
const char *envFile, |
| 307 |
SbBool buildNow) |
| 308 |
: SoXtComponent( |
| 309 |
parent, |
| 310 |
name, |
| 311 |
buildInsideParent) |
| 312 |
// |
| 313 |
//////////////////////////////////////////////////////////////////////// |
| 314 |
{ |
| 315 |
// In this case, render area may be what the app wants, |
| 316 |
// or it may want a subclass of render area. Pass along buildNow |
| 317 |
// as it was passed to us. |
| 318 |
constructorCommon(inputGraph, envFile, buildNow); |
| 319 |
} |
| 320 |
|
| 321 |
//////////////////////////////////////////////////////////////////////// |
| 322 |
// |
| 323 |
// Called by the constructors |
| 324 |
// |
| 325 |
// private |
| 326 |
// |
| 327 |
void |
| 328 |
SoSceneViewer::constructorCommon( |
| 329 |
SoSelection *inputGraph, |
| 330 |
const char *envFile, |
| 331 |
SbBool buildNow) |
| 332 |
// |
| 333 |
//////////////////////////////////////////////////////////////////////// |
| 334 |
{ |
| 335 |
int i; |
| 336 |
|
| 337 |
// getting resources. |
| 338 |
XtGetSubresources( getParentWidget(), &fileData[0], "intl", "Intl", |
| 339 |
intl_file_resources, intl_num_file_resources, |
| 340 |
NULL, 0 ); |
| 341 |
XtGetSubresources( getParentWidget(), &editData[0], "intl", "Intl", |
| 342 |
intl_edit_resources, intl_num_edit_resources, |
| 343 |
NULL, 0 ); |
| 344 |
XtGetSubresources( getParentWidget(), &manipData[0], "intl", "Intl", |
| 345 |
intl_manip_resources, intl_num_manip_resources, |
| 346 |
NULL, 0 ); |
| 347 |
XtGetSubresources( getParentWidget(), &selData[0], "intl", "Intl", |
| 348 |
intl_sel_resources, intl_num_sel_resources, |
| 349 |
NULL, 0 ); |
| 350 |
XtGetSubresources( getParentWidget(), &viewData[0], "intl", "Intl", |
| 351 |
intl_view_resources, intl_num_view_resources, |
| 352 |
NULL, 0 ); |
| 353 |
XtGetSubresources( getParentWidget(), &editorData[0], "intl", "Intl", |
| 354 |
intl_editor_resources, intl_num_editor_resources, |
| 355 |
NULL, 0 ); |
| 356 |
XtGetSubresources( getParentWidget(), &lightData[0], "intl", "Intl", |
| 357 |
intl_light_resources, intl_num_light_resources, |
| 358 |
NULL, 0 ); |
| 359 |
XtGetSubresources( getParentWidget(), &Light, "intl", "Intl", |
| 360 |
intl_lightType_resources, intl_num_lightType_resources, |
| 361 |
NULL, 0 ); |
| 362 |
XtGetSubresources( getParentWidget(), &pulldownData[0], "intl", "Intl", |
| 363 |
intl_pulldown_resources, intl_num_pulldown_resources, |
| 364 |
NULL, 0 ); |
| 365 |
|
| 366 |
setClassName("SoSceneViewer"); |
| 367 |
setSize( SbVec2s(520, 510) ); |
| 368 |
|
| 369 |
// selection is the users scene graph. |
| 370 |
selection = inputGraph; |
| 371 |
currentViewer = NULL; |
| 372 |
createLightsCameraEnvironment(); |
| 373 |
|
| 374 |
// the scene viewer supplies its own camera and lights. |
| 375 |
// in fact, we remove any cameras that might be in the users graph. |
| 376 |
// NOTE: since the camera may be switched by the viewer (ortho/perspective toggle) |
| 377 |
// make sure to get the camera from the viewer (and not cache the camera). |
| 378 |
sceneGraph = new SoSeparator(); |
| 379 |
sceneGraph->ref(); // must ref it |
| 380 |
sceneGraph->addChild(lightsCameraEnvironment); |
| 381 |
sceneGraph->addChild(selection); |
| 382 |
|
| 383 |
// Create the dictionary that keeps track of original camera |
| 384 |
// settings in scenekits |
| 385 |
sceneKitCamNumDict = new SbDict(5);; |
| 386 |
#ifndef EXPLORER |
| 387 |
SoCamera *camFromScene = getLastSceneKitCamera(selection); |
| 388 |
switchOffSceneKitCameras(selection); |
| 389 |
removeCameras(selection); |
| 390 |
#endif |
| 391 |
|
| 392 |
// |
| 393 |
// Widget and menu variables |
| 394 |
// |
| 395 |
mgrWidget = NULL; |
| 396 |
showMenuFlag = TRUE; |
| 397 |
menuWidget = NULL; |
| 398 |
menuItems = new SoSceneViewerData[SV_MENU_NUM]; |
| 399 |
for (i=0; i<SV_MENU_NUM; i++) { |
| 400 |
menuItems[i].id = i; |
| 401 |
menuItems[i].classPt = this; |
| 402 |
menuItems[i].widget = NULL; |
| 403 |
} |
| 404 |
|
| 405 |
// |
| 406 |
// File |
| 407 |
// |
| 408 |
fileName = NULL; |
| 409 |
fileDialog = NULL; |
| 410 |
printDialog = NULL; |
| 411 |
|
| 412 |
// |
| 413 |
// Viewing |
| 414 |
// |
| 415 |
// Allocate only one viewer at a time. The other viewers will |
| 416 |
// be allocated as needed to increase speed and save memory. |
| 417 |
// |
| 418 |
for (i=0; i<4; i++) |
| 419 |
viewerList[i] = NULL; |
| 420 |
|
| 421 |
|
| 422 |
// fog |
| 423 |
fogFlag = FALSE; |
| 424 |
environment->fogType.setValue( SoEnvironment::NONE ); |
| 425 |
|
| 426 |
antialiasingFlag = FALSE; |
| 427 |
backgroundColorEditor = NULL; |
| 428 |
|
| 429 |
// |
| 430 |
// Selection |
| 431 |
// These callbacks are used to update the SceneViewer state after |
| 432 |
// the current selection changes (e.g. attach/detach editors and manips). |
| 433 |
// |
| 434 |
selection->addSelectionCallback(SoSceneViewer::selectionCallback, this); |
| 435 |
selection->addDeselectionCallback(SoSceneViewer::deselectionCallback, this); |
| 436 |
selection->setPickFilterCallback(SoSceneViewer::pickFilterCB, this); |
| 437 |
|
| 438 |
highlightRA = new SoBoxHighlightRenderAction; |
| 439 |
|
| 440 |
// |
| 441 |
// Editors |
| 442 |
// |
| 443 |
ignoreCallback = FALSE; |
| 444 |
materialEditor = NULL; |
| 445 |
colorEditor = NULL; |
| 446 |
transformSliderSet = NULL; |
| 447 |
|
| 448 |
// |
| 449 |
// Manips |
| 450 |
// |
| 451 |
curManip = SV_NONE; |
| 452 |
highlightRA->setVisible(TRUE); // highlight visible when no manip |
| 453 |
curManipReplaces = TRUE; |
| 454 |
maniplist = new SvManipList; |
| 455 |
|
| 456 |
#ifdef EXPLORER |
| 457 |
// |
| 458 |
// User callback |
| 459 |
// |
| 460 |
userModeCB = NULL; |
| 461 |
userModedata = NULL; |
| 462 |
userModeFlag = FALSE; |
| 463 |
#endif /* EXPLORER */ |
| 464 |
|
| 465 |
// |
| 466 |
// Lights |
| 467 |
// |
| 468 |
ambientColorEditor = NULL; |
| 469 |
headlightData = new SvLightData; |
| 470 |
headlightData->classPt = this; |
| 471 |
headlightData->name = Light.headlight; |
| 472 |
headlightData->type = SoDirectionalLight::getClassTypeId(); |
| 473 |
headlightData->colorEditor = NULL; |
| 474 |
headlightData->shouldBeManip = FALSE; |
| 475 |
headlightEditor = NULL; |
| 476 |
calculatedLightManipSize = FALSE; |
| 477 |
|
| 478 |
// Build the widget tree, and let SoXtComponent know about our base widget. |
| 479 |
if (buildNow) { |
| 480 |
Widget w = buildWidget(getParentWidget()); |
| 481 |
setBaseWidget(w); |
| 482 |
} |
| 483 |
|
| 484 |
// do this after everything else has been set up (viewer needs to exists |
| 485 |
// because the camera is gotten from the viewer (not cached here)) |
| 486 |
if (envFile != NULL) |
| 487 |
readEnvFile(envFile); |
| 488 |
|
| 489 |
// If scene had sceneKit with a camera, copy its values into our camera. |
| 490 |
if (camFromScene) |
| 491 |
setCameraFields( camFromScene ); |
| 492 |
} |
| 493 |
|
| 494 |
//////////////////////////////////////////////////////////////////////// |
| 495 |
// |
| 496 |
// Description: |
| 497 |
// Destructor. |
| 498 |
// |
| 499 |
// Use: public |
| 500 |
|
| 501 |
SoSceneViewer::~SoSceneViewer() |
| 502 |
// |
| 503 |
//////////////////////////////////////////////////////////////////////// |
| 504 |
{ |
| 505 |
// Delete the dictionary that keeps track of original camera |
| 506 |
// settings in scenekits |
| 507 |
delete sceneKitCamNumDict; |
| 508 |
|
| 509 |
// detach and delete the manips |
| 510 |
detachManipFromAll(); |
| 511 |
delete maniplist; |
| 512 |
|
| 513 |
// detach and delete the viewers |
| 514 |
currentViewer->setSceneGraph(NULL); |
| 515 |
delete (SoXtExaminerViewer *) viewerList[SV_VWR_EXAMINER]; |
| 516 |
delete (SoXtFlyViewer *) viewerList[SV_VWR_FLY]; |
| 517 |
delete (SoXtWalkViewer *) viewerList[SV_VWR_WALK]; |
| 518 |
delete (SoXtPlaneViewer *) viewerList[SV_VWR_PLANE]; |
| 519 |
|
| 520 |
// delete menu items data |
| 521 |
delete [ /*SV_MENU_NUM*/ ] menuItems; |
| 522 |
delete headlightData; |
| 523 |
delete headlightEditor; |
| 524 |
|
| 525 |
delete printDialog; |
| 526 |
|
| 527 |
// Editor components |
| 528 |
delete materialEditor; |
| 529 |
delete colorEditor; |
| 530 |
delete transformSliderSet; |
| 531 |
delete ambientColorEditor; |
| 532 |
delete backgroundColorEditor; |
| 533 |
|
| 534 |
sceneGraph->unref(); |
| 535 |
} |
| 536 |
|
| 537 |
//////////////////////////////////////////////////////////////////////// |
| 538 |
// |
| 539 |
// Description: |
| 540 |
// New data is going to be coming into the viewer. Time to disconnect all |
| 541 |
// manipulators and picking, and wait for new information. Might as well go |
| 542 |
// into a viewing mode as well, this gets rid of the manipulators, and puts |
| 543 |
// the user in control of viewing when new data shows up. |
| 544 |
// |
| 545 |
// Use: public |
| 546 |
void |
| 547 |
SoSceneViewer::newData() |
| 548 |
// |
| 549 |
//////////////////////////////////////////////////////////////////////// |
| 550 |
{ |
| 551 |
selection->deselectAll(); |
| 552 |
} |
| 553 |
|
| 554 |
#ifdef EXPLORER |
| 555 |
//////////////////////////////////////////////////////////////////////// |
| 556 |
// |
| 557 |
// Description: |
| 558 |
// This sets the user mode callack routine |
| 559 |
// |
| 560 |
// Use: public |
| 561 |
void |
| 562 |
SoSceneViewer::setUserModeEventCallback(SoXtRenderAreaEventCB *fcn) |
| 563 |
// |
| 564 |
//////////////////////////////////////////////////////////////////////// |
| 565 |
{ |
| 566 |
userModeCB = fcn; |
| 567 |
userModedata = currentViewer->getSceneGraph(); |
| 568 |
if (userModeFlag) |
| 569 |
currentViewer->setEventCallback(userModeCB, userModedata); |
| 570 |
} |
| 571 |
#endif /* EXPLORER */ |
| 572 |
|
| 573 |
//////////////////////////////////////////////////////////////////////// |
| 574 |
// |
| 575 |
// Description: |
| 576 |
// switches from the current viewer to the given viewer. The new |
| 577 |
// viewer will automatically be allocated if needed, and set to have |
| 578 |
// the same settings the current viewer has (drawing style, buffer |
| 579 |
// type, etc..). |
| 580 |
// |
| 581 |
// Use: private |
| 582 |
void |
| 583 |
SoSceneViewer::switchToViewer(SvEViewer newViewer) |
| 584 |
// |
| 585 |
//////////////////////////////////////////////////////////////////////// |
| 586 |
{ |
| 587 |
if (whichViewer == newViewer) |
| 588 |
return; |
| 589 |
|
| 590 |
// remove the sensor + scene graph from the old viewer (to prevent |
| 591 |
// an unecessary redraw of the old viewer) |
| 592 |
currentViewer->setAutoRedraw(FALSE); |
| 593 |
currentViewer->setSceneGraph(NULL); |
| 594 |
|
| 595 |
// allocate the viewer if needed and set the window title. |
| 596 |
// all viewers share the same highlight render action. |
| 597 |
switch (newViewer) { |
| 598 |
case SV_VWR_EXAMINER: |
| 599 |
// examiner vwr is already created in build() |
| 600 |
setTitle("SceneViewer (Examiner)"); |
| 601 |
break; |
| 602 |
case SV_VWR_FLY: |
| 603 |
if ( viewerList[newViewer] == NULL ) { |
| 604 |
viewerList[newViewer] = new SoXtFlyViewer(mgrWidget); |
| 605 |
viewerList[newViewer]->setGLRenderAction(highlightRA); |
| 606 |
viewerList[newViewer]->redrawOnSelectionChange(selection); |
| 607 |
} |
| 608 |
setTitle("SceneViewer (Fly)"); |
| 609 |
break; |
| 610 |
case SV_VWR_WALK: |
| 611 |
if ( viewerList[newViewer] == NULL ) { |
| 612 |
viewerList[newViewer] = new SoXtWalkViewer(mgrWidget); |
| 613 |
viewerList[newViewer]->setGLRenderAction(highlightRA); |
| 614 |
viewerList[newViewer]->redrawOnSelectionChange(selection); |
| 615 |
} |
| 616 |
setTitle("SceneViewer (Walk)"); |
| 617 |
break; |
| 618 |
case SV_VWR_PLANE: |
| 619 |
if ( viewerList[newViewer] == NULL ) { |
| 620 |
viewerList[newViewer] = new SoXtPlaneViewer(mgrWidget); |
| 621 |
viewerList[newViewer]->setGLRenderAction(highlightRA); |
| 622 |
viewerList[newViewer]->redrawOnSelectionChange(selection); |
| 623 |
} |
| 624 |
setTitle("SceneViewer (Plane)"); |
| 625 |
break; |
| 626 |
} |
| 627 |
SoXtFullViewer *newVwr = viewerList[newViewer]; |
| 628 |
|
| 629 |
// re-init the render action (since it is shared between viewers) now that |
| 630 |
// we are changing windows + set the new scene graph |
| 631 |
newVwr->setAutoRedraw(TRUE); |
| 632 |
newVwr->setSceneGraph(sceneGraph); |
| 633 |
newVwr->getGLRenderAction()->invalidateState(); |
| 634 |
|
| 635 |
// |
| 636 |
// make sure the new viewer has all the same settings as |
| 637 |
// the current viewer. |
| 638 |
// |
| 639 |
|
| 640 |
// XtRenderArea methods |
| 641 |
//???can't each viewer have it's own background color? especially |
| 642 |
//???if we nuke the background color editor. The user might set the |
| 643 |
//???colors to be different in the app-defaults file. |
| 644 |
//???newVwr->setBackgroundColor( currentViewer->getBackgroundColor() ); |
| 645 |
|
| 646 |
environment->fogColor.setValue( newVwr->getBackgroundColor() ); |
| 647 |
|
| 648 |
newVwr->setClearBeforeRender( currentViewer->isClearBeforeRender() ); |
| 649 |
// XtViewer methods |
| 650 |
newVwr->setHeadlight( currentViewer->isHeadlight() ); |
| 651 |
newVwr->setDrawStyle( |
| 652 |
SoXtViewer::STILL, |
| 653 |
currentViewer->getDrawStyle(SoXtViewer::STILL) ); |
| 654 |
newVwr->setDrawStyle( |
| 655 |
SoXtViewer::INTERACTIVE, |
| 656 |
currentViewer->getDrawStyle(SoXtViewer::INTERACTIVE) ); |
| 657 |
newVwr->setBufferingType( currentViewer->getBufferingType() ); |
| 658 |
newVwr->setViewing( currentViewer->isViewing() ); |
| 659 |
newVwr->setAutoClipping( currentViewer->isAutoClipping() ); |
| 660 |
newVwr->setSeekTime( currentViewer->getSeekTime() ); |
| 661 |
// XtFullViewer methods |
| 662 |
newVwr->setDecoration( currentViewer->isDecoration() ); |
| 663 |
|
| 664 |
// The tabBoxManip adds a finish callback to the viewer. |
| 665 |
// We need to remove from the old and add to the new. |
| 666 |
for (int m = 0; m < maniplist->getLength(); m++ ) { |
| 667 |
SoTransformManip *manip = maniplist->getManip(m); |
| 668 |
if ( manip->isOfType( SoTabBoxManip::getClassTypeId() ) ) { |
| 669 |
|
| 670 |
currentViewer->removeFinishCallback( |
| 671 |
&SoSceneViewer::adjustScaleTabSizeCB, manip->getDragger() ); |
| 672 |
newVwr->addFinishCallback( |
| 673 |
&SoSceneViewer::adjustScaleTabSizeCB, manip->getDragger() ); |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
#ifdef EXPLORER |
| 678 |
if (userModeFlag) |
| 679 |
newVwr->setEventCallback(userModeCB, userModedata); |
| 680 |
else |
| 681 |
newVwr->setEventCallback(NULL, NULL); |
| 682 |
#endif |
| 683 |
|
| 684 |
// build and layout the new viewer |
| 685 |
buildAndLayoutViewer(newVwr); |
| 686 |
|
| 687 |
// finally switch to the new viewer by showing the new viewer, |
| 688 |
// and hidding the old viewer (hide is done last to reduce flicker). |
| 689 |
newVwr->show(); |
| 690 |
currentViewer->hide(); |
| 691 |
whichViewer = newViewer; |
| 692 |
currentViewer = newVwr; |
| 693 |
setOverlayLogo(currentViewer); |
| 694 |
} |
| 695 |
|
| 696 |
//////////////////////////////////////////////////////////////////////// |
| 697 |
// |
| 698 |
// Description: |
| 699 |
// Move up the picked path to the parent group. |
| 700 |
// |
| 701 |
// Use: public |
| 702 |
|
| 703 |
void |
| 704 |
SoSceneViewer::pickParent() |
| 705 |
// |
| 706 |
//////////////////////////////////////////////////////////////////////// |
| 707 |
{ |
| 708 |
SoFullPath *pickPath; |
| 709 |
int parentIndex; |
| 710 |
|
| 711 |
// We'll pick the parent of the last selection in the list... |
| 712 |
pickPath = (SoFullPath *) (*selection)[selection->getNumSelected() - 1]; |
| 713 |
if(pickPath == NULL || pickPath->getLength() < 2) |
| 714 |
return; |
| 715 |
|
| 716 |
// Get actual node that is the current selection: |
| 717 |
SoNode *tail = pickPath->getTail(); |
| 718 |
SoNode *kitTail = ((SoNodeKitPath *)pickPath)->getTail(); |
| 719 |
SoType nkt = SoBaseKit::getClassTypeId(); |
| 720 |
if ( kitTail->isOfType( nkt ) ) |
| 721 |
tail = kitTail; |
| 722 |
else |
| 723 |
kitTail = NULL; |
| 724 |
|
| 725 |
// If kitTail is at top of path, we've already gone as high as we can go. |
| 726 |
if ( kitTail == pickPath->getHead() ) |
| 727 |
return; |
| 728 |
|
| 729 |
// Get index of parent of selection. |
| 730 |
if ( kitTail != NULL ) { |
| 731 |
// Look for first kit above tail. If none, use direct parent of kitTail. |
| 732 |
SoNode *aboveTail = ((SoNodeKitPath *)pickPath)->getNodeFromTail( 1 ); |
| 733 |
SbBool aboveIsKit = aboveTail->isOfType( nkt ); |
| 734 |
for (int i = pickPath->getLength() - 1; i >= 0; i-- ) { |
| 735 |
if ( aboveIsKit ) { |
| 736 |
if (pickPath->getNode(i) == aboveTail ) { |
| 737 |
parentIndex = i; |
| 738 |
break; |
| 739 |
} |
| 740 |
} |
| 741 |
else if ( pickPath->getNode(i) == kitTail ) { |
| 742 |
parentIndex = i - 1; |
| 743 |
break; |
| 744 |
} |
| 745 |
} |
| 746 |
} |
| 747 |
else { |
| 748 |
// If tail is not a nodkeit, parentIndex is just parent of tail... |
| 749 |
parentIndex = pickPath->getLength() - 2; |
| 750 |
} |
| 751 |
|
| 752 |
// cannot select the selection node (make sure we're not) |
| 753 |
if (pickPath->getNode(parentIndex) == selection) { |
| 754 |
fprintf(stderr, "No more parents to pick (cannot pick above the selection node)\n"); |
| 755 |
return; |
| 756 |
} |
| 757 |
|
| 758 |
pickPath->ref(); // need to ref it, because |
| 759 |
// selection->clear unref's it |
| 760 |
selection->deselectAll(); |
| 761 |
pickPath->truncate(parentIndex + 1); // Make path end at parentIndex |
| 762 |
selection->select(pickPath); // add path back in |
| 763 |
pickPath->unref(); // now we can unref it, again |
| 764 |
} |
| 765 |
|
| 766 |
//////////////////////////////////////////////////////////////////////// |
| 767 |
// |
| 768 |
// Description: |
| 769 |
// Pick all group nodes and shapes under selection. |
| 770 |
// |
| 771 |
// Use: private |
| 772 |
void |
| 773 |
SoSceneViewer::pickAll() |
| 774 |
// |
| 775 |
//////////////////////////////////////////////////////////////////////// |
| 776 |
{ |
| 777 |
selection->deselectAll(); |
| 778 |
|
| 779 |
#ifdef DEBUG |
| 780 |
assert(selection != NULL); |
| 781 |
#endif |
| 782 |
|
| 783 |
SoPathList myPaths; |
| 784 |
|
| 785 |
// Our callbacks on the selection's 'select' method may add |
| 786 |
// more children to the selection node (by making a trackball or handlebox) |
| 787 |
// Therefore, we must first determine the selections by storing |
| 788 |
// paths to them. |
| 789 |
// Following this, we call 'select' on each path, in turn. |
| 790 |
|
| 791 |
// |
| 792 |
// Create paths from the selection node to all of it's children |
| 793 |
// that are groups or shapes. |
| 794 |
// |
| 795 |
for (int i = 0; i < selection->getNumChildren(); i++) { |
| 796 |
SoNode *node = selection->getChild(i); |
| 797 |
if ((node->isOfType(SoGroup::getClassTypeId()) || |
| 798 |
node->isOfType(SoShape::getClassTypeId())) ) |
| 799 |
{ |
| 800 |
SoPath *thisPath = new SoPath(selection); |
| 801 |
thisPath->append(i); |
| 802 |
|
| 803 |
myPaths.append( thisPath ); |
| 804 |
} |
| 805 |
} |
| 806 |
|
| 807 |
// |
| 808 |
// Select each path in 'myPaths' |
| 809 |
// |
| 810 |
for (int j = 0; j < myPaths.getLength(); j++) |
| 811 |
selection->select(myPaths[j]); |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
//////////////////////////////////////////////////////////////////////// |
| 816 |
// |
| 817 |
// Description: |
| 818 |
// This routine first detaches manipulators from all selected objects, |
| 819 |
// then attaches a manipulator to all selected objects. |
| 820 |
// |
| 821 |
// Use: private |
| 822 |
|
| 823 |
void |
| 824 |
SoSceneViewer::replaceAllManips( |
| 825 |
SvEManipMode manipMode ) // Current manipulator |
| 826 |
// |
| 827 |
//////////////////////////////////////////////////////////////////////// |
| 828 |
{ |
| 829 |
detachManipFromAll(); |
| 830 |
attachManipToAll( manipMode ); |
| 831 |
} |
| 832 |
|
| 833 |
//////////////////////////////////////////////////////////////////////// |
| 834 |
// |
| 835 |
// Description: |
| 836 |
// This routine attaches a manipulator to all selected objects. |
| 837 |
// |
| 838 |
// Use: private |
| 839 |
|
| 840 |
void |
| 841 |
SoSceneViewer::attachManipToAll( |
| 842 |
SvEManipMode manipMode ) // Current manipulator |
| 843 |
// |
| 844 |
//////////////////////////////////////////////////////////////////////// |
| 845 |
{ |
| 846 |
int i; |
| 847 |
|
| 848 |
for ( i = 0; i < selection->getNumSelected(); i++ ) { |
| 849 |
SoPath *p = (*selection)[i]; |
| 850 |
attachManip( manipMode, p ); |
| 851 |
} |
| 852 |
} |
| 853 |
|
| 854 |
//////////////////////////////////////////////////////////////////////// |
| 855 |
// |
| 856 |
// Description: |
| 857 |
// This routine attaches and activates a manipulator. |
| 858 |
// |
| 859 |
// Use: private |
| 860 |
|
| 861 |
void |
| 862 |
SoSceneViewer::attachManip( |
| 863 |
SvEManipMode manipMode, // Current manipulator |
| 864 |
SoPath *selectedPath ) // Which selection to attach to |
| 865 |
// |
| 866 |
//////////////////////////////////////////////////////////////////////// |
| 867 |
{ |
| 868 |
SoTransformManip *theXfManip; |
| 869 |
SoPath *xfPath; |
| 870 |
|
| 871 |
// |
| 872 |
// Attach to a manipulator. |
| 873 |
// |
| 874 |
|
| 875 |
if ( manipMode == SV_NONE ) |
| 876 |
return; |
| 877 |
|
| 878 |
xfPath = findTransformForAttach( selectedPath ); |
| 879 |
xfPath->ref(); |
| 880 |
theXfManip = NULL; |
| 881 |
|
| 882 |
switch( manipMode ) { |
| 883 |
case SV_TRANSFORMER: |
| 884 |
theXfManip = new SoTransformerManip; |
| 885 |
break; |
| 886 |
|
| 887 |
case SV_TRACKBALL: |
| 888 |
theXfManip = new SoTrackballManip; |
| 889 |
break; |
| 890 |
|
| 891 |
case SV_HANDLEBOX: |
| 892 |
theXfManip = new SoHandleBoxManip; |
| 893 |
|
| 894 |
break; |
| 895 |
|
| 896 |
case SV_JACK: |
| 897 |
theXfManip = new SoJackManip; |
| 898 |
break; |
| 899 |
|
| 900 |
case SV_CENTERBALL: |
| 901 |
theXfManip = new SoCenterballManip; |
| 902 |
break; |
| 903 |
|
| 904 |
case SV_XFBOX: |
| 905 |
theXfManip = new SoTransformBoxManip; |
| 906 |
break; |
| 907 |
|
| 908 |
case SV_TABBOX: |
| 909 |
theXfManip = new SoTabBoxManip; |
| 910 |
break; |
| 911 |
|
| 912 |
case SV_NONE: |
| 913 |
return; |
| 914 |
} |
| 915 |
|
| 916 |
if ( theXfManip ) { |
| 917 |
|
| 918 |
SoFullPath *fp = (SoFullPath *) xfPath; |
| 919 |
|
| 920 |
#ifdef DEBUG |
| 921 |
if ( !fp->getTail()->isOfType( SoTransform::getClassTypeId() ) ) { |
| 922 |
fprintf(stderr,"DBG> Fatal Error: in SoSceneViewer::attachManip\n"); |
| 923 |
fprintf(stderr," > end of path is not a transform\n"); |
| 924 |
} |
| 925 |
#endif |
| 926 |
SoTransform *oldXf = (SoTransform *)fp->getTail(); |
| 927 |
oldXf->ref(); |
| 928 |
theXfManip->ref(); |
| 929 |
|
| 930 |
if ( !theXfManip->replaceNode( xfPath ) ) { |
| 931 |
theXfManip->unref(); |
| 932 |
#ifdef DEBUG |
| 933 |
fprintf(stderr,"DBG> Fatal Error: in SoSceneViewer::attachManip\n"); |
| 934 |
fprintf(stderr," > manip->replaceNode() failed!\n" ); |
| 935 |
#endif |
| 936 |
} |
| 937 |
|
| 938 |
// If the transformSliderSet is attached to the oldXf, then attach |
| 939 |
// it to the new manip instead. |
| 940 |
if ( transformSliderSet && transformSliderSet->isVisible() |
| 941 |
&& transformSliderSet->getNode() == oldXf) |
| 942 |
transformSliderSet->setNode(theXfManip); |
| 943 |
|
| 944 |
// Add manip and paths to the maniplist (maniplist will ref/unref) |
| 945 |
maniplist->append(selectedPath, theXfManip, xfPath ); |
| 946 |
|
| 947 |
theXfManip->unref(); |
| 948 |
oldXf->unref(); |
| 949 |
|
| 950 |
if ( manipMode == SV_TABBOX ) { |
| 951 |
// Special case! When using a tab box, we want to adjust the |
| 952 |
// scale tabs upon viewer finish. |
| 953 |
currentViewer->addFinishCallback( |
| 954 |
&SoSceneViewer::adjustScaleTabSizeCB,theXfManip->getDragger()); |
| 955 |
} |
| 956 |
if ( manipMode == SV_JACK ) { |
| 957 |
// Special case! For jack manip, we want it so that clicking on the |
| 958 |
// selected object initiates 2-dimensional translation. Other |
| 959 |
// parts of the jack manip should use the default resource geometry. |
| 960 |
// So, we replace the parts that do planar motion. |
| 961 |
// We need to replace a total of six parts: |
| 962 |
// 'translator.yzTranslator.translator': |
| 963 |
// 'translator.xzTranslator.translator': |
| 964 |
// 'translator.xyTranslator.translator': |
| 965 |
// 'translator.yzTranslator.translatorActive': |
| 966 |
// 'translator.xzTranslator.translatorActive': |
| 967 |
// 'translator.xyTranslator.translatorActive': |
| 968 |
// In the SoJackDragger, 'translator' is an SoDragPointDragger, |
| 969 |
// which takes care of all translations in 3 dimensions for jack. |
| 970 |
// In the SoDragPointDragger there are 3 planar translation parts |
| 971 |
// (each is an SoTranslate2Dragger) and 3 linear translation parts |
| 972 |
// (each is an SoTranslate1Dragger). At any given time, dragPoint |
| 973 |
// displays one of each kind of dragger. We leave the linear |
| 974 |
// translators as the default geometry (a cylinder along the axis |
| 975 |
// of motion), but replace the geometry in the planar translators. |
| 976 |
// Within the SoDragPointDragger, the planar translators are named |
| 977 |
// 'yzTranslator', 'xzTranslator', and 'xyTranslator'. |
| 978 |
// Each of these is an SoTranslate2Dragger, which has two parts |
| 979 |
// for its geometry, 'translator' and 'translatorActive.' Clicking |
| 980 |
// on the 'translator' is what initiates the 2D translation. |
| 981 |
// Once begun, the 'translatorActive' part is displayed. We |
| 982 |
// replace both of these parts with a path to the selected object. |
| 983 |
|
| 984 |
// When we call setPartAsPath, we need to prune the path if our |
| 985 |
// selected geometry lays inside a nodekit. |
| 986 |
// For example, let's say a dumbBellKit contains 1 bar (a cylinder) |
| 987 |
// and 2 end (spheres). Since this is the lowest-level kit |
| 988 |
// containing these 3 shapes, they are considered a single object |
| 989 |
// by the SceneViewer. |
| 990 |
// So we need to pass a path to the kit, not the individual piece |
| 991 |
// that is selected. This way, subsequent clicks on any piece of |
| 992 |
// the dumbbell will cause 2D translation. |
| 993 |
// First, is a nodekit on the path? If so, find the last one. |
| 994 |
SoFullPath *jackP = (SoFullPath *) selectedPath; |
| 995 |
SoType bkType = SoBaseKit::getClassTypeId(); |
| 996 |
int lastKitInd = -1; |
| 997 |
for (int i = jackP->getLength() - 1; i >= 0; i--) { |
| 998 |
if (jackP->getNode(i)->isOfType(bkType)) { |
| 999 |
lastKitInd = i; |
| 1000 |
break; |
| 1001 |
} |
| 1002 |
} |
| 1003 |
// If there's a lastKitInd, make jackP be a copy of |
| 1004 |
// selectedPath, but only up to lastKitInd. |
| 1005 |
if ( lastKitInd != -1) |
| 1006 |
jackP = (SoFullPath *) selectedPath->copy(0,lastKitInd + 1); |
| 1007 |
|
| 1008 |
// Get the dragger from the manip (the manip contains the dragger, |
| 1009 |
// and the dragger has the parts). |
| 1010 |
SoDragger *d = theXfManip->getDragger(); |
| 1011 |
|
| 1012 |
// Use jackP to set the translator parts, then discard (unref) it: |
| 1013 |
jackP->ref(); |
| 1014 |
d->setPartAsPath("translator.yzTranslator.translator", jackP ); |
| 1015 |
d->setPartAsPath("translator.xzTranslator.translator", jackP ); |
| 1016 |
d->setPartAsPath("translator.xyTranslator.translator", jackP ); |
| 1017 |
d->setPartAsPath( |
| 1018 |
"translator.yzTranslator.translatorActive", jackP); |
| 1019 |
d->setPartAsPath( |
| 1020 |
"translator.xzTranslator.translatorActive", jackP); |
| 1021 |
d->setPartAsPath( |
| 1022 |
"translator.xyTranslator.translatorActive", jackP); |
| 1023 |
jackP->unref(); |
| 1024 |
} |
| 1025 |
} |
| 1026 |
|
| 1027 |
xfPath->unref(); |
| 1028 |
} |
| 1029 |
|
| 1030 |
|
| 1031 |
//////////////////////////////////////////////////////////////////////// |
| 1032 |
// |
| 1033 |
// Description: |
| 1034 |
// This routine detaches the manipulators from all selected objects. |
| 1035 |
// |
| 1036 |
// Use: private |
| 1037 |
void |
| 1038 |
SoSceneViewer::detachManipFromAll() |
| 1039 |
// |
| 1040 |
//////////////////////////////////////////////////////////////////////// |
| 1041 |
{ |
| 1042 |
// |
| 1043 |
// Loop from the end of the list to the start. |
| 1044 |
// |
| 1045 |
for (int i = selection->getNumSelected() - 1; i >= 0 ; i-- ) { |
| 1046 |
SoPath *p = (SoPath *) (*selection)[i]; |
| 1047 |
detachManip( p ); |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
|
| 1052 |
//////////////////////////////////////////////////////////////////////// |
| 1053 |
// |
| 1054 |
// Description: |
| 1055 |
// This routine detaches a manipulator. |
| 1056 |
// |
| 1057 |
// Use: private |
| 1058 |
|
| 1059 |
void |
| 1060 |
SoSceneViewer::detachManip( |
| 1061 |
SoPath *p ) // Selection object that is being removed |
| 1062 |
// |
| 1063 |
//////////////////////////////////////////////////////////////////////// |
| 1064 |
{ |
| 1065 |
// |
| 1066 |
// Detach manip and remove from scene graph. |
| 1067 |
// |
| 1068 |
int which = maniplist->find(p); |
| 1069 |
// See if this path is registered in the manip list. |
| 1070 |
if (which != -1) { |
| 1071 |
// remove from scene graph |
| 1072 |
SoTransformManip *manip = maniplist->getManip(which); |
| 1073 |
|
| 1074 |
if ( manip->isOfType(SoTabBoxManip::getClassTypeId() )) { |
| 1075 |
// Special case! When using a tab box, we want to adjust the |
| 1076 |
// scale tabs upon viewer finish. |
| 1077 |
currentViewer->removeFinishCallback( |
| 1078 |
&SoSceneViewer::adjustScaleTabSizeCB, manip->getDragger() ); |
| 1079 |
} |
| 1080 |
|
| 1081 |
SoPath *xfPath = maniplist->getXfPath(which); |
| 1082 |
SoTransform *newXf = new SoTransform; |
| 1083 |
newXf->ref(); |
| 1084 |
manip->ref(); |
| 1085 |
|
| 1086 |
// replace the manip |
| 1087 |
manip->replaceManip( xfPath, newXf ); |
| 1088 |
|
| 1089 |
// If the transformSliderSet is attached to the manip, then attach |
| 1090 |
// it to the new node instead. |
| 1091 |
if ( transformSliderSet && transformSliderSet->isVisible() |
| 1092 |
&& transformSliderSet->getNode() == manip) |
| 1093 |
transformSliderSet->setNode(newXf); |
| 1094 |
|
| 1095 |
manip->unref(); |
| 1096 |
newXf->unref(); |
| 1097 |
|
| 1098 |
// remove from maniplist |
| 1099 |
maniplist->remove(which); |
| 1100 |
} |
| 1101 |
} |
| 1102 |
|
| 1103 |
//////////////////////////////////////////////////////////////////////// |
| 1104 |
// |
| 1105 |
// Description: |
| 1106 |
// Added as a finish callback to the current viewer. It makes sure |
| 1107 |
// the scale tab size gets changed when a viewer gesture is |
| 1108 |
// completed. |
| 1109 |
// |
| 1110 |
// Use: public |
| 1111 |
void |
| 1112 |
SoSceneViewer::adjustScaleTabSizeCB( void *userData, SoXtViewer *) |
| 1113 |
// |
| 1114 |
//////////////////////////////////////////////////////////////////////// |
| 1115 |
{ |
| 1116 |
SoTabBoxDragger *dragger = (SoTabBoxDragger *) userData; |
| 1117 |
dragger->adjustScaleTabSize(); |
| 1118 |
} |
| 1119 |
|
| 1120 |
//////////////////////////////////////////////////////////////////////// |
| 1121 |
// |
| 1122 |
// Description: |
| 1123 |
// See the selection from the camera |
| 1124 |
// |
| 1125 |
// Use: public |
| 1126 |
void |
| 1127 |
SoSceneViewer::viewSelection() |
| 1128 |
// |
| 1129 |
//////////////////////////////////////////////////////////////////////// |
| 1130 |
{ |
| 1131 |
if (selection->getNumSelected() == 0) { |
| 1132 |
viewAll(); |
| 1133 |
return; |
| 1134 |
} |
| 1135 |
|
| 1136 |
SoPath *path = (*selection)[0]; |
| 1137 |
if(path != NULL) { |
| 1138 |
getCamera()->viewAll(path, currentViewer->getViewportRegion()); |
| 1139 |
} |
| 1140 |
else { |
| 1141 |
viewAll(); |
| 1142 |
return; |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
|
| 1147 |
//////////////////////////////////////////////////////////////////////// |
| 1148 |
// |
| 1149 |
// Description: |
| 1150 |
// Create a color editor for the currently selected object. |
| 1151 |
// Attachment code copied from SoXformManip.c++ |
| 1152 |
// |
| 1153 |
// Use: private |
| 1154 |
void |
| 1155 |
SoSceneViewer::createColorEditor() |
| 1156 |
// |
| 1157 |
//////////////////////////////////////////////////////////////////////// |
| 1158 |
{ |
| 1159 |
if (colorEditor == NULL) { |
| 1160 |
colorEditor = new MyColorEditor; |
| 1161 |
colorEditor->setWYSIWYG(TRUE); |
| 1162 |
colorEditor->setTitle("Diffuse Color"); |
| 1163 |
} |
| 1164 |
|
| 1165 |
SoMaterial *editMaterial = findMaterialForAttach( NULL ); |
| 1166 |
|
| 1167 |
colorEditor->attach(&(editMaterial->diffuseColor), 0, editMaterial); |
| 1168 |
|
| 1169 |
colorEditor->show(); |
| 1170 |
} |
| 1171 |
|
| 1172 |
|
| 1173 |
//////////////////////////////////////////////////////////////////////// |
| 1174 |
// |
| 1175 |
// Description: |
| 1176 |
// Find the appropriate material node in the scene graph to attach a material |
| 1177 |
// editor to. |
| 1178 |
// |
| 1179 |
// Two possible cases: |
| 1180 |
// [1] The path-tail is NOT a group. We search the siblings of the path |
| 1181 |
// tail (including the tail itself) from right to left for a node |
| 1182 |
// that is affected by materials (shapes or groups). |
| 1183 |
// We stop the search if we come to a material node to the left of the |
| 1184 |
// pathTail. If we find a node that IS affected by material, we will |
| 1185 |
// insert a material node just before the path-tail. This is |
| 1186 |
// because the editor should not affect nodes that appear |
| 1187 |
// before attachPath in the scene graph. |
| 1188 |
// [2] The path-tail IS a group. We search the children from left to |
| 1189 |
// right for material nodes. |
| 1190 |
// We stop the search if we come to a material node. |
| 1191 |
// If we find a node that is affected by materials, we will insert a |
| 1192 |
// material just before this node. This is because the editor for a |
| 1193 |
// group should affect ALL nodes within that group. |
| 1194 |
// |
| 1195 |
// NOTE: For the purposes of this routine, we consider SoSwitch as different |
| 1196 |
// from other types of group. This is because we don't want to put |
| 1197 |
// the new node underneath the switch, but next to it. |
| 1198 |
// |
| 1199 |
// Use: private |
| 1200 |
// |
| 1201 |
SoMaterial * |
| 1202 |
SoSceneViewer::findMaterialForAttach( |
| 1203 |
const SoPath *target ) // path to start search from |
| 1204 |
// |
| 1205 |
//////////////////////////////////////////////////////////////////////// |
| 1206 |
{ |
| 1207 |
int pathLength; |
| 1208 |
SoPath *selectionPath; |
| 1209 |
SoMaterial *editMtl; |
| 1210 |
|
| 1211 |
SbBool madeNewMtl = FALSE; // did we create a new material |
| 1212 |
// node within this method? |
| 1213 |
|
| 1214 |
|
| 1215 |
if ( ( selectionPath = (SoPath *) target ) == NULL ) { |
| 1216 |
// |
| 1217 |
// If no selection path is specified, then use the LAST path in the |
| 1218 |
// current selection list. |
| 1219 |
// |
| 1220 |
selectionPath = (*selection)[selection->getNumSelected() - 1]; // last guy |
| 1221 |
} |
| 1222 |
pathLength = selectionPath->getLength(); |
| 1223 |
|
| 1224 |
if ( pathLength <= 0 ) { |
| 1225 |
fprintf( stderr, "No objects currently selected...\n" ); |
| 1226 |
return NULL; |
| 1227 |
} |
| 1228 |
|
| 1229 |
#ifdef DEBUG |
| 1230 |
if ( pathLength < 2 ) { |
| 1231 |
fprintf( stderr, "Picked object has no parent...\n" ); |
| 1232 |
return NULL; |
| 1233 |
} |
| 1234 |
#endif |
| 1235 |
|
| 1236 |
|
| 1237 |
// find 'group' and try to find 'editMtl' |
| 1238 |
SoGroup *group; |
| 1239 |
SoNode *node; |
| 1240 |
int index, i; |
| 1241 |
SbBool ignoreNodekit = FALSE; |
| 1242 |
|
| 1243 |
editMtl = NULL; |
| 1244 |
|
| 1245 |
if ( selectionPath->getTail()->isOfType( SoBaseKit::getClassTypeId() )) { |
| 1246 |
// Nodekits have their own built in policy for creating new material |
| 1247 |
// nodes. Allow them to contruct and return it. |
| 1248 |
// Get the last nodekit in the path: |
| 1249 |
SoBaseKit *kit = (SoBaseKit *) |
| 1250 |
((SoNodeKitPath *)selectionPath)->getTail(); |
| 1251 |
// SO_CHECK_PART returns NULL if the part doesn't exist yet... |
| 1252 |
editMtl = SO_GET_PART( kit, "material", SoMaterial ); |
| 1253 |
if ( editMtl == NULL ) { |
| 1254 |
// This nodekit does not have a material part. |
| 1255 |
// Ignore the fact that this is a nodekit. |
| 1256 |
ignoreNodekit = TRUE; |
| 1257 |
} |
| 1258 |
} |
| 1259 |
|
| 1260 |
SbBool isTailGroup = |
| 1261 |
selectionPath->getTail()->isOfType( SoGroup::getClassTypeId()) && |
| 1262 |
(!selectionPath->getTail()->isOfType( SoSwitch::getClassTypeId())); |
| 1263 |
|
| 1264 |
if ((editMtl == NULL) && ( !isTailGroup )) { |
| 1265 |
// |
| 1266 |
// CASE 1: The path-tail is not a group. |
| 1267 |
// 'group' becomes the second to last node in the path. |
| 1268 |
// We search the path tail and its siblings from right to left for a |
| 1269 |
// mtl node. |
| 1270 |
// We stop the search if we come to a shape node or a group node |
| 1271 |
// to the left of the pathTail. If we find a shape or group, we |
| 1272 |
// will insert a mtl just before the path-tail. This is |
| 1273 |
// because the manipulator should not affect objects that appear |
| 1274 |
// before selectionPath in the scene graph. |
| 1275 |
// |
| 1276 |
group = (SoGroup *) selectionPath->getNode(pathLength - 2); |
| 1277 |
index = group->findChild( selectionPath->getTail() ); |
| 1278 |
|
| 1279 |
for (i = index; (i >= 0) && (editMtl == NULL); i--){ |
| 1280 |
node = group->getChild(i); |
| 1281 |
if (node->isOfType(SoMaterial::getClassTypeId())) // found SoMaterial |
| 1282 |
editMtl = (SoMaterial *) node; |
| 1283 |
else if ( i != index ) { |
| 1284 |
if ( isAffectedByMaterial( node ) ) |
| 1285 |
break; |
| 1286 |
} |
| 1287 |
} |
| 1288 |
|
| 1289 |
if ( editMtl == NULL ) { |
| 1290 |
editMtl = new SoMaterial; |
| 1291 |
group->insertChild( editMtl, index ); |
| 1292 |
madeNewMtl = TRUE; |
| 1293 |
} |
| 1294 |
} |
| 1295 |
else if (editMtl == NULL) { |
| 1296 |
// CASE 2: The path-tail is a group. |
| 1297 |
// 'group' becomes the path tail |
| 1298 |
// We search the children from left to right for mtl nodes. |
| 1299 |
// We stop the search if we come to a shape node or a group node. |
| 1300 |
// If we find a shape or group, we will insert a mtl just |
| 1301 |
// before this shape or group. This is because the editor |
| 1302 |
// for a group should affect ALL objects within that group. |
| 1303 |
// |
| 1304 |
group = (SoGroup *) selectionPath->getTail(); |
| 1305 |
for (i = 0; (i < group->getNumChildren()) && (editMtl == NULL); i++ ) { |
| 1306 |
node = group->getChild(i); |
| 1307 |
if (node->isOfType(SoMaterial::getClassTypeId())) |
| 1308 |
editMtl = (SoMaterial *) node; |
| 1309 |
else if ( isAffectedByMaterial( node ) ) |
| 1310 |
break; |
| 1311 |
} |
| 1312 |
|
| 1313 |
if ( editMtl == NULL ) { |
| 1314 |
editMtl = new SoMaterial; |
| 1315 |
group->insertChild( editMtl, i ); |
| 1316 |
madeNewMtl = TRUE; |
| 1317 |
} |
| 1318 |
} |
| 1319 |
|
| 1320 |
// If we just created the material node here, then set the ignore |
| 1321 |
// flags for all fields in the node. This will cause the fields |
| 1322 |
// to be inherited from their ancestors. The material editor will |
| 1323 |
// undo these flags whenever it changes the value of a field |
| 1324 |
if ( madeNewMtl == TRUE ) { |
| 1325 |
editMtl->ambientColor.setIgnored( TRUE ); |
| 1326 |
editMtl->diffuseColor.setIgnored( TRUE ); |
| 1327 |
editMtl->specularColor.setIgnored( TRUE ); |
| 1328 |
editMtl->emissiveColor.setIgnored( TRUE ); |
| 1329 |
editMtl->shininess.setIgnored( TRUE ); |
| 1330 |
editMtl->transparency.setIgnored( TRUE ); |
| 1331 |
} |
| 1332 |
|
| 1333 |
// If any of the fields is ignored, then fill the value with the value |
| 1334 |
// inherited from the rest of the scene graph |
| 1335 |
if ( editMtl->ambientColor.isIgnored() |
| 1336 |
|| editMtl->diffuseColor.isIgnored() |
| 1337 |
|| editMtl->specularColor.isIgnored() |
| 1338 |
|| editMtl->emissiveColor.isIgnored() |
| 1339 |
|| editMtl->shininess.isIgnored() |
| 1340 |
|| editMtl->transparency.isIgnored() ){ |
| 1341 |
|
| 1342 |
// Create a path to the material |
| 1343 |
SoPath *mtlPath; |
| 1344 |
if ( (! ignoreNodekit) && selectionPath->getTail()->isOfType( SoBaseKit::getClassTypeId() )) { |
| 1345 |
SoBaseKit *kit = (SoBaseKit *) |
| 1346 |
((SoNodeKitPath *)selectionPath)->getTail(); |
| 1347 |
mtlPath = kit->createPathToPart( "material", TRUE, selectionPath ); |
| 1348 |
mtlPath->ref(); |
| 1349 |
} |
| 1350 |
else { |
| 1351 |
if ( !isTailGroup ) { |
| 1352 |
// CASE 1: path-tail was NOT 'group' -- copy all but last entry |
| 1353 |
mtlPath = selectionPath->copy(0, pathLength - 1); |
| 1354 |
} |
| 1355 |
else { |
| 1356 |
// CASE 2: path-tail was 'group' -- copy all of editPath |
| 1357 |
mtlPath = selectionPath->copy(0, pathLength); |
| 1358 |
} |
| 1359 |
mtlPath->ref(); |
| 1360 |
// add the material to the end of the path |
| 1361 |
int mtlIndex = group->findChild(editMtl); |
| 1362 |
mtlPath->append( mtlIndex ); |
| 1363 |
} |
| 1364 |
|
| 1365 |
// Pass the material node to an accumulate state callback |
| 1366 |
// that will load any 'ignored' values with their inherited values. |
| 1367 |
SoCallbackAction cba; |
| 1368 |
cba.addPreTailCallback( SoSceneViewer::findMtlPreTailCB, editMtl); |
| 1369 |
cba.apply( mtlPath ); |
| 1370 |
|
| 1371 |
mtlPath->unref(); |
| 1372 |
} |
| 1373 |
|
| 1374 |
|
| 1375 |
return( editMtl ); |
| 1376 |
} |
| 1377 |
|
| 1378 |
//////////////////////////////////////////////////////////////////////// |
| 1379 |
// |
| 1380 |
// Description: |
| 1381 |
// Callback used by 'findMaterialForAttach' as part of the accumulate state |
| 1382 |
// action. Returns 'PRUNE', which tells the action not to draw the |
| 1383 |
// shape as part of the accum state action. |
| 1384 |
// editor to. |
| 1385 |
// |
| 1386 |
// Use: private |
| 1387 |
// |
| 1388 |
SoCallbackAction::Response |
| 1389 |
SoSceneViewer::findMtlPreTailCB( void *data, SoCallbackAction *accum, |
| 1390 |
const SoNode * ) |
| 1391 |
// |
| 1392 |
//////////////////////////////////////////////////////////////////////// |
| 1393 |
{ |
| 1394 |
SoMaterial *mtl = (SoMaterial *) data; |
| 1395 |
|
| 1396 |
SbColor ambient, diffuse, specular, emissive; |
| 1397 |
float shininess, transparency; |
| 1398 |
|
| 1399 |
accum->getMaterial( ambient, diffuse, specular, emissive, |
| 1400 |
shininess, transparency ); |
| 1401 |
|
| 1402 |
// inherit the accumulated values only in those fields being ignored. |
| 1403 |
if ( mtl->ambientColor.isIgnored() ) |
| 1404 |
mtl->ambientColor.setValue( ambient ); |
| 1405 |
if ( mtl->diffuseColor.isIgnored() ) |
| 1406 |
mtl->diffuseColor.setValue( diffuse ); |
| 1407 |
if ( mtl->specularColor.isIgnored() ) |
| 1408 |
mtl->specularColor.setValue( specular ); |
| 1409 |
if ( mtl->emissiveColor.isIgnored() ) |
| 1410 |
mtl->emissiveColor.setValue( emissive ); |
| 1411 |
if ( mtl->shininess.isIgnored() ) |
| 1412 |
mtl->shininess.setValue( shininess ); |
| 1413 |
if ( mtl->transparency.isIgnored() ) |
| 1414 |
mtl->transparency.setValue( transparency ); |
| 1415 |
|
| 1416 |
return SoCallbackAction::ABORT; |
| 1417 |
} |
| 1418 |
|
| 1419 |
//////////////////////////////////////////////////////////////////////// |
| 1420 |
// |
| 1421 |
// Description: |
| 1422 |
// Find the appropriate transform node in the scene graph for attaching a |
| 1423 |
// transform editor or manipulator. |
| 1424 |
// |
| 1425 |
// How we treat the 'center' field of the transform node: |
| 1426 |
// If we need to create a new transform node: |
| 1427 |
// set the 'center' to be the geometric center of all objects |
| 1428 |
// affected by that transform. |
| 1429 |
// If we find a transform node that already exists: |
| 1430 |
// 'center' will not be changed. |
| 1431 |
// |
| 1432 |
// Three possible cases: |
| 1433 |
// [1] The path-tail is a node kit. Just ask the node kit for a path |
| 1434 |
// to the part called "transform" |
| 1435 |
// [2] The path-tail is NOT a group. We search the siblings of the path |
| 1436 |
// tail (including the tail itself) from right to left for a node |
| 1437 |
// that is affected by transforms (shapes, groups, lights,cameras). |
| 1438 |
// We stop the search if we come to a transform node to the left of |
| 1439 |
// the pathTail. If we find a node that IS affected by transform, |
| 1440 |
// we will insert a transform node just before the path-tail. This is |
| 1441 |
// because the editor should not affect nodes that appear |
| 1442 |
// before attachPath in the scene graph. |
| 1443 |
// [3] The path-tail IS a group. We search the children from left to |
| 1444 |
// right for transform nodes. |
| 1445 |
// We stop the search if we come to a transform node. |
| 1446 |
// If we find a node that is affected by transform, we will insert a |
| 1447 |
// transform just before this node. This is because the editor for a |
| 1448 |
// group should affect ALL nodes within that group. |
| 1449 |
// |
| 1450 |
// NOTE: For the purposes of this routine, we consider SoSwitch as different |
| 1451 |
// from other types of group. This is because we don't want to put |
| 1452 |
// the new node underneath the switch, but next to it. |
| 1453 |
// |
| 1454 |
// Use: private |
| 1455 |
// |
| 1456 |
SoPath * |
| 1457 |
SoSceneViewer::findTransformForAttach( |
| 1458 |
const SoPath *target ) // path to start search from |
| 1459 |
// |
| 1460 |
//////////////////////////////////////////////////////////////////////// |
| 1461 |
{ |
| 1462 |
int pathLength; |
| 1463 |
SoPath *selectionPath; |
| 1464 |
SoTransform *editXform; |
| 1465 |
|
| 1466 |
|
| 1467 |
if ( ( selectionPath = (SoPath *) target ) == NULL ) { |
| 1468 |
// |
| 1469 |
// If no selection path is specified, then use the LAST path in the |
| 1470 |
// current selection list. |
| 1471 |
// |
| 1472 |
selectionPath = (*selection)[selection->getNumSelected() - 1]; |
| 1473 |
} |
| 1474 |
pathLength = selectionPath->getLength(); |
| 1475 |
|
| 1476 |
if ( pathLength <= 0 ) { |
| 1477 |
fprintf( stderr, "No objects currently selected...\n" ); |
| 1478 |
return NULL; |
| 1479 |
} |
| 1480 |
|
| 1481 |
#ifdef DEBUG |
| 1482 |
if ( pathLength < 2 ) { |
| 1483 |
fprintf( stderr, "Picked object has no parent...\n" ); |
| 1484 |
return NULL; |
| 1485 |
} |
| 1486 |
#endif |
| 1487 |
|
| 1488 |
// find 'group' and try to find 'editXform' |
| 1489 |
SoGroup *group; |
| 1490 |
SoNode *node; |
| 1491 |
int index, i; |
| 1492 |
SbBool isTailGroup, isTailKit; |
| 1493 |
SbBool existedBefore = FALSE; |
| 1494 |
SoPath *pathToXform = NULL; |
| 1495 |
|
| 1496 |
editXform = NULL; |
| 1497 |
|
| 1498 |
isTailGroup = |
| 1499 |
( selectionPath->getTail()->isOfType(SoGroup::getClassTypeId() ) |
| 1500 |
&& !selectionPath->getTail()->isOfType(SoSwitch::getClassTypeId())); |
| 1501 |
|
| 1502 |
isTailKit = selectionPath->getTail()->isOfType(SoBaseKit::getClassTypeId()); |
| 1503 |
|
| 1504 |
// CASE 1: The path-tail is a node kit. |
| 1505 |
if ( isTailKit ) { |
| 1506 |
|
| 1507 |
// Nodekits have their own built in policy for creating new transform |
| 1508 |
// nodes. Allow them to contruct and return a path to it. |
| 1509 |
SoBaseKit *kit = (SoBaseKit *) |
| 1510 |
((SoNodeKitPath *)selectionPath)->getTail(); |
| 1511 |
|
| 1512 |
// Before creating path, see if the transform part exists yet: |
| 1513 |
if (SO_CHECK_PART(kit, "transform", SoTransform) != NULL) |
| 1514 |
existedBefore = TRUE; |
| 1515 |
|
| 1516 |
if ((editXform = SO_GET_PART(kit, "transform", SoTransform)) != NULL) { |
| 1517 |
pathToXform = kit->createPathToPart( "transform", TRUE, selectionPath ); |
| 1518 |
pathToXform->ref(); |
| 1519 |
} |
| 1520 |
else { |
| 1521 |
// This nodekit has no transform part. |
| 1522 |
// Treat the object as if it were not a nodekit. |
| 1523 |
isTailKit = FALSE; |
| 1524 |
} |
| 1525 |
} |
| 1526 |
|
| 1527 |
if ( !isTailGroup && !isTailKit ) { |
| 1528 |
// |
| 1529 |
// CASE 2: The path-tail is not a group. |
| 1530 |
// 'group' becomes the second to last node in the path. |
| 1531 |
// We search the path tail and its siblings from right to left for a |
| 1532 |
// transform node. |
| 1533 |
// We stop the search if we come to a 'movable' node |
| 1534 |
// to the left of the pathTail. If we find a movable node, we |
| 1535 |
// will insert a transform just before the path-tail. This is |
| 1536 |
// because the manipulator should not affect objects that appear |
| 1537 |
// before selectionPath in the scene graph. |
| 1538 |
// |
| 1539 |
group = (SoGroup *) selectionPath->getNode(pathLength - 2); |
| 1540 |
index = group->findChild( selectionPath->getTail() ); |
| 1541 |
|
| 1542 |
for (i = index; (i >= 0) && (editXform == NULL); i--){ |
| 1543 |
node = group->getChild(i); |
| 1544 |
if (node->isOfType(SoTransform::getClassTypeId())) // found an SoMaterial |
| 1545 |
editXform = (SoTransform *) node; |
| 1546 |
else if ( i != index ) { |
| 1547 |
if ( isAffectedByTransform( node ) ) |
| 1548 |
break; |
| 1549 |
} |
| 1550 |
} |
| 1551 |
|
| 1552 |
if ( editXform == NULL ) { |
| 1553 |
existedBefore = FALSE; |
| 1554 |
editXform = new SoTransform; |
| 1555 |
group->insertChild( editXform, index ); |
| 1556 |
} |
| 1557 |
else |
| 1558 |
existedBefore = TRUE; |
| 1559 |
} |
| 1560 |
else if ( !isTailKit ) { |
| 1561 |
// CASE 3: The path-tail is a group. |
| 1562 |
// 'group' becomes the path tail |
| 1563 |
// We search the children from left to right for transform nodes. |
| 1564 |
// We stop the search if we come to a movable node. |
| 1565 |
// If we find a movable node, we will insert a transform just |
| 1566 |
// before this node. This is because the editor |
| 1567 |
// for a group should affect ALL objects within that group. |
| 1568 |
// |
| 1569 |
group = (SoGroup *) selectionPath->getTail(); |
| 1570 |
for (i = 0; (i < group->getNumChildren()) && (editXform == NULL); i++ ) { |
| 1571 |
node = group->getChild(i); |
| 1572 |
if (node->isOfType(SoTransform::getClassTypeId())) |
| 1573 |
editXform = (SoTransform *) node; |
| 1574 |
else if ( isAffectedByTransform( node ) ) |
| 1575 |
break; |
| 1576 |
} |
| 1577 |
|
| 1578 |
if ( editXform == NULL ) { |
| 1579 |
existedBefore = FALSE; |
| 1580 |
editXform = new SoTransform; |
| 1581 |
group->insertChild( editXform, i ); |
| 1582 |
} |
| 1583 |
else |
| 1584 |
existedBefore = TRUE; |
| 1585 |
} |
| 1586 |
|
| 1587 |
// If we don't have a path yet (i.e., we weren't handed a nodekit path) |
| 1588 |
// create the 'pathToXform' |
| 1589 |
// by copying editPath and making the last node in the path be editXform |
| 1590 |
if ( pathToXform == NULL ) { |
| 1591 |
if ( !isTailGroup ) |
| 1592 |
// CASE 2: path-tail was NOT 'group' -- copy all but last entry |
| 1593 |
pathToXform = selectionPath->copy(0, pathLength - 1); |
| 1594 |
else |
| 1595 |
// CASE 3: path-tail was 'group' -- copy all of editPath |
| 1596 |
pathToXform = selectionPath->copy(0, pathLength); |
| 1597 |
pathToXform->ref(); |
| 1598 |
|
| 1599 |
// add the transform to the end |
| 1600 |
int xfIndex = group->findChild(editXform); |
| 1601 |
pathToXform->append( xfIndex ); |
| 1602 |
} |
| 1603 |
|
| 1604 |
|
| 1605 |
// Now. If we created the transform node right here, right now, then |
| 1606 |
// we will set the 'center' field based on the geometric center. We |
| 1607 |
// don't do this if we didn't create the transform, because "maybe it |
| 1608 |
// was that way for a reason." |
| 1609 |
if ( existedBefore == FALSE ) { |
| 1610 |
// First, find 'applyPath' by popping nodes off the path until you |
| 1611 |
// reach a separator. This path will contain all nodes affected by |
| 1612 |
// the transform at the end of 'pathToXform' |
| 1613 |
SoFullPath *applyPath = (SoFullPath *) pathToXform->copy(); |
| 1614 |
applyPath->ref(); |
| 1615 |
for (int i = (applyPath->getLength() - 1); i >0; i-- ) { |
| 1616 |
if (applyPath->getNode(i)->isOfType( SoSeparator::getClassTypeId())) |
| 1617 |
break; |
| 1618 |
applyPath->pop(); |
| 1619 |
} |
| 1620 |
|
| 1621 |
// Next, apply a bounding box action to applyPath, and reset the |
| 1622 |
// bounding box just before the tail of 'pathToXform' (which is just |
| 1623 |
// the editXform). This will assure that the only things included in |
| 1624 |
// the resulting bbox will be those affected by the editXform. |
| 1625 |
SoGetBoundingBoxAction bboxAction(currentViewer->getViewportRegion()); |
| 1626 |
bboxAction.setResetPath(pathToXform,TRUE,SoGetBoundingBoxAction::BBOX ); |
| 1627 |
bboxAction.apply(applyPath); |
| 1628 |
|
| 1629 |
applyPath->unref(); |
| 1630 |
|
| 1631 |
// Get the center of the bbox in world space... |
| 1632 |
SbVec3f worldBoxCenter = bboxAction.getBoundingBox().getCenter(); |
| 1633 |
|
| 1634 |
// Convert it into local space of the transform... |
| 1635 |
SbVec3f localBoxCenter; |
| 1636 |
SoGetMatrixAction ma(currentViewer->getViewportRegion()); |
| 1637 |
ma.apply( pathToXform ); |
| 1638 |
ma.getInverse().multVecMatrix( worldBoxCenter, localBoxCenter ); |
| 1639 |
|
| 1640 |
// Finally, set the center value... |
| 1641 |
editXform->center.setValue( localBoxCenter ); |
| 1642 |
} |
| 1643 |
|
| 1644 |
pathToXform->unrefNoDelete(); |
| 1645 |
return( pathToXform ); |
| 1646 |
} |
| 1647 |
|
| 1648 |
|
| 1649 |
//////////////////////////////////////////////////////////////////////// |
| 1650 |
// |
| 1651 |
// Description: |
| 1652 |
// Create a material editor for the currently selected object. |
| 1653 |
// |
| 1654 |
// Use: private |
| 1655 |
void |
| 1656 |
SoSceneViewer::createMaterialEditor() |
| 1657 |
// |
| 1658 |
//////////////////////////////////////////////////////////////////////// |
| 1659 |
{ |
| 1660 |
if (materialEditor == NULL) |
| 1661 |
materialEditor = new SoXtMaterialEditor; |
| 1662 |
materialEditor->show(); |
| 1663 |
|
| 1664 |
materialEditor->attach( findMaterialForAttach( NULL ) ); |
| 1665 |
} |
| 1666 |
|
| 1667 |
//////////////////////////////////////////////////////////////////////// |
| 1668 |
// |
| 1669 |
// Description: |
| 1670 |
// Create a transform editor for the currently selected object |
| 1671 |
// |
| 1672 |
// Use: private |
| 1673 |
void |
| 1674 |
SoSceneViewer::createTransformSliderSet() |
| 1675 |
// |
| 1676 |
//////////////////////////////////////////////////////////////////////// |
| 1677 |
{ |
| 1678 |
SoPath *editTransformPath; |
| 1679 |
SoTransform *editTransform; |
| 1680 |
|
| 1681 |
// get path to a transform to edit |
| 1682 |
if ( ( editTransformPath = findTransformForAttach( NULL )) == NULL ) |
| 1683 |
return; |
| 1684 |
|
| 1685 |
// the tail of the path is a transform for us! |
| 1686 |
editTransformPath->ref(); |
| 1687 |
editTransform =(SoTransform *) ((SoFullPath *)editTransformPath)->getTail(); |
| 1688 |
editTransformPath->unref(); |
| 1689 |
|
| 1690 |
// Nuke the old slider set and get a new one |
| 1691 |
if (transformSliderSet == NULL) |
| 1692 |
transformSliderSet = new SoXtTransformSliderSet(); |
| 1693 |
transformSliderSet->setNode(editTransform); |
| 1694 |
transformSliderSet->show(); |
| 1695 |
} |
| 1696 |
|
| 1697 |
//////////////////////////////////////////////////////////////////////// |
| 1698 |
// |
| 1699 |
// Description: |
| 1700 |
// Set fog on/off. Leave density alone - when default, the environment |
| 1701 |
// node will do something useful to make the fog look good. |
| 1702 |
// |
| 1703 |
// Use: private |
| 1704 |
void |
| 1705 |
SoSceneViewer::setFog(SbBool flag) |
| 1706 |
// |
| 1707 |
//////////////////////////////////////////////////////////////////////// |
| 1708 |
{ |
| 1709 |
fogFlag = flag; |
| 1710 |
|
| 1711 |
if (fogFlag) |
| 1712 |
environment->fogType.setValue( SoEnvironment::HAZE ); // purple ? |
| 1713 |
else environment->fogType.setValue( SoEnvironment::NONE ); |
| 1714 |
} |
| 1715 |
|
| 1716 |
//////////////////////////////////////////////////////////////////////// |
| 1717 |
// |
| 1718 |
// Description: |
| 1719 |
// Set AA-ing on/off. |
| 1720 |
// |
| 1721 |
// Use: private |
| 1722 |
void |
| 1723 |
SoSceneViewer::setAntialiasing(SbBool flag) |
| 1724 |
// |
| 1725 |
//////////////////////////////////////////////////////////////////////// |
| 1726 |
{ |
| 1727 |
antialiasingFlag = flag; |
| 1728 |
|
| 1729 |
if (antialiasingFlag) |
| 1730 |
currentViewer->setAntialiasing( TRUE, 3 ); |
| 1731 |
else |
| 1732 |
currentViewer->setAntialiasing( FALSE, 1 ); |
| 1733 |
} |
| 1734 |
|
| 1735 |
//////////////////////////////////////////////////////////////////////// |
| 1736 |
// |
| 1737 |
// Description: |
| 1738 |
// Invokes color editor on ambient lighting color. |
| 1739 |
void |
| 1740 |
SoSceneViewer::editAmbientColor() |
| 1741 |
// |
| 1742 |
//////////////////////////////////////////////////////////////////////// |
| 1743 |
{ |
| 1744 |
if ( ambientColorEditor == NULL ) { |
| 1745 |
ambientColorEditor = new MyColorEditor; |
| 1746 |
ambientColorEditor->setTitle( "Ambient Lighting" ); |
| 1747 |
ambientColorEditor->addColorChangedCallback( |
| 1748 |
SoSceneViewer::ambientColorCallback, this ); |
| 1749 |
} |
| 1750 |
|
| 1751 |
// Normalize ambient intensity |
| 1752 |
SbColor ambCol; |
| 1753 |
ambCol = environment->ambientColor.getValue(); |
| 1754 |
ambCol *= environment->ambientIntensity.getValue(); |
| 1755 |
environment->ambientIntensity.setValue( 1.0 ); |
| 1756 |
environment->ambientColor.setValue( ambCol ); |
| 1757 |
|
| 1758 |
ignoreCallback = TRUE; |
| 1759 |
ambientColorEditor->setColor( environment->ambientColor.getValue() ); |
| 1760 |
ignoreCallback = FALSE; |
| 1761 |
ambientColorEditor->show(); |
| 1762 |
} |
| 1763 |
|
| 1764 |
//////////////////////////////////////////////////////////////////////// |
| 1765 |
// |
| 1766 |
// Description: |
| 1767 |
// Callback proc invoked by the color editor, this changes the scene's |
| 1768 |
// ambient lighting color. |
| 1769 |
// |
| 1770 |
// Use: static, private |
| 1771 |
// |
| 1772 |
void |
| 1773 |
SoSceneViewer::ambientColorCallback(void *userData, const SbColor *color) |
| 1774 |
// |
| 1775 |
//////////////////////////////////////////////////////////////////////// |
| 1776 |
{ |
| 1777 |
SoSceneViewer *sv = (SoSceneViewer *) userData; |
| 1778 |
|
| 1779 |
if (sv->ignoreCallback) |
| 1780 |
return; |
| 1781 |
|
| 1782 |
sv->environment->ambientColor.setValue( *color ); |
| 1783 |
} |
| 1784 |
|
| 1785 |
//////////////////////////////////////////////////////////////////////// |
| 1786 |
// |
| 1787 |
// Description: |
| 1788 |
// Invokes color editor on background color. |
| 1789 |
void |
| 1790 |
SoSceneViewer::editBackgroundColor() |
| 1791 |
// |
| 1792 |
//////////////////////////////////////////////////////////////////////// |
| 1793 |
{ |
| 1794 |
if ( backgroundColorEditor == NULL ) { |
| 1795 |
backgroundColorEditor = new MyColorEditor; |
| 1796 |
backgroundColorEditor->setTitle( "Background Color" ); |
| 1797 |
backgroundColorEditor->addColorChangedCallback( |
| 1798 |
SoSceneViewer::backgroundColorCallback, this ); |
| 1799 |
} |
| 1800 |
ignoreCallback = TRUE; |
| 1801 |
backgroundColorEditor->setColor(getBackgroundColor()); |
| 1802 |
ignoreCallback = FALSE; |
| 1803 |
backgroundColorEditor->show(); |
| 1804 |
} |
| 1805 |
|
| 1806 |
//////////////////////////////////////////////////////////////////////// |
| 1807 |
// |
| 1808 |
// Description: |
| 1809 |
// Callback proc invoked by the color editor, this changes the current |
| 1810 |
// viewer's background color. |
| 1811 |
// |
| 1812 |
// Use: static, private |
| 1813 |
// |
| 1814 |
void |
| 1815 |
SoSceneViewer::backgroundColorCallback(void *userData, const SbColor *c) |
| 1816 |
// |
| 1817 |
//////////////////////////////////////////////////////////////////////// |
| 1818 |
{ |
| 1819 |
//??? should be using the Roxy color editor, not the So color editor |
| 1820 |
|
| 1821 |
SoSceneViewer *sv = (SoSceneViewer *) userData; |
| 1822 |
|
| 1823 |
if (sv->ignoreCallback) |
| 1824 |
return; |
| 1825 |
|
| 1826 |
sv->currentViewer->setBackgroundColor( *c ); |
| 1827 |
|
| 1828 |
// keep fog color up to date with bkg color |
| 1829 |
sv->environment->fogColor.setValue( *c ); |
| 1830 |
} |
| 1831 |
|
| 1832 |
//////////////////////////////////////////////////////////////////////// |
| 1833 |
// |
| 1834 |
// Description: |
| 1835 |
// This will: |
| 1836 |
// [a] find the last sceneKit camera that is being looked through |
| 1837 |
// in the scene and return a pointer to it. |
| 1838 |
// |
| 1839 |
// Use: private |
| 1840 |
SoCamera * |
| 1841 |
SoSceneViewer::getLastSceneKitCamera(SoGroup *root) |
| 1842 |
// |
| 1843 |
//////////////////////////////////////////////////////////////////////// |
| 1844 |
{ |
| 1845 |
// Find scene kits under the root node and loop backwards: |
| 1846 |
SoSearchAction sa; |
| 1847 |
sa.setType(SoSceneKit::getClassTypeId()); |
| 1848 |
sa.setInterest(SoSearchAction::ALL); |
| 1849 |
sa.apply(root); |
| 1850 |
|
| 1851 |
SoPathList paths = sa.getPaths(); |
| 1852 |
for (int i = paths.getLength() - 1; i >= 0; i--) { |
| 1853 |
SoPath *p = paths[i]; |
| 1854 |
if (p->getTail()->isOfType( SoSceneKit::getClassTypeId() ) ) { |
| 1855 |
SoSceneKit *sceneKit = (SoSceneKit *) p->getTail(); |
| 1856 |
int camNum = sceneKit->getCameraNumber(); |
| 1857 |
|
| 1858 |
SoNodeKitListPart *camList = |
| 1859 |
(SoNodeKitListPart *) sceneKit->getPart("cameraList",FALSE); |
| 1860 |
if (camList && camNum >= 0) { |
| 1861 |
SoCameraKit *camKit |
| 1862 |
= (SoCameraKit *)camList->getChild( camNum ); |
| 1863 |
if (camKit) |
| 1864 |
return( (SoCamera *) camKit->getPart( "camera", FALSE )); |
| 1865 |
} |
| 1866 |
} |
| 1867 |
} |
| 1868 |
return NULL; |
| 1869 |
} |
| 1870 |
|
| 1871 |
//////////////////////////////////////////////////////////////////////// |
| 1872 |
// |
| 1873 |
// Description: |
| 1874 |
// This will: |
| 1875 |
// [a] find the last sceneKit, its camera number, and replace the |
| 1876 |
// given camera for that node. |
| 1877 |
// |
| 1878 |
// Use: private |
| 1879 |
void |
| 1880 |
SoSceneViewer::setLastSceneKitCamera(SoGroup *root, SoCamera *theCam) |
| 1881 |
// |
| 1882 |
//////////////////////////////////////////////////////////////////////// |
| 1883 |
{ |
| 1884 |
// Find scene kits under the root node and loop backwards: |
| 1885 |
SoSearchAction sa; |
| 1886 |
sa.setType(SoSceneKit::getClassTypeId()); |
| 1887 |
sa.setInterest(SoSearchAction::ALL); |
| 1888 |
sa.apply(root); |
| 1889 |
|
| 1890 |
SoPathList paths = sa.getPaths(); |
| 1891 |
for (int i = paths.getLength() - 1; i >= 0; i--) { |
| 1892 |
SoPath *p = paths[i]; |
| 1893 |
if (p->getTail()->isOfType( SoSceneKit::getClassTypeId() ) ) { |
| 1894 |
SoSceneKit *sceneKit = (SoSceneKit *) p->getTail(); |
| 1895 |
int camNum = sceneKit->getCameraNumber(); |
| 1896 |
|
| 1897 |
SoNodeKitListPart *camList = |
| 1898 |
(SoNodeKitListPart *) sceneKit->getPart("cameraList",FALSE); |
| 1899 |
if (camList && camNum >= 0) { |
| 1900 |
SoCameraKit *camKit |
| 1901 |
= (SoCameraKit *)camList->getChild( camNum ); |
| 1902 |
if (camKit) { |
| 1903 |
camKit->setPart("camera",theCam); |
| 1904 |
return; |
| 1905 |
} |
| 1906 |
} |
| 1907 |
} |
| 1908 |
} |
| 1909 |
return; |
| 1910 |
} |
| 1911 |
|
| 1912 |
//////////////////////////////////////////////////////////////////////// |
| 1913 |
// |
| 1914 |
// Description: |
| 1915 |
// This will: |
| 1916 |
// [a] find scene kits if under the root node. |
| 1917 |
// [b] Save the camera number settings of the kits in a dictionary. |
| 1918 |
// [c] Switch off the scenekit cameras. |
| 1919 |
// |
| 1920 |
// Use: private |
| 1921 |
void |
| 1922 |
SoSceneViewer::switchOffSceneKitCameras(SoGroup *root) |
| 1923 |
// |
| 1924 |
//////////////////////////////////////////////////////////////////////// |
| 1925 |
{ |
| 1926 |
// [a] find scene kits if under the root node. |
| 1927 |
SoSearchAction sa; |
| 1928 |
sa.setType(SoSceneKit::getClassTypeId()); |
| 1929 |
sa.setInterest(SoSearchAction::ALL); |
| 1930 |
sa.apply(root); |
| 1931 |
|
| 1932 |
// Deal with each kit: |
| 1933 |
SoPathList paths = sa.getPaths(); |
| 1934 |
for (int i = paths.getLength() - 1; i >= 0; i--) { |
| 1935 |
SoPath *p = paths[i]; |
| 1936 |
if (p->getTail()->isOfType( SoSceneKit::getClassTypeId() ) ) { |
| 1937 |
SoSceneKit *sceneKit = (SoSceneKit *) p->getTail(); |
| 1938 |
int *camNumPtr = new int; |
| 1939 |
*camNumPtr = sceneKit->getCameraNumber(); |
| 1940 |
|
| 1941 |
// [b] Save the camera number settings of the kits in a dictionary. |
| 1942 |
sceneKitCamNumDict->enter((unsigned long)sceneKit, |
| 1943 |
(void *)camNumPtr); |
| 1944 |
|
| 1945 |
// [c] Switch off the scenekit cameras. |
| 1946 |
sceneKit->setCameraNumber( SO_SWITCH_NONE ); |
| 1947 |
} |
| 1948 |
} |
| 1949 |
} |
| 1950 |
|
| 1951 |
//////////////////////////////////////////////////////////////////////// |
| 1952 |
// |
| 1953 |
// Description: |
| 1954 |
// This will: |
| 1955 |
// [a] find scene kits if under the root node. |
| 1956 |
// [b] Find the camera number settings of the kits from a dictionary. |
| 1957 |
// [c] Restore the sceneKit camera numbers. |
| 1958 |
// |
| 1959 |
// Use: private |
| 1960 |
void |
| 1961 |
SoSceneViewer::restoreSceneKitCameras(SoGroup *root) |
| 1962 |
// |
| 1963 |
//////////////////////////////////////////////////////////////////////// |
| 1964 |
{ |
| 1965 |
// [a] find scene kits if under the root node. |
| 1966 |
SoSearchAction sa; |
| 1967 |
sa.setType(SoSceneKit::getClassTypeId()); |
| 1968 |
sa.setInterest(SoSearchAction::ALL); |
| 1969 |
sa.apply(root); |
| 1970 |
|
| 1971 |
// Deal with each kit: |
| 1972 |
SoPathList paths = sa.getPaths(); |
| 1973 |
for (int i = paths.getLength() - 1; i >= 0; i--) { |
| 1974 |
SoPath *p = paths[i]; |
| 1975 |
if (p->getTail()->isOfType( SoSceneKit::getClassTypeId() ) ) { |
| 1976 |
SoSceneKit *sceneKit = (SoSceneKit *) p->getTail(); |
| 1977 |
void *myPtr; |
| 1978 |
int camNum; |
| 1979 |
if (sceneKitCamNumDict->find((unsigned long)sceneKit, myPtr)) |
| 1980 |
camNum = *((int *)myPtr); |
| 1981 |
else |
| 1982 |
camNum = SO_SWITCH_NONE; |
| 1983 |
|
| 1984 |
sceneKit->setCameraNumber( camNum ); |
| 1985 |
} |
| 1986 |
} |
| 1987 |
} |
| 1988 |
|
| 1989 |
//////////////////////////////////////////////////////////////////////// |
| 1990 |
// |
| 1991 |
// Description: |
| 1992 |
// Copies from given camera into this viewer's camera, if types match. |
| 1993 |
// |
| 1994 |
// Use: private |
| 1995 |
void |
| 1996 |
SoSceneViewer::setCameraFields( SoCamera *fromCam ) |
| 1997 |
// |
| 1998 |
//////////////////////////////////////////////////////////////////////// |
| 1999 |
{ |
| 2000 |
SoCamera *myCam = getCamera(); |
| 2001 |
|
| 2002 |
if ( ! myCam || ! fromCam ) |
| 2003 |
return; |
| 2004 |
|
| 2005 |
// Types must match! |
| 2006 |
if ( myCam->getTypeId() != fromCam->getTypeId() ) |
| 2007 |
return; |
| 2008 |
|
| 2009 |
myCam->viewportMapping = fromCam->viewportMapping.getValue(); |
| 2010 |
myCam->position = fromCam->position.getValue(); |
| 2011 |
myCam->orientation = fromCam->orientation.getValue(); |
| 2012 |
myCam->aspectRatio = fromCam->aspectRatio.getValue(); |
| 2013 |
myCam->nearDistance = fromCam->nearDistance.getValue(); |
| 2014 |
myCam->farDistance = fromCam->farDistance.getValue(); |
| 2015 |
myCam->focalDistance = fromCam->focalDistance.getValue(); |
| 2016 |
|
| 2017 |
if ( myCam->isOfType( SoPerspectiveCamera::getClassTypeId() )) { |
| 2018 |
((SoPerspectiveCamera *)myCam)->heightAngle |
| 2019 |
= ((SoPerspectiveCamera *)fromCam)->heightAngle.getValue(); |
| 2020 |
} |
| 2021 |
else if ( myCam->isOfType( SoOrthographicCamera::getClassTypeId() )) { |
| 2022 |
((SoOrthographicCamera *)myCam)->height |
| 2023 |
= ((SoOrthographicCamera *)fromCam)->height.getValue(); |
| 2024 |
} |
| 2025 |
} |
| 2026 |
|
| 2027 |
//////////////////////////////////////////////////////////////////////// |
| 2028 |
// |
| 2029 |
// Description: |
| 2030 |
// This will remove any cameras under root. |
| 2031 |
// |
| 2032 |
// Use: private |
| 2033 |
void |
| 2034 |
SoSceneViewer::removeCameras(SoGroup *root) |
| 2035 |
// |
| 2036 |
//////////////////////////////////////////////////////////////////////// |
| 2037 |
{ |
| 2038 |
SoSearchAction sa; |
| 2039 |
sa.setType(SoCamera::getClassTypeId()); |
| 2040 |
sa.setInterest(SoSearchAction::ALL); |
| 2041 |
sa.apply(root); |
| 2042 |
|
| 2043 |
// remove those cameras! |
| 2044 |
SoPathList paths = sa.getPaths(); |
| 2045 |
for (int i = 0; i < paths.getLength(); i++) { |
| 2046 |
SoPath *p = paths[i]; |
| 2047 |
int cam = p->getIndexFromTail(0); |
| 2048 |
SoGroup *group = (SoGroup *) p->getNodeFromTail(1); |
| 2049 |
group->removeChild(cam); |
| 2050 |
|
| 2051 |
// See if the parent of this camera is a switch node with whichChild set |
| 2052 |
// to render the camera. With the camera gone, the switch has nothing |
| 2053 |
// to render. |
| 2054 |
if (group->isOfType(SoSwitch::getClassTypeId())) { |
| 2055 |
SoSwitch *sw = (SoSwitch *) group; |
| 2056 |
if (sw->whichChild.getValue() == cam) |
| 2057 |
sw->whichChild.setValue(SO_SWITCH_NONE); |
| 2058 |
} |
| 2059 |
} |
| 2060 |
} |
| 2061 |
|
| 2062 |
//////////////////////////////////////////////////////////////////////// |
| 2063 |
// |
| 2064 |
// Description: |
| 2065 |
// Reads the given file and insert the geometry under the selection |
| 2066 |
// node. If the node didn't have any children, the viewAll() method is |
| 2067 |
// automatically called. |
| 2068 |
// |
| 2069 |
// Use: private |
| 2070 |
SbBool |
| 2071 |
SoSceneViewer::readFile(const char *filename) |
| 2072 |
// |
| 2073 |
//////////////////////////////////////////////////////////////////////// |
| 2074 |
{ |
| 2075 |
SbBool hadNoChildren = (selection->getNumChildren() == 0); |
| 2076 |
|
| 2077 |
// Try reading the file |
| 2078 |
SbString errorMessage; |
| 2079 |
SoSeparator *sep = MyFileRead(filename, errorMessage); |
| 2080 |
|
| 2081 |
// add nodes under selection, not sceneGraph |
| 2082 |
if (sep != NULL) |
| 2083 |
selection->addChild(sep); |
| 2084 |
|
| 2085 |
// display error dialog if there were reading errors |
| 2086 |
else { |
| 2087 |
SoXt::createSimpleErrorDialog(mgrWidget, "File Error Dialog", |
| 2088 |
(char *) errorMessage.getString()); |
| 2089 |
return FALSE; |
| 2090 |
} |
| 2091 |
|
| 2092 |
// remove any cameras under selection which were just added |
| 2093 |
SoCamera *camFromScene = getLastSceneKitCamera(selection); |
| 2094 |
switchOffSceneKitCameras(selection); |
| 2095 |
removeCameras(selection); |
| 2096 |
|
| 2097 |
if (hadNoChildren) { |
| 2098 |
viewAll(); |
| 2099 |
saveHomePosition(); |
| 2100 |
} |
| 2101 |
|
| 2102 |
// If scene had sceneKit with a camera, copy its values into our camera. |
| 2103 |
if (camFromScene) |
| 2104 |
setCameraFields( camFromScene ); |
| 2105 |
|
| 2106 |
return TRUE; |
| 2107 |
} |
| 2108 |
|
| 2109 |
//////////////////////////////////////////////////////////////////////// |
| 2110 |
// |
| 2111 |
// Description: |
| 2112 |
// Read environment data. We expect the following nodes: |
| 2113 |
// |
| 2114 |
// Group { |
| 2115 |
// Label { "SoSceneViewer Environment v3.0" } |
| 2116 |
// Camera {} |
| 2117 |
// Environment {} |
| 2118 |
// LightGroup { |
| 2119 |
// Switch { DirectionalLight } # 1 |
| 2120 |
// ... |
| 2121 |
// Switch { DirectionalLight } # 6 |
| 2122 |
// } |
| 2123 |
// DirectionalLight {} # optional headlight |
| 2124 |
// } |
| 2125 |
// |
| 2126 |
// Use: private |
| 2127 |
SbBool |
| 2128 |
SoSceneViewer::readEnvFile(const char *filename) |
| 2129 |
// |
| 2130 |
//////////////////////////////////////////////////////////////////////// |
| 2131 |
{ |
| 2132 |
SoInput in; |
| 2133 |
if (! in.openFile(filename)) { |
| 2134 |
// display an error dialog |
| 2135 |
char str[100]; |
| 2136 |
strcpy(str, "Error opening file: "); |
| 2137 |
strcat(str, filename); |
| 2138 |
SoXt::createSimpleErrorDialog(mgrWidget, "File Error Dialog", str); |
| 2139 |
return FALSE; |
| 2140 |
} |
| 2141 |
|
| 2142 |
SoNode *n; |
| 2143 |
SoLabel *l = NULL; |
| 2144 |
SbBool isValid = FALSE; |
| 2145 |
SbBool ok; |
| 2146 |
|
| 2147 |
if ((ok = SoDB::read(&in, n)) && n != NULL) { |
| 2148 |
// we expect a label first |
| 2149 |
n->ref(); |
| 2150 |
if (n->isOfType(SoLabel::getClassTypeId())) { |
| 2151 |
l = (SoLabel *) n; |
| 2152 |
isValid = (strcmp(l->label.getValue().getString(), |
| 2153 |
SV_ENV_LABEL) == 0); |
| 2154 |
} |
| 2155 |
n->unref(); |
| 2156 |
} |
| 2157 |
else if (!ok) { |
| 2158 |
// display error dialog if there were reading errors |
| 2159 |
char str[100]; |
| 2160 |
strcpy(str, "Error reading file: "); |
| 2161 |
strcat(str, filename); |
| 2162 |
SoXt::createSimpleErrorDialog(mgrWidget, "File Error Dialog", str); |
| 2163 |
return FALSE; |
| 2164 |
} |
| 2165 |
|
| 2166 |
// if ok, read the rest. |
| 2167 |
if (isValid) { |
| 2168 |
// Camera |
| 2169 |
if (SoDB::read(&in, n) != FALSE && (n != NULL)) { |
| 2170 |
n->ref(); |
| 2171 |
if (n->isOfType(SoCamera::getClassTypeId())) { |
| 2172 |
// replace the old camera with the new camera and |
| 2173 |
// re-attach the viewer. |
| 2174 |
SoCamera *newCamera = (SoCamera *) n; |
| 2175 |
SoCamera *oldCamera = getCamera(); |
| 2176 |
SoSearchAction sa; |
| 2177 |
sa.setNode(oldCamera); |
| 2178 |
sa.apply(sceneGraph); |
| 2179 |
SoFullPath *fullCamPath = (SoFullPath *) sa.getPath(); |
| 2180 |
if (fullCamPath) { |
| 2181 |
SoGroup *parent = |
| 2182 |
(SoGroup *)fullCamPath->getNode(fullCamPath->getLength() - 2); |
| 2183 |
parent->insertChild(newCamera, parent->findChild(oldCamera)); |
| 2184 |
setCamera(newCamera); |
| 2185 |
if (parent->findChild(oldCamera) >= 0) |
| 2186 |
parent->removeChild(oldCamera); |
| 2187 |
} |
| 2188 |
#if DEBUG |
| 2189 |
else |
| 2190 |
SoDebugError::post("SoSceneViewer::readEnvFile", |
| 2191 |
"cannot find camera in graph"); |
| 2192 |
#endif |
| 2193 |
} |
| 2194 |
n->unref(); |
| 2195 |
} |
| 2196 |
// Environment |
| 2197 |
if (SoDB::read(&in, n) != FALSE && (n != NULL)) { |
| 2198 |
n->ref(); |
| 2199 |
if (n->isOfType(SoEnvironment::getClassTypeId())) { |
| 2200 |
lightsCameraEnvironment->replaceChild(environment, n); |
| 2201 |
environment = (SoEnvironment *) n; |
| 2202 |
} |
| 2203 |
n->unref(); |
| 2204 |
} |
| 2205 |
// Light group |
| 2206 |
if (SoDB::read(&in, n) != FALSE && (n != NULL)) { |
| 2207 |
n->ref(); |
| 2208 |
if (n->isOfType(SoGroup::getClassTypeId())) { |
| 2209 |
|
| 2210 |
// remove all of the existing lights |
| 2211 |
int i; |
| 2212 |
for (i = lightDataList.getLength(); i > 0; i--) |
| 2213 |
removeLight( (SvLightData *) lightDataList[i-1] ); |
| 2214 |
|
| 2215 |
lightsCameraEnvironment->replaceChild(lightGroup, n); |
| 2216 |
lightGroup = (SoGroup *) n; |
| 2217 |
|
| 2218 |
// This was busted. It was looking for a light as child 0, |
| 2219 |
// but the scale and scaleInverse made it think no light was |
| 2220 |
// there. So now, we do this right... |
| 2221 |
// We'll just check for the light as any old child. |
| 2222 |
// This way it's okay to add a translation node under that |
| 2223 |
// switch too, so we can translate the manips as well. |
| 2224 |
// This allows as to place the directional light manips. |
| 2225 |
for (i=0; i < lightGroup->getNumChildren(); i++) { |
| 2226 |
SoNode *node = lightGroup->getChild(i); |
| 2227 |
if (node->isOfType(SoSwitch::getClassTypeId())) { |
| 2228 |
SoSwitch *sw = (SoSwitch *) node; |
| 2229 |
SbBool addedIt = FALSE; |
| 2230 |
for (int j = 0; |
| 2231 |
addedIt == FALSE && j < sw->getNumChildren(); |
| 2232 |
j++ ) { |
| 2233 |
node = sw->getChild(j); |
| 2234 |
if (node->isOfType(SoLight::getClassTypeId())) { |
| 2235 |
addLightEntry((SoLight *)node, sw); |
| 2236 |
addedIt = TRUE; |
| 2237 |
} |
| 2238 |
} |
| 2239 |
} |
| 2240 |
} |
| 2241 |
} |
| 2242 |
n->unref(); |
| 2243 |
} |
| 2244 |
// Headlight (optional) - if not there, turn headlight off |
| 2245 |
if (SoDB::read(&in, n) != FALSE && (n != NULL)) { |
| 2246 |
n->ref(); |
| 2247 |
if (n->isOfType(SoDirectionalLight::getClassTypeId())) { |
| 2248 |
SoDirectionalLight *headlight = getHeadlight(); |
| 2249 |
SoDirectionalLight *newLight = (SoDirectionalLight *) n; |
| 2250 |
if (headlight != NULL) { |
| 2251 |
headlight->intensity.setValue(newLight->intensity.getValue()); |
| 2252 |
headlight->color.setValue(newLight->color.getValue()); |
| 2253 |
headlight->direction.setValue(newLight->direction.getValue()); |
| 2254 |
setHeadlight(TRUE); |
| 2255 |
} |
| 2256 |
} |
| 2257 |
n->unref(); |
| 2258 |
} |
| 2259 |
else setHeadlight(FALSE); |
| 2260 |
} |
| 2261 |
else { |
| 2262 |
fprintf(stderr, "Sorry, file is not formatted correctly\n"); |
| 2263 |
} |
| 2264 |
|
| 2265 |
return TRUE; |
| 2266 |
} |
| 2267 |
|
| 2268 |
//////////////////////////////////////////////////////////////////////// |
| 2269 |
// |
| 2270 |
// Description: |
| 2271 |
// This routine is called to get a file name using the |
| 2272 |
// standard file dialog. |
| 2273 |
// |
| 2274 |
// Use: private |
| 2275 |
void |
| 2276 |
SoSceneViewer::getFileName() |
| 2277 |
// |
| 2278 |
//////////////////////////////////////////////////////////////////////// |
| 2279 |
{ |
| 2280 |
// use a motif file selection dialog |
| 2281 |
if (fileDialog == NULL) { |
| 2282 |
Arg args[5]; |
| 2283 |
int n = 0; |
| 2284 |
|
| 2285 |
// unmanage when ok/cancel are pressed |
| 2286 |
XtSetArg(args[n], XmNautoUnmanage, TRUE); n++; |
| 2287 |
fileDialog = XmCreateFileSelectionDialog( |
| 2288 |
XtParent(mgrWidget), "File Dialog", args, n); |
| 2289 |
|
| 2290 |
XtAddCallback(fileDialog, XmNokCallback, |
| 2291 |
(XtCallbackProc)SoSceneViewer::fileDialogCB, |
| 2292 |
(XtPointer)this); |
| 2293 |
} |
| 2294 |
|
| 2295 |
// manage the dialog |
| 2296 |
XtManageChild(fileDialog); |
| 2297 |
} |
| 2298 |
|
| 2299 |
//////////////////////////////////////////////////////////////////////// |
| 2300 |
// |
| 2301 |
// Description: |
| 2302 |
// Motif file dialog callback. |
| 2303 |
// |
| 2304 |
void |
| 2305 |
SoSceneViewer::fileDialogCB(Widget, SoSceneViewer *sv, |
| 2306 |
XmFileSelectionBoxCallbackStruct *data) |
| 2307 |
// |
| 2308 |
//////////////////////////////////////////////////////////////////////// |
| 2309 |
{ |
| 2310 |
// Get the file name |
| 2311 |
char *filename; |
| 2312 |
XmStringGetLtoR(data->value, |
| 2313 |
(XmStringCharSet) XmSTRING_DEFAULT_CHARSET, &filename); |
| 2314 |
|
| 2315 |
// Use that file |
| 2316 |
sv->doFileIO(filename); |
| 2317 |
|
| 2318 |
XtFree(filename); |
| 2319 |
} |
| 2320 |
|
| 2321 |
//////////////////////////////////////////////////////////////////////// |
| 2322 |
// |
| 2323 |
// Description: |
| 2324 |
// detach everything and nuke the existing scene. |
| 2325 |
// |
| 2326 |
// Use: private |
| 2327 |
void |
| 2328 |
SoSceneViewer::deleteScene() |
| 2329 |
// |
| 2330 |
//////////////////////////////////////////////////////////////////////// |
| 2331 |
{ |
| 2332 |
// deselect everything (also detach manips) |
| 2333 |
selection->deselectAll(); |
| 2334 |
|
| 2335 |
// remove the geometry under the selection node |
| 2336 |
for (int i = selection->getNumChildren(); i>0; i--) |
| 2337 |
selection->removeChild(i-1); |
| 2338 |
} |
| 2339 |
|
| 2340 |
//////////////////////////////////////////////////////////////////////// |
| 2341 |
// |
| 2342 |
// Description: |
| 2343 |
// Read/Write to the given file name, given the current file mode. |
| 2344 |
// |
| 2345 |
// Use: private |
| 2346 |
SbBool |
| 2347 |
SoSceneViewer::doFileIO(const char *file) |
| 2348 |
// |
| 2349 |
//////////////////////////////////////////////////////////////////////// |
| 2350 |
{ |
| 2351 |
SbBool okFile = TRUE; |
| 2352 |
|
| 2353 |
switch (fileMode) { |
| 2354 |
case SV_FILE_OPEN: |
| 2355 |
deleteScene(); |
| 2356 |
okFile = readFile(file); |
| 2357 |
// If we've already made lights, re-calculate size for light |
| 2358 |
// manips based on size of new scene. |
| 2359 |
if (calculatedLightManipSize) |
| 2360 |
calculateLightManipSize(); |
| 2361 |
break; |
| 2362 |
case SV_FILE_IMPORT: |
| 2363 |
okFile = readFile(file); |
| 2364 |
// If we've already made lights, re-calculate size for light |
| 2365 |
// manips based on size of new scene. |
| 2366 |
if (calculatedLightManipSize) |
| 2367 |
calculateLightManipSize(); |
| 2368 |
break; |
| 2369 |
case SV_FILE_SAVE_AS: |
| 2370 |
okFile = writeFile(file); |
| 2371 |
break; |
| 2372 |
case SV_FILE_READ_ENV: |
| 2373 |
readEnvFile(file); |
| 2374 |
break; |
| 2375 |
case SV_FILE_SAVE_ENV: |
| 2376 |
{ |
| 2377 |
|
| 2378 |
// Run through the lights. If any light is a directionalLightManip, |
| 2379 |
// transfer its translation into the SvLightData, since that |
| 2380 |
// info will not write out. |
| 2381 |
for (int i=0; i < lightDataList.getLength(); i++) |
| 2382 |
transferDirectionalLightLocation((SvLightData *) lightDataList[i]); |
| 2383 |
|
| 2384 |
writeEnvFile(file); |
| 2385 |
} |
| 2386 |
|
| 2387 |
break; |
| 2388 |
default: |
| 2389 |
fprintf(stderr, "Wrong file mode %d passed!\n", fileMode); |
| 2390 |
return FALSE; |
| 2391 |
} |
| 2392 |
|
| 2393 |
// save the new file name so we can simply use "Save" instead of |
| 2394 |
// "Save As" next time around. |
| 2395 |
if (fileMode == SV_FILE_OPEN || fileMode == SV_FILE_SAVE_AS) { |
| 2396 |
|
| 2397 |
// save the current file name |
| 2398 |
delete fileName; |
| 2399 |
if (okFile && file != NULL) |
| 2400 |
fileName = strdup(file); |
| 2401 |
else |
| 2402 |
fileName = NULL; |
| 2403 |
} |
| 2404 |
|
| 2405 |
// enable/disable cmd key shortcuts and menu items |
| 2406 |
updateCommandAvailability(); |
| 2407 |
|
| 2408 |
return okFile; |
| 2409 |
} |
| 2410 |
|
| 2411 |
//////////////////////////////////////////////////////////////////////// |
| 2412 |
// |
| 2413 |
// Description: |
| 2414 |
// Saves the scene to the current file. |
| 2415 |
// |
| 2416 |
// Use: private |
| 2417 |
void |
| 2418 |
SoSceneViewer::save() |
| 2419 |
// |
| 2420 |
//////////////////////////////////////////////////////////////////////// |
| 2421 |
{ |
| 2422 |
if (fileName != NULL) { |
| 2423 |
SbBool ok = writeFile(fileName); |
| 2424 |
if (!ok) { |
| 2425 |
delete fileName; |
| 2426 |
fileName = NULL; |
| 2427 |
} |
| 2428 |
} |
| 2429 |
else { |
| 2430 |
fileMode = SV_FILE_SAVE_AS; |
| 2431 |
getFileName(); |
| 2432 |
} |
| 2433 |
} |
| 2434 |
|
| 2435 |
//////////////////////////////////////////////////////////////////////// |
| 2436 |
// |
| 2437 |
// Description: |
| 2438 |
// Removes the attached light manips geometry from the scene. This |
| 2439 |
// is used for file writting,... |
| 2440 |
// |
| 2441 |
// Use: private |
| 2442 |
void |
| 2443 |
SoSceneViewer::removeAttachedLightManipGeometry() |
| 2444 |
// |
| 2445 |
//////////////////////////////////////////////////////////////////////// |
| 2446 |
{ |
| 2447 |
for (int i = 0; i < lightDataList.getLength(); i++ ) { |
| 2448 |
|
| 2449 |
SvLightData *data = (SvLightData *) lightDataList[i]; |
| 2450 |
|
| 2451 |
// We'll be putting everything back later, so make a note of this... |
| 2452 |
data->shouldBeManip = data->isManip(); |
| 2453 |
|
| 2454 |
if ( data->isManip() == TRUE ) |
| 2455 |
editLight(data, FALSE); |
| 2456 |
} |
| 2457 |
} |
| 2458 |
|
| 2459 |
//////////////////////////////////////////////////////////////////////// |
| 2460 |
// |
| 2461 |
// Description: |
| 2462 |
// Add the attached light manips geometry back into the scene. This |
| 2463 |
// is called after the geometry has been temporaly revomed (used for file |
| 2464 |
// writting). |
| 2465 |
// |
| 2466 |
// Use: private |
| 2467 |
void |
| 2468 |
SoSceneViewer::addAttachedLightManipGeometry() |
| 2469 |
// |
| 2470 |
//////////////////////////////////////////////////////////////////////// |
| 2471 |
{ |
| 2472 |
for (int i = 0; i < lightDataList.getLength(); i++ ) { |
| 2473 |
|
| 2474 |
SvLightData *data = (SvLightData *) lightDataList[i]; |
| 2475 |
|
| 2476 |
if ( data->isManip() != data->shouldBeManip ) |
| 2477 |
editLight(data, data->shouldBeManip); |
| 2478 |
} |
| 2479 |
} |
| 2480 |
|
| 2481 |
//////////////////////////////////////////////////////////////////////// |
| 2482 |
// |
| 2483 |
// Description: |
| 2484 |
// Write the nodes under the selection node to the given file name. |
| 2485 |
// |
| 2486 |
// Use: private |
| 2487 |
SbBool |
| 2488 |
SoSceneViewer::writeFile(const char *filename) |
| 2489 |
// |
| 2490 |
//////////////////////////////////////////////////////////////////////// |
| 2491 |
{ |
| 2492 |
SoWriteAction wa; |
| 2493 |
|
| 2494 |
if (! wa.getOutput()->openFile(filename)) { |
| 2495 |
|
| 2496 |
// display an error dialog |
| 2497 |
char str[100]; |
| 2498 |
strcpy(str, "Error creating file: "); |
| 2499 |
strcat(str, filename); |
| 2500 |
SoXt::createSimpleErrorDialog(mgrWidget, "File Error Dialog", str); |
| 2501 |
|
| 2502 |
return FALSE; |
| 2503 |
} |
| 2504 |
|
| 2505 |
// temporarily replace all manips with regular transform nodes. |
| 2506 |
removeManips(); |
| 2507 |
|
| 2508 |
// restore the cameraNum settings of any scenekits. |
| 2509 |
restoreSceneKitCameras(selection); |
| 2510 |
// Copy our camera into the last sceneKit. |
| 2511 |
setLastSceneKitCamera(selection, (SoCamera *)getCamera()->copy()); |
| 2512 |
|
| 2513 |
// write out all the children of the selection node |
| 2514 |
for (int i = 0; i < selection->getNumChildren(); i++) |
| 2515 |
wa.apply(selection->getChild(i)); |
| 2516 |
wa.getOutput()->closeFile(); |
| 2517 |
|
| 2518 |
// Switch the sceneKit cameras back off: |
| 2519 |
switchOffSceneKitCameras(selection); |
| 2520 |
|
| 2521 |
// Now put the manips back in the scene graph. |
| 2522 |
restoreManips(); |
| 2523 |
|
| 2524 |
return TRUE; |
| 2525 |
} |
| 2526 |
|
| 2527 |
//////////////////////////////////////////////////////////////////////// |
| 2528 |
// |
| 2529 |
// Description: |
| 2530 |
// Write the Enviroment nodes (camera and lights) to the given |
| 2531 |
// file name. |
| 2532 |
// |
| 2533 |
// Use: private |
| 2534 |
SbBool |
| 2535 |
SoSceneViewer::writeEnvFile(const char *filename) |
| 2536 |
// |
| 2537 |
//////////////////////////////////////////////////////////////////////// |
| 2538 |
{ |
| 2539 |
SoWriteAction wa; |
| 2540 |
|
| 2541 |
if (! wa.getOutput()->openFile(filename)) { |
| 2542 |
|
| 2543 |
// display an error dialog |
| 2544 |
char str[100]; |
| 2545 |
strcpy(str, "Error creating file: "); |
| 2546 |
strcat(str, filename); |
| 2547 |
SoXt::createSimpleErrorDialog(mgrWidget, "File Error Dialog", str); |
| 2548 |
|
| 2549 |
return FALSE; |
| 2550 |
} |
| 2551 |
|
| 2552 |
// write out the environment including the headlight |
| 2553 |
wa.apply(envLabel); |
| 2554 |
wa.apply(getCamera()); |
| 2555 |
wa.apply(environment); |
| 2556 |
wa.apply(lightGroup); |
| 2557 |
if (isHeadlight()) |
| 2558 |
wa.apply(getHeadlight()); |
| 2559 |
|
| 2560 |
wa.getOutput()->closeFile(); |
| 2561 |
|
| 2562 |
return TRUE; |
| 2563 |
} |
| 2564 |
|
| 2565 |
//////////////////////////////////////////////////////////////////////// |
| 2566 |
// |
| 2567 |
// Description: |
| 2568 |
// Print the scene using a custom print dialog. |
| 2569 |
// |
| 2570 |
// Use: private |
| 2571 |
void |
| 2572 |
SoSceneViewer::print() |
| 2573 |
// |
| 2574 |
//////////////////////////////////////////////////////////////////////// |
| 2575 |
{ |
| 2576 |
if (printDialog == NULL) { |
| 2577 |
printDialog = new SoXtPrintDialog; |
| 2578 |
printDialog->setTitle("SceneViewer Printing"); |
| 2579 |
printDialog->setBeforePrintCallback( |
| 2580 |
SoSceneViewer::beforePrintCallback, (void *) this); |
| 2581 |
printDialog->setAfterPrintCallback( |
| 2582 |
SoSceneViewer::afterPrintCallback, (void *) this); |
| 2583 |
} |
| 2584 |
|
| 2585 |
// |
| 2586 |
// Send the render area size and scene graph to the print dialog |
| 2587 |
// |
| 2588 |
Widget widget = getRenderAreaWidget(); |
| 2589 |
if (widget != NULL) { |
| 2590 |
Arg args[2]; |
| 2591 |
int n = 0; |
| 2592 |
SbVec2s sz; |
| 2593 |
XtSetArg(args[n], XtNwidth, &sz[0]); n++; |
| 2594 |
XtSetArg(args[n], XtNheight, &sz[1]); n++; |
| 2595 |
XtGetValues(widget, args, n); |
| 2596 |
printDialog->setPrintSize(sz); |
| 2597 |
} |
| 2598 |
|
| 2599 |
printDialog->show(); |
| 2600 |
} |
| 2601 |
|
| 2602 |
//////////////////////////////////////////////////////////////////////// |
| 2603 |
// |
| 2604 |
// Description: |
| 2605 |
// Temporarily remove manips from the scene. |
| 2606 |
// Restore them with a call to restoreManips(). |
| 2607 |
// |
| 2608 |
// Use: private |
| 2609 |
void |
| 2610 |
SoSceneViewer::removeManips() |
| 2611 |
// |
| 2612 |
//////////////////////////////////////////////////////////////////////// |
| 2613 |
{ |
| 2614 |
// temporarily replace all manips with regular transform nodes. |
| 2615 |
for (int m = 0; m < maniplist->getLength(); m++ ) { |
| 2616 |
SoTransformManip *manip = maniplist->getManip(m); |
| 2617 |
SoPath *xfPath = maniplist->getXfPath(m); |
| 2618 |
manip->replaceManip(xfPath, NULL); |
| 2619 |
} |
| 2620 |
} |
| 2621 |
|
| 2622 |
//////////////////////////////////////////////////////////////////////// |
| 2623 |
// |
| 2624 |
// Description: |
| 2625 |
// Restore manips that were removed with removeManips(). |
| 2626 |
// |
| 2627 |
// Use: private |
| 2628 |
void |
| 2629 |
SoSceneViewer::restoreManips() |
| 2630 |
// |
| 2631 |
//////////////////////////////////////////////////////////////////////// |
| 2632 |
{ |
| 2633 |
// Now put the manips back in the scene graph. |
| 2634 |
for (int m = 0; m < maniplist->getLength(); m++ ) { |
| 2635 |
SoTransformManip *manip = maniplist->getManip(m); |
| 2636 |
SoPath *xfPath = maniplist->getXfPath(m); |
| 2637 |
manip->replaceNode(xfPath); |
| 2638 |
} |
| 2639 |
} |
| 2640 |
|
| 2641 |
//////////////////////////////////////////////////////////////////////// |
| 2642 |
// |
| 2643 |
// Description: |
| 2644 |
// Temporarily remove manips from the scene. They |
| 2645 |
// will all be restored after the printing is done. |
| 2646 |
// |
| 2647 |
// Use: private, static |
| 2648 |
void |
| 2649 |
SoSceneViewer::beforePrintCallback(void *uData, SoXtPrintDialog *) |
| 2650 |
// |
| 2651 |
//////////////////////////////////////////////////////////////////////// |
| 2652 |
{ |
| 2653 |
SoSceneViewer *sv = (SoSceneViewer *)uData; |
| 2654 |
|
| 2655 |
// temporarily replace all manips with regular transforms. |
| 2656 |
sv->removeManips(); |
| 2657 |
|
| 2658 |
// Do the same for all the light manips |
| 2659 |
sv->removeAttachedLightManipGeometry(); |
| 2660 |
|
| 2661 |
// if the current viewer is the examiner viewer, turn the |
| 2662 |
// feedback axis off while we print |
| 2663 |
if (sv->whichViewer == SV_VWR_EXAMINER) { |
| 2664 |
SoXtExaminerViewer *exam = (SoXtExaminerViewer *) sv->currentViewer; |
| 2665 |
sv->feedbackShown = exam->isFeedbackVisible(); |
| 2666 |
exam->setFeedbackVisibility(FALSE); |
| 2667 |
} |
| 2668 |
|
| 2669 |
// set the scene to print |
| 2670 |
sv->printDialog->setSceneGraph(sv->sceneGraph); |
| 2671 |
} |
| 2672 |
|
| 2673 |
//////////////////////////////////////////////////////////////////////// |
| 2674 |
// |
| 2675 |
// Description: |
| 2676 |
// Called after printing is done. Add the manips back into the |
| 2677 |
// scene. |
| 2678 |
// |
| 2679 |
// Use: private, static |
| 2680 |
void |
| 2681 |
SoSceneViewer::afterPrintCallback(void *uData, SoXtPrintDialog *) |
| 2682 |
// |
| 2683 |
//////////////////////////////////////////////////////////////////////// |
| 2684 |
{ |
| 2685 |
SoSceneViewer *sv = (SoSceneViewer *)uData; |
| 2686 |
|
| 2687 |
// put the manips back in the scene graph. |
| 2688 |
sv->restoreManips(); |
| 2689 |
|
| 2690 |
// put the light manips back in the scene graph. |
| 2691 |
sv->addAttachedLightManipGeometry(); |
| 2692 |
|
| 2693 |
// restor the examiner feedback |
| 2694 |
if (sv->whichViewer == SV_VWR_EXAMINER) { |
| 2695 |
SoXtExaminerViewer *exam = (SoXtExaminerViewer *) sv->currentViewer; |
| 2696 |
exam->setFeedbackVisibility( sv->feedbackShown ); |
| 2697 |
} |
| 2698 |
} |
| 2699 |
|
| 2700 |
//////////////////////////////////////////////////////////////////////// |
| 2701 |
// |
| 2702 |
// Description: |
| 2703 |
// Static routine for processing topbar menu events. |
| 2704 |
// When the menu is created, it stores pointer to the SoSceneViewer |
| 2705 |
// in the client_data, so that we can tell which SoSceneViewer needs |
| 2706 |
// the event. |
| 2707 |
// |
| 2708 |
// Use: private, static |
| 2709 |
// |
| 2710 |
void |
| 2711 |
SoSceneViewer::processTopbarEvent( |
| 2712 |
Widget, // Which widget? I don't care |
| 2713 |
SoSceneViewerData *data, // Pointer to button/SoSceneViewer |
| 2714 |
XmAnyCallbackStruct *cb ) // X garbage |
| 2715 |
// |
| 2716 |
//////////////////////////////////////////////////////////////////////// |
| 2717 |
{ |
| 2718 |
SoSceneViewer *sv = data->classPt; |
| 2719 |
Time eventTime = cb->event->xbutton.time; |
| 2720 |
|
| 2721 |
switch (data->id) { |
| 2722 |
|
| 2723 |
// |
| 2724 |
// File |
| 2725 |
// |
| 2726 |
|
| 2727 |
case SV_FILE_ABOUT: |
| 2728 |
sv->showAboutDialog(); |
| 2729 |
break; |
| 2730 |
|
| 2731 |
case SV_FILE_NEW: |
| 2732 |
sv->deleteScene(); |
| 2733 |
delete sv->fileName; |
| 2734 |
sv->fileName = NULL; |
| 2735 |
break; |
| 2736 |
|
| 2737 |
case SV_FILE_OPEN: |
| 2738 |
case SV_FILE_IMPORT: |
| 2739 |
case SV_FILE_SAVE_AS: |
| 2740 |
case SV_FILE_READ_ENV: |
| 2741 |
case SV_FILE_SAVE_ENV: |
| 2742 |
sv->fileMode = data->id; |
| 2743 |
sv->getFileName(); |
| 2744 |
break; |
| 2745 |
|
| 2746 |
case SV_FILE_SAVE: |
| 2747 |
sv->save(); |
| 2748 |
break; |
| 2749 |
|
| 2750 |
case SV_FILE_PRINT: |
| 2751 |
sv->print(); |
| 2752 |
break; |
| 2753 |
case SV_FILE_QUIT: |
| 2754 |
delete sv; |
| 2755 |
exit(0); |
| 2756 |
break; |
| 2757 |
|
| 2758 |
// |
| 2759 |
// Edit |
| 2760 |
// |
| 2761 |
|
| 2762 |
case SV_EDIT_PICK_PARENT: |
| 2763 |
sv->pickParent(); |
| 2764 |
break; |
| 2765 |
case SV_EDIT_PICK_ALL: |
| 2766 |
sv->pickAll(); |
| 2767 |
break; |
| 2768 |
case SV_EDIT_CUT: |
| 2769 |
// Remove manipulators before cutting the selection. |
| 2770 |
sv->detachManipFromAll(); |
| 2771 |
sv->clipboard->copy((SoPathList *)sv->selection->getList(), eventTime); |
| 2772 |
sv->destroySelectedObjects(); |
| 2773 |
sv->updateCommandAvailability(); |
| 2774 |
break; |
| 2775 |
case SV_EDIT_COPY: |
| 2776 |
// Remove manipulators while copying the selection. |
| 2777 |
sv->removeManips(); |
| 2778 |
sv->clipboard->copy((SoPathList *)sv->selection->getList(), eventTime); |
| 2779 |
sv->restoreManips(); |
| 2780 |
break; |
| 2781 |
case SV_EDIT_PASTE: |
| 2782 |
sv->clipboard->paste(eventTime, pasteDoneCB, sv); |
| 2783 |
break; |
| 2784 |
case SV_EDIT_DELETE: |
| 2785 |
sv->destroySelectedObjects(); |
| 2786 |
sv->updateCommandAvailability(); |
| 2787 |
break; |
| 2788 |
|
| 2789 |
// |
| 2790 |
// Viewing |
| 2791 |
// |
| 2792 |
|
| 2793 |
case SV_VIEW_PICK: |
| 2794 |
sv->setViewing(! sv->isViewing()); |
| 2795 |
break; |
| 2796 |
#ifdef EXPLORER |
| 2797 |
case SV_VIEW_USER: |
| 2798 |
sv->userModeFlag = !sv->userModeFlag; |
| 2799 |
if (sv->userModeFlag) |
| 2800 |
sv->currentViewer->setEventCallback(sv->userModeCB, sv->userModedata); |
| 2801 |
else |
| 2802 |
sv->currentViewer->setEventCallback(NULL, NULL); |
| 2803 |
break; |
| 2804 |
#endif |
| 2805 |
|
| 2806 |
case SV_VIEW_EXAMINER: |
| 2807 |
sv->switchToViewer(SV_VWR_EXAMINER); |
| 2808 |
break; |
| 2809 |
case SV_VIEW_WALK: |
| 2810 |
sv->switchToViewer(SV_VWR_WALK); |
| 2811 |
break; |
| 2812 |
case SV_VIEW_PLANE: |
| 2813 |
sv->switchToViewer(SV_VWR_PLANE); |
| 2814 |
break; |
| 2815 |
case SV_VIEW_FLY: |
| 2816 |
sv->switchToViewer(SV_VWR_FLY); |
| 2817 |
break; |
| 2818 |
|
| 2819 |
case SV_VIEW_SELECTION: |
| 2820 |
sv->viewSelection(); |
| 2821 |
break; |
| 2822 |
|
| 2823 |
case SV_VIEW_SCREEN_TRANSPARENCY: |
| 2824 |
sv->setTransparencyType(SoGLRenderAction::SCREEN_DOOR); |
| 2825 |
break; |
| 2826 |
case SV_VIEW_BLEND_TRANSPARENCY: |
| 2827 |
sv->setTransparencyType(SoGLRenderAction::BLEND); |
| 2828 |
break; |
| 2829 |
case SV_VIEW_DELAY_BLEND_TRANSPARENCY: |
| 2830 |
sv->setTransparencyType(SoGLRenderAction::DELAYED_BLEND); |
| 2831 |
break; |
| 2832 |
case SV_VIEW_SORT_BLEND_TRANSPARENCY: |
| 2833 |
sv->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND); |
| 2834 |
break; |
| 2835 |
|
| 2836 |
case SV_VIEW_FOG: |
| 2837 |
sv->setFog(! sv->fogFlag); |
| 2838 |
break; |
| 2839 |
case SV_VIEW_ANTIALIASING: |
| 2840 |
sv->setAntialiasing(! sv->antialiasingFlag); |
| 2841 |
break; |
| 2842 |
case SV_VIEW_BKG_COLOR: |
| 2843 |
sv->editBackgroundColor(); |
| 2844 |
break; |
| 2845 |
|
| 2846 |
|
| 2847 |
// |
| 2848 |
// Editors |
| 2849 |
// |
| 2850 |
case SV_EDITOR_MATERIAL: |
| 2851 |
sv->createMaterialEditor(); |
| 2852 |
break; |
| 2853 |
|
| 2854 |
case SV_EDITOR_TRANSFORM: |
| 2855 |
sv->createTransformSliderSet(); |
| 2856 |
break; |
| 2857 |
|
| 2858 |
case SV_EDITOR_COLOR: |
| 2859 |
sv->createColorEditor(); |
| 2860 |
break; |
| 2861 |
|
| 2862 |
// |
| 2863 |
// Selection |
| 2864 |
// |
| 2865 |
case SV_SEL_SINGLE_SELECT: |
| 2866 |
sv->selection->policy.setValue(SoSelection::SINGLE); |
| 2867 |
break; |
| 2868 |
|
| 2869 |
case SV_SEL_TOGGLE_SELECT: |
| 2870 |
sv->selection->policy.setValue(SoSelection::TOGGLE); |
| 2871 |
break; |
| 2872 |
|
| 2873 |
case SV_SEL_SHIFT_SELECT: |
| 2874 |
sv->selection->policy.setValue(SoSelection::SHIFT); |
| 2875 |
break; |
| 2876 |
|
| 2877 |
// |
| 2878 |
// Manips |
| 2879 |
// |
| 2880 |
case SV_MANIP_TRANSFORMER: |
| 2881 |
sv->highlightRA->setVisible(FALSE); // highlight visible when no manip |
| 2882 |
sv->curManip = (sv->curManip == SV_TRANSFORMER) ? SV_NONE : SV_TRANSFORMER; |
| 2883 |
if ( sv->curManipReplaces ) |
| 2884 |
sv->replaceAllManips( sv->curManip ); |
| 2885 |
break; |
| 2886 |
|
| 2887 |
case SV_MANIP_TRACKBALL: |
| 2888 |
sv->highlightRA->setVisible(FALSE); // highlight visible when no manip |
| 2889 |
sv->curManip = (sv->curManip == SV_TRACKBALL) ? SV_NONE : SV_TRACKBALL; |
| 2890 |
if ( sv->curManipReplaces ) |
| 2891 |
sv->replaceAllManips( sv->curManip ); |
| 2892 |
break; |
| 2893 |
|
| 2894 |
case SV_MANIP_HANDLEBOX: |
| 2895 |
sv->highlightRA->setVisible(FALSE); // highlight visible when no manip |
| 2896 |
sv->curManip = (sv->curManip == SV_HANDLEBOX) ? SV_NONE : SV_HANDLEBOX; |
| 2897 |
if ( sv->curManipReplaces ) |
| 2898 |
sv->replaceAllManips( sv->curManip ); |
| 2899 |
break; |
| 2900 |
|
| 2901 |
case SV_MANIP_JACK: |
| 2902 |
sv->highlightRA->setVisible(FALSE); // highlight visible when no manip |
| 2903 |
sv->curManip = (sv->curManip == SV_JACK) ? SV_NONE : SV_JACK; |
| 2904 |
if ( sv->curManipReplaces ) |
| 2905 |
sv->replaceAllManips( sv->curManip ); |
| 2906 |
break; |
| 2907 |
|
| 2908 |
case SV_MANIP_CENTERBALL: |
| 2909 |
sv->highlightRA->setVisible(FALSE); // highlight visible when no manip |
| 2910 |
sv->curManip =(sv->curManip == SV_CENTERBALL) ? SV_NONE : SV_CENTERBALL; |
| 2911 |
if ( sv->curManipReplaces ) |
| 2912 |
sv->replaceAllManips( sv->curManip ); |
| 2913 |
break; |
| 2914 |
|
| 2915 |
case SV_MANIP_XFBOX: |
| 2916 |
sv->highlightRA->setVisible(FALSE); // highlight visible when no manip |
| 2917 |
sv->curManip = (sv->curManip == SV_XFBOX) ? SV_NONE : SV_XFBOX; |
| 2918 |
if ( sv->curManipReplaces ) |
| 2919 |
sv->replaceAllManips( sv->curManip ); |
| 2920 |
break; |
| 2921 |
|
| 2922 |
case SV_MANIP_TABBOX: |
| 2923 |
sv->highlightRA->setVisible(FALSE); // highlight visible when no manip |
| 2924 |
sv->curManip = (sv->curManip == SV_TABBOX) ? SV_NONE : SV_TABBOX; |
| 2925 |
if ( sv->curManipReplaces ) |
| 2926 |
sv->replaceAllManips( sv->curManip ); |
| 2927 |
break; |
| 2928 |
|
| 2929 |
case SV_MANIP_NONE: |
| 2930 |
sv->highlightRA->setVisible(TRUE); // highlight visible when no manip |
| 2931 |
sv->curManip = SV_NONE; |
| 2932 |
if ( sv->curManipReplaces ) |
| 2933 |
sv->detachManipFromAll(); |
| 2934 |
break; |
| 2935 |
case SV_MANIP_REPLACE_ALL: |
| 2936 |
// Toggle the value of 'curManipReplaces' |
| 2937 |
sv->curManipReplaces = ( sv->curManipReplaces == TRUE) ? FALSE : TRUE; |
| 2938 |
|
| 2939 |
if ( sv->curManipReplaces ) |
| 2940 |
sv->replaceAllManips( sv->curManip ); |
| 2941 |
break; |
| 2942 |
|
| 2943 |
// |
| 2944 |
// Lights |
| 2945 |
// |
| 2946 |
case SV_LIGHT_AMBIENT_EDIT: sv->editAmbientColor(); break; |
| 2947 |
case SV_LIGHT_ADD_DIRECT: sv->addLight(new SoDirectionalLightManip); break; |
| 2948 |
case SV_LIGHT_ADD_POINT: sv->addLight(new SoPointLightManip); break; |
| 2949 |
case SV_LIGHT_ADD_SPOT: |
| 2950 |
{ |
| 2951 |
// Set the dropOffRate to be non-zero, or it will always work |
| 2952 |
// like a point light. |
| 2953 |
SoSpotLightManip *newSpotManip = new SoSpotLightManip; |
| 2954 |
newSpotManip->dropOffRate = .01; |
| 2955 |
sv->addLight(newSpotManip); |
| 2956 |
} |
| 2957 |
break; |
| 2958 |
|
| 2959 |
case SV_LIGHT_TURN_ON: |
| 2960 |
case SV_LIGHT_TURN_OFF: |
| 2961 |
{ |
| 2962 |
SbBool onFlag = (data->id == SV_LIGHT_TURN_ON); |
| 2963 |
for (int i=0; i < sv->lightDataList.getLength(); i++) |
| 2964 |
sv->turnLightOnOff((SvLightData *) sv->lightDataList[i], onFlag); |
| 2965 |
sv->turnLightOnOff( sv->headlightData, onFlag); |
| 2966 |
} |
| 2967 |
break; |
| 2968 |
case SV_LIGHT_SHOW_ALL: |
| 2969 |
case SV_LIGHT_HIDE_ALL: |
| 2970 |
{ |
| 2971 |
SbBool onFlag = (data->id == SV_LIGHT_SHOW_ALL); |
| 2972 |
for (int i=0; i < sv->lightDataList.getLength(); i++) |
| 2973 |
sv->editLight((SvLightData *) sv->lightDataList[i], onFlag); |
| 2974 |
} |
| 2975 |
break; |
| 2976 |
|
| 2977 |
} // endswitch( topbar button ) |
| 2978 |
} |
| 2979 |
|
| 2980 |
//////////////////////////////////////////////////////////////////////// |
| 2981 |
// |
| 2982 |
// Description: |
| 2983 |
// Adds the given light to the scene and to the menu. |
| 2984 |
// |
| 2985 |
// Use: private |
| 2986 |
// |
| 2987 |
void |
| 2988 |
SoSceneViewer::addLight(SoLight *light) |
| 2989 |
// |
| 2990 |
//////////////////////////////////////////////////////////////////////// |
| 2991 |
{ |
| 2992 |
// Calculate the light manip size if necessary. |
| 2993 |
// Do this before adding the light into the scene, |
| 2994 |
// since if the light is a manip, its default size might influence the |
| 2995 |
// scene size. |
| 2996 |
if (!calculatedLightManipSize) |
| 2997 |
calculateLightManipSize(); |
| 2998 |
|
| 2999 |
// create the switch and light node and add it to the scene |
| 3000 |
SoSwitch *lightSwitch = new SoSwitch; |
| 3001 |
lightGroup->addChild(lightSwitch); |
| 3002 |
lightSwitch->addChild(light); |
| 3003 |
SWITCH_LIGHT_ON(lightSwitch); |
| 3004 |
|
| 3005 |
// add the light entry for the new light |
| 3006 |
SvLightData *data = addLightEntry(light, lightSwitch); |
| 3007 |
|
| 3008 |
// |
| 3009 |
// Try to come up with some meaningfull default position base |
| 3010 |
// of the current camera view volume. |
| 3011 |
// |
| 3012 |
SoCamera *vwrCamera = getCamera(); // don't cache this in the class |
| 3013 |
SbViewVolume vv = vwrCamera->getViewVolume(0.0); |
| 3014 |
SbVec3f forward = - vv.zVector(); |
| 3015 |
SbVec3f center = vwrCamera->position.getValue() + forward * |
| 3016 |
(vwrCamera->nearDistance.getValue() + vwrCamera->farDistance.getValue()) / 2.0; |
| 3017 |
SbVec3f position( vv.ulf + forward * vv.nearToFar * .25 ); |
| 3018 |
//XXX ??? XXX |
| 3019 |
//XXX this algorithm should be replaced. Perhaps instead of using |
| 3020 |
//XXX 'forward' we could go a little up and to the left? |
| 3021 |
//XXX ??? XXX |
| 3022 |
|
| 3023 |
if (data->type.isDerivedFrom(SoDirectionalLight::getClassTypeId())) { |
| 3024 |
SoDirectionalLight *myLight = (SoDirectionalLight *) data->light; |
| 3025 |
// the position of the light can't be given to the light itself. |
| 3026 |
// So we use the translation and translation inverse to |
| 3027 |
// get it to go where we want. |
| 3028 |
data->translation->translation = position; |
| 3029 |
data->translationInverse->translation = -position; |
| 3030 |
myLight->direction = center - position; |
| 3031 |
} |
| 3032 |
else { |
| 3033 |
// The data->scale will influence the position we set. |
| 3034 |
// So we need to prepare for this. Note, it's not a prolem for |
| 3035 |
// directional lights since they use the translation node, |
| 3036 |
// which is outside the scale and scaleInverse grouping |
| 3037 |
SbVec3f invrs = data->scaleInverse->scaleFactor.getValue(); |
| 3038 |
SbVec3f scaledLoc = position; |
| 3039 |
scaledLoc *= invrs[0]; |
| 3040 |
|
| 3041 |
if (data->type.isDerivedFrom(SoPointLight::getClassTypeId())) { |
| 3042 |
SoPointLight *myLight = (SoPointLight *) data->light; |
| 3043 |
myLight->location = scaledLoc; |
| 3044 |
// no direction for this light |
| 3045 |
} |
| 3046 |
else if (data->type.isDerivedFrom(SoSpotLight::getClassTypeId())) { |
| 3047 |
SoSpotLight *myLight = (SoSpotLight *) data->light; |
| 3048 |
myLight->location = scaledLoc; |
| 3049 |
myLight->direction = center - position; |
| 3050 |
} |
| 3051 |
} |
| 3052 |
} |
| 3053 |
|
| 3054 |
//////////////////////////////////////////////////////////////////////// |
| 3055 |
// |
| 3056 |
// Description: |
| 3057 |
// Creates and append the light data struct, and adds a menu entry |
| 3058 |
// for the light. |
| 3059 |
// |
| 3060 |
// Use: private |
| 3061 |
// |
| 3062 |
SvLightData * |
| 3063 |
SoSceneViewer::addLightEntry(SoLight *light, SoSwitch *lightSwitch) |
| 3064 |
// |
| 3065 |
//////////////////////////////////////////////////////////////////////// |
| 3066 |
{ |
| 3067 |
// |
| 3068 |
// create the light data |
| 3069 |
// |
| 3070 |
|
| 3071 |
SvLightData *data = new SvLightData; |
| 3072 |
lightDataList.append(data); |
| 3073 |
|
| 3074 |
light->ref(); |
| 3075 |
data->light = light; |
| 3076 |
|
| 3077 |
data->lightSwitch = lightSwitch; |
| 3078 |
|
| 3079 |
// Try and find the scale, scaleInverse, translation, and |
| 3080 |
// translationInverse. |
| 3081 |
data->scale = NULL; |
| 3082 |
data->scaleInverse = NULL; |
| 3083 |
data->translation = NULL; |
| 3084 |
data->translationInverse = NULL; |
| 3085 |
SbBool gotLight = FALSE; |
| 3086 |
for ( int i = 0; i < lightSwitch->getNumChildren(); i++ ) { |
| 3087 |
SoNode *n = lightSwitch->getChild(i); |
| 3088 |
if (n == light) |
| 3089 |
gotLight = TRUE; |
| 3090 |
else if (n->isOfType(SoScale::getClassTypeId())){ |
| 3091 |
if (data->scale == NULL && gotLight == FALSE) |
| 3092 |
data->scale = (SoScale *) n; |
| 3093 |
else if (data->scaleInverse == NULL && gotLight == TRUE) |
| 3094 |
data->scaleInverse = (SoScale *) n; |
| 3095 |
} |
| 3096 |
else if (n->isOfType(SoTranslation::getClassTypeId())){ |
| 3097 |
if (data->translation == NULL && gotLight == FALSE) |
| 3098 |
data->translation = (SoTranslation *) n; |
| 3099 |
else if (data->translationInverse == NULL && gotLight == TRUE) |
| 3100 |
data->translationInverse = (SoTranslation *) n; |
| 3101 |
} |
| 3102 |
} |
| 3103 |
|
| 3104 |
// Now install any missing nodes... |
| 3105 |
if (data->scale == NULL) { |
| 3106 |
data->scale = new SoScale; |
| 3107 |
int lightInd = lightSwitch->findChild(light); |
| 3108 |
lightSwitch->insertChild( data->scale, lightInd ); |
| 3109 |
} |
| 3110 |
if (data->scaleInverse == NULL) { |
| 3111 |
data->scaleInverse = new SoScale; |
| 3112 |
int lightInd = lightSwitch->findChild(light); |
| 3113 |
lightSwitch->insertChild( data->scaleInverse, lightInd + 1 ); |
| 3114 |
} |
| 3115 |
if (data->translation == NULL) { |
| 3116 |
data->translation = new SoTranslation; |
| 3117 |
int scaleInd = lightSwitch->findChild(data->scale); |
| 3118 |
lightSwitch->insertChild( data->translation, scaleInd ); |
| 3119 |
} |
| 3120 |
if (data->translationInverse == NULL) { |
| 3121 |
data->translationInverse = new SoTranslation; |
| 3122 |
int scaleInvInd = lightSwitch->findChild(data->scaleInverse); |
| 3123 |
lightSwitch->insertChild( data->translationInverse, scaleInvInd+1 ); |
| 3124 |
} |
| 3125 |
// See if the size was already calculated (this happens when we read |
| 3126 |
// .env files)... |
| 3127 |
SbVec3f oldScale = data->scale->scaleFactor.getValue(); |
| 3128 |
if ( calculatedLightManipSize == FALSE |
| 3129 |
&& oldScale != SbVec3f(1,1,1) ) { |
| 3130 |
lightManipSize = oldScale[0]; |
| 3131 |
calculatedLightManipSize = TRUE; |
| 3132 |
} |
| 3133 |
|
| 3134 |
data->classPt = this; |
| 3135 |
data->colorEditor = NULL; |
| 3136 |
data->type = light->getTypeId(); |
| 3137 |
|
| 3138 |
// set the correct label name |
| 3139 |
char *str; |
| 3140 |
if (data->type.isDerivedFrom( SoDirectionalLight::getClassTypeId())) |
| 3141 |
str = Light.directionallight; |
| 3142 |
else if (data->type.isDerivedFrom( SoPointLight::getClassTypeId()) ) |
| 3143 |
str = Light.pointlight; |
| 3144 |
else if (data->type.isDerivedFrom( SoSpotLight::getClassTypeId()) ) |
| 3145 |
str = Light.spotlight; |
| 3146 |
else str = "??? "; |
| 3147 |
data->name = strdup(str); |
| 3148 |
|
| 3149 |
// Set the size for the light manips. |
| 3150 |
if ( !calculatedLightManipSize ) |
| 3151 |
calculateLightManipSize(); |
| 3152 |
|
| 3153 |
data->scale->scaleFactor.setValue( lightManipSize, lightManipSize, |
| 3154 |
lightManipSize ); |
| 3155 |
float invSz = (lightManipSize == 0.0) ? 1.0 : 1.0 / lightManipSize; |
| 3156 |
data->scaleInverse->scaleFactor.setValue( invSz, invSz, invSz ); |
| 3157 |
|
| 3158 |
// |
| 3159 |
// add the menu entry |
| 3160 |
// |
| 3161 |
addLightMenuEntry(data); |
| 3162 |
|
| 3163 |
return data; |
| 3164 |
} |
| 3165 |
|
| 3166 |
//////////////////////////////////////////////////////////////////////// |
| 3167 |
// |
| 3168 |
// Description: |
| 3169 |
// build the light menu entry for the given light. |
| 3170 |
// |
| 3171 |
// Use: private |
| 3172 |
// |
| 3173 |
void |
| 3174 |
SoSceneViewer::addLightMenuEntry(SvLightData *data) |
| 3175 |
// |
| 3176 |
//////////////////////////////////////////////////////////////////////// |
| 3177 |
{ |
| 3178 |
// |
| 3179 |
// create the motif menu entry |
| 3180 |
// |
| 3181 |
|
| 3182 |
Widget menu = menuItems[SV_LIGHT].widget; |
| 3183 |
|
| 3184 |
// makes sure menu has been built |
| 3185 |
if (menu == NULL) |
| 3186 |
return; |
| 3187 |
|
| 3188 |
// create the submenu widget, adding a callback to update the toggles |
| 3189 |
Arg args[8]; |
| 3190 |
int argnum = 0; |
| 3191 |
#ifdef MENUS_IN_POPUP |
| 3192 |
SoXt::getPopupArgs(XtDisplay(menu), SCREEN(menu), args, &argnum); |
| 3193 |
#endif |
| 3194 |
data->submenuWidget = XmCreatePulldownMenu(menu, "submenu", args, argnum); |
| 3195 |
|
| 3196 |
XtAddCallback(data->submenuWidget, XmNmapCallback, |
| 3197 |
(XtCallbackProc) SoSceneViewer::lightSubmenuDisplay, |
| 3198 |
(XtPointer) data); |
| 3199 |
|
| 3200 |
// create a cascade menu entry which will bring the submenu |
| 3201 |
XtSetArg(args[0], XmNsubMenuId, data->submenuWidget); |
| 3202 |
data->cascadeWidget = XtCreateWidget(data->name, |
| 3203 |
xmCascadeButtonGadgetClass, menu, args, 1); |
| 3204 |
|
| 3205 |
// add "on/off" toggle |
| 3206 |
data->onOffWidget = XtCreateWidget("On/Off", xmToggleButtonGadgetClass, |
| 3207 |
data->submenuWidget, NULL, 0); |
| 3208 |
XtAddCallback(data->onOffWidget, XmNvalueChangedCallback, |
| 3209 |
(XtCallbackProc) SoSceneViewer::lightToggleCB, (XtPointer) data); |
| 3210 |
|
| 3211 |
// add "Icon" toggle |
| 3212 |
data->iconWidget = XtCreateWidget("Icon", xmToggleButtonGadgetClass, |
| 3213 |
data->submenuWidget, NULL, 0); |
| 3214 |
XtAddCallback(data->iconWidget, XmNvalueChangedCallback, |
| 3215 |
(XtCallbackProc) SoSceneViewer::editLightToggleCB, (XtPointer) data); |
| 3216 |
|
| 3217 |
// add "Edit Color" toggle |
| 3218 |
data->editColorWidget = XtCreateWidget("Edit Color", xmPushButtonGadgetClass, |
| 3219 |
data->submenuWidget, NULL, 0); |
| 3220 |
XtAddCallback(data->editColorWidget, XmNactivateCallback, |
| 3221 |
(XtCallbackProc) SoSceneViewer::editLightColorCB, (XtPointer) data); |
| 3222 |
|
| 3223 |
// add "Remove" entry |
| 3224 |
data->removeWidget = XtCreateWidget("Remove", xmPushButtonGadgetClass, |
| 3225 |
data->submenuWidget, NULL, 0); |
| 3226 |
XtAddCallback(data->removeWidget, XmNactivateCallback, |
| 3227 |
(XtCallbackProc) SoSceneViewer::removeLightCB, (XtPointer) data); |
| 3228 |
|
| 3229 |
// manage children |
| 3230 |
XtManageChild(data->onOffWidget); |
| 3231 |
XtManageChild(data->iconWidget); |
| 3232 |
XtManageChild(data->editColorWidget); |
| 3233 |
XtManageChild(data->removeWidget); |
| 3234 |
XtManageChild(data->cascadeWidget); |
| 3235 |
} |
| 3236 |
|
| 3237 |
//////////////////////////////////////////////////////////////////////// |
| 3238 |
// |
| 3239 |
// Description: |
| 3240 |
// Called by "On/Off" light menu entry when toggle changes. |
| 3241 |
// |
| 3242 |
// Use: static private |
| 3243 |
// |
| 3244 |
void |
| 3245 |
SoSceneViewer::lightToggleCB(Widget toggle, SvLightData *data, void *) |
| 3246 |
// |
| 3247 |
//////////////////////////////////////////////////////////////////////// |
| 3248 |
{ |
| 3249 |
data->classPt->turnLightOnOff(data, XmToggleButtonGetState(toggle)); |
| 3250 |
} |
| 3251 |
|
| 3252 |
//////////////////////////////////////////////////////////////////////// |
| 3253 |
// |
| 3254 |
// Description: |
| 3255 |
// Turn the given light on or off. |
| 3256 |
// |
| 3257 |
// Use: private |
| 3258 |
// |
| 3259 |
void |
| 3260 |
SoSceneViewer::turnLightOnOff(SvLightData *data, SbBool flag) |
| 3261 |
// |
| 3262 |
//////////////////////////////////////////////////////////////////////// |
| 3263 |
{ |
| 3264 |
// check if it is the headlight |
| 3265 |
if (data == headlightData) |
| 3266 |
setHeadlight( flag ); |
| 3267 |
else { |
| 3268 |
if ( flag ) |
| 3269 |
SWITCH_LIGHT_ON(data->lightSwitch); |
| 3270 |
else |
| 3271 |
SWITCH_LIGHT_OFF(data->lightSwitch); |
| 3272 |
} |
| 3273 |
} |
| 3274 |
|
| 3275 |
//////////////////////////////////////////////////////////////////////// |
| 3276 |
// |
| 3277 |
// Description: |
| 3278 |
// "Edit" light menu entry callback. |
| 3279 |
// |
| 3280 |
// Use: static private |
| 3281 |
// |
| 3282 |
void |
| 3283 |
SoSceneViewer::editLightToggleCB(Widget toggle, SvLightData *data, void *) |
| 3284 |
// |
| 3285 |
//////////////////////////////////////////////////////////////////////// |
| 3286 |
{ |
| 3287 |
data->classPt->editLight( data, XmToggleButtonGetState(toggle) ); |
| 3288 |
} |
| 3289 |
|
| 3290 |
//////////////////////////////////////////////////////////////////////// |
| 3291 |
// |
| 3292 |
// Description: |
| 3293 |
// Attach/detach the correct manipulator on the given light. |
| 3294 |
// |
| 3295 |
// Use: private |
| 3296 |
// |
| 3297 |
void |
| 3298 |
SoSceneViewer::editLight(SvLightData *data, SbBool flag) |
| 3299 |
// |
| 3300 |
//////////////////////////////////////////////////////////////////////// |
| 3301 |
{ |
| 3302 |
// ??? check if this is for the headlight, which is special cased |
| 3303 |
// ??? since a manipulator cannot be used (aligned to camera). |
| 3304 |
SbBool forHeadlight = (data == data->classPt->headlightData); |
| 3305 |
|
| 3306 |
SoType dataType = data->type; |
| 3307 |
SoType dirLightType = SoDirectionalLight::getClassTypeId(); |
| 3308 |
SoType ptLightType = SoPointLight::getClassTypeId(); |
| 3309 |
SoType spotLightType = SoSpotLight::getClassTypeId(); |
| 3310 |
|
| 3311 |
// |
| 3312 |
// attach the manip to the light and add it to the scene |
| 3313 |
// |
| 3314 |
if (flag) { |
| 3315 |
|
| 3316 |
if (forHeadlight) { |
| 3317 |
|
| 3318 |
if (headlightEditor == NULL) { |
| 3319 |
headlightEditor = new SoXtDirectionalLightEditor; |
| 3320 |
headlightEditor->setTitle("Headlight Editor"); |
| 3321 |
} |
| 3322 |
|
| 3323 |
// Make sure we have the current viewer's headlight |
| 3324 |
SoLight *l = data->classPt->getHeadlight(); |
| 3325 |
l->ref(); |
| 3326 |
if (data->light) |
| 3327 |
data->light->unref(); |
| 3328 |
data->light = l; |
| 3329 |
|
| 3330 |
// attach the dir light editor |
| 3331 |
// ??? don't use the path from the root to the headlight |
| 3332 |
// ??? since we want the light to be relative to the |
| 3333 |
// ??? camera (i.e. moving the camera shouldn't affect |
| 3334 |
// ??? the arrow in the editor since that direction |
| 3335 |
// ??? is relative to the camera). |
| 3336 |
SoPath *littlePath = new SoPath( data->light ); |
| 3337 |
headlightEditor->attach( littlePath ); |
| 3338 |
headlightEditor->show(); |
| 3339 |
} |
| 3340 |
else if (data->isManip() == FALSE) { |
| 3341 |
|
| 3342 |
// NOTE: if isManip() == TRUE, then the light is already a manip |
| 3343 |
// and doesn't need to be changed. |
| 3344 |
|
| 3345 |
SoLight *newManip = NULL; |
| 3346 |
|
| 3347 |
// allocate the right manipulator type if needed |
| 3348 |
if ( dataType.isDerivedFrom( dirLightType ) ) { |
| 3349 |
newManip = new SoDirectionalLightManip; |
| 3350 |
newManip->ref(); |
| 3351 |
} |
| 3352 |
else if ( dataType.isDerivedFrom( ptLightType ) ) { |
| 3353 |
newManip = new SoPointLightManip; |
| 3354 |
newManip->ref(); |
| 3355 |
} |
| 3356 |
else if ( dataType.isDerivedFrom( spotLightType ) ) { |
| 3357 |
newManip = new SoSpotLightManip; |
| 3358 |
newManip->ref(); |
| 3359 |
// Set dropOffRate non-zero, or it will look like a pointLight. |
| 3360 |
((SoSpotLightManip *)newManip)->dropOffRate = .01; |
| 3361 |
} |
| 3362 |
|
| 3363 |
// get the path from the root to the light node |
| 3364 |
SoSearchAction sa; |
| 3365 |
sa.setNode( data->light ); |
| 3366 |
sa.apply( currentViewer->getSceneGraph() ); |
| 3367 |
SoPath *path = sa.getPath(); |
| 3368 |
// ??? light is probably turned off so we don't |
| 3369 |
// ??? need to print a warning message. Just don't |
| 3370 |
// ??? do anything |
| 3371 |
if (path == NULL) { |
| 3372 |
newManip->unref(); |
| 3373 |
return; |
| 3374 |
} |
| 3375 |
|
| 3376 |
path->ref(); |
| 3377 |
|
| 3378 |
// Set the size for the light manips. |
| 3379 |
if ( !calculatedLightManipSize ) |
| 3380 |
calculateLightManipSize(); |
| 3381 |
|
| 3382 |
data->scale->scaleFactor.setValue( lightManipSize, lightManipSize, |
| 3383 |
lightManipSize ); |
| 3384 |
float invSz = (lightManipSize == 0.0) ? 1.0 : 1.0 / lightManipSize; |
| 3385 |
data->scaleInverse->scaleFactor.setValue( invSz, invSz, invSz ); |
| 3386 |
|
| 3387 |
// Put the manip into the scene. |
| 3388 |
if ( dataType.isDerivedFrom( ptLightType ) ) |
| 3389 |
((SoPointLightManip *)newManip)->replaceNode(path); |
| 3390 |
else if (dataType.isDerivedFrom(dirLightType) ) |
| 3391 |
((SoDirectionalLightManip *)newManip)->replaceNode(path); |
| 3392 |
else if (dataType.isDerivedFrom(spotLightType)) |
| 3393 |
((SoSpotLightManip *)newManip)->replaceNode(path); |
| 3394 |
|
| 3395 |
// Okay, now that we stuck that manip in there, |
| 3396 |
// we better make a note of it... |
| 3397 |
path->unref(); |
| 3398 |
data->light->unref(); |
| 3399 |
data->light = newManip; |
| 3400 |
|
| 3401 |
} |
| 3402 |
} |
| 3403 |
// |
| 3404 |
// detach the manip from the light and remove it from the scene |
| 3405 |
// |
| 3406 |
else { |
| 3407 |
if (forHeadlight) { |
| 3408 |
// detach editor from light |
| 3409 |
if (headlightEditor != NULL) { |
| 3410 |
headlightEditor->detach(); |
| 3411 |
headlightEditor->hide(); |
| 3412 |
} |
| 3413 |
} |
| 3414 |
else if (data->isManip() == TRUE ) { |
| 3415 |
|
| 3416 |
// replace the lightManip node with a regular light node |
| 3417 |
// get the path from the root to the lightManip node |
| 3418 |
SoSearchAction sa; |
| 3419 |
sa.setNode( data->light ); |
| 3420 |
sa.apply( currentViewer->getSceneGraph() ); |
| 3421 |
SoPath *path = sa.getPath(); |
| 3422 |
|
| 3423 |
if (path != NULL ) { |
| 3424 |
path->ref(); |
| 3425 |
|
| 3426 |
SoLight *newLight; |
| 3427 |
|
| 3428 |
if (dataType.isDerivedFrom(ptLightType)) { |
| 3429 |
newLight = new SoPointLight; |
| 3430 |
newLight->ref(); |
| 3431 |
((SoPointLightManip *)data->light)->replaceManip( |
| 3432 |
path, (SoPointLight *)newLight ); |
| 3433 |
} |
| 3434 |
else if (dataType.isDerivedFrom(dirLightType)) { |
| 3435 |
// when removing a directional light manip, |
| 3436 |
// we don't want to lose the translation of the manip. |
| 3437 |
// Since the regular light can't hold this value, |
| 3438 |
// get it from the manip and move it to the translation. |
| 3439 |
|
| 3440 |
transferDirectionalLightLocation(data); |
| 3441 |
|
| 3442 |
newLight = new SoDirectionalLight; |
| 3443 |
newLight->ref(); |
| 3444 |
((SoDirectionalLightManip *)data->light)->replaceManip( |
| 3445 |
path, (SoDirectionalLight *)newLight ); |
| 3446 |
} |
| 3447 |
else if (dataType.isDerivedFrom(spotLightType)) { |
| 3448 |
newLight = new SoSpotLight; |
| 3449 |
newLight->ref(); |
| 3450 |
((SoSpotLightManip *)data->light)->replaceManip( |
| 3451 |
path, (SoSpotLight *)newLight ); |
| 3452 |
} |
| 3453 |
path->unref(); |
| 3454 |
data->light->unref(); |
| 3455 |
data->light = newLight; |
| 3456 |
} |
| 3457 |
} |
| 3458 |
} |
| 3459 |
} |
| 3460 |
|
| 3461 |
//////////////////////////////////////////////////////////////////////// |
| 3462 |
// |
| 3463 |
// Description: |
| 3464 |
// When removing or writing directional light manip, |
| 3465 |
// we don't want to lose the translation of the manip. |
| 3466 |
// Since the regular light can't hold this value, |
| 3467 |
// get it from the manip and move it to the translation. |
| 3468 |
// |
| 3469 |
// Use: private |
| 3470 |
// |
| 3471 |
void |
| 3472 |
SoSceneViewer::transferDirectionalLightLocation( SvLightData *data ) |
| 3473 |
// |
| 3474 |
//////////////////////////////////////////////////////////////////////// |
| 3475 |
{ |
| 3476 |
if ( !data->light ) |
| 3477 |
return; |
| 3478 |
|
| 3479 |
if ( !data->light->isOfType(SoDirectionalLightManip::getClassTypeId() )) |
| 3480 |
return; |
| 3481 |
|
| 3482 |
// when removing a directional light manip, |
| 3483 |
// we don't want to lose the translation of the manip. |
| 3484 |
// Since the regular light can't hold this value, |
| 3485 |
// get it from the manip and move it to the translation. |
| 3486 |
|
| 3487 |
SoDirectionalLightManip *manip |
| 3488 |
= (SoDirectionalLightManip *) data->light; |
| 3489 |
SoDirectionalLightDragger *dragger |
| 3490 |
= (SoDirectionalLightDragger *) manip->getDragger(); |
| 3491 |
|
| 3492 |
SbVec3f lightTrans(0,0,0); |
| 3493 |
|
| 3494 |
if (dragger) |
| 3495 |
lightTrans += dragger->translation.getValue(); |
| 3496 |
|
| 3497 |
SbVec3f scl = data->scale->scaleFactor.getValue(); |
| 3498 |
lightTrans *= scl[0]; |
| 3499 |
|
| 3500 |
lightTrans += data->translation->translation.getValue(); |
| 3501 |
data->translation->translation = lightTrans; |
| 3502 |
data->translationInverse->translation = -lightTrans; |
| 3503 |
|
| 3504 |
// Now zero out the translation in the dragger itself: |
| 3505 |
dragger->translation = SbVec3f(0,0,0); |
| 3506 |
} |
| 3507 |
|
| 3508 |
//////////////////////////////////////////////////////////////////////// |
| 3509 |
// |
| 3510 |
// Description: |
| 3511 |
// Called by "Edit Color" light menu entry. |
| 3512 |
// |
| 3513 |
// Use: static private |
| 3514 |
// |
| 3515 |
void |
| 3516 |
SoSceneViewer::editLightColorCB(Widget, SvLightData *data, void *) |
| 3517 |
// |
| 3518 |
//////////////////////////////////////////////////////////////////////// |
| 3519 |
{ |
| 3520 |
// create the color editor with the right title |
| 3521 |
if (data->colorEditor == NULL) { |
| 3522 |
data->colorEditor = new MyColorEditor; |
| 3523 |
char str[50]; |
| 3524 |
strcpy(str, data->name); |
| 3525 |
strcat(str, " Light Color"); |
| 3526 |
data->colorEditor->setTitle(str); |
| 3527 |
} |
| 3528 |
|
| 3529 |
if ( !data->colorEditor->isAttached() ) { |
| 3530 |
// if this is for the headlight, make sure we have the |
| 3531 |
// current viewer headlight |
| 3532 |
if (data == data->classPt->headlightData) { |
| 3533 |
SoLight *l = data->classPt->getHeadlight(); |
| 3534 |
l->ref(); |
| 3535 |
if (data->light) |
| 3536 |
data->light->unref(); |
| 3537 |
data->light = l; |
| 3538 |
} |
| 3539 |
|
| 3540 |
// normalize the light intensity |
| 3541 |
SbColor col; |
| 3542 |
col = data->light->color.getValue(); |
| 3543 |
col *= data->light->intensity.getValue(); |
| 3544 |
data->light->intensity.setValue( 1.0 ); |
| 3545 |
data->light->color.setValue( col ); |
| 3546 |
|
| 3547 |
data->colorEditor->attach( &data->light->color, data->light ); |
| 3548 |
} |
| 3549 |
|
| 3550 |
data->colorEditor->show(); |
| 3551 |
} |
| 3552 |
|
| 3553 |
//////////////////////////////////////////////////////////////////////// |
| 3554 |
// |
| 3555 |
// Description: |
| 3556 |
// remove button menu entry callback. |
| 3557 |
// |
| 3558 |
// Use: static private |
| 3559 |
// |
| 3560 |
void |
| 3561 |
SoSceneViewer::removeLightCB(Widget, SvLightData *data, void *) |
| 3562 |
// |
| 3563 |
//////////////////////////////////////////////////////////////////////// |
| 3564 |
{ |
| 3565 |
data->classPt->removeLight(data); |
| 3566 |
} |
| 3567 |
|
| 3568 |
//////////////////////////////////////////////////////////////////////// |
| 3569 |
// |
| 3570 |
// Description: |
| 3571 |
// removes the light from the scene, and removes the light data |
| 3572 |
// and pulldown menu entry. |
| 3573 |
// |
| 3574 |
// Use: private |
| 3575 |
// |
| 3576 |
void |
| 3577 |
SoSceneViewer::removeLight(SvLightData *data) |
| 3578 |
// |
| 3579 |
//////////////////////////////////////////////////////////////////////// |
| 3580 |
{ |
| 3581 |
// delete the color editor and manip |
| 3582 |
delete data->colorEditor; |
| 3583 |
|
| 3584 |
// note: deleted code that dealt with the manip. |
| 3585 |
// Since the light and the manip are one and the same now. |
| 3586 |
// unrefing the light also removes the manip |
| 3587 |
|
| 3588 |
// unref the light (or manip) for this entry |
| 3589 |
if (data->light) |
| 3590 |
data->light->unref(); |
| 3591 |
|
| 3592 |
// remove the light from the scene |
| 3593 |
lightGroup->removeChild( data->lightSwitch ); |
| 3594 |
|
| 3595 |
// nuke the menu entry |
| 3596 |
if (data->cascadeWidget != NULL) |
| 3597 |
XtDestroyWidget( data->cascadeWidget ); |
| 3598 |
|
| 3599 |
// remove from list and delete the struct |
| 3600 |
lightDataList.remove( lightDataList.find(data) ); |
| 3601 |
delete data; |
| 3602 |
} |
| 3603 |
|
| 3604 |
//////////////////////////////////////////////////////////////////////// |
| 3605 |
// |
| 3606 |
// Description: |
| 3607 |
// Calculate the size for the light manips. |
| 3608 |
// Called when the first lightmanip is created. |
| 3609 |
// Also called when a scene is read or imported, assuming lights |
| 3610 |
// have already been created. |
| 3611 |
// |
| 3612 |
// Use: private |
| 3613 |
// |
| 3614 |
void |
| 3615 |
SoSceneViewer::calculateLightManipSize() |
| 3616 |
// |
| 3617 |
//////////////////////////////////////////////////////////////////////// |
| 3618 |
{ |
| 3619 |
// Set the size for the light manips. |
| 3620 |
// Calculate a good size, based on the size of the scene. |
| 3621 |
// Once this size is determined, use it for all other light manips. |
| 3622 |
// (We need to save the value because the scene size will change |
| 3623 |
// over time, but we want all light manips to be the same size. |
| 3624 |
|
| 3625 |
// This routine will also get called again if a new scene is read in. |
| 3626 |
|
| 3627 |
// Run a bounding box action on the scene... |
| 3628 |
SoGetBoundingBoxAction ba(currentViewer->getViewportRegion()); |
| 3629 |
ba.apply( currentViewer->getSceneGraph() ); |
| 3630 |
SbBox3f sceneBox = ba.getBoundingBox(); |
| 3631 |
SbVec3f size; |
| 3632 |
if (sceneBox.isEmpty()) { |
| 3633 |
// Oh, just take a guess. Default scene would be 2x2x2 |
| 3634 |
size.setValue(2,2,2); |
| 3635 |
} |
| 3636 |
else |
| 3637 |
size = sceneBox.getMax() - sceneBox.getMin(); |
| 3638 |
//XXX pick a good size! |
| 3639 |
lightManipSize = .025 * size.length(); |
| 3640 |
|
| 3641 |
// Visit every light entry and set the scale and scaleInverse |
| 3642 |
// nodes to have the correct lightManipSize. |
| 3643 |
for (int i = 0; i < lightDataList.getLength(); i++ ) { |
| 3644 |
|
| 3645 |
SvLightData *data = (SvLightData *) lightDataList[i]; |
| 3646 |
|
| 3647 |
if (data->scale != NULL) { |
| 3648 |
if (data->scale->scaleFactor.getValue()[0] != lightManipSize) |
| 3649 |
data->scale->scaleFactor.setValue( lightManipSize, |
| 3650 |
lightManipSize, lightManipSize ); |
| 3651 |
} |
| 3652 |
if (data->scaleInverse != NULL) { |
| 3653 |
float invSz = (lightManipSize == 0.0) ? 1.0 : 1.0 / lightManipSize; |
| 3654 |
if (data->scaleInverse->scaleFactor.getValue()[0] != invSz) |
| 3655 |
data->scaleInverse->scaleFactor.setValue( invSz, invSz, invSz ); |
| 3656 |
} |
| 3657 |
} |
| 3658 |
|
| 3659 |
calculatedLightManipSize = TRUE; |
| 3660 |
} |
| 3661 |
|
| 3662 |
|
| 3663 |
//////////////////////////////////////////////////////////////////////// |
| 3664 |
// |
| 3665 |
// Description: |
| 3666 |
// Called whenever a light submenu is mapped on screen (update |
| 3667 |
// the toggles) |
| 3668 |
// |
| 3669 |
// Use: static private |
| 3670 |
// |
| 3671 |
void |
| 3672 |
SoSceneViewer::lightSubmenuDisplay(Widget, SvLightData *data, void *) |
| 3673 |
// |
| 3674 |
//////////////////////////////////////////////////////////////////////// |
| 3675 |
{ |
| 3676 |
SoSceneViewer *sv = data->classPt; |
| 3677 |
SbBool set; |
| 3678 |
|
| 3679 |
// |
| 3680 |
// update the "on/off" toggle |
| 3681 |
// |
| 3682 |
if (data == sv->headlightData) |
| 3683 |
set = sv->isHeadlight(); |
| 3684 |
else |
| 3685 |
set = IS_LIGHT_ON(data->lightSwitch); |
| 3686 |
if (set) |
| 3687 |
TOGGLE_ON(data->onOffWidget); |
| 3688 |
else |
| 3689 |
TOGGLE_OFF(data->onOffWidget); |
| 3690 |
|
| 3691 |
// |
| 3692 |
// update the "Edit" toggle |
| 3693 |
// |
| 3694 |
if (data == sv->headlightData) |
| 3695 |
set = (sv->headlightEditor != NULL && sv->headlightEditor->isVisible()); |
| 3696 |
else |
| 3697 |
set = (data->isManip() == TRUE ); |
| 3698 |
if (set) |
| 3699 |
TOGGLE_ON(data->iconWidget); |
| 3700 |
else |
| 3701 |
TOGGLE_OFF(data->iconWidget); |
| 3702 |
} |
| 3703 |
|
| 3704 |
//////////////////////////////////////////////////////////////////////// |
| 3705 |
// |
| 3706 |
// Description: |
| 3707 |
// Called after a paste operation has completed. |
| 3708 |
// |
| 3709 |
// Use: static, private |
| 3710 |
// |
| 3711 |
void |
| 3712 |
SoSceneViewer::pasteDoneCB(void *userData, SoPathList *pathList) |
| 3713 |
// |
| 3714 |
//////////////////////////////////////////////////////////////////////// |
| 3715 |
{ |
| 3716 |
SoSceneViewer *sv = (SoSceneViewer *) userData; |
| 3717 |
sv->pasteDone(pathList); |
| 3718 |
} |
| 3719 |
|
| 3720 |
//////////////////////////////////////////////////////////////////////// |
| 3721 |
// |
| 3722 |
// Description: |
| 3723 |
// Called after a drop operation has completed. |
| 3724 |
// |
| 3725 |
// Use: static, private |
| 3726 |
// |
| 3727 |
SbBool |
| 3728 |
SoSceneViewer::iconDropCB(void *userData, const char *filename) |
| 3729 |
// |
| 3730 |
//////////////////////////////////////////////////////////////////////// |
| 3731 |
{ |
| 3732 |
SoSceneViewer *sv = (SoSceneViewer *) userData; |
| 3733 |
sv->fileMode = SV_FILE_IMPORT; |
| 3734 |
return sv->doFileIO(filename); |
| 3735 |
} |
| 3736 |
|
| 3737 |
//////////////////////////////////////////////////////////////////////// |
| 3738 |
// |
| 3739 |
// Description: |
| 3740 |
// Called during a drop operation of INVENTOR objects. |
| 3741 |
// |
| 3742 |
// Use: static, private |
| 3743 |
// |
| 3744 |
SbBool |
| 3745 |
SoSceneViewer::objDropCB( |
| 3746 |
void *userData, |
| 3747 |
Atom target, |
| 3748 |
void *data, uint32_t numBytes) |
| 3749 |
// |
| 3750 |
//////////////////////////////////////////////////////////////////////// |
| 3751 |
{ |
| 3752 |
SoSceneViewer *sv = (SoSceneViewer *) userData; |
| 3753 |
SoPathList *pathList = NULL; |
| 3754 |
SbBool success = FALSE; |
| 3755 |
Display *d = SoXt::getDisplay(); |
| 3756 |
|
| 3757 |
if (data != NULL) { |
| 3758 |
if (target == _ATOM_(d, "INVENTOR_2_1") || |
| 3759 |
target == _ATOM_(d, "VRML_1_0") || |
| 3760 |
target == _ATOM_(d, "INVENTOR") || |
| 3761 |
target == _ATOM_(d, "INVENTOR_2_0")) { |
| 3762 |
|
| 3763 |
pathList = SoByteStream::unconvert(data, numBytes); |
| 3764 |
if (pathList != NULL && pathList->getLength() > 0) { |
| 3765 |
sv->pasteDone(pathList); |
| 3766 |
success = TRUE; |
| 3767 |
// pathList will be deleted by pasteDone... |
| 3768 |
} |
| 3769 |
} |
| 3770 |
} |
| 3771 |
|
| 3772 |
return success; |
| 3773 |
} |
| 3774 |
|
| 3775 |
//////////////////////////////////////////////////////////////////////// |
| 3776 |
// |
| 3777 |
// Description: |
| 3778 |
// Called after a paste operation has completed, this adds the |
| 3779 |
// pasted data to our scene graph. |
| 3780 |
// |
| 3781 |
// Use: private |
| 3782 |
// |
| 3783 |
void |
| 3784 |
SoSceneViewer::pasteDone(SoPathList *pathList) |
| 3785 |
// |
| 3786 |
//////////////////////////////////////////////////////////////////////// |
| 3787 |
{ |
| 3788 |
if (pathList->getLength() <= 0) |
| 3789 |
return; |
| 3790 |
|
| 3791 |
// If this is the only obj, we will view all |
| 3792 |
SbBool doViewAll = (selection->getNumChildren() == 0); |
| 3793 |
|
| 3794 |
// first, detach manips from all selected objects |
| 3795 |
detachManipFromAll(); |
| 3796 |
|
| 3797 |
// now, turn off the sel/desel callbacks. |
| 3798 |
// we'll turn them on again after we've adjusted the selection |
| 3799 |
selection->removeSelectionCallback( SoSceneViewer::selectionCallback, this ); |
| 3800 |
selection->removeDeselectionCallback( SoSceneViewer::deselectionCallback, this ); |
| 3801 |
|
| 3802 |
// now deselect all, and build up a selection from the pasted paths |
| 3803 |
selection->deselectAll(); |
| 3804 |
|
| 3805 |
// Add every path in the path list as a child under selection. |
| 3806 |
// Then select each of these paths. |
| 3807 |
for (int i = 0; i < pathList->getLength(); i++) { |
| 3808 |
|
| 3809 |
// if the head of the path is a selection node, then don't |
| 3810 |
// paste the head - rather, paste all of its children. |
| 3811 |
// this makes sure we don't have more than 1 selection node. |
| 3812 |
// While we're adding the paths as children, select each path. |
| 3813 |
SoPath *p = (*pathList)[i]; |
| 3814 |
SoNode *head = p->getHead(); |
| 3815 |
SoPath *selpath; |
| 3816 |
if (head->isOfType(SoSelection::getClassTypeId())) { |
| 3817 |
for (int j = 0; j < ((SoSelection *)head)->getNumChildren(); j++) { |
| 3818 |
selection->addChild(((SoSelection *)head)->getChild(j)); |
| 3819 |
|
| 3820 |
// create a path from selection to this child |
| 3821 |
// and select the path. |
| 3822 |
selpath = new SoPath(selection); |
| 3823 |
selpath->append(selection->getNumChildren() - 1); |
| 3824 |
selection->select(selpath); |
| 3825 |
} |
| 3826 |
} |
| 3827 |
else { |
| 3828 |
// not a selection node, so just add it. |
| 3829 |
selection->addChild(p->getHead()); |
| 3830 |
|
| 3831 |
// create a path from selection to this child |
| 3832 |
// and select the path. |
| 3833 |
selpath = new SoPath(selection); |
| 3834 |
selpath->append(selection->getNumChildren() - 1); |
| 3835 |
selection->select(selpath); |
| 3836 |
} |
| 3837 |
} |
| 3838 |
|
| 3839 |
// now add manips to all the selected objects |
| 3840 |
attachManipToAll(curManip); |
| 3841 |
|
| 3842 |
// and turn the sel/desel callbacks back on |
| 3843 |
selection->addSelectionCallback( SoSceneViewer::selectionCallback, this ); |
| 3844 |
selection->addDeselectionCallback( SoSceneViewer::deselectionCallback, this ); |
| 3845 |
|
| 3846 |
// enable/disable keyboard shortcuts |
| 3847 |
updateCommandAvailability(); |
| 3848 |
|
| 3849 |
// View all? |
| 3850 |
if (doViewAll) |
| 3851 |
viewAll(); |
| 3852 |
|
| 3853 |
delete pathList; |
| 3854 |
} |
| 3855 |
|
| 3856 |
//////////////////////////////////////////////////////////////////////// |
| 3857 |
// |
| 3858 |
// Description: |
| 3859 |
// Build routine for SceneViewer. This creates all of the X widgets |
| 3860 |
// |
| 3861 |
// Use: public, virtual |
| 3862 |
|
| 3863 |
Widget |
| 3864 |
SoSceneViewer::buildWidget(Widget parent) |
| 3865 |
// |
| 3866 |
//////////////////////////////////////////////////////////////////////// |
| 3867 |
{ |
| 3868 |
int n; |
| 3869 |
Arg args[10]; |
| 3870 |
|
| 3871 |
// create a form to hold everything together |
| 3872 |
SbVec2s size = getSize(); |
| 3873 |
n = 0; |
| 3874 |
if (size[0] != 0 && size[1] != 0) { |
| 3875 |
XtSetArg(args[n], XtNwidth, size[0]); n++; |
| 3876 |
XtSetArg(args[n], XtNheight, size[1]); n++; |
| 3877 |
} |
| 3878 |
mgrWidget = XtCreateWidget(getWidgetName(), xmFormWidgetClass, parent, args, n); |
| 3879 |
registerWidget(mgrWidget); |
| 3880 |
|
| 3881 |
// create the topbar menu |
| 3882 |
if (showMenuFlag) |
| 3883 |
buildAndLayoutMenu(mgrWidget); |
| 3884 |
|
| 3885 |
// build and layout the current viewer |
| 3886 |
whichViewer = SV_VWR_EXAMINER; |
| 3887 |
setTitle("SceneViewer (Examiner)"); |
| 3888 |
currentViewer = viewerList[whichViewer] = new SoXtExaminerViewer(mgrWidget); |
| 3889 |
currentViewer->setSceneGraph(sceneGraph); |
| 3890 |
currentViewer->setGLRenderAction(highlightRA); |
| 3891 |
currentViewer->redrawOnSelectionChange(selection); |
| 3892 |
|
| 3893 |
setOverlayLogo(currentViewer); |
| 3894 |
|
| 3895 |
// Fog |
| 3896 |
environment->fogColor.setValue( currentViewer->getBackgroundColor() ); |
| 3897 |
|
| 3898 |
// since we created the camera, do a view all and save this |
| 3899 |
// as the starting point (don't want default camera values). |
| 3900 |
viewAll(); |
| 3901 |
saveHomePosition(); |
| 3902 |
|
| 3903 |
|
| 3904 |
buildAndLayoutViewer(currentViewer); |
| 3905 |
|
| 3906 |
// manage those children |
| 3907 |
if (showMenuFlag) |
| 3908 |
XtManageChild(menuWidget); |
| 3909 |
currentViewer->show(); |
| 3910 |
|
| 3911 |
// clipboard is for copy/paste of 3d data. |
| 3912 |
//??? what if this SceneViewer had its widget destroyed and rebuilt? |
| 3913 |
//??? we need to destroy the clipboards when that happens. |
| 3914 |
clipboard = new SoXtClipboard(mgrWidget); |
| 3915 |
|
| 3916 |
MyDropSite::registerCallback( |
| 3917 |
mgrWidget, iconDropCB, objDropCB, this); |
| 3918 |
|
| 3919 |
return mgrWidget; |
| 3920 |
} |
| 3921 |
|
| 3922 |
//////////////////////////////////////////////////////////////////////// |
| 3923 |
// |
| 3924 |
// Description: |
| 3925 |
// Builds and layout the given viewer. |
| 3926 |
// |
| 3927 |
// Use: private |
| 3928 |
void |
| 3929 |
SoSceneViewer::buildAndLayoutViewer(SoXtFullViewer *vwr) |
| 3930 |
// |
| 3931 |
//////////////////////////////////////////////////////////////////////// |
| 3932 |
{ |
| 3933 |
if (mgrWidget == NULL) |
| 3934 |
return; |
| 3935 |
|
| 3936 |
// build the viewer if necessary |
| 3937 |
if (vwr->getWidget() == NULL) { |
| 3938 |
fprintf(stderr, "ERROR - need to create the viewer widget before it can be layed out\n"); |
| 3939 |
return; |
| 3940 |
} |
| 3941 |
|
| 3942 |
// layout the viewer to be attached under the topbar menu |
| 3943 |
// (if the pulldown menu is shown) |
| 3944 |
Arg args[12]; |
| 3945 |
int n = 0; |
| 3946 |
if ( showMenuFlag ) { |
| 3947 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; |
| 3948 |
XtSetArg(args[n], XmNtopWidget, menuWidget); n++; |
| 3949 |
} |
| 3950 |
else { |
| 3951 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 3952 |
} |
| 3953 |
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; |
| 3954 |
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; |
| 3955 |
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; |
| 3956 |
XtSetValues(vwr->getWidget(), args, n); |
| 3957 |
} |
| 3958 |
|
| 3959 |
//////////////////////////////////////////////////////////////////////// |
| 3960 |
// |
| 3961 |
// Description: |
| 3962 |
// Create topbar menu. Invalid buttons are rendered gray. |
| 3963 |
// Each button's callback include a structure with the ID |
| 3964 |
// of the button and a pointer to the SoSceneViewer that created |
| 3965 |
// it. |
| 3966 |
// |
| 3967 |
// Use: private |
| 3968 |
// |
| 3969 |
void |
| 3970 |
SoSceneViewer::buildAndLayoutMenu(Widget parent) |
| 3971 |
// |
| 3972 |
//////////////////////////////////////////////////////////////////////// |
| 3973 |
{ |
| 3974 |
if (menuWidget != NULL) |
| 3975 |
return; |
| 3976 |
|
| 3977 |
Arg args[8]; |
| 3978 |
int i, j, n, id; |
| 3979 |
WidgetList buttons, subButtons; |
| 3980 |
int itemCount, subItemCount; |
| 3981 |
WidgetClass widgetClass; |
| 3982 |
String callbackReason; |
| 3983 |
XmString xmstr; |
| 3984 |
|
| 3985 |
// create topbar menu |
| 3986 |
menuWidget = XmCreateMenuBar(parent, "menuBar", NULL, 0); |
| 3987 |
|
| 3988 |
Arg popupargs[4]; |
| 3989 |
int popupn = 0; |
| 3990 |
#ifdef MENUS_IN_POPUP |
| 3991 |
Widget shell = SoXt::getShellWidget(mgrWidget); |
| 3992 |
SoXt::getPopupArgs(XtDisplay(menuWidget), SCREEN(shell), popupargs, &popupn); |
| 3993 |
#endif |
| 3994 |
|
| 3995 |
itemCount = XtNumber(pulldownData); |
| 3996 |
buttons = (WidgetList) XtMalloc(itemCount * sizeof(Widget)); |
| 3997 |
|
| 3998 |
for (i = 0; i < itemCount; i++) { |
| 3999 |
// Make Topbar menu button |
| 4000 |
Widget subMenu = XmCreatePulldownMenu(menuWidget, "subMenu", popupargs, popupn); |
| 4001 |
|
| 4002 |
#ifdef MENUS_IN_POPUP |
| 4003 |
// register callbacks to load/unload the pulldown colormap when the |
| 4004 |
// pulldown menu is posted. |
| 4005 |
SoXt::registerColormapLoad(subMenu, shell); |
| 4006 |
#endif |
| 4007 |
|
| 4008 |
id = pulldownData[i].id; |
| 4009 |
menuItems[id].widget = subMenu; |
| 4010 |
XtAddCallback(subMenu, XmNmapCallback, |
| 4011 |
(XtCallbackProc) SoSceneViewer::menuDisplay, |
| 4012 |
(XtPointer) &menuItems[id]); |
| 4013 |
|
| 4014 |
XtSetArg(args[0], XmNsubMenuId, subMenu); |
| 4015 |
buttons[i] = XtCreateWidget(pulldownData[i].name, |
| 4016 |
xmCascadeButtonGadgetClass, menuWidget, args, 1); |
| 4017 |
|
| 4018 |
// Make subMenu buttons |
| 4019 |
subItemCount = pulldownData[i].subItemCount; |
| 4020 |
subButtons = (WidgetList) XtMalloc(subItemCount * sizeof(Widget)); |
| 4021 |
|
| 4022 |
for (j = 0; j < subItemCount; j++) { |
| 4023 |
if (pulldownData[i].subMenu[j].buttonType == SV_SEPARATOR) |
| 4024 |
subButtons[j] = XtCreateWidget(NULL, xmSeparatorGadgetClass, |
| 4025 |
subMenu, NULL, 0); |
| 4026 |
else { |
| 4027 |
switch (pulldownData[i].subMenu[j].buttonType) { |
| 4028 |
case SV_PUSH_BUTTON: |
| 4029 |
widgetClass = xmPushButtonGadgetClass; |
| 4030 |
callbackReason = XmNactivateCallback; |
| 4031 |
n = 0; |
| 4032 |
break; |
| 4033 |
case SV_TOGGLE_BUTTON: |
| 4034 |
widgetClass = xmToggleButtonGadgetClass; |
| 4035 |
callbackReason = XmNvalueChangedCallback; |
| 4036 |
n = 0; |
| 4037 |
break; |
| 4038 |
case SV_RADIO_BUTTON: |
| 4039 |
widgetClass = xmToggleButtonGadgetClass; |
| 4040 |
callbackReason = XmNvalueChangedCallback; |
| 4041 |
XtSetArg(args[0], XmNindicatorType, XmONE_OF_MANY); |
| 4042 |
n = 1; |
| 4043 |
break; |
| 4044 |
default: |
| 4045 |
fprintf(stderr, "SceneViewer INTERNAL ERROR: bad buttonType\n"); |
| 4046 |
break; |
| 4047 |
} |
| 4048 |
|
| 4049 |
// check for keyboard accelerator |
| 4050 |
char *accel = pulldownData[i].subMenu[j].accelerator; |
| 4051 |
char *accelText = pulldownData[i].subMenu[j].accelText; |
| 4052 |
xmstr = NULL; |
| 4053 |
if (accel != NULL) { |
| 4054 |
XtSetArg(args[n], XmNaccelerator, accel); n++; |
| 4055 |
|
| 4056 |
if (accelText != NULL) { |
| 4057 |
xmstr = XmStringCreate(accelText, |
| 4058 |
XmSTRING_DEFAULT_CHARSET); |
| 4059 |
XtSetArg(args[n], XmNacceleratorText, xmstr); n++; |
| 4060 |
} |
| 4061 |
} |
| 4062 |
|
| 4063 |
subButtons[j] = XtCreateWidget( |
| 4064 |
pulldownData[i].subMenu[j].name, |
| 4065 |
widgetClass, |
| 4066 |
subMenu, args, n); |
| 4067 |
|
| 4068 |
if (xmstr != NULL) |
| 4069 |
XmStringFree(xmstr); |
| 4070 |
id = pulldownData[i].subMenu[j].id; |
| 4071 |
menuItems[id].widget = subButtons[j]; |
| 4072 |
XtAddCallback(subButtons[j], callbackReason, |
| 4073 |
(XtCallbackProc)SoSceneViewer::processTopbarEvent, |
| 4074 |
(XtPointer) &menuItems[id]); |
| 4075 |
} |
| 4076 |
} |
| 4077 |
XtManageChildren(subButtons, subItemCount); |
| 4078 |
XtFree((char *)subButtons); |
| 4079 |
} |
| 4080 |
XtManageChildren(buttons, itemCount); |
| 4081 |
XtFree((char *)buttons); |
| 4082 |
|
| 4083 |
// |
| 4084 |
// layout the menu bar |
| 4085 |
// |
| 4086 |
n = 0; |
| 4087 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 4088 |
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; |
| 4089 |
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; |
| 4090 |
XtSetValues(menuWidget, args, n); |
| 4091 |
|
| 4092 |
// |
| 4093 |
// Add the light items which are dynamically created |
| 4094 |
// |
| 4095 |
// first add the headlight |
| 4096 |
addLightMenuEntry(headlightData); |
| 4097 |
XtUnmanageChild(headlightData->removeWidget); |
| 4098 |
XtUnmanageChild(headlightData->editColorWidget); |
| 4099 |
xmstr = XmStringCreate( Light.editlight, XmSTRING_DEFAULT_CHARSET); |
| 4100 |
XtSetArg(args[0], XmNlabelString, xmstr); |
| 4101 |
XtSetValues(headlightData->iconWidget, args, 1); |
| 4102 |
XmStringFree(xmstr); |
| 4103 |
|
| 4104 |
// now the regular lights |
| 4105 |
for (i=0; i < lightDataList.getLength(); i++) |
| 4106 |
addLightMenuEntry( (SvLightData *) lightDataList[i] ); |
| 4107 |
} |
| 4108 |
|
| 4109 |
//////////////////////////////////////////////////////////////////////// |
| 4110 |
// |
| 4111 |
// Description: |
| 4112 |
// Show/hide the pulldown menu bar. |
| 4113 |
// |
| 4114 |
// Use: public |
| 4115 |
void |
| 4116 |
SoSceneViewer::showMenu(SbBool flag) |
| 4117 |
// |
| 4118 |
//////////////////////////////////////////////////////////////////////// |
| 4119 |
{ |
| 4120 |
if (showMenuFlag == flag || mgrWidget == NULL) { |
| 4121 |
showMenuFlag = flag; |
| 4122 |
return; |
| 4123 |
} |
| 4124 |
|
| 4125 |
showMenuFlag = flag; |
| 4126 |
|
| 4127 |
if ( showMenuFlag ) { |
| 4128 |
|
| 4129 |
// turn topbar menu on |
| 4130 |
if (menuWidget == NULL) |
| 4131 |
buildAndLayoutMenu(mgrWidget); |
| 4132 |
XtManageChild(menuWidget); |
| 4133 |
|
| 4134 |
// attach viewer to bottom of menu |
| 4135 |
Arg args[2]; |
| 4136 |
int n = 0; |
| 4137 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; |
| 4138 |
XtSetArg(args[n], XmNtopWidget, menuWidget); n++; |
| 4139 |
XtSetValues(currentViewer->getWidget(), args, n); |
| 4140 |
} |
| 4141 |
else { |
| 4142 |
// attach viewer to form |
| 4143 |
Arg args[2]; |
| 4144 |
int n = 0; |
| 4145 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 4146 |
XtSetValues(currentViewer->getWidget(), args, n); |
| 4147 |
|
| 4148 |
// turn topbar menu off |
| 4149 |
if (menuWidget != NULL) |
| 4150 |
XtUnmanageChild(menuWidget); |
| 4151 |
} |
| 4152 |
} |
| 4153 |
|
| 4154 |
//////////////////////////////////////////////////////////////////////// |
| 4155 |
// |
| 4156 |
// Manage the changes in the selected node(s) |
| 4157 |
// |
| 4158 |
// Use: private, static |
| 4159 |
// |
| 4160 |
SoPath * |
| 4161 |
SoSceneViewer::pickFilterCB(void *userData, const SoPickedPoint *pick) |
| 4162 |
// |
| 4163 |
//////////////////////////////////////////////////////////////////////// |
| 4164 |
{ |
| 4165 |
SoSceneViewer *sv = (SoSceneViewer *) userData; |
| 4166 |
SoPath *filteredPath = NULL; |
| 4167 |
|
| 4168 |
// If there are any transform manips along the path, check if they |
| 4169 |
// belong to our personal set of manips. |
| 4170 |
// If so, change the path so it points to the object the manip |
| 4171 |
// is attached to. |
| 4172 |
SoFullPath *fullP = (SoFullPath *) pick->getPath(); |
| 4173 |
SoNode *n; |
| 4174 |
for (int i = 0; i < fullP->getLength(); i++ ) { |
| 4175 |
n = fullP->getNode(i); |
| 4176 |
if (n->isOfType(SoTransformManip::getClassTypeId())) { |
| 4177 |
int which = sv->maniplist->find((SoTransformManip *) n); |
| 4178 |
if (which != -1) { |
| 4179 |
filteredPath = sv->maniplist->getSelectionPath(which); |
| 4180 |
return filteredPath; |
| 4181 |
} |
| 4182 |
} |
| 4183 |
} |
| 4184 |
|
| 4185 |
// If we didn't pick one of our manipulators, then return the pickPath |
| 4186 |
filteredPath = pick->getPath(); |
| 4187 |
return filteredPath; |
| 4188 |
} |
| 4189 |
|
| 4190 |
//////////////////////////////////////////////////////////////////////// |
| 4191 |
// |
| 4192 |
// Manage the changes in the selected node(s) |
| 4193 |
// |
| 4194 |
// Use: private, static |
| 4195 |
// |
| 4196 |
void |
| 4197 |
SoSceneViewer::deselectionCallback( void *userData, // my data |
| 4198 |
SoPath *deselectedPath ) // object |
| 4199 |
// |
| 4200 |
//////////////////////////////////////////////////////////////////////// |
| 4201 |
{ |
| 4202 |
SoSceneViewer *sv = (SoSceneViewer *) userData; |
| 4203 |
|
| 4204 |
// remove the manip |
| 4205 |
sv->detachManip( deselectedPath ); |
| 4206 |
|
| 4207 |
// Remove editors |
| 4208 |
if (sv->materialEditor) |
| 4209 |
sv->materialEditor->detach(); |
| 4210 |
|
| 4211 |
if (sv->colorEditor) |
| 4212 |
sv->colorEditor->detach(); |
| 4213 |
|
| 4214 |
if (sv->transformSliderSet) |
| 4215 |
sv->transformSliderSet->setNode( NULL ); |
| 4216 |
|
| 4217 |
// enable/disable cmd key shortcuts and menu items |
| 4218 |
sv->updateCommandAvailability(); |
| 4219 |
} |
| 4220 |
|
| 4221 |
//////////////////////////////////////////////////////////////////////// |
| 4222 |
// |
| 4223 |
// Manage the changes in the selected node(s) |
| 4224 |
// |
| 4225 |
// Use: private, static |
| 4226 |
// |
| 4227 |
void |
| 4228 |
SoSceneViewer::selectionCallback( void *userData, // my data |
| 4229 |
SoPath *selectedPath ) // object |
| 4230 |
// |
| 4231 |
//////////////////////////////////////////////////////////////////////// |
| 4232 |
{ |
| 4233 |
SoSceneViewer *sv = (SoSceneViewer *) userData; |
| 4234 |
|
| 4235 |
// attach the manip |
| 4236 |
sv->attachManip( sv->curManip, selectedPath ); |
| 4237 |
|
| 4238 |
// |
| 4239 |
// If active, attach editors to new selection. |
| 4240 |
// |
| 4241 |
SoMaterial *mtl = NULL; |
| 4242 |
if ( sv->materialEditor && sv->materialEditor->isVisible()) { |
| 4243 |
mtl = sv->findMaterialForAttach(selectedPath); |
| 4244 |
sv->materialEditor->attach(mtl); |
| 4245 |
} |
| 4246 |
|
| 4247 |
if (sv->colorEditor && sv->colorEditor->isVisible()) { |
| 4248 |
if (mtl == NULL) |
| 4249 |
mtl = sv->findMaterialForAttach(selectedPath); |
| 4250 |
sv->colorEditor->attach(&(mtl->diffuseColor), 0, mtl); |
| 4251 |
} |
| 4252 |
|
| 4253 |
if ( sv->transformSliderSet && sv->transformSliderSet->isVisible() ) { |
| 4254 |
SoPath *editTransformPath; |
| 4255 |
editTransformPath = sv->findTransformForAttach( selectedPath ); |
| 4256 |
if ( editTransformPath == NULL ) { |
| 4257 |
sv->transformSliderSet->setNode( NULL ); |
| 4258 |
} |
| 4259 |
else { |
| 4260 |
editTransformPath->ref(); |
| 4261 |
sv->transformSliderSet->setNode(((SoFullPath *)editTransformPath)->getTail() ); |
| 4262 |
editTransformPath->unref(); |
| 4263 |
} |
| 4264 |
} |
| 4265 |
|
| 4266 |
// enable/disable cmd key shortcuts and menu items |
| 4267 |
sv->updateCommandAvailability(); |
| 4268 |
} |
| 4269 |
|
| 4270 |
//////////////////////////////////////////////////////////////////////// |
| 4271 |
// |
| 4272 |
// Remove selected objects from the scene graph. |
| 4273 |
// In this demo, we don't really know how the graphs are set up, |
| 4274 |
// so act conservatively, and simply remove the node which is the |
| 4275 |
// tail of the path from its parent. Note if the node is instanced, |
| 4276 |
// all instances will be destroyed. Then travel up the path to a |
| 4277 |
// parent separator. If there are no other shapes under the separator, |
| 4278 |
// destroy it too. |
| 4279 |
// |
| 4280 |
// Other applications might delete selected objects a different way, |
| 4281 |
// depending on how the data is organized in the scene graph. |
| 4282 |
// |
| 4283 |
// Use: protected |
| 4284 |
// |
| 4285 |
void |
| 4286 |
SoSceneViewer::destroySelectedObjects() |
| 4287 |
// |
| 4288 |
//////////////////////////////////////////////////////////////////////// |
| 4289 |
{ |
| 4290 |
for (int i = selection->getNumSelected() - 1; i >= 0; i--) { |
| 4291 |
SoPath *p = (*selection)[i]; |
| 4292 |
p->ref(); |
| 4293 |
|
| 4294 |
// Deselect this path |
| 4295 |
selection->deselect(i); |
| 4296 |
|
| 4297 |
// Remove the tail node from the graph |
| 4298 |
SoGroup *g = (SoGroup *) p->getNodeFromTail(1); |
| 4299 |
g->removeChild(p->getTail()); |
| 4300 |
|
| 4301 |
// Travel up the path to separators, and see if this was |
| 4302 |
// the only shape node under the sep. If so, delete the sep too. |
| 4303 |
// (Don't go all the way up to the selection node). |
| 4304 |
SbBool shapeFound = FALSE; |
| 4305 |
int j = 0; |
| 4306 |
while ((! shapeFound) && (j < p->getLength() - 1)) { |
| 4307 |
SoNode *n = p->getNodeFromTail(j); |
| 4308 |
if (n->isOfType(SoSeparator::getClassTypeId())) { |
| 4309 |
// Search for other shape nodes |
| 4310 |
SoSearchAction sa; |
| 4311 |
sa.setFind(SoSearchAction::TYPE); |
| 4312 |
sa.setType(SoShape::getClassTypeId()); |
| 4313 |
sa.apply(n); |
| 4314 |
|
| 4315 |
// If no other shapes under this separator, delete it! |
| 4316 |
if (sa.getPath() == NULL) { |
| 4317 |
g = (SoGroup *) p->getNodeFromTail(j + 1); |
| 4318 |
g->removeChild(n); |
| 4319 |
|
| 4320 |
// Reset j since we have a new end of path |
| 4321 |
j = 0; |
| 4322 |
} |
| 4323 |
else shapeFound = TRUE; |
| 4324 |
} |
| 4325 |
// Else a group with no children? |
| 4326 |
else if (n->isOfType(SoGroup::getClassTypeId()) && |
| 4327 |
(((SoGroup *)n)->getNumChildren() == 0)) { |
| 4328 |
g = (SoGroup *) p->getNodeFromTail(j + 1); |
| 4329 |
g->removeChild(n); |
| 4330 |
|
| 4331 |
// Reset j since we have a new end of path |
| 4332 |
j = 0; |
| 4333 |
} |
| 4334 |
// Else continue up the path looking for separators |
| 4335 |
else j++; |
| 4336 |
} |
| 4337 |
|
| 4338 |
p->unref(); |
| 4339 |
} |
| 4340 |
} |
| 4341 |
|
| 4342 |
//////////////////////////////////////////////////////////////////////// |
| 4343 |
// |
| 4344 |
// This enables/disables cmd key shortcuts and menu items |
| 4345 |
// based on whether there are any objects, and/or any selected objects |
| 4346 |
// in the scene graph. |
| 4347 |
// |
| 4348 |
// Use: static private |
| 4349 |
// |
| 4350 |
// |
| 4351 |
void |
| 4352 |
SoSceneViewer::updateCommandAvailability() |
| 4353 |
// |
| 4354 |
//////////////////////////////////////////////////////////////////////// |
| 4355 |
{ |
| 4356 |
Arg args[1]; |
| 4357 |
|
| 4358 |
// enable/disable based on the number of child objects in scene |
| 4359 |
if (selection->getNumChildren() == 0) |
| 4360 |
XtSetArg(args[0], XmNsensitive, False); |
| 4361 |
else XtSetArg(args[0], XmNsensitive, True); |
| 4362 |
|
| 4363 |
// save (if no children, nothing to save) |
| 4364 |
XtSetValues(menuItems[SV_FILE_SAVE].widget, args, 1); |
| 4365 |
XtSetValues(menuItems[SV_FILE_SAVE_AS].widget, args, 1); |
| 4366 |
|
| 4367 |
// pickAll (if no children, nothing to pick) |
| 4368 |
XtSetValues(menuItems[SV_EDIT_PICK_ALL].widget, args, 1); |
| 4369 |
|
| 4370 |
|
| 4371 |
// enable/disable based on the number of selected objects |
| 4372 |
if (selection->getNumSelected() == 0) |
| 4373 |
XtSetArg(args[0], XmNsensitive, False); |
| 4374 |
else XtSetArg(args[0], XmNsensitive, True); |
| 4375 |
|
| 4376 |
// if nothing selected, then cannot pick parent, cut, copy, delete, |
| 4377 |
// view selection, bring up editors |
| 4378 |
XtSetValues(menuItems[SV_EDIT_PICK_PARENT].widget, args, 1); |
| 4379 |
XtSetValues(menuItems[SV_EDIT_CUT].widget, args, 1); |
| 4380 |
XtSetValues(menuItems[SV_EDIT_COPY].widget, args, 1); |
| 4381 |
XtSetValues(menuItems[SV_EDIT_DELETE].widget, args, 1); |
| 4382 |
XtSetValues(menuItems[SV_VIEW_SELECTION].widget, args, 1); |
| 4383 |
XtSetValues(menuItems[SV_EDITOR_TRANSFORM].widget, args, 1); |
| 4384 |
XtSetValues(menuItems[SV_EDITOR_MATERIAL].widget, args, 1); |
| 4385 |
XtSetValues(menuItems[SV_EDITOR_COLOR].widget, args, 1); |
| 4386 |
} |
| 4387 |
|
| 4388 |
//////////////////////////////////////////////////////////////////////// |
| 4389 |
// |
| 4390 |
// Called by Xt when a menu is about to be displayed. |
| 4391 |
// This gives us a chance to update any items in the menu. |
| 4392 |
// |
| 4393 |
// Use: static private |
| 4394 |
// |
| 4395 |
void |
| 4396 |
SoSceneViewer::menuDisplay(Widget, SoSceneViewerData *data, XtPointer) |
| 4397 |
// |
| 4398 |
//////////////////////////////////////////////////////////////////////// |
| 4399 |
{ |
| 4400 |
SoSceneViewer *sv = data->classPt; |
| 4401 |
Arg args[1]; |
| 4402 |
char str[100]; |
| 4403 |
XmString xmstr; |
| 4404 |
|
| 4405 |
switch (data->id) { |
| 4406 |
case SV_FILE: |
| 4407 |
// disable saving if there isn't any geometry |
| 4408 |
if (sv->selection->getNumChildren() == 0) |
| 4409 |
XtSetArg(args[0], XmNsensitive, False); |
| 4410 |
else |
| 4411 |
XtSetArg(args[0], XmNsensitive, True); |
| 4412 |
|
| 4413 |
XtSetValues(sv->menuItems[SV_FILE_SAVE].widget, args, 1); |
| 4414 |
XtSetValues(sv->menuItems[SV_FILE_SAVE_AS].widget, args, 1); |
| 4415 |
|
| 4416 |
// update the "Save" menu entry to reflect the current file name |
| 4417 |
#ifndef EXPLORER |
| 4418 |
strcpy(str,fileData[5].name ); |
| 4419 |
#else |
| 4420 |
strcpy(str,fileData[0].name ); |
| 4421 |
#endif |
| 4422 |
if (sv->fileName != NULL) { |
| 4423 |
// get the file name withought the entire path |
| 4424 |
char *pt = strrchr(sv->fileName, '/'); // last occurance of '/' |
| 4425 |
pt = (pt == NULL) ? sv->fileName : pt + 1; |
| 4426 |
strcat(str, " -> "); |
| 4427 |
strcat(str, pt); |
| 4428 |
} |
| 4429 |
xmstr = XmStringCreate(str, XmSTRING_DEFAULT_CHARSET); |
| 4430 |
XtSetArg(args[0], XmNlabelString, xmstr); |
| 4431 |
XtSetValues(sv->menuItems[SV_FILE_SAVE].widget, args, 1); |
| 4432 |
XmStringFree(xmstr); |
| 4433 |
break; |
| 4434 |
|
| 4435 |
#ifndef EXPLORER |
| 4436 |
case SV_EDIT: |
| 4437 |
// disable cut, copy, delete, pickParent if there is no selection |
| 4438 |
if(sv->selection->getNumSelected() == 0) |
| 4439 |
XtSetArg(args[0], XmNsensitive, False); |
| 4440 |
else |
| 4441 |
XtSetArg(args[0], XmNsensitive, True); |
| 4442 |
|
| 4443 |
XtSetValues(sv->menuItems[SV_EDIT_PICK_PARENT].widget, args, 1); |
| 4444 |
XtSetValues(sv->menuItems[SV_EDIT_CUT].widget, args, 1); |
| 4445 |
XtSetValues(sv->menuItems[SV_EDIT_COPY].widget, args, 1); |
| 4446 |
XtSetValues(sv->menuItems[SV_EDIT_DELETE].widget, args, 1); |
| 4447 |
|
| 4448 |
// disable pick all if there are nothing to pick |
| 4449 |
if (sv->selection->getNumChildren() == 0) |
| 4450 |
XtSetArg(args[0], XmNsensitive, False); |
| 4451 |
else |
| 4452 |
XtSetArg(args[0], XmNsensitive, True); |
| 4453 |
XtSetValues(sv->menuItems[SV_EDIT_PICK_ALL].widget, args, 1); |
| 4454 |
break; |
| 4455 |
#endif /* EXPLORER */ |
| 4456 |
|
| 4457 |
case SV_VIEW: |
| 4458 |
// set pick/edit toggle |
| 4459 |
if ( sv->isViewing() ) |
| 4460 |
TOGGLE_OFF(sv->menuItems[SV_VIEW_PICK].widget); |
| 4461 |
else TOGGLE_ON(sv->menuItems[SV_VIEW_PICK].widget); |
| 4462 |
|
| 4463 |
#ifdef EXPLORER |
| 4464 |
// set user pick toggle |
| 4465 |
if ( sv->userModeFlag ) |
| 4466 |
TOGGLE_ON(sv->menuItems[SV_VIEW_USER].widget); |
| 4467 |
else TOGGLE_OFF(sv->menuItems[SV_VIEW_USER].widget); |
| 4468 |
#endif |
| 4469 |
// Set the correct viewer |
| 4470 |
TOGGLE_OFF(sv->menuItems[SV_VIEW_EXAMINER].widget); |
| 4471 |
TOGGLE_OFF(sv->menuItems[SV_VIEW_WALK].widget); |
| 4472 |
TOGGLE_OFF(sv->menuItems[SV_VIEW_PLANE].widget); |
| 4473 |
TOGGLE_OFF(sv->menuItems[SV_VIEW_FLY].widget); |
| 4474 |
switch ( sv->whichViewer ) { |
| 4475 |
case SV_VWR_EXAMINER: |
| 4476 |
TOGGLE_ON(sv->menuItems[SV_VIEW_EXAMINER].widget); |
| 4477 |
break; |
| 4478 |
case SV_VWR_WALK: |
| 4479 |
TOGGLE_ON(sv->menuItems[SV_VIEW_WALK].widget); |
| 4480 |
break; |
| 4481 |
case SV_VWR_FLY: |
| 4482 |
TOGGLE_ON(sv->menuItems[SV_VIEW_FLY].widget); |
| 4483 |
break; |
| 4484 |
case SV_VWR_PLANE: |
| 4485 |
TOGGLE_ON(sv->menuItems[SV_VIEW_PLANE].widget); |
| 4486 |
break; |
| 4487 |
} |
| 4488 |
|
| 4489 |
// set the correct transparency type |
| 4490 |
TOGGLE_OFF(sv->menuItems[SV_VIEW_SCREEN_TRANSPARENCY].widget); |
| 4491 |
TOGGLE_OFF(sv->menuItems[SV_VIEW_BLEND_TRANSPARENCY].widget); |
| 4492 |
TOGGLE_OFF(sv->menuItems[SV_VIEW_DELAY_BLEND_TRANSPARENCY].widget); |
| 4493 |
TOGGLE_OFF(sv->menuItems[SV_VIEW_SORT_BLEND_TRANSPARENCY].widget); |
| 4494 |
switch( sv->getTransparencyType() ) { |
| 4495 |
case SoGLRenderAction::SCREEN_DOOR: |
| 4496 |
TOGGLE_ON(sv->menuItems[SV_VIEW_SCREEN_TRANSPARENCY].widget); |
| 4497 |
break; |
| 4498 |
case SoGLRenderAction::BLEND: |
| 4499 |
TOGGLE_ON(sv->menuItems[SV_VIEW_BLEND_TRANSPARENCY].widget); |
| 4500 |
break; |
| 4501 |
case SoGLRenderAction::DELAYED_BLEND: |
| 4502 |
TOGGLE_ON(sv->menuItems[SV_VIEW_DELAY_BLEND_TRANSPARENCY].widget); |
| 4503 |
break; |
| 4504 |
case SoGLRenderAction::SORTED_OBJECT_BLEND: |
| 4505 |
TOGGLE_ON(sv->menuItems[SV_VIEW_SORT_BLEND_TRANSPARENCY].widget); |
| 4506 |
break; |
| 4507 |
} |
| 4508 |
|
| 4509 |
// disable view selection if nothing is selected |
| 4510 |
if ( sv->selection->getNumSelected() == 0 ) |
| 4511 |
XtSetArg(args[0], XmNsensitive, False); |
| 4512 |
else |
| 4513 |
XtSetArg(args[0], XmNsensitive, True); |
| 4514 |
XtSetValues(sv->menuItems[SV_VIEW_SELECTION].widget, args, 1); |
| 4515 |
|
| 4516 |
// set fog toggle |
| 4517 |
if ( sv->fogFlag ) |
| 4518 |
TOGGLE_ON(sv->menuItems[SV_VIEW_FOG].widget); |
| 4519 |
else TOGGLE_OFF(sv->menuItems[SV_VIEW_FOG].widget); |
| 4520 |
|
| 4521 |
// set antialiasing toggle |
| 4522 |
if ( sv->antialiasingFlag ) |
| 4523 |
TOGGLE_ON(sv->menuItems[SV_VIEW_ANTIALIASING].widget); |
| 4524 |
else TOGGLE_OFF(sv->menuItems[SV_VIEW_ANTIALIASING].widget); |
| 4525 |
|
| 4526 |
break; |
| 4527 |
|
| 4528 |
#ifndef EXPLORER |
| 4529 |
case SV_SELECTION: |
| 4530 |
// mirror the selection policy |
| 4531 |
TOGGLE_OFF(sv->menuItems[SV_SEL_SINGLE_SELECT].widget); |
| 4532 |
TOGGLE_OFF(sv->menuItems[SV_SEL_TOGGLE_SELECT].widget); |
| 4533 |
TOGGLE_OFF(sv->menuItems[SV_SEL_SHIFT_SELECT].widget); |
| 4534 |
switch ( sv->selection->policy.getValue() ) { |
| 4535 |
case SoSelection::SINGLE: |
| 4536 |
TOGGLE_ON (sv->menuItems[SV_SEL_SINGLE_SELECT].widget); |
| 4537 |
break; |
| 4538 |
case SoSelection::TOGGLE: |
| 4539 |
TOGGLE_ON (sv->menuItems[SV_SEL_TOGGLE_SELECT].widget); |
| 4540 |
break; |
| 4541 |
case SoSelection::SHIFT: |
| 4542 |
TOGGLE_ON (sv->menuItems[SV_SEL_SHIFT_SELECT].widget); |
| 4543 |
break; |
| 4544 |
default: |
| 4545 |
fprintf(stderr, "INTERNAL ERROR, unknown selection policy\n"); |
| 4546 |
break; |
| 4547 |
} |
| 4548 |
|
| 4549 |
break; |
| 4550 |
#endif /* EXPLORER */ |
| 4551 |
|
| 4552 |
case SV_EDITOR: |
| 4553 |
// disable items if there is no selection |
| 4554 |
if(sv->selection->getNumSelected() == 0) |
| 4555 |
XtSetArg(args[0], XmNsensitive, False); |
| 4556 |
else |
| 4557 |
XtSetArg(args[0], XmNsensitive, True); |
| 4558 |
|
| 4559 |
XtSetValues(sv->menuItems[SV_EDITOR_TRANSFORM].widget, args, 1); |
| 4560 |
XtSetValues(sv->menuItems[SV_EDITOR_MATERIAL].widget, args, 1); |
| 4561 |
XtSetValues(sv->menuItems[SV_EDITOR_COLOR].widget, args, 1); |
| 4562 |
break; |
| 4563 |
|
| 4564 |
case SV_MANIP: |
| 4565 |
|
| 4566 |
// First, the section with the different types of manipulators. |
| 4567 |
TOGGLE_OFF( sv->menuItems[SV_MANIP_HANDLEBOX].widget ); |
| 4568 |
TOGGLE_OFF( sv->menuItems[SV_MANIP_TRANSFORMER].widget ); |
| 4569 |
TOGGLE_OFF( sv->menuItems[SV_MANIP_TRACKBALL].widget ); |
| 4570 |
TOGGLE_OFF( sv->menuItems[SV_MANIP_JACK].widget ); |
| 4571 |
TOGGLE_OFF( sv->menuItems[SV_MANIP_CENTERBALL].widget ); |
| 4572 |
TOGGLE_OFF( sv->menuItems[SV_MANIP_XFBOX].widget ); |
| 4573 |
TOGGLE_OFF( sv->menuItems[SV_MANIP_TABBOX].widget ); |
| 4574 |
TOGGLE_OFF( sv->menuItems[SV_MANIP_NONE].widget ); |
| 4575 |
|
| 4576 |
// Turn appropriate radio button on |
| 4577 |
if (sv->curManip == SV_HANDLEBOX) |
| 4578 |
TOGGLE_ON(sv->menuItems[SV_MANIP_HANDLEBOX].widget); |
| 4579 |
else if (sv->curManip == SV_TRACKBALL) |
| 4580 |
TOGGLE_ON(sv->menuItems[SV_MANIP_TRACKBALL].widget); |
| 4581 |
else if (sv->curManip == SV_TRANSFORMER) |
| 4582 |
TOGGLE_ON(sv->menuItems[SV_MANIP_TRANSFORMER].widget); |
| 4583 |
else if (sv->curManip == SV_JACK) |
| 4584 |
TOGGLE_ON(sv->menuItems[SV_MANIP_JACK].widget); |
| 4585 |
else if (sv->curManip == SV_CENTERBALL) |
| 4586 |
TOGGLE_ON(sv->menuItems[SV_MANIP_CENTERBALL].widget); |
| 4587 |
else if (sv->curManip == SV_XFBOX) |
| 4588 |
TOGGLE_ON(sv->menuItems[SV_MANIP_XFBOX].widget); |
| 4589 |
else if (sv->curManip == SV_TABBOX) |
| 4590 |
TOGGLE_ON(sv->menuItems[SV_MANIP_TABBOX].widget); |
| 4591 |
else |
| 4592 |
TOGGLE_ON(sv->menuItems[SV_MANIP_NONE].widget); |
| 4593 |
|
| 4594 |
// Next, the toggle that says whether we replace current |
| 4595 |
// manipulators every time we change the type given in the menu. |
| 4596 |
if (sv->curManipReplaces == TRUE ) |
| 4597 |
TOGGLE_ON( sv->menuItems[SV_MANIP_REPLACE_ALL].widget ); |
| 4598 |
else |
| 4599 |
TOGGLE_OFF( sv->menuItems[SV_MANIP_REPLACE_ALL].widget ); |
| 4600 |
|
| 4601 |
break; |
| 4602 |
|
| 4603 |
case SV_LIGHT: |
| 4604 |
// disable the add light entries if we have more than 8 lights |
| 4605 |
if (sv->lightDataList.getLength() < 8) |
| 4606 |
XtSetArg(args[0], XmNsensitive, True); |
| 4607 |
else |
| 4608 |
XtSetArg(args[0], XmNsensitive, False); |
| 4609 |
|
| 4610 |
XtSetValues(sv->menuItems[SV_LIGHT_ADD_DIRECT].widget, args, 1); |
| 4611 |
XtSetValues(sv->menuItems[SV_LIGHT_ADD_POINT].widget, args, 1); |
| 4612 |
XtSetValues(sv->menuItems[SV_LIGHT_ADD_SPOT].widget, args, 1); |
| 4613 |
|
| 4614 |
// update the headlight label (show on/off with '*') |
| 4615 |
sv->isHeadlight() ? strcpy(str, "* ") : strcpy(str, " "); |
| 4616 |
strcat(str, sv->headlightData->name); |
| 4617 |
xmstr = XmStringCreate(str, XmSTRING_DEFAULT_CHARSET); |
| 4618 |
XtSetArg(args[0], XmNlabelString, xmstr); |
| 4619 |
XtSetValues(sv->headlightData->cascadeWidget, args, 1); |
| 4620 |
XmStringFree(xmstr); |
| 4621 |
|
| 4622 |
// update the lights label (show on/off with '*') |
| 4623 |
{ |
| 4624 |
for (int i=0; i < sv->lightDataList.getLength(); i++) { |
| 4625 |
SvLightData *data = (SvLightData *) sv->lightDataList[i]; |
| 4626 |
IS_LIGHT_ON(data->lightSwitch) ? strcpy(str, "* ") : strcpy(str, " "); |
| 4627 |
strcat(str, data->name); |
| 4628 |
xmstr = XmStringCreate(str, XmSTRING_DEFAULT_CHARSET); |
| 4629 |
XtSetArg(args[0], XmNlabelString, xmstr); |
| 4630 |
XtSetValues(data->cascadeWidget, args, 1); |
| 4631 |
XmStringFree(xmstr); |
| 4632 |
} |
| 4633 |
} |
| 4634 |
break; |
| 4635 |
|
| 4636 |
default: |
| 4637 |
break; |
| 4638 |
} |
| 4639 |
} |
| 4640 |
|
| 4641 |
//////////////////////////////////////////////////////////////////////// |
| 4642 |
// |
| 4643 |
// Description: |
| 4644 |
// Determines whether a given node is affected by a transform. |
| 4645 |
// |
| 4646 |
// Use: static, public |
| 4647 |
// |
| 4648 |
SbBool |
| 4649 |
SoSceneViewer::isAffectedByTransform( |
| 4650 |
SoNode *theNode ) // node to be affected? |
| 4651 |
// |
| 4652 |
//////////////////////////////////////////////////////////////////////// |
| 4653 |
{ |
| 4654 |
if ( theNode->isOfType( SoGroup::getClassTypeId() ) |
| 4655 |
|| theNode->isOfType( SoShape::getClassTypeId() ) |
| 4656 |
|| theNode->isOfType( SoCamera::getClassTypeId() ) |
| 4657 |
|| theNode->isOfType( SoLight::getClassTypeId() ) ) { |
| 4658 |
return TRUE; |
| 4659 |
} |
| 4660 |
return FALSE; |
| 4661 |
} |
| 4662 |
|
| 4663 |
//////////////////////////////////////////////////////////////////////// |
| 4664 |
// |
| 4665 |
// Description: |
| 4666 |
// Determines whether a given node is affected by material node. |
| 4667 |
// |
| 4668 |
// Use: static, public |
| 4669 |
// |
| 4670 |
SbBool |
| 4671 |
SoSceneViewer::isAffectedByMaterial( |
| 4672 |
SoNode *theNode ) // node to be affected? |
| 4673 |
// |
| 4674 |
//////////////////////////////////////////////////////////////////////// |
| 4675 |
{ |
| 4676 |
if ( theNode->isOfType( SoGroup::getClassTypeId() ) |
| 4677 |
|| theNode->isOfType( SoShape::getClassTypeId() ) ) { |
| 4678 |
return TRUE; |
| 4679 |
} |
| 4680 |
return FALSE; |
| 4681 |
} |
| 4682 |
|
| 4683 |
//////////////////////////////////////////////////////////////////////// |
| 4684 |
// |
| 4685 |
// Description: |
| 4686 |
// Create the lights and camera environment structure. |
| 4687 |
// |
| 4688 |
// Use: private |
| 4689 |
// |
| 4690 |
void |
| 4691 |
SoSceneViewer::createLightsCameraEnvironment() |
| 4692 |
// |
| 4693 |
//////////////////////////////////////////////////////////////////////// |
| 4694 |
{ |
| 4695 |
// Group { |
| 4696 |
// Label { "SoSceneViewer Environment v3.0" } |
| 4697 |
// Camera {} |
| 4698 |
// Environment {} |
| 4699 |
// Group { |
| 4700 |
// Switch { Light 1 } # switch is child 0, light is child 0 |
| 4701 |
// Switch { Light 2 } # switch is child 1, light is child 0 |
| 4702 |
// ... |
| 4703 |
// } |
| 4704 |
// } |
| 4705 |
// |
| 4706 |
// NOTE: since the camera may be switched by the viewer (ortho/perspective toggle) |
| 4707 |
// make sure to get the camera from the viewer (and not cache the camera). |
| 4708 |
|
| 4709 |
lightsCameraEnvironment = new SoGroup; |
| 4710 |
environment = new SoEnvironment; |
| 4711 |
lightGroup = new SoGroup; |
| 4712 |
envLabel = new SoLabel; |
| 4713 |
|
| 4714 |
envLabel->label.setValue(SV_ENV_LABEL); |
| 4715 |
lightsCameraEnvironment->addChild(envLabel); |
| 4716 |
#ifndef EXPLORER |
| 4717 |
// Explorer SceneViewer doesn't remove cameras from the Scene, so |
| 4718 |
// don't add any... |
| 4719 |
lightsCameraEnvironment->addChild(new SoPerspectiveCamera); |
| 4720 |
#endif |
| 4721 |
lightsCameraEnvironment->addChild(environment); |
| 4722 |
lightsCameraEnvironment->addChild(lightGroup); |
| 4723 |
} |
| 4724 |
|
| 4725 |
//////////////////////////////////////////////////////////////////////// |
| 4726 |
// |
| 4727 |
// Description: |
| 4728 |
// Brings up the "About..." dialog (same code as gavin demo programs) |
| 4729 |
// |
| 4730 |
// Use: private |
| 4731 |
// |
| 4732 |
void |
| 4733 |
SoSceneViewer::showAboutDialog() |
| 4734 |
// |
| 4735 |
//////////////////////////////////////////////////////////////////////// |
| 4736 |
{ |
| 4737 |
if (access(IVDEMOBINDIR "/SceneViewer.about.pdf", R_OK) != 0) |
| 4738 |
{ |
| 4739 |
system("xmessage 'Sorry, could not find " |
| 4740 |
IVDEMOBINDIR "/SceneViewer.about.pdf' > /dev/null"); |
| 4741 |
return; |
| 4742 |
} |
| 4743 |
|
| 4744 |
char command[2*PATH_MAX+100]; |
| 4745 |
sprintf(command, "which " PDFVIEWER " > /dev/null"); |
| 4746 |
|
| 4747 |
int err = system(command); |
| 4748 |
if (err) |
| 4749 |
{ |
| 4750 |
system("xmessage 'You must install " PDFVIEWER |
| 4751 |
" for this function to work' > /dev/null"); |
| 4752 |
return; |
| 4753 |
} |
| 4754 |
|
| 4755 |
sprintf(command, PDFVIEWER " " |
| 4756 |
IVDEMOBINDIR "/SceneViewer.about.pdf &"); |
| 4757 |
system(command); |
| 4758 |
} |
| 4759 |
|
| 4760 |
// |
| 4761 |
// define those generic virtual functions |
| 4762 |
// |
| 4763 |
const char * |
| 4764 |
SoSceneViewer::getDefaultWidgetName() const |
| 4765 |
{ return "SoSceneViewer"; } |
| 4766 |
|
| 4767 |
const char * |
| 4768 |
SoSceneViewer::getDefaultTitle() const |
| 4769 |
{ return "SceneViewer"; } |
| 4770 |
|
| 4771 |
const char * |
| 4772 |
SoSceneViewer::getDefaultIconTitle() const |
| 4773 |
{ return "SceneViewer"; } |
| 4774 |
|