| 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 |
| Classes: |
| 38 |
| Interface |
| 39 |
| |
| 40 |
| Author(s): Paul Isaacs |
| 41 |
| |
| 42 |
*/ |
| 43 |
|
| 44 |
|
| 45 |
#include <unistd.h> |
| 46 |
#include <cstdlib> |
| 47 |
#include <cstdio> |
| 48 |
#include <Inventor/SbLinear.h> |
| 49 |
#include <Inventor/SoDB.h> |
| 50 |
|
| 51 |
#include <Xm/MessageB.h> |
| 52 |
|
| 53 |
#include <Inventor/actions/SoBoxHighlightRenderAction.h> |
| 54 |
#include <Inventor/actions/SoWriteAction.h> |
| 55 |
#include <Inventor/manips/SoHandleBoxManip.h> |
| 56 |
#include <Inventor/manips/SoTrackballManip.h> |
| 57 |
#include <Inventor/nodes/SoSelection.h> |
| 58 |
#include <Inventor/nodes/SoSeparator.h> |
| 59 |
#include <Inventor/Xt/SoXt.h> |
| 60 |
#include <Inventor/Xt/SoXtClipboard.h> |
| 61 |
#include <Inventor/Xt/viewers/SoXtViewer.h> |
| 62 |
|
| 63 |
#include "GeneralizedCylinder.h" |
| 64 |
#include "WorldInfo.h" |
| 65 |
#include "PullDowns.h" |
| 66 |
#include "Interface.h" |
| 67 |
#include "NoodleTextureGizmo.h" |
| 68 |
#include "NoodleSurfaceGizmo.h" |
| 69 |
|
| 70 |
#define SCREEN(w) XScreenNumberOfScreen(XtScreen(w)) |
| 71 |
|
| 72 |
extern SoNode *createProfileGraph( Widget, GeneralizedCylinder *); |
| 73 |
extern SoNode *createCrossSectionGraph( Widget, GeneralizedCylinder *); |
| 74 |
extern SoNode *createSpineGraph( Widget, GeneralizedCylinder *); |
| 75 |
extern SoNode *createTwistGraph( Widget, GeneralizedCylinder *); |
| 76 |
|
| 77 |
Interface::Interface() |
| 78 |
{ |
| 79 |
// Initialize other variables. |
| 80 |
bgColor.setValue(0,0,0); |
| 81 |
worldInfo = NULL; |
| 82 |
mgrWidget = NULL; |
| 83 |
mainViewer = NULL; |
| 84 |
menuItems = NULL; |
| 85 |
myTextureGizmo = NULL; |
| 86 |
mySurfaceGizmo = NULL; |
| 87 |
|
| 88 |
profileViewer = NULL; |
| 89 |
sectionViewer = NULL; |
| 90 |
spineViewer = NULL; |
| 91 |
twistViewer = NULL; |
| 92 |
|
| 93 |
closeProfileButton = NULL; |
| 94 |
closeSectionButton = NULL; |
| 95 |
closeSpineButton = NULL; |
| 96 |
closeTwistButton = NULL; |
| 97 |
} |
| 98 |
|
| 99 |
Interface::~Interface() |
| 100 |
{ |
| 101 |
worldInfo = NULL; |
| 102 |
if (myTextureGizmo) |
| 103 |
delete myTextureGizmo; |
| 104 |
if (mySurfaceGizmo) |
| 105 |
delete mySurfaceGizmo; |
| 106 |
} |
| 107 |
|
| 108 |
void |
| 109 |
Interface::setWorldInfo( WorldInfo *newWorldInfo ) |
| 110 |
{ |
| 111 |
if (newWorldInfo == NULL) |
| 112 |
return; |
| 113 |
|
| 114 |
worldInfo = newWorldInfo; |
| 115 |
SoSelection *s = worldInfo->getSelectorNode(); |
| 116 |
s->addSelectionCallback( &Interface::selectionCB, this ); |
| 117 |
} |
| 118 |
|
| 119 |
///////////////////////////////////////////////////////////////////// |
| 120 |
// Reads the scene given by filename and puts the results into worldInfo. |
| 121 |
// Returns pointer to top of scene graph. |
| 122 |
// If filename is NULL, uses name already found in worldInfo. |
| 123 |
// If filename and worldInfo are both NULL, it is an error. |
| 124 |
SoSeparator * |
| 125 |
Interface::readScene( char *newFileName, SbBool okIfNoName ) |
| 126 |
{ |
| 127 |
if (newFileName == NULL && |
| 128 |
(worldInfo == NULL || worldInfo->getFileName() == NULL)) { |
| 129 |
if ( ! okIfNoName ) { |
| 130 |
fprintf(stderr, "Interface::readScene programming error:" |
| 131 |
"Can\'t read scene because no filename given and \n" |
| 132 |
"Interface has worldInfo equal to NULL\n"); |
| 133 |
} |
| 134 |
return (NULL); |
| 135 |
} |
| 136 |
|
| 137 |
SoInput in; |
| 138 |
SoSeparator *root; |
| 139 |
FILE *filePtr = NULL; |
| 140 |
|
| 141 |
if (newFileName != NULL && worldInfo != NULL) |
| 142 |
worldInfo->setFileName( newFileName ); |
| 143 |
|
| 144 |
const char *fName |
| 145 |
= (worldInfo == NULL) ? newFileName : worldInfo->getFileName(); |
| 146 |
|
| 147 |
fprintf(stderr, "Reading file %s...\n", fName ); |
| 148 |
|
| 149 |
const char *slashPtr; |
| 150 |
char *searchPath = NULL; |
| 151 |
|
| 152 |
filePtr = fopen(fName, "r"); |
| 153 |
if (filePtr == NULL) { |
| 154 |
fprintf(stderr, "Error opening file %s\n", fName); |
| 155 |
return (NULL); |
| 156 |
} |
| 157 |
|
| 158 |
// |
| 159 |
// If the filename includes a directory path, add the |
| 160 |
// directory name to the list of directories where to look |
| 161 |
// for files referenced in the input file (e.g. SoFile nodes) |
| 162 |
// |
| 163 |
if ((slashPtr = strrchr(fName, '/')) != NULL) { |
| 164 |
searchPath = strdup(fName); |
| 165 |
searchPath[slashPtr - fName] = '\0'; |
| 166 |
in.addDirectoryFirst(searchPath); |
| 167 |
} |
| 168 |
|
| 169 |
in.setFilePointer(filePtr); |
| 170 |
root = SoDB::readAll(&in); |
| 171 |
if (root == NULL) |
| 172 |
fprintf(stderr, "Error reading file %s\n", fName); |
| 173 |
|
| 174 |
fclose(filePtr); |
| 175 |
if ( worldInfo != NULL) |
| 176 |
worldInfo->setScene( root ); |
| 177 |
return root; |
| 178 |
} |
| 179 |
|
| 180 |
///////////////////////////////////////////////////////////////////// |
| 181 |
// Writes the scene contained in worldInfo. |
| 182 |
// If asVanilla==FALSE, uses special GeneralizedCylinder class in the file. |
| 183 |
// If asVanilla==TRUE, uses only standard Inventor nodes. |
| 184 |
// If filename is NULL, uses name already found in worldInfo. |
| 185 |
// If filename and worldInfo->getFileName() are both NULL, it is an error. |
| 186 |
void |
| 187 |
Interface::writeToFile( SbBool asVanilla, char *newFileName ) |
| 188 |
{ |
| 189 |
if ( worldInfo == NULL || |
| 190 |
(newFileName == NULL && worldInfo->getFileName() == NULL)) { |
| 191 |
fprintf(stderr, "Interface::writeToFile programming error:" |
| 192 |
"Can\'t write scene because no filename given or \n" |
| 193 |
"Interface has worldInfo equal to NULL\n"); |
| 194 |
return; |
| 195 |
} |
| 196 |
|
| 197 |
SoWriteAction wa; |
| 198 |
|
| 199 |
if (newFileName != NULL ) |
| 200 |
worldInfo->setFileName( newFileName ); |
| 201 |
|
| 202 |
const char *fName = worldInfo->getFileName(); |
| 203 |
|
| 204 |
if (! wa.getOutput()->openFile(fName)) { |
| 205 |
char str[100]; |
| 206 |
strcpy(str, "Error creating file: "); |
| 207 |
strcat(str, fName); |
| 208 |
SoXt::createSimpleErrorDialog(mgrWidget, |
| 209 |
"File Write Error Dialog", str); |
| 210 |
} |
| 211 |
else { |
| 212 |
// Temporarily remove manips from scene |
| 213 |
SoType savedManipType = worldInfo->getManipType(); |
| 214 |
worldInfo->setManipType( SoTransform::getClassTypeId() ); |
| 215 |
|
| 216 |
// Get the scene from worldInfo and write it out. |
| 217 |
SoSeparator *scene; |
| 218 |
if ( asVanilla ) |
| 219 |
scene = worldInfo->getVanillaSceneCopy(); |
| 220 |
else |
| 221 |
scene = worldInfo->getScene(); |
| 222 |
|
| 223 |
|
| 224 |
scene->ref(); |
| 225 |
wa.apply(scene); |
| 226 |
wa.getOutput()->closeFile(); |
| 227 |
scene->unref(); |
| 228 |
|
| 229 |
// Restore manips to scene. |
| 230 |
worldInfo->setManipType( savedManipType ); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
/////////////////////////////////////////////////////////////////// |
| 235 |
// |
| 236 |
// If scene isn't empty, check if user wants to save scene first. |
| 237 |
// If not, then create an empty scene so user can start over. |
| 238 |
// |
| 239 |
void |
| 240 |
Interface::fileNewEvent() |
| 241 |
{ |
| 242 |
if (worldInfo->isSceneEmpty() == FALSE ) { |
| 243 |
createOkayCancelDialog(mgrWidget, |
| 244 |
Interface::newSceneCB, |
| 245 |
"New Scene Error Dialog", |
| 246 |
"Your current scene is not empty.", |
| 247 |
"Hit OK to continue, CANCEL if you want to Save first."); |
| 248 |
|
| 249 |
} |
| 250 |
else |
| 251 |
Interface::newSceneCB(NULL, (XtPointer) this, NULL); |
| 252 |
} |
| 253 |
|
| 254 |
/////////////////////////////////////////////////////////////////// |
| 255 |
// |
| 256 |
// If scene not empty, check if user wants to save scene first. |
| 257 |
// If not, bring up the file dialog box and read a new scene from file. |
| 258 |
// |
| 259 |
void |
| 260 |
Interface::fileOpenEvent() |
| 261 |
{ |
| 262 |
if (worldInfo->isSceneEmpty() == FALSE ) { |
| 263 |
createOkayCancelDialog(mgrWidget, |
| 264 |
Interface::openSceneCB, |
| 265 |
"Open Scene Error Dialog", |
| 266 |
"Your current scene is not empty.", |
| 267 |
"Hit OK to continue, CANCEL if you want to Save first."); |
| 268 |
|
| 269 |
} |
| 270 |
else |
| 271 |
Interface::openSceneCB(NULL, (XtPointer) this, NULL); |
| 272 |
} |
| 273 |
|
| 274 |
/////////////////////////////////////////////////////////////////// |
| 275 |
// |
| 276 |
// If scene is empty, show a dialog and return. |
| 277 |
// If there is more than one file in the list, direct them to Save As... |
| 278 |
// If everything's okay, ask the world for the scene and write it out. |
| 279 |
// |
| 280 |
void |
| 281 |
Interface::fileSaveEvent() |
| 282 |
{ |
| 283 |
if (worldInfo->isSceneEmpty() == TRUE ) { |
| 284 |
SoXt::createSimpleErrorDialog(mgrWidget, |
| 285 |
"File Save Empty Error Dialog", |
| 286 |
"The current scene is empty. Create a scene first,", |
| 287 |
"or fix my code to grey out this menu item."); |
| 288 |
} |
| 289 |
else |
| 290 |
writeToFile( FALSE ); |
| 291 |
} |
| 292 |
|
| 293 |
/////////////////////////////////////////////////////////////////// |
| 294 |
// |
| 295 |
// If the scene is empty, show a dialog and return. |
| 296 |
// If everything's okay, ask the world for the scene and write it out. |
| 297 |
// |
| 298 |
void |
| 299 |
Interface::fileSaveAsEvent() |
| 300 |
{ |
| 301 |
if (worldInfo->isSceneEmpty() == TRUE ) { |
| 302 |
SoXt::createSimpleErrorDialog(mgrWidget, |
| 303 |
"File Save As Empty Error Dialog", |
| 304 |
"The current scene is empty. Create a scene first,", |
| 305 |
"or fix my code to grey out this menu item."); |
| 306 |
} |
| 307 |
else |
| 308 |
showFileSelectionDialog( (XtCallbackProc) Interface::writeToFileCB ); |
| 309 |
} |
| 310 |
|
| 311 |
/////////////////////////////////////////////////////////////////// |
| 312 |
// |
| 313 |
// If the scene is empty, show a dialog and return. |
| 314 |
// If everything's okay, ask the world for the scene and write it out. |
| 315 |
// |
| 316 |
void |
| 317 |
Interface::fileSaveVanillaEvent() |
| 318 |
{ |
| 319 |
if (worldInfo->isSceneEmpty() == TRUE ) { |
| 320 |
SoXt::createSimpleErrorDialog(mgrWidget, |
| 321 |
"File Save As Empty Error Dialog", |
| 322 |
"The current scene is empty. Create a scene first,", |
| 323 |
"or fix my code to grey out this menu item."); |
| 324 |
} |
| 325 |
else |
| 326 |
showFileSelectionDialog( (XtCallbackProc) Interface::writeToVanillaFileCB ); |
| 327 |
} |
| 328 |
|
| 329 |
/////////////////////////////////////////////////////////////////// |
| 330 |
// |
| 331 |
// If the scene is not empty, see if the user would like to save. |
| 332 |
// Otherwise, quit. |
| 333 |
// |
| 334 |
void |
| 335 |
Interface::fileQuitEvent() |
| 336 |
{ |
| 337 |
if (worldInfo->isSceneEmpty() == FALSE ) { |
| 338 |
createOkayCancelDialog(mgrWidget, |
| 339 |
Interface::quitProgramCB, |
| 340 |
"Quit Error Dialog", |
| 341 |
"Your current scene is not empty.", |
| 342 |
"Hit OK to Quit anyway, CANCEL if you want to Save first."); |
| 343 |
|
| 344 |
} |
| 345 |
else |
| 346 |
Interface::quitProgramCB(NULL, (XtPointer) this, NULL); |
| 347 |
} |
| 348 |
|
| 349 |
//////////////////////////////////////////////////////////////////////// |
| 350 |
// |
| 351 |
// creates a dialog box. |
| 352 |
// Prints a message and has two buttons: |
| 353 |
// CANCEL and OK. |
| 354 |
// |
| 355 |
// When calling this, you must pass a callback for when the |
| 356 |
// OK button is pressed. |
| 357 |
// |
| 358 |
void |
| 359 |
Interface::createOkayCancelDialog(Widget widget, XtCallbackProc okCB, |
| 360 |
char *dialogTitle, char *str1, char *str2) |
| 361 |
{ |
| 362 |
Widget shell = SoXt::getShellWidget(widget); |
| 363 |
if (shell == NULL) |
| 364 |
return; |
| 365 |
|
| 366 |
Arg args[5]; |
| 367 |
XmString xmstr = XmStringCreateSimple(str1); |
| 368 |
xmstr = XmStringConcat(xmstr, XmStringSeparatorCreate()); |
| 369 |
xmstr = XmStringConcat(xmstr, XmStringCreateSimple(str2)); |
| 370 |
|
| 371 |
int n = 0; |
| 372 |
XtSetArg(args[n], XmNautoUnmanage, FALSE); n++; |
| 373 |
XtSetArg(args[n], XtNtitle, dialogTitle); n++; |
| 374 |
XtSetArg(args[n], XmNmessageString, xmstr); n++; |
| 375 |
Widget dialog = XmCreateErrorDialog(shell, "Error Dialog", args, n); |
| 376 |
XmStringFree(xmstr); |
| 377 |
|
| 378 |
XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON)); |
| 379 |
|
| 380 |
// First, destroy the dialog box. |
| 381 |
// Then, call the passed callback. |
| 382 |
XtAddCallback(dialog, XmNokCallback, |
| 383 |
(XtCallbackProc) Interface::destroyDialogCB, (XtPointer)this); |
| 384 |
XtAddCallback(dialog, XmNokCallback, |
| 385 |
(XtCallbackProc) okCB, (XtPointer)this); |
| 386 |
|
| 387 |
// If the user cancels, we'll always want to destroy the dialog. |
| 388 |
// register callback to destroy (and not just unmap) the dialog |
| 389 |
XtAddCallback(dialog, XmNcancelCallback, |
| 390 |
(XtCallbackProc) Interface::destroyDialogCB, (XtPointer)this); |
| 391 |
|
| 392 |
XtManageChild(dialog); |
| 393 |
} |
| 394 |
|
| 395 |
/////////////////////////////////////////////////////////////////// |
| 396 |
// |
| 397 |
// Brings up the "About..." dialog |
| 398 |
// |
| 399 |
void |
| 400 |
Interface::showAboutDialog() |
| 401 |
{ |
| 402 |
if (access(IVDEMOBINDIR"/noodle.about.pdf", R_OK) != 0) { |
| 403 |
system("xmessage 'Sorry, could not find " |
| 404 |
IVDEMOBINDIR"/noodle.about.pdf' > /dev/null"); |
| 405 |
return; |
| 406 |
} |
| 407 |
|
| 408 |
char command[2*PATH_MAX+100]; |
| 409 |
sprintf(command, "which " PDFVIEWER " > /dev/null"); |
| 410 |
|
| 411 |
int err = system(command); |
| 412 |
if (err) { |
| 413 |
system("xmessage 'You must install " PDFVIEWER |
| 414 |
" for this function to work' > /dev/null"); |
| 415 |
return; |
| 416 |
} |
| 417 |
|
| 418 |
sprintf(command, PDFVIEWER " " IVDEMOBINDIR"/noodle.about.pdf &"); |
| 419 |
system(command); |
| 420 |
} |
| 421 |
|
| 422 |
/////////////////////////////////////////////////////////////////// |
| 423 |
// |
| 424 |
// Use a motif file selection dialog to get the new filename. |
| 425 |
// When calling this, you must pass a callback for when the |
| 426 |
// OK button is pressed. |
| 427 |
// |
| 428 |
void |
| 429 |
Interface::showFileSelectionDialog( XtCallbackProc okCB ) |
| 430 |
{ |
| 431 |
static Widget fileDialog = NULL; |
| 432 |
|
| 433 |
if (fileDialog == NULL) { |
| 434 |
Arg args[5]; |
| 435 |
int n = 0; |
| 436 |
|
| 437 |
// Unmanage when ok/cancel are pressed |
| 438 |
XtSetArg(args[n], XmNautoUnmanage, TRUE); n++; |
| 439 |
fileDialog = XmCreateFileSelectionDialog( |
| 440 |
XtParent(mgrWidget), "File Dialog", args, n); |
| 441 |
|
| 442 |
XtAddCallback(fileDialog, XmNokCallback, |
| 443 |
(XtCallbackProc)okCB, (XtPointer) this); |
| 444 |
} |
| 445 |
else { |
| 446 |
// We need to remove the old callback, |
| 447 |
// then install the one we were passed, since this file selector |
| 448 |
// is used for both reading and writing files. |
| 449 |
XtRemoveAllCallbacks(fileDialog, XmNokCallback ); |
| 450 |
XtAddCallback(fileDialog, XmNokCallback, |
| 451 |
(XtCallbackProc)okCB, this); |
| 452 |
} |
| 453 |
|
| 454 |
// Manage the dialog |
| 455 |
XtManageChild(fileDialog); |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
////////////////////////////////////////////////////////////// |
| 460 |
// Gets rid of dialog box. |
| 461 |
void |
| 462 |
Interface::destroyDialogCB(Widget dialog, void *, void *) |
| 463 |
{ |
| 464 |
XtDestroyWidget(dialog); |
| 465 |
} |
| 466 |
|
| 467 |
////////////////////////////////////////////////////////////// |
| 468 |
// Makes a brand new scene. |
| 469 |
// |
| 470 |
void |
| 471 |
Interface::newSceneCB(Widget, void *userData, void *) |
| 472 |
{ |
| 473 |
Interface *myself = (Interface *) userData; |
| 474 |
// Create a new scene with one Noodle under a separator. |
| 475 |
SoSeparator *newRoot = new SoSeparator; |
| 476 |
newRoot->ref(); |
| 477 |
newRoot->addChild( new GeneralizedCylinder ); |
| 478 |
|
| 479 |
myself->getWorldInfo()->setScene( newRoot ); |
| 480 |
newRoot->unref(); |
| 481 |
} |
| 482 |
|
| 483 |
////////////////////////////////////////////////////////////// |
| 484 |
// Brings up file selection widget and reads scene from selected file. |
| 485 |
// |
| 486 |
void |
| 487 |
Interface::openSceneCB(Widget, void *userData, void *) |
| 488 |
{ |
| 489 |
((Interface *)userData)->showFileSelectionDialog( |
| 490 |
(XtCallbackProc) Interface::readFromFileCB ); |
| 491 |
} |
| 492 |
|
| 493 |
////////////////////////////////////////////////////////////// |
| 494 |
// Brings up file selection widget and reads scene from selected file. |
| 495 |
// Callback routine that gets called when the new filename |
| 496 |
// has been entered. |
| 497 |
// |
| 498 |
// Reads the scene and gives it to 'worldInfo' |
| 499 |
// |
| 500 |
void |
| 501 |
Interface::readFromFileCB(Widget, void *userData, |
| 502 |
XmFileSelectionBoxCallbackStruct *data) |
| 503 |
{ |
| 504 |
// Get the file name |
| 505 |
char *filename; |
| 506 |
XmStringGetLtoR(data->value, |
| 507 |
(XmStringCharSet) XmSTRING_DEFAULT_CHARSET, &filename); |
| 508 |
|
| 509 |
((Interface *)userData)->readScene( filename ); |
| 510 |
|
| 511 |
XtFree(filename); |
| 512 |
} |
| 513 |
|
| 514 |
////////////////////////////////////////////////////////////// |
| 515 |
// Callback routine that gets called when the new filename |
| 516 |
// has been entered. |
| 517 |
// |
| 518 |
// Writes the scene held by 'worldInfo' |
| 519 |
// |
| 520 |
void |
| 521 |
Interface::writeToFileCB(Widget, void *userData, |
| 522 |
XmFileSelectionBoxCallbackStruct *data) |
| 523 |
{ |
| 524 |
// Get the file name |
| 525 |
char *filename; |
| 526 |
XmStringGetLtoR(data->value, |
| 527 |
(XmStringCharSet) XmSTRING_DEFAULT_CHARSET, &filename); |
| 528 |
|
| 529 |
((Interface *)userData)->writeToFile( FALSE, filename ); |
| 530 |
|
| 531 |
XtFree(filename); |
| 532 |
} |
| 533 |
|
| 534 |
////////////////////////////////////////////////////////////// |
| 535 |
// Callback routine that gets called when the new filename |
| 536 |
// has been entered. |
| 537 |
// |
| 538 |
// Writes the scene AS A STANDARD INVENTOR FILE WITHOUT GENERALIZED CYLINDERS |
| 539 |
// to file held by 'worldInfo' |
| 540 |
// |
| 541 |
void |
| 542 |
Interface::writeToVanillaFileCB(Widget, void *userData, |
| 543 |
XmFileSelectionBoxCallbackStruct *data) |
| 544 |
{ |
| 545 |
// Get the file name |
| 546 |
char *filename; |
| 547 |
XmStringGetLtoR(data->value, |
| 548 |
(XmStringCharSet) XmSTRING_DEFAULT_CHARSET, &filename); |
| 549 |
|
| 550 |
// TRUE means to write it 'vanilla style' |
| 551 |
((Interface *) userData)->writeToFile( TRUE, filename ); |
| 552 |
|
| 553 |
XtFree(filename); |
| 554 |
} |
| 555 |
|
| 556 |
void |
| 557 |
Interface::quitProgramCB(Widget, void *, void *) |
| 558 |
{ |
| 559 |
exit(0); |
| 560 |
} |
| 561 |
|
| 562 |
/////////////////////////////////////////////////////////////////// |
| 563 |
// |
| 564 |
// Process the topbar menu events. |
| 565 |
void |
| 566 |
Interface::processTopbarEvent(Widget, |
| 567 |
NoodleMenuItem *data, XmAnyCallbackStruct *cbstruct ) |
| 568 |
{ |
| 569 |
Interface *myself = data->ownerInterface; |
| 570 |
WorldInfo *myWorld = myself->worldInfo; |
| 571 |
GeneralizedCylinder *myNoodle = myWorld->getCurrentNoodle(); |
| 572 |
|
| 573 |
static SoXtClipboard *theClipboard = NULL; |
| 574 |
|
| 575 |
switch (data->id) { |
| 576 |
|
| 577 |
// |
| 578 |
// File |
| 579 |
// |
| 580 |
|
| 581 |
case MM_FILE_NEW: |
| 582 |
myself->fileNewEvent(); |
| 583 |
break; |
| 584 |
|
| 585 |
case MM_FILE_OPEN: |
| 586 |
myself->fileOpenEvent(); |
| 587 |
break; |
| 588 |
|
| 589 |
case MM_FILE_SAVE: |
| 590 |
myself->fileSaveEvent(); |
| 591 |
break; |
| 592 |
|
| 593 |
case MM_FILE_SAVE_AS: |
| 594 |
myself->fileSaveAsEvent(); |
| 595 |
break; |
| 596 |
|
| 597 |
case MM_FILE_SAVE_VANILLA: |
| 598 |
myself->fileSaveVanillaEvent(); |
| 599 |
break; |
| 600 |
|
| 601 |
case MM_FILE_QUIT: |
| 602 |
myself->fileQuitEvent(); |
| 603 |
break; |
| 604 |
|
| 605 |
// |
| 606 |
// Edit |
| 607 |
// |
| 608 |
|
| 609 |
case MM_EDIT_NEW: |
| 610 |
// Add the current selection to the list of deleted objects. |
| 611 |
myWorld->addNewNoodle(); |
| 612 |
break; |
| 613 |
|
| 614 |
case MM_EDIT_DELETE: |
| 615 |
// Add the current selection to the list of deleted objects. |
| 616 |
myWorld->deleteCurrentNoodle(); |
| 617 |
// Set the primary selection to NULL... |
| 618 |
myself->setPrimarySelection(NULL); |
| 619 |
break; |
| 620 |
|
| 621 |
case MM_EDIT_UNDELETE: |
| 622 |
// Undelete the most recently deleted object. |
| 623 |
myWorld->undeleteNoodle(); |
| 624 |
break; |
| 625 |
|
| 626 |
case MM_EDIT_COPY: |
| 627 |
case MM_EDIT_COPY_ALL: |
| 628 |
// Establish what we are copying |
| 629 |
SoNode *copyStuff; |
| 630 |
if (data->id == MM_EDIT_COPY) |
| 631 |
copyStuff = myNoodle; |
| 632 |
else |
| 633 |
copyStuff = myWorld->getScene(); |
| 634 |
|
| 635 |
// Make a clipboard |
| 636 |
if (theClipboard == NULL) |
| 637 |
theClipboard = new SoXtClipboard(myself->mainViewer->getWidget()); |
| 638 |
|
| 639 |
// Copy into clipboard |
| 640 |
if ( copyStuff != NULL ) |
| 641 |
theClipboard->copy( copyStuff, cbstruct->event->xbutton.time); |
| 642 |
break; |
| 643 |
|
| 644 |
// |
| 645 |
// Options |
| 646 |
// |
| 647 |
|
| 648 |
case MM_SHAPE_FACE_SET: |
| 649 |
if ( myNoodle && XmToggleButtonGetState( data->widget ) ) { |
| 650 |
myNoodle->renderShapeType = GeneralizedCylinder::FACE_SET; |
| 651 |
myself->setRenderStyleRadioButtons( GeneralizedCylinder::FACE_SET ); |
| 652 |
} |
| 653 |
break; |
| 654 |
case MM_SHAPE_TRI_STRIP: |
| 655 |
if ( myNoodle && XmToggleButtonGetState( data->widget ) ) { |
| 656 |
myNoodle->renderShapeType = GeneralizedCylinder::TRIANGLE_STRIP_SET; |
| 657 |
myself->setRenderStyleRadioButtons(GeneralizedCylinder::TRIANGLE_STRIP_SET); |
| 658 |
} |
| 659 |
break; |
| 660 |
case MM_SHAPE_QUAD_MESH: |
| 661 |
if ( myNoodle && XmToggleButtonGetState( data->widget ) ) { |
| 662 |
myNoodle->renderShapeType = GeneralizedCylinder::QUAD_MESH; |
| 663 |
myself->setRenderStyleRadioButtons(GeneralizedCylinder::QUAD_MESH); |
| 664 |
} |
| 665 |
break; |
| 666 |
case MM_SHAPE_CUBIC_SPLINE: |
| 667 |
if ( myNoodle && XmToggleButtonGetState( data->widget ) ) { |
| 668 |
myNoodle->renderShapeType = GeneralizedCylinder::CUBIC_SPLINE_SURFACE; |
| 669 |
myself->setRenderStyleRadioButtons(GeneralizedCylinder::CUBIC_SPLINE_SURFACE); |
| 670 |
} |
| 671 |
break; |
| 672 |
case MM_SHAPE_CUBIC_TO_EDGE: |
| 673 |
if ( myNoodle && XmToggleButtonGetState( data->widget ) ) { |
| 674 |
myNoodle->renderShapeType = GeneralizedCylinder::CUBIC_TO_EDGE_SURFACE; |
| 675 |
myself->setRenderStyleRadioButtons(GeneralizedCylinder::CUBIC_TO_EDGE_SURFACE); |
| 676 |
} |
| 677 |
break; |
| 678 |
case MM_SHAPE_BEZIER: |
| 679 |
if ( myNoodle && XmToggleButtonGetState( data->widget ) ) { |
| 680 |
myNoodle->renderShapeType = GeneralizedCylinder::BEZIER_SURFACE; |
| 681 |
myself->setRenderStyleRadioButtons(GeneralizedCylinder::BEZIER_SURFACE); |
| 682 |
} |
| 683 |
break; |
| 684 |
|
| 685 |
case MM_PARTS_SIDES: |
| 686 |
if (myNoodle != NULL ) { |
| 687 |
GeneralizedCylinder *c = myNoodle; |
| 688 |
if (c->withSides.getValue()) |
| 689 |
c->withSides = FALSE; |
| 690 |
else |
| 691 |
c->withSides = TRUE; |
| 692 |
} |
| 693 |
break; |
| 694 |
case MM_PARTS_TOP_CAP: |
| 695 |
if (myNoodle != NULL ) { |
| 696 |
GeneralizedCylinder *c = myNoodle; |
| 697 |
if (c->withTopCap.getValue()) |
| 698 |
c->withTopCap = FALSE; |
| 699 |
else |
| 700 |
c->withTopCap = TRUE; |
| 701 |
} |
| 702 |
break; |
| 703 |
case MM_PARTS_BOT_CAP: |
| 704 |
if (myNoodle != NULL ) { |
| 705 |
GeneralizedCylinder *c = myNoodle; |
| 706 |
if (c->withBottomCap.getValue()) |
| 707 |
c->withBottomCap = FALSE; |
| 708 |
else |
| 709 |
c->withBottomCap = TRUE; |
| 710 |
} |
| 711 |
break; |
| 712 |
|
| 713 |
// |
| 714 |
// Manips |
| 715 |
// |
| 716 |
case MM_MANIPS_HBOX: |
| 717 |
if ( XmToggleButtonGetState( data->widget ) ) { |
| 718 |
if (myWorld->getManipType() != SoHandleBoxManip::getClassTypeId()) { |
| 719 |
|
| 720 |
// Don't show bounding box (check action type to be safe...) |
| 721 |
SoGLRenderAction *ra = myself->mainViewer->getGLRenderAction(); |
| 722 |
if (ra->isOfType( SoBoxHighlightRenderAction::getClassTypeId())) |
| 723 |
((SoBoxHighlightRenderAction *) ra)->setVisible(FALSE); |
| 724 |
|
| 725 |
myWorld->setManipType( SoHandleBoxManip::getClassTypeId() ); |
| 726 |
myself->setManipTypeRadioButtons( SoHandleBoxManip::getClassTypeId() ); |
| 727 |
} |
| 728 |
} |
| 729 |
break; |
| 730 |
case MM_MANIPS_TRACKBALL: |
| 731 |
if ( XmToggleButtonGetState( data->widget ) ) { |
| 732 |
if (myWorld->getManipType() != SoTrackballManip::getClassTypeId()) { |
| 733 |
|
| 734 |
// Don't show bounding box (check action type to be safe...) |
| 735 |
SoGLRenderAction *ra = myself->mainViewer->getGLRenderAction(); |
| 736 |
if (ra->isOfType( SoBoxHighlightRenderAction::getClassTypeId())) |
| 737 |
((SoBoxHighlightRenderAction *) ra)->setVisible(FALSE); |
| 738 |
|
| 739 |
myWorld->setManipType( SoTrackballManip::getClassTypeId() ); |
| 740 |
myself->setManipTypeRadioButtons( SoTrackballManip::getClassTypeId() ); |
| 741 |
} |
| 742 |
} |
| 743 |
break; |
| 744 |
case MM_MANIPS_NONE: |
| 745 |
if ( XmToggleButtonGetState( data->widget ) ) { |
| 746 |
if (myWorld->getManipType() != SoTransform::getClassTypeId() ) { |
| 747 |
|
| 748 |
// Do show bounding box (check renderaction type to be safe...) |
| 749 |
SoGLRenderAction *ra = myself->mainViewer->getGLRenderAction(); |
| 750 |
if (ra->isOfType( SoBoxHighlightRenderAction::getClassTypeId())) |
| 751 |
((SoBoxHighlightRenderAction *) ra)->setVisible(TRUE); |
| 752 |
|
| 753 |
myWorld->setManipType( SoTransform::getClassTypeId() ); |
| 754 |
myself->setManipTypeRadioButtons( SoTransform::getClassTypeId() ); |
| 755 |
} |
| 756 |
} |
| 757 |
break; |
| 758 |
|
| 759 |
case MM_GIZMOS_TEXTURE: |
| 760 |
{ |
| 761 |
// Create a texture gizmo, if it does not exist. |
| 762 |
if (myself->myTextureGizmo == NULL ) { |
| 763 |
myself->myTextureGizmo = new NoodleTextureGizmo(); |
| 764 |
myself->myTextureGizmo->setTitle( "Texture Gizmo" ); |
| 765 |
// Set the noodle for the gizmo. |
| 766 |
myself->myTextureGizmo->setNoodle( myNoodle ); |
| 767 |
} |
| 768 |
// Show the texture gizmo. |
| 769 |
myself->myTextureGizmo->show(); |
| 770 |
} |
| 771 |
break; |
| 772 |
|
| 773 |
case MM_GIZMOS_SURFACE: |
| 774 |
{ |
| 775 |
if (myself->mySurfaceGizmo == NULL ) { |
| 776 |
// Create a surface gizmo, if it does not exist. |
| 777 |
myself->mySurfaceGizmo = new NoodleSurfaceGizmo(); |
| 778 |
myself->mySurfaceGizmo->setTitle( "Surface Gizmo" ); |
| 779 |
// Set the noodle for the gizmo. |
| 780 |
myself->mySurfaceGizmo->setNoodle( myNoodle ); |
| 781 |
} |
| 782 |
// Show the surface gizmo. |
| 783 |
myself->mySurfaceGizmo->show(); |
| 784 |
} |
| 785 |
break; |
| 786 |
|
| 787 |
// |
| 788 |
// About |
| 789 |
// |
| 790 |
case MM_ABOUT_ABOUT: |
| 791 |
myself->showAboutDialog(); |
| 792 |
break; |
| 793 |
|
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
/////////////////////////////////////////////////////////////////// |
| 798 |
// |
| 799 |
// Makes all settings of the interface reflect the given object |
| 800 |
void |
| 801 |
Interface::setPrimarySelection( GeneralizedCylinder *g ) |
| 802 |
{ |
| 803 |
if (menuItems == NULL) |
| 804 |
return; |
| 805 |
|
| 806 |
SbBool bv; |
| 807 |
|
| 808 |
// Render Style: |
| 809 |
if (g == NULL) |
| 810 |
setRenderStyleRadioButtons( GeneralizedCylinder::FACE_SET ); |
| 811 |
else |
| 812 |
setRenderStyleRadioButtons( (GeneralizedCylinder::RenderShapeType) |
| 813 |
g->renderShapeType.getValue()); |
| 814 |
|
| 815 |
// Parts on or off: |
| 816 |
bv = (g) ? g->withSides.getValue() : FALSE; |
| 817 |
XmToggleButtonSetState( menuItems[MM_PARTS_SIDES].widget,bv,FALSE); |
| 818 |
bv = (g) ? g->withTopCap.getValue() : FALSE; |
| 819 |
XmToggleButtonSetState( menuItems[MM_PARTS_TOP_CAP].widget,bv,FALSE); |
| 820 |
bv = (g) ? g->withBottomCap.getValue() : FALSE; |
| 821 |
XmToggleButtonSetState( menuItems[MM_PARTS_BOT_CAP].widget,bv,FALSE); |
| 822 |
|
| 823 |
// Manip Type: |
| 824 |
SoNode *xf = NULL; |
| 825 |
if ( g ) |
| 826 |
xf = g->getPart( "transform", FALSE ); |
| 827 |
if ( ! xf ) |
| 828 |
setManipTypeRadioButtons( SoTransform::getClassTypeId() ); |
| 829 |
else |
| 830 |
setManipTypeRadioButtons( xf->getTypeId() ); |
| 831 |
|
| 832 |
// Texture |
| 833 |
if (myTextureGizmo) |
| 834 |
myTextureGizmo->setNoodle( g ); |
| 835 |
|
| 836 |
// Surface |
| 837 |
if (mySurfaceGizmo) |
| 838 |
mySurfaceGizmo->setNoodle( g ); |
| 839 |
|
| 840 |
// Tell the curve viewers to build new scenes... |
| 841 |
if (profileViewer) |
| 842 |
profileViewer->setSceneGraph( |
| 843 |
createProfileGraph(profileViewer->getWidget(), g)); |
| 844 |
if (sectionViewer) |
| 845 |
sectionViewer->setSceneGraph( |
| 846 |
createCrossSectionGraph(sectionViewer->getWidget(),g)); |
| 847 |
if (spineViewer) |
| 848 |
spineViewer->setSceneGraph( |
| 849 |
createSpineGraph(spineViewer->getWidget(), g)); |
| 850 |
if (twistViewer) |
| 851 |
twistViewer->setSceneGraph( |
| 852 |
createTwistGraph(twistViewer->getWidget(), g)); |
| 853 |
|
| 854 |
// Curve information for each of the four editors... |
| 855 |
bv = (g) ? g->profileClosed.getValue() : FALSE; |
| 856 |
XmToggleButtonSetState(closeProfileButton, bv, FALSE ); |
| 857 |
bv = (g) ? g->crossSectionClosed.getValue() : FALSE; |
| 858 |
XmToggleButtonSetState(closeSectionButton, bv, FALSE ); |
| 859 |
bv = (g) ? g->spineClosed.getValue() : FALSE; |
| 860 |
XmToggleButtonSetState(closeSpineButton, bv, FALSE ); |
| 861 |
bv = (g) ? g->twistClosed.getValue() : FALSE; |
| 862 |
XmToggleButtonSetState(closeTwistButton, bv, FALSE ); |
| 863 |
|
| 864 |
} |
| 865 |
|
| 866 |
void |
| 867 |
Interface::setRenderStyleRadioButtons( GeneralizedCylinder::RenderShapeType shapeType ) |
| 868 |
{ |
| 869 |
// First turn all radio buttons to FALSE... |
| 870 |
XmToggleButtonSetState(menuItems[MM_SHAPE_FACE_SET].widget,FALSE,FALSE); |
| 871 |
XmToggleButtonSetState(menuItems[MM_SHAPE_TRI_STRIP].widget,FALSE,FALSE); |
| 872 |
XmToggleButtonSetState(menuItems[MM_SHAPE_QUAD_MESH].widget,FALSE,FALSE); |
| 873 |
XmToggleButtonSetState(menuItems[MM_SHAPE_CUBIC_SPLINE].widget,FALSE,FALSE); |
| 874 |
XmToggleButtonSetState(menuItems[MM_SHAPE_CUBIC_TO_EDGE].widget,FALSE,FALSE); |
| 875 |
XmToggleButtonSetState(menuItems[MM_SHAPE_BEZIER].widget,FALSE,FALSE); |
| 876 |
|
| 877 |
// Set the appropriate radio button for shape rendering type. |
| 878 |
Widget onWidget = NULL; |
| 879 |
switch(shapeType) { |
| 880 |
case GeneralizedCylinder::FACE_SET: |
| 881 |
onWidget = menuItems[MM_SHAPE_FACE_SET].widget; |
| 882 |
break; |
| 883 |
case GeneralizedCylinder::TRIANGLE_STRIP_SET: |
| 884 |
onWidget = menuItems[MM_SHAPE_TRI_STRIP].widget; |
| 885 |
break; |
| 886 |
case GeneralizedCylinder::QUAD_MESH: |
| 887 |
onWidget = menuItems[MM_SHAPE_QUAD_MESH].widget; |
| 888 |
break; |
| 889 |
case GeneralizedCylinder::CUBIC_SPLINE_SURFACE: |
| 890 |
onWidget = menuItems[MM_SHAPE_CUBIC_SPLINE].widget; |
| 891 |
break; |
| 892 |
case GeneralizedCylinder::CUBIC_TO_EDGE_SURFACE: |
| 893 |
onWidget = menuItems[MM_SHAPE_CUBIC_TO_EDGE].widget; |
| 894 |
break; |
| 895 |
case GeneralizedCylinder::BEZIER_SURFACE: |
| 896 |
onWidget = menuItems[MM_SHAPE_BEZIER].widget; |
| 897 |
break; |
| 898 |
} |
| 899 |
if (onWidget) |
| 900 |
XmToggleButtonSetState( onWidget, TRUE, FALSE ); |
| 901 |
} |
| 902 |
|
| 903 |
void |
| 904 |
Interface::setManipTypeRadioButtons( const SoType &manipType ) |
| 905 |
{ |
| 906 |
// First turn all radio buttons to FALSE... |
| 907 |
XmToggleButtonSetState(menuItems[MM_MANIPS_HBOX].widget,FALSE,FALSE); |
| 908 |
XmToggleButtonSetState(menuItems[MM_MANIPS_TRACKBALL].widget,FALSE,FALSE); |
| 909 |
XmToggleButtonSetState(menuItems[MM_MANIPS_NONE].widget,FALSE,FALSE); |
| 910 |
|
| 911 |
// Set the appropriate radio button for manip type. |
| 912 |
Widget onWidget = NULL; |
| 913 |
if ( manipType.isDerivedFrom( SoHandleBoxManip::getClassTypeId() ) ) |
| 914 |
onWidget = menuItems[MM_MANIPS_HBOX].widget; |
| 915 |
else if ( manipType.isDerivedFrom( SoTrackballManip::getClassTypeId()) ) |
| 916 |
onWidget = menuItems[MM_MANIPS_TRACKBALL].widget; |
| 917 |
else |
| 918 |
onWidget = menuItems[MM_MANIPS_NONE].widget; |
| 919 |
|
| 920 |
if (onWidget) |
| 921 |
XmToggleButtonSetState( onWidget, TRUE, FALSE ); |
| 922 |
} |
| 923 |
|
| 924 |
/////////////////////////////////////////////////////////////////////// |
| 925 |
// |
| 926 |
// Callback registered on WorldInfo's selection node to invoke |
| 927 |
// setPrimarySelection() on the new selection. |
| 928 |
// |
| 929 |
void |
| 930 |
Interface::selectionCB( void *userData, SoPath *selectPath ) |
| 931 |
{ |
| 932 |
// Return if pickFilter truncated path down to nothing. |
| 933 |
if (selectPath->getLength() == 0) |
| 934 |
return; |
| 935 |
|
| 936 |
Interface *myself = (Interface *) userData; |
| 937 |
|
| 938 |
SoNodeKitPath *nkPath = (SoNodeKitPath *) selectPath; |
| 939 |
GeneralizedCylinder *g = (GeneralizedCylinder *) nkPath->getTail(); |
| 940 |
|
| 941 |
myself->setPrimarySelection( g ); |
| 942 |
} |
| 943 |
|
| 944 |
/////////////////////////////////////////////////////////////////////// |
| 945 |
// |
| 946 |
// Create the top menu bar and the associated menus |
| 947 |
// |
| 948 |
Widget |
| 949 |
Interface::build( Widget parentWidget ) |
| 950 |
{ |
| 951 |
mgrWidget = parentWidget; |
| 952 |
if (mgrWidget == NULL) |
| 953 |
fprintf(stderr, "Error. NULL passed to Interface::build\n"); |
| 954 |
|
| 955 |
menuItems = new NoodleMenuItem[MM_MENU_NUM]; |
| 956 |
int i; |
| 957 |
for (i=0; i<MM_MENU_NUM; i++) { |
| 958 |
menuItems[i].id = i; |
| 959 |
menuItems[i].widget = NULL; |
| 960 |
menuItems[i].ownerInterface = this; |
| 961 |
} |
| 962 |
|
| 963 |
// |
| 964 |
// Create the topbar menu |
| 965 |
// |
| 966 |
Widget menuWidget = XmCreateMenuBar(mgrWidget, "menuBar", NULL, 0); |
| 967 |
|
| 968 |
Arg popupargs[4]; |
| 969 |
int popupn = 0; |
| 970 |
#ifdef MENUS_IN_POPUP |
| 971 |
Widget shell = SoXt::getShellWidget(menuWidget); |
| 972 |
SoXt::getPopupArgs(XtDisplay(menuWidget), SCREEN(menuWidget), |
| 973 |
popupargs, &popupn); |
| 974 |
#endif |
| 975 |
|
| 976 |
int itemCount = XtNumber(pulldownData); |
| 977 |
WidgetList buttons = (WidgetList) XtMalloc(itemCount * sizeof(Widget)); |
| 978 |
|
| 979 |
|
| 980 |
Arg args[12]; |
| 981 |
int n; |
| 982 |
for (i=0; i<itemCount; i++) { |
| 983 |
// |
| 984 |
// Make Topbar menu button |
| 985 |
// |
| 986 |
Widget subMenu = |
| 987 |
XmCreatePulldownMenu(menuWidget, "subMenu", popupargs, popupn); |
| 988 |
XtSetArg(args[0], XmNtearOffModel, XmTEAR_OFF_ENABLED); |
| 989 |
XtSetValues(subMenu, args, 1); |
| 990 |
|
| 991 |
#ifdef MENUS_IN_POPUP |
| 992 |
// register callbacks to load/unload the pulldown colormap when the |
| 993 |
// pulldown menu is posted. |
| 994 |
SoXt::registerColormapLoad(subMenu, shell); |
| 995 |
#endif |
| 996 |
|
| 997 |
int id = pulldownData[i].id; |
| 998 |
menuItems[id].widget = subMenu; |
| 999 |
|
| 1000 |
XtSetArg(args[0], XmNsubMenuId, subMenu); |
| 1001 |
buttons[i] = XtCreateWidget(pulldownData[i].name, |
| 1002 |
xmCascadeButtonGadgetClass, menuWidget, args, 1); |
| 1003 |
|
| 1004 |
// |
| 1005 |
// Make subMenu buttons |
| 1006 |
// |
| 1007 |
int subItemCount = pulldownData[i].subItemCount; |
| 1008 |
WidgetList subButtons = |
| 1009 |
(WidgetList) XtMalloc(subItemCount * sizeof(Widget)); |
| 1010 |
|
| 1011 |
for (int j=0; j<subItemCount; j++) { |
| 1012 |
if (pulldownData[i].subMenu[j].buttonType == MM_SEPARATOR) { |
| 1013 |
subButtons[j] = XtCreateWidget( |
| 1014 |
NULL, xmSeparatorGadgetClass, subMenu, NULL, 0); |
| 1015 |
} |
| 1016 |
else { |
| 1017 |
String callbackReason; |
| 1018 |
|
| 1019 |
switch (pulldownData[i].subMenu[j].buttonType) { |
| 1020 |
case MM_PUSH_BUTTON: |
| 1021 |
widgetClass = xmPushButtonGadgetClass; |
| 1022 |
callbackReason = XmNactivateCallback; |
| 1023 |
n = 0; |
| 1024 |
break; |
| 1025 |
case MM_TOGGLE_BUTTON: |
| 1026 |
widgetClass = xmToggleButtonGadgetClass; |
| 1027 |
callbackReason = XmNvalueChangedCallback; |
| 1028 |
n = 0; |
| 1029 |
break; |
| 1030 |
case MM_RADIO_BUTTON: |
| 1031 |
widgetClass = xmToggleButtonGadgetClass; |
| 1032 |
callbackReason = XmNvalueChangedCallback; |
| 1033 |
XtSetArg(args[0], XmNindicatorType, XmONE_OF_MANY); |
| 1034 |
n = 1; |
| 1035 |
break; |
| 1036 |
case MM_SEPARATOR: |
| 1037 |
n = 0; |
| 1038 |
fprintf(stderr, |
| 1039 |
"Programming Error in Interface::build\n"); |
| 1040 |
break; |
| 1041 |
default: |
| 1042 |
fprintf(stderr, |
| 1043 |
"noodle INTERNAL ERROR: bad buttonType\n"); |
| 1044 |
break; |
| 1045 |
} |
| 1046 |
|
| 1047 |
// |
| 1048 |
// Check for keyboard accelerator |
| 1049 |
// |
| 1050 |
char *accel = pulldownData[i].subMenu[j].accelerator; |
| 1051 |
char *accelText = pulldownData[i].subMenu[j].accelText; |
| 1052 |
XmString xmstr = NULL; |
| 1053 |
if (accel != NULL) { |
| 1054 |
XtSetArg(args[n], XmNaccelerator, accel); n++; |
| 1055 |
|
| 1056 |
if (accelText != NULL) { |
| 1057 |
xmstr = XmStringCreate(accelText, |
| 1058 |
XmSTRING_DEFAULT_CHARSET); |
| 1059 |
XtSetArg(args[n], XmNacceleratorText, xmstr); n++; |
| 1060 |
} |
| 1061 |
} |
| 1062 |
|
| 1063 |
subButtons[j] = XtCreateWidget( |
| 1064 |
pulldownData[i].subMenu[j].name, |
| 1065 |
widgetClass, subMenu, args, n); |
| 1066 |
if (xmstr != NULL) |
| 1067 |
XmStringFree(xmstr); |
| 1068 |
id = pulldownData[i].subMenu[j].id; |
| 1069 |
menuItems[id].widget = subButtons[j]; |
| 1070 |
XtAddCallback(subButtons[j], callbackReason, |
| 1071 |
(XtCallbackProc)Interface::processTopbarEvent, |
| 1072 |
(XtPointer) &menuItems[id]); |
| 1073 |
|
| 1074 |
// If a toggle, set the starting state: |
| 1075 |
if (pulldownData[i].subMenu[j].buttonType == MM_TOGGLE_BUTTON || |
| 1076 |
pulldownData[i].subMenu[j].buttonType == MM_RADIO_BUTTON){ |
| 1077 |
SbBool isOn; |
| 1078 |
isOn = pulldownData[i].subMenu[j].isOn; |
| 1079 |
|
| 1080 |
XmToggleButtonGadgetSetState(subButtons[j], isOn, FALSE); |
| 1081 |
} |
| 1082 |
} |
| 1083 |
} |
| 1084 |
XtManageChildren(subButtons, subItemCount); |
| 1085 |
XtFree((char *)subButtons); |
| 1086 |
} |
| 1087 |
XtManageChildren(buttons, itemCount); |
| 1088 |
XtFree((char *)buttons); |
| 1089 |
|
| 1090 |
// |
| 1091 |
// Layout the menu bar |
| 1092 |
// |
| 1093 |
n = 0; |
| 1094 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 1095 |
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; |
| 1096 |
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; |
| 1097 |
XtSetValues(menuWidget, args, n); |
| 1098 |
XtManageChild(menuWidget); |
| 1099 |
|
| 1100 |
return (menuWidget); |
| 1101 |
} |