[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 | // |
---|
| 27 | // $Id: G4OpenInventorXtViewer.cc,v 1.24 2006/06/29 21:22:26 gunter Exp $ |
---|
[850] | 28 | // GEANT4 tag $Name: HEAD $ |
---|
[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" |
---|
| 67 | |
---|
| 68 | G4OpenInventorXtViewer::G4OpenInventorXtViewer( |
---|
| 69 | G4OpenInventorSceneHandler& sceneHandler |
---|
| 70 | ,const G4String& name) |
---|
| 71 | :G4OpenInventorViewer (sceneHandler, name) |
---|
| 72 | ,fShell(0) |
---|
| 73 | ,fViewer(0) |
---|
| 74 | ,fHelpForm(0) |
---|
| 75 | ,fHelpText(0) |
---|
| 76 | { |
---|
| 77 | G4cout << "Window name: " << fName << G4endl; |
---|
| 78 | |
---|
| 79 | G4String wName = fName; |
---|
| 80 | |
---|
| 81 | #define SIZE 600 |
---|
| 82 | Widget parent = (Widget)fInteractorManager->GetParentInteractor (); |
---|
| 83 | if(!parent) { |
---|
| 84 | // Check if user has specified an X-Windows-type geometry string... |
---|
| 85 | char s[32]; |
---|
| 86 | sprintf(s,"%dx%d",SIZE,SIZE); |
---|
| 87 | G4String sgeometry = fVP.GetXGeometryString(); |
---|
| 88 | if(sgeometry.empty()) sgeometry = s; |
---|
| 89 | |
---|
| 90 | //Create a shell window : |
---|
| 91 | G4String shellName = wName; |
---|
| 92 | shellName += "_shell"; |
---|
| 93 | Arg args[10]; |
---|
| 94 | XtSetArg(args[0],XtNgeometry,XtNewString(sgeometry.c_str())); |
---|
| 95 | XtSetArg(args[1],XtNborderWidth,0); |
---|
| 96 | XtSetArg(args[2],XtNtitle,XtNewString(wName.c_str())); |
---|
| 97 | fShell = XtAppCreateShell(shellName.c_str(),"Inventor", |
---|
| 98 | topLevelShellWidgetClass, |
---|
| 99 | SoXt::getDisplay(), |
---|
| 100 | args,3); |
---|
| 101 | |
---|
| 102 | XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM); |
---|
| 103 | XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 104 | XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 105 | XtSetArg(args[3],XmNbottomAttachment,XmATTACH_FORM); |
---|
| 106 | Widget form = XmCreateForm (fShell,(char*)"form",args,4); |
---|
| 107 | XtManageChild (form); |
---|
| 108 | |
---|
| 109 | XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM); |
---|
| 110 | XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 111 | XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 112 | Widget menuBar = XmCreateMenuBar (form,(char*)"menuBar",args,3); |
---|
| 113 | XtManageChild(menuBar); |
---|
| 114 | |
---|
| 115 | {Widget menu = AddMenu(menuBar,"File","File"); |
---|
| 116 | AddButton(menu,"PS (gl2ps)",PostScriptCbk); |
---|
| 117 | AddButton(menu,"PS (pixmap)",PixmapPostScriptCbk); |
---|
| 118 | AddButton(menu,"IV",WriteInventorCbk); |
---|
| 119 | AddButton(menu,"Escape",EscapeCbk);} |
---|
| 120 | |
---|
| 121 | {Widget menu = AddMenu(menuBar,"Etc","Etc"); |
---|
| 122 | AddButton(menu,"Erase detector",EraseDetectorCbk); |
---|
| 123 | AddButton(menu,"Erase event",EraseEventCbk); |
---|
| 124 | AddButton(menu,"Set solid",SetSolidCbk); |
---|
| 125 | /* AddButton(menu,"Set (G4) wire frame",SetWireFrameCbk);*/ |
---|
| 126 | AddButton(menu,"Set (G4) reduced wire frame",SetReducedWireFrameCbk); |
---|
| 127 | AddButton(menu,"Set (G4) full wire frame",SetFullWireFrameCbk); |
---|
| 128 | AddButton(menu,"Visible mothers + invisible daughters",SetPreviewCbk); |
---|
| 129 | AddButton(menu,"Visible mothers + visible daughters",SetPreviewAndFullCbk); |
---|
| 130 | AddButton(menu,"Update scene",UpdateSceneCbk); |
---|
| 131 | AddButton(menu,"Scene graph stats",SceneGraphStatisticsCbk); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | {Widget menu = AddMenu(menuBar,"Help","Help"); |
---|
| 135 | AddButton(menu,"Controls",HelpCbk);} |
---|
| 136 | |
---|
| 137 | fViewer = new SoXtExaminerViewer(form,wName.c_str(),TRUE); |
---|
| 138 | |
---|
| 139 | XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET); |
---|
| 140 | XtSetArg(args[1],XmNtopWidget ,menuBar); |
---|
| 141 | XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 142 | XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 143 | XtSetArg(args[4],XmNbottomAttachment,XmATTACH_FORM); |
---|
| 144 | XtSetValues(fViewer->getWidget(),args,5); |
---|
| 145 | |
---|
| 146 | fHelpForm = XmCreateFormDialog(fShell,(char*)"help",NULL,0); |
---|
| 147 | XtSetArg(args[0],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 148 | XtSetArg(args[1],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 149 | XtSetArg(args[2],XmNbottomAttachment,XmATTACH_FORM); |
---|
| 150 | Widget cancel = XmCreatePushButton(fHelpForm,(char*)"helpCancel",args,3); |
---|
| 151 | XtAddCallback(cancel,XmNactivateCallback,HelpCancelCbk,(XtPointer)this); |
---|
| 152 | XtManageChild(cancel); |
---|
| 153 | XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM); |
---|
| 154 | XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 155 | XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 156 | XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET); |
---|
| 157 | XtSetArg(args[4],XmNbottomWidget ,cancel); |
---|
| 158 | fHelpText = XmCreateScrolledText(fHelpForm,(char*)"helpText",args,5); |
---|
| 159 | XtManageChild(fHelpText); |
---|
| 160 | |
---|
| 161 | fInteractorManager->AddShell(fShell); |
---|
| 162 | |
---|
| 163 | } else { |
---|
| 164 | char* str = fInteractorManager->GetCreationString(); |
---|
| 165 | if(str!=0) wName = str; |
---|
| 166 | fViewer = new SoXtExaminerViewer(parent,wName.c_str(),TRUE); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | fViewer->setSize(SbVec2s(SIZE,SIZE)); |
---|
| 170 | |
---|
| 171 | // Have a GL2PS render action : |
---|
| 172 | const SbViewportRegion& vpRegion = fViewer->getViewportRegion(); |
---|
| 173 | fGL2PSAction = new SoGL2PSAction(vpRegion); |
---|
| 174 | fViewer->setGLRenderAction(fGL2PSAction); |
---|
| 175 | |
---|
| 176 | // Else : |
---|
| 177 | fViewer->setSceneGraph(fSoSelection); |
---|
| 178 | fViewer->viewAll(); |
---|
| 179 | fViewer->saveHomePosition(); |
---|
| 180 | fViewer->setTitle(fName); |
---|
| 181 | fViewer->show(); |
---|
| 182 | if(fShell) { |
---|
| 183 | SoXt::show(fShell); |
---|
| 184 | fInteractorManager->FlushAndWaitExecution (); |
---|
| 185 | } |
---|
| 186 | fInteractorManager->SetCreatedInteractor (fViewer -> getWidget()); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | G4OpenInventorXtViewer::~G4OpenInventorXtViewer () { |
---|
| 190 | if(fShell) fInteractorManager->RemoveShell(fShell); |
---|
| 191 | if(fViewer) { |
---|
| 192 | fViewer->setSceneGraph(0); |
---|
| 193 | //FIXME : SGI : the below "delete" block things. |
---|
| 194 | //FIXME : CoinXt : the below "delete" crashe in ~SoXtRenderArea. |
---|
| 195 | //FIXME : delete fViewer; |
---|
| 196 | } |
---|
| 197 | if(fShell) XtDestroyWidget(fShell); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | void G4OpenInventorXtViewer::FinishView () { |
---|
| 201 | if(!fViewer) return; |
---|
| 202 | fViewer->viewAll(); |
---|
| 203 | fViewer->saveHomePosition(); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | void G4OpenInventorXtViewer::SetView () { |
---|
| 207 | G4OpenInventorViewer::SetView (); |
---|
| 208 | if(!fViewer) return; |
---|
| 209 | // Background. |
---|
| 210 | G4Colour b = fVP.GetBackgroundColour (); |
---|
| 211 | fViewer->setBackgroundColor |
---|
| 212 | (SbColor((float)b.GetRed(),(float)b.GetGreen(),(float)b.GetBlue())); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | void G4OpenInventorXtViewer::ViewerRender () { |
---|
| 217 | if(!fViewer) return; |
---|
| 218 | fViewer->render(); |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | SoCamera* G4OpenInventorXtViewer::GetCamera () { |
---|
| 222 | if(!fViewer) return 0; |
---|
| 223 | return fViewer->getCamera(); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | Widget G4OpenInventorXtViewer::AddMenu( |
---|
| 227 | Widget aMenuBar |
---|
| 228 | ,const G4String& aName |
---|
| 229 | ,const G4String& aLabel |
---|
| 230 | ) |
---|
| 231 | { |
---|
| 232 | // Pulldown menu : |
---|
| 233 | Widget menu = XmCreatePulldownMenu(aMenuBar,(char*)aName.c_str(),NULL,0); |
---|
| 234 | // Cascade button : |
---|
| 235 | Arg args[2]; |
---|
| 236 | XmString cps = |
---|
| 237 | XmStringLtoRCreate((char*)aLabel.c_str(),XmSTRING_DEFAULT_CHARSET); |
---|
| 238 | XtSetArg (args[0],XmNlabelString,cps); |
---|
| 239 | XtSetArg (args[1],XmNsubMenuId,menu); |
---|
| 240 | Widget widget = XmCreateCascadeButton(aMenuBar,(char*)aName.c_str(),args,2); |
---|
| 241 | XmStringFree (cps); |
---|
| 242 | XtManageChild(widget); |
---|
| 243 | return menu; |
---|
| 244 | } |
---|
| 245 | void G4OpenInventorXtViewer::AddButton ( |
---|
| 246 | Widget aMenu |
---|
| 247 | ,const G4String& aLabel |
---|
| 248 | ,XtCallbackProc aCallback |
---|
| 249 | ) |
---|
| 250 | { |
---|
| 251 | Widget widget = XmCreatePushButton(aMenu,(char*)aLabel.c_str(),NULL,0); |
---|
| 252 | XtManageChild(widget); |
---|
| 253 | XtAddCallback(widget,XmNactivateCallback,aCallback,(XtPointer)this); |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | void G4OpenInventorXtViewer::HelpCancelCbk( |
---|
| 257 | Widget,XtPointer aData,XtPointer) { |
---|
| 258 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 259 | XtUnmanageChild(This->fHelpForm); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | |
---|
| 263 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 264 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 265 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 266 | |
---|
| 267 | void G4OpenInventorXtViewer::EscapeCbk( |
---|
| 268 | Widget,XtPointer aData,XtPointer) { |
---|
| 269 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 270 | This->Escape(); |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | void G4OpenInventorXtViewer::PostScriptCbk( |
---|
| 274 | Widget,XtPointer aData,XtPointer) { |
---|
| 275 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 276 | This->WritePostScript(); |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | void G4OpenInventorXtViewer::PixmapPostScriptCbk( |
---|
| 280 | Widget,XtPointer aData,XtPointer) { |
---|
| 281 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 282 | This->WritePixmapPostScript(); |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | void G4OpenInventorXtViewer::SceneGraphStatisticsCbk( |
---|
| 286 | Widget,XtPointer aData,XtPointer) { |
---|
| 287 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 288 | This->SceneGraphStatistics(); |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | void G4OpenInventorXtViewer::WriteInventorCbk( |
---|
| 292 | Widget,XtPointer aData,XtPointer) { |
---|
| 293 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 294 | This->WriteInventor(); |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | void G4OpenInventorXtViewer::EraseDetectorCbk( |
---|
| 298 | Widget,XtPointer aData,XtPointer) { |
---|
| 299 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 300 | This->EraseDetector(); |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | void G4OpenInventorXtViewer::EraseEventCbk( |
---|
| 304 | Widget,XtPointer aData,XtPointer) { |
---|
| 305 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 306 | This->EraseEvent(); |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | void G4OpenInventorXtViewer::SetSolidCbk( |
---|
| 310 | Widget,XtPointer aData,XtPointer) { |
---|
| 311 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 312 | This->SetSolid(); |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | void G4OpenInventorXtViewer::SetWireFrameCbk( |
---|
| 316 | Widget,XtPointer aData,XtPointer) { |
---|
| 317 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 318 | This->SetWireFrame(); |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | void G4OpenInventorXtViewer::SetReducedWireFrameCbk( |
---|
| 322 | Widget,XtPointer aData,XtPointer) { |
---|
| 323 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 324 | This->SetReducedWireFrame(true); |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | void G4OpenInventorXtViewer::SetFullWireFrameCbk( |
---|
| 328 | Widget,XtPointer aData,XtPointer) { |
---|
| 329 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 330 | This->SetReducedWireFrame(false); |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | void G4OpenInventorXtViewer::UpdateSceneCbk( |
---|
| 334 | Widget,XtPointer aData,XtPointer) { |
---|
| 335 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 336 | This->UpdateScene(); |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | void G4OpenInventorXtViewer::SetPreviewCbk( |
---|
| 340 | Widget,XtPointer aData,XtPointer) { |
---|
| 341 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 342 | This->SetPreview(); |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | void G4OpenInventorXtViewer::SetPreviewAndFullCbk( |
---|
| 346 | Widget,XtPointer aData,XtPointer) { |
---|
| 347 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 348 | This->SetPreviewAndFull(); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | void G4OpenInventorXtViewer::HelpCbk( |
---|
| 352 | Widget,XtPointer aData,XtPointer) { |
---|
| 353 | G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData; |
---|
| 354 | XtManageChild(This->fHelpForm); |
---|
| 355 | XmTextSetString(This->fHelpText,(char*)This->Help().c_str()); |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | |
---|
| 359 | #endif |
---|
| 360 | |
---|
| 361 | |
---|