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>
71 G4OpenInventorXtExtendedViewer::G4OpenInventorXtExtendedViewer(
72 G4OpenInventorSceneHandler& sceneHandler
74 :G4OpenInventorViewer (sceneHandler, name)
85 void G4OpenInventorXtExtendedViewer::Initialise() {
89 Widget parent = (Widget)fInteractorManager->GetParentInteractor ();
97 G4String sgeometry = fVP.GetXGeometryString();
98 if(sgeometry.empty()) {
99 G4cout <<
"ERROR: Geometry string \""
101 <<
"\" is empty. Using \"600x600\"."
105 sprintf(s,
"%dx%d",width,height);
108 width = fVP.GetWindowSizeHintX();
109 height = fVP.GetWindowSizeHintX();
114 shellName +=
"_shell";
116 XtSetArg(args[0],XtNgeometry,XtNewString(sgeometry.c_str()));
117 XtSetArg(args[1],XtNborderWidth,0);
118 XtSetArg(args[2],XtNtitle,XtNewString(wName.c_str()));
119 fShell = XtAppCreateShell(shellName.c_str(),
"Inventor",
120 topLevelShellWidgetClass,
137 Widget menuBar = fViewer->getMenuBar();
145 {Widget menu = fViewer->getMenu();
147 AddButton(menu,
"PS (gl2ps)",PostScriptCbk);
148 AddButton(menu,
"PS (pixmap)",PixmapPostScriptCbk);
149 AddButton(menu,
"Write IV",WriteInventorCbk);
150 AddButton(menu,
"Escape",EscapeCbk);}
152 {Widget menu = AddMenu(menuBar,
"Etc",
"Etc");
153 AddButton(menu,
"Erase detector",EraseDetectorCbk);
154 AddButton(menu,
"Erase event",EraseEventCbk);
155 AddButton(menu,
"Set solid",SetSolidCbk);
157 AddButton(menu,
"Set (G4) reduced wire frame",SetReducedWireFrameCbk);
158 AddButton(menu,
"Set (G4) full wire frame",SetFullWireFrameCbk);
159 AddButton(menu,
"Visible mothers + invisible daughters",SetPreviewCbk);
160 AddButton(menu,
"Visible mothers + visible daughters",SetPreviewAndFullCbk);
161 AddButton(menu,
"Update scene",UpdateSceneCbk);
162 AddButton(menu,
"Scene graph stats",SceneGraphStatisticsCbk);
165 {Widget menu = AddMenu(menuBar,
"Help",
"Help");
166 AddButton(menu,
"Controls",HelpCbk);}
170 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET);
171 XtSetArg(args[1],XmNtopWidget ,menuBar);
172 XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM);
173 XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
174 XtSetArg(args[4],XmNbottomAttachment,XmATTACH_FORM);
175 XtSetValues(fViewer->getWidget(),args,5);
177 fHelpForm = XmCreateFormDialog(fShell,(
char*)
"help",NULL,0);
178 XtSetArg(args[0],XmNleftAttachment ,XmATTACH_FORM);
179 XtSetArg(args[1],XmNrightAttachment ,XmATTACH_FORM);
180 XtSetArg(args[2],XmNbottomAttachment,XmATTACH_FORM);
181 Widget cancel = XmCreatePushButton(fHelpForm,(
char*)
"helpCancel",args,3);
182 XtAddCallback(cancel,XmNactivateCallback,HelpCancelCbk,(XtPointer)
this);
183 XtManageChild(cancel);
184 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
185 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
186 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
187 XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
188 XtSetArg(args[4],XmNbottomWidget ,cancel);
189 fHelpText = XmCreateScrolledText(fHelpForm,(
char*)
"helpText",args,5);
190 XtManageChild(fHelpText);
192 fInteractorManager->AddShell(fShell);
195 char* str = fInteractorManager->GetCreationString();
196 if(str!=0) wName = str;
202 fSoSelection->removeSelectionCallback(G4OpenInventorViewer::SelectionCB,
206 fViewer->setSize(SbVec2s(width,height));
209 const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
211 fViewer->setGLRenderAction(fGL2PSAction);
214 fViewer->setSceneGraph(fSoSelection);
216 fViewer->saveHomePosition();
217 fViewer->setTitle(
fName);
221 fInteractorManager->FlushAndWaitExecution ();
223 fInteractorManager->SetCreatedInteractor (fViewer -> getWidget());
225 fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
228 G4OpenInventorXtExtendedViewer::~G4OpenInventorXtExtendedViewer () {
229 if(fShell) fInteractorManager->RemoveShell(fShell);
231 fViewer->setSceneGraph(0);
236 if(fShell) XtDestroyWidget(fShell);
239 void G4OpenInventorXtExtendedViewer::FinishView () {
242 fViewer->saveHomePosition();
245 void G4OpenInventorXtExtendedViewer::SetView () {
246 G4OpenInventorViewer::SetView ();
250 fViewer->setBackgroundColor
255 void G4OpenInventorXtExtendedViewer::ViewerRender () {
260 SoCamera* G4OpenInventorXtExtendedViewer::GetCamera () {
261 if(!fViewer)
return 0;
262 return fViewer->getCamera();
265 Widget G4OpenInventorXtExtendedViewer::AddMenu(
272 Widget menu = XmCreatePulldownMenu(aMenuBar,(
char*)aName.c_str(),NULL,0);
276 XmStringLtoRCreate((
char*)aLabel.c_str(),XmSTRING_DEFAULT_CHARSET);
277 XtSetArg (args[0],XmNlabelString,cps);
278 XtSetArg (args[1],XmNsubMenuId,menu);
279 Widget widget = XmCreateCascadeButton(aMenuBar,(
char*)aName.c_str(),args,2);
281 XtManageChild(widget);
284 void G4OpenInventorXtExtendedViewer::AddButton (
287 ,XtCallbackProc aCallback
290 Widget widget = XmCreatePushButton(aMenu,(
char*)aLabel.c_str(),NULL,0);
291 XtManageChild(widget);
292 XtAddCallback(widget,XmNactivateCallback,aCallback,(XtPointer)
this);
295 void G4OpenInventorXtExtendedViewer::HelpCancelCbk(
296 Widget,XtPointer aData,XtPointer) {
297 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
298 XtUnmanageChild(This->fHelpForm);
306 void G4OpenInventorXtExtendedViewer::EscapeCbk(
307 Widget,XtPointer aData,XtPointer) {
308 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
313 void G4OpenInventorXtExtendedViewer::EscapeFromKeyboardCbk(
void* o) {
314 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)o;
318 void G4OpenInventorXtExtendedViewer::PostScriptCbk(
319 Widget,XtPointer aData,XtPointer) {
320 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
321 This->WritePostScript();
324 void G4OpenInventorXtExtendedViewer::PixmapPostScriptCbk(
325 Widget,XtPointer aData,XtPointer) {
326 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
327 This->WritePixmapPostScript();
330 void G4OpenInventorXtExtendedViewer::SceneGraphStatisticsCbk(
331 Widget,XtPointer aData,XtPointer) {
332 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
333 This->SceneGraphStatistics();
336 void G4OpenInventorXtExtendedViewer::WriteInventorCbk(
337 Widget,XtPointer aData,XtPointer) {
338 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
339 This->WriteInventor();
342 void G4OpenInventorXtExtendedViewer::EraseDetectorCbk(
343 Widget,XtPointer aData,XtPointer) {
344 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
345 This->EraseDetector();
348 void G4OpenInventorXtExtendedViewer::EraseEventCbk(
349 Widget,XtPointer aData,XtPointer) {
350 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
354 void G4OpenInventorXtExtendedViewer::SetSolidCbk(
355 Widget,XtPointer aData,XtPointer) {
356 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
360 void G4OpenInventorXtExtendedViewer::SetWireFrameCbk(
361 Widget,XtPointer aData,XtPointer) {
362 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
363 This->SetWireFrame();
366 void G4OpenInventorXtExtendedViewer::SetReducedWireFrameCbk(
367 Widget,XtPointer aData,XtPointer) {
368 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
369 This->SetReducedWireFrame(
true);
372 void G4OpenInventorXtExtendedViewer::SetFullWireFrameCbk(
373 Widget,XtPointer aData,XtPointer) {
374 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
375 This->SetReducedWireFrame(
false);
378 void G4OpenInventorXtExtendedViewer::UpdateSceneCbk(
379 Widget,XtPointer aData,XtPointer) {
380 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
384 void G4OpenInventorXtExtendedViewer::SetPreviewCbk(
385 Widget,XtPointer aData,XtPointer) {
386 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
390 void G4OpenInventorXtExtendedViewer::SetPreviewAndFullCbk(
391 Widget,XtPointer aData,XtPointer) {
392 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
393 This->SetPreviewAndFull();
396 void G4OpenInventorXtExtendedViewer::HelpCbk(
397 Widget,XtPointer aData,XtPointer) {
398 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
399 XtManageChild(This->fHelpForm);
400 XmTextSetString(This->fHelpText,(
char*)This->Help().c_str());