| 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: G4UIcmdWithADoubleAndUnit.cc,v 1.9 2006/06/29 19:08:48 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: HEAD $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 |
|
|---|
| 32 | #include "G4UIcmdWithADoubleAndUnit.hh"
|
|---|
| 33 | #include "G4Tokenizer.hh"
|
|---|
| 34 | #include "G4UnitsTable.hh"
|
|---|
| 35 | #include <sstream>
|
|---|
| 36 |
|
|---|
| 37 | G4UIcmdWithADoubleAndUnit::G4UIcmdWithADoubleAndUnit
|
|---|
| 38 | (const char * theCommandPath,G4UImessenger * theMessenger)
|
|---|
| 39 | :G4UIcommand(theCommandPath,theMessenger)
|
|---|
| 40 | {
|
|---|
| 41 | G4UIparameter * dblParam = new G4UIparameter('d');
|
|---|
| 42 | SetParameter(dblParam);
|
|---|
| 43 | G4UIparameter * untParam = new G4UIparameter('s');
|
|---|
| 44 | SetParameter(untParam);
|
|---|
| 45 | untParam->SetParameterName("Unit");
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | G4double G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(const char* paramString)
|
|---|
| 49 | {
|
|---|
| 50 | return ConvertToDimensionedDouble(paramString);
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | G4double G4UIcmdWithADoubleAndUnit::GetNewDoubleRawValue(const char* paramString)
|
|---|
| 54 | {
|
|---|
| 55 | G4double vl;
|
|---|
| 56 | char unts[30];
|
|---|
| 57 |
|
|---|
| 58 | std::istringstream is(paramString);
|
|---|
| 59 | is >> vl >> unts;
|
|---|
| 60 |
|
|---|
| 61 | return vl;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | G4double G4UIcmdWithADoubleAndUnit::GetNewUnitValue(const char* paramString)
|
|---|
| 65 | {
|
|---|
| 66 | G4double vl;
|
|---|
| 67 | char unts[30];
|
|---|
| 68 |
|
|---|
| 69 | std::istringstream is(paramString);
|
|---|
| 70 | is >> vl >> unts;
|
|---|
| 71 | G4String unt = unts;
|
|---|
| 72 |
|
|---|
| 73 | return ValueOf(unt);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | G4String G4UIcmdWithADoubleAndUnit::ConvertToStringWithBestUnit(G4double val)
|
|---|
| 77 | {
|
|---|
| 78 | G4UIparameter* unitParam = GetParameter(1);
|
|---|
| 79 | G4String canList = unitParam->GetParameterCandidates();
|
|---|
| 80 | G4Tokenizer candidateTokenizer(canList);
|
|---|
| 81 | G4String aToken = candidateTokenizer();
|
|---|
| 82 | std::ostringstream os;
|
|---|
| 83 | os << G4BestUnit(val,CategoryOf(aToken));
|
|---|
| 84 |
|
|---|
| 85 | G4String st = os.str();
|
|---|
| 86 | return st;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | G4String G4UIcmdWithADoubleAndUnit::ConvertToStringWithDefaultUnit(G4double val)
|
|---|
| 90 | {
|
|---|
| 91 | G4UIparameter* unitParam = GetParameter(1);
|
|---|
| 92 | G4String st;
|
|---|
| 93 | if(unitParam->IsOmittable())
|
|---|
| 94 | { st = ConvertToString(val,unitParam->GetDefaultValue()); }
|
|---|
| 95 | else
|
|---|
| 96 | { st = ConvertToStringWithBestUnit(val); }
|
|---|
| 97 | return st;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | void G4UIcmdWithADoubleAndUnit::SetParameterName
|
|---|
| 101 | (const char * theName,G4bool omittable,G4bool currentAsDefault)
|
|---|
| 102 | {
|
|---|
| 103 | G4UIparameter * theParam = GetParameter(0);
|
|---|
| 104 | theParam->SetParameterName(theName);
|
|---|
| 105 | theParam->SetOmittable(omittable);
|
|---|
| 106 | theParam->SetCurrentAsDefault(currentAsDefault);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | void G4UIcmdWithADoubleAndUnit::SetDefaultValue(G4double defVal)
|
|---|
| 110 | {
|
|---|
| 111 | G4UIparameter * theParam = GetParameter(0);
|
|---|
| 112 | theParam->SetDefaultValue(defVal);
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | void G4UIcmdWithADoubleAndUnit::SetUnitCategory(const char * unitCategory)
|
|---|
| 116 | {
|
|---|
| 117 | SetUnitCandidates(UnitsList(unitCategory));
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | void G4UIcmdWithADoubleAndUnit::SetUnitCandidates(const char * candidateList)
|
|---|
| 121 | {
|
|---|
| 122 | G4UIparameter * untParam = GetParameter(1);
|
|---|
| 123 | G4String canList = candidateList;
|
|---|
| 124 | untParam->SetParameterCandidates(canList);
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | void G4UIcmdWithADoubleAndUnit::SetDefaultUnit(const char * defUnit)
|
|---|
| 128 | {
|
|---|
| 129 | G4UIparameter * untParam = GetParameter(1);
|
|---|
| 130 | untParam->SetOmittable(true);
|
|---|
| 131 | untParam->SetDefaultValue(defUnit);
|
|---|
| 132 | SetUnitCategory(CategoryOf(defUnit));
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|