40 #ifdef G4VIS_BUILD_OIX_DRIVER
45 #include <Inventor/nodes/SoSelection.h>
47 #include <Inventor/Xt/SoXt.h>
48 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
50 #include <X11/StringDefs.h>
51 #include <X11/Shell.h>
56 #include <Xm/CascadeB.h>
57 #include <Xm/RowColumn.h>
67 G4OpenInventorXtViewer::G4OpenInventorXtViewer(
68 G4OpenInventorSceneHandler& sceneHandler
70 :G4OpenInventorViewer (sceneHandler, name)
81 void G4OpenInventorXtViewer::Initialise() {
85 Widget parent = (Widget)fInteractorManager->GetParentInteractor ();
93 G4String sgeometry = fVP.GetXGeometryString();
94 if(sgeometry.empty()) {
95 G4cout <<
"ERROR: Geometry string \""
97 <<
"\" is empty. Using \"600x600\"."
101 sprintf(str,
"%dx%d",width,height);
104 width = fVP.GetWindowSizeHintX();
105 height = fVP.GetWindowSizeHintX();
110 shellName +=
"_shell";
112 XtSetArg(args[0],XtNgeometry,XtNewString(sgeometry.c_str()));
113 XtSetArg(args[1],XtNborderWidth,0);
114 XtSetArg(args[2],XtNtitle,XtNewString(wName.c_str()));
115 fShell = XtAppCreateShell(shellName.c_str(),
"Inventor",
116 topLevelShellWidgetClass,
120 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
121 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
122 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
123 XtSetArg(args[3],XmNbottomAttachment,XmATTACH_FORM);
124 Widget form = XmCreateForm (fShell,(
char*)
"form",args,4);
125 XtManageChild (form);
127 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
128 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
129 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
130 Widget menuBar = XmCreateMenuBar (form,(
char*)
"menuBar",args,3);
131 XtManageChild(menuBar);
133 {Widget menu = AddMenu(menuBar,
"File",
"File");
134 AddButton(menu,
"PS (gl2ps)",PostScriptCbk);
135 AddButton(menu,
"PS (pixmap)",PixmapPostScriptCbk);
136 AddButton(menu,
"IV",WriteInventorCbk);
137 AddButton(menu,
"Escape",EscapeCbk);}
139 {Widget menu = AddMenu(menuBar,
"Etc",
"Etc");
140 AddButton(menu,
"Erase detector",EraseDetectorCbk);
141 AddButton(menu,
"Erase event",EraseEventCbk);
142 AddButton(menu,
"Set solid",SetSolidCbk);
144 AddButton(menu,
"Set (G4) reduced wire frame",SetReducedWireFrameCbk);
145 AddButton(menu,
"Set (G4) full wire frame",SetFullWireFrameCbk);
146 AddButton(menu,
"Visible mothers + invisible daughters",SetPreviewCbk);
147 AddButton(menu,
"Visible mothers + visible daughters",SetPreviewAndFullCbk);
148 AddButton(menu,
"Update scene",UpdateSceneCbk);
149 AddButton(menu,
"Scene graph stats",SceneGraphStatisticsCbk);
152 {Widget menu = AddMenu(menuBar,
"Help",
"Help");
153 AddButton(menu,
"Controls",HelpCbk);}
155 fViewer =
new SoXtExaminerViewer(form,wName.c_str(),
TRUE);
157 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET);
158 XtSetArg(args[1],XmNtopWidget ,menuBar);
159 XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM);
160 XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
161 XtSetArg(args[4],XmNbottomAttachment,XmATTACH_FORM);
162 XtSetValues(fViewer->getWidget(),args,5);
164 fHelpForm = XmCreateFormDialog(fShell,(
char*)
"help",NULL,0);
165 XtSetArg(args[0],XmNleftAttachment ,XmATTACH_FORM);
166 XtSetArg(args[1],XmNrightAttachment ,XmATTACH_FORM);
167 XtSetArg(args[2],XmNbottomAttachment,XmATTACH_FORM);
168 Widget cancel = XmCreatePushButton(fHelpForm,(
char*)
"helpCancel",args,3);
169 XtAddCallback(cancel,XmNactivateCallback,HelpCancelCbk,(XtPointer)
this);
170 XtManageChild(cancel);
171 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
172 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
173 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
174 XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
175 XtSetArg(args[4],XmNbottomWidget ,cancel);
176 fHelpText = XmCreateScrolledText(fHelpForm,(
char*)
"helpText",args,5);
177 XtManageChild(fHelpText);
179 fInteractorManager->AddShell(fShell);
182 char* str = fInteractorManager->GetCreationString();
183 if(str!=0) wName = str;
184 fViewer =
new SoXtExaminerViewer(parent,wName.c_str(),
TRUE);
187 fViewer->setSize(SbVec2s(width,height));
190 const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
192 fViewer->setGLRenderAction(fGL2PSAction);
195 fViewer->setSceneGraph(fSoSelection);
197 fViewer->saveHomePosition();
198 fViewer->setTitle(
fName);
202 fInteractorManager->FlushAndWaitExecution ();
204 fInteractorManager->SetCreatedInteractor (fViewer -> getWidget());
205 fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
208 G4OpenInventorXtViewer::~G4OpenInventorXtViewer () {
209 if(fShell) fInteractorManager->RemoveShell(fShell);
211 fViewer->setSceneGraph(0);
216 if(fShell) XtDestroyWidget(fShell);
219 void G4OpenInventorXtViewer::FinishView () {
222 fViewer->saveHomePosition();
225 void G4OpenInventorXtViewer::SetView () {
226 G4OpenInventorViewer::SetView ();
230 fViewer->setBackgroundColor
235 void G4OpenInventorXtViewer::ViewerRender () {
240 SoCamera* G4OpenInventorXtViewer::GetCamera () {
241 if(!fViewer)
return 0;
242 return fViewer->getCamera();
245 Widget G4OpenInventorXtViewer::AddMenu(
252 Widget menu = XmCreatePulldownMenu(aMenuBar,(
char*)aName.c_str(),NULL,0);
256 XmStringLtoRCreate((
char*)aLabel.c_str(),(
char*)XmSTRING_DEFAULT_CHARSET);
257 XtSetArg (args[0],XmNlabelString,cps);
258 XtSetArg (args[1],XmNsubMenuId,menu);
259 Widget widget = XmCreateCascadeButton(aMenuBar,(
char*)aName.c_str(),args,2);
261 XtManageChild(widget);
264 void G4OpenInventorXtViewer::AddButton (
267 ,XtCallbackProc aCallback
270 Widget widget = XmCreatePushButton(aMenu,(
char*)aLabel.c_str(),NULL,0);
271 XtManageChild(widget);
272 XtAddCallback(widget,XmNactivateCallback,aCallback,(XtPointer)
this);
275 void G4OpenInventorXtViewer::HelpCancelCbk(
276 Widget,XtPointer aData,XtPointer) {
277 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
278 XtUnmanageChild(This->fHelpForm);
286 void G4OpenInventorXtViewer::EscapeCbk(
287 Widget,XtPointer aData,XtPointer) {
288 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
292 void G4OpenInventorXtViewer::PostScriptCbk(
293 Widget,XtPointer aData,XtPointer) {
294 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
295 This->WritePostScript();
298 void G4OpenInventorXtViewer::PixmapPostScriptCbk(
299 Widget,XtPointer aData,XtPointer) {
300 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
301 This->WritePixmapPostScript();
304 void G4OpenInventorXtViewer::SceneGraphStatisticsCbk(
305 Widget,XtPointer aData,XtPointer) {
306 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
307 This->SceneGraphStatistics();
310 void G4OpenInventorXtViewer::WriteInventorCbk(
311 Widget,XtPointer aData,XtPointer) {
312 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
313 This->WriteInventor();
316 void G4OpenInventorXtViewer::EraseDetectorCbk(
317 Widget,XtPointer aData,XtPointer) {
318 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
319 This->EraseDetector();
322 void G4OpenInventorXtViewer::EraseEventCbk(
323 Widget,XtPointer aData,XtPointer) {
324 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
328 void G4OpenInventorXtViewer::SetSolidCbk(
329 Widget,XtPointer aData,XtPointer) {
330 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
334 void G4OpenInventorXtViewer::SetWireFrameCbk(
335 Widget,XtPointer aData,XtPointer) {
336 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
337 This->SetWireFrame();
340 void G4OpenInventorXtViewer::SetReducedWireFrameCbk(
341 Widget,XtPointer aData,XtPointer) {
342 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
343 This->SetReducedWireFrame(
true);
346 void G4OpenInventorXtViewer::SetFullWireFrameCbk(
347 Widget,XtPointer aData,XtPointer) {
348 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
349 This->SetReducedWireFrame(
false);
352 void G4OpenInventorXtViewer::UpdateSceneCbk(
353 Widget,XtPointer aData,XtPointer) {
354 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
358 void G4OpenInventorXtViewer::SetPreviewCbk(
359 Widget,XtPointer aData,XtPointer) {
360 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
364 void G4OpenInventorXtViewer::SetPreviewAndFullCbk(
365 Widget,XtPointer aData,XtPointer) {
366 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
367 This->SetPreviewAndFull();
370 void G4OpenInventorXtViewer::HelpCbk(
371 Widget,XtPointer aData,XtPointer) {
372 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
373 XtManageChild(This->fHelpForm);
374 XmTextSetString(This->fHelpText,(
char*)This->Help().c_str());