Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Wt.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 // $Id: G4Wt.cc,v 1.17 2010-05-20 07:01:03 lgarnier Exp $
28 // GEANT4 tag $Name: not supported by cvs2svn $
29 //
30 // L. Garnier
31 
32 #if defined(G4INTY_BUILD_WT) || defined(G4INTY_USE_WT)
33 
34 #include <stdlib.h>
35 #include <string.h>
36 
37 #include "G4ios.hh"
38 
39 #include "G4Wt.hh"
40 
41 #include <Wt/WApplication>
42 #include <Wt/WEnvironment>
43 
44 
45 G4Wt* G4Wt::instance = NULL;
46 
47 static G4bool WtInited = FALSE;
48 
49 /***************************************************************************/
50 G4Wt* G4Wt::getInstance (
51  )
52 /***************************************************************************/
53 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
54 {
55  return G4Wt::getInstance (0,NULL,(char*)"Geant4");
56 }
57 
58 /***************************************************************************/
59 G4Wt* G4Wt::getInstance (
60  int a_argn
61 ,char** a_args
62 ,char* a_class
63 )
64 /***************************************************************************/
65 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
66 {
67  if (instance==NULL) {
68  instance = new G4Wt(a_argn,a_args,a_class);
69  }
70  return instance;
71 }
72 /***************************************************************************/
73 G4Wt::G4Wt (
74  int a_argn
75 ,char** a_args
76  ,char* /*a_class */
77 )
78 /***************************************************************************/
79 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
80 {
81  argn = 0;
82  args = NULL;
83 
84 #ifdef G4DEBUG_INTERFACES_COMMON
85  printf("G4Wt::G4Wt try to inited Wt\n");
86 #endif
87  // Check if Wt already init in another external app
88  if(wApp) {
89  WtInited = TRUE;
90  SetMainInteractor (wServer);
91  //#endif
92  SetArguments (a_argn,a_args);
93 
94 #ifdef G4DEBUG_INTERFACES_COMMON
95  printf("G4Wt::G4Wt alredy inited in external \n");
96 #endif
97  } else {
98 
99  if(WtInited==FALSE) { //Wt should be Inited once !
100  // Then two cases :
101  // - It is the first time we create G4UI (argc!=0)
102  // -> Inited and register
103  // - It is the first time we create G4VIS (argc == 0)
104  // -> Inited and NOT register
105 
106  if (a_argn != 0) {
107  argn = a_argn;
108  args = a_args;
109 
110  } else { //argc = 0
111 
112  // FIXME : That's not the good arguments, but I don't know how to get args from other Interactor.
113  // Ex: How to get them from G4Xt ?
114  argn = 1;
115  args = (char **)malloc( 1 * sizeof(char *) );
116  args[0] = (char *)malloc(10 * sizeof(char));
117  strncpy(args[0], "my_app \0", 9);
118  }
119 
120  int *p_argn = (int*)malloc(sizeof(int));
121  *p_argn = argn;
122 #ifdef G4DEBUG_INTERFACES_COMMON
123  printf("G4Wt::G4Wt WAppl \n");
124 #endif
125  Wt::WApplication:: instance();
126  ////
127  //WApplication (*p_argn, args);
128 
129  if(!wApp) {
130 
131  G4cout << "G4Wt : Unable to init Wt." << G4endl;
132  } else {
133  WtInited = TRUE;
134  if (a_argn != 0) {
135 #ifdef G4DEBUG_INTERFACES_COMMON
136  printf("G4Wt::G4Wt SetMainInteractor\n");
137 #endif
138  // SetMainInteractor ();
139  }
140  SetArguments (a_argn,a_args);
141 #ifdef G4DEBUG_INTERFACES_COMMON
142  printf("G4Wt::G4Wt inited Wt END\n");
143 #endif
144  }
145  }
146  }
147 #ifdef G4DEBUG_INTERFACES_COMMON
148  if (wApp) {
149  printf("G4Wt::wApp already exist\n");
150  } else {
151  printf("G4Wt::wApp not exist\n");
152  }
153 #endif
154  // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
155 
156 
157  DisableSecondaryLoop ();
158 }
159 /***************************************************************************/
160 G4Wt::~G4Wt (
161 )
162 /***************************************************************************/
163 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
164 {
165  if(this==instance) {
166  instance = NULL;
167  }
168 }
169 /***************************************************************************/
170 G4bool G4Wt::Inited (
171 )
172 /***************************************************************************/
173 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
174 {
175  return WtInited;
176 }
177 /***************************************************************************/
178 void* G4Wt::GetEvent (
179 )
180 /***************************************************************************/
181 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
182 {
183 //FIXME
184 // G4cout << "G4Wt : Rien compris a cette fonction G4Wt::GetEvent." << G4endl;
185 // static XEvent event;
186 // if(appContext==NULL) return NULL;
187 // if(mainApp==NULL) return NULL;
188 // WtAppNextEvent (appContext, &event);
189 // return &event;
190  printf("*");
191  return 0;
192 }
193 /***************************************************************************/
194 void G4Wt::FlushAndWaitExecution (
195 )
196 /***************************************************************************/
197 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
198 {
199  // printf("G4Wt::FlushAndWaitExecution :: Flush ....\n");
200  if(!wApp) return;
201  // wApp->processEvents();
202 }
203 
204 #endif
205 
206 
207 
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55
#define G4endl
Definition: G4ios.hh:61
void * malloc(size_t __size)
Definition: hjmalloc.cc:30