Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenInventorQtViewer.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// Frederick Jones TRIUMF 07 November 2017
27
28#ifdef G4VIS_BUILD_OIQT_DRIVER
29
30// this :
32
34
35#include <Inventor/nodes/SoSelection.h>
36
37#include <Inventor/Qt/SoQt.h>
38// FWJ these are needed (why?) to use flags in SoQtExaminerViewer constr.
39#include <Inventor/Qt/viewers/SoQtViewer.h>
40#include <Inventor/Qt/viewers/SoQtFullViewer.h>
41#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
42
43//#include <QMenuBar>
44#include <QMenu>
45#include <QAction>
46#include <QFont>
47
49
50#include "G4OpenInventor.hh"
53#include "G4VisManager.hh"
54
55#include "G4SoQt.hh"
56
57#ifndef G4GMAKE
58#include "moc_G4OpenInventorQtViewer.cpp"
59#endif
60
61G4OpenInventorQtViewer::G4OpenInventorQtViewer(
62 G4OpenInventorSceneHandler& sceneHandler, const G4String& name)
63 : G4OpenInventorViewer(sceneHandler, name), fViewer(0)
64{
65 // FWJ fName is in G4VViewer parent of G4OpenInventorViewer
67 G4cout << "Window name: " << fName << G4endl;
68}
69
70
71void G4OpenInventorQtViewer::Initialise()
72{
73
74 QWidget* parent = SoQt::getTopLevelWidget();
75
76 // FWJ DEBUG
77 // G4cout << "G4OIQtViewer: Creating G4OIQtExaminerViewer with parent " <<
78 // parent << G4endl;
79
80 // fViewer = new SoQtExaminerViewer(parent, "Geant4", TRUE);
81 fViewer = new G4OpenInventorQtExaminerViewer(parent, "Geant4", TRUE);
82
83 // G4String wName = fName;
84 //
85 // QWidget parent = (QWidget)fInteractorManager->GetParentInteractor();
86
87 int width = fVP.GetWindowSizeHintX();
88 int height = fVP.GetWindowSizeHintY();
89
90 // FWJ not sure what this is for
91 // fInteractorManager->AddShell(fShell);
92
93 // FWJ or this:
94 // } else {
95 // char* str = fInteractorManager->GetCreationString();
96 // if(str!=0) wName = str;
97 // fViewer = new SoQtExaminerViewer(parent,wName.c_str(),TRUE);
98 // }
99
100 fViewer->setSize(SbVec2s(width, height));
101
102 // Add common menu items...
103
104 // QMenuBar* menubar = fViewer->getMenubar();
105 QMenu* filemenu = fViewer->getFileMenu();
106 QMenu* etcmenu = fViewer->getEtcMenu();
107 QFont* font = fViewer->getFont();
108
109 // File menu
110
111 FileWritePS = new QAction("Write PostScript (gl2ps)", this);
112 FileWritePS->setFont(*font);
113 connect(FileWritePS, SIGNAL(triggered()), this,
114 SLOT(FileWritePSCB()));
115 filemenu->addAction(FileWritePS);
116
117 FileWritePDF = new QAction("Write PDF (gl2ps)", this);
118 FileWritePDF->setFont(*font);
119 connect(FileWritePDF, SIGNAL(triggered()), this,
120 SLOT(FileWritePDFCB()));
121 filemenu->addAction(FileWritePDF);
122
123 FileWriteIV = new QAction("Write IV", this);
124 FileWriteIV->setFont(*font);
125 connect(FileWriteIV, SIGNAL(triggered()), this,
126 SLOT(FileWriteIVCB()));
127 filemenu->addAction(FileWriteIV);
128
129 FileEscape = new QAction("Escape", this);
130 FileEscape->setFont(*font);
131 connect(FileEscape, SIGNAL(triggered()), this,
132 SLOT(FileEscapeCB()));
133 filemenu->addAction(FileEscape);
134
135 // G4cout << "G4OIQtViewer: externalApp = " <<
136 // static_cast<G4SoQt*>(fInteractorManager)->IsExternalApp() << G4endl;
137 if (static_cast<G4SoQt*>(fInteractorManager)->IsExternalApp())
138 fViewer->setExternalQtApp();
139
140 // Register escape CB with viewer, allowing E key escape
141 // fViewer->addEscapeCallback(FileEscapeCB);
142 // fViewer->addEscapeCallback(FileEscapeCB, (void*)this);
143
144 // Etc menu
145
146 EtcEraseDetector = new QAction("Erase detector", this);
147 EtcEraseDetector->setFont(*font);
148 connect(EtcEraseDetector, SIGNAL(triggered()), this,
149 SLOT(EtcEraseDetectorCB()));
150 etcmenu->addAction(EtcEraseDetector);
151
152 EtcEraseEvent = new QAction("Erase event", this);
153 EtcEraseEvent->setFont(*font);
154 connect(EtcEraseEvent, SIGNAL(triggered()), this,
155 SLOT(EtcEraseEventCB()));
156 etcmenu->addAction(EtcEraseEvent);
157
158 EtcSetSolid = new QAction("Set solid", this);
159 EtcSetSolid->setFont(*font);
160 connect(EtcSetSolid, SIGNAL(triggered()), this, SLOT(EtcSetSolidCB()));
161 etcmenu->addAction(EtcSetSolid);
162
163 EtcSetReducedWireframe = new QAction("Set (G4) reduced wireframe", this);
164 EtcSetReducedWireframe->setFont(*font);
165 connect(EtcSetReducedWireframe, SIGNAL(triggered()), this,
166 SLOT(EtcSetReducedWireframeCB()));
167 etcmenu->addAction(EtcSetReducedWireframe);
168
169 EtcSetFullWireframe = new QAction("Set full wireframe", this);
170 EtcSetFullWireframe->setFont(*font);
171 connect(EtcSetFullWireframe, SIGNAL(triggered()), this,
172 SLOT(EtcSetFullWireframeCB()));
173 etcmenu->addAction(EtcSetFullWireframe);
174
175 EtcVisibMInvisibD = new QAction("Visible mothers + invisible daughters",
176 this);
177 EtcVisibMInvisibD->setFont(*font);
178 connect(EtcVisibMInvisibD, SIGNAL(triggered()), this,
179 SLOT(EtcVisibMInvisibDCB()));
180 etcmenu->addAction(EtcVisibMInvisibD);
181
182 EtcVisibMVisibD = new QAction("Visible mothers + visible daughters", this);
183 EtcVisibMVisibD->setFont(*font);
184 connect(EtcVisibMVisibD, SIGNAL(triggered()), this,
185 SLOT(EtcVisibMVisibDCB()));
186 etcmenu->addAction(EtcVisibMVisibD);
187
188 EtcUpdateScene = new QAction("Update scene", this);
189 EtcUpdateScene->setFont(*font);
190 connect(EtcUpdateScene, SIGNAL(triggered()), this,
191 SLOT(EtcUpdateSceneCB()));
192 etcmenu->addAction(EtcUpdateScene);
193
194 EtcSceneGraphStats = new QAction("Scene graph stats", this);
195 EtcSceneGraphStats->setFont(*font);
196 connect(EtcSceneGraphStats, SIGNAL(triggered()), this,
197 SLOT(EtcSceneGraphStatsCB()));
198 etcmenu->addAction(EtcSceneGraphStats);
199
200
201 // Have a GL2PS render action :
202 const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
203 fGL2PSAction = new SoGL2PSAction(vpRegion);
204 fViewer->setGLRenderAction(fGL2PSAction);
205
206 // Else :
207
208 // FWJ DEBUG
209 // G4cout << "G4OpenInventorQtViewer: setting scene graph " <<
210 // fSoSelection << G4endl;
211 // G4cout << "G4OpenInventorQtViewer: getNumChildren " <<
212 // fSoSelection->getNumChildren() << G4endl;
213
214 fViewer->setSceneGraph(fSoSelection);
215 fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
216 fViewer->viewAll();
217 fViewer->saveHomePosition();
218 fViewer->setTitle(fName);
219 fViewer->show();
220
221 // This SHOULD invoke the event loop:
222 // if(fShell) {
223
224 QWidget* mainWin = SoQt::getTopLevelWidget();
225
226 // FWJ DEBUG
227 // G4cout << "G4OIQtViewer: calling SoQt::show on mainWin = " << mainWin
228 // << G4endl;
229
230 SoQt::show(mainWin);
231 fInteractorManager->FlushAndWaitExecution();
232
233 // }
234 fInteractorManager->SetCreatedInteractor(fViewer->getWidget());
235}
236
237
238G4OpenInventorQtViewer::~G4OpenInventorQtViewer()
239{
240 // if(fShell) fInteractorManager->RemoveShell(fShell);
241 if(fViewer) {
242 fViewer->setSceneGraph(0);
243 //FIXME : SGI : the below "delete" block things.
244 //FIXME : CoinXt : the below "delete" crashe in ~SoXtRenderArea.
245 //FIXME : delete fViewer;
246 }
247 // if(fShell) XtDestroyWidget(fShell);
248}
249
250void G4OpenInventorQtViewer::FinishView()
251{
252 if(!fViewer) return;
253 fViewer->viewAll();
254 fViewer->saveHomePosition();
255}
256
257void G4OpenInventorQtViewer::SetView()
258{
259 G4OpenInventorViewer::SetView();
260 if(!fViewer) return;
261 // Background.
262 G4Colour b = fVP.GetBackgroundColour();
263 fViewer->setBackgroundColor
264 (SbColor((float)b.GetRed(),(float)b.GetGreen(),(float)b.GetBlue()));
265}
266
267
268void G4OpenInventorQtViewer::ViewerRender()
269{
270 if(!fViewer) return;
271 fViewer->render();
272}
273
274SoCamera* G4OpenInventorQtViewer::GetCamera () {
275 if(!fViewer) return 0;
276 return fViewer->getCamera();
277}
278
279
280// File menu...
281
282void G4OpenInventorQtViewer::FileWritePSCB()
283{
284 // G4cout << "G4OIQtViewer: File: Write PS CALLBACK" << G4endl;
285 // FWJ Workaround: avoids empty 2nd page in file
286 SbBool superimpState =
287 fViewer->getSuperimpositionEnabled(fViewer->superimposition);
288 fViewer->setSuperimpositionEnabled(fViewer->superimposition, FALSE);
289 WritePostScript();
290 if (superimpState)
291 fViewer->setSuperimpositionEnabled(fViewer->superimposition, TRUE);
292}
293
294void G4OpenInventorQtViewer::FileWritePDFCB()
295{
296 // G4cout << "G4OIQtViewer: File: Write PDF CALLBACK" << G4endl;
297 // FWJ Workaround: avoids empty 2nd page in file
298 SbBool superimpState =
299 fViewer->getSuperimpositionEnabled(fViewer->superimposition);
300 fViewer->setSuperimpositionEnabled(fViewer->superimposition, FALSE);
301 WritePDF();
302 if (superimpState)
303 fViewer->setSuperimpositionEnabled(fViewer->superimposition, TRUE);
304}
305
306void G4OpenInventorQtViewer::FileWriteIVCB()
307{
308 // G4cout << "G4OIQtViewer: File: Write IV CALLBACK" << G4endl;
309 WriteInventor();
310}
311
312void G4OpenInventorQtViewer::FileEscapeCB()
313{
314 // G4cout << "G4OIQtViewer: File: Escape CALLBACK" << G4endl;
315 static_cast<G4SoQt*>(fInteractorManager)->ExitSecondaryLoop();
316 // Escape();
317}
318
319// Etc menu...
320
321void
322G4OpenInventorQtViewer::EtcEraseDetectorCB()
323{
324 // G4cout << "G4OIQtViewer: Etc: Erase Detector CALLBACK" << G4endl;
325 EraseDetector();
326}
327
328void
329G4OpenInventorQtViewer::EtcEraseEventCB()
330{
331 // G4cout << "G4OIQtViewer: Etc: Erase Event CALLBACK" << G4endl;
332 EraseEvent();
333}
334
335void G4OpenInventorQtViewer::EtcSetSolidCB()
336{
337 // G4cout << "G4OIQtViewer: Etc: Set Solid CALLBACK" << G4endl;
338 SetSolid();
339}
340
341void G4OpenInventorQtViewer::EtcSetReducedWireframeCB()
342{
343 // G4cout << "G4OIQtViewer: Etc: Set Reduced Wireframe CALLBACK" << G4endl;
344 SetReducedWireFrame(true);
345}
346
347void G4OpenInventorQtViewer::EtcSetFullWireframeCB()
348{
349 // G4cout << "G4OIQtViewer: Etc: Set Full Wireframe CALLBACK" << G4endl;
350 SetReducedWireFrame(false);
351}
352
353void G4OpenInventorQtViewer::EtcVisibMInvisibDCB()
354{
355 // G4cout << "G4OIQtViewer: Etc: Visible Mothers + Invisible Daughters"
356 // " CALLBACK" << G4endl;
357 SetPreview();
358}
359
360void G4OpenInventorQtViewer::EtcVisibMVisibDCB()
361{
362 // G4cout << "G4OIQtViewer: Etc: Visible Mothers + Visible Daughters"
363 // "CALLBACK" << G4endl;
364 SetPreviewAndFull();
365}
366
367void G4OpenInventorQtViewer::EtcUpdateSceneCB()
368{
369 // G4cout << "G4OIQtViewer: Etc: Update Scene CALLBACK" << G4endl;
370 UpdateScene();
371}
372
373void G4OpenInventorQtViewer::EtcSceneGraphStatsCB()
374{
375 // G4cout << "G4OIQtViewer: Etc: Scene Graph Stats CALLBACK" << G4endl;
376 SceneGraphStatistics();
377}
378
379
380#endif
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23
#define SoGL2PSAction
Definition: SoGL2PSAction.h:38
G4double GetBlue() const
Definition: G4Colour.hh:152
G4double GetRed() const
Definition: G4Colour.hh:150
G4double GetGreen() const
Definition: G4Colour.hh:151
static Verbosity GetVerbosity()
const char * name(G4int ptype)