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());
206 fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
209 G4OpenInventorXtViewer::~G4OpenInventorXtViewer () {
210 if(fShell) fInteractorManager->RemoveShell(fShell);
212 fViewer->setSceneGraph(0);
217 if(fShell) XtDestroyWidget(fShell);
220 void G4OpenInventorXtViewer::FinishView () {
223 fViewer->saveHomePosition();
226 void G4OpenInventorXtViewer::SetView () {
227 G4OpenInventorViewer::SetView ();
231 fViewer->setBackgroundColor
236 void G4OpenInventorXtViewer::ViewerRender () {
241 SoCamera* G4OpenInventorXtViewer::GetCamera () {
242 if(!fViewer)
return 0;
243 return fViewer->getCamera();
246 Widget G4OpenInventorXtViewer::AddMenu(
253 Widget menu = XmCreatePulldownMenu(aMenuBar,(
char*)aName.c_str(),NULL,0);
257 XmStringLtoRCreate((
char*)aLabel.c_str(),(
char*)XmSTRING_DEFAULT_CHARSET);
258 XtSetArg (args[0],XmNlabelString,cps);
259 XtSetArg (args[1],XmNsubMenuId,menu);
260 Widget widget = XmCreateCascadeButton(aMenuBar,(
char*)aName.c_str(),args,2);
262 XtManageChild(widget);
265 void G4OpenInventorXtViewer::AddButton (
268 ,XtCallbackProc aCallback
271 Widget widget = XmCreatePushButton(aMenu,(
char*)aLabel.c_str(),NULL,0);
272 XtManageChild(widget);
273 XtAddCallback(widget,XmNactivateCallback,aCallback,(XtPointer)
this);
276 void G4OpenInventorXtViewer::HelpCancelCbk(
277 Widget,XtPointer aData,XtPointer) {
278 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
279 XtUnmanageChild(This->fHelpForm);
287 void G4OpenInventorXtViewer::EscapeCbk(
288 Widget,XtPointer aData,XtPointer) {
289 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
293 void G4OpenInventorXtViewer::PostScriptCbk(
294 Widget,XtPointer aData,XtPointer) {
295 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
296 This->WritePostScript();
299 void G4OpenInventorXtViewer::PixmapPostScriptCbk(
300 Widget,XtPointer aData,XtPointer) {
301 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
302 This->WritePixmapPostScript();
305 void G4OpenInventorXtViewer::SceneGraphStatisticsCbk(
306 Widget,XtPointer aData,XtPointer) {
307 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
308 This->SceneGraphStatistics();
311 void G4OpenInventorXtViewer::WriteInventorCbk(
312 Widget,XtPointer aData,XtPointer) {
313 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
314 This->WriteInventor();
317 void G4OpenInventorXtViewer::EraseDetectorCbk(
318 Widget,XtPointer aData,XtPointer) {
319 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
320 This->EraseDetector();
323 void G4OpenInventorXtViewer::EraseEventCbk(
324 Widget,XtPointer aData,XtPointer) {
325 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
329 void G4OpenInventorXtViewer::SetSolidCbk(
330 Widget,XtPointer aData,XtPointer) {
331 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
335 void G4OpenInventorXtViewer::SetWireFrameCbk(
336 Widget,XtPointer aData,XtPointer) {
337 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
338 This->SetWireFrame();
341 void G4OpenInventorXtViewer::SetReducedWireFrameCbk(
342 Widget,XtPointer aData,XtPointer) {
343 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
344 This->SetReducedWireFrame(
true);
347 void G4OpenInventorXtViewer::SetFullWireFrameCbk(
348 Widget,XtPointer aData,XtPointer) {
349 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
350 This->SetReducedWireFrame(
false);
353 void G4OpenInventorXtViewer::UpdateSceneCbk(
354 Widget,XtPointer aData,XtPointer) {
355 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
359 void G4OpenInventorXtViewer::SetPreviewCbk(
360 Widget,XtPointer aData,XtPointer) {
361 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
365 void G4OpenInventorXtViewer::SetPreviewAndFullCbk(
366 Widget,XtPointer aData,XtPointer) {
367 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
368 This->SetPreviewAndFull();
371 void G4OpenInventorXtViewer::HelpCbk(
372 Widget,XtPointer aData,XtPointer) {
373 G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
374 XtManageChild(This->fHelpForm);
375 XmTextSetString(This->fHelpText,(
char*)This->Help().c_str());
G4GLOB_DLL std::ostream G4cout
G4double GetGreen() const
static Verbosity GetVerbosity()