40 #ifdef G4VIS_BUILD_OIX_DRIVER
45 #include <Inventor/nodes/SoSelection.h>
47 #include <Inventor/Xt/SoXt.h>
50 #include <Inventor/Xt/viewers/SoXtFlyViewer.h>
52 #include <X11/StringDefs.h>
53 #include <X11/Shell.h>
58 #include <Xm/CascadeB.h>
59 #include <Xm/RowColumn.h>
73 G4OpenInventorXtExtendedViewer::G4OpenInventorXtExtendedViewer(
74 G4OpenInventorSceneHandler& sceneHandler
76 :G4OpenInventorViewer (sceneHandler, name)
87 void G4OpenInventorXtExtendedViewer::Initialise() {
91 Widget parent = (Widget)fInteractorManager->GetParentInteractor ();
100 G4String sgeometry = fVP.GetXGeometryString();
101 if(sgeometry.empty()) {
102 G4cout <<
"ERROR: Geometry string \""
104 <<
"\" is empty. Using \"600x600\"."
108 sprintf(s,
"%dx%d",width,height);
111 width = fVP.GetWindowSizeHintX();
112 height = fVP.GetWindowSizeHintX();
117 shellName +=
"_shell";
119 XtSetArg(args[0],XtNgeometry,XtNewString(sgeometry.c_str()));
120 XtSetArg(args[1],XtNborderWidth,0);
121 XtSetArg(args[2],XtNtitle,XtNewString(wName.c_str()));
122 fShell = XtAppCreateShell(shellName.c_str(),
"Inventor",
123 topLevelShellWidgetClass,
141 Widget menuBar = fViewer->getMenuBar();
149 {Widget menu = fViewer->getMenu();
151 AddButton(menu,
"Write PS (gl2ps)",PostScriptCbk);
152 AddButton(menu,
"Write PDF (gl2ps)", PDFCbk);
153 AddButton(menu,
"Write PS (pixmap)",PixmapPostScriptCbk);
154 AddButton(menu,
"Write IV",WriteInventorCbk);
155 AddButton(menu,
"Escape",EscapeCbk);}
157 {Widget menu = AddMenu(menuBar,
"Etc",
"Etc");
158 AddButton(menu,
"Erase detector",EraseDetectorCbk);
159 AddButton(menu,
"Erase event",EraseEventCbk);
160 AddButton(menu,
"Set solid",SetSolidCbk);
162 AddButton(menu,
"Set (G4) reduced wire frame",SetReducedWireFrameCbk);
163 AddButton(menu,
"Set (G4) full wire frame",SetFullWireFrameCbk);
164 AddButton(menu,
"Visible mothers + invisible daughters",SetPreviewCbk);
165 AddButton(menu,
"Visible mothers + visible daughters",SetPreviewAndFullCbk);
166 AddButton(menu,
"Update scene",UpdateSceneCbk);
167 AddButton(menu,
"Scene graph stats",SceneGraphStatisticsCbk);
170 {Widget menu = AddMenu(menuBar,
"Help",
"Help");
171 AddButton(menu,
"Controls",HelpCbk);}
175 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET);
176 XtSetArg(args[1],XmNtopWidget ,menuBar);
177 XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM);
178 XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
179 XtSetArg(args[4],XmNbottomAttachment,XmATTACH_FORM);
180 XtSetValues(fViewer->getWidget(),args,5);
182 fHelpForm = XmCreateFormDialog(fShell,(
char*)
"help",NULL,0);
183 XtSetArg(args[0],XmNleftAttachment ,XmATTACH_FORM);
184 XtSetArg(args[1],XmNrightAttachment ,XmATTACH_FORM);
185 XtSetArg(args[2],XmNbottomAttachment,XmATTACH_FORM);
186 Widget cancel = XmCreatePushButton(fHelpForm,(
char*)
"helpCancel",args,3);
187 XtAddCallback(cancel,XmNactivateCallback,HelpCancelCbk,(XtPointer)
this);
188 XtManageChild(cancel);
189 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
190 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
191 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
192 XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
193 XtSetArg(args[4],XmNbottomWidget ,cancel);
194 fHelpText = XmCreateScrolledText(fHelpForm,(
char*)
"helpText",args,5);
195 XtManageChild(fHelpText);
197 fInteractorManager->AddShell(fShell);
200 char* str = fInteractorManager->GetCreationString();
201 if(str!=0) wName = str;
208 fSoSelection->removeSelectionCallback(G4OpenInventorViewer::SelectionCB,
212 fViewer->setSize(SbVec2s(width,height));
215 const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
217 fViewer->setGLRenderAction(fGL2PSAction);
220 fViewer->setSceneGraph(fSoSelection);
222 fViewer->saveHomePosition();
223 fViewer->setTitle(
fName);
227 fInteractorManager->FlushAndWaitExecution ();
229 fInteractorManager->SetCreatedInteractor (fViewer -> getWidget());
231 fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
234 G4OpenInventorXtExtendedViewer::~G4OpenInventorXtExtendedViewer () {
235 if(fShell) fInteractorManager->RemoveShell(fShell);
237 fViewer->setSceneGraph(0);
242 if(fShell) XtDestroyWidget(fShell);
245 void G4OpenInventorXtExtendedViewer::FinishView () {
248 fViewer->saveHomePosition();
251 void G4OpenInventorXtExtendedViewer::SetView () {
252 G4OpenInventorViewer::SetView ();
255 G4Colour b = fVP.GetBackgroundColour ();
256 fViewer->setBackgroundColor
261 void G4OpenInventorXtExtendedViewer::ViewerRender () {
266 SoCamera* G4OpenInventorXtExtendedViewer::GetCamera () {
267 if(!fViewer)
return 0;
268 return fViewer->getCamera();
271 Widget G4OpenInventorXtExtendedViewer::AddMenu(
278 Widget menu = XmCreatePulldownMenu(aMenuBar,(
char*)aName.c_str(),NULL,0);
282 XmStringLtoRCreate((
char*)aLabel.c_str(),(
char*)XmSTRING_DEFAULT_CHARSET);
283 XtSetArg (args[0],XmNlabelString,cps);
284 XtSetArg (args[1],XmNsubMenuId,menu);
285 Widget widget = XmCreateCascadeButton(aMenuBar,(
char*)aName.c_str(),args,2);
287 XtManageChild(widget);
290 void G4OpenInventorXtExtendedViewer::AddButton (
293 ,XtCallbackProc aCallback
296 Widget widget = XmCreatePushButton(aMenu,(
char*)aLabel.c_str(),NULL,0);
297 XtManageChild(widget);
298 XtAddCallback(widget,XmNactivateCallback,aCallback,(XtPointer)
this);
301 void G4OpenInventorXtExtendedViewer::HelpCancelCbk(
302 Widget,XtPointer aData,XtPointer) {
303 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
304 XtUnmanageChild(This->fHelpForm);
312 void G4OpenInventorXtExtendedViewer::EscapeCbk(
313 Widget,XtPointer aData,XtPointer) {
314 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
319 void G4OpenInventorXtExtendedViewer::EscapeFromKeyboardCbk(
void* o) {
320 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)o;
324 void G4OpenInventorXtExtendedViewer::PostScriptCbk(
325 Widget,XtPointer aData,XtPointer) {
326 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
328 SbBool superimpState =
329 This->fViewer->getSuperimpositionEnabled(This->fViewer->superimposition);
330 This->fViewer->setSuperimpositionEnabled(This->fViewer->superimposition,
332 This->WritePostScript();
334 This->fViewer->setSuperimpositionEnabled(This->fViewer->superimposition,
337 void G4OpenInventorXtExtendedViewer::PDFCbk(
338 Widget,XtPointer aData,XtPointer) {
339 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
341 SbBool superimpState =
342 This->fViewer->getSuperimpositionEnabled(This->fViewer->superimposition);
343 This->fViewer->setSuperimpositionEnabled(This->fViewer->superimposition,
347 This->fViewer->setSuperimpositionEnabled(This->fViewer->superimposition,
351 void G4OpenInventorXtExtendedViewer::PixmapPostScriptCbk(
352 Widget,XtPointer aData,XtPointer) {
353 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
354 This->WritePixmapPostScript();
357 void G4OpenInventorXtExtendedViewer::SceneGraphStatisticsCbk(
358 Widget,XtPointer aData,XtPointer) {
359 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
360 This->SceneGraphStatistics();
363 void G4OpenInventorXtExtendedViewer::WriteInventorCbk(
364 Widget,XtPointer aData,XtPointer) {
365 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
366 This->WriteInventor();
369 void G4OpenInventorXtExtendedViewer::EraseDetectorCbk(
370 Widget,XtPointer aData,XtPointer) {
371 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
372 This->EraseDetector();
375 void G4OpenInventorXtExtendedViewer::EraseEventCbk(
376 Widget,XtPointer aData,XtPointer) {
377 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
381 void G4OpenInventorXtExtendedViewer::SetSolidCbk(
382 Widget,XtPointer aData,XtPointer) {
383 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
387 void G4OpenInventorXtExtendedViewer::SetWireFrameCbk(
388 Widget,XtPointer aData,XtPointer) {
389 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
390 This->SetWireFrame();
393 void G4OpenInventorXtExtendedViewer::SetReducedWireFrameCbk(
394 Widget,XtPointer aData,XtPointer) {
395 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
396 This->SetReducedWireFrame(
true);
399 void G4OpenInventorXtExtendedViewer::SetFullWireFrameCbk(
400 Widget,XtPointer aData,XtPointer) {
401 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
402 This->SetReducedWireFrame(
false);
405 void G4OpenInventorXtExtendedViewer::UpdateSceneCbk(
406 Widget,XtPointer aData,XtPointer) {
407 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
411 void G4OpenInventorXtExtendedViewer::SetPreviewCbk(
412 Widget,XtPointer aData,XtPointer) {
413 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
417 void G4OpenInventorXtExtendedViewer::SetPreviewAndFullCbk(
418 Widget,XtPointer aData,XtPointer) {
419 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
420 This->SetPreviewAndFull();
423 void G4OpenInventorXtExtendedViewer::HelpCbk(
424 Widget,XtPointer aData,XtPointer) {
425 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
426 XtManageChild(This->fHelpForm);
427 XmTextSetString(This->fHelpText,(
char*)This->Help().c_str());
G4GLOB_DLL std::ostream G4cout
G4double GetGreen() const
static Verbosity GetVerbosity()
void addEscapeCallback(void(*cb)(void *), void *)