Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Xt.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// G.Barrand
29
30#if defined(G4INTY_BUILD_XT) || defined(G4INTY_USE_XT)
31
32#include <stdlib.h>
33#include <string.h>
34
35#include <X11/Intrinsic.h>
36#include <X11/Shell.h>
37
38#include "G4ios.hh"
39
40#include "G4Xt.hh"
41
42#define NewString(str) \
43 ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
44
45//static void XWidgetIconify (Widget);
46//static void XWidgetUniconify (Widget);
47//static void XDisplaySetWindowToNormalState (Display*,Window);
48
49G4Xt* G4Xt::instance = NULL;
50
51static G4bool XtInited = FALSE;
52static int argn = 0;
53static char** args = NULL;
54static XtAppContext appContext = NULL;
55static Widget topWidget = NULL;
56/***************************************************************************/
57G4Xt* G4Xt::getInstance (
58)
59/***************************************************************************/
60/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
61{
62 return G4Xt::getInstance (0,NULL,(char*)"Geant4");
63}
64/***************************************************************************/
65G4Xt* G4Xt::getInstance (
66 int a_argn
67,char** a_args
68,char* a_class
69)
70/***************************************************************************/
71/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
72{
73 if (instance==NULL) {
74 instance = new G4Xt(a_argn,a_args,a_class);
75 }
76 return instance;
77}
78/***************************************************************************/
79G4Xt::G4Xt (
80 int a_argn
81,char** a_args
82,char* a_class
83)
84/***************************************************************************/
85/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
86{
87 if(XtInited==FALSE) { //Xt should be Inited once !
88 if(a_argn!=0) { //Save args.
89 args = (char**)malloc(a_argn * sizeof(char*));
90 if(args!=NULL) {
91 argn = a_argn;
92 for(int argi=0;argi<a_argn;argi++) {
93 args[argi] = (char*)NewString (a_args[argi]);
94 }
95 }
96 }
97#if XtSpecificationRelease == 4
98 Cardinal narg;
99 narg = (Cardinal)a_argn;
100#else
101 int narg;
102 narg = a_argn;
103#endif
104 Arg xargs[1];
105 XtSetArg (xargs[0],XtNgeometry,"100x100");
106 topWidget = XtAppInitialize (&appContext,a_class,
107 NULL,(Cardinal)0,
108 &narg,a_args,NULL,
109 xargs,1);
110 if(topWidget==NULL) {
111 G4cout << "G4Xt : Unable to init Xt." << G4endl;
112 }
113 // Restore a_args. XtAppInitialize corrupts the given ones !!!
114 if( (a_argn!=0) && (args!=NULL)) {
115 for(int argi=0;argi<a_argn;argi++) {
116 if(args[argi]!=NULL)
117 strcpy(a_args[argi],args[argi]);
118 else
119 a_args[argi] = NULL;
120 }
121 }
122 // If topWidget not realized, pbs with Inventor shells.
123 XtSetMappedWhenManaged (topWidget,False);
124 XtRealizeWidget (topWidget);
125 XtInited = TRUE;
126 }
127 SetArguments (argn,args);
128 SetMainInteractor (topWidget);
129 AddDispatcher(xt_dispatch_event);
130 // Coverity gcc8 cast warning
131 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
132}
133/***************************************************************************/
134G4Xt::~G4Xt (
135)
136/***************************************************************************/
137/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
138{
139 if(this==instance) {
140 instance = NULL;
141 }
142}
143/***************************************************************************/
144G4bool G4Xt::Inited (
145)
146/***************************************************************************/
147/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
148{
149 return XtInited;
150}
151/***************************************************************************/
152void* G4Xt::GetEvent (
153)
154/***************************************************************************/
155/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
156{
157 static XEvent event;
158 if(appContext==NULL) return NULL;
159 if(topWidget==NULL) return NULL;
160 XtAppNextEvent (appContext, &event);
161 return &event;
162}
163/***************************************************************************/
164void G4Xt::PutStringInResourceDatabase (
165 char* a_string
166)
167/***************************************************************************/
168/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
169{
170 if(topWidget==NULL) return;
171 if(a_string==NULL) return;
172 Display* dpy = XtDisplay(topWidget);
173 XrmDatabase dbres = XrmGetStringDatabase (a_string);
174 if(dbres==NULL) return;
175 XrmDatabase database = XrmGetDatabase (dpy);
176 if(database!=NULL) {
177 XrmMergeDatabases (dbres,&database);
178 } else {
179 XrmSetDatabase (dpy,dbres);
180 }
181}
182/***************************************************************************/
183void G4Xt::FlushAndWaitExecution (
184)
185/***************************************************************************/
186/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
187{
188 if(topWidget==NULL) return;
189 XSync(XtDisplay(topWidget),False);
190}
191
192#endif
193
194
195
bool G4bool
Definition: G4Types.hh:86
#define NewString(str)
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23