41 #ifdef G4VIS_BUILD_OIX_DRIVER
46 #include <Inventor/nodes/SoSelection.h>
48 #include <Inventor/Xt/SoXt.h>
49 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
51 #include <X11/StringDefs.h>
52 #include <X11/Shell.h>
57 #include <Xm/CascadeB.h>
58 #include <Xm/RowColumn.h>
68 G4OpenInventorXtViewer::G4OpenInventorXtViewer(
69 G4OpenInventorSceneHandler& sceneHandler
71 :G4OpenInventorViewer (sceneHandler, name)
82 void G4OpenInventorXtViewer::Initialise() {
86 Widget parent = (Widget)fInteractorManager->GetParentInteractor ();
94 G4String sgeometry = fVP.GetXGeometryString();
95 if(sgeometry.empty()) {
96 G4cout <<
"ERROR: Geometry string \""
98 <<
"\" is empty. Using \"600x600\"."
102 sprintf(str,
"%dx%d",width,height);
105 width = fVP.GetWindowSizeHintX();
106 height = fVP.GetWindowSizeHintX();
111 shellName +=
"_shell";
113 XtSetArg(args[0],XtNgeometry,XtNewString(sgeometry.c_str()));
114 XtSetArg(args[1],XtNborderWidth,0);
115 XtSetArg(args[2],XtNtitle,XtNewString(wName.c_str()));
116 fShell = XtAppCreateShell(shellName.c_str(),
"Inventor",
117 topLevelShellWidgetClass,
121 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
122 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
123 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
124 XtSetArg(args[3],XmNbottomAttachment,XmATTACH_FORM);
125 Widget form = XmCreateForm (fShell,(
char*)
"form",args,4);
126 XtManageChild (form);
128 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
129 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
130 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
131 Widget menuBar = XmCreateMenuBar (form,(
char*)
"menuBar",args,3);
132 XtManageChild(menuBar);
134 {Widget menu = AddMenu(menuBar,
"File",
"File");
135 AddButton(menu,
"PS (gl2ps)",PostScriptCbk);
136 AddButton(menu,
"PS (pixmap)",PixmapPostScriptCbk);
137 AddButton(menu,
"IV",WriteInventorCbk);
138 AddButton(menu,
"Escape",EscapeCbk);}
140 {Widget menu = AddMenu(menuBar,
"Etc",
"Etc");
141 AddButton(menu,
"Erase detector",EraseDetectorCbk);
142 AddButton(menu,
"Erase event",EraseEventCbk);
143 AddButton(menu,
"Set solid",SetSolidCbk);
145 AddButton(menu,
"Set (G4) reduced wire frame",SetReducedWireFrameCbk);
146 AddButton(menu,
"Set (G4) full wire frame",SetFullWireFrameCbk);
147 AddButton(menu,
"Visible mothers + invisible daughters",SetPreviewCbk);
148 AddButton(menu,
"Visible mothers + visible daughters",SetPreviewAndFullCbk);
149 AddButton(menu,
"Update scene",UpdateSceneCbk);
150 AddButton(menu,
"Scene graph stats",SceneGraphStatisticsCbk);
153 {Widget menu = AddMenu(menuBar,
"Help",
"Help");
154 AddButton(menu,
"Controls",HelpCbk);}
156 fViewer =
new SoXtExaminerViewer(form,wName.c_str(),
TRUE);
158 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET);
159 XtSetArg(args[1],XmNtopWidget ,menuBar);
160 XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM);
161 XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
162 XtSetArg(args[4],XmNbottomAttachment,XmATTACH_FORM);
163 XtSetValues(fViewer->getWidget(),args,5);
165 fHelpForm = XmCreateFormDialog(fShell,(
char*)
"help",NULL,0);
166 XtSetArg(args[0],XmNleftAttachment ,XmATTACH_FORM);
167 XtSetArg(args[1],XmNrightAttachment ,XmATTACH_FORM);
168 XtSetArg(args[2],XmNbottomAttachment,XmATTACH_FORM);
169 Widget cancel = XmCreatePushButton(fHelpForm,(
char*)
"helpCancel",args,3);
170 XtAddCallback(cancel,XmNactivateCallback,HelpCancelCbk,(XtPointer)
this);
171 XtManageChild(cancel);
172 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
173 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
174 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
175 XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
176 XtSetArg(args[4],XmNbottomWidget ,cancel);
177 fHelpText = XmCreateScrolledText(fHelpForm,(
char*)
"helpText",args,5);
178 XtManageChild(fHelpText);
180 fInteractorManager->AddShell(fShell);
183 char* str = fInteractorManager->GetCreationString();
184 if(str!=0) wName = str;
185 fViewer =
new SoXtExaminerViewer(parent,wName.c_str(),
TRUE);
188 fViewer->setSize(SbVec2s(width,height));
191 const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
193 fViewer->setGLRenderAction(fGL2PSAction);
196 fViewer->setSceneGraph(fSoSelection);
198 fViewer->saveHomePosition();
199 fViewer->setTitle(
fName);
203 fInteractorManager->FlushAndWaitExecution ();
205 fInteractorManager->SetCreatedInteractor (fViewer -> getWidget());
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(),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());