ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ModelApplyCommandsT.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ModelApplyCommandsT.hh
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"
40 #include "G4UIcmdWithAnInteger.hh"
41 #include "G4UIcmdWithAString.hh"
42 #include "G4UIcommand.hh"
43 #include "G4VModelCommand.hh"
44 #include "G4VVisManager.hh"
45 #include <sstream>
46 
48 // ApplyStringColour command
49 template <typename M>
51 
52 public: // With description
53 
54  G4ModelCmdApplyStringColour(M* model, const G4String& placement, const G4String& cmdName);
55 
57 
58  void SetNewValue(G4UIcommand* command, G4String newValue);
59 
60 protected:
61 
62  // Implement in derived class
63  virtual void Apply(const G4String&, const G4Colour&) = 0;
64 
67 
68 private:
69 
72 
73 };
74 
75 template <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);
99 
100  param = new G4UIparameter("Red component", 'd', false);
102 
103  param = new G4UIparameter("Green component", 'd', false);
105 
106  param = new G4UIparameter("Blue component", 'd', false);
108 
109  param = new G4UIparameter("Alpha component", 'd', false);
111 }
112 
113 template <typename M>
115 {
116  delete fpStringCmd;
117  delete fpComponentCmd;
118 }
119 
120 template <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 
157 //ApplyColour command
158 template <typename M>
160 
161 public: // 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 
169 protected:
170 
171  // Implement in derived class
172  virtual void Apply(const G4Colour&) = 0;
173 
176 
177 private:
178 
181 
182 };
183 
184 template <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);
207 
208  param = new G4UIparameter("Green component", 'd', false);
210 
211  param = new G4UIparameter("Blue component", 'd', false);
213 
214  param = new G4UIparameter("Alpha component", 'd', false);
216 }
217 
218 template <typename M>
220 {
221  delete fpStringCmd;
222  delete fpComponentCmd;
223 }
224 
225 template <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 
261 //ApplyBool command
262 template <typename M>
264 
265 public: // 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 
272 protected:
273 
274  // Implement in derived class
275  virtual void Apply(const G4bool&) = 0;
276 
278 
279 private:
280 
282 
283 };
284 
285 template <typename M>
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 
295 template <typename M>
297 {
298  delete fpCmd;
299 }
300 
301 template <typename M>
303 {
304  Apply(fpCmd->GetNewBoolValue(newValue));
306  if (visManager) visManager->NotifyHandlers();
307 }
308 
310 //ApplyNull command
311 template <typename M>
313 
314 public: // 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 
322 protected:
323 
324  // Implement in derived class
325  virtual void Apply() = 0;
326 
327  G4UIcommand* Command() {return fpCmd;}
328 
329 private:
330 
332 
333 };
334 
335 template <typename M>
337  :G4VModelCommand<M>(model, placement)
338 {
339  G4String dir = placement+"/"+model->Name()+"/"+cmdName;
340  fpCmd = new G4UIcommand(dir, this);
341 }
342 
343 template <typename M>
345 {
346  delete fpCmd;
347 }
348 
349 template <typename M>
351 {
352  Apply();
354  if (visManager) visManager->NotifyHandlers();
355 }
356 
358 //ApplyDouble command
359 template <typename M>
361 
362 public: // 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 
370 protected:
371 
372  // Implement in derived class
373  virtual void Apply(const G4double&) = 0;
374 
376 
377 private:
378 
380 
381 };
382 
383 template <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 
393 template <typename M>
395 {
396  delete fpCmd;
397 }
398 
399 template <typename M>
401 {
402  Apply(fpCmd->GetNewDoubleValue(newValue));
404  if (visManager) visManager->NotifyHandlers();
405 }
406 
408 //ApplyDoubleAndUnit command
409 template <typename M>
411 
412 public: // With description
413 
414  G4ModelCmdApplyDoubleAndUnit(M* model, const G4String& placement, const G4String& cmdName);
415 
417 
418  void SetNewValue(G4UIcommand* command, G4String newValue);
419 
420 protected:
421 
422  // Implement in derived class
423  virtual void Apply(const G4double&) = 0;
424 
426 
427 private:
428 
430 
431 };
432 
433 template <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 
443 template <typename M>
445 {
446  delete fpCmd;
447 }
448 
449 template <typename M>
451 {
452  Apply(fpCmd->GetNewDoubleValue(newValue));
454  if (visManager) visManager->NotifyHandlers();
455 }
456 
458 // ApplyInteger command
459 template <typename M>
461 
462 public: // 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 
470 protected:
471 
472  // Implement in derived class
473  virtual void Apply(const G4int&) = 0;
474 
476 
477 private:
478 
480 };
481 
482 template <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 
492 template <typename M>
494 {
495  delete fpCmd;
496 }
497 
498 template <typename M>
500 {
501  Apply(fpCmd->GetNewIntValue(newValue));
503  if (visManager) visManager->NotifyHandlers();
504 }
505 
507 // ApplyString command
508 template <typename M>
510 
511 public: // 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 
519 protected:
520 
521  // Implement in derived class
522  virtual void Apply(const G4String&) = 0;
523 
525 
526 private:
527 
529 
530 };
531 
532 template <typename M>
534  :G4VModelCommand<M>(model, placement)
535 {
536  G4String dir = placement+"/"+model->Name()+"/"+cmdName;
537 
538  fpCmd = new G4UIcmdWithAString(dir, this);
539 }
540 
541 template <typename M>
543 {
544  delete fpCmd;
545 }
546 
547 template <typename M>
549 {
550  Apply(newValue);
552  if (visManager) visManager->NotifyHandlers();
553 }
554 
555 #endif