File indexing completed on 2025-01-18 09:58:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 #ifndef G4APPLYCOMMANDST_HH
0033 #define G4APPLYCOMMANDST_HH
0034
0035 #include "G4Colour.hh"
0036 #include "G4String.hh"
0037 #include "G4UIcmdWithABool.hh"
0038 #include "G4UIcmdWithADouble.hh"
0039 #include "G4UIcmdWithADoubleAndUnit.hh"
0040 #include "G4UIcmdWithAnInteger.hh"
0041 #include "G4UIcmdWithAString.hh"
0042 #include "G4UIcommand.hh"
0043 #include "G4VModelCommand.hh"
0044 #include "G4VVisManager.hh"
0045 #include <sstream>
0046
0047
0048
0049 template <typename M>
0050 class G4ModelCmdApplyStringColour : public G4VModelCommand<M> {
0051
0052 public:
0053
0054 G4ModelCmdApplyStringColour(M* model, const G4String& placement, const G4String& cmdName);
0055
0056 virtual ~G4ModelCmdApplyStringColour();
0057
0058 void SetNewValue(G4UIcommand* command, G4String newValue);
0059
0060 protected:
0061
0062
0063 virtual void Apply(const G4String&, const G4Colour&) = 0;
0064
0065 G4UIcommand* StringCommand() {return fpStringCmd;}
0066 G4UIcommand* ComponentCommand() {return fpComponentCmd;}
0067
0068 private:
0069
0070 G4UIcommand* fpStringCmd;
0071 G4UIcommand* fpComponentCmd;
0072
0073 };
0074
0075 template <typename M>
0076 G4ModelCmdApplyStringColour<M>::G4ModelCmdApplyStringColour(M* model, const G4String& placement, const G4String& cmdName)
0077 :G4VModelCommand<M>(model, placement)
0078 {
0079
0080 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
0081 G4UIparameter* param(0);
0082
0083 fpStringCmd = new G4UIcommand(dir, this);
0084 fpStringCmd->SetGuidance("Set variable colour through a string");
0085
0086 param = new G4UIparameter("Variable", 's', false);
0087 fpStringCmd->SetParameter(param);
0088
0089 param = new G4UIparameter("Value", 's', false);
0090 fpStringCmd->SetParameter(param);
0091
0092
0093 G4String componentDir = dir+"RGBA";
0094
0095 fpComponentCmd = new G4UIcommand(componentDir, this);
0096 fpComponentCmd->SetGuidance("Set variable colour through red, green, blue and alpha components");
0097 param = new G4UIparameter("Variable", 's', false);
0098 fpComponentCmd->SetParameter(param);
0099
0100 param = new G4UIparameter("Red component", 'd', false);
0101 fpComponentCmd->SetParameter(param);
0102
0103 param = new G4UIparameter("Green component", 'd', false);
0104 fpComponentCmd->SetParameter(param);
0105
0106 param = new G4UIparameter("Blue component", 'd', false);
0107 fpComponentCmd->SetParameter(param);
0108
0109 param = new G4UIparameter("Alpha component", 'd', false);
0110 fpComponentCmd->SetParameter(param);
0111 }
0112
0113 template <typename M>
0114 G4ModelCmdApplyStringColour<M>::~G4ModelCmdApplyStringColour()
0115 {
0116 delete fpStringCmd;
0117 delete fpComponentCmd;
0118 }
0119
0120 template <typename M>
0121 void G4ModelCmdApplyStringColour<M>::SetNewValue(G4UIcommand* cmd, G4String newValue)
0122 {
0123 G4Colour myColour;
0124 G4String parameter;
0125
0126 if (cmd == fpStringCmd) {
0127 G4String colour;
0128 std::istringstream is (newValue);
0129 is >> parameter >> colour;
0130
0131
0132 if (!G4Colour::GetColour(colour, myColour)) {
0133 G4ExceptionDescription ed;
0134 ed << "G4Colour with key "<<colour<<" does not exist ";
0135 G4Exception
0136 ("G4ModelCmdApplyStringColour<M>::SetNewValue",
0137 "modeling0106", JustWarning, ed);
0138 return;
0139 }
0140 }
0141
0142 if (cmd == fpComponentCmd) {
0143 G4double red(0), green(0), blue(0), alpha(0);
0144 std::istringstream is (newValue);
0145 is >> parameter >> red >> green >> blue >> alpha;
0146
0147 G4Colour colour(red, green, blue, alpha);
0148 myColour = colour;
0149 }
0150
0151 Apply(parameter, myColour);
0152 G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
0153 if (visManager) visManager->NotifyHandlers();
0154 }
0155
0156
0157
0158 template <typename M>
0159 class G4ModelCmdApplyColour : public G4VModelCommand<M> {
0160
0161 public:
0162
0163 G4ModelCmdApplyColour(M* model, const G4String& placement, const G4String& cmdName);
0164
0165 virtual ~G4ModelCmdApplyColour();
0166
0167 void SetNewValue(G4UIcommand* command, G4String newValue);
0168
0169 protected:
0170
0171
0172 virtual void Apply(const G4Colour&) = 0;
0173
0174 G4UIcommand* StringCommand() {return fpStringCmd;}
0175 G4UIcommand* ComponentCommand() {return fpComponentCmd;}
0176
0177 private:
0178
0179 G4UIcommand* fpStringCmd;
0180 G4UIcommand* fpComponentCmd;
0181
0182 };
0183
0184 template <typename M>
0185 G4ModelCmdApplyColour<M>::G4ModelCmdApplyColour(M* model, const G4String& placement, const G4String& cmdName)
0186 :G4VModelCommand<M>(model, placement)
0187 {
0188
0189 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
0190 G4UIparameter* param(0);
0191
0192 fpStringCmd = new G4UIcommand(dir, this);
0193 fpStringCmd->SetGuidance("Set colour through a string");
0194
0195 param = new G4UIparameter("Variable", 's', false);
0196 fpStringCmd->SetParameter(param);
0197
0198
0199 G4String componentDir = dir+"RGBA";
0200
0201 fpComponentCmd = new G4UIcommand(componentDir, this);
0202 fpComponentCmd->SetGuidance("Set colour through red, green, blue and alpha components");
0203 fpComponentCmd->SetGuidance("Four inputs are expected.");
0204
0205 param = new G4UIparameter("Red component", 'd', false);
0206 fpComponentCmd->SetParameter(param);
0207
0208 param = new G4UIparameter("Green component", 'd', false);
0209 fpComponentCmd->SetParameter(param);
0210
0211 param = new G4UIparameter("Blue component", 'd', false);
0212 fpComponentCmd->SetParameter(param);
0213
0214 param = new G4UIparameter("Alpha component", 'd', false);
0215 fpComponentCmd->SetParameter(param);
0216 }
0217
0218 template <typename M>
0219 G4ModelCmdApplyColour<M>::~G4ModelCmdApplyColour()
0220 {
0221 delete fpStringCmd;
0222 delete fpComponentCmd;
0223 }
0224
0225 template <typename M>
0226 void G4ModelCmdApplyColour<M>::SetNewValue(G4UIcommand* cmd, G4String newValue)
0227 {
0228 G4Colour myColour;
0229
0230 if (cmd == fpStringCmd) {
0231 G4String colour;
0232 std::istringstream is (newValue);
0233 is >> colour;
0234
0235
0236 if (!G4Colour::GetColour(colour, myColour)) {
0237 G4ExceptionDescription ed;
0238 ed << "G4Colour with key "<<colour<<" does not exist ";
0239 G4Exception
0240 ("G4ModelCmdApplyColour<M>::SetNewValue",
0241 "modeling0107", JustWarning, ed);
0242 return;
0243 }
0244 }
0245
0246 if (cmd == fpComponentCmd) {
0247 G4double red(0), green(0), blue(0), alpha(0);
0248 std::istringstream is (newValue);
0249 is >> red >> green >> blue >> alpha;
0250
0251 G4Colour colour(red, green, blue, alpha);
0252 myColour = colour;
0253 }
0254
0255 Apply(myColour);
0256 G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
0257 if (visManager) visManager->NotifyHandlers();
0258 }
0259
0260
0261
0262 template <typename M>
0263 class G4ModelCmdApplyBool : public G4VModelCommand<M> {
0264
0265 public:
0266
0267 G4ModelCmdApplyBool(M* model, const G4String& placement, const G4String& cmdName);
0268 virtual ~G4ModelCmdApplyBool();
0269
0270 void SetNewValue(G4UIcommand* command, G4String newValue);
0271
0272 protected:
0273
0274
0275 virtual void Apply(const G4bool&) = 0;
0276
0277 G4UIcmdWithABool* Command() {return fpCmd;}
0278
0279 private:
0280
0281 G4UIcmdWithABool* fpCmd;
0282
0283 };
0284
0285 template <typename M>
0286 G4ModelCmdApplyBool<M>::G4ModelCmdApplyBool(M* model, const G4String& placement, const G4String& cmdName)
0287 :G4VModelCommand<M>(model, placement)
0288 {
0289 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
0290 fpCmd = new G4UIcmdWithABool(dir, this);
0291
0292 fpCmd->SetParameterName("Bool", false);
0293 }
0294
0295 template <typename M>
0296 G4ModelCmdApplyBool<M>::~G4ModelCmdApplyBool()
0297 {
0298 delete fpCmd;
0299 }
0300
0301 template <typename M>
0302 void G4ModelCmdApplyBool<M>::SetNewValue(G4UIcommand*, G4String newValue)
0303 {
0304 Apply(fpCmd->GetNewBoolValue(newValue));
0305 G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
0306 if (visManager) visManager->NotifyHandlers();
0307 }
0308
0309
0310
0311 template <typename M>
0312 class G4ModelCmdApplyNull : public G4VModelCommand<M> {
0313
0314 public:
0315
0316 G4ModelCmdApplyNull(M* model, const G4String& placement, const G4String& cmdName);
0317
0318 virtual ~G4ModelCmdApplyNull();
0319
0320 void SetNewValue(G4UIcommand* command, G4String newValue);
0321
0322 protected:
0323
0324
0325 virtual void Apply() = 0;
0326
0327 G4UIcommand* Command() {return fpCmd;}
0328
0329 private:
0330
0331 G4UIcommand* fpCmd;
0332
0333 };
0334
0335 template <typename M>
0336 G4ModelCmdApplyNull<M>::G4ModelCmdApplyNull(M* model, const G4String& placement, const G4String& cmdName)
0337 :G4VModelCommand<M>(model, placement)
0338 {
0339 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
0340 fpCmd = new G4UIcommand(dir, this);
0341 }
0342
0343 template <typename M>
0344 G4ModelCmdApplyNull<M>::~G4ModelCmdApplyNull()
0345 {
0346 delete fpCmd;
0347 }
0348
0349 template <typename M>
0350 void G4ModelCmdApplyNull<M>::SetNewValue(G4UIcommand*, G4String)
0351 {
0352 Apply();
0353 G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
0354 if (visManager) visManager->NotifyHandlers();
0355 }
0356
0357
0358
0359 template <typename M>
0360 class G4ModelCmdApplyDouble : public G4VModelCommand<M> {
0361
0362 public:
0363
0364 G4ModelCmdApplyDouble(M* model, const G4String& placement, const G4String& cmdName);
0365
0366 virtual ~G4ModelCmdApplyDouble();
0367
0368 void SetNewValue(G4UIcommand* command, G4String newValue);
0369
0370 protected:
0371
0372
0373 virtual void Apply(const G4double&) = 0;
0374
0375 G4UIcmdWithADouble* Command() {return fpCmd;}
0376
0377 private:
0378
0379 G4UIcmdWithADouble* fpCmd;
0380
0381 };
0382
0383 template <typename M>
0384 G4ModelCmdApplyDouble<M>::G4ModelCmdApplyDouble(M* model, const G4String& placement, const G4String& cmdName)
0385 :G4VModelCommand<M>(model, placement)
0386 {
0387 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
0388
0389 fpCmd = new G4UIcmdWithADouble(dir, this);
0390 fpCmd->SetParameterName("Double", false);
0391 }
0392
0393 template <typename M>
0394 G4ModelCmdApplyDouble<M>::~G4ModelCmdApplyDouble()
0395 {
0396 delete fpCmd;
0397 }
0398
0399 template <typename M>
0400 void G4ModelCmdApplyDouble<M>::SetNewValue(G4UIcommand*, G4String newValue)
0401 {
0402 Apply(fpCmd->GetNewDoubleValue(newValue));
0403 G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
0404 if (visManager) visManager->NotifyHandlers();
0405 }
0406
0407
0408
0409 template <typename M>
0410 class G4ModelCmdApplyDoubleAndUnit : public G4VModelCommand<M> {
0411
0412 public:
0413
0414 G4ModelCmdApplyDoubleAndUnit(M* model, const G4String& placement, const G4String& cmdName);
0415
0416 virtual ~G4ModelCmdApplyDoubleAndUnit();
0417
0418 void SetNewValue(G4UIcommand* command, G4String newValue);
0419
0420 protected:
0421
0422
0423 virtual void Apply(const G4double&) = 0;
0424
0425 G4UIcmdWithADoubleAndUnit* Command() {return fpCmd;}
0426
0427 private:
0428
0429 G4UIcmdWithADoubleAndUnit* fpCmd;
0430
0431 };
0432
0433 template <typename M>
0434 G4ModelCmdApplyDoubleAndUnit<M>::G4ModelCmdApplyDoubleAndUnit(M* model, const G4String& placement, const G4String& cmdName)
0435 :G4VModelCommand<M>(model, placement)
0436 {
0437 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
0438
0439 fpCmd = new G4UIcmdWithADoubleAndUnit(dir, this);
0440 fpCmd->SetParameterName("DoubleAndUnit", false);
0441 }
0442
0443 template <typename M>
0444 G4ModelCmdApplyDoubleAndUnit<M>::~G4ModelCmdApplyDoubleAndUnit()
0445 {
0446 delete fpCmd;
0447 }
0448
0449 template <typename M>
0450 void G4ModelCmdApplyDoubleAndUnit<M>::SetNewValue(G4UIcommand*, G4String newValue)
0451 {
0452 Apply(fpCmd->GetNewDoubleValue(newValue));
0453 G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
0454 if (visManager) visManager->NotifyHandlers();
0455 }
0456
0457
0458
0459 template <typename M>
0460 class G4ModelCmdApplyInteger : public G4VModelCommand<M> {
0461
0462 public:
0463
0464 G4ModelCmdApplyInteger(M* model, const G4String& placement, const G4String& cmdName);
0465
0466 virtual ~G4ModelCmdApplyInteger();
0467
0468 void SetNewValue(G4UIcommand* command, G4String newValue);
0469
0470 protected:
0471
0472
0473 virtual void Apply(const G4int&) = 0;
0474
0475 G4UIcmdWithAnInteger* Command() {return fpCmd;}
0476
0477 private:
0478
0479 G4UIcmdWithAnInteger* fpCmd;
0480 };
0481
0482 template <typename M>
0483 G4ModelCmdApplyInteger<M>::G4ModelCmdApplyInteger(M* model, const G4String& placement, const G4String& cmdName)
0484 :G4VModelCommand<M>(model, placement)
0485 {
0486 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
0487
0488 fpCmd = new G4UIcmdWithAnInteger(dir, this);
0489 fpCmd->SetParameterName("Integer", false);
0490 }
0491
0492 template <typename M>
0493 G4ModelCmdApplyInteger<M>::~G4ModelCmdApplyInteger()
0494 {
0495 delete fpCmd;
0496 }
0497
0498 template <typename M>
0499 void G4ModelCmdApplyInteger<M>::SetNewValue(G4UIcommand*, G4String newValue)
0500 {
0501 Apply(fpCmd->GetNewIntValue(newValue));
0502 G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
0503 if (visManager) visManager->NotifyHandlers();
0504 }
0505
0506
0507
0508 template <typename M>
0509 class G4ModelCmdApplyString : public G4VModelCommand<M> {
0510
0511 public:
0512
0513 G4ModelCmdApplyString(M* model, const G4String& placement, const G4String& cmdName);
0514
0515 virtual ~G4ModelCmdApplyString();
0516
0517 void SetNewValue(G4UIcommand* command, G4String newValue);
0518
0519 protected:
0520
0521
0522 virtual void Apply(const G4String&) = 0;
0523
0524 G4UIcmdWithAString* Command() {return fpCmd;}
0525
0526 private:
0527
0528 G4UIcmdWithAString* fpCmd;
0529
0530 };
0531
0532 template <typename M>
0533 G4ModelCmdApplyString<M>::G4ModelCmdApplyString(M* model, const G4String& placement, const G4String& cmdName)
0534 :G4VModelCommand<M>(model, placement)
0535 {
0536 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
0537
0538 fpCmd = new G4UIcmdWithAString(dir, this);
0539 }
0540
0541 template <typename M>
0542 G4ModelCmdApplyString<M>::~G4ModelCmdApplyString()
0543 {
0544 delete fpCmd;
0545 }
0546
0547 template <typename M>
0548 void G4ModelCmdApplyString<M>::SetNewValue(G4UIcommand*, G4String newValue)
0549 {
0550 Apply(newValue);
0551 G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
0552 if (visManager) visManager->NotifyHandlers();
0553 }
0554
0555 #endif