Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenInventorXtViewer.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28/*
29 * jck 05 Feb 1997 - Initial Implementation
30 * jck 21 Apr 1997
31 * Mods for SoXtHepViewer
32 * gb : on Win32 use an SoXtExaminerViewer.
33 * gb 05 April 2004 : revisit to separate Windows things.
34 * gb 09 November 2004 : restore the escape button.
35 * gb 09 November 2004 : have a menu bar in the viewer shell.
36 * gb 09 November 2004 : have gl2ps file production.
37 * gb 14 November 2004 : inherit G4OpenInventorViewer.
38 */
39
40// this :
42
43#include <Inventor/nodes/SoSelection.h>
44
45#include <Inventor/Xt/SoXt.h>
46#include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
47
48#include <X11/StringDefs.h>
49#include <X11/Shell.h>
50
51#include <Xm/Xm.h>
52#include <Xm/PushB.h>
53#include <Xm/Form.h>
54#include <Xm/CascadeB.h>
55#include <Xm/RowColumn.h>
56#include <Xm/Text.h>
57
59
60#include "G4OpenInventor.hh"
63#include "G4VisManager.hh"
64
66 G4OpenInventorSceneHandler& sceneHandler
67,const G4String& name)
68:G4OpenInventorViewer (sceneHandler, name)
69,fShell(0)
70,fViewer(0)
71,fHelpForm(0)
72,fHelpText(0)
73{
75 G4cout << "Window name: " << fName << G4endl;
76}
77
78
80
81 G4String wName = fName;
82
83 Widget parent = (Widget)fInteractorManager->GetParentInteractor ();
84 int width = 600;
85 int height = 600;
86
87 if(!parent) {
88 // Check if user has specified an X-Windows-type geometry string...
89 char str[32];
90
91 G4String sgeometry = fVP.GetXGeometryString();
92 if(sgeometry.empty()) {
93 G4cout << "ERROR: Geometry string \""
94 << sgeometry
95 << "\" is empty. Using \"600x600\"."
96 << G4endl;
97 width = 600;
98 height = 600;
99 snprintf(str,sizeof str,"%dx%d",width,height);
100 sgeometry = str;
101 } else {
102 width = fVP.GetWindowSizeHintX();
103 height = fVP.GetWindowSizeHintX();
104 }
105
106 //Create a shell window :
107 G4String shellName = wName;
108 shellName += "_shell";
109 Arg args[10];
110 XtSetArg(args[0],XtNgeometry,XtNewString(sgeometry.c_str()));
111 XtSetArg(args[1],XtNborderWidth,0);
112 XtSetArg(args[2],XtNtitle,XtNewString(wName.c_str()));
113 fShell = XtAppCreateShell(shellName.c_str(),"Inventor",
114 topLevelShellWidgetClass,
115 SoXt::getDisplay(),
116 args,3);
117
118 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
119 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
120 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
121 XtSetArg(args[3],XmNbottomAttachment,XmATTACH_FORM);
122 Widget form = XmCreateForm (fShell,(char*)"form",args,4);
123 XtManageChild (form);
124
125 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
126 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
127 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
128 Widget menuBar = XmCreateMenuBar (form,(char*)"menuBar",args,3);
129 XtManageChild(menuBar);
130
131 {Widget menu = AddMenu(menuBar,"File","File");
132 AddButton(menu,"PS (gl2ps)",PostScriptCbk);
133 AddButton(menu,"PS (pixmap)",PixmapPostScriptCbk);
134 AddButton(menu,"IV",WriteInventorCbk);
135 AddButton(menu,"Escape",EscapeCbk);}
136
137 {Widget menu = AddMenu(menuBar,"Etc","Etc");
138 AddButton(menu,"Erase detector",EraseDetectorCbk);
139 AddButton(menu,"Erase event",EraseEventCbk);
140 AddButton(menu,"Set solid",SetSolidCbk);
141/* AddButton(menu,"Set (G4) wire frame",SetWireFrameCbk);*/
142 AddButton(menu,"Set (G4) reduced wire frame",SetReducedWireFrameCbk);
143 AddButton(menu,"Set (G4) full wire frame",SetFullWireFrameCbk);
144 AddButton(menu,"Visible mothers + invisible daughters",SetPreviewCbk);
145 AddButton(menu,"Visible mothers + visible daughters",SetPreviewAndFullCbk);
146 AddButton(menu,"Update scene",UpdateSceneCbk);
147 AddButton(menu,"Scene graph stats",SceneGraphStatisticsCbk);
148 }
149
150 {Widget menu = AddMenu(menuBar,"Help","Help");
151 AddButton(menu,"Controls",HelpCbk);}
152
153 fViewer = new SoXtExaminerViewer(form,wName.c_str(),TRUE);
154
155 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET);
156 XtSetArg(args[1],XmNtopWidget ,menuBar);
157 XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM);
158 XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
159 XtSetArg(args[4],XmNbottomAttachment,XmATTACH_FORM);
160 XtSetValues(fViewer->getWidget(),args,5);
161
162 fHelpForm = XmCreateFormDialog(fShell,(char*)"help",NULL,0);
163 XtSetArg(args[0],XmNleftAttachment ,XmATTACH_FORM);
164 XtSetArg(args[1],XmNrightAttachment ,XmATTACH_FORM);
165 XtSetArg(args[2],XmNbottomAttachment,XmATTACH_FORM);
166 Widget cancel = XmCreatePushButton(fHelpForm,(char*)"helpCancel",args,3);
167 XtAddCallback(cancel,XmNactivateCallback,HelpCancelCbk,(XtPointer)this);
168 XtManageChild(cancel);
169 XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
170 XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
171 XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
172 XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
173 XtSetArg(args[4],XmNbottomWidget ,cancel);
174 fHelpText = XmCreateScrolledText(fHelpForm,(char*)"helpText",args,5);
175 XtManageChild(fHelpText);
176
178
179 } else {
181 if(str!=0) wName = str;
182 fViewer = new SoXtExaminerViewer(parent,wName.c_str(),TRUE);
183 }
184
185 fViewer->setSize(SbVec2s(width,height));
186
187 // Have a GL2PS render action :
188 const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
189 fGL2PSAction = new SoGL2PSAction(vpRegion);
190 fViewer->setGLRenderAction(fGL2PSAction);
191
192 // Else :
193 fViewer->setSceneGraph(fSoSelection);
194 fViewer->viewAll();
195 fViewer->saveHomePosition();
196 fViewer->setTitle(fName);
197 fViewer->show();
198 if(fShell) {
199 SoXt::show(fShell);
201 }
203 fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
204}
205
208 if(fViewer) {
209 fViewer->setSceneGraph(0);
210 //FIXME : SGI : the below "delete" block things.
211 //FIXME : CoinXt : the below "delete" crashe in ~SoXtRenderArea.
212 //FIXME : delete fViewer;
213 }
214 if(fShell) XtDestroyWidget(fShell);
215}
216
218 if(!fViewer) return;
219 fViewer->viewAll();
220 fViewer->saveHomePosition();
221}
222
225 if(!fViewer) return;
226 // Background.
228 fViewer->setBackgroundColor
229 (SbColor((float)b.GetRed(),(float)b.GetGreen(),(float)b.GetBlue()));
230}
231
232
234 if(!fViewer) return;
235 fViewer->render();
236}
237
239 if(!fViewer) return 0;
240 return fViewer->getCamera();
241}
242
244 Widget aMenuBar
245,const G4String& aName
246,const G4String& aLabel
247)
248{
249 // Pulldown menu :
250 Widget menu = XmCreatePulldownMenu(aMenuBar,(char*)aName.c_str(),NULL,0);
251 // Cascade button :
252 Arg args[2];
253 XmString cps =
254 XmStringLtoRCreate((char*)aLabel.c_str(),(char*)XmSTRING_DEFAULT_CHARSET);
255 XtSetArg (args[0],XmNlabelString,cps);
256 XtSetArg (args[1],XmNsubMenuId,menu);
257 Widget widget = XmCreateCascadeButton(aMenuBar,(char*)aName.c_str(),args,2);
258 XmStringFree (cps);
259 XtManageChild(widget);
260 return menu;
261}
263 Widget aMenu
264,const G4String& aLabel
265,XtCallbackProc aCallback
266)
267{
268 Widget widget = XmCreatePushButton(aMenu,(char*)aLabel.c_str(),NULL,0);
269 XtManageChild(widget);
270 XtAddCallback(widget,XmNactivateCallback,aCallback,(XtPointer)this);
271}
272
274 Widget,XtPointer aData,XtPointer) {
276 XtUnmanageChild(This->fHelpForm);
277}
278
279
280//////////////////////////////////////////////////////////////////////////////
281//////////////////////////////////////////////////////////////////////////////
282//////////////////////////////////////////////////////////////////////////////
283
285 Widget,XtPointer aData,XtPointer) {
287 This->Escape();
288}
289
291 Widget,XtPointer aData,XtPointer) {
293 This->WritePostScript();
294}
295
297 Widget,XtPointer aData,XtPointer) {
299 This->WritePixmapPostScript();
300}
301
303 Widget,XtPointer aData,XtPointer) {
305 This->SceneGraphStatistics();
306}
307
309 Widget,XtPointer aData,XtPointer) {
311 This->WriteInventor();
312}
313
315 Widget,XtPointer aData,XtPointer) {
317 This->EraseDetector();
318}
319
321 Widget,XtPointer aData,XtPointer) {
323 This->EraseEvent();
324}
325
327 Widget,XtPointer aData,XtPointer) {
329 This->SetSolid();
330}
331
333 Widget,XtPointer aData,XtPointer) {
335 This->SetWireFrame();
336}
337
339 Widget,XtPointer aData,XtPointer) {
341 This->SetReducedWireFrame(true);
342}
343
345 Widget,XtPointer aData,XtPointer) {
347 This->SetReducedWireFrame(false);
348}
349
351 Widget,XtPointer aData,XtPointer) {
353 This->UpdateScene();
354}
355
357 Widget,XtPointer aData,XtPointer) {
359 This->SetPreview();
360}
361
363 Widget,XtPointer aData,XtPointer) {
365 This->SetPreviewAndFull();
366}
367
369 Widget,XtPointer aData,XtPointer) {
371 XtManageChild(This->fHelpForm);
372 XmTextSetString(This->fHelpText,(char*)This->Help().c_str());
373}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define SoGL2PSAction
Definition: SoGL2PSAction.h:40
G4double GetBlue() const
Definition: G4Colour.hh:154
G4double GetRed() const
Definition: G4Colour.hh:152
G4double GetGreen() const
Definition: G4Colour.hh:153
G4String Help(const G4String &topic="controls")
void WriteInventor(const G4String &file="g4out.iv")
void WritePostScript(const G4String &file="g4out.ps")
void Escape()
Menu items callbacks /////////////////////////////////////////////////////.
G4VInteractorManager * fInteractorManager
void WritePixmapPostScript(const G4String &file="g4out.ps")
Geant4_SoGL2PSAction * fGL2PSAction
static void SetPreviewCbk(Widget, XtPointer, XtPointer)
static void SetReducedWireFrameCbk(Widget, XtPointer, XtPointer)
static void SceneGraphStatisticsCbk(Widget, XtPointer, XtPointer)
static void SetPreviewAndFullCbk(Widget, XtPointer, XtPointer)
static void EraseDetectorCbk(Widget, XtPointer, XtPointer)
static void PixmapPostScriptCbk(Widget, XtPointer, XtPointer)
static void SetFullWireFrameCbk(Widget, XtPointer, XtPointer)
static void PostScriptCbk(Widget, XtPointer, XtPointer)
static void SetWireFrameCbk(Widget, XtPointer, XtPointer)
virtual SoCamera * GetCamera()
static void WriteInventorCbk(Widget, XtPointer, XtPointer)
void AddButton(Widget, const G4String &, XtCallbackProc)
static void HelpCancelCbk(Widget, XtPointer, XtPointer)
static void EraseEventCbk(Widget, XtPointer, XtPointer)
G4OpenInventorXtViewer(G4OpenInventorSceneHandler &scene, const G4String &name="")
static void UpdateSceneCbk(Widget, XtPointer, XtPointer)
static void EscapeCbk(Widget, XtPointer, XtPointer)
static void SetSolidCbk(Widget, XtPointer, XtPointer)
static void HelpCbk(Widget, XtPointer, XtPointer)
Widget AddMenu(Widget, const G4String &, const G4String &)
SoXtExaminerViewer * fViewer
void SetCreatedInteractor(G4Interactor)
virtual void FlushAndWaitExecution()=0
G4Interactor GetParentInteractor()
void RemoveShell(G4Interactor)
void AddShell(G4Interactor)
G4String fName
Definition: G4VViewer.hh:218
G4ViewParameters fVP
Definition: G4VViewer.hh:220
const G4String & GetXGeometryString() const
unsigned int GetWindowSizeHintX() const
const G4Colour & GetBackgroundColour() const
static Verbosity GetVerbosity()
#define TRUE
Definition: globals.hh:41