Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ModelApplyCommandsT.hh
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// Abstract model messenges. Derived classes should implement
28// the "Apply" method
29//
30// Jane Tinslay April 2006
31//
32#ifndef G4APPLYCOMMANDST_HH
33#define G4APPLYCOMMANDST_HH
34
35#include "G4Colour.hh"
36#include "G4String.hh"
37#include "G4UIcmdWithABool.hh"
38#include "G4UIcmdWithADouble.hh"
41#include "G4UIcmdWithAString.hh"
42#include "G4UIcommand.hh"
43#include "G4VModelCommand.hh"
44#include "G4VVisManager.hh"
45#include <sstream>
46
47///////////////////////////////////////////////////////////////////////////
48// ApplyStringColour command
49template <typename M>
51
52public: // With description
53
54 G4ModelCmdApplyStringColour(M* model, const G4String& placement, const G4String& cmdName);
55
57
58 void SetNewValue(G4UIcommand* command, G4String newValue);
59
60protected:
61
62 // Implement in derived class
63 virtual void Apply(const G4String&, const G4Colour&) = 0;
64
65 G4UIcommand* StringCommand() {return fpStringCmd;}
66 G4UIcommand* ComponentCommand() {return fpComponentCmd;}
67
68private:
69
70 G4UIcommand* fpStringCmd;
71 G4UIcommand* fpComponentCmd;
72
73};
74
75template <typename M>
77 :G4VModelCommand<M>(model, placement)
78{
79 //Set variable colour through a string
80 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
81 G4UIparameter* param(0);
82
83 fpStringCmd = new G4UIcommand(dir, this);
84 fpStringCmd->SetGuidance("Set variable colour through a string");
85
86 param = new G4UIparameter("Variable", 's', false);
87 fpStringCmd->SetParameter(param);
88
89 param = new G4UIparameter("Value", 's', false);
90 fpStringCmd->SetParameter(param);
91
92 //Set variable colour through RGBA components
93 G4String componentDir = dir+"RGBA";
94
95 fpComponentCmd = new G4UIcommand(componentDir, this);
96 fpComponentCmd->SetGuidance("Set variable colour through red, green, blue and alpha components");
97 param = new G4UIparameter("Variable", 's', false);
98 fpComponentCmd->SetParameter(param);
99
100 param = new G4UIparameter("Red component", 'd', false);
101 fpComponentCmd->SetParameter(param);
102
103 param = new G4UIparameter("Green component", 'd', false);
104 fpComponentCmd->SetParameter(param);
105
106 param = new G4UIparameter("Blue component", 'd', false);
107 fpComponentCmd->SetParameter(param);
108
109 param = new G4UIparameter("Alpha component", 'd', false);
110 fpComponentCmd->SetParameter(param);
111}
112
113template <typename M>
115{
116 delete fpStringCmd;
117 delete fpComponentCmd;
118}
119
120template <typename M>
122{
123 G4Colour myColour;
124 G4String parameter;
125
126 if (cmd == fpStringCmd) {
127 G4String colour;
128 std::istringstream is (newValue);
129 is >> parameter >> colour;
130
131 // Colour key should exist
132 if (!G4Colour::GetColour(colour, myColour)) {
134 ed << "G4Colour with key "<<colour<<" does not exist ";
136 ("G4ModelCmdApplyStringColour<M>::SetNewValue",
137 "modeling0106", JustWarning, ed);
138 return;
139 }
140 }
141
142 if (cmd == fpComponentCmd) {
143 G4double red(0), green(0), blue(0), alpha(0);
144 std::istringstream is (newValue);
145 is >> parameter >> red >> green >> blue >> alpha;
146
147 G4Colour colour(red, green, blue, alpha);
148 myColour = colour;
149 }
150
151 Apply(parameter, myColour);
153 if (visManager) visManager->NotifyHandlers();
154}
155
156///////////////////////////////////////////////////////////////////////////
157//ApplyColour command
158template <typename M>
160
161public: // With description
162
163 G4ModelCmdApplyColour(M* model, const G4String& placement, const G4String& cmdName);
164
165 virtual ~G4ModelCmdApplyColour();
166
167 void SetNewValue(G4UIcommand* command, G4String newValue);
168
169protected:
170
171 // Implement in derived class
172 virtual void Apply(const G4Colour&) = 0;
173
174 G4UIcommand* StringCommand() {return fpStringCmd;}
175 G4UIcommand* ComponentCommand() {return fpComponentCmd;}
176
177private:
178
179 G4UIcommand* fpStringCmd;
180 G4UIcommand* fpComponentCmd;
181
182};
183
184template <typename M>
186 :G4VModelCommand<M>(model, placement)
187{
188 //Set colour through a string
189 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
190 G4UIparameter* param(0);
191
192 fpStringCmd = new G4UIcommand(dir, this);
193 fpStringCmd->SetGuidance("Set colour through a string");
194
195 param = new G4UIparameter("Variable", 's', false);
196 fpStringCmd->SetParameter(param);
197
198 //Set colour through RGBA components
199 G4String componentDir = dir+"RGBA";
200
201 fpComponentCmd = new G4UIcommand(componentDir, this);
202 fpComponentCmd->SetGuidance("Set colour through red, green, blue and alpha components");
203 fpComponentCmd->SetGuidance("Four inputs are expected.");
204
205 param = new G4UIparameter("Red component", 'd', false);
206 fpComponentCmd->SetParameter(param);
207
208 param = new G4UIparameter("Green component", 'd', false);
209 fpComponentCmd->SetParameter(param);
210
211 param = new G4UIparameter("Blue component", 'd', false);
212 fpComponentCmd->SetParameter(param);
213
214 param = new G4UIparameter("Alpha component", 'd', false);
215 fpComponentCmd->SetParameter(param);
216}
217
218template <typename M>
220{
221 delete fpStringCmd;
222 delete fpComponentCmd;
223}
224
225template <typename M>
227{
228 G4Colour myColour;
229
230 if (cmd == fpStringCmd) {
231 G4String colour;
232 std::istringstream is (newValue);
233 is >> colour;
234
235 // Colour key should exist
236 if (!G4Colour::GetColour(colour, myColour)) {
238 ed << "G4Colour with key "<<colour<<" does not exist ";
240 ("G4ModelCmdApplyColour<M>::SetNewValue",
241 "modeling0107", JustWarning, ed);
242 return;
243 }
244 }
245
246 if (cmd == fpComponentCmd) {
247 G4double red(0), green(0), blue(0), alpha(0);
248 std::istringstream is (newValue);
249 is >> red >> green >> blue >> alpha;
250
251 G4Colour colour(red, green, blue, alpha);
252 myColour = colour;
253 }
254
255 Apply(myColour);
257 if (visManager) visManager->NotifyHandlers();
258}
259
260///////////////////////////////////////////////////////////////////////////
261//ApplyBool command
262template <typename M>
264
265public: // With description
266
267 G4ModelCmdApplyBool(M* model, const G4String& placement, const G4String& cmdName);
268 virtual ~G4ModelCmdApplyBool();
269
270 void SetNewValue(G4UIcommand* command, G4String newValue);
271
272protected:
273
274 // Implement in derived class
275 virtual void Apply(const G4bool&) = 0;
276
277 G4UIcmdWithABool* Command() {return fpCmd;}
278
279private:
280
281 G4UIcmdWithABool* fpCmd;
282
283};
284
285template <typename M>
286G4ModelCmdApplyBool<M>::G4ModelCmdApplyBool(M* model, const G4String& placement, const G4String& cmdName)
287 :G4VModelCommand<M>(model, placement)
288{
289 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
290 fpCmd = new G4UIcmdWithABool(dir, this);
291
292 fpCmd->SetParameterName("Bool", false);
293}
294
295template <typename M>
297{
298 delete fpCmd;
299}
300
301template <typename M>
303{
304 Apply(fpCmd->GetNewBoolValue(newValue));
306 if (visManager) visManager->NotifyHandlers();
307}
308
309///////////////////////////////////////////////////////////////////////////
310//ApplyNull command
311template <typename M>
313
314public: // With description
315
316 G4ModelCmdApplyNull(M* model, const G4String& placement, const G4String& cmdName);
317
318 virtual ~G4ModelCmdApplyNull();
319
320 void SetNewValue(G4UIcommand* command, G4String newValue);
321
322protected:
323
324 // Implement in derived class
325 virtual void Apply() = 0;
326
327 G4UIcommand* Command() {return fpCmd;}
328
329private:
330
331 G4UIcommand* fpCmd;
332
333};
334
335template <typename M>
336G4ModelCmdApplyNull<M>::G4ModelCmdApplyNull(M* model, const G4String& placement, const G4String& cmdName)
337 :G4VModelCommand<M>(model, placement)
338{
339 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
340 fpCmd = new G4UIcommand(dir, this);
341}
342
343template <typename M>
345{
346 delete fpCmd;
347}
348
349template <typename M>
351{
352 Apply();
354 if (visManager) visManager->NotifyHandlers();
355}
356
357///////////////////////////////////////////////////////////////////////////
358//ApplyDouble command
359template <typename M>
361
362public: // With description
363
364 G4ModelCmdApplyDouble(M* model, const G4String& placement, const G4String& cmdName);
365
366 virtual ~G4ModelCmdApplyDouble();
367
368 void SetNewValue(G4UIcommand* command, G4String newValue);
369
370protected:
371
372 // Implement in derived class
373 virtual void Apply(const G4double&) = 0;
374
375 G4UIcmdWithADouble* Command() {return fpCmd;}
376
377private:
378
379 G4UIcmdWithADouble* fpCmd;
380
381};
382
383template <typename M>
385 :G4VModelCommand<M>(model, placement)
386{
387 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
388
389 fpCmd = new G4UIcmdWithADouble(dir, this);
390 fpCmd->SetParameterName("Double", false);
391}
392
393template <typename M>
395{
396 delete fpCmd;
397}
398
399template <typename M>
401{
402 Apply(fpCmd->GetNewDoubleValue(newValue));
404 if (visManager) visManager->NotifyHandlers();
405}
406
407///////////////////////////////////////////////////////////////////////////
408//ApplyDoubleAndUnit command
409template <typename M>
411
412public: // With description
413
414 G4ModelCmdApplyDoubleAndUnit(M* model, const G4String& placement, const G4String& cmdName);
415
417
418 void SetNewValue(G4UIcommand* command, G4String newValue);
419
420protected:
421
422 // Implement in derived class
423 virtual void Apply(const G4double&) = 0;
424
426
427private:
428
430
431};
432
433template <typename M>
435 :G4VModelCommand<M>(model, placement)
436{
437 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
438
439 fpCmd = new G4UIcmdWithADoubleAndUnit(dir, this);
440 fpCmd->SetParameterName("DoubleAndUnit", false);
441}
442
443template <typename M>
445{
446 delete fpCmd;
447}
448
449template <typename M>
451{
452 Apply(fpCmd->GetNewDoubleValue(newValue));
454 if (visManager) visManager->NotifyHandlers();
455}
456
457///////////////////////////////////////////////////////////////////////////
458// ApplyInteger command
459template <typename M>
461
462public: // With description
463
464 G4ModelCmdApplyInteger(M* model, const G4String& placement, const G4String& cmdName);
465
466 virtual ~G4ModelCmdApplyInteger();
467
468 void SetNewValue(G4UIcommand* command, G4String newValue);
469
470protected:
471
472 // Implement in derived class
473 virtual void Apply(const G4int&) = 0;
474
475 G4UIcmdWithAnInteger* Command() {return fpCmd;}
476
477private:
478
480};
481
482template <typename M>
484 :G4VModelCommand<M>(model, placement)
485{
486 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
487
488 fpCmd = new G4UIcmdWithAnInteger(dir, this);
489 fpCmd->SetParameterName("Integer", false);
490}
491
492template <typename M>
494{
495 delete fpCmd;
496}
497
498template <typename M>
500{
501 Apply(fpCmd->GetNewIntValue(newValue));
503 if (visManager) visManager->NotifyHandlers();
504}
505
506///////////////////////////////////////////////////////////////////////////
507// ApplyString command
508template <typename M>
510
511public: // With description
512
513 G4ModelCmdApplyString(M* model, const G4String& placement, const G4String& cmdName);
514
515 virtual ~G4ModelCmdApplyString();
516
517 void SetNewValue(G4UIcommand* command, G4String newValue);
518
519protected:
520
521 // Implement in derived class
522 virtual void Apply(const G4String&) = 0;
523
524 G4UIcmdWithAString* Command() {return fpCmd;}
525
526private:
527
528 G4UIcmdWithAString* fpCmd;
529
530};
531
532template <typename M>
534 :G4VModelCommand<M>(model, placement)
535{
536 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
537
538 fpCmd = new G4UIcmdWithAString(dir, this);
539}
540
541template <typename M>
543{
544 delete fpCmd;
545}
546
547template <typename M>
549{
550 Apply(newValue);
552 if (visManager) visManager->NotifyHandlers();
553}
554
555#endif
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
#define M(row, col)
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:155
G4UIcmdWithABool * Command()
void SetNewValue(G4UIcommand *command, G4String newValue)
G4ModelCmdApplyBool(M *model, const G4String &placement, const G4String &cmdName)
virtual void Apply(const G4bool &)=0
G4ModelCmdApplyColour(M *model, const G4String &placement, const G4String &cmdName)
virtual void Apply(const G4Colour &)=0
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithADoubleAndUnit * Command()
virtual void Apply(const G4double &)=0
void SetNewValue(G4UIcommand *command, G4String newValue)
G4ModelCmdApplyDoubleAndUnit(M *model, const G4String &placement, const G4String &cmdName)
virtual void Apply(const G4double &)=0
G4ModelCmdApplyDouble(M *model, const G4String &placement, const G4String &cmdName)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithADouble * Command()
G4ModelCmdApplyInteger(M *model, const G4String &placement, const G4String &cmdName)
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual void Apply(const G4int &)=0
G4UIcmdWithAnInteger * Command()
void SetNewValue(G4UIcommand *command, G4String newValue)
G4ModelCmdApplyNull(M *model, const G4String &placement, const G4String &cmdName)
virtual void Apply()=0
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual void Apply(const G4String &, const G4Colour &)=0
G4ModelCmdApplyStringColour(M *model, const G4String &placement, const G4String &cmdName)
G4ModelCmdApplyString(M *model, const G4String &placement, const G4String &cmdName)
virtual void Apply(const G4String &)=0
G4UIcmdWithAString * Command()
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:157
virtual void NotifyHandlers()
static G4VVisManager * GetConcreteInstance()