1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
|
namespace Kitware.VTK
{
partial class RenderWindowControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
}
finally
{
base.Dispose(disposing);
}
}
/// <summary>
/// Called to set the vtkRenderWindow size according to this control's
/// Size property.
/// </summary>
internal void SyncRenderWindowSize()
{
if (this.m_RenderWindow != null)
{
this.m_RenderWindow.SetSize(this.Size.Width, this.Size.Height);
}
}
private System.IntPtr XDisplay;
/// <summary>
/// Retrieve the X11 Display* to pass to VTK's vtkRenderWindow::SetDisplayId
/// </summary>
private System.IntPtr GetXDisplay()
{
System.Type xplatui = System.Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
if (xplatui != null)
{
System.IntPtr DisplayHandle = (System.IntPtr)xplatui.
GetField("DisplayHandle", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).
GetValue(null);
XDisplay = DisplayHandle;
// Also, may need possibly:
// Setup correct X visual and colormap so that VTK OpenGL stuff
// works properly on mono/X11. Cache the display value so that we
// can use it to set the RenderWindowId in OnCreated.
//System.IntPtr RootWindow = (System.IntPtr)xplatui.GetField("RootWindow", System.Reflection.BindingFlags.Static |
//System.Reflection.BindingFlags.NonPublic).GetValue(null);
//int ScreenNo = (int)xplatui.GetField("ScreenNo", System.Reflection.BindingFlags.Static |
//System.Reflection.BindingFlags.NonPublic).GetValue(null);
//int[] dblBuf = new int[] { 5, (int)GLXFlags.GLX_RGBA, (int)GLXFlags.GLX_RED_SIZE, 1, (int)GLXFlags.GLX_GREEN_SIZE,
//1, (int)GLXFlags.GLX_BLUE_SIZE, 1, (int)GLXFlags.GLX_DEPTH_SIZE, 1, 0 };
//GLXVisualInfo = glXChooseVisual(DisplayHandle, ScreenNo, dblBuf);
//XVisualInfo xVisualInfo = (XVisualInfo)Marshal.PtrToStructure(GLXVisualInfo, typeof(XVisualInfo));
//System.IntPtr visual = System.IntPtr.Zero; // xVisualInfo.visual;
//System.IntPtr colormap = XCreateColormap(DisplayHandle, RootWindow, visual, 0/*AllocNone*/);
//xplatui.GetField("CustomVisual", System.Reflection.BindingFlags.Static |
//System.Reflection.BindingFlags.NonPublic).SetValue(null, visual);
//xplatui.GetField("CustomColormap", System.Reflection.BindingFlags.Static |
//System.Reflection.BindingFlags.NonPublic).SetValue(null, colormap);
}
return XDisplay;
}
private bool AttachedInteractor;
private void AttachInteractor()
{
if (!this.AttachedInteractor)
{
this.AttachedInteractor = true;
this.m_RenderWindow.SetInteractor(this.m_RenderWindowInteractor);
}
}
/// <summary>
/// OnHandleCreated.
/// </summary>
protected override void OnHandleCreated(System.EventArgs e)
{
if (!this.DesignMode)
{
Kitware.VTK.vtkLogoWidget w = new Kitware.VTK.vtkLogoWidget();
this.m_Renderer = Kitware.VTK.vtkRenderer.New();
this.m_RenderWindow = Kitware.VTK.vtkRenderWindow.New();
System.IntPtr xdisplay = GetXDisplay();
bool isX11 = false;
if (System.IntPtr.Zero != xdisplay)
{
isX11 = true;
}
if (isX11)
{
// If running an X11-based build, then we must use a
// vtkGenericRenderWindowInteractor:
//
this.m_RenderWindowInteractor = Kitware.VTK.vtkGenericRenderWindowInteractor.New();
this.m_RenderWindow.SetDisplayId(xdisplay);
}
else
{
// Allow the native factory method to produce the natively expected subclass
// of vtkRenderWindowInteractor:
//
this.m_RenderWindowInteractor = Kitware.VTK.vtkRenderWindowInteractor.New();
}
Kitware.VTK.vtkInteractorStyleSwitch style = this.m_RenderWindowInteractor.GetInteractorStyle()
as Kitware.VTK.vtkInteractorStyleSwitch;
if (null != style)
{
style.SetCurrentStyleToTrackballCamera();
}
this.m_RenderWindow.SetParentId(this.Handle);
this.m_RenderWindow.AddRenderer(this.m_Renderer);
if (!isX11)
{
this.AttachInteractor();
}
w.Dispose();
}
base.OnHandleCreated(e);
}
/// <summary>
/// OnHandleDestroyed.
/// </summary>
protected override void OnHandleDestroyed(System.EventArgs e)
{
if (this.m_Renderer != null)
{
this.m_Renderer.SetRenderWindow(null);
}
if (this.m_RenderWindowInteractor != null)
{
this.m_RenderWindowInteractor.Dispose();
this.m_RenderWindowInteractor = null;
}
if (this.m_RenderWindow != null)
{
this.m_RenderWindow.Dispose();
this.m_RenderWindow = null;
}
if (this.m_Renderer != null)
{
this.m_Renderer.Dispose();
this.m_Renderer = null;
}
base.OnHandleDestroyed(e);
}
/// <summary>
/// OnMouseDown.
/// </summary>
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
Kitware.VTK.vtkGenericRenderWindowInteractor grwi = this.m_RenderWindowInteractor as Kitware.VTK.vtkGenericRenderWindowInteractor;
if (null != grwi)
{
grwi.SetEventInformationFlipY(e.X, e.Y, 0, 0, 0, e.Clicks, null);
switch (e.Button)
{
case System.Windows.Forms.MouseButtons.Left:
grwi.LeftButtonPressEvent();
break;
case System.Windows.Forms.MouseButtons.Middle:
grwi.MiddleButtonPressEvent();
break;
case System.Windows.Forms.MouseButtons.Right:
grwi.RightButtonPressEvent();
break;
}
}
}
/// <summary>
/// OnMouseMove.
/// </summary>
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
{
Kitware.VTK.vtkGenericRenderWindowInteractor grwi = this.m_RenderWindowInteractor as Kitware.VTK.vtkGenericRenderWindowInteractor;
if (null != grwi)
{
grwi.SetEventInformationFlipY(e.X, e.Y, 0, 0, 0, e.Clicks, null);
grwi.MouseMoveEvent();
}
}
/// <summary>
/// OnMouseUp.
/// </summary>
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
{
Kitware.VTK.vtkGenericRenderWindowInteractor grwi = this.m_RenderWindowInteractor as Kitware.VTK.vtkGenericRenderWindowInteractor;
if (null != grwi)
{
grwi.SetEventInformationFlipY(e.X, e.Y, 0, 0, 0, e.Clicks, null);
switch (e.Button)
{
case System.Windows.Forms.MouseButtons.Left:
grwi.LeftButtonReleaseEvent();
break;
case System.Windows.Forms.MouseButtons.Middle:
grwi.MiddleButtonReleaseEvent();
break;
case System.Windows.Forms.MouseButtons.Right:
grwi.RightButtonReleaseEvent();
break;
}
}
}
/// <summary>
/// OnMouseWheel.
/// </summary>
protected override void OnMouseWheel(System.Windows.Forms.MouseEventArgs e)
{
Kitware.VTK.vtkGenericRenderWindowInteractor grwi = this.m_RenderWindowInteractor as Kitware.VTK.vtkGenericRenderWindowInteractor;
if (null != grwi)
{
grwi.SetEventInformationFlipY(e.X, e.Y, 0, 0, 0, e.Clicks, null);
if (e.Delta > 0)
{
grwi.MouseWheelForwardEvent();
}
else
{
grwi.MouseWheelBackwardEvent();
}
}
}
//string s = "e.KeyCode.ToString(): " + e.KeyCode.ToString();
//System.Windows.Forms.MessageBox.Show(s, "KeyDown1");
//System.Windows.Forms.KeysConverter kc = new System.Windows.Forms.KeysConverter();
//s = "kc.ConvertToString(e.KeyCode): " + kc.ConvertToString(e.KeyCode);
//System.Windows.Forms.MessageBox.Show(s, "KeyDown2");
/// <summary>
/// OnKeyDown.
/// </summary>
protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
Kitware.VTK.vtkGenericRenderWindowInteractor grwi = this.m_RenderWindowInteractor as Kitware.VTK.vtkGenericRenderWindowInteractor;
if (null != grwi)
{
grwi.SetKeyEventInformation(e.Control ? 1 : 0, e.Shift ? 1 : 0, (sbyte) e.KeyCode, 1, null);
grwi.KeyPressEvent();
}
}
/// <summary>
/// OnKeyPress.
/// </summary>
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{
Kitware.VTK.vtkGenericRenderWindowInteractor grwi = this.m_RenderWindowInteractor as Kitware.VTK.vtkGenericRenderWindowInteractor;
if (null != grwi)
{
grwi.SetKeyEventInformation(0, 0, (sbyte) e.KeyChar, 1, e.KeyChar.ToString());
grwi.CharEvent();
}
}
/// <summary>
/// OnKeyUp.
/// </summary>
protected override void OnKeyUp(System.Windows.Forms.KeyEventArgs e)
{
Kitware.VTK.vtkGenericRenderWindowInteractor grwi = this.m_RenderWindowInteractor as Kitware.VTK.vtkGenericRenderWindowInteractor;
if (null != grwi)
{
grwi.SetKeyEventInformation(e.Control ? 1 : 0, e.Shift ? 1 : 0, (sbyte) e.KeyCode, 1, null);
grwi.KeyReleaseEvent();
}
}
/// <summary>
/// OnSizeChanged fires after the Size property has changed value.
/// </summary>
protected override void OnSizeChanged(System.EventArgs e)
{
this.SyncRenderWindowSize();
Kitware.VTK.vtkGenericRenderWindowInteractor grwi = this.m_RenderWindowInteractor as Kitware.VTK.vtkGenericRenderWindowInteractor;
if (null != grwi)
{
grwi.ConfigureEvent();
}
base.OnSizeChanged(e);
this.Invalidate();
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
internal static extern System.IntPtr SetFocus(System.IntPtr hWnd);
/// <summary>
/// OnGotFocus fires after Windows keyboard focus enters the control.
/// </summary>
protected override void OnGotFocus(System.EventArgs e)
{
if (this.m_RenderWindow != null)
{
System.IntPtr hWnd = (System.IntPtr) this.m_RenderWindow.GetGenericWindowId();
if (System.IntPtr.Zero != hWnd)
{
try
{
// TODO: X-Windows equivalent to Win32 SetFocus?
//
// (For now, the try/catch block handles trying to call the Win32
// function even on mono/Linux/Mac, but it would be nice to have
// the correct behavior on all platforms...)
//
SetFocus(hWnd);
}
catch
{
}
}
}
base.OnGotFocus(e);
}
/// <summary>
/// Override to do "last minute cram" of child control...
/// </summary>
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (this.m_RenderWindow != null)
{
if (this.Visible)
{
this.SyncRenderWindowSize();
if (this.m_RenderWindow.GetInteractor() != this.m_RenderWindowInteractor)
{
// On X11, the SetInteractor method cannot be called until the parent
// window is already visible/mapped/painting... Since SetInteractor
// is the method that does this in VTK, we avoid calling it until now:
// when our parent has definitely shown us and we are in the process
// of painting.
//
this.AttachInteractor();
this.m_RenderWindow.Render();
}
if (this.AddTestActors && !this.m_AddedTestActors)
{
this.m_AddedTestActors = true;
this.TestAddActorsToRenderWindow(this.m_RenderWindow);
}
this.m_RenderWindow.Render();
}
}
base.OnPaint(e);
}
/// <summary>
/// OnVisibleChanged fires after the Visible property has changed value.
/// </summary>
protected override void OnVisibleChanged(System.EventArgs e)
{
base.OnVisibleChanged(e);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// RenderWindowControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "RenderWindowControl";
this.Size = new System.Drawing.Size(400, 300);
this.ResumeLayout(false);
}
#endregion
}
}
|