37 #ifdef G4VIS_BUILD_OIWIN32_DRIVER
42 #include <Inventor/nodes/SoSelection.h>
44 #include <Inventor/Win/SoWin.h>
45 #include <Inventor/Win/viewers/SoWinExaminerViewer.h>
57 class Geant4_SoWinExaminerViewer :
public SoWinExaminerViewer {
59 Geant4_SoWinExaminerViewer(HWND parent,
const char*
name,SbBool embed)
60 :SoWinExaminerViewer(parent,name,embed){}
61 virtual void sizeChanged(
const SbVec2s & size){
62 SoWinExaminerViewer::sizeChanged(size);
67 #define ID_FILE_POSTSCRIPT 1
68 #define ID_FILE_PIXMAP_POSTSCRIPT 2
69 #define ID_FILE_INVENTOR 3
70 #define ID_FILE_ESCAPE 4
72 #define ID_ETC_ERASE_DETECTOR 101
73 #define ID_ETC_ERASE_EVENT 102
74 #define ID_ETC_SET_SOLID 103
75 #define ID_ETC_SET_WIRE_FRAME 104
76 #define ID_ETC_SET_REDUCED_WIRE_FRAME 105
77 #define ID_ETC_SET_FULL_WIRE_FRAME 106
78 #define ID_ETC_SET_PREVIEW 107
79 #define ID_ETC_SET_PREVIEW_AND_FULL 108
80 #define ID_ETC_UPDATE_SCENE 109
81 #define ID_ETC_STATS 110
83 #define ID_HELP_CONTROLS 201
87 static const char className[] =
"G4OpenInventorShellWindow";
89 G4OpenInventorWinViewer::G4OpenInventorWinViewer(
90 G4OpenInventorSceneHandler& sceneHandler
92 :G4OpenInventorViewer (sceneHandler, name)
101 void G4OpenInventorWinViewer::Initialise() {
108 HWND parent = (HWND)fInteractorManager->GetParentInteractor ();
112 shellName +=
"_shell";
113 static SbBool done =
FALSE;
115 HBRUSH brush = (HBRUSH) GetSysColorBrush(COLOR_BTNFACE);
117 wc.style = CS_HREDRAW | CS_VREDRAW;
118 wc.lpfnWndProc = (WNDPROC)WindowProc;
121 wc.hInstance = ::GetModuleHandle(0);
122 wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
123 wc.hCursor = ::LoadCursor(0, IDC_ARROW);
124 wc.hbrBackground = brush;
125 wc.lpszMenuName = className;
126 wc.lpszClassName = className;
127 ::RegisterClass(&wc);
131 width = fVP.GetWindowSizeHintX();
132 height = fVP.GetWindowSizeHintX();
134 HMENU menuBar = CreateMenu();
136 {HMENU casc = CreatePopupMenu();
137 ::AppendMenu(menuBar,MF_POPUP,(
UINT)casc,
"File");
138 ::AppendMenu(casc,MF_STRING,ID_FILE_POSTSCRIPT,
"PS (gl2ps)");
139 ::AppendMenu(casc,MF_STRING,ID_FILE_PIXMAP_POSTSCRIPT,
"PS (pixmap)");
140 ::AppendMenu(casc,MF_STRING,ID_FILE_INVENTOR,
"IV");
141 ::AppendMenu(casc,MF_STRING,ID_FILE_ESCAPE,
"Escape");}
143 {HMENU casc = CreatePopupMenu();
144 ::AppendMenu(menuBar,MF_POPUP,(
UINT)casc,
"Etc");
145 ::AppendMenu(casc,MF_STRING,ID_ETC_ERASE_DETECTOR,
"Erase detector");
146 ::AppendMenu(casc,MF_STRING,ID_ETC_ERASE_EVENT,
"Erase event");
147 ::AppendMenu(casc,MF_STRING,ID_ETC_SET_SOLID,
"Set solid");
149 ::AppendMenu(casc,MF_STRING,ID_ETC_SET_REDUCED_WIRE_FRAME,
150 "Set (G4) reduced wire frame");
151 ::AppendMenu(casc,MF_STRING,ID_ETC_SET_FULL_WIRE_FRAME,
152 "Set (G4) full wire frame");
153 ::AppendMenu(casc,MF_STRING,ID_ETC_SET_PREVIEW,
154 "Visible mothers + invisible daughters");
155 ::AppendMenu(casc,MF_STRING,ID_ETC_SET_PREVIEW_AND_FULL,
156 "Visible mothers + visible daughters");
157 ::AppendMenu(casc,MF_STRING,ID_ETC_UPDATE_SCENE,
"Update scene");
158 ::AppendMenu(casc,MF_STRING,ID_ETC_STATS,
"Scene graph stats");}
160 {HMENU casc = CreatePopupMenu();
161 ::AppendMenu(menuBar,MF_POPUP,(
UINT)casc,
"Help");
162 ::AppendMenu(casc,MF_STRING,ID_HELP_CONTROLS,
"Controls");}
164 fShell = ::CreateWindow(className, shellName.c_str(),
165 WS_OVERLAPPEDWINDOW |
166 WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
167 CW_USEDEFAULT, CW_USEDEFAULT,
169 0,menuBar,::GetModuleHandle(0),0);
172 GetWindowRect((HWND)fShell,&wrect);
173 GetClientRect((HWND)fShell,&crect);
174 int ww = wrect.right-wrect.left;
175 int wh = wrect.bottom-wrect.top;
176 int cw = crect.right-crect.left;
177 int ch = crect.bottom-crect.top;
179 MoveWindow((HWND)fShell,wrect.left,wrect.top,width+ww-cw,height+wh-ch,
TRUE);
180 ::SetWindowLongPtr((HWND)fShell,GWLP_USERDATA,LONG(
this));
181 ::SetWindowText((HWND)fShell,shellName.c_str());
183 fInteractorManager->AddShell(fShell);
185 char* str = fInteractorManager->GetCreationString();
186 if(str!=0) wName = str;
188 fViewer =
new Geant4_SoWinExaminerViewer(parent,wName.c_str(),
TRUE);
191 const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
193 fViewer->setGLRenderAction(fGL2PSAction);
195 fViewer->setSize(SbVec2s(width,height));
196 fViewer->setSceneGraph(fSoSelection);
198 fViewer->saveHomePosition();
199 fViewer->setTitle(
fName);
203 fInteractorManager->FlushAndWaitExecution ();
205 fInteractorManager->SetCreatedInteractor (fViewer -> getWidget());
206 fViewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_ADD);
209 G4OpenInventorWinViewer::~G4OpenInventorWinViewer () {
210 if(fShell) fInteractorManager->RemoveShell(fShell);
212 fViewer->setSceneGraph(0);
216 ::SetWindowLongPtr((HWND)fShell,GWLP_USERDATA,LONG(0));
217 ::DestroyWindow((HWND)fShell);
221 void G4OpenInventorWinViewer::FinishView () {
224 fViewer->saveHomePosition();
227 void G4OpenInventorWinViewer::SetView () {
228 G4OpenInventorViewer::SetView ();
232 fViewer->setBackgroundColor
235 void G4OpenInventorWinViewer::ViewerRender () {
240 SoCamera* G4OpenInventorWinViewer::GetCamera () {
241 if(!fViewer)
return 0;
242 return fViewer->getCamera();
247 LRESULT CALLBACK G4OpenInventorWinViewer::WindowProc (
262 int width = LOWORD(aLParam);
263 int height = HIWORD(aLParam);
265 G4OpenInventorWinViewer* This =
266 (G4OpenInventorWinViewer*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
267 if(This && This->fViewer) {
268 This->fViewer->sizeChanged(SbVec2s(width,height));
272 HWND hwnd = ::GetFirstChild(aWindow);
273 if(hwnd!=0) ::SetFocus(hwnd);
281 G4OpenInventorWinViewer* This =
282 (G4OpenInventorWinViewer*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
286 if(aWParam==ID_FILE_POSTSCRIPT) {
287 This->WritePostScript();
288 }
else if(aWParam==ID_FILE_PIXMAP_POSTSCRIPT) {
289 This->WritePixmapPostScript();
290 }
else if(aWParam==ID_FILE_INVENTOR) {
291 This->WriteInventor();
292 }
else if(aWParam==ID_FILE_ESCAPE) {
295 }
else if(aWParam==ID_ETC_ERASE_DETECTOR) {
296 This->EraseDetector();
297 }
else if(aWParam==ID_ETC_ERASE_EVENT) {
299 }
else if(aWParam==ID_ETC_SET_SOLID) {
301 }
else if(aWParam==ID_ETC_SET_WIRE_FRAME) {
302 This->SetWireFrame();
303 }
else if(aWParam==ID_ETC_SET_REDUCED_WIRE_FRAME) {
304 This->SetReducedWireFrame(
true);
305 }
else if(aWParam==ID_ETC_SET_FULL_WIRE_FRAME) {
306 This->SetReducedWireFrame(
false);
307 }
else if(aWParam==ID_ETC_SET_PREVIEW) {
309 }
else if(aWParam==ID_ETC_SET_PREVIEW_AND_FULL) {
310 This->SetPreviewAndFull();
311 }
else if(aWParam==ID_ETC_UPDATE_SCENE) {
313 }
else if(aWParam==ID_ETC_STATS) {
314 This->SceneGraphStatistics();
316 }
else if(aWParam==ID_HELP_CONTROLS) {
323 return (::DefWindowProc(aWindow,aMessage,aWParam,aLParam));