Geant4-11
G4OpenInventorWinViewer.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 : Mods for SoXtHepViewer
31 * gb : on Win32 use an SoXtExaminerViewer.
32 * gb : 05 April 2004 : creation.
33 * gb : 09 November 2004 : Pulldown menu with the escape menu item.
34 * gb 14 November 2004 : inherit G4OpenInventorViewer.
35 */
36
37// this :
39
40#include <Inventor/nodes/SoSelection.h>
41
42#include <Inventor/Win/SoWin.h>
43#include <Inventor/Win/viewers/SoWinExaminerViewer.h>
44
46
47#include "G4OpenInventor.hh"
50#include "G4VisManager.hh"
51
52#include <windowsx.h>
53
54// To have sizeChanged public :
55class Geant4_SoWinExaminerViewer : public SoWinExaminerViewer {
56public:
57 Geant4_SoWinExaminerViewer(HWND parent,const char* name,SbBool embed)
58 :SoWinExaminerViewer(parent,name,embed){}
59 virtual void sizeChanged(const SbVec2s & size){
60 SoWinExaminerViewer::sizeChanged(size);
61 }
62};
63
64// File :
65#define ID_FILE_POSTSCRIPT 1
66#define ID_FILE_PIXMAP_POSTSCRIPT 2
67#define ID_FILE_INVENTOR 3
68#define ID_FILE_ESCAPE 4
69// Etc :
70#define ID_ETC_ERASE_DETECTOR 101
71#define ID_ETC_ERASE_EVENT 102
72#define ID_ETC_SET_SOLID 103
73#define ID_ETC_SET_WIRE_FRAME 104
74#define ID_ETC_SET_REDUCED_WIRE_FRAME 105
75#define ID_ETC_SET_FULL_WIRE_FRAME 106
76#define ID_ETC_SET_PREVIEW 107
77#define ID_ETC_SET_PREVIEW_AND_FULL 108
78#define ID_ETC_UPDATE_SCENE 109
79#define ID_ETC_STATS 110
80// Help :
81#define ID_HELP_CONTROLS 201
82
83//static void SecondaryLoopPostAction ();
84
85static const char className[] = "G4OpenInventorShellWindow";
86
88 G4OpenInventorSceneHandler& sceneHandler
89,const G4String& name)
90:G4OpenInventorViewer (sceneHandler, name)
91,fShell(0)
92,fViewer(0)
93{
95 G4cout << "Window name: " << fName << G4endl;
96}
97
98
100
101 G4String wName = fName;
102
103 int width = fVP.GetWindowSizeHintX();
104 int height = fVP.GetWindowSizeHintY();;
105
106 HWND parent = (HWND)fInteractorManager->GetParentInteractor ();
107 if(!parent) {
108 //Create a shell window :
109 G4String shellName = wName;
110 shellName += "_shell";
111 static SbBool done = FALSE;
112 if(done==FALSE) {
113 HBRUSH brush = (HBRUSH) GetSysColorBrush(COLOR_BTNFACE);
114 WNDCLASS wc;
115 wc.style = CS_HREDRAW | CS_VREDRAW;
116 wc.lpfnWndProc = (WNDPROC)WindowProc;
117 wc.cbClsExtra = 0;
118 wc.cbWndExtra = 0;
119 wc.hInstance = ::GetModuleHandle(0);
120 wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
121 wc.hCursor = ::LoadCursor(0, IDC_ARROW);
122 wc.hbrBackground = brush;
123 wc.lpszMenuName = className;
124 wc.lpszClassName = className;
125 ::RegisterClass(&wc);
126 done = TRUE;
127 }
128
129 width = fVP.GetWindowSizeHintX();
130 height = fVP.GetWindowSizeHintX();
131
132 HMENU menuBar = CreateMenu();
133
134 {HMENU casc = CreatePopupMenu();
135 ::AppendMenu(menuBar,MF_POPUP,(UINT)casc,"File");
136 ::AppendMenu(casc,MF_STRING,ID_FILE_POSTSCRIPT,"PS (gl2ps)");
137 ::AppendMenu(casc,MF_STRING,ID_FILE_PIXMAP_POSTSCRIPT,"PS (pixmap)");
138 ::AppendMenu(casc,MF_STRING,ID_FILE_INVENTOR,"IV");
139 ::AppendMenu(casc,MF_STRING,ID_FILE_ESCAPE,"Escape");}
140
141 {HMENU casc = CreatePopupMenu();
142 ::AppendMenu(menuBar,MF_POPUP,(UINT)casc,"Etc");
143 ::AppendMenu(casc,MF_STRING,ID_ETC_ERASE_DETECTOR,"Erase detector");
144 ::AppendMenu(casc,MF_STRING,ID_ETC_ERASE_EVENT,"Erase event");
145 ::AppendMenu(casc,MF_STRING,ID_ETC_SET_SOLID,"Set solid");
146 //::AppendMenu(casc,MF_STRING,ID_ETC_SET_WIRE_FRAME,"Set (G4) wire frame");
147 ::AppendMenu(casc,MF_STRING,ID_ETC_SET_REDUCED_WIRE_FRAME,
148 "Set (G4) reduced wire frame");
149 ::AppendMenu(casc,MF_STRING,ID_ETC_SET_FULL_WIRE_FRAME,
150 "Set (G4) full wire frame");
151 ::AppendMenu(casc,MF_STRING,ID_ETC_SET_PREVIEW,
152 "Visible mothers + invisible daughters");
153 ::AppendMenu(casc,MF_STRING,ID_ETC_SET_PREVIEW_AND_FULL,
154 "Visible mothers + visible daughters");
155 ::AppendMenu(casc,MF_STRING,ID_ETC_UPDATE_SCENE,"Update scene");
156 ::AppendMenu(casc,MF_STRING,ID_ETC_STATS,"Scene graph stats");}
157
158 {HMENU casc = CreatePopupMenu();
159 ::AppendMenu(menuBar,MF_POPUP,(UINT)casc,"Help");
160 ::AppendMenu(casc,MF_STRING,ID_HELP_CONTROLS,"Controls");}
161
162 fShell = ::CreateWindow(className, shellName.c_str(),
163 WS_OVERLAPPEDWINDOW |
164 WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
165 CW_USEDEFAULT, CW_USEDEFAULT,
166 width,height,
167 0,menuBar,::GetModuleHandle(0),0);
168 // Retreive window and client sizez :
169 RECT wrect,crect;
170 GetWindowRect((HWND)fShell,&wrect);
171 GetClientRect((HWND)fShell,&crect);
172 int ww = wrect.right-wrect.left;
173 int wh = wrect.bottom-wrect.top;
174 int cw = crect.right-crect.left;
175 int ch = crect.bottom-crect.top;
176 // Compell client rect to be width height :
177 MoveWindow((HWND)fShell,wrect.left,wrect.top,width+ww-cw,height+wh-ch,TRUE);
178 ::SetWindowLongPtr((HWND)fShell,GWLP_USERDATA,LONG(this));
179 ::SetWindowText((HWND)fShell,shellName.c_str());
180 parent = fShell;
182 } else {
184 if(str!=0) wName = str;
185 }
186 fViewer = new Geant4_SoWinExaminerViewer(parent,wName.c_str(),TRUE);
187
188 // Have a GL2PS render action :
189 const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
190 fGL2PSAction = new SoGL2PSAction(vpRegion);
191 fViewer->setGLRenderAction(fGL2PSAction);
192
193 fViewer->setSize(SbVec2s(width,height));
194 fViewer->setSceneGraph(fSoSelection);
195 fViewer->viewAll();
196 fViewer->saveHomePosition();
197 fViewer->setTitle(fName);
198 fViewer->show();
199 if(fShell) {
200 SoWin::show(fShell);
202 }
204 fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
205}
206
209 if(fViewer) {
210 fViewer->setSceneGraph(0);
211 delete fViewer;
212 }
213 if(fShell) {
214 ::SetWindowLongPtr((HWND)fShell,GWLP_USERDATA,LONG(0));
215 ::DestroyWindow((HWND)fShell);
216 }
217}
218
220 if(!fViewer) return;
221 fViewer->viewAll();
222 fViewer->saveHomePosition();
223}
224
227 if(!fViewer) return;
228 // Background.
230 fViewer->setBackgroundColor
231 (SbColor((float)b.GetRed(),(float)b.GetGreen(),(float)b.GetBlue()));
232}
234 if(!fViewer) return;
235 fViewer->render();
236}
237
239 if(!fViewer) return 0;
240 return fViewer->getCamera();
241}
242
243
246 HWND aWindow
247,UINT aMessage
248,WPARAM aWParam
249,LPARAM aLParam
250)
252// Below treatment of WM_SIZE, WM_SETFOCUS not necessary
253// with TGS, but needed with SoFree. WM_DESTROY needed for
254// 'main top level window' so that 'Close window' induces
255// the end of the task.
257{
258 switch (aMessage) {
259 case WM_SIZE:{ // Assume one child window !
260 int width = LOWORD(aLParam);
261 int height = HIWORD(aLParam);
262 //printf("debug : G4SoWindow : WMS_SIZE : %d %d\n",width,height);
264 (G4OpenInventorWinViewer*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
265 if(This && This->fViewer) {
266 This->fViewer->sizeChanged(SbVec2s(width,height));
267 }
268 }return 0;
269 case WM_SETFOCUS:{ // Assume one child window !
270 HWND hwnd = ::GetFirstChild(aWindow);
271 if(hwnd!=0) ::SetFocus(hwnd);
272 }return 0;
273 case WM_DESTROY:{
274 //G4OpenInventorWinViewer* This =
275 // (G4OpenInventorWinViewer*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
276 //::PostQuitMessage(0);
277 }return 0;
278 case WM_COMMAND:{
280 (G4OpenInventorWinViewer*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
281 if(This) {
282 if(aLParam==0) { //From menu.
283 // File :
284 if(aWParam==ID_FILE_POSTSCRIPT) {
285 This->WritePostScript();
286 } else if(aWParam==ID_FILE_PIXMAP_POSTSCRIPT) {
287 This->WritePixmapPostScript();
288 } else if(aWParam==ID_FILE_INVENTOR) {
289 This->WriteInventor();
290 } else if(aWParam==ID_FILE_ESCAPE) {
291 This->Escape();
292 // Etc :
293 } else if(aWParam==ID_ETC_ERASE_DETECTOR) {
294 This->EraseDetector();
295 } else if(aWParam==ID_ETC_ERASE_EVENT) {
296 This->EraseEvent();
297 } else if(aWParam==ID_ETC_SET_SOLID) {
298 This->SetSolid();
299 } else if(aWParam==ID_ETC_SET_WIRE_FRAME) {
300 This->SetWireFrame();
301 } else if(aWParam==ID_ETC_SET_REDUCED_WIRE_FRAME) {
302 This->SetReducedWireFrame(true);
303 } else if(aWParam==ID_ETC_SET_FULL_WIRE_FRAME) {
304 This->SetReducedWireFrame(false);
305 } else if(aWParam==ID_ETC_SET_PREVIEW) {
306 This->SetPreview();
307 } else if(aWParam==ID_ETC_SET_PREVIEW_AND_FULL) {
308 This->SetPreviewAndFull();
309 } else if(aWParam==ID_ETC_UPDATE_SCENE) {
310 This->UpdateScene();
311 } else if(aWParam==ID_ETC_STATS) {
312 This->SceneGraphStatistics();
313 // Help :
314 } else if(aWParam==ID_HELP_CONTROLS) {
315 G4cout << This->Help() << G4endl;
316 }
317 }
318 }
319 }return 0;
320 default:
321 return (::DefWindowProc(aWindow,aMessage,aWParam,aLParam));
322 }
323}
#define ID_ETC_SET_WIRE_FRAME
#define ID_ETC_SET_FULL_WIRE_FRAME
#define ID_ETC_UPDATE_SCENE
#define ID_ETC_SET_PREVIEW_AND_FULL
#define ID_ETC_STATS
#define ID_FILE_PIXMAP_POSTSCRIPT
static const char className[]
#define ID_ETC_SET_PREVIEW
#define ID_ETC_ERASE_DETECTOR
#define ID_ETC_SET_REDUCED_WIRE_FRAME
#define ID_HELP_CONTROLS
#define ID_FILE_POSTSCRIPT
#define ID_ETC_ERASE_EVENT
#define ID_ETC_SET_SOLID
#define ID_FILE_ESCAPE
#define ID_FILE_INVENTOR
#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: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 LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
G4OpenInventorWinViewer(G4OpenInventorSceneHandler &scene, const G4String &name="")
Geant4_SoWinExaminerViewer * fViewer
void SetCreatedInteractor(G4Interactor)
virtual void FlushAndWaitExecution()=0
G4Interactor GetParentInteractor()
void RemoveShell(G4Interactor)
void AddShell(G4Interactor)
G4String fName
Definition: G4VViewer.hh:217
G4ViewParameters fVP
Definition: G4VViewer.hh:219
unsigned int GetWindowSizeHintX() const
const G4Colour & GetBackgroundColour() const
unsigned int GetWindowSizeHintY() const
static Verbosity GetVerbosity()
virtual void sizeChanged(const SbVec2s &size)
Geant4_SoWinExaminerViewer(HWND parent, const char *name, SbBool embed)
const char * name(G4int ptype)