source: trunk/source/visualization/OpenInventor/src/G4OpenInventorWinViewer.cc@ 1358

Last change on this file since 1358 was 1347, checked in by garnier, 15 years ago

geant4 tag 9.4

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