Geant4 11.1.1
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// this :
30
32
33#include <Inventor/nodes/SoSelection.h>
34
35#include <Inventor/Qt/SoQt.h>
36// FWJ these are needed (why?) to use flags in SoQtExaminerViewer constr.
37#include <Inventor/Qt/viewers/SoQtViewer.h>
38#include <Inventor/Qt/viewers/SoQtFullViewer.h>
39#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
40
41//#include <QMenuBar>
42#include <QMenu>
43#include <QAction>
44#include <QFont>
45
47
48#include "G4OpenInventor.hh"
51#include "G4VisManager.hh"
52#include "G4UImanager.hh"
53#include "G4UIQt.hh"
54
55#include "G4SoQt.hh"
56
57#ifndef G4GMAKE
58#include "moc_G4OpenInventorQtViewer.cpp"
59#endif
60
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
72{
73
74 QWidget* parent = SoQt::getTopLevelWidget();
75
76 // FWJ DEBUG
77 // G4cout << "G4OIQtViewer: Creating G4OIQtExaminerViewer with parent " <<
78 // parent << G4endl;
79
81
82 // FWJ tried this to replace sensors, but it misses some camera changes.
83 // fGroupCameraSensor->detach();
84 // fCameraSensor->detach();
85 // fViewer->addFinishCallback(FinishCB);
86
87 auto UI = G4UImanager::GetUIpointer();
88 auto uiQt = dynamic_cast<G4UIQt*>(UI->GetG4UIWindow());
89
90 // Moved this to G4OpenInventorQtExaminerViewer::afterRealizeHook()
91 ///////////////////////////////////////////////////////////
92 //
93 // This explicitly sets the TabWidget as parent before addTab():
94 // if (uiQt) uiQt->AddTabWidget(parent, QString(fName));
95 ///////////////////////////////////////////////////////////
96
97 // Simpler: calls addTab(), but causes viewer parts to show (temporarily)
98 // in the "Useful tips" page !!
99 // if (uiQt) uiQt->AddViewerTab(parent, fName);
100 // Leaves an empty viewer window frame hanging around:
101 // if (uiQt) uiQt->AddTabWidget(fViewer->getWidget(), QString(fName));
102
103 // G4String wName = fName;
104 //
105 // QWidget parent = (QWidget)fInteractorManager->GetParentInteractor();
106
107 int width = fVP.GetWindowSizeHintX();
108 int height = fVP.GetWindowSizeHintY();
109
110 // FWJ not sure what this is for
111 // fInteractorManager->AddShell(fShell);
112
113 // FWJ or this:
114 // } else {
115 // char* str = fInteractorManager->GetCreationString();
116 // if(str!=0) wName = str;
117 // fViewer = new SoQtExaminerViewer(parent,wName.c_str(),TRUE);
118 // }
119
120 fViewer->setSize(SbVec2s(width, height));
121 fViewer->setOrigWindowSize(width, height);
122
123 // Add common menu items...
124
125 // QMenuBar* menubar = fViewer->getMenubar();
126 QMenu* filemenu = fViewer->getFileMenu();
127 QMenu* etcmenu = fViewer->getEtcMenu();
128 QFont* font = fViewer->getFont();
129
130 // File menu
131
132 FileWritePS = new QAction("Write PostScript (gl2ps)", this);
133 FileWritePS->setFont(*font);
134 connect(FileWritePS, SIGNAL(triggered()), this,
135 SLOT(FileWritePSCB()));
136 filemenu->addAction(FileWritePS);
137
138 FileWritePDF = new QAction("Write PDF (gl2ps)", this);
139 FileWritePDF->setFont(*font);
140 connect(FileWritePDF, SIGNAL(triggered()), this,
141 SLOT(FileWritePDFCB()));
142 filemenu->addAction(FileWritePDF);
143
144 FileWriteIV = new QAction("Write IV", this);
145 FileWriteIV->setFont(*font);
146 connect(FileWriteIV, SIGNAL(triggered()), this,
147 SLOT(FileWriteIVCB()));
148 filemenu->addAction(FileWriteIV);
149
150 FileEscape = new QAction("Escape", this);
151 FileEscape->setFont(*font);
152 connect(FileEscape, SIGNAL(triggered()), this,
153 SLOT(FileEscapeCB()));
154 filemenu->addAction(FileEscape);
155
156 // G4cout << "G4OIQtViewer: externalApp = " <<
157 // static_cast<G4SoQt*>(fInteractorManager)->IsExternalApp() << G4endl;
158 if (static_cast<G4SoQt*>(fInteractorManager)->IsExternalApp())
160
161 // Register escape CB with viewer, allowing E key escape
162 // fViewer->addEscapeCallback(FileEscapeCB);
163 // fViewer->addEscapeCallback(FileEscapeCB, (void*)this);
164
165 // Etc menu
166
167 EtcEraseDetector = new QAction("Erase detector", this);
168 EtcEraseDetector->setFont(*font);
169 connect(EtcEraseDetector, SIGNAL(triggered()), this,
170 SLOT(EtcEraseDetectorCB()));
171 etcmenu->addAction(EtcEraseDetector);
172
173 EtcEraseEvent = new QAction("Erase event", this);
174 EtcEraseEvent->setFont(*font);
175 connect(EtcEraseEvent, SIGNAL(triggered()), this,
176 SLOT(EtcEraseEventCB()));
177 etcmenu->addAction(EtcEraseEvent);
178
179 EtcSetSolid = new QAction("Set solid", this);
180 EtcSetSolid->setFont(*font);
181 connect(EtcSetSolid, SIGNAL(triggered()), this, SLOT(EtcSetSolidCB()));
182 etcmenu->addAction(EtcSetSolid);
183
184 EtcSetReducedWireframe = new QAction("Set (G4) reduced wireframe", this);
185 EtcSetReducedWireframe->setFont(*font);
186 connect(EtcSetReducedWireframe, SIGNAL(triggered()), this,
187 SLOT(EtcSetReducedWireframeCB()));
188 etcmenu->addAction(EtcSetReducedWireframe);
189
190 EtcSetFullWireframe = new QAction("Set full wireframe", this);
191 EtcSetFullWireframe->setFont(*font);
192 connect(EtcSetFullWireframe, SIGNAL(triggered()), this,
193 SLOT(EtcSetFullWireframeCB()));
194 etcmenu->addAction(EtcSetFullWireframe);
195
196 EtcVisibMInvisibD = new QAction("Visible mothers + invisible daughters",
197 this);
198 EtcVisibMInvisibD->setFont(*font);
199 connect(EtcVisibMInvisibD, SIGNAL(triggered()), this,
200 SLOT(EtcVisibMInvisibDCB()));
201 etcmenu->addAction(EtcVisibMInvisibD);
202
203 EtcVisibMVisibD = new QAction("Visible mothers + visible daughters", this);
204 EtcVisibMVisibD->setFont(*font);
205 connect(EtcVisibMVisibD, SIGNAL(triggered()), this,
206 SLOT(EtcVisibMVisibDCB()));
207 etcmenu->addAction(EtcVisibMVisibD);
208
209 EtcUpdateScene = new QAction("Update scene", this);
210 EtcUpdateScene->setFont(*font);
211 connect(EtcUpdateScene, SIGNAL(triggered()), this,
212 SLOT(EtcUpdateSceneCB()));
213 etcmenu->addAction(EtcUpdateScene);
214
215 EtcSceneGraphStats = new QAction("Scene graph stats", this);
216 EtcSceneGraphStats->setFont(*font);
217 connect(EtcSceneGraphStats, SIGNAL(triggered()), this,
218 SLOT(EtcSceneGraphStatsCB()));
219 etcmenu->addAction(EtcSceneGraphStats);
220
221
222 // Have a GL2PS render action :
223 const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
224 fGL2PSAction = new SoGL2PSAction(vpRegion);
225 fViewer->setGLRenderAction(fGL2PSAction);
226
227 // Else :
228
229 // FWJ DEBUG
230 // G4cout << "G4OpenInventorQtViewer: setting scene graph " <<
231 // fSoSelection << G4endl;
232 // G4cout << "G4OpenInventorQtViewer: getNumChildren " <<
233 // fSoSelection->getNumChildren() << G4endl;
234
235 fViewer->setSceneGraph(fSoSelection);
236 fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
237 fViewer->viewAll();
238 fViewer->saveHomePosition();
239 // SOMEHOW this also the OIQt main window title
240 if (!uiQt) fViewer->setTitle(fName);
241 fViewer->show();
242
243 // This SHOULD invoke the event loop:
244 // if(fShell) {
245
246 QWidget* mainWin = SoQt::getTopLevelWidget();
247
248 // FWJ DEBUG
249 // G4cout << "G4OIQtViewer: calling SoQt::show on mainWin = " << mainWin
250 // << G4endl;
251
252 SoQt::show(mainWin);
254
255 // }
257}
258
259
261{
262 // if(fShell) fInteractorManager->RemoveShell(fShell);
263 if(fViewer) {
264 fViewer->setSceneGraph(0);
265 //FIXME : SGI : the below "delete" block things.
266 //FIXME : CoinXt : the below "delete" crashe in ~SoXtRenderArea.
267 //FIXME : delete fViewer;
268 }
269 // if(fShell) XtDestroyWidget(fShell);
270}
271
273{
274 if(!fViewer) return;
275 fViewer->viewAll();
276 fViewer->saveHomePosition();
277}
278
280{
282 if(!fViewer) return;
283 // Background.
285 fViewer->setBackgroundColor
286 (SbColor((float)b.GetRed(),(float)b.GetGreen(),(float)b.GetBlue()));
287}
288
290{
291 if(!fViewer) return;
292 fViewer->render();
293}
294
296 if(!fViewer) return 0;
297 return fViewer->getCamera();
298}
299
300
301// User interaction finished: update VPs
302//void G4OpenInventorQtViewer::FinishCB(void* data, SoQtViewer* viewer)
303//{
304// G4cout << "FINISHCB CALLED !!!!!" << G4endl;
305//}
306
307
308// File menu...
309
310void G4OpenInventorQtViewer::FileWritePSCB()
311{
312 // G4cout << "G4OIQtViewer: File: Write PS CALLBACK" << G4endl;
313 // FWJ Workaround: avoids empty 2nd page in file
314 SbBool superimpState =
315 fViewer->getSuperimpositionEnabled(fViewer->superimposition);
316 fViewer->setSuperimpositionEnabled(fViewer->superimposition, FALSE);
318 if (superimpState)
319 fViewer->setSuperimpositionEnabled(fViewer->superimposition, TRUE);
320}
321
322void G4OpenInventorQtViewer::FileWritePDFCB()
323{
324 // G4cout << "G4OIQtViewer: File: Write PDF CALLBACK" << G4endl;
325 // FWJ Workaround: avoids empty 2nd page in file
326 SbBool superimpState =
327 fViewer->getSuperimpositionEnabled(fViewer->superimposition);
328 fViewer->setSuperimpositionEnabled(fViewer->superimposition, FALSE);
329 WritePDF();
330 if (superimpState)
331 fViewer->setSuperimpositionEnabled(fViewer->superimposition, TRUE);
332}
333
334void G4OpenInventorQtViewer::FileWriteIVCB()
335{
336 // G4cout << "G4OIQtViewer: File: Write IV CALLBACK" << G4endl;
338}
339
340void G4OpenInventorQtViewer::FileEscapeCB()
341{
342 // G4cout << "G4OIQtViewer: File: Escape CALLBACK" << G4endl;
343 static_cast<G4SoQt*>(fInteractorManager)->ExitSecondaryLoop();
344 // Escape();
345}
346
347// Etc menu...
348
349void
350G4OpenInventorQtViewer::EtcEraseDetectorCB()
351{
352 // G4cout << "G4OIQtViewer: Etc: Erase Detector CALLBACK" << G4endl;
354}
355
356void
357G4OpenInventorQtViewer::EtcEraseEventCB()
358{
359 // G4cout << "G4OIQtViewer: Etc: Erase Event CALLBACK" << G4endl;
360 EraseEvent();
361}
362
363void G4OpenInventorQtViewer::EtcSetSolidCB()
364{
365 // G4cout << "G4OIQtViewer: Etc: Set Solid CALLBACK" << G4endl;
366 SetSolid();
367}
368
369void G4OpenInventorQtViewer::EtcSetReducedWireframeCB()
370{
371 // G4cout << "G4OIQtViewer: Etc: Set Reduced Wireframe CALLBACK" << G4endl;
373}
374
375void G4OpenInventorQtViewer::EtcSetFullWireframeCB()
376{
377 // G4cout << "G4OIQtViewer: Etc: Set Full Wireframe CALLBACK" << G4endl;
378 SetReducedWireFrame(false);
379}
380
381void G4OpenInventorQtViewer::EtcVisibMInvisibDCB()
382{
383 // G4cout << "G4OIQtViewer: Etc: Visible Mothers + Invisible Daughters"
384 // " CALLBACK" << G4endl;
385 SetPreview();
386}
387
388void G4OpenInventorQtViewer::EtcVisibMVisibDCB()
389{
390 // G4cout << "G4OIQtViewer: Etc: Visible Mothers + Visible Daughters"
391 // "CALLBACK" << G4endl;
393}
394
395void G4OpenInventorQtViewer::EtcUpdateSceneCB()
396{
397 // G4cout << "G4OIQtViewer: Etc: Update Scene CALLBACK" << G4endl;
398 UpdateScene();
399}
400
401void G4OpenInventorQtViewer::EtcSceneGraphStatsCB()
402{
403 // G4cout << "G4OIQtViewer: Etc: Scene Graph Stats CALLBACK" << G4endl;
405}
#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
virtual SoCamera * GetCamera()
G4OpenInventorQtViewer(G4OpenInventorSceneHandler &scene, const G4String &name="")
G4OpenInventorQtExaminerViewer * fViewer
void WriteInventor(const G4String &file="g4out.iv")
void WritePostScript(const G4String &file="g4out.ps")
G4VInteractorManager * fInteractorManager
void WritePDF(const G4String &file="g4out.pdf")
Geant4_SoGL2PSAction * fGL2PSAction
Definition: G4SoQt.hh:46
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void SetCreatedInteractor(G4Interactor)
virtual void FlushAndWaitExecution()=0
G4String fName
Definition: G4VViewer.hh:218
G4ViewParameters fVP
Definition: G4VViewer.hh:220
unsigned int GetWindowSizeHintX() const
const G4Colour & GetBackgroundColour() const
unsigned int GetWindowSizeHintY() const
static Verbosity GetVerbosity()
#define TRUE
Definition: globals.hh:41
#define FALSE
Definition: globals.hh:38