00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "G4UIcmdWith3VectorAndUnit.hh"
00032 #include "G4Tokenizer.hh"
00033 #include "G4UnitsTable.hh"
00034 #include <sstream>
00035
00036 G4UIcmdWith3VectorAndUnit::G4UIcmdWith3VectorAndUnit
00037 (const char * theCommandPath,G4UImessenger * theMessenger)
00038 :G4UIcommand(theCommandPath,theMessenger)
00039 {
00040 G4UIparameter * dblParamX = new G4UIparameter('d');
00041 SetParameter(dblParamX);
00042 G4UIparameter * dblParamY = new G4UIparameter('d');
00043 SetParameter(dblParamY);
00044 G4UIparameter * dblParamZ = new G4UIparameter('d');
00045 SetParameter(dblParamZ);
00046 G4UIparameter * untParam = new G4UIparameter('s');
00047 SetParameter(untParam);
00048 untParam->SetParameterName("Unit");
00049 }
00050
00051 G4int G4UIcmdWith3VectorAndUnit::DoIt(G4String parameterList)
00052 {
00053 std::vector<G4String> token_vector;
00054 G4Tokenizer tkn(parameterList);
00055 G4String str;
00056 while( (str = tkn()) != "" ) {
00057 token_vector.push_back(str);
00058 }
00059
00060
00061 G4String converted_parameter;
00062 G4String default_unit = GetParameter(3)-> GetDefaultValue();
00063 if (default_unit != "" && token_vector.size() >= 4) {
00064 G4double value_given = ValueOf(token_vector[3]);
00065 G4double value_default = ValueOf(default_unit);
00066 G4double x = ConvertToDouble(token_vector[0]) * value_given / value_default;
00067 G4double y = ConvertToDouble(token_vector[1]) * value_given / value_default;
00068 G4double z = ConvertToDouble(token_vector[2]) * value_given / value_default;
00069
00070
00071 converted_parameter += ConvertToString(x);
00072 converted_parameter += " ";
00073 converted_parameter += ConvertToString(y);
00074 converted_parameter += " ";
00075 converted_parameter += ConvertToString(z);
00076 converted_parameter += " ";
00077 converted_parameter += default_unit;
00078 for ( size_t i=4 ; i< token_vector.size(); i++) {
00079 converted_parameter += " ";
00080 converted_parameter += token_vector[i];
00081 }
00082 } else {
00083 converted_parameter = parameterList;
00084 }
00085
00086 return G4UIcommand::DoIt(converted_parameter);
00087 }
00088
00089 G4ThreeVector G4UIcmdWith3VectorAndUnit::GetNew3VectorValue(const char* paramString)
00090 {
00091 return ConvertToDimensioned3Vector(paramString);
00092 }
00093
00094 G4ThreeVector G4UIcmdWith3VectorAndUnit::GetNew3VectorRawValue(const char* paramString)
00095 {
00096 G4double vx;
00097 G4double vy;
00098 G4double vz;
00099 char unts[30];
00100 std::istringstream is(paramString);
00101 is >> vx >> vy >> vz >> unts;
00102 return G4ThreeVector(vx,vy,vz);
00103 }
00104
00105 G4double G4UIcmdWith3VectorAndUnit::GetNewUnitValue(const char* paramString)
00106 {
00107 G4double vx;
00108 G4double vy;
00109 G4double vz;
00110 char unts[30];
00111 std::istringstream is(paramString);
00112 is >> vx >> vy >> vz >> unts;
00113 G4String unt = unts;
00114 return ValueOf(unt);
00115 }
00116
00117 G4String G4UIcmdWith3VectorAndUnit::ConvertToStringWithBestUnit(G4ThreeVector vec)
00118 {
00119 G4UIparameter* unitParam = GetParameter(3);
00120 G4String canList = unitParam->GetParameterCandidates();
00121 G4Tokenizer candidateTokenizer(canList);
00122 G4String aToken = candidateTokenizer();
00123
00124 std::ostringstream os;
00125 os << G4BestUnit(vec,CategoryOf(aToken));
00126 G4String st = os.str();
00127
00128 return st;
00129 }
00130
00131 G4String G4UIcmdWith3VectorAndUnit::ConvertToStringWithDefaultUnit(G4ThreeVector vec)
00132 {
00133 G4UIparameter* unitParam = GetParameter(3);
00134 G4String st;
00135 if(unitParam->IsOmittable())
00136 { st = ConvertToString(vec,unitParam->GetDefaultValue()); }
00137 else
00138 { st = ConvertToStringWithBestUnit(vec); }
00139 return st;
00140 }
00141
00142 void G4UIcmdWith3VectorAndUnit::SetParameterName
00143 (const char * theNameX,const char * theNameY,const char * theNameZ,
00144 G4bool omittable,G4bool currentAsDefault)
00145 {
00146 G4UIparameter * theParamX = GetParameter(0);
00147 theParamX->SetParameterName(theNameX);
00148 theParamX->SetOmittable(omittable);
00149 theParamX->SetCurrentAsDefault(currentAsDefault);
00150 G4UIparameter * theParamY = GetParameter(1);
00151 theParamY->SetParameterName(theNameY);
00152 theParamY->SetOmittable(omittable);
00153 theParamY->SetCurrentAsDefault(currentAsDefault);
00154 G4UIparameter * theParamZ = GetParameter(2);
00155 theParamZ->SetParameterName(theNameZ);
00156 theParamZ->SetOmittable(omittable);
00157 theParamZ->SetCurrentAsDefault(currentAsDefault);
00158 }
00159
00160 void G4UIcmdWith3VectorAndUnit::SetDefaultValue(G4ThreeVector vec)
00161 {
00162 G4UIparameter * theParamX = GetParameter(0);
00163 theParamX->SetDefaultValue(vec.x());
00164 G4UIparameter * theParamY = GetParameter(1);
00165 theParamY->SetDefaultValue(vec.y());
00166 G4UIparameter * theParamZ = GetParameter(2);
00167 theParamZ->SetDefaultValue(vec.z());
00168 }
00169
00170 void G4UIcmdWith3VectorAndUnit::SetUnitCategory(const char * unitCategory)
00171 {
00172 SetUnitCandidates(UnitsList(unitCategory));
00173 }
00174
00175 void G4UIcmdWith3VectorAndUnit::SetUnitCandidates(const char * candidateList)
00176 {
00177 G4UIparameter * untParam = GetParameter(3);
00178 G4String canList = candidateList;
00179 untParam->SetParameterCandidates(canList);
00180 }
00181
00182 void G4UIcmdWith3VectorAndUnit::SetDefaultUnit(const char * defUnit)
00183 {
00184 G4UIparameter * untParam = GetParameter(3);
00185 untParam->SetOmittable(true);
00186 untParam->SetDefaultValue(defUnit);
00187 SetUnitCategory(CategoryOf(defUnit));
00188 }
00189