[529] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
[1347] | 27 | // $Id: G4OpenInventorXtViewer.cc,v 1.26 2010/11/10 17:53:22 allison Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $ |
---|
[529] | 29 | // |
---|
| 30 | /* |
---|
| 31 | * jck 05 Feb 1997 - Initial Implementation |
---|
| 32 | * jck 21 Apr 1997 |
---|
| 33 | * Mods for SoXtHepViewer |
---|
| 34 | * gb : on Win32 use an SoXtExaminerViewer. |
---|
| 35 | * gb 05 April 2004 : revisit to separate Windows things. |
---|
| 36 | * gb 09 November 2004 : restore the escape button. |
---|
| 37 | * gb 09 November 2004 : have a menu bar in the viewer shell. |
---|
| 38 | * gb 09 November 2004 : have gl2ps file production. |
---|
| 39 | * gb 14 November 2004 : inherit G4OpenInventorViewer. |
---|
| 40 | */ |
---|
| 41 | |
---|
| 42 | #ifdef G4VIS_BUILD_OIX_DRIVER |
---|
| 43 | |
---|
| 44 | // this : |
---|
| 45 | #include "G4OpenInventorXtViewer.hh" |
---|
| 46 | |
---|
| 47 | #include <Inventor/nodes/SoSelection.h> |
---|
| 48 | |
---|
| 49 | #include <Inventor/Xt/SoXt.h> |
---|
| 50 | #include <Inventor/Xt/viewers/SoXtExaminerViewer.h> |
---|
| 51 | |
---|
| 52 | #include <X11/StringDefs.h> |
---|
| 53 | #include <X11/Shell.h> |
---|
| 54 | |
---|
| 55 | #include <Xm/Xm.h> |
---|
| 56 | #include <Xm/PushB.h> |
---|
| 57 | #include <Xm/Form.h> |
---|
| 58 | #include <Xm/CascadeB.h> |
---|
| 59 | #include <Xm/RowColumn.h> |
---|
| 60 | #include <Xm/Text.h> |
---|
| 61 | |
---|
| 62 | #include "HEPVis/actions/SoGL2PSAction.h" |
---|
| 63 | |
---|
| 64 | #include "G4OpenInventor.hh" |
---|
| 65 | #include "G4OpenInventorSceneHandler.hh" |
---|
| 66 | #include "G4VInteractorManager.hh" |
---|
[1347] | 67 | #include "G4VisManager.hh" |
---|
[529] | 68 | |
---|
| 69 | G4OpenInventorXtViewer::G4OpenInventorXtViewer( |
---|
| 70 | G4OpenInventorSceneHandler& sceneHandler |
---|
| 71 | ,const G4String& name) |
---|
| 72 | :G4OpenInventorViewer (sceneHandler, name) |
---|
| 73 | ,fShell(0) |
---|
| 74 | ,fViewer(0) |
---|
| 75 | ,fHelpForm(0) |
---|
| 76 | ,fHelpText(0) |
---|
| 77 | { |
---|
[1347] | 78 | if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations) |
---|
| 79 | G4cout << "Window name: " << fName << G4endl; |
---|
[1097] | 80 | } |
---|
[529] | 81 | |
---|
[1097] | 82 | |
---|
| 83 | void G4OpenInventorXtViewer::Initialise() { |
---|
| 84 | |
---|
[529] | 85 | G4String wName = fName; |
---|
[1097] | 86 | |
---|
| 87 | Widget parent = (Widget)fInteractorManager->GetParentInteractor (); |
---|
| 88 | int width = 600; |
---|
| 89 | int height = 600; |
---|
[529] | 90 | |
---|
| 91 | if(!parent) { |
---|
| 92 | // Check if user has specified an X-Windows-type geometry string... |
---|
| 93 | char s[32]; |
---|
[1097] | 94 | |
---|
[529] | 95 | G4String sgeometry = fVP.GetXGeometryString(); |
---|
[1097] | 96 | if(sgeometry.empty()) { |
---|
| 97 | G4cout << "ERROR: Geometry string \"" |
---|
| 98 | << sgeometry |
---|
| 99 | << "\" is empty. Using \"600x600\"." |
---|
| 100 | << G4endl; |
---|
| 101 | width = 600; |
---|
| 102 | height = 600; |
---|
| 103 | sprintf(s,"%dx%d",width,height); |
---|
| 104 | sgeometry = s; |
---|
| 105 | } else { |
---|
| 106 | width = fVP.GetWindowSizeHintX(); |
---|
| 107 | height = fVP.GetWindowSizeHintX(); |
---|
| 108 | } |
---|
[529] | 109 | |
---|
| 110 | //Create a shell window : |
---|
| 111 | G4String shellName = wName; |
---|
| 112 | shellName += "_shell"; |
---|
| 113 | Arg args[10]; |
---|
| 114 | XtSetArg(args[0],XtNgeometry,XtNewString(sgeometry.c_str())); |
---|
| 115 | XtSetArg(args[1],XtNborderWidth,0); |
---|
| 116 | XtSetArg(args[2],XtNtitle,XtNewString(wName.c_str())); |
---|
| 117 | fShell = XtAppCreateShell(shellName.c_str(),"Inventor", |
---|
| 118 | topLevelShellWidgetClass, |
---|
| 119 | SoXt::getDisplay(), |
---|
| 120 | args,3); |
---|
| 121 | |
---|
| 122 | XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM); |
---|
| 123 | XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 124 | XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 125 | XtSetArg(args[3],XmNbottomAttachment,XmATTACH_FORM); |
---|
| 126 | Widget form = XmCreateForm (fShell,(char*)"form",args,4); |
---|
| 127 | XtManageChild (form); |
---|
| 128 | |
---|
| 129 | XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM); |
---|
| 130 | XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 131 | XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 132 | Widget menuBar = XmCreateMenuBar (form,(char*)"menuBar",args,3); |
---|
| 133 | XtManageChild(menuBar); |
---|
| 134 | |
---|
| 135 | {Widget menu = AddMenu(menuBar,"File","File"); |
---|
| 136 | AddButton(menu,"PS (gl2ps)",PostScriptCbk); |
---|
| 137 | AddButton(menu,"PS (pixmap)",PixmapPostScriptCbk); |
---|
| 138 | AddButton(menu,"IV",WriteInventorCbk); |
---|
| 139 | AddButton(menu,"Escape",EscapeCbk);} |
---|
| 140 | |
---|
| 141 | {Widget menu = AddMenu(menuBar,"Etc","Etc"); |
---|
| 142 | AddButton(menu,"Erase detector",EraseDetectorCbk); |
---|
| 143 | AddButton(menu,"Erase event",EraseEventCbk); |
---|
| 144 | AddButton(menu,"Set solid",SetSolidCbk); |
---|
| 145 | /* AddButton(menu,"Set (G4) wire frame",SetWireFrameCbk);*/ |
---|
| 146 | AddButton(menu,"Set (G4) reduced wire frame",SetReducedWireFrameCbk); |
---|
| 147 | AddButton(menu,"Set (G4) full wire frame",SetFullWireFrameCbk); |
---|
| 148 | AddButton(menu,"Visible mothers + invisible daughters",SetPreviewCbk); |
---|
| 149 | AddButton(menu,"Visible mothers + visible daughters",SetPreviewAndFullCbk); |
---|
| 150 | AddButton(menu,"Update scene",UpdateSceneCbk); |
---|
| 151 | AddButton(menu,"Scene graph stats",SceneGraphStatisticsCbk); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | {Widget menu = AddMenu(menuBar,"Help","Help"); |
---|
| 155 | AddButton(menu,"Controls",HelpCbk);} |
---|
| 156 | |
---|
| 157 | fViewer = new SoXtExaminerViewer(form,wName.c_str(),TRUE); |
---|
| 158 | |
---|
| 159 | XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET); |
---|
| 160 | XtSetArg(args[1],XmNtopWidget ,menuBar); |
---|
| 161 | XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 162 | XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 163 | XtSetArg(args[4],XmNbottomAttachment,XmATTACH_FORM); |
---|
| 164 | XtSetValues(fViewer->getWidget(),args,5); |
---|
| 165 | |
---|
| 166 | fHelpForm = XmCreateFormDialog(fShell,(char*)"help",NULL,0); |
---|
| 167 | XtSetArg(args[0],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 168 | XtSetArg(args[1],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 169 | XtSetArg(args[2],XmNbottomAttachment,XmATTACH_FORM); |
---|
| 170 | Widget cancel = XmCreatePushButton(fHelpForm,(char*)"helpCancel",args,3); |
---|
| 171 | XtAddCallback(cancel,XmNactivateCallback,HelpCancelCbk,(XtPointer)this); |
---|
| 172 | XtManageChild(cancel); |
---|
| 173 | XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM); |
---|
| 174 | XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 175 | XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 176 | XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET); |
---|
| 177 | XtSetArg(args[4],XmNbottomWidget ,cancel); |
---|
| 178 | fHelpText = XmCreateScrolledText(fHelpForm,(char*)"helpText",args,5); |
---|
| 179 | XtManageChild(fHelpText); |
---|
| 180 | |
---|
| 181 | fInteractorManager->AddShell(fShell); |
---|
| 182 | |
---|
| 183 | } else { |
---|
| 184 | char* str = fInteractorManager->GetCreationString(); |
---|
| 185 | if(str!=0) wName = str; |
---|
| 186 | fViewer = new SoXtExaminerViewer(parent,wName.c_str(),TRUE); |
---|
| 187 | } |
---|
| 188 | |
---|
[1097] | 189 | fViewer->setSize(SbVec2s(width,height)); |
---|
[529] | 190 | |
---|
| 191 | // Have a GL2PS render action : |
---|
| 192 | const SbViewportRegion& vpRegion = fViewer->getViewportRegion(); |
---|
| 193 | fGL2PSAction = new SoGL2PSAction(vpRegion); |
---|
| 194 | fViewer->setGLRenderAction(fGL2PSAction); |
---|
| 195 | |
---|
| 196 | // Else : |
---|
| 197 | fViewer->setSceneGraph(fSoSelection); |
---|
| 198 | fViewer->viewAll(); |
---|
| 199 | fViewer->saveHomePosition(); |
---|
| 200 | fViewer->setTitle(fName); |
---|
| 201 | fViewer->show(); |
---|
| 202 | if(fShell) { |
---|
| 203 | SoXt::show(fShell); |
---|
| 204 | fInteractorManager->FlushAndWaitExecution (); |
---|
| 205 | } |
---|
| 206 | fInteractorManager->SetCreatedInteractor (fViewer -> getWidget()); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | G4OpenInventorXtViewer::~G4OpenInventorXtViewer () { |
---|
| 210 | if(fShell) fInteractorManager->RemoveShell(fShell); |
---|
| 211 | if(fViewer) { |
---|
| 212 | fViewer->setSceneGraph(0); |
---|
| 213 | //FIXME : SGI : the below "delete" block things. |
---|
| 214 | //FIXME : CoinXt : the below "delete" crashe in ~SoXtRenderArea. |
---|
| 215 | //FIXME : delete fViewer; |
---|
| 216 | } |
---|
| 217 | if(fShell) XtDestroyWidget(fShell); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | void G4OpenInventorXtViewer::FinishView () { |
---|
| 221 | if(!fViewer) return; |
---|
| 222 | fViewer->viewAll(); |
---|
| 223 | fViewer->saveHomePosition(); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | void G4OpenInventorXtViewer::SetView () { |
---|
| 227 | G4OpenInventorViewer::SetView (); |
---|
| 228 | if(!fViewer) return; |
---|
| 229 | // Background. |
---|
| 230 | G4Colour b = fVP.GetBackgroundColour (); |
---|
| 231 | fViewer->setBackgroundColor |
---|
| 232 | (SbColor((float)b.GetRed(),(float)b.GetGreen(),(float)b.GetBlue())); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | void G4OpenInventorXtViewer::ViewerRender () { |
---|
| 237 | if(!fViewer) return; |
---|
| 238 | fViewer->render(); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | SoCamera* G4OpenInventorXtViewer::GetCamera () { |
---|
| 242 | if(!fViewer) return 0; |
---|
| 243 | return fViewer->getCamera(); |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | Widget G4OpenInventorXtViewer::AddMenu( |
---|
| 247 | Widget aMenuBar |
---|
| 248 | ,const G4String& aName |
---|
| 249 | ,const G4String& aLabel |
---|
| 250 | ) |
---|
| 251 | { |
---|
| 252 | // Pulldown menu : |
---|
| 253 | Widget menu = XmCreatePulldownMenu(aMenuBar,(char*)aName.c_str(),NULL,0); |
---|
| 254 | // Cascade button : |
---|
| 255 | Arg args[2]; |
---|
| 256 | XmString cps = |
---|
| 257 | XmStringLtoRCreate((char*)aLabel.c_str(),XmSTRING_DEFAULT_CHARSET); |
---|
| 258 | XtSetArg (args[0],XmNlabelString,cps); |
---|
| 259 | XtSetArg (args[1],XmNsubMenuId,menu); |
---|
| 260 | Widget widget = XmCreateCascadeButton(aMenuBar,(char*)aName.c_str(),args,2); |
---|
| 261 | XmStringFree (cps); |
---|
| 262 | XtManageChild(widget); |
---|
| 263 | return menu; |
---|
| 264 | } |
---|
| 265 | void G4OpenInventorXtViewer::AddButton ( |
---|
| 266 | Widget aMenu |
---|
| 267 | ,const G4String& aLabel |
---|
| 268 | ,XtCallbackProc aCallback |
---|
| 269 | ) |
---|
| 270 | { |
---|
| 271 | Widget widget = XmCreatePushButton(aMenu,(char*)aLabel.c_str(),NULL,0); |
---|
| 272 | XtManageChild(widget); |
---|
| 273 | XtAddCallback(widget,XmNactivateCallback,aCallback,(XtPointer)this); |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | void G4OpenInventorXtViewer::HelpCancelCbk( |
---|
| 277 | Widget,XtPointer aData,XtPointer) { |
---|
| 278 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 279 | XtUnmanageChild(This->fHelpForm); |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | |
---|
| 283 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 284 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 285 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 286 | |
---|
| 287 | void G4OpenInventorXtViewer::EscapeCbk( |
---|
| 288 | Widget,XtPointer aData,XtPointer) { |
---|
| 289 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 290 | This->Escape(); |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | void G4OpenInventorXtViewer::PostScriptCbk( |
---|
| 294 | Widget,XtPointer aData,XtPointer) { |
---|
| 295 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 296 | This->WritePostScript(); |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | void G4OpenInventorXtViewer::PixmapPostScriptCbk( |
---|
| 300 | Widget,XtPointer aData,XtPointer) { |
---|
| 301 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 302 | This->WritePixmapPostScript(); |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | void G4OpenInventorXtViewer::SceneGraphStatisticsCbk( |
---|
| 306 | Widget,XtPointer aData,XtPointer) { |
---|
| 307 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 308 | This->SceneGraphStatistics(); |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | void G4OpenInventorXtViewer::WriteInventorCbk( |
---|
| 312 | Widget,XtPointer aData,XtPointer) { |
---|
| 313 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 314 | This->WriteInventor(); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | void G4OpenInventorXtViewer::EraseDetectorCbk( |
---|
| 318 | Widget,XtPointer aData,XtPointer) { |
---|
| 319 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 320 | This->EraseDetector(); |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | void G4OpenInventorXtViewer::EraseEventCbk( |
---|
| 324 | Widget,XtPointer aData,XtPointer) { |
---|
| 325 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 326 | This->EraseEvent(); |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | void G4OpenInventorXtViewer::SetSolidCbk( |
---|
| 330 | Widget,XtPointer aData,XtPointer) { |
---|
| 331 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 332 | This->SetSolid(); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | void G4OpenInventorXtViewer::SetWireFrameCbk( |
---|
| 336 | Widget,XtPointer aData,XtPointer) { |
---|
| 337 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 338 | This->SetWireFrame(); |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | void G4OpenInventorXtViewer::SetReducedWireFrameCbk( |
---|
| 342 | Widget,XtPointer aData,XtPointer) { |
---|
| 343 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 344 | This->SetReducedWireFrame(true); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | void G4OpenInventorXtViewer::SetFullWireFrameCbk( |
---|
| 348 | Widget,XtPointer aData,XtPointer) { |
---|
| 349 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 350 | This->SetReducedWireFrame(false); |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | void G4OpenInventorXtViewer::UpdateSceneCbk( |
---|
| 354 | Widget,XtPointer aData,XtPointer) { |
---|
| 355 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 356 | This->UpdateScene(); |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | void G4OpenInventorXtViewer::SetPreviewCbk( |
---|
| 360 | Widget,XtPointer aData,XtPointer) { |
---|
| 361 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 362 | This->SetPreview(); |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | void G4OpenInventorXtViewer::SetPreviewAndFullCbk( |
---|
| 366 | Widget,XtPointer aData,XtPointer) { |
---|
| 367 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 368 | This->SetPreviewAndFull(); |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | void G4OpenInventorXtViewer::HelpCbk( |
---|
| 372 | Widget,XtPointer aData,XtPointer) { |
---|
| 373 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 374 | XtManageChild(This->fHelpForm); |
---|
| 375 | XmTextSetString(This->fHelpText,(char*)This->Help().c_str()); |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | #endif |
---|
| 380 | |
---|
| 381 | |
---|