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 ();
99 G4String sgeometry = fVP.GetXGeometryString();
100 if(sgeometry.empty()) {
101 G4cout <<
"ERROR: Geometry string \""
103 <<
"\" is empty. Using \"600x600\"."
107 sprintf(s,
"%dx%d",width,height);
110 width = fVP.GetWindowSizeHintX();
111 height = fVP.GetWindowSizeHintX();
116 shellName +=
"_shell";
118 XtSetArg(args[0],XtNgeometry,XtNewString(sgeometry.c_str()));
119 XtSetArg(args[1],XtNborderWidth,0);
120 XtSetArg(args[2],XtNtitle,XtNewString(wName.c_str()));
121 fShell = XtAppCreateShell(shellName.c_str(),
"Inventor",
122 topLevelShellWidgetClass,
139 Widget menuBar = fViewer->getMenuBar();
147 {Widget menu = fViewer->getMenu();
149 AddButton(menu,
"PS (gl2ps)",PostScriptCbk);
150 AddButton(menu,
"PS (pixmap)",PixmapPostScriptCbk);
151 AddButton(menu,
"Write IV",WriteInventorCbk);
152 AddButton(menu,
"Escape",EscapeCbk);}
154 {Widget menu = AddMenu(menuBar,
"Etc",
"Etc");
155 AddButton(menu,
"Erase detector",EraseDetectorCbk);
156 AddButton(menu,
"Erase event",EraseEventCbk);
157 AddButton(menu,
"Set solid",SetSolidCbk);
159 AddButton(menu,
"Set (G4) reduced wire frame",SetReducedWireFrameCbk);
160 AddButton(menu,
"Set (G4) full wire frame",SetFullWireFrameCbk);
161 AddButton(menu,
"Visible mothers + invisible daughters",SetPreviewCbk);
162 AddButton(menu,
"Visible mothers + visible daughters",SetPreviewAndFullCbk);
163 AddButton(menu,
"Update scene",UpdateSceneCbk);
164 AddButton(menu,
"Scene graph stats",SceneGraphStatisticsCbk);
167 {Widget menu = AddMenu(menuBar,
"Help",
"Help");
168 AddButton(menu,
"Controls",HelpCbk);}
172 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET);
173 XtSetArg(args[1],XmNtopWidget ,menuBar);
174 XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM);
175 XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
176 XtSetArg(args[4],XmNbottomAttachment,XmATTACH_FORM);
177 XtSetValues(fViewer->getWidget(),args,5);
179 fHelpForm = XmCreateFormDialog(fShell,(
char*)
"help",NULL,0);
180 XtSetArg(args[0],XmNleftAttachment ,XmATTACH_FORM);
181 XtSetArg(args[1],XmNrightAttachment ,XmATTACH_FORM);
182 XtSetArg(args[2],XmNbottomAttachment,XmATTACH_FORM);
183 Widget cancel = XmCreatePushButton(fHelpForm,(
char*)
"helpCancel",args,3);
184 XtAddCallback(cancel,XmNactivateCallback,HelpCancelCbk,(XtPointer)
this);
185 XtManageChild(cancel);
186 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
187 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
188 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
189 XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
190 XtSetArg(args[4],XmNbottomWidget ,cancel);
191 fHelpText = XmCreateScrolledText(fHelpForm,(
char*)
"helpText",args,5);
192 XtManageChild(fHelpText);
194 fInteractorManager->AddShell(fShell);
197 char* str = fInteractorManager->GetCreationString();
198 if(str!=0) wName = str;
204 fSoSelection->removeSelectionCallback(G4OpenInventorViewer::SelectionCB,
208 fViewer->setSize(SbVec2s(width,height));
211 const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
213 fViewer->setGLRenderAction(fGL2PSAction);
216 fViewer->setSceneGraph(fSoSelection);
218 fViewer->saveHomePosition();
219 fViewer->setTitle(
fName);
223 fInteractorManager->FlushAndWaitExecution ();
225 fInteractorManager->SetCreatedInteractor (fViewer -> getWidget());
227 fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
230 G4OpenInventorXtExtendedViewer::~G4OpenInventorXtExtendedViewer () {
231 if(fShell) fInteractorManager->RemoveShell(fShell);
233 fViewer->setSceneGraph(0);
238 if(fShell) XtDestroyWidget(fShell);
241 void G4OpenInventorXtExtendedViewer::FinishView () {
244 fViewer->saveHomePosition();
247 void G4OpenInventorXtExtendedViewer::SetView () {
248 G4OpenInventorViewer::SetView ();
252 fViewer->setBackgroundColor
257 void G4OpenInventorXtExtendedViewer::ViewerRender () {
262 SoCamera* G4OpenInventorXtExtendedViewer::GetCamera () {
263 if(!fViewer)
return 0;
264 return fViewer->getCamera();
267 Widget G4OpenInventorXtExtendedViewer::AddMenu(
274 Widget menu = XmCreatePulldownMenu(aMenuBar,(
char*)aName.c_str(),NULL,0);
278 XmStringLtoRCreate((
char*)aLabel.c_str(),XmSTRING_DEFAULT_CHARSET);
279 XtSetArg (args[0],XmNlabelString,cps);
280 XtSetArg (args[1],XmNsubMenuId,menu);
281 Widget widget = XmCreateCascadeButton(aMenuBar,(
char*)aName.c_str(),args,2);
283 XtManageChild(widget);
286 void G4OpenInventorXtExtendedViewer::AddButton (
289 ,XtCallbackProc aCallback
292 Widget widget = XmCreatePushButton(aMenu,(
char*)aLabel.c_str(),NULL,0);
293 XtManageChild(widget);
294 XtAddCallback(widget,XmNactivateCallback,aCallback,(XtPointer)
this);
297 void G4OpenInventorXtExtendedViewer::HelpCancelCbk(
298 Widget,XtPointer aData,XtPointer) {
299 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
300 XtUnmanageChild(This->fHelpForm);
308 void G4OpenInventorXtExtendedViewer::EscapeCbk(
309 Widget,XtPointer aData,XtPointer) {
310 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
315 void G4OpenInventorXtExtendedViewer::EscapeFromKeyboardCbk(
void* o) {
316 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)o;
320 void G4OpenInventorXtExtendedViewer::PostScriptCbk(
321 Widget,XtPointer aData,XtPointer) {
322 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
323 This->WritePostScript();
326 void G4OpenInventorXtExtendedViewer::PixmapPostScriptCbk(
327 Widget,XtPointer aData,XtPointer) {
328 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
329 This->WritePixmapPostScript();
332 void G4OpenInventorXtExtendedViewer::SceneGraphStatisticsCbk(
333 Widget,XtPointer aData,XtPointer) {
334 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
335 This->SceneGraphStatistics();
338 void G4OpenInventorXtExtendedViewer::WriteInventorCbk(
339 Widget,XtPointer aData,XtPointer) {
340 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
341 This->WriteInventor();
344 void G4OpenInventorXtExtendedViewer::EraseDetectorCbk(
345 Widget,XtPointer aData,XtPointer) {
346 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
347 This->EraseDetector();
350 void G4OpenInventorXtExtendedViewer::EraseEventCbk(
351 Widget,XtPointer aData,XtPointer) {
352 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
356 void G4OpenInventorXtExtendedViewer::SetSolidCbk(
357 Widget,XtPointer aData,XtPointer) {
358 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
362 void G4OpenInventorXtExtendedViewer::SetWireFrameCbk(
363 Widget,XtPointer aData,XtPointer) {
364 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
365 This->SetWireFrame();
368 void G4OpenInventorXtExtendedViewer::SetReducedWireFrameCbk(
369 Widget,XtPointer aData,XtPointer) {
370 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
371 This->SetReducedWireFrame(
true);
374 void G4OpenInventorXtExtendedViewer::SetFullWireFrameCbk(
375 Widget,XtPointer aData,XtPointer) {
376 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
377 This->SetReducedWireFrame(
false);
380 void G4OpenInventorXtExtendedViewer::UpdateSceneCbk(
381 Widget,XtPointer aData,XtPointer) {
382 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
386 void G4OpenInventorXtExtendedViewer::SetPreviewCbk(
387 Widget,XtPointer aData,XtPointer) {
388 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
392 void G4OpenInventorXtExtendedViewer::SetPreviewAndFullCbk(
393 Widget,XtPointer aData,XtPointer) {
394 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
395 This->SetPreviewAndFull();
398 void G4OpenInventorXtExtendedViewer::HelpCbk(
399 Widget,XtPointer aData,XtPointer) {
400 G4OpenInventorXtExtendedViewer* This = (G4OpenInventorXtExtendedViewer*)aData;
401 XtManageChild(This->fHelpForm);
402 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 *)