00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * 00004 * The IPPL Framework 00005 * 00006 * This program was prepared by PSI. 00007 * All rights in the program are reserved by PSI. 00008 * Neither PSI nor the author(s) 00009 * makes any warranty, express or implied, or assumes any liability or 00010 * responsibility for the use of this software 00011 * 00012 * Visit http://www.acl.lanl.gov/POOMS for more details 00013 * 00014 ***************************************************************************/ 00015 00016 // -*- C++ -*- 00017 /*************************************************************************** 00018 * 00019 * The IPPL Framework 00020 * 00021 * 00022 * Visit http://people.web.psi.ch/adelmann/ for more details 00023 * 00024 ***************************************************************************/ 00025 00026 /* 00027 * File: UIWindow.cpp 00028 * Author: Patrick McCormick 00029 * Advanced Computing Laboratory 00030 * Los Alamos National Laboratory 00031 * 00032 * This file contains the implementation of the UIWindow class which is 00033 * used to remove the creation of the toplevel widget in the main 00034 * function of BX generated code. Our primary purpose for this class 00035 * has been to incorporate BX and VTK together in a working package. 00036 * However, by yanking out the VTK specifics, this class may serve 00037 * other purposes as well. 00038 * 00039 * Please note that the structure of the main program generated by BX 00040 * must be changed to take advantage of this class. We have locally 00041 * created our own version of the BX code generators for this purpose. 00042 * 00043 * VTK NOTES 00044 * 00045 * In terms of VTK, this class assumes that there will be only 00046 * one render master per application. In addition, from the 00047 * perspective of X Windows, we store the application context 00048 * within this class as well (there is only one context per 00049 * application). The remaining functionality of VTK is handled 00050 * by the VTKWindow class (which is incorporated as a class into 00051 * the local BX pallette). 00052 * 00053 */ 00054 00055 #include "UIWindow.h" 00056 00057 #include <stdio.h> 00058 #include <stdlib.h> 00059 #include <assert.h> 00060 00061 XtAppContext UIWindow::app; 00062 vtkRenderMaster *UIWindow::renderMaster = 0; 00063 00064 00065 /* -------------------------- */ 00066 /* --- UIWindow::UIWindow --- */ 00067 /* -------------------------- */ 00068 /* 00069 * Construct a UIWindow object. 00070 * 00071 * 'parent' should be the widget returned by XtVaAppInitialize(). 00072 * 'args' and 'num_args' are the standard resource arguments for widgets. 00073 * 'app_context' is the application context initialized during the 00074 * XtVaAppInitialize() call. 00075 * 00076 */ 00077 UIWindow::UIWindow(Widget parent, 00078 ArgList args, 00079 Cardinal num_args, 00080 XtAppContext app_context) 00081 { 00082 app = app_context; 00083 00084 00085 // Create a new render master. 00086 renderMaster = new vtkRenderMaster(); 00087 assert(renderMaster); 00088 00089 // 00090 // Create the VTK specifics we'll need for the window. 00091 // This is basically used to set up the correct visual, 00092 // colormap, and depth so we can make VTK happy. We're 00093 // not certain if this approach works correctly on non-SGI 00094 // systems. 00095 // 00096 00097 // 00098 // In a real application, there is a one-to-one correspondence 00099 // between a VTK render window and a VTKWindow object. However, 00100 // in order to extract the correct information from VTK we need 00101 // access to a render window -- in this case, we simply create a 00102 // temporary window. 00103 // 00104 vtkXRenderWindow *renwin; // Just a temp var. 00105 renwin = (vtkXRenderWindow *)renderMaster->MakeRenderWindow(); 00106 00107 Visual *visual; 00108 Colormap *cmap; 00109 int depth; 00110 00111 renwin->SetDisplayId(XtDisplay(parent)); 00112 00113 depth = renwin->GetDesiredDepth(); 00114 visual = renwin->GetDesiredVisual(); 00115 cmap = (Colormap *)renwin->GetDesiredColormap(); 00116 00117 // 00118 // Finally create the toplevel shell. 00119 // 00120 _toplevel = XtVaCreateWidget("topLevelShell", 00121 topLevelShellWidgetClass, parent, 00122 XmNdepth, depth, 00123 XmNvisual, visual, 00124 XmNcolormap, cmap, 00125 NULL); 00126 00127 // Set the passed in resources for the toplevel shell. 00128 XtSetValues(_toplevel, args, num_args); 00129 00130 00131 // Clean up. 00132 delete renwin; 00133 } 00134 00135 00136 UIWindow::~UIWindow(void) 00137 { 00138 delete renderMaster; 00139 XtDestroyWidget(_toplevel); 00140 } 00141 00142 00143 Widget UIWindow::baseWidget() 00144 { 00145 return _toplevel; 00146 } 00147 00148 00149 void UIWindow::show(void) 00150 { 00151 XtPopup(_toplevel, XtGrabNone); 00152 } 00153 00154 00155 void UIWindow::hide(void) 00156 { 00157 XtPopdown(_toplevel); 00158 } 00159 00160 00161 /* EOF */ 00162 00163 /*************************************************************************** 00164 * $RCSfile: UIWindow.cpp,v $ $Author: adelmann $ 00165 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:34 $ 00166 * IPPL_VERSION_ID: $Id: UIWindow.cpp,v 1.1.1.1 2003/01/23 07:40:34 adelmann Exp $ 00167 ***************************************************************************/