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