source: trunk/source/visualization/modeling/include/G4ModelApplyCommandsT.hh@ 849

Last change on this file since 849 was 834, checked in by garnier, 17 years ago

import all except CVS

File size: 14.5 KB
Line 
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// $Id: G4ModelApplyCommandsT.hh,v 1.5 2006/09/11 21:22:02 tinslay Exp $
27// GEANT4 tag $Name: $
28//
29// Abstract model messenges. Derived classes should implement
30// the "Apply" method
31//
32// Jane Tinslay April 2006
33//
34#ifndef G4APPLYCOMMANDST_HH
35#define G4APPLYCOMMANDST_HH
36
37#include "G4Colour.hh"
38#include "G4String.hh"
39#include "G4UIcmdWithABool.hh"
40#include "G4UIcmdWithADouble.hh"
41#include "G4UIcmdWithADoubleAndUnit.hh"
42#include "G4UIcmdWithAnInteger.hh"
43#include "G4UIcmdWithAString.hh"
44#include "G4UIcommand.hh"
45#include "G4VModelCommand.hh"
46#include "globals.hh"
47#include <sstream>
48
49///////////////////////////////////////////////////////////////////////////
50// ApplyStringColour command
51template <typename M>
52class G4ModelCmdApplyStringColour : public G4VModelCommand<M> {
53
54public: // With description
55
56 G4ModelCmdApplyStringColour(M* model, const G4String& placement, const G4String& cmdName);
57
58 virtual ~G4ModelCmdApplyStringColour();
59
60 void SetNewValue(G4UIcommand* command, G4String newValue);
61
62protected:
63
64 // Implement in derived class
65 virtual void Apply(const G4String&, const G4Colour&) = 0;
66
67 G4UIcommand* StringCommand() {return fpStringCmd;}
68 G4UIcommand* ComponentCommand() {return fpComponentCmd;}
69
70private:
71
72 G4UIcommand* fpStringCmd;
73 G4UIcommand* fpComponentCmd;
74
75};
76
77template <typename M>
78G4ModelCmdApplyStringColour<M>::G4ModelCmdApplyStringColour(M* model, const G4String& placement, const G4String& cmdName)
79 :G4VModelCommand<M>(model, placement)
80{
81 //Set variable colour through a string
82 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
83 G4UIparameter* param(0);
84
85 fpStringCmd = new G4UIcommand(dir, this);
86 fpStringCmd->SetGuidance("Set variable colour through a string");
87
88 param = new G4UIparameter("Variable", 's', false);
89 fpStringCmd->SetParameter(param);
90
91 param = new G4UIparameter("Value", 's', false);
92 fpStringCmd->SetParameter(param);
93
94 //Set variable colour through RGBA components
95 G4String componentDir = dir+"RGBA";
96
97 fpComponentCmd = new G4UIcommand(componentDir, this);
98 fpComponentCmd->SetGuidance("Set variable colour through red, green, blue and alpha components");
99 param = new G4UIparameter("Variable", 's', false);
100 fpComponentCmd->SetParameter(param);
101
102 param = new G4UIparameter("Red component", 'd', false);
103 fpComponentCmd->SetParameter(param);
104
105 param = new G4UIparameter("Green component", 'd', false);
106 fpComponentCmd->SetParameter(param);
107
108 param = new G4UIparameter("Blue component", 'd', false);
109 fpComponentCmd->SetParameter(param);
110
111 param = new G4UIparameter("Alpha component", 'd', false);
112 fpComponentCmd->SetParameter(param);
113}
114
115template <typename M>
116G4ModelCmdApplyStringColour<M>::~G4ModelCmdApplyStringColour()
117{
118 delete fpStringCmd;
119 delete fpComponentCmd;
120}
121
122template <typename M>
123void G4ModelCmdApplyStringColour<M>::SetNewValue(G4UIcommand* cmd, G4String newValue)
124{
125 G4Colour myColour;
126 G4String parameter;
127
128 if (cmd == fpStringCmd) {
129 G4String colour;
130 std::istringstream is (newValue);
131 is >> parameter >> colour;
132
133 // Colour key should exist
134 if (!G4Colour::GetColour(colour, myColour)) {
135 std::ostringstream o;
136 o << "G4Colour with key "<<colour<<" does not exist ";
137 G4Exception
138 ("G4ModelCmdApplyStringColour<M>::SetNewValue",
139 "NonExistentColour", JustWarning, o.str().c_str());
140 return;
141 }
142 }
143
144 if (cmd == fpComponentCmd) {
145 G4double red(0), green(0), blue(0), alpha(0);
146 std::istringstream is (newValue);
147 is >> parameter >> red >> green >> blue >> alpha;
148
149 G4Colour colour(red, green, blue, alpha);
150 myColour = colour;
151 }
152
153 Apply(parameter, myColour);
154}
155
156///////////////////////////////////////////////////////////////////////////
157//ApplyColour command
158template <typename M>
159class G4ModelCmdApplyColour : public G4VModelCommand<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>
185G4ModelCmdApplyColour<M>::G4ModelCmdApplyColour(M* model, const G4String& placement, const G4String& cmdName)
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>
219G4ModelCmdApplyColour<M>::~G4ModelCmdApplyColour()
220{
221 delete fpStringCmd;
222 delete fpComponentCmd;
223}
224
225template <typename M>
226void G4ModelCmdApplyColour<M>::SetNewValue(G4UIcommand* cmd, G4String newValue)
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)) {
237 std::ostringstream o;
238 o << "G4Colour with key "<<colour<<" does not exist ";
239 G4Exception
240 ("G4ModelCmdApplyColour<M>::SetNewValue",
241 "NonExistentColour", JustWarning, o.str().c_str());
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);
256}
257
258///////////////////////////////////////////////////////////////////////////
259//ApplyBool command
260template <typename M>
261class G4ModelCmdApplyBool : public G4VModelCommand<M> {
262
263public: // With description
264
265 G4ModelCmdApplyBool(M* model, const G4String& placement, const G4String& cmdName);
266 virtual ~G4ModelCmdApplyBool();
267
268 void SetNewValue(G4UIcommand* command, G4String newValue);
269
270protected:
271
272 // Implement in derived class
273 virtual void Apply(const G4bool&) = 0;
274
275 G4UIcmdWithABool* Command() {return fpCmd;}
276
277private:
278
279 G4UIcmdWithABool* fpCmd;
280
281};
282
283template <typename M>
284G4ModelCmdApplyBool<M>::G4ModelCmdApplyBool(M* model, const G4String& placement, const G4String& cmdName)
285 :G4VModelCommand<M>(model, placement)
286{
287 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
288 fpCmd = new G4UIcmdWithABool(dir, this);
289
290 fpCmd->SetParameterName("Bool", false);
291}
292
293template <typename M>
294G4ModelCmdApplyBool<M>::~G4ModelCmdApplyBool()
295{
296 delete fpCmd;
297}
298
299template <typename M>
300void G4ModelCmdApplyBool<M>::SetNewValue(G4UIcommand*, G4String newValue)
301{
302 Apply(fpCmd->GetNewBoolValue(newValue));
303}
304
305///////////////////////////////////////////////////////////////////////////
306//ApplyNull command
307template <typename M>
308class G4ModelCmdApplyNull : public G4VModelCommand<M> {
309
310public: // With description
311
312 G4ModelCmdApplyNull(M* model, const G4String& placement, const G4String& cmdName);
313
314 virtual ~G4ModelCmdApplyNull();
315
316 void SetNewValue(G4UIcommand* command, G4String newValue);
317
318protected:
319
320 // Implement in derived class
321 virtual void Apply() = 0;
322
323 G4UIcommand* Command() {return fpCmd;}
324
325private:
326
327 G4UIcommand* fpCmd;
328
329};
330
331template <typename M>
332G4ModelCmdApplyNull<M>::G4ModelCmdApplyNull(M* model, const G4String& placement, const G4String& cmdName)
333 :G4VModelCommand<M>(model, placement)
334{
335 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
336 fpCmd = new G4UIcommand(dir, this);
337}
338
339template <typename M>
340G4ModelCmdApplyNull<M>::~G4ModelCmdApplyNull()
341{
342 delete fpCmd;
343}
344
345template <typename M>
346void G4ModelCmdApplyNull<M>::SetNewValue(G4UIcommand*, G4String)
347{
348 Apply();
349}
350
351///////////////////////////////////////////////////////////////////////////
352//ApplyDouble command
353template <typename M>
354class G4ModelCmdApplyDouble : public G4VModelCommand<M> {
355
356public: // With description
357
358 G4ModelCmdApplyDouble(M* model, const G4String& placement, const G4String& cmdName);
359
360 virtual ~G4ModelCmdApplyDouble();
361
362 void SetNewValue(G4UIcommand* command, G4String newValue);
363
364protected:
365
366 // Implement in derived class
367 virtual void Apply(const G4double&) = 0;
368
369 G4UIcmdWithADouble* Command() {return fpCmd;}
370
371private:
372
373 G4UIcmdWithADouble* fpCmd;
374
375};
376
377template <typename M>
378G4ModelCmdApplyDouble<M>::G4ModelCmdApplyDouble(M* model, const G4String& placement, const G4String& cmdName)
379 :G4VModelCommand<M>(model, placement)
380{
381 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
382
383 fpCmd = new G4UIcmdWithADouble(dir, this);
384 fpCmd->SetParameterName("Double", false);
385}
386
387template <typename M>
388G4ModelCmdApplyDouble<M>::~G4ModelCmdApplyDouble()
389{
390 delete fpCmd;
391}
392
393template <typename M>
394void G4ModelCmdApplyDouble<M>::SetNewValue(G4UIcommand*, G4String newValue)
395{
396 Apply(fpCmd->GetNewDoubleValue(newValue));
397}
398
399///////////////////////////////////////////////////////////////////////////
400//ApplyDoubleAndUnit command
401template <typename M>
402class G4ModelCmdApplyDoubleAndUnit : public G4VModelCommand<M> {
403
404public: // With description
405
406 G4ModelCmdApplyDoubleAndUnit(M* model, const G4String& placement, const G4String& cmdName);
407
408 virtual ~G4ModelCmdApplyDoubleAndUnit();
409
410 void SetNewValue(G4UIcommand* command, G4String newValue);
411
412protected:
413
414 // Implement in derived class
415 virtual void Apply(const G4double&) = 0;
416
417 G4UIcmdWithADoubleAndUnit* Command() {return fpCmd;}
418
419private:
420
421 G4UIcmdWithADoubleAndUnit* fpCmd;
422
423};
424
425template <typename M>
426G4ModelCmdApplyDoubleAndUnit<M>::G4ModelCmdApplyDoubleAndUnit(M* model, const G4String& placement, const G4String& cmdName)
427 :G4VModelCommand<M>(model, placement)
428{
429 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
430
431 fpCmd = new G4UIcmdWithADoubleAndUnit(dir, this);
432 fpCmd->SetParameterName("DoubleAndUnit", false);
433}
434
435template <typename M>
436G4ModelCmdApplyDoubleAndUnit<M>::~G4ModelCmdApplyDoubleAndUnit()
437{
438 delete fpCmd;
439}
440
441template <typename M>
442void G4ModelCmdApplyDoubleAndUnit<M>::SetNewValue(G4UIcommand*, G4String newValue)
443{
444 Apply(fpCmd->GetNewDoubleValue(newValue));
445}
446
447///////////////////////////////////////////////////////////////////////////
448// ApplyInteger command
449template <typename M>
450class G4ModelCmdApplyInteger : public G4VModelCommand<M> {
451
452public: // With description
453
454 G4ModelCmdApplyInteger(M* model, const G4String& placement, const G4String& cmdName);
455
456 virtual ~G4ModelCmdApplyInteger();
457
458 void SetNewValue(G4UIcommand* command, G4String newValue);
459
460protected:
461
462 // Implement in derived class
463 virtual void Apply(const G4int&) = 0;
464
465 G4UIcmdWithAnInteger* Command() {return fpCmd;}
466
467private:
468
469 G4UIcmdWithAnInteger* fpCmd;
470};
471
472template <typename M>
473G4ModelCmdApplyInteger<M>::G4ModelCmdApplyInteger(M* model, const G4String& placement, const G4String& cmdName)
474 :G4VModelCommand<M>(model, placement)
475{
476 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
477
478 fpCmd = new G4UIcmdWithAnInteger(dir, this);
479 fpCmd->SetParameterName("Integer", false);
480}
481
482template <typename M>
483G4ModelCmdApplyInteger<M>::~G4ModelCmdApplyInteger()
484{
485 delete fpCmd;
486}
487
488template <typename M>
489void G4ModelCmdApplyInteger<M>::SetNewValue(G4UIcommand* cmd, G4String newValue)
490{
491 Apply(fpCmd->GetNewIntValue(newValue));
492}
493
494///////////////////////////////////////////////////////////////////////////
495// ApplyString command
496template <typename M>
497class G4ModelCmdApplyString : public G4VModelCommand<M> {
498
499public: // With description
500
501 G4ModelCmdApplyString(M* model, const G4String& placement, const G4String& cmdName);
502
503 virtual ~G4ModelCmdApplyString();
504
505 void SetNewValue(G4UIcommand* command, G4String newValue);
506
507protected:
508
509 // Implement in derived class
510 virtual void Apply(const G4String&) = 0;
511
512 G4UIcmdWithAString* Command() {return fpCmd;}
513
514private:
515
516 G4UIcmdWithAString* fpCmd;
517
518};
519
520template <typename M>
521G4ModelCmdApplyString<M>::G4ModelCmdApplyString(M* model, const G4String& placement, const G4String& cmdName)
522 :G4VModelCommand<M>(model, placement)
523{
524 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
525
526 fpCmd = new G4UIcmdWithAString(dir, this);
527}
528
529template <typename M>
530G4ModelCmdApplyString<M>::~G4ModelCmdApplyString()
531{
532 delete fpCmd;
533}
534
535template <typename M>
536void G4ModelCmdApplyString<M>::SetNewValue(G4UIcommand*, G4String newValue)
537{
538 Apply(newValue);
539}
540
541#endif
Note: See TracBrowser for help on using the repository browser.