ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenInventorQtViewer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4OpenInventorQtViewer.cc
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 <Xm/Xm.h>
44 //#include <Xm/PushB.h>
45 //#include <Xm/Form.h>
46 //#include <Xm/CascadeB.h>
47 //#include <Xm/RowColumn.h>
48 //#include <Xm/Text.h>
49 
51 
52 #include "G4OpenInventor.hh"
54 #include "G4VInteractorManager.hh"
55 #include "G4VisManager.hh"
56 
57 G4OpenInventorQtViewer::G4OpenInventorQtViewer(
58  G4OpenInventorSceneHandler& sceneHandler, const G4String& name)
59  : G4OpenInventorViewer(sceneHandler, name)
60  , fViewer(0)
61 {
62  // FWJ fName is in G4VViewer parent of G4OpenInventorViewer
64  G4cout << "Window name: " << fName << G4endl;
65 }
66 
67 
68 void G4OpenInventorQtViewer::Initialise()
69 {
70 
71  QWidget* parent = SoQt::getTopLevelWidget();
72 
73  G4cout << "G4OIQtViewer: Creating G4OIQtExaminerViewer with parent " <<
74  parent << G4endl;
75 
76  // fViewer = new SoQtExaminerViewer(parent, "Geant4", TRUE);
77  fViewer = new G4OpenInventorQtExaminerViewer(parent, "Geant4", TRUE);
78 
79  // G4String wName = fName;
80  //
81  // QWidget parent = (QWidget)fInteractorManager->GetParentInteractor();
82  int width = 600;
83  int height = 600;
84 
85  // FWJ not sure what this is for
86  // fInteractorManager->AddShell(fShell);
87 
88  // FWJ or this:
89  // } else {
90  // char* str = fInteractorManager->GetCreationString();
91  // if(str!=0) wName = str;
92  // fViewer = new SoQtExaminerViewer(parent,wName.c_str(),TRUE);
93  // }
94 
95  fViewer->setSize(SbVec2s(width, height));
96 
97  // Have a GL2PS render action :
98  const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
99  fGL2PSAction = new SoGL2PSAction(vpRegion);
100  fViewer->setGLRenderAction(fGL2PSAction);
101 
102  // Else :
103  G4cout << "G4OpenInventorQtViewer: setting scene graph " <<
104  fSoSelection << G4endl;
105  G4cout << "G4OpenInventorQtViewer: getNumChildren " <<
106  fSoSelection->getNumChildren() << G4endl;
107  fViewer->setSceneGraph(fSoSelection);
108  fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
109  fViewer->viewAll();
110  fViewer->saveHomePosition();
111  fViewer->setTitle(fName);
112  fViewer->show();
113 
114  // This SHOULD invoke the event loop:
115  // if(fShell) {
116  QWidget* mainWin = SoQt::getTopLevelWidget();
117  G4cout << "G4OIQtViewer: calling SoQt::show on mainWin = " << mainWin
118  << G4endl;
119  SoQt::show(mainWin);
120  fInteractorManager->FlushAndWaitExecution();
121  // }
122  fInteractorManager->SetCreatedInteractor(fViewer->getWidget());
123 }
124 
125 G4OpenInventorQtViewer::~G4OpenInventorQtViewer()
126 {
127  // if(fShell) fInteractorManager->RemoveShell(fShell);
128  if(fViewer) {
129  fViewer->setSceneGraph(0);
130  //FIXME : SGI : the below "delete" block things.
131  //FIXME : CoinXt : the below "delete" crashe in ~SoXtRenderArea.
132  //FIXME : delete fViewer;
133  }
134  // if(fShell) XtDestroyWidget(fShell);
135 }
136 
137 void G4OpenInventorQtViewer::FinishView()
138 {
139  if(!fViewer) return;
140  fViewer->viewAll();
141  fViewer->saveHomePosition();
142 }
143 
144 void G4OpenInventorQtViewer::SetView()
145 {
146  G4OpenInventorViewer::SetView();
147  if(!fViewer) return;
148  // Background.
149  G4Colour b = fVP.GetBackgroundColour();
150  fViewer->setBackgroundColor
151  (SbColor((float)b.GetRed(),(float)b.GetGreen(),(float)b.GetBlue()));
152 }
153 
154 
155 void G4OpenInventorQtViewer::ViewerRender()
156 {
157  if(!fViewer) return;
158  fViewer->render();
159 }
160 
161 SoCamera* G4OpenInventorQtViewer::GetCamera () {
162  if(!fViewer) return 0;
163  return fViewer->getCamera();
164 }
165 
166 
167 // FWJ need new implementation in SoQt for the following...
168 //Widget G4OpenInventorQtViewer::AddMenu(
169 // Widget aMenuBar
170 //,const G4String& aName
171 //,const G4String& aLabel
172 //)
173 //{
174  // // Pulldown menu :
175  // Widget menu = XmCreatePulldownMenu(aMenuBar,(char*)aName.c_str(),NULL,0);
176  // // Cascade button :
177  // Arg args[2];
178  // XmString cps =
179  // XmStringLtoRCreate((char*)aLabel.c_str(),(char*)XmSTRING_DEFAULT_CHARSET);
180  // XtSetArg (args[0],XmNlabelString,cps);
181  // XtSetArg (args[1],XmNsubMenuId,menu);
182  // Widget widget = XmCreateCascadeButton(aMenuBar,(char*)aName.c_str(),args,2);
183  // XmStringFree (cps);
184  // XtManageChild(widget);
185  // return menu;
186 //}
187 
188 // void G4OpenInventorQtViewer::AddButton (
189 // Widget aMenu
190 // ,const G4String& aLabel
191 // ,XtCallbackProc aCallback
192 // )
193 // {
194  // Widget widget = XmCreatePushButton(aMenu,(char*)aLabel.c_str(),NULL,0);
195  // XtManageChild(widget);
196  // XtAddCallback(widget,XmNactivateCallback,aCallback,(XtPointer)this);
197 //}
198 
199 //void G4OpenInventorQtViewer::HelpCancelCbk(
200  // Widget,XtPointer aData,XtPointer) {
201  // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
202  // XtUnmanageChild(This->fHelpForm);
203 //}
204 
205 
206 // void G4OpenInventorQtViewer::EscapeCbk(
207  // Widget,XtPointer aData,XtPointer) {
208  // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
209  // This->Escape();
210 //}
211 
212 // void G4OpenInventorQtViewer::PostScriptCbk(
213  // Widget,XtPointer aData,XtPointer) {
214  // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
215  // This->WritePostScript();
216 //}
217 
218 //void G4OpenInventorQtViewer::PixmapPostScriptCbk(
219  // Widget,XtPointer aData,XtPointer) {
220  // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
221  // This->WritePixmapPostScript();
222 //}
223 
224 //void G4OpenInventorQtViewer::SceneGraphStatisticsCbk(
225  // Widget,XtPointer aData,XtPointer) {
226  // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
227  // This->SceneGraphStatistics();
228 //}
229 
230 //void G4OpenInventorQtViewer::WriteInventorCbk(
231  // Widget,XtPointer aData,XtPointer) {
232  // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
233  // This->WriteInventor();
234 //}
235 
236 //void G4OpenInventorQtViewer::EraseDetectorCbk(
237  // Widget,XtPointer aData,XtPointer) {
238  // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
239  // This->EraseDetector();
240 //}
241 
242 //void G4OpenInventorQtViewer::EraseEventCbk(
243  // Widget,XtPointer aData,XtPointer) {
244  // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
245  // This->EraseEvent();
246 //}
247 
248 //void G4OpenInventorQtViewer::SetSolidCbk(
249  // Widget,XtPointer aData,XtPointer) {
250  // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
251  // This->SetSolid();
252 //}
253 
254 //void G4OpenInventorQtViewer::SetWireFrameCbk(
255  // Widget,XtPointer aData,XtPointer) {
256  // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
257  // This->SetWireFrame();
258 //}
259 
260 // void G4OpenInventorQtViewer::SetReducedWireFrameCbk(
261 // Widget,XtPointer aData,XtPointer) {
262 // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
263 // This->SetReducedWireFrame(true);
264 // }
265 
266 // void G4OpenInventorQtViewer::SetFullWireFrameCbk(
267 // Widget,XtPointer aData,XtPointer) {
268 // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
269 // This->SetReducedWireFrame(false);
270 // }
271 
272 // void G4OpenInventorQtViewer::UpdateSceneCbk(
273 // Widget,XtPointer aData,XtPointer) {
274 // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
275 // This->UpdateScene();
276 // }
277 
278 // void G4OpenInventorQtViewer::SetPreviewCbk(
279 // Widget,XtPointer aData,XtPointer) {
280 // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
281 // This->SetPreview();
282 // }
283 
284 // void G4OpenInventorQtViewer::SetPreviewAndFullCbk(
285 // Widget,XtPointer aData,XtPointer) {
286 // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
287 // This->SetPreviewAndFull();
288 // }
289 
290 // void G4OpenInventorQtViewer::HelpCbk(
291 // Widget,XtPointer aData,XtPointer) {
292 // G4OpenInventorQtViewer* This = (G4OpenInventorQtViewer*)aData;
293 // XtManageChild(This->fHelpForm);
294 // XmTextSetString(This->fHelpText,(char*)This->Help().c_str());
295 // }
296 
297 #endif